Implement SpecialDaysWorkTimeFrom() and SpecialDaysWorkTimeUntil().

Extend getBusinessHours() to include new enum-values.
Implement isDayIncluded() as switch-case on dayOfWeek.
Implement dumpBusinessHours().
This commit is contained in:
Gerhard Hoffmann 2024-04-19 13:21:38 +02:00
parent b0e7bd91b4
commit e20eb93abf

View File

@ -1,5 +1,6 @@
#include "utilities.h"
#include "tariff_log.h"
#include "tariff_business_hours.h"
#include <QDebug>
#include <algorithm>
@ -333,6 +334,14 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it) {
return QTime::fromString(it->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it) {
return QTime::fromString(it->second.pedwt_time_to.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
}
@ -420,10 +429,10 @@ uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod
}
BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) {
int businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
uint64_t businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
switch (businessHours) {
case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
//case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
case OnlyWorkingDays: return BusinessHours::OnlyWorkingDays;
case OnlyWeekDays: return BusinessHours::OnlyWeekDays;
case OnlyWeekEnd: return BusinessHours::OnlyWeekEnd;
@ -433,6 +442,21 @@ BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMetho
case SpecialAndSchoolHolidays: return BusinessHours::SpecialAndSchoolHolidays;
case OnlyOpenForBusinessDays: return BusinessHours::OnlyOpenForBusinessDays;
case AllDaysWithRestrictedHours: return BusinessHours::AllDaysWithRestrictedHours;
case _NO_RESTRICTION_24_7_: return BusinessHours::NO_RESTRICTION_24_7;
case _MON_: return BusinessHours::MON;
case _TUE_: return BusinessHours::TUE;
case _WED_: return BusinessHours::WED;
case _THU_: return BusinessHours::THU;
case _FRI_: return BusinessHours::FRI;
case _SAT_: return BusinessHours::SAT;
case _SUN_: return BusinessHours::SUN;
case _WEEK_DAYS_: return BusinessHours::WEEK_DAYS;
case _WORKING_DAYS_: return BusinessHours::WORKING_DAYS;
case _ALL_DAYS_: return BusinessHours::ALL_DAYS;
case _OFFICIAL_HOLIDAY_: return BusinessHours::OFFICIAL_HOLIDAY;
case _ONLY_WEEKEND_: return BusinessHours::ONLY_WEEKEND;
case _ONLY_OPEN_FOR_BUSINESS_DAYS_: return BusinessHours::ONLY_OPEN_FOR_BUSINESS_DAYS;
case _NOT_DEFINED_: return BusinessHours::NOT_DEFINED;
}
return BusinessHours::NoBusinessHoursDefined;
}
@ -447,3 +471,82 @@ double Utilities::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentM
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
return (double)(cfg->Duration.find(durationId)->second.pun_duration);
}
bool Utilities::isDayIncluded(uint64_t businessHours, QDateTime const &dt) {
int dayOfWeek = dt.date().dayOfWeek();
switch (dayOfWeek) {
case Qt::Monday:
return ((businessHours & BusinessHours::MON) == BusinessHours::MON);
case Qt::Tuesday:
return ((businessHours & BusinessHours::TUE) == BusinessHours::TUE);
case Qt::Wednesday:
return ((businessHours & BusinessHours::WED) == BusinessHours::WED);
case Qt::Thursday:
return ((businessHours & BusinessHours::THU) == BusinessHours::THU);
case Qt::Friday:
return ((businessHours & BusinessHours::FRI) == BusinessHours::FRI);
case Qt::Saturday:
return ((businessHours & BusinessHours::SAT) == BusinessHours::SAT);
case Qt::Sunday:
return ((businessHours & BusinessHours::SUN) == BusinessHours::SUN);
default:;
}
return false;
}
QStringList Utilities::dumpBusinessHours(uint64_t businessHours) {
QStringList s;
if ((businessHours & BusinessHours::MON) == BusinessHours::MON) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "MON (Holiday)";
} else {
s << "MON";
}
}
if ((businessHours & BusinessHours::TUE) == BusinessHours::TUE) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "TUE (Holiday)";
} else {
s << "TUE";
}
}
if ((businessHours & BusinessHours::WED) == BusinessHours::WED) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "WED (Holiday)";
} else {
s << "WED";
}
}
if ((businessHours & BusinessHours::THU) == BusinessHours::THU) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "THU (Holiday)";
} else {
s << "THU";
}
}
if ((businessHours & BusinessHours::FRI) == BusinessHours::FRI) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "FRI (Holiday)";
} else {
s << "FRI";
}
}
if ((businessHours & BusinessHours::SAT) == BusinessHours::SAT) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "SAT (Holiday)";
} else {
s << "SAT";
}
}
if ((businessHours & BusinessHours::SUN) == BusinessHours::SUN) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "SUN (Holiday)";
} else {
s << "SUN";
}
}
return s;
}