🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 02:10

This commit is contained in:
Hamza-Ayed
2026-05-03 02:10:24 +03:00
parent 76a6957627
commit 6b4ef5ffd5

View File

@@ -355,15 +355,23 @@
function showAddCompanyModal() {
const modals = document.getElementById('modals');
modals.innerHTML = `
<div class="fixed inset-0 bg-black/60 backdrop-blur-sm z-[100] flex items-center justify-center" id="company-modal">
<div class="glass-panel p-8 rounded-3xl w-full max-w-md border border-white/10 shadow-2xl">
<div class="fixed inset-0 bg-black/60 backdrop-blur-sm z-[100] flex items-center justify-center p-4 overflow-y-auto" id="company-modal">
<div class="glass-panel p-8 rounded-3xl w-full max-w-lg border border-white/10 shadow-2xl my-auto">
<h3 class="text-2xl font-bold mb-6">إضافة شركة جديدة</h3>
<form id="add-company-form" class="space-y-4">
<input type="text" id="comp-name" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="اسم الشركة" required>
<input type="text" id="comp-tax" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="الرقم الضريبي (مثال: 123456789)" required>
<div class="flex gap-3 mt-6">
<div class="grid grid-cols-2 gap-4">
<input type="text" id="comp-name" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="الاسم (عربي) *" required>
<input type="text" id="comp-name-en" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="الاسم (إنجليزي)">
<input type="text" id="comp-tax" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="الرقم الضريبي *" required>
<input type="text" id="comp-cr" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="السجل التجاري">
<input type="text" id="comp-city" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="المدينة">
<input type="text" id="comp-address" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="العنوان">
<input type="email" id="comp-email" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="البريد الإلكتروني">
<input type="text" id="comp-phone" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none" placeholder="رقم الهاتف">
</div>
<div class="flex gap-3 mt-6 pt-4 border-t border-white/10">
<button type="button" onclick="document.getElementById('company-modal').remove()" class="flex-1 py-3 bg-white/5 hover:bg-white/10 rounded-xl transition">إلغاء</button>
<button type="submit" class="flex-1 py-3 bg-primary hover:bg-primary-dark text-white font-bold rounded-xl shadow-lg transition">حفظ</button>
<button type="submit" class="flex-1 py-3 bg-primary hover:bg-primary-dark text-white font-bold rounded-xl shadow-lg transition">حفظ الشركة</button>
</div>
</form>
</div>
@@ -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 = `
<div class="fixed inset-0 bg-black/60 backdrop-blur-sm z-[100] flex items-center justify-center p-4" id="jofotara-modal">
<div class="glass-panel p-8 rounded-3xl w-full max-w-md border border-white/10 shadow-2xl">
<h3 class="text-2xl font-bold mb-6">إعدادات الربط مع JoFotara</h3>
<form id="jofotara-form" class="space-y-4">
<input type="text" id="jf-client-id" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none font-mono" placeholder="Client ID" required>
<input type="password" id="jf-secret-key" class="w-full bg-black/20 border border-white/10 rounded-xl px-4 py-3 text-white focus:border-primary outline-none font-mono" placeholder="Secret Key" required>
<div class="flex gap-3 mt-6">
<button type="button" onclick="document.getElementById('jofotara-modal').remove()" class="flex-1 py-3 bg-white/5 hover:bg-white/10 rounded-xl transition">إلغاء</button>
<button type="submit" class="flex-1 py-3 bg-primary hover:bg-primary-dark text-white font-bold rounded-xl shadow-lg transition">حفظ الإعدادات</button>
</div>
</form>
</div>
</div>
`;
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"]');