compute_price_for_parking_ticket():
Added handling for prepaid and carry-over.
This commit is contained in:
parent
cde490bab2
commit
9cb7d4aea6
@ -708,7 +708,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QDateTime &start_parking_time,
|
QDateTime &start_parking_time_,
|
||||||
int netto_parking_time,
|
int netto_parking_time,
|
||||||
QDateTime &end_parking_time,
|
QDateTime &end_parking_time,
|
||||||
struct price_t *price,
|
struct price_t *price,
|
||||||
@ -717,6 +717,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
{
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
|
|
||||||
|
QDateTime start_parking_time(start_parking_time_);
|
||||||
|
|
||||||
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||||
|
|
||||||
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
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
|
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
|
||||||
<< " minMin: " << minMin << endl
|
<< " minMin: " << minMin << endl
|
||||||
<< " maxMin: " << maxMin
|
<< " maxMin: " << maxMin
|
||||||
|
<< " prepaid: " << prepaid
|
||||||
<< " permitType: " << permitType.toString();
|
<< " permitType: " << permitType.toString();
|
||||||
|
|
||||||
|
|
||||||
if (netto_parking_time < 0) {
|
if (netto_parking_time < 0) {
|
||||||
calcState.setDesc(QString("end=%1, start=%2")
|
calcState.setDesc(QString("end=%1, start=%2")
|
||||||
.arg(end_parking_time.toString(Qt::ISODate),
|
.arg(end_parking_time.toString(Qt::ISODate),
|
||||||
@ -753,59 +755,65 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
|
|
||||||
double cost = -1;
|
double cost = -1;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
|
|
||||||
// qCritical() << __func__ << __LINE__;
|
|
||||||
|
|
||||||
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps ||
|
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps ||
|
||||||
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Degressive) {
|
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Degressive) {
|
||||||
// qCritical() << __func__ << __LINE__;
|
|
||||||
// hier muesste man unterscheiden: uebertrag oder nicht?
|
// hier muesste man unterscheiden: uebertrag oder nicht?
|
||||||
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
|
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
|
||||||
netto_parking_time, paymentOptionIndex);
|
netto_parking_time, paymentOptionIndex);
|
||||||
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
|
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
<< calcState.toString();
|
<< calcState.toString();
|
||||||
// qCritical() << __func__ << __LINE__;
|
|
||||||
return calcState;
|
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);
|
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
|
||||||
|
|
||||||
int weekDay = start_parking_time.date().dayOfWeek();
|
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 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;
|
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||||
|
|
||||||
qCritical() << "LINE" << __LINE__ << "carryStart" << carryOverStart.toString(Qt::ISODate);
|
qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||||
qCritical() << "LINE" << __LINE__ << "carryDur" << carryOverDuration;
|
qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
|
||||||
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
|
|
||||||
|
|
||||||
if (start_parking_time.time() > carryOverStart) {
|
// handle prepaid option
|
||||||
//int const backTime = carryOverStart.secsTo(start_parking_time.time()) / 60;
|
QDateTime effectiveStartTime(start_parking_time);
|
||||||
//qCritical() << "LINE" << __LINE__ << "backTime" << backTime;
|
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
||||||
//qCritical() << "LINE" << __LINE__ << "backTime + dur" << backTime + carryOverDuration;
|
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
|
||||||
start_parking_time.setTime(carryOverStart);
|
if (prepaidOption.has_value()) {
|
||||||
start_parking_time = start_parking_time.addSecs(carryOverDuration * 60);
|
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);
|
// handle carry over
|
||||||
|
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
|
||||||
qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time;
|
if (netto_parking_time > minutesUntilCarryOver) {
|
||||||
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
|
int const rest = netto_parking_time - minutesUntilCarryOver;
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
QDateTime s(effectiveStartTime);
|
||||||
<< "end_parking_time" << end_parking_time.toString(Qt::ISODate);
|
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 {
|
} else {
|
||||||
// qCritical() << __func__ << __LINE__;
|
|
||||||
cost = Calculator::GetInstance().GetCostFromDuration(
|
cost = Calculator::GetInstance().GetCostFromDuration(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
@ -822,8 +830,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
|
//qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
|
||||||
qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
|
//qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
|
||||||
|
|
||||||
price->brutto = price->vat = price->vat_percentage = 0;
|
price->brutto = price->vat = price->vat_percentage = 0;
|
||||||
price->units = cost;
|
price->units = cost;
|
||||||
@ -899,10 +907,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
bool const nextDay = false;
|
bool const nextDay = false;
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
||||||
qCritical() << "compute_duration_for_parking_ticket(2): ";
|
qCritical() << "compute_duration_for_parking_ticket(2): ";
|
||||||
qCritical() << " payment option index: " << paymentOptionIndex;
|
qCritical() << " payment option index: " << paymentOptionIndex;
|
||||||
qCritical() << " prepaid: " << prepaid;
|
qCritical() << " prepaid: " << prepaid;
|
||||||
qCritical() << " price: " << price;
|
qCritical() << " price: " << price;
|
||||||
|
}
|
||||||
|
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
|
Loading…
Reference in New Issue
Block a user