Synced GetDurationFromCost() with GetCostFromDuration()

This commit is contained in:
Gerhard Hoffmann 2024-02-21 14:53:06 +01:00
parent 9d5ddfc328
commit 7933c826e6

View File

@ -231,6 +231,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
if (carryOverNotSet) {
int range = 0;
int minsToCarryOver = 0; // from one work-time to the other on the same day
int minsUsed = 0;
QDateTime lastCurrent = QDateTime();
auto timeRangeIt = cfg->TimeRange.cbegin();
@ -246,7 +247,6 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
if (current.time() >= to) {
continue; // try to use next available work-time
} else
@ -272,22 +272,23 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
int duration = timeRange.time_range_to_in_minutes_from_start -
timeRange.time_range_from_in_minutes_from_start;
if (current.addSecs(duration * 60).time() <= to) {
for(const auto &x: cfg->PaymentRate) {
ATBPaymentRate const rate = x.second;
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
if (minsToCarryOver > 0) {
durationMinutes -= minsToCarryOver;
durationMinutesNetto += minsToCarryOver;
durationMinutesBrutto += minsToCarryOver;
current = current.addSecs(minsToCarryOver*60);
minsToCarryOver = 0;
} else {
if (price >= cost) {
end_datetime = current;
return end_datetime.toString(Qt::ISODate).toStdString();
}
if (minsUsed > 0) {
duration -= minsUsed;
minsUsed = 0;
}
if (current.addSecs(duration * 60).time() <= to) {
if (minsToCarryOver > 0) { // the price for this time range
// has been is paid already
durationMinutes -= duration;
durationMinutesNetto += duration;
durationMinutesBrutto += duration;
current = current.addSecs(duration*60);
minsToCarryOver = 0;
} else {
for(const auto &x: cfg->PaymentRate) {
ATBPaymentRate const rate = x.second;
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
price += (uint)rate.pra_price;
if (price >= maxParkingPrice) {
@ -304,8 +305,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
end_datetime = current;
return end_datetime.toString(Qt::ISODate).toStdString();
}
break;
}
break;
}
}
@ -320,11 +322,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
lastCurrent = current;
current.setTime(to);
int const minsUsed = lastCurrent.secsTo(current) / 60;
minsUsed = lastCurrent.secsTo(current) / 60;
// mod duration: possibly discard some minutes in
// the next time-range
minsToCarryOver = (durationMinutes - minsUsed) % duration;
if (durationMinutes >= minsUsed) {
minsToCarryOver = durationMinutes - minsUsed;
}
durationMinutes -= minsUsed;
durationMinutesNetto += minsUsed;
@ -344,12 +348,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
end_datetime = current;
// return end_datetime.toString(Qt::ISODate).toStdString();
}
break;
}
}
}
break;
}
}