Compare commits

...

75 Commits

Author SHA1 Message Date
2d53224feb Minor: add some (commented out) debug output -> used for debugging. 2024-05-15 15:23:12 +02:00
38964ad9a8 get_minimal_parkingprice(): for PERMIT_TYPE::DAY_TICKET
call compute_product_price(cfg, permitType, start) to get
minimal price dependent on 'start' datetime.
2024-05-15 15:21:38 +02:00
d3f18f3b82 get_minimal_parkingprice(): add default parameter 'start', set to
value of QDateTime::currentDateTime();
2024-05-15 15:19:47 +02:00
1a4265372e Add tests for Pernegg an der Mur 2024-05-15 15:19:13 +02:00
eb20410849 Use paymentOptionIndex in getPaymentOptions() 2024-05-08 16:34:07 +02:00
2a492475e3 Bad Neuenahr: Zone5 tests 2024-05-07 16:21:36 +02:00
6a5272da7a Fix: Check if endTime is still on the same day. 2024-05-07 15:01:16 +02:00
4d5583df2d Handling for pop_carry_over_traget. 2024-05-07 14:59:00 +02:00
de6f263817 Add FRI/SAT/SUN with restricted hours. 2024-05-07 14:57:41 +02:00
e4ce14da3f updated some tests 2024-05-06 11:38:37 +02:00
b71c979a91 Fix: getPaymentOptionIndex() -> return 0 instead of -1
Removed exit(0)-call which was used for testing.
2024-05-06 11:36:12 +02:00
33f43fb83d Start parsing of pop_min_date_time and pop_max_date_time 2024-05-03 13:50:10 +02:00
1606a784a4 Add macro _WEEKEND_WITH_RESTRICTED_HOURS_. 2024-05-03 13:49:15 +02:00
9f2cf613e1 Add struct ATBMaxDateTime. 2024-05-03 13:48:27 +02:00
dbd9644047 Add ATBPaymentOptionType = std::multimap<int, ATBPaymentOption> 2024-05-03 13:47:28 +02:00
f8fef12b55 Zone6 for Bad neuenahr 2024-04-30 14:09:48 +02:00
1dd81d4a56 get_minimal_parkingtime(): const Configuration parameter.
Cast of const pointer necessary.

get_maximal_parkingtime(): const Configuration parameter.
2024-04-30 14:08:08 +02:00
f93cf11d23 get_minimal_parkingtime()
get_maximal_parkingtime(): made configuration parameter const.
2024-04-30 14:06:04 +02:00
9d0ac4f8ce Add TWENTY_FOUR_HOURS_TICKET. Add toString() and implement conversion
operators in therm of toString().
2024-04-30 13:51:31 +02:00
4ec5589f30 Implement getTariffProductForProductId() in terms of
getTariffProductForProductTypeName().
2024-04-30 13:49:49 +02:00
c1d5ffcf3c Implement getTariffProductForProductTypeName().
Use the type names of PERMIT_TYPE, not real indices as they can change.
2024-04-30 13:48:03 +02:00
7aded2b7fb Explicit cast due to compiler warning. 2024-04-30 13:46:59 +02:00
ed9e60a972 Declaration for getTariffProductForProductTypeName(). 2024-04-30 13:45:22 +02:00
5d35331c83 Minor: introduced TariffProductType. 2024-04-30 13:44:53 +02:00
c7623429d9 Compute end_parking_time using "netto_parking_time", which is the
current timestep.
2024-04-25 15:41:52 +02:00
b596086245 Pass paymentOptionIndex to cfg->getPaymentOptions(), which has
a default parameter of paymentOptionIndex=0.
2024-04-24 13:20:02 +02:00
24ca857b6f Fix: init m_timeSteps-vector in case its size is 0: m_timeSteps.push_back(QList<int>()).
Detected during testing.
2024-04-24 13:18:23 +02:00
ea0bcde413 Check iterator for it != cfg->TimeRange.cend(). 2024-04-24 13:16:22 +02:00
e93b08505a Minor: introduce TimeRangeType as typedef for std::multimap<int, ATBTimeRange>. 2024-04-24 13:14:04 +02:00
44efd44ede Check paymentOptionIndex for test of GALTUER. 2024-04-24 13:11:28 +02:00
9d72574106 Minor: additional loop for test of NAZ 2024-04-24 12:01:24 +02:00
d8ec41ebfc Repeated tests for KIRCHDORF. Re-added utility test_neuhauser_kirchdorf(). Found bug during testing, accessing vector of size 0. 2024-04-24 11:56:50 +02:00
f17c4f240b Minor: add tests for special days in KORNEUBURG 2024-04-24 10:52:18 +02:00
76bb1eb56a Minor: small changes for tests of SCHOENAU 2024-04-24 09:54:29 +02:00
3b813e5eff Minor: small changes for tests of PERNEGG-AN-DER-MUR 2024-04-24 09:33:57 +02:00
436f5a109b Minor: add small changes to Christoph-Reisen 2024-04-24 09:17:26 +02:00
e17e54b315 Minor: add define: _ALL_DAYS_WITH_RESTRICTED_HOURS_ 2024-04-19 14:10:47 +02:00
d07fdd8540 GetPriceForTimeStep(): use parameter paymentOptionIndex. 2024-04-19 13:33:54 +02:00
1fab458de3 Implement isParkingAllowedForWeekDay(), isParkingAllowedForSpecialDay()
and isParkingAllowed() (4 parameters) using the 2 functions.
2024-04-19 13:32:24 +02:00
1ac2ca91c5 GetCostFromDuration(): use new parameter paymentOptionIndex. 2024-04-19 13:31:01 +02:00
1852f552a3 compute_price_for_parking_ticket(): compute paymentOptionIndex.
(a tariff-file can conatin more than one payment options).
2024-04-19 13:28:35 +02:00
e2c02420f0 Add parsing for new values in helper-structures.
NOTE: unfortunately switched to Unix-File-Format.
2024-04-19 13:26:33 +02:00
1240abbbec Add test cases BAD_NEUENAHR_AHRWEILER, zone2. 2024-04-19 13:24:10 +02:00
e20eb93abf Implement SpecialDaysWorkTimeFrom() and SpecialDaysWorkTimeUntil().
Extend getBusinessHours() to include new enum-values.
Implement isDayIncluded() as switch-case on dayOfWeek.
Implement dumpBusinessHours().
2024-04-19 13:21:38 +02:00
b0e7bd91b4 Add ariff_global_defines.h. 2024-04-19 13:20:44 +02:00
0cd4424434 Add utilities
isDayIncluded(), SpecialDaysWorkTimeFrom() and specialDaysWorkTimeUntil().
2024-04-19 13:19:26 +02:00
1991853b66 Add new enum-values for business_hours. Keep the old ones for
backward-compatibility.
2024-04-19 13:18:02 +02:00
b31fcc5f4f Minor: add explicit default constructor. 2024-04-19 13:17:00 +02:00
dbe649d0e4 Add member variables
pop_carry_over_start_time_range
pop_carry_over_end_time_range:

