feat: truncate long cashier names to first and last name, apply bold formatting to receipt items, and reduce paper feed length
This commit is contained in:
parent
85ddc0ab44
commit
fe1b692f4f
@ -255,12 +255,12 @@ export class EscPosGenerator {
|
|||||||
const displayName = name.length > nameMaxLen
|
const displayName = name.length > nameMaxLen
|
||||||
? name.substring(0, nameMaxLen - 1) + '.'
|
? name.substring(0, nameMaxLen - 1) + '.'
|
||||||
: name;
|
: name;
|
||||||
cmds.push(...this.addLine(qtyLabel + displayName));
|
cmds.push(...this.addLine(qtyLabel + displayName, { bold: true, height: 2 }));
|
||||||
} else {
|
} else {
|
||||||
// ── Full receipt ───────────────────────────────────────────
|
// ── Full receipt ───────────────────────────────────────────
|
||||||
// Line 1: product name
|
// Line 1: product name
|
||||||
const displayName = name.length > W ? name.substring(0, W - 1) + '.' : name;
|
const displayName = name.length > W ? name.substring(0, W - 1) + '.' : name;
|
||||||
cmds.push(...this.addLine(displayName));
|
cmds.push(...this.addLine(displayName, { bold: true, height: 2 }));
|
||||||
|
|
||||||
// Line 2: qty x unitPrice = total (right-aligned)
|
// Line 2: qty x unitPrice = total (right-aligned)
|
||||||
const priceStr = this.formatAmount(line.price || 0);
|
const priceStr = this.formatAmount(line.price || 0);
|
||||||
@ -268,14 +268,15 @@ export class EscPosGenerator {
|
|||||||
const middle = `${qtyStr}x ${priceStr}`;
|
const middle = `${qtyStr}x ${priceStr}`;
|
||||||
let itemLine = middle + totalStr.padStart(W - middle.length);
|
let itemLine = middle + totalStr.padStart(W - middle.length);
|
||||||
if (itemLine.length > W) itemLine = totalStr.padStart(W);
|
if (itemLine.length > W) itemLine = totalStr.padStart(W);
|
||||||
cmds.push(...this.addLine(itemLine));
|
cmds.push(...this.addLine(itemLine, { bold: true, height: 2 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note line (customer note / kitchen note) — shown on both modes
|
// Note line (customer note / kitchen note) — shown on both modes
|
||||||
if (line.note) {
|
if (line.note) {
|
||||||
const noteText = `* ${line.note}`;
|
const noteText = `* ${line.note}`;
|
||||||
cmds.push(...this.addLine(
|
cmds.push(...this.addLine(
|
||||||
noteText.length > W ? noteText.substring(0, W - 1) + '.' : noteText
|
noteText.length > W ? noteText.substring(0, W - 1) + '.' : noteText,
|
||||||
|
{ bold: true }
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -336,8 +337,8 @@ export class EscPosGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feed and cut
|
// Feed and cut (reduced feed to 1 line to prevent footer white spaces on integrated Android/iMin printers)
|
||||||
cmds.push(...this.feedAndCut(4));
|
cmds.push(...this.feedAndCut(1));
|
||||||
|
|
||||||
return new Uint8Array(cmds);
|
return new Uint8Array(cmds);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,22 @@ import { EscPosGraphics } from "./escpos_graphics";
|
|||||||
* Ensures sale completion is never blocked by print errors.
|
* Ensures sale completion is never blocked by print errors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const formatFirstLastName = (name) => {
|
||||||
|
if (!name) return "";
|
||||||
|
let temp = name.trim();
|
||||||
|
let prefix = "";
|
||||||
|
const prefixMatch = temp.match(/^(served\s+by:?|order\s+taker:?|kasir:?)\s*/i);
|
||||||
|
if (prefixMatch) {
|
||||||
|
prefix = prefixMatch[0];
|
||||||
|
temp = temp.substring(prefix.length).trim();
|
||||||
|
}
|
||||||
|
const parts = temp.split(/\s+/);
|
||||||
|
if (parts.length <= 2) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
return prefix + parts[0] + " " + parts[parts.length - 1];
|
||||||
|
};
|
||||||
|
|
||||||
// Singleton instances for the POS session
|
// Singleton instances for the POS session
|
||||||
let bluetoothManager = null;
|
let bluetoothManager = null;
|
||||||
let escposGenerator = null;
|
let escposGenerator = null;
|
||||||
@ -680,7 +696,7 @@ patch(PosPrinterService.prototype, {
|
|||||||
const orderData = {
|
const orderData = {
|
||||||
orderName: order.pos_reference || order.name || '',
|
orderName: order.pos_reference || order.name || '',
|
||||||
date: dateStr || new Date().toLocaleString(),
|
date: dateStr || new Date().toLocaleString(),
|
||||||
cashier: (typeof order.getCashierName === 'function' ? order.getCashierName() : '') || '',
|
cashier: formatFirstLastName((typeof order.getCashierName === 'function' ? order.getCashierName() : '') || ''),
|
||||||
customer: order.partner_id?.name || null,
|
customer: order.partner_id?.name || null,
|
||||||
tableName,
|
tableName,
|
||||||
};
|
};
|
||||||
@ -823,7 +839,7 @@ patch(PosPrinterService.prototype, {
|
|||||||
const orderData = {
|
const orderData = {
|
||||||
orderName: getText('.pos-receipt-vat') || getText('.pos-receipt-order-name') || getText('.order-name') || getText('.pos-receipt-order-data') || '',
|
orderName: getText('.pos-receipt-vat') || getText('.pos-receipt-order-name') || getText('.order-name') || getText('.pos-receipt-order-data') || '',
|
||||||
date: getText('#order-date') || getText('.pos-receipt-date') || new Date().toLocaleString(),
|
date: getText('#order-date') || getText('.pos-receipt-date') || new Date().toLocaleString(),
|
||||||
cashier: getText('.cashier') || getText('.pos-receipt-cashier') || '',
|
cashier: formatFirstLastName(getText('.cashier') || getText('.pos-receipt-cashier') || ''),
|
||||||
customer: getText('.pos-receipt-customer') || getText('.customer') || null
|
customer: getText('.pos-receipt-customer') || getText('.customer') || null
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1073,6 +1089,7 @@ patch(PosPrinterService.prototype, {
|
|||||||
} else if (pos.user) {
|
} else if (pos.user) {
|
||||||
cashierName = pos.user.name || '';
|
cashierName = pos.user.name || '';
|
||||||
}
|
}
|
||||||
|
cashierName = formatFirstLastName(cashierName);
|
||||||
console.log('[BluetoothPrint] Cashier name:', cashierName);
|
console.log('[BluetoothPrint] Cashier name:', cashierName);
|
||||||
|
|
||||||
// Get customer info - try multiple ways
|
// Get customer info - try multiple ways
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user