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);