Compare commits
	
		
			45 Commits
		
	
	
		
			fuchs-mueh
			...
			kleipeda-e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7c0514e241 | |||
| f53e9ceaae | |||
| dffc6e2a03 | |||
| f9cc3af473 | |||
| 9dd0108731 | |||
| fa10ea4b89 | |||
| 05f03a623b | |||
| 03e9076962 | |||
| 5dbd3645c6 | |||
| d21f69cb9b | |||
| e38a1bfe12 | |||
| f38a8d528c | |||
| 08a593eb12 | |||
| f322d30e36 | |||
| 7a53a68850 | |||
| 275c3ec869 | |||
| 6d2bde1fe9 | |||
| f02521d3c2 | |||
| 75f1c1bb76 | |||
| f47695de8b | |||
| cce3db301b | |||
| 5cab0de9fb | |||
| f92906f680 | |||
| 8cdeef26fc | |||
| 52ebbf7bc9 | |||
| 349e9d8b06 | |||
| 68a1c24861 | |||
| c946c106d1 | |||
| f24f1fe646 | |||
| c6b8a37263 | |||
| 58d8f16681 | |||
| 431664d8b9 | |||
| 53cf9a7341 | |||
| 3a18ee2d7c | |||
| 929a8a4a27 | |||
| 2b9657787d | |||
| eca285cc25 | |||
| bda8914f1a | |||
| a3983ed427 | |||
| f8805e9e78 | |||
| 7a6360f392 | |||
| 08a249f393 | |||
| 7c173ae292 | |||
| 80637260f3 | |||
| 9b524d63e5 | 
@@ -3,6 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <optional>
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include "configuration.h"
 | 
			
		||||
#include "calculate_price.h"
 | 
			
		||||
@@ -70,7 +71,8 @@ public:
 | 
			
		||||
	/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z)</param>
 | 
			
		||||
	/// <param name="price"></param>
 | 
			
		||||
	/// <returns>Returns duration in seconds (data type: double)</returns>
 | 
			
		||||
    std::string GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
 | 
			
		||||
    std::pair<std::string, QDateTime>
 | 
			
		||||
        GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
 | 
			
		||||
                                    PermitType permitType, bool nextDay = false, bool prepaid = false);
 | 
			
		||||
 | 
			
		||||
	/// <summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,6 @@
 | 
			
		||||
#include "tariff_interpolation.h"
 | 
			
		||||
#include "tariff_prepaid.h"
 | 
			
		||||
#include "tariff_carryover.h"
 | 
			
		||||
#include "tariff_prepay.h"
 | 
			
		||||
#include "tariff_permit_type.h"
 | 
			
		||||
 | 
			
		||||
#include <QVector>
 | 
			
		||||
@@ -37,6 +36,7 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace rapidjson;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Calculator;
 | 
			
		||||
class Configuration
 | 
			
		||||
{
 | 
			
		||||
@@ -48,7 +48,6 @@ public:
 | 
			
		||||
    using ATBPaymentOptionType = std::multimap<int, ATBPaymentOption>;
 | 
			
		||||
    using TariffInterpolationType = std::multimap<int, ATBInterpolation>;
 | 
			
		||||
    using TariffPrepaidType = std::multimap<int, ATBPrepaid>;
 | 
			
		||||
    using TariffPrepayOptionType = std::multimap<int, ATBPrepay>;
 | 
			
		||||
    using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
 | 
			
		||||
    using TariffDurationType = std::multimap<int, ATBDuration>;
 | 
			
		||||
 | 
			
		||||
@@ -61,7 +60,7 @@ public:
 | 
			
		||||
	multimap<int, ATBPaymentRate> PaymentRate;
 | 
			
		||||
	SpecialDaysWorktimeType SpecialDaysWorktime;
 | 
			
		||||
	SpecialDaysType SpecialDays;
 | 
			
		||||
	multimap<int, ATBWeekDays> WeekDays;
 | 
			
		||||
    multimap<Qt::DayOfWeek, ATBWeekDay> WeekDays;
 | 
			
		||||
	multimap<int, ATBPeriodYear> YearPeriod;
 | 
			
		||||
	multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
 | 
			
		||||
	ATBPaymentOptionType PaymentOption;
 | 
			
		||||
@@ -73,7 +72,6 @@ public:
 | 
			
		||||
	TariffProductType TariffProduct;
 | 
			
		||||
	TariffInterpolationType TariffInterpolations;
 | 
			
		||||
	TariffPrepaidType TariffPrepaidOptions;
 | 
			
		||||
	TariffPrepayOptionType TariffPrepayOptions;
 | 
			
		||||
	TariffCarryOverType TariffCarryOverOptions;
 | 
			
		||||
 | 
			
		||||
	/// <summary>
 | 
			
		||||
@@ -129,3 +127,15 @@ private:
 | 
			
		||||
 | 
			
		||||
	QVector<ATBPaymentOption> currentPaymentOptions;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t);
 | 
			
		||||
bool isHoliday(Configuration const &cfg, QDateTime const &t);
 | 
			
		||||
int getPaymentOptionIndex(Configuration const &cfg, QDateTime const& dt = QDateTime::currentDateTime());
 | 
			
		||||
 | 
			
		||||
ATBWeekDay parseWeekDay(Configuration &cfg,
 | 
			
		||||
                        rapidjson::GenericMemberIterator<false,
 | 
			
		||||
                                                         rapidjson::UTF8<char>,
 | 
			
		||||
                                                         rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> k,
 | 
			
		||||
                        QString const &innerObjName,
 | 
			
		||||
                        Qt::DayOfWeek weekDay,
 | 
			
		||||
                        QString const &weekDayName);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
 | 
			
		||||
