Compare commits

..

No commits in common. "7a5d797ae01f54d30e2db24b84bd516ad3664abb" and "b84970fd1267f7ae606a8d86d6f854bd919a9d56" have entirely different histories.

7 changed files with 537 additions and 727 deletions

View File

@ -1,14 +1,7 @@
#ifndef CALCULATOR_FUNCTIONS_H_INCLUDED #pragma once
#define CALCULATOR_FUNCTIONS_H_INCLUDED
#include <iostream> #include <iostream>
#include <optional>
#include "configuration.h" #include "configuration.h"
#include "payment_method.h" #include "payment_method.h"
#include "ticket.h"
#include "tariff_time_range.h"
#include <QDateTime> #include <QDateTime>
using namespace std; using namespace std;
@ -56,13 +49,13 @@ private:
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId); int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId); int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
Ticket private_GetCostFromDuration(Configuration const* cfg, uint32_t private_GetCostFromDuration(Configuration const* cfg,
QDateTime const &start, QDateTime const &start,
QDateTime &end, QDateTime &end,
int &durationMinutes, int durationMinutes,
bool nextDay = false, bool nextDay = false,
bool prepaid = false, bool prepaid = false,
bool overtime = false); bool overtime = false);
bool checkDurationMinutes(bool overTime, bool checkDurationMinutes(bool overTime,
int minParkingTime, int maxParkingTime, int minParkingTime, int maxParkingTime,
@ -71,13 +64,4 @@ private:
// //
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const; uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
uint32_t GetDurationForPrice(Configuration *cfg, int price) const; uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
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

View File

@ -21,10 +21,7 @@ public:
using Status = std::tuple<int, char const*, char const*>; using Status = std::tuple<int, char const*, char const*>;
explicit Ticket(); explicit Ticket();
explicit Ticket(QDateTime const &s, QDateTime const &e,
int durationMinutesNetto, int durationMinutesBrutto,
uint32_t price, Status status);
explicit operator bool() { return std::get<CODE>(m_status) == VALID; } explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
operator QString(); operator QString();
@ -38,15 +35,6 @@ public:
void setValidUntil(QDateTime const &validUnil); void setValidUntil(QDateTime const &validUnil);
void setPrice(uint32_t price); void setPrice(uint32_t price);
bool isValid() { return operator bool(); }
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" }
};
private: private:
Status m_status; Status m_status;
@ -57,8 +45,20 @@ private:
int m_durationMinutesBrutto; int m_durationMinutesBrutto;
uint32_t m_price; 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); 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 #endif // TICKET_H_INCLUDED

View File

@ -1,85 +1,78 @@
#pragma once #pragma once
#include <cstring> #include <cstring>
#include <string.h> #include <string.h>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include "day_of_week.h" #include "day_of_week.h"
#include "configuration.h" #include "configuration.h"
#include "time_range.h" #include "time_range.h"
#include "payment_method.h"
#include <QDateTime>
#include <QDateTime>
using namespace std;
using namespace std;
namespace Utilities {
namespace Utilities { /// <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);
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);
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);
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);
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();
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);
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 /// </summary>
/// </summary> /// <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);
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
bool IsYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime); /// <summary>
/// Check permissions
/// <summary> /// </summary>
/// Check permissions bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice);
/// </summary> bool CheckSpecialDay(Configuration const *cfg,
bool CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice); QDateTime const &currentDateTimeS,
bool CheckSpecialDay(Configuration const *cfg, int* specialDayId, uint32_t *specialDayPrice);
QDateTime const &currentDateTimeS,
int* specialDayId, uint32_t *specialDayPrice); /// <summary>
/// Calculates price per unit
/// <summary> /// </summary>
/// Calculates price per unit /// <param name="pra_price"></param>
/// </summary> /// <returns></returns>
/// <param name="pra_price"></param> double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
/// <returns></returns>
double CalculatePricePerUnit(double pra_price, double durationUnit = -1); QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId); }
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
QTime WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
PaymentMethod getPaymentMethodId(Configuration const *cfg);
}

View File

