Use free function getPaymentOptionIndex() in serveral places to compute valid

index of a payment-option-section within tariff file. If this is not possible,
then try the already available functionality.
This commit is contained in:
Gerhard Hoffmann 2024-09-02 17:09:26 +02:00
parent 349e9d8b06
commit 52ebbf7bc9

View File

@ -36,7 +36,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) {
int minTime = 0;
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
@ -69,7 +72,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
int maxTime = 0;
switch(permitType) {
@ -94,7 +100,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1;
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
@ -321,7 +330,9 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
@ -474,7 +485,11 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// return currentTimeMinutes;
//}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
@ -654,7 +669,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState calcState;
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
}
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
@ -721,7 +739,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
@ -873,7 +894,11 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) { // see tariff03.json for 502: 2 means no prepaid-option
prepaid = false;
@ -913,7 +938,14 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
CalcState calcState;
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
qCritical() << __func__ << ":" << __LINE__ << " payment option index: " << paymentOptionIndex;
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) {