🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 14:27
This commit is contained in:
@@ -18,7 +18,9 @@ final class DashboardController
|
||||
$where = "WHERE tenant_id = ?";
|
||||
$params = [$tenantId];
|
||||
|
||||
if ($role !== 'super_admin') {
|
||||
// Fix: Only accountants should be restricted to a single company if assigned.
|
||||
// Admins and Super Admins should see all companies in their tenant.
|
||||
if ($role === 'accountant' && $assignedCompanyId) {
|
||||
$where .= " AND company_id = ?";
|
||||
$params[] = $assignedCompanyId;
|
||||
}
|
||||
@@ -26,7 +28,7 @@ final class DashboardController
|
||||
// 1. Total Invoices this month
|
||||
$stmt = $db->prepare("SELECT COUNT(*) as count FROM invoices {$where} AND MONTH(created_at) = MONTH(CURRENT_DATE)");
|
||||
$stmt->execute($params);
|
||||
$thisMonth = $stmt->fetch()['count'];
|
||||
$thisMonth = (int) $stmt->fetch()['count'];
|
||||
|
||||
// 2. Approved vs Rejected
|
||||
$stmt = $db->prepare("SELECT status, COUNT(*) as count FROM invoices {$where} GROUP BY status");
|
||||
@@ -34,17 +36,24 @@ final class DashboardController
|
||||
$statusCounts = $stmt->fetchAll();
|
||||
|
||||
// 3. Recent Activity - Fixed ambiguity
|
||||
$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 = ? " . ($role !== 'super_admin' ? " AND i.company_id = ?" : "") . " ORDER BY i.created_at DESC LIMIT 5");
|
||||
$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 = ? " . ($role === 'accountant' && $assignedCompanyId ? " AND i.company_id = ?" : "") . " ORDER BY i.created_at DESC LIMIT 5");
|
||||
$stmt->execute($params);
|
||||
$recent = $stmt->fetchAll();
|
||||
|
||||
// 4. Calculate Subscription Usage
|
||||
$stmt = $db->prepare("SELECT max_invoices_per_month FROM subscriptions WHERE tenant_id = ?");
|
||||
$stmt->execute([$tenantId]);
|
||||
$sub = $stmt->fetch();
|
||||
$maxInvoices = (int) ($sub['max_invoices_per_month'] ?? 100);
|
||||
$usage = $maxInvoices > 0 ? round(($thisMonth / $maxInvoices) * 100, 1) : 0;
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'total_this_month' => $thisMonth,
|
||||
'status_distribution' => $statusCounts,
|
||||
'recent_invoices' => $recent,
|
||||
'subscription_usage' => 45 // Placeholder
|
||||
'subscription_usage' => $usage
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user