From acbc27cfb2fddb3c0b8433b051662ded8e84bbe9 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 30 Sep 2024 16:51:51 +0200 Subject: [PATCH] ComputeDurationFromCost(): If overapid or trunctae has been set, then truncated max. parking time to time-limit configured in tariff-file. --- library/src/calculator_functions.cpp | 57 ++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index a897f1d..e4b2d4c 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -347,9 +347,60 @@ Calculator::ComputeDurationFromCost(Configuration *cfg, .arg(free_parking_time_in_minutes); if (std::optional oos = getOutOfService(cfg, dt)) { - if (overPaid || startDateNotOutOfService) { - return std::make_pair(CalcState(CalcState::State::OVERPAID, - CalcState::OVERPAID), dt); + if (overPaid) { + QList keys = nettoParktimePrice.keys(); + for (int k = 0; k < keys.size(); ++k) { + if (keys[k] < netto_parking_time_in_minutes) { + continue; + } + + int const maxPriceForTimeLimit = nettoParktimePrice[keys[k]]; + if (cost > maxPriceForTimeLimit) { + cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit; + + CalcState cs(CalcState::State::OVERPAID); + return std::make_pair(cs, dt); + } + if (cost == maxPriceForTimeLimit) { + cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit; + + CalcState cs(CalcState::State::SUCCESS_MAXPRICE); + return std::make_pair(cs, dt); + } + } + return std::make_pair(CalcState(CalcState::State::OVERPAID), dt); + } + if (startDateNotOutOfService) { + if (truncate) { + qCritical() << __func__ << ":" << __LINE__ << "set time-limit reached"; + qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time_in_minutes; + Calculator::GetInstance().setTimeLimitReached(true); + QList keys = nettoParktimePrice.keys(); + for (int k = 0; k < keys.size(); ++k) { + if (keys[k] < netto_parking_time_in_minutes) { + continue; + } + + int const maxPriceForTimeLimit = nettoParktimePrice[keys[k]]; + qCritical() << __func__ << ":" << __LINE__ << keys[k] << maxPriceForTimeLimit << cost; + // Calculator::GetInstance().setCostAtTimeLimit(nettoParktimePrice[keys[k]]); + if (cost > maxPriceForTimeLimit) { + cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit; + + CalcState cs(CalcState::State::OVERPAID); + return std::make_pair(cs, dt); + } + if (cost == maxPriceForTimeLimit) { + cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit; + + CalcState cs(CalcState::State::SUCCESS_MAXPRICE); + return std::make_pair(cs, dt); + } + } + + qCritical() << __func__ << ":" << __LINE__ << "DT" << dt.toString(Qt::ISODate); + return std::make_pair(CalcState(CalcState::State::SUCCESS), dt); + } } return std::make_pair(CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, CalcState::OUTSIDE_ALLOWED_PARKING_TIME), dt);