Merge branch 'moransBranch'
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
enum DayOfWeek
|
||||
{
|
||||
Saturday = 0x06,
|
||||
Sunday = 0x01,
|
||||
Monday = 0x02,
|
||||
Tuesday = 0x02,
|
||||
Wednesday = 0x03,
|
||||
Thursday = 0x04,
|
||||
Friday = 0x05,
|
||||
UndefinedDay = 0xFF
|
||||
};
|
||||
Monday = 0x01,
|
||||
Tuesday = 0x02,
|
||||
Wednesday = 0x03,
|
||||
Thursday = 0x04,
|
||||
Friday = 0x05,
|
||||
Saturday = 0x06,
|
||||
Sunday = 0x07,
|
||||
UndefinedDay = 0xFF
|
||||
};
|
||||
|
@@ -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);
|
||||
|
||||
};
|
||||
|
@@ -182,8 +182,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;
|
||||
@@ -202,16 +206,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
if (price_per_unit < 0) price_per_unit = 1.0f;
|
||||
|
||||
if((price/price_per_unit) < minMin) return "PARKING NOT ALLOWED";
|
||||
// if((price/price_per_unit) < minMin) return "PARKING NOT ALLOWED";
|
||||
LOG_DEBUG("Calculated price per minute: ", price_per_unit);
|
||||
|
||||
if (price_per_unit < 0)
|
||||
{
|
||||
inputDate = inputDate.addDays(1);
|
||||
inputDate.setTime(worktime_from);
|
||||
return GetDurationFromCost(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), money_left, true);
|
||||
}
|
||||
|
||||
// If overtime flag is set
|
||||
if (overtime || nextDay)
|
||||
{
|
||||
@@ -315,12 +312,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
// }
|
||||
|
||||
double ret_val = 0;
|
||||
double calc_price = (int)total_duration_min - (int)price / price_per_unit;
|
||||
// double calc_price = (int)total_duration_min - (int)price / price_per_unit;
|
||||
|
||||
if (calc_price > 0 && total_duration_min > 0)
|
||||
{
|
||||
inputDate = inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
||||
}
|
||||
//if (calc_price > 0 && total_duration_min > 0)
|
||||
//{
|
||||
// inputDate = inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
||||
//}
|
||||
|
||||
if(price >= min_price && total_duration_min >= minMin)
|
||||
qDebug() << "GetDurationFromCost(): Valid until: " << inputDate.toString(Qt::ISODate);
|
||||
@@ -415,8 +412,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;
|
||||
@@ -511,11 +513,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");
|
||||
|
@@ -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));
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user