Fix: rounding issue in GetCostFromDuration(): do not price_per_unit/durationUnit,
but set price_per_unit to day_price, and divide end result by durationUnit to work around the rounding problem (for e.g. a full hour price).
This commit is contained in:
parent
9bfea0f46d
commit
68ba6808fa
@ -456,11 +456,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
double price_per_unit = 0.0f;
|
double price_per_unit = 0.0f;
|
||||||
QTime worktime_from;
|
QTime worktime_from;
|
||||||
QTime worktime_to;
|
QTime worktime_to;
|
||||||
|
double durationUnit = 60.0;
|
||||||
|
|
||||||
if(is_special_day)
|
if(is_special_day)
|
||||||
{
|
{
|
||||||
// Set special day price
|
// Set price_per_unit to special day price: at the end of the calculation
|
||||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
// divide by durationUnit to get correct price.
|
||||||
|
price_per_unit = day_price;
|
||||||
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str());
|
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str());
|
||||||
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str());
|
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str());
|
||||||
}
|
}
|
||||||
@ -472,8 +474,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
||||||
|
|
||||||
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
||||||
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
|
if (durationUnit == 0) {
|
||||||
|
durationUnit = 60.0;
|
||||||
|
}
|
||||||
|
// Set price_per_unit to day price: at the end of the calculation
|
||||||
|
// divide by durationUnit to get correct price.
|
||||||
|
price_per_unit = day_price;
|
||||||
|
|
||||||
// If no working day found, skip it (recursively call method again)
|
// If no working day found, skip it (recursively call method again)
|
||||||
size_t found = 0;
|
size_t found = 0;
|
||||||
@ -484,7 +491,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
LOG_DEBUG("- No workday found, trying to find next available day");
|
LOG_DEBUG("- No workday found, trying to find next available day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid));
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid) / durationUnit;
|
||||||
}
|
}
|
||||||
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
||||||
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
||||||
@ -497,7 +504,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
inputDate.setTime(worktime_from);
|
inputDate.setTime(worktime_from);
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid) / durationUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If overtime flag is set
|
// If overtime flag is set
|
||||||
@ -527,7 +534,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
LOG_DEBUG(" *** PREPAID *** Current time is past the time range end, searching for next available day");
|
LOG_DEBUG(" *** PREPAID *** Current time is past the time range end, searching for next available day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid) / durationUnit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +586,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
overtime = true;
|
overtime = true;
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, total_duration_min);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, total_duration_min) / durationUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment input date minutes for each monetary unit
|
// Increment input date minutes for each monetary unit
|
||||||
@ -594,7 +601,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
|
|
||||||
double ret_val = total_cost;
|
double ret_val = total_cost;
|
||||||
total_cost = 0.0f;
|
total_cost = 0.0f;
|
||||||
return ceil(ret_val);
|
return round(ret_val / durationUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user