class ATBDuration
 | 
			
		||||
{
 | 
			
		||||
@@ -13,15 +12,7 @@ public:
 | 
			
		||||
      , pun_duration_saved(0)
 | 
			
		||||
      , pun_duration_min(0)
 | 
			
		||||
      , pun_duration_max(0)
 | 
			
		||||
      , pun_interpolation_id(-1)
 | 
			
		||||
      , pun_netto(false)
 | 
			
		||||
      , pun_brutto(false)
 | 
			
		||||
      , pun_fixed(false)
 | 
			
		||||
      , pun_mutable(false)
 | 
			
		||||
      , pun_round_to_next_24h_boundary(false)
 | 
			
		||||
      , pun_round_to_prev_24h_boundary(false)
 | 
			
		||||
      , pun_align_with_timepoint(QDateTime())
 | 
			
		||||
      , pun_next_step_correction(0) {
 | 
			
		||||
      , pun_interpolation_id(-1) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBDuration const &td) {
 | 
			
		||||
@@ -34,14 +25,7 @@ public:
 | 
			
		||||
            << "  pun_duration_saved: " << td.pun_duration_saved << "\n"
 | 
			
		||||
            << "    pun_duration_min: " << td.pun_duration_min << "\n"
 | 
			
		||||
            << "    pun_duration_max: " << td.pun_duration_max << "\n"
 | 
			
		||||
            << "          pun_interpolation_id: " << td.pun_interpolation_id << "\n"
 | 
			
		||||
            << "                     pun_netto: " << td.pun_netto << "\n"
 | 
			
		||||
            << "                    pun_brutto: " << td.pun_brutto << "\n"
 | 
			
		||||
            << "                     pun_fixed: " << td.pun_fixed << "\n"
 | 
			
		||||
            << "                   pun_mutable: " << td.pun_mutable << "\n"
 | 
			
		||||
            << "pun_round_to_next_24h_boundary: " << td.pun_round_to_next_24h_boundary << "\n"
 | 
			
		||||
            << "pun_round_to_prev_24h_boundary: " << td.pun_round_to_prev_24h_boundary << "\n"
 | 
			
		||||
            << "      pun_align_with_timepoint: " << td.pun_align_with_timepoint << endl;
 | 
			
		||||
            << "pun_interpolation_id: " << td.pun_interpolation_id << "\n";
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
@@ -53,12 +37,4 @@ public:
 | 
			
		||||
    int pun_duration_min;
 | 
			
		||||
    int pun_duration_max;
 | 
			
		||||
    int pun_interpolation_id;
 | 
			
		||||
	bool pun_netto;             // the timestep expressed by this duration is a netto timestep
 | 
			
		||||
	bool pun_brutto;            // the timestep expressed by this duration is a brutto timestep
 | 
			
		||||
	bool pun_fixed;             // the value given in tariff-file is fixed (constant)
 | 
			
		||||
	bool pun_mutable;           // the value could change
 | 
			
		||||
	bool pun_round_to_next_24h_boundary;
 | 
			
		||||
	bool pun_round_to_prev_24h_boundary;
 | 
			
		||||
	QDateTime pun_align_with_timepoint;
 | 
			
		||||
	int pun_next_step_correction;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,8 @@ enum MemberType
 | 
			
		||||
    TimeStepConfigType = 0x0E,
 | 
			
		||||
    ProductType = 0x0F,
 | 
			
		||||
    InterpolationType = 0x10,
 | 
			
		||||
	PrepaidType = 0x11, // deprecated
 | 
			
		||||
	CarryOverType = 0x12,
 | 
			
		||||
	PrepaidOptionType = 0x13,
 | 
			
		||||
    PrepaidType = 0x11,
 | 
			
		||||
    CarryOverType = 0x12
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MEMBER_TYPE_H_INCLUDED
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,6 @@ public:
 | 
			
		||||
        pop_carry_over = -1;
 | 
			
		||||
        pop_carry_over_option_id = -1;
 | 
			
		||||
        pop_prepaid_option_id = -1;
 | 
			
		||||
        pop_prepay_option_id = -1;
 | 
			
		||||
        pop_truncate_last_interpolation_step = false;
 | 
			
		||||
        pop_accumulate_prices = false;
 | 
			
		||||
        pop_accumulate_durations = false;
 | 
			
		||||
@@ -42,7 +41,10 @@ public:
 | 
			
		||||
        pop_use_only_upto_datetime = ""; // deprecated
 | 
			
		||||
        pop_use_only_for_duration = 0;   // deprecated
 | 
			
		||||
        pop_plus_steps = 1;  // +: jump <x=1> steps forward
 | 
			
		||||
        pop_plus_steps_saved = 1;
 | 
			
		||||
        pop_minus_steps = 1; // -: jump <x=1> steps backward
 | 
			
		||||
        pop_allow_overpay = false;
 | 
			
		||||
        pop_apply_carry_over_to_ticket_endtime = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int pop_id;
 | 
			
		||||
@@ -62,8 +64,7 @@ public:
 | 
			
		||||
    int pop_carry_over;
 | 
			
		||||
    int pop_carry_over_option_id;
 | 
			
		||||
    bool pop_truncate_last_interpolation_step;
 | 
			
		||||
    int pop_prepaid_option_id; // deprecated
 | 
			
		||||
    int pop_prepay_option_id;
 | 
			
		||||
    int pop_prepaid_option_id;
 | 
			
		||||
    bool pop_carry_over_target;
 | 
			
		||||
    int pop_carry_over_time_range_id;
 | 
			
		||||
    int pop_carry_over_start_time_range;
 | 
			
		||||
@@ -74,7 +75,10 @@ public:
 | 
			
		||||
    bool pop_accumulate_prices;
 | 
			
		||||
    bool pop_accumulate_durations;
 | 
			
		||||
    int pop_plus_steps;
 | 
			
		||||
    int pop_plus_steps_saved;
 | 
			
		||||
    int pop_minus_steps;
 | 
			
		||||
    bool pop_allow_overpay;
 | 
			
		||||
    bool pop_apply_carry_over_to_ticket_endtime;
 | 
			
		||||
 | 
			
		||||
    struct ATBMaxDateTime {
 | 
			
		||||
        int direction;
 | 
			
		||||
 
 | 
			
		||||
@@ -9,4 +9,8 @@ public:
 | 
			
		||||
	std::string pedwt_time_from;
 | 
			
		||||
	std::string pedwt_time_to;
 | 
			
		||||
    double pedwt_price;
 | 
			
		||||
    int pedwt_paid; // 00: not paid (i.e. free)
 | 
			
		||||
                    // 01: not paid in winter term, piad in summer term
 | 
			
		||||
                    // 10: paid in winter term, not paid in summer term
 | 
			
		||||
                    // 11: paid in winter and in summer term
 | 
			
		||||
};
 | 
			
		||||
@@ -15,6 +15,19 @@ struct ATBCarryOver {
 | 
			
		||||
 | 
			
		||||
    int id;
 | 
			
		||||
 | 
			
		||||
    explicit ATBCarryOver()
 | 
			
		||||
      : id(-1) {
 | 
			
		||||
 | 
			
		||||
        for (int i = 0 ; i < 8; ++i) {
 | 
			
		||||
            carryover[i].day = -1;
 | 
			
		||||
            carryover[i].seemless = false;
 | 
			
		||||
            carryover[i].never = false;
 | 
			
		||||
            carryover[i].static_start = QTime(23, 59, 59);
 | 
			
		||||
            carryover[i].static_end = QTime(0, 0, 0);
 | 
			
		||||
            carryover[i].duration = -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBCarryOver const &co) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
@@ -31,21 +44,21 @@ struct ATBCarryOver {
 | 
			
		||||
            << "                day: " << co.carryover[(int)Qt::Tuesday].day << "\n"
 | 
			
		||||
            << "       static_start: " << co.carryover[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << co.carryover[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Tuesday].duration << "\n"
 | 
			
		||||
            << "            anytime: " << co.carryover[(int)Qt::Tuesday].seemless << "\n"
 | 
			
		||||
            << "              never: " << co.carryover[(int)Qt::Tuesday].never << "\n"
 | 
			
		||||
            << "        **** Wednesday **** \n"
 | 
			
		||||
            << "                day: " << co.carryover[(int)Qt::Wednesday].day << "\n"
 | 
			
		||||
            << "       static_start: " << co.carryover[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << co.carryover[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Wednesday].duration << "\n"
 | 
			
		||||
            << "            anytime: " << co.carryover[(int)Qt::Wednesday].seemless << "\n"
 | 
			
		||||
            << "              never: " << co.carryover[(int)Qt::Wednesday].never << "\n"
 | 
			
		||||
            << "        **** Thursday **** \n"
 | 
			
		||||
            << "                day: " << co.carryover[(int)Qt::Thursday].day << "\n"
 | 
			
		||||
            << "       static_start: " << co.carryover[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << co.carryover[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Thursday].duration << "\n"
 | 
			
		||||
            << "            anytime: " << co.carryover[(int)Qt::Thursday].seemless << "\n"
 | 
			
		||||
            << "              never: " << co.carryover[(int)Qt::Thursday].never << "\n"
 | 
			
		||||
            << "        **** Friday **** \n"
 | 
			
		||||
@@ -58,14 +71,14 @@ struct ATBCarryOver {
 | 
			
		||||
            << "                day: " << co.carryover[(int)Qt::Saturday].day << "\n"
 | 
			
		||||
            << "       static_start: " << co.carryover[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << co.carryover[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Saturday].duration << "\n"
 | 
			
		||||
            << "            anytime: " << co.carryover[(int)Qt::Saturday].seemless << "\n"
 | 
			
		||||
            << "              never: " << co.carryover[(int)Qt::Saturday].never << "\n"
 | 
			
		||||
            << "        **** Sunday **** \n"
 | 
			
		||||
            << "                day: " << co.carryover[(int)Qt::Sunday].day << "\n"
 | 
			
		||||
            << "       static_start: " << co.carryover[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << co.carryover[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "           duration: " << co.carryover[(int)Qt::Sunday].duration << "\n"
 | 
			
		||||
            << "            anytime: " << co.carryover[(int)Qt::Sunday].seemless << "\n"
 | 
			
		||||
            << "              never: " << co.carryover[(int)Qt::Sunday].never << "\n";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										69
									
								
								library/include/mobilisis/tariff_carryover_settings.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								library/include/mobilisis/tariff_carryover_settings.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
#ifndef ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED
 | 
			
		||||
#define ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
 | 
			
		||||
#include <functional>
 | 
			
		||||
 | 
			
		||||
struct ATBTariffCarryOverSettings {
 | 
			
		||||
 | 
			
		||||
    // parking time limit not violated: return false, otherwise: return true.
 | 
			
		||||
    using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
 | 
			
		||||
                                                       QDateTime const &startTime,
 | 
			
		||||
                                                       QDateTime const &endTime,
 | 
			
		||||
                                                       int paymentOptionIndex)>;
 | 
			
		||||
 | 
			
		||||
    int m_duration;
 | 
			
		||||
    QTime m_start;
 | 
			
		||||
    QTime m_end;
 | 
			
		||||
    ParkingTimeLimitChecker m_parkingTimeLimitChecker;
 | 
			
		||||
 | 
			
		||||
    QTime m_parking_time_limit;
 | 
			
		||||
    QTime m_about_to_exceed_parking_time_limit;
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffCarryOverSettings()
 | 
			
		||||
      : m_duration(0)
 | 
			
		||||
      , m_start(QTime())
 | 
			
		||||
      , m_end(QTime())
 | 
			
		||||
      , m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&,
 | 
			
		||||
                                  QDateTime const&, QDateTime const&, int) { return false; })
 | 
			
		||||
      , m_parking_time_limit(QTime())
 | 
			
		||||
      , m_about_to_exceed_parking_time_limit(QTime()) {}
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffCarryOverSettings(int duration, QTime const &start,
 | 
			
		||||
                                        QTime const &end,
 | 
			
		||||
                                        QTime const &parking_time_limit,
 | 
			
		||||
                                        QTime const &about_to_exceed_parking_time_limit,
 | 
			
		||||
                                        ParkingTimeLimitChecker parkingTimeLimitChecker)
 | 
			
		||||
      : m_duration(duration)
 | 
			
		||||
      , m_start(start)
 | 
			
		||||
      , m_end(end)
 | 
			
		||||
      , m_parkingTimeLimitChecker(std::move(parkingTimeLimitChecker))
 | 
			
		||||
      , m_parking_time_limit(parking_time_limit)
 | 
			
		||||
      , m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool parkingTimeLimitExceeded(QDateTime const &startTime,
 | 
			
		||||
                                  QDateTime const &endTime,
 | 
			
		||||
                                  int paymentOptionIndex) const {
 | 
			
		||||
        return m_parkingTimeLimitChecker(*this, startTime, endTime, paymentOptionIndex);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QTime const &parkingTimeLimit() const { return m_parking_time_limit; }
 | 
			
		||||
    QTime &parkingTimeLimit() { return m_parking_time_limit; }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "                 duration: " << co.m_duration << "\n"
 | 
			
		||||
            << "                    start: " << co.m_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "                      end: " << co.m_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "       parking_time_limit: " << co.m_parking_time_limit.toString(Qt::ISODate) << endl;
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED
 | 
			
		||||
@@ -14,6 +14,8 @@
 | 
			
		||||
void setDebugLevel(int level);
 | 
			
		||||
int getDebugLevel();
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
 | 
			
		||||
static void print() {
 | 
			
		||||
    std::cerr << "\n";
 | 
			
		||||
    if (getDebugLevel() == DBG_LEVEL_FATAL) {
 | 
			
		||||
@@ -75,4 +77,6 @@ static void LOG_FATAL(const Arg1& arg1, const Args&&... args) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif //  TARIFF_LOG_INCLUDED_H
 | 
			
		||||
 
 | 
			
		||||
@@ -5,13 +5,34 @@
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
struct ATBPrepaid {
 | 
			
		||||
    explicit ATBPrepaid() = default;
 | 
			
		||||
    int id;
 | 
			
		||||
    bool anytime;
 | 
			
		||||
    bool never;
 | 
			
		||||
    QTime static_start;
 | 
			
		||||
    QTime static_end;
 | 
			
		||||
 | 
			
		||||
    struct week {
 | 
			
		||||
        int day;
 | 
			
		||||
        QTime static_start;
 | 
			
		||||
        QTime static_end;
 | 
			
		||||
        int duration;
 | 
			
		||||
    } prepaid[8];
 | 
			
		||||
 | 
			
		||||
    explicit ATBPrepaid()
 | 
			
		||||
      : id(-1)
 | 
			
		||||
      , anytime(false)
 | 
			
		||||
      , never(false)
 | 
			
		||||
      , static_start(QTime(23, 59, 59))
 | 
			
		||||
      , static_end(QTime(0, 0, 0)) {
 | 
			
		||||
 | 
			
		||||
        for (int i = 0 ; i < 8; ++i) {
 | 
			
		||||
            prepaid[i].day = -1;
 | 
			
		||||
            prepaid[i].static_start = QTime(23, 59, 59);
 | 
			
		||||
            prepaid[i].static_end = QTime(0, 0, 0);
 | 
			
		||||
            prepaid[i].duration = -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBPrepaid const &pp) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
@@ -20,7 +41,41 @@ struct ATBPrepaid {
 | 
			
		||||
            << "       static_start: " << pp.static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "            anytime: " << pp.anytime << "\n"
 | 
			
		||||
            << "              never: " << pp.never << "\n";
 | 
			
		||||
            << "              never: " << pp.never << "\n"
 | 
			
		||||
            << "        **** Monday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Monday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Monday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Monday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "        **** Tuesday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Tuesday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Tuesday].duration << "\n"
 | 
			
		||||
            << "        **** Wednesday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Wednesday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Wednesday].duration << "\n"
 | 
			
		||||
            << "        **** Thursday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Thursday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Thursday].duration << "\n"
 | 
			
		||||
            << "        **** Friday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Friday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Friday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Friday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "        **** Saturday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Saturday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Saturday].duration << "\n"
 | 
			
		||||
            << "        **** Sunday **** \n"
 | 
			
		||||
            << "                day: " << pp.prepaid[(int)Qt::Sunday].day << "\n"
 | 
			
		||||
            << "       static_start: " << pp.prepaid[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         static_end: " << pp.prepaid[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "           duration: " << pp.prepaid[(int)Qt::Sunday].duration << "\n";
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,68 +0,0 @@
 | 
			
		||||
#ifndef TARIFF_PREPAY_H_INCLUDED
 | 
			
		||||
#define TARIFF_PREPAY_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QTime>
 | 
			
		||||
 | 
			
		||||
struct ATBPrepay {
 | 
			
		||||
    struct week {
 | 
			
		||||
        int day;
 | 
			
		||||
        bool prepaid;       // yes/no
 | 
			
		||||
        QTime start; // only valid if prepaid == true
 | 
			
		||||
        QTime end;
 | 
			
		||||
        int duration;
 | 
			
		||||
    } prepay[8];
 | 
			
		||||
 | 
			
		||||
    int id;
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBPrepay const &pp) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "          id:" << pp.id << "\n"
 | 
			
		||||
            << "        **** Monday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Monday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Monday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Monday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Monday].prepaid << "\n"
 | 
			
		||||
            << "        **** Tuesday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Tuesday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Tuesday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Tuesday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Tuesday].prepaid << "\n"
 | 
			
		||||
            << "        **** Wednesday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Wednesday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Wednesday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Wednesday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Wednesday].prepaid << "\n"
 | 
			
		||||
            << "        **** Thursday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Thursday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Thursday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Thursday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Thursday].prepaid << "\n"
 | 
			
		||||
            << "        **** Friday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Friday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Friday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Friday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Friday].prepaid << "\n"
 | 
			
		||||
            << "        **** Saturday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Saturday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Saturday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Saturday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Saturday].prepaid << "\n"
 | 
			
		||||
            << "        **** Sunday **** \n"
 | 
			
		||||
            << "         day: " << pp.prepay[(int)Qt::Sunday].day << "\n"
 | 
			
		||||
            << "       start: " << pp.prepay[(int)Qt::Sunday].start.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "         end: " << pp.prepay[(int)Qt::Sunday].end.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "    duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
 | 
			
		||||
            << "     prepaid: " << pp.prepay[(int)Qt::Sunday].prepaid << "\n";
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TARIFF_CARRYOVER_H_INCLUDED
 | 
			
		||||
							
								
								
									
										40
									
								
								library/include/mobilisis/tariff_settings.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								library/include/mobilisis/tariff_settings.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
#ifndef ATB_TARIFF_SETTINGS_H_INCLUDED
 | 
			
		||||
#define ATB_TARIFF_SETTINGS_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
struct ATBTariffSettings {
 | 
			
		||||
    int m_max_price;
 | 
			
		||||
    int m_min_price;
 | 
			
		||||
    int m_max_time;
 | 
			
		||||
    int m_min_time;
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffSettings()
 | 
			
		||||
      : m_max_price(0)
 | 
			
		||||
      , m_min_price(0)
 | 
			
		||||
      , m_max_time(0)
 | 
			
		||||
      , m_min_time(0) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffSettings(int max_price, int min_price, int max_time, int min_time)
 | 
			
		||||
      : m_max_price(max_price)
 | 
			
		||||
      , m_min_price(min_price)
 | 
			
		||||
      , m_max_time(max_time)
 | 
			
		||||
      , m_min_time(min_time) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBTariffSettings const &ts) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "                max_price: " << ts.m_max_price << "\n"
 | 
			
		||||
            << "                min_price: " << ts.m_min_price << "\n"
 | 
			
		||||
            << "                 max_time: " << ts.m_max_time << "\n"
 | 
			
		||||
            << "                 min_time: " << ts.m_min_time << endl;
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // ATB_TARIFF_SETTINGS_H_INCLUDED
 | 
			
		||||
@@ -6,7 +6,7 @@
 | 
			
		||||
#include <QDebugStateSaver>
 | 
			
		||||
 | 
			
		||||
struct ATBTimeStepConfig {
 | 
			
		||||
    enum class TimeStepConfig {STATIC=1, DYNAMIC=2, RECOMPUTE_SOME=3};
 | 
			
		||||
    enum class TimeStepConfig {STATIC=1, DYNAMIC=2};
 | 
			
		||||
 | 
			
		||||
    ATBTimeStepConfig() = default;
 | 
			
		||||
    int tsconfig_id;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,57 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
#include "tariff_settings.h"
 | 
			
		||||
#include "tariff_carryover_settings.h"
 | 
			
		||||
 | 
			
		||||
class ATBWeekDays
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	int pdiw_id;
 | 
			
		||||
	std::string pdiw_label;
 | 
			
		||||
	int pdiw_index;
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <Qt>
 | 
			
		||||
#include <QDate>
 | 
			
		||||
 | 
			
		||||
struct ATBWeekDay {
 | 
			
		||||
    enum WeekDayType {USUAL_WEEKDAY=0, HOLIDAY=1};
 | 
			
		||||
 | 
			
		||||
    Qt::DayOfWeek m_id;
 | 
			
		||||
    QString m_name;
 | 
			
		||||
    QDate m_date;
 | 
			
		||||
    WeekDayType m_type;
 | 
			
		||||
    ATBTariffSettings m_tariffSettings;
 | 
			
		||||
    ATBTariffCarryOverSettings m_tariffCarryOverSettings;
 | 
			
		||||
 | 
			
		||||
    explicit ATBWeekDay()
 | 
			
		||||
        : m_id(Qt::Monday)
 | 
			
		||||
        , m_name("")
 | 
			
		||||
        , m_date(QDate())
 | 
			
		||||
        , m_type(USUAL_WEEKDAY)
 | 
			
		||||
        , m_tariffSettings()
 | 
			
		||||
        , m_tariffCarryOverSettings() {}
 | 
			
		||||
 | 
			
		||||
    explicit ATBWeekDay(Qt::DayOfWeek id, QString const &name, WeekDayType type,
 | 
			
		||||
                        QDate const &date,
 | 
			
		||||
                        ATBTariffSettings const &tariffSettings,
 | 
			
		||||
                        ATBTariffCarryOverSettings const &tariffCarryOverSettings)
 | 
			
		||||
        : m_id(id)
 | 
			
		||||
        , m_name(name)
 | 
			
		||||
        , m_date(date)
 | 
			
		||||
        , m_type(type)
 | 
			
		||||
        , m_tariffSettings(tariffSettings)
 | 
			
		||||
        , m_tariffCarryOverSettings(tariffCarryOverSettings) {}
 | 
			
		||||
 | 
			
		||||
    ATBTariffCarryOverSettings &getTariffCarryOverSettings() { return m_tariffCarryOverSettings; }
 | 
			
		||||
    ATBTariffCarryOverSettings const &getTariffCarryOverSettings() const { return m_tariffCarryOverSettings; }
 | 
			
		||||
 | 
			
		||||
    ATBTariffSettings &getTariffSettings() { return m_tariffSettings; }
 | 
			
		||||
    ATBTariffSettings const &getTariffSettings() const { return m_tariffSettings; }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBWeekDay const &wd) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "                       id: " << (int)wd.m_id << "\n"
 | 
			
		||||
            << "                     name: " << wd.m_name << "\n"
 | 
			
		||||
            << "                     type: " << (int)wd.m_type << "\n\n"
 | 
			
		||||
            << "          tariff settings: " << "\n"
 | 
			
		||||
                                             << wd.m_tariffSettings << "\n"
 | 
			
		||||
            << "tariff carryover settings: " << "\n"
 | 
			
		||||
                                             << wd.m_tariffCarryOverSettings << endl;
 | 
			
		||||
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
@@ -89,14 +89,12 @@ HEADERS += \
 | 
			
		||||
    include/mobilisis/tariff_interpolation.h \
 | 
			
		||||
    include/mobilisis/tariff_prepaid.h \
 | 
			
		||||
    include/mobilisis/tariff_carryover.h \
 | 
			
		||||
    include/mobilisis/tariff_prepay.h \
 | 
			
		||||
    include/mobilisis/tariff_global_defines.h
 | 
			
		||||
 | 
			
		||||
# OTHER_FILES += src/main.cpp \
 | 
			
		||||
#    ../tariffs/tariff_korneuburg.json \
 | 
			
		||||
#    ../tariffs/tariff_linsinger_maschinenbau.json \
 | 
			
		||||
#    ../tariffs/tariff_naz.json \
 | 
			
		||||
#    /home/linux/customer_502/etc/psa_tariff/tariff03.json
 | 
			
		||||
OTHER_FILES += src/main.cpp \
 | 
			
		||||
    ../tariffs/tariff_korneuburg.json \
 | 
			
		||||
    ../tariffs/tariff_linsinger_maschinenbau.json \
 | 
			
		||||
    ../tariffs/tariff_naz.json
 | 
			
		||||
 | 
			
		||||
# Default rules for deployment.
 | 
			
		||||
qnx: target.path = /tmp/$${TARGET}/bin
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
 | 
			
		||||
                                                  int paymentOptionIndex) {
 | 
			
		||||
    int minTime = 0;
 | 
			
		||||
 | 
			
		||||
    paymentOptionIndex = getPaymentOptionIndex(*cfg);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
    qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
 | 
			
		||||
@@ -69,7 +72,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
 | 
			
		||||
                                                  PERMIT_TYPE permitType,
 | 
			
		||||
                                                  int paymentOptionIndex) {
 | 
			
		||||
 | 
			
		||||
    paymentOptionIndex = getPaymentOptionIndex(*cfg);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
    int maxTime = 0;
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
@@ -94,7 +100,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
 | 
			
		||||
                                                   int paymentOptionIndex,
 | 
			
		||||
                                                   QDateTime const &start) {
 | 
			
		||||
    int minPrice = -1;
 | 
			
		||||
 | 
			
		||||
    if ((paymentOptionIndex = getPaymentOptionIndex(*cfg, start)) == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
 | 
			
		||||
 | 
			
		||||
@@ -321,14 +330,16 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
 | 
			
		||||
    int maxPrice = -1;
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
 | 
			
		||||
    if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
        if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
            maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
 | 
			
		||||
        } else if (paymentMethodId == PaymentMethod::Degressive) {
 | 
			
		||||
            maxPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
 | 
			
		||||
            //maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
 | 
			
		||||
            ATBPaymentOption const &po = cfg->getPaymentOptions(paymentOptionIndex);
 | 
			
		||||
            maxPrice = po.pop_max_price; // maxTime is given in minutes
 | 
			
		||||
        } else { // PaymentMethod::Linear -> e.g. szeged
 | 
			
		||||
            int const key = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
            int const maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; // maxTime is given in minutes
 | 
			
		||||
@@ -476,7 +487,11 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
 | 
			
		||||
    //    return currentTimeMinutes;
 | 
			
		||||
    //}
 | 
			
		||||
 | 
			
		||||
    int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*tariff);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
 | 
			
		||||
    int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
 | 
			
		||||
 | 
			
		||||
@@ -541,7 +556,7 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            // max. tolerance set to 3 minutes
 | 
			
		||||
            unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
 | 
			
		||||
            // unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
 | 
			
		||||
            if (j != -1) {
 | 
			
		||||
                stepList[j] = currentTimeMinutes;
 | 
			
		||||
            }
 | 
			
		||||
@@ -656,7 +671,16 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
 | 
			
		||||
    CalcState calcState;
 | 
			
		||||
 | 
			
		||||
    int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
    QDate const d(1970, 1, 1);
 | 
			
		||||
    QTime const t(0, 0, 0);
 | 
			
		||||
    QDateTime start(d, t, Qt::UTC);
 | 
			
		||||
    start = start.toLocalTime().addSecs(start_parking_time * 60);
 | 
			
		||||
    QDateTime end(start);
 | 
			
		||||
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
 | 
			
		||||
    double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
 | 
			
		||||
@@ -684,11 +708,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
        return calcState.set(CalcState::State::SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QDate const d(1970, 1, 1);
 | 
			
		||||
    QTime const t(0, 0, 0);
 | 
			
		||||
    QDateTime start(d, t, Qt::UTC);
 | 
			
		||||
    start = start.toLocalTime().addSecs(start_parking_time * 60);
 | 
			
		||||
    QDateTime end(start);
 | 
			
		||||
    //QDate const d(1970, 1, 1);
 | 
			
		||||
    //QTime const t(0, 0, 0);
 | 
			
		||||
    //QDateTime start(d, t, Qt::UTC);
 | 
			
		||||
    //start = start.toLocalTime().addSecs(start_parking_time * 60);
 | 
			
		||||
    //QDateTime end(start);
 | 
			
		||||
    if (start.isValid()) {
 | 
			
		||||
        double cost = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
                    tariff,
 | 
			
		||||
@@ -723,7 +747,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
 | 
			
		||||
    QDateTime start_parking_time(start_parking_time_);
 | 
			
		||||
 | 
			
		||||
    int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
    double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
 | 
			
		||||
@@ -770,7 +797,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
                return calcState;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex, start_parking_time_);
 | 
			
		||||
            QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
 | 
			
		||||
            Q_UNUSED(tlist);
 | 
			
		||||
 | 
			
		||||
            // compute cost (price)
 | 
			
		||||
@@ -778,39 +805,84 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
 | 
			
		||||
            int weekDay = start_parking_time.date().dayOfWeek();
 | 
			
		||||
            int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
 | 
			
		||||
            qCritical() << __func__ << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
 | 
			
		||||
            int pop_prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
 | 
			
		||||
 | 
			
		||||
            std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
 | 
			
		||||
            int period_id = -1;
 | 
			
		||||
            if (yperiod.has_value()) {
 | 
			
		||||
                ATBPeriodYear const &period = yperiod.value();
 | 
			
		||||
                period_id = period.pye_id;
 | 
			
		||||
                pop_carry_over_option_id = period.pye_id;
 | 
			
		||||
                qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
 | 
			
		||||
                pop_prepaid_option_id = period.pye_id;
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "   re-computed prepaid-id" << pop_prepaid_option_id;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
 | 
			
		||||
            int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
 | 
			
		||||
            QDateTime effectiveStartTime(start_parking_time);
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
 | 
			
		||||
            qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
 | 
			
		||||
            // handle special days
 | 
			
		||||
            int const specialDayId = tariff->specialDayId(start_parking_time);
 | 
			
		||||
            if (specialDayId > 0) { // found special day
 | 
			
		||||
                for (auto[itr, rangeEnd] = tariff->SpecialDaysWorktime.equal_range(specialDayId); itr != rangeEnd; ++itr) {
 | 
			
		||||
                    ATBSpecialDaysWorktime const &wt = itr->second;
 | 
			
		||||
                    switch(period_id) {
 | 
			
		||||
                    case 1: // summer term
 | 
			
		||||
                        if ((wt.pedwt_paid & 1) == 0) {
 | 
			
		||||
                            // does not have to be paid, move to next midnight
 | 
			
		||||
 | 
			
		||||
                            // better: start of next day (falls kein vorkauf besteht)
 | 
			
		||||
                            effectiveStartTime = effectiveStartTime.addDays(1);
 | 
			
		||||
                            effectiveStartTime.setTime(QTime(0, 0, 0));
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 2: // winter term
 | 
			
		||||
                        if ((wt.pedwt_paid & 2) == 0) {
 | 
			
		||||
                            // does not have to be paid, move to next midnight
 | 
			
		||||
 | 
			
		||||
                            // better: start of next day (falls kein vorkauf besteht)
 | 
			
		||||
                            effectiveStartTime = effectiveStartTime.addDays(1);
 | 
			
		||||
                            effectiveStartTime.setTime(QTime(0, 0, 0));
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    default:;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // handle prepaid option
 | 
			
		||||
            QDateTime effectiveStartTime(start_parking_time);
 | 
			
		||||
            int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
 | 
			
		||||
            std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
 | 
			
		||||
            if (prepaidOption.has_value()) {
 | 
			
		||||
                ATBPrepaid const &p = prepaidOption.value();
 | 
			
		||||
                if (p.never) {
 | 
			
		||||
                    qCritical() << __func__ << __LINE__ << "prepaid: no";
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "prepaid: no";
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (start_parking_time.time() < p.static_end) {     // static_end: e.g. 08:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.static_end);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "    prepaidStart" << p.prepaid[weekDay].static_start.toString(Qt::ISODate);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "      prepaidEnd" << p.prepaid[weekDay].static_end.toString(Qt::ISODate);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "prepaid duration" << p.prepaid[weekDay].duration;
 | 
			
		||||
 | 
			
		||||
                    if (start_parking_time.time() < p.prepaid[weekDay].static_end) {     // static_end: e.g. 08:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.prepaid[weekDay].static_end);
 | 
			
		||||
                    } else
 | 
			
		||||
                    if (start_parking_time.time() > p.static_start) {   // static_start: e.g. 22:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.static_start);
 | 
			
		||||
                    if (start_parking_time.time() > p.prepaid[weekDay].static_start) {   // static_start: e.g. 22:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.prepaid[weekDay].static_start);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
            int const carryOver = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over;
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "   carryOver flag" << carryOver;
 | 
			
		||||
 | 
			
		||||
            if (carryOver == 1) {
 | 
			
		||||
                QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
 | 
			
		||||
                int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
 | 
			
		||||
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "   carryOverStart" << carryOverStart.toString(Qt::ISODate);
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
 | 
			
		||||
 | 
			
		||||
                // handle carry over
 | 
			
		||||
                int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
 | 
			
		||||
                if (netto_parking_time > minutesUntilCarryOver) {
 | 
			
		||||
@@ -823,6 +895,51 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
                    end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
                weekDay = end_parking_time.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
                // musste man in einer schleife machen
 | 
			
		||||
                carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
 | 
			
		||||
                carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
 | 
			
		||||
 | 
			
		||||
                if (end_parking_time.time() > carryOverStart) {
 | 
			
		||||
                    end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
 | 
			
		||||
                } else
 | 
			
		||||
                if (end_parking_time.time() == carryOverStart) {
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "   carryOverStart" << carryOverStart.toString(Qt::ISODate);
 | 
			
		||||
                    ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
 | 
			
		||||
                    if (po.pop_apply_carry_over_to_ticket_endtime) {
 | 
			
		||||
                        end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
 | 
			
		||||
                        qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "NO carryOver configured";
 | 
			
		||||
                end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            end_parking_time.setTime(QTime(end_parking_time.time().hour(),
 | 
			
		||||
                                           end_parking_time.time().minute(), 0));
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "        week-day:" << weekDay;
 | 
			
		||||
 | 
			
		||||
            for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
 | 
			
		||||
                ATBWeekDay const &wd = itr->second;
 | 
			
		||||
                bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(effectiveStartTime,
 | 
			
		||||
                                                                                                            end_parking_time,
 | 
			
		||||
                                                                                                            paymentOptionIndex);
 | 
			
		||||
                if (parkTimeLimitViolated) {
 | 
			
		||||
                    //QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
 | 
			
		||||
                    //end_parking_time.setTime(tlimit);
 | 
			
		||||
 | 
			
		||||
                    calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
 | 
			
		||||
                                        .arg(end_parking_time.time().toString(Qt::ISODate)));
 | 
			
		||||
                    return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            cost = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
                        tariff,
 | 
			
		||||
@@ -875,7 +992,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
			
		||||
        QString cs = start.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
        bool prepaid = true;
 | 
			
		||||
        int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
        int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
 | 
			
		||||
        qCritical() << " payment option index: " << paymentOptionIndex;
 | 
			
		||||
        if (paymentOptionIndex == -1) {
 | 
			
		||||
            paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
 | 
			
		||||
        if (prepaid_option_id == 2) { // see tariff03.json for 502: 2 means no prepaid-option
 | 
			
		||||
            prepaid = false;
 | 
			
		||||
@@ -889,10 +1011,14 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
			
		||||
        qCritical() << "           start (cs): " << cs;
 | 
			
		||||
        qCritical() << "                price: " << price;
 | 
			
		||||
 | 
			
		||||
        duration = Calculator::GetInstance().GetDurationFromCost(tariff,
 | 
			
		||||
        std::pair<std::string, QDateTime> p_duration
 | 
			
		||||
                = Calculator::GetInstance().GetDurationFromCost(tariff,
 | 
			
		||||
                    tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id,
 | 
			
		||||
                                              cs.toLocal8Bit().constData(),
 | 
			
		||||
                                                  price, permitType, nextDay, prepaid).c_str();
 | 
			
		||||
                                              price, permitType, nextDay, prepaid);
 | 
			
		||||
        duration = p_duration.first.c_str();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
 | 
			
		||||
        if (!d.isValid()) {
 | 
			
		||||
            calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
 | 
			
		||||
@@ -915,31 +1041,64 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
			
		||||
    CalcState calcState;
 | 
			
		||||
 | 
			
		||||
    bool prepaid = true;
 | 
			
		||||
    int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
 | 
			
		||||
    qCritical() << __func__ << ":" << __LINE__ << "payment option index: " << paymentOptionIndex;
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << __func__ << ":" << __LINE__ << " payment option index: " << paymentOptionIndex;
 | 
			
		||||
 | 
			
		||||
    int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
 | 
			
		||||
 | 
			
		||||
    if (prepaid_option_id == 2) {
 | 
			
		||||
        prepaid = false;
 | 
			
		||||
    }
 | 
			
		||||
    bool const nextDay = false;
 | 
			
		||||
 | 
			
		||||
    // DEBUG
 | 
			
		||||
    // if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
        qCritical() << "\ncompute_duration_for_parking_ticket(2):";
 | 
			
		||||
        qCritical() << "                              start time:" << start_parking_time.toString(Qt::ISODate);
 | 
			
		||||
        qCritical() << "                    payment option index:" << paymentOptionIndex;
 | 
			
		||||
        qCritical() << "                                 prepaid:" << prepaid;
 | 
			
		||||
        qCritical() << "                                   price:" << price;
 | 
			
		||||
        qCritical() << "                             permit type:" << permitType.toString() << endl;
 | 
			
		||||
 | 
			
		||||
    // }
 | 
			
		||||
    if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
        qCritical() << "compute_duration_for_parking_ticket(2): ";
 | 
			
		||||
        qCritical() << " payment option index: " << paymentOptionIndex;
 | 
			
		||||
        qCritical() << "              prepaid: " << prepaid;
 | 
			
		||||
        qCritical() << "                price: " << price;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (start_parking_time.isValid()) {
 | 
			
		||||
 | 
			
		||||
        int const pop_time_step_config = tariff->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
 | 
			
		||||
        if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
 | 
			
		||||
            // handle prepaid option
 | 
			
		||||
            QDateTime effectiveStartTime(start_parking_time);
 | 
			
		||||
            int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
 | 
			
		||||
            std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
 | 
			
		||||
            if (prepaidOption.has_value()) {
 | 
			
		||||
                ATBPrepaid const &p = prepaidOption.value();
 | 
			
		||||
                if (p.never) {
 | 
			
		||||
                    qCritical() << __func__ << __LINE__ << "prepaid: no";
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (start_parking_time.time() < p.static_end) {     // static_end: e.g. 08:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.static_end);
 | 
			
		||||
                    } else
 | 
			
		||||
                    if (start_parking_time.time() > p.static_start) {   // static_start: e.g. 22:00:00
 | 
			
		||||
                        effectiveStartTime.setTime(p.static_start);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        QString cs = start_parking_time.toString(Qt::ISODate);
 | 
			
		||||
        QString endTime = Calculator::GetInstance().GetDurationFromCost(
 | 
			
		||||
 | 
			
		||||
        std::pair<std::string, QDateTime> p_endTime
 | 
			
		||||
                = Calculator::GetInstance().GetDurationFromCost(
 | 
			
		||||
                    tariff,
 | 
			
		||||
                    tariff->getPaymentOptions().pop_payment_method_id,
 | 
			
		||||
                    cs.toLocal8Bit().constData(),
 | 
			
		||||
                    price, permitType, nextDay, prepaid).c_str();
 | 
			
		||||
                    price, permitType, nextDay, prepaid);
 | 
			
		||||
 | 
			
		||||
        QString endTime = p_endTime.first.c_str();
 | 
			
		||||
        ticketEndTime = p_endTime.second;
 | 
			
		||||
 | 
			
		||||
        if (endTime == CalcState::SUCCESS) {
 | 
			
		||||
            calcState.setDesc(QString("SUCCESS"));
 | 
			
		||||
@@ -1001,21 +1160,96 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
			
		||||
        } else {
 | 
			
		||||
            ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "step-config:" << pop_time_step_config;
 | 
			
		||||
 | 
			
		||||
            if (!ticketEndTime.isValid()) {
 | 
			
		||||
                calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
 | 
			
		||||
                return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
 | 
			
		||||
                // handle carry over for ticket-end-time
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
                int weekDay = start_parking_time.date().dayOfWeek();
 | 
			
		||||
                int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
 | 
			
		||||
 | 
			
		||||
                std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
 | 
			
		||||
                if (yperiod.has_value()) {
 | 
			
		||||
                    ATBPeriodYear const &period = yperiod.value();
 | 
			
		||||
                    pop_carry_over_option_id = period.pye_id;
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                QTime carryOverStart;
 | 
			
		||||
                QTime carryOverEnd;
 | 
			
		||||
                int carryOverDuration = -1;
 | 
			
		||||
 | 
			
		||||
                // using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
 | 
			
		||||
                std::multimap<int, ATBCarryOver>::const_iterator it;
 | 
			
		||||
                if ((it = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)) !=
 | 
			
		||||
                    tariff->TariffCarryOverOptions.cend()) {
 | 
			
		||||
                    carryOverStart = it->second.carryover[weekDay].static_start;
 | 
			
		||||
                    carryOverEnd = it->second.carryover[weekDay].static_end;
 | 
			
		||||
                    carryOverDuration = it->second.carryover[weekDay].duration;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (carryOverStart.isValid() && carryOverEnd.isValid()) {
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "carryOverEnd" << carryOverEnd.toString(Qt::ISODate);
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) {
 | 
			
		||||
                    // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
 | 
			
		||||
                    if (ticketEndTime.time() > carryOverStart) {
 | 
			
		||||
                        // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
 | 
			
		||||
                        ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
 | 
			
		||||
                        if (ticketEndTime.time() < carryOverEnd) {
 | 
			
		||||
                            // qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
 | 
			
		||||
                            ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    qCritical() << __func__ << ":" << __LINE__ << "WARNING: wrong carry-over-settings";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            ticketEndTime.setTime(QTime(ticketEndTime.time().hour(),
 | 
			
		||||
                                        ticketEndTime.time().minute(), 0));
 | 
			
		||||
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
            for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek()));
 | 
			
		||||
                 itr != rangeEnd;
 | 
			
		||||
                 ++itr) {
 | 
			
		||||
                ATBWeekDay const &wd = itr->second;
 | 
			
		||||
                bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
 | 
			
		||||
                                                                                                            ticketEndTime,
 | 
			
		||||
                                                                                                            paymentOptionIndex);
 | 
			
		||||
                if (parkTimeLimitViolated) {
 | 
			
		||||
                    //QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
 | 
			
		||||
                    //ticketEndTime.setTime(tlimit);
 | 
			
		||||
 | 
			
		||||
                    calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
 | 
			
		||||
                                      .arg(ticketEndTime.time().toString(Qt::ISODate)));
 | 
			
		||||
                    return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (ticketEndTime.time().hour() == 0 && ticketEndTime.time().minute() == 0) {
 | 
			
		||||
                ticketEndTime = ticketEndTime.addDays(-1);
 | 
			
		||||
                ticketEndTime.setTime(QTime(23, 59, 0));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // DEBUG
 | 
			
		||||
            qCritical() << "\ncompute_duration_for_parking_ticket():";
 | 
			
		||||
            qCritical() << "                           start time:" << start_parking_time.toString(Qt::ISODate);
 | 
			
		||||
            qCritical() << "                              endTime:" << endTime;
 | 
			
		||||
            qCritical() << "                        ticketEndTime:" << ticketEndTime.toString(Qt::ISODate) << endl;
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "      endTime:" << endTime;
 | 
			
		||||
            qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        return calcState.set(CalcState::State::INVALID_START_DATE);
 | 
			
		||||
@@ -1027,7 +1261,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
			
		||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
 | 
			
		||||
                                                                  QDateTime const &start_parking_time,
 | 
			
		||||
                                                                  QDateTime &ticketEndTime,
 | 
			
		||||
                                                                  PermitType PermitType)
 | 
			
		||||
                                                                  PermitType /* PermitType */)
 | 
			
		||||
{
 | 
			
		||||
    CalcState calcState;
 | 
			
		||||
    if (start_parking_time.isValid()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,12 +10,9 @@
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <optional>
 | 
			
		||||
#include <iterator>
 | 
			
		||||
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
#include <QScopedArrayPointer>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QTimeZone>
 | 
			
		||||
 | 
			
		||||
double total_duration_min = 0.0f;
 | 
			
		||||
double total_cost = 0.0f;
 | 
			
		||||
@@ -121,11 +118,12 @@ QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime
 | 
			
		||||
    return QDateTime();
 | 
			
		||||
}
 | 
			
		||||
/// <inheritdoc/>
 | 
			
		||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
std::pair<std::string, QDateTime>
 | 
			
		||||
Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                uint8_t payment_option,
 | 
			
		||||
                                char const *startDatetimePassed, // given in local time
 | 
			
		||||
                                double cost,
 | 
			
		||||
                                            PermitType permitType,
 | 
			
		||||
                                PermitType /*permitType*/,
 | 
			
		||||
                                bool nextDay,
 | 
			
		||||
                                bool prepaid)
 | 
			
		||||
{
 | 
			
		||||
@@ -136,7 +134,15 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
    QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
 | 
			
		||||
    inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
 | 
			
		||||
    bool overPaid = false;
 | 
			
		||||
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << "   option index:" << paymentOptionIndex;
 | 
			
		||||
 | 
			
		||||
    if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
        qCritical() << DBG_HEADER << "          start:" << inputDate.toString(Qt::ISODate);
 | 
			
		||||
@@ -159,11 +165,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
            // 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;
 | 
			
		||||
            return CalcState::BELOW_MIN_PARKING_PRICE.toStdString();
 | 
			
		||||
            return std::make_pair(CalcState::BELOW_MIN_PARKING_PRICE.toStdString(), QDateTime());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
 | 
			
		||||
        if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME || prepaid == false) {
 | 
			
		||||
        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;
 | 
			
		||||
@@ -178,9 +183,6 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
 | 
			
		||||
            for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
 | 
			
		||||
                int const pra_price = itr->second.pra_price;
 | 
			
		||||
 | 
			
		||||
                // qCritical() << DBG_HEADER << "pra_price" << pra_price;
 | 
			
		||||
 | 
			
		||||
                int const durationId = itr->second.pra_payment_unit_id;
 | 
			
		||||
                if (pop_accumulate_prices) {
 | 
			
		||||
                    price += pra_price;
 | 
			
		||||
@@ -198,9 +200,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                    ATBDuration duration = search->second;
 | 
			
		||||
 | 
			
		||||
                    if (pop_accumulate_prices) {
 | 
			
		||||
                        int32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
 | 
			
		||||
                        // qCritical() << DBG_HEADER << "  duration unit" << durationUnit;
 | 
			
		||||
                        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;
 | 
			
		||||
@@ -228,9 +228,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                            qCritical() << DBG_HEADER << "           minimal parking time (minutes):" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
 | 
			
		||||
                            if (duration_previous < cfg->getPaymentOptions(paymentOptionIndex).pop_min_time) {
 | 
			
		||||
                                return CalcState::BELOW_MIN_PARKING_TIME.toStdString(); // minimal parking time is set by GetTimeSteps()
 | 
			
		||||
                                return std::make_pair(CalcState::BELOW_MIN_PARKING_TIME.toStdString(), d); // minimal parking time is set by GetTimeSteps()
 | 
			
		||||
                            }
 | 
			
		||||
                            return d.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                            return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
@@ -243,7 +243,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                        qCritical() << DBG_HEADER << "   provided price (cost):" << cost;
 | 
			
		||||
                        qCritical() << DBG_HEADER << "      duration for price:" << durationStr;
 | 
			
		||||
 | 
			
		||||
                        return durationStr.toStdString();
 | 
			
		||||
                        return std::make_pair(durationStr.toStdString(), d);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -257,30 +257,35 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
            // use tariff with structure as for instance Schoenau, Koenigsee:
 | 
			
		||||
            // without given YearPeriod, SpecialDays and SpecialDaysWorktime
 | 
			
		||||
            inputDate = inputDate.addSecs(GetDurationForPrice(cfg, cost) * 60);
 | 
			
		||||
            return inputDate.toString(Qt::ISODate).toStdString();
 | 
			
		||||
            return std::make_pair(inputDate.toString(Qt::ISODate).toStdString(), inputDate);
 | 
			
		||||
        } else {
 | 
			
		||||
            if (Utilities::IsYearPeriodActive(cfg, inputDate)) {
 | 
			
		||||
                if (!prepaid) {
 | 
			
		||||
                    CalcState cs = isParkingAllowed(cfg, inputDate);
 | 
			
		||||
                    if (cs) {
 | 
			
		||||
                        inputDate.setTime(cs.getAllowedTimeRange().getTimeUntil());
 | 
			
		||||
                        return inputDate.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                        return std::make_pair(inputDate.toString(Qt::ISODate).toStdString(), inputDate);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
                int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
 | 
			
		||||
                int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
 | 
			
		||||
                int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
 | 
			
		||||
 | 
			
		||||
                if (cost > pop_max_price) {
 | 
			
		||||
                    cost = pop_max_price;
 | 
			
		||||
                    qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
 | 
			
		||||
                    //return CalcState::OVERPAID.toStdString();
 | 
			
		||||
                    if (pop_allow_overpay == false) {
 | 
			
		||||
                        return std::make_pair(CalcState::OVERPAID.toStdString(), QDateTime());
 | 
			
		||||
                    }
 | 
			
		||||
                    cost = pop_max_price;
 | 
			
		||||
                    overPaid = true;
 | 
			
		||||
                    // return CalcState::OVERPAID.toStdString();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (cost < pop_min_price) {
 | 
			
		||||
                    qCritical() << DBG_HEADER << "MIN-PARKING-PRICE" << pop_min_price << ", COST" << cost;
 | 
			
		||||
                    return CalcState::BELOW_MIN_PARKING_PRICE.toStdString();
 | 
			
		||||
                    return std::make_pair(CalcState::BELOW_MIN_PARKING_PRICE.toStdString(), QDateTime());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // int const pop_pre_paid = 1;
 | 
			
		||||
@@ -365,7 +370,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                    qCritical() << DBG_HEADER
 | 
			
		||||
                                << "ERROR" << inputDate.toString(Qt::ISODate)
 | 
			
		||||
                                << "NOT IN VALID WORKING TIME-RANGE";
 | 
			
		||||
                    return "";
 | 
			
		||||
                    return std::make_pair("", QDateTime());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                //qCritical() << __func__ << __LINE__;
 | 
			
		||||
@@ -390,7 +395,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                    qCritical() << DBG_HEADER
 | 
			
		||||
                                << "ERROR" << inputDate.toString(Qt::ISODate)
 | 
			
		||||
                                << "NOT IN VALID WORKING TIME-RANGE";
 | 
			
		||||
                    return "";
 | 
			
		||||
                    return std::make_pair("", QDateTime());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
#if DEBUG_GET_DURATION_FROM_COST==1
 | 
			
		||||
@@ -404,7 +409,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                int new_price = 0;
 | 
			
		||||
                int durationInSecs = 0;
 | 
			
		||||
                uint32_t duration_previous = 0;
 | 
			
		||||
                bool found = false;
 | 
			
		||||
                // bool found = false;
 | 
			
		||||
 | 
			
		||||
                for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
 | 
			
		||||
                    int const pra_price = itr->second.pra_price;
 | 
			
		||||
@@ -433,13 +438,16 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                               duration_previous = durationUnit;
 | 
			
		||||
                               //qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous;
 | 
			
		||||
                            } else {
 | 
			
		||||
                                found = true;
 | 
			
		||||
                               //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 (overPaid) {
 | 
			
		||||
                                    return std::make_pair(CalcState::OVERPAID.toStdString(), d);
 | 
			
		||||
                                }
 | 
			
		||||
                                return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else {
 | 
			
		||||
                            durationInSecs = cfg->Duration.find(durationId)->second.pun_duration * 60;
 | 
			
		||||
@@ -550,7 +558,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                            qCritical() << DBG_HEADER << "TICKET-END" << s;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                            return s.toStdString();
 | 
			
		||||
                            if (overPaid) {
 | 
			
		||||
                                return std::make_pair(CalcState::OVERPAID.toStdString(), inputDate);
 | 
			
		||||
                            }
 | 
			
		||||
                            return std::make_pair(s.toStdString(), inputDate);
 | 
			
		||||
                        } // if ((double)price == cost) {
 | 
			
		||||
                        else {
 | 
			
		||||
                            //qCritical() << DBG_HEADER;
 | 
			
		||||
@@ -560,7 +571,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return "";
 | 
			
		||||
                return std::make_pair("", QDateTime());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else
 | 
			
		||||
@@ -577,7 +588,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
 | 
			
		||||
        if (cost < minParkingPrice) {
 | 
			
		||||
            qCritical() << QString("ERROR: COST < MIN_PARKING_PRICE (%1 < %2)").arg(cost).arg(minParkingPrice);
 | 
			
		||||
            return QDateTime().toString(Qt::ISODate).toStdString();
 | 
			
		||||
            return std::make_pair(QDateTime().toString(Qt::ISODate).toStdString(), QDateTime());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (cost > maxParkingPrice) {
 | 
			
		||||
@@ -616,7 +627,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                weekdayId = current.date().dayOfWeek();
 | 
			
		||||
                if (weekdayId == weekdayIdLast) {
 | 
			
		||||
                    qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
 | 
			
		||||
                    return QDateTime().toString(Qt::ISODate).toStdString();
 | 
			
		||||
                    return std::make_pair(QDateTime().toString(Qt::ISODate).toStdString(), QDateTime());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -634,7 +645,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
 | 
			
		||||
            if (current.time() >= to) {
 | 
			
		||||
                if (carryOverNotSet) {
 | 
			
		||||
                    return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                    if (overPaid) {
 | 
			
		||||
                        return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                    }
 | 
			
		||||
                    return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                } else {
 | 
			
		||||
                    QDateTime const dt = start;
 | 
			
		||||
                    start = start.addDays(1);
 | 
			
		||||
@@ -681,7 +695,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                << "price" << price;
 | 
			
		||||
#endif
 | 
			
		||||
                    end_datetime = current;
 | 
			
		||||
                    return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                    if (overPaid) {
 | 
			
		||||
                        return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                    }
 | 
			
		||||
                    return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
 | 
			
		||||
@@ -776,7 +793,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                    << "end_datetime" << end_datetime.toString(Qt::ISODate)
 | 
			
		||||
                                    << "price" << price;
 | 
			
		||||
#endif
 | 
			
		||||
                        return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                        if (overPaid) {
 | 
			
		||||
                            return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                        }
 | 
			
		||||
                        return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -817,7 +837,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                    << "end_datetime" << end_datetime.toString(Qt::ISODate)
 | 
			
		||||
                                    << "price" << price;
 | 
			
		||||
#endif
 | 
			
		||||
                                return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                                if (overPaid) {
 | 
			
		||||
                                    return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                                }
 | 
			
		||||
                                return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            // price has been updated; use next time range
 | 
			
		||||
@@ -848,7 +871,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                    << "price" << price;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                        return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                        if (overPaid) {
 | 
			
		||||
                            return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                        }
 | 
			
		||||
                        return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (moveToNextTimeRange) {
 | 
			
		||||
@@ -964,8 +990,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                                    << "end_datetime" << end_datetime.toString(Qt::ISODate)
 | 
			
		||||
                                    << "price" << price;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                        return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                        if (overPaid) {
 | 
			
		||||
                            return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                        }
 | 
			
		||||
                        return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -978,7 +1006,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                            << "final price" << std::max(price, minParkingPrice);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
                if (overPaid) {
 | 
			
		||||
                    return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
 | 
			
		||||
                }
 | 
			
		||||
                return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
            } // while (timeRangeIt != cfg->TimeRange.cend()) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -987,7 +1018,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
                            << "INVALID END TIME";
 | 
			
		||||
#endif
 | 
			
		||||
        end_datetime = QDateTime();
 | 
			
		||||
        return end_datetime.toString(Qt::ISODate).toStdString();
 | 
			
		||||
        return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ticket t = private_GetDurationFromCost(cfg, inputDate, cost, prepaid);
 | 
			
		||||
@@ -995,7 +1026,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
    // qCritical().noquote() << t;
 | 
			
		||||
 | 
			
		||||
    // TODO: im fehlerfall
 | 
			
		||||
    return t.getValidUntil().toString(Qt::ISODate).toStdString();
 | 
			
		||||
    return std::make_pair(t.getValidUntil().toString(Qt::ISODate).toStdString(), t.getValidUntil());
 | 
			
		||||
}
 | 
			
		||||
#undef _DEBUG_
 | 
			
		||||
 | 
			
		||||
@@ -1425,7 +1456,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
 | 
			
		||||
    Q_UNUSED(payment_option);
 | 
			
		||||
    Q_UNUSED(nextDay);
 | 
			
		||||
 | 
			
		||||
    int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
    int paymentOptionIndex = getPaymentOptionIndex(*cfg, start_datetime);
 | 
			
		||||
    if (paymentOptionIndex == -1) {
 | 
			
		||||
        paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
 | 
			
		||||
    }
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        if (tariffIs24_7(cfg)) {
 | 
			
		||||
@@ -2577,7 +2611,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
 | 
			
		||||
                        // qCritical() << "(" << __func__ << ":" << __LINE__ << ")            runtime in minutes (1):" << runtimeInMinutes;
 | 
			
		||||
 | 
			
		||||
                        int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
 | 
			
		||||
                        // int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
 | 
			
		||||
 | 
			
		||||
                        // TODO: auslagern
 | 
			
		||||
                        for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
 | 
			
		||||
@@ -2602,7 +2636,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
                            auto search = cfg->Duration.find(durationId);
 | 
			
		||||
                            if (search != cfg->Duration.end()) {
 | 
			
		||||
                                ATBDuration duration = search->second;
 | 
			
		||||
                                ATBDuration &previous = search->second;
 | 
			
		||||
                                // ATBDuration &previous = search->second;
 | 
			
		||||
 | 
			
		||||
                                if (duration.pun_interpolation_id == -1) {
 | 
			
		||||
 | 
			
		||||
@@ -2632,7 +2666,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
                                        // qCritical() << "(" << __func__ << ":" << __LINE__ << ")         interpolation dynamic end:" << interpolationEnd.toString(Qt::ISODate);
 | 
			
		||||
                                        // qCritical() << "(" << __func__ << ":" << __LINE__ << ")    interpolation dynamic end time:" << end_time;
 | 
			
		||||
 | 
			
		||||
                                        int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
                                        // int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
 | 
			
		||||
                                        runtimeInMinutes += duration.pun_duration;
 | 
			
		||||
                                        nextTimeStep = start.addSecs(runtimeInMinutes * 60);
 | 
			
		||||
@@ -2709,7 +2743,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
                                        //qCritical() << "(" << __func__ << ":" << __LINE__ << ")            runtime in minutes:" << runtimeInMinutes;
 | 
			
		||||
 | 
			
		||||
                                        QDateTime s = start.addSecs(runtimeInMinutes * 60);
 | 
			
		||||
                                        int const minutes = s.time().secsTo(carryOverStart) / 60;
 | 
			
		||||
                                        // int const minutes = s.time().secsTo(carryOverStart) / 60;
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
                                        if (minutes > 0) {
 | 
			
		||||
@@ -2779,243 +2813,6 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
                 qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else
 | 
			
		||||
    if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME) {
 | 
			
		||||
        // some durations / timesteps have to be recomputed
 | 
			
		||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::RECOMPUTE_SOME";
 | 
			
		||||
        int size = m_timeSteps.size();
 | 
			
		||||
 | 
			
		||||
        while (size <= paymentOptionIndex) {
 | 
			
		||||
            m_timeSteps.push_back(QList<int>());
 | 
			
		||||
            size = m_timeSteps.size();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
 | 
			
		||||
 | 
			
		||||
        m_timeSteps[paymentOptionIndex].clear();
 | 
			
		||||
 | 
			
		||||
        QDateTime const start(s.date(),
 | 
			
		||||
                              QTime(s.time().hour(), s.time().minute(), 0),
 | 
			
		||||
                              s.timeZone());
 | 
			
		||||
 | 
			
		||||
        if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
            qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        QDateTime current(start);
 | 
			
		||||
 | 
			
		||||
        bool casePrepay = false;
 | 
			
		||||
        int const weekDay = start.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
        int const pop_prepay_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepay_option_id;
 | 
			
		||||
 | 
			
		||||
        // compute prepay settings
 | 
			
		||||
        // assumption: prepay settings the same for all days
 | 
			
		||||
        QDateTime prepayStart(start);
 | 
			
		||||
        QDateTime prepayEnd(start);
 | 
			
		||||
 | 
			
		||||
        prepayStart.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].start);
 | 
			
		||||
        prepayEnd.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].end);
 | 
			
		||||
 | 
			
		||||
        if (start <= prepayEnd) {
 | 
			
		||||
            prepayStart = prepayStart.addDays(-1);
 | 
			
		||||
        } else {
 | 
			
		||||
            prepayEnd = prepayEnd.addDays(1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
            qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
 | 
			
		||||
            qCritical() << "(" << __func__ << ":" << __LINE__ << ")   prepay end" << prepayEnd.toString(Qt::ISODate);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int const prepayDurationInMinutes = start.secsTo(prepayEnd) / 60;
 | 
			
		||||
 | 
			
		||||
        // compute carryover settings
 | 
			
		||||
        // assumption: carryover settings the same for all days
 | 
			
		||||
        int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
 | 
			
		||||
        QDateTime carryOverStart(start);
 | 
			
		||||
        QDateTime carryOverEnd(start);
 | 
			
		||||
 | 
			
		||||
        carryOverStart.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start);
 | 
			
		||||
        carryOverEnd.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end);
 | 
			
		||||
 | 
			
		||||
        if (start <= carryOverEnd) {
 | 
			
		||||
            carryOverStart = carryOverStart.addDays(-1);
 | 
			
		||||
        } else {
 | 
			
		||||
            carryOverEnd = carryOverEnd.addDays(1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // int cnt = 0;
 | 
			
		||||
 | 
			
		||||
        for (Configuration::TariffDurationType::iterator it = cfg->Duration.begin();
 | 
			
		||||
             it != cfg->Duration.end();
 | 
			
		||||
             ++it) {
 | 
			
		||||
            it->second.pun_duration = it->second.pun_duration_saved;
 | 
			
		||||
 | 
			
		||||
            // if (++cnt > 2) continue;
 | 
			
		||||
 | 
			
		||||
            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (it->second.pun_mutable) {
 | 
			
		||||
                if (it->second.pun_netto) {
 | 
			
		||||
                    if (it->second.pun_round_to_next_24h_boundary == false) {
 | 
			
		||||
                        //int weekDay = start.date().dayOfWeek();
 | 
			
		||||
                        if (m_timeSteps[paymentOptionIndex].isEmpty()) {
 | 
			
		||||
                            // handle possible prepay-condition, which applies only
 | 
			
		||||
                            // for the very first step
 | 
			
		||||
 | 
			
		||||
                            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ")   prepay end" << prepayEnd.toString(Qt::ISODate);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            if (prepayStart <= start && start <= prepayEnd) {
 | 
			
		||||
                                it->second.pun_duration = prepayDurationInMinutes;
 | 
			
		||||
                                it->second.pun_duration += it->second.pun_duration_saved ;
 | 
			
		||||
                                casePrepay = true;
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << it->second.pun_duration;
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (!casePrepay) {
 | 
			
		||||
                            // handle possible carryover-condition
 | 
			
		||||
 | 
			
		||||
                            int const durationInSecs = it->second.pun_duration_saved * 60;
 | 
			
		||||
                            it->second.pun_duration = it->second.pun_duration_saved;
 | 
			
		||||
 | 
			
		||||
                            if (current >= carryOverStart && current < carryOverEnd) {
 | 
			
		||||
                                it->second.pun_duration += current.secsTo(carryOverEnd) / 60;
 | 
			
		||||
                            } else {
 | 
			
		||||
                                // start < carryOverStart
 | 
			
		||||
                                QDateTime const &newCurrent = current.addSecs(durationInSecs);
 | 
			
		||||
                                if (newCurrent > carryOverStart && newCurrent <= carryOverEnd) {
 | 
			
		||||
                                    // cross carry over section
 | 
			
		||||
                                    it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
 | 
			
		||||
                                    it->second.pun_duration += it->second.pun_next_step_correction;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                        } else {
 | 
			
		||||
                            // qCritical() << "(" << __func__ << ":" << __LINE__ << ")";
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (pop_accumulate_durations) {
 | 
			
		||||
                            m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
 | 
			
		||||
                        } else {
 | 
			
		||||
                            if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
 | 
			
		||||
                                int d = m_timeSteps[paymentOptionIndex].last();
 | 
			
		||||
                                m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        current = current.addSecs(m_timeSteps[paymentOptionIndex].last() * 60);
 | 
			
		||||
 | 
			
		||||
                        if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                            qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
 | 
			
		||||
                            qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    } else { // if (it->pun_round_to_next_24h_boundary == false) {
 | 
			
		||||
                        if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                            qCritical() << "(" << __func__ << ":" << __LINE__ << ") round-to-next-24h-boundary";
 | 
			
		||||
                            qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
 | 
			
		||||
                            qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (casePrepay) {
 | 
			
		||||
                            // the last time step contains the (dynamic) prepay duration
 | 
			
		||||
                            // so it is possible to compute the last duration
 | 
			
		||||
                            int lastDuration =  m_timeSteps[paymentOptionIndex].last() - prepayDurationInMinutes;
 | 
			
		||||
                            // qCritical() << "(" << __func__ << ":" << __LINE__ << ") last duration " << lastDuration;
 | 
			
		||||
 | 
			
		||||
                            int const minutesToAdd = 1440 - lastDuration;
 | 
			
		||||
                            current = current.addSecs(minutesToAdd * 60);
 | 
			
		||||
 | 
			
		||||
                            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            if (pop_accumulate_durations) {
 | 
			
		||||
                                m_timeSteps[paymentOptionIndex] << minutesToAdd;
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
 | 
			
		||||
                                    int d = m_timeSteps[paymentOptionIndex].last();
 | 
			
		||||
                                    m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            // qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
 | 
			
		||||
 | 
			
		||||
                            casePrepay = false;
 | 
			
		||||
 | 
			
		||||
                        } else {
 | 
			
		||||
                            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << it->second.pun_duration;
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            int secs = s.secsTo(current);
 | 
			
		||||
                            int const dayInSecs = 1440 * 60;
 | 
			
		||||
                            int const rest = secs % dayInSecs;
 | 
			
		||||
                            int const minutesToAdd = (dayInSecs - rest) / 60;
 | 
			
		||||
 | 
			
		||||
                            current = current.addSecs(minutesToAdd * 60);
 | 
			
		||||
                            it->second.pun_duration = minutesToAdd;
 | 
			
		||||
 | 
			
		||||
                            if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
 | 
			
		||||
                                qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            if (pop_accumulate_durations) {
 | 
			
		||||
                                m_timeSteps[paymentOptionIndex] << minutesToAdd;
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
 | 
			
		||||
                                    int d = m_timeSteps[paymentOptionIndex].last();
 | 
			
		||||
                                    m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            // qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                } else { // if (it->second.pun_netto) {
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
 | 
			
		||||
                }
 | 
			
		||||
            } else { // mutable == false
 | 
			
		||||
                if (it->second.pun_brutto) {    // no handling for prepay and carry-over
 | 
			
		||||
                    if (pop_accumulate_durations) {
 | 
			
		||||
                        m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
 | 
			
		||||
                            int d = m_timeSteps[paymentOptionIndex].last();
 | 
			
		||||
                            m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
 | 
			
		||||
 | 
			
		||||
                } else {
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
 | 
			
		||||
 | 
			
		||||
@@ -3034,12 +2831,13 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //qCritical() << "(" << __func__ << ":" << __LINE__ << ")                   NEW timeSteps:" << m_timeSteps;
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ")                   NEW timeSteps:" << m_timeSteps;
 | 
			
		||||
 | 
			
		||||
    if (DBG_LEVEL >= DBG_DEBUG) {
 | 
			
		||||
        QDateTime nextTime(s);
 | 
			
		||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << nextTime.toString(Qt::ISODate);
 | 
			
		||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << ")                   NEW timeSteps:" << m_timeSteps;
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
@@ -3066,7 +2864,7 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
 | 
			
		||||
    uint32_t price = 0;
 | 
			
		||||
    int pun_duration = 0;
 | 
			
		||||
 | 
			
		||||
    //qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
    //qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
 | 
			
		||||
    //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,9 @@
 | 
			
		||||
#include "tariff_business_hours.h"
 | 
			
		||||
#include "tariff_global_defines.h"
 | 
			
		||||
#include "tariff_carryover.h"
 | 
			
		||||
#include "tariff_prepay.h"
 | 
			
		||||
#include "tariff_global_defines.h"
 | 
			
		||||
#include "tariff_settings.h"
 | 
			
		||||
#include "tariff_carryover_settings.h"
 | 
			
		||||
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
@@ -22,7 +23,13 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
 | 
			
		||||
    if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
 | 
			
		||||
    if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
 | 
			
		||||
    if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
 | 
			
		||||
    //if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Monday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Tuesday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Wednesday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Thursday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Friday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Saturday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "Sunday") == 0) return MemberType::WeekDaysType;
 | 
			
		||||
    if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
 | 
			
		||||
    if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
 | 
			
		||||
    if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
 | 
			
		||||
@@ -36,10 +43,301 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
 | 
			
		||||
    if (strcmp(member_name, "Interpolation") == 0) return MemberType::InterpolationType;
 | 
			
		||||
    if (strcmp(member_name, "Prepaid") == 0) return MemberType::PrepaidType;
 | 
			
		||||
    if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType;
 | 
			
		||||
    if (strcmp(member_name, "PrepaidOption") == 0) return MemberType::PrepaidOptionType;
 | 
			
		||||
    else return MemberType::UnknownType;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ATBWeekDay parseWeekDay(Configuration &cfg,
 | 
			
		||||
                        rapidjson::GenericMemberIterator<false,
 | 
			
		||||
                                                         rapidjson::UTF8<char>,
 | 
			
		||||
                                                         rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> k,
 | 
			
		||||
                        QString const &innerObjName,
 | 
			
		||||
                        Qt::DayOfWeek weekDay,
 | 
			
		||||
                        QString const &weekDayName) {
 | 
			
		||||
    int max_price = 0;
 | 
			
		||||
    int min_price = 0;
 | 
			
		||||
    int min_time = 0;
 | 
			
		||||
    int max_time = 0;
 | 
			
		||||
    int duration = 0;
 | 
			
		||||
    ATBWeekDay WeekDay;
 | 
			
		||||
    QTime start, end, parking_time_limit, about_to_exceed_limit;
 | 
			
		||||
    ATBTariffCarryOverSettings::ParkingTimeLimitChecker parkTimeLimitChecker;
 | 
			
		||||
    if (innerObjName == QString("week_day_default")) {
 | 
			
		||||
        if (k->value.IsObject()) {
 | 
			
		||||
            auto obj = k->value.GetObject();
 | 
			
		||||
            for (auto m = obj.MemberBegin(); m != obj.MemberEnd(); ++m) {
 | 
			
		||||
                QString const &name = m->name.GetString();
 | 
			
		||||
                if (name == "week_day_type") {
 | 
			
		||||
                    //
 | 
			
		||||
                } else
 | 
			
		||||
                if (name == "tariff_settings") {
 | 
			
		||||
                    if (m->value.IsObject()) {
 | 
			
		||||
                        auto obj = m->value.GetObject();
 | 
			
		||||
                        for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
 | 
			
		||||
                            QString const &name = QString::fromStdString(n->name.GetString());
 | 
			
		||||
                            if (name == "min_time") {
 | 
			
		||||
                                if (n->value.IsInt()) { min_time = n->value.GetInt(); }
 | 
			
		||||
                            } else if (name == "max_time") {
 | 
			
		||||
                                if (n->value.IsInt()) { max_time = n->value.GetInt(); }
 | 
			
		||||
                            } else if (name == "min_price") {
 | 
			
		||||
                                if (n->value.IsInt()) { min_price = n->value.GetInt(); }
 | 
			
		||||
                            } else if (name == "max_price") {
 | 
			
		||||
                                if (n->value.IsInt()) { max_price = n->value.GetInt(); }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } else
 | 
			
		||||
                if (name == "carry_over_settings") {
 | 
			
		||||
                    if (m->value.IsObject()) {
 | 
			
		||||
                        auto obj = m->value.GetObject();
 | 
			
		||||
                        for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
 | 
			
		||||
                            QString const &name = QString::fromStdString(n->name.GetString());
 | 
			
		||||
                            if (name == "duration") {
 | 
			
		||||
                                if (n->value.IsInt()) {
 | 
			
		||||
                                    duration = n->value.GetInt();
 | 
			
		||||
                                }
 | 
			
		||||
                            } else
 | 
			
		||||
                            if (name == "start") {
 | 
			
		||||
                                if (n->value.IsString()) {
 | 
			
		||||
                                    start = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
 | 
			
		||||
                                }
 | 
			
		||||
                            } else
 | 
			
		||||
                            if (name == "end") {
 | 
			
		||||
                                if (n->value.IsString()) {
 | 
			
		||||
                                    end = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
 | 
			
		||||
                                }
 | 
			
		||||
                            } else
 | 
			
		||||
                            if (name == "parking_time_limit") {
 | 
			
		||||
                                if (n->value.IsObject()) {
 | 
			
		||||
                                    auto o = n->value.GetObject();
 | 
			
		||||
                                    for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
 | 
			
		||||
                                        if (l->name.IsString()) {
 | 
			
		||||
                                            QString const &member = QString::fromStdString(l->name.GetString());
 | 
			
		||||
                                            if (member == "prev_day_sunday?") {
 | 
			
		||||
                                                if (l->value.IsArray()) {
 | 
			
		||||
                                                    auto limits = l->value.GetArray();
 | 
			
		||||
                                                    if (limits.Size() >= 2) {
 | 
			
		||||
                                                        about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
 | 
			
		||||
                                                        parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs,
 | 
			
		||||
                                                                                                        QDateTime const &startTime,
 | 
			
		||||
                                                                                                        QDateTime const &endTime,
 | 
			
		||||
                                                                                                        int paymentOptionIndex) {
 | 
			
		||||
                                                        if (startTime.date() < endTime.date()) { // start end end on different days
 | 
			
		||||
                                                            if (endTime.date().dayOfWeek() == (int)weekDay) {
 | 
			
		||||
                                                                if (endTime.time() > cs.m_parking_time_limit) {
 | 
			
		||||
                                                                    qCritical() << __func__ << ":" << __LINE__
 | 
			
		||||
                                                                                << QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4")
 | 
			
		||||
                                                                                        .arg(weekDayName)
 | 
			
		||||
                                                                                        .arg(endTime.date().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(endTime.time().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
 | 
			
		||||
                                                                    return true;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                                if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
 | 
			
		||||
                                                                } else {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
 | 
			
		||||
                                                                        cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                            }
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                        return false;
 | 
			
		||||
                                                    };
 | 
			
		||||
                                                }
 | 
			
		||||
                                            } else
 | 
			
		||||
                                            if (member == "prev_day_holiday?") {
 | 
			
		||||
                                                if (l->value.IsArray()) {
 | 
			
		||||
                                                    auto limits = l->value.GetArray();
 | 
			
		||||
                                                    if (limits.Size() >= 2) {
 | 
			
		||||
                                                        about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
 | 
			
		||||
                                                        parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs,
 | 
			
		||||
                                                                                               QDateTime const &startTime,
 | 
			
		||||
                                                                                               QDateTime const &endTime,
 | 
			
		||||
                                                                                               int paymentOptionIndex) {
 | 
			
		||||
                                                        if (startTime.date() < endTime.date()) { // start end end on different days
 | 
			
		||||
                                                            if (previousDayHoliday(cfg, endTime)) {
 | 
			
		||||
                                                                if (endTime.time() > cs.m_parking_time_limit) {
 | 
			
		||||
                                                                    qCritical() << __func__ << ":" << __LINE__
 | 
			
		||||
                                                                                << QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4")
 | 
			
		||||
                                                                                        .arg(weekDayName)
 | 
			
		||||
                                                                                        .arg(endTime.date().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(endTime.time().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
 | 
			
		||||
                                                                    return true;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                                if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
 | 
			
		||||
                                                                } else {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
 | 
			
		||||
                                                                        cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                            }
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                        return false;
 | 
			
		||||
                                                    };
 | 
			
		||||
                                                }
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            ATBTariffSettings ts(max_price, min_price, max_time, min_time);
 | 
			
		||||
            ATBTariffCarryOverSettings cs(duration, start, end, parking_time_limit, about_to_exceed_limit,
 | 
			
		||||
                                          parkTimeLimitChecker);
 | 
			
		||||
            WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::USUAL_WEEKDAY, QDate(), ts, cs);
 | 
			
		||||
 | 
			
		||||
        } // if (k->value.IsObject()) {
 | 
			
		||||
    } else {
 | 
			
		||||
        QDate date(QDate::fromString(innerObjName, Qt::ISODate));
 | 
			
		||||
        if (date.isValid()) {
 | 
			
		||||
            if (k->value.IsObject()) {
 | 
			
		||||
                auto obj = k->value.GetObject();
 | 
			
		||||
                for (auto m = obj.MemberBegin(); m != obj.MemberEnd(); ++m) {
 | 
			
		||||
                    QString const &name = m->name.GetString();
 | 
			
		||||
                    if (name == "week_day_type") {
 | 
			
		||||
                        // TODO
 | 
			
		||||
                    } else
 | 
			
		||||
                    if (name == "tariff_settings") {
 | 
			
		||||
                        if (m->value.IsObject()) {
 | 
			
		||||
                            auto obj = m->value.GetObject();
 | 
			
		||||
                            for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
 | 
			
		||||
                                QString const &name = QString::fromStdString(n->name.GetString());
 | 
			
		||||
                                if (name == "min_time") {
 | 
			
		||||
                                    if (n->value.IsInt()) { min_time = n->value.GetInt(); }
 | 
			
		||||
                                } else if (name == "max_time") {
 | 
			
		||||
                                    if (n->value.IsInt()) { max_time = n->value.GetInt(); }
 | 
			
		||||
                                } else if (name == "min_price") {
 | 
			
		||||
                                    if (n->value.IsInt()) { min_price = n->value.GetInt(); }
 | 
			
		||||
                                } else if (name == "max_price") {
 | 
			
		||||
                                    if (n->value.IsInt()) { max_price = n->value.GetInt(); }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } else
 | 
			
		||||
                    if (name == "carry_over_settings") {
 | 
			
		||||
                        if (m->value.IsObject()) {
 | 
			
		||||
                            auto obj = m->value.GetObject();
 | 
			
		||||
                            for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
 | 
			
		||||
                                QString const &name = QString::fromStdString(n->name.GetString());
 | 
			
		||||
                                if (name == "duration") {
 | 
			
		||||
                                    if (n->value.IsInt()) {
 | 
			
		||||
                                        duration = n->value.GetInt();
 | 
			
		||||
                                    }
 | 
			
		||||
                                } else
 | 
			
		||||
                                if (name == "start") {
 | 
			
		||||
                                    if (n->value.IsString()) {
 | 
			
		||||
                                        start = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
 | 
			
		||||
                                    }
 | 
			
		||||
                                } else
 | 
			
		||||
                                if (name == "end") {
 | 
			
		||||
                                    if (n->value.IsString()) {
 | 
			
		||||
                                        end = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
 | 
			
		||||
                                    }
 | 
			
		||||
                                } else
 | 
			
		||||
                                if (name == "parking_time_limit") {
 | 
			
		||||
                                    if (n->value.IsObject()) {
 | 
			
		||||
                                        auto o = n->value.GetObject();
 | 
			
		||||
                                        for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
 | 
			
		||||
                                            if (l->name.IsString()) {
 | 
			
		||||
                                                QString const &member = QString::fromStdString(l->name.GetString());
 | 
			
		||||
                                                if (member == "default") {
 | 
			
		||||
                                                    if (l->value.IsArray()) {
 | 
			
		||||
                                                        auto limits = l->value.GetArray();
 | 
			
		||||
                                                        if (limits.Size() >= 2) {
 | 
			
		||||
                                                            about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
 | 
			
		||||
                                                            parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                    }
 | 
			
		||||
 | 
			
		||||
                                                    parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
 | 
			
		||||
                                                                                           QDateTime const &startTime,
 | 
			
		||||
                                                                                           QDateTime const &endTime,
 | 
			
		||||
                                                                                           int paymentOptionIndex) {
 | 
			
		||||
                                                        if (startTime.date() < endTime.date()) { // start end end on different days
 | 
			
		||||
                                                            if (endTime.date().dayOfWeek() == (int)weekDay) {
 | 
			
		||||
                                                                if (endTime.time() > cs.m_parking_time_limit) {
 | 
			
		||||
                                                                    qCritical() << __func__ << ":" << __LINE__
 | 
			
		||||
                                                                                << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
 | 
			
		||||
                                                                                        .arg(endTime.time().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
 | 
			
		||||
                                                                    return true;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                                if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
 | 
			
		||||
                                                                } else {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
 | 
			
		||||
                                                                        cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                            }
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                        return false;
 | 
			
		||||
                                                    };
 | 
			
		||||
                                                } else
 | 
			
		||||
                                                if (member == "prev_day_holiday?") {
 | 
			
		||||
                                                    if (l->value.IsArray()) {
 | 
			
		||||
                                                        auto limits = l->value.GetArray();
 | 
			
		||||
                                                        if (limits.Size() >= 2) {
 | 
			
		||||
                                                            about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
 | 
			
		||||
                                                            parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
 | 
			
		||||
                                                                                  QDateTime const &startTime,
 | 
			
		||||
                                                                                  QDateTime const &endTime,
 | 
			
		||||
                                                                                  int paymentOptionIndex) {
 | 
			
		||||
                                                        if (startTime.date() < endTime.date()) { // start end end on different days
 | 
			
		||||
                                                            if (previousDayHoliday(cfg, endTime)) {
 | 
			
		||||
                                                                if (endTime.time() > cs.m_parking_time_limit) {
 | 
			
		||||
                                                                    qCritical() << __func__ << ":" << __LINE__
 | 
			
		||||
                                                                                << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
 | 
			
		||||
                                                                                        .arg(endTime.time().toString(Qt::ISODate))
 | 
			
		||||
                                                                                        .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
 | 
			
		||||
                                                                    return true;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                                if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
 | 
			
		||||
                                                                } else {
 | 
			
		||||
                                                                    cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
 | 
			
		||||
                                                                        cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                            }
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                        return false;
 | 
			
		||||
                                                    };
 | 
			
		||||
                                                }
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                ATBTariffSettings ts(max_price, min_price, max_time, min_time);
 | 
			
		||||
                ATBTariffCarryOverSettings cs(duration, start, end, parking_time_limit,
 | 
			
		||||
                                              about_to_exceed_limit, parkTimeLimitChecker);
 | 
			
		||||
                WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::HOLIDAY, date, ts, cs);
 | 
			
		||||
 | 
			
		||||
            } else {// if (k->value.IsObject()) {
 | 
			
		||||
                qCritical() << __func__ << ":" << __LINE__ << "ERROR: no object";
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
            qCritical() << __func__ << __LINE__
 | 
			
		||||
                        << "ERROR: invalid date for" << weekDayName << "," << innerObjName;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return WeekDay;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <inheritdoc/>
 | 
			
		||||
bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
{
 | 
			
		||||
@@ -98,7 +396,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
            ATBPaymentRate PaymentRate;
 | 
			
		||||
            ATBSpecialDaysWorktime SpecialDaysWorktime;
 | 
			
		||||
            ATBSpecialDays SpecialDays;
 | 
			
		||||
            ATBWeekDays  WeekDays;
 | 
			
		||||
            //ATBWeekDay WeekDay;
 | 
			
		||||
            ATBWeekDaysWorktime  WeekDaysWorktime;
 | 
			
		||||
            ATBPeriodYear YearPeriod;
 | 
			
		||||
            ATBDailyTicket DailyTicket;
 | 
			
		||||
@@ -110,7 +408,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
            ATBInterpolation TariffInterpolation;
 | 
			
		||||
            ATBPrepaid TariffPrepaidOption;
 | 
			
		||||
            ATBCarryOver TariffCarryOver;
 | 
			
		||||
            ATBPrepay TariffPrepayOption;
 | 
			
		||||
 | 
			
		||||
            MemberType mb_type = MemberType::UnknownType;
 | 
			
		||||
            this->currentPaymentOptions.clear();
 | 
			
		||||
@@ -144,7 +441,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // qCritical() << " -" << mb_name;
 | 
			
		||||
            qCritical() << " -" << mb_name;
 | 
			
		||||
 | 
			
		||||
            // Get array for each JSON object member
 | 
			
		||||
            auto mb_array = document[mb_name].GetArray();
 | 
			
		||||
@@ -174,60 +471,35 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                    {
 | 
			
		||||
                    case MemberType::UnknownType:
 | 
			
		||||
                        break;
 | 
			
		||||
                    case MemberType::PrepaidOptionType: {
 | 
			
		||||
                        if (QString(inner_obj_name) == QString("prepaid_option_id")) {
 | 
			
		||||
                            if (k->value.IsInt()) {
 | 
			
		||||
                                int const &x = k->value.GetInt();
 | 
			
		||||
                                TariffPrepayOption.id = x;
 | 
			
		||||
                            }
 | 
			
		||||
                    case MemberType::WeekDaysType: {
 | 
			
		||||
                        ATBWeekDay WeekDay;
 | 
			
		||||
                        if (QString(mb_name) == "Monday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Monday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                        if (QString(inner_obj_name) == QString("prepaid_option_week")) {
 | 
			
		||||
                            if (k->value.IsArray()) {
 | 
			
		||||
                                auto days = k->value.GetArray();
 | 
			
		||||
                                for (rapidjson::SizeType j=0; j < days.Size(); ++j) {
 | 
			
		||||
                                    if (days[j].IsObject()) {
 | 
			
		||||
                                        auto weekday = days[j].GetObject();
 | 
			
		||||
                                        for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) {
 | 
			
		||||
                                            int day = j+1; // 8 entries
 | 
			
		||||
                                            QString member(QString::fromStdString(w->name.GetString()));
 | 
			
		||||
                                            if (member == "prepaid_option_day") {
 | 
			
		||||
                                                if (w->value.IsInt()) {
 | 
			
		||||
                                                    rapidjson::SizeType const d = w->value.GetInt();
 | 
			
		||||
                                                    if (d != (j+1)) {
 | 
			
		||||
                                                        qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    TariffPrepayOption.prepay[day].day = day;
 | 
			
		||||
                                                }
 | 
			
		||||
                        if (QString(mb_name) == "Tuesday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Tuesday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                                            if (member == "prepaid_option_duration") {
 | 
			
		||||
                                                if (w->value.IsInt()) {
 | 
			
		||||
                                                    TariffPrepayOption.prepay[day].duration = w->value.GetInt();
 | 
			
		||||
                                                }
 | 
			
		||||
                        if (QString(mb_name) == "Wednesday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Wednesday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                                            if (member == "prepaid_option_prepaid") {
 | 
			
		||||
                                                if (w->value.IsBool()) {
 | 
			
		||||
                                                    bool b = w->value.GetBool();
 | 
			
		||||
                                                    TariffPrepayOption.prepay[day].prepaid = b;
 | 
			
		||||
                                                }
 | 
			
		||||
                        if (QString(mb_name) == "Thursday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Thursday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                                            if (member == "prepaid_option_start") {
 | 
			
		||||
                                                if (w->value.IsString()) {
 | 
			
		||||
                                                    QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                                    TariffPrepayOption.prepay[day].start = t;
 | 
			
		||||
                                                }
 | 
			
		||||
                        if (QString(mb_name) == "Friday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Friday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                                            if (member == "prepaid_option_end") {
 | 
			
		||||
                                                if (w->value.IsString()) {
 | 
			
		||||
                                                    QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                                    TariffPrepayOption.prepay[day].end = t;
 | 
			
		||||
                                                }
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                        if (QString(mb_name) == "Saturday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Saturday, mb_name);
 | 
			
		||||
                        } else
 | 
			
		||||
                        if (QString(mb_name) == "Sunday") {
 | 
			
		||||
                            WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Sunday, mb_name);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            qCritical() << "ERROR: unknown week day" << mb_name;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        }
 | 
			
		||||
                        cfg->WeekDays.insert(pair<Qt::DayOfWeek, ATBWeekDay>(WeekDay.m_id, WeekDay));
 | 
			
		||||
                        // qCritical() << WeekDay;
 | 
			
		||||
 | 
			
		||||
                    } break;
 | 
			
		||||
                    case MemberType::CarryOverType: {
 | 
			
		||||
                        if (QString(inner_obj_name) == QString("carry_over_id")) {
 | 
			
		||||
@@ -289,7 +561,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } break;
 | 
			
		||||
                    // deprecated
 | 
			
		||||
                    case MemberType::PrepaidType: {
 | 
			
		||||
                        if (QString(inner_obj_name) == QString("prepaid_id")) {
 | 
			
		||||
                            if (k->value.IsInt()) {
 | 
			
		||||
@@ -320,6 +591,49 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                                QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                TariffPrepaidOption.static_end = t;
 | 
			
		||||
                            }
 | 
			
		||||
                        } else
 | 
			
		||||
                        if (QString(inner_obj_name) == QString("prepaid_week")) {
 | 
			
		||||
                            if (k->value.IsArray()) {
 | 
			
		||||
                                auto days = k->value.GetArray();
 | 
			
		||||
                                for (rapidjson::SizeType j=0; j < days.Size(); ++j) {
 | 
			
		||||
                                    if (days[j].IsObject()) {
 | 
			
		||||
                                        auto weekday = days[j].GetObject();
 | 
			
		||||
                                        for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) {
 | 
			
		||||
                                            int day = j+1; // 8 entries
 | 
			
		||||
 | 
			
		||||
                                            TariffPrepaidOption.prepaid[day].day = 0;
 | 
			
		||||
 | 
			
		||||
                                            QString member(QString::fromStdString(w->name.GetString()));
 | 
			
		||||
                                            if (member == "prepaid_day") {
 | 
			
		||||
                                                if (w->value.IsInt()) {
 | 
			
		||||
                                                    rapidjson::SizeType const d = w->value.GetInt();
 | 
			
		||||
                                                    if (d != (j+1)) {
 | 
			
		||||
                                                        qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    TariffPrepaidOption.prepaid[day].day = day;
 | 
			
		||||
                                                }
 | 
			
		||||
                                            } else
 | 
			
		||||
                                            if (member == "prepaid_duration") {
 | 
			
		||||
                                                if (w->value.IsInt()) {
 | 
			
		||||
                                                    TariffPrepaidOption.prepaid[day].duration = w->value.GetInt();
 | 
			
		||||
                                                }
 | 
			
		||||
                                            } else
 | 
			
		||||
                                            if (member == "prepaid_static_start") {
 | 
			
		||||
                                                if (w->value.IsString()) {
 | 
			
		||||
                                                    QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                                    TariffPrepaidOption.prepaid[day].static_start = t;
 | 
			
		||||
                                                }
 | 
			
		||||
                                            } else
 | 
			
		||||
                                            if (member == "prepaid_static_end") {
 | 
			
		||||
                                                if (w->value.IsString()) {
 | 
			
		||||
                                                    QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                                    TariffPrepaidOption.prepaid[day].static_end = t;
 | 
			
		||||
                                                }
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } break;
 | 
			
		||||
                    case MemberType::InterpolationType: {
 | 
			
		||||
@@ -660,11 +974,20 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_plus_steps") == 0) {
 | 
			
		||||
                            if (k->value.IsInt()) {
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_plus_steps = k->value.GetInt();
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_plus_steps_saved = k->value.GetInt();
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_minus_steps") == 0) {
 | 
			
		||||
                            if (k->value.IsInt()) {
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_minus_steps = k->value.GetInt();
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_allow_overpay") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_allow_overpay = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_apply_carry_over_to_ticket_endtime") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_apply_carry_over_to_ticket_endtime = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) {
 | 
			
		||||
@@ -681,10 +1004,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_min_price = k->value.GetDouble();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) { // deprecated
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_prepay_option_id") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_prepay_option_id = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_truncate_last_interpolation_step") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_truncate_last_interpolation_step = k->value.GetBool();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_accumulate_prices") == 0) {
 | 
			
		||||
@@ -782,42 +1103,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pun_duration_min") == 0) Duration.pun_duration_min = k->value.GetInt();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_duration_max") == 0) Duration.pun_duration_max = k->value.GetInt();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_interpolation_id") == 0) Duration.pun_interpolation_id = k->value.GetInt();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_netto") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_netto = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_brutto") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_brutto = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_fixed") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_fixed = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_mutable") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_mutable = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_round_to_next_24h_boundary") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_round_to_next_24h_boundary = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_round_to_prev_24h_boundary") == 0) {
 | 
			
		||||
                            if (k->value.IsBool()) {
 | 
			
		||||
                                Duration.pun_round_to_prev_24h_boundary = k->value.GetBool();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pun_align_with_timepoint") == 0) {
 | 
			
		||||
                            if (k->value.IsString()) {
 | 
			
		||||
                                QDateTime const &dt = QDateTime::fromString(k->value.GetString(), Qt::ISODate);
 | 
			
		||||
                                Duration.pun_align_with_timepoint = dt;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                     case MemberType::SpecialDaysWorktimeType:
 | 
			
		||||
                        if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
 | 
			
		||||
@@ -825,6 +1110,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pedwt_time_from") == 0) SpecialDaysWorktime.pedwt_time_from = k->value.GetString();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pedwt_time_to") == 0) SpecialDaysWorktime.pedwt_time_to = k->value.GetString();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pedwt_price") == 0) SpecialDaysWorktime.pedwt_price = k->value.GetDouble();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "pedwt_paid") == 0) SpecialDaysWorktime.pedwt_paid = k->value.GetInt();
 | 
			
		||||
                        break;
 | 
			
		||||
                /*case MemberType::WeekDaysType:
 | 
			
		||||
                        if (strcmp(inner_obj_name, "pdiw_id") == 0) WeekDays.pdiw_id = k->value.GetInt();
 | 
			
		||||
@@ -867,6 +1153,11 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                switch (mb_type) {
 | 
			
		||||
                case MemberType::UnknownType:
 | 
			
		||||
                    break;
 | 
			
		||||
                case MemberType::WeekDaysType:
 | 
			
		||||
                    // qCritical() << "INSERT" << (int)WeekDay.m_id << WeekDay.m_date.toString(Qt::ISODate);
 | 
			
		||||
                    // cfg->WeekDays.insert(pair<Qt::DayOfWeek, ATBWeekDay>(WeekDay.m_id, WeekDay));
 | 
			
		||||
                    // qCritical() << WeekDay;
 | 
			
		||||
                    break;
 | 
			
		||||
                case MemberType::PaymentMethodType:
 | 
			
		||||
                    cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
 | 
			
		||||
                    break;
 | 
			
		||||
@@ -882,7 +1173,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                } break;
 | 
			
		||||
                case MemberType::DurationType:
 | 
			
		||||
                    cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
 | 
			
		||||
                    //qCritical() << Duration;
 | 
			
		||||
                    // qCritical() << Duration;
 | 
			
		||||
                    break;
 | 
			
		||||
                case MemberType::SpecialDaysWorktimeType:
 | 
			
		||||
                    cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
 | 
			
		||||
@@ -936,10 +1227,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                    cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
 | 
			
		||||
                    // qCritical() << TariffCarryOver;
 | 
			
		||||
                    break;
 | 
			
		||||
                case MemberType::PrepaidOptionType:
 | 
			
		||||
                    cfg->TariffPrepayOptions.insert(pair<int, ATBPrepay>(TariffPrepayOption.id, TariffPrepayOption));
 | 
			
		||||
                    //qCritical() << TariffPrepayOption;
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                     break;
 | 
			
		||||
                }
 | 
			
		||||
@@ -1191,7 +1478,6 @@ bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime
 | 
			
		||||
 | 
			
		||||
    if (isSpecialDay(dt)) {
 | 
			
		||||
        bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
 | 
			
		||||
        qCritical() << "XXXXXXXXXXXXXXXXXX r" << r << businessHours;
 | 
			
		||||
        return r;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -1281,7 +1567,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
 | 
			
		||||
    std::optional<QVector<ATBPaymentOption>> paymentOptions = getPaymentOptionsForAllKeys();
 | 
			
		||||
    if (paymentOptions) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        QVector<ATBPaymentOption> const vec = paymentOptions.value();
 | 
			
		||||
        PermitType const p(permitType);
 | 
			
		||||
 | 
			
		||||
@@ -1295,6 +1580,73 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int getPaymentOptionIndex(Configuration const &cfg, QDateTime const &dt) {
 | 
			
		||||
 | 
			
		||||
    int const numOptions = cfg.getAllPaymentOptions().size();
 | 
			
		||||
 | 
			
		||||
    // qCritical() << __func__ << ":" << __LINE__ << "numOptions" << numOptions;
 | 
			
		||||
 | 
			
		||||
    for (int opt=0; opt < numOptions; ++opt) {
 | 
			
		||||
        uint64_t const pop_business_hours = cfg.getPaymentOptions(opt).pop_business_hours;
 | 
			
		||||
 | 
			
		||||
        if (pop_business_hours == 0) { // 0 == 24/7
 | 
			
		||||
            return opt;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // QDateTime const dt = QDateTime::currentDateTime();
 | 
			
		||||
        int const dayOfWeek = dt.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
        // qCritical() << __func__ << ":" << __LINE__ << "dayOfWeek" << dayOfWeek;
 | 
			
		||||
 | 
			
		||||
        if (isHoliday(cfg, dt)) {
 | 
			
		||||
            if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
                return opt;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            switch (dayOfWeek) {
 | 
			
		||||
            case (int)Qt::Monday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::MON) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Tuesday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::TUE) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Wednesday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::WED) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Thursday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::THU) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Friday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::FRI) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Saturday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::SAT) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            case (int)Qt::Sunday: {
 | 
			
		||||
                if (pop_business_hours & BusinessHours::SUN) {
 | 
			
		||||
        qCritical() << __func__ << ":" << __LINE__ << "opt" << opt;
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            } break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::optional<QVector<ATBTariffProduct>>
 | 
			
		||||
Configuration::getTariffProductForProductId(PermitType permitType) const {
 | 
			
		||||
    QString permitTypeName(permitType);
 | 
			
		||||
@@ -1549,3 +1901,43 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
 | 
			
		||||
 | 
			
		||||
    return value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool isHoliday(Configuration const &cfg, QDateTime const &t) {
 | 
			
		||||
    int const weekDay = t.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
    for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
 | 
			
		||||
         iter != rEnd;
 | 
			
		||||
         ++iter) {
 | 
			
		||||
 | 
			
		||||
        if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
 | 
			
		||||
            QDate const &d = iter->second.m_date;
 | 
			
		||||
            if (!d.isNull() && d.isValid()) {
 | 
			
		||||
                if (t.date() == d) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t) {
 | 
			
		||||
    int const weekDay = t.date().dayOfWeek();
 | 
			
		||||
    int const previousWeekDay = (weekDay == static_cast<int>(Qt::Monday)) ?
 | 
			
		||||
                static_cast<int>(Qt::Sunday) : (weekDay - 1);
 | 
			
		||||
 | 
			
		||||
    for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(previousWeekDay));
 | 
			
		||||
         iter != rEnd;
 | 
			
		||||
         ++iter) {
 | 
			
		||||
 | 
			
		||||
        if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
 | 
			
		||||
            QDate const &d = iter->second.m_date;
 | 
			
		||||
            if (!d.isNull() && d.isValid()) {
 | 
			
		||||
                if (t.addDays(-1).date() == d) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -207,7 +207,13 @@ bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt
 | 
			
		||||
                              dt.date().day());
 | 
			
		||||
                QDate const s(2004, year.second.pye_start_month, year.second.pye_start_day);
 | 
			
		||||
                QDate const e(2004, year.second.pye_end_month, year.second.pye_end_day);
 | 
			
		||||
                //qCritical() << __func__ << __LINE__ << "    d" << d.toString(Qt::ISODate);
 | 
			
		||||
                //qCritical() << __func__ << __LINE__ << "start" << s.toString(Qt::ISODate);
 | 
			
		||||
                //qCritical() << __func__ << __LINE__ << "  end" << e.toString(Qt::ISODate);
 | 
			
		||||
                if (s <= e) {
 | 
			
		||||
                    return (d >= s && d <= e);
 | 
			
		||||
                }
 | 
			
		||||
                return (d >= s || d <= e);
 | 
			
		||||
            })) {
 | 
			
		||||
        qCritical() << "NO VALID YEAR PERIOD";
 | 
			
		||||
        return false;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										205
									
								
								main/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										205
									
								
								main/main.cpp
									
									
									
									
									
								
							@@ -43,7 +43,7 @@ extern "C" char* strptime(const char* s,
 | 
			
		||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU        (0)
 | 
			
		||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
 | 
			
		||||
#define NEUHAUSER_BILEXA_GALTUER                (0)
 | 
			
		||||
#define BAD_NEUENAHR_AHRWEILER                  (0)
 | 
			
		||||
#define BAD_NEUENAHR_AHRWEILER                  (1)
 | 
			
		||||
#define NEUHAUSER_CHRISTOPH_REISEN              (0)
 | 
			
		||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR            (0)
 | 
			
		||||
#define NEUHAUSER_STOCKERAU                     (0)
 | 
			
		||||
@@ -51,7 +51,7 @@ extern "C" char* strptime(const char* s,
 | 
			
		||||
#define SEXTEN                                  (0)
 | 
			
		||||
#define SCHNALS_LEITER_KIRCHL                   (0)
 | 
			
		||||
#define SCHNALS_STAUMAUER                       (SCHNALS_LEITER_KIRCHL)
 | 
			
		||||
#define VALSER_ALM                              (1)
 | 
			
		||||
#define VALSER_ALM                              (0)
 | 
			
		||||
 | 
			
		||||
#if NEUHAUSER_KIRCHDORF==1
 | 
			
		||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
 | 
			
		||||
@@ -339,20 +339,20 @@ int main() {
 | 
			
		||||
    cout << endl;
 | 
			
		||||
 | 
			
		||||
    if (isParsed) {
 | 
			
		||||
        pop_min_time = get_minimal_parkingtime(&cfg);
 | 
			
		||||
        pop_max_time = get_maximal_parkingtime(&cfg);
 | 
			
		||||
        pop_min_price = get_minimal_parkingprice(&cfg);
 | 
			
		||||
        pop_max_price = get_maximal_parkingprice(&cfg);
 | 
			
		||||
        pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
 | 
			
		||||
        //pop_min_time = get_minimal_parkingtime(&cfg);
 | 
			
		||||
        //pop_max_time = get_maximal_parkingtime(&cfg);
 | 
			
		||||
        //pop_min_price = get_minimal_parkingprice(&cfg);
 | 
			
		||||
        //pop_max_price = get_maximal_parkingprice(&cfg);
 | 
			
		||||
        //pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
        qCritical() << "        pop_min_time: " << pop_min_time;
 | 
			
		||||
        qCritical() << "        pop_max_time: " << pop_max_time;
 | 
			
		||||
        qCritical() << "       pop_min_price: " << pop_min_price;
 | 
			
		||||
        qCritical() << "       pop_max_price: " << pop_max_price;
 | 
			
		||||
        //qCritical() << "        pop_min_time: " << pop_min_time;
 | 
			
		||||
        //qCritical() << "        pop_max_time: " << pop_max_time;
 | 
			
		||||
        //qCritical() << "       pop_min_price: " << pop_min_price;
 | 
			
		||||
        //qCritical() << "       pop_max_price: " << pop_max_price;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
        qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
        //QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
        //qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
        // return 0;
 | 
			
		||||
 | 
			
		||||
@@ -363,8 +363,7 @@ int main() {
 | 
			
		||||
 | 
			
		||||
        // for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
 | 
			
		||||
        for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
 | 
			
		||||
            QDateTime s(QDate(2024, 7, 29 + day), QTime()); // 20: (whit) monday,..., 26: sunday
 | 
			
		||||
            QDateTime end;
 | 
			
		||||
            QDateTime s(QDate(2024, 8, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
 | 
			
		||||
 | 
			
		||||
            switch (day) {
 | 
			
		||||
            case (int)Qt::Monday:
 | 
			
		||||
@@ -390,6 +389,30 @@ int main() {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            QDateTime start(s);
 | 
			
		||||
            start.setTime(QTime(21, 30, 0));
 | 
			
		||||
 | 
			
		||||
            QDateTime end;
 | 
			
		||||
            int netto_parking_time = 14 * 60;
 | 
			
		||||
            struct price_t costs;
 | 
			
		||||
            PermitType pt(PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
 | 
			
		||||
            double cost = 150;
 | 
			
		||||
 | 
			
		||||
            //cs = compute_price_for_parking_ticket(&cfg, start, netto_parking_time,
 | 
			
		||||
            //                                      end, &costs, pt);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << costs.netto
 | 
			
		||||
            //            << "> end" << end.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
            cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
 | 
			
		||||
                        qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
 | 
			
		||||
                                    << "> end" << end.toString(Qt::ISODate);
 | 
			
		||||
            //}
 | 
			
		||||
 | 
			
		||||
            exit(0);
 | 
			
		||||
 | 
			
		||||
            /*
 | 
			
		||||
            CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
@@ -741,14 +764,7 @@ int main() {
 | 
			
		||||
        input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json");
 | 
			
		||||
    }
 | 
			
		||||
    if (zone == 3) {
 | 
			
		||||
        //input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
 | 
			
		||||
        //input.open("/home/linux/customer_502/etc/psa_tariff/tariff01.json");
 | 
			
		||||
 | 
			
		||||
        // schnals
 | 
			
		||||
        // input.open("/opt/ptu5/opt/customer_505/etc/psa_tariff/tariff01.json");
 | 
			
		||||
 | 
			
		||||
        // muehlbach
 | 
			
		||||
        input.open("/opt/ptu5/opt/customer_504/etc/psa_tariff/tariff01.json");
 | 
			
		||||
        input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::stringstream sstr;
 | 
			
		||||
@@ -907,7 +923,7 @@ int main() {
 | 
			
		||||
            int Down = 0;
 | 
			
		||||
            int Up = 1;
 | 
			
		||||
 | 
			
		||||
            QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
            QDateTime const start = QDateTime::currentDateTime();
 | 
			
		||||
            int paymentOptionIndex = cfg.getPaymentOptionIndex(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
 | 
			
		||||
 | 
			
		||||
            if (paymentOptionIndex != 0) {
 | 
			
		||||
@@ -920,61 +936,17 @@ int main() {
 | 
			
		||||
            //QSet<uint32_t> const prices2{500, 1600, 2400, 3200, 4000, 4800, 5600};
 | 
			
		||||
 | 
			
		||||
            QDateTime end;
 | 
			
		||||
 | 
			
		||||
            QDateTime s(QDateTime::currentDateTime());
 | 
			
		||||
            s.setTime(QTime(10, 0, 0));
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
 | 
			
		||||
            pop_min_time = get_minimal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
 | 
			
		||||
            pop_max_time = get_maximal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
 | 
			
		||||
 | 
			
		||||
            pop_min_price = get_minimal_parkingprice(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex, s);
 | 
			
		||||
            pop_max_price = get_maximal_parkingprice(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
 | 
			
		||||
 | 
			
		||||
            pop_daily_card_price = cfg.getPaymentOptions(paymentOptionIndex).pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
            int h = pop_min_time / 60;
 | 
			
		||||
            int m = pop_min_time % 60;
 | 
			
		||||
            qCritical().noquote() << QString("         pop_min_time %1 (%2h, %3m)").arg(pop_min_time).arg(h).arg(m);
 | 
			
		||||
 | 
			
		||||
            h = pop_max_time / 60;
 | 
			
		||||
            m = pop_max_time % 60;
 | 
			
		||||
            qCritical().noquote()
 | 
			
		||||
               << QString("         pop_max_time %1 (%2h, %3m)").arg(pop_max_time).arg(h).arg(m);
 | 
			
		||||
 | 
			
		||||
            qCritical() << "       pop_min_price " << pop_min_price;
 | 
			
		||||
            qCritical() << "       pop_max_price " << pop_max_price;
 | 
			
		||||
            qCritical() << "pop_daily_card_price " << pop_daily_card_price;
 | 
			
		||||
#endif
 | 
			
		||||
            CalcState calcState;
 | 
			
		||||
 | 
			
		||||
#if 1
 | 
			
		||||
            qCritical() << "start" << s.toString(Qt::ISODate);
 | 
			
		||||
            //for (int i = 1; i < 11; ++i) {
 | 
			
		||||
            for (int i = 0; i < 21; ++i) {
 | 
			
		||||
                calcState = compute_duration_for_parking_ticket(&cfg, s,
 | 
			
		||||
                                                    (double)i*10,
 | 
			
		||||
                                                    end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
 | 
			
		||||
                qCritical() << "RUN" << i << ": start" << s.toString(Qt::ISODate)
 | 
			
		||||
                            << ": price" << i*10 << "->" << end.toString(Qt::ISODate) << calcState.toString();
 | 
			
		||||
            }
 | 
			
		||||
#else
 | 
			
		||||
            struct price_t price;
 | 
			
		||||
            int netto_parking_time = 1440;
 | 
			
		||||
            QDateTime s(QDateTime::currentDateTime());
 | 
			
		||||
            s.setTime(QTime(12, 0, 0));
 | 
			
		||||
 | 
			
		||||
            start = s;
 | 
			
		||||
            qCritical() << "RUN" << 0 << ": start" << s.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
            calcState = compute_price_for_parking_ticket(&cfg, start, netto_parking_time,
 | 
			
		||||
                                                         end, &price,
 | 
			
		||||
                                                         PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
 | 
			
		||||
            qCritical() << "RUN" << 0 << ": start" << start.toString(Qt::ISODate)
 | 
			
		||||
                        << ": price for netto-time" << netto_parking_time
 | 
			
		||||
                        << "->" << price.netto << "->" << end.toString(Qt::ISODate) << calcState.toString();
 | 
			
		||||
#endif
 | 
			
		||||
            int minimal_parking_price = get_minimal_parkingprice(&cfg,
 | 
			
		||||
                                                                 PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
 | 
			
		||||
                                                                 paymentOptionIndex, s);
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
            qCritical() << "minimal parking price" << minimal_parking_price;
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < 8; ++i) {
 | 
			
		||||
                calcState = compute_duration_for_parking_ticket(&cfg, s,
 | 
			
		||||
@@ -983,11 +955,11 @@ int main() {
 | 
			
		||||
                qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
// #else
 | 
			
		||||
            s.setTime(QTime(12, 0, 0));
 | 
			
		||||
#else
 | 
			
		||||
            s.setTime(QTime(15, 0, 0));
 | 
			
		||||
 | 
			
		||||
            minimal_parking_price = get_minimal_parkingprice(&cfg,
 | 
			
		||||
                                                             PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS),
 | 
			
		||||
                                                             PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
 | 
			
		||||
                                                             paymentOptionIndex, s);
 | 
			
		||||
 | 
			
		||||
            qCritical() << "minimal parking price" << minimal_parking_price;
 | 
			
		||||
@@ -995,7 +967,7 @@ int main() {
 | 
			
		||||
            for (int i = 0; i < 8; ++i) {
 | 
			
		||||
                calcState = compute_duration_for_parking_ticket(&cfg, s,
 | 
			
		||||
                                                    (double)minimal_parking_price + i*800,
 | 
			
		||||
                                                    end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
 | 
			
		||||
                                                    end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
 | 
			
		||||
                qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
@@ -1408,7 +1380,7 @@ int main() {
 | 
			
		||||
    int pop_carry_over;
 | 
			
		||||
    int pop_carry_over_time_range_id;
 | 
			
		||||
 | 
			
		||||
    for (int zone=1; zone < 2; ++zone) {
 | 
			
		||||
    for (int zone=2; zone < 3; ++zone) {
 | 
			
		||||
    //for (int t=6; t < 7; t+=20) {
 | 
			
		||||
        switch (zone) {
 | 
			
		||||
        case 1: {
 | 
			
		||||
@@ -1417,6 +1389,7 @@ int main() {
 | 
			
		||||
            //pop_max_time = 6*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 2: {
 | 
			
		||||
            qCritical() << "        ZONE 2: KURZZEIT 1";
 | 
			
		||||
            // kuzzeit-1-tarif
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json");
 | 
			
		||||
            //pop_max_time = 5*60;
 | 
			
		||||
@@ -1459,6 +1432,7 @@ int main() {
 | 
			
		||||
        cout << endl;
 | 
			
		||||
 | 
			
		||||
        if (isParsed) {
 | 
			
		||||
 | 
			
		||||
            // test library functions
 | 
			
		||||
 | 
			
		||||
            if (zone == 1) {
 | 
			
		||||
@@ -1485,10 +1459,10 @@ int main() {
 | 
			
		||||
                static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
                qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
                if (stepsConfigured != timeSteps) {
 | 
			
		||||
                    qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
 | 
			
		||||
                    return -1;
 | 
			
		||||
                }
 | 
			
		||||
                //if (stepsConfigured != timeSteps) {
 | 
			
		||||
                //    qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
 | 
			
		||||
                //    return -1;
 | 
			
		||||
                //}
 | 
			
		||||
 | 
			
		||||
                QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
 | 
			
		||||
@@ -1496,7 +1470,8 @@ int main() {
 | 
			
		||||
                double price1 = 0;
 | 
			
		||||
                double price2 = 0;
 | 
			
		||||
 | 
			
		||||
                for (int m=0; m < 1440; ++m) {
 | 
			
		||||
                //for (int m=0; m < 1440; ++m) {
 | 
			
		||||
                for (int m=480; m < 481; ++m) {
 | 
			
		||||
                    start.setTime(QTime(0, 0, 0));
 | 
			
		||||
                    start = start.addSecs(m*60);
 | 
			
		||||
 | 
			
		||||
@@ -1513,7 +1488,7 @@ int main() {
 | 
			
		||||
                    //}
 | 
			
		||||
 | 
			
		||||
                    CalcState cs;
 | 
			
		||||
 | 
			
		||||
#if 1
 | 
			
		||||
                    for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
 | 
			
		||||
                        QDateTime end = start.addSecs(timeSteps.at(i)*60);
 | 
			
		||||
 | 
			
		||||
@@ -1548,6 +1523,21 @@ int main() {
 | 
			
		||||
                        //                                                                     cost[i], false, true);
 | 
			
		||||
                        //qCritical() << "duration" << duration.c_str();
 | 
			
		||||
                    }
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
                    double cost = 80;
 | 
			
		||||
                    qCritical() << "START" << start.toString(Qt::ISODate) << "cost" << cost;
 | 
			
		||||
                    QDateTime end;
 | 
			
		||||
 | 
			
		||||
                    cs = compute_duration_for_parking_ticket(&cfg, start, cost, end,
 | 
			
		||||
                                                             PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
 | 
			
		||||
                        qCritical() << __LINE__ << cs.toString()
 | 
			
		||||
                                    << "START" << start.toString(Qt::ISODate)
 | 
			
		||||
                                    << "<duration" << start.secsTo(end) / 60
 | 
			
		||||
                                    << "cost" << cost
 | 
			
		||||
                                    << "> end" << end.toString(Qt::ISODate);
 | 
			
		||||
                    //}
 | 
			
		||||
#endif
 | 
			
		||||
                }
 | 
			
		||||
            } // zone == 1
 | 
			
		||||
            if (zone == 2) {
 | 
			
		||||
@@ -1585,18 +1575,19 @@ int main() {
 | 
			
		||||
                bool fail;
 | 
			
		||||
                QDateTime start;
 | 
			
		||||
 | 
			
		||||
                for (int i=0; i < 4; ++i) {
 | 
			
		||||
                for (int i=1; i < 2; ++i) {
 | 
			
		||||
                    switch (i) {
 | 
			
		||||
                    case 0:
 | 
			
		||||
                        start = QDateTime(QDate(2024, 5, 1), QTime(16, 0, 0)); // holiday
 | 
			
		||||
                        fail = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                    case 1:
 | 
			
		||||
                        start = QDateTime(QDate(2024, 4, 21), QTime(16, 0, 0)); // sunday
 | 
			
		||||
                        //start = QDateTime(QDate(2024, 10, 3), QTime(17, 0, 0)); // sunday
 | 
			
		||||
                        start = QDateTime(QDate(2024, 9, 8), QTime(16, 2, 0)); // sunday
 | 
			
		||||
                        fail = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                    case 2:
 | 
			
		||||
                        start = QDateTime(QDate(2024, 4, 22), QTime(8, 0, 0)); // monday
 | 
			
		||||
                        start = QDateTime(QDate(2024, 4, 22), QTime(17, 30, 0)); // monday
 | 
			
		||||
                        fail = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                    case 3:
 | 
			
		||||
@@ -1620,18 +1611,52 @@ int main() {
 | 
			
		||||
 | 
			
		||||
                        QList<int>::const_iterator step;
 | 
			
		||||
                        for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
 | 
			
		||||
                            //qCritical() << __LINE__
 | 
			
		||||
                            //            << "START" << start.toString(Qt::ISODate)
 | 
			
		||||
                            //            << "<duration" << *step;
 | 
			
		||||
 | 
			
		||||
                            // if (*step != 180)
 | 
			
		||||
                            // continue;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                            double cost = 0;
 | 
			
		||||
                            CalcState cs;
 | 
			
		||||
 | 
			
		||||
                            if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
 | 
			
		||||
                            QDateTime s(start);
 | 
			
		||||
 | 
			
		||||
                            qCritical() << __LINE__
 | 
			
		||||
                                        << "START" << start.toString(Qt::ISODate)
 | 
			
		||||
                                        << "<duration" << *step;
 | 
			
		||||
 | 
			
		||||
#if 1
 | 
			
		||||
                            if ((cs = compute_price_for_parking_ticket(&cfg, s, *step, end, &price,
 | 
			
		||||
                                                                       PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
 | 
			
		||||
                                cost = price.netto;
 | 
			
		||||
                                qCritical() << "step" << *step << ": cost" << cost;
 | 
			
		||||
                                qCritical() << __LINE__
 | 
			
		||||
                                            << "START" << start.toString(Qt::ISODate)
 | 
			
		||||
                                            << "<duration" << *step
 | 
			
		||||
                                            << "cost" << cost
 | 
			
		||||
                                            << "> end" << end.toString(Qt::ISODate);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (fail == false) {
 | 
			
		||||
                                    qCritical() << "<<<ERROR>>> cs =" << QString(cs);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
#else
 | 
			
		||||
                            cost = 200;
 | 
			
		||||
                            qCritical() << "START" << start.toString(Qt::ISODate) << "cost" << cost;
 | 
			
		||||
 | 
			
		||||
                            cs = compute_duration_for_parking_ticket(&cfg, start, cost, end,
 | 
			
		||||
                                                                         PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
 | 
			
		||||
                                qCritical() << __LINE__ << cs.toString()
 | 
			
		||||
                                            << "START" << start.toString(Qt::ISODate)
 | 
			
		||||
                                            << "<duration" << start.secsTo(end) / 60
 | 
			
		||||
                                            << "cost" << cost
 | 
			
		||||
                                            << "> end" << end.toString(Qt::ISODate);
 | 
			
		||||
                            break;
 | 
			
		||||
                            //}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        qCritical() << "ERROR paymentOptionIndex =" << paymentOptionIndex;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,9 +30,11 @@ SOURCES += main.cpp
 | 
			
		||||
# HEADERS +=
 | 
			
		||||
 | 
			
		||||
OTHER_FILES += \
 | 
			
		||||
    /opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json
 | 
			
		||||
    /opt/ptu5/opt/customer_335/etc/psa_tariff/tariff01.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_335/etc/psa_tariff/tariff02.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_249/etc/psa_tariff/tariff01.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json \
 | 
			
		||||
    /opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user