فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
docs/feature-matrix-20261014
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
| 1 | // ============================================================ |
| 2 | // InvoicePrint — چاپ فاکتور با ۳ قالب و تنظیمات زنده |
| 3 | // ============================================================ |
| 4 | |
| 5 | import { InvoiceController } from '../controllers/InvoiceController.js'; |
| 6 | import { ContactController } from '../controllers/ContactController.js'; |
| 7 | import { StorageService } from '../core/StorageService.js'; |
| 8 | import { DataScope } from '../core/DataScope.js'; |
| 9 | import { Auth } from '../core/Auth.js'; |
| 10 | import { Modal } from '../core/Modal.js'; |
| 11 | import { Toast } from '../core/Toast.js'; |
| 12 | import { Formatters } from '../utils/Formatters.js'; |
| 13 | import { numberToWords } from '../utils/NumberToWords.js'; |
| 14 | |
| 15 | class InvoicePrintImpl { |
| 16 | constructor() { |
| 17 | this.currentInvoiceId = null; |
| 18 | this.settings = { |
| 19 | template: 'non_formal', |
| 20 | paperSize: 'A4', |
| 21 | orientation: 'portrait', |
| 22 | showSignature: true, |
| 23 | showCode: true, |
| 24 | themeColor: '#0d9488', |
| 25 | showBalance: 'none' |
| 26 | }; |
| 27 | } |
| 28 | |
| 29 | async openSettings(invoiceId) { |
| 30 | this.currentInvoiceId = invoiceId; |
| 31 | const inv = await InvoiceController.get(invoiceId); |
| 32 | if (!inv) { Toast.error('فاکتور یافت نشد'); return; } |
| 33 | |
| 34 | if (inv.isPreInvoice) { |
| 35 | this.settings.template = 'non_formal'; |
| 36 | } else if (inv.kind === 'formal') { |
| 37 | this.settings.template = 'formal'; |
| 38 | } else { |
| 39 | this.settings.template = 'non_formal'; |
| 40 | } |
| 41 | |
| 42 | const body = ` |
| 43 | <div class="form-group"> |
| 44 | <label class="form-label">قالب چاپ</label> |
| 45 | <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px"> |
| 46 | <label class="print-tpl-card ${this.settings.template === 'formal' ? 'active' : ''}" data-tpl="formal"> |
| 47 | <input type="radio" name="tpl" value="formal" ${this.settings.template === 'formal' ? 'checked' : ''} style="display:none" /> |
| 48 | <div style="font-size:24px">📋</div> |
| 49 | <div style="font-weight:700;font-size:12.5px;margin-top:4px">فاکتور رسمی</div> |
| 50 | <div style="font-size:10.5px;color:var(--text-muted);margin-top:2px">مطابق مالیاتی</div> |
| 51 | </label> |
| 52 | <label class="print-tpl-card ${this.settings.template === 'non_formal' ? 'active' : ''}" data-tpl="non_formal"> |
| 53 | <input type="radio" name="tpl" value="non_formal" ${this.settings.template === 'non_formal' ? 'checked' : ''} style="display:none" /> |
| 54 | <div style="font-size:24px">📄</div> |
| 55 | <div style="font-weight:700;font-size:12.5px;margin-top:4px">غیررسمی</div> |
| 56 | <div style="font-size:10.5px;color:var(--text-muted);margin-top:2px">فروشگاهی مدرن</div> |
| 57 | </label> |
| 58 | <label class="print-tpl-card ${this.settings.template === 'thermal' ? 'active' : ''}" data-tpl="thermal"> |
| 59 | <input type="radio" name="tpl" value="thermal" ${this.settings.template === 'thermal' ? 'checked' : ''} style="display:none" /> |
| 60 | <div style="font-size:24px">🧾</div> |
| 61 | <div style="font-weight:700;font-size:12.5px;margin-top:4px">فیش حرارتی</div> |
| 62 | <div style="font-size:10.5px;color:var(--text-muted);margin-top:2px">۸۰ میلیمتری</div> |
| 63 | </label> |
| 64 | </div> |
| 65 | </div> |
| 66 | |
| 67 | <div class="form-row"> |
| 68 | <div class="form-group"> |
| 69 | <label class="form-label">اندازه کاغذ</label> |
| 70 | <select class="form-control" id="prPaper"> |
| 71 | <option value="A4" ${this.settings.paperSize === 'A4' ? 'selected' : ''}>A4</option> |
| 72 | <option value="A5" ${this.settings.paperSize === 'A5' ? 'selected' : ''}>A5</option> |
| 73 | </select> |
| 74 | </div> |
| 75 | <div class="form-group"> |
| 76 | <label class="form-label">جهت صفحه</label> |
| 77 | <select class="form-control" id="prOrientation"> |
| 78 | <option value="portrait" ${this.settings.orientation === 'portrait' ? 'selected' : ''}>عمودی</option> |
| 79 | <option value="landscape" ${this.settings.orientation === 'landscape' ? 'selected' : ''}>افقی</option> |
| 80 | </select> |
| 81 | </div> |
| 82 | <div class="form-group"> |
| 83 | <label class="form-label">رنگ سربرگ</label> |
| 84 | <input type="color" class="form-control" id="prColor" value="${this.settings.themeColor}" style="height:42px;padding:4px" /> |
| 85 | </div> |
| 86 | </div> |
| 87 | |
| 88 | <div class="form-group"> |
| 89 | <label style="display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px"> |
| 90 | <input type="checkbox" id="prSignature" ${this.settings.showSignature ? 'checked' : ''} /> |
| 91 | نمایش محل مهر و امضا |
| 92 | </label> |
| 93 | </div> |
| 94 | |
| 95 | <div class="form-group"> |
| 96 | <label style="display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px"> |
| 97 | <input type="checkbox" id="prCode" ${this.settings.showCode ? 'checked' : ''} /> |
| 98 | نمایش کد کالا در جدول |
| 99 | </label> |
| 100 | </div> |
| 101 | |
| 102 | <div class="form-group"> |
| 103 | <label class="form-label">نمایش وضعیت حساب مشتری</label> |
| 104 | <select class="form-control" id="prBalance"> |
| 105 | <option value="none" ${this.settings.showBalance === 'none' ? 'selected' : ''}>عدم نمایش</option> |
| 106 | <option value="simple" ${this.settings.showBalance === 'simple' ? 'selected' : ''}>فقط مانده فعلی</option> |
| 107 | </select> |
| 108 | </div> |
| 109 | `; |
| 110 | |
| 111 | const footer = ` |
| 112 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button> |
| 113 | <button class="btn btn-secondary" onclick="window.InvoicePrint._preview()">👁️ پیشنمایش</button> |
| 114 | <button class="btn" onclick="window.InvoicePrint._print()">🖨️ چاپ</button> |
| 115 | `; |
| 116 | |
| 117 | Modal.open({ title: 'تنظیمات چاپ فاکتور', body, footer, size: 'md' }); |
| 118 | |
| 119 | setTimeout(() => { |
| 120 | document.querySelectorAll('.print-tpl-card').forEach(card => { |
| 121 | card.addEventListener('click', () => { |
| 122 | document.querySelectorAll('.print-tpl-card').forEach(c => c.classList.remove('active')); |
| 123 | card.classList.add('active'); |
| 124 | card.querySelector('input').checked = true; |
| 125 | }); |
| 126 | }); |
| 127 | }, 50); |
| 128 | } |
| 129 | |
| 130 | _collectSettings() { |
| 131 | const tpl = document.querySelector('input[name="tpl"]:checked'); |
| 132 | if (tpl) this.settings.template = tpl.value; |
| 133 | |
| 134 | const paper = document.getElementById('prPaper'); |
| 135 | if (paper) this.settings.paperSize = paper.value; |
| 136 | |
| 137 | const orientation = document.getElementById('prOrientation'); |
| 138 | if (orientation) this.settings.orientation = orientation.value; |
| 139 | |
| 140 | const color = document.getElementById('prColor'); |
| 141 | if (color) this.settings.themeColor = color.value; |
| 142 | |
| 143 | const sig = document.getElementById('prSignature'); |
| 144 | if (sig) this.settings.showSignature = sig.checked; |
| 145 | |
| 146 | const code = document.getElementById('prCode'); |
| 147 | if (code) this.settings.showCode = code.checked; |
| 148 | |
| 149 | const bal = document.getElementById('prBalance'); |
| 150 | if (bal) this.settings.showBalance = bal.value; |
| 151 | |
| 152 | return this.settings; |
| 153 | } |
| 154 | |
| 155 | async _preview() { |
| 156 | this._collectSettings(); |
| 157 | const html = await this._buildHtml(this.currentInvoiceId); |
| 158 | const body = ` |
| 159 | <div style="background:#e5e7eb;padding:20px;border-radius:8px;overflow:auto;max-height:70vh"> |
| 160 | <div style="background:#fff;margin:0 auto;max-width:${this.settings.template === 'thermal' ? '80mm' : '210mm'};box-shadow:0 4px 20px rgba(0,0,0,.15)"> |
| 161 | ${html} |
| 162 | </div> |
| 163 | </div> |
| 164 | `; |
| 165 | const footer = ` |
| 166 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">بستن</button> |
| 167 | <button class="btn" onclick="window.InvoicePrint._print()">🖨️ چاپ</button> |
| 168 | `; |
| 169 | Modal.open({ title: 'پیشنمایش چاپ', body, footer, size: 'lg' }); |
| 170 | } |
| 171 | |
| 172 | async _print() { |
| 173 | this._collectSettings(); |
| 174 | const html = await this._buildHtml(this.currentInvoiceId); |
| 175 | this._openPrintWindow(html); |
| 176 | Modal.close(); |
| 177 | } |
| 178 | |
| 179 | async _buildHtml(invoiceId) { |
| 180 | const inv = await InvoiceController.get(invoiceId); |
| 181 | if (!inv) throw new Error('فاکتور یافت نشد'); |
| 182 | |
| 183 | const companyId = await DataScope.companyId(); |
| 184 | const seller = await StorageService.get('companies', companyId) || { |
| 185 | name: 'شرکت شما', |
| 186 | phone: '', address: '', national_id: '', economic_code: '', |
| 187 | reg_number: '', postal_code: '', footer: '' |
| 188 | }; |
| 189 | |
| 190 | const matchedContact = inv.contactId ? await StorageService.get('contacts', inv.contactId) : null; |
| 191 | const contact = matchedContact?.companyId === companyId ? matchedContact : {}; |
| 192 | |
| 193 | let balance = 0; |
| 194 | if (this.settings.showBalance !== 'none' && inv.contactId) { |
| 195 | balance = await ContactController.getBalance(inv.contactId); |
| 196 | } |
| 197 | |
| 198 | if (this.settings.template === 'formal') { |
| 199 | return this._formalTemplate(inv, seller, contact, balance); |
| 200 | } else if (this.settings.template === 'thermal') { |
| 201 | return this._thermalTemplate(inv, seller, contact); |
| 202 | } else { |
| 203 | return this._nonFormalTemplate(inv, seller, contact, balance); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // ------------------------------------------------------------ |
| 208 | // قالب فاکتور رسمی |
| 209 | // ------------------------------------------------------------ |
| 210 | _formalTemplate(inv, seller, contact, balance) { |
| 211 | const color = this.settings.themeColor; |
| 212 | |
| 213 | const headerTitle = inv.isPreInvoice |
| 214 | ? 'پیشفاکتور فروش کالا و خدمات' |
| 215 | : 'صورتحساب فروش کالا و خدمات'; |
| 216 | |
| 217 | const items = inv.items.map((it, idx) => { |
| 218 | const qty = Number(it.qty) || 0; |
| 219 | const price = Number(it.price) || 0; |
| 220 | const lineSub = qty * price; |
| 221 | const disc = Number(it.discount) || 0; |
| 222 | const afterDisc = lineSub - disc; |
| 223 | const vat = inv.vatEnabled ? Math.round(afterDisc * (Number(inv.vatRate) || 0) / 100) : 0; |
| 224 | const net = afterDisc + vat; |
| 225 | return ` |
| 226 | <tr> |
| 227 | <td>${Formatters.toPersianDigits(idx + 1)}</td> |
| 228 | <td style="text-align:right">${this._esc(it.productName)}</td> |
| 229 | <td>${Formatters.toPersianDigits(qty)}</td> |
| 230 | <td>${this._esc(it.unit || 'عدد')}</td> |
| 231 | <td>${Formatters.number(price)}</td> |
| 232 | <td>${Formatters.number(lineSub)}</td> |
| 233 | <td>${Formatters.number(disc)}</td> |
| 234 | <td>${Formatters.number(vat)}</td> |
| 235 | <td style="font-weight:700">${Formatters.number(net)}</td> |
| 236 | </tr> |
| 237 | `; |
| 238 | }).join(''); |
| 239 | |
| 240 | const balanceHtml = this.settings.showBalance === 'simple' && balance !== 0 ? ` |
| 241 | <div style="margin-top:6px;padding:6px 10px;background:#fef3c7;border-radius:6px;font-size:10px"> |
| 242 | <strong>مانده حساب فعلی مشتری:</strong> |
| 243 | ${balance > 0 ? Formatters.money(balance) + ' بدهکار' : Formatters.money(Math.abs(balance)) + ' بستانکار'} |
| 244 | </div> |
| 245 | ` : ''; |
| 246 | |
| 247 | return ` |
| 248 | <div class="print-doc" dir="rtl" style="direction:rtl;text-align:right;font-family:'Vazirmatn FD',Tahoma,sans-serif;color:#000;padding:6mm"> |
| 249 | <div style="position:relative;min-height:65px;margin-bottom:8px;display:flex;align-items:flex-start;justify-content:center;padding:10px 0 6px"> |
| 250 | <h1 style="font-size:17px;margin:0;font-weight:bold;color:#111;text-align:center">${headerTitle}</h1> |
| 251 | <div style="position:absolute;left:0;top:4px;direction:rtl;text-align:right;font-size:10.5px;line-height:2;white-space:nowrap"> |
| 252 | <div style="display:grid;grid-template-columns:86px auto;column-gap:5px;align-items:baseline"> |
| 253 | <span>شماره سریال:</span><strong>${Formatters.toPersianDigits(inv.number)}</strong> |
| 254 | <span>تاریخ صدور:</span><strong>${Formatters.toPersianDigits(inv.date)}</strong> |
| 255 | </div> |
| 256 | </div> |
| 257 | </div> |
| 258 | |
| 259 | <table style="width:100%;border-collapse:collapse;border:1.5px solid ${color};font-size:10.5px;margin-bottom:4px"> |
| 260 | <tr style="background:#f8fafc;font-weight:bold"> |
| 261 | <td colspan="4" style="border:1px solid ${color};padding:3px 8px;color:${color}">الف) مشخصات فروشنده</td> |
| 262 | </tr> |
| 263 | <tr> |
| 264 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:15%;background:#f1f5f9">نام شخص حقیقی/حقوقی:</td> |
| 265 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:35%"><strong>${this._esc(seller.name)}</strong></td> |
| 266 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:15%;background:#f1f5f9">شماره اقتصادی:</td> |
| 267 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:35%">${this._esc(seller.economic_code || '—')}</td> |
| 268 | </tr> |
| 269 | <tr> |
| 270 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">شناسه ملی / شماره ثبت:</td> |
| 271 | <td style="border:1px solid #cbd5e1;padding:4px 8px">${this._esc(seller.national_id || '—')} / ${this._esc(seller.reg_number || '—')}</td> |
| 272 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">کد پستی ۱۰ رقمی:</td> |
| 273 | <td style="border:1px solid #cbd5e1;padding:4px 8px">${Formatters.toPersianDigits(seller.postal_code || '—')}</td> |
| 274 | </tr> |
| 275 | <tr> |
| 276 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">نشانی و تلفن:</td> |
| 277 | <td colspan="3" style="border:1px solid #cbd5e1;padding:4px 8px">${this._esc(seller.address || '—')}${seller.phone ? ' | تلفن: ' + Formatters.phone(seller.phone) : ''}</td> |
| 278 | </tr> |
| 279 | </table> |
| 280 | |
| 281 | <table style="width:100%;border-collapse:collapse;border:1.5px solid ${color};font-size:10.5px;margin-bottom:4px"> |
| 282 | <tr style="background:#f8fafc;font-weight:bold"> |
| 283 | <td colspan="4" style="border:1px solid ${color};padding:3px 8px;color:${color}">ب) مشخصات خریدار</td> |
| 284 | </tr> |
| 285 | <tr> |
| 286 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:15%;background:#f1f5f9">نام شخص حقیقی/حقوقی:</td> |
| 287 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:35%"><strong>${this._esc(contact.name || inv.contactName || '—')}</strong></td> |
| 288 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:15%;background:#f1f5f9">شماره اقتصادی:</td> |
| 289 | <td style="border:1px solid #cbd5e1;padding:4px 8px;width:35%">${this._esc(contact.economicCode || '—')}</td> |
| 290 | </tr> |
| 291 | <tr> |
| 292 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">شناسه ملی / شماره ثبت:</td> |
| 293 | <td style="border:1px solid #cbd5e1;padding:4px 8px">${this._esc(contact.nationalId || '—')} / ${this._esc(contact.regNumber || '—')}</td> |
| 294 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">کد پستی ۱۰ رقمی:</td> |
| 295 | <td style="border:1px solid #cbd5e1;padding:4px 8px">${Formatters.toPersianDigits(contact.postalCode || '—')}</td> |
| 296 | </tr> |
| 297 | <tr> |
| 298 | <td style="border:1px solid #cbd5e1;padding:4px 8px;background:#f1f5f9">نشانی و تلفن:</td> |
| 299 | <td colspan="3" style="border:1px solid #cbd5e1;padding:4px 8px">${this._esc(contact.address || '—')}${contact.mobile ? ' | همراه: ' + Formatters.phone(contact.mobile) : ''}</td> |
| 300 | </tr> |
| 301 | </table> |
| 302 | |
| 303 | <table style="width:100%;border-collapse:collapse;border:1.5px solid ${color};font-size:10.5px"> |
| 304 | <thead> |
| 305 | <tr style="background:${color};color:#fff;font-weight:bold;text-align:center"> |
| 306 | <th style="border:1px solid ${color};padding:4px;width:30px">ردیف</th> |
| 307 | <th style="border:1px solid ${color};padding:4px 6px;text-align:right">شرح کالا یا خدمات</th> |
| 308 | <th style="border:1px solid ${color};padding:4px;width:50px">تعداد</th> |
| 309 | <th style="border:1px solid ${color};padding:4px;width:50px">واحد</th> |
| 310 | <th style="border:1px solid ${color};padding:4px;width:90px">مبلغ واحد</th> |
| 311 | <th style="border:1px solid ${color};padding:4px;width:100px">مبلغ کل</th> |
| 312 | <th style="border:1px solid ${color};padding:4px;width:75px">تخفیف</th> |
| 313 | <th style="border:1px solid ${color};padding:4px;width:80px">مالیات</th> |
| 314 | <th style="border:1px solid ${color};padding:4px;width:110px">مبلغ نهایی</th> |
| 315 | </tr> |
| 316 | </thead> |
| 317 | <tbody>${items}</tbody> |
| 318 | </table> |
| 319 | |
| 320 | <table style="width:100%;border-collapse:collapse;border:1.5px solid ${color};font-size:10.5px;margin-top:4px"> |
| 321 | <tr> |
| 322 | <td style="width:60%;border:1px solid ${color};padding:8px;vertical-align:top;background:#f8fafc"> |
| 323 | <div style="margin-bottom:5px"><strong>مبلغ کل به حروف:</strong> ${numberToWords(inv.grandTotal)}</div> |
| 324 | <div style="margin-bottom:5px"><strong>شرایط و نحوه پرداخت:</strong> ${this._paymentLabel(inv.paymentMethod)}</div> |
| 325 | ${inv.description ? `<div style="margin-bottom:5px"><strong>توضیحات:</strong> ${this._esc(inv.description)}</div>` : ''} |
| 326 | ${balanceHtml} |
| 327 | </td> |
| 328 | <td style="width:40%;border:1px solid ${color};padding:0"> |
| 329 | <table style="width:100%;border-collapse:collapse;font-size:10.5px"> |
| 330 | <tr><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px">جمع کل اقلام:</td><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px;text-align:left">${Formatters.money(inv.subtotal)}</td></tr> |
| 331 | <tr><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px">مجموع تخفیف:</td><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px;text-align:left">${Formatters.money(inv.totalDiscount)}</td></tr> |
| 332 | ${inv.vatEnabled ? `<tr><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px">مالیات (${Formatters.toPersianDigits(inv.vatRate)}٪):</td><td style="border-bottom:1px solid #cbd5e1;padding:4px 10px;text-align:left">${Formatters.money(inv.vatAmount)}</td></tr>` : ''} |
| 333 | <tr style="background:#f0fdfa;font-weight:bold;font-size:12px;color:${color}"> |
| 334 | <td style="padding:6px 10px">مبلغ قابل پرداخت:</td> |
| 335 | <td style="padding:6px 10px;text-align:left">${Formatters.money(inv.grandTotal)}</td> |
| 336 | </tr> |
| 337 | ${inv.paidAmount > 0 ? `<tr><td style="padding:4px 10px">پرداختشده:</td><td style="padding:4px 10px;text-align:left">${Formatters.money(inv.paidAmount)}</td></tr>` : ''} |
| 338 | ${inv.remaining > 0 ? `<tr><td style="padding:4px 10px;color:#b91c1c"><strong>باقیمانده:</strong></td><td style="padding:4px 10px;text-align:left;color:#b91c1c;font-weight:bold">${Formatters.money(inv.remaining)}</td></tr>` : ''} |
| 339 | </table> |
| 340 | </td> |
| 341 | </tr> |
| 342 | </table> |
| 343 | |
| 344 | ${this.settings.showSignature ? ` |
| 345 | <table style="width:100%;border-collapse:collapse;border:1px solid ${color};margin-top:8px;text-align:center;font-size:11px"> |
| 346 | <tr> |
| 347 | <td style="width:50%;height:70px;vertical-align:top;border:1px solid ${color};padding:6px;background:#fff"><div style="font-weight:bold">مهر و امضای فروشنده</div></td> |
| 348 | <td style="width:50%;height:70px;vertical-align:top;border:1px solid ${color};padding:6px;background:#fff"><div style="font-weight:bold">مهر و امضای خریدار</div></td> |
| 349 | </tr> |
| 350 | </table> |
| 351 | ` : ''} |
| 352 | </div> |
| 353 | `; |
| 354 | } |
| 355 | |
| 356 | // ------------------------------------------------------------ |
| 357 | // قالب غیررسمی |
| 358 | // ------------------------------------------------------------ |
| 359 | _nonFormalTemplate(inv, seller, contact, balance) { |
| 360 | const color = this.settings.themeColor; |
| 361 | |
| 362 | const items = inv.items.map((it, idx) => { |
| 363 | const qty = Number(it.qty) || 0; |
| 364 | const price = Number(it.price) || 0; |
| 365 | const lineSub = qty * price; |
| 366 | const disc = Number(it.discount) || 0; |
| 367 | const total = lineSub - disc; |
| 368 | return ` |
| 369 | <tr> |
| 370 | <td style="text-align:center">${Formatters.toPersianDigits(idx + 1)}</td> |
| 371 | <td style="text-align:right">${this._esc(it.productName)}</td> |
| 372 | <td style="text-align:center">${this._esc(it.unit || 'عدد')}</td> |
| 373 | <td style="text-align:center">${Formatters.toPersianDigits(qty)}</td> |
| 374 | <td style="text-align:left">${Formatters.number(price)}</td> |
| 375 | <td style="text-align:left">${Formatters.number(disc)}</td> |
| 376 | <td style="text-align:left;font-weight:700">${Formatters.number(total)}</td> |
| 377 | </tr> |
| 378 | `; |
| 379 | }).join(''); |
| 380 | |
| 381 | const balanceHtml = this.settings.showBalance === 'simple' && balance !== 0 ? ` |
| 382 | <div style="margin-top:8px;padding:8px 12px;background:#fef3c7;border-radius:8px;font-size:11px"> |
| 383 | <strong>مانده حساب فعلی مشتری:</strong> |
| 384 | ${balance > 0 ? Formatters.money(balance) + ' بدهکار' : Formatters.money(Math.abs(balance)) + ' بستانکار'} |
| 385 | </div> |
| 386 | ` : ''; |
| 387 | |
| 388 | return ` |
| 389 | <div class="print-doc" dir="rtl" style="direction:rtl;text-align:right;font-family:'Vazirmatn FD',Tahoma,sans-serif;color:#000;padding:8mm"> |
| 390 | <div style="display:flex;justify-content:space-between;align-items:start;padding-bottom:12px;border-bottom:3px solid ${color};margin-bottom:14px"> |
| 391 | <div style="flex:1"> |
| 392 | <div style="font-size:20px;font-weight:800;color:${color}">${this._esc(seller.name)}</div> |
| 393 | ${seller.address ? `<div style="font-size:11px;color:#64748b;margin-top:4px">${this._esc(seller.address)}</div>` : ''} |
| 394 | ${seller.phone ? `<div style="font-size:11px;color:#64748b;margin-top:2px">تلفن: ${Formatters.phone(seller.phone)}</div>` : ''} |
| 395 | </div> |
| 396 | <div style="text-align:left;min-width:180px"> |
| 397 | <div style="font-size:22px;font-weight:800;color:${color};margin-bottom:6px">${inv.isPreInvoice ? 'پیشفاکتور' : 'فاکتور فروش'}</div> |
| 398 | <div style="font-size:12px;background:${color};color:#fff;padding:6px 12px;border-radius:6px;font-weight:700;display:inline-block">#${Formatters.toPersianDigits(inv.number)}</div> |
| 399 | <div style="font-size:11px;color:#475569;margin-top:6px">تاریخ: ${Formatters.toPersianDigits(inv.date)}</div> |
| 400 | </div> |
| 401 | </div> |
| 402 | |
| 403 | <div style="display:flex;gap:12px;margin-bottom:14px"> |
| 404 | <div style="flex:1;background:#f8fafc;padding:10px 12px;border-radius:8px;border-right:3px solid ${color}"> |
| 405 | <div style="font-size:11px;font-weight:700;color:${color};margin-bottom:6px">فروشنده</div> |
| 406 | <div style="font-size:12px;font-weight:600">${this._esc(seller.name)}</div> |
| 407 | ${seller.national_id ? `<div style="font-size:10.5px;color:#64748b;margin-top:2px">شناسه ملی: ${Formatters.toPersianDigits(seller.national_id)}</div>` : ''} |
| 408 | ${seller.phone ? `<div style="font-size:10.5px;color:#64748b;margin-top:2px">تلفن: ${Formatters.phone(seller.phone)}</div>` : ''} |
| 409 | </div> |
| 410 | <div style="flex:1;background:#f8fafc;padding:10px 12px;border-radius:8px;border-right:3px solid ${color}"> |
| 411 | <div style="font-size:11px;font-weight:700;color:${color};margin-bottom:6px">خریدار</div> |
| 412 | <div style="font-size:12px;font-weight:600">${this._esc(contact.name || inv.contactName || '—')}</div> |
| 413 | ${contact.mobile ? `<div style="font-size:10.5px;color:#64748b;margin-top:2px">همراه: ${Formatters.phone(contact.mobile)}</div>` : ''} |
| 414 | ${contact.address ? `<div style="font-size:10.5px;color:#64748b;margin-top:2px;line-height:1.5">${this._esc(contact.address)}</div>` : ''} |
| 415 | </div> |
| 416 | </div> |
| 417 | |
| 418 | <table style="width:100%;border-collapse:collapse;font-size:11px;margin-bottom:14px"> |
| 419 | <thead> |
| 420 | <tr style="background:${color};color:#fff"> |
| 421 | <th style="padding:8px 4px;width:40px;text-align:center;border-radius:0 6px 0 0">#</th> |
| 422 | <th style="padding:8px 8px;text-align:right">شرح کالا یا خدمات</th> |
| 423 | <th style="padding:8px 4px;width:60px;text-align:center">واحد</th> |
| 424 | <th style="padding:8px 4px;width:60px;text-align:center">مقدار</th> |
| 425 | <th style="padding:8px 4px;width:100px;text-align:left">قیمت واحد</th> |
| 426 | <th style="padding:8px 4px;width:90px;text-align:left">تخفیف</th> |
| 427 | <th style="padding:8px 4px;width:110px;text-align:left;border-radius:6px 0 0 0">جمع</th> |
| 428 | </tr> |
| 429 | </thead> |
| 430 | <tbody>${items}</tbody> |
| 431 | </table> |
| 432 | |
| 433 | <div style="display:flex;gap:14px;align-items:stretch"> |
| 434 | <div style="flex:1"> |
| 435 | <div style="background:#f8fafc;padding:12px;border-radius:8px;font-size:11px;line-height:1.9"> |
| 436 | <div style="font-weight:700;color:${color};margin-bottom:6px">مبلغ به حروف:</div> |
| 437 | <div>${numberToWords(inv.grandTotal)}</div> |
| 438 | ${inv.description ? `<div style="margin-top:10px;padding-top:10px;border-top:1px dashed #cbd5e1"><strong>توضیحات:</strong> ${this._esc(inv.description)}</div>` : ''} |
| 439 | ${balanceHtml} |
| 440 | </div> |
| 441 | </div> |
| 442 | <div style="flex:0 0 280px"> |
| 443 | <table style="width:100%;border-collapse:collapse;font-size:11.5px;border:1px solid #e2e8f0;border-radius:8px;overflow:hidden"> |
| 444 | <tr style="background:#f8fafc"><td style="padding:8px 12px">جمع اقلام:</td><td style="padding:8px 12px;text-align:left">${Formatters.money(inv.subtotal)}</td></tr> |
| 445 | ${inv.totalDiscount > 0 ? `<tr><td style="padding:8px 12px">تخفیف:</td><td style="padding:8px 12px;text-align:left;color:#dc2626">- ${Formatters.money(inv.totalDiscount)}</td></tr>` : ''} |
| 446 | ${inv.vatEnabled ? `<tr><td style="padding:8px 12px">مالیات (${Formatters.toPersianDigits(inv.vatRate)}٪):</td><td style="padding:8px 12px;text-align:left;color:#d97706">${Formatters.money(inv.vatAmount)}</td></tr>` : ''} |
| 447 | <tr style="background:${color};color:#fff;font-weight:700;font-size:14px"><td style="padding:10px 12px">قابل پرداخت:</td><td style="padding:10px 12px;text-align:left">${Formatters.money(inv.grandTotal)}</td></tr> |
| 448 | ${inv.paidAmount > 0 ? `<tr><td style="padding:6px 12px">پرداختشده:</td><td style="padding:6px 12px;text-align:left;color:#059669">${Formatters.money(inv.paidAmount)}</td></tr>` : ''} |
| 449 | ${inv.remaining > 0 ? `<tr style="background:#fef2f2"><td style="padding:6px 12px;color:#b91c1c;font-weight:700">باقیمانده:</td><td style="padding:6px 12px;text-align:left;color:#b91c1c;font-weight:700">${Formatters.money(inv.remaining)}</td></tr>` : ''} |
| 450 | </table> |
| 451 | </div> |
| 452 | </div> |
| 453 | |
| 454 | ${this.settings.showSignature ? ` |
| 455 | <div style="display:flex;justify-content:space-between;gap:20px;margin-top:24px;padding-top:14px;border-top:1px dashed #cbd5e1"> |
| 456 | <div style="flex:1;text-align:center;font-size:11px;color:#64748b"> |
| 457 | <div style="font-weight:700;color:#0f172a;margin-bottom:40px">مهر و امضای فروشنده</div> |
| 458 | </div> |
| 459 | <div style="flex:1;text-align:center;font-size:11px;color:#64748b"> |
| 460 | <div style="font-weight:700;color:#0f172a;margin-bottom:40px">مهر و امضای خریدار</div> |
| 461 | </div> |
| 462 | </div> |
| 463 | ` : ''} |
| 464 | |
| 465 | ${seller.footer ? `<div style="margin-top:20px;padding:10px;background:#f8fafc;border-radius:6px;font-size:10.5px;color:#64748b;text-align:center">${this._esc(seller.footer)}</div>` : ''} |
| 466 | </div> |
| 467 | `; |
| 468 | } |
| 469 | |
| 470 | // ------------------------------------------------------------ |
| 471 | // قالب فیش حرارتی |
| 472 | // ------------------------------------------------------------ |
| 473 | _thermalTemplate(inv, seller, contact) { |
| 474 | const items = inv.items.map((it, idx) => { |
| 475 | const qty = Number(it.qty) || 0; |
| 476 | const price = Number(it.price) || 0; |
| 477 | const total = qty * price - (Number(it.discount) || 0); |
| 478 | return ` |
| 479 | <tr> |
| 480 | <td style="text-align:right;padding:2px 0;font-size:10px">${this._esc(it.productName)}</td> |
| 481 | <td style="text-align:center;padding:2px 0;font-size:10px">${Formatters.toPersianDigits(qty)}</td> |
| 482 | <td style="text-align:left;padding:2px 0;font-size:10px">${Formatters.number(total)}</td> |
| 483 | </tr> |
| 484 | `; |
| 485 | }).join(''); |
| 486 | |
| 487 | return ` |
| 488 | <div class="print-doc" dir="rtl" style="direction:rtl;text-align:right;font-family:'Vazirmatn FD',Tahoma,monospace;color:#000;padding:3mm;width:76mm;font-size:11px;background:#fff"> |
| 489 | <div style="text-align:center;padding-bottom:6px;border-bottom:1px dashed #000;margin-bottom:6px"> |
| 490 | <div style="font-size:14px;font-weight:800">${this._esc(seller.name)}</div> |
| 491 | ${seller.phone ? `<div style="font-size:10px;margin-top:2px">تلفن: ${Formatters.phone(seller.phone)}</div>` : ''} |
| 492 | ${seller.address ? `<div style="font-size:9px;margin-top:2px">${this._esc(seller.address)}</div>` : ''} |
| 493 | </div> |
| 494 | |
| 495 | <div style="text-align:center;font-size:11px;font-weight:700;margin-bottom:4px;padding:3px 0;background:#f3f4f6;border-radius:4px"> |
| 496 | ${inv.isPreInvoice ? 'پیشفاکتور فروش' : 'فاکتور فروش'} |
| 497 | </div> |
| 498 | |
| 499 | <div style="display:flex;justify-content:space-between;font-size:10px;margin-bottom:4px"> |
| 500 | <div>شماره: ${Formatters.toPersianDigits(inv.number)}</div> |
| 501 | <div>تاریخ: ${Formatters.toPersianDigits(inv.date)}</div> |
| 502 | </div> |
| 503 | |
| 504 | <div style="font-size:10px;padding:4px 0;border-top:1px dashed #000;border-bottom:1px dashed #000;margin-bottom:6px"> |
| 505 | مشتری: ${this._esc(contact.name || inv.contactName || '—')} |
| 506 | </div> |
| 507 | |
| 508 | <table style="width:100%;border-collapse:collapse;font-size:10px;margin-bottom:6px"> |
| 509 | <thead> |
| 510 | <tr style="border-bottom:1px solid #000"> |
| 511 | <th style="text-align:right;padding:3px 0">شرح</th> |
| 512 | <th style="text-align:center;padding:3px 0;width:30px">تعداد</th> |
| 513 | <th style="text-align:left;padding:3px 0;width:70px">مبلغ</th> |
| 514 | </tr> |
| 515 | </thead> |
| 516 | <tbody>${items}</tbody> |
| 517 | </table> |
| 518 | |
| 519 | <div style="border-top:1px dashed #000;padding-top:6px;font-size:11px"> |
| 520 | <div style="display:flex;justify-content:space-between;margin-bottom:3px"> |
| 521 | <span>جمع کل:</span> |
| 522 | <span>${Formatters.number(inv.subtotal)}</span> |
| 523 | </div> |
| 524 | ${inv.totalDiscount > 0 ? `<div style="display:flex;justify-content:space-between;margin-bottom:3px"><span>تخفیف:</span><span>- ${Formatters.number(inv.totalDiscount)}</span></div>` : ''} |
| 525 | ${inv.vatEnabled ? `<div style="display:flex;justify-content:space-between;margin-bottom:3px"><span>مالیات:</span><span>${Formatters.number(inv.vatAmount)}</span></div>` : ''} |
| 526 | <div style="display:flex;justify-content:space-between;font-size:14px;font-weight:800;padding:6px 0;border-top:1px solid #000;border-bottom:1px solid #000;margin:4px 0"> |
| 527 | <span>قابل پرداخت:</span> |
| 528 | <span>${Formatters.number(inv.grandTotal)}</span> |
| 529 | </div> |
| 530 | ${inv.paidAmount > 0 ? `<div style="display:flex;justify-content:space-between;margin-top:3px"><span>پرداخت:</span><span>${Formatters.number(inv.paidAmount)}</span></div>` : ''} |
| 531 | ${inv.remaining > 0 ? `<div style="display:flex;justify-content:space-between;margin-top:3px;font-weight:700"><span>باقیمانده:</span><span>${Formatters.number(inv.remaining)}</span></div>` : ''} |
| 532 | </div> |
| 533 | |
| 534 | <div style="text-align:center;margin-top:8px;padding-top:6px;border-top:1px dashed #000;font-size:9.5px"> |
| 535 | ${seller.footer ? this._esc(seller.footer) : 'از خرید شما سپاسگزاریم'} |
| 536 | </div> |
| 537 | </div> |
| 538 | `; |
| 539 | } |
| 540 | |
| 541 | _openPrintWindow(html) { |
| 542 | // ساخت iframe مخفی به جای window.open (سازگار با Tauri) |
| 543 | const iframe = document.createElement('iframe'); |
| 544 | iframe.style.position = 'fixed'; |
| 545 | iframe.style.right = '0'; |
| 546 | iframe.style.bottom = '0'; |
| 547 | iframe.style.width = '0'; |
| 548 | iframe.style.height = '0'; |
| 549 | iframe.style.border = '0'; |
| 550 | iframe.style.visibility = 'hidden'; |
| 551 | document.body.appendChild(iframe); |
| 552 | |
| 553 | let pageCss = 'A4 portrait'; |
| 554 | if (this.settings.template === 'thermal') { |
| 555 | pageCss = '80mm 297mm'; |
| 556 | } else { |
| 557 | const size = this.settings.paperSize === 'A5' ? 'A5' : 'A4'; |
| 558 | pageCss = size + ' ' + (this.settings.orientation || 'portrait'); |
| 559 | } |
| 560 | |
| 561 | const doc = iframe.contentWindow.document; |
| 562 | doc.open(); |
| 563 | doc.write(` |
| 564 | <!DOCTYPE html> |
| 565 | <html lang="fa" dir="rtl"> |
| 566 | <head> |
| 567 | <meta charset="UTF-8" /> |
| 568 | <title>چاپ فاکتور</title> |
| 569 | <!-- Offline-first printing: use bundled/system fonts, no external network dependency. --> |
| 570 | <style> |
| 571 | /* Zero page margins prevent Chromium/WebView2 from reserving |
| 572 | the browser-generated date, document title and page-number |
| 573 | header/footer area. The invoice itself already has padding. */ |
| 574 | @page { |
| 575 | size: ${pageCss}; |
| 576 | margin: 0; |
| 577 | } |
| 578 | |
| 579 | * { box-sizing: border-box; margin: 0; padding: 0; } |
| 580 | html, body { |
| 581 | direction: rtl; |
| 582 | text-align: right; |
| 583 | font-family: 'Vazirmatn FD', Tahoma, sans-serif; |
| 584 | background: #fff; |
| 585 | color: #000; |
| 586 | } |
| 587 | body { padding: 4px; } |
| 588 | table { direction: rtl; } |
| 589 | td, th { direction: rtl; } |
| 590 | thead { display: table-header-group; } |
| 591 | tfoot { display: table-footer-group; } |
| 592 | tr, td, th { break-inside: avoid; page-break-inside: avoid; } |
| 593 | .print-doc { direction: rtl !important; } |
| 594 | |
| 595 | @media print { |
| 596 | body { padding: 0; } |
| 597 | .print-doc { page-break-inside: auto; } |
| 598 | * { |
| 599 | -webkit-print-color-adjust: exact !important; |
| 600 | print-color-adjust: exact !important; |
| 601 | } |
| 602 | } |
| 603 | </style> |
| 604 | </head> |
| 605 | <body>${html}</body> |
| 606 | </html> |
| 607 | `); |
| 608 | doc.close(); |
| 609 | |
| 610 | // Print only after iframe fonts/layout settle; never require external font CDNs. |
| 611 | Promise.resolve(doc.fonts?.ready).catch(() => {}).then(() => setTimeout(() => { |
| 612 | try { |
| 613 | iframe.contentWindow.focus(); |
| 614 | iframe.contentWindow.print(); |
| 615 | } catch (err) { |
| 616 | Toast.error('خطا در باز کردن پنجره چاپ: ' + err.message); |
| 617 | } |
| 618 | |
| 619 | // پاک کردن iframe بعد از بسته شدن پنجره چاپ |
| 620 | setTimeout(() => { |
| 621 | if (iframe.parentNode) iframe.parentNode.removeChild(iframe); |
| 622 | }, 5000); |
| 623 | }, 200)); |
| 624 | } |
| 625 | _paymentLabel(method) { |
| 626 | const labels = { cash: 'نقدی ☑', credit: 'نسیه/چک ☑', partial: 'پرداخت جزئی ☑' }; |
| 627 | return labels[method] || '—'; |
| 628 | } |
| 629 | |
| 630 | _esc(s) { |
| 631 | if (s === null || s === undefined) return ''; |
| 632 | return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | export const InvoicePrint = new InvoicePrintImpl(); |
| 637 | window.InvoicePrint = InvoicePrint; |