-
-
Notifications
You must be signed in to change notification settings - Fork 230
Price Calculation
Cars have the following pricing fields:
- Daily price (1 day - required)
- Discounted Daily price (1 day - optional)
- Bi-Weekly price (3 days - optional)
- Discounted Bi-Weekly price (3 days - optional)
- Weekly price (7 days - optional)
- Discounted Weekly price (7 days - optional)
- Monthly price (30 days - optional)
- Discounted Monthly price (30 days - optional)
- Date Based Price Rates (optional)
Only Daily price is required. Other prices are optional.
For any price, if discounted price is set, discounted price will take over normal price.
The discounted price should be equal to a total of (price - discount). For example, if the weekly price is $200, the discounted weekly price should be, for instance, $180. The same goes for discounted daily, discounted bi-weekly and discounted monthly prices.
The discounted price is not discount only. It is the total of (price - discount). If the discounted price is wrong, price calculation will be wrong.
You can add date based price rates (startDate, endDate, dailyPrice) from create car and update car pages from the admin dashboard. You need to toggle Date Based Price option first.
If you want to set a rate for only one day for example 02/16/2025, you need to set startDate and endDate to 02/16/2025.
Date based price rates are used with daily price to calculate the total price.
You can set a price change rate (+/- %) from the Create Supplier and Update Supplier pages in the admin dashboard. This rate is applied to calculate the total rental price, and it can be either positive (markup) or negative (discount).
If the price change rate is positive, the total price increases.
If the price change rate is negative, the total price decreases.
For example if the price change rate is equal to 10%
and the rental price is $100
, the total price will be: $100 + $100 * 10% = $110
And if the price change rate is equal to -10%
and the rental price is $100
, the total price will be: $100 - $100 * 10% = $90
This feature allows flexible pricing adjustments based on supplier preferences.
If date based price rates option is toggeled, Date based price rates are used with daily price to calculate the total price. First, we set the current date to the booking start date. To get the price of the current day, we loop through all date based price rates and we check if current day is between startDate and endDate. If we find a match, we get the current price rate. If no match is found we take the default daily or discounted daily price of the car as price rate. We add the price rate to the total price. Then, we move on to the next day until the last day is reached.
If date based price rates are not used, below is the price calculation logic.
If all other pricing fields are not set, price for N
days is: N * DailyPrice
Otherwise, price is calculated with pricing fields set and daily price.
Here is an example calculation for 10 days:
- If Weekly price is set and Bi-Weekly price is set,
price = 1 * WeeklyPrice + 1 * BiWeeklyPrice
- If Weekly price is not set and Bi-Weekly price is set,
price = 3 * BiWeeklyPrice + 1 * DailyPrice
- If Weekly price is not set and Bi-Weekly price is not set,
price = 10 * DailyPrice
Here is an example calculation for 42 days:
- If Monthly price is set and Weekly price is set and Bi-Weekly price is set,
price = 1 * MonthlyPrice + 1 * WeeklyPrice + 1 * BiWeeklyPrice + 2 * DailyPrice
- If Monthly price is set and Weekly price is set and Bi-Weekly price is not set,
price = 1 * MonthlyPrice + 1 * WeeklyPrice + 5 * DailyPrice
- If Monthly price is set and Weekly price is not set and Bi-Weekly price is set,
price = 1 * MonthlyPrice + 4 * BiWeeklyPrice
- If Monthly price is set and Weekly price is not set and Bi-Weekly price is not set,
price = 1 * MonthlyPrice + 12 * DailyPrice
- If Monthly price is not set and Weekly price is not set and Bi-Weekly price is not set,
price = 42 * DailyPrice
The algorithm is implemented in the following function. This function is utilized by both the frontend and the mobile app to calculate the total price of each car. By being accessible across both platforms, it ensures consistency in how the price is computed, providing users with accurate and up-to-date pricing information regardless of the interface they use. Whether accessed through the web or mobile, the function retrieves relevant data and applies the necessary calculations to determine the total cost, factoring in various dynamic variables such as rental duration, custom rates, and any additional fees.
Copyright © 2025 Akram El Assas. All rights reserved.