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);