From 5dbd3645c62e20c426f19d4f3820f3dc3030540b Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 11 Sep 2024 11:44:09 +0200 Subject: [PATCH] compute_price_for_parking_ticket(): Fetch prepaid-option-id (possibly recalculating it depending on year-period), and fetch associated prepaid-options. --- library/src/calculate_price.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index cb1da5b..93f0814 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -805,20 +805,22 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( int weekDay = start_parking_time.date().dayOfWeek(); int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id; - qCritical() << __func__ << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id; + int pop_prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id; std::optional yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time); if (yperiod.has_value()) { ATBPeriodYear const &period = yperiod.value(); pop_carry_over_option_id = period.pye_id; - qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id; + pop_prepaid_option_id = period.pye_id; + qCritical() << __func__ << ":" << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id; + qCritical() << __func__ << ":" << __LINE__ << " re-computed prepaid-id" << pop_prepaid_option_id; } - QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start; - int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration; + QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start; + int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration; - qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate); - qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration; + qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate); + qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration; // handle prepaid option QDateTime effectiveStartTime(start_parking_time); @@ -827,13 +829,17 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( if (prepaidOption.has_value()) { ATBPrepaid const &p = prepaidOption.value(); if (p.never) { - qCritical() << __func__ << __LINE__ << "prepaid: no"; + 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); + qCritical() << __func__ << ":" << __LINE__ << " prepaidStart" << p.prepaid[weekDay].static_start.toString(Qt::ISODate); + qCritical() << __func__ << ":" << __LINE__ << " prepaidEnd" << p.prepaid[weekDay].static_end.toString(Qt::ISODate); + qCritical() << __func__ << ":" << __LINE__ << "prepaid duration" << p.prepaid[weekDay].duration; + + if (start_parking_time.time() < p.prepaid[weekDay].static_end) { // static_end: e.g. 08:00:00 + effectiveStartTime.setTime(p.prepaid[weekDay].static_end); } else - if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00 - effectiveStartTime.setTime(p.static_start); + if (start_parking_time.time() > p.prepaid[weekDay].static_start) { // static_start: e.g. 22:00:00 + effectiveStartTime.setTime(p.prepaid[weekDay].static_start); } } }