@ -3,7 +3,6 @@
#include "utilities.h" #include "utilities.h"
#include "tariff_log.h" #include "tariff_log.h"
#include "tariff_time_range.h" #include "tariff_time_range.h"
#include "ticket.h"
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
@ -405,18 +404,9 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
return GetCostFromDuration(cfg, start_datetime, end_datetime); return GetCostFromDuration(cfg, start_datetime, end_datetime);
} }
QDateTime start = start_datetime; return private_GetCostFromDuration(cfg, start_datetime,
end_datetime, durationMinutes,
Ticket t = private_GetCostFromDuration(cfg, start, nextDay, prepaid);
end_datetime, durationMinutes,
nextDay, prepaid);
if (t) {
qCritical().noquote() << t;
return t.getPrice();
}
return -1;
} }
int Calculator::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) { int Calculator::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
@ -444,95 +434,66 @@ bool Calculator::checkDurationMinutes(bool overtime,
return true; return true;
} }
int Calculator::findWorkTimeRange(QDateTime const &dt,
QScopedArrayPointer<TariffTimeRange> const &worktime,
size_t size) {
for (size_t w = 0; w < size; ++w) {
QTime const &worktime_from = worktime[w].getTimeFrom();
QTime const &worktime_to = worktime[w].getTimeUntil();
if ((dt.time() >= worktime_from) && (dt.time() < worktime_to)) {
return w;
}
}
return -1;
}
int Calculator::findNextWorkTimeRange(QDateTime const &dt,
QScopedArrayPointer<TariffTimeRange> const &worktime,
size_t size) {
int nextWorkTimeRange = -1;
for (size_t w = 0; w < size; ++w) {
QTime const &worktime_from = worktime[w].getTimeFrom();
if (dt.time() < worktime_from) {
nextWorkTimeRange = w;
continue;
}
}
return nextWorkTimeRange;
}
using namespace Utilities; using namespace Utilities;
Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg, uint32_t Calculator::private_GetCostFromDuration(Configuration const* cfg,
QDateTime const &start, QDateTime const &start,
QDateTime &end, QDateTime &end,
int &durationMinutes, int durationMinutes,
bool nextDay, bool nextDay,
bool prepaid, bool prepaid,
bool overtime) { bool overtime) {
// TODO
static const PaymentMethod paymentMethodId = PaymentMethod::Linear;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId);
static int const minParkingTimeMinutes = getMinimalParkingTime(cfg, paymentMethodId); static int const minParkingTimeMinutes = getMinimalParkingTime(cfg, paymentMethodId);
static int const maxParkingTimeMinutes = getMaximalParkingTime(cfg, paymentMethodId); static int const maxParkingTimeMinutes = getMaximalParkingTime(cfg, paymentMethodId);
static bool const checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes); static bool const checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
static const int durationMinutesNetto = durationMinutes;
if (!checkMinMaxMinutes) { if (!checkMinMaxMinutes) {
qCritical() << QString( qCritical() << QString(
"ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID") "ERROR: CONDITION minMin < maxMin (%1 < %2) IS NOT VALID")
.arg(minParkingTimeMinutes).arg(maxParkingTimeMinutes); .arg(minParkingTimeMinutes).arg(maxParkingTimeMinutes);
return Ticket(); return 0;
} }
if (!checkDurationMinutes(overtime, minParkingTimeMinutes, if (!checkDurationMinutes(overtime, minParkingTimeMinutes,
maxParkingTimeMinutes, durationMinutes)) { maxParkingTimeMinutes, durationMinutes)) {
return Ticket(); return 0;
} }
// Get input date
QDateTime inputDate = start; QDateTime inputDate = start;
// Get day of week
int const weekdayId = inputDate.date().dayOfWeek(); int const weekdayId = inputDate.date().dayOfWeek();
uint32_t price = 0;
double durationUnit = 60.0; uint32_t day_price = 0;
uint32_t price_per_unit = 0;
int current_special_day_id = -1; int current_special_day_id = -1;
// there might be more than 1 worktime ranges per day
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 ranges = 0; int index = 0;
if(Utilities::CheckSpecialDay(cfg, inputDate, &current_special_day_id, &price)) { if(Utilities::CheckSpecialDay(cfg, inputDate, &current_special_day_id, &day_price)) {
// Set special day price: // Set special day price:
durationUnit = 60.0; // ACHTUNG: price_per_unit ist eigentlich immer preis pro minute !!!
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id), price_per_unit = CalculatePricePerUnit(day_price);
SpecialDaysWorkTimeUntil(cfg, current_special_day_id)); worktime[index].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id),
ranges = 1; SpecialDaysWorkTimeUntil(cfg, current_special_day_id));
} else { } else {
// Set new price for the normal day: do not use a floating-point type // Set new price for the normal day
// for the price, rather compute with integers. Only at the very end of
// the computation the price is divided by durationUnit.
int pop_id = cfg->PaymentOption.find(paymentMethodId)->second.pop_id; int pop_id = cfg->PaymentOption.find(paymentMethodId)->second.pop_id;
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;
durationUnit = cfg->Duration.find(durationId)->second.pun_duration; double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
// If no working day found, skip it (recursively call method again) // If no working day found, skip it (recursively call method again)
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) { if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
@ -542,162 +503,114 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
return private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime); return private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
} }
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator; for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId); qCritical() << itr->first << itr->second.pwd_time_from.c_str() << itr->second.pwd_time_to.c_str();
worktime[index].setTimeRange(QTime::fromString(itr->second.pwd_time_from.c_str()),
for (WTIterator itr = p.first; itr != p.second; ++itr) { QTime::fromString(itr->second.pwd_time_to.c_str()));
worktime[ranges].setTimeRange(WeekDaysWorkTimeFrom(itr), index += 1;
WeekDaysWorkTimeUntil(itr));
ranges += 1;
} }
} }
uint32_t costFromDuration = 0; if (price_per_unit < 0) price_per_unit = 1.0f;
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); qDebug() << "Calculated price per minute=" << price_per_unit;
int currentRange = -1;
if (nextDay) { // this means the function has been called recursively double costFromDuration = 0.0;
currentRange = 0; for (int w = 0; w < index; ++w) {
inputDate.setTime(worktime[currentRange].getTimeFrom()); QTime worktime_from = worktime[w].getTimeFrom();
} else { QTime worktime_to = worktime[w].getTimeUntil();
// check if inputDate is located inside a valid worktime-range...
currentRange = findWorkTimeRange(inputDate, worktime, ranges); if (price_per_unit == 0) {
if (currentRange == -1) { // no... inputDate = inputDate.addDays(1);
if (!prepaid) { // parking is not allowed inputDate.setTime(worktime_from);
return Ticket(start, end, durationMinutesNetto, 0, uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
0, Ticket::s[INVALID_FROM_DATETIME]); if (partialCost == 0) {
return 0;
} }
// find the next worktime-range (on the same day), and start from there costFromDuration += partialCost;
currentRange = findNextWorkTimeRange(inputDate, worktime, ranges); continue;
inputDate.setTime(worktime[currentRange].getTimeFrom());
} }
}
for (int w = currentRange; w < ranges; ++w) { // If overtime flag is set
if (durationMinutes > 0) { if (overtime || nextDay) {
QTime const &worktime_from = worktime[w].getTimeFrom(); inputDate.setTime(worktime_from);
QTime const &worktime_to = worktime[w].getTimeUntil(); overtime = false;
}
qCritical() << "from" << worktime_from; // Check prepaid
qCritical() << "until" << worktime_to; if (!prepaid) {
if ((inputDate.time() < worktime_from) || (inputDate.time() > worktime_to)) {
//if (w > 0) { // durationMinutes are always meant as netto time and qDebug() << "[STOP] * Ticket is not valid * ";
// // the time between worktime-ranges are free. return 0.0f;
// inputDate.setTime(worktime_from); }
//} } else {
qDebug() << "* PREPAID MODE ACTIVE *";
// TODO: hier muss dann der preis hin if (inputDate.time() < worktime_from) {
if (price == 0) {
inputDate = inputDate.addDays(1);
inputDate.setTime(worktime_from); inputDate.setTime(worktime_from);
Ticket t = private_GetCostFromDuration( } else if(inputDate.time() > worktime_to) {
cfg, // TODO: erklaerung qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
inputDate, inputDate = inputDate.addDays(1);
end, durationMinutes, uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
true, prepaid); if (partialCost == 0) {
if (!t.isValid()) { return 0;
return t;
} }
costFromDuration += t.getPrice(); costFromDuration += partialCost;
continue; continue;
} }
}
// If overtime flag is set while(durationMinutes > 0) {
// TODO: ueberpruefen, kann man wohl nach oben ziehen // Check for active year period
//if (overtime || nextDay) { if (std::none_of(cfg->YearPeriod.begin(),
// inputDate.setTime(worktime_from); cfg->YearPeriod.end(),
// overtime = false; [&inputDate](std::pair<int, ATBPeriodYear> const &year) {
//} QDate const input(2004, // 2004 is a leap year
inputDate.date().month(),
qCritical() << "inputDate.time()=" << inputDate.time(); inputDate.date().day());
QDate const s(2004, year.second.pye_start_day, year.second.pye_start_month);
// Check prepaid QDate const e(2004, year.second.pye_end_day, year.second.pye_end_month);
if (!prepaid) { return (input >= s && input <= e);
if ((inputDate.time() < worktime_from) || (inputDate.time() > worktime_to)) { })) {
qDebug() << "[STOP] * Ticket is not valid * "; qCritical() << "NO VALID YEAR PERIOD";
return Ticket(); return 0.0;
}
} else {
qDebug() << "* PREPAID MODE ACTIVE *";
if (inputDate.time() < worktime_from) {
inputDate.setTime(worktime_from);
//} else if(inputDate.time() > worktime_to) {
} else if(inputDate.time() > lastWorktimeTo) {
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
// wieso ist hier overtime nicht gesetzt
inputDate = inputDate.addDays(1);
Ticket t = private_GetCostFromDuration(
cfg, inputDate, end,
durationMinutes, true, prepaid);
if (!t.isValid()) {
return t;
}
costFromDuration += t.getPrice();
continue;
}
} }
while(durationMinutes > 0) { // Go to next day if minutes not spent
// Check for active year period if(inputDate.time() >= worktime_to) {
if (!IsYearPeriodActive(cfg, inputDate)) { // check for carry_over status
return Ticket(); if (cfg->PaymentOption.find(paymentMethodId)->second.pop_carry_over < 1) {
break;
} }
qDebug() << "inputDate" << inputDate.toString(Qt::ISODate); qDebug() << "Reached end of worktime, searching for the next working day";
if(inputDate.time() >= lastWorktimeTo) { inputDate = inputDate.addDays(1);
// Go to next day if minutes not spent overtime = true;
if (carryOverNotSet) { uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
// no carry_over, so stop computation if (partialCost == 0) {
break; return 0;
}
qDebug() << "Reached end of worktime, searching for the next working day";
inputDate = inputDate.addDays(1);
inputDate.setTime(QTime());
overtime = true;
Ticket t = private_GetCostFromDuration(
cfg, inputDate, end,
durationMinutes, true, prepaid, overtime);
if (!t.isValid()) {
return t;
}
costFromDuration += t.getPrice();
break; // stop while, and continue in outer loop
} else {
if(inputDate.time() < worktime_to) {
// Increment input date minutes for each monetary unit
inputDate = inputDate.addSecs(60);
qDebug() << "inputDate" << inputDate.toString(Qt::ISODate);
durationMinutes -= 1;
//costFromDuration += price_per_unit;
costFromDuration += price;
} else break;
} }
costFromDuration += partialCost;
break; // stop while, and continue in outer loop
} else {
// Increment input date minutes for each monetary unit
inputDate = inputDate.addSecs(60);
durationMinutes -= 1;
costFromDuration += price_per_unit;
} }
} }
} }
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate);
if (inputDate >= end) { end = inputDate;
end = inputDate;
}
if (nextDay == false) { //double ret_val = total_cost;
qDebug() << "GetCostFromDuration(): Valid until:" << end.toString(Qt::ISODate); //total_cost = 0.0f;
} //return ceil(ret_val);
return // TODO: runden nur falls oberster stack-rahmen
Ticket(start, end,
durationMinutesNetto, return ceil(costFromDuration);
start.secsTo(end) / 60,
nextDay ?
costFromDuration :
llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
Ticket::s[VALID]);
} }

