diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 2d34c7b..0041d08 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -43,13 +43,24 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg, int paymentOptionIndex) { int minTime = 0; + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + Configuration *c = tariffs[permitType].get(); + if (c && c != cfg) { + cfg = c; + } + } + paymentOptionIndex = getPaymentOptionIndex(*cfg); if (paymentOptionIndex == -1) { paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); } qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex; - qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString(); + qCritical() << __func__ << __LINE__ << "permit" << (int)permitType << PermitType(permitType).toString(); + qCritical() << __func__ << __LINE__ << "min_time" << (int)permitType << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time; + qCritical() << __func__ << __LINE__ << "min_price" << (int)permitType << cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; switch(permitType) { case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) @@ -79,6 +90,15 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg, PERMIT_TYPE permitType, int paymentOptionIndex) { + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + Configuration *c = tariffs[permitType].get(); + if (c && c != cfg) { + cfg = c; + } + } + paymentOptionIndex = getPaymentOptionIndex(*cfg); if (paymentOptionIndex == -1) { paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); @@ -109,6 +129,15 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, QDateTime const &start) { int minPrice = -1; + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + Configuration *c = tariffs[permitType].get(); + if (c && c != cfg) { + cfg = c; + } + } + if ((paymentOptionIndex = getPaymentOptionIndex(*cfg, start)) == -1) { paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); } @@ -173,6 +202,14 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, QDateTime const &start, QDateTime *productStart, QDateTime *productEnd) { + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + Configuration *c = tariffs[permitType].get(); + if (c && c != cfg) { + cfg = c; + } + } switch(permitType) { case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) @@ -336,6 +373,16 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType, int paymentOptionIndex) { int maxPrice = -1; + + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + Configuration *c = tariffs[permitType].get(); + if (c && c != cfg) { + cfg = c; + } + } + static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) { @@ -724,6 +771,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( start = start.toLocalTime().addSecs(start_parking_time * 60); QDateTime end(start); + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } + } + int paymentOptionIndex = getPaymentOptionIndex(*tariff, start); if (paymentOptionIndex == -1) { paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get()); @@ -799,6 +855,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( QDateTime start_parking_time(start_parking_time_); + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } + } + int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time); if (paymentOptionIndex == -1) { paymentOptionIndex = tariff->getPaymentOptionIndex(permitType); @@ -1077,6 +1142,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( QString &duration, PermitType permitType) { + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } + } + tariff->getPaymentOptions(0).pop_max_price = tariff->getPaymentOptions(0).pop_max_price_save; @@ -1135,8 +1209,13 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( QDateTime &ticketEndTime, PermitType permitType) { + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. if (tariffs.count(permitType) > 0) { - tariff = tariffs[permitType].get(); + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } } tariff->getPaymentOptions(0).pop_max_price @@ -1474,8 +1553,17 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff, QDateTime const &start_parking_time, QDateTime &ticketEndTime, - PermitType /* PermitType */) + PermitType permitType) { + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } + } + tariff->getPaymentOptions(0).pop_max_price = tariff->getPaymentOptions(0).pop_max_price_save; @@ -1511,6 +1599,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket( PERMIT_TYPE permitType, struct price_t *price) {// return value + // tariffs are only set if there is a Includes-section in the tariff-file, + // which means the code below will be executed only in such a case. + if (tariffs.count(permitType) > 0) { + parking_tariff_t *t = tariffs[permitType].get(); + if (t && t != tariff) { + tariff = t; + } + } + tariff->getPaymentOptions(0).pop_max_price = tariff->getPaymentOptions(0).pop_max_price_save;