سامانه صدور فاکتور و حسابداری

Restore formal A4 and compact A5 print specifications

davoodmehraban89 committed Sep 28, 2026 at 13:42 UTC 20e3a5b8105522a61ef4be9892a378d108052379
1 file changed +10 -6
js/print.js
+10 -6
@@ -207,7 +207,8 @@ function printElectronicDoc(invId){
207 }
208
209 // ============ فاکتورهای معمول ============
210 -const MAX_ROWS_PER_PAGE=10;
210 +const FORMAL_ROWS_PER_PAGE=12;
211 +const NONFORMAL_ROWS_PER_PAGE=10;
212 function computeInvoiceLines(inv){
213 const n=inv.items.length;
214 const afterDiscountTotal=Math.max(0,(inv.subtotal||0)-(inv.discount||0));
@@ -260,7 +261,7 @@ function buildFormalPage(items,seller,contact,inv,opt){
261 <tr>
262 <td style=\"width:60%;border:1px solid #1e3a8a;padding:6px;vertical-align:top;background:#f8fafc\">
263 <div style=\"margin-bottom:4px\"><strong>${wordsLabel}</strong> ${numberToPersianWords(cumNet,cur)}</div>
263 - ${isLast?`<div style=\"margin-bottom:4px\"><strong>شرایط و نحوه پرداخت:</strong> نقدی ☑ &nbsp;&nbsp;&nbsp; غیرنقدی (نسیه/چک) ☐</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>`}
264 + ${isLast?`<div style=\"margin-bottom:4px\"><strong>شرایط و نحوه پرداخت:</strong> ${inv.paymentMethod==='credit'?'نقدی ☐ &nbsp;&nbsp;&nbsp; غیرنقدی (نسیه/چک) ☑':'نقدی ☑ &nbsp;&nbsp;&nbsp; غیرنقدی (نسیه/چک) ☐'}</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>`}
265 </td>
266 <td style=\"width:40%;border:1px solid #1e3a8a;padding:0\">
267 <table style=\"width:100%;border-collapse:collapse;font-size:10.5px\">
@@ -474,13 +475,14 @@ function renderAndPrintDirect(invId){
475 const contact=myContacts.find(c=>c.id===inv.contactId)||{};
476 const isFormal=(inv.kind==='formal');
477 const builder=isFormal?buildFormalPage:buildNonFormalPage;
478 + const rowsPerPage=isFormal?FORMAL_ROWS_PER_PAGE:NONFORMAL_ROWS_PER_PAGE;
479 const allLines=computeInvoiceLines(inv);
480 const pageGroups=[];
481 let cumulativeSub=0,cumulativeDisc=0,cumulativeVat=0;
480 - for(let start=0;start<allLines.length;start+=MAX_ROWS_PER_PAGE){
481 - const pageItems=allLines.slice(start,start+MAX_ROWS_PER_PAGE);
482 + for(let start=0;start<allLines.length;start+=rowsPerPage){
483 + const pageItems=allLines.slice(start,start+rowsPerPage);
484 const isFirstPage=(start===0);
483 - const isLastPage=(start+MAX_ROWS_PER_PAGE>=allLines.length);
485 + const isLastPage=(start+rowsPerPage>=allLines.length);
486 const pageSub=pageItems.reduce((s,li)=>s+li.lineSubtotal,0);
487 const pageDisc=pageItems.reduce((s,li)=>s+li.lineDiscount,0);
488 const pageVat=pageItems.reduce((s,li)=>s+li.lineVat,0);
@@ -495,7 +497,9 @@ function renderAndPrintDirect(invId){
497 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('');
498 let orientationStyle=document.getElementById('dynamic-print-orientation');
499 if(!orientationStyle){orientationStyle=document.createElement('style');orientationStyle.id='dynamic-print-orientation';document.head.appendChild(orientationStyle);}
498 - orientationStyle.innerHTML=`@media print { @page { size: A4 landscape; margin: 8mm 10mm; } }`;
500 + orientationStyle.innerHTML=isFormal
501 + ?`@media print { @page { size: A4 portrait; margin: 5mm; } .invoice-a4-page{max-width:200mm!important;padding:3mm 4mm!important} .invoice-a4-page table{font-size:8.5px!important} .invoice-a4-page td,.invoice-a4-page th{padding:2px 3px!important} }`
502 + :`@media print { @page { size: A5 landscape; margin: 5mm; } .invoice-a4-page{max-width:200mm!important;padding:3mm 4mm!important} .invoice-a4-page table{font-size:9px!important} .invoice-a4-page td,.invoice-a4-page th{padding:2px 3px!important} }`;
503 const printContainer=document.getElementById('printable-invoice');
504 printContainer.innerHTML=containerHtml;
505 printContainer.style.display='block';