View File

@ -11,19 +11,7 @@ Ticket::Ticket()
qDebug() << *this; qDebug() << *this;
qDebug() << m_status; qDebug() << m_status;
} }
Ticket::Ticket(QDateTime const &s, QDateTime const &e,
int durationMinutesNetto, int durationMinutesBrutto,
uint32_t price, Ticket::Status status)
: m_status(status)
, m_validFrom(s)
, m_validUntil(e)
, m_durationMinutesNetto(durationMinutesNetto)
, m_durationMinutesBrutto(durationMinutesBrutto)
, m_price(price) {
}
Ticket::Status Ticket::setStatus(Status status) { Ticket::Status Ticket::setStatus(Status status) {
Status old = m_status; Status old = m_status;
m_status = status; m_status = status;
@ -66,23 +54,14 @@ void Ticket::setPrice(uint32_t price) {
Ticket::operator QString() { Ticket::operator QString() {
QStringList status; QStringList status;
status << QString("**********************"); status << QString("Status .............. : %1 (%2)")
status << QString("Status ............. : %1 (%2)")
.arg(std::get<0>(m_status)) .arg(std::get<0>(m_status))
.arg(std::get<2>(m_status)); .arg(std::get<2>(m_status));
status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate)); status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate));
status << QString("Valid until ........ : %1").arg(m_validUntil.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 (netto) ... : %1").arg(m_durationMinutesNetto);
status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto); status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto);
status << QString("Price .............. : %1").arg(m_price); status << QString("Price ......... : %1").arg(m_price);
status << QString("**********************");
return status.join('\n'); return status.join('\n');;
}
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
QDebugStateSaver saver(debug);
debug << "Ticket-Status: " << std::get<1>(status)
<< "(" << std::get<2>(status) << ")";
return debug;
} }

