DO HTML
DO 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>
<p class="text-sm text-gray-500 mt-1">$
{formattedDate}</p>
</div>
<div class="flex gap-2">
${!notification.read ? `
<button class="mark-read bg-blue-100 text-blue-800
px-2 py-1 rounded text-xs hover:bg-blue-200 dark:bg-blue-900 dark:text-blue-100
dark:hover:bg-blue-800">
تعليم كمقروء
</button>
` : ''}
<button class="delete-notification bg-red-100 text-red-
800 px-2 py-1 rounded text-xs hover:bg-red-200 dark:bg-red-900 dark:text-red-100
dark:hover:bg-red-800">
حذف
</button>
</div>
</div>
<div class="mt-2">
<p>${notification.message}</p>
</div>
${notification.actionLink ? `
<div class="mt-3">
<button class="notification-action bg-primary text-
white px-3 py-1 rounded text-sm hover:bg-secondary transition-colors" data-link="$
{notification.actionLink}">
${notification.actionText || '}'عرض التفاصيل
</button>
</div>
` : ''}
`;
container.appendChild(notificationCard);
});
markNotificationAsRead(notificationId);
card.classList.remove('unread');
card.classList.add('read');
this.remove();
});
});
container.querySelectorAll('.delete-notification').forEach(button => {
button.addEventListener('click', function() {
const card = this.closest('.notification-card');
const notificationId = card.getAttribute('data-id');
deleteNotification(notificationId);
card.remove();
container.querySelectorAll('.notification-action').forEach(button => {
button.addEventListener('click', function() {
const link = this.getAttribute('data-link');
if (link) {
const [screenId, params] = link.split('?');
// االنتقال إلى الشاشة المطلوبة
showScreen(screenId);
SupplierStorage.saveCommissionNotifications(updatedNotifications);
// تحديث العداد
const unreadCount = updatedNotifications.filter(notification => !
notification.read).length;
updateNotificationBadge(unreadCount);
}
// حذف إشعار
function deleteNotification(notificationId) {
const notifications = SupplierStorage.getCommissionNotifications();
const updatedNotifications = notifications.filter(notification =>
notification.id !== notificationId);
SupplierStorage.saveCommissionNotifications(updatedNotifications);
// تحديث العداد
const unreadCount = updatedNotifications.filter(notification => !
notification.read).length;
updateNotificationBadge(unreadCount);
}
SupplierStorage.saveCommissionNotifications(updatedNotifications);
// تحديث العداد
updateNotificationBadge(0);
notifications.push(newNotification);
SupplierStorage.saveCommissionNotifications(notifications);
// تحديث العداد
const unreadCount = notifications.filter(notification => !
notification.read).length;
updateNotificationBadge(unreadCount);
return newNotification;
}
if (!badge) return;
if (count > 0) {
badge.textContent = count > 99 ? '99+' : count;
badge.classList.remove('hidden');
} else {
badge.classList.add('hidden');
}
}
suppliers.forEach(supplier => {
const commissions = SupplierStorage.getCommissionData(supplier.id);
if (!commissions || commissions.length === 0) return;
commissions.forEach(commission => {
if (commission.hasCommission) {
if (commission.commissionType === 'cash') {
totalCashCommission += commission.commissionAmount;
} else if (commission.commissionType === 'kind') {
totalInKindCommission += commission.commissionAmount;
}
}
});
// التحقق مما إذا كان هناك إشعار موجود بالفعل لهذا المورد
const notifications =
SupplierStorage.getCommissionNotifications();
const existingNotification = notifications.find(notification =>
notification.title.includes(supplier.name) &&
notification.actionLink &&
notification.actionLink.includes(supplier.id)
);
addNotification(
` عموالت مستحقة- ${supplier.name}`,
message,
`manage-commissions?supplierId=${supplier.id}`,
''عرض تفاصيل العموالت
);
}
}
});
return pendingCommissionsCount;
}
// ============================
// تحميل إعدادات أنواع المستندات
// ============================
function loadDocTypesSettings() {
const docTypes = SupplierStorage.getDocumentTypes();
const tableBody = document.getElementById('docTypesTableBody');
if (!tableBody) return;
tableBody.innerHTML = '';
// ============================
// تعديل نوع المستند
// ============================
function editDocType(index) {
const docTypes = SupplierStorage.getDocumentTypes();
const docType = docTypes[index];
ModalManager.create({
title: ''تعديل نوع المستند,
content: `
<div class="grid grid-cols-1 gap-4">
<div>
<label for="edit-doctype-name" class="block mb-2 font-
bold"><نوع المستند/label>
<input type="text" id="edit-doctype-name" value="$
{docType.type}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-doctype-keywords" class="block mb-2
font-bold">)<الكلمات المفتاحية (مفصولة بفواصل/label>
<textarea id="edit-doctype-keywords" class="w-full p-2
border border-gray-300 rounded text-base" rows="4">${docType.keywords}</textarea>
</div>
</div>
`,
onOk: () => {
const name = document.getElementById('edit-doctype-
name').value;
const keywords = document.getElementById('edit-doctype-
keywords').value;
if (!name || !keywords) {
ToastManager.error(' الرجاء إدخال نوع المستند والكلمات
;)'المفتاحية
return;
}
docTypes[index] = {
type: name,
keywords: keywords
};
SupplierStorage.saveDocumentTypes(docTypes);
loadDocTypesSettings();
loadDocTypeSelects();
// ============================
// تحميل أنواع المستندات في عناصر االختيار
// ============================
function loadDocTypeSelects() {
const docTypes = SupplierStorage.getDocumentTypes();
const selectElements = [
document.getElementById('matchingReportDocType'),
document.getElementById('commissionReportDocType')
];
selectElements.forEach(select => {
if (!select) return;
// ============================
// تهيئة شاشة النسخ االحتياطي واالستعادة
// ============================
function updateStorageInfo() {
const usageInfo = SupplierStorage.getStorageUsage();
const usedStorageElement = document.getElementById('usedStorage');
const progressBar = document.getElementById('storageProgressBar');
// ============================
// تحديث معلومات الترويسة
// ============================
function updateHeaderInfo(companyInfo) {
const companyInfoDisplay =
document.getElementById('companyInfoDisplay');
if (!companyInfoDisplay) return;
companyInfoDisplay.innerHTML = `
<div class="text-sm">
<div class="font-bold">${companyInfo.nameAr || '<}'الشركة/div>
${companyInfo.branch ? `<div>فرع:
${companyInfo.branch}</div>` : ''}
</div>
`;
}
// ============================
// إعداد شاشة مخزون الموردين
// ============================
function loadInventoryItems(supplierId) {
const items = SupplierStorage.getInventoryItems(supplierId);
const tableBody = document.getElementById('inventoryTableBody');
if (!tableBody) return;
return;
}
tableBody.innerHTML = '';
items.forEach(item => {
// تحديد حالة المخزون بناًء على الكمية المتاحة
let stockStatus = '';
let stockStatusClass = '';
// تهيئة البحث
if (!window.inventorySearchManager) {
window.inventorySearchManager = setupTableSearch('inventorySearch',
'inventoryTable', {
searchableColumns: [0, 1, 2], // البحث في الكود واسم الصنف
والوحدة
paginationManager: window.inventoryTablePagination
});
}
document.querySelectorAll('.delete-inventory-item').forEach(button => {
button.addEventListener('click', function() {
const itemId = this.dataset.id;
deleteInventoryItem(supplierId, itemId);
});
});
}
// ============================
// إضافة أو تعديل صنف في المخزون
// ============================
function addEditInventoryItem(supplierId, itemId = null) {
const items = SupplierStorage.getInventoryItems(supplierId);
let item = null;
const title = item ? ' 'إضافة صنف جديد: ';'تعديل صنف مخزون
ModalManager.create({
title: title,
content: `
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="item-code" class="block mb-2 font-bold">كود
<* الصنف/label>
<input type="text" id="item-code" value="${item ?
item.code : ''}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="item-name" class="block mb-2 font-bold">اسم
<* الصنف/label>
<input type="text" id="item-name" value="${item ?
item.name : ''}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="item-unit" class="block mb-2 font-bold">
<الوحدة/label>
<input type="text" id="item-unit" value="${item ?
item.unit || '' : ''}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="item-quantity" class="block mb-2 font-
bold"><* الكمية المتوفرة/label>
<input type="number" id="item-quantity" value="${item ?
item.quantity : '0'}" min="0" step="0.01" class="w-full p-2 border border-gray-300
rounded text-base">
</div>
<div>
<label for="item-price" class="block mb-2 font-bold">
<* سعر الشراء/label>
<input type="number" id="item-price" value="${item ?
item.price : '0'}" min="0" step="0.01" class="w-full p-2 border border-gray-300
rounded text-base">
</div>
<div>
<label for="item-min-quantity" class="block mb-2 font-
bold"><الحد الأدنى للكمية/label>
<input type="number" id="item-min-quantity" value="$
{item ? item.minQuantity || '10' : '10'}" min="0" step="0.01" class="w-full p-2
border border-gray-300 rounded text-base">
</div>
</div>
`,
onOk: () => {
const code = document.getElementById('item-code').value;
const name = document.getElementById('item-name').value;
const unit = document.getElementById('item-unit').value;
const quantity = parseFloat(document.getElementById('item-
quantity').value) || 0;
const price = parseFloat(document.getElementById('item-
price').value) || 0;
const minQuantity = parseFloat(document.getElementById('item-
min-quantity').value) || 10;
if (item) {
// تحديث صنف موجود
const index = items.findIndex(i => i.id === itemId);
if (index !== -1) {
items[index] = {
...item,
code,
name,
unit,
quantity,
price,
minQuantity,
lastUpdate: new Date().toISOString()
};
SupplierStorage.saveInventoryItems(supplierId, items);
loadInventoryItems(supplierId);
ToastManager.success(';)'تم تحديث الصنف بنجاح
}
} else {
// إضافة صنف جديد
const newItem = {
id: Date.now().toString(),
code,
name,
unit,
quantity,
price,
minQuantity,
lastUpdate: new Date().toISOString()
};
items.push(newItem);
SupplierStorage.saveInventoryItems(supplierId, items);
loadInventoryItems(supplierId);
ToastManager.success(';)'تم إضافة الصنف بنجاح
}
}
});
}
// ============================
// حذف صنف من المخزون
// ============================
function deleteInventoryItem(supplierId, itemId) {
ModalManager.confirm(
''هل أنت متأكد من حذف هذا الصنف من المخزون؟,
() => {
const items = SupplierStorage.getInventoryItems(supplierId);
const updatedItems = items.filter(item => item.id !== itemId);
SupplierStorage.saveInventoryItems(supplierId, updatedItems);
loadInventoryItems(supplierId);
// ============================
// إنشاء تقرير المخزون
// ============================
function generateInventoryReport() {
const supplierId =
document.getElementById('inventoryReportSupplier').value;
const statusFilter =
document.getElementById('inventoryReportStatus').value;
const sortBy = document.getElementById('inventoryReportSort').value;
if (!supplierId) {
ToastManager.error(';)'الرجاء اختيار المورد
return;
}
// الحصول على بيانات المورد
const suppliers = SupplierStorage.getSuppliers();
const supplier = suppliers.find(s => s.id === supplierId);
if (!supplier) {
ToastManager.error(';)'المورد غير موجود
return;
}
if (inventoryItems.length === 0) {
ToastManager.error(';)'ال توجد أصناف مخزنة لهذا المورد
return;
}
return true;
});
}
// ترتيب الأصناف
filteredItems.sort((a, b) => {
if (sortBy === 'name') {
return a.name.localeCompare(b.name);
} else if (sortBy === 'quantity') {
return a.quantity - b.quantity;
} else if (sortBy === 'price') {
return a.price - b.price;
} else if (sortBy === 'date') {
return new Date(b.lastUpdate) - new Date(a.lastUpdate);
}
return 0;
});
document.getElementById('totalItemsCount').textContent = totalItems;
document.getElementById('totalInventoryValue').textContent =
formatNumber(totalValue);
document.getElementById('lowStockCount').textContent = lowStockCount;
document.getElementById('averageUnitPrice').textContent =
formatNumber(averagePrice);
if (!reportTableBody) return;
reportTableBody.innerHTML = '';
filteredItems.forEach(item => {
// تحديد حالة المخزون
let stockStatus = '';
let stockStatusClass = '';
document.getElementById('inventoryReportContent').classList.remove('hidden');
document.getElementById('printInventoryReport').classList.remove('hidden');
document.getElementById('exportInventoryReport').classList.remove('hidden');
// ============================
// طباعة تقرير المخزون
// ============================
function printInventoryReport() {
// إنشاء نافذة الطباعة
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<html dir="rtl" lang="ar">
<head>
<meta charset="UTF-8">
<title><تقرير المخزون/title>
<style>
@import url('https://fonts.googleapis.com/css2?
family=Tajawal:wght@400;500;700&display=swap');
body {
font-family: 'Tajawal', sans-serif;
padding: 20px;
direction: rtl;
}
.header {
margin-bottom: 20px;
border-bottom: 2px solid #40B3EF;
padding-bottom: 10px;
}
.summary-box {
background-color: #f8f9fa;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 8px;
border: 1px solid #ddd;
text-align: right;
}
th {
background-color: #40B3EF;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.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;
}
@media print {
@page {
size: landscape;
margin: 15mm 10mm;
}
body {
font-size: 12pt;
}
}
</style>
</head>
<body>
<div class="header">
${reportHeader}
</div>
${tableHTML}
printWindow.document.close();
// ============================
// تصدير تقرير المخزون للإكسل
// ============================
function exportInventoryReport() {
const supplierId =
document.getElementById('inventoryReportSupplier').value;
if (!supplier) {
ToastManager.error(';)'المورد غير موجود
return;
}
// تصدير الجدول
exportTableToExcel('inventoryReportTable', `_تقرير_مخزون$
{supplier.name}`, {
sheetName: ''المخزون,
headerMap: {
0: ''كود الصنف,
1: ''اسم الصنف,
2: ''الوحدة,
3: ''الكمية المتوفرة,
4: ''سعر الوحدة,
5: ''القيمة الإجمالية,
6: ''آخر تحديث,
7: ''حالة المخزون
}
});
}
// ============================
// تحميل جدول الموردين
// ============================
function loadSuppliersTable() {
const suppliers = SupplierStorage.getSuppliers();
const tableBody = document.getElementById('suppliersTableBody');
if (!tableBody) return;
if (suppliers.length === 0) {
tableBody.innerHTML = `
<tr>
<td colspan="7" class="text-center py-4"> ال توجد بيانات
<متاحة/td>
</tr>
`;
return;
}
tableBody.innerHTML = '';
suppliers.forEach(supplier => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${supplier.id}</td>
<td>${supplier.name}</td>
<td class="truncate-text" title="${supplier.address || ''}">$
{supplier.address || ''}</td>
<td>${supplier.phone1 || ''}</td>
<td>${supplier.fax || ''}</td>
<td>${supplier.reference || ''}</td>
<td class="flex gap-2">
<button class="edit-supplier bg-blue-500 text-white px-2
py-1 rounded text-xs hover:bg-blue-600 transition-colors"
data-id="${supplier.id}" aria-label=" تعديل$
{supplier.name}"><تعديل/button>
<button class="delete-supplier bg-red-500 text-white px-2
py-1 rounded text-xs hover:bg-red-600 transition-colors"
data-id="${supplier.id}" aria-label=" حذف$
{supplier.name}"><حذف/button>
<button class="view-supplier bg-secondary text-white px-2
py-1 rounded text-xs hover:bg-primary transition-colors"
data-id="${supplier.id}" aria-label=" عرض$
{supplier.name}"><عرض/button>
</td>
`;
tableBody.appendChild(row);
});
document.querySelectorAll('.delete-supplier').forEach(button => {
button.addEventListener('click', function() {
const supplierId = this.dataset.id;
deleteSupplier(supplierId);
});
});
document.querySelectorAll('.view-supplier').forEach(button => {
button.addEventListener('click', function() {
const supplierId = this.dataset.id;
// تعيين قيمة المورد في شاشة كشف الحساب
const viewStatementSupplier =
document.getElementById('viewStatementSupplier');
if (viewStatementSupplier) {
viewStatementSupplier.value = supplierId;
viewStatementSupplier.dispatchEvent(new Event('change'));
// إعداد البحث
if (!window.supplierSearchManager) {
window.supplierSearchManager = setupTableSearch('supplierSearch',
'suppliersTable', {
searchableColumns: [0, 1, 2, 3, 4, 5], // البحث في كل الأعمدة
ما عدا العمليات
paginationManager: window.suppliersTablePagination
});
}
}
// ============================
// تعديل بيانات المورد
// ============================
function editSupplier(supplierId) {
const suppliers = SupplierStorage.getSuppliers();
const supplier = suppliers.find(s => s.id === supplierId);
if (!supplier) {
ToastManager.error(';)'المورد غير موجود
return;
}
ModalManager.create({
title: ''تعديل بيانات المورد,
content: `
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="edit-id" class="block mb-2 font-bold">
<الكود/label>
<input type="text" id="edit-id" value="${supplier.id}"
class="w-full p-2 border border-gray-300 rounded text-base" readonly>
</div>
<div>
<label for="edit-name" class="block mb-2 font-bold">اسم
<المورد/label>
<input type="text" id="edit-name" value="$
{supplier.name}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-address" class="block mb-2 font-bold">
<العنوان/label>
<input type="text" id="edit-address" value="$
{supplier.address || ''}" class="w-full p-2 border border-gray-300 rounded text-
base">
</div>
<div>
<label for="edit-phone1" class="block mb-2 font-bold">
1 <تلفون/label>
<input type="text" id="edit-phone1" value="$
{supplier.phone1 || ''}" class="w-full p-2 border border-gray-300 rounded text-
base">
</div>
<div>
<label for="edit-phone2" class="block mb-2 font-bold">
2 <تلفون/label>
<input type="text" id="edit-phone2" value="$
{supplier.phone2 || ''}" class="w-full p-2 border border-gray-300 rounded text-
base">
</div>
<div>
<label for="edit-fax" class="block mb-2 font-bold">
<فاكس/label>
<input type="text" id="edit-fax" value="${supplier.fax
|| ''}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-account" class="block mb-2 font-bold">
<الحساب/label>
<input type="text" id="edit-account" value="$
{supplier.account || ''}" class="w-full p-2 border border-gray-300 rounded text-
base">
</div>
<div>
<label for="edit-reference" class="block mb-2 font-
bold"><الحساب المرجع/label>
<input type="text" id="edit-reference" value="$
{supplier.reference || ''}" class="w-full p-2 border border-gray-300 rounded text-
base">
</div>
</div>
`,
onOk: () => {
const updatedSupplier = {
id: document.getElementById('edit-id').value,
name: document.getElementById('edit-name').value,
address: document.getElementById('edit-address').value,
phone1: document.getElementById('edit-phone1').value,
phone2: document.getElementById('edit-phone2').value,
fax: document.getElementById('edit-fax').value,
account: document.getElementById('edit-account').value,
reference: document.getElementById('edit-reference').value
};
// ============================
// حذف المورد
// ============================
function deleteSupplier(supplierId) {
const suppliers = SupplierStorage.getSuppliers();
const supplier = suppliers.find(s => s.id === supplierId);
if (!supplier) {
ToastManager.error(';)'المورد غير موجود
return;
}
ModalManager.confirm(
`" هل أنت متأكد من حذف المورد${supplier.name}" ؟ سيتم حذف جميع
البيانات المرتبطة به أيًضا.`,
() => {
const updatedSuppliers = suppliers.filter(s => s.id !==
supplierId);
SupplierStorage.saveSuppliers(updatedSuppliers);
loadSuppliersTable();
loadSuppliersInDropdowns();
// ============================
// تحميل الموردين في القوائم المنسدلة
// ============================
function loadSuppliersInDropdowns() {
const suppliers = SupplierStorage.getSuppliers();
const dropdowns = [
document.getElementById('statementSupplier'),
document.getElementById('viewStatementSupplier'),
document.getElementById('matchSupplier'),
document.getElementById('unpostedSupplier'),
document.getElementById('commissionSupplier'),
document.getElementById('matchingReportSupplier'),
document.getElementById('commissionReportSupplier'),
document.getElementById('financialMetricsSupplier'),
document.getElementById('commissionSetupSupplier'),
document.getElementById('inventorySupplier'),
document.getElementById('inventoryReportSupplier')
];
dropdowns.forEach(dropdown => {
if (!dropdown) return;
// ============================
// تحميل كشوفات الحساب
// ============================
function loadStatements(supplierId) {
const statements = SupplierStorage.getStatements(supplierId);
const tableBody = document.getElementById('statementsTableBody');
if (!tableBody) return;
if (statements.length === 0) {
tableBody.innerHTML = `
<tr>
<td colspan="10" class="text-center py-4"> ال توجد بيانات
<متاحة/td>
</tr>
`;
return;
}
tableBody.innerHTML = '';
statements.forEach(statement => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${statement.branch}</td>
<td>${statement.date}</td>
<td>${statement.docNo}</td>
<td>${statement.docType || ''}</td>
<td class="truncate-text" title="${statement.description}">$
{statement.description}</td>
<td>${formatNumber(statement.remainingValue)}</td>
<td>${formatNumber(statement.debit)}</td>
<td>${formatNumber(statement.credit)}</td>
<td>${formatNumber(statement.balance)}</td>
<td class="flex gap-2">
<button class="edit-statement bg-blue-500 text-white px-2
py-1 rounded text-xs hover:bg-blue-600 transition-colors"
data-id="${statement.id}" aria-label=" تعديل
<سجل">تعديل/button>
<button class="delete-statement bg-red-500 text-white px-2
py-1 rounded text-xs hover:bg-red-600 transition-colors"
data-id="${statement.id}" aria-label=" حذف
<سجل">حذف/button>
</td>
`;
tableBody.appendChild(row);
});
// إضافة مستمعي الأحداث للأزرار
document.querySelectorAll('.edit-statement').forEach(button => {
button.addEventListener('click', function() {
const statementId = this.dataset.id;
editStatement(supplierId, statementId);
});
});
document.querySelectorAll('.delete-statement').forEach(button => {
button.addEventListener('click', function() {
const statementId = this.dataset.id;
deleteStatement(supplierId, statementId);
});
});
// ============================
// تعديل سجل في كشف الحساب
// ============================
function editStatement(supplierId, statementId) {
const statements = SupplierStorage.getStatements(supplierId);
const statement = statements.find(s => s.id === statementId);
if (!statement) {
ToastManager.error(';)'السجل غير موجود
return;
}
ModalManager.create({
title: ''تعديل سجل في كشف الحساب,
content: `
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="edit-stmt-branch" class="block mb-2 font-
bold"><الفرع/label>
<input type="text" id="edit-stmt-branch" value="$
{statement.branch}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-stmt-date" class="block mb-2 font-
bold"><التاريخ/label>
<input type="text" id="edit-stmt-date" value="$
{statement.date}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-stmt-docNo" class="block mb-2 font-
bold"><رقم المستند/label>
<input type="text" id="edit-stmt-docNo" value="$
{statement.docNo}" class="w-full p-2 border border-gray-300 rounded text-base">
</div>
<div>
<label for="edit-stmt-docType" class="block mb-2 font-
bold"><نوع المستند/label>
<select id="edit-stmt-docType" class="w-full p-2 border
border-gray-300 rounded text-base">
${docTypeOptions}
</select>
</div>
<div class="md:col-span-2">
<label for="edit-stmt-description" class="block mb-2
font-bold"><البيان/label>
<textarea id="edit-stmt-description" class="w-full p-2
border border-gray-300 rounded text-base"
rows="3">${statement.description}</textarea>
</div>
<div>
<label for="edit-stmt-remainingValue" class="block mb-2
font-bold"><قيمة البضاعة المتبقية/label>
<input type="number" id="edit-stmt-remainingValue"
value="${statement.remainingValue}" class="w-full p-2 border border-gray-300
rounded text-base" step="0.01">
</div>
<div>
<label for="edit-stmt-debit" class="block mb-2 font-
bold"><مدين/label>
<input type="number" id="edit-stmt-debit" value="$
{statement.debit}" class="w-full p-2 border border-gray-300 rounded text-base"
step="0.01">
</div>
<div>
<label for="edit-stmt-credit" class="block mb-2 font-
bold"><دائن/label>
<input type="number" id="edit-stmt-credit" value="$
{statement.credit}" class="w-full p-2 border border-gray-300 rounded text-base"
step="0.01">
</div>
</div>
`,
onOk: () => {
// جمع البيانات المحدثة
const updatedStatement = {
...statement,
branch: document.getElementById('edit-stmt-branch').value,
date: document.getElementById('edit-stmt-date').value,
docNo: document.getElementById('edit-stmt-docNo').value,
docType: document.getElementById('edit-stmt-
docType').value,
description: document.getElementById('edit-stmt-
description').value,
remainingValue: parseFloat(document.getElementById('edit-
stmt-remainingValue').value) || 0,
debit: parseFloat(document.getElementById('edit-stmt-
debit').value) || 0,
credit: parseFloat(document.getElementById('edit-stmt-
credit').value) || 0
};
// التحقق من البيانات
if (!updatedStatement.date || !updatedStatement.docNo) {
ToastManager.error(';)'التاريخ ورقم المستند مطلوبان
return;
}
// تحديث السجل
const index = statements.findIndex(s => s.id === statementId);
if (index !== -1) {
statements[index] = updatedStatement;
SupplierStorage.saveStatements(supplierId, statements);
loadStatements(supplierId);
ToastManager.success(';)'تم تحديث السجل بنجاح
}
}
});
}
// ============================
// حذف سجل من كشف الحساب
// ============================
function deleteStatement(supplierId, statementId) {
ModalManager.confirm(
''هل أنت متأكد من حذف هذا السجل؟,
() => {
const statements = SupplierStorage.getStatements(supplierId);
const updatedStatements = statements.filter(s => s.id !==
statementId);
SupplierStorage.saveStatements(supplierId, updatedStatements);
</script>
</body>
</html>