Compare commits
26 Commits
bd1bdf8a8c
...
bad-neuena
| Author | SHA1 | Date | |
|---|---|---|---|
| aba38d2614 | |||
| 57d6b85f52 | |||
| 4f9c0422fc | |||
| a5b95d71b8 | |||
| fcbc8dcdc3 | |||
| ed99bae725 | |||
| 627d14204d | |||
|
d8a4c4eaa7
|
|||
| 4f45db4fde | |||
| a744a1ebb3 | |||
| df16bd7f9c | |||
| b751ba339e | |||
|
588a88455b
|
|||
|
92bfdced6a
|
|||
| 8bbec596c9 | |||
| 87b14ee3f8 | |||
| 3ad2c77467 | |||
| 493d94aaa1 | |||
| 7831329b11 | |||
| abbbd06f93 | |||
| ac6e45a913 | |||
| b741d2e312 | |||
| 6756aa5b88 | |||
| 7845ab8077 | |||
| cc222c298a | |||
| eb645273cc |
@@ -84,6 +84,51 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
return (m_status == State::SUCCESS);
|
return (m_status == State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString toString() {
|
||||||
|
QString s;
|
||||||
|
switch (m_status) {
|
||||||
|
case State::SUCCESS:
|
||||||
|
s = "SUCCESS";
|
||||||
|
break;
|
||||||
|
case State::ERROR_PARSING_ZONE_NR:
|
||||||
|
s = "ERROR_PARSING_ZONE_NR";
|
||||||
|
break;
|
||||||
|
case State::ERROR_LOADING_TARIFF:
|
||||||
|
s = "ERROR_LOADING_TARIFF";
|
||||||
|
break;
|
||||||
|
case State::ERROR_PARSING_TARIFF:
|
||||||
|
s = "ERROR_PARSING_TARIFF";
|
||||||
|
break;
|
||||||
|
case State::NEGATIVE_PARING_TIME:
|
||||||
|
s = "NEGATIVE_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::ABOVE_MAX_PARKING_TIME:
|
||||||
|
s = "ABOVE_MAX_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::WRONG_PARAM_VALUES:
|
||||||
|
s = "WRONG_PARAM_VALUES";
|
||||||
|
break;
|
||||||
|
case State::BELOW_MIN_PARKING_TIME:
|
||||||
|
s = "BELOW_MIN_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::BELOW_MIN_PARKING_PRICE:
|
||||||
|
s = "BELOW_MIN_PARKING_PRICE";
|
||||||
|
break;
|
||||||
|
case State::OVERPAID:
|
||||||
|
s = "OVERPAID";
|
||||||
|
break;
|
||||||
|
case State::INVALID_START_DATE:
|
||||||
|
s = "INVALID_START_DATE";
|
||||||
|
break;
|
||||||
|
case State::WRONG_ISO_TIME_FORMAT:
|
||||||
|
s = "WRONG_ISO_TIME_FORMAT";
|
||||||
|
break;
|
||||||
|
case State::OUTSIDE_ALLOWED_PARKING_TIME:
|
||||||
|
s = "OUTSIDE_ALLOWED_PARKING_TIME";
|
||||||
|
}
|
||||||
|
return s + ":" + m_desc;
|
||||||
|
}
|
||||||
|
|
||||||
explicit operator QString () const noexcept {
|
explicit operator QString () const noexcept {
|
||||||
QString s;
|
QString s;
|
||||||
switch (m_status) {
|
switch (m_status) {
|
||||||
@@ -130,6 +175,8 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CalcState &set(State s) { m_status = s; return *this; }
|
CalcState &set(State s) { m_status = s; return *this; }
|
||||||
|
CalcState &setStatus(State s) { return set(s); }
|
||||||
|
State getStatus() const { return m_status; }
|
||||||
CalcState &setDesc(QString s) { m_desc = s; return *this; }
|
CalcState &setDesc(QString s) { m_desc = s; return *this; }
|
||||||
|
|
||||||
void setAllowedTimeRange(QTime const &from, QTime const &until) {
|
void setAllowedTimeRange(QTime const &from, QTime const &until) {
|
||||||
@@ -152,6 +199,7 @@ QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
|
|||||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||||
|
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ enum class PERMIT_TYPE : quint8 {
|
|||||||
DAY_TICKET_ADULT,
|
DAY_TICKET_ADULT,
|
||||||
DAY_TICKET_TEEN,
|
DAY_TICKET_TEEN,
|
||||||
DAY_TICKET_CHILD,
|
DAY_TICKET_CHILD,
|
||||||
|
FOOD_STAMP,
|
||||||
INVALID
|
INVALID
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,6 +42,9 @@ struct PermitType {
|
|||||||
case 6:
|
case 6:
|
||||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CHILD;
|
m_permitType = PERMIT_TYPE::DAY_TICKET_CHILD;
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
m_permitType = PERMIT_TYPE::FOOD_STAMP;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
m_permitType = PERMIT_TYPE::INVALID;
|
m_permitType = PERMIT_TYPE::INVALID;
|
||||||
}
|
}
|
||||||
@@ -52,7 +56,7 @@ struct PermitType {
|
|||||||
|
|
||||||
operator PERMIT_TYPE() const { return m_permitType; }
|
operator PERMIT_TYPE() const { return m_permitType; }
|
||||||
|
|
||||||
operator int() const {
|
operator int () const {
|
||||||
switch(m_permitType) {
|
switch(m_permitType) {
|
||||||
case PERMIT_TYPE::SHORT_TERM_PARKING:
|
case PERMIT_TYPE::SHORT_TERM_PARKING:
|
||||||
return 0;
|
return 0;
|
||||||
@@ -68,6 +72,8 @@ struct PermitType {
|
|||||||
return 5;
|
return 5;
|
||||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||||
return 6;
|
return 6;
|
||||||
|
case PERMIT_TYPE::FOOD_STAMP:
|
||||||
|
return 7;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -75,7 +81,7 @@ struct PermitType {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
operator QString() const {
|
operator QString () {
|
||||||
switch(m_permitType) {
|
switch(m_permitType) {
|
||||||
case PERMIT_TYPE::DAY_TICKET:
|
case PERMIT_TYPE::DAY_TICKET:
|
||||||
return QString("DAY_TICKET");
|
return QString("DAY_TICKET");
|
||||||
@@ -91,6 +97,32 @@ struct PermitType {
|
|||||||
return QString("SZEGED_START");
|
return QString("SZEGED_START");
|
||||||
case PERMIT_TYPE::SZEGED_STOP:
|
case PERMIT_TYPE::SZEGED_STOP:
|
||||||
return QString("SZEGED_STOP");
|
return QString("SZEGED_STOP");
|
||||||
|
case PERMIT_TYPE::FOOD_STAMP:
|
||||||
|
return QString("FOOD_STAMP");
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return QString("INVALID");
|
||||||
|
}
|
||||||
|
|
||||||
|
operator QString () const {
|
||||||
|
switch(m_permitType) {
|
||||||
|
case PERMIT_TYPE::DAY_TICKET:
|
||||||
|
return QString("DAY_TICKET");
|
||||||
|
case PERMIT_TYPE::DAY_TICKET_ADULT:
|
||||||
|
return QString("DAY_TICKET_ADULT");
|
||||||
|
case PERMIT_TYPE::DAY_TICKET_CHILD:
|
||||||
|
return QString("DAY_TICKET_CHILD");
|
||||||
|
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||||
|
return QString("DAY_TICKET_TEEN");
|
||||||
|
case PERMIT_TYPE::SHORT_TERM_PARKING:
|
||||||
|
return QString("SHORT_TERM_PARKING");
|
||||||
|
case PERMIT_TYPE::SZEGED_START:
|
||||||
|
return QString("SZEGED_START");
|
||||||
|
case PERMIT_TYPE::SZEGED_STOP:
|
||||||
|
return QString("SZEGED_STOP");
|
||||||
|
case PERMIT_TYPE::FOOD_STAMP:
|
||||||
|
return QString("FOOD_STAMP");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
|
|||||||
// [[fallthrough]];
|
// [[fallthrough]];
|
||||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||||
// [[fallthrough]];
|
// [[fallthrough]];
|
||||||
|
case PERMIT_TYPE::FOOD_STAMP:
|
||||||
|
// [[fallthrough]];
|
||||||
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
||||||
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
|
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
|
||||||
if (products) {
|
if (products) {
|
||||||
@@ -92,6 +94,21 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
|
|||||||
if (product.size() > 0) {
|
if (product.size() > 0) {
|
||||||
ATBTariffProduct const &p = product[0];
|
ATBTariffProduct const &p = product[0];
|
||||||
return p.m_tariff_product_price;
|
return p.m_tariff_product_price;
|
||||||
|
#if 0
|
||||||
|
// in case we do not have prepaid-option
|
||||||
|
QTime const ¤tTime = QDateTime::currentDateTime().time();
|
||||||
|
|
||||||
|
if (p.m_tariff_product_start <= currentTime && currentTime <= p.m_tariff_product_end) {
|
||||||
|
return p.m_tariff_product_price;
|
||||||
|
} else {
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "ERROR currentTime"
|
||||||
|
<< currentTime.toString(Qt::ISODate)
|
||||||
|
<< "INVALID ("
|
||||||
|
<< p.m_tariff_product_start.toString(Qt::ISODate)
|
||||||
|
<< p.m_tariff_product_end.toString(Qt::ISODate) << ")";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@@ -108,7 +125,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TY
|
|||||||
|
|
||||||
switch(permitType) {
|
switch(permitType) {
|
||||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||||
if (paymentMethodId == PaymentMethod::Progressive) {
|
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
|
||||||
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
||||||
} else { // PaymentMethod::Linear -> e.g. szeged
|
} else { // PaymentMethod::Linear -> e.g. szeged
|
||||||
int const key = cfg->getPaymentOptions().pop_id;
|
int const key = cfg->getPaymentOptions().pop_id;
|
||||||
@@ -117,7 +134,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TY
|
|||||||
if (pv) {
|
if (pv) {
|
||||||
QVector<ATBPaymentRate> const &paymentRate = pv.value();
|
QVector<ATBPaymentRate> const &paymentRate = pv.value();
|
||||||
if (paymentRate.size() > 0) {
|
if (paymentRate.size() > 0) {
|
||||||
int const price = paymentRate.at(0).pra_price; // price is given per hour
|
int const price = paymentRate.last().pra_price; // price is given per hour
|
||||||
maxPrice = qRound((maxTime * price) / 60.0f);
|
maxPrice = qRound((maxTime * price) / 60.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,14 +428,23 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double cost = -1;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
double cost = Calculator::GetInstance().GetCostFromDuration(
|
if (tariff->getPaymentOptions().pop_payment_method_id == PaymentMethod::Steps) {
|
||||||
|
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time);
|
||||||
|
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
|
||||||
|
return calcState;
|
||||||
|
}
|
||||||
|
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time);
|
||||||
|
} else {
|
||||||
|
cost = Calculator::GetInstance().GetCostFromDuration(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start_parking_time, // starting time
|
start_parking_time, // starting time
|
||||||
end_parking_time, // return value: end time
|
end_parking_time, // return value: end time
|
||||||
netto_parking_time, // minutes, netto
|
netto_parking_time, // minutes, netto
|
||||||
false, prepaid);
|
false, prepaid);
|
||||||
|
}
|
||||||
double minCost = tariff->getPaymentOptions().pop_min_price;
|
double minCost = tariff->getPaymentOptions().pop_min_price;
|
||||||
if (cost < minCost) {
|
if (cost < minCost) {
|
||||||
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
||||||
@@ -428,8 +454,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << " -> calculated cost (price->netto) = " << cost;
|
qCritical() << " -> calculated cost (price->netto) = " << cost;
|
||||||
|
|
||||||
|
price->brutto = price->vat = price->vat_percentage = 0;
|
||||||
price->units = cost;
|
price->units = cost;
|
||||||
price->netto = cost;
|
price->netto = cost;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return calcState.set(CalcState::State::INVALID_START_DATE);
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
int durationMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
int durationMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
||||||
int durationMinutesBrutto = 0;
|
int durationMinutesBrutto = 0;
|
||||||
|
|
||||||
|
#ifdef _DEBUG_
|
||||||
|
#undef _DEBUG_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#define _DEBUG_ 1
|
||||||
|
#define _DEBUG_ 0
|
||||||
|
|
||||||
QDateTime current = start;
|
QDateTime current = start;
|
||||||
|
|
||||||
int days = 7;
|
int days = 7;
|
||||||
@@ -229,139 +236,340 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
uint price = 0;
|
uint price = 0;
|
||||||
|
|
||||||
if (carryOverNotSet) {
|
if (carryOverNotSet) {
|
||||||
int range = 0;
|
|
||||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||||
int minsUsed = 0;
|
int minsUsed = 0;
|
||||||
QDateTime lastCurrent = QDateTime();
|
QDateTime lastCurrent = QDateTime();
|
||||||
|
|
||||||
|
QVector<ATBWeekDaysWorktime> weekDayWorkTimeRanges;
|
||||||
|
|
||||||
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||||
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||||
|
|
||||||
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||||
|
weekDayWorkTimeRanges.append(itr->second); // working with vector is easier
|
||||||
|
}
|
||||||
|
|
||||||
|
int weekDayWorkTimeIndex = 0;
|
||||||
|
bool moveToNextTimeRange = false;
|
||||||
|
|
||||||
|
// time ranges for Neuhauser-Kirchdorf (743): 30, 5, 5, ... 5
|
||||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||||
for (; timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) {
|
while (timeRangeIt != cfg->TimeRange.cend()) { // ; ++timeRangeIt) {
|
||||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
||||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
||||||
|
|
||||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
if (weekDayWorkTimeIndex >= weekDayWorkTimeRanges.size()) {
|
||||||
++range;
|
|
||||||
|
|
||||||
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
#if _DEBUG_==1
|
||||||
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr);
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "weekDayWorkTimeRanges.size()" << weekDayWorkTimeRanges.size()
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
end_datetime = current;
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
|
||||||
|
QTime const &to = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_to.c_str(), Qt::ISODate);
|
||||||
|
|
||||||
if (current.time() >= to) {
|
#if _DEBUG_==1
|
||||||
continue; // try to use next available work-time
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
} else
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
if (current.time() <= from) {
|
<< "from" << from.toString(Qt::ISODate)
|
||||||
if (prepaid) {
|
<< "to" << to.toString(Qt::ISODate);
|
||||||
lastCurrent = current;
|
#endif
|
||||||
current.setTime(from); // move current forward (range==1),
|
|
||||||
// as prepaid is set
|
|
||||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
|
||||||
durationMinutesBrutto += minutesMoved;
|
|
||||||
|
|
||||||
if (range == 1) {
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||||
start_datetime = current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (timeRangeIt != cfg->TimeRange.cend()) {
|
if (current.time() >= to) {
|
||||||
ATBTimeRange timeRange = timeRangeIt->second;
|
++weekDayWorkTimeIndex;
|
||||||
|
|
||||||
timeRange.computeQTimes(current.time());
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "try to use next available work-time with"
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
// time range is not affected
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
|
if (current.time() <= from) {
|
||||||
|
if (prepaid) {
|
||||||
|
lastCurrent = current;
|
||||||
|
current.setTime(from); // move current forward (range==1),
|
||||||
|
// as prepaid is set
|
||||||
|
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||||
|
durationMinutesBrutto += minutesMoved;
|
||||||
|
|
||||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
#if _DEBUG_==1
|
||||||
timeRange.time_range_from_in_minutes_from_start;
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "minutesMoved" << minutesMoved
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (minsUsed > 0) {
|
if (weekDayWorkTimeIndex == 0) {
|
||||||
duration -= minsUsed;
|
start_datetime = current;
|
||||||
minsUsed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current.addSecs(duration * 60).time() <= to) {
|
|
||||||
if (minsToCarryOver > 0) { // the price for this time range
|
|
||||||
// has been is paid already
|
|
||||||
durationMinutes -= duration;
|
|
||||||
durationMinutesNetto += duration;
|
|
||||||
durationMinutesBrutto += duration;
|
|
||||||
current = current.addSecs(duration*60);
|
|
||||||
minsToCarryOver = 0;
|
|
||||||
} else {
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
|
||||||
ATBPaymentRate const rate = x.second;
|
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
||||||
price += (uint)rate.pra_price;
|
|
||||||
|
|
||||||
if (price >= maxParkingPrice) {
|
|
||||||
price = maxParkingPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
durationMinutes -= duration;
|
|
||||||
durationMinutesNetto += duration;
|
|
||||||
durationMinutesBrutto += duration;
|
|
||||||
|
|
||||||
current = current.addSecs(duration * 60);
|
|
||||||
|
|
||||||
if (price >= cost) {
|
|
||||||
end_datetime = current;
|
|
||||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durationMinutes <= 0) {
|
|
||||||
end_datetime = current;
|
|
||||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
++timeRangeIt;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
lastCurrent = current;
|
|
||||||
current.setTime(to);
|
|
||||||
minsUsed = lastCurrent.secsTo(current) / 60;
|
|
||||||
|
|
||||||
// mod duration: possibly discard some minutes in
|
|
||||||
// the next time-range
|
|
||||||
if (durationMinutes >= minsUsed) {
|
|
||||||
minsToCarryOver = durationMinutes - minsUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
durationMinutes -= minsUsed;
|
|
||||||
durationMinutesNetto += minsUsed;
|
|
||||||
durationMinutesBrutto += minsUsed;
|
|
||||||
|
|
||||||
if (minsUsed > 0) {
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
|
||||||
ATBPaymentRate const rate = x.second;
|
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
||||||
price += (uint)rate.pra_price;
|
|
||||||
|
|
||||||
if (price >= maxParkingPrice) {
|
|
||||||
price = maxParkingPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (price >= cost) {
|
|
||||||
end_datetime = current;
|
|
||||||
// return end_datetime.toString(Qt::ISODate).toStdString();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATBTimeRange timeRange = timeRangeIt->second;
|
||||||
|
|
||||||
|
timeRange.computeQTimes(current.time());
|
||||||
|
|
||||||
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||||
|
timeRange.time_range_from_in_minutes_from_start;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (minsToCarryOver > 0) { // the price for this time range
|
||||||
|
// has been is paid already
|
||||||
|
Q_ASSERT_X(weekDayWorkTimeIndex > 0, __func__, "WRONG-WORK-TIME");
|
||||||
|
|
||||||
|
current = current.addSecs(minsToCarryOver*60);
|
||||||
|
|
||||||
|
durationMinutes -= minsToCarryOver;
|
||||||
|
durationMinutesNetto += minsToCarryOver;
|
||||||
|
durationMinutesBrutto += minsToCarryOver;
|
||||||
|
|
||||||
|
minsToCarryOver = 0;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "durationMinutesNetto" << durationMinutesNetto
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.addSecs(duration * 60).time() <= to) {
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
moveToNextTimeRange = false;
|
||||||
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
|
ATBPaymentRate const rate = x.second;
|
||||||
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
|
if (price >= maxParkingPrice) {
|
||||||
|
price = maxParkingPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
durationMinutes -= duration;
|
||||||
|
durationMinutesNetto += duration;
|
||||||
|
durationMinutesBrutto += duration;
|
||||||
|
|
||||||
|
current = current.addSecs(duration * 60);
|
||||||
|
|
||||||
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// price has been updated; use next time range
|
||||||
|
moveToNextTimeRange = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "price" << price
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "durationMinutesNetto" << durationMinutesNetto
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moveToNextTimeRange) {
|
||||||
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// havin a new time range means that we always have a new
|
||||||
|
// work-time-range
|
||||||
|
// ++timeRangeIt;
|
||||||
|
|
||||||
|
} else { // current.addSecs(duration * 60).time() > to
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< ", to:" << to.toString(Qt::ISODate);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lastCurrent = current;
|
||||||
|
current.setTime(to);
|
||||||
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// mod duration: possibly discard some minutes in
|
||||||
|
// the next time-range
|
||||||
|
if (duration >= minsUsed) {
|
||||||
|
minsToCarryOver = duration - minsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
durationMinutes -= minsUsed;
|
||||||
|
durationMinutesNetto += minsUsed;
|
||||||
|
durationMinutesBrutto += minsUsed;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
moveToNextTimeRange = false;
|
||||||
|
|
||||||
|
if (minsUsed > 0) {
|
||||||
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
|
ATBPaymentRate const rate = x.second;
|
||||||
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
|
if (price >= maxParkingPrice) {
|
||||||
|
price = maxParkingPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// price has been updated; use next time range
|
||||||
|
moveToNextTimeRange = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "moveToNextTimeRange" << moveToNextTimeRange
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (moveToNextTimeRange) {
|
||||||
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no valid time range left
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "start" << start.toString(Qt::ISODate)
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "final price" << std::max(price, minParkingPrice);
|
||||||
|
#endif
|
||||||
|
|
||||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
} // while (timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "INVALID END TIME";
|
||||||
|
#endif
|
||||||
end_datetime = QDateTime();
|
end_datetime = QDateTime();
|
||||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
@@ -373,6 +581,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
// TODO: im fehlerfall
|
// TODO: im fehlerfall
|
||||||
return t.getValidUntil().toString(Qt::ISODate).toStdString();
|
return t.getValidUntil().toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
|
#undef _DEBUG_
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
@@ -522,6 +731,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
int weekdayIdLast = -1;
|
int weekdayIdLast = -1;
|
||||||
int durationMinutesBrutto = 0;
|
int durationMinutesBrutto = 0;
|
||||||
|
|
||||||
|
#ifdef _DEBUG_
|
||||||
|
#undef _DEBUG_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#define _DEBUG_ 1
|
||||||
|
#define _DEBUG_ 0
|
||||||
|
|
||||||
QDateTime current = start;
|
QDateTime current = start;
|
||||||
|
|
||||||
int days = 7;
|
int days = 7;
|
||||||
@@ -571,120 +787,309 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
uint price = 0;
|
uint price = 0;
|
||||||
|
|
||||||
if (carryOverNotSet) {
|
if (carryOverNotSet) {
|
||||||
int range = 0;
|
|
||||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||||
int minsUsed = 0;
|
int minsUsed = 0;
|
||||||
QDateTime lastCurrent = QDateTime();
|
QDateTime lastCurrent = QDateTime();
|
||||||
|
|
||||||
|
QVector<ATBWeekDaysWorktime> weekDayWorkTimeRanges;
|
||||||
|
|
||||||
|
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||||
|
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||||
|
|
||||||
|
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||||
|
weekDayWorkTimeRanges.append(itr->second); // working with vector is easier
|
||||||
|
}
|
||||||
|
|
||||||
|
int weekDayWorkTimeIndex = 0;
|
||||||
|
bool moveToNextTimeRange = false;
|
||||||
|
|
||||||
|
// time ranges for Neuhauser-Kirchdorf (743): 30, 5, 5, ... 5
|
||||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||||
for (; timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) {
|
while (timeRangeIt != cfg->TimeRange.cend()) { // ; ++timeRangeIt) {
|
||||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
|
||||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
|
||||||
|
|
||||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
if (weekDayWorkTimeIndex >= weekDayWorkTimeRanges.size()) {
|
||||||
++range;
|
|
||||||
|
|
||||||
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
#if _DEBUG_==1
|
||||||
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr);
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "weekDayWorkTimeRanges.size()" << weekDayWorkTimeRanges.size();
|
||||||
|
#endif
|
||||||
|
end_datetime = current;
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
|
||||||
|
QTime const &to = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_to.c_str(), Qt::ISODate);
|
||||||
|
|
||||||
if (current.time() >= to) {
|
#if _DEBUG_==1
|
||||||
continue; // try to use next available work-time
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
} else
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
if (current.time() <= from) {
|
<< "from" << from.toString(Qt::ISODate)
|
||||||
if (prepaid) {
|
<< "to" << to.toString(Qt::ISODate);
|
||||||
lastCurrent = current;
|
#endif
|
||||||
current.setTime(from); // move current forward (range==1),
|
|
||||||
// as prepaid is set
|
|
||||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
|
||||||
durationMinutesBrutto += minutesMoved;
|
|
||||||
|
|
||||||
if (range == 1) {
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||||
start_datetime = current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (timeRangeIt != cfg->TimeRange.cend()) {
|
if (current.time() >= to) {
|
||||||
ATBTimeRange timeRange = timeRangeIt->second;
|
++weekDayWorkTimeIndex;
|
||||||
|
|
||||||
timeRange.computeQTimes(current.time());
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "try to use next available work-time with"
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
// time range is not affected
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
|
if (current.time() <= from) {
|
||||||
|
if (prepaid) {
|
||||||
|
lastCurrent = current;
|
||||||
|
current.setTime(from); // move current forward (range==1),
|
||||||
|
// as prepaid is set
|
||||||
|
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||||
|
durationMinutesBrutto += minutesMoved;
|
||||||
|
|
||||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
#if _DEBUG_==1
|
||||||
timeRange.time_range_from_in_minutes_from_start;
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "minutesMoved" << minutesMoved
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (minsUsed > 0) {
|
if (weekDayWorkTimeIndex == 0) {
|
||||||
duration -= minsUsed;
|
start_datetime = current;
|
||||||
minsUsed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current.addSecs(duration * 60).time() <= to) {
|
|
||||||
if (minsToCarryOver > 0) { // the price for this time range
|
|
||||||
// has been is paid already
|
|
||||||
durationMinutes -= duration;
|
|
||||||
durationMinutesNetto += duration;
|
|
||||||
durationMinutesBrutto += duration;
|
|
||||||
current = current.addSecs(duration*60);
|
|
||||||
minsToCarryOver = 0;
|
|
||||||
} else {
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
|
||||||
ATBPaymentRate const rate = x.second;
|
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
||||||
price += (uint)rate.pra_price;
|
|
||||||
|
|
||||||
durationMinutes -= duration;
|
|
||||||
durationMinutesNetto += duration;
|
|
||||||
durationMinutesBrutto += duration;
|
|
||||||
|
|
||||||
current = current.addSecs(duration * 60);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (durationMinutes <= 0) {
|
|
||||||
end_datetime = current;
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
++timeRangeIt;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
lastCurrent = current;
|
|
||||||
current.setTime(to);
|
|
||||||
minsUsed = lastCurrent.secsTo(current) / 60;
|
|
||||||
|
|
||||||
// mod duration: possibly discard some minutes in
|
|
||||||
// the next time-range
|
|
||||||
if (durationMinutes >= minsUsed) {
|
|
||||||
minsToCarryOver = durationMinutes - minsUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
durationMinutes -= minsUsed;
|
|
||||||
durationMinutesNetto += minsUsed;
|
|
||||||
durationMinutesBrutto += minsUsed;
|
|
||||||
|
|
||||||
if (minsUsed > 0) {
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
|
||||||
ATBPaymentRate const rate = x.second;
|
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
|
||||||
price += (uint)rate.pra_price;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATBTimeRange timeRange = timeRangeIt->second;
|
||||||
|
|
||||||
|
timeRange.computeQTimes(current.time());
|
||||||
|
|
||||||
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||||
|
timeRange.time_range_from_in_minutes_from_start;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (minsToCarryOver > 0) { // the price for this time range
|
||||||
|
// has been is paid already
|
||||||
|
Q_ASSERT_X(weekDayWorkTimeIndex > 0, __func__, "WRONG-WORK-TIME");
|
||||||
|
|
||||||
|
current = current.addSecs(minsToCarryOver*60);
|
||||||
|
|
||||||
|
durationMinutes -= minsToCarryOver;
|
||||||
|
durationMinutesNetto += minsToCarryOver;
|
||||||
|
durationMinutesBrutto += minsToCarryOver;
|
||||||
|
|
||||||
|
minsToCarryOver = 0;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "durationMinutesNetto" << durationMinutesNetto
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||||
|
#endif
|
||||||
|
if (durationMinutes <= 0) {
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.addSecs(duration * 60).time() <= to) {
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
moveToNextTimeRange = false;
|
||||||
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
|
ATBPaymentRate const rate = x.second;
|
||||||
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
|
durationMinutes -= duration;
|
||||||
|
durationMinutesNetto += duration;
|
||||||
|
durationMinutesBrutto += duration;
|
||||||
|
|
||||||
|
current = current.addSecs(duration * 60);
|
||||||
|
|
||||||
|
// price has been updated; use next time range
|
||||||
|
moveToNextTimeRange = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "price" << price
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "durationMinutesNetto" << durationMinutesNetto
|
||||||
|
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (durationMinutes <= 0) {
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moveToNextTimeRange) {
|
||||||
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// havin a new time range means that we always have a new
|
||||||
|
// work-time-range
|
||||||
|
// ++timeRangeIt;
|
||||||
|
|
||||||
|
} else { // current.addSecs(duration * 60).time() > to
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< ", to:" << to.toString(Qt::ISODate);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lastCurrent = current;
|
||||||
|
current.setTime(to);
|
||||||
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// mod duration: possibly discard some minutes in
|
||||||
|
// the next time-range
|
||||||
|
if (duration >= minsUsed) {
|
||||||
|
minsToCarryOver = duration - minsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
durationMinutes -= minsUsed;
|
||||||
|
durationMinutesNetto += minsUsed;
|
||||||
|
durationMinutesBrutto += minsUsed;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "to" << to.toString(Qt::ISODate)
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "minsToCarryOver" << minsToCarryOver
|
||||||
|
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
moveToNextTimeRange = false;
|
||||||
|
|
||||||
|
if (minsUsed > 0) {
|
||||||
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
|
ATBPaymentRate const rate = x.second;
|
||||||
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
|
// price has been updated; use next time range
|
||||||
|
moveToNextTimeRange = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "current" << current.toString(Qt::ISODate)
|
||||||
|
<< "duration" << duration
|
||||||
|
<< "minsUsed" << minsUsed
|
||||||
|
<< "durationMinutes" << durationMinutes
|
||||||
|
<< "moveToNextTimeRange" << moveToNextTimeRange
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (moveToNextTimeRange) {
|
||||||
|
if (++timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no valid time range left
|
||||||
|
end_datetime = current;
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "price" << price;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "start" << start.toString(Qt::ISODate)
|
||||||
|
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
|
||||||
|
<< "final price" << std::max(price, minParkingPrice);
|
||||||
|
#endif
|
||||||
|
|
||||||
return std::max(price, minParkingPrice);
|
return std::max(price, minParkingPrice);
|
||||||
}
|
} // while (timeRangeIt != cfg->TimeRange.cend()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _DEBUG_==1
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||||
|
<< "INVALID END TIME";
|
||||||
|
#endif
|
||||||
end_datetime = QDateTime();
|
end_datetime = QDateTime();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1331,6 +1736,9 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
|||||||
if (dailyTickets) {
|
if (dailyTickets) {
|
||||||
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
||||||
switch (permitType) {
|
switch (permitType) {
|
||||||
|
case PERMIT_TYPE::FOOD_STAMP: {
|
||||||
|
// TODO
|
||||||
|
} break;
|
||||||
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
||||||
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::ADULT);
|
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::ADULT);
|
||||||
if (c) {
|
if (c) {
|
||||||
|
|||||||
900
main/main.cpp
900
main/main.cpp
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user