Compare commits
	
		
			1 Commits
		
	
	
		
			v2
			...
			neuhauser-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						16ccb706da
	
				 | 
					
					
						
@@ -175,8 +175,6 @@ struct CALCULATE_LIBRARY_API CalcState {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    CalcState &set(State s) { m_status = s; return *this; }
 | 
			
		||||
    CalcState &setStatus(State s) { return set(s); }
 | 
			
		||||
    State getStatus() const { return m_status; }
 | 
			
		||||
    CalcState &setDesc(QString s) { m_desc = s; return *this; }
 | 
			
		||||
 | 
			
		||||
    void setAllowedTimeRange(QTime const &from, QTime const &until) {
 | 
			
		||||
@@ -196,28 +194,11 @@ int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
 | 
			
		||||
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown);
 | 
			
		||||
 | 
			
		||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg,
 | 
			
		||||
                                                  PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
 | 
			
		||||
                                                  int paymentOptionIndex=0);
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg,
 | 
			
		||||
                                                  PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
 | 
			
		||||
                                                  int paymentOptionIndex=0);
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
 | 
			
		||||
                                                   PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
 | 
			
		||||
                                                   int paymentOptionIndex=0);
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
 | 
			
		||||
                                                   PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
 | 
			
		||||
                                                   int paymentOptionIndex=0);
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
 | 
			
		||||
                                                PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
 | 
			
		||||
                                                QDateTime const &start = QDateTime::currentDateTime(),
 | 
			
		||||
                                                QDateTime *productStart = nullptr,
 | 
			
		||||
                                                QDateTime *productEnd = nullptr);
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
 | 
			
		||||
 | 
			
		||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(       // deprecated
 | 
			
		||||
                                            parking_tariff_t *tariff,
 | 
			
		||||
 
 | 
			
		||||
@@ -14,19 +14,9 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Calculator {
 | 
			
		||||
    mutable QVector<QList<int>> m_timeSteps;
 | 
			
		||||
    mutable QList<int> m_timeSteps;
 | 
			
		||||
    mutable QList<int> m_priceSteps;
 | 
			
		||||
 | 
			
		||||
    CalcState isParkingAllowedForWeekDay(Configuration const *cfg,
 | 
			
		||||
                                         QDateTime const &start,
 | 
			
		||||
                                         int netto_parking_time,
 | 
			
		||||
                                         int paymentOptionIndex);
 | 
			
		||||
 | 
			
		||||
    CalcState isParkingAllowedForSpecialDay(Configuration const *cfg,
 | 
			
		||||
                                            QDateTime const &start,
 | 
			
		||||
                                            int netto_parking_time,
 | 
			
		||||
                                            int paymentOptionIndex);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    explicit Calculator() = default;
 | 
			
		||||
 | 
			
		||||
@@ -39,28 +29,13 @@ public:
 | 
			
		||||
        return c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void ResetTimeSteps(int paymentOptionIndex) {
 | 
			
		||||
        if (m_timeSteps.size() > 0) {
 | 
			
		||||
            m_timeSteps[paymentOptionIndex].clear();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    QList<int> timeSteps(int paymentOptionIndex=0) const {
 | 
			
		||||
        if (m_timeSteps.size() > 0) {
 | 
			
		||||
            return m_timeSteps[paymentOptionIndex];
 | 
			
		||||
        }
 | 
			
		||||
        return QList<int>();
 | 
			
		||||
    }
 | 
			
		||||
    void ResetTimeSteps() { m_timeSteps.clear(); }
 | 
			
		||||
    QList<int> timeSteps() const { return m_timeSteps; }
 | 
			
		||||
 | 
			
		||||
    void ResetPriceSteps() { m_priceSteps.clear(); }
 | 
			
		||||
    QList<int> priceSteps() const { return m_priceSteps; }
 | 
			
		||||
 | 
			
		||||
    CalcState isParkingAllowed(Configuration const *cfg,
 | 
			
		||||
                               QDateTime const &start);
 | 
			
		||||
 | 
			
		||||
    CalcState isParkingAllowed(Configuration const *cfg,
 | 
			
		||||
                               QDateTime const &start,
 | 
			
		||||
                               int netto_parking_time,
 | 
			
		||||
                               int paymentOptionIndex);
 | 
			
		||||
    CalcState isParkingAllowed(Configuration const *cfg, QDateTime const &start);
 | 
			
		||||
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Gets duration in seconds from cost
 | 
			
		||||
@@ -91,8 +66,8 @@ public:
 | 
			
		||||
    // helper function to find time steps for a tariff with PaymentMethod::Steps
 | 
			
		||||
    // (e.g. Schoenau/Koenigsee)
 | 
			
		||||
    //
 | 
			
		||||
    QList<int> GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0) const;
 | 
			
		||||
    QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0) const { return GetTimeSteps(cfg, paymentOptionIndex); }
 | 
			
		||||
    QList<int> GetTimeSteps(Configuration *cfg) const;
 | 
			
		||||
    QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
 | 
			
		||||
 | 
			
		||||
    QList<int> GetPriceSteps(Configuration *cfg) const;
 | 
			
		||||
 | 
			
		||||
@@ -112,8 +87,8 @@ public:
 | 
			
		||||
// testing public:
 | 
			
		||||
    // Introduced for PaymentMethod::Steps (e.g. Schoenau)
 | 
			
		||||
    // For tariff of following structure: only steps, no special days, nonstop.
 | 
			
		||||
    uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes, int paymentOptionIndex=0) const;
 | 
			
		||||
    uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end, int paymentOptionIndex=0) const;
 | 
			
		||||
    uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
 | 
			
		||||
    uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ticket private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
@@ -129,7 +104,7 @@ private:
 | 
			
		||||
                              int durationMinutes);
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex=0) const;
 | 
			
		||||
    uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
 | 
			
		||||
    uint32_t GetPriceForStep(Configuration *cfg, int step) const {
 | 
			
		||||
        return GetPriceForTimeStep(cfg, step);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -36,9 +36,6 @@ class Calculator;
 | 
			
		||||
class Configuration
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    using SpecialDaysType = std::multimap<int, ATBSpecialDays>;
 | 
			
		||||
    using SpecialDaysWorktimeType = std::multimap<int, ATBSpecialDaysWorktime>;
 | 
			
		||||
 | 
			
		||||
    ATBProject project;
 | 
			
		||||
    ATBCurrency Currency;
 | 
			
		||||
	ATBDuration duration;
 | 
			
		||||
@@ -46,8 +43,8 @@ public:
 | 
			
		||||
	multimap<int, ATBDuration> Duration;
 | 
			
		||||
	multimap<int, ATBPaymentMethod> PaymentMethod;
 | 
			
		||||
	multimap<int, ATBPaymentRate> PaymentRate;
 | 
			
		||||
    SpecialDaysWorktimeType SpecialDaysWorktime;
 | 
			
		||||
    SpecialDaysType SpecialDays;
 | 
			
		||||
	multimap<int, ATBSpecialDaysWorktime> SpecialDaysWorktime;
 | 
			
		||||
	multimap<int, ATBSpecialDays> SpecialDays;
 | 
			
		||||
	multimap<int, ATBWeekDays> WeekDays;
 | 
			
		||||
	multimap<int, ATBPeriodYear> YearPeriod;
 | 
			
		||||
	multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
 | 
			
		||||
@@ -66,18 +63,10 @@ public:
 | 
			
		||||
	/// <returns>Returns operation status bool (OK | FAIL) </returns>
 | 
			
		||||
	bool ParseJson(Configuration* cfg, const char* json);
 | 
			
		||||
 | 
			
		||||
    ATBPaymentOption &getPaymentOptions(int paymentOptionsIndex=0);
 | 
			
		||||
    ATBPaymentOption const &getPaymentOptions(int paymentOptionsIndex=0) const;
 | 
			
		||||
    ATBPaymentOption &getPaymentOptions();
 | 
			
		||||
    ATBPaymentOption const &getPaymentOptions() const;
 | 
			
		||||
    QVector<ATBPaymentOption> &getAllPaymentOptions();
 | 
			
		||||
    QVector<ATBPaymentOption> const &getAllPaymentOptions() const;
 | 
			
		||||
    int getPaymentOptionIndex(QDateTime const &dt) const;
 | 
			
		||||
    int getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const;
 | 
			
		||||
    bool isSpecialDay(QDateTime const &dt) const;
 | 
			
		||||
    int specialDayId(QDateTime const &dt) const;
 | 
			
		||||
    ATBSpecialDays specialDay(QDateTime const &dt) const;
 | 
			
		||||
    bool isDayIncluded(uint64_t businessHours, QDateTime const &dt) const;
 | 
			
		||||
    bool isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime const &dt) const;
 | 
			
		||||
    bool isDayIncludedAsSpecialDay(uint64_t businessHours, int specialDayId) const;
 | 
			
		||||
    std::optional<QVector<ATBPaymentRate>> getPaymentRateForAllKeys() const;
 | 
			
		||||
    std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
 | 
			
		||||
    std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,5 @@
 | 
			
		||||
#ifndef PAYMENT_OPT_H_INCLUDED
 | 
			
		||||
#define PAYMENT_OPT_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <cinttypes>
 | 
			
		||||
 | 
			
		||||
