diff --git a/app/modules_app/invoices/index.php b/app/modules_app/invoices/index.php new file mode 100644 index 0000000..8b23fd1 --- /dev/null +++ b/app/modules_app/invoices/index.php @@ -0,0 +1,80 @@ +query(" + SELECT i.*, t.name as tenant_name, c.name as company_name + FROM invoices i + LEFT JOIN tenants t ON i.tenant_id = t.id + LEFT JOIN companies c ON i.company_id = c.id + ORDER BY i.created_at DESC + "); + } elseif ($role === 'admin') { + // Admin sees all invoices in THEIR tenant + $stmt = $db->prepare(" + SELECT i.*, c.name as company_name + FROM invoices i + LEFT JOIN companies c ON i.company_id = c.id + WHERE i.tenant_id = ? + ORDER BY i.created_at DESC + "); + $stmt->execute([$tenantId]); + } else { + // Accountant/Viewer: Filter by assigned companies + $stmtUser = $db->prepare("SELECT company_id FROM user_company_assignments WHERE user_id = ? AND is_active = 1"); + $stmtUser->execute([$userId]); + $assignedCompanyIds = $stmtUser->fetchAll(PDO::FETCH_COLUMN); + + if (empty($assignedCompanyIds)) { + json_success([]); + } + + $placeholders = implode(',', array_fill(0, count($assignedCompanyIds), '?')); + $stmt = $db->prepare(" + SELECT i.*, c.name as company_name + FROM invoices i + LEFT JOIN companies c ON i.company_id = c.id + WHERE i.company_id IN ($placeholders) + ORDER BY i.created_at DESC + "); + $stmt->execute($assignedCompanyIds); + } + + $invoices = $stmt->fetchAll(); + + // 3. Decrypt sensitive fields for display + foreach ($invoices as &$inv) { + $inv['supplier_name'] = Encryption::decrypt($inv['supplier_name'] ?? '') ?: ($inv['supplier_name'] ?? '-'); + $inv['supplier_tin'] = Encryption::decrypt($inv['supplier_tin'] ?? '') ?: ($inv['supplier_tin'] ?? '-'); + $inv['buyer_name'] = Encryption::decrypt($inv['buyer_name'] ?? '') ?: ($inv['buyer_name'] ?? '-'); + + if (!empty($inv['company_name'])) { + $inv['company_name'] = Encryption::decrypt($inv['company_name']) ?: $inv['company_name']; + } + if (!empty($inv['tenant_name'])) { + $inv['tenant_name'] = Encryption::decrypt($inv['tenant_name']) ?: $inv['tenant_name']; + } + } + + json_success($invoices); + +} catch (\Exception $e) { + json_error('SQL Error in Invoices List: ' . $e->getMessage(), 500); +} diff --git a/public/index.php b/public/index.php index 6984dff..7d1bc66 100644 --- a/public/index.php +++ b/public/index.php @@ -24,6 +24,7 @@ $routes = [ 'v1/users/delete' => ['POST', 'users/delete.php'], 'v1/companies' => ['GET', 'companies/index.php'], 'v1/companies/create' => ['POST', 'companies/create.php'], + 'v1/invoices' => ['GET', 'invoices/index.php'], 'v1/invoices/upload' => ['POST', 'invoices/upload.php'], 'v1/dashboard/stats' => ['GET', 'dashboard/stats.php'], 'v1/tenants' => ['GET', 'tenants/index.php'], diff --git a/public/shell.php b/public/shell.php index 27769d2..0fe4905 100644 --- a/public/shell.php +++ b/public/shell.php @@ -17,13 +17,14 @@ } body { font-family: 'IBM Plex Sans Arabic', sans-serif; background-color: var(--bg-base); color: var(--text-primary); } [x-cloak] { display: none !important; } + .glass { background: rgba(13, 20, 36, 0.7); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.05); }
@@ -33,97 +34,118 @@ -
-
-

-
- - - -
+
+
+
+

+

+
+
+ + + +
-
+
-
-

إجمالي الفواتير

-

+
+
📄
+

إجمالي الفواتير

+

-
-

قيد المعالجة

-

+
+
+

قيد المعالجة

+

-
-

تم الاعتماد

-

+
+
+

تم الاعتماد

+

- -
-
- + +
+
+
- - - - + + + + + + - - - - -
اسم المكتبالبريد الإلكترونيالهاتفالحالةالشركةالموردالتاريخالمجموعالحالةإجراءات
لا توجد مكاتب بعد
-
-
- - -
-
- - - - - - - - - - - -
اسم الشركةالرقم الضريبيرقم التسجيلتاريخ الإضافة
لا توجد شركات بعد