-
-
-
Delivery note
-
${esc((s.customer && s.customer.company) || (s.customer && s.customer.name) || '—')}
-
+
+
+
+
Delivery note
+
${esc(companyName || customerName)}
-
-
-
${lines}
-
+
+
+
${noteHtml}
`;
document.getElementById('deliveryCard').innerHTML = html;
+ window.__dnState = state;
}
window.renderDeliveryNote = renderDeliveryNote;
@@ -535,21 +566,15 @@ async function printThermalNetwork(settings){
// hands to the customer at drop-off, not a "paid" receipt. Cash
// / card / EFT get the standard sale slip.
let xml, successLabel;
- if (sale.payment === 'account') {
- const letterheadId = sale.letterhead && sale.letterhead.id;
- const deliveryBlocks = window.PosSlipLayout.getBlocksForPrint(letterheadId, 'delivery');
- const dnToggle = document.getElementById('dnShowPrices');
- const showPricing = dnToggle ? !!dnToggle.checked : window.PosSlipLayout.getShowPricingForPrint(letterheadId);
- const dnLogo = await window.EposPrint.letterheadLogoRaster(sale.letterhead, 384);
- xml = window.EposPrint.buildEposDeliveryXml(sale, deliveryBlocks, showPricing, dnLogo);
- successLabel = 'Delivery note printed · ';
- } else {
- const logo = await window.EposPrint.letterheadLogoRaster(sale.letterhead, 384);
- const letterheadId = sale.letterhead && sale.letterhead.id;
- const blocks = window.PosSlipLayout.getBlocksForPrint(letterheadId, 'sale');
- xml = window.EposPrint.buildEposXml(sale, logo, blocks);
- successLabel = 'Printed · ';
- }
+ // Always the standard sale slip. Account sales no longer print a
+ // thermal delivery note — the system A4 DN is printed by
+ // `printDelivery()` instead, so this button is the till slip for
+ // every tender type.
+ const logo = await window.EposPrint.letterheadLogoRaster(sale.letterhead, 384);
+ const letterheadId = sale.letterhead && sale.letterhead.id;
+ const blocks = window.PosSlipLayout.getBlocksForPrint(letterheadId, 'sale');
+ xml = window.EposPrint.buildEposXml(sale, logo, blocks);
+ successLabel = 'Printed · ';
await window.EposPrint.printViaNetwork(settings.ip, xml);
status.textContent = successLabel + settings.ip;
}catch(e){
@@ -594,11 +619,10 @@ async function printThermalBluetooth(){
// Account sales print a delivery note (received-by / driver lines,
// no payment line). Everything else prints the standard sale slip.
const letterheadIdBt = sale.letterhead && sale.letterhead.id;
- const dnToggle = document.getElementById('dnShowPrices');
- const showPrices = dnToggle ? !!dnToggle.checked : window.PosSlipLayout.getShowPricingForPrint(letterheadIdBt);
- const text = sale.payment === 'account'
- ? buildEscPosDelivery(sale, showPrices, window.PosSlipLayout.getBlocksForPrint(letterheadIdBt, 'delivery'))
- : buildEscPos(sale, window.PosSlipLayout.getBlocksForPrint(letterheadIdBt, 'sale'));
+ // Standard sale slip for every tender — see the note on the
+ // network path above. Account sales print the system A4 DN
+ // through `printDelivery()` instead.
+ const text = buildEscPos(sale, window.PosSlipLayout.getBlocksForPrint(letterheadIdBt, 'sale'));
const CHUNK = 80;
const enc = new TextEncoder();
for(let i=0;i
setTimeout(r,30));
}
- status.textContent = (sale.payment === 'account' ? 'Delivery note printed · ' : 'Printed · ') + (btDevice.name||'printer');
+ status.textContent = 'Printed · ' + (btDevice.name||'printer');
}catch(e){
if(e.name==='NotFoundError') status.textContent = 'Cancelled.';
else status.textContent = 'Print failed: ' + e.message;
@@ -691,7 +715,7 @@ function saleEscPosRenderers(s){
}
// `blocks` is the resolved block list for 'sale'. Returns a plain
-// string (matching buildEscPosDelivery) — the caller runs it through
+// string — the caller runs it through
// TextEncoder before writing to the Bluetooth characteristic. (Note:
// this used to manually pack a Uint8Array here, which the caller then
// fed into TextEncoder.encode() — encoding a Uint8Array as if it were
@@ -704,132 +728,78 @@ function buildEscPos(s, blocks){
return ESC+'@' + body + '\n\n' + GS+'V'+E(0x41)+E(0x10);
}
+// Prints the SYSTEM delivery note — the A4 original the office keeps —
+// by opening it in a new tab and letting the operator send it to the
+// office network printer from there (set Copies to 2 for the client).
+//
+// This replaced the old 80mm thermal delivery-note print. The thermal
+// slip is still the path for cash / card / EFT via `printThermal`,
+// and its button is hidden for account sales entirely.
async function printDelivery(){
if(!sale) return;
+ const dn = sale.deliveryNote;
const btn = document.getElementById('printDnBtn');
const status = document.getElementById('statusText');
const errBox = document.getElementById('status');
+ if(btn) btn.disabled = true;
errBox.classList.remove('err');
- btn.disabled = true;
- status.textContent = 'Printing delivery note…';
- const printerSettings = window.EposPrint.getSettings();
- if(printerSettings.type === 'network'){
- if(!printerSettings.ip){
- status.textContent = 'Set the printer IP address in Printer settings first.';
+
+ if(!dn){
+ if(status) status.textContent = 'No delivery note on this sale yet.';
+ if(btn) btn.disabled = false;
+ return;
+ }
+
+ if(status) status.textContent = 'Fetching ' + dn.delivery_note_number + '…';
+ let url = null;
+ try{
+ // Fetched through posFetch because the route sits behind
+ // assertPosAuth — an