2023-04-24 15:31:46 +02:00
|
|
|
#ifndef CALCULATE_PRICE_H
|
|
|
|
#define CALCULATE_PRICE_H
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <inttypes.h>
|
2024-01-31 15:12:41 +01:00
|
|
|
#include "tariff_time_range.h"
|
2023-04-24 15:31:46 +02:00
|
|
|
|
2023-05-08 12:32:44 +02:00
|
|
|
#include <QString>
|
2023-05-10 16:16:24 +02:00
|
|
|
#include <QDateTime>
|
2023-05-08 12:32:44 +02:00
|
|
|
|
2023-05-02 09:09:18 +02:00
|
|
|
#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
|
|
|
|
|
2024-02-22 16:27:52 +01:00
|
|
|
#include "tariff_permit_type.h"
|
|
|
|
|
2023-04-24 15:31:46 +02:00
|
|
|
class Configuration;
|
|
|
|
|
|
|
|
typedef Configuration parking_tariff_t;
|
|
|
|
|
2023-05-10 16:16:24 +02:00
|
|
|
//#ifdef __cplusplus
|
|
|
|
//extern "C" {
|
|
|
|
//#endif
|
2023-04-24 15:31:46 +02:00
|
|
|
|
2023-05-02 09:44:14 +02:00
|
|
|
struct CALCULATE_LIBRARY_API price_t {
|
2023-04-24 15:31:46 +02:00
|
|
|
uint32_t units;
|
|
|
|
double netto;
|
|
|
|
double brutto;
|
|
|
|
double vat_percentage;
|
|
|
|
double vat;
|
2024-01-31 15:13:24 +01:00
|
|
|
|
|
|
|
explicit price_t() {
|
|
|
|
units = 0;
|
|
|
|
netto = brutto = vat_percentage = vat = 0.0;
|
|
|
|
}
|
2023-04-24 15:31:46 +02:00
|
|
|
};
|
|
|
|
|
2023-05-08 12:32:44 +02:00
|
|
|
struct CALCULATE_LIBRARY_API CalcState {
|
2024-06-05 16:58:12 +02:00
|
|
|
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;
|
|
|
|
|
2023-05-08 12:32:44 +02:00
|
|
|
enum class State : uint8_t {
|
|
|
|
SUCCESS,
|
|
|
|
ERROR_PARSING_ZONE_NR,
|
|
|
|
ERROR_LOADING_TARIFF,
|
|
|
|
ERROR_PARSING_TARIFF,
|
2024-06-05 16:58:12 +02:00
|
|
|
NEGATIVE_PARKING_TIME,
|
2023-05-09 11:38:39 +02:00
|
|
|
INVALID_START_DATE,
|
2023-05-08 12:32:44 +02:00
|
|
|
WRONG_PARAM_VALUES,
|
2023-05-10 16:16:24 +02:00
|
|
|
WRONG_ISO_TIME_FORMAT,
|
2023-05-08 12:32:44 +02:00
|
|
|
ABOVE_MAX_PARKING_TIME,
|
|
|
|
BELOW_MIN_PARKING_TIME,
|
|
|
|
BELOW_MIN_PARKING_PRICE,
|
2024-06-05 16:58:12 +02:00
|
|
|
ABOVE_MAX_PARKING_PRICE,
|
2024-01-31 11:37:49 +01:00
|
|
|
OVERPAID,
|
|
|
|
OUTSIDE_ALLOWED_PARKING_TIME
|
2023-05-08 12:32:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
State m_status;
|
|
|
|
QString m_desc;
|
2024-01-31 15:12:41 +01:00
|
|
|
TariffTimeRange m_allowedTimeRange;
|
2023-05-08 12:32:44 +02:00
|
|
|
|
2024-01-31 15:12:41 +01:00
|
|
|
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) {
|
|
|
|
}
|
2023-05-08 12:32:44 +02:00
|
|
|
|
|
|
|
explicit operator bool() const noexcept {
|
|
|
|
return (m_status == State::SUCCESS);
|
|
|
|
}
|
|
|
|
|
2024-02-28 11:31:28 +01:00
|
|
|
QString toString() {
|
|
|
|
QString s;
|
|
|
|
switch (m_status) {
|
|
|
|
case State::SUCCESS:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::SUCCESS;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_ZONE_NR:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_PARSING_ZONE_NR;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::ERROR_LOADING_TARIFF:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_LOADING_TARIFF;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_TARIFF:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_PARSING_TARIFF;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
2024-06-05 16:58:12 +02:00
|
|
|
case State::NEGATIVE_PARKING_TIME:
|
|
|
|
s = CalcState::NEGATIVE_PARKING_TIME;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::ABOVE_MAX_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::WRONG_PARAM_VALUES:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::WRONG_PARAM_VALUES;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::BELOW_MIN_PARKING_TIME;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_PRICE:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::BELOW_MIN_PARKING_PRICE;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::OVERPAID:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::OVERPAID;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::INVALID_START_DATE:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::INVALID_START_DATE;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::WRONG_ISO_TIME_FORMAT:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::WRONG_ISO_TIME_FORMAT;
|
2024-02-28 11:31:28 +01:00
|
|
|
break;
|
|
|
|
case State::OUTSIDE_ALLOWED_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
|
|
|
|
break;
|
|
|
|
case State::ABOVE_MAX_PARKING_PRICE:
|
|
|
|
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
|
|
break;
|
2024-02-28 11:31:28 +01:00
|
|
|
}
|
2024-06-07 13:33:04 +02:00
|
|
|
if (m_desc.size() > 0) {
|
|
|
|
return s + ":" + m_desc;
|
|
|
|
}
|
|
|
|
return s;
|
2024-02-28 11:31:28 +01:00
|
|
|
}
|
|
|
|
|
2023-05-08 12:32:44 +02:00
|
|
|
explicit operator QString () const noexcept {
|
|
|
|
QString s;
|
|
|
|
switch (m_status) {
|
|
|
|
case State::SUCCESS:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::SUCCESS;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_ZONE_NR:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_PARSING_ZONE_NR;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::ERROR_LOADING_TARIFF:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_LOADING_TARIFF;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_TARIFF:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ERROR_PARSING_TARIFF;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
2024-06-05 16:58:12 +02:00
|
|
|
case State::NEGATIVE_PARKING_TIME:
|
|
|
|
s = CalcState::NEGATIVE_PARKING_TIME;
|
2024-01-30 10:30:11 +01:00
|
|
|
break;
|
2023-05-08 12:32:44 +02:00
|
|
|
case State::ABOVE_MAX_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::WRONG_PARAM_VALUES:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::WRONG_PARAM_VALUES;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::BELOW_MIN_PARKING_TIME;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_PRICE:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::BELOW_MIN_PARKING_PRICE;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
|
|
|
case State::OVERPAID:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::OVERPAID;
|
2023-05-08 12:32:44 +02:00
|
|
|
break;
|
2023-05-09 11:38:39 +02:00
|
|
|
case State::INVALID_START_DATE:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::INVALID_START_DATE;
|
2023-05-09 11:38:39 +02:00
|
|
|
break;
|
2023-05-10 16:16:24 +02:00
|
|
|
case State::WRONG_ISO_TIME_FORMAT:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::WRONG_ISO_TIME_FORMAT;
|
2024-01-31 15:12:41 +01:00
|
|
|
break;
|
2024-01-31 11:37:49 +01:00
|
|
|
case State::OUTSIDE_ALLOWED_PARKING_TIME:
|
2024-06-05 16:58:12 +02:00
|
|
|
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
|
|
|
|
break;
|
|
|
|
case State::ABOVE_MAX_PARKING_PRICE:
|
|
|
|
s = CalcState::ABOVE_MAX_PARKING_TIME;
|
|
|
|
break;
|
2023-05-08 12:32:44 +02:00
|
|
|
}
|
|
|
|
return s + ":" + m_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CalcState &set(State s) { m_status = s; return *this; }
|
2024-04-08 13:52:53 +02:00
|
|
|
CalcState &setStatus(State s) { return set(s); }
|
2024-06-05 16:58:12 +02:00
|
|
|
CalcState &setStatus(QString const &desc) {
|
|
|
|
if (desc == SUCCESS) {
|
|
|
|
m_status = State::SUCCESS;
|
|
|
|
} else
|
|
|
|
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;
|
|
|
|
}
|
2024-04-08 13:52:53 +02:00
|
|
|
State getStatus() const { return m_status; }
|
2024-06-05 16:58:12 +02:00
|
|
|
CalcState &setDesc(QString const &s) { m_desc = s; return *this; }
|
2024-01-31 15:12:41 +01:00
|
|
|
|
|
|
|
void setAllowedTimeRange(QTime const &from, QTime const &until) {
|
|
|
|
m_allowedTimeRange.setTimeRange(from, until);
|
|
|
|
}
|
|
|
|
|
|
|
|
TariffTimeRange getAllowedTimeRange() {
|
|
|
|
return m_allowedTimeRange;
|
|
|
|
}
|
2023-05-08 12:32:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
|
|
|
char const *config_file);
|
2023-05-02 09:09:18 +02:00
|
|
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
2023-05-12 09:20:46 +02:00
|
|
|
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
2023-04-24 15:31:46 +02:00
|
|
|
|
2023-12-07 16:26:09 +01:00
|
|
|
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown);
|
|
|
|
|
2024-01-22 15:39:47 +01:00
|
|
|
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
|
2024-04-12 14:17:43 +02:00
|
|
|
|
2024-04-30 14:06:04 +02:00
|
|
|
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
|
2024-04-12 14:17:43 +02:00
|
|
|
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
|
|
|
|
int paymentOptionIndex=0);
|
|
|
|
|
2024-04-30 14:06:04 +02:00
|
|
|
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
|
2024-04-12 14:17:43 +02:00
|
|
|
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,
|
2024-05-15 15:19:47 +02:00
|
|
|
int paymentOptionIndex = 0,
|
|
|
|
QDateTime const &start = QDateTime::currentDateTime());
|
2024-04-12 14:17:43 +02:00
|
|
|
|
|
|
|
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,
|
2024-04-16 12:07:18 +02:00
|
|
|
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
|
|
|
|
QDateTime const &start = QDateTime::currentDateTime(),
|
|
|
|
QDateTime *productStart = nullptr,
|
|
|
|
QDateTime *productEnd = nullptr);
|
2024-01-22 14:26:57 +01:00
|
|
|
|
2023-05-16 15:31:53 +02:00
|
|
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
2023-05-09 11:38:39 +02:00
|
|
|
parking_tariff_t *tariff,
|
2023-05-08 12:32:44 +02:00
|
|
|
time_t start_parking_time,
|
|
|
|
time_t end_parking_time,
|
|
|
|
struct price_t *price);
|
2023-05-09 11:38:39 +02:00
|
|
|
|
2023-05-10 16:16:24 +02:00
|
|
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|
|
|
parking_tariff_t *tariff,
|
2024-02-15 16:02:48 +01:00
|
|
|
QDateTime &start_parking_time,
|
2023-05-16 15:31:53 +02:00
|
|
|
int netto_parking_time,
|
|
|
|
QDateTime &end_parking_time, // return value
|
2024-02-22 09:40:27 +01:00
|
|
|
struct price_t *price, // return value
|
|
|
|
bool prepaid = true);
|
2023-05-10 16:16:24 +02:00
|
|
|
|
2023-05-16 15:31:53 +02:00
|
|
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
|
2023-05-09 11:38:39 +02:00
|
|
|
parking_tariff_t *tariff,
|
|
|
|
time_t start_parking_time,
|
|
|
|
double cost,
|
|
|
|
QString &duration);
|
2023-05-10 16:16:24 +02:00
|
|
|
|
|
|
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|
|
|
parking_tariff_t *tariff,
|
|
|
|
QDateTime const &start_parking_time,
|
|
|
|
double cost,
|
2023-05-16 15:31:53 +02:00
|
|
|
QDateTime &ticketEndTime); // return value
|
2023-05-15 14:05:55 +02:00
|
|
|
|
|
|
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
|
|
|
parking_tariff_t *tariff,
|
2023-05-16 11:07:21 +02:00
|
|
|
QDateTime const &start_parking_time,
|
|
|
|
QDateTime &ticketEndTime);
|
2024-01-30 10:33:11 +01:00
|
|
|
|
|
|
|
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);
|
2023-05-10 16:16:24 +02:00
|
|
|
//#ifdef __cplusplus
|
|
|
|
//} // extern "C"
|
|
|
|
//#endif
|
2023-04-24 15:31:46 +02:00
|
|
|
|
|
|
|
#endif // CALCULATE_PRICE_H
|