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