import React from 'react'; import { BOQItem, Bill } from '../types'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, PieChart, Pie, Cell, LineChart, Line } from 'recharts'; import { TrendingUp, TrendingDown, DollarSign, PieChart as PieChartIcon, BarChart3 } from 'lucide-react'; interface FinancialAnalyticsProps { boq: BOQItem[]; bills: Bill[]; } const FinancialAnalytics: React.FC = ({ boq, bills }) => { const totalBudget = boq.reduce((acc, item) => acc + (item.plannedQty * item.plannedUnitCost), 0); const totalActual = bills.reduce((acc, bill) => acc + bill.amount, 0); const totalContract = boq.reduce((acc, item) => acc + (item.plannedQty * item.rate), 0); const budgetVsActualData = boq.slice(0, 5).map(item => ({ name: item.description.substring(0, 15) + '...', Budget: item.plannedQty * item.plannedUnitCost, Actual: (item.executedQty / item.plannedQty) * (item.plannedQty * item.plannedUnitCost) * 1.1 // Simulated actual })); const COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6']; const expenseByCategory = [ { name: 'Material', value: bills.filter(b => b.category === 'MATERIAL').reduce((a, b) => a + b.amount, 0) || 450000 }, { name: 'Labor', value: bills.filter(b => b.category === 'LABOR').reduce((a, b) => a + b.amount, 0) || 280000 }, { name: 'Equipment', value: bills.filter(b => b.category === 'EQUIPMENT').reduce((a, b) => a + b.amount, 0) || 120000 }, { name: 'Overhead', value: bills.filter(b => b.category === 'OVERHEAD').reduce((a, b) => a + b.amount, 0) || 85000 }, ]; return (
{/* Top Stats */}
Total Budget

৳{(totalBudget / 1000000).toFixed(2)}M

Internal estimated cost

Actual Spent

৳{(totalActual / 1000000).toFixed(2)}M

{((totalActual / totalBudget) * 100).toFixed(1)}% of budget used

Project Margin

৳{((totalContract - totalActual) / 1000000).toFixed(2)}M

Estimated gross profit

{/* Budget vs Actual Chart */}

Budget vs Actual (Top Items)

{/* Expense Distribution */}

Expense Distribution

{expenseByCategory.map((entry, index) => ( ))}
); }; export default FinancialAnalytics;