Added parsing for Interpolation, CarryOver and Prepaid-options. Has to be formatted.w

This commit is contained in:
Gerhard Hoffmann 2024-07-19 14:09:04 +02:00
parent f2356bec55
commit 2a89f90745

View File

@ -6,6 +6,7 @@
#include "tariff_permit_type.h"
#include "tariff_business_hours.h"
#include "tariff_global_defines.h"
#include "tariff_carryover.h"
#include <QString>
#include <QDebug>
@ -14,75 +15,78 @@
/// <inheritdoc/>
MemberType Configuration::IdentifyJsonMember(const char* member_name)
{
if (strcmp(member_name, "Currency") == 0) return MemberType::CurrencyType;
if (strcmp(member_name, "PaymentMethod") == 0) return MemberType::PaymentMethodType;
if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
//if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
if (strcmp(member_name, "PeriodYear") == 0) return MemberType::PeriodYearType;
if (strcmp(member_name, "Currency") == 0) return MemberType::CurrencyType;
if (strcmp(member_name, "PaymentMethod") == 0) return MemberType::PaymentMethodType;
if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
//if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
if (strcmp(member_name, "PeriodYear") == 0) return MemberType::PeriodYearType;
if (strcmp(member_name, "DailyTicket") == 0) return MemberType::DailyTicketType;
if (strcmp(member_name, "TimeBase") == 0) return MemberType::TimeBaseType;
if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType;
if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType;
if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType;
if (strcmp(member_name, "Product") == 0) return MemberType::ProductType;
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;
else return MemberType::UnknownType;
}
/// <inheritdoc/>
bool Configuration::ParseJson(Configuration* cfg, const char* json)
{
try
{
if (cfg == nullptr)
{
printf("TariffConfiguration pointer not set\n");
return false;
}
if (json == NULL)
{
printf("%s", "Input JSON string is NULL\n");
return false;
}
try
{
if (cfg == nullptr)
{
printf("TariffConfiguration pointer not set\n");
return false;
}
if (json == NULL)
{
printf("%s", "Input JSON string is NULL\n");
return false;
}
// Parse JSON to document
Document document;
document.Parse(json);
// Parse JSON to document
Document document;
document.Parse(json);
// Return if parse error has been found
ParseErrorCode err = document.GetParseError();
if (err != 0)
{
printf("%s %d (%s)\n", "Unable to parse JSON, error code:", err, GetParseError_En(err));
return false;
}
// Return if parse error has been found
ParseErrorCode err = document.GetParseError();
if (err != 0)
{
printf("%s %d (%s)\n", "Unable to parse JSON, error code:", err, GetParseError_En(err));
return false;
}
// Validate JSON, check if it's a JSON object
// Validate JSON, check if it's a JSON object
qCritical() << "JSON parsing has been successful";
if (!document.IsObject()) {
printf("%s", "Error: not a (valid) JSON object\n");
return false;
}
if (!document.IsObject()) {
printf("%s", "Error: not a (valid) JSON object\n");
return false;
}
qCritical() << "Valid JSON object identified";
// Validate JSON, check configuration members
if (!document.HasMember("Currency")
|| !document.HasMember("PaymentMethod")
|| !document.HasMember("PaymentOption")
|| !document.HasMember("PaymentRate")
|| !document.HasMember("Duration")
//|| !document.HasMember("WeekDays")
// Validate JSON, check configuration members
if (!document.HasMember("Currency")
|| !document.HasMember("PaymentMethod")
|| !document.HasMember("PaymentOption")
|| !document.HasMember("PaymentRate")
|| !document.HasMember("Duration")
//|| !document.HasMember("WeekDays")
//|| !document.HasMember("SpecialDaysWorktime")
//|| !document.HasMember("SpecialDays")
)
{
printf("%s", "Error: not a valid configuration JSON\n");
return false;
}
{
printf("%s", "Error: not a valid configuration JSON\n");
return false;
}
qCritical() << "Valid JSON configuration identified";
ATBCurrency Currency;
@ -100,16 +104,19 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBTimeRange TimeRange;
ATBTimeStepConfig TimeStepConfig;
ATBTariffProduct TariffProduct;
ATBInterpolation TariffInterpolation;
ATBPrepaid TariffPrepaidOption;
ATBCarryOver TariffCarryOver;
MemberType mb_type = MemberType::UnknownType;
this->currentPaymentOptions.clear();
// Get all JSON object members
// This code should run only once (to load JSON variables into memory)
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
{
// Get name of all general members of JSON, don't print name if NULL
const char* mb_name = i->name.GetString();
// Get all JSON object members
// This code should run only once (to load JSON variables into memory)
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
{
// Get name of all general members of JSON, don't print name if NULL
const char* mb_name = i->name.GetString();
if (mb_name == NULL) continue;
if (document[mb_name].IsString()) {
@ -135,35 +142,196 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
qCritical() << " -" << mb_name;
// Get array for each JSON object member
auto mb_array = document[mb_name].GetArray();
if (mb_array.Size() <= 0) break;
// Get array for each JSON object member
auto mb_array = document[mb_name].GetArray();
if (mb_array.Size() <= 0) break;
//Iterate over provided array
//Iterate over provided array
for (rapidjson::SizeType j = 0; j < mb_array.Size(); j++)
{
// Get all inner objects, don't print name if NULL
auto inner_obj = mb_array[j].GetObject();
if (inner_obj.MemberCount() <= 0) break;
{
// Get all inner objects, don't print name if NULL
auto inner_obj = mb_array[j].GetObject();
if (inner_obj.MemberCount() <= 0) break;
// Iterate over inner object JSON members
for (auto k = inner_obj.MemberBegin(); k != inner_obj.MemberEnd(); k++)
{
// Get inner object JSON member, don't print name if NULL
const char* inner_obj_name = k->name.GetString();
if (inner_obj_name == NULL)
{
printf("Inner object name is NULL\n");
continue;
}
// Iterate over inner object JSON members
for (auto k = inner_obj.MemberBegin(); k != inner_obj.MemberEnd(); k++)
{
// Get inner object JSON member, don't print name if NULL
const char* inner_obj_name = k->name.GetString();
if (inner_obj_name == NULL)
{
printf("Inner object name is NULL\n");
continue;
}
// Identify member type
mb_type = IdentifyJsonMember(mb_name);
// Identify member type
mb_type = IdentifyJsonMember(mb_name);
switch (mb_type)
{
case MemberType::UnknownType:
break;
switch (mb_type)
{
case MemberType::UnknownType:
break;
case MemberType::CarryOverType: {
if (QString(inner_obj_name) == QString("carry_over_id")) {
if (k->value.IsInt()) {
int const &x = k->value.GetInt();
TariffCarryOver.id = x;
}
} else
if (QString(inner_obj_name) == QString("carry_over_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 == "carry_over_day") {
if (w->value.IsInt()) {
rapidjson::SizeType const d = w->value.GetInt();
if (d != (j+1)) {
qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
}
TariffCarryOver.carryover[day].day = day;
}
} else
if (member == "carry_over_seemless") {
if (w->value.IsBool()) {
bool b = w->value.GetBool();
TariffCarryOver.carryover[day].seemless = b;
}
} else
if (member == "carry_over_never") {
if (w->value.IsBool()) {
bool b = w->value.GetBool();
TariffCarryOver.carryover[day].never = b;
}
} else
if (member == "carry_over_static_start") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffCarryOver.carryover[day].static_start = t;
}
} else
if (member == "carry_over_static_end") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffCarryOver.carryover[day].static_end = t;
}
}
}
}
}
}
}
} break;
case MemberType::PrepaidType: {
if (QString(inner_obj_name) == QString("prepaid_id")) {
if (k->value.IsInt()) {
int const &x = k->value.GetInt();
TariffPrepaidOption.id = x;
}
} else
if (QString(inner_obj_name) == QString("prepaid_anytime")) {
if (k->value.IsBool()) {
bool const &x = k->value.GetBool();
TariffPrepaidOption.anytime = x;
}
} else
if (QString(inner_obj_name) == QString("prepaid_never")) {
if (k->value.IsBool()) {
bool const &x = k->value.GetBool();
TariffPrepaidOption.never = x;
}
} else
if (QString(inner_obj_name) == QString("prepaid_static_start")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffPrepaidOption.static_start = t;
}
} else
if (QString(inner_obj_name) == QString("prepaid_static_end")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffPrepaidOption.static_end = t;
}
}
} break;
case MemberType::InterpolationType: {
if (QString(inner_obj_name) == QString("interpol_id")) {
if (k->value.IsInt()) {
int const &x = k->value.GetInt();
TariffInterpolation.id = x;
}
} else
if (QString(inner_obj_name) == QString("interpol_static_start")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffInterpolation.static_start = t;
}
} else
if (QString(inner_obj_name) == QString("interpol_static_end")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffInterpolation.static_end = t;
}
} else
if (QString(inner_obj_name) == QString("interpol_static_start_str")) {
if (k->value.IsString()) {
QString const &s = k->value.GetString();
TariffInterpolation.static_start_str = s;
}
} else
if (QString(inner_obj_name) == QString("interpol_static_end_str")) {
if (k->value.IsString()) {
QString const &s = k->value.GetString();
TariffInterpolation.static_end_str = s;
}
} else
if (QString(inner_obj_name) == QString("interpol_static_duration")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffInterpolation.static_duration = x;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_start")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffInterpolation.dynamic_start = t;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_end")) {
if (k->value.IsString()) {
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffInterpolation.dynamic_end = t;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_start_str")) {
if (k->value.IsString()) {
QString const &s = k->value.GetString();
TariffInterpolation.dynamic_start_str = s;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_end_str")) {
if (k->value.IsString()) {
QString const &s = k->value.GetString();
TariffInterpolation.dynamic_end_str = s;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_duration")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffInterpolation.dynamic_duration = x;
}
} else
if (QString(inner_obj_name) == QString("interpol_dynamic_until_price")) {
if (k->value.IsInt()) {
int const x = k->value.GetInt();
TariffInterpolation.dynamic_until_price = x;
}
}
} break;
case MemberType::ProductType: {
if (QString(inner_obj_name) == QString("tariff_product_id")) {
if (k->value.IsInt()) {
@ -375,22 +543,22 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
}
break;
case MemberType::CurrencyType:
if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
break;
case MemberType::PaymentMethodType:
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
break;
case MemberType::PaymentRateType:
if (strcmp(inner_obj_name, "pra_payment_option_id") == 0) PaymentRate.pra_payment_option_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pra_payment_unit_id") == 0) PaymentRate.pra_payment_unit_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pra_price") == 0) PaymentRate.pra_price = k->value.GetDouble();
break;
case MemberType::PaymentOptionType:
if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
break;
case MemberType::PaymentMethodType:
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
break;
case MemberType::PaymentRateType:
if (strcmp(inner_obj_name, "pra_payment_option_id") == 0) PaymentRate.pra_payment_option_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pra_payment_unit_id") == 0) PaymentRate.pra_payment_unit_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pra_price") == 0) PaymentRate.pra_price = k->value.GetDouble();
break;
case MemberType::PaymentOptionType:
if (strcmp(inner_obj_name, "pop_id") == 0) {
this->currentPaymentOptions.append(ATBPaymentOption());
this->currentPaymentOptions.last().reset();
@ -413,6 +581,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) {
this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_carry_over_option_id") == 0) {
this->currentPaymentOptions.last().pop_carry_over_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_carry_over") == 0) {
this->currentPaymentOptions.last().pop_carry_over = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) {
@ -493,91 +665,93 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
}
}
break;
case MemberType::DurationType:
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pun_duration") == 0) Duration.pun_duration = k->value.GetDouble();
case MemberType::DurationType:
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pun_duration") == 0) Duration.pun_duration = k->value.GetDouble();
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();
break;
case MemberType::SpecialDaysWorktimeType:
if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pedwt_period_exc_day_id") == 0) SpecialDaysWorktime.pedwt_period_exc_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pedwt_time_from") == 0) SpecialDaysWorktime.pedwt_time_from = k->value.GetString();
else if (strcmp(inner_obj_name, "pedwt_time_to") == 0) SpecialDaysWorktime.pedwt_time_to = k->value.GetString();
else if (strcmp(inner_obj_name, "pedwt_price") == 0) SpecialDaysWorktime.pedwt_price = k->value.GetDouble();
break;
/*case MemberType::WeekDaysType:
if (strcmp(inner_obj_name, "pdiw_id") == 0) WeekDays.pdiw_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pdiw_label") == 0) WeekDays.pdiw_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pdiw_index") == 0) WeekDays.pdiw_index = k->value.GetInt();
break;*/
case MemberType::WeekDaysWorkTimeType:
if (strcmp(inner_obj_name, "pwd_id") == 0) WeekDaysWorktime.pwd_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_week_day_id") == 0) WeekDaysWorktime.pwd_period_week_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_day_in_week_id") == 0) WeekDaysWorktime.pwd_period_day_in_week_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_time_from") == 0) WeekDaysWorktime.pwd_time_from = k->value.GetString();
case MemberType::SpecialDaysWorktimeType:
if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pedwt_period_exc_day_id") == 0) SpecialDaysWorktime.pedwt_period_exc_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pedwt_time_from") == 0) SpecialDaysWorktime.pedwt_time_from = k->value.GetString();
else if (strcmp(inner_obj_name, "pedwt_time_to") == 0) SpecialDaysWorktime.pedwt_time_to = k->value.GetString();
else if (strcmp(inner_obj_name, "pedwt_price") == 0) SpecialDaysWorktime.pedwt_price = k->value.GetDouble();
break;
/*case MemberType::WeekDaysType:
if (strcmp(inner_obj_name, "pdiw_id") == 0) WeekDays.pdiw_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pdiw_label") == 0) WeekDays.pdiw_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pdiw_index") == 0) WeekDays.pdiw_index = k->value.GetInt();
break;*/
case MemberType::WeekDaysWorkTimeType:
if (strcmp(inner_obj_name, "pwd_id") == 0) WeekDaysWorktime.pwd_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_week_day_id") == 0) WeekDaysWorktime.pwd_period_week_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_day_in_week_id") == 0) WeekDaysWorktime.pwd_period_day_in_week_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_time_from") == 0) WeekDaysWorktime.pwd_time_from = k->value.GetString();
else if (strcmp(inner_obj_name, "pwd_time_to") == 0) WeekDaysWorktime.pwd_time_to = k->value.GetString();
break;
case MemberType::SpecialDaysType:
if (strcmp(inner_obj_name, "ped_id") == 0) SpecialDays.ped_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "ped_label") == 0) SpecialDays.ped_label = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_date_start") == 0) SpecialDays.ped_date_start = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_date_end") == 0) SpecialDays.ped_date_end = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_period_special_day_id") == 0) SpecialDays.ped_period_special_day_id = k->value.GetInt();
case MemberType::SpecialDaysType:
if (strcmp(inner_obj_name, "ped_id") == 0) SpecialDays.ped_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "ped_label") == 0) SpecialDays.ped_label = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_date_start") == 0) SpecialDays.ped_date_start = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_date_end") == 0) SpecialDays.ped_date_end = k->value.GetString();
else if (strcmp(inner_obj_name, "ped_period_special_day_id") == 0) SpecialDays.ped_period_special_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "ped_payment_option_id") == 0) SpecialDays.ped_payment_option_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "ped_year") == 0) SpecialDays.ped_year = k->value.GetInt();
break;
case MemberType::PeriodYearType:
if (strcmp(inner_obj_name, "pye_id") == 0) YearPeriod.pye_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_label") == 0) YearPeriod.pye_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pye_start_month") == 0) YearPeriod.pye_start_month = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_start_day") == 0) YearPeriod.pye_start_day = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_end_month") == 0) YearPeriod.pye_end_month = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_end_day") == 0) YearPeriod.pye_end_day = k->value.GetInt();
break;
default:
break;
}
break;
case MemberType::PeriodYearType:
if (strcmp(inner_obj_name, "pye_id") == 0) YearPeriod.pye_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_label") == 0) YearPeriod.pye_label = k->value.GetString();
else if (strcmp(inner_obj_name, "pye_start_month") == 0) YearPeriod.pye_start_month = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_start_day") == 0) YearPeriod.pye_start_day = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_end_month") == 0) YearPeriod.pye_end_month = k->value.GetInt();
else if (strcmp(inner_obj_name, "pye_end_day") == 0) YearPeriod.pye_end_day = k->value.GetInt();
break;
default:
break;
}
//#pragma endregion
}
}
// Push to specific list depending on member type
switch (mb_type)
{
case MemberType::UnknownType:
break;
case MemberType::PaymentMethodType:
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
break;
// Push to specific list depending on member type
switch (mb_type)
{
case MemberType::UnknownType:
break;
case MemberType::PaymentMethodType:
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
break;
case MemberType::PaymentRateType:
// qCritical() << "PaymentRate" << PaymentRate;
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
break;
break;
case MemberType::PaymentOptionType: {
if (!this->currentPaymentOptions.isEmpty()) {
ATBPaymentOption const &PaymentOption = this->currentPaymentOptions.last();
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
}
} break;
case MemberType::DurationType:
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
break;
case MemberType::SpecialDaysWorktimeType:
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
break;
//case MemberType::WeekDaysType:
// cfg->WeekDays.insert(pair<int, ATBWeekDays>(WeekDays.pdiw_index, WeekDays));
// break;
case MemberType::WeekDaysWorkTimeType:
cfg->WeekDaysWorktime.insert(pair<int, ATBWeekDaysWorktime>(WeekDaysWorktime.pwd_period_day_in_week_id, WeekDaysWorktime));
break;
case MemberType::SpecialDaysType:
cfg->SpecialDays.insert(pair<int, ATBSpecialDays>(SpecialDays.ped_id, SpecialDays));
break;
case MemberType::PeriodYearType:
cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod));
break;
case MemberType::DurationType:
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
// qCritical() << Duration;
break;
case MemberType::SpecialDaysWorktimeType:
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
break;
//case MemberType::WeekDaysType:
// cfg->WeekDays.insert(pair<int, ATBWeekDays>(WeekDays.pdiw_index, WeekDays));
// break;
case MemberType::WeekDaysWorkTimeType:
cfg->WeekDaysWorktime.insert(pair<int, ATBWeekDaysWorktime>(WeekDaysWorktime.pwd_period_day_in_week_id, WeekDaysWorktime));
break;
case MemberType::SpecialDaysType:
cfg->SpecialDays.insert(pair<int, ATBSpecialDays>(SpecialDays.ped_id, SpecialDays));
break;
case MemberType::PeriodYearType:
cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod));
break;
case MemberType::DailyTicketType:
cfg->DailyTicket.insert(pair<int, ATBDailyTicket>(DailyTicket.daily_ticket_id, DailyTicket));
qCritical() << DailyTicket;
@ -602,17 +776,30 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
case MemberType::ProductType:
cfg->TariffProduct.insert(pair<int, ATBTariffProduct>(TariffProduct.m_tariff_product_id, TariffProduct));
qCritical() << TariffProduct;
break;
case MemberType::InterpolationType:
cfg->TariffInterpolations.insert(pair<int, ATBInterpolation>(TariffInterpolation.id, TariffInterpolation));
qCritical() << TariffInterpolation;
break;
case MemberType::PrepaidType:
cfg->TariffPrepaidOptions.insert(pair<int, ATBPrepaid>(TariffPrepaidOption.id, TariffPrepaidOption));
qCritical() << TariffPrepaidOption;
break;
case MemberType::CarryOverType:
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
qCritical() << TariffCarryOver;
break;
default:
break;
}
}
}
return true;
}
catch (...) {
printf("%s\n", "General exception has occurred while parsing JSON\n");
return false;
}
break;
}
}
}
return true;
}
catch (...) {
printf("%s\n", "General exception has occurred while parsing JSON\n");
return false;
}
}
int Configuration::getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const {
@ -840,6 +1027,47 @@ Configuration::getDailyTicketsForAllKeys() const {
return value;
}
std::optional<ATBInterpolation> Configuration::getInterpolationType(int key) const {
std::optional<ATBInterpolation> value;
for (auto[it, rangeEnd] = this->TariffInterpolations.equal_range(key); it != rangeEnd; ++it) {
value = value.value_or(it->second);
}
return value;
}
std::optional<ATBPrepaid> Configuration::getPrepaidType(int key) const {
std::optional<ATBPrepaid> value;
for (auto[it, rangeEnd] = this->TariffPrepaidOptions.equal_range(key); it != rangeEnd; ++it) {
value = value.value_or(it->second);
}
return value;
}
std::optional<QDateTime> Configuration::adaptStart(QDateTime const &start, int prepaid_option_id) {
std::optional<QDateTime> value;
QDateTime s = start;
std::optional<ATBPrepaid> prepaid_option = getPrepaidType(prepaid_option_id);
if (prepaid_option.has_value()) {
ATBPrepaid prepaid = prepaid_option.value();
if (prepaid.anytime == true) {
int const weekdayId = s.date().dayOfWeek();
QTime worktime_from = QTime::fromString(WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str(), Qt::ISODate);
QTime worktime_to = QTime::fromString(WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str(), Qt::ISODate);
if (s.time() < worktime_from) {
s.setTime(worktime_from);
} else
if (worktime_to < s.time()) {
s = start.addDays(1);
s.setTime(worktime_from);
}
s.setTime(QTime(s.time().hour(), s.time().minute(), 0));
value = value.value_or(s);
}
}
return value;
}
std::optional<QVector<ATBDailyTicket>>
Configuration::getDailyTicketsForKey(int key) const {
QVector<ATBDailyTicket> tickets;