سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 18:15 UTC
qa/wave0-negative-gate-proof
audit-remediation-wave3-4-20261002
audit-remediation-wave3-verify-20261002
audit-remediation-wave4-20261002
audit-remediation-wave4b-20261002
audit-remediation-wave5a-identity-20261002
audit-remediation-wave5b-offboarding-20261002
audit-remediation-wave5c-authorization-20261002
audit-security-intent-review-20261002
audit/finora-financial-core-20261115
audit/finora-master-prompt-phase0-20261016
audit/finora-stage3-legacy-source-readonly-20261023
audit/full-controls-20261030
audit/owner-live-state-reconcile-20261012
audit/owner-review-20261007
audit/phase1-live-permissions-readonly-20261013
audit/reconcile-live-state-20261006
audit/reconcile-state-20261002
audit/wp0-hardening-baseline-20261102
branding-login-favicon-20261002
c8-workflow-task1
c8-workflow-task2
c8-workflow-task3
chore/wave0-pages-gate-closeout
claude-code-plugins-setup
design/finora-c01-authoritative-source-draft-20261124
docs-wave4b-verified-20261002
docs/active-company-invoice-release-evidence-20261014
docs/agent-operating-model-20261114
docs/chart-taxpayer-release-evidence-20261004
docs/cloud-only-agent-orchestration-20261115
docs/confirm-finora-product-charter-20261115
docs/continuation-20261030
docs/d4a-verified
docs/external-work-review-20261121
docs/finora-audit-continuity-20261014
docs/finora-backup-merge-evidence-20261014
docs/finora-ci-reconciliation-20261122
docs/finora-codex-master-prompt
docs/finora-eight-phase-plan-20261011
docs/finora-f002-live-buyer-filter-verified-20261015
docs/finora-license-race-release-evidence-20261014
docs/finora-license-rollout-acceptance-20261015
docs/finora-phase0-repeat-and-pages-nav-verified-20261015
docs/finora-phase0-repeat-evidence-20261015
docs/finora-selectors-release-and-fixture-qa-20261015
docs/finora-stagea-pr240-ci-triage-20261123
docs/finora-test-license-live-pass-20261015
docs/finora-v2-m01-coverage-20261124
docs/handoff-charter-v2-20261124
docs/invoice-product-search-release-20261011
docs/invoice-workspace-release-20261007
docs/phase-status-20261031
docs/phase0-acceptance-release-evidence-20261012
docs/phase0-admin-provision-release-evidence-20261012
docs/phase0-core-bundle-owner-login-open-20261013
docs/phase0-duplicate-js-release-20261016
docs/phase0-f001-auth-rest-shared-timeout-20261013
docs/phase0-f001-owner-login-observed-20261013
docs/phase0-f001-second-device-fail-40s-20261013
docs/phase0-f003-release-verification-20261011
docs/phase0-f004-print-release-evidence-20261012
docs/phase0-f004-watermark-release-evidence-20261012
docs/phase0-f005-large-selector-release-20261012
docs/phase0-f005-release-evidence-20261012
docs/phase0-f006-dark-release-evidence-20261012
docs/phase0-f008-final-pr-closure-evidence-20261012
docs/phase0-f008-reconcile-stale-prs-20261012
docs/phase0-f107-production-evidence-20261012
docs/phase0-kavenegar-otp-preflight-release-20261012
docs/phase0-login-release-evidence-20261012
docs/phase0-login-rest-bootstrap-stage-release-20261012
docs/phase0-owner-app-assets-bundle-release-20261013
docs/phase0-owner-login-csp-release-20261012
docs/phase0-reconcile-postmerge-evidence-20261012
docs/phase0-site-probe-release-evidence-20261012
docs/phase0-startup-release-evidence-20261012
docs/phase3-treasury-release-evidence-20261014
docs/pilot-posted-correction-release-evidence-20261014
docs/pilot-purchase-correction-release-evidence-20261014
docs/print-persian-release-verification-20261011
docs/qa-ci-triage-218-20261122
docs/real-account-qa-20261030
docs/release-state-20261007
docs/seamless-amendment-release-20261014
docs/seamless-document-correction-release-20261014
docs/settings-login-release-20261025
docs/stripe-qa-deployment-evidence-20261011
docs/ux-f2-release-evidence-20261011
docs/ux-f2-release-verification-20261011
docs/wave0-closeout
docs/wave2-closeout
exec-phase1-architecture
exec-phase1-implementation
exec-phase1-qa
exec-phase1-security-release
exec-phase1-ux
feat/accounting-document-draft-approval-20261011
feat/accounting-document-release-candidate-20261011
feat/active-company-strict-isolation-20261014
feat/admin-provisioning-reconciled-20261011
feat/admin-secure-user-provisioning-20261011
feat/admin-user-provisioning-merged-20261011
feat/d4a-request-work-queue
feat/document-lifecycle-atf-20261118
feat/document-lifecycle-temp-permanent-atef
feat/draft-first-attachment-lifecycle-216
feat/finora-offline-encrypted-backup-20261014
feat/finora-phase-a-navigation-20261023
feat/finora-stripe-sandbox-edge-gate
feat/immutable-attachment-temporary-vouchers
feat/iran-accounting-design-audit
feat/journal-document-lifecycle-20261118
feat/journal-rpc-repository-adapter-20261117
feat/office-c7-fulltext-ocr-provenance
feat/password-recovery-admin-reset-20261025
feat/pilot-expense-income-inplace-amendment-20261014
feat/pilot-journal-invoice-correction-20261014
feat/pilot-purchase-correction-20261014
feat/pilot-treasury-unallocated-correction-20261014
feat/retain-document-editor-after-save-20261014
feat/seamless-financial-document-correction-20261014
feat/slice-b-tenant-rbac
feat/stripe-sandbox-invoice-probe
feature/accounting-core-p0
feature/accounting-product-guidance
feature/admin-identity-phone-auth
feature/commercial-rnd
feature/finora-phase1a-supabase-cli-20261016
feature/finora-stage2-manual-canary-20261017
feature/finora-stage3-commercial-payload-20261023
feature/finora-stage3-enforce-invoice-rpc-20261023
feature/finora-stage3-enforce-purchase-red-20261023
feature/invoice-workspace-cleanup
feature/phase0-kavenegar-otp-preflight-20261012
feature/ux-commerce-settings-r2
fix-shell-scroll-live-cache-20261002
fix-shell-scrollbar-explicit-ownership-20261002
fix-shell-scrollbar-ownership-20261002
fix-shell-scrollbar-right-edge-20261002
fix/about-bug-report-20261114
fix/active-company-invoice-scope-20261014
fix/active-company-isolation-reconcile-20261014
fix/admin-central-password-reset-20261028
fix/auth-network-diagnostics
fix/chart-taxpayer-reference-20261003
fix/combobox-enter-reliability
fix/combobox-live-search
fix/combobox-production-cache
fix/combobox-release-asset-v2
fix/company-edit-action-20261028
fix/company-edit-pilot-delete-20261014
fix/company-form-action-state-20261014
fix/company-form-action-state-rebased-20261014
fix/contact-operational-balance-20261111
fix/dark-theme-contrast
fix/financial-lifecycle-recovery-20261124
fix/finora-accounting-test-organization-readiness-20261015
fix/finora-b01-safe-org-switch-20261124
fix/finora-b02-sync-recovery-20261124
fix/finora-b03-conflict-review-20261124
fix/finora-org-license-bootstrap-race-20261014
fix/finora-stage3-posted-source-immutable-20261023
fix/finora-v2-b03-r2-qa-20261124
fix/finora-v2-b03-r3-readonly-20261124
fix/g01-asof-financial-position-20261128
fix/invoice-product-search-rehydrate-20261011
fix/invoice-search-cache-bust
fix/issue229-linked-draft-status-20261122
fix/login-assets-retry-20261014
fix/login-inert-startup-20261110
fix/login-member-access-20261101
fix/login-resilience-20261017
fix/login-short-viewport-20261028
fix/login-startup-readiness-20261024
fix/navigation-utilities-placement-20261105
fix/office-c7-source-ref-binding
fix/office-c7-source-ref-binding-v2
fix/owner-login-network-20261026
fix/password-recovery-invalid-cancel-20261026
fix/payment-amount-format-20261111
fix/phase0-admin-provision-seat-bootstrap-20261012
fix/phase0-auth-bundled-assets-for-unstable-isp-20261013
fix/phase0-auth-handler-binding-stalled-session-20261012
fix/phase0-login-context-stage-visibility-20261012
fix/phase0-login-single-local-bundle-20261013
fix/phase0-login-site-probe-clarity-20261012
fix/phase0-login-ui-ready-20261012
fix/phase0-modal-dashboard-drill-20261011
fix/phase0-pages-blocking-core-bundles-20261013
fix/phase0-print-no-draft-watermark-20261012
fix/phase0-startup-parallel-asset-load-20261012
fix/phase3-behavioral-verification
fix/preserve-pending-edits-20261121
fix/print-persian-digit-consistency-20261011
fix/recovery-login-startup-20261027
fix/report-opening-balance-release-20261130
fix/settings-checkbox-persistence-20261024
fix/taxpayer-arithmetic-20261004
fix/ux-keyboard-search-f2-20261011
fix/wave2-request-input-integrity
hardening/c01-source-draft-20261129
hardening/global-draft-conversion-20261113
hardening/wp1-ledger-integrity-20261102
integration/finora-execution-20261124
integration/issue229-ui-qa-20261122
integration/wp1-ledger-core-20261115
integration/wp2-manual-journal-rpc-20261116
main
ops-heartbeat-v2-20261002
ops-progress-heartbeat-rule-20261002
ops/wave4-production-20261003
plan/financial-core-phase1-approval-20261016
qa/attachment-allocator-two-session-20261122
qa/draft-first-save-red-evidence-20261122
qa/finora-autopost-retry-identity-red-20261122
qa/finora-identity-rpc-security-tripwire-20261122
qa/finora-issue223-manual-kardex-browser-red-20261123
qa/finora-issue223-stock-real-jwt-20261123
qa/finora-issue238-inventory-count-browser-red-20261123
qa/finora-issue238-save-browser-red-20261122
qa/finora-login-cors-header-preflight-20261025
qa/finora-phase0-saved-session-repeat-20261015
qa/finora-phase5-posted-insert-jwt-red-20261123
qa/finora-stage3-ui-jwt-autopost-20261023
qa/finora-v2-g01-report-reconciliation-20261125
qa/free-supabase-local-wp2-20261116
qa/issue229-approval-boundary-jwt-20261122
qa/issue229-sale-save-linked-draft-red-20261122
qa/phase0-acceptance-start-20261012
qa/phase0-f005-account-project-contract-stress-20261012
qa/phase0-f005-selector-stress-20261012
qa/phase0-f006-dark-contrast-20261012
qa/post-wave4-verification-20261003
qa/posted-source-immutable-jwt-20261122
qa/pr219-wp1-disposable-dburl-proof-20261123
qa/purchase-source-jwt-20261122
qa/real-settings-acceptance-20261025
qa/recovery-mail-acceptance-20261026
qa/source-autopost-jwt-atomicity-20261122
qa/wave0-negative-gate-proof
qa/wp2-auth-tenant-e2e-20261117
qa/wp2-authorized-journal-write-20261122
qa/wp2-financial-paths-reconciliation-20261122
qa/wp3-financial-tenant-isolation-20261117
remediation/wave0-liveqa-wave1
remediation/wave2-request-integrity
staging/finora-stage22-free-20261022
state-scroll-verified-20261002
state-wave4b-production-20261002
state-wave5a-production-20261002
test/finora-accounting-boot-readiness-20261015
test/finora-f0-02-production-selectors-20261015
test/finora-pages-commerce-event-wiring-20261015
test/finora-pages-invoice-selectors-readonly-20261015
test/finora-stage3-jwt-source-post-20261023
test/phase0-invoice-fixture-bootstrap-20261016
test/phase0-invoice-persistence-20261011
test/phase0-pages-delayed-dispatcher-20261016
ux-scroll-ownership-20261002
work/finora-stage3-enforce-purchase-green-20261023
work/finora-stage3-enforce-sale-green-20261023
work/finora-stage3-payload-green-20261023
| 1 | function buildTaxLogo(){ |
| 2 | return `<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\" style=\"width:80px;height:80px\"> |
| 3 | <circle cx=\"50\" cy=\"50\" r=\"46\" fill=\"none\" stroke=\"#1e3a8a\" stroke-width=\"1.5\"/> |
| 4 | <circle cx=\"50\" cy=\"50\" r=\"38\" fill=\"none\" stroke=\"#1e3a8a\" stroke-width=\"1\"/> |
| 5 | <rect x=\"30\" y=\"32\" width=\"4\" height=\"36\" fill=\"#1e3a8a\"/> |
| 6 | <rect x=\"40\" y=\"26\" width=\"4\" height=\"42\" fill=\"#1e3a8a\"/> |
| 7 | <rect x=\"50\" y=\"22\" width=\"4\" height=\"46\" fill=\"#1e3a8a\"/> |
| 8 | <rect x=\"60\" y=\"26\" width=\"4\" height=\"42\" fill=\"#1e3a8a\"/> |
| 9 | <rect x=\"70\" y=\"32\" width=\"4\" height=\"36\" fill=\"#1e3a8a\"/> |
| 10 | <rect x=\"26\" y=\"20\" width=\"52\" height=\"5\" fill=\"#1e3a8a\" rx=\"1\"/> |
| 11 | <rect x=\"28\" y=\"66\" width=\"48\" height=\"4\" fill=\"#1e3a8a\" rx=\"1\"/> |
| 12 | <rect x=\"24\" y=\"72\" width=\"56\" height=\"4\" fill=\"#1e3a8a\" rx=\"1\"/> |
| 13 | </svg>`; |
| 14 | } |
| 15 | function getInvoicePrintSpec(inv){ |
| 16 | const kind=String(inv?.kind||'').toLowerCase(); |
| 17 | if(kind==='non_formal'||kind==='informal')return {paper:'A5',orientation:'landscape',widthMm:210,heightMm:148,marginMm:5}; |
| 18 | return {paper:'A4',orientation:'landscape',widthMm:297,heightMm:210,marginMm:5}; |
| 19 | } |
| 20 | function buildIsolatedPrintDocument(content,spec){ |
| 21 | const usableWidth=Math.max(1,spec.widthMm-(spec.marginMm*2)); |
| 22 | const usableHeight=Math.max(1,spec.heightMm-(spec.marginMm*2)); |
| 23 | return '<!doctype html><html lang="fa" dir="rtl"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Finora Print</title><style>' |
| 24 | +'@page{size:'+spec.paper+' '+spec.orientation+';margin:'+spec.marginMm+'mm}' |
| 25 | +'*{box-sizing:border-box}html,body{margin:0!important;padding:0!important;background:#fff!important;color:#000!important;width:100%!important;direction:rtl;font-family:Tahoma,Arial,sans-serif;-webkit-print-color-adjust:exact;print-color-adjust:exact}' |
| 26 | +'#finora-print-document{margin:0!important;padding:0!important;width:100%!important}' |
| 27 | +'.invoice-a4-page{width:'+usableWidth+'mm!important;max-width:'+usableWidth+'mm!important;min-height:'+usableHeight+'mm!important;margin:0 auto!important;box-sizing:border-box!important;page-break-after:always!important;break-after:page!important;overflow:hidden!important}' |
| 28 | +'.invoice-a4-page:last-child{page-break-after:auto!important;break-after:auto!important}' |
| 29 | +'.invoice-a4-page table{max-width:100%!important}' |
| 30 | +'@media print{html,body,#finora-print-document{width:100%!important}.invoice-a4-page{box-shadow:none!important}}' |
| 31 | +'</style></head><body><main id="finora-print-document" data-paper="'+spec.paper+'" data-orientation="'+spec.orientation+'">'+content+'</main></body></html>'; |
| 32 | } |
| 33 | function removeIsolatedPrintFrame(){ |
| 34 | const old=document.getElementById('finora-print-frame');if(old)old.remove(); |
| 35 | } |
| 36 | function printIsolatedDocument(content,spec){ |
| 37 | removeIsolatedPrintFrame(); |
| 38 | const frame=document.createElement('iframe'); |
| 39 | frame.id='finora-print-frame'; |
| 40 | frame.title='Finora isolated print document'; |
| 41 | frame.setAttribute('aria-hidden','true'); |
| 42 | frame.style.position='fixed';frame.style.left='0';frame.style.bottom='0';frame.style.width='1px';frame.style.height='1px';frame.style.border='0';frame.style.opacity='0';frame.style.pointerEvents='none'; |
| 43 | document.body.appendChild(frame); |
| 44 | const doc=frame.contentDocument; |
| 45 | doc.open();doc.write(buildIsolatedPrintDocument(content,spec));doc.close(); |
| 46 | if(window.__FINORA_PRINT_TEST_MODE)return frame; |
| 47 | const cleanup=()=>{setTimeout(removeIsolatedPrintFrame,0);}; |
| 48 | frame.contentWindow.addEventListener('afterprint',cleanup,{once:true}); |
| 49 | setTimeout(()=>{try{frame.contentWindow.focus();frame.contentWindow.print();setTimeout(cleanup,3000);}catch(err){cleanup();alert('امکان باز کردن پنجره چاپ وجود ندارد. لطفاً دوباره تلاش کنید.');}},80); |
| 50 | return frame; |
| 51 | } |
| 52 | function stageInvoicePrint(content,spec){ |
| 53 | const preview=document.getElementById('printable-invoice'); |
| 54 | if(preview){preview.innerHTML=content;preview.style.display='none';preview.dataset.paper=spec.paper;preview.dataset.orientation=spec.orientation;} |
| 55 | let orientationStyle=document.getElementById('dynamic-print-orientation'); |
| 56 | if(!orientationStyle){orientationStyle=document.createElement('style');orientationStyle.id='dynamic-print-orientation';document.head.appendChild(orientationStyle);} |
| 57 | orientationStyle.innerHTML='@media print { @page { size: '+spec.paper+' '+spec.orientation+'; margin: '+spec.marginMm+'mm; } }'; |
| 58 | return printIsolatedDocument(content,spec); |
| 59 | } |
| 60 | |
| 61 | function buildElectronicDocPage(inv,edoc,seller,contact){ |
| 62 | const cur='ریال'; |
| 63 | const items=inv.items; |
| 64 | const vatRate=(inv.vatRate!==undefined&&inv.vatType!=='fixed')?inv.vatRate:10; |
| 65 | |
| 66 | const itemsRows=items.map((it,idx)=>{ |
| 67 | const line=it.lineTotal; |
| 68 | const rowVatRate=(inv.vat>0)?vatRate:0; |
| 69 | const vat=Math.round(line*rowVatRate/100); |
| 70 | const total=line+vat; |
| 71 | const edItem=(edoc.items&&edoc.items[idx])?edoc.items[idx]:{}; |
| 72 | return `<tr> |
| 73 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${toPersianDigits(idx+1)}</td> |
| 74 | <td style=\"border:1px solid #000;padding:4px\">${esc(it.prodName||'')}</td> |
| 75 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${toPersianDigits(it.qty)}</td> |
| 76 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${esc(it.unit||'')}</td> |
| 77 | <td style=\"border:1px solid #000;padding:4px;text-align:left\">${it.price.toLocaleString('fa-IR')}</td> |
| 78 | <td style=\"border:1px solid #000;padding:4px;text-align:left\">${line.toLocaleString('fa-IR')}</td> |
| 79 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${toPersianDigits(rowVatRate)}٪</td> |
| 80 | <td style=\"border:1px solid #000;padding:4px;text-align:left\">${vat.toLocaleString('fa-IR')}</td> |
| 81 | <td style=\"border:1px solid #000;padding:4px;text-align:left\">${total.toLocaleString('fa-IR')}</td> |
| 82 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${esc(edItem.internalId||'')}</td> |
| 83 | <td style=\"border:1px solid #000;padding:4px;text-align:center\">${esc(edItem.officialId||'')}</td> |
| 84 | </tr>`; |
| 85 | }).join(''); |
| 86 | |
| 87 | let contractText=''; |
| 88 | if(edoc.pattern==='پیمانکاری'&&edoc.contractId){ |
| 89 | contractText=items.map((it,idx)=> |
| 90 | `+ شناسه یکتای ثبت قرارداد حقالعملکاری برای ردیف ${toPersianDigits(idx+1)}: ${esc(edoc.contractId)} است` |
| 91 | ).join('<br>'); |
| 92 | } |
| 93 | |
| 94 | const grandTotal=inv.grandTotal||0; |
| 95 | const vatTotal=inv.vat||0; |
| 96 | const baseTotal=grandTotal-vatTotal; |
| 97 | |
| 98 | return `<div class=\"invoice-a4-page landscape\" style=\"background:#fff;padding:6mm 8mm;color:#000;font-family:'Vazirmatn FD',sans-serif;position:relative\"> |
| 99 | <table style=\"width:100%;border-collapse:collapse;margin-bottom:4px\"> |
| 100 | <tr> |
| 101 | <td style=\"width:20%;vertical-align:top;text-align:center;padding:4px\">${buildTaxLogo()}<div style=\"font-size:9px;color:#1e3a8a;margin-top:2px\">سازمان امور مالیاتی</div></td> |
| 102 | <td style=\"width:60%;text-align:center;vertical-align:middle;padding:6px\"> |
| 103 | <div style=\"font-size:14px;font-weight:bold;color:#1e3a8a\">صورتحساب الکترونیکی فروش کالا / خدمات</div> |
| 104 | <div style=\"font-size:9.5px;color:#475569;margin-top:2px\">(مطابق استاندارد سامانه مودیان)</div> |
| 105 | </td> |
| 106 | <td style=\"width:20%;vertical-align:top;padding:4px;font-size:9.5px;text-align:left\"> |
| 107 | <div>${esc(seller.name||'')}</div> |
| 108 | <div style=\"color:#475569\">${esc(seller.phone||'')}</div> |
| 109 | </td> |
| 110 | </tr> |
| 111 | </table> |
| 112 | |
| 113 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #000;font-size:10px;margin-bottom:4px\"> |
| 114 | <tr> |
| 115 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9;width:30%\"><strong>شماره منحصر به فرد صورتحساب الکترونیکی مالیاتی</strong></td> |
| 116 | <td style=\"border:1px solid #000;padding:4px;width:70%\">${esc(edoc.uniqueNumber||'—')}</td> |
| 117 | </tr> |
| 118 | <tr> |
| 119 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>شماره مالیاتی مندرج در برگه تشخیص</strong></td> |
| 120 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.taxNumber||'—')}</td> |
| 121 | </tr> |
| 122 | <tr> |
| 123 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>تاریخ و زمان صدور صورتحساب الکترونیکی</strong></td> |
| 124 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.issueDateTime||'—')}</td> |
| 125 | </tr> |
| 126 | <tr> |
| 127 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>تاریخ صورتحساب الکترونیکی اصلی</strong></td> |
| 128 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.originalDate||'—')}</td> |
| 129 | </tr> |
| 130 | <tr> |
| 131 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>شماره صورتحساب الکترونیکی اصلی</strong></td> |
| 132 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.originalNumber||'—')}</td> |
| 133 | </tr> |
| 134 | <tr> |
| 135 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>نوع صورتحساب</strong></td> |
| 136 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.kind||'—')}</td> |
| 137 | </tr> |
| 138 | <tr> |
| 139 | <td style=\"border:1px solid #000;padding:4px;background:#f1f5f9\"><strong>موضوع صورتحساب</strong></td> |
| 140 | <td style=\"border:1px solid #000;padding:4px\">${esc(edoc.pattern||'—')}</td> |
| 141 | </tr> |
| 142 | </table> |
| 143 | |
| 144 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #000;font-size:10px;margin-bottom:4px\"> |
| 145 | <tr><td colspan=\"4\" style=\"border:1px solid #000;padding:4px;background:#f1f5f9;font-weight:bold\">مشخصات فروشنده</td></tr> |
| 146 | <tr> |
| 147 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:15%\">نام شخص</td> |
| 148 | <td style=\"border:1px solid #000;padding:4px;width:35%\">${esc(seller.name||'—')}</td> |
| 149 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:15%\">شماره اقتصادی فروشنده</td> |
| 150 | <td style=\"border:1px solid #000;padding:4px;width:35%\">${esc(seller.economic_code||'0000')}</td> |
| 151 | </tr> |
| 152 | <tr> |
| 153 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">شماره ثبت / شناسه ملی</td> |
| 154 | <td style=\"border:1px solid #000;padding:4px\">${esc(seller.national_id||'—')}</td> |
| 155 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">کد پستی</td> |
| 156 | <td style=\"border:1px solid #000;padding:4px\">${esc(seller.postal_code||'—')}</td> |
| 157 | </tr> |
| 158 | </table> |
| 159 | |
| 160 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #000;font-size:10px;margin-bottom:4px\"> |
| 161 | <tr><td colspan=\"4\" style=\"border:1px solid #000;padding:4px;background:#f1f5f9;font-weight:bold\">مشخصات خریدار</td></tr> |
| 162 | <tr> |
| 163 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:15%\">نام شخص</td> |
| 164 | <td style=\"border:1px solid #000;padding:4px;width:35%\">${esc(contact.name||inv.contactName)}</td> |
| 165 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:15%\">شماره اقتصادی خریدار</td> |
| 166 | <td style=\"border:1px solid #000;padding:4px;width:35%\">${esc(contact.economic_code||'0000')}</td> |
| 167 | </tr> |
| 168 | <tr> |
| 169 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">شماره ثبت / شناسه ملی</td> |
| 170 | <td style=\"border:1px solid #000;padding:4px\">${esc(contact.national_id||'—')}</td> |
| 171 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">کد پستی</td> |
| 172 | <td style=\"border:1px solid #000;padding:4px\">${esc(contact.postal_code||'—')}</td> |
| 173 | </tr> |
| 174 | </table> |
| 175 | |
| 176 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #000;font-size:9.5px\"> |
| 177 | <thead> |
| 178 | <tr style=\"background:#f1f5f9;font-weight:bold;text-align:center\"> |
| 179 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">ردیف</th> |
| 180 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">شرح کالا/خدمت</th> |
| 181 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">تعداد/مقدار</th> |
| 182 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">واحد اندازهگیری</th> |
| 183 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">مبلغ واحد (ریال)</th> |
| 184 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">مبلغ کل (ریال)</th> |
| 185 | <th style=\"border:1px solid #000;padding:4px\" colspan=\"3\">مالیات بر ارزش افزوده</th> |
| 186 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">شناسه کالا/خدمت داخلی</th> |
| 187 | <th style=\"border:1px solid #000;padding:4px\" rowspan=\"2\">شناسه کالا/خدمت</th> |
| 188 | </tr> |
| 189 | <tr style=\"background:#f1f5f9;font-weight:bold;text-align:center\"> |
| 190 | <th style=\"border:1px solid #000;padding:4px\">نرخ</th> |
| 191 | <th style=\"border:1px solid #000;padding:4px\">مبلغ</th> |
| 192 | <th style=\"border:1px solid #000;padding:4px\">مبلغ کل کالا/خدمت</th> |
| 193 | </tr> |
| 194 | </thead> |
| 195 | <tbody>${itemsRows}</tbody> |
| 196 | </table> |
| 197 | |
| 198 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #000;font-size:10px;margin-top:6px\"> |
| 199 | <tr> |
| 200 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:25%\">جمع کل مبلغ کالا/خدمت</td> |
| 201 | <td style=\"border:1px solid #000;padding:4px;width:25%;text-align:left\">${baseTotal.toLocaleString('fa-IR')} ${cur}</td> |
| 202 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc;width:25%\">جمع کل مالیات بر ارزش افزوده</td> |
| 203 | <td style=\"border:1px solid #000;padding:4px;width:25%;text-align:left\">${vatTotal.toLocaleString('fa-IR')} ${cur}</td> |
| 204 | </tr> |
| 205 | <tr> |
| 206 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">مبلغ کل صورتحساب</td> |
| 207 | <td style=\"border:1px solid #000;padding:4px;text-align:left;font-weight:bold\" colspan=\"3\">${grandTotal.toLocaleString('fa-IR')} ${cur}</td> |
| 208 | </tr> |
| 209 | <tr> |
| 210 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">مصرفکننده نهایی</td> |
| 211 | <td style=\"border:1px solid #000;padding:4px\">خیر</td> |
| 212 | <td style=\"border:1px solid #000;padding:4px;background:#f8fafc\">مالیات موضوع ماده ۱۷</td> |
| 213 | <td style=\"border:1px solid #000;padding:4px;text-align:left\">۰ ${cur}</td> |
| 214 | </tr> |
| 215 | </table> |
| 216 | |
| 217 | ${contractText?`<div style=\"border:1px solid #000;padding:6px;margin-top:6px;font-size:10.5px;line-height:1.7;background:#fffbeb\">${contractText}</div>`:''} |
| 218 | |
| 219 | <table style=\"width:100%;border-collapse:collapse;margin-top:8px;font-size:10.5px\"> |
| 220 | <tr> |
| 221 | <td style=\"width:50%;border:1px solid #000;padding:8px;height:70px;vertical-align:top\"> |
| 222 | <div style=\"font-weight:bold;margin-bottom:4px\">مهر و امضای فروشنده</div> |
| 223 | <div style=\"font-size:9.5px;color:#475569\">${esc(seller.name||'')}</div> |
| 224 | </td> |
| 225 | <td style=\"width:50%;border:1px solid #000;padding:8px;height:70px;vertical-align:top\"> |
| 226 | <div style=\"font-weight:bold;margin-bottom:4px\">مهر و امضای خریدار</div> |
| 227 | <div style=\"font-size:9.5px;color:#475569\">${esc(contact.name||inv.contactName)}</div> |
| 228 | </td> |
| 229 | </tr> |
| 230 | </table> |
| 231 | </div>`; |
| 232 | } |
| 233 | |
| 234 | function printElectronicDoc(invId){ |
| 235 | const inv=getMyInvoices().find(i=>i.id===invId); |
| 236 | if(!inv||!inv.electronicDoc){ |
| 237 | alert('سند الکترونیکی برای این فاکتور ثبت نشده است.'); |
| 238 | return; |
| 239 | } |
| 240 | const myCompanies=getMyCompanies(); |
| 241 | const myContacts=getMyContacts(); |
| 242 | const seller=myCompanies.find(c=>c.id===inv.companyId)||myCompanies[0]||{}; |
| 243 | const contact=myContacts.find(c=>c.id===inv.contactId)||{}; |
| 244 | const html=buildElectronicDocPage(inv,inv.electronicDoc,seller,contact); |
| 245 | stageInvoicePrint(html,{paper:'A4',orientation:'landscape',widthMm:297,heightMm:210,marginMm:7}); |
| 246 | } |
| 247 | |
| 248 | // ============ فاکتورهای معمول ============ |
| 249 | const FORMAL_ROWS_PER_PAGE=12; |
| 250 | const NONFORMAL_ROWS_PER_PAGE=10; |
| 251 | function computeInvoiceLines(inv){ |
| 252 | const n=inv.items.length; |
| 253 | const afterDiscountTotal=Math.max(0,(inv.subtotal||0)-(inv.discount||0)); |
| 254 | let usedDiscount=0,usedVat=0; |
| 255 | return inv.items.map((it,idx)=>{ |
| 256 | const lineSubtotal=it.lineTotal; |
| 257 | const isLastItem=(idx===n-1); |
| 258 | let lineDiscount,lineVat; |
| 259 | if(isLastItem){ |
| 260 | lineDiscount=Math.max(0,(inv.discount||0)-usedDiscount); |
| 261 | lineVat=Math.max(0,(inv.vat||0)-usedVat); |
| 262 | }else{ |
| 263 | lineDiscount=(inv.subtotal>0)?Math.round((inv.discount||0)*(lineSubtotal/inv.subtotal)):0; |
| 264 | const lineAfterDiscount=lineSubtotal-lineDiscount; |
| 265 | lineVat=(afterDiscountTotal>0&&inv.vat>0)?Math.round((inv.vat||0)*(lineAfterDiscount/afterDiscountTotal)):0; |
| 266 | } |
| 267 | usedDiscount+=lineDiscount;usedVat+=lineVat; |
| 268 | const lineNet=lineSubtotal-lineDiscount+lineVat; |
| 269 | return {rowNo:idx+1,prodName:it.prodName,qty:it.qty,unit:it.unit||'عدد',price:it.price,lineSubtotal,lineDiscount,lineVat,lineNet}; |
| 270 | }); |
| 271 | } |
| 272 | function buildFormalPage(items,seller,contact,inv,opt){ |
| 273 | const cur=inv.currencyLabel||'ریال'; |
| 274 | const isLast=opt.isLastPage; |
| 275 | const rowsHtml=items.map(li=>` |
| 276 | <tr style=\"text-align:center\"> |
| 277 | <td style=\"border:1px solid #1e293b;padding:3px 6px;font-size:10.5px\">${li.rowNo.toLocaleString('fa-IR')}</td> |
| 278 | <td style=\"border:1px solid #1e293b;padding:3px 6px;text-align:right;font-size:10.5px;font-weight:600\">${esc(li.prodName)}</td> |
| 279 | <td style=\"border:1px solid #1e293b;padding:3px 6px;font-size:10.5px\">${li.qty.toLocaleString('fa-IR')}</td> |
| 280 | <td style=\"border:1px solid #1e293b;padding:3px 6px;font-size:10.5px\">${esc(li.unit)}</td> |
| 281 | <td style=\"border:1px solid #1e293b;padding:3px 6px;text-align:left;font-size:10.5px\">${li.price.toLocaleString('fa-IR')}</td> |
| 282 | <td style=\"border:1px solid #1e293b;padding:3px 6px;text-align:left;font-size:10.5px\">${li.lineSubtotal.toLocaleString('fa-IR')}</td> |
| 283 | <td style=\"border:1px solid #1e293b;padding:3px 6px;text-align:left;font-size:10.5px\">${li.lineDiscount.toLocaleString('fa-IR')}</td> |
| 284 | <td style=\"border:1px solid #1e293b;padding:3px 6px;text-align:left;font-size:10.5px\">${li.lineVat.toLocaleString('fa-IR')}</td> |
| 285 | <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> |
| 286 | </tr>`).join(''); |
| 287 | const sellerIds=`${esc(seller.national_id||'—')} / ${esc(seller.reg_number||'—')}`; |
| 288 | const contactIds=`${esc(contact.national_id||'—')} / ${esc(contact.reg_number||'—')}`; |
| 289 | const cumSub=opt.cumulativeSubtotal||0; |
| 290 | const cumDisc=opt.cumulativeDiscount||0; |
| 291 | const cumVat=opt.cumulativeVat||0; |
| 292 | const cumNet=opt.cumulativeNet||0; |
| 293 | const subtotalLabel=isLast?'جمع کل اقلام:':'جمع اقلام تا این صفحه:'; |
| 294 | const discountLabel=isLast?'مجموع تخفیف:':'مجموع تخفیف تا این صفحه:'; |
| 295 | const vatLabel=isLast?'مالیات و عوارض ارزش افزوده:':'مالیات تا این صفحه:'; |
| 296 | const netLabel=isLast?'مبلغ قابل پرداخت:':'جمع تا این صفحه:'; |
| 297 | const wordsLabel=isLast?'مبلغ کل به حروف:':'مبلغ تا این صفحه به حروف:'; |
| 298 | const summaryBox=` |
| 299 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #1e3a8a;font-size:10.5px;margin-top:3px\"> |
| 300 | <tr> |
| 301 | <td style=\"width:60%;border:1px solid #1e3a8a;padding:6px;vertical-align:top;background:#f8fafc\"> |
| 302 | <div style=\"margin-bottom:4px\"><strong>${wordsLabel}</strong> ${numberToPersianWords(cumNet,cur)}</div> |
| 303 | ${isLast?`<div style=\"margin-bottom:4px\"><strong>شرایط و نحوه پرداخت:</strong> ${inv.paymentMethod==='credit'?'نقدی ☐ غیرنقدی (نسیه/چک) ☑':'نقدی ☑ غیرنقدی (نسیه/چک) ☐'}</div><div style=\"font-size:9.5px;color:#475569;line-height:1.5\"><strong>توضیحات:</strong> ${esc(inv.description||seller.footer||'تحویل کالا منوط به تسویه نهایی میباشد.')}</div>`:`<div style=\"font-size:9.5px;color:#64748b;margin-top:4px\">(ادامه اقلام در صفحه بعد درج گردیده است...)</div>`} |
| 304 | </td> |
| 305 | <td style=\"width:40%;border:1px solid #1e3a8a;padding:0\"> |
| 306 | <table style=\"width:100%;border-collapse:collapse;font-size:10.5px\"> |
| 307 | <tr><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\">${subtotalLabel}</td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\">${cumSub.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 308 | <tr><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\">${discountLabel}</td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\">${cumDisc.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 309 | <tr><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\">${vatLabel}</td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\">${cumVat.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 310 | <tr style=\"background:#eff6ff;font-weight:bold;font-size:11.5px;color:#1e3a8a\"><td style=\"padding:5px 8px\">${netLabel}</td><td style=\"padding:5px 8px;text-align:left\">${cumNet.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 311 | </table> |
| 312 | </td> |
| 313 | </tr> |
| 314 | </table>`; |
| 315 | const signatures=isLast?` |
| 316 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #1e3a8a;margin-top:6px;text-align:center;font-size:10.5px\"> |
| 317 | <tr> |
| 318 | <td style=\"width:50%;height:50px;vertical-align:top;border:1px solid #1e3a8a;padding:5px;background:#fff\"><div style=\"font-weight:bold\">مهر و امضای فروشنده</div></td> |
| 319 | <td style=\"width:50%;height:50px;vertical-align:top;border:1px solid #1e3a8a;padding:5px;background:#fff\"><div style=\"font-weight:bold\">مهر و امضای خریدار</div></td> |
| 320 | </tr> |
| 321 | </table>`:''; |
| 322 | return ` |
| 323 | <div class=\"invoice-a4-page landscape\" style=\"background:#fff;padding:6mm 8mm;color:#000;font-family:'Vazirmatn FD',sans-serif\"> |
| 324 | <table style=\"width:100%;border-collapse:collapse;margin-bottom:3px\"> |
| 325 | <tr> |
| 326 | <td style=\"width:28%;padding:5px;vertical-align:middle\"></td> |
| 327 | <td style=\"width:44%;padding:6px;text-align:center;vertical-align:middle;background:#eff6ff\"> |
| 328 | <h1 style=\"font-size:15px;margin:0;font-weight:bold;color:#1e3a8a\">صورتحساب فروش کالا و خدمات</h1> |
| 329 | </td> |
| 330 | <td style=\"width:28%;padding:5px;font-size:10.5px;vertical-align:middle;text-align:left\"> |
| 331 | <div>شماره سریال: <strong style=\"color:#b91c1c\">${esc(inv.number)}</strong></div> |
| 332 | <div style=\"margin-top:1px\">تاریخ صدور: <strong>${esc(inv.date)}</strong></div> |
| 333 | <div style=\"margin-top:1px;color:#64748b;font-size:9.5px\">صفحه: ${opt.pageNum} از ${opt.totalPages}</div> |
| 334 | </td> |
| 335 | </tr> |
| 336 | </table> |
| 337 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #1e3a8a;font-size:10px;margin-bottom:3px\"> |
| 338 | <tr style=\"background:#f8fafc;font-weight:bold\"><td colspan=\"4\" style=\"border:1px solid #1e3a8a;padding:2px 6px;color:#1e3a8a\">مشخصات فروشنده</td></tr> |
| 339 | <tr> |
| 340 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:15%;background:#f1f5f9\">نام شخص حقیقی/حقوقی:</td> |
| 341 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:35%\"><strong>${esc(seller.name||'—')}</strong></td> |
| 342 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:15%;background:#f1f5f9\">شماره اقتصادی:</td> |
| 343 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:35%\">${esc(seller.economic_code||'—')}</td> |
| 344 | </tr> |
| 345 | <tr> |
| 346 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">شناسه ملی / شماره ثبت:</td> |
| 347 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px\">${sellerIds}</td> |
| 348 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">کد پستی ۱۰ رقمی:</td> |
| 349 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px\">${esc(seller.postal_code||'—')}</td> |
| 350 | </tr> |
| 351 | <tr> |
| 352 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">نشانی و تلفن:</td> |
| 353 | <td colspan=\"3\" style=\"border:1px solid #cbd5e1;padding:3px 6px\">${esc(seller.address||'—')} ${esc(seller.phone?' | تلفن: '+seller.phone:'')}</td> |
| 354 | </tr> |
| 355 | </table> |
| 356 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #1e3a8a;font-size:10px;margin-bottom:3px\"> |
| 357 | <tr style=\"background:#f8fafc;font-weight:bold\"><td colspan=\"4\" style=\"border:1px solid #1e3a8a;padding:2px 6px;color:#1e3a8a\">مشخصات خریدار</td></tr> |
| 358 | <tr> |
| 359 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:15%;background:#f1f5f9\">نام شخص حقیقی/حقوقی:</td> |
| 360 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:35%\"><strong>${esc(contact.name||inv.contactName)}</strong></td> |
| 361 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:15%;background:#f1f5f9\">شماره اقتصادی:</td> |
| 362 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;width:35%\">${esc(contact.economic_code||'—')}</td> |
| 363 | </tr> |
| 364 | <tr> |
| 365 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">شناسه ملی / شماره ثبت:</td> |
| 366 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px\">${contactIds}</td> |
| 367 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">کد پستی ۱۰ رقمی:</td> |
| 368 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px\">${esc(contact.postal_code||'—')}</td> |
| 369 | </tr> |
| 370 | <tr> |
| 371 | <td style=\"border:1px solid #cbd5e1;padding:3px 6px;background:#f1f5f9\">نشانی و تلفن:</td> |
| 372 | <td colspan=\"3\" style=\"border:1px solid #cbd5e1;padding:3px 6px\">${esc(contact.address||'—')} ${esc(contact.mobile?' | تلفن: '+contact.mobile:'')}</td> |
| 373 | </tr> |
| 374 | </table> |
| 375 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #1e3a8a;font-size:10px\"> |
| 376 | <thead> |
| 377 | <tr style=\"background:#1e3a8a;color:#fff;font-weight:bold;text-align:center\"> |
| 378 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:28px\">ردیف</th> |
| 379 | <th style=\"border:1px solid #1e3a8a;padding:4px 6px;text-align:right\">شرح کالا یا خدمات</th> |
| 380 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:42px\">تعداد</th> |
| 381 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:42px\">واحد</th> |
| 382 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:105px\">مبلغ واحد (${cur})</th> |
| 383 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:110px\">مبلغ کل (${cur})</th> |
| 384 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:80px\">تخفیف (${cur})</th> |
| 385 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:90px\">مالیات (${cur})</th> |
| 386 | <th style=\"border:1px solid #1e3a8a;padding:4px;width:120px\">مبلغ نهایی (${cur})</th> |
| 387 | </tr> |
| 388 | </thead> |
| 389 | <tbody> |
| 390 | ${!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>`:''} |
| 391 | ${rowsHtml} |
| 392 | </tbody> |
| 393 | </table> |
| 394 | ${summaryBox} |
| 395 | ${signatures} |
| 396 | </div>`; |
| 397 | } |
| 398 | function buildNonFormalPage(items,seller,contact,inv,opt){ |
| 399 | const cur=inv.currencyLabel||'ریال'; |
| 400 | const isPre=inv.kind==='pre_invoice'; |
| 401 | const isLast=opt.isLastPage; |
| 402 | const hasVat=isPre&&inv.vat>0; |
| 403 | const title=isPre?'پیشفاکتور فروش کالا و خدمات':'فاکتور فروش کالا و خدمات'; |
| 404 | const rowsHtml=items.map(li=>hasVat?` |
| 405 | <tr style=\"text-align:center\"> |
| 406 | <td style=\"border:1px solid #334155;padding:3px 5px;font-size:10px\">${li.rowNo.toLocaleString('fa-IR')}</td> |
| 407 | <td style=\"border:1px solid #334155;padding:3px 6px;text-align:right;font-size:10px;font-weight:600\">${esc(li.prodName)}</td> |
| 408 | <td style=\"border:1px solid #334155;padding:3px 5px;font-size:10px\">${esc(li.unit)}</td> |
| 409 | <td style=\"border:1px solid #334155;padding:3px 5px;font-size:10px\">${li.qty.toLocaleString('fa-IR')}</td> |
| 410 | <td style=\"border:1px solid #334155;padding:3px 5px;text-align:left;font-size:10px\">${li.price.toLocaleString('fa-IR')}</td> |
| 411 | <td style=\"border:1px solid #334155;padding:3px 5px;text-align:left;font-size:10px\">${li.lineSubtotal.toLocaleString('fa-IR')}</td> |
| 412 | <td style=\"border:1px solid #334155;padding:3px 5px;text-align:left;font-size:10px\">${li.lineVat.toLocaleString('fa-IR')}</td> |
| 413 | <td style=\"border:1px solid #334155;padding:3px 5px;text-align:left;font-size:10px;font-weight:bold\">${li.lineNet.toLocaleString('fa-IR')}</td> |
| 414 | </tr>`:` |
| 415 | <tr style=\"text-align:center\"> |
| 416 | <td style=\"border:1px solid #334155;padding:4px 5px;font-size:10.5px\">${li.rowNo.toLocaleString('fa-IR')}</td> |
| 417 | <td style=\"border:1px solid #334155;padding:4px 8px;text-align:right;font-size:10.5px;font-weight:600\">${esc(li.prodName)}</td> |
| 418 | <td style=\"border:1px solid #334155;padding:4px 5px;font-size:10.5px\">${esc(li.unit)}</td> |
| 419 | <td style=\"border:1px solid #334155;padding:4px 5px;font-size:10.5px\">${li.qty.toLocaleString('fa-IR')}</td> |
| 420 | <td style=\"border:1px solid #334155;padding:4px 5px;text-align:left;font-size:10.5px\">${li.price.toLocaleString('fa-IR')}</td> |
| 421 | <td style=\"border:1px solid #334155;padding:4px 5px;text-align:left;font-size:10.5px;font-weight:bold\">${li.lineSubtotal.toLocaleString('fa-IR')}</td> |
| 422 | </tr>`).join(''); |
| 423 | const cumSub=opt.cumulativeSubtotal||0; |
| 424 | const cumDisc=opt.cumulativeDiscount||0; |
| 425 | const cumVat=opt.cumulativeVat||0; |
| 426 | const cumNet=opt.cumulativeNet||0; |
| 427 | const subtotalLabel=isLast?'قیمت کل اقلام:':'جمع اقلام تا این صفحه:'; |
| 428 | const discountLabel=isLast?'تخفیف:':'تخفیف تا این صفحه:'; |
| 429 | const vatLabel=isLast?'مالیات ارزش افزوده:':'مالیات تا این صفحه:'; |
| 430 | const netLabel=isLast?`مبلغ کل (${cur}):`:'جمع تا این صفحه:'; |
| 431 | const wordsLabel=isLast?'مبلغ به حروف:':'مبلغ تا این صفحه به حروف:'; |
| 432 | const summaryBox=` |
| 433 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #334155;font-size:10.5px;margin-top:5px\"> |
| 434 | <tr> |
| 435 | <td style=\"width:60%;border:1px solid #334155;padding:6px;vertical-align:top;background:#f8fafc\"> |
| 436 | <div style=\"margin-bottom:4px\"><strong>${wordsLabel}</strong> ${numberToPersianWords(cumNet,cur)}</div> |
| 437 | ${isLast?`<div style=\"font-size:9.5px;color:#475569;line-height:1.5\"><strong>توضیحات:</strong> ${esc(inv.description||seller.footer||(isPre?'اعتبار پیشفاکتور به مدت ۴۸ ساعت میباشد.':'از خرید شما سپاسگزاریم.'))}</div>`:`<div style=\"font-size:9.5px;color:#64748b\">(ادامه در صفحه بعد...)</div>`} |
| 438 | </td> |
| 439 | <td style=\"width:40%;border:1px solid #334155;padding:0\"> |
| 440 | <table style=\"width:100%;border-collapse:collapse;font-size:10.5px\"> |
| 441 | <tr><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\">${subtotalLabel}</td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\">${cumSub.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 442 | ${cumDisc>0||inv.discount>0?`<tr><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\">${discountLabel}</td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\">${cumDisc.toLocaleString('fa-IR')} ${cur}</td></tr>`:''} |
| 443 | ${hasVat?`<tr style=\"background:#fffbeb\"><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px\"><strong>${vatLabel}</strong></td><td style=\"border-bottom:1px solid #cbd5e1;padding:3px 8px;text-align:left\"><strong>${cumVat.toLocaleString('fa-IR')} ${cur}</strong></td></tr>`:''} |
| 444 | <tr style=\"background:#f1f5f9;font-weight:bold;font-size:11.5px\"><td style=\"padding:5px 8px\">${netLabel}</td><td style=\"padding:5px 8px;text-align:left\">${cumNet.toLocaleString('fa-IR')} ${cur}</td></tr> |
| 445 | </table> |
| 446 | </td> |
| 447 | </tr> |
| 448 | </table>`; |
| 449 | const signatures=isLast?` |
| 450 | <table style=\"width:100%;border-collapse:collapse;border:1px solid #334155;margin-top:6px;text-align:center;font-size:10.5px\"> |
| 451 | <tr> |
| 452 | <td style=\"width:50%;height:50px;vertical-align:top;border:1px solid #334155;padding:5px;background:#fff\"><div style=\"font-weight:bold\">مهر و امضای فروشنده</div></td> |
| 453 | <td style=\"width:50%;height:50px;vertical-align:top;border:1px solid #334155;padding:5px;background:#fff\"><div style=\"font-weight:bold\">مهر و امضای خریدار</div></td> |
| 454 | </tr> |
| 455 | </table>`:''; |
| 456 | return ` |
| 457 | <div class=\"invoice-a4-page landscape\" style=\"background:#fff;padding:7mm 8mm;color:#000;font-family:'Vazirmatn FD',sans-serif\"> |
| 458 | <table style=\"width:100%;border-collapse:collapse;margin-bottom:5px\"> |
| 459 | <tr> |
| 460 | <td style=\"width:30%;padding:6px;vertical-align:middle\"></td> |
| 461 | <td style=\"width:40%;padding:6px;text-align:center;vertical-align:middle;background:#f8fafc\"> |
| 462 | <h1 style=\"font-size:15px;margin:0;font-weight:bold;color:#0f172a\">${title}</h1> |
| 463 | </td> |
| 464 | <td style=\"width:30%;padding:6px;font-size:10.5px;vertical-align:middle;text-align:left\"> |
| 465 | <div>شماره: <strong style=\"font-size:11.5px\">#${esc(inv.number)}</strong></div> |
| 466 | <div style=\"margin-top:1px\">تاریخ: <strong>${esc(inv.date)}</strong></div> |
| 467 | <div style=\"margin-top:1px;color:#64748b;font-size:9.5px\">صفحه: ${opt.pageNum} از ${opt.totalPages}</div> |
| 468 | </td> |
| 469 | </tr> |
| 470 | </table> |
| 471 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #334155;font-size:10.5px;margin-bottom:5px\"> |
| 472 | <tr> |
| 473 | <td style=\"width:50%;border:1px solid #334155;padding:5px;vertical-align:top;background:#f8fafc\"> |
| 474 | <div style=\"font-weight:bold;color:#334155;margin-bottom:2px\">مشخصات فروشنده:</div> |
| 475 | <div>نام: <strong>${esc(seller.name||'—')}</strong></div> |
| 476 | <div>نشانی: ${esc(seller.address||'—')}</div> |
| 477 | <div>تلفن تماس: ${esc(seller.phone||'—')}</div> |
| 478 | </td> |
| 479 | <td style=\"width:50%;border:1px solid #334155;padding:5px;vertical-align:top;background:#f8fafc\"> |
| 480 | <div style=\"font-weight:bold;color:#334155;margin-bottom:2px\">مشخصات خریدار:</div> |
| 481 | <div>نام: <strong>${esc(contact.name||inv.contactName)}</strong></div> |
| 482 | <div>نشانی: ${esc(contact.address||'—')}</div> |
| 483 | <div>تلفن: ${esc(contact.mobile||'—')}</div> |
| 484 | </td> |
| 485 | </tr> |
| 486 | </table> |
| 487 | <table style=\"width:100%;border-collapse:collapse;border:1.5px solid #334155;font-size:10.5px\"> |
| 488 | <thead> |
| 489 | <tr style=\"background:#334155;color:#fff;font-weight:bold;text-align:center\"> |
| 490 | <th style=\"border:1px solid #334155;padding:5px 4px;width:32px\">ردیف</th> |
| 491 | <th style=\"border:1px solid #334155;padding:5px 8px;text-align:right\">شرح کالا | خدمات</th> |
| 492 | <th style=\"border:1px solid #334155;padding:5px 4px;width:60px\">واحد</th> |
| 493 | <th style=\"border:1px solid #334155;padding:5px 4px;width:60px\">مقدار</th> |
| 494 | <th style=\"border:1px solid #334155;padding:5px 4px;width:${hasVat?'110':'150'}px;text-align:left\">قیمت واحد (${cur})</th> |
| 495 | <th style=\"border:1px solid #334155;padding:5px 4px;width:${hasVat?'120':'170'}px;text-align:left\">قیمت کل (${cur})</th> |
| 496 | ${hasVat?`<th style=\"border:1px solid #334155;padding:5px 4px;width:110px;text-align:left\">مالیات (${cur})</th><th style=\"border:1px solid #334155;padding:5px 4px;width:130px;text-align:left\">مبلغ نهایی (${cur})</th>`:''} |
| 497 | </tr> |
| 498 | </thead> |
| 499 | <tbody> |
| 500 | ${!opt.isFirstPage?`<tr style=\"background:#fef3c7;font-weight:bold;font-size:9.5px\"><td colspan=\"${hasVat?6:5}\" style=\"border:1px solid #334155;padding:3px;text-align:left\">نقل از صفحه قبل:</td><td colspan=\"${hasVat?2:1}\" style=\"border:1px solid #334155;padding:3px;text-align:left\">${(opt.cumulativeBefore||0).toLocaleString('fa-IR')} ${cur}</td></tr>`:''} |
| 501 | ${rowsHtml} |
| 502 | </tbody> |
| 503 | </table> |
| 504 | ${summaryBox} |
| 505 | ${signatures} |
| 506 | </div>`; |
| 507 | } |
| 508 | function renderAndPrintDirect(invId){ |
| 509 | const inv=getMyInvoices().find(i=>i.id===invId); |
| 510 | if(!inv)return; |
| 511 | const myCompanies=getMyCompanies(); |
| 512 | const myContacts=getMyContacts(); |
| 513 | const seller=myCompanies.find(c=>c.id===inv.companyId)||myCompanies[0]||{}; |
| 514 | const contact=myContacts.find(c=>c.id===inv.contactId)||{}; |
| 515 | const isFormal=(inv.kind==='formal'); |
| 516 | const isPreInvoice=(inv.kind==='pre_invoice'); |
| 517 | const builder=isFormal?buildFormalPage:buildNonFormalPage; |
| 518 | const rowsPerPage=isFormal?FORMAL_ROWS_PER_PAGE:NONFORMAL_ROWS_PER_PAGE; |
| 519 | const allLines=computeInvoiceLines(inv); |
| 520 | if(!allLines.length){alert('این سند ردیف قابل چاپ ندارد.');return;} |
| 521 | const pageGroups=[]; |
| 522 | let cumulativeSub=0,cumulativeDisc=0,cumulativeVat=0; |
| 523 | for(let start=0;start<allLines.length;start+=rowsPerPage){ |
| 524 | const pageItems=allLines.slice(start,start+rowsPerPage); |
| 525 | const isFirstPage=(start===0); |
| 526 | const isLastPage=(start+rowsPerPage>=allLines.length); |
| 527 | const pageSub=pageItems.reduce((s,li)=>s+li.lineSubtotal,0); |
| 528 | const pageDisc=pageItems.reduce((s,li)=>s+li.lineDiscount,0); |
| 529 | const pageVat=pageItems.reduce((s,li)=>s+li.lineVat,0); |
| 530 | const cumSubAfter=cumulativeSub+pageSub; |
| 531 | const cumDiscAfter=cumulativeDisc+pageDisc; |
| 532 | const cumVatAfter=cumulativeVat+pageVat; |
| 533 | const cumNetAfter=cumSubAfter-cumDiscAfter+cumVatAfter; |
| 534 | pageGroups.push({items:pageItems,isFirstPage,isLastPage,cumulativeBefore:cumulativeSub,cumulativeSubtotal:cumSubAfter,cumulativeDiscount:cumDiscAfter,cumulativeVat:cumVatAfter,cumulativeNet:cumNetAfter}); |
| 535 | cumulativeSub=cumSubAfter;cumulativeDisc=cumDiscAfter;cumulativeVat=cumVatAfter; |
| 536 | } |
| 537 | const totalPages=pageGroups.length; |
| 538 | const containerHtml=pageGroups.map((g,idx)=>builder(g.items,seller,contact,inv,{pageNum:idx+1,totalPages,isFirstPage:g.isFirstPage,isLastPage:g.isLastPage,cumulativeBefore:g.cumulativeBefore,cumulativeSubtotal:g.cumulativeSubtotal,cumulativeDiscount:g.cumulativeDiscount,cumulativeVat:g.cumulativeVat,cumulativeNet:g.cumulativeNet})).join(''); |
| 539 | const spec=getInvoicePrintSpec(inv); |
| 540 | stageInvoicePrint(containerHtml,spec); |
| 541 | } |