@tallyui/pos 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +342 -102
- package/dist/index.js +414 -46
- package/package.json +7 -7
- package/src/app-settings/app-settings.ts +17 -2
- package/src/customer-display/display-link.ts +72 -0
- package/src/customer-display/index.ts +5 -0
- package/src/customer-display/transport.ts +54 -0
- package/src/customer-display/use-customer-display.ts +36 -0
- package/src/index.ts +8 -2
- package/src/print/escpos/code-page.ts +48 -0
- package/src/print/escpos/commands.ts +53 -0
- package/src/print/escpos/encode.ts +127 -0
- package/src/print/escpos/index.ts +7 -0
- package/src/print/escpos/transport.ts +45 -0
- package/src/print/index.ts +2 -0
- package/src/print/types.ts +4 -0
- package/src/register/handover.ts +103 -0
- package/src/register/index.ts +2 -0
- package/src/reports/sales-figures.ts +22 -8
- package/src/sale/in-cart.ts +18 -0
- package/src/sale/index.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -646,12 +646,18 @@ var APP_SETTING_DEFINITIONS = {
|
|
|
646
646
|
"ui.font": {
|
|
647
647
|
default: "auto",
|
|
648
648
|
parse: (value) => typeof value === "string" && value.length > 0 && value.length <= 64 ? value : void 0
|
|
649
|
+
},
|
|
650
|
+
"cart.quickDiscounts": {
|
|
651
|
+
default: [5, 10, 15],
|
|
652
|
+
// As v2's `ensureNumberArray`: only real percentages (0 < n <= 100) survive; an empty list is no keys.
|
|
653
|
+
parse: (value) => Array.isArray(value) ? value.filter((n) => typeof n === "number" && Number.isFinite(n) && n > 0 && n <= 100) : void 0
|
|
649
654
|
}
|
|
650
655
|
};
|
|
651
656
|
var DEFAULT_APP_SETTINGS = {
|
|
652
657
|
"ui.theme": APP_SETTING_DEFINITIONS["ui.theme"].default,
|
|
653
658
|
"ui.scale": APP_SETTING_DEFINITIONS["ui.scale"].default,
|
|
654
|
-
"ui.font": APP_SETTING_DEFINITIONS["ui.font"].default
|
|
659
|
+
"ui.font": APP_SETTING_DEFINITIONS["ui.font"].default,
|
|
660
|
+
"cart.quickDiscounts": APP_SETTING_DEFINITIONS["cart.quickDiscounts"].default
|
|
655
661
|
};
|
|
656
662
|
var appSettingSchema = {
|
|
657
663
|
title: "App settings",
|
|
@@ -688,10 +694,11 @@ function appSettings$(collection) {
|
|
|
688
694
|
return collection.find().$.pipe(map((docs) => resolveAppSettings(docs.map((doc) => doc.toJSON()))));
|
|
689
695
|
}
|
|
690
696
|
async function writeAppSetting(collection, key, value) {
|
|
691
|
-
|
|
697
|
+
const parsed = APP_SETTING_DEFINITIONS[key].parse(value);
|
|
698
|
+
if (parsed === void 0) {
|
|
692
699
|
throw new Error(`writeAppSetting: invalid value for ${key}`);
|
|
693
700
|
}
|
|
694
|
-
await collection.upsert({ key, value: JSON.stringify(
|
|
701
|
+
await collection.upsert({ key, value: JSON.stringify(parsed) });
|
|
695
702
|
}
|
|
696
703
|
|
|
697
704
|
// src/app-settings/use-app-settings.ts
|
|
@@ -2643,6 +2650,119 @@ function displayReducer(state, envelope2) {
|
|
|
2643
2650
|
}
|
|
2644
2651
|
}
|
|
2645
2652
|
|
|
2653
|
+
// src/customer-display/transport.ts
|
|
2654
|
+
var DISPLAY_CHANNEL = "tallyui.customer-display";
|
|
2655
|
+
function createBroadcastDisplayTransport(channelName = DISPLAY_CHANNEL, open = (name) => new BroadcastChannel(name)) {
|
|
2656
|
+
const channel = open(channelName);
|
|
2657
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2658
|
+
channel.onmessage = (event) => {
|
|
2659
|
+
const result = decode(event.data);
|
|
2660
|
+
if (result.ok) listeners.forEach((listener) => listener(result.envelope));
|
|
2661
|
+
};
|
|
2662
|
+
return {
|
|
2663
|
+
send(envelope2) {
|
|
2664
|
+
try {
|
|
2665
|
+
channel.postMessage(encode(envelope2));
|
|
2666
|
+
return true;
|
|
2667
|
+
} catch {
|
|
2668
|
+
return false;
|
|
2669
|
+
}
|
|
2670
|
+
},
|
|
2671
|
+
onMessage(listener) {
|
|
2672
|
+
listeners.add(listener);
|
|
2673
|
+
return () => {
|
|
2674
|
+
listeners.delete(listener);
|
|
2675
|
+
};
|
|
2676
|
+
},
|
|
2677
|
+
close() {
|
|
2678
|
+
listeners.clear();
|
|
2679
|
+
channel.onmessage = null;
|
|
2680
|
+
channel.close();
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
// src/customer-display/display-link.ts
|
|
2686
|
+
var systemClock = {
|
|
2687
|
+
setTimeout: (run, ms) => setTimeout(run, ms),
|
|
2688
|
+
clearTimeout: (handle) => clearTimeout(handle)
|
|
2689
|
+
};
|
|
2690
|
+
function createDisplayLink(transport, options) {
|
|
2691
|
+
const { config, clock = systemClock } = options;
|
|
2692
|
+
let current = null;
|
|
2693
|
+
let lastKey = "";
|
|
2694
|
+
let idleTimer = null;
|
|
2695
|
+
const cancelIdle = () => {
|
|
2696
|
+
if (idleTimer !== null) clock.clearTimeout(idleTimer);
|
|
2697
|
+
idleTimer = null;
|
|
2698
|
+
};
|
|
2699
|
+
const publish = (envelope2) => {
|
|
2700
|
+
const key = JSON.stringify([envelope2.action, envelope2.payload]);
|
|
2701
|
+
if (key === lastKey) return;
|
|
2702
|
+
lastKey = key;
|
|
2703
|
+
current = envelope2;
|
|
2704
|
+
transport.send(envelope2);
|
|
2705
|
+
};
|
|
2706
|
+
const idle3 = () => publish(makeEnvelope("display.idle", { reason: "no_cart" }));
|
|
2707
|
+
const unsubscribe = transport.onMessage((envelope2) => {
|
|
2708
|
+
if (envelope2.action !== "display.hello") return;
|
|
2709
|
+
transport.send(makeEnvelope("display.config", { ...config, template: envelope2.payload.template }, envelope2.id));
|
|
2710
|
+
if (current) transport.send(current);
|
|
2711
|
+
});
|
|
2712
|
+
return {
|
|
2713
|
+
showCart(receipt) {
|
|
2714
|
+
if (!receipt || receipt.lineItems.length + receipt.fees.length + receipt.shipping.length === 0) {
|
|
2715
|
+
if (idleTimer === null) idle3();
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
cancelIdle();
|
|
2719
|
+
publish(makeEnvelope("cart.updated", displayCart(receipt)));
|
|
2720
|
+
},
|
|
2721
|
+
showPayment(receipt, payment) {
|
|
2722
|
+
cancelIdle();
|
|
2723
|
+
publish(makeEnvelope("payment.state", { ...displayCart(receipt), ...payment }));
|
|
2724
|
+
if (payment.state === "complete") {
|
|
2725
|
+
idleTimer = clock.setTimeout(() => {
|
|
2726
|
+
idleTimer = null;
|
|
2727
|
+
idle3();
|
|
2728
|
+
}, config.idle.afterCompleteMs);
|
|
2729
|
+
}
|
|
2730
|
+
},
|
|
2731
|
+
close() {
|
|
2732
|
+
cancelIdle();
|
|
2733
|
+
unsubscribe();
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
// src/customer-display/use-customer-display.ts
|
|
2739
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
2740
|
+
var DISPLAY_TEMPLATE = { id: "default", version: 1 };
|
|
2741
|
+
var HELLO_RETRY_MS = 2e3;
|
|
2742
|
+
function useCustomerDisplay(transport) {
|
|
2743
|
+
const [state, setState] = useState5(initialDisplayState);
|
|
2744
|
+
useEffect5(() => {
|
|
2745
|
+
if (!transport) return;
|
|
2746
|
+
const hello = makeEnvelope("display.hello", { template: DISPLAY_TEMPLATE });
|
|
2747
|
+
let configured = false;
|
|
2748
|
+
const retry = setInterval(() => transport.send(hello), HELLO_RETRY_MS);
|
|
2749
|
+
const unsubscribe = transport.onMessage((envelope2) => {
|
|
2750
|
+
if (!configured) {
|
|
2751
|
+
if (envelope2.action !== "display.config" || envelope2.id !== hello.id) return;
|
|
2752
|
+
configured = true;
|
|
2753
|
+
clearInterval(retry);
|
|
2754
|
+
}
|
|
2755
|
+
setState((previous) => displayReducer(previous, envelope2));
|
|
2756
|
+
});
|
|
2757
|
+
transport.send(hello);
|
|
2758
|
+
return () => {
|
|
2759
|
+
clearInterval(retry);
|
|
2760
|
+
unsubscribe();
|
|
2761
|
+
};
|
|
2762
|
+
}, [transport]);
|
|
2763
|
+
return state;
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2646
2766
|
// src/product/search-products.ts
|
|
2647
2767
|
function searchProducts(docs, term, traits) {
|
|
2648
2768
|
const query = term.trim().toLowerCase();
|
|
@@ -2911,12 +3031,12 @@ function createScanSession(options) {
|
|
|
2911
3031
|
}
|
|
2912
3032
|
|
|
2913
3033
|
// src/scanner/use-barcode-scanner.ts
|
|
2914
|
-
import { useEffect as
|
|
3034
|
+
import { useEffect as useEffect6, useRef as useRef2 } from "react";
|
|
2915
3035
|
function useBarcodeScanner(options) {
|
|
2916
3036
|
const latest = useRef2(options);
|
|
2917
3037
|
latest.current = options;
|
|
2918
3038
|
const enabled = options.enabled ?? true;
|
|
2919
|
-
|
|
3039
|
+
useEffect6(() => {
|
|
2920
3040
|
if (!enabled) return;
|
|
2921
3041
|
const detectorOptions = {
|
|
2922
3042
|
getSettings: () => ({
|
|
@@ -3235,8 +3355,183 @@ function createSystemPrintTransport(options = {}) {
|
|
|
3235
3355
|
};
|
|
3236
3356
|
}
|
|
3237
3357
|
|
|
3358
|
+
// src/print/escpos/code-page.ts
|
|
3359
|
+
var ESCPOS_CODE_PAGES = {
|
|
3360
|
+
cp437: {
|
|
3361
|
+
id: 0,
|
|
3362
|
+
high: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0"
|
|
3363
|
+
},
|
|
3364
|
+
// PC850 with the euro sign at 0xD5.
|
|
3365
|
+
cp858: {
|
|
3366
|
+
id: 19,
|
|
3367
|
+
high: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xF8\xA3\xD8\xD7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\xAE\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\xC1\xC2\xC0\xA9\u2563\u2551\u2557\u255D\xA2\xA5\u2510\u2514\u2534\u252C\u251C\u2500\u253C\xE3\xC3\u255A\u2554\u2569\u2566\u2560\u2550\u256C\xA4\xF0\xD0\xCA\xCB\xC8\u20AC\xCD\xCE\xCF\u2518\u250C\u2588\u2584\xA6\xCC\u2580\xD3\xDF\xD4\xD2\xF5\xD5\xB5\xFE\xDE\xDA\xDB\xD9\xFD\xDD\xAF\xB4\xAD\xB1\u2017\xBE\xB6\xA7\xF7\xB8\xB0\xA8\xB7\xB9\xB3\xB2\u25A0\xA0"
|
|
3368
|
+
}
|
|
3369
|
+
};
|
|
3370
|
+
function resolveCodePage(name) {
|
|
3371
|
+
return ESCPOS_CODE_PAGES[name] ?? ESCPOS_CODE_PAGES.cp437;
|
|
3372
|
+
}
|
|
3373
|
+
var PRINTABLE_ASCII = /^[\x20-\x7E]$/;
|
|
3374
|
+
function foldText(text2, page) {
|
|
3375
|
+
const normalized = text2.replace(/[\u2010-\u2014\u2212]/g, "-").replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"').replace(/[\u00A0\u202F\u2009\u2007]/g, " ");
|
|
3376
|
+
return Array.from(normalized, (char) => {
|
|
3377
|
+
if (char === "\n" || PRINTABLE_ASCII.test(char) || page.high.includes(char)) return char;
|
|
3378
|
+
if (char === "\xD7") return "x";
|
|
3379
|
+
const base = char.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
|
|
3380
|
+
return PRINTABLE_ASCII.test(base) ? base : "?";
|
|
3381
|
+
}).join("");
|
|
3382
|
+
}
|
|
3383
|
+
|
|
3384
|
+
// src/print/escpos/commands.ts
|
|
3385
|
+
var ESC = 27;
|
|
3386
|
+
var GS = 29;
|
|
3387
|
+
function escpos(page = resolveCodePage()) {
|
|
3388
|
+
const out = [];
|
|
3389
|
+
const clamp = (n) => Math.min(8, Math.max(1, Math.round(n))) - 1;
|
|
3390
|
+
const builder = {
|
|
3391
|
+
init: () => push(ESC, 64, ESC, 77, 0),
|
|
3392
|
+
codePage: () => push(ESC, 116, page.id),
|
|
3393
|
+
align: (mode) => push(ESC, 97, mode === "left" ? 0 : mode === "center" ? 1 : 2),
|
|
3394
|
+
bold: (on) => push(ESC, 69, on ? 1 : 0),
|
|
3395
|
+
size: (width, height) => push(GS, 33, clamp(width) << 4 | clamp(height)),
|
|
3396
|
+
text: (value) => push(...Array.from(foldText(value, page), (char) => char.charCodeAt(0) < 128 ? char.charCodeAt(0) : 128 + page.high.indexOf(char))),
|
|
3397
|
+
feed: (lines) => push(ESC, 100, Math.min(255, Math.max(0, lines))),
|
|
3398
|
+
cut: (type = "partial") => push(GS, 86, type === "full" ? 65 : 66, 0),
|
|
3399
|
+
pulse: (connector = "pin2") => push(ESC, 112, connector === "pin5" ? 1 : 0, 25, 250),
|
|
3400
|
+
bytes: () => Uint8Array.from(out)
|
|
3401
|
+
};
|
|
3402
|
+
function push(...bytes) {
|
|
3403
|
+
for (const byte of bytes) out.push(byte);
|
|
3404
|
+
return builder;
|
|
3405
|
+
}
|
|
3406
|
+
return builder;
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
// src/print/escpos/encode.ts
|
|
3410
|
+
import { formatMoney as formatMoney3, moneyToMajor } from "@tallyui/core";
|
|
3411
|
+
function wrapText(text2, width) {
|
|
3412
|
+
const lines = [];
|
|
3413
|
+
let line = "";
|
|
3414
|
+
for (let word of text2.split(" ").filter(Boolean)) {
|
|
3415
|
+
while (word.length > width) {
|
|
3416
|
+
if (line) lines.push(line);
|
|
3417
|
+
line = "";
|
|
3418
|
+
lines.push(word.slice(0, width));
|
|
3419
|
+
word = word.slice(width);
|
|
3420
|
+
}
|
|
3421
|
+
if (!line) line = word;
|
|
3422
|
+
else if (line.length + 1 + word.length <= width) line += ` ${word}`;
|
|
3423
|
+
else {
|
|
3424
|
+
lines.push(line);
|
|
3425
|
+
line = word;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
if (line || lines.length === 0) lines.push(line);
|
|
3429
|
+
return lines;
|
|
3430
|
+
}
|
|
3431
|
+
function encodeEscPos(receipt, options) {
|
|
3432
|
+
const { columns, cut = true, openDrawer = false, drawerConnector = "pin2" } = options;
|
|
3433
|
+
const page = resolveCodePage(options.codePage);
|
|
3434
|
+
const fold = (text2) => foldText(text2, page);
|
|
3435
|
+
const money = options.formatMoney ?? ((minor2, currency) => {
|
|
3436
|
+
const formatted = formatMoney3({ amount: minor2, currency }) ?? "";
|
|
3437
|
+
if (!fold(formatted).includes("?")) return formatted;
|
|
3438
|
+
return new Intl.NumberFormat(void 0, { style: "currency", currency, currencyDisplay: "code" }).format(moneyToMajor({ amount: minor2, currency }));
|
|
3439
|
+
});
|
|
3440
|
+
const data = receiptTemplateData(receipt, { ...options, formatMoney: money });
|
|
3441
|
+
const out = escpos(page).init().codePage();
|
|
3442
|
+
const print = (lines) => {
|
|
3443
|
+
for (const line of lines) out.text(`${line}
|
|
3444
|
+
`);
|
|
3445
|
+
};
|
|
3446
|
+
const block = (text2, indent = "") => fold(text2).split("\n").flatMap((part) => wrapText(part, columns - indent.length).map((line) => indent + line));
|
|
3447
|
+
const pair = (left, right, indent = "") => {
|
|
3448
|
+
const amount = fold(right);
|
|
3449
|
+
const space = columns - amount.length - 1;
|
|
3450
|
+
if (space <= indent.length) {
|
|
3451
|
+
print([...block(left, indent), amount.padStart(columns)]);
|
|
3452
|
+
return;
|
|
3453
|
+
}
|
|
3454
|
+
const lines = wrapText(fold(left), space - indent.length).map((line) => indent + line);
|
|
3455
|
+
const last = lines.pop() ?? "";
|
|
3456
|
+
print([...lines, last + " ".repeat(columns - last.length - amount.length) + amount]);
|
|
3457
|
+
};
|
|
3458
|
+
const rule = (char) => print([char.repeat(columns)]);
|
|
3459
|
+
out.align("center").bold(true);
|
|
3460
|
+
print(block(data.store.name));
|
|
3461
|
+
out.bold(false);
|
|
3462
|
+
for (const { line } of data.store.addressLines) print(block(line));
|
|
3463
|
+
out.align("left");
|
|
3464
|
+
rule("-");
|
|
3465
|
+
out.align("center").bold(true);
|
|
3466
|
+
print(block(data.document.title));
|
|
3467
|
+
out.bold(false);
|
|
3468
|
+
if (data.document.isReprint) print(block(`Copy ${data.document.reprintCount}`));
|
|
3469
|
+
out.align("left");
|
|
3470
|
+
pair("Order", data.order.number);
|
|
3471
|
+
pair("Date", data.order.date);
|
|
3472
|
+
for (const [label, value] of [["Cashier", data.cashier], ["Register", data.register], ["Customer", data.customer]]) {
|
|
3473
|
+
if (value) pair(label, value);
|
|
3474
|
+
}
|
|
3475
|
+
rule("-");
|
|
3476
|
+
for (const line of data.lines) {
|
|
3477
|
+
print(block(line.name));
|
|
3478
|
+
for (const option of line.options) print(block(option.text, " "));
|
|
3479
|
+
pair(line.detail, line.amount, " ");
|
|
3480
|
+
for (const discount of line.discounts) pair(discount.label, discount.amount, " ");
|
|
3481
|
+
}
|
|
3482
|
+
rule("-");
|
|
3483
|
+
pair("Subtotal", data.subtotal);
|
|
3484
|
+
if (data.lineDiscount) pair("Line discounts", data.lineDiscount);
|
|
3485
|
+
if (data.orderDiscount) pair("Order discount", data.orderDiscount);
|
|
3486
|
+
for (const charge of [...data.charges, ...data.taxes]) pair(charge.label, charge.amount);
|
|
3487
|
+
out.bold(true);
|
|
3488
|
+
pair("Total", data.total);
|
|
3489
|
+
out.bold(false);
|
|
3490
|
+
rule("=");
|
|
3491
|
+
for (const payment of data.payments) {
|
|
3492
|
+
pair(payment.reference ? `${payment.method} ${payment.reference}` : payment.method, payment.amount);
|
|
3493
|
+
}
|
|
3494
|
+
if (data.change) pair("Change", data.change);
|
|
3495
|
+
if (data.note) {
|
|
3496
|
+
out.feed(1);
|
|
3497
|
+
print(block(data.note));
|
|
3498
|
+
}
|
|
3499
|
+
out.feed(1).align("center");
|
|
3500
|
+
print(["Thank you"]);
|
|
3501
|
+
out.align("left").feed(3);
|
|
3502
|
+
if (openDrawer) out.pulse(drawerConnector);
|
|
3503
|
+
if (cut) out.cut();
|
|
3504
|
+
return out.bytes();
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
// src/print/escpos/transport.ts
|
|
3508
|
+
function createEscPosTransport({ sink, profile, format: format2 }) {
|
|
3509
|
+
return {
|
|
3510
|
+
name: "escpos",
|
|
3511
|
+
async print(job) {
|
|
3512
|
+
if (profile.language !== void 0 && profile.language !== "esc-pos") {
|
|
3513
|
+
throw new PrintError("unsupported", `Printer ${profile.name} speaks ${profile.language}, not ESC/POS`);
|
|
3514
|
+
}
|
|
3515
|
+
const bytes = job.bytes ?? (job.receipt && encodeEscPos(job.receipt, {
|
|
3516
|
+
...format2,
|
|
3517
|
+
columns: profile.columns ?? 42,
|
|
3518
|
+
codePage: profile.codePage,
|
|
3519
|
+
cut: profile.autoCut ?? true,
|
|
3520
|
+
openDrawer: profile.autoOpenDrawer ?? false,
|
|
3521
|
+
drawerConnector: profile.drawerConnector ?? "pin2"
|
|
3522
|
+
}));
|
|
3523
|
+
if (!bytes) throw new PrintError("unsupported", `ESC/POS prints bytes or a receipt; job ${job.id} has neither`);
|
|
3524
|
+
try {
|
|
3525
|
+
await sink.write(bytes);
|
|
3526
|
+
} catch (error) {
|
|
3527
|
+
throw new PrintError("failed", error instanceof Error ? error.message : String(error), { cause: error });
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
};
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3238
3533
|
// src/sale/use-sale.ts
|
|
3239
|
-
import { useEffect as
|
|
3534
|
+
import { useEffect as useEffect8, useLayoutEffect, useRef as useRef4, useState as useState7 } from "react";
|
|
3240
3535
|
import { paymentMethodOf } from "@tallyui/core";
|
|
3241
3536
|
|
|
3242
3537
|
// src/pos-order/finalize.ts
|
|
@@ -5335,7 +5630,7 @@ function buildXReportDocument(session, context) {
|
|
|
5335
5630
|
}
|
|
5336
5631
|
|
|
5337
5632
|
// src/register/use-register-session.ts
|
|
5338
|
-
import { useEffect as
|
|
5633
|
+
import { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef3, useState as useState6, useSyncExternalStore } from "react";
|
|
5339
5634
|
import { combineLatest, map as map6, of, switchMap } from "rxjs";
|
|
5340
5635
|
|
|
5341
5636
|
// src/outbox/register-outbox.ts
|
|
@@ -6540,8 +6835,8 @@ function useRegisterSession(options) {
|
|
|
6540
6835
|
}
|
|
6541
6836
|
});
|
|
6542
6837
|
};
|
|
6543
|
-
|
|
6544
|
-
|
|
6838
|
+
useEffect7(reconcile, [commandTarget]);
|
|
6839
|
+
useEffect7(() => {
|
|
6545
6840
|
if (!commandTarget) return;
|
|
6546
6841
|
const subscription = commandTarget.commands.find({ selector: { registerId: commandTarget.registerId } }).$.subscribe(() => {
|
|
6547
6842
|
void adoptRegisterResults(commandTarget);
|
|
@@ -6571,14 +6866,14 @@ function useRegisterSession(options) {
|
|
|
6571
6866
|
const tender = useRef3(tenderInProgress);
|
|
6572
6867
|
tender.current = tenderInProgress;
|
|
6573
6868
|
const closing = useSyncExternalStore(subscribeClosing, () => closingByRegister.has(registerId ?? ""));
|
|
6574
|
-
const [observed, setObserved] =
|
|
6575
|
-
|
|
6869
|
+
const [observed, setObserved] = useState6(null);
|
|
6870
|
+
useEffect7(() => {
|
|
6576
6871
|
if (!source) return;
|
|
6577
6872
|
const subscription = source.subscribe((snapshot) => setObserved({ source, snapshot }));
|
|
6578
6873
|
return () => subscription.unsubscribe();
|
|
6579
6874
|
}, [source]);
|
|
6580
|
-
const [, setMinute] =
|
|
6581
|
-
|
|
6875
|
+
const [, setMinute] = useState6(0);
|
|
6876
|
+
useEffect7(() => {
|
|
6582
6877
|
if (!enabled || !expectedCloseTime) return;
|
|
6583
6878
|
const timer = setInterval(() => setMinute((value) => value + 1), 6e4);
|
|
6584
6879
|
return () => clearInterval(timer);
|
|
@@ -6610,7 +6905,7 @@ function useRegisterSession(options) {
|
|
|
6610
6905
|
return state.running = run;
|
|
6611
6906
|
};
|
|
6612
6907
|
const seen = useRef3(null);
|
|
6613
|
-
|
|
6908
|
+
useEffect7(() => {
|
|
6614
6909
|
if (!data) return;
|
|
6615
6910
|
const ids = data.closureRows.map((row) => row.id);
|
|
6616
6911
|
if (seen.current?.source !== source) {
|
|
@@ -6922,6 +7217,53 @@ function useRegisterSession(options) {
|
|
|
6922
7217
|
};
|
|
6923
7218
|
}
|
|
6924
7219
|
|
|
7220
|
+
// src/register/handover.ts
|
|
7221
|
+
function switchWarnings({ kind, outbox, parkedSales, paidMinor, sessionStatus }) {
|
|
7222
|
+
const unsentSales = outbox.sales.pending;
|
|
7223
|
+
const sessionOpen = kind !== "cashier" && (sessionStatus === "open" || sessionStatus === "counting");
|
|
7224
|
+
const warnings = [];
|
|
7225
|
+
if (unsentSales > 0) warnings.push({ code: "unsentSales", count: unsentSales });
|
|
7226
|
+
if (outbox.tillUpdates.pending > 0) warnings.push({ code: "unsentTillUpdates", count: outbox.tillUpdates.pending });
|
|
7227
|
+
if (parkedSales > 0) warnings.push({ code: "parkedSales", count: parkedSales });
|
|
7228
|
+
if (paidMinor > 0) warnings.push({ code: "partlyPaidSale" });
|
|
7229
|
+
if (sessionOpen) warnings.push({ code: "openSession" });
|
|
7230
|
+
return { kind, warnings, unsentSales, sessionOpen };
|
|
7231
|
+
}
|
|
7232
|
+
function handoverSlip({
|
|
7233
|
+
session,
|
|
7234
|
+
cashier,
|
|
7235
|
+
registerName,
|
|
7236
|
+
openedByName = "",
|
|
7237
|
+
salesCount,
|
|
7238
|
+
expected,
|
|
7239
|
+
blind,
|
|
7240
|
+
outbox,
|
|
7241
|
+
context
|
|
7242
|
+
}) {
|
|
7243
|
+
const doc = buildXReportDocument(session, {
|
|
7244
|
+
...context,
|
|
7245
|
+
expected: blind ? {} : expected,
|
|
7246
|
+
breakdowns: {
|
|
7247
|
+
...context.breakdowns,
|
|
7248
|
+
register_name: registerName,
|
|
7249
|
+
cashier_name: cashier.name,
|
|
7250
|
+
opened_by_name: openedByName,
|
|
7251
|
+
transaction_count: salesCount
|
|
7252
|
+
}
|
|
7253
|
+
});
|
|
7254
|
+
return {
|
|
7255
|
+
registerName,
|
|
7256
|
+
cashierName: cashier.name,
|
|
7257
|
+
openedByName,
|
|
7258
|
+
openedAtTime: doc.closure.opened_at.time ?? "",
|
|
7259
|
+
salesCount,
|
|
7260
|
+
expected: blind ? null : expected,
|
|
7261
|
+
unsentSales: outbox.sales.pending,
|
|
7262
|
+
unsentTillUpdates: outbox.tillUpdates.pending,
|
|
7263
|
+
document: { ...doc, fiscal: { ...doc.fiscal, document_type: "handover", is_handover: true } }
|
|
7264
|
+
};
|
|
7265
|
+
}
|
|
7266
|
+
|
|
6925
7267
|
// src/sale/cart.ts
|
|
6926
7268
|
import { resolvePrice as resolvePrice3 } from "@tallyui/core";
|
|
6927
7269
|
var CartError = class extends Error {
|
|
@@ -6976,7 +7318,7 @@ var HUNG_SAVE_CHECK_MS = 5e3;
|
|
|
6976
7318
|
function useSale(settings, opts) {
|
|
6977
7319
|
const taxContext = useTax();
|
|
6978
7320
|
const madeWith = useRef4({ taxContext, currency: settings.currency });
|
|
6979
|
-
const [rendered, setBuilder] =
|
|
7321
|
+
const [rendered, setBuilder] = useState7(() => createOrderBuilder({ currency: settings.currency, taxContext }));
|
|
6980
7322
|
const builderNow = useRef4(rendered);
|
|
6981
7323
|
const applied = useRef4(/* @__PURE__ */ new Map());
|
|
6982
7324
|
const appliedWith = useRef4(null);
|
|
@@ -6987,17 +7329,17 @@ function useSale(settings, opts) {
|
|
|
6987
7329
|
function codesFor() {
|
|
6988
7330
|
return opts.capabilities?.coupons === true && (opts.capabilities?.orderCreate ?? 1) >= 6 && opts.discountCodes && opts.discountCodes.supports({ capabilities: opts.capabilities, rounding: taxContext.rounding }) ? opts.discountCodes : null;
|
|
6989
7331
|
}
|
|
6990
|
-
const [order, setOrder] =
|
|
6991
|
-
const [stage, setStage] =
|
|
6992
|
-
const [saleError, setError] =
|
|
7332
|
+
const [order, setOrder] = useState7(() => rendered.getSnapshot());
|
|
7333
|
+
const [stage, setStage] = useState7({ kind: "cart" });
|
|
7334
|
+
const [saleError, setError] = useState7(null);
|
|
6993
7335
|
const configError = referenceError("cashierRef", opts.cashierRef) ?? referenceError("registerId", opts.registerId);
|
|
6994
7336
|
const pending = useRef4(null);
|
|
6995
|
-
const [saving, setSaving] =
|
|
7337
|
+
const [saving, setSaving] = useState7(false);
|
|
6996
7338
|
const error = saving && saleError ? saleError : configError ?? saleError;
|
|
6997
7339
|
const tenderSession = useRef4(null);
|
|
6998
7340
|
const droppedReferences = useRef4(/* @__PURE__ */ new Set());
|
|
6999
7341
|
const confirmed = useRef4(null);
|
|
7000
|
-
const [canContinue, setCanContinue] =
|
|
7342
|
+
const [canContinue, setCanContinue] = useState7(false);
|
|
7001
7343
|
const attempts = useRef4(0);
|
|
7002
7344
|
const hungSaveTimer = useRef4(null);
|
|
7003
7345
|
const checking = useRef4(null);
|
|
@@ -7044,7 +7386,7 @@ function useSale(settings, opts) {
|
|
|
7044
7386
|
setStage(stageNow.current);
|
|
7045
7387
|
setError(null);
|
|
7046
7388
|
}
|
|
7047
|
-
|
|
7389
|
+
useEffect8(() => {
|
|
7048
7390
|
const subscription = rendered.order$.subscribe(setOrder);
|
|
7049
7391
|
return () => subscription.unsubscribe();
|
|
7050
7392
|
}, [rendered]);
|
|
@@ -7054,7 +7396,7 @@ function useSale(settings, opts) {
|
|
|
7054
7396
|
const liveIdle = stageNow.current.kind === "cart" && !live.lineItems.length && !live.fees?.length && !live.shipping?.length && !inFlight.current && !pending.current;
|
|
7055
7397
|
if (liveIdle && (madeWith.current.taxContext !== taxContext || madeWith.current.currency !== settings.currency)) resetSale(live.customer ?? null);
|
|
7056
7398
|
});
|
|
7057
|
-
|
|
7399
|
+
useEffect8(() => () => {
|
|
7058
7400
|
clearHungSaveTimer();
|
|
7059
7401
|
if (pending.current || inFlight.current) {
|
|
7060
7402
|
saleLogger.error(
|
|
@@ -7822,7 +8164,7 @@ function startCouponUsageRefetch(deps) {
|
|
|
7822
8164
|
}
|
|
7823
8165
|
|
|
7824
8166
|
// src/sale/catalogue.ts
|
|
7825
|
-
import { findVariantByCode, formatMoney as
|
|
8167
|
+
import { findVariantByCode, formatMoney as formatMoney4, resolvePrice as resolvePrice4 } from "@tallyui/core";
|
|
7826
8168
|
function catalogueEntries(products, traits, context) {
|
|
7827
8169
|
return products.flatMap((product) => {
|
|
7828
8170
|
const variants = traits.getVariants ? traits.getVariants(product, context) : traits.hasVariants(product) ? [] : [{
|
|
@@ -7841,7 +8183,17 @@ function findEntryByCode(entries, code) {
|
|
|
7841
8183
|
}
|
|
7842
8184
|
function variantPriceLabel(variant, currency, locale) {
|
|
7843
8185
|
const price = resolvePrice4(variant.prices, currency);
|
|
7844
|
-
return price ?
|
|
8186
|
+
return price ? formatMoney4(price.current, locale) : void 0;
|
|
8187
|
+
}
|
|
8188
|
+
|
|
8189
|
+
// src/sale/in-cart.ts
|
|
8190
|
+
function cartQuantities(lines) {
|
|
8191
|
+
const quantities = /* @__PURE__ */ new Map();
|
|
8192
|
+
for (const line of lines) {
|
|
8193
|
+
if (line.custom) continue;
|
|
8194
|
+
quantities.set(line.productId, (quantities.get(line.productId) ?? 0) + line.quantity);
|
|
8195
|
+
}
|
|
8196
|
+
return quantities;
|
|
7845
8197
|
}
|
|
7846
8198
|
|
|
7847
8199
|
// src/outbox/http-transport.ts
|
|
@@ -7905,15 +8257,15 @@ function createHttpCommandTransport(options) {
|
|
|
7905
8257
|
}
|
|
7906
8258
|
|
|
7907
8259
|
// src/outbox/use-register-outbox.ts
|
|
7908
|
-
import { useEffect as
|
|
8260
|
+
import { useEffect as useEffect9, useRef as useRef5, useState as useState8 } from "react";
|
|
7909
8261
|
var idle = { pending: 0, sending: false };
|
|
7910
8262
|
function useRegisterOutbox(options) {
|
|
7911
8263
|
const { commands, sessions, deviceId } = options;
|
|
7912
8264
|
const latest = useRef5(options);
|
|
7913
8265
|
latest.current = options;
|
|
7914
8266
|
const current = useRef5(null);
|
|
7915
|
-
const [state, setState] =
|
|
7916
|
-
|
|
8267
|
+
const [state, setState] = useState8(idle);
|
|
8268
|
+
useEffect9(() => {
|
|
7917
8269
|
setState(idle);
|
|
7918
8270
|
if (!commands) return;
|
|
7919
8271
|
const outbox = createRegisterOutbox({
|
|
@@ -7952,7 +8304,7 @@ function useRegisterOutbox(options) {
|
|
|
7952
8304
|
}
|
|
7953
8305
|
|
|
7954
8306
|
// src/outbox/use-order-outbox.ts
|
|
7955
|
-
import { useEffect as
|
|
8307
|
+
import { useEffect as useEffect10, useMemo as useMemo5, useRef as useRef6, useState as useState9 } from "react";
|
|
7956
8308
|
var idle2 = { pending: 0, sending: false };
|
|
7957
8309
|
var noneStuck = [];
|
|
7958
8310
|
function useOrderOutbox(options) {
|
|
@@ -7962,12 +8314,12 @@ function useOrderOutbox(options) {
|
|
|
7962
8314
|
const current = useRef6(null);
|
|
7963
8315
|
const openingError = useRef6(null);
|
|
7964
8316
|
const loggedMismatches = useRef6(/* @__PURE__ */ new Set());
|
|
7965
|
-
const [orders, setOrders] =
|
|
7966
|
-
const [state, setState] =
|
|
7967
|
-
const [recent, setRecent] =
|
|
8317
|
+
const [orders, setOrders] = useState9(null);
|
|
8318
|
+
const [state, setState] = useState9(idle2);
|
|
8319
|
+
const [recent, setRecent] = useState9([]);
|
|
7968
8320
|
const savesInFlight = useRef6(0);
|
|
7969
|
-
const [savesInFlightCount, setSavesInFlightCount] =
|
|
7970
|
-
|
|
8321
|
+
const [savesInFlightCount, setSavesInFlightCount] = useState9(0);
|
|
8322
|
+
useEffect10(() => {
|
|
7971
8323
|
let active = true;
|
|
7972
8324
|
let dispose;
|
|
7973
8325
|
openingError.current = null;
|
|
@@ -8010,7 +8362,7 @@ function useOrderOutbox(options) {
|
|
|
8010
8362
|
dispose?.();
|
|
8011
8363
|
};
|
|
8012
8364
|
}, [storeKey, deviceId]);
|
|
8013
|
-
|
|
8365
|
+
useEffect10(() => {
|
|
8014
8366
|
latest.current.onBusy?.(state.sending);
|
|
8015
8367
|
return () => latest.current.onBusy?.(false);
|
|
8016
8368
|
}, [state.sending]);
|
|
@@ -8559,6 +8911,7 @@ function tenderRounding(state, balanceMinor, method) {
|
|
|
8559
8911
|
}
|
|
8560
8912
|
|
|
8561
8913
|
// src/reports/sales-figures.ts
|
|
8914
|
+
var DAY_MS = 864e5;
|
|
8562
8915
|
function inRange(at2, range, timezone) {
|
|
8563
8916
|
const day = businessDayOf(at2, timezone);
|
|
8564
8917
|
return range.from <= day && day <= range.to;
|
|
@@ -8572,19 +8925,21 @@ function daysOf(range) {
|
|
|
8572
8925
|
days.push(next);
|
|
8573
8926
|
}
|
|
8574
8927
|
}
|
|
8575
|
-
function comparisonRange(range, mode) {
|
|
8928
|
+
function comparisonRange(range, mode, preset) {
|
|
8929
|
+
const iso2 = (at2) => new Date(at2).toISOString().slice(0, 10);
|
|
8576
8930
|
const [year, month, day] = range.from.split("-").map(Number);
|
|
8577
8931
|
const from = Date.UTC(year, month - 1, day);
|
|
8578
8932
|
const [toYear, toMonth, toDay] = range.to.split("-").map(Number);
|
|
8579
8933
|
const to = Date.UTC(toYear, toMonth - 1, toDay);
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
};
|
|
8934
|
+
const days = daysOf(range).length;
|
|
8935
|
+
const period = preset?.endsWith("Month") ? "month" : preset?.endsWith("Week") ? "week" : days === 1 ? "day" : days <= 7 ? "week" : "month";
|
|
8936
|
+
if (period !== "month") {
|
|
8937
|
+
const shift = (period === "day" && mode === "previous" ? 1 : 7) * DAY_MS;
|
|
8938
|
+
return { from: iso2(from - shift), to: iso2(to - shift) };
|
|
8585
8939
|
}
|
|
8586
|
-
const
|
|
8587
|
-
|
|
8940
|
+
const start = Date.UTC(year, month - 2, Math.min(day, new Date(Date.UTC(year, month - 1, 0)).getUTCDate()));
|
|
8941
|
+
const wholeMonth = day === 1 && to === Date.UTC(year, month, 0);
|
|
8942
|
+
return { from: iso2(start), to: iso2(wholeMonth ? Date.UTC(year, month - 1, 0) : start + (days - 1) * DAY_MS) };
|
|
8588
8943
|
}
|
|
8589
8944
|
function marginOf(lines) {
|
|
8590
8945
|
const margin = { costedNetMinor: 0, costMinor: 0, profitMinor: 0, marginPct: null, missingLines: 0, missingQuantity: 0 };
|
|
@@ -8701,22 +9056,22 @@ function salesFigures(input) {
|
|
|
8701
9056
|
|
|
8702
9057
|
// src/reports/presets.ts
|
|
8703
9058
|
var DATE_PRESETS = ["today", "yesterday", "thisWeek", "lastWeek", "thisMonth", "lastMonth"];
|
|
8704
|
-
var
|
|
9059
|
+
var DAY_MS2 = 864e5;
|
|
8705
9060
|
var iso = (at2) => new Date(at2).toISOString().slice(0, 10);
|
|
8706
9061
|
function presetRange(preset, now, timezone) {
|
|
8707
9062
|
const today = businessDayOf(now.toISOString(), timezone);
|
|
8708
9063
|
const [year, month, day] = today.split("-").map(Number);
|
|
8709
9064
|
const at2 = Date.UTC(year, month - 1, day);
|
|
8710
|
-
const monday = at2 - (new Date(at2).getUTCDay() + 6) % 7 *
|
|
9065
|
+
const monday = at2 - (new Date(at2).getUTCDay() + 6) % 7 * DAY_MS2;
|
|
8711
9066
|
switch (preset) {
|
|
8712
9067
|
case "today":
|
|
8713
9068
|
return { from: today, to: today };
|
|
8714
9069
|
case "yesterday":
|
|
8715
|
-
return { from: iso(at2 -
|
|
9070
|
+
return { from: iso(at2 - DAY_MS2), to: iso(at2 - DAY_MS2) };
|
|
8716
9071
|
case "thisWeek":
|
|
8717
9072
|
return { from: iso(monday), to: today };
|
|
8718
9073
|
case "lastWeek":
|
|
8719
|
-
return { from: iso(monday - 7 *
|
|
9074
|
+
return { from: iso(monday - 7 * DAY_MS2), to: iso(monday - DAY_MS2) };
|
|
8720
9075
|
case "thisMonth":
|
|
8721
9076
|
return { from: iso(Date.UTC(year, month - 1, 1)), to: today };
|
|
8722
9077
|
case "lastMonth":
|
|
@@ -8819,7 +9174,11 @@ export {
|
|
|
8819
9174
|
DEFAULT_WEDGE_SETTINGS,
|
|
8820
9175
|
DISCOUNTS_UNSUPPORTED,
|
|
8821
9176
|
DISPLAY_ACTIONS,
|
|
9177
|
+
DISPLAY_CHANNEL,
|
|
8822
9178
|
DISPLAY_PROTOCOL_VERSION,
|
|
9179
|
+
DISPLAY_TEMPLATE,
|
|
9180
|
+
ESCPOS_CODE_PAGES,
|
|
9181
|
+
HELLO_RETRY_MS,
|
|
8823
9182
|
MAX_MESSAGE_BYTES,
|
|
8824
9183
|
MAX_TENDER_MINOR,
|
|
8825
9184
|
MICROS_PER_MINOR,
|
|
@@ -8888,6 +9247,7 @@ export {
|
|
|
8888
9247
|
canMoveLeg,
|
|
8889
9248
|
canVoidLeg,
|
|
8890
9249
|
capturedMinor,
|
|
9250
|
+
cartQuantities,
|
|
8891
9251
|
cashMovementSchema,
|
|
8892
9252
|
catalogueEntries,
|
|
8893
9253
|
catalogueViewReducer,
|
|
@@ -8906,6 +9266,9 @@ export {
|
|
|
8906
9266
|
countVariance,
|
|
8907
9267
|
countsTowardPaid,
|
|
8908
9268
|
createBackendNotFound,
|
|
9269
|
+
createBroadcastDisplayTransport,
|
|
9270
|
+
createDisplayLink,
|
|
9271
|
+
createEscPosTransport,
|
|
8909
9272
|
createHttpCommandTransport,
|
|
8910
9273
|
createLogger,
|
|
8911
9274
|
createOrderBuilder,
|
|
@@ -8932,7 +9295,9 @@ export {
|
|
|
8932
9295
|
displayReducer,
|
|
8933
9296
|
driverForMethod,
|
|
8934
9297
|
encode as encodeDisplayMessage,
|
|
9298
|
+
encodeEscPos,
|
|
8935
9299
|
ensureRegister,
|
|
9300
|
+
escpos,
|
|
8936
9301
|
evenSplitShareMinor,
|
|
8937
9302
|
exportCsv,
|
|
8938
9303
|
finalizeOrder,
|
|
@@ -8942,6 +9307,7 @@ export {
|
|
|
8942
9307
|
getBoundRegisterId,
|
|
8943
9308
|
getDeviceId,
|
|
8944
9309
|
getProductStock,
|
|
9310
|
+
handoverSlip,
|
|
8945
9311
|
hasValidRetailCheckDigit,
|
|
8946
9312
|
inCategory,
|
|
8947
9313
|
inMotionMinor,
|
|
@@ -9052,6 +9418,7 @@ export {
|
|
|
9052
9418
|
submitOrderRefund,
|
|
9053
9419
|
suggestFloat,
|
|
9054
9420
|
summarizeOutboxHealth,
|
|
9421
|
+
switchWarnings,
|
|
9055
9422
|
takeOverSession,
|
|
9056
9423
|
taxFiguresForBasket,
|
|
9057
9424
|
taxLinesByRate,
|
|
@@ -9071,6 +9438,7 @@ export {
|
|
|
9071
9438
|
useCashier,
|
|
9072
9439
|
useCurrencyCode,
|
|
9073
9440
|
useCurrencyFormatter,
|
|
9441
|
+
useCustomerDisplay,
|
|
9074
9442
|
useOrderOutbox,
|
|
9075
9443
|
useOutboxHealth,
|
|
9076
9444
|
useParkedSales,
|