Fixed pra_payment_unit_id

This commit is contained in:
Moran Rod 2023-05-17 10:08:02 +02:00
parent 617eee39ed
commit 7bd7f66666
5 changed files with 24 additions and 11 deletions

View File

@ -68,6 +68,6 @@ public:
/// </summary>
/// <param name="pra_price"></param>
/// <returns></returns>
static double CalculatePricePerUnit(double pra_price);
static double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
};

View File

@ -177,8 +177,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
else
{
// Set new price for the normal day
day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
// If no working day found, skip it (recursively call method again)
size_t found = 0;
@ -410,8 +414,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
else
{
// Set new price for the normal day
day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
// If no working day found, skip it (recursively call method again)
size_t found = 0;
@ -506,11 +515,12 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
return 0.0f;
}
int carry_over_status = 0;
carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
// Go to next day if minutes not spent
if(inputDate.time() >= worktime_to)
{
int carry_over_status = 0;
carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
if (carry_over_status < 1) break;
LOG_DEBUG("Reached end of worktime, searching for the next working day");

View File

@ -210,7 +210,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
break;
case MemberType::PaymentRateType:
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_unit_id, PaymentRate));
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
break;
case MemberType::PaymentOptionType:
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));

View File

@ -8,12 +8,15 @@ static int protection_counter = 0;
/// </summary>
/// <param name="pra_price"></param>
/// <returns></returns>
double Utilities::CalculatePricePerUnit(double pra_price)
double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit)
{
try
{
double price_per_unit = pra_price;
price_per_unit /= 60.0f; // Divided by 60 because price per unit is set per hour and we are using minutes
double unit = durationUnit;
if(unit < 0 || unit > 65535 ) unit = 60.0f;
price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes
//printf("Price per unit (min) is: %lf\n", price_per_unit);
return price_per_unit;
}

View File

@ -35,7 +35,7 @@ int main() {
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
time_t end_parking_time = start_parking_time + 1230;
time_t end_parking_time = start_parking_time + 615;
if (compute_price_for_parking_ticket(tariff,
start_parking_time,