diff --git a/public/pos/receipt.html b/public/pos/receipt.html index 1cfa1f4..dd1d0ff 100644 --- a/public/pos/receipt.html +++ b/public/pos/receipt.html @@ -506,6 +506,38 @@ let btDevice = null; let btChar = null; async function printThermal(){ + const settings = window.EposPrint.getSettings(); + if(settings.type === 'network') return printThermalNetwork(settings); + return printThermalBluetooth(); +} + +async function printThermalNetwork(settings){ + const btn = document.getElementById('printBtn'); + const status = document.getElementById('statusText'); + const errBox = document.getElementById('status'); + errBox.classList.remove('err'); + btn.disabled = true; + if(!settings.ip){ + status.textContent = 'Set the printer IP address in Printer settings first.'; + errBox.classList.add('err'); + btn.disabled = false; + return; + } + status.textContent = 'Sending to ' + settings.ip + '…'; + try{ + const logo = await window.EposPrint.imageToRaster('/wfdash-logo.png', 384).catch(()=>null); + const xml = window.EposPrint.buildEposXml(sale, logo); + await window.EposPrint.printViaNetwork(settings.ip, xml); + status.textContent = 'Printed · ' + settings.ip; + }catch(e){ + status.textContent = 'Print failed: ' + e.message; + errBox.classList.add('err'); + }finally{ + btn.disabled = false; + } +} + +async function printThermalBluetooth(){ const btn = document.getElementById('printBtn'); const status = document.getElementById('statusText'); const errBox = document.getElementById('status');