Fixed pra_payment_unit_id
This commit is contained in:
		| @@ -68,6 +68,6 @@ public: | |||||||
| 	/// </summary> | 	/// </summary> | ||||||
| 	/// <param name="pra_price"></param> | 	/// <param name="pra_price"></param> | ||||||
| 	/// <returns></returns> | 	/// <returns></returns> | ||||||
| 	static double CalculatePricePerUnit(double pra_price); |     static double CalculatePricePerUnit(double pra_price, double durationUnit = -1); | ||||||
|  |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -177,8 +177,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg, | |||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         // Set new price for the normal day |         // Set new price for the normal day | ||||||
|         day_price = cfg->PaymentRate.find(payment_option)->second.pra_price; |         int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id; | ||||||
|         price_per_unit = Utilities::CalculatePricePerUnit(day_price); |         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) |         // If no working day found, skip it (recursively call method again) | ||||||
|         size_t found = 0; |         size_t found = 0; | ||||||
| @@ -410,8 +414,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio | |||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         // Set new price for the normal day |         // 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) |         // If no working day found, skip it (recursively call method again) | ||||||
|         size_t found = 0; |         size_t found = 0; | ||||||
| @@ -506,11 +515,12 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio | |||||||
|             return 0.0f; |             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 |         // Go to next day if minutes not spent | ||||||
|         if(inputDate.time() >= worktime_to) |         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; |             if (carry_over_status < 1) break; | ||||||
|  |  | ||||||
|             LOG_DEBUG("Reached end of worktime, searching for the next working day"); |             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)); | 					cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod)); | ||||||
| 					break; | 					break; | ||||||
| 				case MemberType::PaymentRateType: | 				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; | 					break; | ||||||
| 				case MemberType::PaymentOptionType: | 				case MemberType::PaymentOptionType: | ||||||
| 					cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption)); | 					cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption)); | ||||||
|   | |||||||
| @@ -8,12 +8,15 @@ static int protection_counter = 0; | |||||||
| /// </summary> | /// </summary> | ||||||
| /// <param name="pra_price"></param> | /// <param name="pra_price"></param> | ||||||
| /// <returns></returns> | /// <returns></returns> | ||||||
| double Utilities::CalculatePricePerUnit(double pra_price) | double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit) | ||||||
| { | { | ||||||
| 	try | 	try | ||||||
| 	{ | 	{ | ||||||
| 		double price_per_unit = pra_price; | 		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); | 		//printf("Price per unit (min) is: %lf\n", price_per_unit); | ||||||
| 		return price_per_unit; | 		return price_per_unit; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -35,7 +35,7 @@ int main() { | |||||||
|         memset(&price, 0x00, sizeof(price)); |         memset(&price, 0x00, sizeof(price)); | ||||||
|         QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime(); |         QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime(); | ||||||
|         time_t start_parking_time = start.toSecsSinceEpoch() / 60; |         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, |         if (compute_price_for_parking_ticket(tariff, | ||||||
|                                              start_parking_time, |                                              start_parking_time, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user