If carry-over has been set, then provide the limits
for the carry-over: at the end of day1 (start) and
at the beginning of the next day (end).
2024-04-19 13:12:46 +02:00
dfd74a455a Add getPaymentOptionIndexIfSpecialDay().
Add isSpecialDay(), isSpecialDay((), specialDayId(),
specialDay(), isSpecialDay(), specialDayId(), specialDay(),
isDayIncluded(), isDayIncludedAsSpecialDay() and isDayIncludedAsSpecialDay().
2024-04-19 13:09:53 +02:00
10828e0708 Add private mathods isParkingAllowedForWeekDay() and isParkingAllowedForSpecialDay().
Overload isParkingAllowed().
GetCostFromDuration(): add default parameter "int paymentOptionIndex=0"
2024-04-19 13:06:37 +02:00
2dbcc7018c start header for global defines 2024-04-19 13:04:36 +02:00
18ed85430d Minor: first commit 2024-04-18 08:52:15 +02:00
b70094abb5 Extend compute_product_price() for use of PERMIT_TYPE::DAY_TICKET.
First time used for Neuhauder-Pernegg-an-der-Mur.
2024-04-16 12:10:34 +02:00
aa15d1c126 Add default-parameters to compute_product_price():
start [in]: currentDateTime(): start date-time for daily-ticket-price computation.
startProduct, endProduct: real start- and end-date/time for daily-ticket.
Used first time for Neuhauser-Pernegg-an-der-Mur (747).
2024-04-16 12:07:18 +02:00
cd159f2bbd Add case for BusinessHours::NoRestriction_24_7: used for Neuhauder-Christoph-Reisen 2024-04-16 12:05:55 +02:00
475487c2ce Minor: add utility getProductPrice() 2024-04-16 12:03:42 +02:00
8ff5b8e2b5 Added test-cases for Neuhauser-Christoph-Reisen (746) and Neuhauser-Pernegg-an-der-Mur (747) 2024-04-16 12:01:36 +02:00
b0c4ad0e2e getCurrentPaymentOptionIndex(): start implementation.
getPaymentOptions(): use new parameter paymentOptionIndex.
2024-04-12 14:31:02 +02:00
7e3347b043 GetTimeSteps(): use new parameter paymentOptionIndex 2024-04-12 14:30:04 +02:00
4e7fa83507 get_minimal_parkingtime()
get_maximal_parkingtime()
get_minimal_parkingprice()
get_maximal_parkingprice():
use new parameter paymentOptionIndex.
2024-04-12 14:27:08 +02:00
ac76f194e1 Added new constants 2024-04-12 14:26:03 +02:00
fe485b7b39 pop_business_hours as uint64_t. 2024-04-12 14:24:32 +02:00
e210224340 getPaymentOptions(): added default-parameter 'paymentOptionsIndex'
Added getCurrentPaymentOptionIndex() and isHoliday().
2024-04-12 14:22:20 +02:00
afa62183fd ResetTimeSteps(), GetTimeSteps(), GetSteps():
add parameter paymentOptionIndex (default=0)
2024-04-12 14:20:05 +02:00
f241a87dc1 get_minimal_parking_price()
get_maximal_parking_price()
get_maximal_parking_time()
get_minimal_parking_time():
	adden perameter paymentOptionIndex
2024-04-12 14:17:43 +02:00
9b1cc49d34 Minor: remove some debug output 2024-04-12 14:16:18 +02:00
449e618417 Add test-cases 2024-04-12 14:14:40 +02:00
aba38d2614 compute_price_for_parking_ticket(): add handling for PaymentMethod::Steps. 2024-04-08 13:58:24 +02:00
57d6b85f52 get_maximal_parking_price(): add handling for PaymentMethod::Steps. 2024-04-08 13:57:40 +02:00
4f9c0422fc Start test case for Bad Neuenahr 2024-04-08 13:53:29 +02:00
a5b95d71b8 CalcState: Add setStatus()/getStatus() 2024-04-08 13:52:53 +02:00
fcbc8dcdc3 Merge branch 'neuhauser-kirchdorf' of https://git.mimbach49.de/GerhardHoffmann/MOBILISIS-Calculator into neuhauser-kirchdorf 2024-03-07 08:19:26 +01:00
ed99bae725 Use Calculator::getInstance() 2024-03-07 08:18:40 +01:00
627d14204d Use paymentRate.last() instead of aymentRate.at(0) so we can enter new entries
in tariff-files to provide the prices for an hour.
2024-03-07 08:17:32 +01:00
16 changed files with 2608 additions and 850 deletions

View File

@@ -175,6 +175,8 @@ struct CALCULATE_LIBRARY_API CalcState {
} }
CalcState &set(State s) { m_status = s; return *this; } 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; } CalcState &setDesc(QString s) { m_desc = s; return *this; }
void setAllowedTimeRange(QTime const &from, QTime const &until) { void setAllowedTimeRange(QTime const &from, QTime const &until) {
@@ -194,11 +196,29 @@ 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); 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); 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 CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING); int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING); 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 paymentOptionIndex=0);
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *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,
QDateTime const &start = QDateTime::currentDateTime());
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);
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
parking_tariff_t *tariff, parking_tariff_t *tariff,

