Update: 2026-05-03 21:37:02
This commit is contained in:
37
app/modules_app/dashboard/stats.php
Normal file
37
app/modules_app/dashboard/stats.php
Normal 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
|
||||
]);
|
||||
Reference in New Issue
Block a user