Update: 2026-05-03 22:35:31

This commit is contained in:
Hamza-Ayed
2026-05-03 22:35:31 +03:00
parent 2732229642
commit 13bbc29e0e
4 changed files with 2252 additions and 11 deletions

2225
PROJECT_DOCUMENTATION.md Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -49,7 +49,7 @@ try {
"); ");
$stmt->execute([ $stmt->execute([
$decoded['user_id'], // Using current admin as tenant_id $decoded['tenant_id'], // Correctly using tenant_id from JWT
$encryptedName, $encryptedName,
$encryptedNameEn, $encryptedNameEn,
$data['tax_identification_number'], $data['tax_identification_number'],

View File

@@ -1,30 +1,46 @@
<?php <?php
/** /**
* Dashboard Stats Endpoint * Dashboard Stats Endpoint (Role-Based & Tenant-Aware)
*/ */
use App\Core\Database; use App\Core\Database;
use App\Middleware\AuthMiddleware; use App\Middleware\AuthMiddleware;
// 1. Auth Check // 1. Auth Check
AuthMiddleware::check(); $decoded = AuthMiddleware::check();
$db = Database::getInstance(); $db = Database::getInstance();
$tenantId = $decoded['tenant_id'];
$companyId = $decoded['company_id'] ?? null;
$role = $decoded['role'];
try { 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 // Total Invoices
$stmt = $db->query("SELECT COUNT(*) FROM invoices"); $stmt = $db->prepare("SELECT COUNT(*) FROM invoices $where");
$stmt->execute($params);
$total = $stmt->fetchColumn(); $total = $stmt->fetchColumn();
// Pending Invoices // 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(); $pending = $stmt->fetchColumn();
// Approved Invoices // 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(); $approved = $stmt->fetchColumn();
} catch (\Exception $e) { } catch (\Exception $e) {
// Fallback if table doesn't exist yet
$total = 0; $total = 0;
$pending = 0; $pending = 0;
$approved = 0; $approved = 0;

View File

@@ -31,7 +31,7 @@
<nav class="flex-1 px-4 space-y-2"> <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='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='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> </nav>
<div class="p-6 border-t border-gray-800"> <div class="p-6 border-t border-gray-800">
<button @click="logout()" class="w-full text-right text-red-400 text-sm">🚪 تسجيل الخروج</button> <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"> <header class="mb-10 flex justify-between items-center">
<h2 class="text-2xl font-bold" x-text="title()"></h2> <h2 class="text-2xl font-bold" x-text="title()"></h2>
<div class="flex items-center gap-4"> <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==='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'" @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==='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 class="text-sm text-gray-500" x-text="user?.name"></div>
</div> </div>
</header> </header>