2024-03-03 11:20:35 +01:00
|
|
|
#include "tariff_editor.h"
|
|
|
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPair>
|
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
|
|
|
TariffEditor::TariffEditor() {
|
|
|
|
m_doc = QJsonDocument();
|
|
|
|
// m_doc.setObject(QJsonObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject TariffEditor::create(QString const &key) {
|
|
|
|
QJsonArray a;
|
|
|
|
if (key.compare("TariffType", Qt::CaseInsensitive) == 0) {
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("tariff_type_id"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_type_label"), QJsonValue("uniform-to-the-minute")),
|
|
|
|
QPair(QString("comment"), QJsonValue("same price for all computational units, typically minutes"))}));
|
|
|
|
} else
|
|
|
|
if (key.compare("TariffAccuracy", Qt::CaseInsensitive) == 0) {
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("tariff_accuracy_id"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_accuracy_label"), QJsonValue("computation per minute")),
|
|
|
|
QPair(QString("tariff_accuracy_value"), QJsonValue(1)),
|
|
|
|
QPair(QString("comment"), QJsonValue("accuracy of tariff computation is individual minutes"))
|
|
|
|
}));
|
|
|
|
} else
|
|
|
|
if (key.compare("TariffPrice", Qt::CaseInsensitive) == 0) {
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("tariff_price_id"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_price"), QJsonValue(165)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("price per hour as entered by customer"))
|
|
|
|
}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("tariff_price_id"), QJsonValue(2)),
|
|
|
|
QPair(QString("tariff_price"), QJsonValue(990)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("price for dayticket as entered by customer"))
|
|
|
|
}));
|
|
|
|
} else
|
|
|
|
if (key.compare("TariffConfig", Qt::CaseInsensitive) == 0) {
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("tariff_config_id"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_config_label"), QJsonValue("Tariff-Config")),
|
|
|
|
QPair(QString("tariff_config_accuracy"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_config_type"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_config_carry_over"), QJsonValue(true)),
|
|
|
|
QPair(QString("tariff_config_prepaid"), QJsonValue(true))
|
|
|
|
}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("MinimalTime"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("value"), QJsonValue(15)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("minimal parking time in minutes (net)"))})))}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("MaximalTime"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("value"), QJsonValue(360)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("maximal parking time in minutes (net)"))})))}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("MinimalPrice"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("value"), QJsonValue(15)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("customer entered price (for hour) expressed in minimal time: 15*(165/60) = 41.25"))})))}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("MaximalPrice"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("value"), QJsonValue(990)),
|
|
|
|
QPair(QString("editable"), QJsonValue(true)),
|
|
|
|
QPair(QString("comment"), QJsonValue("customer entered price (for hour) expressed in maximal time: 15*(165/60) = 41.25"))})))}));
|
|
|
|
} else
|
|
|
|
if (key.compare("TariffProducts", Qt::CaseInsensitive) == 0) {
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("ShortTimeParking"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("tariff_product_id"), QJsonValue(1)),
|
|
|
|
QPair(QString("tariff_product_price_id"), QJsonValue(1))})))}));
|
|
|
|
a.push_back(QJsonObject({
|
|
|
|
QPair(QString("DayTicket"),
|
|
|
|
QJsonValue(QJsonObject({
|
|
|
|
QPair(QString("tariff_product_id"), QJsonValue(2)),
|
|
|
|
QPair(QString("tariff_product_price_id"), QJsonValue(2))})))}));
|
|
|
|
} else
|
|
|
|
if (key.compare("TimeRanges", Qt::CaseInsensitive) == 0) {
|
|
|
|
// if prepaid, unrestricted
|
|
|
|
QJsonArray b;
|
|
|
|
|
|
|
|
QJsonValue v;
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100001)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
|
|
|
|
|
|
|
v = QJsonObject({QPair(QString("Block-Start-0"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100002)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))}),
|
|
|
|
v = QJsonObject({QPair(QString("Block-End-0"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100003)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("08:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
|
|
|
v = QJsonObject({QPair(QString("Block-Start-1"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100004)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("18:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))});
|
|
|
|
v = QJsonObject({QPair(QString("Block-End-1"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100005)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("08:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
|
|
|
v = QJsonObject({QPair(QString("Block-Start-1"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
v = QJsonObject({
|
|
|
|
QPair(QString("tariff_range_id"), QJsonValue(100006)),
|
|
|
|
QPair(QString("tariff_range_start"), QJsonValue("12:00:00")),
|
|
|
|
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
|
|
|
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
|
|
|
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))});
|
|
|
|
v = QJsonObject({QPair(QString("Block-End-1"), v)});
|
|
|
|
b.append(v);
|
|
|
|
|
|
|
|
a.push_back(QJsonObject({QPair(QString("OperationTimes"), b)}));
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
"time_range_id": 100001,
|
|
|
|
"time_range_start": "00:00:00",
|
|
|
|
"time_range_end": "00:00:00",
|
|
|
|
"time_range_start_minute": 0,
|
|
|
|
"time_range_end_minute": 1440,
|
|
|
|
"time_range_price_id": 2,
|
|
|
|
"comment": "[ 00:00-00:00 [ = [ 00:00-24:00 ["
|
|
|
|
},
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return QJsonObject({QPair(key, QJsonValue(a))});
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument &TariffEditor::writeToDocument(QJsonObject const &object) {
|
|
|
|
QJsonArray a = m_doc.array();
|
|
|
|
a.push_back(object);
|
|
|
|
//a.push_back(object);
|
|
|
|
//a.push_back(QJsonObject(std::initializer_list{QPair(key, value)}));
|
|
|
|
m_doc.setArray(a);
|
|
|
|
return m_doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument &TariffEditor::writeToDocument(QString const &key, QString const &value) {
|
|
|
|
return writeToDocument(std::initializer_list{QPair(key, QJsonValue(value))});
|
|
|
|
}
|