'use client'; import React, { useState, useEffect } from 'react'; import Link from 'next/link'; import { useAuth } from '@/contexts/AuthContext'; import { useRouter } from 'next/navigation'; const STAT_CARDS = [ { key: 'revenue_ytd', label: 'Revenue YTD', color: 'text-green-400', bg: 'bg-green-400/10', href: '/admin/accounting/invoices' }, { key: 'expenses_ytd', label: 'Expenses YTD', color: 'text-red-400', bg: 'bg-red-400/10', href: '/admin/accounting/expenses' }, { key: 'net_profit', label: 'Net Profit YTD', color: 'text-blue-400', bg: 'bg-blue-400/10', href: '/admin/accounting/reports' }, { key: 'outstanding', label: 'Outstanding Invoices', color: 'text-yellow-400', bg: 'bg-yellow-400/10', href: '/admin/accounting/invoices?status=pending' }, { key: 'unreconciled', label: 'Unreconciled Transactions', color: 'text-orange-400', bg: 'bg-orange-400/10', href: '/admin/accounting/reconciliation' }, { key: 'commissions_outstanding', label: 'Commissions Outstanding', color: 'text-purple-400', bg: 'bg-purple-400/10', href: '/admin/accounting/commissions' }, ]; function fmt(cents: number) { return '$' + (cents / 100).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } export default function AccountingDashboard() { const { user, loading } = useAuth(); const router = useRouter(); const [stats, setStats] = useState>({}); const [siteRevenue, setSiteRevenue] = useState([]); const [topClients, setTopClients] = useState([]); const [loadingData, setLoadingData] = useState(true); useEffect(() => { if (!loading && !user) router.push('/login'); }, [user, loading, router]); useEffect(() => { if (!user) return; fetch('/api/accounting/dashboard') .then(r => r.json()) .then(d => { setStats(d.stats ?? {}); setSiteRevenue(d.siteRevenue ?? []); setTopClients(d.topClients ?? []); }) .catch(() => {}) .finally(() => setLoadingData(false)); }, [user]); if (loading || loadingData) return (
); if (!user) return null; return (
{/* Header */}

Accounting Dashboard

Relevant Media Properties, LLC

+ New Client + New Order + New Invoice + Log Expense Upload Bank CSV
{/* Stat Cards */}
{STAT_CARDS.map(c => (

{fmt(stats[c.key] ?? 0)}

{c.label}

))}
{/* Site Revenue Table */}

Revenue by Site

{['Site','Revenue MTD','Revenue YTD','Outstanding','Active Orders'].map(h => ( ))} {siteRevenue.length === 0 ? ( ) : siteRevenue.map((row: any) => ( ))}
{h}
No data yet
{row.site} {fmt(row.revenue_mtd ?? 0)} {fmt(row.revenue_ytd ?? 0)} {fmt(row.outstanding ?? 0)} {row.active_orders ?? 0}
{/* Top Clients */}

Top 5 Clients YTD

{['Client','Revenue YTD','Active Orders'].map(h => ( ))} {topClients.length === 0 ? ( ) : topClients.map((c: any) => ( ))}
{h}
No data yet
{c.company_name} {fmt(c.revenue_ytd ?? 0)} {c.active_orders ?? 0}
{/* Sub-nav links */}
{[ { label: 'Clients', href: '/admin/accounting/clients' }, { label: 'Orders', href: '/admin/accounting/orders' }, { label: 'Invoices', href: '/admin/accounting/invoices' }, { label: 'Staff & Commissions', href: '/admin/accounting/staff' }, { label: 'Expenses', href: '/admin/accounting/expenses' }, { label: 'Reconciliation', href: '/admin/accounting/reconciliation' }, { label: 'Commissions', href: '/admin/accounting/commissions' }, { label: 'Reports', href: '/admin/accounting/reports' }, { label: 'Documents', href: '/admin/accounting/documents' }, ].map(l => ( {l.label} ))}
); }