From 0a32d60827b990f5b305eba83a3ffe6cfdd2faad Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 15 Aug 2024 21:23:17 +0200 Subject: [PATCH] Added parsing for new duration members and new prepaid-option. --- library/src/configuration.cpp | 87 ++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index c481ad2..3b1c8ea 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -7,6 +7,7 @@ #include "tariff_business_hours.h" #include "tariff_global_defines.h" #include "tariff_carryover.h" +#include "tariff_prepay.h" #include "tariff_global_defines.h" #include @@ -35,6 +36,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name) if (strcmp(member_name, "Interpolation") == 0) return MemberType::InterpolationType; if (strcmp(member_name, "Prepaid") == 0) return MemberType::PrepaidType; if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType; + if (strcmp(member_name, "PrepaidOption") == 0) return MemberType::PrepaidOptionType; else return MemberType::UnknownType; } @@ -108,6 +110,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) ATBInterpolation TariffInterpolation; ATBPrepaid TariffPrepaidOption; ATBCarryOver TariffCarryOver; + ATBPrepay TariffPrepayOption; MemberType mb_type = MemberType::UnknownType; this->currentPaymentOptions.clear(); @@ -171,6 +174,61 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) { case MemberType::UnknownType: break; + case MemberType::PrepaidOptionType: { + if (QString(inner_obj_name) == QString("prepaid_option_id")) { + if (k->value.IsInt()) { + int const &x = k->value.GetInt(); + TariffPrepayOption.id = x; + } + } else + if (QString(inner_obj_name) == QString("prepaid_option_week")) { + if (k->value.IsArray()) { + auto days = k->value.GetArray(); + for (rapidjson::SizeType j=0; j < days.Size(); ++j) { + if (days[j].IsObject()) { + auto weekday = days[j].GetObject(); + for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) { + int day = j+1; // 8 entries + QString member(QString::fromStdString(w->name.GetString())); + if (member == "prepaid_option_day") { + if (w->value.IsInt()) { + rapidjson::SizeType const d = w->value.GetInt(); + if (d != (j+1)) { + qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1); + } + TariffPrepayOption.prepay[day].day = day; + } + } else + if (member == "prepaid_option_duration") { + if (w->value.IsInt()) { + TariffPrepayOption.prepay[day].duration = w->value.GetInt(); + } + } else + if (member == "prepaid_option_prepaid") { + if (w->value.IsBool()) { + bool b = w->value.GetBool(); + TariffPrepayOption.prepay[day].prepaid = b; + } + } else + if (member == "prepaid_option_start") { + if (w->value.IsString()) { + QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate); + TariffPrepayOption.prepay[day].start = t; + } + } else + if (member == "prepaid_option_end") { + if (w->value.IsString()) { + QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate); + TariffPrepayOption.prepay[day].end = t; + } + } + } + } + } + } + + } + } break; case MemberType::CarryOverType: { if (QString(inner_obj_name) == QString("carry_over_id")) { if (k->value.IsInt()) { @@ -231,6 +289,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } } } break; + // deprecated case MemberType::PrepaidType: { if (QString(inner_obj_name) == QString("prepaid_id")) { if (k->value.IsInt()) { @@ -622,8 +681,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble(); } else if (strcmp(inner_obj_name, "pop_min_price") == 0) { this->currentPaymentOptions.last().pop_min_price = k->value.GetDouble(); - } else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) { + } else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) { // deprecated this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_prepay_option_id") == 0) { + this->currentPaymentOptions.last().pop_prepay_option_id = k->value.GetInt(); } else if (strcmp(inner_obj_name, "pop_truncate_last_interpolation_step") == 0) { this->currentPaymentOptions.last().pop_truncate_last_interpolation_step = k->value.GetBool(); } else if (strcmp(inner_obj_name, "pop_accumulate_prices") == 0) { @@ -721,6 +782,26 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } else if (strcmp(inner_obj_name, "pun_duration_min") == 0) Duration.pun_duration_min = k->value.GetInt(); else if (strcmp(inner_obj_name, "pun_duration_max") == 0) Duration.pun_duration_max = k->value.GetInt(); else if (strcmp(inner_obj_name, "pun_interpolation_id") == 0) Duration.pun_interpolation_id = k->value.GetInt(); + else if (strcmp(inner_obj_name, "pun_netto") == 0) { + if (k->value.IsBool()) { + Duration.pun_netto = k->value.GetBool(); + } + } + else if (strcmp(inner_obj_name, "pun_brutto") == 0) { + if (k->value.IsBool()) { + Duration.pun_brutto = k->value.GetBool(); + } + } + else if (strcmp(inner_obj_name, "pun_fixed") == 0) { + if (k->value.IsBool()) { + Duration.pun_fixed = k->value.GetBool(); + } + } + else if (strcmp(inner_obj_name, "pun_requires_change") == 0) { + if (k->value.IsBool()) { + Duration.pun_requires_change = k->value.GetBool(); + } + } break; case MemberType::SpecialDaysWorktimeType: if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt(); @@ -839,6 +920,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) cfg->TariffCarryOverOptions.insert(pair(TariffCarryOver.id, TariffCarryOver)); // qCritical() << TariffCarryOver; break; + case MemberType::PrepaidOptionType: + cfg->TariffPrepayOptions.insert(pair(TariffPrepayOption.id, TariffPrepayOption)); + qCritical() << TariffPrepayOption; + break; default: break; }