GetDurationFromCost(): add some sanity checks for cost. Check if cost < minParkingPrice.
Cut cost internally to maxParkingPrice if cost > maxParkingPrice.
This commit is contained in:
parent
3ff9883647
commit
9c19414e5a
@ -157,6 +157,17 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
static const bool carryOverNotSet = Utilities::isCarryOverNotSet(cfg, paymentMethodId);
|
||||
static const uint minParkingPrice = Utilities::getMinimalParkingPrice(cfg, paymentMethodId);
|
||||
static const uint maxParkingPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
||||
|
||||
if (cost < minParkingPrice) {
|
||||
qCritical() << QString("ERROR: COST < MIN_PARKING_PRICE (%1 < %2)").arg(cost).arg(minParkingPrice);
|
||||
return QDateTime().toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
if (cost > maxParkingPrice) {
|
||||
qCritical() << QString("WARN: COST > MAX_PARKING_PRICE (%1 > %2)").arg(cost).arg(maxParkingPrice);
|
||||
cost = maxParkingPrice;
|
||||
}
|
||||
|
||||
Q_ASSERT_X(carryOverNotSet, __func__, "CARRYOVER SET (FOR KIRCHDORF)");
|
||||
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
||||
@ -279,6 +290,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
price += (uint)rate.pra_price;
|
||||
|
||||
if (price >= maxParkingPrice) {
|
||||
price = maxParkingPrice;
|
||||
}
|
||||
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
@ -320,10 +335,16 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user