From 5cab0de9fb64f0d4e86ad75dee35890cadadd7a0 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 2 Sep 2024 17:14:20 +0200 Subject: [PATCH] Use free function getPaymentOptionIndex() to compute index of valid payment-option-section in tariff-file based on configured businessHours. --- library/src/calculator_functions.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 80731de..edff2ed 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -133,7 +133,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate); inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0)); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); - int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get()); + + int paymentOptionIndex = getPaymentOptionIndex(*cfg); + if (paymentOptionIndex == -1) { + paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate)); + } + + qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex; if (DBG_LEVEL >= DBG_DEBUG) { qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate); @@ -1420,7 +1426,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg, Q_UNUSED(payment_option); Q_UNUSED(nextDay); - int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get()); + int paymentOptionIndex = getPaymentOptionIndex(*cfg); + if (paymentOptionIndex == -1) { + paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get()); + } static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); if (paymentMethodId == PaymentMethod::Steps) { if (tariffIs24_7(cfg)) {