فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix/a07-version-and-startup-banner
a02/strict-export-preflight-20261018 audit/a01-readonly-invoice-metadata-20261101 ci/a06-require-trusted-issuer-for-release ci/main-postmerge-phase-a-validation-20261020 ci/phase-a-controlled-public-release design/issue-5-commercial-corrections-adr docs/a01-a02-a05-oct23-verified-evidence docs/a01-cheque-endorsement-evidence-20261022 docs/a01-cheque-event-date-evidence-20261021 docs/a01-explicit-refund-reason-evidence-20261021 docs/a01-refund-auth-status-20261020 docs/a01-refund-trace-evidence-20261020 docs/a02-102-evidence-20261018 docs/a02-pr104-evidence-20261018 docs/a02-pr106-evidence-20261019 docs/a02-pr108-ten-tests-20261019 docs/a02-private-sql-backup-evidence-20261111 docs/a03-merge-status-sync-20261020 docs/a04-software-gate-acceptance-20261020 docs/feature-matrix-20261014 docs/finora-master-execution-playbook docs/four-phase-execution-20261014 docs/four-phase-roadmap-20261014 docs/holoo-lab-stabilization-phase1-20261111 docs/holoo-runtime-schema-audit-20261111 docs/ops-142-governance-5-1-3-20261030 docs/phase-a-a01-a02-a06-a08-verified-evidence-20261023 docs/phase-a-a01-a05-a06-evidence-20261023 docs/phase-a-independent-acceptance-evidence docs/phase-a-pr110-evidence-20261019 docs/project-status-phase-a-20261014 feat/a01-referenced-return-corrections feat/a01-referenced-returns-on-main feat/a02-atomic-opening-ledger-preflight feat/a02-holoo-compatibility-preflight feat/a02-holoo-declared-control-totals feat/a02-holoo-explicit-csv-gate feat/a02-holoo-safe-zip-intake-offline-webview2-20261030 feat/a02-offline-sql-server-provisioning-20261030 feat/a02-opening-balance-dry-run feat/a02-opening-ledger-admin-ui feat/a02-opt-in-isolated-sql-restore-executor-20261030 feat/a02-private-holoo-zip-staging-20261030 feat/a02-safe-isolated-restore-plan-20261030 feat/a02-sql-backup-header-verifyonly-20261030 feat/a03-audit-schema-atomic-events feat/a03-complete-manual-journal-audit feat/a05-cheque-treasury-reconciliation feat/a06-signed-offline-license-activation feat/a08-synthetic-performance-baseline feat/phase-a-accounting-benchmark-return-preview feat/phase-a-ledger-settlement-diagnostics feature/v2-reconciliation-20261013 fix/a01-atomic-confirm-ui-one-shot-20261031 fix/a01-cheque-clearance-explicit-account-20261023 fix/a01-cheque-contractual-due-date-validity-20261023 fix/a01-cheque-endorsement-counterparty-20261022 fix/a01-cheque-event-date-open-period-20261021 fix/a01-cumulative-return-amount-cap fix/a01-explicit-refund-reason-approval-20261021 fix/a01-manager-authorized-customer-refunds-20261020 fix/a01-no-implicit-refund fix/a01-one-shot-confirm-on-atomic-import-20261031 fix/a01-refund-and-overcollection-net-cash fix/a01-refund-correction-trace-20261020 fix/a02-atomic-excel-master-merge-20261031 fix/a02-canonical-mapping-contract-20261018 fix/a02-disable-destructive-excel-replace-20261031 fix/a02-holoo-invoice-line-coverage-20261023 fix/a02-holoo-preflight-required-invoice-lines-20261023 fix/a02-mapping-contract-20261018 fix/a02-opening-preflight-unbalanced-report fix/a02-orphan-mapping-20261018 fix/a02-private-excel-import-session-20261031 fix/a02-strict-export-input-20261019 fix/a03-append-only-full-backup-import fix/a03-append-only-write-guard fix/a03-block-transaction-clear-append-only-20261016 fix/a03-chain-validation-20261020 fix/a03-company-scoped-audit-data-access fix/a03-deny-direct-audit-write-20261019 fix/a03-escaped-expense-list-20261031 fix/a03-escaped-financial-record-ids-20261031 fix/a03-financial-ledger-actions-and-print-20261031 fix/a04-backup-checksum-preflight fix/a04-company-audit-replay-stable-compare fix/a04-company-backup-source-isolation-20261020 fix/a04-full-restore-posted-financial-integrity fix/a04-reject-mixed-company-backup-20261019 fix/a04-replace-immutable-posted-ledger fix/a04-restore-financial-journal-references fix/a04-service-source-company-boundary-20261020 fix/a05-block-inactive-treasury-settlements fix/a05-cheque-cash-evidence-reconciliation-20261023 fix/a05-cheque-ledger-and-bank-reconciliation-20261023 fix/a05-fiscal-close-invariant-gates fix/a06-backup-restore-user-privileges fix/a06-license-user-company-quota-20261023 fix/a06-malformed-trial-state-fail-closed fix/a06-offline-clock-fail-closed-20261019 fix/a07-indexeddb-blocked-startup fix/a07-offline-bundled-assets fix/a07-version-and-startup-banner fix/issue-7-company-backup-isolation fix/p0-deterministic-fractional-invoice-money-20261031 fix/p0-fractional-quantity-input-20261031 fix/p0-fractional-quantity-integrated-20261031 fix/p0-invoice-posting-invariants-20261031 fix/p0-legacy-stock-and-product-inputs-20261031 fix/p0-reports-immutable-cogs-20261101 fix/p0-verified-financial-percent-20261031 fix/p0-zero-discount-report-revenue-20261101 fix/phase-a-backup-app-version fix/phase-a-backup-integrity-checksum fix/phase-a-backup-record-id-validation-20261014 fix/phase-a-backup-version-validation-20261014 fix/phase-a-closure-pack3-20261101 fix/phase-a-entitlement-payload-validation fix/phase-a-gate-exact-evidence-20261019 fix/phase-a-pack4-stock-scope-20261101 fix/phase-a-pack5-integrated-evidence-20261101 fix/phase-a-pack6-atomic-legacy-20261101 fix/phase-a-restore-envelope-and-rollback fix/phase-a-settings-admin-gate fix/print-browser-header-footer-20261014 fix/q01-expense-security-probe-exact-option-20261031 fix/q01-financial-grid-labels-20261031 fix/q01-form-label-association-20261031 fix/q01-native-evidence-integrity-20261030 fix/q01-number-input-persian-decimal-20261031 fix/q01-responsive-dashboard-and-cheque-table-20261031 fix/q01-safe-ui-action-audit-coverage-20261031 fix/q01-visible-desktop-sidebar-and-safe-confirm-20261030 fix/roadmap-metadata-sync-20261014 gate/a03-audit-metadata-validation-20261019 integration/a02-windows-holoo-setup-candidate-20261030 license-server main perf/a07-lazy-load-excel perf/a08-cheque-reconciliation-account-index-20261023 perf/a08-paginated-reports-20261101 phase1-restore-hardening planning/holoo-execution-20261013 planning/roadmap-project-management-20261014 qa/native-click-coverage-audit-20261030 release/v2.0.0 test/a01-native-endorsement-mandatory-20261023 test/a01-native-purchase-return-guardrails test/a01-native-sale-return-financial-guardrails test/a01-safe-integer-boundary-20261019 test/a02-native-opening-dry-run-rejections test/a02-native-positive-opening-ledger test/a04-native-corrupt-fbackup-20261016 test/a04-native-encrypted-company-backup test/a04-native-encrypted-company-backup-main test/a04-native-late-transaction-rollback test/a04-native-windows-backup-recovery test/a04-real-edge-v6-v7-migration test/a04-real-native-interrupted-restore test/a05-native-draft-ledger-and-repeat-close-20261016 test/a05-native-fiscal-close-guardrails test/a07-native-multipage-print-engine test/a07-native-origin-provenance test/a07-native-webview2-offline-routes test/a07-windows-offline-startup-smoke test/a08-installed-webview2-60k-baseline test/a08-native-webview2-heap-metrics test/a08-windows-synthetic-performance-baseline test/github-write-access-20261009 test/native-win-ui-routes-after-finance-backup test/phase-a-combined-a01-a05-a08-final-evidence test/phase-a-combined-native-acceptance-matrix test/phase-a-ledger-invariants-20261014 test/phase-a-native-all-routes-on-merged-lab test/phase-a-native-encrypted-backup test/phase-a-native-finance-backup-matrix test/phase-a-native-ui-and-backup-smoke test/phase-a-windows-native-installer-lab work/a08-dispatch-activation-20261123 work/a08-memory-stability-20261123 work/finance-curated-20261123
js 416 lines 18.8 KB
Raw
1 // ============================================================
2 // ChequesView — صفحه‌ی مدیریت چک‌ها
3 // ============================================================
4
5 import { NumberInput } from '../utils/NumberInput.js';
6 import { ChequeController } from '../controllers/ChequeController.js';
7 import { ContactController } from '../controllers/ContactController.js';
8 import { Modal } from '../core/Modal.js';
9 import { Toast } from '../core/Toast.js';
10 import { Formatters } from '../utils/Formatters.js';
11
12 let filter = { search: '', direction: '', status: '' };
13 let cache = { cheques: [], contacts: [], stats: {} };
14
15 class ChequesViewImpl {
16 async render() {
17 await this.reload();
18 return `
19 <div class="page-title">
20 <h2>چک‌ها</h2>
21 <p>مدیریت چک‌های دریافتی و پرداختی با شماره صیادی</p>
22 </div>
23
24 <div class="grid-kpi">
25 <div class="card" style="margin:0">
26 <div style="font-size:11px;color:var(--text-muted);margin-bottom:6px">کل چک‌ها</div>
27 <div style="font-size:20px;font-weight:800">${Formatters.number(cache.stats.total || 0)}</div>
28 <div style="font-size:11px;color:var(--text-muted);margin-top:4px">${Formatters.toPersianDigits(cache.stats.pending || 0)} در جریان</div>
29 </div>
30 <div class="card" style="margin:0">
31 <div style="font-size:11px;color:var(--text-muted);margin-bottom:6px">چک‌های دریافتی</div>
32 <div style="font-size:18px;font-weight:800;color:var(--success)">${Formatters.money(cache.stats.inboundAmount || 0)}</div>
33 <div style="font-size:11px;color:var(--text-muted);margin-top:4px">${Formatters.number(cache.stats.inbound || 0)} فقره</div>
34 </div>
35 <div class="card" style="margin:0">
36 <div style="font-size:11px;color:var(--text-muted);margin-bottom:6px">چک‌های پرداختی</div>
37 <div style="font-size:18px;font-weight:800;color:var(--danger)">${Formatters.money(cache.stats.outboundAmount || 0)}</div>
38 <div style="font-size:11px;color:var(--text-muted);margin-top:4px">${Formatters.number(cache.stats.outbound || 0)} فقره</div>
39 </div>
40 <div class="card" style="margin:0">
41 <div style="font-size:11px;color:var(--text-muted);margin-bottom:6px">مانده در جریان</div>
42 <div style="font-size:18px;font-weight:800;color:var(--warning)">${Formatters.money(cache.stats.pendingAmount || 0)}</div>
43 <div style="font-size:11px;color:var(--text-muted);margin-top:4px">جمع مبلغ چک‌های باز</div>
44 </div>
45 </div>
46
47 <div id="cheques-content">${this.renderContent()}</div>
48 `;
49 }
50
51 onMount() {
52 window.ChequesView = this;
53 }
54
55 async reload() {
56 cache.cheques = await ChequeController.getAll();
57 cache.contacts = await ContactController.getAll();
58 cache.stats = await ChequeController.getStats();
59 }
60
61 renderContent() {
62 let list = cache.cheques;
63 if (filter.search) {
64 const q = filter.search.toLowerCase();
65 list = list.filter(c =>
66 (c.contactName || '').toLowerCase().includes(q) ||
67 (c.sayadNumber || '').includes(q) ||
68 (c.bankName || '').toLowerCase().includes(q)
69 );
70 }
71 if (filter.direction) list = list.filter(c => c.direction === filter.direction);
72 if (filter.status) list = list.filter(c => c.status === filter.status);
73
74 const rows = list.length === 0
75 ? `<tr><td colspan="9"><div class="empty-state"><div class="icon">💳</div><h3>هیچ چکی ثبت نشده</h3><p>اولین چک دریافتی یا پرداختی خود را ثبت کنید</p><button class="btn" onclick="window.ChequesView.openChequeModal()">➕ چک جدید</button></div></td></tr>`
76 : list.map(c => {
77 const today = new Date();
78 const due = new Date(c.dueDate ? this._parseJalali(c.dueDate) : new Date());
79 const diffDays = Math.ceil((due - today) / (1000 * 60 * 60 * 24));
80 const isOverdue = diffDays < 0 && c.status === 'pending';
81 const isSoon = diffDays >= 0 && diffDays <= 7 && c.status === 'pending';
82
83 let dueDisplay = Formatters.toPersianDigits(c.dueDate || '—');
84 if (isOverdue) dueDisplay += ` <span class="badge badge-danger" style="font-size:9px">${Formatters.toPersianDigits(Math.abs(diffDays))} روز گذشته</span>`;
85 else if (isSoon) dueDisplay += ` <span class="badge badge-warning" style="font-size:9px">${Formatters.toPersianDigits(diffDays)} روز مانده</span>`;
86
87 return `
88 <tr>
89 <td>
90 <span class="badge ${c.direction === 'inbound' ? 'badge-success' : 'badge-danger'}">
91 ${c.direction === 'inbound' ? '📥 دریافتی' : '📤 پرداختی'}
92 </span>
93 </td>
94 <td><strong>${this._esc(c.contactName || '—')}</strong></td>
95 <td style="font-family:monospace;font-size:11.5px">${Formatters.toPersianDigits(c.sayadNumber || '—')}</td>
96 <td>${this._esc(c.bankName || '—')}</td>
97 <td style="font-weight:700">${Formatters.money(c.amount)}</td>
98 <td>${dueDisplay}</td>
99 <td>${Formatters.toPersianDigits(c.issueDate || '—')}</td>
100 <td>
101 <span class="badge ${ChequeController.getStatusClass(c.status)}">
102 ${ChequeController.getStatusLabel(c.status)}
103 </span>
104 </td>
105 <td>
106 <div class="row-actions">
107 <button class="icon-btn-sm" title="تغییر وضعیت" onclick="window.ChequesView.changeStatus('${c.id}')">🔄</button>
108 <button class="icon-btn-sm" title="ویرایش" onclick="window.ChequesView.editCheque('${c.id}')">✏️</button>
109 <button class="icon-btn-sm danger" title="حذف" onclick="window.ChequesView.deleteCheque('${c.id}')">🗑️</button>
110 </div>
111 </td>
112 </tr>
113 `;
114 }).join('');
115
116 return `
117 <div class="toolbar">
118 <div class="search-input-wrap">
119 <span class="icon">🔍</span>
120 <input type="text" class="form-control" placeholder="جستجو بر اساس طرف حساب، صیادی یا بانک..." value="${this._esc(filter.search)}" oninput="window.ChequesView._onSearch(this.value)" />
121 </div>
122 <select class="form-control" style="width:auto;min-width:130px" onchange="window.ChequesView._onFilter('direction', this.value)">
123 <option value="">همه انواع</option>
124 <option value="inbound" ${filter.direction === 'inbound' ? 'selected' : ''}>دریافتی</option>
125 <option value="outbound" ${filter.direction === 'outbound' ? 'selected' : ''}>پرداختی</option>
126 </select>
127 <select class="form-control" style="width:auto;min-width:130px" onchange="window.ChequesView._onFilter('status', this.value)">
128 <option value="">همه وضعیت‌ها</option>
129 <option value="pending" ${filter.status === 'pending' ? 'selected' : ''}>در جریان</option>
130 <option value="cleared" ${filter.status === 'cleared' ? 'selected' : ''}>وصول شده</option>
131 <option value="bounced" ${filter.status === 'bounced' ? 'selected' : ''}>برگشتی</option>
132 <option value="returned" ${filter.status === 'returned' ? 'selected' : ''}>عودت داده شده</option>
133 </select>
134 <button class="btn" onclick="window.ChequesView.openChequeModal()">➕ چک جدید</button>
135 </div>
136
137 <div class="table-wrap">
138 <table>
139 <thead>
140 <tr>
141 <th style="width:110px">نوع</th>
142 <th>طرف حساب</th>
143 <th style="width:160px">شماره صیادی</th>
144 <th style="width:110px">بانک</th>
145 <th style="width:140px">مبلغ</th>
146 <th style="width:170px">سررسید</th>
147 <th style="width:100px">تاریخ صدور</th>
148 <th style="width:110px">وضعیت</th>
149 <th style="width:130px">عملیات</th>
150 </tr>
151 </thead>
152 <tbody>${rows}</tbody>
153 </table>
154 </div>
155 `;
156 }
157
158 _onSearch(val) {
159 filter.search = val;
160 document.getElementById('cheques-content').innerHTML = this.renderContent();
161 const input = document.querySelector('#cheques-content input[type="text"]');
162 if (input) { input.focus(); input.setSelectionRange(val.length, val.length); }
163 }
164
165 _onFilter(key, val) {
166 filter[key] = val;
167 document.getElementById('cheques-content').innerHTML = this.renderContent();
168 }
169
170 // ============================================================
171 // فرم چک
172 // ============================================================
173 async openChequeModal(chequeId = null) {
174 const cheque = chequeId ? await ChequeController.get(chequeId) : null;
175 const isEdit = !!cheque;
176 const d = cheque || {
177 direction: 'inbound',
178 contactId: null,
179 sayadNumber: '',
180 bankName: '',
181 branchName: '',
182 accountNumber: '',
183 holderName: '',
184 amount: 0,
185 issueDate: this._todayJalali(),
186 dueDate: this._todayJalali(),
187 description: ''
188 };
189
190 const contactOptions = cache.contacts.map(c =>
191 `<option value="${c.id}" ${d.contactId === c.id ? 'selected' : ''}>${this._esc(c.name)}</option>`
192 ).join('');
193
194 const body = `
195 <div class="form-row">
196 <div class="form-group">
197 <label class="form-label">نوع چک <span class="req">*</span></label>
198 <select class="form-control" id="chqDirection">
199 <option value="inbound" ${d.direction === 'inbound' ? 'selected' : ''}>دریافتی (از مشتری)</option>
200 <option value="outbound" ${d.direction === 'outbound' ? 'selected' : ''}>پرداختی (به تامین‌کننده)</option>
201 </select>
202 </div>
203 <div class="form-group">
204 <label class="form-label">طرف حساب</label>
205 <select class="form-control" id="chqContact">
206 <option value="">— انتخاب کنید —</option>
207 ${contactOptions}
208 </select>
209 </div>
210 </div>
211
212 <div class="form-row">
213 <div class="form-group">
214 <label class="form-label">شماره صیادی (۱۶ رقم) <span class="req">*</span></label>
215 <input type="text" class="form-control" id="chqSayad" value="${this._esc(d.sayadNumber)}" maxlength="16" placeholder="۱۶ رقم" />
216 </div>
217 <div class="form-group">
218 <label class="form-label">مبلغ (ریال) <span class="req">*</span></label>
219 <input type="text" inputmode="numeric" class="form-control" id="chqAmount" value="${NumberInput.format(d.amount || 0)}" />
220 </div>
221 </div>
222
223 <div class="form-row">
224 <div class="form-group">
225 <label class="form-label">بانک</label>
226 <input type="text" class="form-control" id="chqBank" value="${this._esc(d.bankName)}" placeholder="مثلاً ملی" />
227 </div>
228 <div class="form-group">
229 <label class="form-label">شعبه</label>
230 <input type="text" class="form-control" id="chqBranch" value="${this._esc(d.branchName)}" />
231 </div>
232 </div>
233
234 <div class="form-row">
235 <div class="form-group">
236 <label class="form-label">شماره حساب</label>
237 <input type="text" class="form-control" id="chqAccount" value="${this._esc(d.accountNumber)}" />
238 </div>
239 <div class="form-group">
240 <label class="form-label">نام صاحب حساب</label>
241 <input type="text" class="form-control" id="chqHolder" value="${this._esc(d.holderName)}" />
242 </div>
243 </div>
244
245 <div class="form-row">
246 <div class="form-group">
247 <label class="form-label">تاریخ صدور (شمسی)</label>
248 <input type="text" class="form-control" id="chqIssueDate" value="${this._esc(d.issueDate)}" placeholder="1405/06/27" />
249 </div>
250 <div class="form-group">
251 <label class="form-label">تاریخ سررسید (شمسی) <span class="req">*</span></label>
252 <input type="text" class="form-control" id="chqDueDate" value="${this._esc(d.dueDate)}" placeholder="1405/06/27" />
253 </div>
254 </div>
255
256 <div class="form-group">
257 <label class="form-label">توضیحات</label>
258 <textarea class="form-control" id="chqDescription" rows="2">${this._esc(d.description)}</textarea>
259 </div>
260 `;
261
262 const footer = `
263 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
264 <button class="btn" onclick="window.ChequesView.saveCheque(${isEdit ? `'${chequeId}'` : 'null'})">💾 ذخیره</button>
265 `;
266
267 Modal.open({ title: isEdit ? 'ویرایش چک' : 'چک جدید', body, footer, size: 'md' });
268 }
269
270 async saveCheque(id) {
271 const contactId = document.getElementById('chqContact').value || null;
272 const contact = contactId ? cache.contacts.find(c => c.id === contactId) : null;
273
274 const data = {
275 direction: document.getElementById('chqDirection').value,
276 contactId,
277 contactName: contact?.name || '',
278 sayadNumber: document.getElementById('chqSayad').value,
279 bankName: document.getElementById('chqBank').value,
280 branchName: document.getElementById('chqBranch').value,
281 accountNumber: document.getElementById('chqAccount').value,
282 holderName: document.getElementById('chqHolder').value,
283 amount: NumberInput.parse(document.getElementById('chqAmount').value),
284 issueDate: document.getElementById('chqIssueDate').value,
285 dueDate: document.getElementById('chqDueDate').value,
286 description: document.getElementById('chqDescription').value
287 };
288
289 if (!data.sayadNumber.trim()) { Toast.warning('شماره صیادی الزامی است'); return; }
290 if (data.amount <= 0) { Toast.warning('مبلغ معتبر نیست'); return; }
291 if (!data.dueDate.trim()) { Toast.warning('سررسید الزامی است'); return; }
292
293 try {
294 if (id) {
295 await ChequeController.update(id, data);
296 Toast.success('چک ویرایش شد');
297 } else {
298 await ChequeController.create(data);
299 Toast.success('چک ثبت شد');
300 }
301 Modal.close();
302 await this.reload();
303 document.getElementById('cheques-content').innerHTML = this.renderContent();
304 } catch (err) {
305 Toast.error('خطا: ' + err.message);
306 }
307 }
308
309 async editCheque(id) {
310 await this.openChequeModal(id);
311 }
312
313 async changeStatus(id) {
314 const cheque = cache.cheques.find(c => c.id === id);
315 if (!cheque) return;
316
317 const statuses = [
318 { value: 'pending', label: 'در جریان' },
319 { value: 'cleared', label: 'وصول شده' },
320 { value: 'bounced', label: 'برگشتی' },
321 { value: 'returned', label: 'عودت داده شده' },
322 { value: 'spent', label: 'خرج شده (به شخص دیگر واگذار شد)' }
323 ];
324
325 const body = `
326 <p style="font-size:13px;margin-bottom:14px;color:var(--text-muted)">وضعیت فعلی: <strong>${ChequeController.getStatusLabel(cheque.status)}</strong></p>
327 <div class="form-group">
328 <label class="form-label">وضعیت جدید</label>
329 <select class="form-control" id="newStatus">
330 ${statuses.map(s => `<option value="${s.value}" ${cheque.status === s.value ? 'selected' : ''}>${s.label}</option>`).join('')}
331 </select>
332 </div>
333 `;
334 const footer = `
335 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
336 <button class="btn" onclick="window.ChequesView._applyStatusChange('${id}')">اعمال</button>
337 `;
338 Modal.open({ title: 'تغییر وضعیت چک', body, footer, size: 'sm' });
339 }
340
341 async _applyStatusChange(id) {
342 const status = document.getElementById('newStatus').value;
343 try {
344 await ChequeController.changeStatus(id, status);
345 Toast.success('وضعیت چک تغییر کرد');
346 Modal.close();
347 await this.reload();
348 document.getElementById('cheques-content').innerHTML = this.renderContent();
349 } catch (err) {
350 Toast.error('خطا: ' + err.message);
351 }
352 }
353
354 async deleteCheque(id) {
355 const c = cache.cheques.find(x => x.id === id);
356 Modal.confirm({
357 title: 'حذف چک',
358 message: `آیا از حذف چک ${Formatters.toPersianDigits(c?.sayadNumber || '')} مطمئن هستید؟`,
359 confirmText: 'حذف',
360 danger: true,
361 onConfirm: async () => {
362 await ChequeController.delete(id);
363 Toast.success('چک حذف شد');
364 await this.reload();
365 document.getElementById('cheques-content').innerHTML = this.renderContent();
366 }
367 });
368 }
369
370 _todayJalali() {
371 const d = new Date();
372 const gy = d.getFullYear(), gm = d.getMonth() + 1, gd = d.getDate();
373 const g_d_m = [0,31,59,90,120,151,181,212,243,273,304,334];
374 let jy = (gy <= 1600) ? 0 : 979;
375 let gy2 = gy - (gy <= 1600 ? 621 : 1600);
376 const gyAdj = (gm > 2) ? (gy2 + 1) : gy2;
377 let days = (365 * gy2) + Math.floor((gyAdj + 3) / 4) - Math.floor((gyAdj + 99) / 100) + Math.floor((gyAdj + 399) / 400) - 80 + gd + g_d_m[gm - 1];
378 jy += 33 * Math.floor(days / 12053);
379 days %= 12053;
380 jy += 4 * Math.floor(days / 1461);
381 days %= 1461;
382 if (days > 365) { jy += Math.floor((days - 1) / 365); days = (days - 1) % 365; }
383 const jm = (days < 186) ? 1 + Math.floor(days / 31) : 7 + Math.floor((days - 186) / 30);
384 const jd = 1 + ((days < 186) ? (days % 31) : ((days - 186) % 30));
385 return `${jy}/${String(jm).padStart(2, '0')}/${String(jd).padStart(2, '0')}`;
386 }
387
388 _parseJalali(str) {
389 if (!str) return new Date();
390 const parts = str.split('/').map(Number);
391 if (parts.length !== 3) return new Date();
392 const [jy, jm, jd] = parts;
393 let gy = (jy <= 979) ? 621 : 1600;
394 let jy2 = jy - (jy <= 979 ? 0 : 979);
395 let days = (365 * jy2) + (Math.floor(jy2 / 33) * 8) + Math.floor(((jy2 % 33) + 3) / 4) + 78 + jd + ((jm < 7) ? (jm - 1) * 31 : ((jm - 7) * 30) + 186);
396 gy += 400 * Math.floor(days / 146097);
397 days %= 146097;
398 if (days > 36524) { gy += 100 * Math.floor(--days / 36524); days %= 36524; if (days >= 365) days++; }
399 gy += 4 * Math.floor(days / 1461);
400 days %= 1461;
401 if (days > 365) { gy += Math.floor((days - 1) / 365); days = (days - 1) % 365; }
402 let gd = days + 1;
403 const sal_a = [0,31,((gy % 4 === 0 && gy % 100 !== 0) || (gy % 400 === 0)) ? 29 : 28,31,30,31,30,31,31,30,31,30,31];
404 let gm = 0;
405 for (gm = 0; gm < 13 && gd > sal_a[gm]; gm++) gd -= sal_a[gm];
406 return new Date(gy, gm - 1, gd);
407 }
408
409 _esc(s) {
410 if (!s) return '';
411 return String(s).replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
412 }
413 }
414
415 export const ChequesView = new ChequesViewImpl();
416 window.ChequesView = ChequesView;