Compare commits
9 Commits
932d4e8cb9
...
2.3.99-21
Author | SHA1 | Date | |
---|---|---|---|
1b716c48d2
|
|||
77e1414c13 | |||
d95275a72d | |||
577a17dc6a | |||
d8d32820a3 | |||
2ce0aeef1d | |||
0cba85eafb | |||
4030a4b165 | |||
8c7afdfcb1 |
@@ -1,354 +0,0 @@
|
|||||||
#ifndef CALCULATE_PRICE_H
|
|
||||||
#define CALCULATE_PRICE_H
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include "tariff_time_range.h"
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QDateTime>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#ifdef CALCULATE_LIBRARY_EXPORTS
|
|
||||||
#define CALCULATE_LIBRARY_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define CALCULATE_LIBRARY_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define CALCULATE_LIBRARY_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tariff_permit_type.h"
|
|
||||||
|
|
||||||
class Configuration;
|
|
||||||
|
|
||||||
typedef Configuration parking_tariff_t;
|
|
||||||
|
|
||||||
//#ifdef __cplusplus
|
|
||||||
//extern "C" {
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
struct CALCULATE_LIBRARY_API price_t {
|
|
||||||
uint32_t units;
|
|
||||||
double netto;
|
|
||||||
double brutto;
|
|
||||||
double vat_percentage;
|
|
||||||
double vat;
|
|
||||||
|
|
||||||
explicit price_t() {
|
|
||||||
units = 0;
|
|
||||||
netto = brutto = vat_percentage = vat = 0.0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CALCULATE_LIBRARY_API CalcState {
|
|
||||||
static QString const SUCCESS;
|
|
||||||
static QString const ERROR_PARSING_ZONE_NR;
|
|
||||||
static QString const ERROR_LOADING_TARIFF;
|
|
||||||
static QString const ERROR_PARSING_TARIFF;
|
|
||||||
static QString const NEGATIVE_PARKING_TIME;
|
|
||||||
static QString const INVALID_START_DATE;
|
|
||||||
static QString const WRONG_PARAM_VALUES;
|
|
||||||
static QString const WRONG_ISO_TIME_FORMAT;
|
|
||||||
static QString const ABOVE_MAX_PARKING_TIME;
|
|
||||||
static QString const BELOW_MIN_PARKING_TIME;
|
|
||||||
static QString const BELOW_MIN_PARKING_PRICE;
|
|
||||||
static QString const ABOVE_MAX_PARKING_PRICE;
|
|
||||||
static QString const OVERPAID;
|
|
||||||
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
|
|
||||||
static QString const SUCCESS_MAXPRICE;
|
|
||||||
|
|
||||||
enum class State : uint8_t {
|
|
||||||
SUCCESS,
|
|
||||||
ERROR_PARSING_ZONE_NR,
|
|
||||||
ERROR_LOADING_TARIFF,
|
|
||||||
ERROR_PARSING_TARIFF,
|
|
||||||
NEGATIVE_PARKING_TIME,
|
|
||||||
INVALID_START_DATE,
|
|
||||||
WRONG_PARAM_VALUES,
|
|
||||||
WRONG_ISO_TIME_FORMAT,
|
|
||||||
ABOVE_MAX_PARKING_TIME,
|
|
||||||
BELOW_MIN_PARKING_TIME,
|
|
||||||
BELOW_MIN_PARKING_PRICE,
|
|
||||||
ABOVE_MAX_PARKING_PRICE,
|
|
||||||
OVERPAID,
|
|
||||||
OUTSIDE_ALLOWED_PARKING_TIME,
|
|
||||||
SUCCESS_MAXPRICE
|
|
||||||
};
|
|
||||||
|
|
||||||
State m_status;
|
|
||||||
QString m_desc;
|
|
||||||
TariffTimeRange m_allowedTimeRange;
|
|
||||||
|
|
||||||
explicit CalcState()
|
|
||||||
: m_status(State::SUCCESS)
|
|
||||||
, m_desc("") {
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit CalcState(State state, QString desc = "")
|
|
||||||
: m_status(state)
|
|
||||||
, m_desc(desc) {
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit CalcState(State state, QString desc = "",
|
|
||||||
QTime const &from = QTime(),
|
|
||||||
QTime const &until = QTime())
|
|
||||||
: m_status(state)
|
|
||||||
, m_desc(desc)
|
|
||||||
, m_allowedTimeRange(from, until) {
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator bool() const noexcept {
|
|
||||||
return (m_status == State::SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString() {
|
|
||||||
QString s;
|
|
||||||
switch (m_status) {
|
|
||||||
case State::SUCCESS:
|
|
||||||
s = CalcState::SUCCESS;
|
|
||||||
break;
|
|
||||||
case State::SUCCESS_MAXPRICE:
|
|
||||||
s = CalcState::SUCCESS_MAXPRICE;
|
|
||||||
break;
|
|
||||||
case State::ERROR_PARSING_ZONE_NR:
|
|
||||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
|
||||||
break;
|
|
||||||
case State::ERROR_LOADING_TARIFF:
|
|
||||||
s = CalcState::ERROR_LOADING_TARIFF;
|
|
||||||
break;
|
|
||||||
case State::ERROR_PARSING_TARIFF:
|
|
||||||
s = CalcState::ERROR_PARSING_TARIFF;
|
|
||||||
break;
|
|
||||||
case State::NEGATIVE_PARKING_TIME:
|
|
||||||
s = CalcState::NEGATIVE_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::ABOVE_MAX_PARKING_TIME:
|
|
||||||
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::WRONG_PARAM_VALUES:
|
|
||||||
s = CalcState::WRONG_PARAM_VALUES;
|
|
||||||
break;
|
|
||||||
case State::BELOW_MIN_PARKING_TIME:
|
|
||||||
s = CalcState::BELOW_MIN_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::BELOW_MIN_PARKING_PRICE:
|
|
||||||
s = CalcState::BELOW_MIN_PARKING_PRICE;
|
|
||||||
break;
|
|
||||||
case State::OVERPAID:
|
|
||||||
s = CalcState::OVERPAID;
|
|
||||||
break;
|
|
||||||
case State::INVALID_START_DATE:
|
|
||||||
s = CalcState::INVALID_START_DATE;
|
|
||||||
break;
|
|
||||||
case State::WRONG_ISO_TIME_FORMAT:
|
|
||||||
s = CalcState::WRONG_ISO_TIME_FORMAT;
|
|
||||||
break;
|
|
||||||
case State::OUTSIDE_ALLOWED_PARKING_TIME:
|
|
||||||
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::ABOVE_MAX_PARKING_PRICE:
|
|
||||||
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (m_desc.size() > 0) {
|
|
||||||
return s + ":" + m_desc;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator QString () const noexcept {
|
|
||||||
QString s;
|
|
||||||
switch (m_status) {
|
|
||||||
case State::SUCCESS:
|
|
||||||
s = CalcState::SUCCESS;
|
|
||||||
break;
|
|
||||||
case State::SUCCESS_MAXPRICE:
|
|
||||||
s = CalcState::SUCCESS_MAXPRICE;
|
|
||||||
break;
|
|
||||||
case State::ERROR_PARSING_ZONE_NR:
|
|
||||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
|
||||||
break;
|
|
||||||
case State::ERROR_LOADING_TARIFF:
|
|
||||||
s = CalcState::ERROR_LOADING_TARIFF;
|
|
||||||
break;
|
|
||||||
case State::ERROR_PARSING_TARIFF:
|
|
||||||
s = CalcState::ERROR_PARSING_TARIFF;
|
|
||||||
break;
|
|
||||||
case State::NEGATIVE_PARKING_TIME:
|
|
||||||
s = CalcState::NEGATIVE_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::ABOVE_MAX_PARKING_TIME:
|
|
||||||
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::WRONG_PARAM_VALUES:
|
|
||||||
s = CalcState::WRONG_PARAM_VALUES;
|
|
||||||
break;
|
|
||||||
case State::BELOW_MIN_PARKING_TIME:
|
|
||||||
s = CalcState::BELOW_MIN_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::BELOW_MIN_PARKING_PRICE:
|
|
||||||
s = CalcState::BELOW_MIN_PARKING_PRICE;
|
|
||||||
break;
|
|
||||||
case State::OVERPAID:
|
|
||||||
s = CalcState::OVERPAID;
|
|
||||||
break;
|
|
||||||
case State::INVALID_START_DATE:
|
|
||||||
s = CalcState::INVALID_START_DATE;
|
|
||||||
break;
|
|
||||||
case State::WRONG_ISO_TIME_FORMAT:
|
|
||||||
s = CalcState::WRONG_ISO_TIME_FORMAT;
|
|
||||||
break;
|
|
||||||
case State::OUTSIDE_ALLOWED_PARKING_TIME:
|
|
||||||
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
case State::ABOVE_MAX_PARKING_PRICE:
|
|
||||||
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return s + ":" + m_desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
CalcState &set(State s) { m_status = s; return *this; }
|
|
||||||
CalcState &setStatus(State s) { return set(s); }
|
|
||||||
CalcState &setStatus(QString const &desc) {
|
|
||||||
if (desc == SUCCESS) {
|
|
||||||
m_status = State::SUCCESS;
|
|
||||||
} else
|
|
||||||
if (desc == SUCCESS_MAXPRICE) {
|
|
||||||
m_status = State::SUCCESS_MAXPRICE;
|
|
||||||
}
|
|
||||||
if (desc == ERROR_PARSING_ZONE_NR) {
|
|
||||||
m_status = State::ERROR_PARSING_ZONE_NR;
|
|
||||||
} else
|
|
||||||
if (desc == ERROR_LOADING_TARIFF) {
|
|
||||||
m_status = State::SUCCESS;
|
|
||||||
} else
|
|
||||||
if (desc == ERROR_PARSING_TARIFF) {
|
|
||||||
m_status = State::ERROR_LOADING_TARIFF;
|
|
||||||
} else
|
|
||||||
if (desc == NEGATIVE_PARKING_TIME) {
|
|
||||||
m_status = State::NEGATIVE_PARKING_TIME;
|
|
||||||
} else
|
|
||||||
if (desc == INVALID_START_DATE) {
|
|
||||||
m_status = State::INVALID_START_DATE;
|
|
||||||
} else
|
|
||||||
if (desc == WRONG_PARAM_VALUES) {
|
|
||||||
m_status = State::WRONG_PARAM_VALUES;
|
|
||||||
} else
|
|
||||||
if (desc == WRONG_ISO_TIME_FORMAT) {
|
|
||||||
m_status = State::WRONG_ISO_TIME_FORMAT;
|
|
||||||
} else
|
|
||||||
if (desc == ABOVE_MAX_PARKING_TIME) {
|
|
||||||
m_status = State::ABOVE_MAX_PARKING_TIME;
|
|
||||||
} else
|
|
||||||
if (desc == BELOW_MIN_PARKING_TIME) {
|
|
||||||
m_status = State::BELOW_MIN_PARKING_TIME;
|
|
||||||
} else
|
|
||||||
if (desc == BELOW_MIN_PARKING_PRICE) {
|
|
||||||
m_status = State::BELOW_MIN_PARKING_PRICE;
|
|
||||||
} else
|
|
||||||
if (desc == OVERPAID) {
|
|
||||||
m_status = State::OVERPAID;
|
|
||||||
} else
|
|
||||||
if (desc == OUTSIDE_ALLOWED_PARKING_TIME) {
|
|
||||||
m_status = State::OUTSIDE_ALLOWED_PARKING_TIME;
|
|
||||||
} else
|
|
||||||
if (desc == ABOVE_MAX_PARKING_PRICE) {
|
|
||||||
m_status = State::ABOVE_MAX_PARKING_PRICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
State getStatus() const { return m_status; }
|
|
||||||
CalcState &setDesc(QString const &s) { m_desc = s; return *this; }
|
|
||||||
|
|
||||||
void setAllowedTimeRange(QTime const &from, QTime const &until) {
|
|
||||||
m_allowedTimeRange.setTimeRange(from, until);
|
|
||||||
}
|
|
||||||
|
|
||||||
TariffTimeRange getAllowedTimeRange() {
|
|
||||||
return m_allowedTimeRange;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
|
||||||
char const *config_file);
|
|
||||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
|
||||||
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, PermitType const &permitType);
|
|
||||||
|
|
||||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
|
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
|
|
||||||
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
|
|
||||||
int paymentOptionIndex=0);
|
|
||||||
|
|
||||||
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
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
time_t start_parking_time,
|
|
||||||
time_t end_parking_time,
|
|
||||||
struct price_t *price,
|
|
||||||
PermitType permitType);
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
QDateTime &start_parking_time,
|
|
||||||
int netto_parking_time,
|
|
||||||
QDateTime &end_parking_time, // return value
|
|
||||||
struct price_t *price, // return value
|
|
||||||
PermitType permitType,
|
|
||||||
bool prepaid = true);
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
time_t start_parking_time,
|
|
||||||
double cost,
|
|
||||||
QString &duration,
|
|
||||||
PermitType permitType);
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
QDateTime const &start_parking_time,
|
|
||||||
double cost,
|
|
||||||
QDateTime &ticketEndTime,
|
|
||||||
PermitType permitType); // return value
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
QDateTime const &start_parking_time,
|
|
||||||
QDateTime &ticketEndTime,
|
|
||||||
PermitType permitType);
|
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
|
|
||||||
parking_tariff_t *tariff,
|
|
||||||
QDateTime const &start_parking_time,
|
|
||||||
QDateTime &ticketEndTime,
|
|
||||||
PERMIT_TYPE permitType,
|
|
||||||
struct price_t *price);
|
|
||||||
//#ifdef __cplusplus
|
|
||||||
//} // extern "C"
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
#endif // CALCULATE_PRICE_H
|
|
@@ -1,155 +0,0 @@
|
|||||||
#ifndef CALCULATOR_FUNCTIONS_H_INCLUDED
|
|
||||||
#define CALCULATOR_FUNCTIONS_H_INCLUDED
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <optional>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "calculate_price.h"
|
|
||||||
#include "payment_method.h"
|
|
||||||
#include "ticket.h"
|
|
||||||
#include "tariff_time_range.h"
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Calculator {
|
|
||||||
mutable QVector<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;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Calculator(Calculator const &other) = delete;
|
|
||||||
void operator=(Calculator const &) = delete;
|
|
||||||
|
|
||||||
static Calculator &GetInstance() {
|
|
||||||
static Calculator c;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetTimeSteps(int paymentOptionIndex) {
|
|
||||||
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
|
|
||||||
m_timeSteps[paymentOptionIndex].clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QList<int> timeSteps(int paymentOptionIndex=0) const {
|
|
||||||
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
|
|
||||||
return m_timeSteps[paymentOptionIndex];
|
|
||||||
}
|
|
||||||
return QList<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets duration in seconds from cost
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tariff_cfg">Pointer to configuration</param>
|
|
||||||
/// <param name="vehicle_type">Type of vehicle</param>
|
|
||||||
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z)</param>
|
|
||||||
/// <param name="price"></param>
|
|
||||||
/// <returns>Returns duration in seconds (data type: double)</returns>
|
|
||||||
std::pair<std::string, QDateTime>
|
|
||||||
GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
|
|
||||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets cost from duration in seconds
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tariff_cfg">Pointer to configuration</param>
|
|
||||||
/// <param name="vehicle_type">Type of vehicle</param>
|
|
||||||
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
|
||||||
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
|
||||||
/// <param name="durationMin">Duration of parking in minutes</param>
|
|
||||||
/// <returns>Returns cost (data type: double)</returns>
|
|
||||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
|
|
||||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
|
||||||
|
|
||||||
// Daily ticket
|
|
||||||
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
|
||||||
std::optional<struct price_t> GetDailyTicketPrice(Configuration* cfg, QDateTime const &startDatetime, QDateTime &endTime, PERMIT_TYPE permitType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// helper function to find time steps for a tariff with PaymentMethod::Steps
|
|
||||||
// (e.g. Schoenau/Koenigsee)
|
|
||||||
//
|
|
||||||
QList<int> &GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0, QDateTime const &start = QDateTime::currentDateTime()) const;
|
|
||||||
QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0, QDateTime const &start = QDateTime::currentDateTime()) const {
|
|
||||||
return GetTimeSteps(cfg, paymentOptionIndex, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<int> GetPriceSteps(Configuration *cfg) const;
|
|
||||||
|
|
||||||
// additional helper functions
|
|
||||||
bool noSpecialDays(Configuration const *cfg) const {
|
|
||||||
return (cfg->SpecialDays.size() == 0) && (cfg->SpecialDaysWorktime.size() == 0);
|
|
||||||
}
|
|
||||||
bool specialDays(Configuration const *cfg) const {
|
|
||||||
return !noSpecialDays(cfg);
|
|
||||||
}
|
|
||||||
bool tariffIs24_7(Configuration const *cfg) const {
|
|
||||||
return (cfg->YearPeriod.size() == 0 &&
|
|
||||||
cfg->SpecialDays.size() == 0 &&
|
|
||||||
cfg->SpecialDaysWorktime.size() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ticket private_GetCostFromDuration(Configuration const* cfg,
|
|
||||||
QDateTime const &start,
|
|
||||||
int durationMinutes,
|
|
||||||
bool prepaid = false);
|
|
||||||
Ticket private_GetDurationFromCost(Configuration *cfg,
|
|
||||||
QDateTime const &start,
|
|
||||||
uint32_t price,
|
|
||||||
bool prepaid = false);
|
|
||||||
|
|
||||||
bool checkDurationMinutes(int minParkingTime, int maxParkingTime,
|
|
||||||
int durationMinutes);
|
|
||||||
|
|
||||||
//
|
|
||||||
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const;
|
|
||||||
//uint32_t GetPriceForStep(Configuration *cfg, int step) const {
|
|
||||||
// return GetPriceForTimeStep(cfg, step, 0);
|
|
||||||
//}
|
|
||||||
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
|
||||||
uint32_t GetStepForPrice(Configuration *cfg, int price) const {
|
|
||||||
return GetDurationForPrice(cfg, price);
|
|
||||||
}
|
|
||||||
|
|
||||||
int findWorkTimeRange(QDateTime const &dt,
|
|
||||||
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
||||||
size_t size);
|
|
||||||
int findNextWorkTimeRange(QDateTime const &dt,
|
|
||||||
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
||||||
size_t size);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CALCULATOR_FUNCTIONS_H_INCLUDED
|
|
@@ -10,6 +10,7 @@ class ATBTime {
|
|||||||
public:
|
public:
|
||||||
explicit ATBTime();
|
explicit ATBTime();
|
||||||
explicit ATBTime(int h, int m, int s = 0, int ms = 0);
|
explicit ATBTime(int h, int m, int s = 0, int ms = 0);
|
||||||
|
explicit ATBTime(QString const &time);
|
||||||
|
|
||||||
int hour() const { return m_time.time().hour(); }
|
int hour() const { return m_time.time().hour(); }
|
||||||
int minute() const { return m_time.time().minute(); }
|
int minute() const { return m_time.time().minute(); }
|
||||||
|
@@ -56,6 +56,7 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
static QString const ABOVE_MAX_PARKING_PRICE;
|
static QString const ABOVE_MAX_PARKING_PRICE;
|
||||||
static QString const OVERPAID;
|
static QString const OVERPAID;
|
||||||
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
|
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
|
||||||
|
static QString const SUCCESS_MAXPRICE;
|
||||||
|
|
||||||
enum class State : uint8_t {
|
enum class State : uint8_t {
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
@@ -71,7 +72,8 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
BELOW_MIN_PARKING_PRICE,
|
BELOW_MIN_PARKING_PRICE,
|
||||||
ABOVE_MAX_PARKING_PRICE,
|
ABOVE_MAX_PARKING_PRICE,
|
||||||
OVERPAID,
|
OVERPAID,
|
||||||
OUTSIDE_ALLOWED_PARKING_TIME
|
OUTSIDE_ALLOWED_PARKING_TIME,
|
||||||
|
SUCCESS_MAXPRICE
|
||||||
};
|
};
|
||||||
|
|
||||||
State m_status;
|
State m_status;
|
||||||
@@ -106,6 +108,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
case State::SUCCESS:
|
case State::SUCCESS:
|
||||||
s = CalcState::SUCCESS;
|
s = CalcState::SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
case State::SUCCESS_MAXPRICE:
|
||||||
|
s = CalcState::SUCCESS_MAXPRICE;
|
||||||
|
break;
|
||||||
case State::ERROR_PARSING_ZONE_NR:
|
case State::ERROR_PARSING_ZONE_NR:
|
||||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
s = CalcState::ERROR_PARSING_ZONE_NR;
|
||||||
break;
|
break;
|
||||||
@@ -158,6 +163,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
case State::SUCCESS:
|
case State::SUCCESS:
|
||||||
s = CalcState::SUCCESS;
|
s = CalcState::SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
case State::SUCCESS_MAXPRICE:
|
||||||
|
s = CalcState::SUCCESS_MAXPRICE;
|
||||||
|
break;
|
||||||
case State::ERROR_PARSING_ZONE_NR:
|
case State::ERROR_PARSING_ZONE_NR:
|
||||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
s = CalcState::ERROR_PARSING_ZONE_NR;
|
||||||
break;
|
break;
|
||||||
@@ -207,6 +215,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
if (desc == SUCCESS) {
|
if (desc == SUCCESS) {
|
||||||
m_status = State::SUCCESS;
|
m_status = State::SUCCESS;
|
||||||
} else
|
} else
|
||||||
|
if (desc == SUCCESS_MAXPRICE) {
|
||||||
|
m_status = State::SUCCESS_MAXPRICE;
|
||||||
|
}
|
||||||
if (desc == ERROR_PARSING_ZONE_NR) {
|
if (desc == ERROR_PARSING_ZONE_NR) {
|
||||||
m_status = State::ERROR_PARSING_ZONE_NR;
|
m_status = State::ERROR_PARSING_ZONE_NR;
|
||||||
} else
|
} else
|
||||||
|
@@ -73,7 +73,7 @@ public:
|
|||||||
/// <returns>Returns duration in seconds (data type: double)</returns>
|
/// <returns>Returns duration in seconds (data type: double)</returns>
|
||||||
std::pair<std::string, QDateTime>
|
std::pair<std::string, QDateTime>
|
||||||
GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
|
GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
|
||||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets cost from duration in seconds
|
/// Gets cost from duration in seconds
|
||||||
|
@@ -25,6 +25,7 @@ public:
|
|||||||
pop_max_time = 0;
|
pop_max_time = 0;
|
||||||
pop_min_price = 0;
|
pop_min_price = 0;
|
||||||
pop_max_price = 0;
|
pop_max_price = 0;
|
||||||
|
pop_max_price_save = 0;
|
||||||
pop_carry_over = -1;
|
pop_carry_over = -1;
|
||||||
pop_carry_over_option_id = -1;
|
pop_carry_over_option_id = -1;
|
||||||
pop_prepaid_option_id = -1;
|
pop_prepaid_option_id = -1;
|
||||||
@@ -61,6 +62,7 @@ public:
|
|||||||
double pop_max_time;
|
double pop_max_time;
|
||||||
double pop_min_price;
|
double pop_min_price;
|
||||||
double pop_max_price;
|
double pop_max_price;
|
||||||
|
double pop_max_price_save;
|
||||||
int pop_carry_over;
|
int pop_carry_over;
|
||||||
int pop_carry_over_option_id;
|
int pop_carry_over_option_id;
|
||||||
bool pop_truncate_last_interpolation_step;
|
bool pop_truncate_last_interpolation_step;
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include "atb_time.h"
|
||||||
|
|
||||||
struct ATBPrepaid {
|
struct ATBPrepaid {
|
||||||
int id;
|
int id;
|
||||||
bool anytime;
|
bool anytime;
|
||||||
|
@@ -2,18 +2,30 @@
|
|||||||
|
|
||||||
|
|
||||||
ATBTime::ATBTime()
|
ATBTime::ATBTime()
|
||||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
|
||||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ATBTime::ATBTime(int h, int m, int s, int ms)
|
ATBTime::ATBTime(int h, int m, int s, int ms)
|
||||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
|
||||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
|
||||||
|
|
||||||
QTime t(h, m, s, ms);
|
QTime t(h, m, s, ms);
|
||||||
m_time.setTime(t);
|
m_time.setTime(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATBTime::ATBTime(QString const &t)
|
||||||
|
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
||||||
|
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
||||||
|
|
||||||
|
if (t == "24:00:00") {
|
||||||
|
m_time = m_end;
|
||||||
|
} else {
|
||||||
|
m_time.setTime(QTime::fromString(t, Qt::ISODate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTime ATBTime::addMSecs(int ms) const {
|
QTime ATBTime::addMSecs(int ms) const {
|
||||||
return m_time.time().addMSecs(ms);
|
return m_time.time().addMSecs(ms);
|
||||||
}
|
}
|
||||||
|
@@ -77,6 +77,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
|
|||||||
if (paymentOptionIndex == -1) {
|
if (paymentOptionIndex == -1) {
|
||||||
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxTime = 0;
|
int maxTime = 0;
|
||||||
|
|
||||||
switch(permitType) {
|
switch(permitType) {
|
||||||
@@ -683,6 +684,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||||
|
|
||||||
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
|
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
|
||||||
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
|
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
|
||||||
|
|
||||||
@@ -753,6 +757,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||||
|
|
||||||
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||||
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
||||||
|
|
||||||
@@ -878,6 +885,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
effectiveStartTime.setTime(QTime(effectiveStartTime.time().hour(),
|
||||||
|
effectiveStartTime.time().minute(), 0));
|
||||||
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
|
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
|
||||||
|
|
||||||
int const carryOver = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
int const carryOver = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||||
@@ -943,6 +953,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
||||||
//end_parking_time.setTime(tlimit);
|
//end_parking_time.setTime(tlimit);
|
||||||
|
|
||||||
|
// max_price neu berechnen
|
||||||
|
|
||||||
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
||||||
.arg(end_parking_time.time().toString(Qt::ISODate)));
|
.arg(end_parking_time.time().toString(Qt::ISODate)));
|
||||||
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
@@ -1079,6 +1091,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
|
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
|
||||||
// handle prepaid option
|
// handle prepaid option
|
||||||
QDateTime effectiveStartTime(start_parking_time);
|
QDateTime effectiveStartTime(start_parking_time);
|
||||||
|
|
||||||
|
effectiveStartTime.setTime(QTime(effectiveStartTime.time().hour(),
|
||||||
|
effectiveStartTime.time().minute(), 0));
|
||||||
|
|
||||||
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
||||||
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
|
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
|
||||||
if (prepaidOption.has_value()) {
|
if (prepaidOption.has_value()) {
|
||||||
@@ -1095,8 +1111,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QDateTime start(start_parking_time);
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||||
|
QString cs = start.toString(Qt::ISODate);
|
||||||
|
|
||||||
std::pair<std::string, QDateTime> p_endTime
|
std::pair<std::string, QDateTime> p_endTime
|
||||||
= Calculator::GetInstance().GetDurationFromCost(
|
= Calculator::GetInstance().GetDurationFromCost(
|
||||||
@@ -1174,8 +1191,14 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
} else {
|
} else {
|
||||||
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
||||||
|
|
||||||
|
ticketEndTime.setTime(QTime(ticketEndTime.time().hour(),
|
||||||
|
ticketEndTime.time().minute(), 0));
|
||||||
|
|
||||||
|
int netto_parking_time = start_parking_time.secsTo(ticketEndTime) / 60;
|
||||||
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
|
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "step-config:" << pop_time_step_config;
|
qCritical() << __func__ << ":" << __LINE__ << "step-config:" << pop_time_step_config;
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time;
|
||||||
|
|
||||||
if (!ticketEndTime.isValid()) {
|
if (!ticketEndTime.isValid()) {
|
||||||
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
||||||
@@ -1217,6 +1240,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) {
|
if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) {
|
||||||
|
|
||||||
|
// note: in such a case (direct coins) carry-over has been handled
|
||||||
|
// already in GetDurationFromCost()
|
||||||
|
netto_parking_time -= carryOverDuration;
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time;
|
||||||
|
|
||||||
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||||
if (ticketEndTime.time() > carryOverStart) {
|
if (ticketEndTime.time() > carryOverStart) {
|
||||||
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||||
@@ -1242,23 +1271,85 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ticketEndTime.setTime(QTime(ticketEndTime.time().hour(),
|
|
||||||
ticketEndTime.time().minute(), 0));
|
|
||||||
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
|
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
|
||||||
|
|
||||||
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek()));
|
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek()));
|
||||||
itr != rangeEnd;
|
itr != rangeEnd;
|
||||||
++itr) {
|
++itr) {
|
||||||
ATBWeekDay const &wd = itr->second;
|
ATBWeekDay const &wd = itr->second;
|
||||||
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
|
bool parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
|
||||||
ticketEndTime,
|
ticketEndTime,
|
||||||
paymentOptionIndex);
|
paymentOptionIndex);
|
||||||
if (parkTimeLimitViolated) {
|
if (parkTimeLimitViolated) {
|
||||||
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
||||||
//ticketEndTime.setTime(tlimit);
|
//ticketEndTime.setTime(tlimit);
|
||||||
|
|
||||||
|
QList<int> const &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
|
||||||
|
|
||||||
|
QDateTime newTicketEndTime = ticketEndTime;
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "PARK-TIME VIOLATED";
|
||||||
|
|
||||||
|
for (int i = stepList.size() - 1; i > 0; --i) {
|
||||||
|
// qCritical() << __func__ << ":" << __LINE__ << "step[" << i << "]" << stepList.at(i);
|
||||||
|
|
||||||
|
if (netto_parking_time > 0 && stepList.at(i) <= netto_parking_time) {
|
||||||
|
int const diff = stepList.at(i-1) - stepList.at(i);
|
||||||
|
newTicketEndTime = newTicketEndTime.addSecs(diff * 60);
|
||||||
|
|
||||||
|
// qCritical() << __func__ << ":" << __LINE__ << "new-ticket-end-time" << newTicketEndTime.toString(Qt::ISODate);
|
||||||
|
|
||||||
|
parkTimeLimitViolated
|
||||||
|
= wd.getTariffCarryOverSettings()
|
||||||
|
.parkingTimeLimitExceeded(start_parking_time, newTicketEndTime, paymentOptionIndex);
|
||||||
|
|
||||||
|
if (!parkTimeLimitViolated) {
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
|
<< "PARK-TIME NOT VIOLATED FOR" << newTicketEndTime.toString(Qt::ISODate);
|
||||||
|
|
||||||
|
int duration = stepList.at(i-1);
|
||||||
|
|
||||||
|
// qCritical() << __func__ << ":" << __LINE__ << "duration" << duration;
|
||||||
|
|
||||||
|
std::multimap<int, ATBDuration>::const_iterator it;
|
||||||
|
for (it = tariff->Duration.cbegin();
|
||||||
|
it != tariff->Duration.cend();
|
||||||
|
++it) {
|
||||||
|
if (duration == it->second.pun_duration) {
|
||||||
|
|
||||||
|
// qCritical() << __func__ << ":" << __LINE__ << "duration" << duration;
|
||||||
|
|
||||||
|
ATBPaymentOption &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||||
|
int const pop_id = po.pop_id;
|
||||||
|
for (auto[itr, rangeEnd] = tariff->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||||
|
int const durationId = itr->second.pra_payment_unit_id;
|
||||||
|
|
||||||
|
// qCritical() << __func__ << ":" << __LINE__ << "durationId" << durationId << it->second.pun_id;
|
||||||
|
|
||||||
|
// note: for this to work, Duration and PaymentRate must have
|
||||||
|
// exactly the same structure
|
||||||
|
if (durationId == it->second.pun_id) {
|
||||||
|
int const pra_price = itr->second.pra_price;
|
||||||
|
po.pop_max_price = pra_price;
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "new max-price" << po.pop_max_price;
|
||||||
|
|
||||||
|
// note: ABOVE_MAX_PARKING_TIME would also be possible
|
||||||
|
// but here max-parking-time is dynamic. And for
|
||||||
|
// this dynamic value, opverpaid is actually correct
|
||||||
|
|
||||||
|
calcState.setDesc(CalcState::OVERPAID);
|
||||||
|
calcState.setStatus(CalcState::OVERPAID);
|
||||||
|
return calcState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
|
||||||
.arg(ticketEndTime.time().toString(Qt::ISODate)));
|
.arg(ticketEndTime.time().toString(Qt::ISODate)));
|
||||||
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
|
@@ -1000,6 +1000,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
this->currentPaymentOptions.last().pop_min_time = k->value.GetDouble();
|
this->currentPaymentOptions.last().pop_min_time = k->value.GetDouble();
|
||||||
} else if (strcmp(inner_obj_name, "pop_max_price") == 0) {
|
} else if (strcmp(inner_obj_name, "pop_max_price") == 0) {
|
||||||
this->currentPaymentOptions.last().pop_max_price = k->value.GetDouble();
|
this->currentPaymentOptions.last().pop_max_price = k->value.GetDouble();
|
||||||
|
this->currentPaymentOptions.last().pop_max_price_save = k->value.GetDouble();
|
||||||
} else if (strcmp(inner_obj_name, "pop_max_time") == 0) {
|
} else if (strcmp(inner_obj_name, "pop_max_time") == 0) {
|
||||||
this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
|
this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
|
||||||
} else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
|
} else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
|
||||||
|
Reference in New Issue
Block a user