2023-04-24 15:31:46 +02:00
|
|
|
#ifndef CALCULATE_PRICE_H
|
|
|
|
#define CALCULATE_PRICE_H
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
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
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-05-08 12:32:44 +02:00
|
|
|
struct CALCULATE_LIBRARY_API CalcState {
|
|
|
|
enum class State : uint8_t {
|
|
|
|
SUCCESS,
|
|
|
|
ERROR_PARSING_ZONE_NR,
|
|
|
|
ERROR_LOADING_TARIFF,
|
|
|
|
ERROR_PARSING_TARIFF,
|
|
|
|
NEGATIVE_PARING_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,
|
|
|
|
OVERPAID
|
|
|
|
};
|
|
|
|
|
|
|
|
State m_status;
|
|
|
|
QString m_desc;
|
|
|
|
|
|
|
|
explicit CalcState() : m_status(State::SUCCESS), m_desc("") {}
|
|
|
|
|
|
|
|
explicit operator bool() const noexcept {
|
|
|
|
return (m_status == State::SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator QString () const noexcept {
|
|
|
|
QString s;
|
|
|
|
switch (m_status) {
|
|
|
|
case State::SUCCESS:
|
|
|
|
s = "SUCCESS";
|
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_ZONE_NR:
|
|
|
|
s = "ERROR_PARSING_ZONE_NR";
|
|
|
|
break;
|
|
|
|
case State::ERROR_LOADING_TARIFF:
|
|
|
|
s = "ERROR_LOADING_TARIFF";
|
|
|
|
break;
|
|
|
|
case State::ERROR_PARSING_TARIFF:
|
|
|
|
s = "ERROR_PARSING_TARIFF";
|
|
|
|
break;
|
|
|
|
case State::NEGATIVE_PARING_TIME:
|
|
|
|
s = "NEGATIVE_PARKING_TIME";
|
|
|
|
break;
|
|
|
|
case State::ABOVE_MAX_PARKING_TIME:
|
|
|
|
s = "ABOVE_MAX_PARKING_TIME";
|
|
|
|
break;
|
|
|
|
case State::WRONG_PARAM_VALUES:
|
|
|
|
s = "WRONG_PARAM_VALUES";
|
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_TIME:
|
|
|
|
s = "BELOW_MIN_PARKING_TIME";
|
|
|
|
break;
|
|
|
|
case State::BELOW_MIN_PARKING_PRICE:
|
|
|
|
s = "BELOW_MIN_PARKING_PRICE";
|
|
|
|
break;
|
|
|
|
case State::OVERPAID:
|
|
|
|
s = "OVERPAID";
|
|
|
|
break;
|
2023-05-09 11:38:39 +02:00
|
|
|
case State::INVALID_START_DATE:
|
|
|
|
s = "INVALID_START_DATE";
|
|
|
|
break;
|
2023-05-10 16:16:24 +02:00
|
|
|
case State::WRONG_ISO_TIME_FORMAT:
|
|
|
|
s = "WRONG_ISO_TIME_FORMAT";
|
2023-05-08 12:32:44 +02:00
|
|
|
}
|
|
|
|
return s + ":" + m_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CalcState &set(State s) { m_status = s; return *this; }
|
|
|
|
CalcState &setDesc(QString s) { m_desc = s; return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
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-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,
|
|
|
|
QDateTime const &start_parking_time,
|
2023-05-16 15:31:53 +02:00
|
|
|
int netto_parking_time,
|
|
|
|
QDateTime &end_parking_time, // return value
|
|
|
|
struct price_t *price); // return value
|
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);
|
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
|