compute_duration_for_parking_ticket():

Fix: handle carry-over for coin-insertion.
This commit is contained in:
Gerhard Hoffmann 2024-08-21 15:40:55 +02:00
parent 7a6360f392
commit f8805e9e78

View File

@ -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<ATBPeriodYear> 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<int, ATBCarryOver>;
std::multimap<int, ATBCarryOver>::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);