Fix: GetDurationFromCost for PaymentMethod::Steps

This commit is contained in:
Siegfried Siegert 2023-11-23 11:14:21 +01:00
parent 453ca266a5
commit 8f2609c4ae
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03

View File

@ -118,17 +118,21 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
bool nextDay,
bool prepaid)
{
// Get input date
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
// use tariff with structure as for instance Schnau, Koenigsee:
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (cfg->YearPeriod.size() == 0
&& cfg->SpecialDays.size() == 0
&& cfg->SpecialDaysWorktime.size() == 0)
{
return QString().setNum(GetDurationForPrice(cfg, price)).toStdString();
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60);
return inputDate.toString(Qt::ISODate).toStdString();
}
// Get input date
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
// Get day of week
int weekdayId = 0;
@ -633,14 +637,16 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
int const pop_id = cfg->getPaymentOptions().pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
int const payment_unit_id = itr->second.pra_payment_unit_id;
int const pra_price = cfg->PaymentRate.find(payment_unit_id)->second.pra_price;
int const pra_price = itr->second.pra_price;
if (price == pra_price) {
int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
return durationUnit;
}
}