From 77e1414c1350b66e3fed711530a14c368c1e79ec Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 17 Sep 2024 17:05:23 +0200 Subject: [PATCH] compute_duration_for_parking_ticket(): Recompute pop_max_price using netto-parking-time. Search Duration for the time-step with time-step == netto-parking-time, then search for the corresponding price in PaymentRate. The result is the new pop_max_price. --- library/src/calculate_price.cpp | 76 ++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index f38bb21..344ffc8 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -1271,23 +1271,85 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( } } - - ticketEndTime.setTime(QTime(ticketEndTime.time().hour(), - ticketEndTime.time().minute(), 0)); - qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate); for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek())); itr != rangeEnd; ++itr) { ATBWeekDay const &wd = itr->second; - bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time, - ticketEndTime, - paymentOptionIndex); + bool parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time, + ticketEndTime, + paymentOptionIndex); if (parkTimeLimitViolated) { //QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit(); //ticketEndTime.setTime(tlimit); + QList const &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex); + + QDateTime newTicketEndTime = ticketEndTime; + + qCritical() << __func__ << ":" << __LINE__ << "PARK-TIME VIOLATED"; + + for (int i = stepList.size() - 1; i > 0; --i) { + // qCritical() << __func__ << ":" << __LINE__ << "step[" << i << "]" << stepList.at(i); + + if (netto_parking_time > 0 && stepList.at(i) <= netto_parking_time) { + int const diff = stepList.at(i-1) - stepList.at(i); + newTicketEndTime = newTicketEndTime.addSecs(diff * 60); + + // qCritical() << __func__ << ":" << __LINE__ << "new-ticket-end-time" << newTicketEndTime.toString(Qt::ISODate); + + parkTimeLimitViolated + = wd.getTariffCarryOverSettings() + .parkingTimeLimitExceeded(start_parking_time, newTicketEndTime, paymentOptionIndex); + + if (!parkTimeLimitViolated) { + + qCritical() << __func__ << ":" << __LINE__ + << "PARK-TIME NOT VIOLATED FOR" << newTicketEndTime.toString(Qt::ISODate); + + int duration = stepList.at(i-1); + + // qCritical() << __func__ << ":" << __LINE__ << "duration" << duration; + + std::multimap::const_iterator it; + for (it = tariff->Duration.cbegin(); + it != tariff->Duration.cend(); + ++it) { + if (duration == it->second.pun_duration) { + + // qCritical() << __func__ << ":" << __LINE__ << "duration" << duration; + + ATBPaymentOption &po = tariff->getPaymentOptions(paymentOptionIndex); + int const pop_id = po.pop_id; + for (auto[itr, rangeEnd] = tariff->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { + int const durationId = itr->second.pra_payment_unit_id; + + // qCritical() << __func__ << ":" << __LINE__ << "durationId" << durationId << it->second.pun_id; + + // note: for this to work, Duration and PaymentRate must have + // exactly the same structure + if (durationId == it->second.pun_id) { + int const pra_price = itr->second.pra_price; + po.pop_max_price = pra_price; + + qCritical() << __func__ << ":" << __LINE__ << "new max-price" << po.pop_max_price; + + // note: ABOVE_MAX_PARKING_TIME would also be possible + // but here max-parking-time is dynamic. And for + // this dynamic value, opverpaid is actually correct + + calcState.setDesc(CalcState::OVERPAID); + calcState.setStatus(CalcState::OVERPAID); + return calcState; + } + } + } + } + } + } + } + calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__) .arg(ticketEndTime.time().toString(Qt::ISODate))); return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);