diff --git a/library/include/mobilisis/configuration.h b/library/include/mobilisis/configuration.h index cf9a8a8..aa5cef3 100644 --- a/library/include/mobilisis/configuration.h +++ b/library/include/mobilisis/configuration.h @@ -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::GenericMemberIteratorgetPaymentOptionIndex(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); } diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 6920a90..aebf3f2 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -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()); } diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index c2d7c0b..9c07540 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -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)) {