Implemement isParkingAllowed().

This commit is contained in:
Gerhard Hoffmann 2024-01-31 15:19:01 +01:00
parent 87c0f4397b
commit 15006e8e22

View File

@ -200,6 +200,67 @@ uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
} }
CalcState Calculator::isParkingAllowed(Configuration const *cfg, QDateTime const &start) {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
int const weekdayId = start.date().dayOfWeek();
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
if (businessHours == BusinessHours::OnlyWeekDays) {
if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
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) {
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
QTime const &startTime = start.time();
if (from > startTime) {
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
QString("%1 < %2").arg(from.toString(Qt::ISODate))
.arg(startTime.toString(Qt::ISODate)), from, until);
} else
if (startTime >= until) {
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
QString("%1 >= %2").arg(startTime.toString(Qt::ISODate))
.arg(until.toString(Qt::ISODate)), from, until);
}
return CalcState(CalcState::State::SUCCESS,
"PARKING ALLOWED", from, until);
}
}
}
} else
if (businessHours == BusinessHours::AllDaysWithRestrictedHours) { // e.g. for Neuhauser, NAZ (744)
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
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) {
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
QTime const &startTime = start.time();
if (from > startTime) {
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
QString("%1 < %2").arg(from.toString(Qt::ISODate))
.arg(startTime.toString(Qt::ISODate)), from, until);
} else
if (startTime >= until) {
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
QString("%1 >= %2").arg(startTime.toString(Qt::ISODate))
.arg(until.toString(Qt::ISODate)), from, until);
}
return CalcState(CalcState::State::SUCCESS,
"PARKING ALLOWED", from, until);
}
}
}
}
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, "UNKNOWN ERROR",
QTime(), QTime());
}
/////////////////////////////////////// ///////////////////////////////////////