From adbcded611486d51be70512f5e6c0955d421c577 Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Sat, 16 May 2026 15:09:19 +0600 Subject: [PATCH] feat: add battery rent support and integrate adjusted battery costs into rental billing calculations --- src/app/admin/rentals/page.tsx | 152 ++++++++++++++++++++++++++------- 1 file changed, 119 insertions(+), 33 deletions(-) diff --git a/src/app/admin/rentals/page.tsx b/src/app/admin/rentals/page.tsx index 2b53247..7d2bf5a 100644 --- a/src/app/admin/rentals/page.tsx +++ b/src/app/admin/rentals/page.tsx @@ -171,6 +171,7 @@ const mockRentals: Rental[] = [ dailyRate: 150, weeklyRate: 900, monthlyRate: 3500, + batteryRent: 1500, totalPaid: 38500, dueRental: 0, pendingRent: 0, @@ -272,6 +273,7 @@ const mockRentals: Rental[] = [ dailyRate: 100, weeklyRate: 600, monthlyRate: 2200, + batteryRent: 1500, totalPaid: 2600, dueRental: 600, pendingRent: 600, @@ -692,23 +694,42 @@ export default function RentalsPage() { */} {(() => { - const rent = rental[rental.subscriptionType === 'daily' ? 'dailyRate' : rental.subscriptionType === 'weekly' ? 'weeklyRate' : 'monthlyRate']; - const due = rental.pendingRent || 0; + const bikeRent = rental[rental.subscriptionType === 'daily' ? 'dailyRate' : rental.subscriptionType === 'weekly' ? 'weeklyRate' : 'monthlyRate']; + const batteryRent = rental.batteryRent || 0; + const batteryRentAdjusted = rental.subscriptionType === 'daily' + ? Math.round(batteryRent / 30) + : rental.subscriptionType === 'weekly' + ? Math.round(batteryRent / 4) + : batteryRent; + const totalRent = bikeRent + batteryRentAdjusted; + const due = rental.pendingRent + rental.batteryRentPending || 0; const penalty = rental.penaltyAmount || 0; const totalDue = due + penalty; + const periodLabel = rental.subscriptionType === 'daily' ? 'day' : rental.subscriptionType === 'weekly' ? 'wk' : 'mo'; if (totalDue > 0) { return ( -
+
৳{totalDue.toLocaleString()} -

{rental.subscriptionType} ৳{rent}/{(rental.subscriptionType === 'daily' ? 'day' : rental.subscriptionType === 'weekly' ? 'wk' : 'mo')}

- {penalty > 0 && +৳{penalty} penalty} + {batteryRent > 0 ? ( +

+ {rental.subscriptionType} ৳{bikeRent}{periodLabel} +Battery: ৳{batteryRentAdjusted}{periodLabel} +

+ ) : ( +

{rental.subscriptionType} ৳{totalRent}{periodLabel} +৳{penalty} penalty

+ )}
); } return ( -
- ৳{rent.toLocaleString()} -

{rental.subscriptionType}

+
+ ৳{totalRent.toLocaleString()} + {batteryRent > 0 ? ( +

+ {rental.subscriptionType} ৳{bikeRent}{periodLabel} +Battery: ৳{batteryRentAdjusted}{periodLabel} +

+ ) : ( +

{rental.subscriptionType}

+ )}
); })()} @@ -800,18 +821,39 @@ export default function RentalsPage() { {rental.depositPaid ? 'Paid' : 'Unpaid'}
- {totalDue > 0 ? ( -
- ৳{totalDue.toLocaleString()} -

{rental.subscriptionType} ৳{rent}/{(rental.subscriptionType === 'daily' ? 'day' : rental.subscriptionType === 'weekly' ? 'wk' : 'mo')}

- {penalty > 0 && +৳{penalty}} -
- ) : ( -
- ৳{rent.toLocaleString()} -

{rental.subscriptionType}

-
- )} + {(() => { + const batteryRent = rental.batteryRent || 0; + const batteryRentAdjusted = rental.subscriptionType === 'daily' + ? Math.round(batteryRent / 30) + : rental.subscriptionType === 'weekly' + ? Math.round(batteryRent / 4) + : batteryRent; + const totalRent = rent + batteryRentAdjusted; + const periodLabel = rental.subscriptionType === 'daily' ? 'day' : rental.subscriptionType === 'weekly' ? 'wk' : 'mo'; + return totalDue > 0 ? ( +
+ ৳{totalDue.toLocaleString()} + {batteryRent > 0 ? ( +

+ {rental.subscriptionType} ৳{rent}{periodLabel} +Battery: ৳{batteryRentAdjusted}{periodLabel} +৳{penalty} penalty +

+ ) : ( +

{rental.subscriptionType} ৳{totalRent}{periodLabel} +৳{penalty} penalty

+ )} +
+ ) : ( +
+ ৳{totalRent.toLocaleString()} + {batteryRent > 0 ? ( +

+ {rental.subscriptionType} ৳{rent}{periodLabel} +Battery: ৳{batteryRentAdjusted}{periodLabel} +

+ ) : ( +

{rental.subscriptionType}

+ )} +
+ ); + })()}
@@ -967,10 +1009,21 @@ export default function RentalsPage() { {newRental.planConditionName}

Deposit: ৳{selectedPlan?.deposit.toLocaleString()}

-

- Rate: ৳{newRental.subscriptionType === 'daily' ? selectedPlan?.dailyRate : newRental.subscriptionType === 'weekly' ? selectedPlan?.weeklyRate : selectedPlan?.monthlyRate} - /{newRental.subscriptionType === 'daily' ? 'day' : newRental.subscriptionType === 'weekly' ? 'week' : 'month'} -

+
+ Rate: + {(() => { + const bikeRate = newRental.subscriptionType === 'daily' ? selectedPlan?.dailyRate : newRental.subscriptionType === 'weekly' ? selectedPlan?.weeklyRate : selectedPlan?.monthlyRate; + const batteryRent = newRental.batteryRent || 0; + const batteryRate = batteryRent > 0 ? (newRental.subscriptionType === 'daily' ? Math.round(batteryRent / 30) : newRental.subscriptionType === 'weekly' ? Math.round(batteryRent / 4) : batteryRent) : 0; + const totalRate = bikeRate + batteryRate; + return ( + + ৳{totalRate.toLocaleString()}/{newRental.subscriptionType === 'daily' ? 'day' : newRental.subscriptionType === 'weekly' ? 'week' : 'month'} + {batteryRent > 0 && (Bike: ৳{bikeRate} + Battery: ৳{batteryRate})} + + ); + })()} +
)} @@ -978,7 +1031,7 @@ export default function RentalsPage() { {createStep === 3 && (

Step 3: Select Bike & Battery

- +
{ @@ -1017,8 +1071,15 @@ export default function RentalsPage() { ))} {newRental.batteryId && ( -
+

Battery Monthly Rent: ৳{newRental.batteryRent}/month

+
+

Calculated Rate by Subscription:

+

• Daily: ৳{Math.round(newRental.batteryRent / 30)}/day (৳{newRental.batteryRent}/30)

+

• Weekly: ৳{Math.round(newRental.batteryRent / 4)}/week (৳{newRental.batteryRent}/4)

+

• Monthly (30 days): ৳{newRental.batteryRent}/month

+

• Monthly (31 days): ৳{newRental.batteryRent}/month

+
)}
@@ -1034,15 +1095,40 @@ export default function RentalsPage() {

User: {selectedUser?.name}

Bike: {selectedBike?.model} ({selectedBike?.plate})

{newRental.batteryId && ( -

Battery: {availableBatteries.find(b => b.id === newRental.batteryId)?.brand} {availableBatteries.find(b => b.id === newRental.batteryId)?.model} (Rent: ৳{newRental.batteryRent}/month)

+

Battery: {availableBatteries.find(b => b.id === newRental.batteryId)?.brand} {availableBatteries.find(b => b.id === newRental.batteryId)?.model} (Monthly Rent: ৳{newRental.batteryRent})

)}

Hub: {mockHubs.find(h => h.id === newRental.hubId)?.name}

{newRental.batteryId && ( -
-

- Combined Monthly Rent: ৳{(newRental.subscriptionType === 'daily' ? selectedPlan?.dailyRate : newRental.subscriptionType === 'weekly' ? selectedPlan?.weeklyRate : selectedPlan?.monthlyRate) + newRental.batteryRent}/month - (Bike: ৳{newRental.subscriptionType === 'daily' ? selectedPlan?.dailyRate : newRental.subscriptionType === 'weekly' ? selectedPlan?.weeklyRate : selectedPlan?.monthlyRate} + Battery: ৳{newRental.batteryRent}) -

+
+

Total Rental Payment (Bike + Battery):

+ {(() => { + const bikeRate = newRental.subscriptionType === 'daily' ? selectedPlan?.dailyRate : newRental.subscriptionType === 'weekly' ? selectedPlan?.weeklyRate : selectedPlan?.monthlyRate; + const batteryMonthlyRent = newRental.batteryRent || 0; + const dailyRate = bikeRate + Math.round(batteryMonthlyRent / 30); + const weeklyRate = bikeRate + Math.round(batteryMonthlyRent / 4); + const monthly30Rate = bikeRate + batteryMonthlyRent; + const monthly31Rate = bikeRate + batteryMonthlyRent; + return ( +
+

+ Daily: ৳{dailyRate}/day + (Bike: ৳{bikeRate} + Battery: ৳{Math.round(batteryMonthlyRent / 30)}) +

+

+ Weekly: ৳{weeklyRate}/week + (Bike: ৳{bikeRate} + Battery: ৳{Math.round(batteryMonthlyRent / 4)}) +

+

+ Monthly (30 days): ৳{monthly30Rate}/month + (Bike: ৳{bikeRate} + Battery: ৳{batteryMonthlyRent}) +

+

+ Monthly (31 days): ৳{monthly31Rate}/month + (Bike: ৳{bikeRate} + Battery: ৳{batteryMonthlyRent}) +

+
+ ); + })()}
)}