diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 8df1cf7..064c6e0 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -836,3 +836,82 @@ uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const { return duration; } + +std::optional +Calculator::GetDailyTicketPrice(Configuration* cfg, + QDateTime const &startDatetime, + QDateTime &endTime, + PERMIT_TYPE permitType) { + struct price_t price; + std::optional value; + + std::optional 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> dailyTickets = cfg->getDailyTicketsForAllKeys(); + if (dailyTickets) { + QVector const tickets = dailyTickets.value(); + + switch (permitType) { + case PERMIT_TYPE::DAY_TICKET_ADULT: { + std::optional c = cfg->getCustomerForType(ATBCustomer::CustomerType::ADULT); + if (c) { + for (QVector::size_type i=0; i> const &paymentRates = cfg->getPaymentRateForKey(priceId); + if (paymentRates) { + QVector 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 c = cfg->getCustomerForType(ATBCustomer::CustomerType::TEEN); + if (c) { + for (QVector::size_type i=0; i> const &paymentRates = cfg->getPaymentRateForKey(priceId); + if (paymentRates) { + QVector 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; +}