Compare commits
No commits in common. "b84970fd1267f7ae606a8d86d6f854bd919a9d56" and "d765997ca534bc618e7fa50b6cee772695cba44d" have entirely different histories.
b84970fd12
...
d765997ca5
@ -8,7 +8,6 @@ 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>
|
||||||
@ -45,21 +44,6 @@ 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,12 +1,10 @@
|
|||||||
#ifndef PAYMENT_METHOD_H_INCLUDED
|
#pragma once
|
||||||
#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
|
|
@ -1,64 +0,0 @@
|
|||||||
#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;
|
||||||
|
|
||||||
namespace Utilities {
|
class 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>
|
||||||
DayOfWeek GetDayOfWeek(struct tm* tm);
|
static 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>
|
||||||
struct tm DateTimeToStructTm(const char* dateTimeStr);
|
static 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>
|
||||||
struct tm DateToStructTm(const char* dateStr);
|
static 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>
|
||||||
struct tm TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday);
|
static 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>
|
||||||
time_t GetCurrentLocalTime();
|
static time_t GetCurrentLocalTime();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Zeller's algorithm for determining day of week
|
/// Zeller's algorithm for determining day of week
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int ZellersAlgorithm(int day, int month, int year);
|
static 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,23 +56,18 @@ namespace Utilities {
|
|||||||
/// <param name="tariff_cfg"></param>
|
/// <param name="tariff_cfg"></param>
|
||||||
/// <param name="currentDateTime"></param>
|
/// <param name="currentDateTime"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
static bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check permissions
|
/// Check permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
|
static 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>
|
||||||
double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
static double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
||||||
|
|
||||||
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
|
};
|
||||||
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
|
|
||||||
}
|
|
||||||
|
@ -25,8 +25,7 @@ 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 \
|
||||||
@ -67,8 +66,7 @@ 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,7 +395,8 @@ 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)
|
||||||
@ -404,91 +405,58 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
return GetCostFromDuration(cfg, start_datetime, end_datetime);
|
return GetCostFromDuration(cfg, start_datetime, end_datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
return private_GetCostFromDuration(cfg, start_datetime,
|
//Get min and max time defined in JSON
|
||||||
end_datetime, durationMinutes,
|
static int const minMin = std::max((int)cfg->PaymentOption.find(payment_option)->second.pop_min_time, 0);
|
||||||
nextDay, prepaid);
|
static int const maxMin = std::max((int)cfg->PaymentOption.find(payment_option)->second.pop_max_time, 0);
|
||||||
}
|
|
||||||
|
|
||||||
int Calculator::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
|
static const bool checkMinMaxMinutes = [](int minMin, int maxMin){ return (minMin < maxMin) ? true : false; }(minMin, maxMin);
|
||||||
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(
|
qCritical() << QString("ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID").arg(minMin).arg(maxMin);
|
||||||
"ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID")
|
return 0.0;
|
||||||
.arg(minParkingTimeMinutes).arg(maxParkingTimeMinutes);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkDurationMinutes(overtime, minParkingTimeMinutes,
|
|
||||||
maxParkingTimeMinutes, durationMinutes)) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get input date
|
// Get input date
|
||||||
QDateTime inputDate = start;
|
QDateTime inputDate = start_datetime;
|
||||||
|
|
||||||
// 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());
|
||||||
|
|
||||||
uint32_t day_price = 0;
|
// Check overtime
|
||||||
uint32_t price_per_unit = 0;
|
if (!overtime) {
|
||||||
|
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, inputDate, ¤t_special_day_id, &day_price)) {
|
if(Utilities::CheckSpecialDay(cfg,
|
||||||
// Set special day price:
|
inputDate.toString(Qt::ISODate).toStdString().c_str(),
|
||||||
// ACHTUNG: price_per_unit ist eigentlich immer preis pro minute !!!
|
¤t_special_day_id,
|
||||||
price_per_unit = CalculatePricePerUnit(day_price);
|
&day_price)) {
|
||||||
worktime[index].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id),
|
// Set special day price
|
||||||
SpecialDaysWorkTimeUntil(cfg, current_special_day_id));
|
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
||||||
|
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(paymentMethodId)->second.pop_id;
|
int pop_id = cfg->PaymentOption.find(payment_option)->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;
|
||||||
@ -500,7 +468,7 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* 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 private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
|
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
|
for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
|
||||||
@ -522,9 +490,9 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* 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);
|
||||||
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
|
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid);
|
||||||
if (partialCost == 0) {
|
if (partialCost <= __DBL_MIN__) {
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
continue;
|
continue;
|
||||||
@ -549,9 +517,9 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* 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);
|
||||||
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
|
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, true, prepaid);
|
||||||
if (partialCost == 0) {
|
if (partialCost < __DBL_MIN__) {
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
continue;
|
continue;
|
||||||
@ -577,7 +545,7 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* 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(paymentMethodId)->second.pop_carry_over < 1) {
|
if (cfg->PaymentOption.find(payment_option)->second.pop_carry_over < 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,9 +553,9 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
|
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
overtime = true;
|
overtime = true;
|
||||||
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
|
double const partialCost = GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMinutes, false, false);
|
||||||
if (partialCost == 0) {
|
if (partialCost < __DBL_MIN__) {
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += partialCost;
|
||||||
break; // stop while, and continue in outer loop
|
break; // stop while, and continue in outer loop
|
||||||
@ -602,7 +570,7 @@ uint32_t Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
|
|
||||||
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate);
|
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate);
|
||||||
|
|
||||||
end = inputDate;
|
end_datetime = inputDate;
|
||||||
|
|
||||||
//double ret_val = total_cost;
|
//double ret_val = total_cost;
|
||||||
//total_cost = 0.0f;
|
//total_cost = 0.0f;
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
#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,8 +1,6 @@
|
|||||||
#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>
|
||||||
@ -273,47 +271,3 @@ 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