Compare commits
7 Commits
2.3.99-20
...
932d4e8cb9
Author | SHA1 | Date | |
---|---|---|---|
932d4e8cb9 | |||
38abc65425 | |||
205896903b | |||
dbedfd094f | |||
57b9d16abc | |||
48afbc071c | |||
7a7b10260a |
354
library/include/calculate_price.h
Normal file
354
library/include/calculate_price.h
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
#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
|
155
library/include/calculator_functions.h
Normal file
155
library/include/calculator_functions.h
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#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
|
@@ -26,6 +26,7 @@ QString const CalcState::BELOW_MIN_PARKING_PRICE = "BELOW_MIN_PARKING_PRICE";
|
|||||||
QString const CalcState::ABOVE_MAX_PARKING_PRICE = "ABOVE_MAX_PARKING_PRICE";
|
QString const CalcState::ABOVE_MAX_PARKING_PRICE = "ABOVE_MAX_PARKING_PRICE";
|
||||||
QString const CalcState::OVERPAID = "OVERPAID";
|
QString const CalcState::OVERPAID = "OVERPAID";
|
||||||
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
|
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
|
||||||
|
QString const CalcState::SUCCESS_MAXPRICE = "SUCCESS_MAXPRICE";
|
||||||
|
|
||||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
||||||
return Calculator::GetInstance().GetTimeSteps(cfg);
|
return Calculator::GetInstance().GetTimeSteps(cfg);
|
||||||
@@ -818,6 +819,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
qCritical() << __func__ << ":" << __LINE__ << " re-computed prepaid-id" << pop_prepaid_option_id;
|
qCritical() << __func__ << ":" << __LINE__ << " re-computed prepaid-id" << pop_prepaid_option_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
|
||||||
|
int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
|
||||||
|
|
||||||
|
|
||||||
QDateTime effectiveStartTime(start_parking_time);
|
QDateTime effectiveStartTime(start_parking_time);
|
||||||
|
|
||||||
// handle special days
|
// handle special days
|
||||||
@@ -885,7 +893,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
|
|
||||||
// handle carry over
|
// handle carry over
|
||||||
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
|
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
|
||||||
if (netto_parking_time > minutesUntilCarryOver) {
|
if ((minutesUntilCarryOver > 0) && (netto_parking_time > minutesUntilCarryOver)) {
|
||||||
int const rest = netto_parking_time - minutesUntilCarryOver;
|
int const rest = netto_parking_time - minutesUntilCarryOver;
|
||||||
QDateTime s(effectiveStartTime);
|
QDateTime s(effectiveStartTime);
|
||||||
s = s.addSecs(minutesUntilCarryOver * 60);
|
s = s.addSecs(minutesUntilCarryOver * 60);
|
||||||
@@ -1103,6 +1111,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
if (endTime == CalcState::SUCCESS) {
|
if (endTime == CalcState::SUCCESS) {
|
||||||
calcState.setDesc(QString("SUCCESS"));
|
calcState.setDesc(QString("SUCCESS"));
|
||||||
calcState.setStatus(endTime);
|
calcState.setStatus(endTime);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "SUCCESS";
|
||||||
|
} else
|
||||||
|
if (endTime == CalcState::SUCCESS_MAXPRICE) {
|
||||||
|
calcState.setDesc(QString("SUCCESS_MAXPRICE"));
|
||||||
|
calcState.setStatus(endTime);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "SUCCESS_MAXPRICE";
|
||||||
} else
|
} else
|
||||||
if (endTime == CalcState::ERROR_PARSING_ZONE_NR) {
|
if (endTime == CalcState::ERROR_PARSING_ZONE_NR) {
|
||||||
calcState.setStatus(endTime);
|
calcState.setStatus(endTime);
|
||||||
@@ -1207,6 +1221,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
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);
|
||||||
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
|
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
|
||||||
|
} else
|
||||||
|
if (ticketEndTime.time() == carryOverStart) {
|
||||||
|
qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||||
|
ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||||
|
if (po.pop_apply_carry_over_to_ticket_endtime) {
|
||||||
|
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
|
||||||
|
qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||||
if (ticketEndTime.time() < carryOverEnd) {
|
if (ticketEndTime.time() < carryOverEnd) {
|
||||||
@@ -1255,7 +1278,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
return calcState.set(CalcState::State::INVALID_START_DATE);
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return calcState.set(CalcState::State::SUCCESS);
|
//return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << " calcState" << calcState.toString();
|
||||||
|
return calcState;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
|
||||||
|
@@ -136,6 +136,7 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||||
|
|
||||||
bool overPaid = false;
|
bool overPaid = false;
|
||||||
|
bool successMaxPrice = false; // max-price and cost match
|
||||||
|
|
||||||
int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
|
int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
|
||||||
if (paymentOptionIndex == -1) {
|
if (paymentOptionIndex == -1) {
|
||||||
@@ -273,6 +274,11 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
||||||
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
||||||
|
|
||||||
|
if (cost == pop_max_price) {
|
||||||
|
qCritical() << DBG_HEADER << "SUCCESS MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||||
|
successMaxPrice = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (cost > pop_max_price) {
|
if (cost > pop_max_price) {
|
||||||
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||||
if (pop_allow_overpay == false) {
|
if (pop_allow_overpay == false) {
|
||||||
@@ -280,6 +286,7 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
cost = pop_max_price;
|
cost = pop_max_price;
|
||||||
overPaid = true;
|
overPaid = true;
|
||||||
|
qCritical() << DBG_HEADER << "OVERPAID, MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||||
// return CalcState::OVERPAID.toStdString();
|
// return CalcState::OVERPAID.toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,6 +454,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), d);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), d);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), d);
|
||||||
|
}
|
||||||
return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
|
return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -523,6 +533,16 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
|
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
|
||||||
|
|
||||||
|
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||||
|
if (pop_carry_over) {
|
||||||
|
int weekDay = inputDate.date().dayOfWeek();
|
||||||
|
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
|
||||||
|
if (pop_carry_over_option_id != -1) {
|
||||||
|
int const carryOverDuration = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||||
|
inputDate = inputDate.addSecs(carryOverDuration * 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inputDate = inputDate.addSecs(durationInSecs);
|
inputDate = inputDate.addSecs(durationInSecs);
|
||||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||||
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
||||||
@@ -561,6 +581,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), inputDate);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), inputDate);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), inputDate);
|
||||||
|
}
|
||||||
return std::make_pair(s.toStdString(), inputDate);
|
return std::make_pair(s.toStdString(), inputDate);
|
||||||
} // if ((double)price == cost) {
|
} // if ((double)price == cost) {
|
||||||
else {
|
else {
|
||||||
@@ -648,6 +671,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
} else {
|
} else {
|
||||||
QDateTime const dt = start;
|
QDateTime const dt = start;
|
||||||
@@ -698,6 +724,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,6 +825,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,6 +872,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,6 +909,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,6 +1031,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
if (overPaid) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
|
if (successMaxPrice) {
|
||||||
|
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||||
|
}
|
||||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,11 @@ OTHER_FILES += \
|
|||||||
/opt/ptu5/opt/customer_335/etc/psa_tariff/tariff02.json \
|
/opt/ptu5/opt/customer_335/etc/psa_tariff/tariff02.json \
|
||||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff01.json \
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff01.json \
|
||||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json \
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json \
|
||||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json \
|
||||||
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff04.json \
|
||||||
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff05.json \
|
||||||
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff06.json \
|
||||||
|
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff07.json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user