diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 610263c..6c8b119 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -989,7 +989,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( netto_parking_time, // minutes, netto false, prepaid); } - // qCritical() << __func__ << __LINE__; + double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price; if (cost < minCost) { calcState.setDesc(QString("line=%1 minCost=%2, cost=%3").arg(__LINE__).arg(minCost).arg(cost)); @@ -1145,6 +1145,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( QString endTime = p_endTime.first.c_str(); ticketEndTime = p_endTime.second; + qCritical() << __func__ << ":" << __LINE__ << endTime; + qCritical() << __func__ << ":" << __LINE__ << ticketEndTime.toString(Qt::ISODate); + if (endTime == CalcState::SUCCESS) { calcState.setDesc(QString("SUCCESS")); calcState.setStatus(endTime); @@ -1225,154 +1228,157 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT); } - if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) { - // handle carry over for ticket-end-time - qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate); + if (tariff->getPaymentOptions().pop_payment_method_id != PaymentMethod::Unified) { - 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; + if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) { + // handle carry over for ticket-end-time + qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate); - 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; - } + 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; - QTime carryOverStart; - QTime carryOverEnd; - int carryOverDuration = -1; + 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; + } - // 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; - } + QTime carryOverStart; + QTime carryOverEnd; + int carryOverDuration = -1; - 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; - } + // 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() && carryOverDuration != -1) { + 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; + } - // note: in such a case (direct coins) carry-over has been handled - // already in GetDurationFromCost() - netto_parking_time -= carryOverDuration; - qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time; + if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) { + + // note: in such a case (direct coins) carry-over has been handled + // already in GetDurationFromCost() + netto_parking_time -= carryOverDuration; + qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time; - // 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 - if (ticketEndTime.time() == carryOverStart) { - qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); - qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate); - ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex); - if (po.pop_apply_carry_over_to_ticket_endtime) { - ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60); - qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); - } - } else { - // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); - if (ticketEndTime.time() < carryOverEnd) { + if (ticketEndTime.time() > carryOverStart) { // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60); + } else + if (ticketEndTime.time() == carryOverStart) { + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate); + ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex); + if (po.pop_apply_carry_over_to_ticket_endtime) { + ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60); + qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate); + } + } 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"; } - } else { - qCritical() << __func__ << ":" << __LINE__ << "WARNING: wrong carry-over-settings"; } - } - qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate); + 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 parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time, - ticketEndTime, - paymentOptionIndex); - if (parkTimeLimitViolated) { - //QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit(); - //ticketEndTime.setTime(tlimit); + for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek())); + itr != rangeEnd; + ++itr) { + ATBWeekDay const &wd = itr->second; + 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); + QList const &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex); - QDateTime newTicketEndTime = ticketEndTime; + QDateTime newTicketEndTime = ticketEndTime; - qCritical() << __func__ << ":" << __LINE__ << "PARK-TIME VIOLATED"; + qCritical() << __func__ << ":" << __LINE__ << "PARK-TIME VIOLATED"; - for (int i = stepList.size() - 1; i > 0; --i) { - // qCritical() << __func__ << ":" << __LINE__ << "step[" << i << "]" << stepList.at(i); + 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); + 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); + // qCritical() << __func__ << ":" << __LINE__ << "new-ticket-end-time" << newTicketEndTime.toString(Qt::ISODate); - parkTimeLimitViolated - = wd.getTariffCarryOverSettings() - .parkingTimeLimitExceeded(start_parking_time, newTicketEndTime, paymentOptionIndex); + parkTimeLimitViolated + = wd.getTariffCarryOverSettings() + .parkingTimeLimitExceeded(start_parking_time, newTicketEndTime, paymentOptionIndex); - if (!parkTimeLimitViolated) { + if (!parkTimeLimitViolated) { - qCritical() << __func__ << ":" << __LINE__ - << "PARK-TIME NOT VIOLATED FOR" << newTicketEndTime.toString(Qt::ISODate); + qCritical() << __func__ << ":" << __LINE__ + << "PARK-TIME NOT VIOLATED FOR" << newTicketEndTime.toString(Qt::ISODate); - int duration = stepList.at(i-1); + int duration = stepList.at(i-1); - // qCritical() << __func__ << ":" << __LINE__ << "duration" << duration; + // 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) { + 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; + // 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; + 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; + // 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; + // 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; + 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 + // 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(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); + 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); + } } }