Compare commits
9 Commits
b84970fd12
...
7a5d797ae0
Author | SHA1 | Date | |
---|---|---|---|
7a5d797ae0 | |||
215667af61 | |||
2b6d116200 | |||
2d9ed3c1c8 | |||
9ca45e613f | |||
6a3d183129 | |||
684de4acd1 | |||
e9047f995a | |||
20cdb8b07f |
@ -1,7 +1,14 @@
|
|||||||
#pragma once
|
#ifndef CALCULATOR_FUNCTIONS_H_INCLUDED
|
||||||
|
#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;
|
||||||
|
|
||||||
@ -49,13 +56,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);
|
||||||
|
|
||||||
uint32_t private_GetCostFromDuration(Configuration const* cfg,
|
Ticket 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,
|
||||||
@ -64,4 +71,13 @@ 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
|
||||||
|
@ -21,6 +21,9 @@ 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();
|
||||||
@ -35,6 +38,15 @@ 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;
|
||||||
|
|
||||||
@ -45,20 +57,8 @@ 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
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#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>
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ namespace Utilities {
|
|||||||
/// <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 ¤tDateTime);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check permissions
|
/// Check permissions
|
||||||
@ -75,4 +77,9 @@ namespace Utilities {
|
|||||||
|
|
||||||
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
|
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
|
||||||
QTime SpecialDaysWorkTimeUntil(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);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#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>
|
||||||
@ -404,9 +405,18 @@ 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,
|
QDateTime start = start_datetime;
|
||||||
end_datetime, durationMinutes,
|
|
||||||
nextDay, prepaid);
|
Ticket t = private_GetCostFromDuration(cfg, start,
|
||||||
|
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) {
|
||||||
@ -434,66 +444,95 @@ 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;
|
||||||
|
|
||||||
uint32_t Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
Ticket 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 0;
|
return Ticket();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkDurationMinutes(overtime, minParkingTimeMinutes,
|
if (!checkDurationMinutes(overtime, minParkingTimeMinutes,
|
||||||
maxParkingTimeMinutes, durationMinutes)) {
|
maxParkingTimeMinutes, durationMinutes)) {
|
||||||
return 0;
|
return Ticket();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
uint32_t day_price = 0;
|
double durationUnit = 60.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 index = 0;
|
int ranges = 0;
|
||||||
|
|
||||||
if(Utilities::CheckSpecialDay(cfg, inputDate, ¤t_special_day_id, &day_price)) {
|
if(Utilities::CheckSpecialDay(cfg, inputDate, ¤t_special_day_id, &price)) {
|
||||||
// Set special day price:
|
// Set special day price:
|
||||||
// ACHTUNG: price_per_unit ist eigentlich immer preis pro minute !!!
|
durationUnit = 60.0;
|
||||||
price_per_unit = CalculatePricePerUnit(day_price);
|
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id),
|
||||||
worktime[index].setTimeRange(SpecialDaysWorkTimeFrom(cfg, current_special_day_id),
|
SpecialDaysWorkTimeUntil(cfg, current_special_day_id));
|
||||||
SpecialDaysWorkTimeUntil(cfg, current_special_day_id));
|
ranges = 1;
|
||||||
} else {
|
} else {
|
||||||
// Set new price for the normal day
|
// Set new price for the normal day: do not use a floating-point type
|
||||||
|
// 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;
|
||||||
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
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;
|
||||||
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
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) {
|
||||||
@ -503,114 +542,162 @@ uint32_t 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto[itr, rangeEnd] = cfg->WeekDaysWorktime.equal_range(weekdayId); itr != rangeEnd; ++itr) {
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||||
qCritical() << itr->first << itr->second.pwd_time_from.c_str() << itr->second.pwd_time_to.c_str();
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||||
worktime[index].setTimeRange(QTime::fromString(itr->second.pwd_time_from.c_str()),
|
|
||||||
QTime::fromString(itr->second.pwd_time_to.c_str()));
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||||
index += 1;
|
worktime[ranges].setTimeRange(WeekDaysWorkTimeFrom(itr),
|
||||||
|
WeekDaysWorkTimeUntil(itr));
|
||||||
|
ranges += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (price_per_unit < 0) price_per_unit = 1.0f;
|
uint32_t costFromDuration = 0;
|
||||||
qDebug() << "Calculated price per minute=" << price_per_unit;
|
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
||||||
|
int currentRange = -1;
|
||||||
|
|
||||||
double costFromDuration = 0.0;
|
if (nextDay) { // this means the function has been called recursively
|
||||||
for (int w = 0; w < index; ++w) {
|
currentRange = 0;
|
||||||
QTime worktime_from = worktime[w].getTimeFrom();
|
inputDate.setTime(worktime[currentRange].getTimeFrom());
|
||||||
QTime worktime_to = worktime[w].getTimeUntil();
|
} else {
|
||||||
|
// check if inputDate is located inside a valid worktime-range...
|
||||||
if (price_per_unit == 0) {
|
currentRange = findWorkTimeRange(inputDate, worktime, ranges);
|
||||||
inputDate = inputDate.addDays(1);
|
if (currentRange == -1) { // no...
|
||||||
inputDate.setTime(worktime_from);
|
if (!prepaid) { // parking is not allowed
|
||||||
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid);
|
return Ticket(start, end, durationMinutesNetto, 0,
|
||||||
if (partialCost == 0) {
|
0, Ticket::s[INVALID_FROM_DATETIME]);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
// find the next worktime-range (on the same day), and start from there
|
||||||
continue;
|
currentRange = findNextWorkTimeRange(inputDate, worktime, ranges);
|
||||||
|
inputDate.setTime(worktime[currentRange].getTimeFrom());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If overtime flag is set
|
for (int w = currentRange; w < ranges; ++w) {
|
||||||
if (overtime || nextDay) {
|
if (durationMinutes > 0) {
|
||||||
inputDate.setTime(worktime_from);
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
||||||
overtime = false;
|
QTime const &worktime_to = worktime[w].getTimeUntil();
|
||||||
}
|
|
||||||
|
|
||||||
// Check prepaid
|
qCritical() << "from" << worktime_from;
|
||||||
if (!prepaid) {
|
qCritical() << "until" << worktime_to;
|
||||||
if ((inputDate.time() < worktime_from) || (inputDate.time() > worktime_to)) {
|
|
||||||
qDebug() << "[STOP] * Ticket is not valid * ";
|
//if (w > 0) { // durationMinutes are always meant as netto time and
|
||||||
return 0.0f;
|
// // the time between worktime-ranges are free.
|
||||||
}
|
// inputDate.setTime(worktime_from);
|
||||||
} else {
|
//}
|
||||||
qDebug() << "* PREPAID MODE ACTIVE *";
|
|
||||||
if (inputDate.time() < worktime_from) {
|
// TODO: hier muss dann der preis hin
|
||||||
inputDate.setTime(worktime_from);
|
if (price == 0) {
|
||||||
} else if(inputDate.time() > worktime_to) {
|
|
||||||
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);
|
inputDate.setTime(worktime_from);
|
||||||
if (partialCost == 0) {
|
Ticket t = private_GetCostFromDuration(
|
||||||
return 0;
|
cfg, // TODO: erklaerung
|
||||||
|
inputDate,
|
||||||
|
end, durationMinutes,
|
||||||
|
true, prepaid);
|
||||||
|
if (!t.isValid()) {
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
costFromDuration += partialCost;
|
costFromDuration += t.getPrice();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while(durationMinutes > 0) {
|
// If overtime flag is set
|
||||||
// Check for active year period
|
// TODO: ueberpruefen, kann man wohl nach oben ziehen
|
||||||
if (std::none_of(cfg->YearPeriod.begin(),
|
//if (overtime || nextDay) {
|
||||||
cfg->YearPeriod.end(),
|
// inputDate.setTime(worktime_from);
|
||||||
[&inputDate](std::pair<int, ATBPeriodYear> const &year) {
|
// overtime = false;
|
||||||
QDate const input(2004, // 2004 is a leap year
|
//}
|
||||||
inputDate.date().month(),
|
|
||||||
inputDate.date().day());
|
qCritical() << "inputDate.time()=" << inputDate.time();
|
||||||
QDate const s(2004, year.second.pye_start_day, year.second.pye_start_month);
|
|
||||||
QDate const e(2004, year.second.pye_end_day, year.second.pye_end_month);
|
// Check prepaid
|
||||||
return (input >= s && input <= e);
|
if (!prepaid) {
|
||||||
})) {
|
if ((inputDate.time() < worktime_from) || (inputDate.time() > worktime_to)) {
|
||||||
qCritical() << "NO VALID YEAR PERIOD";
|
qDebug() << "[STOP] * Ticket is not valid * ";
|
||||||
return 0.0;
|
return Ticket();
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go to next day if minutes not spent
|
while(durationMinutes > 0) {
|
||||||
if(inputDate.time() >= worktime_to) {
|
// Check for active year period
|
||||||
// check for carry_over status
|
if (!IsYearPeriodActive(cfg, inputDate)) {
|
||||||
if (cfg->PaymentOption.find(paymentMethodId)->second.pop_carry_over < 1) {
|
return Ticket();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Reached end of worktime, searching for the next working day";
|
qDebug() << "inputDate" << inputDate.toString(Qt::ISODate);
|
||||||
|
|
||||||
inputDate = inputDate.addDays(1);
|
if(inputDate.time() >= lastWorktimeTo) {
|
||||||
overtime = true;
|
// Go to next day if minutes not spent
|
||||||
uint32_t const partialCost = private_GetCostFromDuration(cfg, inputDate, end, durationMinutes, true, prepaid, overtime);
|
if (carryOverNotSet) {
|
||||||
if (partialCost == 0) {
|
// no carry_over, so stop computation
|
||||||
return 0;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
|
||||||
|
|
||||||
end = inputDate;
|
if (inputDate >= end) {
|
||||||
|
end = inputDate;
|
||||||
|
}
|
||||||
|
|
||||||
//double ret_val = total_cost;
|
if (nextDay == false) {
|
||||||
//total_cost = 0.0f;
|
qDebug() << "GetCostFromDuration(): Valid until:" << end.toString(Qt::ISODate);
|
||||||
//return ceil(ret_val);
|
}
|
||||||
|
|
||||||
// TODO: runden nur falls oberster stack-rahmen
|
return
|
||||||
|
Ticket(start, end,
|
||||||
return ceil(costFromDuration);
|
durationMinutesNetto,
|
||||||
|
start.secsTo(end) / 60,
|
||||||
|
nextDay ?
|
||||||
|
costFromDuration :
|
||||||
|
llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
||||||
|
Ticket::s[VALID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,18 @@ Ticket::Ticket()
|
|||||||
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;
|
||||||
@ -54,14 +66,23 @@ void Ticket::setPrice(uint32_t price) {
|
|||||||
|
|
||||||
Ticket::operator QString() {
|
Ticket::operator QString() {
|
||||||
QStringList status;
|
QStringList status;
|
||||||
status << QString("Status .............. : %1 (%2)")
|
status << QString("**********************");
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "tariff_log.h"
|
#include "tariff_log.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
static int protection_counter = 0;
|
static int protection_counter = 0;
|
||||||
|
|
||||||
@ -195,6 +196,23 @@ bool Utilities::IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt) {
|
||||||
|
if (std::none_of(cfg->YearPeriod.cbegin(),
|
||||||
|
cfg->YearPeriod.cend(),
|
||||||
|
[&dt](std::pair<int, ATBPeriodYear> const &year) {
|
||||||
|
QDate const d(2004, // 2004 is a leap year
|
||||||
|
dt.date().month(),
|
||||||
|
dt.date().day());
|
||||||
|
QDate const s(2004, year.second.pye_start_month, year.second.pye_start_day);
|
||||||
|
QDate const e(2004, year.second.pye_end_month, year.second.pye_end_day);
|
||||||
|
return (d >= s && d <= e);
|
||||||
|
})) {
|
||||||
|
qCritical() << "NO VALID YEAR PERIOD";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
|
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
|
||||||
{
|
{
|
||||||
@ -317,3 +335,41 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
|
|||||||
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
|
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
|
||||||
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
|
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;
|
||||||
|
}
|
||||||
|
@ -50,9 +50,12 @@ int main() {
|
|||||||
|
|
||||||
if (isParsed)
|
if (isParsed)
|
||||||
{
|
{
|
||||||
QDateTime start = QDateTime::fromString("2023-05-11T08:00:00",Qt::ISODate);
|
QDateTime start = QDateTime::fromString("2023-11-27T17:50:00",Qt::ISODate);
|
||||||
|
//QDateTime start = QDateTime::currentDateTime();
|
||||||
QDateTime end = start.addSecs(120);
|
QDateTime end = start.addSecs(120);
|
||||||
calculator.GetCostFromDuration(&cfg, 3, start, end, 60);
|
uint32_t cost = calculator.GetCostFromDuration(&cfg, 3, start, end, 60);
|
||||||
|
qCritical() << "cost=" << cost;
|
||||||
|
qCritical() << "end=" << end;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user