"use client" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { TrendingUp, TrendingDown, DollarSign, AlertTriangle, Clock, CheckCircle } from "lucide-react" import type { Client, Supplier } from "@/types/business" interface CreditOverviewProps { clients: Client[] suppliers: Supplier[] } export function CreditOverview({ clients, suppliers }: CreditOverviewProps) { // Calculate receivables (money owed to us by clients) const totalReceivables = clients.reduce((sum, client) => sum + client.outstandingAmount, 0) const clientsWithCredit = clients.filter((client) => client.outstandingAmount > 0) const overLimitClients = clients.filter((client) => client.outstandingAmount > client.creditLimit) const totalCreditLimit = clients.reduce((sum, client) => sum + client.creditLimit, 0) const creditUtilization = totalCreditLimit > 0 ? (totalReceivables / totalCreditLimit) * 100 : 0 // Calculate payables (money we owe to suppliers) const totalPayables = suppliers.reduce((sum, supplier) => sum + supplier.amountOwed, 0) const suppliersWithBalance = suppliers.filter((supplier) => supplier.amountOwed > 0) // Net credit position (positive means we're owed more than we owe) const netCreditPosition = totalReceivables - totalPayables // Aging analysis (simplified - in real app would use actual dates) const currentReceivables = totalReceivables * 0.6 const thirtyDayReceivables = totalReceivables * 0.25 const sixtyDayReceivables = totalReceivables * 0.1 const ninetyPlusReceivables = totalReceivables * 0.05 return (
{/* Summary Cards */}
Total Receivables
${totalReceivables.toLocaleString()}

{clientsWithCredit.length} clients with outstanding balances

Total Payables
${totalPayables.toLocaleString()}

{suppliersWithBalance.length} suppliers with outstanding balances

Net Position = 0 ? "text-green-600" : "text-red-600"}`} />
= 0 ? "text-green-600" : "text-red-600"}`}> ${Math.abs(netCreditPosition).toLocaleString()}

{netCreditPosition >= 0 ? "Net receivable position" : "Net payable position"}

Credit Utilization 80 ? "text-red-600" : "text-yellow-600"}`} />
{creditUtilization.toFixed(1)}%

${totalReceivables.toLocaleString()} / ${totalCreditLimit.toLocaleString()} limit

{/* Alerts */} {(overLimitClients.length > 0 || creditUtilization > 90) && ( Credit Alerts {overLimitClients.length > 0 && (

{overLimitClients.length} clients are over their credit limit

)} {creditUtilization > 90 && (

Overall credit utilization is critically high at {creditUtilization.toFixed(1)}%

)}
)} {/* Aging Analysis */}
Receivables Aging Breakdown of outstanding receivables by age
Current (0-30 days)

${currentReceivables.toFixed(0)}

60%
31-60 days

${thirtyDayReceivables.toFixed(0)}

25%
61-90 days

${sixtyDayReceivables.toFixed(0)}

10%
90+ days

${ninetyPlusReceivables.toFixed(0)}

5%
Cash Flow Impact Credit impact on cash flow

Expected Inflow

From client payments

${totalReceivables.toLocaleString()}

Expected Outflow

To supplier payments

${totalPayables.toLocaleString()}

Net Cash Impact

{netCreditPosition >= 0 ? "Positive impact" : "Negative impact"}

= 0 ? "text-green-600" : "text-red-600"}`}> {netCreditPosition >= 0 ? "+" : "-"}${Math.abs(netCreditPosition).toLocaleString()}

) }