Files
musadaq-saas/app/modules_app/dashboard/stats.php
2026-05-03 21:37:02 +03:00

38 lines
810 B
PHP

<?php
/**
* Dashboard Stats Endpoint
*/
use App\Core\Database;
use App\Middleware\AuthMiddleware;
// 1. Auth Check
AuthMiddleware::check();
$db = Database::getInstance();
try {
// Total Invoices
$stmt = $db->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
]);