Update: 2026-05-07 23:06:22

This commit is contained in:
Hamza-Ayed
2026-05-07 23:06:22 +03:00
parent e04229dfbe
commit 80f3d257b0
20 changed files with 1254 additions and 60 deletions

View File

@@ -1377,9 +1377,13 @@
<div class="table-container">
<div class="table-top-bar">
<span style="font-size:18px;">📄</span>
<h3>إدارة الفواتير</h3>
<span class="table-count" x-text="invoices.length + ' فاتورة'"></span>
</div>
<h3>إدارة الفواتير</h3>
<span class="table-count" x-text="invoices.length + ' فاتورة'"></span>
<div class="flex-1"></div>
<button @click="showExcelModal = true" class="btn btn-teal btn-sm">
<span>📊 استيراد اكسل (Bulk)</span>
</button>
</div>
<table class="data-table">
<thead>
<tr>
@@ -2211,6 +2215,42 @@
</div>
<!-- ════ EXCEL IMPORT MODAL ════════════════════════════ -->
<div x-show="showExcelModal" class="modal-backdrop" x-cloak @click.self="showExcelModal = false">
<div class="modal-card" style="max-width: 500px;">
<div class="modal-header">
<h3>📊 استيراد فواتير (Excel/Bulk)</h3>
<button @click="showExcelModal = false" class="text-2xl">&times;</button>
</div>
<div class="p-6">
<p class="text-sm text-gray-500 mb-6">استخدم هذه الميزة لاستيراد كميات كبيرة من الفواتير من ملف Excel. سيقوم النظام بمحاولة مطابقة الأعمدة تلقائياً.</p>
<div class="form-group mb-4">
<label class="form-label">الشركة المستهدفة</label>
<select x-model="uploadData.company_id" class="form-input">
<option value="">اختر الشركة...</option>
<template x-for="c in companies" :key="c.id">
<option :value="c.id" x-text="c.name"></option>
</template>
</select>
</div>
<div class="form-group mb-6">
<label class="form-label">ملف الـ Excel (.xlsx, .csv)</label>
<input type="file" id="excelFileInput" class="form-input" accept=".xlsx, .xls, .csv">
</div>
<div class="modal-footer px-0 pb-0">
<button @click="uploadExcel()" class="btn btn-teal w-full justify-center" :disabled="isBusy">
<span x-show="!isBusy">🚀 بدء الاستيراد الآن</span>
<span x-show="isBusy"> جاري المعالجة...</span>
</button>
</div>
</div>
</div>
</div>
<!-- ════════════════════════════════════════════════════════
ALPINE.JS LOGIC UNCHANGED
════════════════════════════════════════════════════════ -->
@@ -2222,9 +2262,10 @@
users: [], companies: [], invoices: [], tenants: [], subscription: null, plans: [],
stats: { total: 0, pending: 0, approved: 0 },
showAddUserModal: false, showAddCompanyModal: false, showConnectModal: false,
showUploadModal: false, showViewModal: false, showCompanyStatsModal: false,
showAddTenantModal: false, showEditTenantModal: false, showTenantStatsModal: false,
showAddUserModal: false, showAddCompanyModal: false, showConnectModal: false,
showUploadModal: false, showViewModal: false, showCompanyStatsModal: false,
showExcelModal: false,
showAddTenantModal: false, showEditTenantModal: false, showTenantStatsModal: false,
acknowledgedWarnings: false,
isBusy: false, globalError: '',
@@ -2451,7 +2492,40 @@
this.isBusy = false;
this.showError('حدث خطأ أثناء الاعتماد');
}
},
},
async uploadExcel() {
const fileInput = document.getElementById('excelFileInput');
if (!fileInput.files[0]) return alert('الرجاء اختيار ملف اكسل');
if (!this.uploadData.company_id) return alert('الرجاء اختيار الشركة');
this.isBusy = true;
const formData = new FormData();
formData.append('company_id', this.uploadData.company_id);
formData.append('file', fileInput.files[0]);
try {
const res = await fetch('/index.php?route=v1/excel/import', {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + this.token() },
body: formData
});
const json = await res.json();
this.isBusy = false;
if (json.success) {
alert(json.message);
this.showExcelModal = false;
fileInput.value = '';
this.loadAll();
} else {
this.showError(json.message);
}
} catch (e) {
this.isBusy = false;
this.showError('فشل الاتصال بالخادم أثناء استيراد الاكسل');
}
},
logout() { localStorage.clear(); window.location.href = '/login.php'; }
}));