getCurrentPaymentOptionIndex(): start implementation.

getPaymentOptions(): use new parameter paymentOptionIndex.
This commit is contained in:
Gerhard Hoffmann 2024-04-12 14:31:02 +02:00
parent 7e3347b043
commit b0c4ad0e2e

View File

@ -3,6 +3,7 @@
#include "time_range_header.h"
#include "tariff_timestep_config.h"
#include "tariff_permit_type.h"
#include "tariff_business_hours.h"
#include <QString>
#include <QDebug>
@ -542,15 +543,76 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
}
}
int Configuration::getCurrentPaymentOptionIndex(QDateTime const &dt) const {
int const numOptions = getAllPaymentOptions().size();
ATBPaymentOption const &Configuration::getPaymentOptions() const {
Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions.at(0);
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
uint64_t p = 0;
switch (dt.date().dayOfWeek()) {
case (int)Qt::Monday: {
p = BusinessHours::MON;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Tuesday: {
p = BusinessHours::TUE;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Wednesday: {
p = BusinessHours::WED;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Thursday: {
p = BusinessHours::THU;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Friday: {
p = BusinessHours::FRI;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Saturday: {
p = BusinessHours::SAT;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Sunday: {
p = BusinessHours::SUN;
if (isHoliday(dt)) {
p |= BusinessHours::OFFICIAL_HOLIDAY;
}
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
}
}
return -1;
}
ATBPaymentOption &Configuration::getPaymentOptions() {
bool Configuration::isHoliday(QDateTime const &dt) const {
return false;
}
ATBPaymentOption const &Configuration::getPaymentOptions(int paymentOptionsIndex) const {
Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions[0];
return this->currentPaymentOptions.at(paymentOptionsIndex);
}
ATBPaymentOption &Configuration::getPaymentOptions(int paymentOptionsIndex) {
Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions[paymentOptionsIndex];
}
QVector<ATBPaymentOption> const &Configuration::getAllPaymentOptions() const {