From f0d92f31ff1f39a13b0ddb3a196352ad50bd3aa0 Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Tue, 19 May 2026 18:22:06 +0600 Subject: [PATCH] feat: implement dynamic payment tracking with local storage and update transaction UI for battery investments --- .../[id]/investments/[investmentId]/page.tsx | 162 ++++++++++-------- 1 file changed, 91 insertions(+), 71 deletions(-) diff --git a/src/app/admin/investors/[id]/investments/[investmentId]/page.tsx b/src/app/admin/investors/[id]/investments/[investmentId]/page.tsx index 94e2b2b..f21bffa 100644 --- a/src/app/admin/investors/[id]/investments/[investmentId]/page.tsx +++ b/src/app/admin/investors/[id]/investments/[investmentId]/page.tsx @@ -344,10 +344,61 @@ export default function InvestmentDetailPage({ params }: { params: Promise<{ id: date: new Date().toISOString().split('T')[0], notes: '' }); - const [investmentPayments, setInvestmentPayments] = useState([ - { id: 'pay1', date: '2024-01-15', amount: 50000, paymentMethod: 'bank', transactionRef: 'TXN-001', status: 'completed', notes: 'First installment' }, - { id: 'pay2', date: '2024-01-20', amount: 35000, paymentMethod: 'mobile', transactionRef: 'TXN-002', status: 'completed', notes: 'Second installment' }, - ]); + const [investmentPayments, setInvestmentPayments] = useState(() => { + if (!investment) return []; + const isBatteryPlan = investment.assetType === 'battery' || investment.planName?.toLowerCase().includes('battery'); + + if (typeof window !== 'undefined') { + const stored = localStorage.getItem(`jaiben_payments_${investmentId}`); + if (stored) { + try { + return JSON.parse(stored); + } catch (e) { + console.error(e); + } + } + } + + if (isBatteryPlan) { + return [ + { + id: `pay_${investmentId}`, + date: investment.startDate || '2024-02-01', + amount: investment.totalInvestment, + paymentMethod: investment.paymentMethod || 'bank', + transactionRef: investment.transactionId || 'TXN-BAT-001', + status: 'completed', + notes: 'Full Payment' + } + ]; + } + + if (investmentId === 'ip2') { + return [ + { + id: 'pay1_ip2', + date: '2024-01-20', + amount: investment.totalInvestment, + paymentMethod: 'mobile', + transactionRef: 'TXN-002', + status: 'completed', + notes: 'Full Payment' + } + ]; + } + + // Default for ip1 or others + return [ + { id: 'pay1', date: '2024-01-15', amount: 50000, paymentMethod: 'bank', transactionRef: 'TXN-001', status: 'completed', notes: 'First installment' }, + { id: 'pay2', date: '2024-01-20', amount: 35000, paymentMethod: 'mobile', transactionRef: 'TXN-002', status: 'completed', notes: 'Second installment' }, + ]; + }); + + useEffect(() => { + if (typeof window !== 'undefined') { + localStorage.setItem(`jaiben_payments_${investmentId}`, JSON.stringify(investmentPayments)); + } + }, [investmentPayments, investmentId]); if (!investor || !investment) { return ( @@ -622,12 +673,7 @@ export default function InvestmentDetailPage({ params }: { params: Promise<{ id: > Transactions - + + {!isBattery && (investment.totalInvestment - investmentPayments.reduce((sum, p) => sum + p.amount, 0)) > 0 && ( + + )}
@@ -938,24 +990,6 @@ export default function InvestmentDetailPage({ params }: { params: Promise<{ id: -
{assignedBatteries.length > 0 ? ( @@ -1065,20 +1099,6 @@ export default function InvestmentDetailPage({ params }: { params: Promise<{ id: - {assignedBikes.length > 0 ? (