diff --git a/app/Modules/Auth/AuthController.php b/app/Modules/Auth/AuthController.php index 62f0fe9..533fba6 100644 --- a/app/Modules/Auth/AuthController.php +++ b/app/Modules/Auth/AuthController.php @@ -58,9 +58,14 @@ final class AuthController public function me(Request $request): void { + $db = \App\Core\Database::getInstance(); + $stmt = $db->prepare("SELECT id, tenant_id, name, email, role, totp_enabled FROM users WHERE id = ?"); + $stmt->execute([$request->user->user_id]); + $user = $stmt->fetch(); + Response::json([ 'success' => true, - 'data' => $request->user + 'data' => $user ]); } diff --git a/app/Modules/Companies/CompanyController.php b/app/Modules/Companies/CompanyController.php index 919ffe7..801a176 100644 --- a/app/Modules/Companies/CompanyController.php +++ b/app/Modules/Companies/CompanyController.php @@ -63,7 +63,7 @@ final class CompanyController ]; try { - $this->companyService->createCompany(array_merge($data, ['id' => $id])); // Reuses encryption logic + $this->companyService->updateJoFotara($id, $data); Response::json([ 'success' => true, 'message' => 'تم تحديث بيانات جو-فواتير بنجاح' diff --git a/app/Modules/Companies/CompanyService.php b/app/Modules/Companies/CompanyService.php index bc69c7a..f756cef 100644 --- a/app/Modules/Companies/CompanyService.php +++ b/app/Modules/Companies/CompanyService.php @@ -34,6 +34,21 @@ final class CompanyService return (string)$this->companyModel->create($data); } + public function updateJoFotara(string $id, array $data): bool + { + if (isset($data['jofotara_client_id'])) { + $data['jofotara_client_id_encrypted'] = $this->encryption->encrypt($data['jofotara_client_id']); + unset($data['jofotara_client_id']); + } + + if (isset($data['jofotara_secret_key'])) { + $data['jofotara_secret_key_encrypted'] = $this->encryption->encrypt($data['jofotara_secret_key']); + unset($data['jofotara_secret_key']); + } + + return $this->companyModel->update($id, $data); + } + public function getJoFotaraCredentials(string $companyId): array { $company = $this->companyModel->find($companyId); diff --git a/app/Modules/Dashboard/DashboardController.php b/app/Modules/Dashboard/DashboardController.php index 3149102..56b2bde 100644 --- a/app/Modules/Dashboard/DashboardController.php +++ b/app/Modules/Dashboard/DashboardController.php @@ -33,8 +33,8 @@ final class DashboardController $stmt->execute($params); $statusCounts = $stmt->fetchAll(); - // 3. Recent Activity - $stmt = $db->prepare("SELECT i.*, c.name as company_name FROM invoices i JOIN companies c ON i.company_id = c.id {$where} ORDER BY i.created_at DESC LIMIT 5"); + // 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->execute($params); $recent = $stmt->fetchAll(); diff --git a/app/Modules/Invoices/InvoiceController.php b/app/Modules/Invoices/InvoiceController.php index 8ce1114..9b8b400 100644 --- a/app/Modules/Invoices/InvoiceController.php +++ b/app/Modules/Invoices/InvoiceController.php @@ -25,11 +25,11 @@ final class InvoiceController $assignedCompanyId = $request->user->assigned_company_id ?? null; if ($role === 'super_admin') { - $invoices = $this->invoiceModel->findByTenant($tenantId); + $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 = ? AND i.deleted_at IS NULL ORDER BY i.created_at DESC"); + $stmt->execute([$tenantId]); + $invoices = $stmt->fetchAll(); } else { - // Filter by assigned company for admin, accountant, etc. - $db = \App\Core\Database::getInstance(); - $stmt = $db->prepare("SELECT * FROM invoices WHERE tenant_id = ? AND company_id = ? AND deleted_at IS NULL ORDER BY created_at DESC"); + $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 = ? AND i.company_id = ? AND i.deleted_at IS NULL ORDER BY i.created_at DESC"); $stmt->execute([$tenantId, $assignedCompanyId]); $invoices = $stmt->fetchAll(); } diff --git a/app/Modules/Users/UserController.php b/app/Modules/Users/UserController.php index 9031d78..5d4b2d0 100644 --- a/app/Modules/Users/UserController.php +++ b/app/Modules/Users/UserController.php @@ -38,6 +38,8 @@ final class UserController 'success' => true, 'data' => $user ]); + } + public function create(Request $request): void { $tenantId = $request->tenantId; diff --git a/public/index.php b/public/index.php index 72214c7..1852b42 100644 --- a/public/index.php +++ b/public/index.php @@ -15,6 +15,10 @@ $router = $app->getRouter(); // ══ Auth Routes ══════════════════════════════════════════════ $router->addRoute('POST', '/api/v1/auth/login', [AuthController::class, 'login']); $router->addRoute('POST', '/api/v1/auth/register', [AuthController::class, 'register']); +$router->addRoute('GET', '/api/v1/auth/me', [ + 'middleware' => [\App\Middleware\AuthMiddleware::class], + 'handler' => [AuthController::class, 'me'] +]); $router->addRoute('POST', '/api/v1/auth/2fa/enable', [ 'middleware' => [\App\Middleware\AuthMiddleware::class], 'handler' => [AuthController::class, 'enable2FA'] @@ -37,7 +41,7 @@ $router->addRoute('POST', '/api/v1/companies', [ 'middleware' => [\App\Middleware\AuthMiddleware::class], 'handler' => [\App\Modules\Companies\CompanyController::class, 'create'] ]); -$router->addRoute('PUT', '/api/v1/companies/{id}/jofotara', [ +$router->addRoute('POST', '/api/v1/companies/{id}/jofotara', [ 'middleware' => [\App\Middleware\AuthMiddleware::class], 'handler' => [\App\Modules\Companies\CompanyController::class, 'updateJoFotara'] ]); diff --git a/public/shell.php b/public/shell.php index 53c0d72..af2a0c9 100644 --- a/public/shell.php +++ b/public/shell.php @@ -1,1226 +1,543 @@ - + - مُصادَق — أتمتة الفوترة الضريبية - - - + مُصادَق — منصة أتمتة الفواتير الإلكترونية - - - + - + - -
- - - - - -
- - - - -
-
-
-
- - - + + - -
+ + + + +
+
+

لوحة التحكم

+
+
+ + +
+ +
+
+ +
+
+ + +
+ + +