class ATBPaymentOption
 | 
			
		||||
{
 | 
			
		||||
@@ -23,8 +19,6 @@ public:
 | 
			
		||||
        pop_max_price = 0;
 | 
			
		||||
        pop_carry_over = -1;
 | 
			
		||||
        pop_carry_over_time_range_id = -1;
 | 
			
		||||
        pop_carry_over_start_time_range = -1;
 | 
			
		||||
        pop_carry_over_end_time_range = -1;
 | 
			
		||||
        pop_daily_card_price = -1;
 | 
			
		||||
        pop_business_hours = -1;
 | 
			
		||||
        pop_time_step_config = -1;
 | 
			
		||||
@@ -42,11 +36,7 @@ public:
 | 
			
		||||
    double pop_max_price;
 | 
			
		||||
    int pop_carry_over;
 | 
			
		||||
    int pop_carry_over_time_range_id;
 | 
			
		||||
    int pop_carry_over_start_time_range;
 | 
			
		||||
    int pop_carry_over_end_time_range;
 | 
			
		||||
    int pop_daily_card_price;
 | 
			
		||||
    uint64_t pop_business_hours;
 | 
			
		||||
    int pop_business_hours;
 | 
			
		||||
    int pop_time_step_config;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PAYMENT_OPT_H_INCLUDED
 | 
			
		||||
 
 | 
			
		||||
@@ -4,12 +4,10 @@
 | 
			
		||||
class ATBSpecialDays
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    explicit ATBSpecialDays() = default;
 | 
			
		||||
	int ped_id;
 | 
			
		||||
	std::string ped_label;
 | 
			
		||||
	std::string ped_date_start;
 | 
			
		||||
	std::string ped_date_end;
 | 
			
		||||
    int ped_period_special_day_id;
 | 
			
		||||
    int ped_payment_option_id;
 | 
			
		||||
	int ped_period_special_day_id;
 | 
			
		||||
	int ped_year;
 | 
			
		||||
};
 | 
			
		||||
@@ -4,76 +4,19 @@
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Business hours (byte represents payment option id)
 | 
			
		||||
/// </summary>
 | 
			
		||||
///
 | 
			
		||||
 | 
			
		||||
#include <Qt>
 | 
			
		||||
 | 
			
		||||
#define _NO_RESTRICTION_24_7_           (uint64_t)(0ULL)
 | 
			
		||||
#define _MON_                           (uint64_t)(1ULL << 8)
 | 
			
		||||
#define _TUE_                           (uint64_t)(1ULL << 9)
 | 
			
		||||
#define _WED_                           (uint64_t)(1ULL << 10)
 | 
			
		||||
#define _THU_                           (uint64_t)(1ULL << 11)
 | 
			
		||||
#define _FRI_                           (uint64_t)(1ULL << 12)
 | 
			
		||||
#define _SAT_                           (uint64_t)(1ULL << 13)
 | 
			
		||||
#define _SUN_                           (uint64_t)(1ULL << 14)
 | 
			
		||||
#define _WEEK_DAYS_                     ((_MON_|_TUE_|_WED_|_THU_|_FRI_))
 | 
			
		||||
#define _WORKING_DAYS_                  ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_))
 | 
			
		||||
#define _ALL_DAYS_                      ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_|_SUN_))
 | 
			
		||||
#define _OFFICIAL_HOLIDAY_              (uint64_t)(1ULL << 15)
 | 
			
		||||
#define _ONLY_WEEKEND_                  ((_SAT_|_SUN_))
 | 
			
		||||
#define _ONLY_OPEN_FOR_BUSINESS_DAYS_   (uint64_t)(1ULL << 16)    /* verkaufsoffen */
 | 
			
		||||
#define _NOT_DEFINED_                   (uint64_t)(~0ULL)
 | 
			
		||||
 | 
			
		||||
enum BusinessHours : std::uint64_t
 | 
			
		||||
