compute_price_for_parking_ticket():

Added handling for prepaid and carry-over.
This commit is contained in:
Gerhard Hoffmann 2024-08-01 16:04:57 +02:00
parent cde490bab2
commit 9cb7d4aea6

View File

@ -708,7 +708,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime &start_parking_time,
QDateTime &start_parking_time_,
int netto_parking_time,
QDateTime &end_parking_time,
struct price_t *price,
@ -717,6 +717,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
{
CalcState calcState;
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
@ -730,9 +732,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
<< " minMin: " << minMin << endl
<< " maxMin: " << maxMin
<< " prepaid: " << prepaid
<< " permitType: " << permitType.toString();
if (netto_parking_time < 0) {
calcState.setDesc(QString("end=%1, start=%2")
.arg(end_parking_time.toString(Qt::ISODate),
@ -753,59 +755,65 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
double cost = -1;
if (start_parking_time.isValid()) {
// qCritical() << __func__ << __LINE__;
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps ||
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Degressive) {
// qCritical() << __func__ << __LINE__;
// hier muesste man unterscheiden: uebertrag oder nicht?
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
netto_parking_time, paymentOptionIndex);
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< calcState.toString();
// qCritical() << __func__ << __LINE__;
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< calcState.toString();
return calcState;
}
// qCritical() << __func__ << __LINE__;
QList<int> lll = Calculator::GetInstance().GetTimeSteps(tariff);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
Q_UNUSED(tlist);
// netto_parking_time = compute_next_timestep(tariff, netto_parking_time, 1, permitType);
qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time << lll;
// qCritical() << __func__ << __LINE__;
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
int weekDay = start_parking_time.date().dayOfWeek();
int const pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).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__ << "carryOver-id" << pop_carry_over_option_id;
QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
//QTime const carryOverEnd = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end;
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
qCritical() << "LINE" << __LINE__ << "carryStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << "LINE" << __LINE__ << "carryDur" << carryOverDuration;
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
if (start_parking_time.time() > carryOverStart) {
//int const backTime = carryOverStart.secsTo(start_parking_time.time()) / 60;
//qCritical() << "LINE" << __LINE__ << "backTime" << backTime;
//qCritical() << "LINE" << __LINE__ << "backTime + dur" << backTime + carryOverDuration;
start_parking_time.setTime(carryOverStart);
start_parking_time = start_parking_time.addSecs(carryOverDuration * 60);
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value();
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end);
} else
if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.static_start);
}
}
end_parking_time = start_parking_time.addSecs(netto_parking_time*60);
qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time;
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "end_parking_time" << end_parking_time.toString(Qt::ISODate);
// handle carry over
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
if (netto_parking_time > minutesUntilCarryOver) {
int const rest = netto_parking_time - minutesUntilCarryOver;
QDateTime s(effectiveStartTime);
s = s.addSecs(minutesUntilCarryOver * 60);
s = s.addSecs(carryOverDuration * 60);
end_parking_time = s.addSecs(rest * 60);
} else {
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
}
} else {
// qCritical() << __func__ << __LINE__;
cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
@ -822,8 +830,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
}
// DEBUG
qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
//qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
//qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
price->brutto = price->vat = price->vat_percentage = 0;
price->units = cost;
@ -899,10 +907,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
bool const nextDay = false;
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(2): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " price: " << price;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "compute_duration_for_parking_ticket(2): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " price: " << price;
}
if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);