سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 17:00 UTC
Update index.html
davoodmehraban89 committed
Sep 17, 2026 at 22:47 UTC
bed75fc3c7f2acba09fc86dc29860ae0019d229d
1 file changed
+204
-1103
index.html
+204
-1103
@@ -16,21 +16,11 @@
16
17
<style>
18
:root {
19
- --primary: #2563eb;
20
- --primary-hover: #1d4ed8;
21
- --accent: #2563eb;
22
- --bg: #f8fafc;
23
- --card-bg: #ffffff;
24
- --text: #0f172a;
25
- --text-muted: #64748b;
26
- --border: #cbd5e1;
27
- --danger: #dc2626;
28
- --success: #059669;
29
- --warning: #d97706;
30
- --sidebar-w: 240px;
31
- --nav-h: 70px;
19
+ --primary: #2563eb; --primary-hover: #1d4ed8; --accent: #2563eb;
20
+ --bg: #f8fafc; --card-bg: #ffffff; --text: #0f172a; --text-muted: #64748b;
21
+ --border: #cbd5e1; --danger: #dc2626; --success: #059669; --warning: #d97706;
22
+ --sidebar-w: 240px; --nav-h: 70px;
23
}
33
-
24
html, body { width: 100%; max-width: 100%; overflow-x: hidden !important; position: relative; }
25
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Vazirmatn FD', -apple-system, BlinkMacSystemFont, Tahoma, sans-serif; -webkit-tap-highlight-color: transparent; }
26
body { background-color: var(--bg); color: var(--text); font-size: 14px; }
@@ -42,19 +32,57 @@
32
.sidebar { width: var(--sidebar-w); background: var(--card-bg); border-left: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; right: 0; z-index: 100; }
33
.brand-box { padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
34
.brand-icon { width: 40px; height: 40px; background: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: bold; font-size: 18px; }
45
-
35
.sidebar-menu { list-style: none; padding: 16px 8px; flex: 1; overflow-y: auto; }
36
.sidebar-menu li a { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); text-decoration: none; border-radius: 8px; margin-bottom: 4px; font-size: 14px; font-weight: 500; transition: all 0.2s; cursor: pointer; }
37
.sidebar-menu li a:hover, .sidebar-menu li a.active { background: #eff6ff; color: var(--primary); font-weight: bold; }
49
-
38
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); text-align: center; display:flex; flex-direction:column; gap:6px; }
39
.main-surface { flex: 1; margin-right: var(--sidebar-w); padding: 20px; padding-bottom: 100px; max-width: calc(100% - var(--sidebar-w)); overflow-x: hidden; }
52
-
40
.mobile-dock { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: rgba(255,255,255,0.98); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid #cbd5e1; z-index: 200; justify-content: space-around; align-items: center; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 12px rgba(0,0,0,0.06); }
41
.dock-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #475569; text-decoration: none; font-size: 10.5px; font-weight: 600; flex: 1; height: 100%; cursor: pointer; }
42
.dock-tab.active { color: var(--primary); font-weight: 800; }
43
.dock-tab svg { width: 20px; height: 20px; stroke-width: 2; }
44
45
+ /* دکمه شناور پشتیبانی واتساپ */
46
+ .whatsapp-support {
47
+ position: fixed;
48
+ bottom: 90px;
49
+ left: 20px;
50
+ z-index: 250;
51
+ display: flex;
52
+ align-items: center;
53
+ gap: 8px;
54
+ background: linear-gradient(135deg, #25D366, #128C7E);
55
+ color: #fff;
56
+ text-decoration: none;
57
+ padding: 10px 16px 10px 12px;
58
+ border-radius: 50px;
59
+ box-shadow: 0 8px 24px rgba(37, 211, 102, 0.4);
60
+ font-weight: 700;
61
+ font-size: 13px;
62
+ transition: all 0.25s ease;
63
+ cursor: pointer;
64
+ }
65
+ .whatsapp-support:hover {
66
+ transform: translateY(-3px);
67
+ box-shadow: 0 12px 28px rgba(37, 211, 102, 0.55);
68
+ }
69
+ .whatsapp-support svg { width: 22px; height: 22px; flex-shrink: 0; }
70
+ .whatsapp-support .label { white-space: nowrap; }
71
+
72
+ @media (max-width: 768px) {
73
+ .whatsapp-support {
74
+ bottom: 84px;
75
+ left: 12px;
76
+ padding: 8px 12px 8px 10px;
77
+ font-size: 11.5px;
78
+ }
79
+ .whatsapp-support svg { width: 18px; height: 18px; }
80
+ }
81
+
82
+ @media print {
83
+ .whatsapp-support { display: none !important; }
84
+ }
85
+
86
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.03); width: 100%; max-width: 100%; overflow: hidden; }
87
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
88
.kpi-unit { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; display: flex; align-items: center; gap: 14px; }
@@ -105,47 +133,55 @@
133
.accordion-body { padding: 16px; border-top: 1px solid var(--border); display: none; background: #fff; }
134
.accordion-item.open .accordion-body { display: block; }
135
136
+ .about-dev-card {
137
+ background: linear-gradient(135deg, #eff6ff, #f8fafc);
138
+ border: 1.5px solid #bfdbfe;
139
+ border-radius: 12px;
140
+ padding: 16px 18px;
141
+ margin: 14px 0;
142
+ display: flex;
143
+ align-items: center;
144
+ gap: 14px;
145
+ flex-wrap: wrap;
146
+ }
147
+ .about-dev-avatar {
148
+ width: 52px; height: 52px;
149
+ background: linear-gradient(135deg, var(--primary), #1e40af);
150
+ color: #fff; border-radius: 50%;
151
+ display: flex; align-items: center; justify-content: center;
152
+ font-size: 20px; font-weight: bold;
153
+ flex-shrink: 0;
154
+ }
155
+ .about-dev-info { flex: 1; min-width: 180px; }
156
+ .about-dev-info h4 { font-size: 15px; color: #1e293b; margin-bottom: 4px; }
157
+ .about-dev-info p { font-size: 12.5px; color: #64748b; margin-bottom: 2px; }
158
+ .about-dev-actions { display: flex; gap: 8px; flex-wrap: wrap; }
159
+ .about-dev-actions a {
160
+ display: inline-flex; align-items: center; gap: 6px;
161
+ padding: 8px 14px; border-radius: 8px;
162
+ font-size: 12.5px; font-weight: 700;
163
+ text-decoration: none;
164
+ transition: all 0.2s;
165
+ }
166
+ .about-dev-actions .btn-wa {
167
+ background: linear-gradient(135deg, #25D366, #128C7E);
168
+ color: #fff;
169
+ }
170
+ .about-dev-actions .btn-wa:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(37,211,102,0.4); }
171
+ .about-dev-actions .btn-call {
172
+ background: var(--primary); color: #fff;
173
+ }
174
+ .about-dev-actions .btn-call:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(37,99,235,0.4); }
175
+
176
@media print {
109
- @page {
110
- size: A4 landscape;
111
- margin: 8mm 10mm;
112
- }
113
- html, body {
114
- background: #fff !important;
115
- color: #000 !important;
116
- margin: 0 !important;
117
- padding: 0 !important;
118
- width: 100% !important;
119
- }
120
- .sidebar, .mobile-dock, .no-print, #auth-screen, .modal-backdrop {
121
- display: none !important;
122
- }
177
+ @page { size: A4 landscape; margin: 8mm 10mm; }
178
+ html, body { background: #fff !important; color: #000 !important; margin: 0 !important; padding: 0 !important; width: 100% !important; }
179
+ .sidebar, .mobile-dock, .no-print, #auth-screen, .modal-backdrop, .whatsapp-support { display: none !important; }
180
.view-pane { display: none !important; }
124
- .main-surface {
125
- margin: 0 !important;
126
- padding: 0 !important;
127
- max-width: 100% !important;
128
- width: 100% !important;
129
- }
130
- .card {
131
- border: none !important;
132
- box-shadow: none !important;
133
- padding: 0 !important;
134
- margin: 0 !important;
135
- }
136
- .invoice-a4-page {
137
- width: 100% !important;
138
- max-width: 277mm !important;
139
- margin: 0 auto !important;
140
- padding: 0 !important;
141
- page-break-after: always !important;
142
- break-after: page !important;
143
- box-sizing: border-box !important;
144
- }
145
- .invoice-a4-page:last-child {
146
- page-break-after: avoid !important;
147
- break-after: avoid !important;
148
- }
181
+ .main-surface { margin: 0 !important; padding: 0 !important; max-width: 100% !important; width: 100% !important; }
182
+ .card { border: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; }
183
+ .invoice-a4-page { width: 100% !important; max-width: 277mm !important; margin: 0 auto !important; padding: 0 !important; page-break-after: always !important; break-after: page !important; box-sizing: border-box !important; }
184
+ .invoice-a4-page:last-child { page-break-after: avoid !important; break-after: avoid !important; }
185
#printable-invoice { display: block !important; }
186
}
187
@@ -161,7 +197,6 @@
197
</head>
198
<body>
199
164
- <!-- صفحه ورود و ثبتنام -->
200
<div id="auth-screen">
201
<div class="auth-card">
202
<div style="text-align:center; margin-bottom:20px;">
@@ -169,7 +204,6 @@
204
<h2 style="font-size:20px; font-weight:bold; color:var(--text);">سامانه ایزی فاکتور</h2>
205
<p style="font-size:12px; color:var(--text-muted); margin-top:4px;">ورود یا ثبتنام در سامانه</p>
206
</div>
172
-
207
<div id="auth-form-container">
208
<div class="form-group">
209
<label>نام کاربری یا شماره همراه</label>
@@ -193,7 +227,7 @@
227
<div class="brand-icon">ایزی</div>
228
<div>
229
<h2 style="font-size: 15px; font-weight: bold;">ایزی فاکتور</h2>
196
- <small style="color: var(--text-muted); font-size: 11px;">نسخه چندکاربره ۴.۸</small>
230
+ <small style="color: var(--text-muted); font-size: 11px;">نسخه چندکاربره ۵.۱</small>
231
</div>
232
</div>
233
<ul class="sidebar-menu">
@@ -212,9 +246,14 @@
246
</div>
247
</aside>
248
249
+ <!-- دکمه شناور پشتیبانی واتساپ -->
250
+ <a class="whatsapp-support no-print" href="https://wa.me/989124376991?text=سلام%20داود%20عزیز،%20درباره%20نرمافزار%20ایزی%20فاکتور%20سؤال%20داشتم." target="_blank" rel="noopener" title="پشتیبانی واتساپ: ۰۹۱۲۴۳۷۶۹۹۱">
251
+ <svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>
252
+ <span class="label">پشتیبانی واتساپ</span>
253
+ </a>
254
+
255
<main class="main-surface">
256
217
- <!-- ۱. داشبورد -->
257
<section id="view-dashboard" class="view-pane active">
258
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
259
<div>
@@ -226,37 +265,24 @@
265
<button class="btn btn-inline no-print" onclick="startNewInvoice()">➕ فاکتور جدید</button>
266
</div>
267
</div>
229
-
268
<div id="dashboard-license-details"></div>
269
270
<div class="grid-kpi">
271
<div class="kpi-unit">
272
<div class="kpi-icon" style="background:#eff6ff; color:var(--primary);">💰</div>
235
- <div>
236
- <div class="kpi-lbl">مجموع فروش ثبتشده (<span class="cur-label">ریال</span>)</div>
237
- <div class="kpi-val" id="kpi-sales-sum">۰ ریال</div>
238
- </div>
273
+ <div><div class="kpi-lbl">مجموع فروش ثبتشده (<span class="cur-label">ریال</span>)</div><div class="kpi-val" id="kpi-sales-sum">۰ ریال</div></div>
274
</div>
275
<div class="kpi-unit">
276
<div class="kpi-icon" style="background:#ecfdf5; color:var(--success);">📥</div>
242
- <div>
243
- <div class="kpi-lbl">دریافت وصول شده</div>
244
- <div class="kpi-val" id="kpi-settled-sum">۰ ریال</div>
245
- </div>
277
+ <div><div class="kpi-lbl">دریافت وصول شده</div><div class="kpi-val" id="kpi-settled-sum">۰ ریال</div></div>
278
</div>
279
<div class="kpi-unit">
280
<div class="kpi-icon" style="background:#fffbeb; color:var(--warning);">⏳</div>
249
- <div>
250
- <div class="kpi-lbl">مانده مطالبات نسیه</div>
251
- <div class="kpi-val" id="kpi-debtors-sum">۰ ریال</div>
252
- </div>
281
+ <div><div class="kpi-lbl">مانده مطالبات نسیه</div><div class="kpi-val" id="kpi-debtors-sum">۰ ریال</div></div>
282
</div>
283
<div class="kpi-unit">
284
<div class="kpi-icon" style="background:#fef2f2; color:var(--danger);">💳</div>
256
- <div>
257
- <div class="kpi-lbl">چکهای باز صیادی</div>
258
- <div class="kpi-val" id="kpi-cheques-count">۰ فقره</div>
259
- </div>
285
+ <div><div class="kpi-lbl">چکهای باز صیادی</div><div class="kpi-val" id="kpi-cheques-count">۰ فقره</div></div>
286
</div>
287
</div>
288
@@ -265,15 +291,7 @@
291
<div class="table-responsive">
292
<table>
293
<thead>
268
- <tr>
269
- <th>شماره</th>
270
- <th>فروشنده (شرکت)</th>
271
- <th>خریدار</th>
272
- <th>نوع فاکتور</th>
273
- <th>ارزش افزوده</th>
274
- <th>مبلغ کل (<span class="cur-label">ریال</span>)</th>
275
- <th>عملیات</th>
276
- </tr>
294
+ <tr><th>شماره</th><th>فروشنده (شرکت)</th><th>خریدار</th><th>نوع فاکتور</th><th>ارزش افزوده</th><th>مبلغ کل (<span class="cur-label">ریال</span>)</th><th>عملیات</th></tr>
295
</thead>
296
<tbody id="dashboard-recent-table">
297
<tr><td colspan="7" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ فاکتوری صادر نشده است.</td></tr>
@@ -281,27 +299,37 @@
299
</table>
300
</div>
301
</div>
302
+
303
+ <!-- کارت پشتیبانی سریع در انتهای داشبورد -->
304
+ <div class="card no-print" style="background: linear-gradient(135deg, #ecfdf5, #f0fdf4); border-color:#bbf7d0;">
305
+ <div style="display:flex; align-items:center; gap:12px; flex-wrap:wrap; justify-content:space-between;">
306
+ <div style="display:flex; align-items:center; gap:12px;">
307
+ <div style="width:44px; height:44px; border-radius:50%; background:linear-gradient(135deg,#25D366,#128C7E); display:flex; align-items:center; justify-content:center; color:#fff;">
308
+ <svg viewBox="0 0 24 24" fill="currentColor" width="22" height="22"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>
309
+ </div>
310
+ <div>
311
+ <h3 style="font-size:15px; color:#166534;">پشتیبانی سریع</h3>
312
+ <p style="font-size:12.5px; color:#475569; margin-top:2px;">سؤالی دارید؟ از طریق واتساپ با ما در تماس باشید.</p>
313
+ </div>
314
+ </div>
315
+ <a href="https://wa.me/989124376991?text=سلام%20داود%20عزیز،%20درباره%20نرمافزار%20ایزی%20فاکتور%20سؤال%20داشتم." target="_blank" rel="noopener" class="btn btn-inline" style="background:linear-gradient(135deg,#25D366,#128C7E); text-decoration:none;">
316
+ 💬 گفتگو در واتساپ
317
+ </a>
318
+ </div>
319
+ </div>
320
</section>
321
286
- <!-- ۲. صدور فاکتور -->
322
<section id="view-invoices" class="view-pane">
323
<div class="card no-print">
324
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px;">
325
<h2 style="font-size: 17px;" id="invoice-form-title">صدور فاکتور جدید</h2>
326
<button class="btn btn-secondary btn-inline" style="display:none; padding:4px 10px; font-size:12px;" id="btn-cancel-edit" onclick="cancelInvoiceEdit()">انصراف از ویرایش</button>
327
</div>
293
-
328
<input type="hidden" id="edit-invoice-id" value="" />
329
330
<div class="form-row" style="background:#f1f5f9; padding:12px; border-radius:10px; margin-bottom:14px;">
297
- <div class="form-group" style="margin-bottom:0;">
298
- <label>تاریخ فاکتور</label>
299
- <input type="text" id="invoice-date-input" class="form-control" />
300
- </div>
301
- <div class="form-group" style="margin-bottom:0;">
302
- <label>شماره فاکتور</label>
303
- <input type="text" id="invoice-number" class="form-control" placeholder="PINV-31" />
304
- </div>
331
+ <div class="form-group" style="margin-bottom:0;"><label>تاریخ فاکتور</label><input type="text" id="invoice-date-input" class="form-control" /></div>
332
+ <div class="form-group" style="margin-bottom:0;"><label>شماره فاکتور</label><input type="text" id="invoice-number" class="form-control" placeholder="PINV-31" /></div>
333
<div class="form-group" style="margin-bottom:0;">
334
<label>قالب و نوع سند</label>
335
<select id="invoice-kind" class="form-control" onchange="handleInvoiceKindChange()">
@@ -313,10 +341,7 @@
341
</div>
342
343
<div class="form-row">
316
- <div class="form-group">
317
- <label>فروشنده (سربرگ شرکت)</label>
318
- <select id="invoice-company-id" class="form-control" onchange="onActiveCompanyFilterChange()"></select>
319
- </div>
344
+ <div class="form-group"><label>فروشنده (سربرگ شرکت)</label><select id="invoice-company-id" class="form-control" onchange="onActiveCompanyFilterChange()"></select></div>
345
<div class="form-group">
346
<label style="display:flex; justify-content:space-between;">
347
<span>نام خریدار را وارد یا انتخاب کنید</span>
@@ -385,14 +410,8 @@
410
411
<div class="form-group" style="background:#fff; padding:12px; border-radius:8px; border:1px solid var(--border); margin-bottom:0;">
412
<label style="font-weight:bold; border-bottom:1px solid #eee; padding-bottom:6px; margin-bottom:8px;">جمعبندی نهایی</label>
388
- <div style="display:flex; justify-content:space-between; margin-bottom:6px; font-size:13px;">
389
- <span>جمع کل:</span>
390
- <span id="summary-subtotal" style="font-weight:bold;">۰ ریال</span>
391
- </div>
392
- <div style="display:flex; justify-content:space-between; margin-bottom:6px; font-size:13px;">
393
- <span>مالیات:</span>
394
- <span id="summary-vat" style="font-weight:bold;">۰ ریال</span>
395
- </div>
413
+ <div style="display:flex; justify-content:space-between; margin-bottom:6px; font-size:13px;"><span>جمع کل:</span><span id="summary-subtotal" style="font-weight:bold;">۰ ریال</span></div>
414
+ <div style="display:flex; justify-content:space-between; margin-bottom:6px; font-size:13px;"><span>مالیات:</span><span id="summary-vat" style="font-weight:bold;">۰ ریال</span></div>
415
<div style="display:flex; justify-content:space-between; margin-bottom:6px; font-size:14px; border-top:1px solid #eee; padding-top:6px;">
416
<span style="font-weight:bold; color:var(--primary);">قابل پرداخت:</span>
417
<span id="summary-grandtotal" style="font-weight:bold; color:var(--primary);">۰ ریال</span>
@@ -421,15 +440,7 @@
440
<div class="table-responsive">
441
<table>
442
<thead>
424
- <tr>
425
- <th>شماره</th>
426
- <th>فروشنده</th>
427
- <th>خریدار</th>
428
- <th>نوع</th>
429
- <th>تاریخ</th>
430
- <th>قابل پرداخت (<span class="cur-label">ریال</span>)</th>
431
- <th>عملیات</th>
432
- </tr>
443
+ <tr><th>شماره</th><th>فروشنده</th><th>خریدار</th><th>نوع</th><th>تاریخ</th><th>قابل پرداخت (<span class="cur-label">ریال</span>)</th><th>عملیات</th></tr>
444
</thead>
445
<tbody id="invoice-archive-table-body"></tbody>
446
</table>
@@ -437,7 +448,6 @@
448
</div>
449
</section>
450
440
- <!-- ۳. کالاها و خدمات -->
451
<section id="view-products" class="view-pane">
452
<div class="card no-print">
453
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; flex-wrap:wrap; gap:10px;">
@@ -462,28 +472,17 @@
472
</div>
473
<button class="btn btn-success" onclick="commitSaveProduct()">➕ ثبت کالا</button>
474
</div>
465
-
475
<div class="card">
476
<h3 style="font-size: 15px; margin-bottom: 12px;">کالاهای ثبتشده</h3>
477
<div class="table-responsive">
478
<table>
470
- <thead>
471
- <tr>
472
- <th>کد</th>
473
- <th>نام کالا</th>
474
- <th>مشخصه</th>
475
- <th>واحد</th>
476
- <th>قیمت فروش (<span class="cur-label">ریال</span>)</th>
477
- <th>عملیات</th>
478
- </tr>
479
- </thead>
479
+ <thead><tr><th>کد</th><th>نام کالا</th><th>مشخصه</th><th>واحد</th><th>قیمت فروش (<span class="cur-label">ریال</span>)</th><th>عملیات</th></tr></thead>
480
<tbody id="products-catalog-table-body"></tbody>
481
</table>
482
</div>
483
</div>
484
</section>
485
486
- <!-- ۴. اشخاص -->
486
<section id="view-contacts" class="view-pane">
487
<div class="card no-print">
488
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; flex-wrap:wrap; gap:10px;">
@@ -529,30 +528,17 @@
528
</div>
529
<button class="btn btn-success" onclick="commitSaveContact()">➕ ثبت طرف حساب</button>
530
</div>
532
-
531
<div class="card">
532
<h3 style="font-size: 15px; margin-bottom: 12px;">دفتر اشخاص</h3>
533
<div class="table-responsive">
534
<table>
537
- <thead>
538
- <tr>
539
- <th>نام</th>
540
- <th>نوع</th>
541
- <th>شناسه / کد ملی</th>
542
- <th>کد اقتصادی</th>
543
- <th>کد پستی</th>
544
- <th>همراه</th>
545
- <th>مانده (<span class="cur-label">ریال</span>)</th>
546
- <th>عملیات</th>
547
- </tr>
548
- </thead>
535
+ <thead><tr><th>نام</th><th>نوع</th><th>شناسه / کد ملی</th><th>کد اقتصادی</th><th>کد پستی</th><th>همراه</th><th>مانده (<span class="cur-label">ریال</span>)</th><th>عملیات</th></tr></thead>
536
<tbody id="contacts-ledger-table-body"></tbody>
537
</table>
538
</div>
539
</div>
540
</section>
541
555
- <!-- ۵. چکها -->
542
<section id="view-cheques" class="view-pane">
543
<div class="card">
544
<h2 style="font-size: 17px; margin-bottom: 14px;">ثبت چک صیادی</h2>
@@ -580,7 +566,6 @@
566
</div>
567
</section>
568
583
- <!-- ۶. هزینهها -->
569
<section id="view-expenses" class="view-pane">
570
<div class="card">
571
<h2 style="font-size: 17px; margin-bottom: 14px;">ثبت هزینه / درآمد</h2>
@@ -603,19 +588,14 @@
588
</div>
589
</section>
590
606
- <!-- ۷. تنظیمات و شرکتها -->
591
<section id="view-settings" class="view-pane">
608
-
592
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px;">
593
<h2 style="font-size:17px;">⚙️ تنظیمات و شرکتها</h2>
594
<button class="btn btn-danger btn-inline no-print" style="padding:6px 12px; font-size:12px; min-height:32px;" onclick="handleLogout()">🚪 خروج از حساب کاربری</button>
595
</div>
596
597
<div class="accordion-item open">
615
- <div class="accordion-header" onclick="toggleAccordion(this)">
616
- <span>🏢 اطلاعات فروشگاه و چاپ (مدیریت شرکتها)</span>
617
- <span>▼</span>
618
- </div>
598
+ <div class="accordion-header" onclick="toggleAccordion(this)"><span>🏢 اطلاعات فروشگاه و چاپ (مدیریت شرکتها)</span><span>▼</span></div>
599
<div class="accordion-body">
600
<div class="form-row">
601
<div class="form-group"><label>نوع شخص</label><select id="company-entity-type" class="form-control"><option value="legal">حقوقی</option><option value="natural">حقیقی</option></select></div>
@@ -631,7 +611,6 @@
611
<div class="form-group"><label>نشانی کامل</label><input type="text" id="company-address-input" class="form-control" /></div>
612
<div class="form-group"><label>پاورقی فاکتور</label><textarea id="company-footer-input" class="form-control" rows="2"></textarea></div>
613
<button class="btn btn-success" onclick="commitSaveCompany()">➕ ثبت شرکت جدید</button>
634
-
614
<div style="margin-top:16px;">
615
<h4 style="font-size:14px; margin-bottom:8px;">لیست شرکتهای ثبتشده</h4>
616
<div class="table-responsive">
@@ -645,10 +624,7 @@
624
</div>
625
626
<div class="accordion-item">
648
- <div class="accordion-header" onclick="toggleAccordion(this)">
649
- <span>⚙️ مالیات، تخفیف و واحد پول (پیشفرض فاکتور جدید)</span>
650
- <span>▼</span>
651
- </div>
627
+ <div class="accordion-header" onclick="toggleAccordion(this)"><span>⚙️ مالیات، تخفیف و واحد پول (پیشفرض فاکتور جدید)</span><span>▼</span></div>
628
<div class="accordion-body">
629
<div class="form-row">
630
<div class="form-group">
@@ -690,14 +666,9 @@
666
</div>
667
668
<div class="accordion-item">
693
- <div class="accordion-header" onclick="toggleAccordion(this)">
694
- <span>💾 دیتابیس و پشتیبانگیری</span>
695
- <span>▼</span>
696
- </div>
669
+ <div class="accordion-header" onclick="toggleAccordion(this)"><span>💾 دیتابیس و پشتیبانگیری</span><span>▼</span></div>
670
<div class="accordion-body">
698
- <p style="font-size:13px; color:var(--text-muted); margin-bottom:12px;">
699
- وضعیت دیتابیس: <span class="badge badge-success">تفکیک کاربر فعال</span>
700
- </p>
671
+ <p style="font-size:13px; color:var(--text-muted); margin-bottom:12px;">وضعیت دیتابیس: <span class="badge badge-success">تفکیک کاربر فعال</span></p>
672
<div style="display:flex; gap:10px; flex-wrap:wrap;">
673
<button class="btn btn-secondary" onclick="exportDataBlob()">📥 دانلود فایل پشتیبان (JSON)</button>
674
<label class="btn btn-secondary" style="margin-bottom:0;">📤 بازگردانی فایل<input type="file" id="import-json-file" style="display:none;" onchange="importDataBlob(event)" accept=".json" /></label>
@@ -706,32 +677,45 @@
677
</div>
678
679
<div class="accordion-item">
709
- <div class="accordion-header" onclick="toggleAccordion(this)">
710
- <span>ℹ️ درباره نرمافزار</span>
711
- <span>▼</span>
712
- </div>
680
+ <div class="accordion-header" onclick="toggleAccordion(this)"><span>ℹ️ درباره نرمافزار</span><span>▼</span></div>
681
<div class="accordion-body">
682
<h3 style="font-size:16px; font-weight:bold;">ایزی فاکتور - EasyFactor</h3>
683
<p style="color:var(--text-muted); font-size:13px; margin:6px 0 12px 0;">سامانه ابری صدور فاکتور و مدیریت مالی چندکاربره</p>
716
- <p style="font-size:13px; margin-bottom:14px;">نگارش فعال: <strong>نسخه ۴.۸ (Landscape + Currency + Entity-aware)</strong></p>
717
- <div style="display:flex; gap:10px;">
684
+ <p style="font-size:13px; margin-bottom:14px;">نگارش فعال: <strong>نسخه ۵.۱</strong></p>
685
+
686
+ <!-- کارت توسعهدهنده -->
687
+ <div class="about-dev-card">
688
+ <div class="about-dev-avatar">د.م</div>
689
+ <div class="about-dev-info">
690
+ <h4>داود مهربان</h4>
691
+ <p>طراح و توسعهدهنده نرمافزار</p>
692
+ <p>📱 <span dir="ltr" style="font-family:Tahoma;">0912-437-6991</span></p>
693
+ </div>
694
+ <div class="about-dev-actions">
695
+ <a class="btn-wa" href="https://wa.me/989124376991?text=سلام%20داود%20عزیز،%20درباره%20نرمافزار%20ایزی%20فاکتور%20سؤال%20داشتم." target="_blank" rel="noopener">
696
+ <svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>
697
+ واتساپ
698
+ </a>
699
+ <a class="btn-call" href="tel:+989124376991">
700
+ 📞 تماس
701
+ </a>
702
+ </div>
703
+ </div>
704
+
705
+ <div style="display:flex; gap:10px; margin-top:10px;">
706
<button class="btn btn-primary" onclick="alert('آخرین نگارش نصب است.')">بررسی آپدیت</button>
707
<button class="btn btn-secondary" onclick="alert('پشتیبانی فعال است.')">گزارش باگ</button>
708
</div>
709
</div>
710
</div>
723
-
711
</section>
712
726
- <!-- بخش ادمین -->
713
<section id="view-admin" class="view-pane">
714
<div class="card">
715
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; flex-wrap:wrap; gap:10px;">
716
<div>
717
<h2 style="font-size: 18px; color:var(--danger);">👑 پنل مدیریت مرکزی کاربران و لایسنسها</h2>
732
- <p style="color:var(--text-muted); font-size:13px; margin-top:4px;">
733
- تعریف کاربران، تخصیص طرحهای لایسنس، تمدید، تغییر مدت و لغو اشتراک.
734
- </p>
718
+ <p style="color:var(--text-muted); font-size:13px; margin-top:4px;">تعریف کاربران، تخصیص طرحهای لایسنس، تمدید، تغییر مدت و لغو اشتراک.</p>
719
</div>
720
<button class="btn btn-primary btn-inline" onclick="refreshAdminPanel()">🔄 تازهسازی لیست</button>
721
</div>
@@ -739,14 +723,8 @@
723
<div style="background:#f8fafc; border:1px solid var(--border); border-radius:10px; padding:16px; margin-bottom:20px;">
724
<h4 style="font-size:14px; margin-bottom:12px; color:#1e293b;">➕ ایجاد حساب کاربری جدید</h4>
725
<div class="form-row">
742
- <div class="form-group">
743
- <label>نام کاربری</label>
744
- <input type="text" id="admin-new-username" class="form-control" placeholder="نام کاربری..." />
745
- </div>
746
- <div class="form-group">
747
- <label>رمز عبور</label>
748
- <input type="password" id="admin-new-password" class="form-control" placeholder="رمز عبور..." />
749
- </div>
726
+ <div class="form-group"><label>نام کاربری</label><input type="text" id="admin-new-username" class="form-control" placeholder="نام کاربری..." /></div>
727
+ <div class="form-group"><label>رمز عبور</label><input type="password" id="admin-new-password" class="form-control" placeholder="رمز عبور..." /></div>
728
<div class="form-group">
729
<label>طرح اولیه لایسنس</label>
730
<select id="admin-new-subtype" class="form-control">
@@ -765,17 +743,7 @@
743
744
<div class="table-responsive">
745
<table>
768
- <thead>
769
- <tr>
770
- <th>نام کاربری</th>
771
- <th>وضعیت حساب</th>
772
- <th>نوع اشتراک</th>
773
- <th>تاریخ شروع</th>
774
- <th>تاریخ پایان</th>
775
- <th>روزهای باقیمانده</th>
776
- <th>عملیات مدیریت لایسنس</th>
777
- </tr>
778
- </thead>
746
+ <thead><tr><th>نام کاربری</th><th>وضعیت حساب</th><th>نوع اشتراک</th><th>تاریخ شروع</th><th>تاریخ پایان</th><th>روزهای باقیمانده</th><th>عملیات مدیریت لایسنس</th></tr></thead>
747
<tbody id="admin-users-table-body">
748
<tr><td colspan="7" style="text-align:center; padding:20px;">در حال بارگذاری کاربران...</td></tr>
749
</tbody>
@@ -785,11 +753,9 @@
753
</section>
754
755
<div id="printable-invoice" style="display:none;"></div>
788
-
756
</main>
757
</div>
758
792
- <!-- مودال شخص جدید -->
759
<div class="modal-backdrop" id="modal-quick-contact">
760
<div class="modal-card">
761
<h3 style="font-size:16px; margin-bottom:12px;">➕ تعریف سریع خریدار</h3>
@@ -815,7 +781,6 @@
781
</div>
782
</div>
783
818
- <!-- مودال کالای جدید -->
784
<div class="modal-backdrop" id="modal-quick-product">
785
<div class="modal-card">
786
<h3 style="font-size:16px; margin-bottom:12px;">➕ تعریف سریع کالا</h3>
@@ -835,7 +800,6 @@
800
</div>
801
</div>
802
838
- <!-- مودال تغییر مدت و لایسنس -->
803
<div class="modal-backdrop" id="modal-admin-license-edit">
804
<div class="modal-card">
805
<h3 style="font-size:16px; margin-bottom:12px;" id="modal-license-user-title">تغییر مدت و لایسنس کاربر</h3>
@@ -856,39 +820,19 @@
820
</div>
821
</div>
822
859
- <!-- ناو بار موبایل -->
823
<nav class="mobile-dock">
861
- <div class="dock-tab active" onclick="switchView('view-dashboard')">
862
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path></svg>
863
- <span>داشبورد</span>
864
- </div>
865
- <div class="dock-tab" onclick="switchView('view-invoices')">
866
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
867
- <span>فاکتورها</span>
868
- </div>
869
- <div class="dock-tab" onclick="switchView('view-products')">
870
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
871
- <span>کالاها</span>
872
- </div>
873
- <div class="dock-tab" onclick="switchView('view-contacts')">
874
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>
875
- <span>اشخاص</span>
876
- </div>
877
- <div class="dock-tab" onclick="switchView('view-cheques')">
878
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"></path></svg>
879
- <span>چکها</span>
880
- </div>
881
- <div class="dock-tab" onclick="switchView('view-settings')">
882
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
883
- <span>تنظیمات</span>
884
- </div>
824
+ <div class="dock-tab active" onclick="switchView('view-dashboard')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path></svg><span>داشبورد</span></div>
825
+ <div class="dock-tab" onclick="switchView('view-invoices')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg><span>فاکتورها</span></div>
826
+ <div class="dock-tab" onclick="switchView('view-products')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg><span>کالاها</span></div>
827
+ <div class="dock-tab" onclick="switchView('view-contacts')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg><span>اشخاص</span></div>
828
+ <div class="dock-tab" onclick="switchView('view-cheques')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"></path></svg><span>چکها</span></div>
829
+ <div class="dock-tab" onclick="switchView('view-settings')"><svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path></svg><span>تنظیمات</span></div>
830
</nav>
831
832
<script>
833
const STORAGE_KEY = 'easy_factor_commercial_v4_7';
834
const AUTH_KEY = 'easy_factor_auth_users_v4_7';
835
891
- /* ---------- توابع تاریخ و اعداد ---------- */
836
function toPersianDigits(str) {
837
if (str === null || str === undefined) return '';
838
return String(str).replace(/[0-9]/g, d => '۰۱۲۳۴۵۶۷۸۹'[d]);
@@ -897,23 +841,16 @@
841
function formatToJalali(dateInput) {
842
if (!dateInput) return '—';
843
let dateObj;
900
- if (dateInput instanceof Date) {
901
- dateObj = dateInput;
902
- } else if (typeof dateInput === 'string' && dateInput.includes('/')) {
903
- return toPersianDigits(dateInput);
904
- } else {
844
+ if (dateInput instanceof Date) dateObj = dateInput;
845
+ else if (typeof dateInput === 'string' && dateInput.includes('/')) return toPersianDigits(dateInput);
846
+ else {
847
const str = String(dateInput).split('T')[0];
848
const parts = str.split('-');
907
- if (parts.length === 3) {
908
- dateObj = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 12, 0, 0);
909
- } else {
910
- dateObj = new Date(dateInput);
911
- }
849
+ if (parts.length === 3) dateObj = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 12, 0, 0);
850
+ else dateObj = new Date(dateInput);
851
}
852
if (isNaN(dateObj.getTime())) return toPersianDigits(String(dateInput));
914
- return new Intl.DateTimeFormat('fa-IR-u-ca-persian', {
915
- year: 'numeric', month: '2-digit', day: '2-digit'
916
- }).format(dateObj);
853
+ return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(dateObj);
854
}
855
856
function getRemainingDays(endDateStr) {
@@ -924,8 +861,7 @@
861
if (parts.length !== 3) return 0;
862
const end = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 23, 59, 59);
863
const now = new Date();
927
- const diff = end.getTime() - now.getTime();
928
- return Math.ceil(diff / (1000 * 60 * 60 * 24));
864
+ return Math.ceil((end.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
865
}
866
867
function addDaysToDate(baseDateStr, days) {
@@ -933,15 +869,12 @@
869
if (baseDateStr) {
870
const parts = String(baseDateStr).split('T')[0].split('-');
871
d = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 12, 0, 0);
936
- } else {
937
- d = new Date();
938
- }
872
+ } else d = new Date();
873
if (isNaN(d.getTime())) d = new Date();
874
d.setDate(d.getDate() + days);
875
return d.toISOString().split('T')[0];
876
}
877
944
- /* ---------- کاربران و احراز هویت ---------- */
878
let currentUser = null;
879
let usersDb = [];
880
@@ -955,12 +888,9 @@
888
889
function loadUsers() {
890
const saved = localStorage.getItem(AUTH_KEY);
958
- if (saved) {
959
- try { usersDb = JSON.parse(saved); } catch (e) { usersDb = []; }
960
- }
891
+ if (saved) { try { usersDb = JSON.parse(saved); } catch (e) { usersDb = []; } }
892
if (!Array.isArray(usersDb) || usersDb.length === 0) {
962
- usersDb = [defaultAdminUser];
963
- persistUsers();
893
+ usersDb = [defaultAdminUser]; persistUsers();
894
} else {
895
let modified = false;
896
usersDb.forEach((u, idx) => {
@@ -1043,7 +973,6 @@
973
window.location.reload();
974
}
975
1046
- /* ---------- لایسنس ---------- */
976
function updateLicenseDisplay(user) {
977
if (!user) return;
978
const badge = document.getElementById('user-license-status-badge');
@@ -1066,7 +995,6 @@
995
}
996
}
997
1069
- /* ---------- پنل ادمین ---------- */
998
function adminCreateNewUser() {
999
const username = document.getElementById('admin-new-username').value.trim();
1000
const pass = document.getElementById('admin-new-password').value.trim();
@@ -1087,8 +1015,7 @@
1015
subscriptionType: plan, subscriptionStart: today, subscriptionEnd: endDate, licenseStatus: status,
1016
subscription: { type: plan, startDate: today, endDate: endDate, status: status }
1017
};
1090
- usersDb.push(newUser);
1091
- persistUsers();
1018
+ usersDb.push(newUser); persistUsers();
1019
alert(`کاربر جدید "${username}" با موفقیت ایجاد شد.`);
1020
document.getElementById('admin-new-username').value = '';
1021
document.getElementById('admin-new-password').value = '';
@@ -1133,9 +1060,7 @@
1060
}
1061
1062
function adminActivateLicense(username) {
1136
- loadUsers();
1137
- const u = usersDb.find(x => x.username === username);
1138
- if (!u) return;
1063
+ loadUsers(); const u = usersDb.find(x => x.username === username); if (!u) return;
1064
const today = new Date().toISOString().split('T')[0];
1065
const endDate = addDaysToDate(today, 30);
1066
u.subscription = { type: 'monthly', startDate: today, endDate: endDate, status: 'active' };
@@ -1147,9 +1072,7 @@
1072
}
1073
1074
function openLicenseEditModal(username) {
1150
- loadUsers();
1151
- const u = usersDb.find(x => x.username === username);
1152
- if (!u) return;
1075
+ loadUsers(); const u = usersDb.find(x => x.username === username); if (!u) return;
1076
document.getElementById('modal-license-target-username').value = username;
1077
document.getElementById('modal-license-user-title').innerText = `تغییر مدت و نوع لایسنس: ${username}`;
1078
document.getElementById('modal-license-duration-select').value = u.subscription?.type || 'monthly';
@@ -1160,9 +1083,7 @@
1083
function applyLicenseDurationChange() {
1084
const username = document.getElementById('modal-license-target-username').value;
1085
const plan = document.getElementById('modal-license-duration-select').value;
1163
- loadUsers();
1164
- const u = usersDb.find(x => x.username === username);
1165
- if (!u) return;
1086
+ loadUsers(); const u = usersDb.find(x => x.username === username); if (!u) return;
1087
const today = new Date().toISOString().split('T')[0];
1088
let endDate = today;
1089
if (plan === 'monthly') endDate = addDaysToDate(today, 30);
@@ -1179,9 +1100,7 @@
1100
}
1101
1102
function adminExtendSubscription(username, days) {
1182
- loadUsers();
1183
- const u = usersDb.find(x => x.username === username);
1184
- if (!u) return;
1103
+ loadUsers(); const u = usersDb.find(x => x.username === username); if (!u) return;
1104
let currentEnd = u.subscription?.endDate || new Date().toISOString().split('T')[0];
1105
if (currentEnd.startsWith('2099')) { alert('این حساب دائمی است و نیازی به تمدید ندارد.'); return; }
1106
const today = new Date().toISOString().split('T')[0];
@@ -1200,19 +1119,15 @@
1119
1120
function adminCancelSubscription(username) {
1121
if (!confirm(`آیا از لغو اشتراک کاربر ${username} اطمینان دارید؟`)) return;
1203
- loadUsers();
1204
- const u = usersDb.find(x => x.username === username);
1205
- if (!u) return;
1122
+ loadUsers(); const u = usersDb.find(x => x.username === username); if (!u) return;
1123
if (!u.subscription) u.subscription = {};
1207
- u.subscription.status = 'cancelled';
1208
- u.licenseStatus = 'cancelled';
1124
+ u.subscription.status = 'cancelled'; u.licenseStatus = 'cancelled';
1125
persistUsers();
1126
if (currentUser && currentUser.username === username) { currentUser = u; updateLicenseDisplay(currentUser); }
1127
alert(`اشتراک کاربر ${username} لغو گردید.`);
1128
renderAdminPanel();
1129
}
1130
1215
- /* ---------- Datastore ---------- */
1131
let datastore = { companies: [], contacts: [], products: [], invoices: [], cheques: [], expenses: [], settings: [] };
1132
1133
function getMyProducts() { return !currentUser ? [] : datastore.products.filter(p => p.ownerUserId === currentUser.id); }
@@ -1283,14 +1198,9 @@
1198
1199
function initDatastore() { loadDatastore(); refreshAllSurfaces(); }
1200
1286
- function getJalaliDate() {
1287
- return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { dateStyle: 'full' }).format(new Date());
1288
- }
1289
- function getJalaliNumeric() {
1290
- return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date());
1291
- }
1201
+ function getJalaliDate() { return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { dateStyle: 'full' }).format(new Date()); }
1202
+ function getJalaliNumeric() { return new Intl.DateTimeFormat('fa-IR-u-ca-persian', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); }
1203
1293
- /* ---------- واحد پول ---------- */
1204
function getCurrencyLabel() {
1205
const s = getMySettings();
1206
if (s.currency_mode === 'toman') return 'تومان';
@@ -1327,13 +1237,8 @@
1237
const invDate = document.getElementById('invoice-date-input');
1238
if (invDate && !invDate.value) invDate.value = getJalaliNumeric();
1239
updateLicenseDisplay(currentUser);
1330
- renderCompanies();
1331
- renderContacts();
1332
- renderProducts();
1333
- renderInvoices();
1334
- renderDashboard();
1335
- renderCheques();
1336
- renderExpenses();
1240
+ renderCompanies(); renderContacts(); renderProducts(); renderInvoices();
1241
+ renderDashboard(); renderCheques(); renderExpenses();
1242
applyDefaultSettingsToForm();
1243
handleContactEntityChange();
1244
handleCurrencyModeChange();
@@ -1341,20 +1246,16 @@
1246
if (currentUser && currentUser.role === 'admin') renderAdminPanel();
1247
}
1248
1344
- /* ---------- نام و پیشوند شخص ---------- */
1249
function formatEntityName(rawName, entityType, customPrefix = '') {
1250
let trimmed = (rawName || '').trim();
1251
if (entityType === 'legal') {
1348
- if (!trimmed.startsWith('شرکت') && !trimmed.startsWith('موسسه') && !trimmed.startsWith('سازمان') && !trimmed.startsWith('اداره')) {
1349
- trimmed = 'شرکت ' + trimmed;
1350
- }
1252
+ if (!trimmed.startsWith('شرکت') && !trimmed.startsWith('موسسه') && !trimmed.startsWith('سازمان') && !trimmed.startsWith('اداره')) trimmed = 'شرکت ' + trimmed;
1253
} else if (entityType === 'natural' && customPrefix) {
1254
if (!trimmed.startsWith(customPrefix)) trimmed = customPrefix + ' ' + trimmed;
1255
}
1256
return trimmed;
1257
}
1258
1357
- /* ---------- رفتار فرم طرفحساب بر اساس نوع شخص ---------- */
1259
function applyEntityTypeToForm(entity, opts) {
1260
const { prefixId, nameId, econId, regId, nationalLabelId } = opts;
1261
const prefixBox = document.getElementById(prefixId);
@@ -1362,7 +1263,6 @@
1263
const econBox = document.getElementById(econId);
1264
const regBox = document.getElementById(regId);
1265
const natLabel = document.getElementById(nationalLabelId);
1365
-
1266
if (entity === 'legal') {
1267
if (prefixBox) prefixBox.style.display = 'none';
1268
if (nameBox) nameBox.style.gridColumn = 'span 3';
@@ -1379,32 +1279,18 @@
1279
}
1280
1281
function handleContactEntityChange() {
1382
- const entitySelect = document.getElementById('contact-entity-type');
1383
- if (!entitySelect) return;
1384
- applyEntityTypeToForm(entitySelect.value, {
1385
- prefixId: 'box-contact-prefix', nameId: 'box-contact-name',
1386
- econId: 'box-contact-economic', regId: 'box-contact-reg',
1387
- nationalLabelId: 'label-contact-national'
1388
- });
1282
+ const el = document.getElementById('contact-entity-type'); if (!el) return;
1283
+ applyEntityTypeToForm(el.value, { prefixId: 'box-contact-prefix', nameId: 'box-contact-name', econId: 'box-contact-economic', regId: 'box-contact-reg', nationalLabelId: 'label-contact-national' });
1284
}
1390
-
1285
function handleQuickCEntityChange() {
1392
- const entitySelect = document.getElementById('quick-c-entity');
1393
- if (!entitySelect) return;
1394
- applyEntityTypeToForm(entitySelect.value, {
1395
- prefixId: 'box-quick-c-prefix', nameId: 'box-quick-c-name',
1396
- econId: 'box-quick-c-economic', regId: 'box-quick-c-reg',
1397
- nationalLabelId: 'label-quick-c-national'
1398
- });
1286
+ const el = document.getElementById('quick-c-entity'); if (!el) return;
1287
+ applyEntityTypeToForm(el.value, { prefixId: 'box-quick-c-prefix', nameId: 'box-quick-c-name', econId: 'box-quick-c-economic', regId: 'box-quick-c-reg', nationalLabelId: 'label-quick-c-national' });
1288
}
1289
1401
- /* ---------- رفتار فرم فاکتور: قالب سند ---------- */
1290
function handleInvoiceKindChange() {
1291
const kind = document.getElementById('invoice-kind').value;
1292
const vatModeRow = document.getElementById('box-invoice-vat-mode-row');
1293
const vatModeSelect = document.getElementById('invoice-vat-mode');
1406
-
1407
- // فاکتور غیررسمی: مالیات ارزش افزوده به هیچ عنوان قابل فعالسازی نیست.
1294
if (kind === 'non_formal') {
1295
if (vatModeRow) vatModeRow.style.display = 'none';
1296
if (vatModeSelect) vatModeSelect.value = 'none';
@@ -1419,19 +1305,14 @@
1305
const mode = document.getElementById('invoice-vat-mode').value;
1306
const kind = document.getElementById('invoice-kind').value;
1307
const rateBox = document.getElementById('box-invoice-vat-rate');
1422
- if (kind === 'non_formal') {
1423
- rateBox.style.display = 'none';
1424
- document.getElementById('invoice-vat-mode').value = 'none';
1425
- } else {
1426
- rateBox.style.display = (mode === 'with_vat') ? 'flex' : 'none';
1427
- }
1308
+ if (kind === 'non_formal') { rateBox.style.display = 'none'; document.getElementById('invoice-vat-mode').value = 'none'; }
1309
+ else { rateBox.style.display = (mode === 'with_vat') ? 'flex' : 'none'; }
1310
recomputeTotals();
1311
}
1312
1313
function handleVatTypeChange() {
1314
const type = document.getElementById('invoice-vat-type').value;
1433
- const input = document.getElementById('invoice-vat-rate-input');
1434
- input.value = (type === 'percent') ? 10 : 0;
1315
+ document.getElementById('invoice-vat-rate-input').value = (type === 'percent') ? 10 : 0;
1316
recomputeTotals();
1317
}
1318
@@ -1440,7 +1321,7 @@
1321
const label = document.getElementById('label-invoice-discount-value');
1322
const cur = getCurrencyLabel();
1323
label.innerText = (type === 'percent') ? 'درصد تخفیف (٪)' : `مبلغ تخفیف (${cur})`;
1443
- input.value = 0;
1324
+ document.getElementById('invoice-discount-fixed').value = 0;
1325
recomputeTotals();
1326
}
1327
@@ -1458,7 +1339,6 @@
1339
if (defCurCustom) defCurCustom.value = def.currency_custom || '';
1340
handleCurrencyModeChange();
1341
1461
- // اعمال پیشفرضها روی فرم فاکتور جدید (اگر در حالت ویرایش نیستیم)
1342
const editId = document.getElementById('edit-invoice-id')?.value;
1343
if (!editId) {
1344
const kindEl = document.getElementById('invoice-kind');
@@ -1484,7 +1364,6 @@
1364
alert('پیشفرضها ذخیره شد.');
1365
}
1366
1487
- /* ---------- داشبورد ---------- */
1367
function renderDashboard() {
1368
let salesSum = 0; let debtorsSum = 0;
1369
const myInvoices = getMyInvoices();
@@ -1533,16 +1412,11 @@
1412
const activeCompId = document.getElementById('invoice-company-id').value;
1413
const filterSelect = document.getElementById('filter-invoice-company');
1414
if (filterSelect) filterSelect.value = activeCompId;
1536
- renderInvoices();
1537
- renderDashboard();
1415
+ renderInvoices(); renderDashboard();
1416
}
1417
1540
- function startNewInvoice() {
1541
- cancelInvoiceEdit();
1542
- switchView('view-invoices');
1543
- }
1418
+ function startNewInvoice() { cancelInvoiceEdit(); switchView('view-invoices'); }
1419
1545
- /* ---------- اقلام فاکتور ---------- */
1420
function updateInvoiceItemRowNumbers() {
1421
const rows = document.querySelectorAll('#invoice-items-table-body tr');
1422
rows.forEach((tr, index) => {
@@ -1562,12 +1436,7 @@
1436
).join('');
1437
tr.innerHTML = `
1438
<td class="row-item-number" style="width:40px; text-align:center; font-weight:bold; vertical-align:middle;"></td>
1565
- <td>
1566
- <select class="form-control row-product-select" onchange="onRowProductChange('${rowKey}')">
1567
- <option value="">-- انتخاب کالا / خدمات --</option>
1568
- ${productOptions}
1569
- </select>
1570
- </td>
1439
+ <td><select class="form-control row-product-select" onchange="onRowProductChange('${rowKey}')"><option value="">-- انتخاب کالا / خدمات --</option>${productOptions}</select></td>
1440
<td style="width:90px;"><input type="text" class="form-control row-unit-input" value="عدد" style="text-align:center;" /></td>
1441
<td style="width:100px;"><input type="number" class="form-control row-quantity" value="${initialQty}" min="1" oninput="recomputeTotals()" style="text-align:center;" /></td>
1442
<td style="width:160px;"><input type="number" class="form-control row-price" value="${initialPrice !== null ? initialPrice : 0}" oninput="recomputeTotals()" style="text-align:left;" /></td>
@@ -1795,7 +1664,7 @@
1664
}
1665
1666
/* =========================================================================
1798
- چاپ فاکتور — همهی قالبها Landscape، حداکثر ۱۰ ردیف در هر صفحه
1667
+ چاپ فاکتور — Landscape، حداکثر ۱۰ ردیف در هر صفحه، باکس کامل روی هر صفحه
1668
========================================================================= */
1669
const MAX_ROWS_PER_PAGE = 10;
1670
@@ -1824,6 +1693,8 @@
1693
1694
function buildFormalPage(items, seller, contact, inv, opt) {
1695
const cur = inv.currencyLabel || 'ریال';
1696
+ const isLast = opt.isLastPage;
1697
+
1698
const rowsHtml = items.map(li => `
1699
<tr style="text-align:center;">
1700
<td style="border:1px solid #1e293b; padding:3px 6px; font-size:10.5px;">${li.rowNo.toLocaleString('fa-IR')}</td>
@@ -1837,775 +1708,5 @@
1708
<td style="border:1px solid #1e293b; padding:3px 6px; text-align:left; font-size:10.5px; font-weight:bold;">${li.lineNet.toLocaleString('fa-IR')}</td>
1709
</tr>
1710
`).join('');
1840
- const pageSubtotal = items.reduce((s, li) => s + li.lineSubtotal, 0);
1841
- const cumulativeAfter = (opt.cumulativeBefore || 0) + pageSubtotal;
1842
- const sellerIds = `${seller.national_id || '—'} / ${seller.reg_number || '—'}`;
1843
- const contactIds = `${contact.national_id || '—'} / ${contact.reg_number || '—'}`;
1844
- return `
1845
- <div class="invoice-a4-page landscape" style="background:#fff; padding:6mm 8mm; color:#000; font-family:'Vazirmatn FD', sans-serif;">
1846
- <table style="width:100%; border-collapse:collapse; border:2px solid #1e3a8a; margin-bottom:3px;">
1847
- <tr>
1848
- <td style="width:28%; border:1px solid #1e3a8a; padding:5px; font-size:11px; vertical-align:middle;">
1849
- <div style="font-weight:bold; font-size:13px; color:#1e3a8a;">${seller.name || 'فروشگاه'}</div>
1850
- <div style="font-size:9.5px; color:#475569; margin-top:1px;">صادرکننده فاکتور رسمی</div>
1851
- </td>
1852
- <td style="width:44%; border:1px solid #1e3a8a; padding:6px; text-align:center; vertical-align:middle; background:#eff6ff;">
1853
- <h1 style="font-size:15px; margin:0; font-weight:bold; color:#1e3a8a;">صورتحساب فروش کالا و خدمات</h1>
1854
- <div style="font-size:10px; margin-top:2px;">(ماده ۱۶۹ مکرر قانون مالیاتهای مستقیم)</div>
1855
- </td>
1856
- <td style="width:28%; border:1px solid #1e3a8a; padding:5px; font-size:10.5px; vertical-align:middle; text-align:left;">
1857
- <div>شماره سریال: <strong style="color:#b91c1c;">${inv.number}</strong></div>
1858
- <div style="margin-top:1px;">تاریخ صدور: <strong>${inv.date}</strong></div>
1859
- <div style="margin-top:1px; color:#64748b; font-size:9.5px;">صفحه: ${opt.pageNum} از ${opt.totalPages}</div>
1860
- </td>
1861
- </tr>
1862
- </table>
1863
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #1e3a8a; font-size:10px; margin-bottom:3px;">
1864
- <tr style="background:#f8fafc; font-weight:bold;"><td colspan="4" style="border:1px solid #1e3a8a; padding:2px 6px; color:#1e3a8a;">الف) مشخصات فروشنده</td></tr>
1865
- <tr>
1866
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:15%; background:#f1f5f9;">نام شخص حقیقی/حقوقی:</td>
1867
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:35%;"><strong>${seller.name || '—'}</strong></td>
1868
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:15%; background:#f1f5f9;">شماره اقتصادی:</td>
1869
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:35%;">${seller.economic_code || '—'}</td>
1870
- </tr>
1871
- <tr>
1872
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">شناسه ملی / شماره ثبت:</td>
1873
- <td style="border:1px solid #cbd5e1; padding:3px 6px;">${sellerIds}</td>
1874
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">کد پستی ۱۰ رقمی:</td>
1875
- <td style="border:1px solid #cbd5e1; padding:3px 6px;">${seller.postal_code || '—'}</td>
1876
- </tr>
1877
- <tr>
1878
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">نشانی و تلفن:</td>
1879
- <td colspan="3" style="border:1px solid #cbd5e1; padding:3px 6px;">${seller.address || '—'} ${seller.phone ? ' | تلفن: ' + seller.phone : ''}</td>
1880
- </tr>
1881
- </table>
1882
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #1e3a8a; font-size:10px; margin-bottom:3px;">
1883
- <tr style="background:#f8fafc; font-weight:bold;"><td colspan="4" style="border:1px solid #1e3a8a; padding:2px 6px; color:#1e3a8a;">ب) مشخصات خریدار</td></tr>
1884
- <tr>
1885
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:15%; background:#f1f5f9;">نام شخص حقیقی/حقوقی:</td>
1886
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:35%;"><strong>${contact.name || inv.contactName}</strong></td>
1887
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:15%; background:#f1f5f9;">شماره اقتصادی:</td>
1888
- <td style="border:1px solid #cbd5e1; padding:3px 6px; width:35%;">${contact.economic_code || '—'}</td>
1889
- </tr>
1890
- <tr>
1891
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">شناسه ملی / شماره ثبت:</td>
1892
- <td style="border:1px solid #cbd5e1; padding:3px 6px;">${contactIds}</td>
1893
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">کد پستی ۱۰ رقمی:</td>
1894
- <td style="border:1px solid #cbd5e1; padding:3px 6px;">${contact.postal_code || '—'}</td>
1895
- </tr>
1896
- <tr>
1897
- <td style="border:1px solid #cbd5e1; padding:3px 6px; background:#f1f5f9;">نشانی و تلفن:</td>
1898
- <td colspan="3" style="border:1px solid #cbd5e1; padding:3px 6px;">${contact.address || '—'} ${contact.mobile ? ' | همراه: ' + contact.mobile : ''}</td>
1899
- </tr>
1900
- </table>
1901
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #1e3a8a; font-size:10px;">
1902
- <thead>
1903
- <tr style="background:#1e3a8a; color:#fff; font-weight:bold; text-align:center;">
1904
- <th style="border:1px solid #1e3a8a; padding:4px; width:28px;">ردیف</th>
1905
- <th style="border:1px solid #1e3a8a; padding:4px 6px; text-align:right;">شرح کالا یا خدمات</th>
1906
- <th style="border:1px solid #1e3a8a; padding:4px; width:42px;">تعداد</th>
1907
- <th style="border:1px solid #1e3a8a; padding:4px; width:42px;">واحد</th>
1908
- <th style="border:1px solid #1e3a8a; padding:4px; width:105px;">مبلغ واحد (${cur})</th>
1909
- <th style="border:1px solid #1e3a8a; padding:4px; width:110px;">مبلغ کل (${cur})</th>
1910
- <th style="border:1px solid #1e3a8a; padding:4px; width:80px;">تخفیف (${cur})</th>
1911
- <th style="border:1px solid #1e3a8a; padding:4px; width:90px;">مالیات (${cur})</th>
1912
- <th style="border:1px solid #1e3a8a; padding:4px; width:120px;">مبلغ نهایی (${cur})</th>
1913
- </tr>
1914
- </thead>
1915
- <tbody>
1916
- ${!opt.isFirstPage ? `<tr style="background:#fef3c7; font-weight:bold; font-size:9.5px;"><td colspan="5" style="border:1px solid #1e293b; padding:3px; text-align:left;">نقل از صفحه قبل:</td><td colspan="4" style="border:1px solid #1e293b; padding:3px; text-align:left;">${(opt.cumulativeBefore || 0).toLocaleString('fa-IR')} ${cur}</td></tr>` : ''}
1917
- ${rowsHtml}
1918
- ${!opt.isLastPage ? `<tr style="background:#f1f5f9; font-weight:bold; font-size:9.5px;"><td colspan="5" style="border:1px solid #1e293b; padding:3px; text-align:left;">جمع این صفحه و نقل به صفحه بعد:</td><td colspan="4" style="border:1px solid #1e293b; padding:3px; text-align:left;">${cumulativeAfter.toLocaleString('fa-IR')} ${cur}</td></tr>` : ''}
1919
- </tbody>
1920
- </table>
1921
- ${opt.isLastPage ? `
1922
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #1e3a8a; font-size:10.5px; margin-top:3px;">
1923
- <tr>
1924
- <td style="width:60%; border:1px solid #1e3a8a; padding:6px; vertical-align:top; background:#f8fafc;">
1925
- <div style="margin-bottom:4px;"><strong>مبلغ کل به حروف:</strong> ${numberToPersianWords(inv.grandTotal, cur)}</div>
1926
- <div style="margin-bottom:4px;"><strong>شرایط و نحوه پرداخت:</strong> نقدی ☑ غیرنقدی (نسیه/چک) ☐</div>
1927
- <div style="font-size:9.5px; color:#475569; line-height:1.5;"><strong>توضیحات:</strong> ${inv.description || seller.footer || 'تحویل کالا منوط به تسویه نهایی میباشد.'}</div>
1928
- </td>
1929
- <td style="width:40%; border:1px solid #1e3a8a; padding:0;">
1930
- <table style="width:100%; border-collapse:collapse; font-size:10.5px;">
1931
- <tr><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;">جمع کل اقلام:</td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;">${inv.subtotal.toLocaleString('fa-IR')} ${cur}</td></tr>
1932
- <tr><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;">مجموع تخفیف:</td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;">${inv.discount.toLocaleString('fa-IR')} ${cur}</td></tr>
1933
- <tr><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;">مالیات و عوارض ارزش افزوده:</td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;">${inv.vat.toLocaleString('fa-IR')} ${cur}</td></tr>
1934
- <tr style="background:#eff6ff; font-weight:bold; font-size:11.5px; color:#1e3a8a;">
1935
- <td style="padding:5px 8px;">مبلغ قابل پرداخت:</td>
1936
- <td style="padding:5px 8px; text-align:left;">${inv.grandTotal.toLocaleString('fa-IR')} ${cur}</td>
1937
- </tr>
1938
- </table>
1939
- </td>
1940
- </tr>
1941
- </table>
1942
- <table style="width:100%; border-collapse:collapse; border:1px solid #1e3a8a; margin-top:6px; text-align:center; font-size:10.5px;">
1943
- <tr>
1944
- <td style="width:50%; height:50px; vertical-align:top; border:1px solid #1e3a8a; padding:5px; background:#fff;"><div style="font-weight:bold;">مهر و امضای فروشنده</div></td>
1945
- <td style="width:50%; height:50px; vertical-align:top; border:1px solid #1e3a8a; padding:5px; background:#fff;"><div style="font-weight:bold;">مهر و امضای خریدار</div></td>
1946
- </tr>
1947
- </table>
1948
- ` : `<div style="margin-top:8px; text-align:center; font-size:10.5px; color:#64748b; font-weight:bold;">(ادامه اقلام در صفحه بعد درج گردیده است...)</div>`}
1949
- </div>`;
1950
- }
1951
-
1952
- function buildNonFormalPage(items, seller, contact, inv, opt) {
1953
- const cur = inv.currencyLabel || 'ریال';
1954
- const isPre = inv.kind === 'pre_invoice';
1955
- const title = isPre ? 'پیشفاکتور فروش کالا و خدمات' : 'فاکتور فروش کالا و خدمات';
1956
-
1957
- const rowsHtml = items.map(li => `
1958
- <tr style="text-align:center;">
1959
- <td style="border:1px solid #334155; padding:4px 6px; font-size:10.5px;">${li.rowNo.toLocaleString('fa-IR')}</td>
1960
- <td style="border:1px solid #334155; padding:4px 8px; text-align:right; font-size:10.5px; font-weight:600;">${li.prodName}</td>
1961
- <td style="border:1px solid #334155; padding:4px 6px; font-size:10.5px;">${li.unit}</td>
1962
- <td style="border:1px solid #334155; padding:4px 6px; font-size:10.5px;">${li.qty.toLocaleString('fa-IR')}</td>
1963
- <td style="border:1px solid #334155; padding:4px 6px; text-align:left; font-size:10.5px;">${li.price.toLocaleString('fa-IR')}</td>
1964
- <td style="border:1px solid #334155; padding:4px 6px; text-align:left; font-size:10.5px; font-weight:bold;">${li.lineSubtotal.toLocaleString('fa-IR')}</td>
1965
- </tr>
1966
- `).join('');
1967
-
1968
- const pageSubtotal = items.reduce((s, li) => s + li.lineSubtotal, 0);
1969
- const cumulativeAfter = (opt.cumulativeBefore || 0) + pageSubtotal;
1970
-
1971
- // پیشفاکتور: مالیات در صورت فعال بودن نمایش داده میشود.
1972
- // فاکتور غیررسمی: inv.vat همیشه صفر است، پس ردیف مالیات نمایش داده نمیشود.
1973
- const showVatRow = isPre && inv.vat > 0;
1974
-
1975
- return `
1976
- <div class="invoice-a4-page landscape" style="background:#fff; padding:7mm 8mm; color:#000; font-family:'Vazirmatn FD', sans-serif;">
1977
- <table style="width:100%; border-collapse:collapse; border:2px solid #334155; margin-bottom:5px;">
1978
- <tr>
1979
- <td style="width:30%; border:1px solid #334155; padding:6px; vertical-align:middle;">
1980
- <div style="font-weight:bold; font-size:13px; color:#0f172a;">${seller.name || 'فروشگاه'}</div>
1981
- <div style="font-size:10px; color:#475569; margin-top:1px;">تلفن: ${seller.phone || '—'}</div>
1982
- </td>
1983
- <td style="width:40%; border:1px solid #334155; padding:6px; text-align:center; vertical-align:middle; background:#f8fafc;">
1984
- <h1 style="font-size:15px; margin:0; font-weight:bold; color:#0f172a;">${title}</h1>
1985
- </td>
1986
- <td style="width:30%; border:1px solid #334155; padding:6px; font-size:10.5px; vertical-align:middle; text-align:left;">
1987
- <div>شماره: <strong style="font-size:11.5px;">#${inv.number}</strong></div>
1988
- <div style="margin-top:1px;">تاریخ: <strong>${inv.date}</strong></div>
1989
- <div style="margin-top:1px; color:#64748b; font-size:9.5px;">صفحه: ${opt.pageNum} از ${opt.totalPages}</div>
1990
- </td>
1991
- </tr>
1992
- </table>
1993
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #334155; font-size:10.5px; margin-bottom:5px;">
1994
- <tr>
1995
- <td style="width:50%; border:1px solid #334155; padding:5px; vertical-align:top; background:#f8fafc;">
1996
- <div style="font-weight:bold; color:#334155; margin-bottom:2px;">مشخصات فروشنده:</div>
1997
- <div>نام: <strong>${seller.name || '—'}</strong></div>
1998
- <div>نشانی: ${seller.address || '—'}</div>
1999
- <div>تلفن تماس: ${seller.phone || '—'}</div>
2000
- </td>
2001
- <td style="width:50%; border:1px solid #334155; padding:5px; vertical-align:top; background:#f8fafc;">
2002
- <div style="font-weight:bold; color:#334155; margin-bottom:2px;">مشخصات خریدار:</div>
2003
- <div>نام: <strong>${contact.name || inv.contactName}</strong></div>
2004
- <div>نشانی: ${contact.address || '—'}</div>
2005
- <div>شماره همراه: ${contact.mobile || '—'}</div>
2006
- </td>
2007
- </tr>
2008
- </table>
2009
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #334155; font-size:10.5px;">
2010
- <thead>
2011
- <tr style="background:#334155; color:#fff; font-weight:bold; text-align:center;">
2012
- <th style="border:1px solid #334155; padding:5px 4px; width:32px;">ردیف</th>
2013
- <th style="border:1px solid #334155; padding:5px 8px; text-align:right;">شرح کالا | خدمات</th>
2014
- <th style="border:1px solid #334155; padding:5px 4px; width:60px;">واحد</th>
2015
- <th style="border:1px solid #334155; padding:5px 4px; width:60px;">مقدار</th>
2016
- <th style="border:1px solid #334155; padding:5px 4px; width:150px; text-align:left;">قیمت واحد (${cur})</th>
2017
- <th style="border:1px solid #334155; padding:5px 4px; width:170px; text-align:left;">قیمت کل (${cur})</th>
2018
- </tr>
2019
- </thead>
2020
- <tbody>
2021
- ${!opt.isFirstPage ? `<tr style="background:#fef3c7; font-weight:bold; font-size:9.5px;"><td colspan="5" style="border:1px solid #334155; padding:3px; text-align:left;">نقل از صفحه قبل:</td><td style="border:1px solid #334155; padding:3px; text-align:left;">${(opt.cumulativeBefore || 0).toLocaleString('fa-IR')} ${cur}</td></tr>` : ''}
2022
- ${rowsHtml}
2023
- ${!opt.isLastPage ? `<tr style="background:#f1f5f9; font-weight:bold; font-size:9.5px;"><td colspan="5" style="border:1px solid #334155; padding:3px; text-align:left;">جمع این صفحه و نقل به صفحه بعد:</td><td style="border:1px solid #334155; padding:3px; text-align:left;">${cumulativeAfter.toLocaleString('fa-IR')} ${cur}</td></tr>` : ''}
2024
- </tbody>
2025
- </table>
2026
- ${opt.isLastPage ? `
2027
- <table style="width:100%; border-collapse:collapse; border:1.5px solid #334155; font-size:10.5px; margin-top:5px;">
2028
- <tr>
2029
- <td style="width:60%; border:1px solid #334155; padding:6px; vertical-align:top; background:#f8fafc;">
2030
- <div style="margin-bottom:4px;"><strong>مبلغ به حروف:</strong> ${numberToPersianWords(inv.grandTotal, cur)}</div>
2031
- <div style="font-size:9.5px; color:#475569; line-height:1.5;"><strong>توضیحات:</strong> ${inv.description || seller.footer || (isPre ? 'اعتبار پیشفاکتور به مدت ۴۸ ساعت میباشد.' : 'از خرید شما سپاسگزاریم.')}</div>
2032
- </td>
2033
- <td style="width:40%; border:1px solid #334155; padding:0;">
2034
- <table style="width:100%; border-collapse:collapse; font-size:10.5px;">
2035
- <tr><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;">قیمت کل اقلام:</td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;">${inv.subtotal.toLocaleString('fa-IR')} ${cur}</td></tr>
2036
- ${inv.discount > 0 ? `<tr><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;">تخفیف:</td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;">${inv.discount.toLocaleString('fa-IR')} ${cur}</td></tr>` : ''}
2037
- ${showVatRow ? `<tr style="background:#fffbeb;"><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px;"><strong>مالیات ارزش افزوده:</strong></td><td style="border-bottom:1px solid #cbd5e1; padding:3px 8px; text-align:left;"><strong>${inv.vat.toLocaleString('fa-IR')} ${cur}</strong></td></tr>` : ''}
2038
- <tr style="background:#f1f5f9; font-weight:bold; font-size:11.5px;">
2039
- <td style="padding:5px 8px;">مبلغ کل (${cur}):</td>
2040
- <td style="padding:5px 8px; text-align:left;">${inv.grandTotal.toLocaleString('fa-IR')} ${cur}</td>
2041
- </tr>
2042
- </table>
2043
- </td>
2044
- </tr>
2045
- </table>
2046
- <table style="width:100%; border-collapse:collapse; border:1px solid #334155; margin-top:6px; text-align:center; font-size:10.5px;">
2047
- <tr>
2048
- <td style="width:50%; height:50px; vertical-align:top; border:1px solid #334155; padding:5px; background:#fff;"><div style="font-weight:bold;">مهر و امضای فروشنده</div></td>
2049
- <td style="width:50%; height:50px; vertical-align:top; border:1px solid #334155; padding:5px; background:#fff;"><div style="font-weight:bold;">مهر و امضای خریدار</div></td>
2050
- </tr>
2051
- </table>
2052
- ` : `<div style="margin-top:8px; text-align:center; font-size:10.5px; color:#64748b; font-weight:bold;">(ادامه در صفحه بعد...)</div>`}
2053
- </div>`;
2054
- }
2055
-
2056
- function renderAndPrintDirect(invId) {
2057
- const inv = getMyInvoices().find(i => i.id === invId);
2058
- if (!inv) return;
2059
- const myCompanies = getMyCompanies();
2060
- const myContacts = getMyContacts();
2061
- const seller = myCompanies.find(c => c.id === inv.companyId) || myCompanies[0] || {};
2062
- const contact = myContacts.find(c => c.id === inv.contactId) || {};
2063
- const isFormal = (inv.kind === 'formal');
2064
- const builder = isFormal ? buildFormalPage : buildNonFormalPage;
2065
-
2066
- const allLines = computeInvoiceLines(inv);
2067
- const pageGroups = [];
2068
- let cumulative = 0;
2069
- for (let start = 0; start < allLines.length; start += MAX_ROWS_PER_PAGE) {
2070
- const pageItems = allLines.slice(start, start + MAX_ROWS_PER_PAGE);
2071
- const isFirstPage = (start === 0);
2072
- const isLastPage = (start + MAX_ROWS_PER_PAGE >= allLines.length);
2073
- pageGroups.push({ items: pageItems, isFirstPage, isLastPage, cumulativeBefore: cumulative });
2074
- cumulative += pageItems.reduce((s, li) => s + li.lineSubtotal, 0);
2075
- }
2076
- const totalPages = pageGroups.length;
2077
- const containerHtml = pageGroups.map((g, idx) =>
2078
- builder(g.items, seller, contact, inv, {
2079
- pageNum: idx + 1, totalPages,
2080
- isFirstPage: g.isFirstPage, isLastPage: g.isLastPage,
2081
- cumulativeBefore: g.cumulativeBefore
2082
- })
2083
- ).join('');
2084
-
2085
- // همه قالبها Landscape چاپ میشوند.
2086
- let orientationStyle = document.getElementById('dynamic-print-orientation');
2087
- if (!orientationStyle) {
2088
- orientationStyle = document.createElement('style');
2089
- orientationStyle.id = 'dynamic-print-orientation';
2090
- document.head.appendChild(orientationStyle);
2091
- }
2092
- orientationStyle.innerHTML = `@media print { @page { size: A4 landscape; margin: 8mm 10mm; } }`;
2093
-
2094
- const printContainer = document.getElementById('printable-invoice');
2095
- printContainer.innerHTML = containerHtml;
2096
- printContainer.style.display = 'block';
2097
- window.print();
2098
- printContainer.style.display = 'none';
2099
- }
2100
-
2101
- /* ---------- کالاها ---------- */
2102
- function commitSaveProduct() {
2103
- if (!currentUser) return;
2104
- const myProducts = getMyProducts();
2105
- const code = document.getElementById('prod-code-input').value || (myProducts.length + 1).toString();
2106
- const name = document.getElementById('prod-name-input').value;
2107
- const spec = document.getElementById('prod-spec-input').value || '';
2108
- const unit = document.getElementById('prod-unit-input').value || 'عدد';
2109
- const buy_price = parseFloat(document.getElementById('prod-buy-input').value) || 0;
2110
- const sale_price = parseFloat(document.getElementById('prod-sale-input').value) || 0;
2111
- if (!name) { alert('عنوان کالا الزامی است.'); return; }
2112
- datastore.products.push({
2113
- id: 'P_' + Date.now(), ownerUserId: currentUser.id,
2114
- code, name, spec, type: 'good', unit, buy_price, sale_price, stock: 0
2115
- });
2116
- saveDatastore();
2117
- alert('کالا ثبت شد.');
2118
- document.getElementById('prod-name-input').value = '';
2119
- document.getElementById('prod-spec-input').value = '';
2120
- refreshAllSurfaces();
2121
- }
2122
-
2123
- function renderProducts() {
2124
- const tbody = document.getElementById('products-catalog-table-body');
2125
- const myProducts = getMyProducts();
2126
- if (myProducts.length === 0) {
2127
- tbody.innerHTML = '<tr><td colspan="6" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ کالایی ثبت نشده است.</td></tr>';
2128
- return;
2129
- }
2130
- tbody.innerHTML = myProducts.map(p => `
2131
- <tr>
2132
- <td>${p.code}</td>
2133
- <td><strong>${p.name}</strong></td>
2134
- <td>${p.spec || '—'}</td>
2135
- <td>${p.unit}</td>
2136
- <td>${p.sale_price.toLocaleString('fa-IR')}</td>
2137
- <td><button class="btn btn-danger btn-inline" style="padding:4px 8px; font-size:12px; min-height:30px;" onclick="deleteProduct('${p.id}')">حذف</button></td>
2138
- </tr>`).join('');
2139
- }
2140
-
2141
- function deleteProduct(id) {
2142
- if (!currentUser) return;
2143
- if (confirm('حذف شود؟')) {
2144
- datastore.products = datastore.products.filter(p => !(p.id === id && p.ownerUserId === currentUser.id));
2145
- saveDatastore();
2146
- refreshAllSurfaces();
2147
- }
2148
- }
2149
-
2150
- function openQuickProductModal() { document.getElementById('modal-quick-product').classList.add('active'); }
2151
- function closeQuickProductModal() { document.getElementById('modal-quick-product').classList.remove('active'); }
2152
-
2153
- function saveQuickProduct() {
2154
- if (!currentUser) return;
2155
- const myProducts = getMyProducts();
2156
- const code = document.getElementById('quick-p-code').value || (myProducts.length + 1).toString();
2157
- const name = document.getElementById('quick-p-name').value;
2158
- const spec = document.getElementById('quick-p-spec').value || '';
2159
- const unit = document.getElementById('quick-p-unit').value || 'عدد';
2160
- const price = parseFloat(document.getElementById('quick-p-price').value) || 0;
2161
- if (!name) { alert('عنوان کالا الزامی است.'); return; }
2162
- const newId = 'P_' + Date.now();
2163
- datastore.products.push({
2164
- id: newId, ownerUserId: currentUser.id,
2165
- code, name, spec, unit, buy_price: 0, sale_price: price, stock: 0, type: 'good'
2166
- });
2167
- saveDatastore();
2168
- closeQuickProductModal();
2169
- refreshAllSurfaces();
2170
- addInvoiceItemRow(newId, 1, price);
2171
- }
2172
-
2173
- function downloadProductsExcelTemplate() {
2174
- const ws_data = [
2175
- ["کد کالا", "نام کالا", "مشخصه و نوع", "واحد", "قیمت فروش (ریال)"],
2176
- ["1", "سوئیچ شبکه 24 پورت", "با 2 پاور", "عدد", 2180000000],
2177
- ["2", "هارد 2.5 اینچ سرور", "", "عدد", 37000000]
2178
- ];
2179
- const ws = XLSX.utils.aoa_to_sheet(ws_data);
2180
- const wb = XLSX.utils.book_new();
2181
- XLSX.utils.book_append_sheet(wb, ws, "کالاها");
2182
- XLSX.writeFile(wb, "نمونه_کالاها_ایزی_فاکتور.xlsx");
2183
- }
2184
-
2185
- function importProductsFromExcel(event) {
2186
- if (!currentUser) return;
2187
- const file = event.target.files[0];
2188
- if (!file) return;
2189
- const reader = new FileReader();
2190
- reader.onload = function(e) {
2191
- try {
2192
- const data = new Uint8Array(e.target.result);
2193
- const workbook = XLSX.read(data, { type: 'array' });
2194
- const rows = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
2195
- const myProducts = getMyProducts();
2196
- rows.forEach((r, idx) => {
2197
- const name = r["نام کالا"] || r["عنوان"];
2198
- if (name) {
2199
- datastore.products.push({
2200
- id: 'P_' + Date.now() + '_' + idx, ownerUserId: currentUser.id,
2201
- code: (r["کد کالا"] || (myProducts.length + idx + 1)).toString(),
2202
- name: name.toString(),
2203
- spec: (r["مشخصه و نوع"] || '').toString(),
2204
- unit: (r["واحد"] || 'عدد').toString(),
2205
- buy_price: 0,
2206
- sale_price: parseFloat(r["قیمت فروش (ریال)"] || r["قیمت فروش"] || 0) || 0,
2207
- stock: 0, type: 'good'
2208
- });
2209
- }
2210
- });
2211
- saveDatastore();
2212
- refreshAllSurfaces();
2213
- alert('کالاها ایمپورت شدند.');
2214
- } catch(err) { alert('خطا در فایل اکسل!'); }
2215
- };
2216
- reader.readAsArrayBuffer(file);
2217
- }
2218
-
2219
- /* ---------- اشخاص ---------- */
2220
- function commitSaveContact() {
2221
- if (!currentUser) return;
2222
- const entity_type = document.getElementById('contact-entity-type').value;
2223
- const custom_prefix = entity_type === 'natural' ? document.getElementById('contact-prefix-select')?.value : '';
2224
- const raw_name = document.getElementById('contact-name-input').value;
2225
- const role = document.getElementById('contact-role-input').value;
2226
- const mobile = document.getElementById('contact-mobile-input').value;
2227
- const national_id = document.getElementById('contact-national-input').value;
2228
- const economic_code = (entity_type === 'natural') ? '' : document.getElementById('contact-economic-input').value;
2229
- const reg_number = (entity_type === 'natural') ? '' : document.getElementById('contact-reg-input').value;
2230
- const postal_code = document.getElementById('contact-postal-input').value;
2231
- const address = document.getElementById('contact-address-input').value;
2232
- if (!raw_name.trim()) { alert('نام طرف حساب الزامی است.'); return; }
2233
- const formatted_name = formatEntityName(raw_name, entity_type, custom_prefix);
2234
- datastore.contacts.push({
2235
- id: 'C_' + Date.now(), ownerUserId: currentUser.id,
2236
- entity_type, name: formatted_name, role, mobile, national_id, economic_code,
2237
- reg_number, postal_code, address, balance: 0
2238
- });
2239
- saveDatastore();
2240
- alert('طرف حساب ثبت شد.');
2241
- document.getElementById('contact-name-input').value = '';
2242
- refreshAllSurfaces();
2243
- }
2244
-
2245
- function renderContacts() {
2246
- const tbody = document.getElementById('contacts-ledger-table-body');
2247
- const invSelect = document.getElementById('invoice-contact-id');
2248
- const chqSelect = document.getElementById('chq-contact-select');
2249
- const myContacts = getMyContacts();
2250
- if (myContacts.length === 0) {
2251
- tbody.innerHTML = '<tr><td colspan="8" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ طرف حسابی ثبت نشده است.</td></tr>';
2252
- } else {
2253
- tbody.innerHTML = myContacts.map(c => `
2254
- <tr>
2255
- <td><strong>${c.name}</strong></td>
2256
- <td><span class="badge ${c.entity_type === 'legal' ? 'badge-warning' : 'badge-success'}">${c.entity_type === 'legal' ? 'حقوقی' : 'حقیقی'}</span></td>
2257
- <td>${c.national_id || '—'}</td>
2258
- <td>${c.economic_code || '—'}</td>
2259
- <td>${c.postal_code || '—'}</td>
2260
- <td>${c.mobile || '—'}</td>
2261
- <td>${Math.abs(c.balance || 0).toLocaleString('fa-IR')}</td>
2262
- <td><button class="btn btn-danger btn-inline" style="padding:4px 8px; font-size:12px; min-height:30px;" onclick="deleteContact('${c.id}')">حذف</button></td>
2263
- </tr>`).join('');
2264
- }
2265
- const options = myContacts.map(c => `<option value="${c.id}">${c.name}</option>`).join('');
2266
- if (invSelect) invSelect.innerHTML = options;
2267
- if (chqSelect) chqSelect.innerHTML = options;
2268
- }
2269
-
2270
- function deleteContact(id) {
2271
- if (!currentUser) return;
2272
- if (confirm('حذف شود؟')) {
2273
- datastore.contacts = datastore.contacts.filter(c => !(c.id === id && c.ownerUserId === currentUser.id));
2274
- saveDatastore();
2275
- refreshAllSurfaces();
2276
- }
2277
- }
2278
-
2279
- function openQuickContactModal() {
2280
- document.getElementById('modal-quick-contact').classList.add('active');
2281
- handleQuickCEntityChange();
2282
- }
2283
- function closeQuickContactModal() { document.getElementById('modal-quick-contact').classList.remove('active'); }
2284
-
2285
- function saveQuickContact() {
2286
- if (!currentUser) return;
2287
- const entity_type = document.getElementById('quick-c-entity').value;
2288
- const prefix = entity_type === 'natural' ? document.getElementById('quick-c-prefix')?.value : '';
2289
- const raw_name = document.getElementById('quick-c-name').value;
2290
- if (!raw_name.trim()) { alert('نام الزامی است.'); return; }
2291
- const newId = 'C_' + Date.now();
2292
- datastore.contacts.push({
2293
- id: newId, ownerUserId: currentUser.id, entity_type,
2294
- name: formatEntityName(raw_name, entity_type, prefix),
2295
- role: 'customer',
2296
- mobile: document.getElementById('quick-c-mobile').value,
2297
- national_id: document.getElementById('quick-c-national').value,
2298
- economic_code: (entity_type === 'natural') ? '' : document.getElementById('quick-c-economic').value,
2299
- reg_number: (entity_type === 'natural') ? '' : document.getElementById('quick-c-reg').value,
2300
- postal_code: document.getElementById('quick-c-postal').value,
2301
- address: document.getElementById('quick-c-address').value,
2302
- balance: 0
2303
- });
2304
- saveDatastore();
2305
- closeQuickContactModal();
2306
- refreshAllSurfaces();
2307
- document.getElementById('invoice-contact-id').value = newId;
2308
- }
2309
-
2310
- function downloadContactsExcelTemplate() {
2311
- const ws_data = [
2312
- ["نام شخص یا شرکت", "نوع (حقیقی/حقوقی)", "شماره همراه", "شناسه یا کد ملی", "کد اقتصادی", "شماره ثبت", "کد پستی", "نشانی"],
2313
- ["دانشگاه صنعتی شریف", "حقوقی", "02166165000", "14002830256", "14002830256", "", "1458889694", "طرشت محله تیموری پلاک 435"]
2314
- ];
2315
- const ws = XLSX.utils.aoa_to_sheet(ws_data);
2316
- const wb = XLSX.utils.book_new();
2317
- XLSX.utils.book_append_sheet(wb, ws, "اشخاص");
2318
- XLSX.writeFile(wb, "نمونه_اشخاص_ایزی_فاکتور.xlsx");
2319
- }
2320
-
2321
- function importContactsFromExcel(event) {
2322
- if (!currentUser) return;
2323
- const file = event.target.files[0];
2324
- if (!file) return;
2325
- const reader = new FileReader();
2326
- reader.onload = function(e) {
2327
- try {
2328
- const data = new Uint8Array(e.target.result);
2329
- const workbook = XLSX.read(data, { type: 'array' });
2330
- const rows = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
2331
- rows.forEach((r, idx) => {
2332
- const raw_name = r["نام شخص یا شرکت"] || r["نام"];
2333
- if (raw_name) {
2334
- const entity_type = (r["نوع (حقیقی/حقوقی)"] || '').includes('حقوقی') ? 'legal' : 'natural';
2335
- datastore.contacts.push({
2336
- id: 'C_' + Date.now() + '_' + idx, ownerUserId: currentUser.id, entity_type,
2337
- name: formatEntityName(raw_name.toString(), entity_type, 'آقا/خانم'),
2338
- role: 'customer',
2339
- mobile: (r["شماره همراه"] || '').toString(),
2340
- national_id: (r["شناسه یا کد ملی"] || '').toString(),
2341
- economic_code: (entity_type === 'legal' ? (r["کد اقتصادی"] || '') : '').toString(),
2342
- reg_number: (entity_type === 'legal' ? (r["شماره ثبت"] || '') : '').toString(),
2343
- postal_code: (r["کد پستی"] || '').toString(),
2344
- address: (r["نشانی"] || '').toString(),
2345
- balance: 0
2346
- });
2347
- }
2348
- });
2349
- saveDatastore();
2350
- refreshAllSurfaces();
2351
- alert('اشخاص ایمپورت شدند.');
2352
- } catch(err) { alert('خطا در فایل اکسل!'); }
2353
- };
2354
- reader.readAsArrayBuffer(file);
2355
- }
2356
-
2357
- /* ---------- چک و هزینه ---------- */
2358
- function commitSaveCheque() {
2359
- if (!currentUser) return;
2360
- const direction = document.getElementById('chq-direction-input').value;
2361
- const contactSelect = document.getElementById('chq-contact-select');
2362
- const contactName = contactSelect.options[contactSelect.selectedIndex]?.text || '';
2363
- const sayad_id = document.getElementById('chq-sayad-input').value;
2364
- const bank = document.getElementById('chq-bank-input').value;
2365
- const amount = parseFloat(document.getElementById('chq-amount-input').value) || 0;
2366
- if (!sayad_id || amount <= 0) { alert('اطلاعات چک نامعتبر است.'); return; }
2367
- datastore.cheques.push({
2368
- id: 'CHQ_' + Date.now(), ownerUserId: currentUser.id,
2369
- direction, contactName, sayad_id, bank, amount,
2370
- due_date: document.getElementById('chq-due-input').value,
2371
- status: document.getElementById('chq-status-input').value
2372
- });
2373
- saveDatastore();
2374
- alert('چک ثبت شد.');
2375
- refreshAllSurfaces();
2376
- }
2377
- function renderCheques() {
2378
- const tbody = document.getElementById('cheques-ledger-table-body');
2379
- const myCheques = getMyCheques();
2380
- tbody.innerHTML = myCheques.length === 0 ? '<tr><td colspan="6" style="text-align:center; padding:20px; color:var(--text-muted);">چکی ثبت نشده است.</td></tr>' :
2381
- myCheques.map(c => `<tr><td>${c.direction === 'inbound' ? 'دریافتی' : 'پرداختی'}</td><td>${c.contactName}</td><td>${c.bank} - ${c.sayad_id}</td><td>${c.amount.toLocaleString('fa-IR')}</td><td>${c.due_date}</td><td>${c.status}</td></tr>`).join('');
2382
- }
2383
- function commitSaveExpense() {
2384
- if (!currentUser) return;
2385
- const amount = parseFloat(document.getElementById('trx-amount-input').value) || 0;
2386
- if (amount <= 0) { alert('مبلغ معتبر نیست.'); return; }
2387
- datastore.expenses.push({
2388
- id: 'TRX_' + Date.now(), ownerUserId: currentUser.id,
2389
- kind: document.getElementById('trx-kind-input').value,
2390
- category: document.getElementById('trx-category-input').value,
2391
- amount, desc: document.getElementById('trx-desc-input').value
2392
- });
2393
- saveDatastore();
2394
- alert('سند ثبت شد.');
2395
- refreshAllSurfaces();
2396
- }
2397
- function renderExpenses() {
2398
- const tbody = document.getElementById('expenses-ledger-table-body');
2399
- const myExpenses = getMyExpenses();
2400
- tbody.innerHTML = myExpenses.length === 0 ? '<tr><td colspan="4" style="text-align:center; padding:20px; color:var(--text-muted);">موردی ثبت نشده است.</td></tr>' :
2401
- myExpenses.map(e => `<tr><td>${e.kind}</td><td>${e.category}</td><td>${e.desc}</td><td>${e.amount.toLocaleString('fa-IR')}</td></tr>`).join('');
2402
- }
2403
-
2404
- /* ---------- شرکتها ---------- */
2405
- function commitSaveCompany() {
2406
- if (!currentUser) return;
2407
- const entity_type = document.getElementById('company-entity-type').value;
2408
- const raw_name = document.getElementById('company-name-input').value;
2409
- if (!raw_name.trim()) { alert('نام شرکت الزامی است.'); return; }
2410
- const newComp = {
2411
- id: 'COMP_' + Date.now(), ownerUserId: currentUser.id, entity_type,
2412
- name: formatEntityName(raw_name, entity_type),
2413
- phone: document.getElementById('company-phone-input').value || '',
2414
- national_id: document.getElementById('company-national-input').value || '',
2415
- economic_code: document.getElementById('company-economic-input').value || '',
2416
- reg_number: document.getElementById('company-reg-input').value || '',
2417
- postal_code: document.getElementById('company-postal-input').value || '',
2418
- address: document.getElementById('company-address-input').value || '',
2419
- footer: document.getElementById('company-footer-input')?.value || 'از خرید شما سپاسگزاریم.'
2420
- };
2421
- datastore.companies.push(newComp);
2422
- const s = getMySettings();
2423
- s.default_company_id = newComp.id;
2424
- saveDatastore();
2425
- alert('شرکت با موفقیت ثبت و ذخیره شد و به عنوان فروشنده پیشفرض تنظیم گردید.');
2426
- ['company-name-input','company-phone-input','company-national-input','company-economic-input','company-reg-input','company-postal-input','company-address-input','company-footer-input'].forEach(id => {
2427
- const el = document.getElementById(id);
2428
- if (el) el.value = '';
2429
- });
2430
- refreshAllSurfaces();
2431
- }
2432
-
2433
- function renderCompanies() {
2434
- const tbody = document.getElementById('companies-table-body');
2435
- const invoiceCompSelect = document.getElementById('invoice-company-id');
2436
- const filterCompSelect = document.getElementById('filter-invoice-company');
2437
- const myCompanies = getMyCompanies();
2438
- const mySettings = getMySettings();
2439
- const defCompId = mySettings.default_company_id || (myCompanies[0]?.id);
2440
- if (tbody) {
2441
- if (myCompanies.length === 0) {
2442
- tbody.innerHTML = '<tr><td colspan="5" style="text-align:center; color:var(--text-muted); padding:20px;">هیچ شرکتی ثبت نشده است. لطفاً ابتدا شرکت خود را ثبت کنید.</td></tr>';
2443
- } else {
2444
- tbody.innerHTML = myCompanies.map(c => `
2445
- <tr>
2446
- <td><strong>${c.name}</strong></td>
2447
- <td>${c.national_id || '—'}</td>
2448
- <td>${c.economic_code || '—'}</td>
2449
- <td>${c.id === defCompId ? '<span class="badge badge-success">پیشفرض</span>' : `<button class="btn btn-secondary btn-inline" style="padding:2px 8px; font-size:11px;" onclick="setDefaultCompany('${c.id}')">انتخاب</button>`}</td>
2450
- <td>${myCompanies.length > 1 ? `<button class="btn btn-danger btn-inline" style="padding:2px 8px; font-size:11px;" onclick="deleteCompany('${c.id}')">حذف</button>` : '—'}</td>
2451
- </tr>`).join('');
2452
- }
2453
- }
2454
- if (invoiceCompSelect) {
2455
- invoiceCompSelect.innerHTML = myCompanies.map(c => `<option value="${c.id}" ${c.id === defCompId ? 'selected' : ''}>${c.name}</option>`).join('');
2456
- if (defCompId) invoiceCompSelect.value = defCompId;
2457
- }
2458
- if (filterCompSelect) {
2459
- const currentVal = filterCompSelect.value || 'ALL';
2460
- filterCompSelect.innerHTML = `<option value="ALL">نمایش همه شرکتها</option>` + myCompanies.map(c => `<option value="${c.id}">فقط ${c.name}</option>`).join('');
2461
- filterCompSelect.value = currentVal;
2462
- }
2463
- }
2464
-
2465
- function setDefaultCompany(id) {
2466
- const s = getMySettings();
2467
- s.default_company_id = id;
2468
- saveDatastore();
2469
- refreshAllSurfaces();
2470
- }
2471
-
2472
- function deleteCompany(id) {
2473
- if (!currentUser) return;
2474
- if (confirm('حذف شود؟')) {
2475
- datastore.companies = datastore.companies.filter(c => !(c.id === id && c.ownerUserId === currentUser.id));
2476
- const myCompanies = getMyCompanies();
2477
- const s = getMySettings();
2478
- if (s.default_company_id === id) s.default_company_id = myCompanies[0]?.id || '';
2479
- saveDatastore();
2480
- refreshAllSurfaces();
2481
- }
2482
- }
2483
-
2484
- function exportDataBlob() {
2485
- const userExport = {
2486
- user: currentUser?.username,
2487
- exportedAt: new Date().toISOString(),
2488
- companies: getMyCompanies(), contacts: getMyContacts(), products: getMyProducts(),
2489
- invoices: getMyInvoices(), cheques: getMyCheques(), expenses: getMyExpenses(),
2490
- settings: getMySettings()
2491
- };
2492
- const blobString = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(userExport, null, 2));
2493
- const anchor = document.createElement('a');
2494
- anchor.setAttribute("href", blobString);
2495
- anchor.setAttribute("download", `easy-factor-${currentUser?.username || 'data'}-${Date.now()}.json`);
2496
- document.body.appendChild(anchor);
2497
- anchor.click();
2498
- anchor.remove();
2499
- }
2500
-
2501
- function importDataBlob(event) {
2502
- if (!currentUser) return;
2503
- const file = event.target.files[0];
2504
- if (!file) return;
2505
- const reader = new FileReader();
2506
- reader.onload = function(e) {
2507
- try {
2508
- const imported = JSON.parse(e.target.result);
2509
- const userId = currentUser.id;
2510
- ['companies', 'contacts', 'products', 'invoices', 'cheques', 'expenses'].forEach(key => {
2511
- if (Array.isArray(imported[key])) {
2512
- imported[key].forEach(item => { item.ownerUserId = userId; datastore[key].push(item); });
2513
- }
2514
- });
2515
- if (imported.settings) {
2516
- const s = getMySettings();
2517
- Object.assign(s, imported.settings, { ownerUserId: userId });
2518
- }
2519
- saveDatastore();
2520
- refreshAllSurfaces();
2521
- alert('اطلاعات با موفقیت به حساب کاربری شما اضافه شد.');
2522
- } catch(err) { alert('فایل نامعتبر است.'); }
2523
- };
2524
- reader.readAsText(file);
2525
- }
2526
-
2527
- function numberToPersianWords(num, currencyLabel) {
2528
- const cur = currencyLabel || 'ریال';
2529
- if (!num || isNaN(num) || num == 0) return 'صفر ' + cur;
2530
- const yegan = ["", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه"];
2531
- const dahgan = ["", "", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود"];
2532
- const dah_ta_bist = ["ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده"];
2533
- const sadgan = ["", "صد", "دویست", "سیصد", "چهارصد", "پانصد", "ششصد", "هفتصد", "هشتصد", "نهصد"];
2534
- const part_names = ["", "هزار", "میلیون", "میلیارد", "تریلیون"];
2535
- function threeDigitToWords(n) {
2536
- let c = Math.floor(n / 100);
2537
- let d = Math.floor((n % 100) / 10);
2538
- let y = n % 10;
2539
- let parts = [];
2540
- if (c > 0) parts.push(sadgan[c]);
2541
- if (d === 1) parts.push(dah_ta_bist[y]);
2542
- else {
2543
- if (d > 1) parts.push(dahgan[d]);
2544
- if (y > 0) parts.push(yegan[y]);
2545
- }
2546
- return parts.join(" و ");
2547
- }
2548
- let parts = [];
2549
- let chunkIdx = 0;
2550
- let temp = Math.abs(Math.round(num));
2551
- while (temp > 0) {
2552
- let chunk = temp % 1000;
2553
- if (chunk > 0) {
2554
- let w = threeDigitToWords(chunk);
2555
- if (part_names[chunkIdx]) w += " " + part_names[chunkIdx];
2556
- parts.unshift(w);
2557
- }
2558
- temp = Math.floor(temp / 1000);
2559
- chunkIdx++;
2560
- }
2561
- return parts.join(" و ") + " " + cur;
2562
- }
2563
-
2564
- window.addEventListener('DOMContentLoaded', () => { initAuthSystem(); });
2565
- </script>
2566
-
2567
-<style>
2568
-.form-control, textarea, select { direction: rtl; }
2569
-</style>
2570
-
2571
-<script>
2572
-/* ولیدیشن نهایی روی ثبت فاکتور */
2573
-(function(){
2574
- const oldSave = window.commitSaveInvoice;
2575
- window.commitSaveInvoice = function(){
2576
- const rows = document.querySelectorAll('#invoice-items-table-body tr');
2577
- if(!rows.length){
2578
- alert('حداقل یک ردیف کالا یا خدمت لازم است.');
2579
- return;
2580
- }
2581
- for(const row of rows){
2582
- const sel = row.querySelector('.row-product-select');
2583
- if(sel && !sel.value){
2584
- alert('لطفاً شرح کالا یا خدمت را از لیست انتخاب کنید.');
2585
- return;
2586
- }
2587
- const qty = parseFloat(row.querySelector('.row-quantity')?.value) || 0;
2588
- if(qty <= 0){
2589
- alert('مقدار کالا باید بزرگتر از صفر باشد.');
2590
- return;
2591
- }
2592
- }
2593
- if(typeof oldSave === 'function') return oldSave();
2594
- };
2595
-
2596
- window.EasyFactorHealth = {
2597
- version: '4.8-landscape-currency',
2598
- storage: 'localStorage',
2599
- checks(){
2600
- return {
2601
- rtl: document.documentElement.dir === 'rtl',
2602
- storage: !!window.localStorage,
2603
- printReady: !!document.getElementById('printable-invoice')
2604
- };
2605
- }
2606
- };
2607
-})();
2608
-</script>
1711
2610
-</body>
2611
-</html>
1712
+ const