Add interface to access 'PaymentOptions'
This commit is contained in:
parent
cd77e380ef
commit
3a2e521345
@ -49,6 +49,8 @@ public:
|
|||||||
/// <returns>Returns operation status bool (OK | FAIL) </returns>
|
/// <returns>Returns operation status bool (OK | FAIL) </returns>
|
||||||
bool ParseJson(Configuration* cfg, const char* json);
|
bool ParseJson(Configuration* cfg, const char* json);
|
||||||
|
|
||||||
|
ATBPaymentOption const & getPaymentOptions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Identify type of JSON member
|
/// Identify type of JSON member
|
||||||
@ -56,4 +58,6 @@ private:
|
|||||||
/// <param name="member_name"></param>
|
/// <param name="member_name"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
MemberType IdentifyJsonMember(const char* member_name);
|
MemberType IdentifyJsonMember(const char* member_name);
|
||||||
|
|
||||||
|
ATBPaymentOption currentPaymentOptions;
|
||||||
};
|
};
|
||||||
|
@ -100,8 +100,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
time_t end_parking_time, // netto time in minutes
|
time_t end_parking_time, // netto time in minutes
|
||||||
struct price_t *price) {
|
struct price_t *price) {
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_time;
|
||||||
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_max_time;
|
||||||
|
|
||||||
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
|
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
|
||||||
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
|
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
|
||||||
@ -134,11 +134,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
QDateTime end(start);
|
QDateTime end(start);
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff, PaymentOption::Option1,
|
tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
duration, false, true);
|
duration, false, true);
|
||||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_price;
|
||||||
if (cost < minCost) {
|
if (cost < minCost) {
|
||||||
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
|
||||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
||||||
@ -160,8 +161,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
struct price_t *price)
|
struct price_t *price)
|
||||||
{
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
double minMin = tariff->getPaymentOptions().pop_min_time;
|
||||||
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
double maxMin = tariff->getPaymentOptions().pop_max_time;
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << "compute_price_for_parking_ticket() " << endl
|
qCritical() << "compute_price_for_parking_ticket() " << endl
|
||||||
@ -192,12 +193,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
|
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff, PaymentOption::Option1,
|
tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start_parking_time, // starting time
|
start_parking_time, // starting time
|
||||||
end_parking_time, // return value: end time
|
end_parking_time, // return value: end time
|
||||||
netto_parking_time, // minutes, netto
|
netto_parking_time, // minutes, netto
|
||||||
false, true);
|
false, true);
|
||||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
double minCost = tariff->getPaymentOptions().pop_min_price;
|
||||||
if (cost < minCost) {
|
if (cost < minCost) {
|
||||||
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
||||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
||||||
@ -233,7 +235,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
qCritical() << " start (cs): " << cs;
|
qCritical() << " start (cs): " << cs;
|
||||||
qCritical() << " price: " << price;
|
qCritical() << " price: " << price;
|
||||||
|
|
||||||
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
duration = calculator.GetDurationFromCost(tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
price, false, true).c_str();
|
price, false, true).c_str();
|
||||||
QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
|
QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
|
||||||
@ -258,7 +261,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
QString endTime = calculator.GetDurationFromCost(
|
QString endTime = calculator.GetDurationFromCost(
|
||||||
tariff, PaymentOption::Option1,
|
tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
price, false, true).c_str();
|
price, false, true).c_str();
|
||||||
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
||||||
@ -286,7 +290,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
|
|||||||
|
|
||||||
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
||||||
start_parking_time,
|
start_parking_time,
|
||||||
PaymentOption::Option1,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
false); // carry over
|
false); // carry over
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
|
@ -378,12 +378,11 @@ uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
|
|||||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||||
{
|
{
|
||||||
// condition for 'PaymentMethod::Steps' (e.g. 332/Schoenau):
|
// condition for 'PaymentMethod::Steps' (e.g. 332/Schoenau):
|
||||||
if (payment_option == PaymentOption::Option1
|
if (cfg->SpecialDays.size() == 0
|
||||||
&& cfg->SpecialDays.size() == 0
|
|
||||||
&& cfg->SpecialDaysWorktime.size() == 0)
|
&& cfg->SpecialDaysWorktime.size() == 0)
|
||||||
{
|
{
|
||||||
QDateTime const end = start_datetime.addSecs(durationMin*60);
|
end_datetime = start_datetime.addSecs(durationMin*60);
|
||||||
return GetCostFromDuration(cfg, start_datetime, end, PaymentMethod::Steps);
|
return GetCostFromDuration(cfg, start_datetime, end_datetime, PaymentMethod::Steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get input date
|
// Get input date
|
||||||
|
@ -169,6 +169,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
|
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
|
||||||
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
|
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
|
||||||
else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
|
else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
|
||||||
|
this->currentPaymentOptions = PaymentOption;
|
||||||
break;
|
break;
|
||||||
case MemberType::DurationType:
|
case MemberType::DurationType:
|
||||||
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
||||||
@ -259,3 +260,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const ATBPaymentOption & Configuration::getPaymentOptions()
|
||||||
|
{
|
||||||
|
return this->currentPaymentOptions;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user