From 6b4ef5ffd503153b8f130ac9e6a88f0f14c0a235 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 3 May 2026 02:10:24 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=D9=85=D9=8F=D8=B5=D8=A7=D8=AF?= =?UTF-8?q?=D9=8E=D9=82:=20=D8=AA=D8=AD=D8=AF=D9=8A=D8=AB=20=D8=A8=D8=B1?= =?UTF-8?q?=D9=85=D8=AC=D9=8A=20=D8=AC=D8=AF=D9=8A=D8=AF=202026-05-03=2002?= =?UTF-8?q?:10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/shell.php | 83 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/public/shell.php b/public/shell.php index 653cb1e..41b29a8 100644 --- a/public/shell.php +++ b/public/shell.php @@ -355,15 +355,23 @@ function showAddCompanyModal() { const modals = document.getElementById('modals'); modals.innerHTML = ` -
-
+
+

إضافة شركة جديدة

- - -
+
+ + + + + + + + +
+
- +
@@ -373,13 +381,66 @@ document.getElementById('add-company-form').onsubmit = async (e) => { e.preventDefault(); try { - const name = document.getElementById('comp-name').value; - const tax = document.getElementById('comp-tax').value; - await API.post('/companies', { name, tax_identification_number: tax }); + const data = { + name: document.getElementById('comp-name').value, + name_en: document.getElementById('comp-name-en').value || null, + tax_identification_number: document.getElementById('comp-tax').value, + commercial_registration_number: document.getElementById('comp-cr').value || null, + city: document.getElementById('comp-city').value || null, + address: document.getElementById('comp-address').value || null, + contact_email: document.getElementById('comp-email').value || null, + contact_phone: document.getElementById('comp-phone').value || null + }; + await API.post('/companies', data); document.getElementById('company-modal').remove(); renderCompanies(); } catch(err) { - alert(err.error?.message_ar || 'حدث خطأ'); + alert(err.error?.message_ar || err.error?.details?.message || err.message || 'حدث خطأ'); + } + }; + } + + function showJoFotaraModal(companyId) { + const modals = document.getElementById('modals'); + modals.innerHTML = ` +
+
+

إعدادات الربط مع JoFotara

+
+ + +
+ + +
+
+
+
+ `; + + document.getElementById('jofotara-form').onsubmit = async (e) => { + e.preventDefault(); + try { + const client_id = document.getElementById('jf-client-id').value; + const secret_key = document.getElementById('jf-secret-key').value; + // Note: We need a PUT endpoint to update Jofotara credentials. + // Our API has: PUT /api/v1/companies/{id}/jofotara + const res = await fetch(`${API.baseUrl}/companies/${companyId}/jofotara`, { + method: 'PUT', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': \`Bearer \${API.accessToken}\` + }, + body: JSON.stringify({ client_id, secret_key }) + }); + const data = await res.json(); + if (!res.ok) throw data; + + document.getElementById('jofotara-modal').remove(); + renderCompanies(); + } catch(err) { + alert(err.error?.message_ar || err.error?.details?.message || 'حدث خطأ أثناء حفظ الإعدادات'); } }; } @@ -405,7 +466,7 @@ document.getElementById('upload-invoice-form').onsubmit = async (e) => { e.preventDefault(); try { - const companyId = parseInt(document.getElementById('inv-comp-id').value); + const companyId = document.getElementById('inv-comp-id').value; // Keep as string (UUID) const payload = JSON.parse(document.getElementById('inv-payload').value); const btn = e.target.querySelector('button[type="submit"]');