diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 6dce64e..8833ec8 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -2258,121 +2258,82 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, if (w.has_value()) { QVector const &vec = w.value(); - if (pop_carry_over) { - for (int i = 0; i < vec.size(); ++i) { - QTime const &from = QTime::fromString(QString::fromStdString(vec[i].pwd_time_from), Qt::ISODate); - QString const &toStr = QString::fromStdString(vec[i].pwd_time_to); + if (pop_carry_over == false) { + for (int i = 1; i <= vec.size(); ++i) { + QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate); + QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to); QTime const &to = QTime::fromString(toStr, Qt::ISODate); - int weekDayId = vec[i].pwd_period_day_in_week_id; + int weekDayId = vec[i-1].pwd_period_day_in_week_id; if (start.date().dayOfWeek() == weekDayId) { - //qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId; - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate); - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate); - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate); + qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate); - if (start.time() >= from) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate); - if (start.time() < to) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate); - - int runtimeInMinutes = (start.time().secsTo(to) / 60); - qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes; - qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex; - - m_timeSteps[paymentOptionIndex] << runtimeInMinutes; - - cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes; - - int pop_id = vec[i].pwd_pop_id; - int pwd_id = vec[i].pwd_id; - int pop_next_id = vec[i].pwd_next_id; - - for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { - int const durationId = itr->second.pra_payment_unit_id; - - qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId; - // int const price = itr->second.pra_price; - - auto search = cfg->Duration.find(durationId); - if (search != cfg->Duration.end()) { - ATBDuration duration = search->second; - duration.pun_duration = runtimeInMinutes; - search->second = duration; - } - } - - if (weekDayId == vec[pop_next_id].pwd_period_day_in_week_id) { - // on the same day - start.setTime(to); - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") next start" << start.toString(Qt::ISODate); - } else { - // on the next day - start.setTime(QTime::fromString(QString::fromStdString(vec[pop_next_id].pwd_time_from), Qt::ISODate)); - start = start.addDays(1); - - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") next start" << start.toString(Qt::ISODate); - } - - - while ((s.secsTo(start) / 60) < 5000) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ") next start" << start.toString(Qt::ISODate); - - pop_id = vec[i].pwd_pop_id; - pwd_id = vec[i].pwd_id; - pop_next_id = vec[i].pwd_next_id; - - runtimeInMinutes += (start.time().secsTo(to) / 60); - - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pwd_id " << pwd_id; - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id " << pop_id; - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_next_id " << pop_next_id; - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep" << nextTimeStep; - - // ATBPaymentOption o = cfg->getPaymentOptionForId(); - - m_timeSteps[paymentOptionIndex] << runtimeInMinutes; - qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX pop" << pop_id; - qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX index" << paymentOptionIndex; - -#if 0 - for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { - int const durationId = itr->second.pra_payment_unit_id; - - qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX durationId" << durationId; - // int const price = itr->second.pra_price; - - auto search = cfg->Duration.find(durationId); - if (search != cfg->Duration.end()) { - ATBDuration duration = search->second; - duration.pun_duration = runtimeInMinutes; - qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX durationId" << runtimeInMinutes; - search->second = duration; - } - } -#endif - - if (weekDayId == vec[pop_next_id].pwd_period_day_in_week_id) { - // on the same day - start.setTime(to); - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") next start" << start.toString(Qt::ISODate); - } else { - // on the next day - start.setTime(QTime::fromString(QString::fromStdString(vec[pop_next_id].pwd_time_from), Qt::ISODate)); - start = start.addDays(1); - - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") next start" << start.toString(Qt::ISODate); - } - //qCritical() << "(" << __func__ << ":" << __LINE__ << ") until" << s.secsTo(start) / 60; - } - break; + if (start.time() >= from && start.time() < to) { + int runtimeInMinutes = (start.time().secsTo(to) / 60); + if (to.hour() == 23 && to.minute() == 59) { + runtimeInMinutes += 1; } - } - } - } - } - } + qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex; + m_timeSteps[paymentOptionIndex] << runtimeInMinutes; + + cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes; + + int pop_id = vec[i-1].pwd_pop_id; + // int pwd_id = vec[i-1].pwd_id; + // int pwd_next_id = vec[i-1].pwd_next_id; + + qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id; + + int price = -1; + int durationId = -1; + + for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { + durationId = itr->second.pra_payment_unit_id; + + price = itr->second.pra_price; + + auto search = cfg->Duration.find(durationId); + if (search != cfg->Duration.end()) { + ATBDuration duration = search->second; + duration.pun_duration = runtimeInMinutes; + search->second = duration; + break; + } + } + + if (price >= 0 && durationId >= 0) { + qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price; + + pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; + for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { + if (durationId == itr->second.pra_payment_unit_id) { + itr->second.pra_price = price; + break; + } + } + } + + break; + } // if (start.time() >= from && start.time() < to) { + } // if (start.date().dayOfWeek() == weekDayId) { + } // for (int i = 1; i <= vec.size(); ++i) { + + // show content: + for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin(); + it != cfg->Duration.cend(); + ++it) { + qCritical() << "(" << __func__ << ":" << __LINE__ << ")" + << (*it).first << " => " << (*it).second; + } + + } // if (pop_carry_over == false) { + } // if (w.has_value()) { } else { uint16_t timeStepCompensation = 0;