getPaymentOptionIndex(): add start-time parameter

This commit is contained in:
Gerhard Hoffmann 2024-09-06 12:05:41 +02:00
parent 275c3ec869
commit 7a53a68850
4 changed files with 23 additions and 15 deletions

View File

@ -130,7 +130,7 @@ private:
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t);
bool isHoliday(Configuration const &cfg, QDateTime const &t);
int getPaymentOptionIndex(Configuration const &cfg);
int getPaymentOptionIndex(Configuration const &cfg, QDateTime const& dt = QDateTime::currentDateTime());
ATBWeekDay parseWeekDay(Configuration &cfg,
rapidjson::GenericMemberIterator<false,

View File

@ -101,7 +101,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
QDateTime const &start) {
int minPrice = -1;
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg, start)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
@ -669,7 +669,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState calcState;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
QDate const d(1970, 1, 1);
QTime const t(0, 0, 0);
QDateTime start(d, t, Qt::UTC);
start = start.toLocalTime().addSecs(start_parking_time * 60);
QDateTime end(start);
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
}
@ -700,11 +706,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
return calcState.set(CalcState::State::SUCCESS);
}
QDate const d(1970, 1, 1);
QTime const t(0, 0, 0);
QDateTime start(d, t, Qt::UTC);
start = start.toLocalTime().addSecs(start_parking_time * 60);
QDateTime end(start);
//QDate const d(1970, 1, 1);
//QTime const t(0, 0, 0);
//QDateTime start(d, t, Qt::UTC);
//start = start.toLocalTime().addSecs(start_parking_time * 60);
//QDateTime end(start);
if (start.isValid()) {
double cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
@ -739,7 +745,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
@ -914,7 +920,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
qCritical() << " payment option index: " << paymentOptionIndex;
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
@ -959,7 +966,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
bool prepaid = true;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
qCritical() << __func__ << ":" << __LINE__ << "payment option index: " << paymentOptionIndex;
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}

View File

@ -134,7 +134,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate));
}
@ -1426,7 +1426,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
Q_UNUSED(payment_option);
Q_UNUSED(nextDay);
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
int paymentOptionIndex = getPaymentOptionIndex(*cfg, start_datetime);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
}

View File

@ -1533,7 +1533,7 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
return 0;
}
int getPaymentOptionIndex(Configuration const &cfg) {
int getPaymentOptionIndex(Configuration const &cfg, QDateTime const &dt) {
int const numOptions = cfg.getAllPaymentOptions().size();
@ -1544,7 +1544,7 @@ int getPaymentOptionIndex(Configuration const &cfg) {
return opt;
}
QDateTime const dt = QDateTime::currentDateTime();
// QDateTime const dt = QDateTime::currentDateTime();
int const dayOfWeek = dt.date().dayOfWeek();
if (isHoliday(cfg, dt)) {