GetTimeSteps(): compute time steps and duration values.

For each element in the duration list (and for a given start-date-time)
check if there is a prepaid-option or an carry-over-option to compute the
correct values.
This commit is contained in:
Gerhard Hoffmann 2024-08-15 21:41:09 +02:00
parent 48cc6b1302
commit 84dbfc7234

View File

@ -2773,6 +2773,165 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
}
}
} else
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME) {
// some durations / timesteps have to be recomputed
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::RECOMPUTE_SOME";
int size = m_timeSteps.size();
while (size <= paymentOptionIndex) {
m_timeSteps.push_back(QList<int>());
size = m_timeSteps.size();
}
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
m_timeSteps[paymentOptionIndex].clear();
Configuration::TariffDurationType::iterator prev_it = cfg->Duration.end();
start = s;
start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
for (Configuration::TariffDurationType::iterator it = cfg->Duration.begin();
it != cfg->Duration.end();
++it) {
it->second.pun_duration = it->second.pun_duration_saved;
if (it->second.pun_requires_change) {
if (it->second.pun_netto && !it->second.pun_brutto) {
int weekDay = start.date().dayOfWeek();
bool casePrepay = false;
if (m_timeSteps[paymentOptionIndex].isEmpty()) {
// handle possible prepay-condition, which applies only
// for the very first step
int const pop_prepay_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepay_option_id;
QDateTime prepayStart(start);
QDateTime prepayEnd(start);
prepayStart.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].start);
prepayEnd.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].end);
if (start <= prepayEnd) {
prepayStart = prepayStart.addDays(-1);
} else {
prepayEnd = prepayEnd.addDays(1);
}
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << prepayEnd.toString(Qt::ISODate);
if (prepayStart <= start && start <= prepayEnd) {
it->second.pun_duration = start.secsTo(prepayEnd) / 60;
it->second.pun_duration += it->second.pun_duration_saved ;
casePrepay = true;
}
//if (start >= prepayStart && ) {
// it->second.pun_duration = start.secsTo(prepayEnd) / 60;
// it->second.pun_duration += it->second.pun_duration_saved ;
// casePrepay = true;
//}
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << it->second.pun_duration;
}
if (!casePrepay) {
// handle possible carryover-condition
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
QDateTime carryOverStart(start);
QDateTime carryOverEnd(start);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << carryOverStart.toString(Qt::ISODate);
carryOverStart.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start);
carryOverEnd.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end);
//while (carryOverStart > carryOverEnd) {
// carryOverEnd = carryOverEnd.addDays(1);
//}
if (start <= carryOverEnd) {
carryOverStart = carryOverStart.addDays(-1);
} else {
carryOverEnd = carryOverEnd.addDays(1);
}
int durationInSecs = it->second.pun_duration_saved * 60;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << durationInSecs;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << start.addSecs(durationInSecs).toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << carryOverStart.toString(Qt::ISODate);
it->second.pun_duration = it->second.pun_duration_saved;
if (start >= carryOverStart) {
it->second.pun_duration += start.secsTo(carryOverEnd) / 60;
} else {
// start < carryOverStart
if (start.addSecs(durationInSecs) >= carryOverStart) {
// cross carry over section
it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
it->second.pun_duration += it->second.pun_next_step_correction;
prev_it = it;
}
}
}
if (pop_accumulate_durations) {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
} else {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
}
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "no change required, but set to brutto, which does not have to be changed";
}
} else {
if (it->second.pun_fixed) { // no change required: must be true
if (it->second.pun_brutto) { // no handling for prepay and carry-over
if (pop_accumulate_durations) {
int correction = 0;
if (prev_it != cfg->Duration.end()) {
correction = prev_it->second.pun_next_step_correction;
prev_it->second.pun_next_step_correction = 0;
}
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
it->second.pun_duration -= correction;
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
} else {
it->second.pun_duration -= correction;
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
}
}
} else
if (it->second.pun_netto) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "TODO";
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "fixed is false, but no change required";
}
}
}
#if 0
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = start;
// nextTime.setTime(QTime(0, 0, 0));
int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
nextTime = nextTime.addSecs(secs);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
<< i << secs << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
}
#endif
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";