Extend compute_product_price() for use of PERMIT_TYPE::DAY_TICKET.

First time used for Neuhauder-Pernegg-an-der-Mur.
This commit is contained in:
Gerhard Hoffmann 2024-04-16 12:10:34 +02:00
parent aa15d1c126
commit b70094abb5

View File

@ -82,7 +82,11 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
return minPrice; return minPrice;
} }
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
PERMIT_TYPE permitType,
QDateTime const &start,
QDateTime *productStart,
QDateTime *productEnd) {
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)
@ -118,6 +122,40 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
} }
} }
} break; } break;
case PERMIT_TYPE::INVALID:
// [[fallthrough]];
case PERMIT_TYPE::DAY_TICKET: {
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
if (products) {
QVector<ATBTariffProduct> product = products.value();
int product_price = 0;
if (productStart && productEnd) {
*productStart = start;
*productEnd = start;
if (product.size() > 0) {
productStart->setTime(product[0].getTimeStart());
productEnd->setTime(product[0].getTimeEnd());
}
}
for (QVector<ATBTariffProduct>::size_type i=0; i<product.size(); ++i) {
ATBTariffProduct const &p = product[i];
QTime const &startTime = p.getTimeStart();
QTime const &endTime = p.getTimeEnd();
if (start.time() >= startTime && start.time() < endTime) {
product_price = p.getProductPrice();
if (productStart && productEnd) {
productStart->setTime(startTime);
productEnd->setTime(endTime);
}
}
}
return product_price;
}
} break;
default: default:
break; break;
} }