query("SELECT COUNT(*) FROM invoices"); $total = $stmt->fetchColumn(); // Pending Invoices $stmt = $db->query("SELECT COUNT(*) FROM invoices WHERE status = 'pending'"); $pending = $stmt->fetchColumn(); // Approved Invoices $stmt = $db->query("SELECT COUNT(*) FROM invoices WHERE status = 'approved'"); $approved = $stmt->fetchColumn(); } catch (\Exception $e) { // Fallback if table doesn't exist yet $total = 0; $pending = 0; $approved = 0; } json_success([ 'total' => $total, 'pending' => $pending, 'approved' => $approved ]);