View File

@@ -14,9 +14,19 @@
using namespace std; using namespace std;
class Calculator { class Calculator {
mutable QList<int> m_timeSteps; mutable QVector<QList<int>> m_timeSteps;
mutable QList<int> m_priceSteps; 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: protected:
explicit Calculator() = default; explicit Calculator() = default;
@@ -29,13 +39,28 @@ public:
return c; return c;
} }
void ResetTimeSteps() { m_timeSteps.clear(); } void ResetTimeSteps(int paymentOptionIndex) {
QList<int> timeSteps() const { return m_timeSteps; } 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 ResetPriceSteps() { m_priceSteps.clear(); } void ResetPriceSteps() { m_priceSteps.clear(); }
QList<int> priceSteps() const { return m_priceSteps; } QList<int> priceSteps() const { return m_priceSteps; }
CalcState isParkingAllowed(Configuration const *cfg, QDateTime const &start); CalcState isParkingAllowed(Configuration const *cfg,
QDateTime const &start);
CalcState isParkingAllowed(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex);
/// <summary> /// <summary>
/// Gets duration in seconds from cost /// Gets duration in seconds from cost
@@ -66,8 +91,8 @@ public:
// helper function to find time steps for a tariff with PaymentMethod::Steps // helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee) // (e.g. Schoenau/Koenigsee)
// //
QList<int> GetTimeSteps(Configuration *cfg) const; QList<int> GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0) const;
QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); } QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0) const { return GetTimeSteps(cfg, paymentOptionIndex); }
QList<int> GetPriceSteps(Configuration *cfg) const; QList<int> GetPriceSteps(Configuration *cfg) const;
@@ -87,8 +112,8 @@ public:
// testing public: // testing public:
// Introduced for PaymentMethod::Steps (e.g. Schoenau) // Introduced for PaymentMethod::Steps (e.g. Schoenau)
// For tariff of following structure: only steps, no special days, nonstop. // For tariff of following structure: only steps, no special days, nonstop.
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const; 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) const; uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end, int paymentOptionIndex=0) const;
private: private:
Ticket private_GetCostFromDuration(Configuration const* cfg, Ticket private_GetCostFromDuration(Configuration const* cfg,
@@ -104,7 +129,7 @@ private:
int durationMinutes); int durationMinutes);
// //
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const; uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex=0) const;
uint32_t GetPriceForStep(Configuration *cfg, int step) const { uint32_t GetPriceForStep(Configuration *cfg, int step) const {
return GetPriceForTimeStep(cfg, step); return GetPriceForTimeStep(cfg, step);
} }

View File

