diff --git a/src/app/admin/investors/[id]/page.tsx b/src/app/admin/investors/[id]/page.tsx index 1a56c42..c8010c4 100644 --- a/src/app/admin/investors/[id]/page.tsx +++ b/src/app/admin/investors/[id]/page.tsx @@ -53,6 +53,20 @@ export default function InvestorDetailPage() { const [showEditModal, setShowEditModal] = useState(false); const [showAssignBikeModal, setShowAssignBikeModal] = useState(false); const [selectedBikeId, setSelectedBikeId] = useState(''); + const [showCreateInvestmentModal, setShowCreateInvestmentModal] = useState(false); + const [newInvestment, setNewInvestment] = useState({ + planName: '', + planType: 'gold' as 'silver' | 'gold' | 'platinum' | 'diamond', + selectedBikeIds: [] as string[], + totalInvestment: 0, + monthlyReturn: 0, + expectedRoi: 15, + startDate: new Date().toISOString().split('T')[0], + endDate: '', + paymentMethod: 'bank' as 'bank' | 'mobile' | 'cash' | 'cheque', + transactionReference: '', + notes: '' + }); if (!investor) { return ( @@ -76,6 +90,49 @@ export default function InvestorDetailPage() { setSelectedBikeId(''); }; + const handleCreateInvestment = () => { + const invId = `ip${Date.now()}`; + const transactionId = `INV/${new Date().getFullYear()}/${String(Math.floor(Math.random() * 1000)).padStart(3, '0')}`; + + console.log('Creating Investment:', { + id: invId, + investorId: investor.id, + ...newInvestment, + actualEarnings: 0, + status: 'active' as const, + transactionId: transactionId, + createdAt: new Date().toISOString() + }); + + console.log('Accounting Entry:', { + entryId: `AC-${Date.now()}`, + type: 'investment_created', + investorId: investor.id, + investmentId: invId, + amount: newInvestment.totalInvestment, + debitAccount: 'Investment Asset - Investor', + creditAccount: newInvestment.paymentMethod === 'bank' ? 'Bank Account' : 'Cash Account', + transactionRef: transactionId, + createdAt: new Date().toISOString() + }); + + alert(`Investment created successfully!\n\nInvestment ID: ${invId}\nTransaction Ref: ${transactionId}\nAmount: ৳${newInvestment.totalInvestment.toLocaleString()}\n\nAccounting entries have been logged.`); + setShowCreateInvestmentModal(false); + setNewInvestment({ + planName: '', + planType: 'gold', + selectedBikeIds: [], + totalInvestment: 0, + monthlyReturn: 0, + expectedRoi: 15, + startDate: new Date().toISOString().split('T')[0], + endDate: '', + paymentMethod: 'bank', + transactionReference: '', + notes: '' + }); + }; + return (
@@ -380,7 +437,7 @@ export default function InvestorDetailPage() {

Investment Plans

-
@@ -664,6 +721,181 @@ export default function InvestorDetailPage() {
)} + + {showCreateInvestmentModal && ( +
+
+
+

Create New Investment

+ +
+ +
+
+
+ + setNewInvestment({ ...newInvestment, planName: e.target.value })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + placeholder="e.g., Gold EV Fleet 2024" + /> +
+
+ + +
+
+ +
+ +
+ {availableBikesForAssignment.map(bike => ( + + ))} +
+
+ +
+
+ + setNewInvestment({ ...newInvestment, totalInvestment: Number(e.target.value), monthlyReturn: Math.round(Number(e.target.value) * newInvestment.expectedRoi / 100 / 12) })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + placeholder="0" + /> +
+
+ + setNewInvestment({ ...newInvestment, monthlyReturn: Number(e.target.value) })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + placeholder="0" + /> +
+
+ + setNewInvestment({ ...newInvestment, expectedRoi: Number(e.target.value) })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + placeholder="15" + /> +
+
+ +
+
+ + setNewInvestment({ ...newInvestment, startDate: e.target.value })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + /> +
+
+ + setNewInvestment({ ...newInvestment, endDate: e.target.value })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + /> +
+
+ +
+
+ + +
+
+ + setNewInvestment({ ...newInvestment, transactionReference: e.target.value })} + className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" + placeholder="Auto-generated if empty" + /> +
+
+ +
+ +