GetCostFromDuration(): fixed moving from time range 8:00-12:00 -> 14:00-18:00.

This commit is contained in:
Gerhard Hoffmann 2024-02-21 14:20:51 +01:00
parent 102607b71f
commit 9d5ddfc328

View File

@ -320,17 +320,17 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
lastCurrent = current; lastCurrent = current;
current.setTime(to); current.setTime(to);
int const minsLeft = lastCurrent.secsTo(current) / 60; int const 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 - minsLeft) % duration; minsToCarryOver = (durationMinutes - minsUsed) % duration;
durationMinutes -= minsLeft; durationMinutes -= minsUsed;
durationMinutesNetto += minsLeft; durationMinutesNetto += minsUsed;
durationMinutesBrutto += minsLeft; durationMinutesBrutto += minsUsed;
if (minsLeft > 0) { if (minsUsed > 0) {
for(const auto &x: cfg->PaymentRate) { for(const auto &x: cfg->PaymentRate) {
ATBPaymentRate const rate = x.second; ATBPaymentRate const rate = x.second;
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) { if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
@ -569,6 +569,7 @@ double Calculator::GetCostFromDuration(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();
@ -609,18 +610,23 @@ double Calculator::GetCostFromDuration(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) {
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) { for(const auto &x: cfg->PaymentRate) {
ATBPaymentRate const rate = x.second; ATBPaymentRate const rate = x.second;
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) { 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 {
price += (uint)rate.pra_price; price += (uint)rate.pra_price;
durationMinutes -= duration; durationMinutes -= duration;
@ -628,10 +634,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
durationMinutesBrutto += duration; durationMinutesBrutto += duration;
current = current.addSecs(duration * 60); current = current.addSecs(duration * 60);
}
break; break;
} }
} }
}
if (durationMinutes <= 0) { if (durationMinutes <= 0) {
end_datetime = current; end_datetime = current;
@ -644,17 +650,19 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
lastCurrent = current; lastCurrent = current;
current.setTime(to); current.setTime(to);
int const minsLeft = 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 - minsLeft) % duration; if (durationMinutes >= minsUsed) {
minsToCarryOver = durationMinutes - minsUsed;
}
durationMinutes -= minsLeft; durationMinutes -= minsUsed;
durationMinutesNetto += minsLeft; durationMinutesNetto += minsUsed;
durationMinutesBrutto += minsLeft; durationMinutesBrutto += minsUsed;
if (minsLeft > 0) { if (minsUsed > 0) {
for(const auto &x: cfg->PaymentRate) { for(const auto &x: cfg->PaymentRate) {
ATBPaymentRate const rate = x.second; ATBPaymentRate const rate = x.second;
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) { if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
@ -663,7 +671,6 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
} }
} }
} }
break; break;
} }
} }