@@ -36,6 +36,12 @@ class Calculator;
class Configuration class Configuration
{ {
public: public:
using SpecialDaysType = std::multimap<int, ATBSpecialDays>;
using SpecialDaysWorktimeType = std::multimap<int, ATBSpecialDaysWorktime>;
using TimeRangeType = std::multimap<int, ATBTimeRange>;
using TariffProductType = std::multimap<int, ATBTariffProduct>;
using ATBPaymentOptionType = std::multimap<int, ATBPaymentOption>;
ATBProject project; ATBProject project;
ATBCurrency Currency; ATBCurrency Currency;
ATBDuration duration; ATBDuration duration;
@@ -43,18 +49,18 @@ public:
multimap<int, ATBDuration> Duration; multimap<int, ATBDuration> Duration;
multimap<int, ATBPaymentMethod> PaymentMethod; multimap<int, ATBPaymentMethod> PaymentMethod;
multimap<int, ATBPaymentRate> PaymentRate; multimap<int, ATBPaymentRate> PaymentRate;
multimap<int, ATBSpecialDaysWorktime> SpecialDaysWorktime; SpecialDaysWorktimeType SpecialDaysWorktime;
multimap<int, ATBSpecialDays> SpecialDays; SpecialDaysType SpecialDays;
multimap<int, ATBWeekDays> WeekDays; multimap<int, ATBWeekDays> WeekDays;
multimap<int, ATBPeriodYear> YearPeriod; multimap<int, ATBPeriodYear> YearPeriod;
multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime; multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
multimap<int, ATBPaymentOption> PaymentOption; ATBPaymentOptionType PaymentOption;
multimap<int, ATBDailyTicket> DailyTicket; multimap<int, ATBDailyTicket> DailyTicket;
multimap<int, ATBTimeRange> TimeRange; TimeRangeType TimeRange;
multimap<int, ATBTimeStepConfig> TimeStepConfig; multimap<int, ATBTimeStepConfig> TimeStepConfig;
multimap<int, ATBTimeBase> TimeBase; multimap<int, ATBTimeBase> TimeBase;
multimap<int, ATBCustomer> Customer; multimap<int, ATBCustomer> Customer;
multimap<int, ATBTariffProduct> TariffProduct; TariffProductType TariffProduct;
/// <summary> /// <summary>
/// Parse JSON string /// Parse JSON string
@@ -63,10 +69,18 @@ public:
/// <returns>Returns operation status bool (OK | FAIL) </returns> /// <returns>Returns operation status bool (OK | FAIL) </returns>
bool ParseJson(Configuration* cfg, const char* json); bool ParseJson(Configuration* cfg, const char* json);
ATBPaymentOption &getPaymentOptions(); ATBPaymentOption &getPaymentOptions(int paymentOptionsIndex=0);
ATBPaymentOption const &getPaymentOptions() const; ATBPaymentOption const &getPaymentOptions(int paymentOptionsIndex=0) const;
QVector<ATBPaymentOption> &getAllPaymentOptions(); QVector<ATBPaymentOption> &getAllPaymentOptions();
QVector<ATBPaymentOption> const &getAllPaymentOptions() const; 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>> getPaymentRateForAllKeys() const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const; std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const; std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;
@@ -74,6 +88,7 @@ public:
std::optional<QVector<ATBTariffProduct>> getTariffProductForAllKeys() const; std::optional<QVector<ATBTariffProduct>> getTariffProductForAllKeys() const;
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(int id) const; std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(int id) const;
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(PermitType permitType) const; std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(PermitType permitType) const;
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductTypeName(QString const &permitTypeName) const;
std::optional<ATBCustomer> getCustomerForType(ATBCustomer::CustomerType customerType); std::optional<ATBCustomer> getCustomerForType(ATBCustomer::CustomerType customerType);
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek); std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);

View File

@@ -1,5 +1,11 @@
#pragma once #ifndef PAYMENT_OPT_H_INCLUDED
#define PAYMENT_OPT_H_INCLUDED
#include <string> #include <string>
#include <cinttypes>
#include <QDateTime>
class ATBPaymentOption class ATBPaymentOption
{ {
@@ -18,7 +24,10 @@ public:
pop_min_price = 0; pop_min_price = 0;
pop_max_price = 0; pop_max_price = 0;
pop_carry_over = -1; pop_carry_over = -1;
pop_carry_over_target = false;
pop_carry_over_time_range_id = -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_daily_card_price = -1;
pop_business_hours = -1; pop_business_hours = -1;
pop_time_step_config = -1; pop_time_step_config = -1;
@@ -35,8 +44,21 @@ public:
double pop_min_price; double pop_min_price;
double pop_max_price; double pop_max_price;
int pop_carry_over; int pop_carry_over;
bool pop_carry_over_target;
int pop_carry_over_time_range_id; 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; int pop_daily_card_price;
int pop_business_hours; uint64_t pop_business_hours;
int pop_time_step_config; int pop_time_step_config;
struct ATBMaxDateTime {
int direction;
uint8_t week;
uint8_t day;
QTime time;
} pop_min_date_time,
pop_max_date_time;
}; };
#endif // PAYMENT_OPT_H_INCLUDED

View File

@@ -4,10 +4,12 @@
class ATBSpecialDays class ATBSpecialDays
{ {
public: public:
explicit ATBSpecialDays() = default;
int ped_id; int ped_id;
std::string ped_label; std::string ped_label;
std::string ped_date_start; std::string ped_date_start;
std::string ped_date_end; std::string ped_date_end;
int ped_period_special_day_id; int ped_period_special_day_id;
int ped_payment_option_id;
int ped_year; int ped_year;
}; };

View File

