get_maximal_parkingprice(): in case of progressive tariff, read maximal parking time

directly form tariff-file as there is not price per hour.
This commit is contained in:
Gerhard Hoffmann 2024-02-20 15:47:02 +01:00
parent 9c19414e5a
commit 690267c388

View File

@ -78,17 +78,22 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TY
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
int const key = cfg->getPaymentOptions().pop_id;
int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
if (pv) {
QVector<ATBPaymentRate> const &paymentRate = pv.value();
if (paymentRate.size() > 0) {
int const price = paymentRate.at(0).pra_price; // price is given per hour
maxPrice = qRound((maxTime * price) / 60.0f);
if (paymentMethodId == PaymentMethod::Progressive) {
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
} else { // PaymentMethod::Linear -> e.g. szeged
int const key = cfg->getPaymentOptions().pop_id;
int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
if (pv) {
QVector<ATBPaymentRate> const &paymentRate = pv.value();
if (paymentRate.size() > 0) {
int const price = paymentRate.at(0).pra_price; // price is given per hour
maxPrice = qRound((maxTime * price) / 60.0f);
}
}
}
} break;