Compare commits
6 Commits
d765997ca5
...
b84970fd12
Author | SHA1 | Date | |
---|---|---|---|
b84970fd12 | |||
7ac033720e | |||
c749de2bf9 | |||
c4cec1c04b | |||
a53cb37291 | |||
b1a98a20c5 |
@ -8,6 +8,7 @@ using namespace std;
|
|||||||
class Calculator
|
class Calculator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets duration in seconds from cost
|
/// Gets duration in seconds from cost
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -44,6 +45,21 @@ private:
|
|||||||
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
|
||||||
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
|
||||||
|
|
||||||
|
PaymentMethod getPaymentMethodId(Configuration const *cfg);
|
||||||
|
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
|
||||||
|
int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
|
||||||
|
|
||||||
|
uint32_t private_GetCostFromDuration(Configuration const* cfg,
|
||||||
|
QDateTime const &start,
|
||||||
|
QDateTime &end,
|
||||||
|
int durationMinutes,
|
||||||
|
bool nextDay = false,
|
||||||
|
bool prepaid = false,
|
||||||
|
bool overtime = false);
|
||||||
|
|
||||||
|
bool checkDurationMinutes(bool overTime,
|
||||||
|
int minParkingTime, int maxParkingTime,
|
||||||
|
int durationMinutes);
|
||||||
|
|
||||||
//
|
//
|
||||||
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#ifndef PAYMENT_METHOD_H_INCLUDED
|
||||||
|
#define PAYMENT_METHOD_H_INCLUDED
|
||||||
enum PaymentMethod
|
|
||||||
{
|
enum PaymentMethod {
|
||||||
Undefined = 0xFF,
|
Undefined = 0xFF,
|
||||||
Progressive = 0x01,
|
Progressive = 0x01,
|
||||||
Degressive = 0x02,
|
Degressive = 0x02,
|
||||||
Linear = 0x03,
|
Linear = 0x03,
|
||||||
Steps = 0x04
|
Steps = 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // PAYMENT_METHOD_H_INCLUDED
|
||||||
|
64
library/include/mobilisis/ticket.h
Normal file
64
library/include/mobilisis/ticket.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef TICKET_H_INCLUDED
|
||||||
|
#define TICKET_H_INCLUDED
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDebugStateSaver>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
#define NOT_INITIALIZED (0)
|
||||||
|
#define VALID (1)
|
||||||
|
#define INVALID_FROM_DATETIME (2)
|
||||||
|
#define INVALID_UNTIL_DATETIME (3)
|
||||||
|
#define STATUS_END (4)
|
||||||
|
|
||||||
|
class Ticket {
|
||||||
|
enum {CODE=0, CODE_STR=1, CODE_DESC=3};
|
||||||
|
public:
|
||||||
|
using Status = std::tuple<int, char const*, char const*>;
|
||||||
|
|
||||||
|
explicit Ticket();
|
||||||
|
|
||||||
|
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
|
||||||
|
operator QString();
|
||||||
|
|
||||||
|
Status getStatus() const;
|
||||||
|
QDateTime getValidFrom() const;
|
||||||
|
QDateTime getValidUntil() const;
|
||||||
|
uint32_t getPrice() const;
|
||||||
|
|
||||||
|
Status setStatus(Status status);
|
||||||
|
void setValidFrom(QDateTime const &validFrom);
|
||||||
|
void setValidUntil(QDateTime const &validUnil);
|
||||||
|
void setPrice(uint32_t price);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Status m_status;
|
||||||
|
|
||||||
|
QDateTime m_validFrom;
|
||||||
|
QDateTime m_validUntil;
|
||||||
|
|
||||||
|
int m_durationMinutesNetto;
|
||||||
|
int m_durationMinutesBrutto;
|
||||||
|
|
||||||
|
uint32_t m_price;
|
||||||
|
|
||||||
|
static constexpr const Status s[STATUS_END] = {
|
||||||
|
{NOT_INITIALIZED , "NOT_INITIALIZED" , "Ticket not initialized" },
|
||||||
|
{VALID , "VALID" , "Ticket is valid" },
|
||||||
|
{INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
|
||||||
|
{INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime" }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
|
||||||
|
QDebugStateSaver saver(debug);
|
||||||
|
debug << "Ticket-Status: " << std::get<1>(status)
|
||||||
|
<< "(" << std::get<2>(status) << ")";
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TICKET_H_INCLUDED
|
@ -9,46 +9,46 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "time_range.h"
|
#include "time_range.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Utilities {
|
namespace Utilities {
|
||||||
public:
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
|
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="date"></param>
|
/// <param name="date"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static DayOfWeek GetDayOfWeek(struct tm* tm);
|
DayOfWeek GetDayOfWeek(struct tm* tm);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Date and time parse helper function
|
/// Date and time parse helper function
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns time (tm) structure</returns>
|
/// <returns>Returns time (tm) structure</returns>
|
||||||
static struct tm DateTimeToStructTm(const char* dateTimeStr);
|
struct tm DateTimeToStructTm(const char* dateTimeStr);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Date parse helper function
|
/// Date parse helper function
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns time (tm) structure</returns>
|
/// <returns>Returns time (tm) structure</returns>
|
||||||
static struct tm DateToStructTm(const char* dateStr);
|
struct tm DateToStructTm(const char* dateStr);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Time parse helper function
|
/// Time parse helper function
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns time (tm) structure</returns>
|
/// <returns>Returns time (tm) structure</returns>
|
||||||
static struct tm TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday);
|
struct tm TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get current local time
|
/// Get current local time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns time_t structure</returns>
|
/// <returns>Returns time_t structure</returns>
|
||||||
static time_t GetCurrentLocalTime();
|
time_t GetCurrentLocalTime();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Zeller's algorithm for determining day of week
|
/// Zeller's algorithm for determining day of week
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static int ZellersAlgorithm(int day, int month, int year);
|
int ZellersAlgorithm(int day, int month, int year);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if current datetime is in range between start and end month of parking worktime
|
/// Checks if current datetime is in range between start and end month of parking worktime
|
||||||
@ -56,18 +56,23 @@ public:
|
|||||||
/// <param name="tariff_cfg"></param>
|
/// <param name="tariff_cfg"></param>
|
||||||
/// <param name="currentDateTime"></param>
|
/// <param name="currentDateTime"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check permissions
|
/// Check permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
|
bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
|
||||||
|
bool CheckSpecialDay(Configuration const *cfg,
|
||||||
|
QDateTime const ¤tDateTimeS,
|
||||||
|
int* specialDayId, uint32_t *specialDayPrice);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates price per unit
|
/// Calculates price per unit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pra_price"></param>
|
/// <param name="pra_price"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
||||||
|
|
||||||
};
|
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
|
||||||
|
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
|
||||||
|
}
|
||||||
|
@ -25,7 +25,8 @@ SOURCES += \
|
|||||||
src/utilities.cpp \
|
src/utilities.cpp \
|
||||||
src/configuration.cpp \
|
src/configuration.cpp \
|
||||||
src/tariff_log.cpp \
|
src/tariff_log.cpp \
|
||||||
src/calculate_price.cpp
|
src/calculate_price.cpp \
|
||||||
|
src/ticket.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
include/mobilisis/calculator_functions.h \
|
include/mobilisis/calculator_functions.h \
|
||||||
@ -66,7 +67,8 @@ HEADERS += \
|
|||||||
include/mobilisis/tariff_payment_rate.h \
|
include/mobilisis/tariff_payment_rate.h \
|
||||||
include/mobilisis/tariff_log.h \
|
include/mobilisis/tariff_log.h \
|
||||||
include/mobilisis/calculate_price.h \
|
include/mobilisis/calculate_price.h \
|
||||||
include/mobilisis/atb_project.h
|
include/mobilisis/atb_project.h \
|
||||||
|
include/mobilisis/ticket.h
|
||||||
|
|
||||||
OTHER_FILES += src/main.cpp
|
OTHER_FILES += src/main.cpp
|
||||||
|
|
||||||
|
@ -395,8 +395,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
QDateTime &end_datetime,
|
QDateTime &end_datetime,
|
||||||
int durationMinutes,
|
int durationMinutes,
|
||||||
bool nextDay,
|
bool nextDay,
|
||||||
bool prepaid)
|
bool prepaid) {
|
||||||
{
|
|
||||||
if (cfg->YearPeriod.size() == 0
|
if (cfg->YearPeriod.size() == 0
|
||||||
&& cfg->SpecialDays.size() == 0
|
&& cfg->SpecialDays.size() == 0
|
||||||
&& cfg->SpecialDaysWorktime.size() == 0)
|
&& cfg->SpecialDaysWorktime.size() == 0)
|
||||||
@ -405,58 +404,91 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
return GetCostFromDuration(cfg, start_datetime, end_datetime);
|
return GetCostFromDuration(cfg, start_datetime, end_datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get min and max time defined in JSON
|
return private_GetCostFromDuration(cfg, start_datetime,
|
||||||
static int const minMin = std::max((int)cfg->PaymentOption.find(payment_option)->second.pop_min_time, 0);
|
end_datetime, durationMinutes,
|
||||||
static int const maxMin = std::max((int)cfg->PaymentOption.find(payment_option)->second.pop_max_time, 0);
|
nextDay, prepaid);
|
||||||
|
}
|
||||||
|
|
||||||
static const bool checkMinMaxMinutes = [](int minMin, int maxMin){ return (minMin < maxMin) ? true : false; }(minMin, maxMin);
|
int Calculator::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
|
||||||
|
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_time, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Calculator::getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
|
||||||
|
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_time, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Calculator::checkDurationMinutes(bool overtime,
|
||||||
|
int minParkingTime,
|
||||||
|
int maxParkingTime,
|
||||||
|
int durationMinutes) {
|
||||||
|
if (!overtime) {
|
||||||
|
if (durationMinutes > maxParkingTime) {
|
||||||
|
qWarning() << QString("Total duration >= max_min (%1 >= %2)").arg(durationMinutes).arg(maxParkingTime);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (durationMinutes < minParkingTime) {
|
||||||
|
qWarning() << QString("Total duration <= minMin (%1 <= %2)").arg(durationMinutes).arg(minParkingTime);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Utilities;
|
||||||
|
|
||||||
|
uint32_t Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||||
|
QDateTime const &start,
|
||||||
|
QDateTime &end,
|
||||||
|
int durationMinutes,
|
||||||
|
bool nextDay,
|
||||||
|
bool prepaid,
|
||||||
|
bool overtime) {
|
||||||
|
// TODO
|
||||||
|
static const PaymentMethod paymentMethodId = PaymentMethod::Linear;
|
||||||
|
|
||||||
|
static int const minParkingTimeMinutes = getMinimalParkingTime(cfg, paymentMethodId);
|
||||||
|
static int const maxParkingTimeMinutes = getMaximalParkingTime(cfg, paymentMethodId);
|
||||||
|
|
||||||
|
static bool const checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
|
||||||
|
|
||||||
if (!checkMinMaxMinutes) {
|
if (!checkMinMaxMinutes) {
|
||||||
qCritical() << QString("ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID").arg(minMin).arg(maxMin);
|
qCritical() << QString(
|
||||||
return 0.0;
|
"ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID")
|
||||||
|
.arg(minParkingTimeMinutes).arg(maxParkingTimeMinutes);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkDurationMinutes(overtime, minParkingTimeMinutes,
|
||||||
|
maxParkingTimeMinutes, durationMinutes)) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get input date
|
// Get input date
|
||||||
QDateTime inputDate = start_datetime;
|
QDateTime inputDate = start;
|
||||||
|
|
||||||
// Get day of week
|
// Get day of week
|
||||||
int const weekdayId = inputDate.date().dayOfWeek();
|
int const weekdayId = inputDate.date().dayOfWeek();
|
||||||
|
|
||||||
// weekdayId = Utilities::ZellersAlgorithm(inputDate.date().day(),inputDate.date().month(),inputDate.date().year());
|
|
||||||
|
|
||||||
// Check overtime
|
uint32_t day_price = 0;
|
||||||
if (!overtime) {
|
uint32_t price_per_unit = 0;
|
||||||
if (durationMinutes > maxMin) {
|
|
||||||
qWarning() << QString("Total duration >= max_min (%1 >= %2)").arg(durationMinutes).arg(maxMin);
|
|
||||||
return maxMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durationMinutes < minMin) {
|
|
||||||
qWarning() << QString("Total duration <= minMin (%1 <= %2)").arg(durationMinutes).arg(minMin);
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double day_price = 0.0;
|
|
||||||
int current_special_day_id = -1;
|
int current_special_day_id = -1;
|
||||||
double price_per_unit = 0.0f;
|
|
||||||
|
|
||||||
int const timeRanges = std::max((int)cfg->WeekDaysWorktime.count(weekdayId), 1);
|
int const timeRanges = std::max((int)cfg->WeekDaysWorktime.count(weekdayId), 1);
|
||||||
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
if(Utilities::CheckSpecialDay(cfg,
|
if(Utilities::CheckSpecialDay(cfg, inputDate, ¤t_special_day_id, &day_price)) {
|
||||||
inputDate.toString(Qt::ISODate).toStdString().c_str(),
|
// Set special day price:
|
||||||
¤t_special_day_id,
|
// ACHTUNG: price_per_unit ist eigentlich immer preis pro minute !!!
|
||||||
&day_price)) {
|
price_per_unit = CalculatePricePerUnit(day_price);
|
||||||
// Set special day price
|
worktime[index].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id),
|
||||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
SpecialDaysWorkTimeUntil(cfg, current_special_day_id));
|
||||||
worktime[index].setTimeRange(QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str()),
|
|
||||||
QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str()));
|
|
||||||
} else {
|
} else {
|
||||||
// Set new price for the normal day
|
// Set new price for the normal day
|
||||||
|
|
||||||
int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
|
int pop_id = cfg->PaymentOption.find(paymentMethodId)->second.pop_id;
|
||||||
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
||||||
|
|
||||||
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
||||||
@ -468,7 +500,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
// When no workday found, go to next available day
|
// When no workday found, go to next available day
|
||||||
qDebug() << "No workday found, trying to find next available day";
|
qDebug() << "No workday found, trying to find next available day";
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid));
|
return private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
|
for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
|
||||||
@ -490,9 +522,9 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
if (price_per_unit == 0) {
|
if (price_per_unit == 0) {
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
inputDate.setTime(worktime_from);
|
inputDate.setTime(worktime_from);
|
||||||
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid);
|
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
|
||||||
if (partialCost <= __DBL_MIN__) {
|
if (partialCost == 0) {
|
||||||
return 0.0;
|
return 0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
continue;
|
continue;
|
||||||
@ -517,9 +549,9 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
} else if(inputDate.time() > worktime_to) {
|
} else if(inputDate.time() > worktime_to) {
|
||||||
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid);
|
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
|
||||||
if (partialCost < __DBL_MIN__) {
|
if (partialCost == 0) {
|
||||||
return 0.0;
|
return 0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
continue;
|
continue;
|
||||||
@ -545,7 +577,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
// Go to next day if minutes not spent
|
// Go to next day if minutes not spent
|
||||||
if(inputDate.time() >= worktime_to) {
|
if(inputDate.time() >= worktime_to) {
|
||||||
// check for carry_over status
|
// check for carry_over status
|
||||||
if (cfg->PaymentOption.find(payment_option)->second.pop_carry_over < 1) {
|
if (cfg->PaymentOption.find(paymentMethodId)->second.pop_carry_over < 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,9 +585,9 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
|
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
overtime = true;
|
overtime = true;
|
||||||
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, false, false);
|
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
|
||||||
if (partialCost < __DBL_MIN__) {
|
if (partialCost == 0) {
|
||||||
return 0.0;
|
return 0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
break; // stop while, and continue in outer loop
|
break; // stop while, and continue in outer loop
|
||||||
@ -570,7 +602,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
|
|
||||||
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate);
|
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate);
|
||||||
|
|
||||||
end_datetime = inputDate;
|
end = inputDate;
|
||||||
|
|
||||||
//double ret_val = total_cost;
|
//double ret_val = total_cost;
|
||||||
//total_cost = 0.0f;
|
//total_cost = 0.0f;
|
||||||
|
67
library/src/ticket.cpp
Normal file
67
library/src/ticket.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "ticket.h"
|
||||||
|
|
||||||
|
Ticket::Ticket()
|
||||||
|
: m_status(Ticket::s[NOT_INITIALIZED])
|
||||||
|
, m_validFrom()
|
||||||
|
, m_validUntil()
|
||||||
|
, m_durationMinutesNetto(0)
|
||||||
|
, m_durationMinutesBrutto(0)
|
||||||
|
, m_price() {
|
||||||
|
|
||||||
|
qDebug() << *this;
|
||||||
|
qDebug() << m_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ticket::Status Ticket::setStatus(Status status) {
|
||||||
|
Status old = m_status;
|
||||||
|
m_status = status;
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ticket::Status Ticket::getStatus() const {
|
||||||
|
return m_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ticket::setValidFrom(QDateTime const &validFrom) {
|
||||||
|
m_validFrom = validFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ticket::setValidUntil(QDateTime const &validUntil) {
|
||||||
|
m_validUntil = validUntil;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime Ticket::getValidFrom() const {
|
||||||
|
if (std::get<CODE>(m_status) == VALID) {
|
||||||
|
return m_validFrom;
|
||||||
|
}
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime Ticket::getValidUntil() const {
|
||||||
|
if (std::get<CODE>(m_status) == VALID) {
|
||||||
|
return m_validFrom;
|
||||||
|
}
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Ticket::getPrice() const {
|
||||||
|
return m_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ticket::setPrice(uint32_t price) {
|
||||||
|
m_price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ticket::operator QString() {
|
||||||
|
QStringList status;
|
||||||
|
status << QString("Status .............. : %1 (%2)")
|
||||||
|
.arg(std::get<0>(m_status))
|
||||||
|
.arg(std::get<2>(m_status));
|
||||||
|
status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate));
|
||||||
|
status << QString("Valid until ........ : %1").arg(m_validUntil.toString(Qt::ISODate));
|
||||||
|
status << QString("Duration (netto) ... : %1").arg(m_durationMinutesNetto);
|
||||||
|
status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto);
|
||||||
|
status << QString("Price ......... : %1").arg(m_price);
|
||||||
|
|
||||||
|
return status.join('\n');;
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "tariff_log.h"
|
#include "tariff_log.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
static int protection_counter = 0;
|
static int protection_counter = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -271,3 +273,47 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utilities::CheckSpecialDay(Configuration const *cfg,
|
||||||
|
QDateTime const ¤tDateTime,
|
||||||
|
int* specialDayId,
|
||||||
|
uint32_t *specialDayPrice) {
|
||||||
|
*specialDayId = -1;
|
||||||
|
*specialDayPrice = 0;
|
||||||
|
|
||||||
|
std::multimap<int, ATBSpecialDays>::const_iterator spec_days_itr;
|
||||||
|
|
||||||
|
for (spec_days_itr = cfg->SpecialDays.cbegin(); spec_days_itr != cfg->SpecialDays.cend(); ++spec_days_itr) {
|
||||||
|
int repeat_every_year = spec_days_itr->second.ped_year;
|
||||||
|
QDate start = QDate::fromString(spec_days_itr->second.ped_date_start.c_str(), Qt::ISODate);
|
||||||
|
QDate end = QDate::fromString(spec_days_itr->second.ped_date_end.c_str(), Qt::ISODate);
|
||||||
|
if (start.isValid() && end.isValid()) {
|
||||||
|
if ((currentDateTime.date().month() >= start.month()) &&
|
||||||
|
(currentDateTime.date().month() <= end.month())) {
|
||||||
|
if ((currentDateTime.date().day() >= start.day()) &&
|
||||||
|
(currentDateTime.date().day() <= end.day())) {
|
||||||
|
if (repeat_every_year <= 0) {
|
||||||
|
if ((currentDateTime.date().year() != start.year()) ||
|
||||||
|
(currentDateTime.date().year() != end.year())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << "CheckSpecialDay() => SPECIAL DAY";
|
||||||
|
*specialDayId = spec_days_itr->second.ped_id;
|
||||||
|
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId) {
|
||||||
|
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
|
||||||
|
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user