diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index dd1c8d0..bcd3ca1 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -765,7 +765,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } } break; case MemberType::DurationType: - cfg->Duration.insert(pair(Duration.pun_id, Duration)); + cfg->Duration.insert(pair(Duration.pun_id, Duration)); // qCritical() << Duration; break; case MemberType::SpecialDaysWorktimeType: @@ -1131,6 +1131,37 @@ Configuration::getTariffProductForProductTypeName(QString const &permitTypeName) return value; } +int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) { + + std::optional> paymentOptions = getPaymentOptionsForAllKeys(); + if (paymentOptions) { + QVector const vec = paymentOptions.value(); + PermitType const p(permitType); + for (int i = 0; i < vec.size(); ++i) { + if (vec[i].pop_product_name == p.toString()) { + return i; + } + } + } + + return 0; +} + +int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const { + std::optional> paymentOptions = getPaymentOptionsForAllKeys(); + if (paymentOptions) { + QVector const vec = paymentOptions.value(); + PermitType const p(permitType); + for (int i = 0; i < vec.size(); ++i) { + if (vec[i].pop_product_name == p.toString()) { + return i; + } + } + } + + return 0; +} + std::optional> Configuration::getTariffProductForProductId(PermitType permitType) const { QString permitTypeName(permitType); @@ -1240,6 +1271,49 @@ Configuration::getDailyTicketsForKey(int key) const { return value; } +std::optional> +Configuration::getPaymentOptionsForAllKeys() const { + QVector paymentOptions; + std::optional> value; + for (std::multimap::const_iterator it = this->PaymentOption.cbegin(); + it != this->PaymentOption.cend(); ++it) { + paymentOptions.append(it->second); + } + + if (paymentOptions.size() > 0) { + value = value.value_or(paymentOptions); + } + + return value; +} + +std::optional +Configuration::getPaymentOptionForKey(PERMIT_TYPE permitType) const { + return getPaymentOptionForKey(static_cast(permitType)); +} + +std::optional +Configuration::getPaymentOptionForKey(int permitType) const { + std::optional value; + + for (std::multimap::const_iterator it = this->PaymentOption.cbegin(); + it != this->PaymentOption.cend(); ++it) { + ATBPaymentOption const &paymentOption = it->second; + if (paymentOption.pop_product_id == permitType) { + value = value.value_or(paymentOption); + break; + } + } + + return value; +} + +std::optional +Configuration::getPaymentOptionForKey(QString const &permitTypeStr) const { + PERMIT_TYPE permitType = PermitType::toPermitType(permitTypeStr); + return getPaymentOptionForKey(static_cast(permitType)); +} + std::optional> Configuration::getPaymentRateForAllKeys() const { QVector paymentRates;