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.
This commit is contained in:
Gerhard Hoffmann 2024-09-17 17:05:23 +02:00
parent d95275a72d
commit 77e1414c13

View File

@ -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); qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek())); for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek()));
itr != rangeEnd; itr != rangeEnd;
++itr) { ++itr) {
ATBWeekDay const &wd = itr->second; ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time, bool parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
ticketEndTime, ticketEndTime,
paymentOptionIndex); paymentOptionIndex);
if (parkTimeLimitViolated) { if (parkTimeLimitViolated) {
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit(); //QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
//ticketEndTime.setTime(tlimit); //ticketEndTime.setTime(tlimit);
QList<int> 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<int, ATBDuration>::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__) calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(ticketEndTime.time().toString(Qt::ISODate))); .arg(ticketEndTime.time().toString(Qt::ISODate)));
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME); return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);