سامانه صدور فاکتور و حسابداری
fix: normalize every printable invoice text digit to Persian without touching stored identifiers
davoodmehraban89 committed
Oct 11, 2026 at 16:31 UTC
23b3f5488dbb85f2aac6e24e72cd73a1a8862545
1 file changed
+20
-2
js/print.js
+20
-2
@@ -17,7 +17,24 @@ function getInvoicePrintSpec(inv){
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
+// Print-only display normalization: stored serials, API identifiers and numeric values stay unchanged.
21
+function localizePrintHtmlDigits(html){
22
+ const template=document.createElement('template');
23
+ template.innerHTML=String(html??'');
24
+ const walker=document.createTreeWalker(template.content,NodeFilter.SHOW_TEXT);
25
+ const latin='0123456789',arabic='٠١٢٣٤٥٦٧٨٩',persian='۰۱۲۳۴۵۶۷۸۹';
26
+ let node;
27
+ while((node=walker.nextNode())){
28
+ if(node.parentElement&&/^(SCRIPT|STYLE|NOSCRIPT)$/i.test(node.parentElement.tagName))continue;
29
+ node.nodeValue=node.nodeValue.replace(/[0-9٠-٩]/g,ch=>{
30
+ const n=latin.includes(ch)?latin.indexOf(ch):arabic.indexOf(ch);
31
+ return n<0?ch:persian[n];
32
+ });
33
+ }
34
+ return template.innerHTML;
35
+}
36
function buildIsolatedPrintDocument(content,spec){
37
+ content=localizePrintHtmlDigits(content);
38
const usableWidth=Math.max(1,spec.widthMm-(spec.marginMm*2));
39
const usableHeight=Math.max(1,spec.heightMm-(spec.marginMm*2));
40
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>'
@@ -55,12 +72,13 @@ function printIsolatedDocument(content,spec){
72
return frame;
73
}
74
function stageInvoicePrint(content,spec){
75
+ const localized=localizePrintHtmlDigits(content);
76
const preview=document.getElementById('printable-invoice');
59
- if(preview){preview.innerHTML=content;preview.style.display='none';preview.dataset.paper=spec.paper;preview.dataset.orientation=spec.orientation;}
77
+ if(preview){preview.innerHTML=localized;preview.style.display='none';preview.dataset.paper=spec.paper;preview.dataset.orientation=spec.orientation;}
78
let orientationStyle=document.getElementById('dynamic-print-orientation');
79
if(!orientationStyle){orientationStyle=document.createElement('style');orientationStyle.id='dynamic-print-orientation';document.head.appendChild(orientationStyle);}
80
orientationStyle.innerHTML='@media print { @page { size: '+spec.paper+' '+spec.orientation+'; margin: '+spec.marginMm+'mm; } }';
63
- return printIsolatedDocument(content,spec);
81
+ return printIsolatedDocument(localized,spec);
82
}
83
84
function buildElectronicDocPage(inv,edoc,seller,contact){