@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / fd25168
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 19:30 UTC

Update print statement from 'Hello' to 'Goodbye'

davoodmehraban89 committed Sep 16, 2026 at 13:43 UTC fd251683028655c7088fca5998b237a5d23073c0
1 file changed +755 -223
index.html
+755 -223
@@ -5,13 +5,15 @@
5 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
6 <title>ایزی فاکتور | سامانه صدور فاکتور و مدیریت مالی</title>
7
8 - <!-- تنظیمات PWA اختصاصی iOS بدون زوم و لرزش -->
8 <link rel="manifest" href="manifest.json" />
9 <meta name="apple-mobile-web-app-capable" content="yes" />
10 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
11 <meta name="apple-mobile-web-app-title" content="ایزی فاکتور" />
12 <meta name="theme-color" content="#1e3a8a" />
13
14 + <!-- کتابخانه خواندن و پردازش فایل اکسل -->
15 + <script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
16 + <!-- فونت وزیرمتن فارسی -->
17 <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/misc/Farsi-Digits/Vazirmatn-FD-font-face.css" />
18
19 <style>
@@ -31,7 +33,6 @@
33 --nav-h: 74px;
34 }
35
34 - /* جلوگیری قطعی از اسکرول و لرزش به چپ و راست */
36 html, body {
37 width: 100%;
38 max-width: 100%;
@@ -92,7 +93,7 @@
93 justify-content: center;
94 color: #fff;
95 font-weight: bold;
95 - font-size: 22px;
96 + font-size: 20px;
97 }
98
99 .sidebar-menu {
@@ -122,6 +123,14 @@
123 font-weight: bold;
124 }
125
126 + .sidebar-footer {
127 + padding: 14px;
128 + border-top: 1px solid var(--border);
129 + font-size: 11px;
130 + color: var(--text-muted);
131 + text-align: center;
132 + }
133 +
134 .main-surface {
135 flex: 1;
136 margin-right: var(--sidebar-w);
@@ -131,7 +140,6 @@
140 overflow-x: hidden;
141 }
142
134 - /* نوار پایین مخصوص گوشی آیفون */
143 .mobile-dock {
144 display: none;
145 position: fixed;
@@ -232,7 +240,7 @@
240 align-items: center;
241 justify-content: center;
242 gap: 8px;
235 - min-height: 48px;
243 + min-height: 46px;
244 padding: 10px 18px;
245 background: var(--primary);
246 color: #fff;
@@ -265,7 +273,7 @@
273
274 .form-control {
275 width: 100%;
268 - min-height: 48px;
276 + min-height: 46px;
277 padding: 10px 14px;
278 border: 1.5px solid var(--border);
279 border-radius: 10px;
@@ -294,7 +302,6 @@
302 width: 100%;
303 }
304
297 - /* جلوگیری از ریختگی عرضی جداول در صفحه گوشی */
305 .table-responsive {
306 width: 100%;
307 max-width: 100%;
@@ -309,7 +316,7 @@
316 border-collapse: collapse;
317 text-align: right;
318 font-size: 14px;
312 - min-width: 580px;
319 + min-width: 600px;
320 }
321
322 th, td {
@@ -339,6 +346,30 @@
346 .view-pane { display: none; }
347 .view-pane.active { display: block; }
348
349 + /* پنجره مودال پاپ‌آپ سریع */
350 + .modal-backdrop {
351 + display: none;
352 + position: fixed;
353 + top: 0; left: 0; right: 0; bottom: 0;
354 + background: rgba(15,23,42,0.6);
355 + backdrop-filter: blur(4px);
356 + z-index: 999;
357 + align-items: center;
358 + justify-content: center;
359 + padding: 16px;
360 + }
361 + .modal-backdrop.active { display: flex; }
362 + .modal-card {
363 + background: #fff;
364 + border-radius: 16px;
365 + max-width: 650px;
366 + width: 100%;
367 + max-height: 90vh;
368 + overflow-y: auto;
369 + padding: 24px;
370 + box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
371 + }
372 +
373 @media print {
374 body { background: #fff; }
375 .sidebar, .mobile-dock, .no-print { display: none !important; }
@@ -365,13 +396,13 @@
396 <body>
397
398 <div class="app-root">
368 - <!-- منوی کناری مخصوص کامپیوتر -->
399 + <!-- منوی کناری دسکتاپ -->
400 <aside class="sidebar">
401 <div class="brand-box">
402 <div class="brand-icon">ایزی</div>
403 <div>
404 <h2 style="font-size: 16px; font-weight: bold;">ایزی فاکتور</h2>
374 - <small style="color: var(--text-muted); font-size: 12px;">سیستم صدور فاکتور چندشرکتی</small>
405 + <small style="color: var(--text-muted); font-size: 12px;">صدور هوشمند انواع فاکتور</small>
406 </div>
407 </div>
408 <ul class="sidebar-menu">
@@ -383,6 +414,9 @@
414 <li><a href="#" class="nav-link" data-view="view-expenses">💰 هزینه‌ها و درآمد</a></li>
415 <li><a href="#" class="nav-link" data-view="view-settings">⚙️ تنظیمات و شرکت‌ها</a></li>
416 </ul>
417 + <div class="sidebar-footer">
418 + نگارش ۳.۰ | <span id="lbl-build-date">۱۴۰۵/۰۶/۲۶</span>
419 + </div>
420 </aside>
421
422 <!-- محتوای اصلی -->
@@ -395,7 +429,7 @@
429 <h1 style="font-size: 22px; font-weight: bold;">سامانه ایزی فاکتور</h1>
430 <p style="color: var(--text-muted); font-size: 14px;" id="dashboard-date-display"></p>
431 </div>
398 - <button class="btn btn-inline no-print" onclick="switchView('view-invoices')">➕ صدور فاکتور جدید</button>
432 + <button class="btn btn-inline no-print" onclick="startNewInvoice()">➕ صدور فاکتور جدید</button>
433 </div>
434
435 <div class="grid-kpi">
@@ -430,7 +464,7 @@
464 </div>
465
466 <div class="card">
433 - <h3 style="font-size: 16px; margin-bottom: 14px;">آخرین فاکتورهای صادر شده</h3>
467 + <h3 style="font-size: 16px; margin-bottom: 14px;">آخرین فاکتورهای صادر شده شرکت فعال</h3>
468 <div class="table-responsive">
469 <table>
470 <thead>
@@ -452,15 +486,20 @@
486 </div>
487 </section>
488
455 - <!-- ۲. صدور فاکتور -->
489 + <!-- ۲. صدور و ویرایش فاکتور -->
490 <section id="view-invoices" class="view-pane">
491 <div class="card no-print">
458 - <h2 style="font-size: 18px; margin-bottom: 16px;">صدور فاکتور فروش در ایزی فاکتور</h2>
492 + <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
493 + <h2 style="font-size: 18px;" id="invoice-form-title">صدور فاکتور فروش</h2>
494 + <button class="btn btn-secondary btn-inline" style="display:none;" id="btn-cancel-edit" onclick="cancelInvoiceEdit()">انصراف از ویرایش</button>
495 + </div>
496
497 + <input type="hidden" id="edit-invoice-id" value="" />
498 +
499 <div class="form-row">
500 <div class="form-group">
462 - <label>فروشنده (انتخاب سربرگ شرکت)</label>
463 - <select id="invoice-company-id" class="form-control"></select>
501 + <label>فروشنده (سربرگ شرکت)</label>
502 + <select id="invoice-company-id" class="form-control" onchange="onActiveCompanyFilterChange()"></select>
503 </div>
504 <div class="form-group">
505 <label>قالب و نوع سند</label>
@@ -470,7 +509,6 @@
509 <option value="pre_invoice">پیش‌فاکتور رسمی</option>
510 </select>
511 </div>
473 - <!-- باکس کاملاً مجزای ارزش افزوده قبل از شماره فاکتور -->
512 <div class="form-group" id="box-invoice-vat-mode">
513 <label>وضعیت ارزش افزوده</label>
514 <select id="invoice-vat-mode" class="form-control" onchange="handleVatModeChange()">
@@ -487,8 +525,14 @@
525 <input type="text" id="invoice-number" class="form-control" placeholder="1085" />
526 </div>
527 <div class="form-group">
490 - <label>خریدار / طرف حساب</label>
491 - <select id="invoice-contact-id" class="form-control"></select>
528 + <label style="display:flex; justify-content:space-between;">
529 + <span>خریدار / طرف حساب</span>
530 + <a href="#" style="color:var(--accent); text-decoration:none;" onclick="openQuickContactModal()">➕ شخص جدید</a>
531 + </label>
532 + <div style="display:flex; gap:8px;">
533 + <select id="invoice-contact-id" class="form-control" style="flex:1;"></select>
534 + <button class="btn btn-secondary btn-inline" type="button" onclick="openQuickContactModal()" style="padding:0 12px; min-height:46px;">➕</button>
535 + </div>
536 </div>
537 <div class="form-group">
538 <label>تاریخ فاکتور (شمسی)</label>
@@ -497,7 +541,10 @@
541 </div>
542
543 <div style="margin: 20px 0;">
500 - <h4 style="font-size: 15px; margin-bottom: 10px;">اقلام فاکتور</h4>
544 + <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">
545 + <h4 style="font-size: 15px;">اقلام فاکتور</h4>
546 + <button class="btn btn-secondary btn-inline" style="font-size:13px; min-height:36px; padding:4px 12px;" onclick="openQuickProductModal()">➕ کالای جدید</button>
547 + </div>
548 <div class="table-responsive">
549 <table>
550 <thead>
@@ -512,7 +559,9 @@
559 <tbody id="invoice-items-table-body"></tbody>
560 </table>
561 </div>
515 - <button class="btn btn-secondary btn-inline" style="margin-top: 12px;" onclick="addInvoiceItemRow()">➕ افزودن ردیف کالا</button>
562 + <div style="display:flex; gap:10px; margin-top:12px; flex-wrap:wrap;">
563 + <button class="btn btn-secondary btn-inline" onclick="addInvoiceItemRow()">➕ افزودن ردیف کالا</button>
564 + </div>
565 </div>
566
567 <div class="form-row" style="background:#f1f5f9; padding:16px; border-radius:12px; margin-top:14px;">
@@ -520,7 +569,7 @@
569 <label>شرایط تسویه</label>
570 <select id="invoice-payment-method" class="form-control">
571 <option value="cash">نقدی / کارتخوان (تسویه کامل)</option>
523 - <option value="credit">نسیه (بدهکار در معین مشتری)</option>
572 + <option value="credit">نسیه (بدهکار در معین خریدار)</option>
573 <option value="cheque">چک صیادی</option>
574 <option value="installment">فروش اقساطی</option>
575 </select>
@@ -536,12 +585,20 @@
585 </div>
586
587 <div style="display:flex; gap:12px; margin-top: 20px; flex-wrap:wrap;">
539 - <button class="btn btn-success" onclick="commitSaveInvoice()">💾 ثبت و صدور فاکتور</button>
588 + <button class="btn btn-success" id="btn-save-invoice" onclick="commitSaveInvoice()">💾 ثبت و صدور فاکتور</button>
589 </div>
590 </div>
591
592 <div class="card no-print">
544 - <h3 style="font-size: 16px; margin-bottom: 14px;">دفتر بایگانی فاکتورها</h3>
593 + <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; flex-wrap:wrap; gap:10px;">
594 + <h3 style="font-size: 16px;">دفتر بایگانی فاکتورها</h3>
595 + <div style="display:flex; align-items:center; gap:8px;">
596 + <label style="font-size:13px; font-weight:600;">فیلتر شرکت:</label>
597 + <select id="filter-invoice-company" class="form-control" style="width:200px; min-height:38px;" onchange="renderInvoices()">
598 + <!-- گزینه‌ها داینامیک پر می‌شوند -->
599 + </select>
600 + </div>
601 + </div>
602 <div class="table-responsive">
603 <table>
604 <thead>
@@ -553,7 +610,6 @@
610 <th>ارزش افزوده</th>
611 <th>تاریخ</th>
612 <th>مبلغ نهایی (تومان)</th>
556 - <th>تسویه</th>
613 <th>عملیات</th>
614 </tr>
615 </thead>
@@ -563,10 +619,19 @@
619 </div>
620 </section>
621
566 - <!-- ۳. کالاها و خدمات -->
622 + <!-- ۳. کالاها و خدمات + ایمپورت اکسل -->
623 <section id="view-products" class="view-pane">
624 <div class="card no-print">
569 - <h2 style="font-size: 18px; margin-bottom: 16px;">تعریف کالا / خدمت جدید</h2>
625 + <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; flex-wrap:wrap; gap:10px;">
626 + <h2 style="font-size: 18px;">تعریف کالا / خدمت جدید</h2>
627 + <div style="display:flex; gap:8px;">
628 + <label class="btn btn-secondary btn-inline" style="min-height:40px; padding:6px 14px;">
629 + 📥 ورود کالاها از اکسل
630 + <input type="file" id="excel-import-products" style="display:none;" onchange="importProductsFromExcel(event)" accept=".xlsx, .xls" />
631 + </label>
632 + <button class="btn btn-secondary btn-inline" style="min-height:40px; padding:6px 14px;" onclick="downloadProductsExcelTemplate()">📄 دانلود نمونه اکسل</button>
633 + </div>
634 + </div>
635 <div class="form-row">
636 <div class="form-group">
637 <label>کد کالا</label>
@@ -610,7 +675,7 @@
675 </div>
676
677 <div class="card">
613 - <h3 style="font-size: 16px; margin-bottom: 14px;">لیست کالاها و مشخصات</h3>
678 + <h3 style="font-size: 16px; margin-bottom: 14px;">لیست کالاها و خدمات ثبت‌شده</h3>
679 <div class="table-responsive">
680 <table>
681 <thead>
@@ -629,15 +694,42 @@
694 </div>
695 </section>
696
632 - <!-- ۴. اشخاص و طرف‌حساب‌ها -->
697 + <!-- ۴. اشخاص و طرف‌حساب‌ها + ایمپورت اکسل -->
698 <section id="view-contacts" class="view-pane">
699 <div class="card no-print">
635 - <h2 style="font-size: 18px; margin-bottom: 16px;">ثبت طرف حساب جدید</h2>
700 + <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; flex-wrap:wrap; gap:10px;">
701 + <h2 style="font-size: 18px;">ثبت طرف حساب جدید</h2>
702 + <div style="display:flex; gap:8px;">
703 + <label class="btn btn-secondary btn-inline" style="min-height:40px; padding:6px 14px;">
704 + 📥 ورود اشخاص از اکسل
705 + <input type="file" id="excel-import-contacts" style="display:none;" onchange="importContactsFromExcel(event)" accept=".xlsx, .xls" />
706 + </label>
707 + <button class="btn btn-secondary btn-inline" style="min-height:40px; padding:6px 14px;" onclick="downloadContactsExcelTemplate()">📄 دانلود نمونه اکسل</button>
708 + </div>
709 + </div>
710 +
711 <div class="form-row">
712 <div class="form-group">
638 - <label>نام و نام خانوادگی / شرکت</label>
639 - <input type="text" id="contact-name-input" class="form-control" placeholder="مثلاً: شرکت ساختمانی پردیس" />
713 + <label>نوع شخص</label>
714 + <select id="contact-entity-type" class="form-control" onchange="handleContactEntityChange()">
715 + <option value="natural">شخص حقیقی</option>
716 + <option value="legal">شخص حقوقی</option>
717 + </select>
718 + </div>
719 + <div class="form-group" id="box-contact-prefix">
720 + <label>پیشوند انتخابی</label>
721 + <select id="contact-prefix-select" class="form-control">
722 + <option value="آقا/خانم">آقا / خانم</option>
723 + <option value="فروشگاه">فروشگاه</option>
724 + </select>
725 </div>
726 + <div class="form-group" style="grid-column: span 2;">
727 + <label>نام طرف حساب (شخص یا نام فروشگاه/شرکت)</label>
728 + <input type="text" id="contact-name-input" class="form-control" placeholder="مثلاً: احمدی یا عمران نوین" />
729 + </div>
730 + </div>
731 +
732 + <div class="form-row">
733 <div class="form-group">
734 <label>نقش تجاری</label>
735 <select id="contact-role-input" class="form-control">
@@ -651,29 +743,30 @@
743 <input type="text" id="contact-mobile-input" class="form-control" placeholder="0912..." />
744 </div>
745 <div class="form-group">
654 - <label>شناسه ملی (۱۰ یا ۱۱ رقم)</label>
655 - <input type="text" id="contact-national-input" class="form-control" />
746 + <label>کد ملی / شناسه ملی</label>
747 + <input type="text" id="contact-national-input" class="form-control" placeholder="۱۰ یا ۱۱ رقم" />
748 </div>
657 - </div>
658 - <div class="form-row">
749 <div class="form-group">
660 - <label>کد اقتصادی (۱۲ رقم)</label>
661 - <input type="text" id="contact-economic-input" class="form-control" />
750 + <label>کد اقتصادی</label>
751 + <input type="text" id="contact-economic-input" class="form-control" placeholder="کد اقتصادی ۱۲ رقمی" />
752 </div>
753 + </div>
754 +
755 + <div class="form-row">
756 <div class="form-group">
664 - <label>شماره ثبت</label>
665 - <input type="text" id="contact-reg-input" class="form-control" />
757 + <label>شماره ثبت (ویژه اشخاص حقوقی)</label>
758 + <input type="text" id="contact-reg-input" class="form-control" placeholder="شماره ثبت شرکت" />
759 </div>
760 <div class="form-group">
761 <label>کد پستی (۱۰ رقم مجزا)</label>
669 - <input type="text" id="contact-postal-input" class="form-control" />
762 + <input type="text" id="contact-postal-input" class="form-control" placeholder="کد پستی ۱۰ رقمی" />
763 + </div>
764 + <div class="form-group" style="grid-column: span 2;">
765 + <label>نشانی کامل</label>
766 + <input type="text" id="contact-address-input" class="form-control" placeholder="استان، شهر، خیابان..." />
767 </div>
768 </div>
672 - <div class="form-group">
673 - <label>نشانی کامل</label>
674 - <input type="text" id="contact-address-input" class="form-control" placeholder="استان، شهر، خیابان..." />
675 - </div>
676 - <button class="btn btn-success" onclick="commitSaveContact()">➕ ثبت اطلاعات طرف حساب</button>
769 + <button class="btn btn-success" onclick="commitSaveContact()">➕ ثبت طرف حساب</button>
770 </div>
771
772 <div class="card">
@@ -683,11 +776,12 @@
776 <thead>
777 <tr>
778 <th>نام طرف حساب</th>
779 + <th>نوع</th>
780 <th>شناسه ملی</th>
781 <th>کد اقتصادی</th>
782 <th>شماره ثبت</th>
783 <th>کد پستی</th>
690 - <th>تلفن</th>
784 + <th>همراه</th>
785 <th>مانده (تومان)</th>
786 <th>عملیات</th>
787 </tr>
@@ -816,60 +910,67 @@
910 </div>
911 </section>
912
819 - <!-- ۷. تنظیمات، چندشرکتی و پیش‌فرض‌ها -->
913 + <!-- ۷. تنظیمات و چندشرکتی -->
914 <section id="view-settings" class="view-pane">
821 - <!-- مدیریت شرکت‌ها -->
915 <div class="card">
916 <h2 style="font-size: 18px; margin-bottom: 16px;">🏢 مدیریت شرکت‌ها و فروشندگان (چند شرکتی نامحدود)</h2>
824 - <p style="color:var(--text-muted); font-size:13px; margin-bottom:14px;">هر تعداد فروشنده یا شرکت که نیاز دارید را با سربرگ و اطلاعات مجزا تعریف کنید.</p>
917 + <p style="color:var(--text-muted); font-size:13px; margin-bottom:14px;">شرکت‌های مختلف (مثلاً باناپ، آوان‌تک و...) را با اطلاعات حقوقی جداگانه تعریف کنید.</p>
918
919 <div class="form-row">
920 <div class="form-group">
828 - <label>نام فروشگاه / شرکت</label>
829 - <input type="text" id="company-name-input" class="form-control" placeholder="مثلاً: شرکت آرا بتن" />
921 + <label>نوع شخص / فروشنده</label>
922 + <select id="company-entity-type" class="form-control">
923 + <option value="legal">شخص حقوقی (شرکت)</option>
924 + <option value="natural">شخص حقیقی (فروشگاه)</option>
925 + </select>
926 </div>
927 <div class="form-group">
832 - <label>شماره تماس</label>
833 - <input type="text" id="company-phone-input" class="form-control" placeholder="021... / 0912..." />
928 + <label>نام فروشگاه یا شرکت (بدون نیاز به نوشتن کلمه شرکت/فروشگاه)</label>
929 + <input type="text" id="company-name-input" class="form-control" placeholder="مثلاً: باناپ یا آوان‌تک" />
930 </div>
931 <div class="form-group">
836 - <label>شناسه ملی (۱۰ یا ۱۱ رقم)</label>
837 - <input type="text" id="company-national-input" class="form-control" />
932 + <label>شماره تماس مستقیم</label>
933 + <input type="text" id="company-phone-input" class="form-control" placeholder="021... / 0912..." />
934 </div>
935 </div>
936
937 <div class="form-row">
938 + <div class="form-group">
939 + <label>شناسه ملی / کد ملی</label>
940 + <input type="text" id="company-national-input" class="form-control" placeholder="۱۰ یا ۱۱ رقم" />
941 + </div>
942 <div class="form-group">
943 <label>کد اقتصادی (۱۲ رقم)</label>
844 - <input type="text" id="company-economic-input" class="form-control" />
944 + <input type="text" id="company-economic-input" class="form-control" placeholder="کد اقتصادی" />
945 </div>
946 <div class="form-group">
847 - <label>شماره ثبت</label>
848 - <input type="text" id="company-reg-input" class="form-control" />
947 + <label>شماره ثبت (برای شرکت‌ها)</label>
948 + <input type="text" id="company-reg-input" class="form-control" placeholder="شماره ثبت" />
949 </div>
950 <div class="form-group">
951 <label>کد پستی (۱۰ رقم مجزا)</label>
852 - <input type="text" id="company-postal-input" class="form-control" />
952 + <input type="text" id="company-postal-input" class="form-control" placeholder="کد پستی" />
953 </div>
954 </div>
955
956 <div class="form-group">
857 - <label>نشانی دقیق کارخانه / دفتر فروشگاه</label>
858 - <input type="text" id="company-address-input" class="form-control" placeholder="استان، شهر، آدرس..." />
957 + <label>نشانی کامل فروشگاه / کارخانه</label>
958 + <input type="text" id="company-address-input" class="form-control" placeholder="استان، شهر، آدرس دقیق..." />
959 </div>
960 <div class="form-group">
961 <label>متن پاورقی فاکتور این شرکت</label>
862 - <textarea id="company-footer-input" class="form-control" rows="2" placeholder="شرایط فروش، پیام تشکر یا شماره حساب"></textarea>
962 + <textarea id="company-footer-input" class="form-control" rows="2" placeholder="شرایط فروش، پیام تشکر یا اطلاعات حساب"></textarea>
963 </div>
864 - <button class="btn btn-success" onclick="commitSaveCompany()">➕ ثبت شرکت / فروشنده جدید</button>
964 + <button class="btn btn-success" onclick="commitSaveCompany()">➕ ثبت فروشنده جدید</button>
965
966 <div style="margin-top:24px;">
867 - <h4 style="font-size:15px; margin-bottom:10px;">لیست شرکت‌ها و سربرگ‌های فعال</h4>
967 + <h4 style="font-size:15px; margin-bottom:10px;">لیست فروشندگان و سربرگ‌های فعال</h4>
968 <div class="table-responsive">
969 <table>
970 <thead>
971 <tr>
872 - <th>نام شرکت</th>
972 + <th>عنوان رسمی</th>
973 + <th>نوع</th>
974 <th>شناسه ملی</th>
975 <th>کد اقتصادی</th>
976 <th>شماره ثبت</th>
@@ -884,9 +985,8 @@
985 </div>
986 </div>
987
887 - <!-- پیش‌فرض‌های فاکتور -->
988 <div class="card">
889 - <h2 style="font-size: 18px; margin-bottom: 16px;">⚙️ تنظیمات پیش‌فرض فاکتور</h2>
989 + <h2 style="font-size: 18px; margin-bottom: 16px;">⚙️ تنظیمات پیش‌فرض صدور فاکتور</h2>
990 <div class="form-row">
991 <div class="form-group">
992 <label>قالب پیش‌فرض فاکتور</label>
@@ -910,111 +1010,229 @@
1010 <button class="btn btn-primary" onclick="commitSaveDefaultSettings()">ذخیره پیش‌فرض‌ها</button>
1011 </div>
1012
913 - <!-- پشتیبان‌گیری -->
1013 + <div class="card" style="background:#f8fafc;">
1014 + <h3 style="font-size: 16px; margin-bottom: 10px;">📌 وضعیت نگارش برنامه</h3>
1015 + <p style="font-size:14px; color:#334155; line-height:1.8;">
1016 + نگارش فعال: <strong>ایزی فاکتور - نسخه ۳.۰ (پایدار رسمی)</strong><br />
1017 + تاریخ انتشار و اعمال تغییرات: <strong id="lbl-last-update-full">۱۴۰۵/۰۶/۲۶ - ۱۳:۳۸</strong>
1018 + </p>
1019 + </div>
1020 +
1021 <div class="card">
1022 <h3 style="font-size: 16px; margin-bottom: 14px;">💾 پشتیبان‌گیری و انتقال اطلاعات</h3>
916 - <p style="color:var(--text-muted); font-size:14px; margin-bottom:14px;">
917 - جهت جابه‌جایی فایل دیتابیس بین آیفون، کامپیوتر و اندروید فایل بکاپ JSON را دریافت و در دستگاه دیگر بازگردانی کنید.
918 - </p>
1023 <div style="display:flex; gap:12px; flex-wrap:wrap;">
920 - <button class="btn btn-secondary btn-inline" onclick="exportDataBlob()">📥 دانلود فایل پشتیبان (JSON)</button>
1024 + <button class="btn btn-secondary btn-inline" onclick="exportDataBlob()">📥 دانلود پشتیبان (JSON)</button>
1025 <label class="btn btn-secondary btn-inline" style="margin-bottom:0;">
922 - 📤 بازگردانی فایل پشتیبان
1026 + 📤 بازگردانی پشتیبان
1027 <input type="file" id="import-json-file" style="display:none;" onchange="importDataBlob(event)" accept=".json" />
1028 </label>
1029 </div>
1030 </div>
1031 </section>
1032
929 - <!-- قالب استاندارد پرینت A4 رسمی و غیررسمی -->
930 - <div id="printable-invoice" style="display:none; background:#fff; padding:24px; border:2px solid #000; margin-top:20px; border-radius:4px;">
931 - <div style="display:flex; justify-content:space-between; align-items:center; border-bottom:2px solid #000; padding-bottom:12px;">
932 - <div>
933 - <h1 id="p-org-name" style="font-size:20px; margin:0; font-weight:bold;">ایزی فاکتور</h1>
934 - <p style="font-size:12px; color:#333; margin-top:4px;">تلفن: <span id="p-org-phone"></span></p>
935 - </div>
936 - <div style="text-align:center;">
937 - <h2 id="p-doc-kind-title" style="font-size:18px; margin:0; font-weight:bold;">صورتحساب فروش کالا و خدمات</h2>
938 - </div>
939 - <div style="text-align:left; font-size:12px;">
940 - <p>شماره: <strong id="p-doc-number"></strong></p>
941 - <p style="margin-top:4px;">تاریخ: <span id="p-doc-date"></span></p>
942 - </div>
943 - </div>
1033 + <!-- قالب پرینت A4 منطبق بر صورتحساب استاندارد دارایی و رسمی -->
1034 + <div id="printable-invoice" style="display:none; background:#fff; padding:20px; border:2px solid #000; margin-top:20px; border-radius:0px;">
1035 + <!-- سربرگ رسمی با ۳ کادر بالا -->
1036 + <table style="width:100%; border-collapse:collapse; border:1.5px solid #000; margin-bottom:6px;">
1037 + <tr>
1038 + <td style="width:25%; border:1px solid #000; padding:6px; font-size:11px; vertical-align:top;">
1039 + <div>شماره سریال: <strong id="p-doc-number"></strong></div>
1040 + <div style="margin-top:4px;">تاریخ: <span id="p-doc-date"></span></div>
1041 + <div style="margin-top:4px;">پیوست: ندارد</div>
1042 + </td>
1043 + <td style="width:50%; border:1px solid #000; padding:8px; text-align:center; vertical-align:middle;">
1044 + <h2 id="p-doc-kind-title" style="font-size:16px; margin:0; font-weight:bold;">صورتحساب فروش کالا و خدمات</h2>
1045 + <div style="font-size:12px; margin-top:4px; font-weight:600;" id="p-org-name"></div>
1046 + </td>
1047 + <td style="width:25%; border:1px solid #000; padding:6px; font-size:11px; text-align:left; vertical-align:top;">
1048 + <div>تلفن: <span id="p-org-phone"></span></div>
1049 + </td>
1050 + </tr>
1051 + </table>
1052
945 - <table style="width:100%; border-collapse:collapse; margin-top:10px; font-size:12px; border:1px solid #000;">
946 - <tr style="background:#f1f5f9;"><th colspan="4" style="border:1px solid #000; padding:6px; text-align:right;">مشخصات فروشنده</th></tr>
1053 + <!-- کادر مشخصات فروشنده -->
1054 + <table style="width:100%; border-collapse:collapse; border:1.5px solid #000; font-size:11px; margin-bottom:6px;">
1055 + <tr style="background:#e2e8f0; font-weight:bold;"><td colspan="4" style="border:1px solid #000; padding:5px; text-align:right;">مشخصات فروشنده</td></tr>
1056 <tr>
948 - <td style="border:1px solid #000; padding:6px; width:15%;">فروشنده:</td>
949 - <td style="border:1px solid #000; padding:6px; width:35%;"><strong id="p-seller-name"></strong></td>
950 - <td style="border:1px solid #000; padding:6px; width:15%;">شناسه ملی:</td>
951 - <td style="border:1px solid #000; padding:6px; width:35%;"><span id="p-seller-national"></span></td>
1057 + <td style="border:1px solid #000; padding:5px; width:15%;">نام شخص حقیقی/حقوقی:</td>
1058 + <td style="border:1px solid #000; padding:5px; width:35%;"><strong id="p-seller-name"></strong></td>
1059 + <td style="border:1px solid #000; padding:5px; width:15%;">شماره اقتصادی:</td>
1060 + <td style="border:1px solid #000; padding:5px; width:35%;"><span id="p-seller-economic"></span></td>
1061 </tr>
1062 <tr>
954 - <td style="border:1px solid #000; padding:6px;">کد اقتصادی:</td>
955 - <td style="border:1px solid #000; padding:6px;"><span id="p-seller-economic"></span></td>
956 - <td style="border:1px solid #000; padding:6px;">شماره ثبت:</td>
957 - <td style="border:1px solid #000; padding:6px;"><span id="p-seller-reg"></span></td>
1063 + <td style="border:1px solid #000; padding:5px;">شماره ثبت / شناسه ملی:</td>
1064 + <td style="border:1px solid #000; padding:5px;"><span id="p-seller-national"></span> / ثبت: <span id="p-seller-reg"></span></td>
1065 + <td style="border:1px solid #000; padding:5px;">کد پستی ۱۰ رقمی:</td>
1066 + <td style="border:1px solid #000; padding:5px;"><span id="p-seller-postal"></span></td>
1067 </tr>
1068 <tr>
960 - <td style="border:1px solid #000; padding:6px;">کد پستی:</td>
961 - <td style="border:1px solid #000; padding:6px;"><span id="p-seller-postal"></span></td>
962 - <td style="border:1px solid #000; padding:6px;">نشانی:</td>
963 - <td style="border:1px solid #000; padding:6px;"><span id="p-seller-address"></span></td>
1069 + <td style="border:1px solid #000; padding:5px;">نشانی کامل:</td>
1070 + <td colspan="3" style="border:1px solid #000; padding:5px;"><span id="p-seller-address"></span></td>
1071 </tr>
965 - <tr style="background:#f1f5f9;"><th colspan="4" style="border:1px solid #000; padding:6px; text-align:right;">مشخصات خریدار</th></tr>
1072 + </table>
1073 +
1074 + <!-- کادر مشخصات خریدار -->
1075 + <table style="width:100%; border-collapse:collapse; border:1.5px solid #000; font-size:11px; margin-bottom:6px;">
1076 + <tr style="background:#e2e8f0; font-weight:bold;"><td colspan="4" style="border:1px solid #000; padding:5px; text-align:right;">مشخصات خریدار</td></tr>
1077 <tr>
967 - <td style="border:1px solid #000; padding:6px;">نام خریدار:</td>
968 - <td style="border:1px solid #000; padding:6px;"><strong id="p-target-name"></strong></td>
969 - <td style="border:1px solid #000; padding:6px;">شناسه ملی:</td>
970 - <td style="border:1px solid #000; padding:6px;"><span id="p-target-national"></span></td>
1078 + <td style="border:1px solid #000; padding:5px; width:15%;">نام شخص حقیقی/حقوقی:</td>
1079 + <td style="border:1px solid #000; padding:5px; width:35%;"><strong id="p-target-name"></strong></td>
1080 + <td style="border:1px solid #000; padding:5px; width:15%;">شماره اقتصادی:</td>
1081 + <td style="border:1px solid #000; padding:5px; width:35%;"><span id="p-target-economic"></span></td>
1082 </tr>
1083 <tr>
973 - <td style="border:1px solid #000; padding:6px;">کد اقتصادی:</td>
974 - <td style="border:1px solid #000; padding:6px;"><span id="p-target-economic"></span></td>
975 - <td style="border:1px solid #000; padding:6px;">شماره ثبت:</td>
976 - <td style="border:1px solid #000; padding:6px;"><span id="p-target-reg"></span></td>
1084 + <td style="border:1px solid #000; padding:5px;">شماره ثبت / شناسه ملی:</td>
1085 + <td style="border:1px solid #000; padding:5px;"><span id="p-target-national"></span> / ثبت: <span id="p-target-reg"></span></td>
1086 + <td style="border:1px solid #000; padding:5px;">کد پستی ۱۰ رقمی:</td>
1087 + <td style="border:1px solid #000; padding:5px;"><span id="p-target-postal"></span></td>
1088 </tr>
1089 <tr>
979 - <td style="border:1px solid #000; padding:6px;">کد پستی:</td>
980 - <td style="border:1px solid #000; padding:6px;"><span id="p-target-postal"></span></td>
981 - <td style="border:1px solid #000; padding:6px;">نشانی:</td>
982 - <td style="border:1px solid #000; padding:6px;"><span id="p-target-address"></span></td>
1090 + <td style="border:1px solid #000; padding:5px;">نشانی و تلفن:</td>
1091 + <td colspan="3" style="border:1px solid #000; padding:5px;"><span id="p-target-address"></span> | تلفن: <span id="p-target-phone"></span></td>
1092 </tr>
1093 </table>
1094
986 - <table style="width:100%; border-collapse:collapse; margin-top:10px; font-size:12px; border:1px solid #000;">
1095 + <!-- جدول مشخصات کالا و خدمات -->
1096 + <table style="width:100%; border-collapse:collapse; border:1.5px solid #000; font-size:11px;">
1097 <thead>
988 - <tr style="background:#f1f5f9;">
989 - <th style="border:1px solid #000; padding:8px; width:40px; text-align:center;">ردیف</th>
990 - <th style="border:1px solid #000; padding:8px; text-align:right;">شرح کالا یا خدمت (مشخصه/نوع)</th>
991 - <th style="border:1px solid #000; padding:8px; width:65px; text-align:center;">تعداد</th>
992 - <th style="border:1px solid #000; padding:8px; width:130px; text-align:left;">قیمت واحد (تومان)</th>
993 - <th style="border:1px solid #000; padding:8px; width:150px; text-align:left;">جمع کل (تومان)</th>
1098 + <tr style="background:#e2e8f0; font-weight:bold; text-align:center;">
1099 + <th style="border:1px solid #000; padding:6px; width:35px;">ردیف</th>
1100 + <th style="border:1px solid #000; padding:6px; text-align:right;">شرح کالا یا خدمت</th>
1101 + <th style="border:1px solid #000; padding:6px; width:60px;">تعداد/مقدار</th>
1102 + <th style="border:1px solid #000; padding:6px; width:110px; text-align:left;">مبلغ واحد (تومان)</th>
1103 + <th style="border:1px solid #000; padding:6px; width:130px; text-align:left;">مبلغ کل (تومان)</th>
1104 </tr>
1105 </thead>
1106 <tbody id="p-target-items-table"></tbody>
1107 </table>
1108
999 - <div style="display:flex; justify-content:space-between; margin-top:14px; font-size:13px;">
1000 - <div style="width:55%; font-size:12px; padding:8px; border:1px solid #cbd5e1; border-radius:4px;" id="p-doc-footer-note"></div>
1001 - <div style="width:40%;">
1002 - <table style="width:100%; border-collapse:collapse; font-size:13px;">
1003 - <tr><td style="padding:5px;">جمع اقلام:</td><td style="padding:5px; text-align:left;"><span id="p-calc-subtotal"></span> تومان</td></tr>
1004 - <tr><td style="padding:5px;">تخفیف:</td><td style="padding:5px; text-align:left;"><span id="p-calc-discount"></span> تومان</td></tr>
1005 - <tr id="p-tax-row"><td style="padding:5px;">مالیات ارزش افزوده:</td><td style="padding:5px; text-align:left;"><span id="p-calc-tax"></span> تومان</td></tr>
1006 - <tr style="border-top:2px solid #000; font-weight:bold; font-size:14px;">
1007 - <td style="padding:8px 5px;">مبلغ نهایی:</td>
1008 - <td style="padding:8px 5px; text-align:left;"><span id="p-calc-grandtotal"></span> تومان</td>
1009 - </tr>
1010 - </table>
1011 - </div>
1012 - </div>
1109 + <!-- محاسبات پایانی و امضاها -->
1110 + <table style="width:100%; border-collapse:collapse; border:1.5px solid #000; font-size:11px; margin-top:6px;">
1111 + <tr>
1112 + <td style="width:55%; border:1px solid #000; padding:8px; vertical-align:top;">
1113 + <div><strong>شرایط و توضیحات فاکتور:</strong></div>
1114 + <div id="p-doc-footer-note" style="margin-top:4px; font-size:11px;"></div>
1115 + </td>
1116 + <td style="width:45%; border:1px solid #000; padding:0;">
1117 + <table style="width:100%; border-collapse:collapse; font-size:11px;">
1118 + <tr><td style="border-bottom:1px solid #000; padding:5px;">جمع کل اقلام:</td><td style="border-bottom:1px solid #000; padding:5px; text-align:left;"><span id="p-calc-subtotal"></span> تومان</td></tr>
1119 + <tr><td style="border-bottom:1px solid #000; padding:5px;">مبلغ تخفیف:</td><td style="border-bottom:1px solid #000; padding:5px; text-align:left;"><span id="p-calc-discount"></span> تومان</td></tr>
1120 + <tr id="p-tax-row"><td style="border-bottom:1px solid #000; padding:5px;">مالیات و عوارض ارزش افزوده:</td><td style="border-bottom:1px solid #000; padding:5px; text-align:left;"><span id="p-calc-tax"></span> تومان</td></tr>
1121 + <tr style="background:#f1f5f9; font-weight:bold; font-size:12px;">
1122 + <td style="padding:6px;">مبلغ قابل پرداخت:</td>
1123 + <td style="padding:6px; text-align:left;"><span id="p-calc-grandtotal"></span> تومان</td>
1124 + </tr>
1125 + </table>
1126 + </td>
1127 + </tr>
1128 + </table>
1129 +
1130 + <!-- بخش مهرهای رسمی طرفین -->
1131 + <table style="width:100%; margin-top:15px; text-align:center; font-size:12px;">
1132 + <tr>
1133 + <td style="width:50%; height:75px; vertical-align:top; border:1px dashed #666; padding:8px;">مهر و امضای فروشنده</td>
1134 + <td style="width:50%; height:75px; vertical-align:top; border:1px dashed #666; padding:8px;">مهر و امضای خریدار</td>
1135 + </tr>
1136 + </table>
1137 </div>
1138
1139 </main>
1140 </div>
1141
1142 + <!-- مودال پاپ‌آپ سریع تعریف طرف‌حساب داخل فاکتور -->
1143 + <div class="modal-backdrop" id="modal-quick-contact">
1144 + <div class="modal-card">
1145 + <h3 style="font-size:17px; margin-bottom:14px;">➕ تعریف سریع طرف حساب</h3>
1146 + <div class="form-row">
1147 + <div class="form-group">
1148 + <label>نوع شخص</label>
1149 + <select id="quick-c-entity" class="form-control" onchange="handleQuickCEntityChange()">
1150 + <option value="natural">شخص حقیقی</option>
1151 + <option value="legal">شخص حقوقی</option>
1152 + </select>
1153 + </div>
1154 + <div class="form-group" id="box-quick-c-prefix">
1155 + <label>پیشوند</label>
1156 + <select id="quick-c-prefix" class="form-control">
1157 + <option value="آقا/خانم">آقا / خانم</option>
1158 + <option value="فروشگاه">فروشگاه</option>
1159 + </select>
1160 + </div>
1161 + <div class="form-group">
1162 + <label>نام شخص یا شرکت</label>
1163 + <input type="text" id="quick-c-name" class="form-control" placeholder="نام خریدار" />
1164 + </div>
1165 + </div>
1166 + <div class="form-row">
1167 + <div class="form-group">
1168 + <label>شماره تماس همراه</label>
1169 + <input type="text" id="quick-c-mobile" class="form-control" placeholder="0912..." />
1170 + </div>
1171 + <div class="form-group">
1172 + <label>شناسه/کد ملی</label>
1173 + <input type="text" id="quick-c-national" class="form-control" />
1174 + </div>
1175 + <div class="form-group">
1176 + <label>کد اقتصادی</label>
1177 + <input type="text" id="quick-c-economic" class="form-control" />
1178 + </div>
1179 + </div>
1180 + <div class="form-row">
1181 + <div class="form-group">
1182 + <label>شماره ثبت</label>
1183 + <input type="text" id="quick-c-reg" class="form-control" />
1184 + </div>
1185 + <div class="form-group">
1186 + <label>کد پستی (۱۰ رقم)</label>
1187 + <input type="text" id="quick-c-postal" class="form-control" />
1188 + </div>
1189 + </div>
1190 + <div class="form-group">
1191 + <label>نشانی کامل</label>
1192 + <input type="text" id="quick-c-address" class="form-control" />
1193 + </div>
1194 + <div style="display:flex; gap:10px; margin-top:14px;">
1195 + <button class="btn btn-success" onclick="saveQuickContact()">ذخیره و انتخاب در فاکتور</button>
1196 + <button class="btn btn-secondary" onclick="closeQuickContactModal()">انصراف</button>
1197 + </div>
1198 + </div>
1199 + </div>
1200 +
1201 + <!-- مودال پاپ‌آپ سریع تعریف کالا داخل فاکتور -->
1202 + <div class="modal-backdrop" id="modal-quick-product">
1203 + <div class="modal-card">
1204 + <h3 style="font-size:17px; margin-bottom:14px;">➕ تعریف سریع کالا / خدمات</h3>
1205 + <div class="form-row">
1206 + <div class="form-group">
1207 + <label>کد کالا</label>
1208 + <input type="text" id="quick-p-code" class="form-control" placeholder="101" />
1209 + </div>
1210 + <div class="form-group">
1211 + <label>عنوان کالا</label>
1212 + <input type="text" id="quick-p-name" class="form-control" placeholder="مثلاً: بلوک سیمانی" />
1213 + </div>
1214 + <div class="form-group">
1215 + <label>مشخصه / مدل</label>
1216 + <input type="text" id="quick-p-spec" class="form-control" placeholder="مثلاً: سبک ۱۰" />
1217 + </div>
1218 + </div>
1219 + <div class="form-row">
1220 + <div class="form-group">
1221 + <label>واحد</label>
1222 + <input type="text" id="quick-p-unit" class="form-control" value="عدد" />
1223 + </div>
1224 + <div class="form-group">
1225 + <label>قیمت فروش (تومان)</label>
1226 + <input type="number" id="quick-p-price" class="form-control" value="0" />
1227 + </div>
1228 + </div>
1229 + <div style="display:flex; gap:10px; margin-top:14px;">
1230 + <button class="btn btn-success" onclick="saveQuickProduct()">ذخیره و افزودن به سطر</button>
1231 + <button class="btn btn-secondary" onclick="closeQuickProductModal()">انصراف</button>
1232 + </div>
1233 + </div>
1234 + </div>
1235 +
1236 <!-- منوی لمسی پایین در آیفون -->
1237 <nav class="mobile-dock">
1238 <div class="dock-tab active" onclick="switchView('view-dashboard')">
@@ -1040,7 +1258,8 @@
1258 </nav>
1259
1260 <script>
1043 - const STORAGE_KEY = 'easy_factor_datastore_v2';
1261 + const STORAGE_KEY = 'easy_factor_datastore_v3_0';
1262 + const APP_BUILD_TIMESTAMP = '۱۴۰۵/۰۶/۲۶ - ۱۳:۳۸';
1263
1264 let datastore = {
1265 default_settings: {
@@ -1052,20 +1271,34 @@
1271 companies: [
1272 {
1273 id: 'COMP-1',
1055 - name: 'شرکت آرا بتن',
1056 - phone: '09120000000',
1274 + entity_type: 'legal',
1275 + name: 'شرکت باناپ',
1276 + phone: '02188888888',
1277 national_id: '10103040506',
1278 economic_code: '411122233344',
1279 reg_number: '54321',
1280 postal_code: '1987654321',
1061 - address: 'تهران، جاده مخصوص، شهرک صنعتی',
1281 + address: 'تهران، خیابان سهروردی شمالی',
1282 footer: 'از حسن انتخاب و اعتماد شما سپاسگزاریم.'
1283 + },
1284 + {
1285 + id: 'COMP-2',
1286 + entity_type: 'natural',
1287 + name: 'فروشگاه آوان‌تک',
1288 + phone: '09121111111',
1289 + national_id: '0012345678',
1290 + economic_code: '',
1291 + reg_number: '',
1292 + postal_code: '1455667788',
1293 + address: 'تهران، بازار موبایل',
1294 + footer: 'کالای فروخته شده دارای ۲۴ ساعت ضمانت تست می‌باشد.'
1295 }
1296 ],
1297 contacts: [
1298 {
1299 id: 'C-1',
1068 - name: 'شرکت عمران نوین (نادر بحری)',
1300 + entity_type: 'legal',
1301 + name: 'شرکت عمران نوین',
1302 mobile: '09121111111',
1303 national_id: '10109876543',
1304 economic_code: '411188899900',
@@ -1086,31 +1319,14 @@
1319 };
1320
1321 function initDatastore() {
1089 - const persisted = localStorage.getItem(STORAGE_KEY) || localStorage.getItem('faktora_enterprise_datastore');
1322 + const persisted = localStorage.getItem(STORAGE_KEY) || localStorage.getItem('easy_factor_datastore_v2_4') || localStorage.getItem('easy_factor_datastore_v2');
1323 if (persisted) {
1324 try {
1325 const parsed = JSON.parse(persisted);
1326 if (parsed.companies && parsed.companies.length > 0) {
1327 datastore = parsed;
1095 - } else if (parsed.settings) {
1096 - datastore.companies = [{
1097 - id: 'COMP-1',
1098 - name: parsed.settings.store_name || 'شرکت آرا بتن',
1099 - phone: parsed.settings.phone || '',
1100 - national_id: parsed.settings.tax_number || '',
1101 - economic_code: '',
1102 - reg_number: '',
1103 - postal_code: '',
1104 - address: parsed.settings.address || '',
1105 - footer: parsed.settings.footer || ''
1106 - }];
1107 - datastore.contacts = parsed.contacts || datastore.contacts;
1108 - datastore.products = parsed.products || datastore.products;
1109 - datastore.invoices = parsed.invoices || [];
1110 - datastore.cheques = parsed.cheques || [];
1111 - datastore.expenses = parsed.expenses || [];
1328 }
1113 - } catch(e) { console.error('Migration error', e); }
1329 + } catch(e) { console.error('Data init error', e); }
1330 }
1331 persistDatastore();
1332 refreshAllSurfaces();
@@ -1156,18 +1372,39 @@
1372 function refreshAllSurfaces() {
1373 document.getElementById('dashboard-date-display').innerText = getJalaliDate();
1374 document.getElementById('invoice-date-input').value = getJalaliNumeric();
1375 + document.getElementById('lbl-build-date').innerText = APP_BUILD_TIMESTAMP;
1376 + document.getElementById('lbl-last-update-full').innerText = APP_BUILD_TIMESTAMP;
1377
1160 - renderDashboard();
1378 renderCompanies();
1379 renderContacts();
1380 renderProducts();
1381 renderInvoices();
1382 + renderDashboard();
1383 renderCheques();
1384 renderExpenses();
1385 applyDefaultSettingsToForm();
1386 }
1387
1170 - // رفتار دقیق تفکیک رسمی و ارزش افزوده
1388 + function formatEntityName(rawName, entityType, customPrefix = '') {
1389 + let trimmed = (rawName || '').trim();
1390 + if (entityType === 'legal') {
1391 + if (!trimmed.startsWith('شرکت')) {
1392 + trimmed = 'شرکت ' + trimmed;
1393 + }
1394 + } else if (entityType === 'natural') {
1395 + if (customPrefix === 'فروشگاه') {
1396 + if (!trimmed.startsWith('فروشگاه')) {
1397 + trimmed = 'فروشگاه ' + trimmed;
1398 + }
1399 + } else if (customPrefix === 'آقا/خانم') {
1400 + if (!trimmed.startsWith('آقا/خانم') && !trimmed.startsWith('آقای') && !trimmed.startsWith('خانم')) {
1401 + trimmed = 'آقا/خانم ' + trimmed;
1402 + }
1403 + }
1404 + }
1405 + return trimmed;
1406 + }
1407 +
1408 function handleInvoiceKindChange() {
1409 const kind = document.getElementById('invoice-kind').value;
1410 const vatModeSelect = document.getElementById('invoice-vat-mode');
@@ -1175,10 +1412,8 @@
1412
1413 if (kind === 'formal') {
1414 vatModeSelect.disabled = false;
1178 - // بازگردانی طبق آخرین انتخاب یا پیش‌فرض
1415 handleVatModeChange();
1416 } else {
1181 - // فاکتور غیررسمی ارزش افزوده ندارد و قفل می‌شود
1417 vatModeSelect.value = 'none';
1418 vatModeSelect.disabled = true;
1419 rateBox.style.display = 'none';
@@ -1199,6 +1434,12 @@
1434 recomputeTotals();
1435 }
1436
1437 + function handleContactEntityChange() {
1438 + const type = document.getElementById('contact-entity-type').value;
1439 + const prefixBox = document.getElementById('box-contact-prefix');
1440 + prefixBox.style.display = type === 'natural' ? 'block' : 'none';
1441 + }
1442 +
1443 function handleDefaultKindChange() {
1444 const kind = document.getElementById('def-invoice-kind').value;
1445 const vatModeSelect = document.getElementById('def-vat-mode');
@@ -1238,6 +1479,7 @@
1479
1480 handleDefaultKindChange();
1481 handleInvoiceKindChange();
1482 + handleContactEntityChange();
1483 }
1484
1485 function commitSaveDefaultSettings() {
@@ -1248,15 +1490,18 @@
1490 default_company_id: datastore.default_settings?.default_company_id || (datastore.companies[0]?.id)
1491 };
1492 persistDatastore();
1251 - alert('تنظیمات پیش‌فرض صدور فاکتور با موفقیت ذخیره شد.');
1493 + alert('تنظیمات پیش‌فرض با موفقیت ذخیره شد.');
1494 }
1495
1254 - // ۱. داشبورد
1496 + // ۱. داشبورد (با فیلتر تفکیکی شرکت فعال)
1497 function renderDashboard() {
1498 let salesSum = 0;
1499 let debtorsSum = 0;
1500 + const activeCompId = document.getElementById('invoice-company-id')?.value || datastore.companies[0]?.id;
1501 +
1502 + const filteredInvoices = datastore.invoices.filter(inv => inv.companyId === activeCompId);
1503
1259 - datastore.invoices.forEach(inv => {
1504 + filteredInvoices.forEach(inv => {
1505 salesSum += inv.grandTotal;
1506 if (inv.paymentMethod === 'credit') debtorsSum += inv.grandTotal;
1507 });
@@ -1267,12 +1512,12 @@
1512 document.getElementById('kpi-cheques-count').innerText = datastore.cheques.filter(c => c.status === 'registered').length.toLocaleString('fa-IR') + ' فقره';
1513
1514 const recentTbody = document.getElementById('dashboard-recent-table');
1270 - if (datastore.invoices.length === 0) {
1271 - recentTbody.innerHTML = '<tr><td colspan="7" style="text-align:center; color:var(--text-muted); padding:20px;">هنوز فاکتوری صادر نشده است.</td></tr>';
1515 + if (filteredInvoices.length === 0) {
1516 + recentTbody.innerHTML = '<tr><td colspan="7" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ فاکتوری برای این شرکت صادر نشده است.</td></tr>';
1517 return;
1518 }
1519
1275 - recentTbody.innerHTML = datastore.invoices.slice(-5).reverse().map(inv => `
1520 + recentTbody.innerHTML = filteredInvoices.slice(-5).reverse().map(inv => `
1521 <tr>
1522 <td><strong>#${inv.number}</strong></td>
1523 <td>${inv.companyName || '—'}</td>
@@ -1285,15 +1530,30 @@
1530 `).join('');
1531 }
1532
1288 - // ۲. فاکتورها
1289 - function addInvoiceItemRow() {
1533 + // ۲. فاکتورها (صدور، اقلام و ویرایش)
1534 + function onActiveCompanyFilterChange() {
1535 + const activeCompId = document.getElementById('invoice-company-id').value;
1536 + const filterSelect = document.getElementById('filter-invoice-company');
1537 + if (filterSelect) {
1538 + filterSelect.value = activeCompId;
1539 + }
1540 + renderInvoices();
1541 + renderDashboard();
1542 + }
1543 +
1544 + function startNewInvoice() {
1545 + cancelInvoiceEdit();
1546 + switchView('view-invoices');
1547 + }
1548 +
1549 + function addInvoiceItemRow(selectedProdId = '', initialQty = 1, initialPrice = null) {
1550 const tbody = document.getElementById('invoice-items-table-body');
1551 const rowKey = 'item_' + Date.now() + '_' + Math.random().toString(36).substr(2, 4);
1552 const tr = document.createElement('tr');
1553 tr.id = rowKey;
1554
1555 const productOptions = datastore.products.map(p =>
1296 - `<option value="${p.id}" data-price="${p.sale_price}">${p.name} ${p.spec ? '(' + p.spec + ')' : ''} [${p.unit}]</option>`
1556 + `<option value="${p.id}" data-price="${p.sale_price}" ${p.id === selectedProdId ? 'selected' : ''}>${p.name} ${p.spec ? '(' + p.spec + ')' : ''} [${p.unit}]</option>`
1557 ).join('');
1558
1559 tr.innerHTML = `
@@ -1303,19 +1563,25 @@
1563 ${productOptions}
1564 </select>
1565 </td>
1306 - <td><input type="number" class="form-control row-quantity" value="1" min="1" oninput="recomputeTotals()" /></td>
1307 - <td><input type="number" class="form-control row-price" value="0" oninput="recomputeTotals()" /></td>
1566 + <td><input type="number" class="form-control row-quantity" value="${initialQty}" min="1" oninput="recomputeTotals()" /></td>
1567 + <td><input type="number" class="form-control row-price" value="${initialPrice !== null ? initialPrice : 0}" oninput="recomputeTotals()" /></td>
1568 <td class="row-linetotal" style="font-weight:bold; padding-top:16px;">۰</td>
1569 <td><button class="btn btn-danger" style="min-height:40px; padding:4px 10px;" onclick="document.getElementById('${rowKey}').remove(); recomputeTotals();">✕</button></td>
1570 `;
1571 tbody.appendChild(tr);
1572 +
1573 + if (selectedProdId && initialPrice === null) {
1574 + onRowProductChange(rowKey);
1575 + } else {
1576 + recomputeTotals();
1577 + }
1578 }
1579
1580 function onRowProductChange(rowKey) {
1581 const tr = document.getElementById(rowKey);
1582 const sel = tr.querySelector('.row-product-select');
1583 const opt = sel.options[sel.selectedIndex];
1318 - const prc = opt.getAttribute('data-price') || 0;
1584 + const prc = opt?.getAttribute('data-price') || 0;
1585 tr.querySelector('.row-price').value = prc;
1586 recomputeTotals();
1587 }
@@ -1358,6 +1624,7 @@
1624 const date = document.getElementById('invoice-date-input').value;
1625 const kind = document.getElementById('invoice-kind').value;
1626 const paymentMethod = document.getElementById('invoice-payment-method').value;
1627 + const editId = document.getElementById('edit-invoice-id').value;
1628
1629 const items = [];
1630 document.querySelectorAll('#invoice-items-table-body tr').forEach(tr => {
@@ -1373,7 +1640,7 @@
1640 });
1641
1642 if (items.length === 0) {
1376 - alert('لطفاً حداقل یک قلم کالا یا خدمات به جدول اضافه کنید.');
1643 + alert('لطفاً حداقل یک قلم کالا یا خدمات به فاکتور اضافه کنید.');
1644 return;
1645 }
1646
@@ -1381,43 +1648,111 @@
1648 const methodLabels = { cash: 'نقدی', credit: 'نسیه', cheque: 'چک صیاد', installment: 'اقساطی' };
1649 const kindLabels = { formal: 'رسمی', non_formal: 'غیررسمی', pre_invoice: 'پیش‌فاکتور' };
1650
1384 - const record = {
1385 - id: 'INV_' + Date.now(),
1386 - number,
1387 - date,
1388 - companyId,
1389 - companyName,
1390 - kind,
1391 - kindLabel: kindLabels[kind],
1392 - contactId,
1393 - contactName,
1394 - paymentMethod,
1395 - paymentMethodLabel: methodLabels[paymentMethod],
1396 - subtotal: totals.subtotal,
1397 - discount: totals.fixedDiscount,
1398 - vat: totals.vatAmount,
1399 - vatRate: totals.vatRate,
1400 - grandTotal: totals.grandTotal,
1401 - items
1402 - };
1651 + if (editId) {
1652 + // ویرایش فاکتور موجود
1653 + const existingIndex = datastore.invoices.findIndex(i => i.id === editId);
1654 + if (existingIndex !== -1) {
1655 + datastore.invoices[existingIndex] = {
1656 + ...datastore.invoices[existingIndex],
1657 + number, date, companyId, companyName, kind,
1658 + kindLabel: kindLabels[kind],
1659 + contactId, contactName, paymentMethod,
1660 + paymentMethodLabel: methodLabels[paymentMethod],
1661 + subtotal: totals.subtotal,
1662 + discount: totals.fixedDiscount,
1663 + vat: totals.vatAmount,
1664 + vatRate: totals.vatRate,
1665 + grandTotal: totals.grandTotal,
1666 + items
1667 + };
1668 + alert('فاکتور با موفقیت ویرایش شد.');
1669 + }
1670 + cancelInvoiceEdit();
1671 + } else {
1672 + // ثبت فاکتور جدید
1673 + const record = {
1674 + id: 'INV_' + Date.now(),
1675 + number, date, companyId, companyName, kind,
1676 + kindLabel: kindLabels[kind],
1677 + contactId, contactName, paymentMethod,
1678 + paymentMethodLabel: methodLabels[paymentMethod],
1679 + subtotal: totals.subtotal,
1680 + discount: totals.fixedDiscount,
1681 + vat: totals.vatAmount,
1682 + vatRate: totals.vatRate,
1683 + grandTotal: totals.grandTotal,
1684 + items
1685 + };
1686 + datastore.invoices.push(record);
1687 + alert('فاکتور با موفقیت صادر و ثبت گردید.');
1688 + cancelInvoiceEdit();
1689 + renderAndPrintDirect(record.id);
1690 + }
1691
1404 - datastore.invoices.push(record);
1692 persistDatastore();
1406 - alert('فاکتور با موفقیت صادر و ثبت شد.');
1693 + refreshAllSurfaces();
1694 + }
1695 +
1696 + function editInvoice(invId) {
1697 + const inv = datastore.invoices.find(i => i.id === invId);
1698 + if (!inv) return;
1699 +
1700 + switchView('view-invoices');
1701 + document.getElementById('edit-invoice-id').value = inv.id;
1702 + document.getElementById('invoice-form-title').innerText = `✏️ ویرایش فاکتور #${inv.number}`;
1703 + document.getElementById('btn-cancel-edit').style.display = 'inline-flex';
1704 + document.getElementById('btn-save-invoice').innerText = '💾 ذخیره تغییرات فاکتور';
1705 +
1706 + document.getElementById('invoice-company-id').value = inv.companyId;
1707 + document.getElementById('invoice-kind').value = inv.kind;
1708 + document.getElementById('invoice-vat-mode').value = inv.vat > 0 ? 'with_vat' : 'none';
1709 + document.getElementById('invoice-vat-rate-input').value = inv.vatRate || 10;
1710 + document.getElementById('invoice-number').value = inv.number;
1711 + document.getElementById('invoice-contact-id').value = inv.contactId;
1712 + document.getElementById('invoice-date-input').value = inv.date;
1713 + document.getElementById('invoice-payment-method').value = inv.paymentMethod;
1714 + document.getElementById('invoice-discount-fixed').value = inv.discount || 0;
1715 +
1716 + handleInvoiceKindChange();
1717 +
1718 + // بارگذاری اقلام
1719 + const tbody = document.getElementById('invoice-items-table-body');
1720 + tbody.innerHTML = '';
1721 + inv.items.forEach(it => {
1722 + addInvoiceItemRow(it.prodId, it.qty, it.price);
1723 + });
1724 + recomputeTotals();
1725 + }
1726 +
1727 + function cancelInvoiceEdit() {
1728 + document.getElementById('edit-invoice-id').value = '';
1729 + document.getElementById('invoice-form-title').innerText = 'صدور فاکتور فروش';
1730 + document.getElementById('btn-cancel-edit').style.display = 'none';
1731 + document.getElementById('btn-save-invoice').innerText = '💾 ثبت و صدور فاکتور';
1732 document.getElementById('invoice-items-table-body').innerHTML = '';
1733 + document.getElementById('invoice-number').value = '';
1734 + document.getElementById('invoice-discount-fixed').value = 0;
1735 addInvoiceItemRow();
1409 - refreshAllSurfaces();
1410 - renderAndPrintDirect(record.id);
1736 + applyDefaultSettingsToForm();
1737 }
1738
1739 + // رندر فاکتورها بر اساس فیلتر شرکت انتخابی یا تمام شرکت‌ها
1740 function renderInvoices() {
1741 const tbody = document.getElementById('invoice-archive-table-body');
1415 - if (datastore.invoices.length === 0) {
1416 - tbody.innerHTML = '<tr><td colspan="9" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ فاکتوری ذخیره نشده است.</td></tr>';
1742 + const filterSelect = document.getElementById('filter-invoice-company');
1743 + const selectedFilter = filterSelect?.value || document.getElementById('invoice-company-id')?.value || 'ALL';
1744 +
1745 + let list = datastore.invoices;
1746 + if (selectedFilter !== 'ALL') {
1747 + list = list.filter(i => i.companyId === selectedFilter);
1748 + }
1749 +
1750 + if (list.length === 0) {
1751 + tbody.innerHTML = '<tr><td colspan="8" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ فاکتوری برای این فیلتر ثبت نشده است.</td></tr>';
1752 return;
1753 }
1754
1420 - tbody.innerHTML = datastore.invoices.map(inv => `
1755 + tbody.innerHTML = list.map(inv => `
1756 <tr>
1757 <td><strong>#${inv.number}</strong></td>
1758 <td>${inv.companyName || '—'}</td>
@@ -1426,9 +1761,9 @@
1761 <td>${inv.vat > 0 ? (inv.vatRate + '٪') : '—'}</td>
1762 <td>${inv.date}</td>
1763 <td>${inv.grandTotal.toLocaleString('fa-IR')}</td>
1429 - <td>${inv.paymentMethodLabel}</td>
1764 <td>
1431 - <button class="btn btn-secondary btn-inline" style="padding:4px 10px; font-size:12px;" onclick="renderAndPrintDirect('${inv.id}')">🖨️ چاپ</button>
1765 + <button class="btn btn-secondary btn-inline" style="padding:4px 8px; font-size:12px; min-height:30px;" onclick="editInvoice('${inv.id}')">✏️ ویرایش</button>
1766 + <button class="btn btn-secondary btn-inline" style="padding:4px 8px; font-size:12px; min-height:30px;" onclick="renderAndPrintDirect('${inv.id}')">🖨️ چاپ</button>
1767 </td>
1768 </tr>
1769 `).join('');
@@ -1448,7 +1783,6 @@
1783 document.getElementById('p-doc-number').innerText = inv.number;
1784 document.getElementById('p-doc-date').innerText = inv.date;
1785
1451 - // مشخصات فروشنده
1786 document.getElementById('p-seller-name').innerText = seller.name || '—';
1787 document.getElementById('p-seller-national').innerText = seller.national_id || '—';
1788 document.getElementById('p-seller-economic').innerText = seller.economic_code || '—';
@@ -1456,23 +1790,23 @@
1790 document.getElementById('p-seller-postal').innerText = seller.postal_code || '—';
1791 document.getElementById('p-seller-address').innerText = seller.address || '—';
1792
1459 - // مشخصات خریدار
1793 document.getElementById('p-target-name').innerText = contact.name || inv.contactName;
1794 document.getElementById('p-target-national').innerText = contact.national_id || '—';
1795 document.getElementById('p-target-economic').innerText = contact.economic_code || '—';
1796 document.getElementById('p-target-reg').innerText = contact.reg_number || '—';
1797 document.getElementById('p-target-postal').innerText = contact.postal_code || '—';
1798 document.getElementById('p-target-address').innerText = contact.address || '—';
1799 + document.getElementById('p-target-phone').innerText = contact.mobile || '—';
1800
1801 document.getElementById('p-doc-footer-note').innerText = seller.footer || 'از خرید شما سپاسگزاریم.';
1802
1803 document.getElementById('p-target-items-table').innerHTML = inv.items.map((it, idx) => `
1804 <tr>
1471 - <td style="border:1px solid #000; padding:8px; text-align:center;">${idx + 1}</td>
1472 - <td style="border:1px solid #000; padding:8px; text-align:right;">${it.prodName}</td>
1473 - <td style="border:1px solid #000; padding:8px; text-align:center;">${it.qty}</td>
1474 - <td style="border:1px solid #000; padding:8px; text-align:left;">${it.price.toLocaleString('fa-IR')}</td>
1475 - <td style="border:1px solid #000; padding:8px; text-align:left;">${it.lineTotal.toLocaleString('fa-IR')}</td>
1805 + <td style="border:1px solid #000; padding:6px; text-align:center;">${idx + 1}</td>
1806 + <td style="border:1px solid #000; padding:6px; text-align:right;">${it.prodName}</td>
1807 + <td style="border:1px solid #000; padding:6px; text-align:center;">${it.qty}</td>
1808 + <td style="border:1px solid #000; padding:6px; text-align:left;">${it.price.toLocaleString('fa-IR')}</td>
1809 + <td style="border:1px solid #000; padding:6px; text-align:left;">${it.lineTotal.toLocaleString('fa-IR')}</td>
1810 </tr>
1811 `).join('');
1812
@@ -1495,7 +1829,7 @@
1829 document.getElementById('printable-invoice').style.display = 'none';
1830 }
1831
1498 - // ۳. کالاها
1832 + // ۳. کالاها و ورود از اکسل
1833 function commitSaveProduct() {
1834 const code = document.getElementById('prod-code-input').value || (datastore.products.length + 101).toString();
1835 const name = document.getElementById('prod-name-input').value;
@@ -1538,9 +1872,87 @@
1872 }
1873 }
1874
1541 - // ۴. اشخاص
1875 + function openQuickProductModal() {
1876 + document.getElementById('modal-quick-product').classList.add('active');
1877 + }
1878 + function closeQuickProductModal() {
1879 + document.getElementById('modal-quick-product').classList.remove('active');
1880 + }
1881 + function saveQuickProduct() {
1882 + const code = document.getElementById('quick-p-code').value || (datastore.products.length + 101).toString();
1883 + const name = document.getElementById('quick-p-name').value;
1884 + const spec = document.getElementById('quick-p-spec').value || '';
1885 + const unit = document.getElementById('quick-p-unit').value || 'عدد';
1886 + const price = parseFloat(document.getElementById('quick-p-price').value) || 0;
1887 +
1888 + if (!name) { alert('عنوان کالا الزامی است.'); return; }
1889 +
1890 + const newId = 'P_' + Date.now();
1891 + datastore.products.push({ id: newId, code, name, spec, unit, buy_price: 0, sale_price: price, stock: 0, type: 'good' });
1892 + persistDatastore();
1893 + closeQuickProductModal();
1894 + refreshAllSurfaces();
1895 + addInvoiceItemRow(newId, 1, price);
1896 + }
1897 +
1898 + // ایمپورت اکسل کالاها
1899 + function downloadProductsExcelTemplate() {
1900 + const ws_data = [
1901 + ["کد کالا", "نام کالا", "مشخصه و نوع", "واحد", "قیمت فروش (تومان)"],
1902 + ["101", "بلوک سیمانی ۱۰", "سبک لیکا", "قالب", 26000],
1903 + ["102", "بلوک سیمانی ۱۵", "سنگین ماسه‌ای", "قالب", 32000]
1904 + ];
1905 + const ws = XLSX.utils.aoa_to_sheet(ws_data);
1906 + const wb = XLSX.utils.book_new();
1907 + XLSX.utils.book_append_sheet(wb, ws, "کالاها");
1908 + XLSX.writeFile(wb, "نمونه_کالاها_ایزی_فاکتور.xlsx");
1909 + }
1910 +
1911 + function importProductsFromExcel(event) {
1912 + const file = event.target.files[0];
1913 + if (!file) return;
1914 +
1915 + const reader = new FileReader();
1916 + reader.onload = function(e) {
1917 + try {
1918 + const data = new Uint8Array(e.target.result);
1919 + const workbook = XLSX.read(data, { type: 'array' });
1920 + const firstSheetName = workbook.SheetNames[0];
1921 + const rows = XLSX.utils.sheet_to_json(workbook.Sheets[firstSheetName]);
1922 +
1923 + let added = 0;
1924 + rows.forEach((r, idx) => {
1925 + const name = r["نام کالا"] || r["عنوان"] || r["name"];
1926 + if (name) {
1927 + datastore.products.push({
1928 + id: 'P_' + Date.now() + '_' + idx,
1929 + code: (r["کد کالا"] || r["code"] || (datastore.products.length + 101)).toString(),
1930 + name: name.toString(),
1931 + spec: (r["مشخصه و نوع"] || r["مشخصه"] || r["spec"] || '').toString(),
1932 + unit: (r["واحد"] || r["unit"] || 'عدد').toString(),
1933 + buy_price: parseFloat(r["قیمت خرید"] || 0) || 0,
1934 + sale_price: parseFloat(r["قیمت فروش (تومان)"] || r["قیمت فروش"] || r["price"] || 0) || 0,
1935 + stock: 0,
1936 + type: 'good'
1937 + });
1938 + added++;
1939 + }
1940 + });
1941 + persistDatastore();
1942 + refreshAllSurfaces();
1943 + alert(`${added} کالا با موفقیت از اکسل اضافه شد.`);
1944 + } catch(err) {
1945 + alert('خطا در خواندن فایل اکسل! لطفاً از فرمت نمونه استفاده فرمایید.');
1946 + }
1947 + };
1948 + reader.readAsArrayBuffer(file);
1949 + }
1950 +
1951 + // ۴. اشخاص و ورود از اکسل
1952 function commitSaveContact() {
1543 - const name = document.getElementById('contact-name-input').value;
1953 + const entity_type = document.getElementById('contact-entity-type').value;
1954 + const custom_prefix = entity_type === 'natural' ? document.getElementById('contact-prefix-select').value : '';
1955 + const raw_name = document.getElementById('contact-name-input').value;
1956 const role = document.getElementById('contact-role-input').value;
1957 const mobile = document.getElementById('contact-mobile-input').value;
1958 const national_id = document.getElementById('contact-national-input').value;
@@ -1549,11 +1961,18 @@
1961 const postal_code = document.getElementById('contact-postal-input').value;
1962 const address = document.getElementById('contact-address-input').value;
1963
1552 - if (!name) { alert('نام طرف حساب الزامی است.'); return; }
1964 + if (!raw_name) { alert('نام طرف حساب الزامی است.'); return; }
1965
1554 - datastore.contacts.push({ id: 'C_' + Date.now(), name, role, mobile, national_id, economic_code, reg_number, postal_code, address, balance: 0 });
1966 + const formatted_name = formatEntityName(raw_name, entity_type, custom_prefix);
1967 +
1968 + datastore.contacts.push({
1969 + id: 'C_' + Date.now(),
1970 + entity_type,
1971 + name: formatted_name,
1972 + role, mobile, national_id, economic_code, reg_number, postal_code, address, balance: 0
1973 + });
1974 persistDatastore();
1556 - alert('طرف حساب با تمام فیلدهای حقوقی ثبت شد.');
1975 + alert('طرف حساب با موفقیت ثبت شد.');
1976 document.getElementById('contact-name-input').value = '';
1977 document.getElementById('contact-national-input').value = '';
1978 document.getElementById('contact-economic-input').value = '';
@@ -1571,6 +1990,7 @@
1990 tbody.innerHTML = datastore.contacts.map(c => `
1991 <tr>
1992 <td><strong>${c.name}</strong> (${c.role === 'customer' ? 'مشتری' : 'تامین‌کننده'})</td>
1993 + <td><span class="badge ${c.entity_type === 'legal' ? 'badge-warning' : 'badge-success'}">${c.entity_type === 'legal' ? 'حقوقی' : 'حقیقی'}</span></td>
1994 <td>${c.national_id || '—'}</td>
1995 <td>${c.economic_code || '—'}</td>
1996 <td>${c.reg_number || '—'}</td>
@@ -1594,6 +2014,104 @@
2014 }
2015 }
2016
2017 + function openQuickContactModal() {
2018 + document.getElementById('modal-quick-contact').classList.add('active');
2019 + }
2020 + function closeQuickContactModal() {
2021 + document.getElementById('modal-quick-contact').classList.remove('active');
2022 + }
2023 + function handleQuickCEntityChange() {
2024 + const type = document.getElementById('quick-c-entity').value;
2025 + document.getElementById('box-quick-c-prefix').style.display = type === 'natural' ? 'block' : 'none';
2026 + }
2027 + function saveQuickContact() {
2028 + const entity_type = document.getElementById('quick-c-entity').value;
2029 + const prefix = entity_type === 'natural' ? document.getElementById('quick-c-prefix').value : '';
2030 + const raw_name = document.getElementById('quick-c-name').value;
2031 + const mobile = document.getElementById('quick-c-mobile').value;
2032 + const national_id = document.getElementById('quick-c-national').value;
2033 + const economic_code = document.getElementById('quick-c-economic').value;
2034 + const reg_number = document.getElementById('quick-c-reg').value;
2035 + const postal_code = document.getElementById('quick-c-postal').value;
2036 + const address = document.getElementById('quick-c-address').value;
2037 +
2038 + if (!raw_name) { alert('نام طرف حساب الزامی است.'); return; }
2039 +
2040 + const newId = 'C_' + Date.now();
2041 + const formatted_name = formatEntityName(raw_name, entity_type, prefix);
2042 +
2043 + datastore.contacts.push({
2044 + id: newId,
2045 + entity_type,
2046 + name: formatted_name,
2047 + role: 'customer',
2048 + mobile, national_id, economic_code, reg_number, postal_code, address, balance: 0
2049 + });
2050 + persistDatastore();
2051 + closeQuickContactModal();
2052 + refreshAllSurfaces();
2053 + document.getElementById('invoice-contact-id').value = newId;
2054 + }
2055 +
2056 + // ایمپورت اکسل اشخاص
2057 + function downloadContactsExcelTemplate() {
2058 + const ws_data = [
2059 + ["نام شخص یا شرکت", "نوع (حقیقی/حقوقی)", "شماره همراه", "شناسه یا کد ملی", "کد اقتصادی", "شماره ثبت", "کد پستی", "نشانی"],
2060 + ["عمران سازه پردیس", "حقوقی", "09121234567", "10103456789", "411122233344", "12345", "1455667788", "تهران - خیابان سهروردی"],
2061 + ["احمدی", "حقیقی", "09129876543", "0012345678", "", "", "1987654321", "تهران - بازار"]
2062 + ];
2063 + const ws = XLSX.utils.aoa_to_sheet(ws_data);
2064 + const wb = XLSX.utils.book_new();
2065 + XLSX.utils.book_append_sheet(wb, ws, "اشخاص");
2066 + XLSX.writeFile(wb, "نمونه_اشخاص_ایزی_فاکتور.xlsx");
2067 + }
2068 +
2069 + function importContactsFromExcel(event) {
2070 + const file = event.target.files[0];
2071 + if (!file) return;
2072 +
2073 + const reader = new FileReader();
2074 + reader.onload = function(e) {
2075 + try {
2076 + const data = new Uint8Array(e.target.result);
2077 + const workbook = XLSX.read(data, { type: 'array' });
2078 + const firstSheetName = workbook.SheetNames[0];
2079 + const rows = XLSX.utils.sheet_to_json(workbook.Sheets[firstSheetName]);
2080 +
2081 + let added = 0;
2082 + rows.forEach((r, idx) => {
2083 + const raw_name = r["نام شخص یا شرکت"] || r["نام"] || r["name"];
2084 + if (raw_name) {
2085 + const typeStr = (r["نوع (حقیقی/حقوقی)"] || r["نوع"] || '').toString();
2086 + const entity_type = typeStr.includes('حقوقی') ? 'legal' : 'natural';
2087 + const formatted_name = formatEntityName(raw_name.toString(), entity_type, entity_type === 'natural' ? 'آقا/خانم' : '');
2088 +
2089 + datastore.contacts.push({
2090 + id: 'C_' + Date.now() + '_' + idx,
2091 + entity_type,
2092 + name: formatted_name,
2093 + role: 'customer',
2094 + mobile: (r["شماره همراه"] || r["همراه"] || r["تلفن"] || '').toString(),
2095 + national_id: (r["شناسه یا کد ملی"] || r["کد ملی"] || '').toString(),
2096 + economic_code: (r["کد اقتصادی"] || '').toString(),
2097 + reg_number: (r["شماره ثبت"] || '').toString(),
2098 + postal_code: (r["کد پستی"] || '').toString(),
2099 + address: (r["نشانی"] || r["آدرس"] || '').toString(),
2100 + balance: 0
2101 + });
2102 + added++;
2103 + }
2104 + });
2105 + persistDatastore();
2106 + refreshAllSurfaces();
2107 + alert(`${added} طرف حساب با موفقیت از اکسل وارد شد.`);
2108 + } catch(err) {
2109 + alert('خطا در خواندن فایل اکسل اشخاص! لطفاً ساختار فایل نمونه را رعایت فرمایید.');
2110 + }
2111 + };
2112 + reader.readAsArrayBuffer(file);
2113 + }
2114 +
2115 // ۵. چک‌های صیاد
2116 function commitSaveCheque() {
2117 const direction = document.getElementById('chq-direction-input').value;
@@ -1669,7 +2187,8 @@
2187
2188 // ۷. چندشرکتی
2189 function commitSaveCompany() {
1672 - const name = document.getElementById('company-name-input').value;
2190 + const entity_type = document.getElementById('company-entity-type').value;
2191 + const raw_name = document.getElementById('company-name-input').value;
2192 const phone = document.getElementById('company-phone-input').value;
2193 const national_id = document.getElementById('company-national-input').value;
2194 const economic_code = document.getElementById('company-economic-input').value;
@@ -1678,14 +2197,18 @@
2197 const address = document.getElementById('company-address-input').value;
2198 const footer = document.getElementById('company-footer-input').value;
2199
1681 - if (!name) { alert('نام شرکت یا فروشگاه الزامی است.'); return; }
2200 + if (!raw_name) { alert('نام شرکت یا فروشگاه الزامی است.'); return; }
2201 +
2202 + const formatted_name = formatEntityName(raw_name, entity_type, entity_type === 'natural' ? 'فروشگاه' : '');
2203
2204 datastore.companies.push({
2205 id: 'COMP_' + Date.now(),
1685 - name, phone, national_id, economic_code, reg_number, postal_code, address, footer
2206 + entity_type,
2207 + name: formatted_name,
2208 + phone, national_id, economic_code, reg_number, postal_code, address, footer
2209 });
2210 persistDatastore();
1688 - alert('شرکت / فروشنده جدید با موفقیت ثبت شد.');
2211 + alert('فروشنده جدید با موفقیت ثبت شد.');
2212 document.getElementById('company-name-input').value = '';
2213 document.getElementById('company-phone-input').value = '';
2214 document.getElementById('company-national-input').value = '';
@@ -1700,11 +2223,13 @@
2223 function renderCompanies() {
2224 const tbody = document.getElementById('companies-table-body');
2225 const invoiceCompSelect = document.getElementById('invoice-company-id');
2226 + const filterCompSelect = document.getElementById('filter-invoice-company');
2227 const defCompId = datastore.default_settings?.default_company_id || (datastore.companies[0]?.id);
2228
2229 tbody.innerHTML = datastore.companies.map(c => `
2230 <tr>
2231 <td><strong>${c.name}</strong></td>
2232 + <td><span class="badge ${c.entity_type === 'legal' ? 'badge-warning' : 'badge-success'}">${c.entity_type === 'legal' ? 'حقوقی' : 'حقیقی'}</span></td>
2233 <td>${c.national_id || '—'}</td>
2234 <td>${c.economic_code || '—'}</td>
2235 <td>${c.reg_number || '—'}</td>
@@ -1717,6 +2242,13 @@
2242 invoiceCompSelect.innerHTML = datastore.companies.map(c =>
2243 `<option value="${c.id}" ${c.id === defCompId ? 'selected' : ''}>${c.name}</option>`
2244 ).join('');
2245 +
2246 + if (filterCompSelect) {
2247 + filterCompSelect.innerHTML = `
2248 + <option value="ALL">نمایش همه شرکت‌ها</option>
2249 + ${datastore.companies.map(c => `<option value="${c.id}" ${c.id === defCompId ? 'selected' : ''}>فقط ${c.name}</option>`).join('')}
2250 + `;
2251 + }
2252 }
2253
2254 function setDefaultCompany(id) {