From 68a1c24861f29f04a4eb4356978177abd0c15a38 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 2 Sep 2024 17:03:37 +0200 Subject: [PATCH] Add free function getPaymentOptionIndex(): Compute payment option index base on current start-date-time and businesshour-setiing in tariff-file. Returns -1 to indicate error. --- library/src/configuration.cpp | 64 ++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index d43d9e8..ccbd758 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -1508,7 +1508,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const { std::optional> paymentOptions = getPaymentOptionsForAllKeys(); if (paymentOptions) { - QVector const vec = paymentOptions.value(); PermitType const p(permitType); @@ -1522,6 +1521,69 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const { return 0; } +int getPaymentOptionIndex(Configuration const &cfg) { + + + int const numOptions = cfg.getAllPaymentOptions().size(); + + for (int opt=0; opt < numOptions; ++opt) { + uint64_t const pop_business_hours = cfg.getPaymentOptions(opt).pop_business_hours; + + if (pop_business_hours == 0) { // 0 == 24/7 + return opt; + } + + QDateTime const dt = QDateTime::currentDateTime(); + int const dayOfWeek = dt.date().dayOfWeek(); + + switch (dayOfWeek) { + case (int)Qt::Monday: { + if (pop_business_hours & BusinessHours::MON) { + return opt; + } + } break; + case (int)Qt::Tuesday: { + if (pop_business_hours & BusinessHours::TUE) { + return opt; + } + } break; + case (int)Qt::Wednesday: { + if (pop_business_hours & BusinessHours::WED) { + return opt; + } + } break; + case (int)Qt::Thursday: { + if (pop_business_hours & BusinessHours::THU) { + return opt; + } + } break; + case (int)Qt::Friday: { + if (pop_business_hours & BusinessHours::FRI) { + return opt; + } + } break; + case (int)Qt::Saturday: { + if (pop_business_hours & BusinessHours::SAT) { + return opt; + } + } break; + case (int)Qt::Sunday: { + if (pop_business_hours & BusinessHours::SUN) { + return opt; + } + } break; + } + + if (isHoliday(cfg, dt)) { + if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) { + return opt; + } + } + } + + return -1; +} + std::optional> Configuration::getTariffProductForProductId(PermitType permitType) const { QString permitTypeName(permitType);