Add methods for PaymentMethod::Steps
This commit is contained in:
parent
d15c9dad29
commit
f7e462188f
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "configuration.h"
|
||||
#include "payment_method.h"
|
||||
#include <QDateTime>
|
||||
using namespace std;
|
||||
|
||||
@ -30,4 +31,19 @@ public:
|
||||
|
||||
// Daily ticket
|
||||
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||
|
||||
|
||||
private:
|
||||
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
|
||||
// For tariff of following structure: only steps, no special days, nonstop.
|
||||
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, quint64 durationMinutes, uint8_t paymentMethod = PaymentMethod::Steps);
|
||||
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, QDateTime const &end, uint8_t paymentMethod = PaymentMethod::Steps);
|
||||
|
||||
|
||||
//
|
||||
// helper functions for PaymentMethod::Steps
|
||||
//
|
||||
QList<int> GetTimeSteps(Configuration const *cfg, int paymentMethod);
|
||||
//
|
||||
uint32_t GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentMethod, int timeStep);
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "calculator_functions.h"
|
||||
#include "payment_method.h"
|
||||
#include "payment_option.h"
|
||||
#include "utilities.h"
|
||||
#include "tariff_log.h"
|
||||
|
||||
@ -336,11 +336,56 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
return inputDate.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
/// <inheritdoc/>
|
||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||
{
|
||||
// condition for 'PaymentMethod::Steps' (e.g. 332/Schoenau):
|
||||
if (payment_option == PaymentOption::Option1
|
||||
&& cfg->SpecialDays.size() == 0
|
||||
&& cfg->SpecialDaysWorktime.size() == 0)
|
||||
{
|
||||
QDateTime const end = start_datetime.addSecs(durationMin*60);
|
||||
return GetCostFromDuration(cfg, start_datetime, end, PaymentMethod::Steps);
|
||||
}
|
||||
|
||||
// Get input date
|
||||
QDateTime inputDate = start_datetime;
|
||||
|
||||
@ -541,3 +586,40 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
total_cost = 0.0f;
|
||||
return ceil(ret_val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption) {
|
||||
QList<int> timeSteps;
|
||||
|
||||
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
|
||||
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||
{
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
timeSteps << durationUnit;
|
||||
}
|
||||
|
||||
return timeSteps;
|
||||
}
|
||||
|
||||
uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentOption, int timeStep) {
|
||||
|
||||
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
|
||||
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||
{
|
||||
int const payment_unit_id = itr->second.pra_payment_unit_id;
|
||||
int const pun_id = cfg->Duration.find(payment_unit_id)->second.pun_id;
|
||||
|
||||
Q_ASSERT(pun_id == payment_unit_id);
|
||||
|
||||
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
||||
if (timeStep == pun_duration) {
|
||||
return (uint32_t)(itr->second.pra_price);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user