@@ -4,19 +4,87 @@
/// <summary> /// <summary>
/// Business hours (byte represents payment option id) /// Business hours (byte represents payment option id)
/// </summary> /// </summary>
enum BusinessHours ///
#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 _WITH_RESTRICTED_HOURS_ (uint64_t)(1ULL << 17)
#define _ALL_DAYS_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_ALL_DAYS_))
#define _WEEKEND_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_|_SAT_|_SUN_))
#define _FRI_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_))
#define _SAT_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SAT_))
#define _SUN_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SUN_))
#define _NOT_DEFINED_ (uint64_t)(~0ULL)
enum BusinessHours : std::uint64_t
{ {
NoRestriction_24_7 = 0, NoRestriction_24_7 = 0,
OnlyWorkingDays = 1, // [Monday-Friday] OnlyWorkingDays = 1, // [Monday-Friday]
OnlyWeekDays = 2, // [Monday-Saturday] OnlyWeekDays = 2, // [Monday-Saturday]
OnlyWeekEnd = 4, // [Saturday+Sunday] OnlyWeekEnd = 4, // [Saturday+Sunday]
OnlyOfficialHolidays = 8, OnlyOfficialHolidays = 8,
OnlySundaysAndHolidays = 12, // [Sun+Holiday]
OnlySpecialDays = 16, OnlySpecialDays = 16,
OnlySchoolHolidays = 32, OnlySchoolHolidays = 32,
SpecialAndSchoolHolidays = 48, SpecialAndSchoolHolidays = 48,
OnlyOpenForBusinessDays = 64, // verkaufsoffen OnlyOpenForBusinessDays = 64, // verkaufsoffen
AllDaysWithRestrictedHours = 128, // every day, restricted to some time range AllDaysWithRestrictedHours = 128, // every day, restricted to some time range
NoBusinessHoursDefined = 255 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_,
ALL_DAYS_WITH_RESTRICTED_HOURS = _ALL_DAYS_WITH_RESTRICTED_HOURS_,
WEEKEND_WITH_RESTRICTED_HOURS = _WEEKEND_WITH_RESTRICTED_HOURS_,
FRI_WITH_RESTRICTED_HOURS = _FRI_WITH_RESTRICTED_HOURS_,
SAT_WITH_RESTRICTED_HOURS = _SAT_WITH_RESTRICTED_HOURS_,
SUN_WITH_RESTRICTED_HOURS = _SUN_WITH_RESTRICTED_HOURS_,
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;
}; };
#endif // TARIFF_BUSINESS_HOURS_H_INCLUDED #endif // TARIFF_BUSINESS_HOURS_H_INCLUDED

View File

@@ -0,0 +1,6 @@
#ifndef TARIFF_GLOBAL_DEFINES_H_INCLUDED
#define TARIFF_GLOBAL_DEFINES_H_INCLUDED
#define DBG_HEADER "(" << __func__ << ":" << __LINE__ << ")"
#endif // TARIFF_GLOBAL_DEFINES_H_INCLUDED

View File

@@ -4,15 +4,16 @@
#include <QString> #include <QString>
enum class PERMIT_TYPE : quint8 { enum class PERMIT_TYPE : quint8 {
SHORT_TERM_PARKING, SHORT_TERM_PARKING=0,
DAY_TICKET, DAY_TICKET=1,
SZEGED_START, SZEGED_START=2,
SZEGED_STOP, SZEGED_STOP=3,
DAY_TICKET_ADULT, DAY_TICKET_ADULT=4,
DAY_TICKET_TEEN, DAY_TICKET_TEEN=5,
DAY_TICKET_CHILD, DAY_TICKET_CHILD=6,
FOOD_STAMP, INVALID=7,
INVALID FOOD_STAMP=8,
TWENTY_FOUR_HOURS_TICKET=9
}; };
struct PermitType { struct PermitType {
@@ -45,6 +46,9 @@ struct PermitType {
case 7: case 7:
m_permitType = PERMIT_TYPE::FOOD_STAMP; m_permitType = PERMIT_TYPE::FOOD_STAMP;
break; break;
case 8:
m_permitType = PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET;
break;
default: default:
m_permitType = PERMIT_TYPE::INVALID; m_permitType = PERMIT_TYPE::INVALID;
} }
@@ -74,6 +78,8 @@ struct PermitType {
return 6; return 6;
case PERMIT_TYPE::FOOD_STAMP: case PERMIT_TYPE::FOOD_STAMP:
return 7; return 7;
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
return 8;
default: default:
break; break;
} }
@@ -81,7 +87,7 @@ struct PermitType {
} }
operator QString () { QString toString() {
switch(m_permitType) { switch(m_permitType) {
case PERMIT_TYPE::DAY_TICKET: case PERMIT_TYPE::DAY_TICKET:
return QString("DAY_TICKET"); return QString("DAY_TICKET");
@@ -99,13 +105,15 @@ struct PermitType {
return QString("SZEGED_STOP"); return QString("SZEGED_STOP");
case PERMIT_TYPE::FOOD_STAMP: case PERMIT_TYPE::FOOD_STAMP:
return QString("FOOD_STAMP"); return QString("FOOD_STAMP");
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
return QString("TWENTY_FOUR_HOURS_TICKET");
default: default:
break; break;
} }
return QString("INVALID"); return QString("INVALID");
} }
operator QString () const { QString toString() const {
switch(m_permitType) { switch(m_permitType) {
case PERMIT_TYPE::DAY_TICKET: case PERMIT_TYPE::DAY_TICKET:
return QString("DAY_TICKET"); return QString("DAY_TICKET");
@@ -123,11 +131,21 @@ struct PermitType {
return QString("SZEGED_STOP"); return QString("SZEGED_STOP");
case PERMIT_TYPE::FOOD_STAMP: case PERMIT_TYPE::FOOD_STAMP:
return QString("FOOD_STAMP"); return QString("FOOD_STAMP");
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
return QString("TWENTY_FOUR_HOURS_TICKET");
default: default:
break; break;
} }
return QString("INVALID"); return QString("INVALID");
} }
operator QString () {
return toString();
}
operator QString () const {
return toString();
}
}; };
#endif // TARIFF_PERMIT_TYPE_H_INCLUDED #endif // TARIFF_PERMIT_TYPE_H_INCLUDED

