Use of permitType in several places

This commit is contained in:
Gerhard Hoffmann 2024-07-25 09:48:12 +02:00
parent 003b7e8e8a
commit b0ecef0361

View File

@ -34,6 +34,8 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) {
int minTime = 0;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minTime = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
@ -58,6 +60,8 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int maxTime = 0;
switch(permitType) {
@ -71,10 +75,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
case PERMIT_TYPE::DAY_TICKET_CHILD: {
} break;
default: ;
maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
}
return maxTime;
}
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
@ -82,6 +86,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
@ -96,7 +101,8 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
case PERMIT_TYPE::DAY_TICKET: {
minPrice = compute_product_price(cfg, permitType, start);
} break;
default: ;
default:
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
}
return minPrice;
@ -214,7 +220,14 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW: {
qCritical() << "TODO: SHORT_TERM_PARKING_PKW";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "SHORT_TERM_PARKING_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS: {
qCritical() << "TODO: SHORT_TERM_PARKING_BUS";
@ -223,15 +236,34 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
qCritical() << "TODO: SHORT_TERM_PARKING_CAMPER";
} break;
case PERMIT_TYPE::DAY_TICKET_PKW: {
int const pop_daily_card_price = cfg->getPaymentOptions().pop_daily_card_price;
qCritical() << "DAY_TICKET_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::DAY_TICKET_BUS: {
qCritical() << "TODO: DAY_TICKET_BUS";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_BUS: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::DAY_TICKET_CAMPER: {
qCritical() << "TODO: DAY_TICKET_CAMPER";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_CAMPER: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
default:
break;
@ -246,6 +278,8 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
@ -269,6 +303,18 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
break;
case PERMIT_TYPE::DAY_TICKET_CHILD:
break;
case PERMIT_TYPE::DAY_TICKET_BUS:
break;
case PERMIT_TYPE::DAY_TICKET_CAMPER:
break;
case PERMIT_TYPE::DAY_TICKET_PKW:
break;
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS:
break;
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW:
break;
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER:
break;
default: ;
}
@ -359,11 +405,22 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
//
// UpDown 1 -> up; 0 -> down
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes,
int UpDown, PermitType const &permitType)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
if (!paymentOption.has_value()) {
return currentTimeMinutes;
}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
qCritical() << " compute_next_timestep() payment option index: " << paymentOptionIndex;
Configuration const *cfg = tariff;
// compute payment method id (e.g. Linear=3, Steps=4)
@ -392,7 +449,9 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
(paymentMethodId == PaymentMethod::Progressive))
{
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff);
// int paymentOptionIndex = 1;
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
int const size = stepList.size();
if (size == 0) {
qCritical() << "compute_next_timestep() *ERROR empty step-list*";
@ -482,12 +541,16 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// this is currently not used
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
time_t start_parking_time, // in minutes
time_t end_parking_time, // netto time in minutes
struct price_t *price) {
time_t start_parking_time, // in minutes
time_t end_parking_time, // netto time in minutes
struct price_t *price,
PermitType permitType) { // permitType maps to product
CalcState calcState;
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_max_time;
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
@ -520,13 +583,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
if (start.isValid()) {
double cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id,
start,
end,
duration, false, true);
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_price;
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_price;
if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
calcState.setDesc(QString("line=%1 minCost=%2, cost=%3").arg(__LINE__).arg(minCost).arg(cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
}
price->units = cost;
@ -544,6 +607,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
int netto_parking_time,
QDateTime &end_parking_time,
struct price_t *price,
PermitType /* permitType */,
bool prepaid)
{
CalcState calcState;
@ -609,7 +673,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
}
double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price;
if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
calcState.setDesc(QString("line=%1 minCost=%2, cost=%3").arg(__LINE__).arg(minCost).arg(cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
}
@ -632,7 +696,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
parking_tariff_t *tariff,
time_t start_parking_time,
double price,
QString &duration) {
QString &duration,
PermitType permitType) {
CalcState calcState;
QDate const d(1970, 1, 1);
QTime const t(0, 0, 0);
@ -666,7 +731,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime const &start_parking_time,
double price,
QDateTime &ticketEndTime)
QDateTime &ticketEndTime,
PermitType permitType)
{
CalcState calcState;
if (start_parking_time.isValid()) {
@ -754,7 +820,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
return calcState.set(CalcState::State::SUCCESS);
}
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff, QDateTime const &start_parking_time, QDateTime &ticketEndTime)
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
QDateTime const &start_parking_time,
QDateTime &ticketEndTime,
PermitType PermitType)
{
CalcState calcState;
if (start_parking_time.isValid()) {