enum BusinessHours
 | 
			
		||||
{
 | 
			
		||||
    NoRestriction_24_7          = 0,
 | 
			
		||||
    OnlyWorkingDays             = 1,    // [Monday-Friday]
 | 
			
		||||
    OnlyWeekDays                = 2,    // [Monday-Saturday]
 | 
			
		||||
    OnlyWeekEnd                 = 4,    // [Saturday+Sunday]
 | 
			
		||||
    OnlyOfficialHolidays        = 8,
 | 
			
		||||
    OnlySundaysAndHolidays      = 12,   // [Sun+Holiday]
 | 
			
		||||
    OnlySpecialDays             = 16,
 | 
			
		||||
    OnlySchoolHolidays          = 32,
 | 
			
		||||
    SpecialAndSchoolHolidays    = 48,
 | 
			
		||||
    OnlyOpenForBusinessDays     = 64,   // verkaufsoffen
 | 
			
		||||
    AllDaysWithRestrictedHours  = 128,  // every day, restricted to some time range
 | 
			
		||||
    NoBusinessHoursDefined      = 255,
 | 
			
		||||
 | 
			
		||||
    // new 12.04.2024
 | 
			
		||||
    NO_RESTRICTION_24_7 = _NO_RESTRICTION_24_7_,
 | 
			
		||||
    MON = _MON_,
 | 
			
		||||
    TUE = _TUE_,
 | 
			
		||||
    WED = _WED_,
 | 
			
		||||
    THU = _THU_,
 | 
			
		||||
    FRI = _FRI_,
 | 
			
		||||
    SAT = _SAT_,
 | 
			
		||||
    SUN = _SUN_,
 | 
			
		||||
    WEEK_DAYS = _WEEK_DAYS_,
 | 
			
		||||
    WORKING_DAYS = _WORKING_DAYS_,
 | 
			
		||||
    ALL_DAYS = _ALL_DAYS_,
 | 
			
		||||
    OFFICIAL_HOLIDAY = _OFFICIAL_HOLIDAY_,
 | 
			
		||||
    ONLY_WEEKEND = _ONLY_WEEKEND_,
 | 
			
		||||
    ONLY_OPEN_FOR_BUSINESS_DAYS = _ONLY_OPEN_FOR_BUSINESS_DAYS_,
 | 
			
		||||
    NOT_DEFINED = _NOT_DEFINED_
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
static bool business(uint64_t businessHours, QDateTime &const dt) {
 | 
			
		||||
    switch (dayOfWeek) {
 | 
			
		||||
    case Qt::Monday:
 | 
			
		||||
        (businessHours & _MON_) == _MON_;
 | 
			
		||||
    case Qt::Tuesday:
 | 
			
		||||
    case Qt::Wednesday:
 | 
			
		||||
    case Qt::Thursday:
 | 
			
		||||
    case Qt::Saturday:
 | 
			
		||||
    case Qt::Sunday:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
struct BusinessHours_struct {
 | 
			
		||||
    BusinessHours bh;
 | 
			
		||||
    NoBusinessHoursDefined      = 255
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TARIFF_BUSINESS_HOURS_H_INCLUDED
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +0,0 @@
 | 
			
		||||
#ifndef TARIFF_GLOBAL_DEFINES_H_INCLUDED
 | 
			
		||||
#define TARIFF_GLOBAL_DEFINES_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#define DBG_HEADER "(" << __func__ << ":" << __LINE__ << ")"
 | 
			
		||||
 | 
			
		||||
#endif // TARIFF_GLOBAL_DEFINES_H_INCLUDED
 | 
			
		||||
@@ -45,8 +45,6 @@ struct ATBTariffProduct {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint32_t getProductPrice() const { return m_tariff_product_price; }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,9 +15,6 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
namespace Utilities {
 | 
			
		||||
 | 
			
		||||
    bool isDayIncluded(uint64_t businessHours, QDateTime const &dt);
 | 
			
		||||
 | 
			
		||||
	/// <summary>
 | 
			
		||||
	/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
 | 
			
		||||
	/// </summary>
 | 
			
		||||
@@ -79,9 +76,7 @@ namespace Utilities {
 | 
			
		||||
	double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
 | 
			
		||||
 | 
			
		||||
    QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
 | 
			
		||||
    QTime SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it);
 | 
			
		||||
    QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
 | 
			
		||||
    QTime SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it);
 | 
			
		||||
    QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
 | 
			
		||||
    QTime WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
 | 
			
		||||
    int WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
 | 
			
		||||
@@ -99,5 +94,4 @@ namespace Utilities {
 | 
			
		||||
    BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
 | 
			
		||||
    uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
 | 
			
		||||
    double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
 | 
			
		||||
    QStringList dumpBusinessHours(uint64_t businessHours);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -79,8 +79,7 @@ HEADERS += \
 | 
			
		||||
    include/mobilisis/tariff_timebase.h \
 | 
			
		||||
    include/mobilisis/tariff_timestep_config.h \
 | 
			
		||||
    include/mobilisis/tariff_product.h \
 | 
			
		||||
    include/mobilisis/tariff_permit_type.h \
 | 
			
		||||
    include/mobilisis/tariff_global_defines.h
 | 
			
		||||
    include/mobilisis/tariff_permit_type.h
 | 
			
		||||
 | 
			
		||||
OTHER_FILES += src/main.cpp \
 | 
			
		||||
    ../tariffs/tariff_korneuburg.json \
 | 
			
		||||
 
 | 
			
		||||
@@ -14,14 +14,12 @@ QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
 | 
			
		||||
    return Calculator::GetInstance().GetTimeSteps(cfg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg,
 | 
			
		||||
                                                  PERMIT_TYPE permitType,
 | 
			
		||||
                                                  int paymentOptionIndex) {
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) {
 | 
			
		||||
    int minTime = 0;
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
        minTime = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
        minTime = cfg->getPaymentOptions().pop_min_time;
 | 
			
		||||
    } break;
 | 
			
		||||
    case PERMIT_TYPE::DAY_TICKET_ADULT: {
 | 
			
		||||
    } break;
 | 
			
		||||
@@ -32,22 +30,20 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg,
 | 
			
		||||
    default:
 | 
			
		||||
        // for each new sell-procedure, recomute the timesteps. implicitly, set
 | 
			
		||||
        // the minimal parking time.
 | 
			
		||||
        Calculator::GetInstance().ResetTimeSteps(paymentOptionIndex);
 | 
			
		||||
        Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex);
 | 
			
		||||
        minTime = qRound(cfg->getPaymentOptions(paymentOptionIndex).pop_min_time);
 | 
			
		||||
        Calculator::GetInstance().ResetTimeSteps();
 | 
			
		||||
        Calculator::GetInstance().GetTimeSteps(cfg);
 | 
			
		||||
        minTime = qRound(cfg->getPaymentOptions().pop_min_time);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return minTime;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg,
 | 
			
		||||
                                                  PERMIT_TYPE permitType,
 | 
			
		||||
                                                  int paymentOptionIndex) {
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) {
 | 
			
		||||
    int maxTime = 0;
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
        maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
 | 
			
		||||
        maxTime = cfg->getPaymentOptions().pop_max_time;
 | 
			
		||||
    } break;
 | 
			
		||||
    case PERMIT_TYPE::DAY_TICKET_ADULT: {
 | 
			
		||||
    } break;
 | 
			
		||||
@@ -61,14 +57,12 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg,
 | 
			
		||||
    return maxTime;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
 | 
			
		||||
                                                   PERMIT_TYPE permitType,
 | 
			
		||||
                                                   int paymentOptionIndex) {
 | 
			
		||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
 | 
			
		||||
    int minPrice = -1;
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
        minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
 | 
			
		||||
        minPrice = cfg->getPaymentOptions().pop_min_price;
 | 
			
		||||
    } break;
 | 
			
		||||
    case PERMIT_TYPE::DAY_TICKET_ADULT: {
 | 
			
		||||
    } break;
 | 
			
		||||
@@ -82,11 +76,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
 | 
			
		||||
    return minPrice;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
 | 
			
		||||
                                                PERMIT_TYPE permitType,
 | 
			
		||||
                                                QDateTime const &start,
 | 
			
		||||
                                                QDateTime *productStart,
 | 
			
		||||
                                                QDateTime *productEnd) {
 | 
			
		||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType) {
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
@@ -122,40 +112,6 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } break;
 | 
			
		||||
    case PERMIT_TYPE::INVALID:
 | 
			
		||||
        // [[fallthrough]];
 | 
			
		||||
    case PERMIT_TYPE::DAY_TICKET: {
 | 
			
		||||
        std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
 | 
			
		||||
        if (products) {
 | 
			
		||||
            QVector<ATBTariffProduct> product = products.value();
 | 
			
		||||
            int product_price = 0;
 | 
			
		||||
 | 
			
		||||
            if (productStart && productEnd) {
 | 
			
		||||
                *productStart = start;
 | 
			
		||||
                *productEnd = start;
 | 
			
		||||
                if (product.size() > 0) {
 | 
			
		||||
                    productStart->setTime(product[0].getTimeStart());
 | 
			
		||||
                    productEnd->setTime(product[0].getTimeEnd());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for (QVector<ATBTariffProduct>::size_type i=0; i<product.size(); ++i) {
 | 
			
		||||
                ATBTariffProduct const &p = product[i];
 | 
			
		||||
                QTime const &startTime = p.getTimeStart();
 | 
			
		||||
                QTime const &endTime = p.getTimeEnd();
 | 
			
		||||
 | 
			
		||||
                if (start.time() >= startTime && start.time() < endTime) {
 | 
			
		||||
                    product_price = p.getProductPrice();
 | 
			
		||||
                    if (productStart && productEnd) {
 | 
			
		||||
                        productStart->setTime(startTime);
 | 
			
		||||
                        productEnd->setTime(endTime);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return product_price;
 | 
			
		||||
        }
 | 
			
		||||
    } break;
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
@@ -163,19 +119,17 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
 | 
			
		||||
                                                   PERMIT_TYPE permitType,
 | 
			
		||||
                                                   int paymentOptionIndex) {
 | 
			
		||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
 | 
			
		||||
    int maxPrice = -1;
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
 | 
			
		||||
    switch(permitType) {
 | 
			
		||||
    case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
 | 
			
		||||
        if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        if (paymentMethodId == PaymentMethod::Progressive) {
 | 
			
		||||
            maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
 | 
			
		||||
        } 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
 | 
			
		||||
            int const key = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
            int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
 | 
			
		||||
            std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
 | 
			
		||||
            if (pv) {
 | 
			
		||||
                QVector<ATBPaymentRate> const &paymentRate = pv.value();
 | 
			
		||||
@@ -445,11 +399,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
        bool prepaid)
 | 
			
		||||
{
 | 
			
		||||
    CalcState calcState;
 | 
			
		||||
 | 
			
		||||
    int paymentOptionIndex = tariff->getPaymentOptionIndex(start_parking_time);
 | 
			
		||||
 | 
			
		||||
    double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
    double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
 | 
			
		||||
    double minMin = tariff->getPaymentOptions().pop_min_time;
 | 
			
		||||
    double maxMin = tariff->getPaymentOptions().pop_max_time;
 | 
			
		||||
 | 
			
		||||
    // DEBUG
 | 
			
		||||
    qCritical() << "compute_price_for_parking_ticket() " << endl
 | 
			
		||||
@@ -477,26 +428,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
        return calcState.set(CalcState::State::SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    double cost = -1;
 | 
			
		||||
    if (start_parking_time.isValid()) {
 | 
			
		||||
        if (tariff->getPaymentOptions().pop_payment_method_id == PaymentMethod::Steps) {
 | 
			
		||||
            // hier muesste man unterscheiden: uebertrag oder nicht?
 | 
			
		||||
            calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
 | 
			
		||||
                                                                   netto_parking_time, paymentOptionIndex);
 | 
			
		||||
            if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
 | 
			
		||||
                return calcState;
 | 
			
		||||
            }
 | 
			
		||||
            cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
 | 
			
		||||
        } else {
 | 
			
		||||
            cost = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
        double cost = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
                        tariff,
 | 
			
		||||
                        tariff->getPaymentOptions().pop_payment_method_id,
 | 
			
		||||
                        start_parking_time,         // starting time
 | 
			
		||||
                        end_parking_time,           // return value: end time
 | 
			
		||||
                        netto_parking_time,         // minutes, netto
 | 
			
		||||
                        false, prepaid);
 | 
			
		||||
        }
 | 
			
		||||
        double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price;
 | 
			
		||||
        double minCost = tariff->getPaymentOptions().pop_min_price;
 | 
			
		||||
        if (cost < minCost) {
 | 
			
		||||
            calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
 | 
			
		||||
            return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
 | 
			
		||||
@@ -505,10 +445,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
			
		||||
        // DEBUG
 | 
			
		||||
        qCritical() << "               -> calculated cost (price->netto) =  " << cost;
 | 
			
		||||
 | 
			
		||||
        price->brutto = price->vat = price->vat_percentage = 0;
 | 
			
		||||
        price->units = cost;
 | 
			
		||||
        price->netto = cost;
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
        return calcState.set(CalcState::State::INVALID_START_DATE);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,6 @@
 | 
			
		||||
#include "tariff_log.h"
 | 
			
		||||
#include "tariff_time_range.h"
 | 
			
		||||
#include "ticket.h"
 | 
			
		||||
#include "tariff_global_defines.h"
 | 
			
		||||
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
@@ -591,292 +590,35 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
 | 
			
		||||
                                         QDateTime const &start,
 | 
			
		||||
                                         quint64 timeStepInMinutes,
 | 
			
		||||
                                         int paymentOptionIndex) const {
 | 
			
		||||
                                         quint64 timeStepInMinutes) const {
 | 
			
		||||
    // for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
 | 
			
		||||
    // special days, nonstop.
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        QDateTime const end = start.addSecs(timeStepInMinutes*60);
 | 
			
		||||
        return GetCostFromDuration(cfg, start, end, paymentOptionIndex);
 | 
			
		||||
        return GetCostFromDuration(cfg, start, end);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
 | 
			
		||||
                                         QDateTime const &start,
 | 
			
		||||
                                         QDateTime const &end,
 | 
			
		||||
                                         int paymentOptionIndex) const {
 | 
			
		||||
                                         QDateTime const &end) const {
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        int const timeStepInMinutes = start.secsTo(end) / 60;
 | 
			
		||||
        return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
 | 
			
		||||
        return GetPriceForTimeStep(cfg, timeStepInMinutes);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
 | 
			
		||||
                                                 QDateTime const &start,
 | 
			
		||||
                                                 int netto_parking_time,
 | 
			
		||||
                                                 int paymentOptionIndex) {
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
 | 
			
		||||
                << "paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
 | 
			
		||||
    QString errorStr = "UNKNOWN ERROR";
 | 
			
		||||
 | 
			
		||||
    PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
 | 
			
		||||
        if (cfg->isDayIncluded(businessHours, start)) {
 | 
			
		||||
            if (businessHours == BusinessHours::NO_RESTRICTION_24_7) {
 | 
			
		||||
                return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
 | 
			
		||||
                         QTime(0, 0, 0), QTime(23, 59, 59));
 | 
			
		||||
            }
 | 
			
		||||
            int const weekdayId = start.date().dayOfWeek();
 | 
			
		||||
            if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
 | 
			
		||||
                using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
 | 
			
		||||
                std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
 | 
			
		||||
 | 
			
		||||
                for (WTIterator itr = p.first; itr != p.second; ++itr) {
 | 
			
		||||
                    QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
 | 
			
		||||
                    QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
 | 
			
		||||
 | 
			
		||||
                    qCritical() << DBG_HEADER
 | 
			
		||||
                                << "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
 | 
			
		||||
                                << from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
 | 
			
		||||
 | 
			
		||||
                    QTime const &startTime = start.time();
 | 
			
		||||
 | 
			
		||||
                    if (startTime >= from && startTime <= until) {
 | 
			
		||||
                        QTime const endTime = start.addSecs(netto_parking_time*60).time();
 | 
			
		||||
                        if (endTime <= until) {
 | 
			
		||||
                            return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
 | 
			
		||||
                                                .arg(__LINE__)
 | 
			
		||||
                                                .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                                .arg(from.toString(Qt::ISODate))
 | 
			
		||||
                                                .arg(endTime.toString(Qt::ISODate));
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
 | 
			
		||||
                                            .arg(__LINE__)
 | 
			
		||||
                                            .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                            .arg(from.toString(Qt::ISODate))
 | 
			
		||||
                                            .arg(until.toString(Qt::ISODate));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
 | 
			
		||||
                    if (pop_carry_over == 1) {
 | 
			
		||||
                        qCritical() << DBG_HEADER
 | 
			
		||||
                                    << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
 | 
			
		||||
 | 
			
		||||
                        int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
 | 
			
		||||
                        int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
 | 
			
		||||
 | 
			
		||||
                        if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
 | 
			
		||||
                            cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
 | 
			
		||||
 | 
			
		||||
                            ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
 | 
			
		||||
                            ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
 | 
			
		||||
 | 
			
		||||
                            if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
 | 
			
		||||
                                QDateTime sd = start;
 | 
			
		||||
                                sd.setTime(s.getTimeUntil());
 | 
			
		||||
 | 
			
		||||
                                QDateTime ed = start.addDays(1);
 | 
			
		||||
                                ed.setTime(e.getTimeFrom());
 | 
			
		||||
 | 
			
		||||
                                int const jumpSecs = sd.secsTo(ed);
 | 
			
		||||
                                QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
 | 
			
		||||
                                if (end.time() <= e.getTimeUntil()) {
 | 
			
		||||
 | 
			
		||||
                                    qCritical() << DBG_HEADER
 | 
			
		||||
                                                << "PARKING IS ALLOWED WITH CARRY-OVER ("
 | 
			
		||||
                                                << start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
 | 
			
		||||
 | 
			
		||||
                                    return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
 | 
			
		||||
                                                     startTime, end.time());
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    errorStr = QString("endTime %1 exceeds [%2, %3))")
 | 
			
		||||
                                                  .arg(end.toString(Qt::ISODate))
 | 
			
		||||
                                                  .arg(sd.toString(Qt::ISODate))
 | 
			
		||||
                                                  .arg(ed.toString(Qt::ISODate));
 | 
			
		||||
                                }
 | 
			
		||||
                            } else {
 | 
			
		||||
                                errorStr = QString("startTime %1 exceeds [%2, %3))")
 | 
			
		||||
                                              .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                              .arg(s.getTimeFrom().toString(Qt::ISODate))
 | 
			
		||||
                                              .arg(s.getTimeUntil().toString(Qt::ISODate));
 | 
			
		||||
                            }
 | 
			
		||||
                        } else {
 | 
			
		||||
                           errorStr = "no carry-over limits configured";
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        errorStr = "no carry-over configured";
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                errorStr = QString("no weekday configured for day-id %1").arg(weekdayId);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
            errorStr = QString("start %1 not contained in business hours %2")
 | 
			
		||||
                            .arg(start.toString(Qt::ISODate))
 | 
			
		||||
                            .arg(businessHours);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
 | 
			
		||||
                     QTime(), QTime());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CalcState Calculator::isParkingAllowedForSpecialDay(Configuration const *cfg,
 | 
			
		||||
                                                    QDateTime const &start,
 | 
			
		||||
                                                    int netto_parking_time,
 | 
			
		||||
                                                    int paymentOptionIndex) {
 | 
			
		||||
    QString errorStr = "UNKNOWN ERROR";
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
 | 
			
		||||
                << "paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
 | 
			
		||||
    PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        //uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
 | 
			
		||||
        int const specialDayId = cfg->specialDayId(start);
 | 
			
		||||
        if ((specialDayId > 0) && (cfg->SpecialDaysWorktime.count(specialDayId) > 0)) {
 | 
			
		||||
            using SDIterator = Configuration::SpecialDaysWorktimeType::const_iterator;
 | 
			
		||||
            std::pair<SDIterator, SDIterator> p = cfg->SpecialDaysWorktime.equal_range(specialDayId);
 | 
			
		||||
 | 
			
		||||
            for (SDIterator it = p.first; it != p.second; ++it) {
 | 
			
		||||
                QTime const &from = Utilities::SpecialDaysWorkTimeFrom(it);
 | 
			
		||||
                QTime const &until = Utilities::SpecialDaysWorkTimeUntil(it);
 | 
			
		||||
 | 
			
		||||
                qCritical() << DBG_HEADER
 | 
			
		||||
                            << "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
 | 
			
		||||
                            << from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
 | 
			
		||||
 | 
			
		||||
                QTime const &startTime = start.time();
 | 
			
		||||
 | 
			
		||||
                if (startTime >= from && startTime <= until) {
 | 
			
		||||
                    QTime const endTime = start.addSecs(netto_parking_time*60).time();
 | 
			
		||||
                    if (endTime <= until) {
 | 
			
		||||
                        return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
 | 
			
		||||
                                            .arg(__LINE__)
 | 
			
		||||
                                            .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                            .arg(from.toString(Qt::ISODate))
 | 
			
		||||
                                            .arg(endTime.toString(Qt::ISODate));
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
 | 
			
		||||
                                        .arg(__LINE__)
 | 
			
		||||
                                        .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                        .arg(from.toString(Qt::ISODate))
 | 
			
		||||
                                        .arg(until.toString(Qt::ISODate));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
 | 
			
		||||
                if (pop_carry_over == 1) {
 | 
			
		||||
                    qCritical() << DBG_HEADER << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
 | 
			
		||||
 | 
			
		||||
                    int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
 | 
			
		||||
                    int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
 | 
			
		||||
 | 
			
		||||
                    if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
 | 
			
		||||
                        cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
 | 
			
		||||
 | 
			
		||||
                        ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
 | 
			
		||||
                        ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
 | 
			
		||||
 | 
			
		||||
                        if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
 | 
			
		||||
                            QDateTime sd = start;
 | 
			
		||||
                            sd.setTime(s.getTimeUntil());
 | 
			
		||||
 | 
			
		||||
                            QDateTime ed = start.addDays(1);
 | 
			
		||||
                            ed.setTime(e.getTimeFrom());
 | 
			
		||||
 | 
			
		||||
                            int const jumpSecs = sd.secsTo(ed);
 | 
			
		||||
                            QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
 | 
			
		||||
                            if (end.time() <= e.getTimeUntil()) {
 | 
			
		||||
 | 
			
		||||
                                ed.setTime(e.getTimeUntil()); // for printing
 | 
			
		||||
 | 
			
		||||
                                qCritical() << DBG_HEADER
 | 
			
		||||
                                            << "PARKING IS ALLOWED WITH CARRY-OVER ("
 | 
			
		||||
                                            << start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
 | 
			
		||||
 | 
			
		||||
                                return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
 | 
			
		||||
                                                 startTime, end.time());
 | 
			
		||||
                            } else {
 | 
			
		||||
                                ed.setTime(e.getTimeUntil()); // for printing
 | 
			
		||||
 | 
			
		||||
                                errorStr = QString("endTime %1 exceeds [%2, %3))")
 | 
			
		||||
                                              .arg(end.toString(Qt::ISODate))
 | 
			
		||||
                                              .arg(sd.toString(Qt::ISODate))
 | 
			
		||||
                                              .arg(ed.toString(Qt::ISODate));
 | 
			
		||||
                            }
 | 
			
		||||
                        } else {
 | 
			
		||||
                            errorStr = QString("startTime %1 exceeds [%2, %3))")
 | 
			
		||||
                                          .arg(startTime.toString(Qt::ISODate))
 | 
			
		||||
                                          .arg(s.getTimeFrom().toString(Qt::ISODate))
 | 
			
		||||
                                          .arg(s.getTimeUntil().toString(Qt::ISODate));
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                       errorStr = "no carry-over limits configured";
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    errorStr = "no carry-over configured";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
 | 
			
		||||
                     QTime(), QTime());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
 | 
			
		||||
                                       QDateTime const &start,
 | 
			
		||||
                                       int netto_parking_time,
 | 
			
		||||
                                       int paymentOptionIndex) {
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << "CHECK IF PARKING IS ALLOWED AT"
 | 
			
		||||
                << start.toString(Qt::ISODate) << "...";
 | 
			
		||||
 | 
			
		||||
    CalcState cs;
 | 
			
		||||
 | 
			
		||||
    if ((cs = isParkingAllowedForWeekDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
 | 
			
		||||
        return cs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << QString(cs);
 | 
			
		||||
 | 
			
		||||
    if ((cs = isParkingAllowedForSpecialDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
 | 
			
		||||
        return cs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << DBG_HEADER << QString(cs);
 | 
			
		||||
 | 
			
		||||
    return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, "UNKNOWN ERROR",
 | 
			
		||||
                     QTime(), QTime());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
 | 
			
		||||
                                       QDateTime const &start) {
 | 
			
		||||
CalcState Calculator::isParkingAllowed(Configuration const *cfg, QDateTime const &start) {
 | 
			
		||||
    static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
 | 
			
		||||
    if (paymentMethodId == PaymentMethod::Steps) {
 | 
			
		||||
        int const weekdayId = start.date().dayOfWeek();
 | 
			
		||||
        BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
 | 
			
		||||
        if (businessHours == BusinessHours::NoRestriction_24_7) {
 | 
			
		||||
            return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
 | 
			
		||||
                             QTime(0, 0, 0), QTime(23, 59, 59));
 | 
			
		||||
        } else
 | 
			
		||||
        if (businessHours == BusinessHours::OnlyWeekDays) {
 | 
			
		||||
            if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
 | 
			
		||||
                if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
 | 
			
		||||
@@ -1827,26 +1569,24 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
 | 
			
		||||
    return QList<int>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const {
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "paymentOptionIndex:" << paymentOptionIndex;
 | 
			
		||||
 | 
			
		||||
    if (m_timeSteps.size() > paymentOptionIndex) {
 | 
			
		||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
 | 
			
		||||
    if (m_timeSteps.size() > 0) {
 | 
			
		||||
        //qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps;
 | 
			
		||||
        return m_timeSteps[paymentOptionIndex];
 | 
			
		||||
        return m_timeSteps;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
    start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
 | 
			
		||||
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
    int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
 | 
			
		||||
    int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
    int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
 | 
			
		||||
    int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
 | 
			
		||||
 | 
			
		||||
    static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
 | 
			
		||||
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ")        start parking time:" << start.toString(Qt::ISODate);
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ")         payment option id:" << pop_id;
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
 | 
			
		||||
    qCritical() << __func__ << ":" << __LINE__ << "       start parking time:" << start.toString(Qt::ISODate);
 | 
			
		||||
    qCritical() << __func__ << ":" << __LINE__ << "        payment option id:" << pop_id;
 | 
			
		||||
    qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over;
 | 
			
		||||
 | 
			
		||||
    if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
 | 
			
		||||
        //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
 | 
			
		||||
@@ -1855,13 +1595,13 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
 | 
			
		||||
            std::size_t const s = cfg->TimeRange.size();
 | 
			
		||||
            for (std::size_t id = 1; id <= s; ++id) {
 | 
			
		||||
                int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
 | 
			
		||||
                m_timeSteps[paymentOptionIndex].append(step);
 | 
			
		||||
                m_timeSteps.append(step);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            uint16_t timeStepCompensation = 0;
 | 
			
		||||
 | 
			
		||||
            if (pop_carry_over) {
 | 
			
		||||
                int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
 | 
			
		||||
                int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
 | 
			
		||||
                QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
 | 
			
		||||
                QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
 | 
			
		||||
 | 
			
		||||
@@ -1885,19 +1625,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
 | 
			
		||||
                                                .arg(timeStep).arg(duration.pun_duration_max);
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    }
 | 
			
		||||
                                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
                                    qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
 | 
			
		||||
 | 
			
		||||
                                    // set dynamic minimal parking time
 | 
			
		||||
                                    cfg->getPaymentOptions().pop_min_time = timeStep;
 | 
			
		||||
 | 
			
		||||
                                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
 | 
			
		||||
                                    qCritical() << __PRETTY_FUNCTION__ << "  computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
 | 
			
		||||
 | 
			
		||||
                                    duration.pun_duration = timeStep;
 | 
			
		||||
                                    timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
 | 
			
		||||
                                    m_timeSteps[paymentOptionIndex] << duration.pun_duration;
 | 
			
		||||
                                    m_timeSteps << duration.pun_duration;
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
 | 
			
		||||
                                    m_timeSteps[paymentOptionIndex] << duration.pun_duration;;
 | 
			
		||||
                                    m_timeSteps << duration.pun_duration;;
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                cfg->Duration.erase(search);
 | 
			
		||||
@@ -1918,31 +1658,24 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
 | 
			
		||||
        qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
 | 
			
		||||
 | 
			
		||||
        for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
 | 
			
		||||
        {
 | 
			
		||||
            int const durationId = itr->second.pra_payment_unit_id;
 | 
			
		||||
            int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
			
		||||
            int size = m_timeSteps.size();
 | 
			
		||||
 | 
			
		||||
            while (size <= paymentOptionIndex) {
 | 
			
		||||
                m_timeSteps.push_back(QList<int>());
 | 
			
		||||
                size = m_timeSteps.size();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            m_timeSteps[paymentOptionIndex] << durationUnit;
 | 
			
		||||
            m_timeSteps << durationUnit;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "NEW timeSteps:" << m_timeSteps;
 | 
			
		||||
    qCritical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps;
 | 
			
		||||
 | 
			
		||||
    return m_timeSteps[paymentOptionIndex];
 | 
			
		||||
    return m_timeSteps;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
 | 
			
		||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
 | 
			
		||||
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
 | 
			
		||||
    int const pop_id = cfg->getPaymentOptions().pop_id;
 | 
			
		||||
 | 
			
		||||
    for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,8 @@
 | 
			
		||||
#include "configuration.h"
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
#include "tariff_timebase.h"
 | 
			
		||||
#include "time_range_header.h"
 | 
			
		||||
#include "tariff_timestep_config.h"
 | 
			
		||||
#include "tariff_permit_type.h"
 | 
			
		||||
#include "tariff_business_hours.h"
 | 
			
		||||
#include "tariff_global_defines.h"
 | 
			
		||||
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
@@ -416,24 +413,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_carry_over = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_carry_over_time_range_id = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_carry_over_start_time_range") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_carry_over_start_time_range = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_carry_over_end_time_range") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_carry_over_end_time_range = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_daily_card_price = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_business_hours") == 0) {
 | 
			
		||||
                            if (k->value.IsInt()) {
 | 
			
		||||
                                int const v = k->value.GetInt();
 | 
			
		||||
                                this->currentPaymentOptions.last().pop_business_hours = v;
 | 
			
		||||
                            } else
 | 
			
		||||
                            if (k->value.IsString()) {
 | 
			
		||||
                                bool ok;
 | 
			
		||||
                                uint64_t const v = QString::fromStdString(k->value.GetString()).toLongLong(&ok);
 | 
			
		||||
                                if (ok) {
 | 
			
		||||
                                    this->currentPaymentOptions.last().pop_business_hours = v;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_business_hours = k->value.GetInt();
 | 
			
		||||
                        } else if (strcmp(inner_obj_name, "pop_time_step_config") == 0) {
 | 
			
		||||
                            this->currentPaymentOptions.last().pop_time_step_config = k->value.GetInt();
 | 
			
		||||
                        }
 | 
			
		||||
@@ -470,8 +453,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
						else if (strcmp(inner_obj_name, "ped_date_start") == 0) SpecialDays.ped_date_start = k->value.GetString();
 | 
			
		||||
						else if (strcmp(inner_obj_name, "ped_date_end") == 0) SpecialDays.ped_date_end = k->value.GetString();
 | 
			
		||||
						else if (strcmp(inner_obj_name, "ped_period_special_day_id") == 0) SpecialDays.ped_period_special_day_id = k->value.GetInt();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "ped_payment_option_id") == 0) SpecialDays.ped_payment_option_id = k->value.GetInt();
 | 
			
		||||
                        else if (strcmp(inner_obj_name, "ped_year") == 0) SpecialDays.ped_year = k->value.GetInt();
 | 
			
		||||
						else if (strcmp(inner_obj_name, "ped_year") == 0) SpecialDays.ped_year = k->value.GetInt();
 | 
			
		||||
						break;
 | 
			
		||||
					case MemberType::PeriodYearType:
 | 
			
		||||
						if (strcmp(inner_obj_name, "pye_id") == 0) YearPeriod.pye_id = k->value.GetInt();
 | 
			
		||||
@@ -560,134 +542,15 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Configuration::getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const {
 | 
			
		||||
    if (isSpecialDay(dt)) {
 | 
			
		||||
        int const numOptions = getAllPaymentOptions().size();
 | 
			
		||||
        for (int opt=0; opt < numOptions; ++opt) {
 | 
			
		||||
            uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
 | 
			
		||||
            if ((pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
                return opt;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
 | 
			
		||||
    int const numOptions = getAllPaymentOptions().size();
 | 
			
		||||
 | 
			
		||||
    // special days are handled before usual week days
 | 
			
		||||
    int const sid = specialDayId(dt);
 | 
			
		||||
    if (sid > 0) {
 | 
			
		||||
        ATBSpecialDays const sd = specialDay(dt);
 | 
			
		||||
        if (sd.ped_id != 0) {
 | 
			
		||||
            for (int opt=0; opt < numOptions; ++opt) {
 | 
			
		||||
                uint64_t const pop_id = getPaymentOptions(opt).pop_id;
 | 
			
		||||
                if (pop_id == sd.ped_payment_option_id) {
 | 
			
		||||
                    return opt;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (int opt=0; opt < numOptions; ++opt) {
 | 
			
		||||
        uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        uint64_t p = 0;
 | 
			
		||||
        int const dayOfWeek = dt.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
        switch (dayOfWeek) {
 | 
			
		||||
        case (int)Qt::Monday: {
 | 
			
		||||
            p = BusinessHours::MON;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Tuesday: {
 | 
			
		||||
            p = BusinessHours::TUE;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Wednesday: {
 | 
			
		||||
            p = BusinessHours::WED;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Thursday: {
 | 
			
		||||
            p = BusinessHours::THU;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Friday: {
 | 
			
		||||
            p = BusinessHours::FRI;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Saturday: {
 | 
			
		||||
            p = BusinessHours::SAT;
 | 
			
		||||
        } break;
 | 
			
		||||
        case (int)Qt::Sunday: {
 | 
			
		||||
            p = BusinessHours::SUN;
 | 
			
		||||
            qCritical() << DBG_HEADER << Utilities::dumpBusinessHours(pop_business_hours) << pop_business_hours << p;
 | 
			
		||||
        } break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ((pop_business_hours & p) == p) {
 | 
			
		||||
            return opt;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ATBSpecialDays Configuration::specialDay(QDateTime const &dt) const {
 | 
			
		||||
    SpecialDaysType::const_iterator it;
 | 
			
		||||
    for (it = SpecialDays.cbegin(); it != SpecialDays.cend(); ++it) {
 | 
			
		||||
        if (dt.date().toString(Qt::ISODate) == QString::fromStdString(it->second.ped_date_start)) {
 | 
			
		||||
            return it->second;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ATBSpecialDays();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Configuration::specialDayId(QDateTime const &dt) const {
 | 
			
		||||
    SpecialDaysType::const_iterator it;
 | 
			
		||||
    for (it = SpecialDays.cbegin(); it != SpecialDays.cend(); ++it) {
 | 
			
		||||
        if (dt.date().toString(Qt::ISODate) == QString::fromStdString(it->second.ped_date_start)) {
 | 
			
		||||
            int const specialDayId = it->second.ped_id;
 | 
			
		||||
            return specialDayId; // must be > 0
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Configuration::isSpecialDay(QDateTime const &dt) const {
 | 
			
		||||
    return (specialDayId(dt) > 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, int specialDayId) const {
 | 
			
		||||
    if (specialDayId > 0) {
 | 
			
		||||
        bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
 | 
			
		||||
        return r;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime const &dt) const {
 | 
			
		||||
    // included in 'businessHours'
 | 
			
		||||
 | 
			
		||||
    if (isSpecialDay(dt)) {
 | 
			
		||||
        bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
 | 
			
		||||
        qCritical() << "XXXXXXXXXXXXXXXXXX r" << r << businessHours;
 | 
			
		||||
        return r;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Configuration::isDayIncluded(uint64_t businessHours, QDateTime const &dt) const {
 | 
			
		||||
    return Utilities::isDayIncluded(businessHours, dt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ATBPaymentOption const &Configuration::getPaymentOptions(int paymentOptionsIndex) const {
 | 
			
		||||
ATBPaymentOption const &Configuration::getPaymentOptions() const {
 | 
			
		||||
    Q_ASSERT(!this->currentPaymentOptions.isEmpty());
 | 
			
		||||
    return this->currentPaymentOptions.at(paymentOptionsIndex);
 | 
			
		||||
    return this->currentPaymentOptions.at(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ATBPaymentOption &Configuration::getPaymentOptions(int paymentOptionsIndex) {
 | 
			
		||||
ATBPaymentOption &Configuration::getPaymentOptions() {
 | 
			
		||||
    Q_ASSERT(!this->currentPaymentOptions.isEmpty());
 | 
			
		||||
    return this->currentPaymentOptions[paymentOptionsIndex];
 | 
			
		||||
    return this->currentPaymentOptions[0];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVector<ATBPaymentOption> const &Configuration::getAllPaymentOptions() const {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
#include "utilities.h"
 | 
			
		||||
#include "tariff_log.h"
 | 
			
		||||
#include "tariff_business_hours.h"
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
@@ -261,7 +260,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
 | 
			
		||||
						//cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
 | 
			
		||||
						if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
 | 
			
		||||
						{
 | 
			
		||||
                            //LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
 | 
			
		||||
							LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
 | 
			
		||||
							*specialDayId = spec_days_itr->second.ped_id;
 | 
			
		||||
							*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
 | 
			
		||||
							return true;
 | 
			
		||||
@@ -276,7 +275,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
 | 
			
		||||
					//cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
 | 
			
		||||
					if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
 | 
			
		||||
					{
 | 
			
		||||
                        //LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
 | 
			
		||||
						LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
 | 
			
		||||
						*specialDayId = spec_days_itr->second.ped_id;
 | 
			
		||||
						*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
 | 
			
		||||
						return true;
 | 
			
		||||
@@ -318,7 +317,7 @@ bool Utilities::CheckSpecialDay(Configuration const *cfg,
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    //qDebug() << "CheckSpecialDay() => SPECIAL DAY";
 | 
			
		||||
                    qDebug() << "CheckSpecialDay() => SPECIAL DAY";
 | 
			
		||||
                    *specialDayId = spec_days_itr->second.ped_id;
 | 
			
		||||
                    *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
 | 
			
		||||
                    return true;
 | 
			
		||||
@@ -334,14 +333,6 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
 | 
			
		||||
    return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it) {
 | 
			
		||||
    return QTime::fromString(it->second.pedwt_time_from.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it) {
 | 
			
		||||
    return QTime::fromString(it->second.pedwt_time_to.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
 | 
			
		||||
    return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
 | 
			
		||||
}
 | 
			
		||||
@@ -429,10 +420,10 @@ uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) {
 | 
			
		||||
    uint64_t businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
 | 
			
		||||
    int businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
 | 
			
		||||
 | 
			
		||||
    switch (businessHours) {
 | 
			
		||||
    //case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
 | 
			
		||||
    case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
 | 
			
		||||
    case OnlyWorkingDays: return BusinessHours::OnlyWorkingDays;
 | 
			
		||||
    case OnlyWeekDays: return BusinessHours::OnlyWeekDays;
 | 
			
		||||
    case OnlyWeekEnd: return BusinessHours::OnlyWeekEnd;
 | 
			
		||||
@@ -442,21 +433,6 @@ BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMetho
 | 
			
		||||
    case SpecialAndSchoolHolidays: return BusinessHours::SpecialAndSchoolHolidays;
 | 
			
		||||
    case OnlyOpenForBusinessDays: return BusinessHours::OnlyOpenForBusinessDays;
 | 
			
		||||
    case AllDaysWithRestrictedHours: return BusinessHours::AllDaysWithRestrictedHours;
 | 
			
		||||
    case _NO_RESTRICTION_24_7_: return BusinessHours::NO_RESTRICTION_24_7;
 | 
			
		||||
    case _MON_: return BusinessHours::MON;
 | 
			
		||||
    case _TUE_: return BusinessHours::TUE;
 | 
			
		||||
    case _WED_: return BusinessHours::WED;
 | 
			
		||||
    case _THU_: return BusinessHours::THU;
 | 
			
		||||
    case _FRI_: return BusinessHours::FRI;
 | 
			
		||||
    case _SAT_: return BusinessHours::SAT;
 | 
			
		||||
    case _SUN_: return BusinessHours::SUN;
 | 
			
		||||
    case _WEEK_DAYS_: return BusinessHours::WEEK_DAYS;
 | 
			
		||||
    case _WORKING_DAYS_: return BusinessHours::WORKING_DAYS;
 | 
			
		||||
    case _ALL_DAYS_: return BusinessHours::ALL_DAYS;
 | 
			
		||||
    case _OFFICIAL_HOLIDAY_: return BusinessHours::OFFICIAL_HOLIDAY;
 | 
			
		||||
    case _ONLY_WEEKEND_: return BusinessHours::ONLY_WEEKEND;
 | 
			
		||||
    case _ONLY_OPEN_FOR_BUSINESS_DAYS_: return BusinessHours::ONLY_OPEN_FOR_BUSINESS_DAYS;
 | 
			
		||||
    case _NOT_DEFINED_: return BusinessHours::NOT_DEFINED;
 | 
			
		||||
    }
 | 
			
		||||
    return BusinessHours::NoBusinessHoursDefined;
 | 
			
		||||
}
 | 
			
		||||
@@ -471,82 +447,3 @@ double Utilities::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentM
 | 
			
		||||
    int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
 | 
			
		||||
    return (double)(cfg->Duration.find(durationId)->second.pun_duration);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Utilities::isDayIncluded(uint64_t businessHours, QDateTime const &dt) {
 | 
			
		||||
    int dayOfWeek = dt.date().dayOfWeek();
 | 
			
		||||
    switch (dayOfWeek) {
 | 
			
		||||
    case Qt::Monday:
 | 
			
		||||
        return ((businessHours & BusinessHours::MON) == BusinessHours::MON);
 | 
			
		||||
    case Qt::Tuesday:
 | 
			
		||||
        return ((businessHours & BusinessHours::TUE) == BusinessHours::TUE);
 | 
			
		||||
    case Qt::Wednesday:
 | 
			
		||||
        return ((businessHours & BusinessHours::WED) == BusinessHours::WED);
 | 
			
		||||
    case Qt::Thursday:
 | 
			
		||||
        return ((businessHours & BusinessHours::THU) == BusinessHours::THU);
 | 
			
		||||
    case Qt::Friday:
 | 
			
		||||
        return ((businessHours & BusinessHours::FRI) == BusinessHours::FRI);
 | 
			
		||||
    case Qt::Saturday:
 | 
			
		||||
        return ((businessHours & BusinessHours::SAT) == BusinessHours::SAT);
 | 
			
		||||
    case Qt::Sunday:
 | 
			
		||||
        return ((businessHours & BusinessHours::SUN) == BusinessHours::SUN);
 | 
			
		||||
    default:;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QStringList Utilities::dumpBusinessHours(uint64_t businessHours) {
 | 
			
		||||
    QStringList s;
 | 
			
		||||
 | 
			
		||||
    if ((businessHours & BusinessHours::MON) == BusinessHours::MON) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "MON (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "MON";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::TUE) == BusinessHours::TUE) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "TUE (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "TUE";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::WED) == BusinessHours::WED) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "WED (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "WED";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::THU) == BusinessHours::THU) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "THU (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "THU";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::FRI) == BusinessHours::FRI) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "FRI (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "FRI";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::SAT) == BusinessHours::SAT) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "SAT (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "SAT";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if ((businessHours & BusinessHours::SUN) == BusinessHours::SUN) {
 | 
			
		||||
        if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
 | 
			
		||||
            s << "SUN (Holiday)";
 | 
			
		||||
        } else {
 | 
			
		||||
            s << "SUN";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										577
									
								
								main/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										577
									
								
								main/main.cpp
									
									
									
									
									
								
							@@ -38,439 +38,130 @@ extern "C" char* strptime(const char* s,
 | 
			
		||||
#define SCHOENAU_KOENIGSEE                      (0)
 | 
			
		||||
#define NEUHAUSER_KORNEUBURG                    (0)
 | 
			
		||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU        (0)
 | 
			
		||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
 | 
			
		||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (1)
 | 
			
		||||
#define NEUHAUSER_BILEXA_GALTUER                (0)
 | 
			
		||||
#define NEUHAUSER_KIRCHDORF                     (0)
 | 
			
		||||
#define BAD_NEUENAHR_AHRWEILER                  (1)
 | 
			
		||||
#define NEUHAUSER_CHRISTOPH_REISEN              (0)
 | 
			
		||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR            (0)
 | 
			
		||||
 | 
			
		||||
#if NEUHAUSER_KIRCHDORF==1
 | 
			
		||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
 | 
			
		||||
    switch (step) {
 | 
			
		||||
    case 30:
 | 
			
		||||
        if (cost != 30) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 30;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 35:
 | 
			
		||||
        if (cost != 40) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 40;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 40:
 | 
			
		||||
        if (cost != 50) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 50;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 45:
 | 
			
		||||
        if (cost != 60) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 60;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 50:
 | 
			
		||||
        if (cost != 70) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 70;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 55:
 | 
			
		||||
        if (cost != 80) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 80;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 60:
 | 
			
		||||
        if (cost != 90) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 90;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 65:
 | 
			
		||||
        if (cost != 100) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 100;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 70:
 | 
			
		||||
        if (cost != 110) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 110;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 75:
 | 
			
		||||
        if (cost != 120) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 120;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 80:
 | 
			
		||||
        if (cost != 130) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 130;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 85:
 | 
			
		||||
        if (cost != 140) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 140;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 90:
 | 
			
		||||
        if (cost != 150) {
 | 
			
		||||
            qCritical() << "ERROR COMPUTING COST"
 | 
			
		||||
                        << "HAVE" << cost
 | 
			
		||||
                        << "SHOULD" << 150;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
#if NEUHAUSER_PERNEGG_AN_DER_MUR==1
 | 
			
		||||
    std::ifstream input;
 | 
			
		||||
    int pop_min_time;
 | 
			
		||||
    int pop_max_time;
 | 
			
		||||
    int pop_min_price;
 | 
			
		||||
    int pop_max_price;
 | 
			
		||||
    int pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
    input.open("/opt/ptu5/opt/customer_747/etc/psa_tariff/tariff01.json");
 | 
			
		||||
 | 
			
		||||
    std::stringstream sstr;
 | 
			
		||||
    while(input >> sstr.rdbuf());
 | 
			
		||||
    std::string json(sstr.str());
 | 
			
		||||
 | 
			
		||||
    Configuration cfg;
 | 
			
		||||
 | 
			
		||||
    bool isParsed = cfg.ParseJson(&cfg, json.c_str());
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
        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_daily_card_price: " << pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
        int price;
 | 
			
		||||
        QDateTime productStart;
 | 
			
		||||
        QDateTime productEnd;
 | 
			
		||||
        QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
        start.setTime(QTime(0, 0, 0));
 | 
			
		||||
        price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start);
 | 
			
		||||
        qCritical() << QString("price (%1) :").arg(start.time().toString(Qt::ISODate)) << price;
 | 
			
		||||
 | 
			
		||||
        start.setTime(QTime(6, 0, 0));
 | 
			
		||||
        productStart = productEnd = QDateTime();
 | 
			
		||||
        price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
 | 
			
		||||
        qCritical() << QString("price (%1-%2) :")
 | 
			
		||||
                       .arg(productStart.time().toString(Qt::ISODate))
 | 
			
		||||
                       .arg(productEnd.time().toString(Qt::ISODate))
 | 
			
		||||
                    << price;
 | 
			
		||||
 | 
			
		||||
        start.setTime(QTime(15, 0, 0));
 | 
			
		||||
        productStart = productEnd = QDateTime();
 | 
			
		||||
        price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
 | 
			
		||||
        qCritical() << QString("price (%1-%2) :")
 | 
			
		||||
                       .arg(productStart.time().toString(Qt::ISODate))
 | 
			
		||||
                       .arg(productEnd.time().toString(Qt::ISODate))
 | 
			
		||||
                    << price;
 | 
			
		||||
 | 
			
		||||
        start.setTime(QTime(16, 0, 0));
 | 
			
		||||
        productStart = productEnd = QDateTime();
 | 
			
		||||
        price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
 | 
			
		||||
        qCritical() << QString("price (%1-%2) :")
 | 
			
		||||
                       .arg(productStart.time().toString(Qt::ISODate))
 | 
			
		||||
                       .arg(productEnd.time().toString(Qt::ISODate))
 | 
			
		||||
                    << price;
 | 
			
		||||
 | 
			
		||||
        start.setTime(QTime(17, 0, 0));
 | 
			
		||||
        productStart = productEnd = QDateTime();
 | 
			
		||||
        price = compute_product_price(&cfg, PERMIT_TYPE::INVALID, start, &productStart, &productEnd);
 | 
			
		||||
        qCritical() << QString("price (%1-%2) :")
 | 
			
		||||
                       .arg(productStart.time().toString(Qt::ISODate))
 | 
			
		||||
                       .arg(productEnd.time().toString(Qt::ISODate))
 | 
			
		||||
                    << price;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NEUHAUSER_CHRISTOPH_REISEN==1
 | 
			
		||||
    std::ifstream input;
 | 
			
		||||
    int pop_min_time;
 | 
			
		||||
    int pop_max_time;
 | 
			
		||||
    int pop_min_price;
 | 
			
		||||
    int pop_max_price;
 | 
			
		||||
    int pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
    input.open("/opt/ptu5/opt/customer_746/etc/psa_tariff/tariff01.json");
 | 
			
		||||
        std::stringstream sstr;
 | 
			
		||||
        while(input >> sstr.rdbuf());
 | 
			
		||||
        std::string json(sstr.str());
 | 
			
		||||
 | 
			
		||||
        Configuration cfg;
 | 
			
		||||
 | 
			
		||||
        bool isParsed = cfg.ParseJson(&cfg, json.c_str());
 | 
			
		||||
        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;
 | 
			
		||||
 | 
			
		||||
            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_daily_card_price: " << pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
            static QList<int> stepsConfigured
 | 
			
		||||
                = QList(std::initializer_list<int>{
 | 
			
		||||
                    360, 420, 1440, 2880, 4320, 5400, 7440});
 | 
			
		||||
 | 
			
		||||
            QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
                qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
            if (stepsConfigured != timeSteps) {
 | 
			
		||||
                qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            stepsConfigured.push_front(360); // for test run
 | 
			
		||||
            stepsConfigured.push_back(7440);
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
            static const int Down = 0;
 | 
			
		||||
            static const int Up = 1;
 | 
			
		||||
 | 
			
		||||
            for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
 | 
			
		||||
                int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
 | 
			
		||||
                if (nextTimeStep != stepsConfigured.at(i+2)) {
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR"
 | 
			
		||||
                                << nextTimeStep << stepsConfigured.at(i+2);
 | 
			
		||||
                    return -1;
 | 
			
		||||
                }
 | 
			
		||||
                qCritical() << "curTimeStep" << timeSteps.at(i) << ", nextTimeStep" << nextTimeStep;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                int prevTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Down);
 | 
			
		||||
                if (prevTimeStep != stepsConfigured.at(i)) {
 | 
			
		||||
                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR"
 | 
			
		||||
                                << prevTimeStep << stepsConfigured.at(i);
 | 
			
		||||
                    return -1;
 | 
			
		||||
                }
 | 
			
		||||
                qCritical() << "curTimeStep" << timeSteps.at(i) << ", prevTimeStep" << prevTimeStep;
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
            //start.setTime(QTime(0, 0, 0));
 | 
			
		||||
 | 
			
		||||
            struct price_t costs;
 | 
			
		||||
            double const cost[] = {600, 700, 800, 1600, 2400, 3000, 3600};
 | 
			
		||||
            double price1 = 0;
 | 
			
		||||
            double price2 = 0;
 | 
			
		||||
 | 
			
		||||
            CalcState cs;
 | 
			
		||||
 | 
			
		||||
            for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
 | 
			
		||||
                QDateTime end = start.addSecs(timeSteps.at(i)*60);
 | 
			
		||||
 | 
			
		||||
                cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
 | 
			
		||||
                if (cs.getStatus() != CalcState::State::SUCCESS) {
 | 
			
		||||
                    qCritical() << "ERROR STATUS" << costs.netto;
 | 
			
		||||
                    exit(-1);
 | 
			
		||||
                }
 | 
			
		||||
                price1 = costs.netto;
 | 
			
		||||
                price2 = Calculator::GetInstance().GetCostFromDuration(&cfg, start, timeSteps.at(i));
 | 
			
		||||
 | 
			
		||||
                if (price1 != price2) {
 | 
			
		||||
                    qCritical() << "ERROR DIFFERENT PRICES" << price1 << price2;
 | 
			
		||||
                    exit(-1);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
 | 
			
		||||
                            << timeSteps.at(i) << "PRICE=" << price1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
 | 
			
		||||
                                                                                     start.toString(Qt::ISODate).toStdString().c_str(),
 | 
			
		||||
                                                                                     cost[i], false, true);
 | 
			
		||||
                QDateTime d(QDateTime::fromString(QString(duration.c_str()), Qt::ISODate));
 | 
			
		||||
 | 
			
		||||
                qCritical() << "start" << start.toString(Qt::ISODate)
 | 
			
		||||
                            << "cost[" << i << "]" << cost[i] << "duration" << d.toString(Qt::ISODate) << (start.secsTo(d) + 59) / 60;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
#if BAD_NEUENAHR_AHRWEILER==1
 | 
			
		||||
    std::ifstream input;
 | 
			
		||||
    int pop_min_time;
 | 
			
		||||
    int pop_max_time;
 | 
			
		||||
    int pop_min_price;
 | 
			
		||||
    int pop_max_price;
 | 
			
		||||
    int pop_daily_card_price;
 | 
			
		||||
    int pop_carry_over;
 | 
			
		||||
    int pop_carry_over_time_range_id;
 | 
			
		||||
 | 
			
		||||
    for (int zone=2; zone < 3; ++zone) {
 | 
			
		||||
    //for (int t=6; t < 7; t+=20) {
 | 
			
		||||
        switch (zone) {
 | 
			
		||||
        case 1: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff01.json");
 | 
			
		||||
            //pop_max_time = 6*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 2: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json");
 | 
			
		||||
            //pop_max_time = 5*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 3: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json");
 | 
			
		||||
            //pop_max_time = 6*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 4: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff04.json");
 | 
			
		||||
            //pop_max_time = 4*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 5: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff05.json");
 | 
			
		||||
            //pop_max_time = 6*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 6: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff06.json");
 | 
			
		||||
            //pop_max_time = 4*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        case 7: {
 | 
			
		||||
            input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff07.json");
 | 
			
		||||
            //pop_max_time = 4*60;
 | 
			
		||||
        } break;
 | 
			
		||||
        default:
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        std::stringstream sstr;
 | 
			
		||||
        while(input >> sstr.rdbuf());
 | 
			
		||||
        std::string json(sstr.str());
 | 
			
		||||
 | 
			
		||||
        Configuration cfg;
 | 
			
		||||
 | 
			
		||||
        bool isParsed = cfg.ParseJson(&cfg, json.c_str());
 | 
			
		||||
        cout << endl;
 | 
			
		||||
 | 
			
		||||
        if (isParsed) {
 | 
			
		||||
            // test library functions
 | 
			
		||||
 | 
			
		||||
            if (zone == 1) {
 | 
			
		||||
                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_daily_card_price: " << pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
                static QList<int> const stepsConfigured
 | 
			
		||||
                    = QList(std::initializer_list<int>{
 | 
			
		||||
                        20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 1440});
 | 
			
		||||
 | 
			
		||||
                //static QList<double> const cost
 | 
			
		||||
                //    = QList(std::initializer_list<double>{
 | 
			
		||||
                //        0, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 500});
 | 
			
		||||
 | 
			
		||||
                static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
                qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
                if (stepsConfigured != timeSteps) {
 | 
			
		||||
                    qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
 | 
			
		||||
                    return -1;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
 | 
			
		||||
                struct price_t costs;
 | 
			
		||||
                double price1 = 0;
 | 
			
		||||
                double price2 = 0;
 | 
			
		||||
 | 
			
		||||
                for (int m=0; m < 1440; ++m) {
 | 
			
		||||
                    start.setTime(QTime(0, 0, 0));
 | 
			
		||||
                    start = start.addSecs(m*60);
 | 
			
		||||
 | 
			
		||||
                    qCritical() << "START" << start.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
                    //int Down = 0;
 | 
			
		||||
                    //int Up = 1;
 | 
			
		||||
                    // for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
 | 
			
		||||
                    //    int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
 | 
			
		||||
                    //    qCritical() << "nextTimeStep" << nextTimeStep;
 | 
			
		||||
                    //
 | 
			
		||||
                    //    int prevTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Down);
 | 
			
		||||
                    //    qCritical() << "prevTimeStep" << prevTimeStep;
 | 
			
		||||
                    //}
 | 
			
		||||
 | 
			
		||||
                    CalcState cs;
 | 
			
		||||
 | 
			
		||||
                    for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
 | 
			
		||||
                        QDateTime end = start.addSecs(timeSteps.at(i)*60);
 | 
			
		||||
 | 
			
		||||
                        cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
 | 
			
		||||
                        if (cs.getStatus() != CalcState::State::SUCCESS) {
 | 
			
		||||
                            if (start.time().hour() >= 8 && start.time().hour() < 18) {
 | 
			
		||||
                                qCritical() << "ERROR CALC-STATE-1=" << QString(cs);
 | 
			
		||||
                                exit(-1);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (cs.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
 | 
			
		||||
                                    qCritical() << "CALC-STATE=" << QString(cs);
 | 
			
		||||
                                    continue;
 | 
			
		||||
                                }
 | 
			
		||||
                                qCritical() << "ERROR CALC-STATE-2=" << QString(cs);
 | 
			
		||||
                                exit(-1);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        price1 = costs.netto;
 | 
			
		||||
                        price2 = Calculator::GetInstance().GetCostFromDuration(&cfg, start, timeSteps.at(i));
 | 
			
		||||
 | 
			
		||||
                        if (price1 != price2) {
 | 
			
		||||
                            qCritical() << "ERROR DIFFERENT PRICES" << price1 << price2;
 | 
			
		||||
                            exit(-1);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
 | 
			
		||||
                                    << timeSteps.at(i) << "PRICE=" << price1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                        //std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
 | 
			
		||||
                        //                                                                     start.toString(Qt::ISODate).toStdString().c_str(),
 | 
			
		||||
                        //                                                                     cost[i], false, true);
 | 
			
		||||
                        //qCritical() << "duration" << duration.c_str();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } // zone == 1
 | 
			
		||||
            if (zone == 2) {
 | 
			
		||||
                int const numOptions = cfg.getAllPaymentOptions().size();
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
                for (int payOpt=0; payOpt < numOptions; ++payOpt) {
 | 
			
		||||
                    pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
 | 
			
		||||
                    pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
 | 
			
		||||
                    pop_min_price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
 | 
			
		||||
                    pop_max_price = get_maximal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
 | 
			
		||||
                    pop_daily_card_price = cfg.getPaymentOptions(payOpt).pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
                    pop_carry_over = cfg.getPaymentOptions(payOpt).pop_carry_over;
 | 
			
		||||
                    pop_carry_over_time_range_id = cfg.getPaymentOptions(payOpt).pop_carry_over_time_range_id;
 | 
			
		||||
 | 
			
		||||
                    qCritical() << QString("                pop_min_time[%1]: %2").arg(payOpt).arg(pop_min_time);
 | 
			
		||||
                    qCritical() << QString("                pop_max_time[%1]: %2").arg(payOpt).arg(pop_max_time);
 | 
			
		||||
                    qCritical() << QString("               pop_min_price[%1]: %2").arg(payOpt).arg(pop_min_price);
 | 
			
		||||
                    qCritical() << QString("               pop_max_price[%1]: %2").arg(payOpt).arg(pop_max_price);
 | 
			
		||||
                    qCritical() << QString("        pop_daily_card_price[%1]: %2").arg(payOpt).arg(pop_daily_card_price);
 | 
			
		||||
                    qCritical() << QString("              pop_carry_over[%1]: %2").arg(payOpt).arg(pop_carry_over);
 | 
			
		||||
                    qCritical() << QString("pop_carry_over_time_range_id[%1]: %2").arg(payOpt).arg(pop_carry_over_time_range_id);
 | 
			
		||||
 | 
			
		||||
                    if (pop_carry_over_time_range_id != -1) {
 | 
			
		||||
                        QTime const carryOverTimeRangeFrom = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
 | 
			
		||||
                        QTime const carryOverTimeRangeTo = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
 | 
			
		||||
                    qCritical() << QString("               timeRangeFrom[%1]: %2").arg(payOpt).arg(carryOverTimeRangeFrom.toString(Qt::ISODate));
 | 
			
		||||
                    qCritical() << QString("                 timeRangeTo[%1]: %2").arg(payOpt).arg(carryOverTimeRangeTo.toString(Qt::ISODate));
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
#endif
 | 
			
		||||
                bool fail;
 | 
			
		||||
                QDateTime start;
 | 
			
		||||
 | 
			
		||||
                for (int i=0; i < 4; ++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
 | 
			
		||||
                        fail = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                    case 2:
 | 
			
		||||
                        start = QDateTime(QDate(2024, 4, 22), QTime(8, 0, 0)); // monday
 | 
			
		||||
                        fail = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                    case 3:
 | 
			
		||||
                        start = QDateTime(QDate(2024, 4, 22), QTime(17, 30, 0)); // monday
 | 
			
		||||
                        fail = true;
 | 
			
		||||
                    break;
 | 
			
		||||
                    default:;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    QDateTime end;
 | 
			
		||||
                    struct price_t price;
 | 
			
		||||
 | 
			
		||||
                    //start = QDateTime::currentDateTime();
 | 
			
		||||
                    QList<int> timeSteps;
 | 
			
		||||
 | 
			
		||||
                    int paymentOptionIndex = cfg.getPaymentOptionIndex(start);
 | 
			
		||||
                    if (paymentOptionIndex != -1) {
 | 
			
		||||
                        qCritical() << "paymentOptionIndex" << paymentOptionIndex;
 | 
			
		||||
                        timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, paymentOptionIndex);
 | 
			
		||||
                        qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
                        QList<int>::const_iterator step;
 | 
			
		||||
                        for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
 | 
			
		||||
 | 
			
		||||
                            double cost = 0;
 | 
			
		||||
                            CalcState cs;
 | 
			
		||||
 | 
			
		||||
                            if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
 | 
			
		||||
                                cost = price.netto;
 | 
			
		||||
                                qCritical() << "step" << *step << ": cost" << cost;
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (fail == false) {
 | 
			
		||||
                                    qCritical() << "<<<ERROR>>> cs =" << QString(cs);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        qCritical() << "ERROR paymentOptionIndex =" << paymentOptionIndex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if SCHOENAU_KOENIGSEE==1
 | 
			
		||||
    //QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json");
 | 
			
		||||
    QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json");
 | 
			
		||||
    QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json");
 | 
			
		||||
    //QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json");
 | 
			
		||||
 | 
			
		||||
    std::ifstream input(f.toUtf8().constData());
 | 
			
		||||
 | 
			
		||||
@@ -492,22 +183,24 @@ int main() {
 | 
			
		||||
        QDateTime start = QDateTime::currentDateTime();
 | 
			
		||||
 | 
			
		||||
        // zone 1
 | 
			
		||||
        //int timeSteps[] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080, 11520, 12960, 14400};
 | 
			
		||||
        //int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        // zone 2
 | 
			
		||||
        //int timeSteps[3] = {60, 180, 1440};
 | 
			
		||||
 | 
			
		||||
        static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
 | 
			
		||||
        qCritical() << "TimeSteps" << timeSteps;
 | 
			
		||||
 | 
			
		||||
        for (int i = 0 ; i < timeSteps.size(); ++i) {
 | 
			
		||||
            QDateTime end = start.addSecs(timeSteps.at(i)*60);
 | 
			
		||||
 | 
			
		||||
            double price = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
                                 &cfg,
 | 
			
		||||
                                 start,
 | 
			
		||||
                                 timeSteps.at(i));
 | 
			
		||||
            qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i)
 | 
			
		||||
                     << "(" << timeSteps.at(i)/60 << "h)"
 | 
			
		||||
                     << "price=" << price;
 | 
			
		||||
        }
 | 
			
		||||
        // for (int i = 0 ; i < timeSteps.size(); ++i) {
 | 
			
		||||
        //    QDateTime end = start.addSecs(timeSteps.at(i)*60);
 | 
			
		||||
        //
 | 
			
		||||
        //    double price = Calculator::GetInstance().GetCostFromDuration(
 | 
			
		||||
        //                         &cfg,
 | 
			
		||||
        //                         start,
 | 
			
		||||
        //                         timeSteps.at(i));
 | 
			
		||||
        //    qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) << "price=" << price;
 | 
			
		||||
        //}
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@@ -1010,7 +703,7 @@ int main() {
 | 
			
		||||
    int pop_max_price;
 | 
			
		||||
    int pop_daily_card_price;
 | 
			
		||||
 | 
			
		||||
    for (int zone=1; zone < 2; ++zone) {
 | 
			
		||||
    for (int zone=6; zone < 7; ++zone) {
 | 
			
		||||
    //for (int t=6; t < 7; t+=20) {
 | 
			
		||||
        switch (zone) {
 | 
			
		||||
        case 1: {
 | 
			
		||||
@@ -1086,7 +779,7 @@ int main() {
 | 
			
		||||
 | 
			
		||||
            {
 | 
			
		||||
                // zone 1 (lila)
 | 
			
		||||
                QDateTime s(QDate(2024, 3, 26), QTime());
 | 
			
		||||
                QDateTime s(QDate(2023, 11, 30), QTime());
 | 
			
		||||
                QDateTime end;
 | 
			
		||||
                int cnt = 1;
 | 
			
		||||
                if (zone == 1) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user