2023-11-24 13:52:49 +01:00
|
|
|
#include "calculator_functions.h"
|
|
|
|
#include "payment_option.h"
|
|
|
|
#include "utilities.h"
|
|
|
|
#include "tariff_log.h"
|
|
|
|
#include "tariff_time_range.h"
|
2023-11-27 16:18:06 +01:00
|
|
|
#include "ticket.h"
|
2024-04-19 13:31:01 +02:00
|
|
|
#include "tariff_global_defines.h"
|
2024-07-19 14:10:07 +02:00
|
|
|
#include "tariff_prepaid.h"
|
2024-09-27 13:57:30 +02:00
|
|
|
#include "tariff_out_of_service.h"
|
|
|
|
#include "tariff_service.h"
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
2024-07-25 09:49:16 +02:00
|
|
|
#include <optional>
|
2023-11-24 13:52:49 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QScopedArrayPointer>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
double total_duration_min = 0.0f;
|
|
|
|
double total_cost = 0.0f;
|
|
|
|
bool overtime = false;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
|
|
|
if(!clock || !result) return NULL;
|
|
|
|
memcpy(result,localtime(clock),sizeof(*result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over)
|
|
|
|
{
|
|
|
|
if(!start_datetime.isValid()) {
|
|
|
|
return QDateTime();
|
|
|
|
}
|
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
// qCritical() << __func__ << start_datetime.toString(Qt::ISODate);
|
|
|
|
|
2023-11-24 13:52:49 +01:00
|
|
|
double day_price = 0.0f;
|
|
|
|
int current_special_day_id = -1;
|
|
|
|
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toString(Qt::ISODate).toStdString().c_str(), ¤t_special_day_id, &day_price);
|
|
|
|
|
|
|
|
QDateTime inputDateTime = start_datetime;
|
|
|
|
QTime worktime_from;
|
|
|
|
QTime worktime_to;
|
|
|
|
|
|
|
|
int daily_card_price = cfg->PaymentOption.find(payment_option)->second.pop_daily_card_price;
|
|
|
|
if(daily_card_price <= 0) {
|
2023-12-12 11:34:04 +01:00
|
|
|
qCritical() << "Calculator::GetDailyTicketDuration(): Daily ticket price zero or less";
|
2023-11-24 13:52:49 +01:00
|
|
|
return QDateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_special_day)
|
|
|
|
{
|
|
|
|
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str(), Qt::ISODate);
|
|
|
|
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str(),Qt::ISODate);
|
|
|
|
|
|
|
|
if(inputDateTime.time() < worktime_from) inputDateTime.setTime(worktime_from);
|
|
|
|
if(carry_over) inputDateTime.setTime(worktime_from);
|
|
|
|
|
|
|
|
if(inputDateTime.time() >= worktime_to)
|
|
|
|
{
|
|
|
|
// Go to next day if outside worktime
|
|
|
|
inputDateTime = inputDateTime.addSecs(86400);
|
|
|
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(day_price <=0)
|
|
|
|
{
|
|
|
|
// Go to next day if special day price is 0
|
|
|
|
inputDateTime = inputDateTime.addSecs(86400);
|
|
|
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
|
|
|
inputDateTime = inputDateTime.addSecs(diff);
|
|
|
|
|
|
|
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
|
|
|
return inputDateTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get day of week
|
2023-12-12 11:34:04 +01:00
|
|
|
int const weekdayId = inputDateTime.date().dayOfWeek();
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
// If no working day found, skip it (recursively call method again)
|
2023-12-12 11:34:04 +01:00
|
|
|
size_t found = cfg->WeekDaysWorktime.count(weekdayId);
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
// When no workday found, go to next available day
|
|
|
|
if(found <=0)
|
|
|
|
{
|
|
|
|
inputDateTime = inputDateTime.addSecs(86400);
|
|
|
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str(),Qt::ISODate);
|
|
|
|
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str(),Qt::ISODate);
|
|
|
|
if(inputDateTime.time() < worktime_from)
|
|
|
|
inputDateTime.setTime(worktime_from);
|
|
|
|
|
|
|
|
if(carry_over)
|
|
|
|
inputDateTime.setTime(worktime_from);
|
|
|
|
|
|
|
|
if(inputDateTime.time() >= worktime_to)
|
|
|
|
{
|
|
|
|
// Go to next day if outside worktime
|
|
|
|
inputDateTime = inputDateTime.addSecs(86400);
|
|
|
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
|
|
|
inputDateTime = inputDateTime.addSecs(diff);
|
|
|
|
|
2024-07-21 20:58:12 +02:00
|
|
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
2023-11-24 13:52:49 +01:00
|
|
|
return inputDateTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDateTime();
|
|
|
|
}
|
2024-09-27 14:04:39 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief getPrepaid
|
|
|
|
/// \param cfg
|
|
|
|
/// \param dt
|
|
|
|
/// \return
|
|
|
|
///
|
|
|
|
|
|
|
|
std::optional<ATBTariffPrepaid> getPrepaid(Configuration const *cfg, QDateTime const &dt) {
|
|
|
|
std::optional<ATBTariffPrepaid> value = std::nullopt;
|
|
|
|
|
|
|
|
int weekDay = dt.date().dayOfWeek();
|
|
|
|
ATBTime inputTime(dt.time());
|
|
|
|
auto const &prepaidRange = cfg->TariffPrepaids.equal_range(weekDay);
|
|
|
|
for (auto i = prepaidRange.first; i != prepaidRange.second; ++i) {
|
|
|
|
ATBTariffPrepaid const &prepaid = i->second;
|
|
|
|
TimeRange const &prepaidTimeRange = prepaid.m_range;
|
|
|
|
if (inputTime >= prepaidTimeRange.m_start && inputTime < prepaidTimeRange.m_end) {
|
|
|
|
value = value.value_or(i->second);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief getCarryOver
|
|
|
|
/// \param cfg
|
|
|
|
/// \param dt
|
|
|
|
/// \return
|
|
|
|
///
|
|
|
|
std::optional<ATBTariffCarryOver> getCarryOver(Configuration const *cfg, QDateTime const &dt) {
|
|
|
|
std::optional<ATBTariffCarryOver> value = std::nullopt;
|
|
|
|
|
|
|
|
int weekDay = dt.date().dayOfWeek();
|
|
|
|
ATBTime inputTime(dt.time());
|
|
|
|
auto const &carryOverRange = cfg->TariffCarryOvers.equal_range(weekDay);
|
|
|
|
for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) {
|
|
|
|
ATBTariffCarryOver const &carryOver = i->second;
|
|
|
|
TimeRange const &carryOverTimeRange = carryOver.m_range;
|
|
|
|
if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) {
|
|
|
|
value = value.value_or(i->second);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief getService
|
|
|
|
/// \param cfg
|
|
|
|
/// \param dt
|
|
|
|
/// \return
|
|
|
|
///
|
|
|
|
|
|
|
|
std::optional<ATBTariffService> getService(Configuration const *cfg, QDateTime const &dt) {
|
|
|
|
std::optional<ATBTariffService> value = std::nullopt;
|
|
|
|
|
|
|
|
int weekDay = dt.date().dayOfWeek();
|
|
|
|
ATBTime inputTime(dt.time());
|
|
|
|
auto const &serviceRange = cfg->TariffServices.equal_range(weekDay);
|
|
|
|
for (auto i = serviceRange.first; i != serviceRange.second; ++i) {
|
|
|
|
ATBTariffService const &service = i->second;
|
|
|
|
TimeRange const &serviceTimeRange = service.m_range;
|
|
|
|
if (inputTime >= serviceTimeRange.m_start && inputTime < serviceTimeRange.m_end) {
|
|
|
|
value = value.value_or(i->second);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief getOutOfService
|
|
|
|
/// \param cfg
|
|
|
|
/// \param dt
|
|
|
|
/// \return
|
|
|
|
///
|
|
|
|
std::optional<ATBTariffOutOfService> getOutOfService(Configuration const *cfg, QDateTime const &dt) {
|
|
|
|
std::optional<ATBTariffOutOfService> value = std::nullopt;
|
|
|
|
|
|
|
|
int weekDay = dt.date().dayOfWeek();
|
|
|
|
ATBTime inputTime(dt.time());
|
|
|
|
QDate date;
|
|
|
|
|
|
|
|
auto const &outOfServiceRange = cfg->TariffOutOfServices.equal_range(weekDay);
|
|
|
|
for (auto i = outOfServiceRange.first; i != outOfServiceRange.second; ++i) {
|
|
|
|
ATBTariffOutOfService const &outOfService = i->second;
|
|
|
|
TimeRange const &outOfServiceTimeRange = outOfService.m_range;
|
|
|
|
if (outOfService.m_date == dt.date()) {
|
|
|
|
date = dt.date();
|
|
|
|
if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) {
|
|
|
|
value = value.value_or(i->second);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (date.isNull() || !date.isValid()) {
|
|
|
|
for (auto i = outOfServiceRange.first; i != outOfServiceRange.second; ++i) {
|
|
|
|
ATBTariffOutOfService const &outOfService = i->second;
|
|
|
|
TimeRange const &outOfServiceTimeRange = outOfService.m_range;
|
|
|
|
if (inputTime >= outOfServiceTimeRange.m_start && inputTime < outOfServiceTimeRange.m_end) {
|
|
|
|
value = value.value_or(i->second);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<CalcState, QDateTime>
|
|
|
|
Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
|
|
|
QDateTime const &startDatetimePassed, // given in local time
|
|
|
|
int cost) {
|
|
|
|
|
|
|
|
QDateTime inputDate = startDatetimePassed;
|
|
|
|
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
int paymentOptionIndex = 0;
|
|
|
|
|
|
|
|
bool overPaid = false;
|
|
|
|
bool successMaxPrice = false;
|
|
|
|
|
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
|
|
|
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
|
|
|
int const pop_max_time = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
|
|
|
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
|
|
|
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
|
|
|
|
|
|
|
int price = 0;
|
|
|
|
int durationId = 0;
|
|
|
|
int netto_parking_time_in_minutes = 0;
|
|
|
|
int brutto_parking_time_in_minutes = 0;
|
|
|
|
int free_parking_time_in_minutes = 0;
|
|
|
|
|
|
|
|
QMap<int, int> nettoParktimePrice;
|
|
|
|
QMap<int, int> priceNettoParktime;
|
|
|
|
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
durationId = itr->second.pra_payment_unit_id;
|
|
|
|
|
|
|
|
int const pra_price = itr->second.pra_price;
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
price += pra_price;
|
|
|
|
} else {
|
|
|
|
price = pra_price;
|
|
|
|
}
|
|
|
|
|
|
|
|
//if ((double)price == cost) {
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
// found now the duration in minutes
|
|
|
|
// check if we are still inside the working-time-range
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
nettoParktimePrice.insert(duration.pun_duration, price);
|
|
|
|
priceNettoParktime.insert(price, duration.pun_duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
// qCritical() << __func__ << ":" << __LINE__ << nettoParktimePrice;
|
|
|
|
// qCritical() << __func__ << ":" << __LINE__ << priceNettoParktime;
|
|
|
|
|
|
|
|
if (cost == pop_max_price) {
|
|
|
|
qCritical() << DBG_HEADER << "SUCCESS MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
|
|
|
successMaxPrice = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cost > pop_max_price) {
|
|
|
|
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
|
|
|
if (pop_allow_overpay == false) {
|
|
|
|
return std::make_pair(CalcState(CalcState::State::OVERPAID), QDateTime());
|
|
|
|
}
|
|
|
|
cost = pop_max_price;
|
|
|
|
overPaid = true;
|
|
|
|
qCritical() << DBG_HEADER << "OVERPAID, MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
|
|
|
// return CalcState::OVERPAID.toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cost < pop_min_price) {
|
|
|
|
qCritical() << DBG_HEADER << "MIN-PARKING-PRICE" << pop_min_price << ", COST" << cost;
|
|
|
|
return std::make_pair(CalcState(CalcState::State::BELOW_MIN_PARKING_PRICE), QDateTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
int weekDay = inputDate.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "START weekDay" << weekDay << inputDate.toString(Qt::ISODate);
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "START cost" << cost;
|
|
|
|
|
|
|
|
QDateTime dt;
|
|
|
|
bool computationStarted = false;
|
|
|
|
price = 0;
|
|
|
|
netto_parking_time_in_minutes = 0;
|
|
|
|
brutto_parking_time_in_minutes = 0;
|
|
|
|
free_parking_time_in_minutes = 0;
|
|
|
|
|
|
|
|
int const nettoParktimeForCost = priceNettoParktime[int(cost)];
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "nettoParktimeForCost" << nettoParktimeForCost;
|
|
|
|
|
|
|
|
bool startDateNotOutOfService = false;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
while (++cnt < 10 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
|
|
|
// qCritical() << __func__ << ":" << __LINE__ << "cnt [" << cnt;
|
|
|
|
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
|
|
|
weekDay = dt.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
|
|
|
.arg(dt.toString(Qt::ISODate))
|
|
|
|
.arg(weekDay)
|
|
|
|
.arg(brutto_parking_time_in_minutes)
|
|
|
|
.arg(netto_parking_time_in_minutes)
|
|
|
|
.arg(free_parking_time_in_minutes);
|
|
|
|
|
|
|
|
if (std::optional<ATBTariffOutOfService> oos = getOutOfService(cfg, dt)) {
|
|
|
|
if (overPaid || startDateNotOutOfService) {
|
|
|
|
return std::make_pair(CalcState(CalcState::State::OVERPAID,
|
|
|
|
CalcState::OVERPAID), dt);
|
|
|
|
}
|
|
|
|
return std::make_pair(CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
|
|
|
CalcState::OUTSIDE_ALLOWED_PARKING_TIME), dt);
|
|
|
|
} else {
|
|
|
|
startDateNotOutOfService = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (computationStarted == false) {
|
|
|
|
computationStarted = true;
|
|
|
|
if (std::optional<ATBTariffPrepaid> pp = getPrepaid(cfg, dt)) {
|
|
|
|
TimeRange const &prepaidTimeRange = pp.value().m_range;
|
|
|
|
ATBTime t(dt.time().hour(), dt.time().minute(), 0, 0);
|
|
|
|
free_parking_time_in_minutes += t.secsTo(prepaidTimeRange.m_end.toString(Qt::ISODate)) / 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
|
|
|
weekDay = dt.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
|
|
|
.arg(dt.toString(Qt::ISODate))
|
|
|
|
.arg(weekDay)
|
|
|
|
.arg(brutto_parking_time_in_minutes)
|
|
|
|
.arg(netto_parking_time_in_minutes)
|
|
|
|
.arg(free_parking_time_in_minutes);
|
|
|
|
|
|
|
|
if (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, inputDate.addSecs(brutto_parking_time_in_minutes * 60))) {
|
|
|
|
TimeRange const &carryOverTimeRange = co.value().m_range;
|
|
|
|
free_parking_time_in_minutes += carryOverTimeRange.m_duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
|
|
|
weekDay = dt.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
|
|
|
.arg(dt.toString(Qt::ISODate))
|
|
|
|
.arg(weekDay)
|
|
|
|
.arg(brutto_parking_time_in_minutes)
|
|
|
|
.arg(netto_parking_time_in_minutes)
|
|
|
|
.arg(free_parking_time_in_minutes);
|
|
|
|
|
|
|
|
if (std::optional<ATBTariffService> serv = getService(cfg, dt)) {
|
|
|
|
TimeRange const &serviceTimeRange = serv.value().m_range;
|
|
|
|
|
|
|
|
if (nettoParktimeForCost > netto_parking_time_in_minutes) {
|
|
|
|
int rest_parking_time_in_minutes = nettoParktimeForCost - netto_parking_time_in_minutes;
|
|
|
|
ATBTime t(dt.time().hour(), dt.time().minute(), 0, 0);
|
|
|
|
int timeToServiceEnd = t.secsTo(serviceTimeRange.m_end.toString(Qt::ISODate)) / 60;
|
|
|
|
if (serviceTimeRange.m_duration > 0) {
|
|
|
|
if (timeToServiceEnd < rest_parking_time_in_minutes) {
|
|
|
|
netto_parking_time_in_minutes += timeToServiceEnd;
|
|
|
|
} else {
|
|
|
|
netto_parking_time_in_minutes += rest_parking_time_in_minutes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
|
|
|
weekDay = dt.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
|
|
|
.arg(dt.toString(Qt::ISODate))
|
|
|
|
.arg(weekDay)
|
|
|
|
.arg(brutto_parking_time_in_minutes)
|
|
|
|
.arg(netto_parking_time_in_minutes)
|
|
|
|
.arg(free_parking_time_in_minutes);
|
|
|
|
|
|
|
|
// qCritical() << __func__ << ":" << __LINE__ << "cnt" << cnt << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt >= 10) {
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "BREAK";
|
|
|
|
}
|
|
|
|
|
|
|
|
// configure if last carry-over ranges shall be added to ticket-end-time
|
|
|
|
cnt = 0;
|
|
|
|
while (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, inputDate.addSecs(brutto_parking_time_in_minutes * 60))) {
|
|
|
|
if (++cnt > 5) {
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "BREAK";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TimeRange const &carryOverTimeRange = co.value().m_range;
|
|
|
|
free_parking_time_in_minutes += carryOverTimeRange.m_duration;
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
|
|
|
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
|
|
|
weekDay = dt.date().dayOfWeek();
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << QString("ticket-end-time %1 (%2): brutto: %3 = netto: %4 + free: %5")
|
|
|
|
.arg(dt.toString(Qt::ISODate))
|
|
|
|
.arg(weekDay)
|
|
|
|
.arg(brutto_parking_time_in_minutes)
|
|
|
|
.arg(netto_parking_time_in_minutes)
|
|
|
|
.arg(free_parking_time_in_minutes);
|
|
|
|
|
|
|
|
if (successMaxPrice) {
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "SUCC" << dt;
|
|
|
|
return std::make_pair(CalcState(CalcState::State::SUCCESS_MAXPRICE), dt);
|
|
|
|
}
|
|
|
|
if (overPaid) {
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "OVER" << dt;
|
|
|
|
return std::make_pair(CalcState(CalcState::State::OVERPAID), dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "DT" << dt.toString(Qt::ISODate);
|
|
|
|
return std::make_pair(CalcState(CalcState::State::SUCCESS), dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<CalcState, std::optional<int>>
|
|
|
|
Calculator::ComputeCostFromDuration(Configuration const* cfg, QDateTime const &startDatetime,
|
|
|
|
QDateTime &endDatetime, int nettoParkingTime) {
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
int paymentOptionIndex = 0;
|
|
|
|
|
|
|
|
std::optional<int> cost{};
|
|
|
|
|
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
|
|
|
|
|
|
|
int price = 0;
|
|
|
|
int durationId = 0;
|
|
|
|
int netto_parking_time_in_minutes = 0;
|
|
|
|
int brutto_parking_time_in_minutes = 0;
|
|
|
|
int free_parking_time_in_minutes = 0;
|
|
|
|
|
|
|
|
QMap<int, int> nettoParktimePrice;
|
|
|
|
QMap<int, int> priceNettoParktime;
|
|
|
|
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
durationId = itr->second.pra_payment_unit_id;
|
|
|
|
|
|
|
|
int const pra_price = itr->second.pra_price;
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
price += pra_price;
|
|
|
|
} else {
|
|
|
|
price = pra_price;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
// found now the duration in minutes
|
|
|
|
// check if we are still inside the working-time-range
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
nettoParktimePrice.insert(duration.pun_duration, price);
|
|
|
|
priceNettoParktime.insert(price, duration.pun_duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "START netto-parking-time" << nettoParkingTime;
|
|
|
|
CalcState returnState;
|
|
|
|
|
|
|
|
QList<int> keys = nettoParktimePrice.keys();
|
|
|
|
int index = keys.indexOf(nettoParkingTime);
|
|
|
|
if (index != -1) {
|
|
|
|
int c = nettoParktimePrice[keys.at(index)];
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "cost for netto-parking-time" << c;
|
|
|
|
|
|
|
|
std::pair<CalcState, QDateTime> r = ComputeDurationFromCost(cfg, startDatetime, c);
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "result"
|
|
|
|
<< r.first.toString() << r.second.toString(Qt::ISODate);
|
|
|
|
|
|
|
|
|
|
|
|
returnState = r.first;
|
|
|
|
|
|
|
|
if (returnState.getStatus() == CalcState::State::SUCCESS ||
|
|
|
|
returnState.getStatus() == CalcState::State::SUCCESS_MAXPRICE) {
|
|
|
|
|
|
|
|
endDatetime = r.second;
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "--- endDateTime" << endDatetime.toString(Qt::ISODate);
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "------ r.second" << r.second.toString(Qt::ISODate);
|
|
|
|
|
|
|
|
if (!endDatetime.isNull() && endDatetime.isValid()) {
|
|
|
|
cost = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cost) {
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "--- return cost" << cost.value();
|
|
|
|
return std::make_pair(returnState, cost);
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << "--- return error for cost" << returnState.toString();
|
|
|
|
return std::make_pair(returnState, cost);
|
|
|
|
}
|
|
|
|
|
2023-11-24 13:52:49 +01:00
|
|
|
/// <inheritdoc/>
|
2024-09-13 10:42:45 +02:00
|
|
|
std::pair<std::string, QDateTime>
|
|
|
|
Calculator::GetDurationFromCost(Configuration* cfg,
|
|
|
|
uint8_t payment_option,
|
|
|
|
char const *startDatetimePassed, // given in local time
|
|
|
|
double cost,
|
|
|
|
PermitType /*permitType*/,
|
|
|
|
bool nextDay,
|
|
|
|
bool prepaid)
|
2023-11-24 13:52:49 +01:00
|
|
|
{
|
2023-12-01 14:24:15 +01:00
|
|
|
Q_UNUSED(payment_option);
|
|
|
|
Q_UNUSED(nextDay);
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
// Get input date
|
2024-07-30 15:37:28 +02:00
|
|
|
QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
|
2023-12-12 10:43:16 +01:00
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
2024-09-02 17:14:20 +02:00
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
bool overPaid = false;
|
2024-09-16 16:49:00 +02:00
|
|
|
bool successMaxPrice = false; // max-price and cost match
|
2024-09-13 10:42:45 +02:00
|
|
|
|
2024-09-06 12:05:41 +02:00
|
|
|
int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
|
2024-09-02 17:14:20 +02:00
|
|
|
if (paymentOptionIndex == -1) {
|
|
|
|
paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate));
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
|
2024-07-30 15:37:28 +02:00
|
|
|
|
2024-08-01 16:43:19 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
|
|
|
|
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
|
|
|
|
qCritical() << DBG_HEADER << "paymentMethodId:" << static_cast<int>(paymentMethodId);
|
|
|
|
qCritical() << DBG_HEADER << " prepaid:" << prepaid;
|
|
|
|
qCritical() << DBG_HEADER << " cost (price):" << cost;
|
|
|
|
}
|
2024-07-30 15:37:28 +02:00
|
|
|
|
|
|
|
QList<int> tsteps = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, inputDate);
|
2024-08-01 16:43:19 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << DBG_HEADER << " time steps:" << tsteps;
|
|
|
|
} else {
|
|
|
|
Q_UNUSED(tsteps);
|
|
|
|
}
|
2024-07-30 15:37:28 +02:00
|
|
|
|
|
|
|
if (paymentMethodId == PaymentMethod::Degressive) {
|
2024-07-31 10:25:03 +02:00
|
|
|
|
|
|
|
if (static_cast<int>(cost) < cfg->getPaymentOptions(paymentOptionIndex).pop_min_price) {
|
|
|
|
// minimal price is set by GetTimeSteps()
|
|
|
|
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
|
|
|
|
qCritical() << DBG_HEADER << "configured minimal price:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(CalcState::BELOW_MIN_PARKING_PRICE.toStdString(), QDateTime());
|
2024-07-31 10:25:03 +02:00
|
|
|
}
|
|
|
|
|
2024-07-30 15:37:28 +02:00
|
|
|
if (prepaid == false) {
|
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
|
|
|
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
|
|
|
|
|
|
|
|
// qCritical() << DBG_HEADER << " pop id:" << pop_id;
|
|
|
|
|
|
|
|
int price = 0;
|
|
|
|
int new_price = 0;
|
|
|
|
int durationInMinutes = 0;
|
|
|
|
uint32_t duration_previous = 0;
|
|
|
|
// bool found = false;
|
|
|
|
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
int const pra_price = itr->second.pra_price;
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
price += pra_price;
|
|
|
|
} else {
|
|
|
|
price = pra_price;
|
|
|
|
}
|
2024-07-22 15:50:36 +02:00
|
|
|
|
2024-08-02 14:34:44 +02:00
|
|
|
// qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
|
|
|
|
// qCritical() << DBG_HEADER << " duration id" << durationId;
|
2024-07-30 15:37:28 +02:00
|
|
|
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
// found now the duration in minutes
|
|
|
|
// check if we are still inside the working-time-range
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
|
|
|
|
|
|
|
new_price += pra_price;
|
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
|
|
|
|
if (new_price <= cost) {
|
|
|
|
duration_previous = durationUnit;
|
|
|
|
if (pop_accumulate_durations) {
|
|
|
|
durationInMinutes += durationUnit;
|
|
|
|
}
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
|
|
|
|
} else {
|
|
|
|
//found = true;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
|
2024-08-02 14:34:44 +02:00
|
|
|
QDateTime d;
|
|
|
|
if (pop_accumulate_durations) {
|
|
|
|
d = inputDate.addSecs(durationInMinutes * 60);
|
|
|
|
} else {
|
|
|
|
d = inputDate.addSecs(duration_previous * 60);
|
|
|
|
}
|
2024-07-31 10:26:47 +02:00
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
|
|
|
|
qCritical() << DBG_HEADER << " computed time for price (minutes):" << duration_previous;
|
2024-08-02 14:34:44 +02:00
|
|
|
qCritical() << DBG_HEADER << " minimal parking time (minutes):" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
2024-07-31 10:26:47 +02:00
|
|
|
|
|
|
|
if (duration_previous < cfg->getPaymentOptions(paymentOptionIndex).pop_min_time) {
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(CalcState::BELOW_MIN_PARKING_TIME.toStdString(), d); // minimal parking time is set by GetTimeSteps()
|
2024-07-31 10:26:47 +02:00
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
|
2024-07-30 15:37:28 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-22 15:50:36 +02:00
|
|
|
|
2024-07-30 15:37:28 +02:00
|
|
|
if ((double)price == cost) {
|
2024-07-31 10:26:47 +02:00
|
|
|
QDateTime d(inputDate.addSecs(durationInMinutes * 60));
|
|
|
|
|
|
|
|
QString const durationStr(d.toString(Qt::ISODate));
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << " duration in minutes:" << durationInMinutes;
|
|
|
|
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
|
|
|
|
qCritical() << DBG_HEADER << " duration for price:" << durationStr;
|
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(durationStr.toStdString(), d);
|
2024-07-30 15:37:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
qCritical() << DBG_HEADER << " TODO";
|
|
|
|
}
|
|
|
|
} else
|
2024-09-27 14:10:02 +02:00
|
|
|
if (paymentMethodId == PaymentMethod::Unified) {
|
|
|
|
std::pair<CalcState, QDateTime> r =
|
|
|
|
ComputeDurationFromCost(cfg, QDateTime::fromString(startDatetimePassed, Qt::ISODate), cost);
|
|
|
|
|
|
|
|
CalcState cs = r.first;
|
|
|
|
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << cs.toString();
|
|
|
|
qCritical() << __func__ << ":" << __LINE__ << r.second.toString(Qt::ISODate);
|
|
|
|
|
|
|
|
return std::make_pair(r.first.toString().toStdString(), r.second);
|
|
|
|
} else
|
2023-12-12 10:43:16 +01:00
|
|
|
if (paymentMethodId == PaymentMethod::Steps) {
|
|
|
|
if (tariffIs24_7(cfg)) {
|
|
|
|
// use tariff with structure as for instance Schoenau, Koenigsee:
|
|
|
|
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
2024-02-16 13:37:24 +01:00
|
|
|
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, cost) * 60);
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(inputDate.toString(Qt::ISODate).toStdString(), inputDate);
|
2023-12-12 10:43:16 +01:00
|
|
|
} else {
|
2024-01-31 15:19:31 +01:00
|
|
|
if (Utilities::IsYearPeriodActive(cfg, inputDate)) {
|
2023-12-12 10:43:16 +01:00
|
|
|
if (!prepaid) {
|
2024-01-31 15:19:31 +01:00
|
|
|
CalcState cs = isParkingAllowed(cfg, inputDate);
|
|
|
|
if (cs) {
|
|
|
|
inputDate.setTime(cs.getAllowedTimeRange().getTimeUntil());
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(inputDate.toString(Qt::ISODate).toStdString(), inputDate);
|
2023-12-12 10:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
2024-09-27 14:17:35 +02:00
|
|
|
//int const pop_max_time = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
2024-06-05 17:00:27 +02:00
|
|
|
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
2024-08-21 15:39:05 +02:00
|
|
|
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
2024-09-27 14:17:35 +02:00
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
|
|
|
int price = 0;
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-09-16 16:49:00 +02:00
|
|
|
if (cost == pop_max_price) {
|
|
|
|
qCritical() << DBG_HEADER << "SUCCESS MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
|
|
|
successMaxPrice = true;
|
|
|
|
}
|
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
if (cost > pop_max_price) {
|
|
|
|
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
2024-08-21 15:39:05 +02:00
|
|
|
if (pop_allow_overpay == false) {
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), QDateTime());
|
2024-08-21 15:39:05 +02:00
|
|
|
}
|
|
|
|
cost = pop_max_price;
|
2024-09-13 10:42:45 +02:00
|
|
|
overPaid = true;
|
2024-09-16 16:49:00 +02:00
|
|
|
qCritical() << DBG_HEADER << "OVERPAID, MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
2024-08-21 15:39:05 +02:00
|
|
|
// return CalcState::OVERPAID.toStdString();
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cost < pop_min_price) {
|
|
|
|
qCritical() << DBG_HEADER << "MIN-PARKING-PRICE" << pop_min_price << ", COST" << cost;
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(CalcState::BELOW_MIN_PARKING_PRICE.toStdString(), QDateTime());
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// int const pop_pre_paid = 1;
|
|
|
|
|
|
|
|
if (prepaid) {
|
|
|
|
// no limits on pre-pay-option, i.e. pre-pay-ranges are exactly
|
|
|
|
// the complements of operational-ranges
|
|
|
|
|
|
|
|
// find out if we are in a pre-pay-range.
|
|
|
|
// in this case, adapt inputDate accordingly.
|
|
|
|
|
2024-06-06 14:02:43 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
#define DEBUG_GET_DURATION_FROM_COST 0
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "PRE-PAID-OPTION: ADAPT-INPUT-DATE" << inputDate.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
|
|
|
|
QTime currentTime = inputDate.time();
|
|
|
|
int pwd_period_day_in_week_id = inputDate.date().dayOfWeek();
|
|
|
|
|
|
|
|
bool useWeekDaysWorkTimeOfOtherDay = true;
|
|
|
|
|
|
|
|
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_day_in_week_id); iter != rEnd; ++iter) {
|
|
|
|
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
|
|
|
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
|
|
|
|
|
2024-08-01 16:43:19 +02:00
|
|
|
//qCritical() << DBG_HEADER << "from" << pwd_time_from.toString(Qt::ISODate);
|
|
|
|
//qCritical() << DBG_HEADER << " to" << pwd_time_to.toString(Qt::ISODate);
|
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
if (inputDate.time() < pwd_time_from) {
|
|
|
|
inputDate.setTime(pwd_time_from);
|
|
|
|
useWeekDaysWorkTimeOfOtherDay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (currentTime <= pwd_time_to) {
|
|
|
|
useWeekDaysWorkTimeOfOtherDay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useWeekDaysWorkTimeOfOtherDay) {// for the current day, we are above
|
|
|
|
// the latest worktime-range -> find the next valid range
|
|
|
|
|
|
|
|
QTime pwd_time_from_next_valid_range(0, 0, 0);
|
|
|
|
int pwd_period_next_day_in_week_id = pwd_period_day_in_week_id;
|
|
|
|
for (int days = 1; days < 8; ++days) {
|
|
|
|
pwd_period_next_day_in_week_id += 1;
|
|
|
|
if (pwd_period_next_day_in_week_id > (int)Qt::Sunday) {
|
|
|
|
pwd_period_next_day_in_week_id = Qt::Monday;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->WeekDaysWorktime.count(pwd_period_next_day_in_week_id) > 0) {
|
|
|
|
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_next_day_in_week_id); iter != rEnd; ++iter) {
|
|
|
|
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
|
|
|
if (pwd_time_from_next_valid_range < pwd_time_from) {
|
|
|
|
pwd_time_from_next_valid_range = pwd_time_from;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputDate = inputDate.addDays(days);
|
|
|
|
inputDate.setTime(pwd_time_from_next_valid_range);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-30 15:39:35 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << "no prepaid";
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "(ADAPTED) INPUT-DATE" << inputDate.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << __func__ << __LINE__;
|
2024-06-05 17:00:27 +02:00
|
|
|
|
|
|
|
// inputDate is now located in a valid operational-working-range
|
|
|
|
// find this working-time-range
|
|
|
|
int pwd_period_day_in_week_id = inputDate.date().dayOfWeek();
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << __func__ << __LINE__ << pwd_period_day_in_week_id;
|
|
|
|
//qCritical() << __func__ << __LINE__ << cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id);
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
if (cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id) == 0) {
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "ERROR" << inputDate.toString(Qt::ISODate)
|
|
|
|
<< "NOT IN VALID WORKING TIME-RANGE";
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair("", QDateTime());
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << __func__ << __LINE__;
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
QTime current_working_time_from;
|
|
|
|
QTime current_working_time_to;
|
|
|
|
|
|
|
|
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_day_in_week_id); iter != rEnd; ++iter) {
|
|
|
|
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
|
|
|
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
//qCritical() << __func__ << pwd_time_from.toString(Qt::ISODate);
|
|
|
|
//qCritical() << __func__ << pwd_time_to.toString(Qt::ISODate);
|
|
|
|
//qCritical() << __func__ << inputDate.toString(Qt::ISODate);
|
2024-06-05 17:00:27 +02:00
|
|
|
if (pwd_time_from <= inputDate.time() && inputDate.time() <= pwd_time_to) {
|
|
|
|
current_working_time_from = pwd_time_from;
|
|
|
|
current_working_time_to = pwd_time_to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_working_time_from.isNull() || current_working_time_to.isNull()) {
|
|
|
|
// can never happen
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "ERROR" << inputDate.toString(Qt::ISODate)
|
|
|
|
<< "NOT IN VALID WORKING TIME-RANGE";
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair("", QDateTime());
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "CURRENT WORKING-TIME-FROM" << current_working_time_from.toString(Qt::ISODate);
|
|
|
|
qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-09-27 14:17:35 +02:00
|
|
|
// int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
2024-07-25 09:49:16 +02:00
|
|
|
// int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
|
2024-09-27 14:17:35 +02:00
|
|
|
// int price = 0;
|
2024-07-26 17:01:44 +02:00
|
|
|
int new_price = 0;
|
2024-07-22 15:53:27 +02:00
|
|
|
int durationInSecs = 0;
|
2024-07-26 17:01:44 +02:00
|
|
|
uint32_t duration_previous = 0;
|
2024-09-02 17:15:33 +02:00
|
|
|
// bool found = false;
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
int const pra_price = itr->second.pra_price;
|
2024-07-22 15:53:27 +02:00
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
price += pra_price;
|
|
|
|
} else {
|
|
|
|
price = pra_price;
|
|
|
|
}
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-07-30 15:39:35 +02:00
|
|
|
// qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-07-22 15:53:27 +02:00
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
// found now the duration in minutes
|
|
|
|
// check if we are still inside the working-time-range
|
|
|
|
ATBDuration duration = search->second;
|
2024-07-26 17:01:44 +02:00
|
|
|
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
|
|
|
|
|
|
|
new_price += pra_price;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX price:" << price;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") YYYYYY new_price:" << new_price;
|
2024-07-26 17:01:44 +02:00
|
|
|
if (new_price <= cost) {
|
|
|
|
duration_previous = durationUnit;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous;
|
2024-07-26 17:01:44 +02:00
|
|
|
} else {
|
2024-09-02 17:15:33 +02:00
|
|
|
//found = true;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") WWWWWW duration_previous" << duration_previous;
|
2024-07-26 17:01:44 +02:00
|
|
|
QString s = inputDate.toString(Qt::ISODate);
|
|
|
|
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
|
|
|
|
d = d.addSecs(duration_previous * 60);
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << d;
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), d);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), d);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
|
2024-07-26 17:01:44 +02:00
|
|
|
}
|
2024-08-01 16:44:06 +02:00
|
|
|
} else {
|
|
|
|
durationInSecs = cfg->Duration.find(durationId)->second.pun_duration * 60;
|
|
|
|
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
|
|
|
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
2024-07-26 17:01:44 +02:00
|
|
|
}
|
|
|
|
|
2024-07-22 15:53:27 +02:00
|
|
|
if ((double)price == cost) {
|
2024-06-05 17:00:27 +02:00
|
|
|
QDateTime current_working_date_time_to = inputDate;
|
|
|
|
current_working_date_time_to.setTime(current_working_time_to);
|
|
|
|
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-07-22 15:53:27 +02:00
|
|
|
qCritical() << DBG_HEADER << " DURATION ID" << duration.pun_id;
|
|
|
|
qCritical() << DBG_HEADER << "DURATION IN MINUTES" << durationInSecs / 60;
|
|
|
|
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << durationInSecs;
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO"
|
|
|
|
<< current_working_date_time_to.toString(Qt::ISODate);
|
|
|
|
qCritical() << DBG_HEADER << "NEW INPUT DATE" << inputDate.addSecs(durationInSecs).toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
|
|
|
|
if (inputDate.addSecs(durationInSecs) > current_working_date_time_to) {
|
|
|
|
QTime next_working_time_from;
|
|
|
|
if (cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over != 0) {
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "CARRY-OVER SET";
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
// check for next working-time-range on same day
|
|
|
|
int day_in_week_id = inputDate.date().dayOfWeek();
|
|
|
|
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
|
|
|
|
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
|
|
|
if (pwd_time_from > current_working_time_to) {
|
|
|
|
next_working_time_from = pwd_time_from;
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "NEXT-WORKING-TIME-FROM"
|
|
|
|
<< next_working_time_from.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check for next working-time-range on following day(s)
|
|
|
|
if (next_working_time_from.isNull()) {
|
|
|
|
next_working_time_from = QTime(0, 0, 0);
|
|
|
|
for (int days = 1; days < 8; ++days) {
|
|
|
|
day_in_week_id += 1;
|
|
|
|
if (day_in_week_id > (int)Qt::Sunday) {
|
|
|
|
day_in_week_id = Qt::Monday;
|
|
|
|
}
|
|
|
|
if (cfg->WeekDaysWorktime.count(day_in_week_id) > 0) {
|
|
|
|
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
|
|
|
|
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
|
|
|
|
if (next_working_time_from < pwd_time_from) {
|
|
|
|
next_working_time_from = pwd_time_from;
|
2024-08-01 16:43:19 +02:00
|
|
|
qCritical() << DBG_HEADER << "next working time from" << next_working_time_from.toString(Qt::ISODate);
|
2024-06-05 17:00:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER << "DAYS" << days;
|
|
|
|
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
|
|
|
|
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-06-06 14:04:04 +02:00
|
|
|
QDateTime upper = inputDate.addDays(days);
|
|
|
|
upper.setTime(next_working_time_from);
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-06-06 14:04:04 +02:00
|
|
|
QDateTime lower = inputDate;
|
|
|
|
lower.setTime(current_working_time_to);
|
2024-06-05 17:00:27 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-07-26 17:34:24 +02:00
|
|
|
// inputDate = inputDate.addSecs(lower.secsTo(upper));
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-09-16 16:50:16 +02:00
|
|
|
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
|
|
|
if (pop_carry_over) {
|
|
|
|
int weekDay = inputDate.date().dayOfWeek();
|
|
|
|
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
|
|
|
|
if (pop_carry_over_option_id != -1) {
|
|
|
|
int const carryOverDuration = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
|
|
|
inputDate = inputDate.addSecs(carryOverDuration * 60);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 17:01:44 +02:00
|
|
|
inputDate = inputDate.addSecs(durationInSecs);
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
|
|
|
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // for (int days = 1; days < 8; ++days) {
|
2024-06-05 17:00:27 +02:00
|
|
|
} else { // next working-time is on same day
|
|
|
|
QDateTime upper = inputDate;
|
|
|
|
upper.setTime(next_working_time_from);
|
|
|
|
|
|
|
|
QDateTime lower = inputDate;
|
|
|
|
lower.setTime(current_working_time_to);
|
|
|
|
|
|
|
|
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
|
2024-06-06 14:02:43 +02:00
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputDate = inputDate.addSecs(duration.pun_duration * 60);
|
2024-06-06 14:02:43 +02:00
|
|
|
|
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "INPUT-DATE" << inputDate.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
|
|
|
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString const &s = inputDate.toString(Qt::ISODate);
|
2024-06-06 14:02:43 +02:00
|
|
|
|
|
|
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
2024-06-05 17:00:27 +02:00
|
|
|
qCritical() << DBG_HEADER << "TICKET-END" << s;
|
2024-06-06 14:02:43 +02:00
|
|
|
#endif
|
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), inputDate);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), inputDate);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(s.toStdString(), inputDate);
|
2024-07-22 15:53:27 +02:00
|
|
|
} // if ((double)price == cost) {
|
2024-07-26 17:01:44 +02:00
|
|
|
else {
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << DBG_HEADER;
|
2024-07-26 17:01:44 +02:00
|
|
|
}
|
|
|
|
} else {
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << __func__ << __LINE__;
|
2024-06-05 17:00:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair("", QDateTime());
|
2023-12-12 10:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
} else
|
|
|
|
if (paymentMethodId == PaymentMethod::Progressive) {
|
|
|
|
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
|
|
|
// for now try out some ideas
|
|
|
|
|
2024-02-19 11:59:06 +01:00
|
|
|
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
|
|
|
// for now try out some ideas
|
|
|
|
|
2024-02-16 13:37:24 +01:00
|
|
|
static const bool carryOverNotSet = Utilities::isCarryOverNotSet(cfg, paymentMethodId);
|
2024-02-19 11:59:06 +01:00
|
|
|
static const uint minParkingPrice = Utilities::getMinimalParkingPrice(cfg, paymentMethodId);
|
2024-02-20 13:47:45 +01:00
|
|
|
static const uint maxParkingPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
|
|
|
|
|
|
|
if (cost < minParkingPrice) {
|
|
|
|
qCritical() << QString("ERROR: COST < MIN_PARKING_PRICE (%1 < %2)").arg(cost).arg(minParkingPrice);
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(QDateTime().toString(Qt::ISODate).toStdString(), QDateTime());
|
2024-02-20 13:47:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cost > maxParkingPrice) {
|
|
|
|
qCritical() << QString("WARN: COST > MAX_PARKING_PRICE (%1 > %2)").arg(cost).arg(maxParkingPrice);
|
|
|
|
cost = maxParkingPrice;
|
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
|
|
|
|
Q_ASSERT_X(carryOverNotSet, __func__, "CARRYOVER SET (FOR KIRCHDORF)");
|
|
|
|
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
|
|
|
|
2024-02-19 11:59:06 +01:00
|
|
|
QDateTime start_datetime = QDateTime::fromString(QString(startDatetimePassed), Qt::ISODate);
|
|
|
|
QDateTime start = start_datetime;
|
|
|
|
QDateTime end_datetime = QDateTime();
|
2024-02-16 13:37:24 +01:00
|
|
|
|
|
|
|
int weekdayId = -1;
|
|
|
|
int weekdayIdLast = -1;
|
2024-02-19 11:59:06 +01:00
|
|
|
int durationMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
2024-02-16 13:37:24 +01:00
|
|
|
int durationMinutesBrutto = 0;
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#ifdef _DEBUG_
|
|
|
|
#undef _DEBUG_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//#define _DEBUG_ 1
|
|
|
|
#define _DEBUG_ 0
|
|
|
|
|
2024-02-19 11:59:06 +01:00
|
|
|
QDateTime current = start;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
|
|
|
int days = 7;
|
|
|
|
while (--days > 0) {
|
|
|
|
weekdayId = current.date().dayOfWeek();
|
|
|
|
weekdayIdLast = weekdayId; // TODO: some end condition in json-file
|
|
|
|
|
2024-02-19 11:59:06 +01:00
|
|
|
while (cfg->WeekDaysWorktime.count(weekdayId) == 0) {
|
2024-02-16 13:37:24 +01:00
|
|
|
current = current.addDays(1);
|
|
|
|
weekdayId = current.date().dayOfWeek();
|
|
|
|
if (weekdayId == weekdayIdLast) {
|
|
|
|
qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(QDateTime().toString(Qt::ISODate).toStdString(), QDateTime());
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
QTime to = QTime(0, 0, 0);
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
QTime const &t = Utilities::WeekDaysWorkTimeUntil(itr);
|
|
|
|
|
|
|
|
if (to < t) {
|
|
|
|
to = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.time() >= to) {
|
2024-02-19 11:59:06 +01:00
|
|
|
if (carryOverNotSet) {
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-19 11:59:06 +01:00
|
|
|
} else {
|
|
|
|
QDateTime const dt = start;
|
|
|
|
start = start.addDays(1);
|
|
|
|
start.setTime(QTime(0, 0, 0));
|
|
|
|
|
|
|
|
durationMinutesBrutto += dt.secsTo(start) / 60;
|
|
|
|
current = start;
|
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int durationMinutesNetto = 0;
|
2024-02-19 11:59:06 +01:00
|
|
|
uint price = 0;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
|
|
|
if (carryOverNotSet) {
|
|
|
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
2024-02-21 14:53:06 +01:00
|
|
|
int minsUsed = 0;
|
2024-02-16 13:37:24 +01:00
|
|
|
QDateTime lastCurrent = QDateTime();
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
QVector<ATBWeekDaysWorktime> weekDayWorkTimeRanges;
|
|
|
|
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
weekDayWorkTimeRanges.append(itr->second); // working with vector is easier
|
|
|
|
}
|
|
|
|
|
|
|
|
int weekDayWorkTimeIndex = 0;
|
|
|
|
bool moveToNextTimeRange = false;
|
|
|
|
|
|
|
|
// time ranges for Neuhauser-Kirchdorf (743): 30, 5, 5, ... 5
|
2024-02-16 13:37:24 +01:00
|
|
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
2024-02-27 17:11:00 +01:00
|
|
|
while (timeRangeIt != cfg->TimeRange.cend()) { // ; ++timeRangeIt) {
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
if (weekDayWorkTimeIndex >= weekDayWorkTimeRanges.size()) {
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "weekDayWorkTimeRanges.size()" << weekDayWorkTimeRanges.size()
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
end_datetime = current;
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-27 17:11:00 +01:00
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
|
|
|
|
QTime const &to = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_to.c_str(), Qt::ISODate);
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "from" << from.toString(Qt::ISODate)
|
|
|
|
<< "to" << to.toString(Qt::ISODate);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
|
|
|
|
|
|
|
if (current.time() >= to) {
|
|
|
|
++weekDayWorkTimeIndex;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "try to use next available work-time with"
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
// time range is not affected
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if (current.time() <= from) {
|
|
|
|
if (prepaid) {
|
|
|
|
lastCurrent = current;
|
|
|
|
current.setTime(from); // move current forward (range==1),
|
|
|
|
// as prepaid is set
|
|
|
|
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
|
|
|
durationMinutesBrutto += minutesMoved;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "minutesMoved" << minutesMoved
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (weekDayWorkTimeIndex == 0) {
|
|
|
|
start_datetime = current;
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-27 17:11:00 +01:00
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
ATBTimeRange timeRange = timeRangeIt->second;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
timeRange.computeQTimes(current.time());
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
|
|
|
timeRange.time_range_from_in_minutes_from_start;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-02-19 11:59:06 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
if (minsToCarryOver > 0) { // the price for this time range
|
|
|
|
// has been is paid already
|
|
|
|
Q_ASSERT_X(weekDayWorkTimeIndex > 0, __func__, "WRONG-WORK-TIME");
|
|
|
|
|
|
|
|
current = current.addSecs(minsToCarryOver*60);
|
|
|
|
|
|
|
|
durationMinutes -= minsToCarryOver;
|
|
|
|
durationMinutesNetto += minsToCarryOver;
|
|
|
|
durationMinutesBrutto += minsToCarryOver;
|
|
|
|
|
|
|
|
minsToCarryOver = 0;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "durationMinutesNetto" << durationMinutesNetto
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
if (price >= cost) {
|
|
|
|
end_datetime = current;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-27 17:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.addSecs(duration * 60).time() <= to) {
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
moveToNextTimeRange = false;
|
|
|
|
for(const auto &x: cfg->PaymentRate) {
|
|
|
|
ATBPaymentRate const rate = x.second;
|
|
|
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
|
|
price += (uint)rate.pra_price;
|
|
|
|
|
|
|
|
if (price >= maxParkingPrice) {
|
|
|
|
price = maxParkingPrice;
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
durationMinutes -= duration;
|
|
|
|
durationMinutesNetto += duration;
|
|
|
|
durationMinutesBrutto += duration;
|
|
|
|
|
|
|
|
current = current.addSecs(duration * 60);
|
|
|
|
|
|
|
|
if (price >= cost) {
|
2024-02-19 11:59:06 +01:00
|
|
|
end_datetime = current;
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
// price has been updated; use next time range
|
|
|
|
moveToNextTimeRange = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "price" << price
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "durationMinutesNetto" << durationMinutesNetto
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
|
|
#endif
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
if (price >= cost) {
|
|
|
|
end_datetime = current;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-27 17:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (moveToNextTimeRange) {
|
|
|
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// havin a new time range means that we always have a new
|
|
|
|
// work-time-range
|
|
|
|
// ++timeRangeIt;
|
|
|
|
|
|
|
|
} else { // current.addSecs(duration * 60).time() > to
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< ", to:" << to.toString(Qt::ISODate);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lastCurrent = current;
|
|
|
|
current.setTime(to);
|
|
|
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// mod duration: possibly discard some minutes in
|
|
|
|
// the next time-range
|
|
|
|
if (duration >= minsUsed) {
|
|
|
|
minsToCarryOver = duration - minsUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
durationMinutes -= minsUsed;
|
|
|
|
durationMinutesNetto += minsUsed;
|
|
|
|
durationMinutesBrutto += minsUsed;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
moveToNextTimeRange = false;
|
2024-02-16 13:37:24 +01:00
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
if (minsUsed > 0) {
|
|
|
|
for(const auto &x: cfg->PaymentRate) {
|
|
|
|
ATBPaymentRate const rate = x.second;
|
|
|
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
|
|
price += (uint)rate.pra_price;
|
|
|
|
|
|
|
|
if (price >= maxParkingPrice) {
|
|
|
|
price = maxParkingPrice;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (price >= cost) {
|
|
|
|
end_datetime = current;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// return end_datetime.toString(Qt::ISODate).toStdString();
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
2024-02-27 17:11:00 +01:00
|
|
|
|
|
|
|
// price has been updated; use next time range
|
|
|
|
moveToNextTimeRange = true;
|
|
|
|
break;
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 17:11:00 +01:00
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "moveToNextTimeRange" << moveToNextTimeRange
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (moveToNextTimeRange) {
|
|
|
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no valid time range left
|
|
|
|
end_datetime = current;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-16 16:49:00 +02:00
|
|
|
if (successMaxPrice) {
|
|
|
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
|
|
|
}
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-27 17:11:00 +01:00
|
|
|
}
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
|
2024-02-19 11:59:06 +01:00
|
|
|
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
2024-02-27 17:11:00 +01:00
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "start" << start.toString(Qt::ISODate)
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "final price" << std::max(price, minParkingPrice);
|
|
|
|
#endif
|
|
|
|
|
2024-09-13 10:42:45 +02:00
|
|
|
if (overPaid) {
|
|
|
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
|
|
|
}
|
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2024-02-27 17:11:00 +01:00
|
|
|
} // while (timeRangeIt != cfg->TimeRange.cend()) {
|
2024-02-16 13:37:24 +01:00
|
|
|
}
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "INVALID END TIME";
|
|
|
|
#endif
|
2024-02-19 11:59:06 +01:00
|
|
|
end_datetime = QDateTime();
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2024-02-16 13:37:24 +01:00
|
|
|
Ticket t = private_GetDurationFromCost(cfg, inputDate, cost, prepaid);
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-12-05 17:31:56 +01:00
|
|
|
// qCritical().noquote() << t;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-12-01 14:24:15 +01:00
|
|
|
// TODO: im fehlerfall
|
2024-09-13 10:42:45 +02:00
|
|
|
return std::make_pair(t.getValidUntil().toString(Qt::ISODate).toStdString(), t.getValidUntil());
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
2024-02-27 17:11:00 +01:00
|
|
|
#undef _DEBUG_
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
///
|
|
|
|
|
|
|
|
uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
|
|
|
|
QDateTime const &start,
|
2024-04-19 13:31:01 +02:00
|
|
|
quint64 timeStepInMinutes,
|
|
|
|
int paymentOptionIndex) const {
|
2023-11-24 13:52:49 +01:00
|
|
|
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
|
|
|
|
// special days, nonstop.
|
2024-07-29 17:26:26 +02:00
|
|
|
//qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2023-12-12 10:49:51 +01:00
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
2024-07-26 10:59:45 +02:00
|
|
|
if (paymentMethodId == PaymentMethod::Steps ||
|
|
|
|
paymentMethodId == PaymentMethod::Degressive) {
|
2023-11-24 13:52:49 +01:00
|
|
|
QDateTime const end = start.addSecs(timeStepInMinutes*60);
|
2024-04-19 13:31:01 +02:00
|
|
|
return GetCostFromDuration(cfg, start, end, paymentOptionIndex);
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
|
|
|
|
QDateTime const &start,
|
2024-04-19 13:31:01 +02:00
|
|
|
QDateTime const &end,
|
|
|
|
int paymentOptionIndex) const {
|
2023-12-12 10:49:51 +01:00
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-29 17:26:26 +02:00
|
|
|
//qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
|
|
|
if (paymentMethodId == PaymentMethod::Steps ||
|
|
|
|
paymentMethodId == PaymentMethod::Degressive) {
|
2023-11-24 13:52:49 +01:00
|
|
|
int const timeStepInMinutes = start.secsTo(end) / 60;
|
2024-08-02 11:11:20 +02:00
|
|
|
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, start);
|
|
|
|
qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
|
2024-07-26 10:59:45 +02:00
|
|
|
qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
|
|
|
|
|
2024-04-19 13:31:01 +02:00
|
|
|
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex) {
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-07-29 17:26:26 +02:00
|
|
|
//qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
|
|
|
|
// << "paymentOptionIndex" << paymentOptionIndex;
|
2024-04-19 13:32:24 +02:00
|
|
|
|
2024-07-24 12:30:46 +02:00
|
|
|
// TODO: wieder entfernen
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", QTime(), QTime());
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
QString errorStr = "UNKNOWN ERROR";
|
|
|
|
|
|
|
|
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
if (paymentMethodId == PaymentMethod::Steps) {
|
|
|
|
uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (cfg->isDayIncluded(businessHours, start)) {
|
|
|
|
if (businessHours == BusinessHours::NO_RESTRICTION_24_7) {
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
|
|
|
|
QTime(0, 0, 0), QTime(23, 59, 59));
|
|
|
|
}
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
int const weekdayId = start.date().dayOfWeek();
|
2024-06-04 11:18:00 +02:00
|
|
|
|
|
|
|
// qCritical() << DBG_HEADER
|
|
|
|
// << "weekdayId" << weekdayId
|
|
|
|
// << "count" << cfg->WeekDaysWorktime.count(weekdayId);
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
|
|
|
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
|
|
|
|
<< from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
|
|
|
|
|
|
|
|
QTime const &startTime = start.time();
|
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
// qCritical() << DBG_HEADER << "START TIME" << startTime.toString(Qt::ISODate);
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (startTime >= from && startTime <= until) {
|
2024-05-07 15:01:16 +02:00
|
|
|
QDateTime const end = start.addSecs(netto_parking_time*60);
|
2024-07-24 12:37:29 +02:00
|
|
|
|
|
|
|
//qCritical() << DBG_HEADER << "END-DATE-TIME" << end.toString(Qt::ISODate);
|
|
|
|
|
2024-05-07 15:01:16 +02:00
|
|
|
QTime const endTime = end.time();
|
|
|
|
if (endTime <= until && start.date().dayOfWeek() == end.date().dayOfWeek()) {
|
|
|
|
qCritical() << DBG_HEADER;
|
2024-04-19 13:32:24 +02:00
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
|
|
|
|
} else {
|
|
|
|
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
|
|
|
|
.arg(__LINE__)
|
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(endTime.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
|
|
|
|
.arg(__LINE__)
|
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(until.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
|
|
|
|
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
2024-06-04 11:18:00 +02:00
|
|
|
|
|
|
|
// qCritical() << DBG_HEADER
|
|
|
|
// << "paymentOptionIndex" << paymentOptionIndex
|
|
|
|
// << "pop_carry_over" << pop_carry_over;
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (pop_carry_over == 1) {
|
2024-06-04 11:18:00 +02:00
|
|
|
// qCritical() << DBG_HEADER
|
|
|
|
// << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
|
2024-04-19 13:32:24 +02:00
|
|
|
|
|
|
|
int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
|
|
|
|
int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
|
|
|
|
|
2024-06-04 11:19:39 +02:00
|
|
|
// qCritical() << DBG_HEADER
|
|
|
|
// << "pop_carry_over_start_time_range" << pop_carry_over_start_time_range
|
|
|
|
// << "pop_carry_over_end_time_range" << pop_carry_over_end_time_range;
|
|
|
|
|
|
|
|
if ((int)cfg->TimeRange.count(pop_carry_over_start_time_range) <= 0 &&
|
|
|
|
(int)cfg->TimeRange.count(pop_carry_over_end_time_range) <= 0) {
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << "PARKING_ALLOWED. startTime" << startTime.toString(Qt::ISODate);
|
2024-09-27 14:18:31 +02:00
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", startTime, QTime());
|
2024-06-04 11:19:39 +02:00
|
|
|
|
|
|
|
} else
|
|
|
|
// search entry in time-range-field of tariff-file
|
2024-04-19 13:32:24 +02:00
|
|
|
if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
|
|
|
|
cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
|
|
|
|
|
|
|
|
ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
|
|
|
|
ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
|
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
//qCritical() << DBG_HEADER << "startTime" << startTime.toString(Qt::ISODate);
|
|
|
|
//qCritical() << DBG_HEADER << "s: time range from" << s.getTimeFrom().toString(Qt::ISODate);
|
|
|
|
//qCritical() << DBG_HEADER << "s: time range until" << s.getTimeUntil().toString(Qt::ISODate);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
QDateTime sd = start;
|
|
|
|
sd.setTime(s.getTimeUntil());
|
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
//qCritical() << DBG_HEADER << "jumpFrom" << sd.toString(Qt::ISODate);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
QDateTime ed = start.addDays(1);
|
|
|
|
ed.setTime(e.getTimeFrom());
|
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
//qCritical() << DBG_HEADER << "to" << ed.toString(Qt::ISODate);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
int const jumpSecs = sd.secsTo(ed);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
//qCritical() << DBG_HEADER << "jumpSecs" << jumpSecs;
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
//qCritical() << DBG_HEADER << "new end" << end.toString(Qt::ISODate);
|
2024-06-04 11:18:00 +02:00
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
if (end.time() <= e.getTimeUntil()) {
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "PARKING IS ALLOWED WITH CARRY-OVER ("
|
|
|
|
<< start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
|
|
|
|
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
|
|
|
|
startTime, end.time());
|
|
|
|
} else {
|
2024-06-04 11:18:00 +02:00
|
|
|
errorStr = QString("endTime %1 outside [%2, %3))")
|
2024-04-19 13:32:24 +02:00
|
|
|
.arg(end.toString(Qt::ISODate))
|
|
|
|
.arg(sd.toString(Qt::ISODate))
|
|
|
|
.arg(ed.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
2024-06-04 11:18:00 +02:00
|
|
|
errorStr = QString("startTime %1 outside [%2, %3))")
|
2024-04-19 13:32:24 +02:00
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(s.getTimeFrom().toString(Qt::ISODate))
|
|
|
|
.arg(s.getTimeUntil().toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = "no carry-over limits configured";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = "no carry-over configured";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = QString("no weekday configured for day-id %1").arg(weekdayId);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
errorStr = QString("start %1 not contained in business hours %2")
|
|
|
|
.arg(start.toString(Qt::ISODate))
|
|
|
|
.arg(businessHours);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 11:18:00 +02:00
|
|
|
qCritical() << DBG_HEADER << "errorStr" << errorStr;
|
|
|
|
|
2024-04-19 13:32:24 +02:00
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
|
|
|
|
QTime(), QTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CalcState Calculator::isParkingAllowedForSpecialDay(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex) {
|
|
|
|
QString errorStr = "UNKNOWN ERROR";
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
|
|
|
|
<< "paymentOptionIndex" << paymentOptionIndex;
|
|
|
|
|
|
|
|
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
if (paymentMethodId == PaymentMethod::Steps) {
|
|
|
|
//uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
|
|
|
|
int const specialDayId = cfg->specialDayId(start);
|
|
|
|
if ((specialDayId > 0) && (cfg->SpecialDaysWorktime.count(specialDayId) > 0)) {
|
|
|
|
using SDIterator = Configuration::SpecialDaysWorktimeType::const_iterator;
|
|
|
|
std::pair<SDIterator, SDIterator> p = cfg->SpecialDaysWorktime.equal_range(specialDayId);
|
|
|
|
|
|
|
|
for (SDIterator it = p.first; it != p.second; ++it) {
|
|
|
|
QTime const &from = Utilities::SpecialDaysWorkTimeFrom(it);
|
|
|
|
QTime const &until = Utilities::SpecialDaysWorkTimeUntil(it);
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
|
|
|
|
<< from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
|
|
|
|
|
|
|
|
QTime const &startTime = start.time();
|
|
|
|
|
|
|
|
if (startTime >= from && startTime <= until) {
|
|
|
|
QTime const endTime = start.addSecs(netto_parking_time*60).time();
|
|
|
|
if (endTime <= until) {
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
|
|
|
|
} else {
|
|
|
|
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
|
|
|
|
.arg(__LINE__)
|
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(endTime.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
|
|
|
|
.arg(__LINE__)
|
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(until.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
|
|
|
|
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
|
|
|
if (pop_carry_over == 1) {
|
|
|
|
qCritical() << DBG_HEADER << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
|
|
|
|
|
|
|
|
int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
|
|
|
|
int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
|
|
|
|
|
|
|
|
if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
|
|
|
|
cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
|
|
|
|
|
|
|
|
ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
|
|
|
|
ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
|
|
|
|
|
|
|
|
if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
|
|
|
|
QDateTime sd = start;
|
|
|
|
sd.setTime(s.getTimeUntil());
|
|
|
|
|
|
|
|
QDateTime ed = start.addDays(1);
|
|
|
|
ed.setTime(e.getTimeFrom());
|
|
|
|
|
|
|
|
int const jumpSecs = sd.secsTo(ed);
|
|
|
|
QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
|
|
|
|
if (end.time() <= e.getTimeUntil()) {
|
|
|
|
|
|
|
|
ed.setTime(e.getTimeUntil()); // for printing
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER
|
|
|
|
<< "PARKING IS ALLOWED WITH CARRY-OVER ("
|
|
|
|
<< start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
|
|
|
|
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
|
|
|
|
startTime, end.time());
|
|
|
|
} else {
|
|
|
|
ed.setTime(e.getTimeUntil()); // for printing
|
|
|
|
|
|
|
|
errorStr = QString("endTime %1 exceeds [%2, %3))")
|
|
|
|
.arg(end.toString(Qt::ISODate))
|
|
|
|
.arg(sd.toString(Qt::ISODate))
|
|
|
|
.arg(ed.toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = QString("startTime %1 exceeds [%2, %3))")
|
|
|
|
.arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(s.getTimeFrom().toString(Qt::ISODate))
|
|
|
|
.arg(s.getTimeUntil().toString(Qt::ISODate));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = "no carry-over limits configured";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorStr = "no carry-over configured";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
|
|
|
|
QTime(), QTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex) {
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << "CHECK IF PARKING IS ALLOWED AT"
|
|
|
|
<< start.toString(Qt::ISODate) << "...";
|
|
|
|
|
|
|
|
CalcState cs;
|
|
|
|
|
|
|
|
if ((cs = isParkingAllowedForWeekDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
|
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << QString(cs);
|
|
|
|
|
|
|
|
if ((cs = isParkingAllowedForSpecialDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
|
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCritical() << DBG_HEADER << QString(cs);
|
|
|
|
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, "UNKNOWN ERROR",
|
|
|
|
QTime(), QTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
|
|
|
|
QDateTime const &start) {
|
2024-01-31 15:19:01 +01:00
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
|
|
|
|
if (paymentMethodId == PaymentMethod::Steps) {
|
|
|
|
int const weekdayId = start.date().dayOfWeek();
|
|
|
|
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
|
2024-04-16 12:05:55 +02:00
|
|
|
if (businessHours == BusinessHours::NoRestriction_24_7) {
|
|
|
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
|
|
|
|
QTime(0, 0, 0), QTime(23, 59, 59));
|
|
|
|
} else
|
2024-01-31 15:19:01 +01:00
|
|
|
if (businessHours == BusinessHours::OnlyWeekDays) {
|
|
|
|
if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
|
|
|
|
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
|
|
|
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
|
|
|
|
QTime const &startTime = start.time();
|
|
|
|
if (from > startTime) {
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
|
|
|
QString("%1 < %2").arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(startTime.toString(Qt::ISODate)), from, until);
|
|
|
|
} else
|
|
|
|
if (startTime >= until) {
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
|
|
|
QString("%1 >= %2").arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(until.toString(Qt::ISODate)), from, until);
|
|
|
|
}
|
|
|
|
return CalcState(CalcState::State::SUCCESS,
|
|
|
|
"PARKING ALLOWED", from, until);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (businessHours == BusinessHours::AllDaysWithRestrictedHours) { // e.g. for Neuhauser, NAZ (744)
|
|
|
|
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
|
|
|
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
|
|
|
|
QTime const &startTime = start.time();
|
|
|
|
if (from > startTime) {
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
|
|
|
QString("%1 < %2").arg(from.toString(Qt::ISODate))
|
|
|
|
.arg(startTime.toString(Qt::ISODate)), from, until);
|
|
|
|
} else
|
|
|
|
if (startTime >= until) {
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
|
|
|
QString("%1 >= %2").arg(startTime.toString(Qt::ISODate))
|
|
|
|
.arg(until.toString(Qt::ISODate)), from, until);
|
|
|
|
}
|
|
|
|
return CalcState(CalcState::State::SUCCESS,
|
|
|
|
"PARKING ALLOWED", from, until);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, "UNKNOWN ERROR",
|
|
|
|
QTime(), QTime());
|
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
double Calculator::GetCostFromDuration(Configuration* cfg,
|
|
|
|
uint8_t payment_option,
|
2024-02-15 16:15:28 +01:00
|
|
|
QDateTime &start_datetime,
|
2023-11-24 13:52:49 +01:00
|
|
|
QDateTime &end_datetime,
|
|
|
|
int durationMinutes,
|
2024-07-25 09:49:16 +02:00
|
|
|
PermitType permitType,
|
2023-11-24 13:52:49 +01:00
|
|
|
bool nextDay,
|
2023-11-26 19:55:21 +01:00
|
|
|
bool prepaid) {
|
2023-12-01 14:24:15 +01:00
|
|
|
Q_UNUSED(payment_option);
|
|
|
|
Q_UNUSED(nextDay);
|
|
|
|
|
2024-09-06 12:05:41 +02:00
|
|
|
int paymentOptionIndex = getPaymentOptionIndex(*cfg, start_datetime);
|
2024-09-02 17:14:20 +02:00
|
|
|
if (paymentOptionIndex == -1) {
|
|
|
|
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
|
|
|
|
}
|
2023-12-12 10:52:16 +01:00
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
if (paymentMethodId == PaymentMethod::Steps) {
|
|
|
|
if (tariffIs24_7(cfg)) {
|
|
|
|
end_datetime = start_datetime.addSecs(durationMinutes*60);
|
2024-07-25 09:49:16 +02:00
|
|
|
return GetCostFromDuration(cfg, start_datetime, end_datetime, paymentOptionIndex);
|
2023-12-12 10:52:16 +01:00
|
|
|
} else {
|
|
|
|
if (Utilities::IsYearPeriodActive(cfg, start_datetime)) {
|
|
|
|
if (!prepaid) {
|
2024-01-31 15:19:31 +01:00
|
|
|
CalcState cs = isParkingAllowed(cfg, start_datetime);
|
|
|
|
if (cs) {
|
|
|
|
end_datetime = start_datetime.addSecs(durationMinutes*60);
|
2024-07-25 09:49:16 +02:00
|
|
|
double cost = GetCostFromDuration(cfg, start_datetime, end_datetime, paymentOptionIndex);
|
2024-01-31 15:19:31 +01:00
|
|
|
end_datetime = start_datetime;
|
|
|
|
end_datetime.setTime(cs.getAllowedTimeRange().getTimeUntil());
|
|
|
|
return cost;
|
2023-12-12 10:52:16 +01:00
|
|
|
}
|
2024-02-22 09:31:41 +01:00
|
|
|
} else {
|
|
|
|
// it might be that in such a case even prepaid ("vorkauf")
|
|
|
|
// is not allowed at any moment
|
2023-12-12 10:52:16 +01:00
|
|
|
}
|
2024-02-22 09:43:04 +01:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "NOT YET IMPLEMENTED";
|
2023-12-12 10:52:16 +01:00
|
|
|
end_datetime = QDateTime();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
} else
|
|
|
|
if (paymentMethodId == PaymentMethod::Progressive) {
|
|
|
|
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
|
|
|
// for now try out some ideas
|
|
|
|
|
|
|
|
static const bool carryOverNotSet = Utilities::isCarryOverNotSet(cfg, paymentMethodId);
|
|
|
|
static const uint minParkingPrice = Utilities::getMinimalParkingPrice(cfg, paymentMethodId);
|
|
|
|
|
|
|
|
Q_ASSERT_X(carryOverNotSet, __func__, "CARRYOVER SET (FOR KIRCHDORF)");
|
|
|
|
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
|
|
|
|
|
|
|
QDateTime start = start_datetime;
|
|
|
|
|
|
|
|
int weekdayId = -1;
|
|
|
|
int weekdayIdLast = -1;
|
|
|
|
int durationMinutesBrutto = 0;
|
|
|
|
|
2024-02-27 17:11:00 +01:00
|
|
|
#ifdef _DEBUG_
|
|
|
|
#undef _DEBUG_
|
|
|
|
#endif
|
2024-02-27 12:25:13 +01:00
|
|
|
|
|
|
|
//#define _DEBUG_ 1
|
|
|
|
#define _DEBUG_ 0
|
|
|
|
|
2024-02-15 16:15:28 +01:00
|
|
|
QDateTime current = start;
|
|
|
|
|
|
|
|
int days = 7;
|
|
|
|
while (--days > 0) {
|
|
|
|
weekdayId = current.date().dayOfWeek();
|
|
|
|
weekdayIdLast = weekdayId; // TODO: some end condition in json-file
|
|
|
|
|
2024-02-16 13:37:24 +01:00
|
|
|
while (cfg->WeekDaysWorktime.count(weekdayId) == 0) {
|
2024-02-15 16:15:28 +01:00
|
|
|
current = current.addDays(1);
|
|
|
|
weekdayId = current.date().dayOfWeek();
|
|
|
|
if (weekdayId == weekdayIdLast) {
|
|
|
|
qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
QTime to = QTime(0, 0, 0);
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
QTime const &t = Utilities::WeekDaysWorkTimeUntil(itr);
|
|
|
|
|
|
|
|
if (to < t) {
|
|
|
|
to = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.time() >= to) {
|
2024-02-19 12:00:45 +01:00
|
|
|
if (carryOverNotSet) {
|
2024-02-21 11:13:53 +01:00
|
|
|
end_datetime = start;
|
2024-02-19 12:00:45 +01:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
QDateTime const dt = start;
|
|
|
|
start = start.addDays(1);
|
|
|
|
start.setTime(QTime(0, 0, 0));
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-19 12:00:45 +01:00
|
|
|
durationMinutesBrutto += dt.secsTo(start) / 60;
|
|
|
|
current = start;
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int durationMinutesNetto = 0;
|
|
|
|
uint price = 0;
|
|
|
|
|
|
|
|
if (carryOverNotSet) {
|
|
|
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
2024-02-21 14:20:51 +01:00
|
|
|
int minsUsed = 0;
|
2024-02-15 16:15:28 +01:00
|
|
|
QDateTime lastCurrent = QDateTime();
|
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
QVector<ATBWeekDaysWorktime> weekDayWorkTimeRanges;
|
|
|
|
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
weekDayWorkTimeRanges.append(itr->second); // working with vector is easier
|
|
|
|
}
|
|
|
|
|
|
|
|
int weekDayWorkTimeIndex = 0;
|
|
|
|
bool moveToNextTimeRange = false;
|
|
|
|
|
|
|
|
// time ranges for Neuhauser-Kirchdorf (743): 30, 5, 5, ... 5
|
2024-02-15 16:15:28 +01:00
|
|
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
2024-02-27 12:25:13 +01:00
|
|
|
while (timeRangeIt != cfg->TimeRange.cend()) { // ; ++timeRangeIt) {
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
if (weekDayWorkTimeIndex >= weekDayWorkTimeRanges.size()) {
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "weekDayWorkTimeRanges.size()" << weekDayWorkTimeRanges.size();
|
|
|
|
#endif
|
|
|
|
end_datetime = current;
|
|
|
|
return price;
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
|
|
|
|
QTime const &to = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_to.c_str(), Qt::ISODate);
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "from" << from.toString(Qt::ISODate)
|
|
|
|
<< "to" << to.toString(Qt::ISODate);
|
|
|
|
#endif
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
|
|
|
|
|
|
|
if (current.time() >= to) {
|
|
|
|
++weekDayWorkTimeIndex;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "try to use next available work-time with"
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
// time range is not affected
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if (current.time() <= from) {
|
|
|
|
if (prepaid) {
|
|
|
|
lastCurrent = current;
|
|
|
|
current.setTime(from); // move current forward (range==1),
|
|
|
|
// as prepaid is set
|
|
|
|
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
|
|
|
durationMinutesBrutto += minutesMoved;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "minutesMoved" << minutesMoved
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (weekDayWorkTimeIndex == 0) {
|
|
|
|
start_datetime = current;
|
2024-02-15 16:15:28 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-27 12:25:13 +01:00
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
ATBTimeRange timeRange = timeRangeIt->second;
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
timeRange.computeQTimes(current.time());
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
|
|
|
timeRange.time_range_from_in_minutes_from_start;
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
if (minsToCarryOver > 0) { // the price for this time range
|
|
|
|
// has been is paid already
|
|
|
|
Q_ASSERT_X(weekDayWorkTimeIndex > 0, __func__, "WRONG-WORK-TIME");
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
current = current.addSecs(minsToCarryOver*60);
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
durationMinutes -= minsToCarryOver;
|
|
|
|
durationMinutesNetto += minsToCarryOver;
|
|
|
|
durationMinutesBrutto += minsToCarryOver;
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
minsToCarryOver = 0;
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "durationMinutesNetto" << durationMinutesNetto
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
|
|
#endif
|
|
|
|
if (durationMinutes <= 0) {
|
|
|
|
end_datetime = current;
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-02-26 16:57:37 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
return price;
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
if (current.addSecs(duration * 60).time() <= to) {
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes;
|
|
|
|
#endif
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
moveToNextTimeRange = false;
|
|
|
|
for(const auto &x: cfg->PaymentRate) {
|
|
|
|
ATBPaymentRate const rate = x.second;
|
|
|
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
|
|
price += (uint)rate.pra_price;
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
durationMinutes -= duration;
|
|
|
|
durationMinutesNetto += duration;
|
|
|
|
durationMinutesBrutto += duration;
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
current = current.addSecs(duration * 60);
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
// price has been updated; use next time range
|
|
|
|
moveToNextTimeRange = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "price" << price
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "durationMinutesNetto" << durationMinutesNetto
|
|
|
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
|
|
#endif
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
if (durationMinutes <= 0) {
|
|
|
|
end_datetime = current;
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
2024-02-15 16:15:28 +01:00
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
return price;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moveToNextTimeRange) {
|
|
|
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// havin a new time range means that we always have a new
|
|
|
|
// work-time-range
|
|
|
|
// ++timeRangeIt;
|
|
|
|
|
|
|
|
} else { // current.addSecs(duration * 60).time() > to
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< ", to:" << to.toString(Qt::ISODate);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lastCurrent = current;
|
|
|
|
current.setTime(to);
|
|
|
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// mod duration: possibly discard some minutes in
|
|
|
|
// the next time-range
|
|
|
|
if (duration >= minsUsed) {
|
|
|
|
minsToCarryOver = duration - minsUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
durationMinutes -= minsUsed;
|
|
|
|
durationMinutesNetto += minsUsed;
|
|
|
|
durationMinutesBrutto += minsUsed;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "to" << to.toString(Qt::ISODate)
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "minsToCarryOver" << minsToCarryOver
|
|
|
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
moveToNextTimeRange = false;
|
|
|
|
|
|
|
|
if (minsUsed > 0) {
|
|
|
|
for(const auto &x: cfg->PaymentRate) {
|
|
|
|
ATBPaymentRate const rate = x.second;
|
|
|
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
|
|
price += (uint)rate.pra_price;
|
|
|
|
|
|
|
|
// price has been updated; use next time range
|
|
|
|
moveToNextTimeRange = true;
|
|
|
|
break;
|
2024-02-15 16:15:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 12:25:13 +01:00
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "current" << current.toString(Qt::ISODate)
|
|
|
|
<< "duration" << duration
|
|
|
|
<< "minsUsed" << minsUsed
|
|
|
|
<< "durationMinutes" << durationMinutes
|
|
|
|
<< "moveToNextTimeRange" << moveToNextTimeRange
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (moveToNextTimeRange) {
|
|
|
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no valid time range left
|
|
|
|
end_datetime = current;
|
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "price" << price;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return price;
|
|
|
|
}
|
2024-02-15 16:15:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
2024-02-27 12:25:13 +01:00
|
|
|
|
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "start" << start.toString(Qt::ISODate)
|
|
|
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
|
|
|
<< "final price" << std::max(price, minParkingPrice);
|
|
|
|
#endif
|
|
|
|
|
2024-02-15 16:15:28 +01:00
|
|
|
return std::max(price, minParkingPrice);
|
2024-02-27 12:25:13 +01:00
|
|
|
} // while (timeRangeIt != cfg->TimeRange.cend()) {
|
2024-02-15 16:15:28 +01:00
|
|
|
}
|
|
|
|
|
2024-02-27 12:25:13 +01:00
|
|
|
#if _DEBUG_==1
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
|
|
<< "INVALID END TIME";
|
|
|
|
#endif
|
2024-02-15 16:15:28 +01:00
|
|
|
end_datetime = QDateTime();
|
|
|
|
return 0;
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2023-11-27 16:18:06 +01:00
|
|
|
QDateTime start = start_datetime;
|
|
|
|
|
|
|
|
Ticket t = private_GetCostFromDuration(cfg, start,
|
2023-11-28 15:25:37 +01:00
|
|
|
durationMinutes,
|
|
|
|
prepaid);
|
2023-11-27 16:18:06 +01:00
|
|
|
if (t) {
|
2023-12-05 17:31:56 +01:00
|
|
|
// qCritical().noquote() << t;
|
2023-11-27 16:18:06 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
end_datetime = t.getValidUntil();
|
|
|
|
|
|
|
|
return t.getPrice();
|
2023-11-26 19:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
bool Calculator::checkDurationMinutes(int minParkingTime,
|
2023-11-26 19:55:21 +01:00
|
|
|
int maxParkingTime,
|
|
|
|
int durationMinutes) {
|
2023-11-28 15:25:37 +01:00
|
|
|
if (durationMinutes > maxParkingTime) {
|
|
|
|
qWarning() << QString("Total duration >= max_min (%1 >= %2)").arg(durationMinutes).arg(maxParkingTime);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (durationMinutes < minParkingTime) {
|
|
|
|
qWarning() << QString("Total duration <= minMin (%1 <= %2)").arg(durationMinutes).arg(minParkingTime);
|
|
|
|
return false;
|
2023-11-26 19:55:21 +01:00
|
|
|
}
|
2023-11-28 15:25:37 +01:00
|
|
|
|
2023-11-26 19:55:21 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-11-27 16:19:39 +01:00
|
|
|
int Calculator::findWorkTimeRange(QDateTime const &dt,
|
|
|
|
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
|
|
size_t size) {
|
|
|
|
for (size_t w = 0; w < size; ++w) {
|
|
|
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
|
|
|
QTime const &worktime_to = worktime[w].getTimeUntil();
|
|
|
|
|
|
|
|
if ((dt.time() >= worktime_from) && (dt.time() < worktime_to)) {
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Calculator::findNextWorkTimeRange(QDateTime const &dt,
|
2023-11-28 15:25:37 +01:00
|
|
|
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
|
|
size_t size) {
|
2023-11-27 16:19:39 +01:00
|
|
|
int nextWorkTimeRange = -1;
|
|
|
|
for (size_t w = 0; w < size; ++w) {
|
|
|
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
|
|
|
|
|
|
|
if (dt.time() < worktime_from) {
|
|
|
|
nextWorkTimeRange = w;
|
2023-12-06 10:49:33 +01:00
|
|
|
break;
|
2023-11-27 16:19:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nextWorkTimeRange;
|
|
|
|
}
|
|
|
|
|
2023-11-26 19:55:21 +01:00
|
|
|
using namespace Utilities;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-11-27 16:21:28 +01:00
|
|
|
Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|
|
|
QDateTime const &start,
|
2023-11-28 15:25:37 +01:00
|
|
|
int durationMinutes, // Netto
|
|
|
|
bool prepaid) {
|
2023-11-27 16:21:28 +01:00
|
|
|
|
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId);
|
2023-12-12 10:55:19 +01:00
|
|
|
static const int minParkingTimeMinutes = Utilities::getMinimalParkingTime(cfg, paymentMethodId);
|
|
|
|
static const int maxParkingTimeMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
2023-11-28 15:25:37 +01:00
|
|
|
static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
|
2023-11-27 16:21:28 +01:00
|
|
|
static const int durationMinutesNetto = durationMinutes;
|
2023-12-12 10:55:19 +01:00
|
|
|
static const uint32_t weekDaysPrice = Utilities::computeWeekDaysPrice(cfg, paymentMethodId);
|
|
|
|
static const double weekDaysDurationUnit = Utilities::computeWeekDaysDurationUnit(cfg, paymentMethodId);
|
2023-11-28 15:25:37 +01:00
|
|
|
static const double specialDaysDurationUnit = 60.0;
|
2023-11-27 16:21:28 +01:00
|
|
|
|
2023-11-24 13:52:49 +01:00
|
|
|
if (!checkMinMaxMinutes) {
|
2023-11-26 19:55:21 +01:00
|
|
|
qCritical() << QString(
|
|
|
|
"ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID")
|
|
|
|
.arg(minParkingTimeMinutes).arg(maxParkingTimeMinutes);
|
2023-11-27 16:21:28 +01:00
|
|
|
return Ticket();
|
2023-11-26 19:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
if (!checkDurationMinutes(minParkingTimeMinutes,
|
2023-11-26 19:55:21 +01:00
|
|
|
maxParkingTimeMinutes, durationMinutes)) {
|
2023-11-27 16:21:28 +01:00
|
|
|
return Ticket();
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2023-11-27 16:21:28 +01:00
|
|
|
uint32_t price = 0;
|
|
|
|
uint32_t costFromDuration = 0;
|
2023-11-28 15:25:37 +01:00
|
|
|
double durationUnit = 0.0;
|
|
|
|
int specialDayId = -1;
|
|
|
|
bool isSpecialDay = false;
|
|
|
|
Ticket ticket;
|
|
|
|
QDateTime end = start;
|
|
|
|
QDateTime current;
|
|
|
|
int totalTimeRanges = 0;
|
|
|
|
|
|
|
|
for (current = start; durationMinutes > 0; current = current.addDays(1)) {
|
|
|
|
int const weekdayId = current.date().dayOfWeek();
|
|
|
|
|
|
|
|
specialDayId = -1;
|
|
|
|
|
|
|
|
// find worktime ranges for the current day
|
|
|
|
int const timeRanges = std::max((int)cfg->WeekDaysWorktime.count(weekdayId), 1);
|
|
|
|
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
|
|
|
int ranges = 0;
|
|
|
|
|
|
|
|
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) {
|
|
|
|
// Set special day price:
|
|
|
|
durationUnit = specialDaysDurationUnit;
|
|
|
|
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
|
|
|
|
SpecialDaysWorkTimeUntil(cfg, specialDayId));
|
|
|
|
ranges = 1;
|
|
|
|
} else {
|
|
|
|
// Set new price for the normal day: do not use a floating-point type
|
|
|
|
// for the price, rather compute with integers. Only at the very end of
|
|
|
|
// the computation the price is divided by durationUnit.
|
|
|
|
price = weekDaysPrice;
|
|
|
|
durationUnit = weekDaysDurationUnit;
|
|
|
|
|
|
|
|
// If no working day found, skip it (epsecially Sundays!)
|
|
|
|
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
|
|
|
|
qDebug() << "No workday found, trying to find next available day";
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime()); // start at midnight on the next day
|
|
|
|
continue;
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
worktime[ranges].setTimeRange(WeekDaysWorkTimeFrom(itr),
|
|
|
|
WeekDaysWorkTimeUntil(itr));
|
|
|
|
ranges += 1;
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
2023-11-28 15:25:37 +01:00
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
2023-11-27 16:21:28 +01:00
|
|
|
|
2023-12-06 10:51:46 +01:00
|
|
|
// qCritical() << "start" << start.toString(Qt::ISODate)
|
|
|
|
// << "current" << current.toString(Qt::ISODate) << lastWorktimeTo;
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
// find worktime range to start with
|
|
|
|
int currentRange = 0;
|
|
|
|
if (!isSpecialDay) {
|
|
|
|
if (start != current) { // on next day
|
|
|
|
current.setTime(worktime[currentRange].getTimeFrom());
|
2023-11-27 16:21:28 +01:00
|
|
|
} else {
|
2023-11-28 15:25:37 +01:00
|
|
|
// check if inputDate is located inside a valid worktime-range...
|
2023-12-05 17:31:56 +01:00
|
|
|
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
|
|
|
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
2023-11-28 15:25:37 +01:00
|
|
|
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
|
|
|
0, Ticket::s[INVALID_FROM_DATETIME]);
|
2023-11-27 16:21:28 +01:00
|
|
|
}
|
2023-11-28 15:25:37 +01:00
|
|
|
// find the next worktime-range (on the same day), and start from there
|
2023-12-05 17:31:56 +01:00
|
|
|
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
|
|
|
end = current;
|
|
|
|
continue;
|
|
|
|
}
|
2023-11-28 15:25:37 +01:00
|
|
|
current.setTime(worktime[currentRange].getTimeFrom());
|
2023-11-27 16:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-28 15:25:37 +01:00
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-12-06 10:51:46 +01:00
|
|
|
// qCritical() << "current" << current.toString(Qt::ISODate);
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
|
|
|
if (durationMinutes > 0) {
|
|
|
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
|
|
|
QTime const &worktime_to = worktime[w].getTimeUntil();
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
if (totalTimeRanges) {
|
|
|
|
// durationMinutes are always meant as netto time and
|
|
|
|
// the time between worktime-ranges are free.
|
|
|
|
current.setTime(worktime_from);
|
|
|
|
}
|
2023-11-27 16:21:28 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
if (price == 0) {
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
2023-11-27 16:21:28 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
if (current.time() == worktime_to) {
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
2023-11-27 16:21:28 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
// Check prepaid
|
|
|
|
if (!prepaid) {
|
|
|
|
if ((current.time() < worktime_from) || (current.time() > worktime_to)) {
|
|
|
|
qDebug() << "[STOP] * Ticket is not valid * ";
|
|
|
|
return Ticket();
|
2023-11-27 16:21:28 +01:00
|
|
|
}
|
|
|
|
} else {
|
2023-12-06 10:51:46 +01:00
|
|
|
//qDebug() << "* PREPAID MODE ACTIVE *";
|
|
|
|
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_from << lastWorktimeTo;
|
2023-11-28 15:25:37 +01:00
|
|
|
if (current.time() < worktime_from) {
|
|
|
|
current.setTime(worktime_from);
|
|
|
|
end = current;
|
|
|
|
} else if(current.time() > lastWorktimeTo) {
|
2023-12-06 10:51:46 +01:00
|
|
|
//qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
2023-11-28 15:25:37 +01:00
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
while(durationMinutes > 0) {
|
|
|
|
// Check for active year period
|
|
|
|
if (!IsYearPeriodActive(cfg, current)) {
|
|
|
|
return Ticket();
|
|
|
|
}
|
|
|
|
if(current.time() >= lastWorktimeTo) {
|
|
|
|
// Go to next day if minutes not spent
|
|
|
|
if (carryOverNotSet) {
|
|
|
|
// no carry_over, so stop computation
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current.setTime(QTime());
|
|
|
|
break; // stop while, and continue in outer loop
|
|
|
|
} else {
|
2023-12-06 10:51:46 +01:00
|
|
|
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_to;
|
2023-11-28 15:25:37 +01:00
|
|
|
if(current.time() < worktime_to) {
|
|
|
|
// Increment input date minutes for each monetary unit
|
|
|
|
current = current.addSecs(60);
|
|
|
|
end = current;
|
|
|
|
durationMinutes -= 1;
|
|
|
|
//costFromDuration += price_per_unit;
|
|
|
|
costFromDuration += price;
|
2023-12-06 10:51:46 +01:00
|
|
|
//qCritical() << "current" << current.toString(Qt::ISODate);
|
2023-11-28 15:25:37 +01:00
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
} // while(durationMinutes > 0) {
|
|
|
|
} // if (durationMinutes > 0) {
|
|
|
|
} // for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
|
|
|
} // for (current = start; durationMinutes > 0; current = current.addDays(1)) {
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-11-28 15:25:37 +01:00
|
|
|
int durationMinutesBrutto = start.secsTo(end) / 60;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2023-11-27 16:21:28 +01:00
|
|
|
return
|
2023-11-28 15:25:37 +01:00
|
|
|
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
2023-12-05 17:31:56 +01:00
|
|
|
ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
2023-11-27 16:21:28 +01:00
|
|
|
Ticket::s[VALID]);
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-28 16:43:03 +01:00
|
|
|
Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
|
|
|
QDateTime const &start,
|
2023-12-01 14:24:15 +01:00
|
|
|
uint32_t cost,
|
2023-11-28 16:43:03 +01:00
|
|
|
bool prepaid) {
|
|
|
|
// Get input date
|
|
|
|
QDateTime current = start;
|
|
|
|
|
|
|
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId);
|
2023-12-12 10:58:08 +01:00
|
|
|
static const uint32_t minParkingTimeMinutes = std::max(Utilities::getMinimalParkingTime(cfg, paymentMethodId), 0);
|
|
|
|
static const uint32_t maxParkingTimeMinutes = std::max(Utilities::getMaximalParkingTime(cfg, paymentMethodId), 0);
|
2023-11-28 16:43:03 +01:00
|
|
|
static const uint32_t minParkingPrice = getMinimalParkingPrice(cfg, paymentMethodId);
|
2023-12-01 14:24:15 +01:00
|
|
|
// static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
|
2023-12-12 10:58:08 +01:00
|
|
|
static const uint32_t weekDaysPrice = Utilities::computeWeekDaysPrice(cfg, paymentMethodId);
|
|
|
|
static const uint32_t weekDaysDurationUnit = Utilities::computeWeekDaysDurationUnit(cfg, paymentMethodId);
|
2023-12-01 14:24:15 +01:00
|
|
|
static const uint32_t specialDaysDurationUnit = 60;
|
2023-11-28 16:43:03 +01:00
|
|
|
|
2023-12-01 14:24:15 +01:00
|
|
|
if(cost < minParkingPrice) {
|
|
|
|
uint64_t const durationMinutes = GetDurationForPrice(cfg, cost);
|
2023-11-28 16:43:03 +01:00
|
|
|
return Ticket(start, current, durationMinutes, durationMinutes,
|
2023-12-01 14:24:15 +01:00
|
|
|
cost, Ticket::s[INVALID_PRICE]);
|
2023-11-28 16:43:03 +01:00
|
|
|
}
|
|
|
|
if (minParkingTimeMinutes >= maxParkingTimeMinutes) {
|
|
|
|
// TODO
|
|
|
|
return Ticket();
|
|
|
|
}
|
|
|
|
if (maxParkingTimeMinutes <= minParkingTimeMinutes) {
|
|
|
|
// TODO
|
|
|
|
return Ticket();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t durationMinutesNetto = 0;
|
2023-12-05 17:31:56 +01:00
|
|
|
double moneyLeft = cost;
|
|
|
|
double durationUnit = 1;
|
2023-11-28 16:43:03 +01:00
|
|
|
int specialDayId = -1;
|
|
|
|
bool isSpecialDay = false;
|
|
|
|
QDateTime end = start;
|
|
|
|
int totalTimeRanges = 0;
|
2023-12-05 17:31:56 +01:00
|
|
|
double price = 0;
|
2023-11-28 16:43:03 +01:00
|
|
|
|
2023-12-05 17:31:56 +01:00
|
|
|
for (current = start; moneyLeft > 0 && moneyLeft >= price; current = current.addDays(1)) {
|
2023-11-28 16:43:03 +01:00
|
|
|
int const weekdayId = current.date().dayOfWeek();
|
|
|
|
|
|
|
|
specialDayId = -1;
|
|
|
|
|
|
|
|
// find worktime ranges for the current day
|
|
|
|
int const timeRanges = std::max((int)cfg->WeekDaysWorktime.count(weekdayId), 1);
|
|
|
|
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
|
|
|
int ranges = 0;
|
|
|
|
|
2023-12-05 17:31:56 +01:00
|
|
|
uint32_t p = 0;
|
|
|
|
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
|
2023-11-28 16:43:03 +01:00
|
|
|
// Set special day price:
|
2023-12-01 14:24:15 +01:00
|
|
|
durationUnit = specialDaysDurationUnit;
|
2023-12-05 17:31:56 +01:00
|
|
|
price = p / durationUnit;
|
|
|
|
price = std::round(price * 1000.0) / 1000.0;
|
2023-11-28 16:43:03 +01:00
|
|
|
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
|
|
|
|
SpecialDaysWorkTimeUntil(cfg, specialDayId));
|
|
|
|
ranges = 1;
|
|
|
|
} else {
|
|
|
|
// Set new price for the normal day: do not use a floating-point type
|
|
|
|
// for the price, rather compute with integers. Only at the very end of
|
|
|
|
// the computation the price is divided by durationUnit.
|
|
|
|
price = weekDaysPrice;
|
2023-12-01 14:24:15 +01:00
|
|
|
durationUnit = weekDaysDurationUnit;
|
2023-12-05 17:31:56 +01:00
|
|
|
price /= durationUnit;
|
|
|
|
price = std::round(price * 1000.0) / 1000.0; // round to 3 decimals
|
2023-11-28 16:43:03 +01:00
|
|
|
|
|
|
|
// If no working day found, skip it (epsecially Sundays!)
|
|
|
|
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
|
2023-12-05 17:31:56 +01:00
|
|
|
// qDebug() << "No workday found, trying to find next available day";
|
2023-11-28 16:43:03 +01:00
|
|
|
end = current;
|
|
|
|
current.setTime(QTime()); // start at midnight on the next day
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
|
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
|
|
|
|
|
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
|
|
|
worktime[ranges].setTimeRange(WeekDaysWorkTimeFrom(itr),
|
|
|
|
WeekDaysWorkTimeUntil(itr));
|
|
|
|
ranges += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
|
|
|
|
|
|
|
// find worktime range to start with
|
|
|
|
int currentRange = 0;
|
|
|
|
if (!isSpecialDay) {
|
|
|
|
if (start != current) { // on next day
|
|
|
|
current.setTime(worktime[currentRange].getTimeFrom());
|
|
|
|
} else {
|
|
|
|
// check if inputDate is located inside a valid worktime-range...
|
2023-12-05 17:31:56 +01:00
|
|
|
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
|
|
|
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
2023-11-28 16:43:03 +01:00
|
|
|
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
|
|
|
0, Ticket::s[INVALID_FROM_DATETIME]);
|
|
|
|
}
|
|
|
|
// find the next worktime-range (on the same day), and start from there
|
2023-12-05 17:31:56 +01:00
|
|
|
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
|
|
|
end = current;
|
|
|
|
continue;
|
|
|
|
}
|
2023-11-28 16:43:03 +01:00
|
|
|
current.setTime(worktime[currentRange].getTimeFrom());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
|
|
|
if (moneyLeft > 0) {
|
|
|
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
|
|
|
QTime const &worktime_to = worktime[w].getTimeUntil();
|
|
|
|
|
|
|
|
if (totalTimeRanges) {
|
|
|
|
// durationMinutes are always meant as netto time and
|
|
|
|
// the time between worktime-ranges are free.
|
|
|
|
current.setTime(worktime_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (price == 0) {
|
|
|
|
// inputDate = inputDate.addDays(1);
|
|
|
|
// inputDate.setTime(worktime_from);
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.time() == worktime_to) {
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check prepaid
|
|
|
|
if (!prepaid) {
|
2024-02-01 13:18:27 +01:00
|
|
|
if (current.time() < worktime_from) {
|
|
|
|
qDebug() << "[STOP] TICKET IS NOT VALID: "
|
|
|
|
<< QString("%1 (current) < %2 (start)")
|
|
|
|
.arg(current.toString(Qt::ISODate)
|
|
|
|
.arg(worktime_from.toString(Qt::ISODate)));
|
|
|
|
return Ticket();
|
|
|
|
} else
|
|
|
|
if (current.time() > worktime_to) {
|
|
|
|
qDebug() << "[STOP] TICKET IS NOT VALID: "
|
|
|
|
<< QString("%1 (current) > %2 (end)")
|
|
|
|
.arg(current.toString(Qt::ISODate)
|
|
|
|
.arg(worktime_to.toString(Qt::ISODate)));
|
2023-11-28 16:43:03 +01:00
|
|
|
return Ticket();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (current.time() < worktime_from) {
|
2024-02-01 13:18:27 +01:00
|
|
|
qDebug() << "*** PREPAID *** Current time is before time range start, fast-forward to start"
|
|
|
|
<< worktime_from.toString(Qt::ISODate);
|
2023-11-28 16:43:03 +01:00
|
|
|
current.setTime(worktime_from);
|
|
|
|
end = current;
|
|
|
|
} else if(current.time() > lastWorktimeTo) {
|
|
|
|
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
|
|
|
end = current;
|
|
|
|
current.setTime(QTime());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 17:31:56 +01:00
|
|
|
while(moneyLeft >= price) {
|
2023-11-28 16:43:03 +01:00
|
|
|
// Check for active year period
|
|
|
|
if (!IsYearPeriodActive(cfg, current)) {
|
|
|
|
return Ticket();
|
|
|
|
}
|
2024-02-01 13:19:08 +01:00
|
|
|
// if(durationMinutesNetto >= maxParkingTimeMinutes) {
|
|
|
|
// might be useful for overpayment
|
|
|
|
// durationMinutesNetto = maxParkingTimeMinutes;
|
|
|
|
// int durationMinutesBrutto = start.secsTo(end) / 60;
|
|
|
|
//
|
|
|
|
// return
|
|
|
|
// Ticket(start, end, durationMinutesNetto,
|
|
|
|
// durationMinutesBrutto, cost, Ticket::s[INVALID_PRICE]);
|
|
|
|
//
|
|
|
|
// }
|
2023-11-28 16:43:03 +01:00
|
|
|
if(current.time() >= lastWorktimeTo) {
|
|
|
|
// Go to next day if minutes not spent
|
|
|
|
if (carryOverNotSet) {
|
|
|
|
// no carry_over, so stop computation
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current.setTime(QTime());
|
|
|
|
break; // stop while, and continue in outer loop
|
|
|
|
} else {
|
|
|
|
if(current.time() < worktime_to) {
|
|
|
|
// Increment input date minutes for each monetary unit
|
2024-02-01 13:19:08 +01:00
|
|
|
durationMinutesNetto += 1;
|
2023-12-05 17:31:56 +01:00
|
|
|
moneyLeft -= price;
|
|
|
|
moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
|
2023-12-01 14:24:15 +01:00
|
|
|
current = current.addSecs(60);
|
2024-02-01 13:19:08 +01:00
|
|
|
|
|
|
|
//qCritical() << "moneyLeft" << moneyLeft
|
|
|
|
// << "durationMinutesNetto" << durationMinutesNetto
|
|
|
|
// << "current" << current.toString(Qt::ISODate);
|
|
|
|
|
|
|
|
if(durationMinutesNetto <= maxParkingTimeMinutes) {
|
|
|
|
// stop updating of end-date if parking time is
|
|
|
|
// overshot
|
|
|
|
end = current;
|
|
|
|
}
|
2023-11-28 16:43:03 +01:00
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
} // while(durationMinutes > 0) {
|
|
|
|
} // if (durationMinutes > 0) {
|
|
|
|
} // for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
|
|
|
} // for (current = start; durationMinutes > 0; current = current.addDays(1)) {
|
|
|
|
|
2024-02-01 13:19:08 +01:00
|
|
|
int durationMinutesBrutto = start.secsTo(end) / 60;
|
2023-11-28 16:43:03 +01:00
|
|
|
|
2023-12-05 17:31:56 +01:00
|
|
|
//qCritical() << "start" << start.toString(Qt::ISODate) << "end"
|
|
|
|
// << end.toString(Qt::ISODate) << durationMinutesBrutto;
|
2023-12-01 14:24:15 +01:00
|
|
|
|
2023-11-28 16:43:03 +01:00
|
|
|
return
|
|
|
|
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
2023-12-01 14:24:15 +01:00
|
|
|
cost, Ticket::s[VALID]);
|
2023-11-28 16:43:03 +01:00
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-01-30 10:25:50 +01:00
|
|
|
QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
|
|
|
|
return QList<int>();
|
|
|
|
}
|
|
|
|
|
2024-07-19 14:10:07 +02:00
|
|
|
|
|
|
|
#define DEBUG_GET_TIME_STEPS (1)
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
|
|
|
|
QDateTime const &s) const {
|
2024-07-24 12:37:29 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
|
|
|
|
}
|
2024-04-12 14:30:04 +02:00
|
|
|
|
|
|
|
if (m_timeSteps.size() > paymentOptionIndex) {
|
2024-07-23 12:51:08 +02:00
|
|
|
|
|
|
|
//if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
|
|
|
|
// return m_timeSteps[paymentOptionIndex];
|
|
|
|
//}
|
|
|
|
|
|
|
|
// recompute time steps
|
|
|
|
m_timeSteps[paymentOptionIndex].clear();
|
|
|
|
|
2024-04-24 13:18:23 +02:00
|
|
|
} else {
|
2024-07-25 09:49:16 +02:00
|
|
|
while (m_timeSteps.size() <= paymentOptionIndex) {
|
|
|
|
m_timeSteps.push_back(QList<int>());
|
|
|
|
}
|
2024-01-23 10:53:26 +01:00
|
|
|
}
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
QDateTime start = s;
|
|
|
|
start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-30 15:39:35 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
|
2024-07-25 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2024-07-30 15:39:35 +02:00
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
|
2024-04-12 14:30:04 +02:00
|
|
|
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
|
|
|
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
|
2024-07-19 14:10:07 +02:00
|
|
|
int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-30 15:39:35 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment method id:" << static_cast<int>(paymentMethodId);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step config:" << pop_time_step_config;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
|
2024-07-22 15:54:36 +02:00
|
|
|
}
|
2024-01-22 15:41:20 +01:00
|
|
|
|
|
|
|
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
2024-01-23 10:53:26 +01:00
|
|
|
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
2024-01-23 09:02:55 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
if (paymentMethodId == PaymentMethod::Progressive) { // e.g. neuhauser kirchdorf (743)
|
|
|
|
std::size_t const s = cfg->TimeRange.size();
|
|
|
|
for (std::size_t id = 1; id <= s; ++id) {
|
|
|
|
int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
|
2024-04-12 14:30:04 +02:00
|
|
|
m_timeSteps[paymentOptionIndex].append(step);
|
2024-02-21 11:16:44 +01:00
|
|
|
}
|
2024-07-26 10:59:45 +02:00
|
|
|
} else
|
|
|
|
if (paymentMethodId == PaymentMethod::Degressive) { // e.g. fuchs, valser alm (fane) (502)
|
|
|
|
// with growing time, the price goes down
|
|
|
|
// for instance: until 13.59: price 8, from 14:00: price 5, then for the next day: 8
|
|
|
|
// for the following days: 8 euros
|
|
|
|
|
2024-07-30 15:39:35 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") degressive:";
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
|
2024-07-26 10:59:45 +02:00
|
|
|
m_timeSteps[paymentOptionIndex].clear();
|
|
|
|
|
|
|
|
// lookup pop_next_id in worktimes;
|
|
|
|
std::optional<QVector<ATBWeekDaysWorktime>> const &w = cfg->getAllWeekDayWorkTimes();
|
|
|
|
if (w.has_value()) {
|
|
|
|
QVector<ATBWeekDaysWorktime> const &vec = w.value();
|
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
//if (pop_carry_over == false) {
|
|
|
|
for (int i = 1; i <= vec.size(); ++i) {
|
|
|
|
QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate);
|
|
|
|
QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to);
|
|
|
|
QTime const &to = QTime::fromString(toStr, Qt::ISODate);
|
|
|
|
|
|
|
|
int weekDayId = vec[i-1].pwd_period_day_in_week_id;
|
|
|
|
if (start.date().dayOfWeek() == weekDayId) {
|
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-29 17:26:53 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate);
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
2024-07-29 17:26:53 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
if (start.time() >= from && start.time() < to) {
|
|
|
|
int runtimeInMinutes = (start.time().secsTo(to) / 60);
|
|
|
|
if (to.hour() == 23 && to.minute() == 59) {
|
|
|
|
runtimeInMinutes += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-29 17:26:53 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex;
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
|
|
|
// m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
int pop_id = vec[i-1].pwd_pop_id;
|
|
|
|
// int pwd_id = vec[i-1].pwd_id;
|
|
|
|
// int pwd_next_id = vec[i-1].pwd_next_id;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-29 17:26:53 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
int price = -1;
|
|
|
|
int durationId = -1;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
durationId = itr->second.pra_payment_unit_id;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
price = itr->second.pra_price;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
duration.pun_duration = runtimeInMinutes;
|
|
|
|
search->second = duration;
|
|
|
|
break;
|
2024-07-29 17:26:53 +02:00
|
|
|
}
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
if (price >= 0 && durationId >= 0) {
|
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-29 17:26:53 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
if (durationId == itr->second.pra_payment_unit_id) {
|
|
|
|
itr->second.pra_price = price;
|
|
|
|
cfg->getPaymentOptions(paymentOptionIndex).pop_min_price = price;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") park min price" << price;
|
|
|
|
break;
|
2024-07-26 10:59:45 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-30 15:39:55 +02:00
|
|
|
}
|
2024-07-29 17:26:53 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
break;
|
|
|
|
} // if (start.time() >= from && start.time() < to) {
|
|
|
|
} // if (start.date().dayOfWeek() == weekDayId) {
|
|
|
|
} // for (int i = 1; i <= vec.size(); ++i) {
|
|
|
|
|
|
|
|
m_timeSteps[paymentOptionIndex].clear();
|
|
|
|
int runtimeInMinutes = 0;
|
|
|
|
for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin();
|
|
|
|
it != cfg->Duration.cend();
|
|
|
|
++it) {
|
|
|
|
runtimeInMinutes += it->second.pun_duration;
|
|
|
|
m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
|
|
|
|
}
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-30 15:39:55 +02:00
|
|
|
//} // if (pop_carry_over == false) {
|
2024-07-29 17:26:53 +02:00
|
|
|
} // if (w.has_value()) {
|
2024-02-21 11:16:44 +01:00
|
|
|
} else {
|
|
|
|
uint16_t timeStepCompensation = 0;
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
|
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
if (pop_carry_over) {
|
2024-04-12 14:30:04 +02:00
|
|
|
int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
|
2024-07-21 20:58:12 +02:00
|
|
|
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
|
2024-07-22 15:54:36 +02:00
|
|
|
int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
|
2024-02-21 11:16:44 +01:00
|
|
|
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
|
|
|
|
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range id:" << pop_carry_over_time_range_id;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over option id:" << pop_carry_over_time_range_id;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
|
|
|
|
}
|
2024-07-21 20:58:12 +02:00
|
|
|
|
|
|
|
int weekDay = start.date().dayOfWeek();
|
|
|
|
QTime const carryOverStart = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
|
|
|
|
QTime const carryOverEnd = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end;
|
2024-07-22 15:54:36 +02:00
|
|
|
int const carryOverDuration = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
|
|
|
|
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start:" << carryOverStart.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over end:" << carryOverEnd.toString(Qt::ISODate);
|
|
|
|
}
|
2024-07-21 20:58:12 +02:00
|
|
|
|
|
|
|
// TODO: reparieren
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
|
|
|
|
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
if (durationId == 1) {
|
|
|
|
QDateTime carryOver = start;
|
|
|
|
carryOver = carryOver.addDays(1);
|
|
|
|
carryOver.setTime(QTime(0, 0, 0));
|
|
|
|
|
|
|
|
int const timeStep = std::ceil(start.secsTo(carryOver) / 60.0);
|
|
|
|
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
|
|
|
qCritical()
|
|
|
|
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
|
|
|
|
.arg(timeStep).arg(duration.pun_duration_min)
|
|
|
|
.arg(timeStep).arg(duration.pun_duration_max);
|
|
|
|
break;
|
|
|
|
}
|
2024-04-12 14:30:04 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
// set dynamic minimal parking time
|
2024-04-24 13:20:02 +02:00
|
|
|
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = timeStep;
|
2024-01-18 14:57:04 +01:00
|
|
|
|
2024-07-16 16:47:26 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
duration.pun_duration = timeStep;
|
|
|
|
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
2024-04-12 14:30:04 +02:00
|
|
|
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
2024-02-21 11:16:44 +01:00
|
|
|
} else {
|
|
|
|
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
2024-07-19 14:10:07 +02:00
|
|
|
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
2024-02-21 11:16:44 +01:00
|
|
|
}
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
cfg->Duration.erase(search);
|
|
|
|
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
2024-01-22 15:41:20 +01:00
|
|
|
|
2024-02-21 11:16:44 +01:00
|
|
|
} else { // if (search != cfg->Duration.end()) {
|
|
|
|
// TODO
|
|
|
|
}
|
2024-01-18 14:57:04 +01:00
|
|
|
}
|
2024-02-21 11:16:44 +01:00
|
|
|
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
2024-07-29 17:26:26 +02:00
|
|
|
//if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-22 15:54:36 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
|
2024-07-29 17:26:26 +02:00
|
|
|
//}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
|
|
|
m_timeSteps[paymentOptionIndex].clear();
|
|
|
|
|
2024-07-21 20:58:12 +02:00
|
|
|
std::optional<QDateTime> prepaidStart = cfg->prepaidStart(start, pop_prepaid_option_id);
|
|
|
|
// TODO: zusaetzlicher faktor falls vorkauf-option zieht
|
|
|
|
if (prepaidStart) {
|
|
|
|
start = prepaidStart.value();
|
2024-07-29 17:26:26 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-22 15:54:36 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid adapted start:" << start.toString(Qt::ISODate);
|
2024-07-29 17:26:26 +02:00
|
|
|
}
|
2024-07-21 20:58:12 +02:00
|
|
|
} else {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
|
|
|
|
}
|
|
|
|
|
2024-07-23 12:51:08 +02:00
|
|
|
// TODO: check if needed
|
2024-07-21 20:58:12 +02:00
|
|
|
QDateTime interpolationEnd;
|
|
|
|
std::optional<QDateTime> interpolationEndDate = cfg->getInterpolationEnd(start, paymentOptionIndex);
|
|
|
|
if (interpolationEndDate) {
|
|
|
|
interpolationEnd = interpolationEndDate.value();
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation end:" << interpolationEnd.toString(Qt::ISODate);
|
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
} else {
|
2024-07-21 20:58:12 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
|
2024-07-19 14:10:07 +02:00
|
|
|
}
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
// int const start_time = start.time().hour() * 60 + start.time().minute();
|
2024-07-21 20:58:12 +02:00
|
|
|
QDateTime nextTimeStep = start;
|
2024-07-22 15:54:36 +02:00
|
|
|
int runtimeInMinutes = 0;
|
|
|
|
|
2024-07-29 17:26:26 +02:00
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
|
2024-07-25 09:49:16 +02:00
|
|
|
|
2024-09-02 17:15:33 +02:00
|
|
|
// int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-23 12:51:08 +02:00
|
|
|
// TODO: auslagern
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
ATBDuration duration = search->second;
|
|
|
|
duration.pun_duration = duration.pun_duration_saved;
|
|
|
|
search->second = duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-19 14:10:07 +02:00
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
2024-07-25 09:49:16 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId;
|
2024-07-19 14:10:07 +02:00
|
|
|
// int const price = itr->second.pra_price;
|
|
|
|
|
|
|
|
auto search = cfg->Duration.find(durationId);
|
|
|
|
if (search != cfg->Duration.end()) {
|
|
|
|
ATBDuration duration = search->second;
|
2024-09-02 17:15:33 +02:00
|
|
|
// ATBDuration &previous = search->second;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
|
|
|
if (duration.pun_interpolation_id == -1) {
|
|
|
|
|
|
|
|
// should never happen -> misconfigured tariff-file
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR pun_interpolation not set!";
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") See for instance customer_505/6";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
|
2024-07-25 09:49:16 +02:00
|
|
|
|
2024-07-19 14:10:07 +02:00
|
|
|
std::optional<ATBInterpolation> ipolCheck = cfg->getInterpolationType(duration.pun_interpolation_id);
|
|
|
|
if (ipolCheck) {
|
|
|
|
ATBInterpolation interpolation = ipolCheck.value();
|
|
|
|
|
2024-07-21 20:58:12 +02:00
|
|
|
if (duration.pun_interpolation_id == (int)ATBInterpolation::DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_PRICE) {
|
2024-07-25 09:49:16 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") HIER NICHT";
|
2024-07-21 20:58:12 +02:00
|
|
|
|
|
|
|
interpolation.dynamic_start = start.time();
|
|
|
|
interpolation.dynamic_start.setHMS(start.time().hour(), start.time().minute(), 0);
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
// int const end_time = interpolation.dynamic_end.hour() * 60 + interpolation.dynamic_end.minute();
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
|
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id;
|
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolationEnd.toString(Qt::ISODate);
|
2024-07-19 14:10:07 +02:00
|
|
|
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time;
|
|
|
|
|
2024-09-02 17:15:33 +02:00
|
|
|
// int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
runtimeInMinutes += duration.pun_duration;
|
|
|
|
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
|
2024-07-21 20:58:12 +02:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (nextTimeStep.time() > carryOverStart) {
|
|
|
|
int const backTime = carryOverStart.secsTo(nextTimeStep.time()) / 60;
|
|
|
|
runtimeInMinutes -= backTime;
|
|
|
|
nextTimeStep.setTime(carryOverStart);
|
|
|
|
nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60);
|
|
|
|
runtimeInMinutes += (backTime + carryOverDuration);
|
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
|
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
int rest = nextTimeStep.secsTo(interpolationEnd);
|
|
|
|
if (nextTimeStep <= interpolationEnd) {
|
|
|
|
if (rest > 0 && rest < duration.pun_duration) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") rest minutes:" << rest;
|
|
|
|
// last time step before switching to dayticket (see Schnals 505/506)
|
|
|
|
//if (duration.pun_duration > 0) {
|
|
|
|
// m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
2024-07-21 20:58:12 +02:00
|
|
|
//}
|
2024-07-22 15:54:36 +02:00
|
|
|
} else {
|
|
|
|
m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
|
|
|
|
}
|
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
duration.pun_duration = runtimeInMinutes;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
search->second = duration;
|
|
|
|
} else
|
|
|
|
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
|
2024-07-25 09:49:16 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (2):" << runtimeInMinutes;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
if (paymentOptionIndex == 1) { // testing TODO: muss in die payment options hinein
|
|
|
|
if (runtimeInMinutes == 0) {
|
|
|
|
if (start.time() < carryOverStart) {
|
|
|
|
runtimeInMinutes = start.time().secsTo(carryOverStart) / 60;
|
|
|
|
duration.pun_duration = runtimeInMinutes;
|
|
|
|
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
|
|
|
search->second = duration;
|
2024-07-29 17:27:16 +02:00
|
|
|
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
|
2024-07-25 09:49:16 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 10:59:45 +02:00
|
|
|
if (runtimeInMinutes == 0) {
|
|
|
|
if (start.time() < carryOverStart) {
|
|
|
|
runtimeInMinutes = start.time().secsTo(carryOverStart) / 60;
|
2024-07-29 17:26:26 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carryOverStart:" << carryOverStart.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
2024-07-26 10:59:45 +02:00
|
|
|
duration.pun_duration = runtimeInMinutes;
|
|
|
|
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
|
|
|
search->second = duration;
|
|
|
|
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
QDateTime s = start.addSecs(runtimeInMinutes * 60);
|
2024-09-02 17:15:33 +02:00
|
|
|
// int const minutes = s.time().secsTo(carryOverStart) / 60;
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
#if 0
|
2024-07-22 15:54:36 +02:00
|
|
|
if (minutes > 0) {
|
|
|
|
runtimeInMinutes += minutes;
|
|
|
|
previous.pun_duration += minutes;
|
2024-07-24 12:37:29 +02:00
|
|
|
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") previous:" << previous.pun_duration;
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
|
|
|
|
m_timeSteps[paymentOptionIndex].last() += minutes;
|
|
|
|
}
|
|
|
|
}
|
2024-07-24 12:37:29 +02:00
|
|
|
#endif
|
2024-07-21 20:58:12 +02:00
|
|
|
|
2024-07-24 12:37:29 +02:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
runtimeInMinutes += duration.pun_duration;
|
|
|
|
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") carryOverStart:" << carryOverStart.toString(Qt::ISODate);
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
|
2024-07-26 17:01:44 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
// TOOO: truncate-flag == false
|
|
|
|
if (nextTimeStep.time() > carryOverStart) {
|
|
|
|
int const backTime = carryOverStart.secsTo(nextTimeStep.time());
|
|
|
|
runtimeInMinutes -= backTime;
|
|
|
|
nextTimeStep.setTime(carryOverStart);
|
|
|
|
nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60);
|
|
|
|
runtimeInMinutes += (backTime + carryOverDuration);
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
|
2024-07-19 14:10:07 +02:00
|
|
|
} else
|
2024-07-22 15:54:36 +02:00
|
|
|
if (nextTimeStep.time() < carryOverStart) {
|
|
|
|
int const forwardTime = nextTimeStep.time().secsTo(carryOverStart) / 60;
|
|
|
|
runtimeInMinutes += forwardTime;
|
|
|
|
nextTimeStep.setTime(carryOverStart);
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
|
2024-07-19 14:10:07 +02:00
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
2024-07-25 09:49:16 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
2024-07-22 15:54:36 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (2):" << runtimeInMinutes;
|
2024-07-29 11:30:00 +02:00
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-26 17:04:33 +02:00
|
|
|
duration.pun_duration = runtimeInMinutes;
|
|
|
|
// duration.pun_duration = runtimeInMinutes - carryOverDuration;
|
2024-07-19 14:10:07 +02:00
|
|
|
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
2024-07-22 15:54:36 +02:00
|
|
|
search->second = duration;
|
2024-07-19 14:10:07 +02:00
|
|
|
} else {
|
2024-07-26 10:59:45 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") HIER NICHT";
|
2024-07-19 14:10:07 +02:00
|
|
|
cfg->Duration.erase(search);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 14:57:04 +01:00
|
|
|
}
|
2024-02-21 11:16:44 +01:00
|
|
|
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
2024-01-18 14:57:04 +01:00
|
|
|
// TODO
|
2024-07-21 20:58:12 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
|
2024-01-18 14:57:04 +01:00
|
|
|
}
|
2024-02-21 11:16:44 +01:00
|
|
|
} else { // if (pop_carry_over) {
|
2024-01-18 14:57:04 +01:00
|
|
|
// TODO
|
2024-07-21 20:58:12 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
|
2024-01-18 14:57:04 +01:00
|
|
|
}
|
2024-01-22 15:41:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
2024-04-12 14:30:04 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
|
2024-01-23 09:02:55 +01:00
|
|
|
|
2024-01-22 15:41:20 +01:00
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
|
|
|
{
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
2024-04-12 14:30:04 +02:00
|
|
|
int size = m_timeSteps.size();
|
|
|
|
|
|
|
|
while (size <= paymentOptionIndex) {
|
|
|
|
m_timeSteps.push_back(QList<int>());
|
|
|
|
size = m_timeSteps.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_timeSteps[paymentOptionIndex] << durationUnit;
|
2024-01-18 14:57:04 +01:00
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2024-07-23 12:51:08 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
|
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
|
2024-01-23 10:53:26 +01:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
|
|
|
|
QDateTime nextTime = s;
|
|
|
|
// nextTime.setTime(QTime(0, 0, 0));
|
|
|
|
int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
|
|
|
|
nextTime = nextTime.addSecs(secs);
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
|
|
|
|
<< i << secs << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
|
2024-07-19 14:10:07 +02:00
|
|
|
|
2024-07-22 15:54:36 +02:00
|
|
|
}
|
2024-07-19 14:10:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-12 14:30:04 +02:00
|
|
|
return m_timeSteps[paymentOptionIndex];
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2024-07-19 14:10:07 +02:00
|
|
|
#undef DEBUG_GET_TIME_STEPS
|
|
|
|
|
2024-04-19 13:33:54 +02:00
|
|
|
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-07-25 09:49:16 +02:00
|
|
|
// test
|
|
|
|
// paymentOptionIndex = 1;
|
|
|
|
|
2024-04-19 13:33:54 +02:00
|
|
|
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
2024-08-02 11:12:07 +02:00
|
|
|
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
|
2024-07-23 11:53:22 +02:00
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
|
|
|
|
|
|
|
uint32_t price = 0;
|
2024-08-02 11:12:07 +02:00
|
|
|
int pun_duration = 0;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-08-02 11:12:07 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
|
2024-07-24 12:37:29 +02:00
|
|
|
|
2023-11-24 13:52:49 +01:00
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
|
|
|
{
|
|
|
|
int const payment_unit_id = itr->second.pra_payment_unit_id;
|
|
|
|
int const pun_id = cfg->Duration.find(payment_unit_id)->second.pun_id;
|
|
|
|
|
|
|
|
Q_ASSERT(pun_id == payment_unit_id);
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
|
2024-07-26 10:59:45 +02:00
|
|
|
|
2024-08-02 11:12:07 +02:00
|
|
|
if (pop_accumulate_durations) {
|
|
|
|
pun_duration += cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
|
|
|
} else {
|
|
|
|
pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
|
|
|
}
|
|
|
|
|
2024-07-23 11:53:22 +02:00
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
price += itr->second.pra_price;
|
|
|
|
} else {
|
|
|
|
price = (uint32_t)(itr->second.pra_price);
|
|
|
|
}
|
|
|
|
|
2024-08-02 11:12:07 +02:00
|
|
|
if (DBG_LEVEL >= DBG_DEBUG) {
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << pun_duration;
|
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
|
|
|
|
}
|
2024-07-24 12:37:29 +02:00
|
|
|
|
2023-11-24 13:52:49 +01:00
|
|
|
if (timeStep == pun_duration) {
|
2024-07-26 10:59:45 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
|
2024-07-23 11:53:22 +02:00
|
|
|
return price;
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
|
|
|
|
int const pop_id = cfg->getPaymentOptions().pop_id;
|
2024-07-26 13:11:29 +02:00
|
|
|
int const pop_accumulate_prices = cfg->getPaymentOptions().pop_accumulate_prices;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") accumulate prices" << pop_accumulate_prices;
|
2024-07-26 13:34:18 +02:00
|
|
|
|
2024-07-26 13:11:29 +02:00
|
|
|
int new_price = 0;
|
2023-11-24 13:52:49 +01:00
|
|
|
uint32_t duration = 0;
|
2024-07-26 12:53:42 +02:00
|
|
|
uint32_t duration_previous = 0;
|
2023-11-24 13:52:49 +01:00
|
|
|
|
|
|
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
|
|
|
{
|
|
|
|
int const durationId = itr->second.pra_payment_unit_id;
|
|
|
|
int const pra_price = itr->second.pra_price;
|
|
|
|
|
|
|
|
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
|
|
|
|
|
|
|
if (pra_price == price) {
|
|
|
|
return durationUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pra_price < price) {
|
|
|
|
duration = durationUnit;
|
|
|
|
}
|
2024-07-26 12:53:42 +02:00
|
|
|
|
|
|
|
if (pop_accumulate_prices) {
|
|
|
|
new_price += pra_price;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pra_price:" << pra_price;
|
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") new_price:" << new_price;
|
2024-07-26 12:53:42 +02:00
|
|
|
if (new_price <= price) {
|
2024-07-26 13:34:18 +02:00
|
|
|
duration_previous = durationUnit;
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
|
2024-07-26 12:53:42 +02:00
|
|
|
} else {
|
2024-07-29 11:30:00 +02:00
|
|
|
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
|
2024-07-26 12:53:42 +02:00
|
|
|
return duration_previous;
|
|
|
|
}
|
|
|
|
}
|
2023-11-24 13:52:49 +01:00
|
|
|
}
|
|
|
|
|
2024-07-29 11:30:00 +02:00
|
|
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration" << duration << "for price" << price;
|
2023-11-24 13:52:49 +01:00
|
|
|
return duration;
|
|
|
|
}
|
2024-01-30 10:26:53 +01:00
|
|
|
|
|
|
|
std::optional<struct price_t>
|
|
|
|
Calculator::GetDailyTicketPrice(Configuration* cfg,
|
|
|
|
QDateTime const &startDatetime,
|
|
|
|
QDateTime &endTime,
|
|
|
|
PERMIT_TYPE permitType) {
|
|
|
|
struct price_t price;
|
|
|
|
std::optional<struct price_t> value;
|
|
|
|
|
|
|
|
std::optional<ATBWeekDaysWorktime> workTime =
|
|
|
|
cfg->getWeekDayWorkTime(startDatetime.time(),
|
|
|
|
(Qt::DayOfWeek)startDatetime.date().dayOfWeek());
|
|
|
|
if (workTime) {
|
|
|
|
ATBWeekDaysWorktime const &wt = workTime.value();
|
|
|
|
endTime = startDatetime;
|
|
|
|
endTime.setTime(QTime::fromString(wt.pwd_time_to.c_str(), Qt::ISODate));
|
|
|
|
std::optional<QVector<ATBDailyTicket>> dailyTickets = cfg->getDailyTicketsForAllKeys();
|
|
|
|
if (dailyTickets) {
|
|
|
|
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
|
|
|
switch (permitType) {
|
2024-06-04 11:18:47 +02:00
|
|
|
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
|
|
|
|
// TODO
|
|
|
|
} break;
|
2024-02-28 12:05:14 +01:00
|
|
|
case PERMIT_TYPE::FOOD_STAMP: {
|
|
|
|
// TODO
|
|
|
|
} break;
|
2024-01-30 10:26:53 +01:00
|
|
|
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
|
|
|
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::ADULT);
|
|
|
|
if (c) {
|
|
|
|
for (QVector<ATBDailyTicket>::size_type i=0; i<tickets.size(); ++i) {
|
|
|
|
if (tickets[i].daily_ticket_clearance_customer_ids.contains(c.value().cust_id)) {
|
|
|
|
int priceId = tickets[i].daily_ticket_price_id;
|
2024-01-31 11:40:41 +01:00
|
|
|
QVector<ATBPaymentOption> const &paymentOptions = cfg->getAllPaymentOptions();
|
|
|
|
for (QVector<ATBPaymentOption>::size_type j=0; j < paymentOptions.size(); ++j) {
|
|
|
|
int const pop_id = paymentOptions.at(j).pop_id;
|
|
|
|
std::optional<QVector<ATBPaymentRate>> const &paymentRates = cfg->getPaymentRateForKey(pop_id);
|
|
|
|
if (paymentRates) {
|
|
|
|
QVector<ATBPaymentRate> const &pr = paymentRates.value();
|
|
|
|
for (QVector<ATBPaymentRate>::size_type k=0; k < pr.size(); ++k) {
|
|
|
|
if (pr.at(k).pra_payment_option_id == pop_id) {
|
|
|
|
if (priceId == pr.at(k).pra_payment_unit_id) {
|
|
|
|
price.netto = pr.at(k).pra_price;
|
|
|
|
value = value.value_or(price);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 10:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::DAY_TICKET_TEEN: {
|
|
|
|
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::TEEN);
|
|
|
|
if (c) {
|
|
|
|
for (QVector<ATBDailyTicket>::size_type i=0; i<tickets.size(); ++i) {
|
|
|
|
if (tickets[i].daily_ticket_clearance_customer_ids.contains(c.value().cust_id)) {
|
|
|
|
int priceId = tickets[i].daily_ticket_price_id;
|
2024-01-31 11:40:41 +01:00
|
|
|
QVector<ATBPaymentOption> const &paymentOptions = cfg->getAllPaymentOptions();
|
|
|
|
for (QVector<ATBPaymentOption>::size_type j=0; j < paymentOptions.size(); ++j) {
|
|
|
|
int const pop_id = paymentOptions.at(j).pop_id;
|
|
|
|
std::optional<QVector<ATBPaymentRate>> const &paymentRates = cfg->getPaymentRateForKey(pop_id);
|
|
|
|
if (paymentRates) {
|
|
|
|
QVector<ATBPaymentRate> const &pr = paymentRates.value();
|
|
|
|
for (QVector<ATBPaymentRate>::size_type k=0; k < pr.size(); ++k) {
|
|
|
|
if (pr.at(k).pra_payment_option_id == pop_id) {
|
|
|
|
if (priceId == pr.at(k).pra_payment_unit_id) {
|
|
|
|
price.netto = pr.at(k).pra_price;
|
|
|
|
value = value.value_or(price);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 10:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::DAY_TICKET_CHILD: {
|
2024-01-31 11:40:41 +01:00
|
|
|
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::CHILD);
|
|
|
|
if (c) {
|
|
|
|
for (QVector<ATBDailyTicket>::size_type i=0; i<tickets.size(); ++i) {
|
|
|
|
if (tickets[i].daily_ticket_clearance_customer_ids.contains(c.value().cust_id)) {
|
|
|
|
int priceId = tickets[i].daily_ticket_price_id;
|
|
|
|
QVector<ATBPaymentOption> const &paymentOptions = cfg->getAllPaymentOptions();
|
|
|
|
for (QVector<ATBPaymentOption>::size_type j=0; j < paymentOptions.size(); ++j) {
|
|
|
|
int const pop_id = paymentOptions.at(j).pop_id;
|
|
|
|
std::optional<QVector<ATBPaymentRate>> const &paymentRates = cfg->getPaymentRateForKey(pop_id);
|
|
|
|
if (paymentRates) {
|
|
|
|
QVector<ATBPaymentRate> const &pr = paymentRates.value();
|
|
|
|
for (QVector<ATBPaymentRate>::size_type k=0; k < pr.size(); ++k) {
|
|
|
|
if (pr.at(k).pra_payment_option_id == pop_id) {
|
|
|
|
if (priceId == pr.at(k).pra_payment_unit_id) {
|
|
|
|
price.netto = pr.at(k).pra_price;
|
|
|
|
value = value.value_or(price);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 10:26:53 +01:00
|
|
|
}
|
|
|
|
// [[fallthrough]];
|
|
|
|
case PERMIT_TYPE::SHORT_TERM_PARKING: {
|
|
|
|
}
|
|
|
|
// [[fallthrough]];
|
|
|
|
case PERMIT_TYPE::DAY_TICKET: {
|
2024-07-25 09:49:16 +02:00
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::DAY_TICKET_PKW: {
|
|
|
|
PermitType const permitType(PERMIT_TYPE::DAY_TICKET_PKW);
|
|
|
|
std::optional<ATBPaymentOption> paymentOption = cfg->getPaymentOptionForKey(permitType.get());
|
|
|
|
if (paymentOption) {
|
|
|
|
ATBPaymentOption option = paymentOption.value();
|
|
|
|
int pop_id = option.pop_id;
|
|
|
|
int pop_daily_card_price = option.pop_daily_card_price;
|
|
|
|
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
|
|
|
|
qCritical() << " PERMIT-TYPE:" << permitType.toString();
|
|
|
|
qCritical() << " option id:" << pop_id;
|
|
|
|
qCritical() << "daily_ticket_card_price:" << pop_daily_card_price;
|
|
|
|
|
|
|
|
price.netto = pop_daily_card_price;
|
|
|
|
value = value.value_or(price);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::DAY_TICKET_BUS: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::DAY_TICKET_CAMPER: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW: {
|
|
|
|
PermitType const permitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
|
|
|
|
std::optional<ATBPaymentOption> paymentOption = cfg->getPaymentOptionForKey(permitType.get());
|
|
|
|
if (paymentOption) {
|
|
|
|
ATBPaymentOption option = paymentOption.value();
|
|
|
|
int pop_id = option.pop_id;
|
|
|
|
int pop_daily_card_price = option.pop_daily_card_price;
|
|
|
|
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
|
|
|
|
qCritical() << " PERMIT-TYPE:" << permitType.toString();
|
|
|
|
qCritical() << " option id:" << pop_id;
|
|
|
|
qCritical() << "daily_ticket_card_price:" << pop_daily_card_price;
|
|
|
|
|
|
|
|
price.netto = pop_daily_card_price;
|
|
|
|
value = value.value_or(price);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::SZEGED_START: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::SZEGED_STOP: {
|
|
|
|
} break;
|
|
|
|
case PERMIT_TYPE::INVALID: {
|
|
|
|
} break;
|
2024-01-30 10:26:53 +01:00
|
|
|
}
|
2024-02-22 16:37:11 +01:00
|
|
|
} else {
|
|
|
|
// for projects which have not defined a daily ticket in their
|
|
|
|
// tariff-files (e.g. szeged)
|
|
|
|
price.netto = cfg->getPaymentOptions().pop_daily_card_price;
|
|
|
|
|
|
|
|
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
|
|
|
|
qCritical() << " start:" << startDatetime.toString(Qt::ISODate);
|
|
|
|
qCritical() << " workTime from:" << QTime::fromString(QString(wt.pwd_time_from.c_str()), Qt::ISODate);
|
|
|
|
qCritical() << " workTime to:" << QTime::fromString(QString(wt.pwd_time_to.c_str()), Qt::ISODate);
|
|
|
|
qCritical() << "daily_ticket_card_price:" << price.netto;
|
|
|
|
|
|
|
|
value = value.value_or(price);
|
2024-01-30 10:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|