From 7a6360f3928cbc4beb21de540cfa5fdadec3d299 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 21 Aug 2024 15:39:44 +0200 Subject: [PATCH] compute_duration_for_parking_ticket(): Fix: handle prepaid-setting for coin-insertion. --- library/src/calculate_price.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 935b872..b54fabd 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -929,6 +929,25 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( } if (start_parking_time.isValid()) { + + // handle prepaid option + QDateTime effectiveStartTime(start_parking_time); + int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id; + std::optional prepaidOption = tariff->getPrepaidType(prepaid_option_id); + if (prepaidOption.has_value()) { + ATBPrepaid const &p = prepaidOption.value(); + if (p.never) { + qCritical() << __func__ << __LINE__ << "prepaid: no"; + } else { + if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00 + effectiveStartTime.setTime(p.static_end); + } else + if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00 + effectiveStartTime.setTime(p.static_start); + } + } + } + QString cs = start_parking_time.toString(Qt::ISODate); QString endTime = Calculator::GetInstance().GetDurationFromCost( tariff,