From 5deaa48f8e1865ac255168b316833394d8d6e3e5 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 30 Jan 2024 10:49:30 +0100 Subject: [PATCH] Implement: getDailyTicketsForAllKeys(), getDailyTicketsForKey(), getPaymentRateForAllKeys(), getPaymentRateForKey(), getCustomerForType() and getWeekDayWorkTime(). --- library/src/configuration.cpp | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index f5b313c..ec22866 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -467,3 +467,112 @@ QVector const &Configuration::getAllPaymentOptions() const { QVector &Configuration::getAllPaymentOptions() { return this->currentPaymentOptions; } + +std::optional> +Configuration::getDailyTicketsForAllKeys() const { + QVector tickets; + std::optional> value; + + for (std::multimap::const_iterator it = this->DailyTicket.cbegin(); + it != this->DailyTicket.cend(); ++it) { + tickets.append(it->second); + } + + if (tickets.size() > 0) { + value.value_or(tickets); + } + + return value; +} + +std::optional> +Configuration::getDailyTicketsForKey(int key) const { + QVector tickets; + std::optional> value; + + std::pair< + std::multimap::const_iterator, + std::multimap::const_iterator + > p = this->DailyTicket.equal_range(key); + + for (std::multimap::const_iterator it = p.first; + it != p.second; ++it) { + tickets.append(it->second); + } + + if (tickets.size() > 0) { + value.value_or(tickets); + } + + return value; +} + +std::optional> +Configuration::getPaymentRateForAllKeys() const { + QVector paymentRates; + std::optional> value; + + for (std::multimap::const_iterator it = this->PaymentRate.cbegin(); + it != this->PaymentRate.cend(); ++it) { + paymentRates.append(it->second); + } + + if (paymentRates.size() > 0) { + value.value_or(paymentRates); + } + + return value; + +} + +std::optional> +Configuration::getPaymentRateForKey(int key) const { + QVector paymentRate; + std::optional> value; + + std::pair< + std::multimap::const_iterator, + std::multimap::const_iterator + > p = this->PaymentRate.equal_range(key); + + for (std::multimap::const_iterator it = p.first; + it != p.second; ++it) { + paymentRate.append(it->second); + } + + if (paymentRate.size() > 0) { + value.value_or(paymentRate); + } + + return value; +} + +std::optional +Configuration::getCustomerForType(ATBCustomer::CustomerType customerType) { + for (std::multimap::const_iterator it = this->Customer.cbegin(); + it != this->Customer.cend(); ++it) { + ATBCustomer const &customer = it->second; + if (customer.cust_type == customerType) { + return customer; + } + } + + return std::nullopt; +} + +std::optional +Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) { + ATBWeekDaysWorktime worktime; + std::optional value; + + std::multimap::const_iterator it = this->WeekDaysWorktime.find((int)dayOfWeek); + if (it != this->WeekDaysWorktime.cend()) { + ATBWeekDaysWorktime const &wt = it->second; + if (QTime::fromString(wt.pwd_time_from.c_str(), Qt::ISODate) >= time + && QTime::fromString(wt.pwd_time_to.c_str(), Qt::ISODate) < time) { + value.value_or(wt); + } + } + + return value; +}