View File

@ -1,375 +1,319 @@
#include "utilities.h" #include "utilities.h"
#include "tariff_log.h" #include "tariff_log.h"
#include <QDebug> #include <QDebug>
#include <algorithm>
static int protection_counter = 0;
static int protection_counter = 0;
/// <summary>
/// <summary> /// Helper function
/// Helper function /// </summary>
/// </summary> /// <param name="pra_price"></param>
/// <param name="pra_price"></param> /// <returns></returns>
/// <returns></returns> double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit)
double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit) {
{ try
try {
{ double price_per_unit = pra_price;
double price_per_unit = pra_price; double unit = durationUnit;
double unit = durationUnit;
if(unit < 0 || unit > 65535 ) unit = 60.0f;
if(unit < 0 || unit > 65535 ) unit = 60.0f; price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes
price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes //printf("Price per unit (min) is: %lf\n", price_per_unit);
//printf("Price per unit (min) is: %lf\n", price_per_unit); return price_per_unit;
return price_per_unit; }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in CalculatePricePerUnit() function\n");
throw std::invalid_argument("An error has occurred in CalculatePricePerUnit() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> time_t Utilities::GetCurrentLocalTime()
time_t Utilities::GetCurrentLocalTime() {
{ try
try {
{ time_t curr_time = time(NULL);
time_t curr_time = time(NULL); tm tm_curr_time = {};
tm tm_curr_time = {}; memset(&tm_curr_time, '\0', sizeof(struct tm));
memset(&tm_curr_time, '\0', sizeof(struct tm));
tm_curr_time = *localtime(&curr_time);
tm_curr_time = *localtime(&curr_time); curr_time = mktime(&tm_curr_time); //- timezone;
curr_time = mktime(&tm_curr_time); //- timezone; return curr_time;
return curr_time; }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in GetCurrentLocalTime() function\n");
throw std::invalid_argument("An error has occurred in GetCurrentLocalTime() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> int Utilities::ZellersAlgorithm(int day, int month, int year)
int Utilities::ZellersAlgorithm(int day, int month, int year) {
{ int mon;
int mon; if (month > 2) mon = month; //for march to december month code is same as month
if (month > 2) mon = month; //for march to december month code is same as month else {
else { mon = (12 + month); //for Jan and Feb, month code will be 13 and 14
mon = (12 + month); //for Jan and Feb, month code will be 13 and 14 year--; //decrease year for month Jan and Feb
year--; //decrease year for month Jan and Feb }
} int y = year % 100; //last two digit
int y = year % 100; //last two digit int c = year / 100; //first two digit
int c = year / 100; //first two digit int w = (day + floor((13 * (mon + 1)) / 5) + y + floor(y / 4) + floor(c / 4) + (5 * c));
int w = (day + floor((13 * (mon + 1)) / 5) + y + floor(y / 4) + floor(c / 4) + (5 * c)); w = ((w + 5) % 7) + 1; //w % 7;
w = ((w + 5) % 7) + 1; //w % 7; return w;
return w; }
}
/// <inheritdoc/>
/// <inheritdoc/> struct tm Utilities::DateToStructTm(const char* dateStr)
struct tm Utilities::DateToStructTm(const char* dateStr) {
{ struct tm t = {};
struct tm t = {}; memset(&t, '\0', sizeof(struct tm));
memset(&t, '\0', sizeof(struct tm));
if (dateStr == nullptr || strlen(dateStr) <= 0) throw std::invalid_argument("DateToStructTm has failed parsing date string (null or empty)\n");
if (dateStr == nullptr || strlen(dateStr) <= 0) throw std::invalid_argument("DateToStructTm has failed parsing date string (null or empty)\n"); try
try {
{ int success = sscanf(dateStr, "%d-%d-%d", &t.tm_year, &t.tm_mon, &t.tm_mday);
int success = sscanf(dateStr, "%d-%d-%d", &t.tm_year, &t.tm_mon, &t.tm_mday); if (success != 3) throw std::invalid_argument("DateToStructTm() has failed parsing datetime string\n");
if (success != 3) throw std::invalid_argument("DateToStructTm() has failed parsing datetime string\n");
t.tm_year = t.tm_year - 1900;
t.tm_year = t.tm_year - 1900; t.tm_mon = t.tm_mon - 1;
t.tm_mon = t.tm_mon - 1; t.tm_isdst = 0;
t.tm_isdst = 0; return t;
return t; }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in DateToStructTm() function\n");
throw std::invalid_argument("An error has occurred in DateToStructTm() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> struct tm Utilities::TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday)
struct tm Utilities::TimeToStructTm(const char* timeStr, int year, int mon, int mday, int wday) {
{ struct tm t = {};
struct tm t = {}; memset(&t, '\0', sizeof(struct tm));
memset(&t, '\0', sizeof(struct tm));
if (timeStr == nullptr || strlen(timeStr) <= 0) throw std::invalid_argument("TimeToStructTm() has failed parsing time string (null or empty)\n");
if (timeStr == nullptr || strlen(timeStr) <= 0) throw std::invalid_argument("TimeToStructTm() has failed parsing time string (null or empty)\n"); try
try {
{ int success_time = sscanf(timeStr, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec);
int success_time = sscanf(timeStr, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec); if (success_time != 3) throw std::invalid_argument("TimeToStructTm() has failed parsing time string\n");
if (success_time != 3) throw std::invalid_argument("TimeToStructTm() has failed parsing time string\n");
struct tm tm_struct;
struct tm tm_struct; t.tm_year = year;
t.tm_year = year; t.tm_mon = mon;
t.tm_mon = mon; t.tm_mday = mday;
t.tm_mday = mday; t.tm_wday = wday;
t.tm_wday = wday; t.tm_isdst = 0;
t.tm_isdst = 0; return t;
return t; }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in TimeToStructTm() function\n");
throw std::invalid_argument("An error has occurred in TimeToStructTm() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> struct tm Utilities::DateTimeToStructTm(const char* dateTimeStr)
struct tm Utilities::DateTimeToStructTm(const char* dateTimeStr) {
{ struct tm t = {};
struct tm t = {}; memset(&t, '\0', sizeof(struct tm));
memset(&t, '\0', sizeof(struct tm));
if (dateTimeStr == nullptr || strlen(dateTimeStr) <= 0) throw std::invalid_argument("DateTimeToStructTm() has failed parsing date string (null or empty)");
if (dateTimeStr == nullptr || strlen(dateTimeStr) <= 0) throw std::invalid_argument("DateTimeToStructTm() has failed parsing date string (null or empty)"); try
try {
{ int success = sscanf(dateTimeStr, "%d-%d-%dT%d:%d:%dZ", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
int success = sscanf(dateTimeStr, "%d-%d-%dT%d:%d:%dZ", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec); if (success != 6) throw std::invalid_argument("DateTimeToStructTm() has failed parsing datetime string\n");
if (success != 6) throw std::invalid_argument("DateTimeToStructTm() has failed parsing datetime string\n");
t.tm_year = t.tm_year - 1900;
t.tm_year = t.tm_year - 1900; t.tm_mon = t.tm_mon - 1;
t.tm_mon = t.tm_mon - 1; t.tm_isdst = 0;
t.tm_isdst = 0; return t;
return t; }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in DateTimeToStructTm() function\n");
throw std::invalid_argument("An error has occurred in DateTimeToStructTm() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> DayOfWeek Utilities::GetDayOfWeek(struct tm* t)
DayOfWeek Utilities::GetDayOfWeek(struct tm* t) {
{ if (t == nullptr) throw std::invalid_argument("GetDayOfWeekFromDate() => parameter 't' is null\n");
if (t == nullptr) throw std::invalid_argument("GetDayOfWeekFromDate() => parameter 't' is null\n"); try
try {
{ int d = t->tm_mday;
int d = t->tm_mday; int m = t->tm_mon + 1;
int m = t->tm_mon + 1; int y = t->tm_year + 1900;
int y = t->tm_year + 1900;
int wd = Utilities::ZellersAlgorithm(d, m, y);
int wd = Utilities::ZellersAlgorithm(d, m, y); return static_cast<DayOfWeek>(wd);
return static_cast<DayOfWeek>(wd); }
} catch (...)
catch (...) {
{ throw std::invalid_argument("An error has occurred in GetDayOfWeekFromDate() function\n");
throw std::invalid_argument("An error has occurred in GetDayOfWeekFromDate() function\n"); }
} }
}
/// <inheritdoc/>
/// <inheritdoc/> bool Utilities::IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime_tm)
bool Utilities::IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime_tm) {
{ if (cfg == nullptr) throw std::invalid_argument("IsYearPeriodActive() = > Configuration not set\n");
if (cfg == nullptr) throw std::invalid_argument("IsYearPeriodActive() = > Configuration not set\n"); if (currentDateTime_tm == nullptr) throw std::invalid_argument("IsYearPeriodActive() = > Current datetime not set\n");
if (currentDateTime_tm == nullptr) throw std::invalid_argument("IsYearPeriodActive() = > Current datetime not set\n");
try
try {
{ //// Parse input date
//// Parse input date int dayCurrent = currentDateTime_tm->tm_mday;
int dayCurrent = currentDateTime_tm->tm_mday; int monthCurrent = currentDateTime_tm->tm_mon + 1;
int monthCurrent = currentDateTime_tm->tm_mon + 1;
// Current date time
// Current date time int cdt = (monthCurrent * 100) + dayCurrent;
int cdt = (monthCurrent * 100) + dayCurrent;
multimap<int, ATBPeriodYear>::iterator year_period_itr;
multimap<int, ATBPeriodYear>::iterator year_period_itr; for (year_period_itr = cfg->YearPeriod.begin(); year_period_itr != cfg->YearPeriod.end(); ++year_period_itr)
for (year_period_itr = cfg->YearPeriod.begin(); year_period_itr != cfg->YearPeriod.end(); ++year_period_itr) {
{ int dStart = year_period_itr->second.pye_start_day;
int dStart = year_period_itr->second.pye_start_day; int dEnd = year_period_itr->second.pye_end_day;
int dEnd = year_period_itr->second.pye_end_day;
int mStart = year_period_itr->second.pye_start_month;
int mStart = year_period_itr->second.pye_start_month; int mEnd = year_period_itr->second.pye_end_month;
int mEnd = year_period_itr->second.pye_end_month;
int start = (mStart * 100) + dStart;
int start = (mStart * 100) + dStart; int end = (mEnd * 100) + dEnd;
int end = (mEnd * 100) + dEnd;
if (cdt >= start && cdt <= end)
if (cdt >= start && cdt <= end) {
{ return true;
return true; }
} }
} return false;
return false; }
} catch (...)
catch (...) {
{ cout << "IsYearPeriodActive() => An exception has occurred, ignoring check, returning true" << endl;
cout << "IsYearPeriodActive() => An exception has occurred, ignoring check, returning true" << endl; return true;
return true; }
} }
}
/// <inheritdoc/>
bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt) { bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
if (std::none_of(cfg->YearPeriod.cbegin(), {
cfg->YearPeriod.cend(), try
[&dt](std::pair<int, ATBPeriodYear> const &year) { {
QDate const d(2004, // 2004 is a leap year *specialDayId = -1;
dt.date().month(), *specialDayPrice = 0.0f;
dt.date().day());
QDate const s(2004, year.second.pye_start_month, year.second.pye_start_day); if (cfg == nullptr) throw std::invalid_argument("CheckSpecialDay() => configuration is not set\n");
QDate const e(2004, year.second.pye_end_month, year.second.pye_end_day); if (currentDateTimeStr == nullptr) throw std::invalid_argument("CheckSpecialDay() => invalid date/time string set\n");
return (d >= s && d <= e);
})) {
qCritical() << "NO VALID YEAR PERIOD"; struct tm current_tm = Utilities::DateTimeToStructTm(currentDateTimeStr);
return false; //cout << "CheckSpecialDay() => Current: " << asctime(&current_tm) << endl;
}
return true; multimap<int, ATBSpecialDays>::iterator spec_days_itr;
}
for (spec_days_itr = cfg->SpecialDays.begin(); spec_days_itr != cfg->SpecialDays.end(); spec_days_itr++)
/// <inheritdoc/> {
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice) int repeat_every_year = 0;
{ repeat_every_year = spec_days_itr->second.ped_year;
try
{ string start = spec_days_itr->second.ped_date_start;
*specialDayId = -1; if (start.length() <= 0) continue;
*specialDayPrice = 0.0f; //cout << "CheckSpecialDay() => Start: " << start << endl;
if (cfg == nullptr) throw std::invalid_argument("CheckSpecialDay() => configuration is not set\n"); string end = spec_days_itr->second.ped_date_end;
if (currentDateTimeStr == nullptr) throw std::invalid_argument("CheckSpecialDay() => invalid date/time string set\n"); if (end.length() <= 0) continue;
//cout << "CheckSpecialDay() => End: " << end << endl;
struct tm current_tm = Utilities::DateTimeToStructTm(currentDateTimeStr); struct tm start_tm = Utilities::DateToStructTm(start.c_str());
//cout << "CheckSpecialDay() => Current: " << asctime(&current_tm) << endl; //cout << "CheckSpecialDay() => Start: " << asctime(&start_tm) << endl;
multimap<int, ATBSpecialDays>::iterator spec_days_itr; struct tm end_tm = Utilities::DateToStructTm(end.c_str());
//cout << "CheckSpecialDay() => End: " << asctime(&end_tm) << endl;
for (spec_days_itr = cfg->SpecialDays.begin(); spec_days_itr != cfg->SpecialDays.end(); spec_days_itr++)
{ if (repeat_every_year <= 0)
int repeat_every_year = 0; {
repeat_every_year = spec_days_itr->second.ped_year; //cout << "CheckSpecialDay() => Repeat every year is: 0" << endl;
if ((current_tm.tm_year == start_tm.tm_year) && (current_tm.tm_year == end_tm.tm_year))
string start = spec_days_itr->second.ped_date_start; {
if (start.length() <= 0) continue; if ((current_tm.tm_mon >= start_tm.tm_mon) && (current_tm.tm_mon <= end_tm.tm_mon))
//cout << "CheckSpecialDay() => Start: " << start << endl; {
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
string end = spec_days_itr->second.ped_date_end; if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
if (end.length() <= 0) continue; {
//cout << "CheckSpecialDay() => End: " << end << endl; LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
*specialDayId = spec_days_itr->second.ped_id;
struct tm start_tm = Utilities::DateToStructTm(start.c_str()); *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
//cout << "CheckSpecialDay() => Start: " << asctime(&start_tm) << endl; return true;
}
struct tm end_tm = Utilities::DateToStructTm(end.c_str()); }
//cout << "CheckSpecialDay() => End: " << asctime(&end_tm) << endl; }
}
if (repeat_every_year <= 0) else
{ {
//cout << "CheckSpecialDay() => Repeat every year is: 0" << endl; if ((current_tm.tm_mon >= start_tm.tm_mon) && (current_tm.tm_mon <= end_tm.tm_mon))
if ((current_tm.tm_year == start_tm.tm_year) && (current_tm.tm_year == end_tm.tm_year)) {
{ //cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
if ((current_tm.tm_mon >= start_tm.tm_mon) && (current_tm.tm_mon <= end_tm.tm_mon)) if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
{ {
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday)) *specialDayId = spec_days_itr->second.ped_id;
{ *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY"); return true;
*specialDayId = spec_days_itr->second.ped_id; }
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; }
return true; }
} }
} //cout << "CheckSpecialDay() => NOT SPECIAL DAY" << endl;
} return false;
} }
else catch (...)
{ {
if ((current_tm.tm_mon >= start_tm.tm_mon) && (current_tm.tm_mon <= end_tm.tm_mon)) throw std::invalid_argument("CheckSpecialDay() => An error has occurred\n");
{ return false;
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; }
if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday)) }
{
LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY"); bool Utilities::CheckSpecialDay(Configuration const *cfg,
*specialDayId = spec_days_itr->second.ped_id; QDateTime const &currentDateTime,
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; int* specialDayId,
return true; uint32_t *specialDayPrice) {
} *specialDayId = -1;
} *specialDayPrice = 0;
}
} std::multimap<int, ATBSpecialDays>::const_iterator spec_days_itr;
//cout << "CheckSpecialDay() => NOT SPECIAL DAY" << endl;
return false; 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;
catch (...) 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);
throw std::invalid_argument("CheckSpecialDay() => An error has occurred\n"); if (start.isValid() && end.isValid()) {
return false; if ((currentDateTime.date().month() >= start.month()) &&
} (currentDateTime.date().month() <= end.month())) {
} if ((currentDateTime.date().day() >= start.day()) &&
(currentDateTime.date().day() <= end.day())) {
bool Utilities::CheckSpecialDay(Configuration const *cfg, if (repeat_every_year <= 0) {
QDateTime const &currentDateTime, if ((currentDateTime.date().year() != start.year()) ||
int* specialDayId, (currentDateTime.date().year() != end.year())) {
uint32_t *specialDayPrice) { continue;
*specialDayId = -1; }
*specialDayPrice = 0; }
qDebug() << "CheckSpecialDay() => SPECIAL DAY";
std::multimap<int, ATBSpecialDays>::const_iterator spec_days_itr; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
for (spec_days_itr = cfg->SpecialDays.cbegin(); spec_days_itr != cfg->SpecialDays.cend(); ++spec_days_itr) { return true;
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())) { return false;
if ((currentDateTime.date().day() >= start.day()) && }
(currentDateTime.date().day() <= end.day())) {
if (repeat_every_year <= 0) { QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId) {
if ((currentDateTime.date().year() != start.year()) || return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
(currentDateTime.date().year() != end.year())) { }
continue;
} QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
} return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
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);
}
QTime Utilities::WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
return QTime::fromString(itr->second.pwd_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
return QTime::fromString(itr->second.pwd_time_to.c_str(), Qt::ISODate);
}
bool Utilities::isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId) {
return !isCarryOverNotSet(cfg, paymentMethodId);
}
bool Utilities::isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId) {
return (cfg->PaymentOption.find(paymentMethodId)->second.pop_carry_over < 1);
}
PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
if (cfg->PaymentOption.size() != 1) {
return PaymentMethod::Undefined;
}
std::multimap<int, ATBPaymentOption>::const_iterator it =
cfg->PaymentOption.cbegin();
switch (it->first) {
case PaymentMethod::Linear:
return PaymentMethod::Linear;
case PaymentMethod::Steps:
return PaymentMethod::Steps;
case PaymentMethod::Degressive:
return PaymentMethod::Degressive;
case PaymentMethod::Progressive:
return PaymentMethod::Progressive;
}
return PaymentMethod::Undefined;
}

View File

@ -50,12 +50,9 @@ int main() {
if (isParsed) if (isParsed)
{ {
QDateTime start = QDateTime::fromString("2023-11-27T17:50:00",Qt::ISODate); QDateTime start = QDateTime::fromString("2023-05-11T08:00:00",Qt::ISODate);
//QDateTime start = QDateTime::currentDateTime();
QDateTime end = start.addSecs(120); QDateTime end = start.addSecs(120);
uint32_t cost = calculator.GetCostFromDuration(&cfg, 3, start, end, 60); calculator.GetCostFromDuration(&cfg, 3, start, end, 60);
qCritical() << "cost=" << cost;
qCritical() << "end=" << end;
} }
return 0; return 0;