Synced GetDurationFromCost() with GetCostFromDuration()
This commit is contained in:
parent
9d5ddfc328
commit
7933c826e6
@ -231,6 +231,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (carryOverNotSet) {
|
if (carryOverNotSet) {
|
||||||
int range = 0;
|
int range = 0;
|
||||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||||
|
int minsUsed = 0;
|
||||||
QDateTime lastCurrent = QDateTime();
|
QDateTime lastCurrent = QDateTime();
|
||||||
|
|
||||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||||
@ -246,7 +247,6 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||||
|
|
||||||
|
|
||||||
if (current.time() >= to) {
|
if (current.time() >= to) {
|
||||||
continue; // try to use next available work-time
|
continue; // try to use next available work-time
|
||||||
} else
|
} else
|
||||||
@ -272,22 +272,23 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||||
timeRange.time_range_from_in_minutes_from_start;
|
timeRange.time_range_from_in_minutes_from_start;
|
||||||
|
|
||||||
if (current.addSecs(duration * 60).time() <= to) {
|
if (minsUsed > 0) {
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
duration -= minsUsed;
|
||||||
ATBPaymentRate const rate = x.second;
|
minsUsed = 0;
|
||||||
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 (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;
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
if (price >= maxParkingPrice) {
|
if (price >= maxParkingPrice) {
|
||||||
@ -304,8 +305,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
end_datetime = current;
|
end_datetime = current;
|
||||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,11 +322,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
lastCurrent = current;
|
lastCurrent = current;
|
||||||
current.setTime(to);
|
current.setTime(to);
|
||||||
int const minsUsed = lastCurrent.secsTo(current) / 60;
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||||
|
|
||||||
// mod duration: possibly discard some minutes in
|
// mod duration: possibly discard some minutes in
|
||||||
// the next time-range
|
// the next time-range
|
||||||
minsToCarryOver = (durationMinutes - minsUsed) % duration;
|
if (durationMinutes >= minsUsed) {
|
||||||
|
minsToCarryOver = durationMinutes - minsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
durationMinutes -= minsUsed;
|
durationMinutes -= minsUsed;
|
||||||
durationMinutesNetto += minsUsed;
|
durationMinutesNetto += minsUsed;
|
||||||
@ -344,12 +348,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
end_datetime = current;
|
end_datetime = current;
|
||||||
// return end_datetime.toString(Qt::ISODate).toStdString();
|
// return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user