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.
This commit is contained in:
Gerhard Hoffmann 2024-09-02 17:03:37 +02:00
parent c946c106d1
commit 68a1c24861

View File

@ -1508,7 +1508,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
std::optional<QVector<ATBPaymentOption>> paymentOptions = getPaymentOptionsForAllKeys();
if (paymentOptions) {
QVector<ATBPaymentOption> 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<QVector<ATBTariffProduct>>
Configuration::getTariffProductForProductId(PermitType permitType) const {
QString permitTypeName(permitType);