From 75f969f821849a5be1a9285d2642dbc4d6fcd239 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 4 May 2026 21:34:28 +0300 Subject: [PATCH] Update: 2026-05-04 21:34:28 --- app/modules_app/tenants/update.php | 63 ++++++++++++++++++++++++++++++ public/index.php | 1 + public/shell.php | 61 +++++++++++++++++++++++++++-- 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 app/modules_app/tenants/update.php diff --git a/app/modules_app/tenants/update.php b/app/modules_app/tenants/update.php new file mode 100644 index 0000000..3bc1682 --- /dev/null +++ b/app/modules_app/tenants/update.php @@ -0,0 +1,63 @@ + 'required', + 'name' => 'required', + 'email' => 'required|email', + 'status' => 'required' +]); + +if ($errors) { + json_error('Validation Failed', 422, $errors); +} + +$db = Database::getInstance(); + +try { + // Encrypt sensitive data + $encryptedName = \App\Core\Encryption::encrypt($data['name']); + $encryptedEmail = \App\Core\Encryption::encrypt($data['email']); + + $stmt = $db->prepare(" + UPDATE tenants + SET name = ?, email = ?, phone = ?, status = ?, updated_at = NOW() + WHERE id = ? + "); + + $stmt->execute([ + $encryptedName, + $encryptedEmail, + $data['phone'] ?? null, + $data['status'], + $data['id'] + ]); + + if ($stmt->rowCount() === 0) { + // Might be unchanged or ID doesn't exist + $check = $db->prepare("SELECT id FROM tenants WHERE id = ?"); + $check->execute([$data['id']]); + if (!$check->fetch()) { + json_error('Tenant not found', 404); + } + } + + json_success(null, 'تم تحديث بيانات المكتب بنجاح'); + +} catch (\Exception $e) { + json_error('حدث خطأ أثناء التحديث: ' . $e->getMessage(), 500); +} diff --git a/public/index.php b/public/index.php index ab7aad6..3a78f91 100644 --- a/public/index.php +++ b/public/index.php @@ -36,6 +36,7 @@ $routes = [ 'v1/dashboard/stats' => ['GET', 'dashboard/stats.php'], 'v1/tenants' => ['GET', 'tenants/index.php'], 'v1/tenants/create' => ['POST', 'tenants/create.php'], + 'v1/tenants/update' => ['POST', 'tenants/update.php'], ]; if (isset($routes[$route])) { diff --git a/public/shell.php b/public/shell.php index 70cf18e..321efb5 100644 --- a/public/shell.php +++ b/public/shell.php @@ -274,7 +274,7 @@ - + @@ -504,6 +504,45 @@
✅ مدققة وموثقة محلياً
+ + +
+
+

تعديل بيانات المكتب

+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+ + +
+
+
+
@@ -556,7 +595,7 @@ showAddUserModal: false, showAddCompanyModal: false, showConnectModal: false, showUploadModal: false, showViewModal: false, showCompanyStatsModal: false, - showAddTenantModal: false, + showAddTenantModal: false, showEditTenantModal: false, isBusy: false, globalError: '', newUser: { name: '', email: '', password: '', role: 'accountant' }, @@ -564,7 +603,7 @@ newTenant: { name: '', email: '', phone: '', manager_name: '', manager_email: '', manager_password: '' }, connectData: { client_id: '', secret_key: '', income_source_sequence: '1' }, uploadData: { company_id: '' }, - currentCompany: null, currentInvoice: null, companyStats: null, + currentCompany: null, currentInvoice: null, companyStats: null, currentTenant: { name: '', email: '', phone: '', status: '' }, init() { if (!this.user) { window.location.href = '/login.php'; return; } @@ -643,6 +682,22 @@ this.isBusy = false; }, + openEditTenantModal(t) { + this.currentTenant = JSON.parse(JSON.stringify(t)); + this.showEditTenantModal = true; + }, + + async updateTenant() { + this.isBusy = true; + const res = await this.apiRequest('v1/tenants/update', 'POST', this.currentTenant); + if (res) { + this.showEditTenantModal = false; + this.loadAll(); + alert('تم تحديث بيانات المكتب بنجاح'); + } + this.isBusy = false; + }, + openConnectModal(company) { this.currentCompany = company; this.connectData.client_id = '';