Update: 2026-05-03 21:37:02

This commit is contained in:
Hamza-Ayed
2026-05-03 21:37:02 +03:00
parent ff8f525c76
commit e1d4917369
3 changed files with 52 additions and 4 deletions

View File

@@ -0,0 +1,37 @@
<?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
]);