Implemented GetCostFromDuration() for tariffs with step-structure and no special days
This commit is contained in:
parent
fd5b41364a
commit
1c13a705c8
@ -339,17 +339,38 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
///
|
||||||
|
|
||||||
|
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
|
||||||
|
QDateTime const &start,
|
||||||
|
quint64 timeStepInMinutes,
|
||||||
|
uint8_t paymentMethod) {
|
||||||
|
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
|
||||||
|
// special days, nonstop.
|
||||||
|
if (paymentMethod == PaymentMethod::Steps
|
||||||
|
&& cfg->SpecialDays.size() == 0
|
||||||
|
&& cfg->SpecialDaysWorktime.size() == 0) {
|
||||||
|
QDateTime const end = start.addSecs(timeStepInMinutes*60);
|
||||||
|
return GetCostFromDuration(cfg, start, end, paymentMethod);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
|
||||||
|
QDateTime const &start,
|
||||||
|
QDateTime const &end,
|
||||||
|
uint8_t paymentMethod) {
|
||||||
|
if (paymentMethod == PaymentMethod::Steps
|
||||||
|
&& cfg->SpecialDays.size() == 0
|
||||||
|
&& cfg->SpecialDaysWorktime.size() == 0) {
|
||||||
|
int const timeStepInMinutes = start.secsTo(end) / 60;
|
||||||
|
return GetPriceForTimeStep(cfg, paymentMethod, timeStepInMinutes);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||||
{
|
{
|
||||||
if (cfg->project.project == "Schoenau" || cfg->project.project == "schoenau") {
|
|
||||||
static QList<int> const timeSteps = GetTimeSteps(cfg, payment_option);
|
|
||||||
if (!timeSteps.contains(durationMin)) {
|
|
||||||
return 0.0f; // error: timestep not valid
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetPriceForTimeStep(cfg, payment_option, durationMin);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get input date
|
// Get input date
|
||||||
QDateTime inputDate = start_datetime;
|
QDateTime inputDate = start_datetime;
|
||||||
|
|
||||||
@ -566,7 +587,7 @@ QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption)
|
|||||||
return timeSteps;
|
return timeSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Calculator::GetPriceForTimeStep(Configuration const *cfg, int paymentOption, int timeStep) {
|
uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentOption, int timeStep) {
|
||||||
|
|
||||||
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
|
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
|
||||||
|
|
||||||
@ -579,9 +600,9 @@ double Calculator::GetPriceForTimeStep(Configuration const *cfg, int paymentOpti
|
|||||||
|
|
||||||
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
||||||
if (timeStep == pun_duration) {
|
if (timeStep == pun_duration) {
|
||||||
return itr->second.pra_price;
|
return (uint32_t)(itr->second.pra_price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user