!Doctype HTML
!Doctype HTML
DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><إدارة الموردين/title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/[email protected]/papaparse.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/xlsx.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#40B3EF',
secondary: '#0047AB',
light: '#F0F8FF',
dark: '#002147'
},
fontSize: {
'base': '16px'
}
}
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?
family=Tajawal:wght@400;500;700&display=swap');
* {
font-family: 'Tajawal', sans-serif;
}
.tree-view.active .tree-content {
display: block;
}
.tree-view .tree-toggle::before {
content: "+";
margin-left: 5px;
font-weight: bold;
transition: transform 0.3s ease;
display: inline-block;
width: 16px;
text-align: center;
}
.tree-view.active .tree-toggle::before {
content: "-";
}
.dark .bg-white {
background-color: #181818;
color: white;
}
.dark .border-gray-200 {
border-color: #333;
}
.dark .text-gray-700 {
color: #ddd;
}
.dark .bg-gray-100 {
background-color: #222;
}
.dark .bg-light {
background-color: #222;
}
.print-only {
display: block !important;
}
.hide-in-print-data-only.print-data-only {
display: none !important;
}
@page {
size: A4;
margin: 15mm 10mm;
}
body {
font-size: 12pt;
background-color: white !important;
color: black !important;
}
table {
page-break-inside: auto;
}
tr {
page-break-inside: avoid;
page-break-after: auto;
}
}
/* تحسين معالجةRTL */
.rtl-grid {
direction: rtl;
text-align: right;
}
/* * تحسين الجداول/
.table-container {
overflow-x: auto;
position: relative;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 8px;
border: 1px solid #ddd;
text-align: right;
}
th {
background-color: #40B3EF;
color: white;
font-weight: bold;
position: sticky;
top: 0;
z-index: 10;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.dark tr:nth-child(even) {
background-color: #2a2a2a;
}
.dark th {
background-color: #205375;
}
.dark .diff-positive {
color: #10b981;
}
.diff-negative {
color: #dc2626;
font-weight: bold;
}
.dark .diff-negative {
color: #ef4444;
}
.print-logo {
max-width: 80px;
max-height: 80px;
}
.modal-overlay.active {
opacity: 1;
}
.modal-content {
background-color: white;
border-radius: 8px;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
max-height: 90vh;
overflow-y: auto;
transform: scale(0.9);
transition: transform 0.3s ease;
}
.dark .modal-content {
background-color: #1f2937;
color: #f3f4f6;
}
.modal-overlay.active .modal-content {
transform: scale(1);
}
/* * أنيميشن التحميل/
.loading-spinner {
display: inline-block;
width: 24px;
height: 24px;
border: 3px solid rgba(64, 179, 239, 0.3);
border-radius: 50%;
border-top-color: #40B3EF;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* * تحسينات النص/
.truncate-text {
max-width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* تحسينات الوصولaccessibility */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
/* * تصميم التوست/
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
max-width: 300px;
}
.toast {
padding: 12px 16px;
border-radius: 6px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 10px;
transform: translateX(120%);
transition: transform 0.3s ease;
display: flex;
align-items: center;
}
.toast.success {
background-color: #059669;
color: white;
}
.toast.error {
background-color: #dc2626;
color: white;
}
.toast.info {
background-color: #40B3EF;
color: white;
}
.toast.visible {
transform: translateX(0);
}
.toast .close-toast {
margin-right: 8px;
cursor: pointer;
opacity: 0.8;
}
.toast .close-toast:hover {
opacity: 1;
}
/* * زر العودة للأعلى/
.back-to-top {
position: fixed;
bottom: 20px;
left: 20px;
width: 40px;
height: 40px;
background-color: #40B3EF;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s, visibility 0.3s;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
z-index: 30;
}
.back-to-top.visible {
opacity: 1;
visibility: visible;
}
.dark .matching-status-complete {
background-color: #065f46;
color: #d1fae5;
}
.matching-status-pending {
background-color: #fff7cd;
color: #854d0e;
padding: 2px 6px;
border-radius: 4px;
font-weight: bold;
}
.dark .matching-status-pending {
background-color: #854d0e;
color: #fef9c3;
}
.matching-status-missing {
background-color: #fee2e2;
color: #b91c1c;
padding: 2px 6px;
border-radius: 4px;
font-weight: bold;
}
.dark .matching-status-missing {
background-color: #991b1b;
color: #fecaca;
}
.commission-annual {
background-color: #C8E6C9;
color: #1B5E20;
}
.commission-special {
background-color: #FFECB3;
color: #FF6F00;
}
.commission-custom {
background-color: #E1BEE7;
color: #6A1B9A;
}
.commission-contract {
background-color: #BBDEFB;
color: #0D47A1;
}
.commission-scientific {
background-color: #F5F5F5;
color: #424242;
}
.dark .commission-annual {
background-color: #1B5E20;
color: #C8E6C9;
}
.dark .commission-special {
background-color: #FF6F00;
color: #FFECB3;
}
.dark .commission-custom {
background-color: #6A1B9A;
color: #E1BEE7;
}
.dark .commission-contract {
background-color: #0D47A1;
color: #BBDEFB;
}
.dark .commission-scientific {
background-color: #424242;
color: #F5F5F5;
}
.notification-card {
border-right: 4px solid;
margin-bottom: 10px;
transition: all 0.3s ease;
}
.notification-card.unread {
border-right-color: #ef4444;
background-color: rgba(239, 68, 68, 0.05);
}
.notification-card.read {
border-right-color: #6b7280;
background-color: rgba(107, 114, 128, 0.05);
}
/* * تنسيقات المخزون/
.stock-status-badge {
display: inline-block;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.875rem;
font-weight: bold;
}
.stock-low {
background-color: #FEE2E2;
color: #B91C1C;
}
.stock-medium {
background-color: #FEF3C7;
color: #D97706;
}
.stock-high {
background-color: #D1FAE5;
color: #047857;
}
.dark .stock-low {
background-color: #B91C1C;
color: #FEE2E2;
}
.dark .stock-medium {
background-color: #D97706;
color: #FEF3C7;
}
.dark .stock-high {
background-color: #047857;
color: #D1FAE5;
}
</style>
</head>
<body class="bg-light dark:bg-dark text-gray-800 dark:text-gray-100">
<div class="flex flex-col min-h-screen">
<!-- Back to Top Button -->
<button id="backToTop" class="back-to-top" aria-label=">"العودة إلى الأعلى
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-
width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" />
</svg>
</button>
<div class="mt-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold text-secondary"> قائمة
<الموردين/h3>
<button id="addNewSupplier" class="bg-green-500
text-white px-3 py-1 rounded text-sm hover:bg-green-600 transition-colors"> إضافة
<مورد جديد/button>
</div>
<div class="mb-4 relative">
<input type="text" id="supplierSearch"
placeholder="بحث عن مورد..." class="w-full p-2 border border-gray-300 rounded text-
base pr-10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5
w-5 text-gray-400 absolute top-2.5 left-3" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4
4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6
6 0 012 8z" clip-rule="evenodd" />
</svg>
</div>
<div class="table-container">
<table id="suppliersTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><الكود/th>
<th scope="col"><اسم المورد/th>
<th scope="col"><العنوان/th>
<th scope="col"><تلفون/th>
<th scope="col"><فاكس/th>
<th scope="col"><الحساب المرجع/th>
<th scope="col"><العمليات/th>
</tr>
</thead>
<tbody id="suppliersTableBody">
<!-- Suppliers will be loaded here -->
<tr>
<td colspan="7" class="text-center py-
4"><ال توجد بيانات متاحة/td>
</tr>
</tbody>
</table>
</div>
<div id="suppliersPagination" class="mt-4 flex justify-
center items-center">
<!-- Pagination will be added here -->
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2">قائمة
<الأصناف المتوفرة لدى المورد/h3>
<div class="mb-4 relative">
<input type="text" id="inventorySearch"
placeholder="بحث عن صنف..." class="w-full p-2 border border-gray-300 rounded text-
base pr-10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5
w-5 text-gray-400 absolute top-2.5 left-3" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4
4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6
6 0 012 8z" clip-rule="evenodd" />
</svg>
</div>
<div class="table-container">
<table id="inventoryTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><كود الصنف/th>
<th scope="col"><اسم الصنف/th>
<th scope="col"><الوحدة/th>
<th scope="col"><الكمية المتوفرة/th>
<th scope="col"><سعر الشراء/th>
<th scope="col"><آخر تحديث/th>
<th scope="col"><حالة المخزون/th>
<th scope="col"><العمليات/th>
</tr>
</thead>
<tbody id="inventoryTableBody">
<!-- Inventory items will be loaded here --
>
<tr>
<td colspan="8" class="text-center py-
4"><يرجى اختيار مورد أوًال/td>
</tr>
</tbody>
</table>
</div>
<div id="inventoryPagination" class="mt-4 flex justify-
center items-center">
<!-- Pagination will be added here -->
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-lg font-bold text-secondary mb-4">
<تعريف العمولة حسب نوع المستند/h3>
<div class="table-container">
<table id="docCommissionTable" class="w-full
border-collapse">
<thead>
<tr>
<th scope="col"><نوع المستند/th>
<th scope="col"><تطبيق العمولة/th>
<th scope="col"><نوع العمولة/th>
<th scope="col">نسبة العمولة
(%)</th>
</tr>
</thead>
<tbody id="docCommissionTableBody">
<!-- سيتم تعبئة البيانات هنا من
الجافاسكريبت-->
</tbody>
</table>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2"> كشف
<الحساب/h3>
<div class="mb-4">
<select id="viewStatementSupplier" class="w-full p-
2 border border-gray-300 rounded text-base">
<option value="">-- اختر المورد لعرض الكشف--
</option>
<!-- Suppliers will be loaded here -->
</select>
</div>
<div class="mb-2 flex justify-between items-center">
<div id="statementNumber" class="text-primary font-
bold"></div>
<div id="statementDate"
class="text-gray-600"></div>
</div>
<div class="table-container">
<table id="statementsTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><الفرع/th>
<th scope="col"><التاريخ/th>
<th scope="col"><رقم المستند/th>
<th scope="col"><نوع المستند/th>
<th scope="col"><البيان/th>
<th scope="col"> قيمة البضاعة
<المتبقية/th>
<th scope="col"><مدين/th>
<th scope="col"><دائن/th>
<th scope="col"><الرصيد/th>
<th scope="col"><العمليات/th>
</tr>
</thead>
<tbody id="statementsTableBody">
<!-- Statements will be loaded here -->
<tr>
<td colspan="10" class="text-center py-
4"><ال توجد بيانات متاحة/td>
</tr>
</tbody>
</table>
</div>
<div class="mt-4 flex flex-wrap gap-2">
<button id="printStatement" class="bg-secondary
text-white px-4 py-2 rounded hover:bg-primary transition-colors">
طباعة الكشف
</button>
<button id="sendStatementWhatsapp" class="bg-green-
500 text-white px-4 py-2 rounded hover:bg-green-600 transition-colors hidden">
إرسال الكشف عبر الواتساب
</button>
<button id="addManualStatement" class="bg-primary
text-white px-4 py-2 rounded hover:bg-secondary transition-colors">
إضافة حركة يدويًا
</button>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2">
<عمليات المطابقة/h3>
<div class="table-container">
<table id="matchingTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><الفرع/th>
<th scope="col"><التاريخ/th>
<th scope="col"><رقم المستند/th>
<th scope="col"><نوع المستند/th>
<th scope="col"><البيان/th>
<th scope="col"><مدين/th>
<th scope="col"><دائن/th>
<th scope="col"><الرصيد/th>
<th scope="col"><حالة المطابقة/th>
<th scope="col"><مبلغ المورد/th>
<th scope="col"><مالحظات/th>
<th scope="col"><الفارق/th>
</tr>
</thead>
<tbody id="matchingTableBody">
<!-- Matching data will be loaded here -->
<tr>
<td colspan="12" class="text-center py-
4"><يرجى اختيار مورد أوًال/td>
</tr>
</tbody>
</table>
</div>
<div class="mt-4">
<button id="saveMatching" class="bg-primary text-
white px-4 py-2 rounded hover:bg-secondary transition-colors"><حفظ المطابقة/button>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2">قائمة
<العمليات الغير مرحلة/h3>
<div class="table-container">
<table id="unpostedTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><الفرع/th>
<th scope="col"><التاريخ/th>
<th scope="col"><رقم المستند/th>
<th scope="col"><نوع المستند/th>
<th scope="col"><البيان/th>
<th scope="col"> قيمة البضاعة
<المتبقية/th>
<th scope="col"><مدين/th>
<th scope="col"><دائن/th>
<th scope="col"><الرصيد/th>
<th scope="col"><العمليات/th>
</tr>
</thead>
<tbody id="unpostedTableBody">
<!-- Unposted transactions will be loaded
here -->
<tr>
<td colspan="10" class="text-center py-
4"><يرجى اختيار مورد أوًال/td>
</tr>
</tbody>
</table>
</div>
<div class="mt-4">
<button id="moveToStatement" class="bg-green-500
text-white px-4 py-2 rounded hover:bg-green-600 transition-colors"> ترحيل العمليات
<المحددة/button>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2">إدارة
<العموالت/h3>
<div class="table-container">
<table id="commissionsTable" class="w-full border-
collapse">
<thead>
<tr>
<th scope="col"><التاريخ/th>
<th scope="col"><رقم المستند/th>
<th scope="col"><نوع المستند/th>
<th scope="col"><البيان/th>
<th scope="col"><مدين/th>
<th scope="col"><دائن/th>
<th scope="col"><مرتبط بعمولة/th>
<th scope="col"><نوع العمولة/th>
<th scope="col"><نسبة العمولة/th>
<th scope="col"><مبلغ العمولة/th>
</tr>
</thead>
<tbody id="commissionsTableBody">
<!-- Commission data will be loaded here --
>
<tr>
<td colspan="10" class="text-center py-
4"><يرجى اختيار مورد أوًال/td>
</tr>
</tbody>
</table>
</div>
<div class="mt-4 p-4 bg-gray-100 dark:bg-gray-700
rounded-lg">
<h4 class="text-lg font-bold text-secondary mb-2">
<ملخص العموالت/h4>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label class="block mb-2 font-bold"> إجمالي
<العمولة النقدية/label>
<div id="totalCashCommission" class="p-2
bg-white dark:bg-gray-600 border border-gray-300 rounded">0.00</div>
</div>
<div>
<label class="block mb-2 font-bold"> إجمالي
<العمولة العينية/label>
<div id="totalInKindCommission" class="p-2
bg-white dark:bg-gray-600 border border-gray-300 rounded">0.00</div>
</div>
<div>
<label for="receivedCashCommission"
class="block mb-2 font-bold"><العمولة النقدية المستلمة/label>
<input type="number"
id="receivedCashCommission" class="w-full p-2 border border-gray-300 rounded text-
base" value="0">
</div>
<div>
<label for="receivedInKindCommission"
class="block mb-2 font-bold"><العمولة العينية المستلمة/label>
<input type="number"
id="receivedInKindCommission" class="w-full p-2 border border-gray-300 rounded
text-base" value="0">
</div>
</div>
<div class="mt-4">
<button id="saveCommissions" class="bg-primary
text-white px-4 py-2 rounded hover:bg-secondary transition-colors"> حفظ
<العموالت/button>
</div>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-xl font-bold text-secondary mb-2">قائمة
<حالة مطابقة الموردين/h3>
<div class="mb-4 relative">
<input type="text" id="supplierStatusSearch"
placeholder="بحث عن مورد..." class="w-full p-2 border border-gray-300 rounded text-
base pr-10">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5
w-5 text-gray-400 absolute top-2.5 left-3" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4
4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6
6 0 012 8z" clip-rule="evenodd" />
</svg>
</div>
<div class="table-container">
<table id="suppliersStatusTable" class="w-full
border-collapse">
<thead>
<tr>
<th scope="col"><رقم المورد/th>
<th scope="col"><اسم المورد/th>
<th scope="col"><حالة المطابقة/th>
<th scope="col"><إجمالي الفارق/th>
<th scope="col"><تفاصيل/th>
</tr>
</thead>
<tbody id="suppliersStatusTableBody">
<!-- توليد البيانات ديناميكًيا-->
<tr>
<td colspan="5" class="text-center py-
4">يتم تحميل البيانات...</td>
</tr>
</tbody>
</table>
</div>
<div id="suppliersStatusPagination" class="mt-4 flex
justify-center items-center">
<!-- ترقيم الصفحات سيظهر هنا-->
</div>
</div>
</div>
<div class="print-content">
<div id="documentTypesSummary" class="mt-4 p-4 bg-
gray-100 dark:bg-gray-700 rounded-lg mb-6">
<h4 class="text-lg font-bold text-secondary mb-
4"><ملخص العمليات حسب نوع المستند/h4>
<div class="table-container">
<table id="documentTypesSummaryTable"
class="w-full border-collapse">
<thead>
<tr>
<th scope="col"> نوع
<المستند/th>
<th scope="col"> عدد
<العمليات/th>
<th scope="col"> إجمالي
<المدين/th>
<th scope="col"> إجمالي
<الدائن/th>
<th scope="col"> الرصيد
<الصافي/th>
</tr>
</thead>
<tbody
id="documentTypesSummaryTableBody">
<!-- سيتم إضافة بيانات ملخص أنواع
المستندات هنا-->
</tbody>
</table>
</div>
</div>
// ============================
// إضافة مكون إدارة الإشعارات
// ============================
const ToastManager = {
show: function(message, type = 'info', duration = 3000) {
const container = document.getElementById('toastContainer');
if (!container) return;
container.appendChild(toast);
return toast;
},
hide: function(toast) {
toast.classList.remove('visible');
setTimeout(() => {
if (toast && toast.parentNode) {
toast.parentNode.removeChild(toast);
}
}, 300);
},
// ============================
// )مكون إدارة الموداالت (مربعات الحوار
// ============================
const ModalManager = {
modals: [],
create: function(options) {
const modal = document.createElement('div');
modal.className = 'modal-overlay';
modal.setAttribute('role', 'dialog');
modal.setAttribute('aria-modal', 'true');
modal.innerHTML = `
<div class="modal-content p-6 relative">
${title ? `<h3 class="text-xl font-bold text-secondary mb-
4">${title}</h3>` : ''}
<div class="modal-body">
${content}
</div>
${showFooter ? `
<div class="flex justify-end mt-4 gap-2">
${options.showCancel !== false ? `<button
class="modal-cancel bg-gray-300 text-gray-800 px-4 py-2 rounded hover:bg-gray-400
transition-colors">${cancelText}</button>` : ''}
<button class="modal-ok bg-primary text-white px-4
py-2 rounded hover:bg-secondary transition-colors">${okText}</button>
</div>
` : ''}
<button class="modal-close absolute top-2 left-2 text-gray-
500 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-100">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6"
fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-
linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
<span class="sr-only"><إغالق/span>
</button>
</div>
`;
document.body.appendChild(modal);
// أزرار الإغالق
const closeBtn = modal.querySelector('.modal-close');
if (closeBtn) {
closeBtn.addEventListener('click', () => {
this.close(modal);
if (options.onCancel) options.onCancel();
});
}
// زر الإلغاء
const cancelBtn = modal.querySelector('.modal-cancel');
if (cancelBtn) {
cancelBtn.addEventListener('click', () => {
this.close(modal);
if (options.onCancel) options.onCancel();
});
}
// زر الموافقة
const okBtn = modal.querySelector('.modal-ok');
if (okBtn) {
okBtn.addEventListener('click', () => {
if (options.onOk) options.onOk(modal);
if (options.closeOnOk !== false) {
this.close(modal);
}
});
}
document.addEventListener('keydown', escapeHandler);
return modal;
},
close: function(modal) {
modal.classList.remove('active');
setTimeout(() => {
if (modal && modal.parentNode) {
modal.parentNode.removeChild(modal);
// إزالة المودال من المصفوفة
this.modals = this.modals.filter(m => m !== modal);
}
}, 300);
},
closeAll: function() {
[...this.modals].forEach(modal => {
this.close(modal);
});
},
return modal;
}
};
// ============================
// تحسين االصطفاف للتيبالت
// ============================
function setupTableSorting(tableId, options = {}) {
const table = document.getElementById(tableId);
if (!table) return;
return text.toLowerCase();
}
th.classList.add('cursor-pointer', 'select-none');
th.setAttribute('tabindex', '0');
// فرز الصفوف
rows.sort((a, b) => {
const aValue = getCellValue(a, columnIndex);
const bValue = getCellValue(b, columnIndex);
// ============================
// ترقيم الصفحات للجداول
// ============================
function setupTablePagination(tableId, paginationId, itemsPerPage = 10) {
const table = document.getElementById(tableId);
const pagination = document.getElementById(paginationId);
if (startPage > 2) {
const ellipsis = document.createElement('span');
ellipsis.className = 'px-3 py-1';
ellipsis.textContent = '...';
pagination.appendChild(ellipsis);
}
}
// ============================
// مدير البحث في الجداول
// ============================
function setupTableSearch(searchInputId, tableId, options = {}) {
const searchInput = document.getElementById(searchInputId);
const table = document.getElementById(tableId);
// وظيفة البحث
function performSearch() {
const searchTerm = searchInput.value.toLowerCase();
const rows = Array.from(tbody.rows);
let matchCount = 0;
// فلترة الصفوف
rows.forEach(row => {
let shouldShow = false;
if (paginationManager) {
// نخفي الصفوف غير المطابقة،إذا كان هناك مدير ترقيم صفحات
ونحدث مدير الترقيم
row.dataset.searchMatch = shouldShow ? 'true' : 'false';
if (shouldShow) matchCount++;
} else {
// مباشرة تحديث عرض الصفوف بدون ترقيم صفحات
row.style.display = shouldShow ? '' : 'none';
if (shouldShow) matchCount++;
}
});
if (!existingMessage) {
const noResultsRow = document.createElement('tr');
noResultsRow.className = 'no-results-message';
noResultsRow.innerHTML = `<td colspan="$
{table.querySelectorAll('thead th').length}" class="text-center py-4"> ال توجد نتائج
<للبحث/td>`;
tbody.appendChild(noResultsRow);
}
} else {
const existingMessage = tbody.querySelector('.no-results-
message');
if (existingMessage) {
existingMessage.remove();
}
}
}
// إضافة مستمع للبحث مع تأخير
searchInput.addEventListener('input', () => {
debounce(performSearch);
});
// تحديث مع البداية
clearButton.style.opacity = '0';
return {
search: performSearch
};
}
// ============================
// مدير التصدير للإكسل
// ============================
function exportTableToExcel(tableId, fileName = 'exported_data', options =
{}) {
const table = document.getElementById(tableId);
if (!table) {
ToastManager.error(';)'لم يتم العثور على الجدول المطلوب للتصدير
return;
}
try {
// معالجة الخيارات
const sheetName = options.sheetName || 'Sheet1';
const includeHidden = options.includeHidden !== false;
const excludeColumns = options.excludeColumns || [];
const headerMap = options.headerMap || {}; // تخصيص عناوين الأعمدة
// إضافة الترويسة
const headerRow = [];
const headers = table.querySelectorAll('thead th');
headers.forEach((header, index) => {
if (!excludeColumns.includes(index)) {
// استخدام االسم المخصص أو نص العنوان الأصلي
headerRow.push(headerMap[index] ||
header.textContent.trim());
}
});
data.push(headerRow);
// إضافة الصفوف
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
// تخطي الصفوف المخفية إذا تم تحديد ذلك
if (!includeHidden && row.style.display === 'none') {
return;
}
rowData.push(cellData);
}
});
// تنزيل الملف
XLSX.writeFile(wb, `${fileName}.xlsx`);
// ============================
// تحسين وظائف التخزين المحلي
// ============================
const SupplierStorage = {
// تحسين الوظائف العامة مع معالجة الأخطاء
saveData: function(key, data) {
try {
localStorage.setItem(key, JSON.stringify(data));
return true;
} catch (error) {
// معالجة خطأ امتالء التخزين
if (error instanceof DOMException && (error.code === 22 ||
error.name === 'QuotaExceededError')) {
ToastManager.error(' حاول إزالة.ال توجد مساحة كافية للتخزين
بعض البيانات غير المستخدمة.');
} else {
console.error(`( خطأ في حفظ البيانات${key}):`, error);
ToastManager.error(';)'حدث خطأ أثناء حفظ البيانات
}
return false;
}
},
removeData: function(key) {
try {
localStorage.removeItem(key);
return true;
} catch (error) {
console.error(`( خطأ في حذف البيانات${key}):`, error);
return false;
}
},
getSuppliers: function() {
return this.getData('suppliers', []);
},
getStatements: function(supplierId) {
return this.getData(`statements_${supplierId}`, []);
},
getUnpostedTransactions: function(supplierId) {
return this.getData(`unposted_${supplierId}`, []);
},
getMatchingData: function(supplierId) {
return this.getData(`matching_${supplierId}`, []);
},
getCommissionData: function(supplierId) {
return this.getData(`commission_${supplierId}`, []);
},
getCompanyInfo: function() {
return this.getData('companyInfo', {
nameAr: '',
nameEn: '',
branch: '',
address: '',
mobile: '',
whatsapp: '',
phone: '',
email: '',
logo: '',
logoSize: 80
});
},
getRegionalSettings: function() {
return this.getData('regionalSettings', {
currency: 'YER',
numberFormat: 'comma',
allowNegative: true
});
},
getCommissionSetup: function(supplierId) {
return this.getData(`commission_setup_${supplierId}`, {
defaultType: 'cash',
defaultPercentage: 10,
defaultBasis: 'purchases',
docTypes: []
});
},
getCurrentStatementNumber: function() {
try {
return parseInt(localStorage.getItem('statementNumber') ||
'0');
} catch (error) {
console.error("خطأ في استرجاع رقم كشف الحساب الحالي:", error);
return 0;
}
},
// وظائف محسنة لمعلومات كشف الحساب
saveStatementInfo: function(statementNumber, supplierId, date,
recordCount) {
try {
const statementInfo = {
number: statementNumber,
supplierId: supplierId,
date: date,
recordCount: recordCount,
createdAt: new Date().toISOString()
};
getDocumentTypes: function() {
return this.getData('documentTypes', DEFAULT_DOC_TYPES);
},
getInventoryItems: function(supplierId) {
return this.getData(`inventory_${supplierId}`, []);
},
getCommissionNotifications: function() {
return this.getData('commission_notifications', []);
},
const a = document.createElement('a');
a.href = url;
a.download = `suppliers_backup_${new
Date().toISOString().slice(0, 10)}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
return true;
} catch (error) {
console.error("خطأ في إنشاء نسخة احتياطية:", error);
return false;
}
},
استعادة النسخة االحتياطية //
{ )restoreBackup: function(backupData
{ try
مسح البيانات الحالية //
;)(localStorage.clear
;return true
{ )} catch (error
;):", errorخطأ في استعادة النسخة االحتياطية"(console.error
;return false
}
}
;}
============================ //
أنواع المستندات االفتراضية //
============================ //
[ = const DEFAULT_DOC_TYPES
{
',رصيد افتتاحي' type:
الرصيد الإفتتــاحي,رصيد افتتاحي,الرصيد االفتتاحي,الرصيد ' keywords:
'الأول,رصيد أول المدة,رصيد اول
},
{
',فاتورة تعويض مجانيه' type:
فاتورة تعويض رقم,فاتورة تعويض مجانيه,فاتورة تعويض,تعويض' keywords:
'مجان,بضاعة مجانية,تعويض عن,فاتورة مجانية
},
{
',فاتورة مشترات آجله' type:
لكم فاتورة مشتروات آجلة رقم,لكم فاتورة مشتريات ' keywords:
آجلة,فاتورة مشتريات اجل,لكم فاتورة مشتريات اجله,مشتريات آجلة,فاتورة آجل,مشترات
'آجل,فاتورة مشتريات بالأجل
},
{
',فاتورة مشتريات نقدية' type:
فاتورة مشتروات نقديةرقم,فاتورة مشتريات نقدية رقم,فاتورة' keywords:
'مشتريات نقدي,مشتريات نقد,مشتريات كاش,فاتورة نقد,مشتريات نقدية
},
{
',سند صرف نقدي' type:
عليكم أمر صرف نقدي رقم,عليكم امر صرف نقدي رقم,امر صرف ' keywords:
نقدي,سند صرف نقد,صرف نقد,دفع نقدي,نقدية للمورد,سداد نقدي,دفعة نقدية,تحويل نقدي,أمر
'صرف نقدي رقم
},
{
',مرود مشتريات اجل' type:
عليكم مردودمشتروات رقم,مردود مشتريات رقم,مرتجع ' keywords:
مشتريات,ارتجاع مشتريات,مردود مشتريات اجل,مرتجع مشتروات,مردودات مشتريات,ارجاع
'مشتريات,مرجوع مشتريات,مردودمشتروات رقم
},
{
',سند صرف شيك' type:
أمر صرف شيكات رقم,امر صرف شيك,سند صرف شيك,دفع شيك,شيك ' keywords:
دفع بشيك,سداد شيك,دفعة بشيك,شيك مسحوب,شيك بنكي,'رقم
},
{
type: ''قيد يومية,
keywords: ' قيد,قيد اليومية,قيد تسوية,سند قيد,قيد محاسبي,قيد يومية
قيد اليومية العامة,قيد فروق,قيد التسويات رقم,قيد تصحيح,قيد تعديل,'عام
},
{
type: ''قيد فارق عملة,
keywords: 'قيد فارق عملة,فرق العملة,'قيد فروق العملة
},
{
type: ''عمولة نقدية,
keywords: 'خصم عمولة,عمولة نقدية,اشعار خصم,'إشعار خصم رقم
},
{
type: ''اشعار مدين,
keywords: 'مدين,خصم على المورد,اشعار خصم,إشعار مدين,اشعار مدين رقم
خصم مورد,'بقيمة
},
{
type: ''اشعار دائن,
keywords: 'اضافة,إشعار اضافة,اشعار اضافه,إشعار دائن,اشعار دائن رقم
إضافة للمورد,'رصيد
},
{
type: ''مرتجع مشتريات نقدية,
keywords: ' مردود,ارتجاع مشتريات نقدية,مرتجع مشتريات نقدية
ارجاع نقدي,'نقدي
}
];
// ============================
// وظائف تنسيق الأرقام
// ============================
function formatNumber(number) {
const settings = SupplierStorage.getRegionalSettings();
return formattedNumber;
}
// ============================
// التعرف على نوع المستند
// ============================
function detectDocumentType(description) {
if (!description) return '';
description = description.trim().toLowerCase();
// ============================
// تحليل التاريخ العربي
// ============================
function parseArabicDate(dateStr) {
if (!dateStr) return null;
try {
if (dateStr.includes('/')) {
// التنسيقDD/MM/YYYY أو ما شابه
dateParts = dateStr.split('/');
if (dateParts.length === 3) {
if (dateParts[2].length === 2) {
year = parseInt('20' + dateParts[2]);
} else {
year = parseInt(dateParts[2]);
}
return date;
} catch (error) {
console.error("خطأ في تحليل التاريخ:", error);
return null;
}
}
// ============================
// فلترة كشوفات الحساب حسب نطاق تاريخ
// ============================
function filterStatementsByDate(statements, fromDate, toDate) {
if (!fromDate || !toDate) return statements;
// ============================
// إعداد زر العودة للأعلى
// ============================
function initializeBackToTopButton() {
const backToTopBtn = document.getElementById('backToTop');
if (!backToTopBtn) return;
// ============================
// تهيئة التنقل في شجرة القائمة
// ============================
function initializeTreeNavigation() {
const treeToggles = document.querySelectorAll('.tree-toggle');
treeToggles.forEach(toggle => {
toggle.addEventListener('click', () => {
const treeView = toggle.parentElement;
treeView.classList.toggle('active');
});
// ============================
// تهيئة التنقل بين الشاشات
// ============================
function initializeScreenNavigation() {
const screenLinks = document.querySelectorAll('[data-screen]');
screenLinks.forEach(link => {
link.addEventListener('click', () => {
const screenId = link.dataset.screen;
showScreen(screenId);
});
// ============================
// وظيفة عرض الشاشة
// ============================
function showScreen(screenId) {
// إخفاء جميع الشاشات
document.querySelectorAll('.screen-content').forEach(screen => {
screen.classList.add('hidden');
});
// ============================
// تهيئة شاشة إشعارات العموالت
// ============================
function loadCommissionNotifications() {
const notifications = SupplierStorage.getCommissionNotifications();
const container = document.getElementById('notificationsContainer');
if (!container) return;
container.innerHTML = '';
sortedNotifications.forEach(notification => {
const notificationCard = document.createElement('div');
notificationCard.className = `notification-card p-4 rounded-lg $
{notification.read ? 'read' : 'unread'}`;
notificationCard.setAttribute('data-id', notification.id);
// تنسيق التاريخ
const date = new Date(notification.date);
const formattedDate = date.toLocaleDateString('ar-SA', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
notificationCard.innerHTML = `
<div class="flex justify-between items-start">
<div>
<h4 class="font-bold">${notification.title}</h4>
</script>
</body>
</html>