Use computeBruttoDurationInSecs() to compute from durationInSecs
(which is a netto-time) to corresponding brutto-time, and adapt inputDate according to that date.
This commit is contained in:
parent
8b65bb3e2c
commit
77ca6a4736
@ -542,18 +542,16 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
#endif
|
||||
|
||||
} else {
|
||||
found = true;
|
||||
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") WWWWWW duration_previous" << duration_previous;
|
||||
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
|
||||
QString s = inputDate.toString(Qt::ISODate);
|
||||
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
|
||||
d = d.addSecs(duration_previous * 60);
|
||||
//qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << d;
|
||||
return d.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
} else {
|
||||
durationInSecs = cfg->Duration.find(durationId)->second.pun_duration * 60;
|
||||
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
||||
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
||||
qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
||||
qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
||||
}
|
||||
|
||||
if ((double)price == cost) {
|
||||
@ -566,25 +564,50 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << durationInSecs;
|
||||
qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO"
|
||||
<< current_working_date_time_to.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " INPUT DATE" << inputDate.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << "NEW INPUT DATE" << inputDate.addSecs(durationInSecs).toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
if (inputDate.addSecs(durationInSecs) > current_working_date_time_to) {
|
||||
int bruttoDurationInSecs = computeBruttoDurationInSecs(cfg, inputDate, durationInSecs);
|
||||
// qCritical() << DBG_HEADER << "DURATION IN SECONDS (NETTO)" << durationInSecs;
|
||||
// qCritical() << DBG_HEADER << "DURATION IN SECONDS (BRUTTO)" << bruttoDurationInSecs;
|
||||
|
||||
inputDate = inputDate.addSecs(bruttoDurationInSecs);
|
||||
#if 0
|
||||
// durationInSecs is a netto time
|
||||
// needed is the corresponding brutto-time
|
||||
int day_in_week_id = inputDate.date().dayOfWeek();
|
||||
int nettoDurationInSecs = 0;
|
||||
|
||||
while (nettoDurationInSecs <= durationInSecs) {
|
||||
if (cfg->WeekDaysWorktime.count(day_in_week_id) > 0) {
|
||||
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
|
||||
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
||||
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
|
||||
nettoDurationInSecs += pwd_time_from.secsTo(pwd_time_to);
|
||||
if (nettoDurationInSecs > durationInSecs) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
day_in_week_id += 1;
|
||||
if (day_in_week_id > (int)Qt::Sunday) {
|
||||
day_in_week_id = Qt::Monday;
|
||||
}
|
||||
}
|
||||
qCritical() << DBG_HEADER;
|
||||
|
||||
QTime next_working_time_from;
|
||||
if (cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over != 0) {
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "CARRY-OVER SET";
|
||||
#endif
|
||||
// check for next working-time-range on same day
|
||||
int day_in_week_id = inputDate.date().dayOfWeek();
|
||||
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
|
||||
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
||||
if (pwd_time_from > current_working_time_to) {
|
||||
next_working_time_from = pwd_time_from;
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "NEXT-WORKING-TIME-FROM"
|
||||
<< next_working_time_from.toString(Qt::ISODate);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -601,33 +624,33 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
||||
if (next_working_time_from < pwd_time_from) {
|
||||
next_working_time_from = pwd_time_from;
|
||||
qCritical() << DBG_HEADER << " day in week" << day_in_week_id;
|
||||
qCritical() << DBG_HEADER << "next working time from" << next_working_time_from.toString(Qt::ISODate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//qCritical() << DBG_HEADER << "DAYS" << days;
|
||||
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
||||
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
||||
qCritical() << DBG_HEADER << "DAYS" << days;
|
||||
qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
||||
qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
||||
|
||||
QDateTime upper = inputDate.addDays(days);
|
||||
upper.setTime(next_working_time_from);
|
||||
|
||||
//qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
|
||||
|
||||
QDateTime lower = inputDate;
|
||||
lower.setTime(current_working_time_to);
|
||||
|
||||
//qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
|
||||
|
||||
// inputDate = inputDate.addSecs(lower.secsTo(upper));
|
||||
|
||||
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
|
||||
|
||||
inputDate = inputDate.addSecs(durationInSecs);
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
// durationInSecs is a netto-parking-time
|
||||
inputDate = inputDate.addSecs(durationInSecs + lower.secsTo(upper));
|
||||
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
} // for (int days = 1; days < 8; ++days) {
|
||||
@ -639,36 +662,31 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
lower.setTime(current_working_time_to);
|
||||
|
||||
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
||||
//qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} else { // if (inputDate.addSecs(durationInSecs) > current_working_date_time_to) {
|
||||
if (pop_accumulate_durations) {
|
||||
inputDate = inputDate.addSecs(durationInSecs);
|
||||
} else {
|
||||
inputDate = inputDate.addSecs(duration.pun_duration * 60);
|
||||
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "INPUT-DATE" << inputDate.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
}
|
||||
// qCritical() << DBG_HEADER << "INPUT-DATE" << inputDate.toString(Qt::ISODate);
|
||||
}
|
||||
|
||||
QString const &s = inputDate.toString(Qt::ISODate);
|
||||
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "TICKET-END" << s;
|
||||
#endif
|
||||
|
||||
// qCritical() << DBG_HEADER << "TICKET-END" << s;
|
||||
return s.toStdString();
|
||||
} // if ((double)price == cost) {
|
||||
else {
|
||||
// qCritical() << DBG_HEADER;
|
||||
}
|
||||
} else {
|
||||
//qCritical() << __func__ << __LINE__;
|
||||
// qCritical() << DBG_HEADER;
|
||||
}
|
||||
}
|
||||
|
||||
// qCritical() << DBG_HEADER;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1142,10 +1160,11 @@ uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
|
||||
paymentMethodId == PaymentMethod::Degressive) {
|
||||
int const timeStepInMinutes = start.secsTo(end) / 60;
|
||||
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, start);
|
||||
qCritical() << DBG_HEADER << " start" << start.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << " end" << end.toString(Qt::ISODate);
|
||||
qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
|
||||
qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
|
||||
Q_UNUSED(tlist);
|
||||
//qCritical() << DBG_HEADER << " start" << start.toString(Qt::ISODate);
|
||||
//qCritical() << DBG_HEADER << " end" << end.toString(Qt::ISODate);
|
||||
//qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
|
||||
//qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
|
||||
|
||||
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user