tenantId; $db = Database::getInstance(); // 1. Total Invoices this month $stmt = $db->prepare("SELECT COUNT(*) as count FROM invoices WHERE tenant_id = ? AND MONTH(created_at) = MONTH(CURRENT_DATE)"); $stmt->execute([$tenantId]); $thisMonth = $stmt->fetch()['count']; // 2. Approved vs Rejected $stmt = $db->prepare("SELECT status, COUNT(*) as count FROM invoices WHERE tenant_id = ? GROUP BY status"); $stmt->execute([$tenantId]); $statusCounts = $stmt->fetchAll(); // 3. Recent Activity $stmt = $db->prepare("SELECT i.*, c.name as company_name FROM invoices i JOIN companies c ON i.company_id = c.id WHERE i.tenant_id = ? ORDER BY i.created_at DESC LIMIT 5"); $stmt->execute([$tenantId]); $recent = $stmt->fetchAll(); Response::json([ 'success' => true, 'data' => [ 'total_this_month' => $thisMonth, 'status_distribution' => $statusCounts, 'recent_invoices' => $recent, 'subscription_usage' => 45 // Placeholder ] ]); } }