feat: enable dynamic deposit calculation from rental input or plan settings and add validation for hub selection during creation
This commit is contained in:
@@ -457,9 +457,9 @@ export default function RentalsPage() {
|
||||
: undefined,
|
||||
contractMonths: newRental.contractMonths > 0 ? newRental.contractMonths : undefined,
|
||||
subscriptionType: newRental.subscriptionType,
|
||||
deposit: settings.deposit,
|
||||
deposit: newRental.depositAmount > 0 ? newRental.depositAmount : settings.deposit,
|
||||
depositPaymentMethod: newRental.depositPaymentMethod,
|
||||
depositPaid: settings.deposit > 0,
|
||||
depositPaid: newRental.depositAmount > 0 || settings.deposit > 0,
|
||||
dailyRate: settings.dailyRate,
|
||||
weeklyRate: settings.weeklyRate,
|
||||
monthlyRate: settings.monthlyRate,
|
||||
@@ -867,15 +867,7 @@ export default function RentalsPage() {
|
||||
<p className="text-sm text-slate-600">Hub: {mockHubs.find(h => h.id === newRental.hubId)?.name}</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{/* <div>
|
||||
<label className="text-sm text-slate-600 mb-1 block">Deposit Amount (৳)</label>
|
||||
<input
|
||||
type="number"
|
||||
value={newRental.depositAmount}
|
||||
onChange={(e) => setNewRental({ ...newRental, depositAmount: Number(e.target.value) })}
|
||||
className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm"
|
||||
/>
|
||||
</div> */}
|
||||
|
||||
<div>
|
||||
<label className="text-sm text-slate-600 mb-2 block">Payment Method</label>
|
||||
<div className="flex gap-2">
|
||||
@@ -898,7 +890,7 @@ export default function RentalsPage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{newRental.depositAmount > 0 && (
|
||||
{(newRental.depositAmount > 0 || selectedPlan?.deposit > 0) && (
|
||||
<div className="bg-white border border-slate-200 rounded-lg overflow-hidden">
|
||||
<div className="bg-slate-100 px-4 py-2 border-b border-slate-200">
|
||||
<p className="text-sm font-semibold text-slate-700">Proforma Invoice</p>
|
||||
@@ -924,20 +916,20 @@ export default function RentalsPage() {
|
||||
{newRental.depositPaymentMethod === 'bank' && '1100 - Bank'}
|
||||
{newRental.depositPaymentMethod === 'wallet' && '1200 - Biker Wallet'}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right">{newRental.depositAmount.toLocaleString()}</td>
|
||||
<td className="px-3 py-2 text-right">-</td>
|
||||
</tr>
|
||||
<tr className="border-t border-slate-100">
|
||||
<td className="px-3 py-2">2100 - Deposit Received</td>
|
||||
<td className="px-3 py-2 text-right">-</td>
|
||||
<td className="px-3 py-2 text-right">{newRental.depositAmount.toLocaleString()}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot className="bg-slate-50 border-t border-slate-200">
|
||||
<tr>
|
||||
<td className="px-3 py-2 font-semibold text-slate-700">Total</td>
|
||||
<td className="px-3 py-2 text-right font-semibold">{newRental.depositAmount.toLocaleString()}</td>
|
||||
<td className="px-3 py-2 text-right font-semibold">{newRental.depositAmount.toLocaleString()}</td>
|
||||
<td className="px-3 py-2 text-right">{newRental.depositAmount > 0 ? newRental.depositAmount.toLocaleString() : selectedPlan?.deposit.toLocaleString()}</td>
|
||||
<td className="px-3 py-2 text-right">-</td>
|
||||
</tr>
|
||||
<tr className="border-t border-slate-100">
|
||||
<td className="px-3 py-2">2100 - Deposit Received</td>
|
||||
<td className="px-3 py-2 text-right">-</td>
|
||||
<td className="px-3 py-2 text-right">{newRental.depositAmount > 0 ? newRental.depositAmount.toLocaleString() : selectedPlan?.deposit.toLocaleString()}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot className="bg-slate-50 border-t border-slate-200">
|
||||
<tr>
|
||||
<td className="px-3 py-2 font-semibold text-slate-700">Total</td>
|
||||
<td className="px-3 py-2 text-right font-semibold">{newRental.depositAmount > 0 ? newRental.depositAmount.toLocaleString() : selectedPlan?.deposit.toLocaleString()}</td>
|
||||
<td className="px-3 py-2 text-right font-semibold">{newRental.depositAmount > 0 ? newRental.depositAmount.toLocaleString() : selectedPlan?.deposit.toLocaleString()}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@@ -963,7 +955,7 @@ export default function RentalsPage() {
|
||||
<button
|
||||
onClick={() => setCreateStep(createStep + 1)}
|
||||
disabled={
|
||||
(createStep === 1 && !newRental.userId) ||
|
||||
(createStep === 1 && (!newRental.userId || !newRental.hubId)) ||
|
||||
(createStep === 3 && !newRental.bikeId)
|
||||
}
|
||||
className="px-4 py-2 bg-emerald-600 text-white rounded-lg text-sm disabled:opacity-50 flex items-center gap-2"
|
||||
@@ -972,8 +964,8 @@ export default function RentalsPage() {
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
{newRental.depositAmount > 0 && (
|
||||
<button className="px-4 py-2 bg-blue-600 text-white rounded-lg text-sm flex items-center gap-2">
|
||||
{(newRental.depositAmount > 0 || selectedPlan?.deposit > 0) && (
|
||||
<button onClick={() => window.print()} className="px-4 py-2 bg-blue-600 text-white rounded-lg text-sm flex items-center gap-2">
|
||||
<Printer className="w-4 h-4" /> Print Invoice
|
||||
</button>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user