Update: 2026-05-03 22:35:31
This commit is contained in:
2225
PROJECT_DOCUMENTATION.md
Normal file
2225
PROJECT_DOCUMENTATION.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,7 @@ try {
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
$decoded['user_id'], // Using current admin as tenant_id
|
||||
$decoded['tenant_id'], // Correctly using tenant_id from JWT
|
||||
$encryptedName,
|
||||
$encryptedNameEn,
|
||||
$data['tax_identification_number'],
|
||||
|
||||
@@ -1,30 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Dashboard Stats Endpoint
|
||||
* Dashboard Stats Endpoint (Role-Based & Tenant-Aware)
|
||||
*/
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
|
||||
// 1. Auth Check
|
||||
AuthMiddleware::check();
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
$db = Database::getInstance();
|
||||
|
||||
$tenantId = $decoded['tenant_id'];
|
||||
$companyId = $decoded['company_id'] ?? null;
|
||||
$role = $decoded['role'];
|
||||
|
||||
try {
|
||||
// 2. Build Query based on Role
|
||||
$where = "WHERE tenant_id = :tenant_id";
|
||||
$params = [':tenant_id' => $tenantId];
|
||||
|
||||
// If accountant or employee restricted to a company
|
||||
if (($role === 'accountant' || $role === 'viewer') && $companyId) {
|
||||
$where .= " AND company_id = :company_id";
|
||||
$params[':company_id'] = $companyId;
|
||||
}
|
||||
|
||||
// Total Invoices
|
||||
$stmt = $db->query("SELECT COUNT(*) FROM invoices");
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM invoices $where");
|
||||
$stmt->execute($params);
|
||||
$total = $stmt->fetchColumn();
|
||||
|
||||
// Pending Invoices
|
||||
$stmt = $db->query("SELECT COUNT(*) FROM invoices WHERE status = 'pending'");
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM invoices $where AND status = 'pending'");
|
||||
$stmt->execute($params);
|
||||
$pending = $stmt->fetchColumn();
|
||||
|
||||
// Approved Invoices
|
||||
$stmt = $db->query("SELECT COUNT(*) FROM invoices WHERE status = 'approved'");
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM invoices $where AND status = 'approved'");
|
||||
$stmt->execute($params);
|
||||
$approved = $stmt->fetchColumn();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Fallback if table doesn't exist yet
|
||||
$total = 0;
|
||||
$pending = 0;
|
||||
$approved = 0;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<nav class="flex-1 px-4 space-y-2">
|
||||
<a href="#" @click="page='dashboard'" class="block p-3 rounded hover:bg-gray-800" :class="page==='dashboard'?'bg-emerald-900/20 text-emerald-500':''">📊 لوحة التحكم</a>
|
||||
<a href="#" @click="page='companies'" class="block p-3 rounded hover:bg-gray-800" :class="page==='companies'?'bg-emerald-900/20 text-emerald-500':''">🏢 الشركات</a>
|
||||
<a href="#" @click="page='users'" class="block p-3 rounded hover:bg-gray-800" :class="page==='users'?'bg-emerald-900/20 text-emerald-500':''">👥 المستخدمون</a>
|
||||
<a x-show="user?.role === 'super_admin' || user?.role === 'admin'" href="#" @click="page='users'" class="block p-3 rounded hover:bg-gray-800" :class="page==='users'?'bg-emerald-900/20 text-emerald-500':''">👥 المستخدمون</a>
|
||||
</nav>
|
||||
<div class="p-6 border-t border-gray-800">
|
||||
<button @click="logout()" class="w-full text-right text-red-400 text-sm">🚪 تسجيل الخروج</button>
|
||||
@@ -43,8 +43,8 @@
|
||||
<header class="mb-10 flex justify-between items-center">
|
||||
<h2 class="text-2xl font-bold" x-text="title()"></h2>
|
||||
<div class="flex items-center gap-4">
|
||||
<button x-show="page==='users'" @click="showAddModal = true" class="bg-emerald-600 hover:bg-emerald-500 px-4 py-2 rounded text-sm font-bold transition">➕ إضافة مستخدم</button>
|
||||
<button x-show="page==='companies'" @click="showAddCompanyModal = true" class="bg-emerald-600 hover:bg-emerald-500 px-4 py-2 rounded text-sm font-bold transition">➕ إضافة شركة</button>
|
||||
<button x-show="page==='users' && (user?.role === 'super_admin' || user?.role === 'admin')" @click="showAddModal = true" class="bg-emerald-600 hover:bg-emerald-500 px-4 py-2 rounded text-sm font-bold transition">➕ إضافة مستخدم</button>
|
||||
<button x-show="page==='companies' && (user?.role === 'super_admin' || user?.role === 'admin')" @click="showAddCompanyModal = true" class="bg-emerald-600 hover:bg-emerald-500 px-4 py-2 rounded text-sm font-bold transition">➕ إضافة شركة</button>
|
||||
<div class="text-sm text-gray-500" x-text="user?.name"></div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user