Implemented GetDailyTicketPrice().

To be tested.
This commit is contained in:
Gerhard Hoffmann 2024-01-30 10:26:53 +01:00
parent 1ea42f88ba
commit f8dc59532c

View File

@ -836,3 +836,82 @@ uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
return duration; return duration;
} }
std::optional<struct price_t>
Calculator::GetDailyTicketPrice(Configuration* cfg,
QDateTime const &startDatetime,
QDateTime &endTime,
PERMIT_TYPE permitType) {
struct price_t price;
std::optional<struct price_t> value;
std::optional<ATBWeekDaysWorktime> workTime =
cfg->getWeekDayWorkTime(startDatetime.time(),
(Qt::DayOfWeek)startDatetime.date().dayOfWeek());
if (workTime) {
ATBWeekDaysWorktime const &wt = workTime.value();
endTime = startDatetime;
endTime.setTime(QTime::fromString(wt.pwd_time_to.c_str(), Qt::ISODate));
std::optional<QVector<ATBDailyTicket>> dailyTickets = cfg->getDailyTicketsForAllKeys();
if (dailyTickets) {
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
switch (permitType) {
case PERMIT_TYPE::DAY_TICKET_ADULT: {
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::ADULT);
if (c) {
for (QVector<ATBDailyTicket>::size_type i=0; i<tickets.size(); ++i) {
if (tickets[i].daily_ticket_clearance_customer_ids.contains(c.value().cust_id)) {
int priceId = tickets[i].daily_ticket_price_id;
std::optional<QVector<ATBPaymentRate>> const &paymentRates = cfg->getPaymentRateForKey(priceId);
if (paymentRates) {
QVector<ATBPaymentRate> const &pr = paymentRates.value();
if (pr.size() > 0) {
price.netto = pr.at(0).pra_price;
value.value_or(price);
}
}
}
}
}
} break;
case PERMIT_TYPE::DAY_TICKET_TEEN: {
std::optional<ATBCustomer> c = cfg->getCustomerForType(ATBCustomer::CustomerType::TEEN);
if (c) {
for (QVector<ATBDailyTicket>::size_type i=0; i<tickets.size(); ++i) {
if (tickets[i].daily_ticket_clearance_customer_ids.contains(c.value().cust_id)) {
int priceId = tickets[i].daily_ticket_price_id;
std::optional<QVector<ATBPaymentRate>> const &paymentRates = cfg->getPaymentRateForKey(priceId);
if (paymentRates) {
QVector<ATBPaymentRate> const &pr = paymentRates.value();
if (pr.size() > 0) {
price.netto = pr.at(0).pra_price;
value.value_or(price);
}
}
}
}
}
} break;
case PERMIT_TYPE::DAY_TICKET_CHILD: {
}
// [[fallthrough]];
case PERMIT_TYPE::SHORT_TERM_PARKING: {
}
// [[fallthrough]];
case PERMIT_TYPE::DAY_TICKET: {
}
// [[fallthrough]];
case PERMIT_TYPE::SZEGED_START:
// [[fallthrough]];
case PERMIT_TYPE::SZEGED_STOP:
// [[fallthrough]];
case PERMIT_TYPE::INVALID:
break;
}
}
}
return value;
}