get_minimal_parking_price(): compute this price dynamically according to settings

in the tariff-file. Introduced for Fuchs (500) for Valser Alm (Location: Fane)
This commit is contained in:
Gerhard Hoffmann 2024-07-30 15:29:47 +02:00
parent 7233bc55c2
commit 9a6b2b195d

View File

@ -94,6 +94,40 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int minPrice = -1;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
if (payment_method_id == PaymentMethod::Degressive) {
// Degressive: new for Fuchs Technik (500), ValserAlm (Fane):
// the minimal price has to be calculated, in cannot be hard coded into
// the tariff file.
// The working times have a reference into the payment rates. Two special
// entries (with the numbers 1000/1001) point to the respective prices.
switch(permitType) {
default: {
// find the correct work time range
int weekDay = start.date().dayOfWeek();
std::optional<QVector<ATBWeekDaysWorktime>> const &wd = cfg->getAllWeekDayWorkTimes();
if (wd.has_value()) {
QVector<ATBWeekDaysWorktime> const &vec = wd.value();
for (int i = 0; i < vec.size(); ++i) {
ATBWeekDaysWorktime const &wt = vec[i];
if (wt.pwd_period_day_in_week_id == weekDay) {
if (start.time() >= QTime::fromString(QString::fromStdString(wt.pwd_time_from), Qt::ISODate)
&& start.time() <= QTime::fromString(QString::fromStdString(wt.pwd_time_to), Qt::ISODate)) {
// found worktime range
int pop_id = wt.pwd_pop_id; // 1000 or 1001
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
i = vec.size(); // to leave outer loop
minPrice = itr->second.pra_price; // this is now the minimal price
break;
}
}
}
}
}
}
}
} else {
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
@ -110,6 +144,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
default:
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
}
}
return minPrice;
}