View File

@@ -45,6 +45,8 @@ struct ATBTariffProduct {
return false; return false;
} }
uint32_t getProductPrice() const { return m_tariff_product_price; }
friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) { friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) {
QDebugStateSaver saver(debug); QDebugStateSaver saver(debug);

View File

@@ -15,6 +15,9 @@
using namespace std; using namespace std;
namespace Utilities { namespace Utilities {
bool isDayIncluded(uint64_t businessHours, QDateTime const &dt);
/// <summary> /// <summary>
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday /// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
/// </summary> /// </summary>
@@ -76,7 +79,9 @@ namespace Utilities {
double CalculatePricePerUnit(double pra_price, double durationUnit = -1); double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId); QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId); QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr); QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
QTime WeekDaysWorkTimeUntil(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); int WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
@@ -94,4 +99,5 @@ namespace Utilities {
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId); BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id); uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id); double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
QStringList dumpBusinessHours(uint64_t businessHours);
} }

View File

@@ -79,7 +79,8 @@ HEADERS += \
include/mobilisis/tariff_timebase.h \ include/mobilisis/tariff_timebase.h \
include/mobilisis/tariff_timestep_config.h \ include/mobilisis/tariff_timestep_config.h \
include/mobilisis/tariff_product.h \ include/mobilisis/tariff_product.h \
include/mobilisis/tariff_permit_type.h include/mobilisis/tariff_permit_type.h \
include/mobilisis/tariff_global_defines.h
OTHER_FILES += src/main.cpp \ OTHER_FILES += src/main.cpp \
../tariffs/tariff_korneuburg.json \ ../tariffs/tariff_korneuburg.json \

View File

@@ -14,12 +14,14 @@ QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return Calculator::GetInstance().GetTimeSteps(cfg); return Calculator::GetInstance().GetTimeSteps(cfg);
} }
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int minTime = 0; int minTime = 0;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minTime = cfg->getPaymentOptions().pop_min_time; minTime = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@@ -30,20 +32,22 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYP
default: default:
// for each new sell-procedure, recomute the timesteps. implicitly, set // for each new sell-procedure, recomute the timesteps. implicitly, set
// the minimal parking time. // the minimal parking time.
Calculator::GetInstance().ResetTimeSteps(); Calculator::GetInstance().ResetTimeSteps(paymentOptionIndex);
Calculator::GetInstance().GetTimeSteps(cfg); Calculator::GetInstance().GetTimeSteps((Configuration *)cfg, paymentOptionIndex);
minTime = qRound(cfg->getPaymentOptions().pop_min_time); minTime = qRound(cfg->getPaymentOptions(paymentOptionIndex).pop_min_time);
} }
return minTime; return minTime;
} }
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int maxTime = 0; int maxTime = 0;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
maxTime = cfg->getPaymentOptions().pop_max_time; maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@@ -55,14 +59,18 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYP
} }
return maxTime; return maxTime;
} }
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1; int minPrice = -1;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions().pop_min_price; minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@@ -70,13 +78,20 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TY
} break; } break;
case PERMIT_TYPE::DAY_TICKET_CHILD: { case PERMIT_TYPE::DAY_TICKET_CHILD: {
} break; } break;
case PERMIT_TYPE::DAY_TICKET: {
minPrice = compute_product_price(cfg, permitType, start);
} break;
default: ; default: ;
} }
return minPrice; return minPrice;
} }
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
PERMIT_TYPE permitType,
QDateTime const &start,
QDateTime *productStart,
QDateTime *productEnd) {
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
@@ -112,6 +127,66 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
} }
} }
} break; } 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();
// qCritical() << __LINE__ << startTime.toString(Qt::ISODate);
// qCritical() << __LINE__ << endTime.toString(Qt::ISODate);
// qCritical() << __LINE__ << start.toString(Qt::ISODate);
if (start.time() >= startTime && start.time() < endTime) {
product_price = p.getProductPrice();
if (productStart && productEnd) {
productStart->setTime(startTime);
productEnd->setTime(endTime);
}
}
}
return product_price;
}
} break;
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
if (products) {
int product_price = 0;
QVector<ATBTariffProduct> product = products.value();
if (product.size() > 0) {
if (productStart && productEnd) {
int pop_min_time = get_minimal_parkingtime(cfg); // in minutes
int pop_max_time = get_maximal_parkingtime(cfg); // in minutes
if (pop_max_time >= pop_min_time) {
*productStart = start;
*productEnd = start.addSecs(pop_max_time*60);
product_price = product[0].getProductPrice();
}
}
}
return product_price;
}
} break;
default: default:
break; break;
} }
@@ -119,22 +194,24 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
return 0; return 0;
} }
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) { int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int maxPrice = -1; int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive) { if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId); maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
} else { // PaymentMethod::Linear -> e.g. szeged } else { // PaymentMethod::Linear -> e.g. szeged
int const key = cfg->getPaymentOptions().pop_id; int const key = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes int const maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; // maxTime is given in minutes
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key); std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
if (pv) { if (pv) {
QVector<ATBPaymentRate> const &paymentRate = pv.value(); QVector<ATBPaymentRate> const &paymentRate = pv.value();
if (paymentRate.size() > 0) { if (paymentRate.size() > 0) {
int const price = paymentRate.at(0).pra_price; // price is given per hour int const price = paymentRate.last().pra_price; // price is given per hour
maxPrice = qRound((maxTime * price) / 60.0f); maxPrice = qRound((maxTime * price) / 60.0f);
} }
} }
@@ -399,11 +476,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
bool prepaid) bool prepaid)
{ {
CalcState calcState; CalcState calcState;
double minMin = tariff->getPaymentOptions().pop_min_time;
double maxMin = tariff->getPaymentOptions().pop_max_time; int paymentOptionIndex = tariff->getPaymentOptionIndex(start_parking_time);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
// DEBUG // DEBUG
qCritical() << "compute_price_for_parking_ticket() " << endl qCritical() << "compute_price_for_parking_ticket() " << endl
<< " paymentOptionIndex: " << paymentOptionIndex << endl
<< " start_parking_time: " << start_parking_time << endl << " start_parking_time: " << start_parking_time << endl
<< " netto_parking_time: " << netto_parking_time << endl << " netto_parking_time: " << netto_parking_time << endl
<< " minMin: " << minMin << endl << " minMin: " << minMin << endl
@@ -428,15 +509,33 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
return calcState.set(CalcState::State::SUCCESS); return calcState.set(CalcState::State::SUCCESS);
} }
double cost = -1;
if (start_parking_time.isValid()) { if (start_parking_time.isValid()) {
double cost = Calculator::GetInstance().GetCostFromDuration( if (tariff->getPaymentOptions(paymentOptionIndex).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) {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << calcState.toString();
return calcState;
}
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
end_parking_time = start_parking_time.addSecs(netto_parking_time*60);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << "end_parking_time" << end_parking_time.toString(Qt::ISODate);
} else {
cost = Calculator::GetInstance().GetCostFromDuration(
tariff, tariff,
tariff->getPaymentOptions().pop_payment_method_id, tariff->getPaymentOptions().pop_payment_method_id,
start_parking_time, // starting time start_parking_time, // starting time
end_parking_time, // return value: end time end_parking_time, // return value: end time
netto_parking_time, // minutes, netto netto_parking_time, // minutes, netto
false, prepaid); false, prepaid);
double minCost = tariff->getPaymentOptions().pop_min_price; }
double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price;
if (cost < minCost) { if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost)); calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE); return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
@@ -445,8 +544,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
// DEBUG // DEBUG
qCritical() << " -> calculated cost (price->netto) = " << cost; qCritical() << " -> calculated cost (price->netto) = " << cost;
price->brutto = price->vat = price->vat_percentage = 0;
price->units = cost; price->units = cost;
price->netto = cost; price->netto = cost;
} else { } else {
return calcState.set(CalcState::State::INVALID_START_DATE); return calcState.set(CalcState::State::INVALID_START_DATE);
} }

