Update: 2026-05-04 16:06:15

This commit is contained in:
Hamza-Ayed
2026-05-04 16:06:15 +03:00
parent 863dabc069
commit 47652b4d95
5 changed files with 77 additions and 77 deletions

View File

@@ -328,8 +328,11 @@
<div class="p-6 bg-gray-950/50 border-t border-gray-800 flex gap-4">
<template x-if="currentInvoice?.status === 'extracted'">
<button @click="approveInvoice(currentInvoice.id)" class="flex-1 bg-emerald-600 hover:bg-emerald-500 py-3 rounded-xl font-bold transition flex items-center justify-center gap-2">
<span> اعتماد الفاتورة وتوليد QR</span>
<button @click="approveInvoice(currentInvoice.id)"
class="flex-1 bg-emerald-600 hover:bg-emerald-500 py-3 rounded-xl font-bold transition flex items-center justify-center gap-2 disabled:opacity-50"
:disabled="isApproving">
<span x-show="!isApproving"> اعتماد الفاتورة وتوليد QR</span>
<span x-show="isApproving">جارِ الإرسال إلى جوفوترة... </span>
</button>
</template>
<template x-if="currentInvoice?.status === 'approved'">
@@ -417,6 +420,7 @@
showUploadModal: false,
showViewModal: false,
isUploading: false,
isApproving: false,
globalError: '',
newUser: { name: '', email: '', password: '', role: 'employee', tenant_id: '' },
@@ -470,33 +474,39 @@
async approveInvoice(id) {
if (!confirm('هل أنت متأكد من اعتماد الفاتورة وإرسالها إلى جوفوترة؟')) return;
const res = await fetch('/index.php?route=v1/invoices/approve', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.token(),
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: id })
});
const json = await res.json();
if (json.success) {
alert('تم الاعتماد بنجاح!');
this.viewInvoice(id); // Reload to show QR
this.loadInvoices();
} else {
this.showError(json.message);
this.isApproving = true;
try {
const res = await fetch('/index.php?route=v1/invoices/approve', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.token(),
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: id })
});
const json = await res.json();
if (json.success) {
alert('✅ تم الاعتماد بنجاح!');
this.viewInvoice(id); // Reload to show QR
this.loadInvoices();
} else {
this.showError(json.message || 'فشل الاتصال بنظام جوفوترة');
}
} catch (e) {
this.showError('خطأ غير متوقع: ' + e.message);
} finally {
this.isApproving = false;
}
},
generateQRPng(base64Tlv) {
if (!base64Tlv) return '';
const qr = new QRious({
value: base64Tlv,
size: 200,
level: 'M'
});
// Remove 'data:image/png;base64,' from the return, as the template adds it
return qr.toDataURL().split(',')[1];
},
@@ -519,7 +529,7 @@
if (json.success) {
this.showUploadModal = false;
this.loadInvoices();
this.viewInvoice(json.data.id); // Open view modal immediately!
this.viewInvoice(json.data.id);
} else {
this.showError(json.message);
}