get_minimal_parkingtime()

get_maximal_parkingtime()
compute_product_price()
get_maximal_parkingprice()
compute_price_for_parking_ticket()
compute_duration_for_parking_ticket()
compute_duration_for_daily_ticket()
compute_price_for_daily_ticket():

In case main-tariff file contains an Includes-section, change to the
included tariff based on product-id (permit-type).
This commit is contained in:
Gerhard Hoffmann 2025-05-08 11:15:23 +02:00
parent 35294e99f0
commit b4818a3918

View File

@ -43,13 +43,24 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) { int paymentOptionIndex) {
int minTime = 0; 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); paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) { if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
} }
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex; 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) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) 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, PERMIT_TYPE permitType,
int paymentOptionIndex) { 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); paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) { if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
@ -109,6 +129,15 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
QDateTime const &start) { QDateTime const &start) {
int minPrice = -1; 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) { if ((paymentOptionIndex = getPaymentOptionIndex(*cfg, start)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
} }
@ -173,6 +202,14 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
QDateTime const &start, QDateTime const &start,
QDateTime *productStart, QDateTime *productStart,
QDateTime *productEnd) { 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) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) 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, PERMIT_TYPE permitType,
int paymentOptionIndex) { int paymentOptionIndex) {
int maxPrice = -1; 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); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) { 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); start = start.toLocalTime().addSecs(start_parking_time * 60);
QDateTime end(start); 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); int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
if (paymentOptionIndex == -1) { if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get()); 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_); 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); int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
if (paymentOptionIndex == -1) { if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType); paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
@ -1077,6 +1142,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QString &duration, QString &duration,
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
= tariff->getPaymentOptions(0).pop_max_price_save; = tariff->getPaymentOptions(0).pop_max_price_save;
@ -1135,8 +1209,13 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QDateTime &ticketEndTime, 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) { 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 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, CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
QDateTime const &start_parking_time, QDateTime const &start_parking_time,
QDateTime &ticketEndTime, 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
= tariff->getPaymentOptions(0).pop_max_price_save; = tariff->getPaymentOptions(0).pop_max_price_save;
@ -1511,6 +1599,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
PERMIT_TYPE permitType, PERMIT_TYPE permitType,
struct price_t *price) {// return value 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
= tariff->getPaymentOptions(0).pop_max_price_save; = tariff->getPaymentOptions(0).pop_max_price_save;