Use isParkingAllowed() to steamline source code.

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

View File

@ -134,30 +134,17 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60);
return inputDate.toString(Qt::ISODate).toStdString();
} else {
QDateTime const &start = QDateTime::fromString(start_datetime, Qt::ISODate);
if (Utilities::IsYearPeriodActive(cfg, start)) {
if (Utilities::IsYearPeriodActive(cfg, inputDate)) {
if (!prepaid) {
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
if (businessHours == BusinessHours::OnlyWeekDays) {
int const weekdayId = start.date().dayOfWeek();
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 && startTime <= until) {
return inputDate.addSecs(GetDurationForPrice(cfg, price) * 60).toString(Qt::ISODate).toStdString();
}
}
CalcState cs = isParkingAllowed(cfg, inputDate);
if (cs) {
inputDate.setTime(cs.getAllowedTimeRange().getTimeUntil());
return inputDate.toString(Qt::ISODate).toStdString();
}
}
qCritical() << __PRETTY_FUNCTION__ << "NOT YET IMPLEMENTED";
return 0;
qCritical() << __func__ << ":" << __LINE__ << "NOT YET IMPLEMENTED";
return "";
}
}
}
@ -284,23 +271,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
} else {
if (Utilities::IsYearPeriodActive(cfg, start_datetime)) {
if (!prepaid) {
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
if (businessHours == BusinessHours::OnlyWeekDays) {
int const weekdayId = start_datetime.date().dayOfWeek();
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_datetime.time();
if (from <= startTime && startTime <= until) {
end_datetime = start_datetime.addSecs(durationMinutes*60);
return GetCostFromDuration(cfg, start_datetime, end_datetime);
}
}
CalcState cs = isParkingAllowed(cfg, start_datetime);
if (cs) {
end_datetime = start_datetime.addSecs(durationMinutes*60);
double cost = GetCostFromDuration(cfg, start_datetime, end_datetime);
end_datetime = start_datetime;
end_datetime.setTime(cs.getAllowedTimeRange().getTimeUntil());
return cost;
}
}