From f8805e9e78ffc6d8e647e52dee7c18ec53f4832f Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 21 Aug 2024 15:40:55 +0200 Subject: [PATCH] compute_duration_for_parking_ticket(): Fix: handle carry-over for coin-insertion. --- library/src/calculate_price.cpp | 54 +++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index b54fabd..a1e04bf 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -1020,15 +1020,63 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT); } + // handle carry over for ticket-end-time + qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate); + + 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; + + 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; + } + + QTime carryOverStart; + QTime carryOverEnd; + int carryOverDuration = -1; + + // using TariffCarryOverType = std::multimap; + std::multimap::const_iterator it; + if ((it = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)) != + tariff->TariffCarryOverOptions.cend()) { + carryOverStart = it->second.carryover[weekDay].static_start; + carryOverEnd = it->second.carryover[weekDay].static_end; + carryOverDuration = it->second.carryover[weekDay].duration; + } + + if (carryOverStart.isValid() && carryOverEnd.isValid()) { + qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate); + qCritical() << __func__ << __LINE__ << "carryOverEnd" << carryOverEnd.toString(Qt::ISODate); + qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration; + } + + if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) { + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + if (ticketEndTime.time() > carryOverStart) { + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60); + } else { + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + if (ticketEndTime.time() < carryOverEnd) { + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60); + } + } + } else { + qCritical() << __func__ << __LINE__ << "WARNING: wrong carry-over-settings"; + } + if (ticketEndTime.time().hour() == 0 && ticketEndTime.time().minute() == 0) { ticketEndTime = ticketEndTime.addDays(-1); ticketEndTime.setTime(QTime(23, 59, 0)); } // DEBUG - qCritical() << "compute_duration_for_parking_ticket(): "; - qCritical() << " endTime: " << endTime; - qCritical() << " ticketEndTime: " << ticketEndTime; + qCritical() << __func__ << __LINE__ << " endTime:" << endTime; + qCritical() << __func__ << __LINE__ << "ticketEndTime:" << ticketEndTime; } } else { return calcState.set(CalcState::State::INVALID_START_DATE);