From b70094abb507bba4ae01ba50cc7053784e783451 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 16 Apr 2024 12:10:34 +0200 Subject: [PATCH] Extend compute_product_price() for use of PERMIT_TYPE::DAY_TICKET. First time used for Neuhauder-Pernegg-an-der-Mur. --- library/src/calculate_price.cpp | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 5845a27..bb8dd99 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -82,7 +82,11 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, 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) { 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; + case PERMIT_TYPE::INVALID: + // [[fallthrough]]; + case PERMIT_TYPE::DAY_TICKET: { + std::optional> products = cfg->getTariffProductForProductId(permitType); + if (products) { + QVector 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::size_type i=0; i= startTime && start.time() < endTime) { + product_price = p.getProductPrice(); + if (productStart && productEnd) { + productStart->setTime(startTime); + productEnd->setTime(endTime); + } + } + } + + return product_price; + } + } break; default: break; }