diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 5677658..eb0bd2e 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -680,10 +680,31 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // qCritical() << __func__ << __LINE__; cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex); + + int weekDay = start_parking_time.date().dayOfWeek(); + int const pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id; + QTime const carryOverStart = tariff->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; + int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration; + + qCritical() << "LINE" << __LINE__ << "carryStart" << carryOverStart.toString(Qt::ISODate); + qCritical() << "LINE" << __LINE__ << "carryDur" << carryOverDuration; + qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate); + + if (start_parking_time.time() > carryOverStart) { + //int const backTime = carryOverStart.secsTo(start_parking_time.time()) / 60; + //qCritical() << "LINE" << __LINE__ << "backTime" << backTime; + //qCritical() << "LINE" << __LINE__ << "backTime + dur" << backTime + carryOverDuration; + start_parking_time.setTime(carryOverStart); + start_parking_time = start_parking_time.addSecs(carryOverDuration * 60); + } + end_parking_time = start_parking_time.addSecs(netto_parking_time*60); - // qCritical() << "(" << __func__ << ":" << __LINE__ << ")" - // << "end_parking_time" << end_parking_time.toString(Qt::ISODate); + qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time; + qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate); + qCritical() << "(" << __func__ << ":" << __LINE__ << ")" + << "end_parking_time" << end_parking_time.toString(Qt::ISODate); } else { // qCritical() << __func__ << __LINE__; @@ -703,8 +724,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( } // DEBUG - qCritical() << " end_parking_time: " << end_parking_time; - qCritical() << " -> calculated cost (netto): " << cost; + qCritical() << __LINE__ << " end_parking_time: " << end_parking_time; + qCritical() << __LINE__ << " -> calculated cost (netto): " << cost; price->brutto = price->vat = price->vat_percentage = 0; price->units = cost; diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 10ff7c9..2f38e89 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -131,10 +131,11 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, // Get input date QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate); + inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0)); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); - //qCritical() << DBG_HEADER << " start" << inputDate.toString(Qt::ISODate); - //qCritical() << DBG_HEADER << "paymentMethodId" << static_cast(paymentMethodId); + qCritical() << DBG_HEADER << " start" << inputDate.toString(Qt::ISODate); + qCritical() << DBG_HEADER << "paymentMethodId" << static_cast(paymentMethodId); Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate); @@ -161,8 +162,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; if (cost > pop_max_price) { + cost = pop_max_price; qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost; - return CalcState::OVERPAID.toStdString(); + //return CalcState::OVERPAID.toStdString(); } if (cost < pop_min_price) { @@ -172,7 +174,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, // int const pop_pre_paid = 1; + qCritical() << __func__ << __LINE__; + if (prepaid) { + qCritical() << __func__ << __LINE__; // no limits on pre-pay-option, i.e. pre-pay-ranges are exactly // the complements of operational-ranges @@ -180,7 +185,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, // in this case, adapt inputDate accordingly. -// #define DEBUG_GET_DURATION_FROM_COST 1 +#define DEBUG_GET_DURATION_FROM_COST 1 #if DEBUG_GET_DURATION_FROM_COST==1 qCritical() << DBG_HEADER << "PRE-PAID-OPTION: ADAPT-INPUT-DATE" << inputDate.toString(Qt::ISODate); #endif @@ -235,23 +240,33 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, #if DEBUG_GET_DURATION_FROM_COST==1 qCritical() << DBG_HEADER << "(ADAPTED) INPUT-DATE" << inputDate.toString(Qt::ISODate); #endif + qCritical() << __func__ << __LINE__; // 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(); + qCritical() << __func__ << __LINE__ << pwd_period_day_in_week_id; + qCritical() << __func__ << __LINE__ << cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id); + 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"; + qCritical() << __func__ << __LINE__; return ""; } + qCritical() << __func__ << __LINE__; + 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); + //qCritical() << __func__ << pwd_time_from.toString(Qt::ISODate); + //qCritical() << __func__ << pwd_time_to.toString(Qt::ISODate); + //qCritical() << __func__ << inputDate.toString(Qt::ISODate); 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; @@ -263,6 +278,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, qCritical() << DBG_HEADER << "ERROR" << inputDate.toString(Qt::ISODate) << "NOT IN VALID WORKING TIME-RANGE"; + qCritical() << __func__ << __LINE__; return ""; } @@ -271,11 +287,16 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate); #endif + qCritical() << __func__ << __LINE__; int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices; // int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations; int price = 0; + int new_price = 0; int durationInSecs = 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; @@ -285,13 +306,46 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, price = pra_price; } - //qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost; + qCritical() << DBG_HEADER << " PRICE" << price << "COST" << 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; + + if (pop_accumulate_prices) { + uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration; + + new_price += pra_price; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX price:" << price; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") YYYYYY new_price:" << new_price; + if (new_price <= cost) { + duration_previous = durationUnit; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous; + } else { + found = true; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") WWWWWW duration_previous" << duration_previous; + QString s = inputDate.toString(Qt::ISODate); + QDateTime d(QDateTime::fromString(s, Qt::ISODate)); + d = d.addSecs(duration_previous * 60); + qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << d; + return d.toString(Qt::ISODate).toStdString(); + } + } + + //if (price < cost) { + // qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << duration; + // qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << duration.pun_duration; + // QString s = inputDate.toString(Qt::ISODate); + // qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << s; + // QDateTime d(QDateTime::fromString(s, Qt::ISODate)); + // d = d.addSecs(duration.pun_duration * 60); + // qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << d; + // return d.toString(Qt::ISODate).toStdString(); +// + // } + //if (pop_accumulate_durations) { // durationInSecs += duration.pun_duration * 60; //} else { @@ -299,6 +353,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, //} if ((double)price == cost) { + qCritical() << DBG_HEADER; QDateTime current_working_date_time_to = inputDate; current_working_date_time_to.setTime(current_working_time_to); @@ -347,13 +402,25 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, } } + qCritical() << DBG_HEADER << "DAYS" << days; + qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs; + qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60; + QDateTime upper = inputDate.addDays(days); upper.setTime(next_working_time_from); + qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate); + QDateTime lower = inputDate; lower.setTime(current_working_time_to); - inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs); + qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate); + + inputDate = inputDate.addSecs(lower.secsTo(upper)); + + qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate); + + inputDate = inputDate.addSecs(durationInSecs); #if DEBUG_GET_DURATION_FROM_COST==1 qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate); #endif @@ -382,14 +449,21 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, } + qCritical() << __func__ << __LINE__; QString const &s = inputDate.toString(Qt::ISODate); #if DEBUG_GET_DURATION_FROM_COST==1 qCritical() << DBG_HEADER << "TICKET-END" << s; #endif + qCritical() << __func__ << __LINE__ << s; return s.toStdString(); } // if ((double)price == cost) { + else { + qCritical() << DBG_HEADER; + } + } else { + qCritical() << __func__ << __LINE__; } } @@ -2412,9 +2486,9 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, // TODO: zusaetzlicher faktor falls vorkauf-option zieht if (prepaidStart) { start = prepaidStart.value(); - if (DBG_LEVEL >= DBG_DEBUG) { + //if (DBG_LEVEL >= DBG_DEBUG) { qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid adapted start:" << start.toString(Qt::ISODate); - } + //} } else { qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO"; } @@ -2554,6 +2628,8 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, if (runtimeInMinutes == 0) { if (start.time() < carryOverStart) { runtimeInMinutes = start.time().secsTo(carryOverStart) / 60; + 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; duration.pun_duration = runtimeInMinutes; @@ -2588,6 +2664,9 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, runtimeInMinutes += duration.pun_duration; nextTimeStep = start.addSecs(runtimeInMinutes * 60); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") carryOverStart:" << carryOverStart.toString(Qt::ISODate); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate); + // TOOO: truncate-flag == false if (nextTimeStep.time() > carryOverStart) { int const backTime = carryOverStart.secsTo(nextTimeStep.time()); @@ -2595,11 +2674,15 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, nextTimeStep.setTime(carryOverStart); nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60); runtimeInMinutes += (backTime + carryOverDuration); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate); } else if (nextTimeStep.time() < carryOverStart) { int const forwardTime = nextTimeStep.time().secsTo(carryOverStart) / 60; runtimeInMinutes += forwardTime; nextTimeStep.setTime(carryOverStart); + qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate); } //if (DBG_LEVEL >= DBG_DEBUG) { @@ -2610,6 +2693,7 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, //} duration.pun_duration = runtimeInMinutes; + // duration.pun_duration = runtimeInMinutes - carryOverDuration; m_timeSteps[paymentOptionIndex] << duration.pun_duration; search->second = duration; } else {