diff --git a/pos/static/js/pos.js b/pos/static/js/pos.js index d01fada..c1374ab 100644 --- a/pos/static/js/pos.js +++ b/pos/static/js/pos.js @@ -1660,41 +1660,39 @@ const POS = (() => { function printTicket() { const src = document.getElementById('ticketContent'); - if (!src) return; + if (!src) { console.warn('printTicket: ticketContent not found'); return; } - // Paper width: 58 mm -> 48 mm printable; 80 mm -> 72 mm printable. + try { + // Paper width: 58 mm -> 48 mm printable; 80 mm -> 72 mm printable. + const paperWidth = parseInt(rc('paper_width', '80'), 10) || 80; + const is58 = paperWidth === 58; + const printWidth = is58 ? 48 : 72; + const fontSize = is58 ? '12pt' : '14pt'; + const smallFont = is58 ? '10pt' : '12pt'; + const nameMax = is58 ? '20mm' : '38mm'; + let iframe = document.getElementById('ticketPrintFrame'); + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.id = 'ticketPrintFrame'; + iframe.style.position = 'fixed'; + iframe.style.left = '-9999px'; + iframe.style.top = '0'; + iframe.style.width = printWidth + 'mm'; + iframe.style.border = '0'; + document.body.appendChild(iframe); + } - let iframe = document.getElementById('ticketPrintFrame'); - if (!iframe) { - iframe = document.createElement('iframe'); - iframe.id = 'ticketPrintFrame'; - iframe.style.position = 'fixed'; - iframe.style.left = '-9999px'; - iframe.style.top = '0'; - iframe.style.width = printWidth + 'mm'; - iframe.style.border = '0'; - document.body.appendChild(iframe); - } - - const paperWidth = parseInt(rc('paper_width', '80'), 10) || 80; - const is58 = paperWidth === 58; - // Render at the real printable width so text is not scaled down by the driver. - const printWidth = is58 ? 48 : 72; - const fontSize = is58 ? '12pt' : '14pt'; - const smallFont = is58 ? '10pt' : '12pt'; - const nameMax = is58 ? '20mm' : '38mm'; - - const doc = iframe.contentDocument || iframe.contentWindow.document; - doc.open(); - doc.write(` + const doc = iframe.contentDocument || iframe.contentWindow.document; + doc.open(); + doc.write(` ${src.innerHTML} `); - doc.close(); + doc.close(); - // Measure real content height and set exact page size (avoids phantom 3276 mm). - const bodyEl = doc.body; - const heightPx = Math.max(bodyEl.scrollHeight, bodyEl.offsetHeight); - const heightMm = Math.ceil((heightPx * 25.4 / 96) + 5); + // Measure real content height and set exact page size (avoids phantom 3276 mm). + const bodyEl = doc.body; + const heightPx = Math.max(bodyEl.scrollHeight, bodyEl.offsetHeight); + const heightMm = Math.ceil((heightPx * 25.4 / 96) + 5); - const exactPage = doc.createElement('style'); - exactPage.textContent = `@page { margin: 0; size: ${printWidth}mm ${heightMm}mm; }`; - doc.head.appendChild(exactPage); + const exactPage = doc.createElement('style'); + exactPage.textContent = `@page { margin: 0; size: ${printWidth}mm ${heightMm}mm; }`; + doc.head.appendChild(exactPage); - iframe.contentWindow.focus(); - setTimeout(() => { iframe.contentWindow.print(); }, 150); + iframe.contentWindow.focus(); + setTimeout(() => { + try { + iframe.contentWindow.print(); + } catch (e) { + console.error('printTicket: iframe.print failed', e); + window.print(); + } + }, 200); + } catch (e) { + console.error('printTicket error:', e); + alert('No se pudo preparar la impresion del ticket. Revise la consola.'); + } } // ─── Thermal Printing ───────────────── diff --git a/pos/static/pwa/sw.js b/pos/static/pwa/sw.js index c0a6b26..5625f66 100644 --- a/pos/static/pwa/sw.js +++ b/pos/static/pwa/sw.js @@ -6,7 +6,7 @@ // The fetch handler normalizes static asset URLs (strips ?v= query strings) // so templates can use cache-busting query params freely. -const VERSION = 50; +const VERSION = 51; const CACHE_NAME = 'nexus-pos-v' + VERSION; const APP_SHELL = [