Price Calculation - aelassas/bookcars GitHub Wiki
Table of Contents
Pricing Fields
Each car in BookCars supports a set of flexible pricing fields to accommodate different rental durations and discount strategies.
Field | Duration | Required | Description |
---|---|---|---|
Daily Price | 1 day | β Yes | Base daily rental price |
Discounted Daily Price | 1 day | β No | Reduced daily rate |
Hourly Price | 1 hour | β No | Base price for hourly rentals |
Discounted Hourly Price | 1 hour | β No | Reduced hourly rate |
Bi-Weekly Price | 3 days | β No | Price for a 3-day rental block |
Discounted Bi-Weekly Price | 3 days | β No | Reduced price for a 3-day rental block |
Weekly Price | 7 days | β No | Price for a 7-day rental |
Discounted Weekly Price | 7 days | β No | Reduced weekly price |
Monthly Price | 30 days | β No | Price for a 30-day rental |
Discounted Monthly Price | 30 days | β No | Reduced monthly price |
Date-Based Price Rates | Custom dates | β No | Overrides daily pricing for specific date ranges |
Only Daily Price is required. All other pricing fields are optional.
Discounted Prices
For each pricing tier (hourly, daily, bi-weekly, weekly, monthly), a discounted price can be set.
- If a discounted price is provided, it will override the regular price during price calculation.
- The discounted price must be the final amount (i.e., already reduced).
- Example:
IfWeeklyPrice = $200
and you want to give a $20 discount, then
DiscountedWeeklyPrice = $180
Important: Do not set the discounted price as the discount amount. Always use the total after discount.
Incorrect values will result in inaccurate pricing.
Date Based Price Rates
BookCars allows defining custom daily prices for specific date ranges (e.g. holidays, peak seasons).
How to set:
- Go to Create Car or Update Car page in the Admin Panel.
- Enable the toggle: Date-Based Price
- Add entries with:
startDate
endDate
dailyPrice
To define a rate for a single day (e.g. 02/16/2025
), set startDate
and endDate
to the same value.
Behavior:
- Date-based rates are used in place of daily price during price calculation.
- If no match is found for a date, the system falls back to the default Daily Price or Discounted Daily Price.
Price Change Rate
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). Only admins can edit this field.
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.
Calculation Algorithm
BookCars supports two modes of pricing calculation:
Date-Based Price Rates Calculation
If the Date-based price rates option is enabled, pricing is calculated per day based on the configured date-specific rates.
How it works:
- The calculation starts at the booking start date.
- For each day in the rental period:
- The system checks if the current date falls within any defined price rate range (
startDate
toendDate
). - If a match is found, the corresponding custom price rate is applied.
- If no match is found, the system falls back to the carβs daily or discounted daily price.
- The system checks if the current date falls within any defined price rate range (
- The matched price is added to the total.
- The loop continues until the booking end date is reached.
Default Pricing Calculation
If date-based pricing is disabled, pricing is calculated using the carβs predefined pricing tiers.
Basic Rules
-
If no pricing tiers are set:
Price = TotalDays Γ DailyPrice
-
If hourly price is set and rental duration is less than one day:
Price = TotalHours Γ HourlyPrice
-
If hourly price is set and rental duration is more than one day:
Price = (FullDays Γ DailyPrice) + (RemainingHours Γ HourlyPrice)
-
If hourly price is not set and rental is less than one day:
Price = 1 Γ DailyPrice
-
If weekly / bi-weekly / monthly prices are set:
The system selects the most cost-efficient combination of:MonthlyPrice
WeeklyPrice
BiWeeklyPrice
(3-day blocks)DailyPrice
HourlyPrice
(for leftover hours)
Examples
Example 1: Rental for 10 Hours
-
If HourlyPrice is set:
Price = 10 Γ HourlyPrice
-
If HourlyPrice is not set:
Price = 1 Γ DailyPrice
Example 2: Rental for 36 Hours (1 day and 12 hours)
-
If HourlyPrice is set:
Price = 1 Γ DailyPrice + 12 Γ HourlyPrice
-
If HourlyPrice is not set:
Price = 2 Γ DailyPrice
Example 3: Rental for 10 Days
-
If Weekly and Bi-Weekly prices are set:
Price = 1 Γ WeeklyPrice + 1 Γ BiWeeklyPrice
-
If only Bi-Weekly is set:
Price = 3 Γ BiWeeklyPrice + 1 Γ DailyPrice
-
If no pricing tiers are set:
Price = 10 Γ DailyPrice
Example 4: Rental for 42 Days
-
If Monthly, Weekly, and Bi-Weekly prices are set:
Price = 1 Γ MonthlyPrice + 1 Γ WeeklyPrice + 1 Γ BiWeeklyPrice + 2 Γ DailyPrice
-
If Monthly and Weekly prices are set:
Price = 1 Γ MonthlyPrice + 1 Γ WeeklyPrice + 5 Γ DailyPrice
-
If Monthly and Bi-Weekly prices are set:
Price = 1 Γ MonthlyPrice + 4 Γ BiWeeklyPrice
-
If only Monthly price is set:
Price = 1 Γ MonthlyPrice + 12 Γ DailyPrice
-
If no pricing tiers are set:
Price = 42 Γ DailyPrice
Function Reference
This pricing logic is implemented in the following function: calculatePrice
This function is used by both the frontend and mobile app to ensure consistent and accurate pricing across all platforms.
It dynamically applies the appropriate price tiers based on:
- Rental duration (in days and hours)
- Available pricing fields (hourly, daily, bi-weekly, weekly, monthly)
- Optional date-based overrides