diff --git a/src/app/admin/maintenance/[id]/page.tsx b/src/app/admin/maintenance/[id]/page.tsx index c6d5db2..fec82f4 100644 --- a/src/app/admin/maintenance/[id]/page.tsx +++ b/src/app/admin/maintenance/[id]/page.tsx @@ -287,6 +287,8 @@ export default function MaintenanceDetailPage() { const [showAddServiceCostModal, setShowAddServiceCostModal] = useState(false); const [partSearch, setPartSearch] = useState(''); const [invoiceData, setInvoiceData] = useState({ tips: 0, discount: 0 }); + const [invoiceCreated, setInvoiceCreated] = useState(false); + const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<'online' | 'offline' | 'later' | null>(null); const [showPaymentSuccess, setShowPaymentSuccess] = useState(false); const [editForm, setEditForm] = useState>({}); const [newNoteText, setNewNoteText] = useState(''); @@ -351,7 +353,11 @@ export default function MaintenanceDetailPage() { if (!record) return; import('jspdf').then(jsPDF => { const doc = new jsPDF.default(); - const cost = record.actualCost || record.estimatedCost; + const partsTotal = record.partsUsed?.reduce((s, p) => s + p.totalPrice, 0) || 0; + const serviceCost = record.serviceCost || 0; + const subtotal = partsTotal + serviceCost; + const total = subtotal + invoiceData.tips - invoiceData.discount; + const cost = total || record.estimatedCost; const qrData = `INV-${record.id}|${record.bikePlate}|${record.type}|${cost}|${new Date().toISOString().split('T')[0]}`; doc.setFontSize(20); @@ -402,11 +408,22 @@ export default function MaintenanceDetailPage() { doc.setFontSize(11); doc.text('Cost Breakdown', 20, 175); doc.setFontSize(10); - doc.text(`Estimated Cost: ৳${record.estimatedCost}`, 20, 181); - if (record.actualCost) doc.text(`Actual Cost: ৳${record.actualCost}`, 20, 187); - if (record.partsUsed && record.partsUsed.length > 0) { - doc.text(`Parts: ${record.partsUsed.join(', ')}`, 20, 193); + doc.text(`Parts Total: ৳${partsTotal.toLocaleString()}`, 20, 181); + doc.text(`Service Cost (Labor): ৳${serviceCost.toLocaleString()}`, 20, 187); + doc.text(`Subtotal: ৳${subtotal.toLocaleString()}`, 20, 193); + if (invoiceData.tips > 0) { + doc.setTextColor(22, 163, 74); + doc.text(`Tips: +৳${invoiceData.tips.toLocaleString()}`, 20, 199); + doc.setTextColor(100); } + if (invoiceData.discount > 0) { + doc.setTextColor(220, 38, 38); + doc.text(`Discount: -৳${invoiceData.discount.toLocaleString()}`, 20, 205); + doc.setTextColor(100); + } + doc.setFontSize(12); + doc.setTextColor(0); + doc.text(`Total: ৳${total.toLocaleString()}`, 20, 215); doc.setFontSize(14); doc.setTextColor(6, 95, 70); @@ -470,20 +487,47 @@ export default function MaintenanceDetailPage() { ) : ( <> - - - {record.status !== 'completed' && ( + {!invoiceCreated && ( + + )} + {!invoiceCreated && ( + + )} + {record.status !== 'completed' && !invoiceCreated && ( )} + {record.status !== 'completed' && invoiceCreated && ( + <> + + + + + )} {record.status === 'completed' && record.paymentStatus !== 'paid' && ( )} @@ -762,11 +806,37 @@ export default function MaintenanceDetailPage() { {record.partsUsed?.map((part) => ( {part.partName} - {part.quantity} + + { + const newQty = Math.max(1, parseInt(e.target.value) || 1); + setRecord(prev => prev ? { + ...prev, + partsUsed: prev.partsUsed?.map(p => + p.id === part.id + ? { ...p, quantity: newQty, totalPrice: newQty * p.unitPrice } + : p + ) + } : null); + }} + className="w-16 px-2 py-1 border border-orange-200 rounded text-center text-sm" + /> + ৳{part.unitPrice.toLocaleString()} ৳{part.totalPrice.toLocaleString()} - @@ -846,7 +916,7 @@ export default function MaintenanceDetailPage() {

- Maintenance Invoice + {invoiceCreated ? 'Edit Invoice' : 'Create Invoice'}

{record.id} • {record.bikeModel}

@@ -865,7 +935,7 @@ export default function MaintenanceDetailPage() { ৳{(record.serviceCost || 0).toLocaleString()}
- +
@@ -890,7 +960,7 @@ export default function MaintenanceDetailPage() { />
- +
Subtotal: @@ -915,7 +985,7 @@ export default function MaintenanceDetailPage() {
- +

After payment, this maintenance will be marked as completed

@@ -923,10 +993,10 @@ export default function MaintenanceDetailPage() {
@@ -970,22 +1040,26 @@ export default function MaintenanceDetailPage() {
-

Cash

-

Debit Cash (1100) → Credit Maintenance (5400)

+

Offline (Cash)

+

Pay with cash

@@ -1219,7 +1293,7 @@ export default function MaintenanceDetailPage() {
-

Payment Successful!

Maintenance has been completed

- +
Maintenance ID @@ -1263,7 +1337,7 @@ export default function MaintenanceDetailPage() { ৳{((record?.partsUsed?.reduce((s, p) => s + p.totalPrice, 0) || 0) + (record?.serviceCost || 0) + invoiceData.tips - invoiceData.discount).toLocaleString()}
- +