pricing tiers
This commit is contained in:
@@ -25,33 +25,27 @@ class LateReturnService {
|
||||
|
||||
let lateFee = 0;
|
||||
let pricingType = "daily";
|
||||
const billableDays = Math.ceil(hoursLate / 24);
|
||||
|
||||
// Check if item has hourly or daily pricing
|
||||
if (rental.item?.pricePerHour && rental.item.pricePerHour > 0) {
|
||||
// Hourly pricing - charge per hour late
|
||||
lateFee = hoursLate * parseFloat(rental.item.pricePerHour);
|
||||
pricingType = "hourly";
|
||||
} else if (rental.item?.pricePerDay && rental.item.pricePerDay > 0) {
|
||||
// Daily pricing - charge per day late (rounded up)
|
||||
const billableDays = Math.ceil(hoursLate / 24);
|
||||
// Calculate late fees per day, deriving daily rate from available pricing tiers
|
||||
if (rental.item?.pricePerDay && rental.item.pricePerDay > 0) {
|
||||
// Daily pricing - charge per day late
|
||||
lateFee = billableDays * parseFloat(rental.item.pricePerDay);
|
||||
pricingType = "daily";
|
||||
} else if (rental.item?.pricePerWeek && rental.item.pricePerWeek > 0) {
|
||||
// Weekly pricing - derive daily rate and charge per day late
|
||||
const dailyRate = parseFloat(rental.item.pricePerWeek) / 7;
|
||||
lateFee = billableDays * dailyRate;
|
||||
} else if (rental.item?.pricePerMonth && rental.item.pricePerMonth > 0) {
|
||||
// Monthly pricing - derive daily rate and charge per day late
|
||||
const dailyRate = parseFloat(rental.item.pricePerMonth) / 30;
|
||||
lateFee = billableDays * dailyRate;
|
||||
} else if (rental.item?.pricePerHour && rental.item.pricePerHour > 0) {
|
||||
// Hourly pricing - derive daily rate and charge per day late
|
||||
const dailyRate = parseFloat(rental.item.pricePerHour) * 24;
|
||||
lateFee = billableDays * dailyRate;
|
||||
} else {
|
||||
// Free borrows: determine pricing type based on rental duration
|
||||
const rentalStart = new Date(rental.startDateTime);
|
||||
const rentalEnd = new Date(rental.endDateTime);
|
||||
const rentalDurationHours = (rentalEnd - rentalStart) / (1000 * 60 * 60);
|
||||
|
||||
if (rentalDurationHours <= 24) {
|
||||
// Hourly rental - charge $10 per hour late
|
||||
lateFee = hoursLate * 10.0;
|
||||
pricingType = "hourly";
|
||||
} else {
|
||||
// Daily rental - charge $10 per day late
|
||||
const billableDays = Math.ceil(hoursLate / 24);
|
||||
lateFee = billableDays * 10.0;
|
||||
pricingType = "daily";
|
||||
}
|
||||
// Free borrows - charge $10 per day late
|
||||
lateFee = billableDays * 10.0;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user