View File

@@ -4,6 +4,7 @@
#include "tariff_log.h" #include "tariff_log.h"
#include "tariff_time_range.h" #include "tariff_time_range.h"
#include "ticket.h" #include "ticket.h"
#include "tariff_global_defines.h"
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
@@ -590,35 +591,294 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint32_t Calculator::GetCostFromDuration(Configuration *cfg, uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
QDateTime const &start, QDateTime const &start,
quint64 timeStepInMinutes) const { quint64 timeStepInMinutes,
int paymentOptionIndex) const {
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no // for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
// special days, nonstop. // special days, nonstop.
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Steps) {
QDateTime const end = start.addSecs(timeStepInMinutes*60); QDateTime const end = start.addSecs(timeStepInMinutes*60);
return GetCostFromDuration(cfg, start, end); return GetCostFromDuration(cfg, start, end, paymentOptionIndex);
} }
return 0; return 0;
} }
uint32_t Calculator::GetCostFromDuration(Configuration * cfg, uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
QDateTime const &start, QDateTime const &start,
QDateTime const &end) const { QDateTime const &end,
int paymentOptionIndex) const {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Steps) {
int const timeStepInMinutes = start.secsTo(end) / 60; int const timeStepInMinutes = start.secsTo(end) / 60;
return GetPriceForTimeStep(cfg, timeStepInMinutes); return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
} }
return 0; return 0;
} }
CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex) {
CalcState Calculator::isParkingAllowed(Configuration const *cfg, QDateTime const &start) { 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) {
QDateTime const end = start.addSecs(netto_parking_time*60);
QTime const endTime = end.time();
if (endTime <= until && start.date().dayOfWeek() == end.date().dayOfWeek()) {
qCritical() << DBG_HEADER;
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) {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Steps) {
int const weekdayId = start.date().dayOfWeek(); int const weekdayId = start.date().dayOfWeek();
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId); 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 (businessHours == BusinessHours::OnlyWeekDays) {
if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741) if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) { if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
@@ -1569,24 +1829,28 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
return QList<int>(); return QList<int>();
} }
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const { QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const {
if (m_timeSteps.size() > 0) { qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "paymentOptionIndex:" << paymentOptionIndex;
if (m_timeSteps.size() > paymentOptionIndex) {
//qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps; //qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps;
return m_timeSteps; return m_timeSteps[paymentOptionIndex];
} else {
m_timeSteps.push_back(QList<int>());
} }
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
start.setTime(QTime(start.time().hour(), start.time().minute(), 0)); start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
int const pop_id = cfg->getPaymentOptions().pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config; int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg); static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
qCritical() << __func__ << ":" << __LINE__ << " start parking time:" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << " payment option id:" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC"; //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
@@ -1595,13 +1859,13 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
std::size_t const s = cfg->TimeRange.size(); std::size_t const s = cfg->TimeRange.size();
for (std::size_t id = 1; id <= s; ++id) { for (std::size_t id = 1; id <= s; ++id) {
int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId); int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
m_timeSteps.append(step); m_timeSteps[paymentOptionIndex].append(step);
} }
} else { } else {
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;
if (pop_carry_over) { if (pop_carry_over) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id; int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from; 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; QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
@@ -1625,19 +1889,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
.arg(timeStep).arg(duration.pun_duration_max); .arg(timeStep).arg(duration.pun_duration_max);
break; break;
} }
qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time; qCritical() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
// set dynamic minimal parking time // set dynamic minimal parking time
cfg->getPaymentOptions().pop_min_time = timeStep; cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = timeStep;
qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time; qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
duration.pun_duration = timeStep; duration.pun_duration = timeStep;
timeStepCompensation = duration.pun_duration_max - duration.pun_duration; timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
m_timeSteps << duration.pun_duration; m_timeSteps[paymentOptionIndex] << duration.pun_duration;
} else { } else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation; duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
m_timeSteps << duration.pun_duration;; m_timeSteps[paymentOptionIndex] << duration.pun_duration;;
} }
cfg->Duration.erase(search); cfg->Duration.erase(search);
@@ -1658,24 +1922,31 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
} }
} }
} else { } else {
qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC"; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{ {
int const durationId = itr->second.pra_payment_unit_id; int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration; int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
m_timeSteps << durationUnit; int size = m_timeSteps.size();
while (size <= paymentOptionIndex) {
m_timeSteps.push_back(QList<int>());
size = m_timeSteps.size();
}
m_timeSteps[paymentOptionIndex] << durationUnit;
} }
} }
qCritical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps; qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "NEW timeSteps:" << m_timeSteps;
return m_timeSteps; return m_timeSteps[paymentOptionIndex];
} }
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const { uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
int const pop_id = cfg->getPaymentOptions().pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
#include "utilities.h" #include "utilities.h"
#include "tariff_log.h" #include "tariff_log.h"
#include "tariff_business_hours.h"
#include <QDebug> #include <QDebug>
#include <algorithm> #include <algorithm>
@@ -260,7 +261,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; //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)) 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; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;
@@ -275,7 +276,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; //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)) 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; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;
@@ -317,7 +318,7 @@ bool Utilities::CheckSpecialDay(Configuration const *cfg,
continue; continue;
} }
} }
qDebug() << "CheckSpecialDay() => SPECIAL DAY"; //qDebug() << "CheckSpecialDay() => SPECIAL DAY";
*specialDayId = spec_days_itr->second.ped_id; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;
@@ -333,6 +334,14 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate); 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) { QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate); return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
} }
@@ -399,7 +408,10 @@ uint32_t Utilities::getMaximalParkingPrice(Configuration const *cfg, PaymentMeth
uint32_t Utilities::getTimeRangeStep(Configuration const *cfg, int step, PaymentMethod methodId) { uint32_t Utilities::getTimeRangeStep(Configuration const *cfg, int step, PaymentMethod methodId) {
if (methodId == PaymentMethod::Progressive) { if (methodId == PaymentMethod::Progressive) {
return std::max((int)cfg->TimeRange.find(step)->second.time_range_to_in_minutes_from_start, 0); Configuration::TimeRangeType::const_iterator it = cfg->TimeRange.find(step);
if (it != cfg->TimeRange.cend()) {
return std::max((int)(it->second.time_range_to_in_minutes_from_start), 0);
}
} }
return 0; return 0;
@@ -420,10 +432,10 @@ uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod
} }
BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) { BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) {
int businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours; uint64_t businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
switch (businessHours) { 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 OnlyWorkingDays: return BusinessHours::OnlyWorkingDays;
case OnlyWeekDays: return BusinessHours::OnlyWeekDays; case OnlyWeekDays: return BusinessHours::OnlyWeekDays;
case OnlyWeekEnd: return BusinessHours::OnlyWeekEnd; case OnlyWeekEnd: return BusinessHours::OnlyWeekEnd;
@@ -433,6 +445,21 @@ BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMetho
case SpecialAndSchoolHolidays: return BusinessHours::SpecialAndSchoolHolidays; case SpecialAndSchoolHolidays: return BusinessHours::SpecialAndSchoolHolidays;
case OnlyOpenForBusinessDays: return BusinessHours::OnlyOpenForBusinessDays; case OnlyOpenForBusinessDays: return BusinessHours::OnlyOpenForBusinessDays;
case AllDaysWithRestrictedHours: return BusinessHours::AllDaysWithRestrictedHours; 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; return BusinessHours::NoBusinessHoursDefined;
} }
@@ -447,3 +474,82 @@ double Utilities::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentM
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id; int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
return (double)(cfg->Duration.find(durationId)->second.pun_duration); 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;
}

File diff suppressed because it is too large Load Diff