@tallyui/pos 3.20.1 → 4.0.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 +1005 -110
- package/dist/index.js +3156 -907
- package/package.json +6 -6
- package/src/app-settings/app-settings.ts +77 -0
- package/src/app-settings/index.ts +2 -0
- package/src/currency/currency-provider.tsx +5 -7
- package/src/currency/index.ts +1 -1
- package/src/customer/customer-patch.ts +70 -0
- package/src/customer-display/display-client.ts +11 -17
- package/src/customer-display/display-link.ts +10 -5
- package/src/customer-display/index.ts +3 -1
- package/src/customer-display/protocol.ts +1 -1
- package/src/customer-display/sale-display.ts +6 -8
- package/src/customer-display/snapshot-fallback.ts +14 -1
- package/src/customer-display/till-device.ts +62 -0
- package/src/customer-display/till-display-service.ts +44 -42
- package/src/customer-display/till-pairing.ts +20 -23
- package/src/customer-display/use-customer-display.ts +2 -1
- package/src/customer-display/use-till-pairing.ts +4 -4
- package/src/index.ts +37 -18
- package/src/order/allocate-order-discount.ts +5 -17
- package/src/order/apportion.ts +29 -0
- package/src/order/from-store-order.ts +115 -0
- package/src/order/index.ts +1 -0
- package/src/order/order-builder.ts +239 -52
- package/src/order/order-drafts.ts +45 -6
- package/src/order/order-manager.ts +2 -1
- package/src/order/tax-ids.ts +27 -0
- package/src/order/types.ts +59 -5
- package/src/order/woocommerce-tax.ts +9 -0
- package/src/outbox/index.ts +1 -1
- package/src/outbox/order-outbox.ts +138 -43
- package/src/outbox/register-outbox.ts +4 -3
- package/src/outbox/retry-delay.ts +8 -0
- package/src/outbox/use-order-outbox.ts +8 -2
- package/src/pos-order/__fixtures__/order-create-v10.json +97 -0
- package/src/pos-order/__fixtures__/order-create-v11.json +90 -0
- package/src/pos-order/__fixtures__/order-create-v12.json +95 -0
- package/src/pos-order/__fixtures__/order-create-v9.json +89 -0
- package/src/pos-order/attention-handled.ts +24 -0
- package/src/pos-order/command.ts +132 -12
- package/src/pos-order/extras-delivery.ts +14 -0
- package/src/pos-order/finalize.ts +138 -29
- package/src/pos-order/index.ts +7 -3
- package/src/pos-order/money-divergence.ts +19 -0
- package/src/pos-order/needs-attention.ts +9 -1
- package/src/pos-order/refund-due.ts +35 -0
- package/src/pos-order/reopen.ts +96 -12
- package/src/pos-order/schema.ts +35 -10
- package/src/pos-order/till-payments.ts +4 -0
- package/src/pos-order/types.ts +44 -5
- package/src/print/escpos/__fixtures__/thermal-every-node.xml +33 -0
- package/src/print/escpos/commands.ts +79 -0
- package/src/print/escpos/drawer.ts +25 -0
- package/src/print/escpos/encode.ts +1 -0
- package/src/print/escpos/index.ts +6 -1
- package/src/print/escpos/network-sinks.ts +130 -0
- package/src/print/escpos/render-escpos.ts +155 -0
- package/src/print/escpos/transport.ts +2 -1
- package/src/print/index.ts +5 -2
- package/src/print/resolve-printer.ts +46 -0
- package/src/print/types.ts +1 -1
- package/src/product/index.ts +2 -0
- package/src/product/terms.ts +42 -0
- package/src/product/tile-fields.ts +27 -0
- package/src/receipt/build-receipt-data.ts +12 -7
- package/src/receipt/carried-rows.ts +29 -0
- package/src/receipt/index.ts +1 -0
- package/src/receipt/reprint.ts +14 -8
- package/src/receipt/types.ts +3 -1
- package/src/receipt-template/default-templates.ts +3 -0
- package/src/receipt-template/template-data.ts +3 -0
- package/src/receipt-template/wcpos/build.ts +1 -0
- package/src/receipt-template/wcpos/format.ts +2 -2
- package/src/receipt-template/wcpos/from-orders.ts +6 -2
- package/src/receipt-template/wcpos/types.ts +5 -1
- package/src/register/closure-document.ts +42 -4
- package/src/register/closure-rows.ts +3 -2
- package/src/register/document-labels.ts +25 -0
- package/src/register/expected.ts +49 -10
- package/src/register/index.ts +5 -5
- package/src/register/money.ts +23 -0
- package/src/register/register-adoption.ts +6 -5
- package/src/register/register-commands.ts +4 -3
- package/src/register/schemas.ts +11 -3
- package/src/register/session-store.ts +44 -23
- package/src/register/settled-figures.ts +5 -19
- package/src/register/use-register-session.ts +18 -19
- package/src/reopen/index.ts +3 -0
- package/src/reopen/reopen-entry.ts +48 -0
- package/src/reopen/reopen-store-order.ts +78 -0
- package/src/reopen/send-order-reopen.ts +61 -0
- package/src/reports/adapters.ts +15 -7
- package/src/reports/sales-figures.ts +15 -1
- package/src/reports/types.ts +2 -0
- package/src/sale/cart.ts +4 -2
- package/src/sale/index.ts +1 -1
- package/src/sale/open-sales.ts +3 -0
- package/src/sale/use-sale.ts +388 -83
- package/src/sale/woocommerce/coupon-refetch.ts +1 -0
- package/src/sale/woocommerce/coupon-source.ts +4 -4
- package/src/sale/woocommerce/coupons.ts +6 -0
- package/src/sale/woocommerce/discount-codes.ts +1 -6
- package/src/scanner/analyze-trace.ts +86 -0
- package/src/scanner/device-scanner.ts +57 -0
- package/src/scanner/hid-scanner.ts +14 -41
- package/src/scanner/index.ts +2 -0
- package/src/scanner/serial-scanner.ts +15 -42
- package/src/scanner/use-barcode-scanner.ts +107 -5
- package/src/scanner/wedge-detector.ts +33 -15
- package/src/tax/exact.ts +1 -13
- package/src/tax/taxed-lines.ts +26 -0
- package/src/tender/index.ts +6 -1
- package/src/tender/split-units.ts +109 -0
- package/src/tender/tender-figures.ts +114 -0
- package/src/tender/tender-state.ts +105 -17
- package/src/currency/format-money-with.ts +0 -45
|
@@ -3,7 +3,7 @@ import type { RxCollection, RxJsonSchema } from 'rxdb';
|
|
|
3
3
|
import type { TaxContext } from '../tax/types';
|
|
4
4
|
import { customerRefusal } from '../pos-order/command';
|
|
5
5
|
import { capturedMinor } from '../tender/payment-legs';
|
|
6
|
-
import { createOrderBuilder, type OrderBuilder } from './order-builder';
|
|
6
|
+
import { couponPricingBasis, createOrderBuilder, isLiveLeg, type OrderBuilder } from './order-builder';
|
|
7
7
|
import type { Order } from './types';
|
|
8
8
|
|
|
9
9
|
/** Apps create their drafts collection with this schema. */
|
|
@@ -58,12 +58,22 @@ export async function writeOrderDraft(drafts: RxCollection, snapshot: Order): Pr
|
|
|
58
58
|
return snapshot.id;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Rebuilds a saved order on `taxContext`. Fees and shipping re-derive their rates; under woo granularity lines re-derive
|
|
63
|
+
* from their class too. Outside woo, a line marked taxFromClass re-derives from its class unless `keepTaxRates` is set;
|
|
64
|
+
* every other line (given rates, a draft from before the marker) keeps its stored rates. `keepCoupons` puts the saved
|
|
65
|
+
* coupons back as parked, figures and all, while an unlocked leg is live (ADR-077 d3, amended 2026-11-19); otherwise none.
|
|
66
|
+
* Carried coupons always restore their priced amounts against the saved basis, keeping stale figures stale.
|
|
67
|
+
*/
|
|
68
|
+
export function restoreOrderDraft(saved: Order, options: { currency: string; taxContext: TaxContext; keepTaxRates?: boolean; keepCoupons?: boolean }): OrderBuilder {
|
|
62
69
|
const { currency, taxContext } = options;
|
|
63
70
|
const builder = createOrderBuilder({
|
|
64
71
|
currency,
|
|
65
72
|
taxContext,
|
|
66
73
|
id: saved.id,
|
|
74
|
+
...(saved.createdAt ? { createdAt: saved.createdAt } : {}), // #742: with every id below (fees and shipping replay whole)
|
|
75
|
+
...(saved.storeOrder !== undefined ? { storeOrder: saved.storeOrder } : {}),
|
|
76
|
+
...(saved.afterClose !== undefined ? { afterClose: saved.afterClose } : {}),
|
|
67
77
|
});
|
|
68
78
|
|
|
69
79
|
// Restore state from saved order
|
|
@@ -74,27 +84,34 @@ export function restoreOrderDraft(saved: Order, options: { currency: string; tax
|
|
|
74
84
|
if (saved.note) {
|
|
75
85
|
builder.setNote(saved.note);
|
|
76
86
|
}
|
|
87
|
+
if (saved.meta?.length) builder.setMeta(saved.meta);
|
|
77
88
|
|
|
78
89
|
// Restore line items and their discounts
|
|
79
90
|
for (const line of saved.lineItems) {
|
|
91
|
+
const rederive = line.taxFromClass === true && !options.keepTaxRates;
|
|
80
92
|
const lineId = builder.addLine({
|
|
93
|
+
id: line.id,
|
|
81
94
|
productId: line.productId,
|
|
95
|
+
separate: true,
|
|
96
|
+
...(line.storeLineId !== undefined ? { storeLineId: line.storeLineId } : {}),
|
|
82
97
|
custom: line.custom,
|
|
83
98
|
taxStatus: line.taxStatus,
|
|
84
|
-
...(taxContext.rounding?.granularity === 'woocommerce' ? { taxClass: line.taxClass } : {}),
|
|
99
|
+
...(rederive || taxContext.rounding?.granularity === 'woocommerce' ? { taxClass: line.taxClass } : {}),
|
|
85
100
|
variantId: line.variantId,
|
|
86
101
|
name: line.name,
|
|
87
102
|
...(line.attributes !== undefined ? { attributes: line.attributes } : {}),
|
|
88
103
|
...(line.anyAttributes !== undefined ? { anyAttributes: line.anyAttributes } : {}),
|
|
89
|
-
sku: line.sku,
|
|
104
|
+
sku: line.catalogueSku ?? line.sku,
|
|
90
105
|
imageUrl: line.imageUrl,
|
|
91
106
|
unitPrice: { amount: line.unitPriceMinor, currency, taxInclusive: line.taxInclusive },
|
|
92
107
|
...(line.regularUnitPriceMinor !== undefined ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {}),
|
|
93
108
|
quantity: line.quantity,
|
|
94
|
-
taxRates: line.taxLines.map(({ code, ratePpm }) => ({ code, ratePpm })),
|
|
109
|
+
...(rederive ? {} : { taxRates: line.taxLines.map(({ code, ratePpm }) => ({ code, ratePpm })) }),
|
|
95
110
|
});
|
|
111
|
+
if (line.catalogueSku !== undefined) builder.updateLine(lineId, { sku: line.sku });
|
|
96
112
|
for (const discount of line.discounts) {
|
|
97
113
|
builder.applyLineDiscount(lineId, {
|
|
114
|
+
id: discount.id,
|
|
98
115
|
type: discount.type,
|
|
99
116
|
value: discount.value,
|
|
100
117
|
label: discount.label,
|
|
@@ -109,6 +126,7 @@ export function restoreOrderDraft(saved: Order, options: { currency: string; tax
|
|
|
109
126
|
// Restore order-level discounts
|
|
110
127
|
for (const discount of saved.discounts) {
|
|
111
128
|
builder.applyOrderDiscount({
|
|
129
|
+
id: discount.id,
|
|
112
130
|
type: discount.type,
|
|
113
131
|
value: discount.value,
|
|
114
132
|
label: discount.label,
|
|
@@ -116,18 +134,39 @@ export function restoreOrderDraft(saved: Order, options: { currency: string; tax
|
|
|
116
134
|
});
|
|
117
135
|
}
|
|
118
136
|
|
|
119
|
-
// Coupons are re-applied by the sale with fresh coupon data (ADR-077 d3),
|
|
137
|
+
// Coupons are re-applied by the sale with fresh coupon data (ADR-077 d3), except carried coupons and keepCoupons below.
|
|
120
138
|
// Restore payments
|
|
121
139
|
for (const payment of saved.payments) {
|
|
122
140
|
builder.addPayment({
|
|
141
|
+
id: payment.id,
|
|
123
142
|
method: payment.method,
|
|
124
143
|
amountMinor: payment.amountMinor,
|
|
125
144
|
tenderedMinor: payment.tenderedMinor,
|
|
126
145
|
changeMinor: payment.changeMinor,
|
|
127
146
|
reference: payment.reference,
|
|
128
147
|
...(payment.status !== undefined ? { status: payment.status } : {}),
|
|
148
|
+
...(payment.storePaymentId !== undefined ? { storePaymentId: payment.storePaymentId } : {}),
|
|
149
|
+
...(payment.locked !== undefined ? { locked: payment.locked } : {}),
|
|
150
|
+
...(payment.methodId !== undefined ? { methodId: payment.methodId } : {}),
|
|
151
|
+
...(payment.units !== undefined ? { units: payment.units } : {}),
|
|
129
152
|
});
|
|
130
153
|
}
|
|
154
|
+
if (saved.coupons?.some((c) => c.carried) && !saved.coupons.every((c) => c.carried)) throw new Error('restoreOrderDraft: a draft cannot mix carried and redeemable coupons');
|
|
155
|
+
if (saved.coupons?.length && saved.coupons.every((coupon) => coupon.carried)) {
|
|
156
|
+
builder.setCoupons(saved.coupons.map((c) => c.code), { kind: 'store-priced', carried: true,
|
|
157
|
+
priced: new Map(saved.coupons.map((c) => [c.code, { couponId: c.couponId,
|
|
158
|
+
lines: (c.lines ?? []).filter((l) => l.amountMinor !== undefined).map(({ lineId, amountMinor }) => ({ lineId, amountMinor: amountMinor! })) }])),
|
|
159
|
+
basis: saved.couponPricesStale ? '' : couponPricingBasis(saved) });
|
|
160
|
+
return builder;
|
|
161
|
+
}
|
|
162
|
+
// Kept only with a display row per coupon; a draft parked stale keeps its figures but stays stale (basis '' never matches).
|
|
163
|
+
if (options.keepCoupons && saved.coupons?.length && saved.display.coupons?.length === saved.coupons.length) {
|
|
164
|
+
const restored = builder.getSnapshot();
|
|
165
|
+
builder.setCoupons(saved.coupons.map((coupon) => coupon.code), { kind: 'kept', coupons: saved.coupons,
|
|
166
|
+
displayRows: saved.display.coupons.map((row) => row.amountMinor), lines: new Map(saved.lineItems.map((li) => [li.id, li])),
|
|
167
|
+
basis: saved.couponPricesStale ? '' : couponPricingBasis(restored), linesBasis: couponPricingBasis({ ...restored, customer: null }),
|
|
168
|
+
legIds: saved.payments.filter(isLiveLeg).map((p) => p.id) });
|
|
169
|
+
}
|
|
131
170
|
return builder;
|
|
132
171
|
}
|
|
133
172
|
|
|
@@ -3,6 +3,7 @@ import type { RxCollection } from 'rxdb';
|
|
|
3
3
|
import type { TaxContext } from '../tax/types';
|
|
4
4
|
import { createOrderBuilder, type OrderBuilder } from './order-builder';
|
|
5
5
|
import type { Order } from './types';
|
|
6
|
+
import { capturedMinor } from '../tender/payment-legs';
|
|
6
7
|
import { writeOrderDraft, restoreOrderDraft, parkedOrderSummaries$, type ParkedOrderSummary } from './order-drafts';
|
|
7
8
|
|
|
8
9
|
export type { ParkedOrderSummary } from './order-drafts';
|
|
@@ -57,7 +58,7 @@ export function createOrderManager(options: OrderManagerOptions): OrderManager {
|
|
|
57
58
|
const json = doc.toJSON() as any;
|
|
58
59
|
const savedOrder: Order = JSON.parse(json.data);
|
|
59
60
|
|
|
60
|
-
const builder = restoreOrderDraft(savedOrder, { currency, taxContext });
|
|
61
|
+
const builder = restoreOrderDraft(savedOrder, { currency, taxContext, keepTaxRates: capturedMinor(savedOrder.payments ?? []) !== 0 });
|
|
61
62
|
|
|
62
63
|
await doc.remove();
|
|
63
64
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ORDER_TAX_ID_TYPE_MAX, ORDER_TAX_ID_VALUE_MAX, ORDER_TAX_IDS_MAX, type CustomerTaxId } from '@tallyui/core';
|
|
2
|
+
|
|
3
|
+
/** ADR-092 6a: the refusal of a tax id list order.create 12 could not carry (setTaxIds, setCustomer, tender entry, finalize). */
|
|
4
|
+
export const TAX_IDS_INVALID = 'Each tax id needs a type of at most 32 characters and a number of at most 64, no two the same; a country is a two-letter code, and a sale takes at most 10.';
|
|
5
|
+
/** A tax id's label is stored on the order but never sent; it is held to the 255 characters of the payload's other free text. */
|
|
6
|
+
const TAX_ID_LABEL_MAX = 255;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* #1064: the one tax-id rule. Trims every field, upper-cases the country and drops an empty country or label, returning a
|
|
10
|
+
* new list of new entries; null when the list is one order.create 12 could not carry (too many, an empty or too long type
|
|
11
|
+
* or value, a NUL, a country that is not two letters, a type and value twice, a too long label).
|
|
12
|
+
*/
|
|
13
|
+
export function cleanTaxIds(list: CustomerTaxId[]): CustomerTaxId[] | null {
|
|
14
|
+
if (list.length > ORDER_TAX_IDS_MAX) return null;
|
|
15
|
+
const seen = new Set<string>();
|
|
16
|
+
const cleaned: CustomerTaxId[] = [];
|
|
17
|
+
for (const taxId of list) {
|
|
18
|
+
const type = taxId.type.trim(), value = taxId.value.trim(), country = taxId.country?.trim().toUpperCase(), label = taxId.label?.trim();
|
|
19
|
+
const key = JSON.stringify([type, value]);
|
|
20
|
+
if (!type || !value || type.length > ORDER_TAX_ID_TYPE_MAX || value.length > ORDER_TAX_ID_VALUE_MAX || seen.has(key)
|
|
21
|
+
|| [type, value, country, label].some((field) => field?.includes('\u0000'))
|
|
22
|
+
|| (country && !/^[A-Z]{2}$/.test(country)) || (label && label.length > TAX_ID_LABEL_MAX)) return null;
|
|
23
|
+
seen.add(key);
|
|
24
|
+
cleaned.push({ type, value, ...(country ? { country } : {}), ...(label ? { label } : {}) });
|
|
25
|
+
}
|
|
26
|
+
return cleaned;
|
|
27
|
+
}
|
package/src/order/types.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import type { CustomerAddress, Money, TaxRounding } from '@tallyui/core';
|
|
1
|
+
import type { CustomerAddress, CustomerTaxId, Money, OrderCreateMeta, TaxRounding } from '@tallyui/core';
|
|
2
2
|
import type { PaymentLegStatus } from '../tender/payment-legs';
|
|
3
3
|
|
|
4
|
+
/** A store-priced coupon's share of one line (#790, docs/contract/order-create-v9.md), tax-exclusive, in integer minor units. */
|
|
5
|
+
export interface OrderCouponLine {
|
|
6
|
+
lineId: string;
|
|
7
|
+
discountMinor: number; // >= 0
|
|
8
|
+
discountTaxMinor: number; // >= 0
|
|
9
|
+
/** The store's priced amount in this line's own tax mode; present only on a carried coupon. */
|
|
10
|
+
amountMinor?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
export interface OrderCoupon {
|
|
5
14
|
code: string; // lower-case code
|
|
6
15
|
couponId: string; // the connector's coupon id, as a string
|
|
7
16
|
discountMinor: number; // the coupon's discount (WooCommerce's replay, or the store's own prices, #709), ex tax, in integer minor units
|
|
8
17
|
discountTaxMinor: number; // its tax, in integer minor units
|
|
18
|
+
/** The store refused this code at send and the sale was charged at its price; it is never sent as a coupon. */
|
|
19
|
+
carried?: true;
|
|
20
|
+
/** #790: present only on a store-priced coupon. It holds the coupon's share of each line, in lineItems order, with no zero entries unless a carried coupon's amountMinor is non-zero. */
|
|
21
|
+
lines?: OrderCouponLine[];
|
|
9
22
|
}
|
|
10
23
|
|
|
24
|
+
/** The store order a reopened cart edits (ADR-090): its id, the revision it was read at, and the till's id for it when a till made it. */
|
|
25
|
+
export interface StoreOrderRef { id: string; revision: string; uuid?: string }
|
|
26
|
+
|
|
11
27
|
export interface Order {
|
|
12
28
|
id: string;
|
|
29
|
+
/** Set only on a reopened sale; absent on every new sale. */
|
|
30
|
+
storeOrder?: StoreOrderRef;
|
|
31
|
+
/** Set only on a reopened sale whose closed session's closure already counted it (ADR-077, Front desk 2026-11-21): it is re-sent with its original time and register, in no session, with the payment legs, fees, shipping and tax that closure counted, at the legs' sum as its total. */
|
|
32
|
+
afterClose?: { sessionId: string; createdAt: string; registerId?: string; payments: Array<{ id: string; method: string; amountMinor: number }>;
|
|
33
|
+
taxMinor: number; fees: Array<Pick<ChargeLine, 'totalMinor' | 'taxLines'>>; shipping: Array<Pick<ChargeLine, 'totalMinor' | 'taxLines'>> };
|
|
13
34
|
status: 'draft' | 'parked' | 'saved' | 'completed';
|
|
14
35
|
lineItems: LineItem[];
|
|
15
36
|
fees?: FeeLine[];
|
|
@@ -22,6 +43,9 @@ export interface Order {
|
|
|
22
43
|
payments: Payment[];
|
|
23
44
|
customer: CustomerSummary | null;
|
|
24
45
|
note: string;
|
|
46
|
+
/** The sale's order meta, WooCommerce's custom fields (ADR-092 6d). Set with `useSale().setMeta`, parked with the draft,
|
|
47
|
+
* stored on the order, and sent at order.create 12. Keys are unique; none starts with `_`. Absent when there is none. */
|
|
48
|
+
meta?: OrderCreateMeta[];
|
|
25
49
|
currency: string;
|
|
26
50
|
pricesIncludeTax: boolean;
|
|
27
51
|
/** The store's tax rounding strategy the figures were computed with (#287), from the sale's tax context; absent is per_order. */
|
|
@@ -69,7 +93,12 @@ export interface DisplayLine {
|
|
|
69
93
|
|
|
70
94
|
export interface LineItem {
|
|
71
95
|
id: string;
|
|
96
|
+
/** The store's id for a line the reopened sale keeps; absent on a line the till added. */
|
|
97
|
+
storeLineId?: string;
|
|
98
|
+
/** The line's tax class: kept under woo granularity, on a custom line that has one, and on a class-taxed line outside woo. */
|
|
72
99
|
taxClass?: string;
|
|
100
|
+
/** Set outside woo granularity when the line's rates came from the tax context for taxClass (absent: rates the caller gave, or a draft from before this field); a re-tax or resume re-derives them. */
|
|
101
|
+
taxFromClass?: true;
|
|
73
102
|
/** WooCommerce's stored net at rounding precision, in integer micro-minor units, and its rounded gross. */
|
|
74
103
|
netMicros?: string;
|
|
75
104
|
totalMinor?: number;
|
|
@@ -83,6 +112,8 @@ export interface LineItem {
|
|
|
83
112
|
/** The names in attributes the cashier picked for the variant's "Any" option groups (#495); absent when none. */
|
|
84
113
|
anyAttributes?: string[];
|
|
85
114
|
sku: string;
|
|
115
|
+
/** The SKU the line was added with, set the first time the cashier edits a catalogue line's SKU (ADR-092 6b); absent means `sku` is the catalogue's. */
|
|
116
|
+
catalogueSku?: string;
|
|
86
117
|
imageUrl?: string;
|
|
87
118
|
unitPriceMinor: number; // as sold, integer
|
|
88
119
|
/** The catalogue's regular unit price, in the line's own tax mode like unitPriceMinor; absent on custom lines (ADR-077 d3). */
|
|
@@ -101,19 +132,25 @@ export interface LineItem {
|
|
|
101
132
|
|
|
102
133
|
export interface ChargeLine {
|
|
103
134
|
id: string;
|
|
135
|
+
/** The store's id for a line the reopened sale keeps; absent on a line the till added. */
|
|
136
|
+
storeLineId?: string;
|
|
104
137
|
netMicros?: string;
|
|
105
138
|
totalMinor?: number;
|
|
106
139
|
name: string;
|
|
107
|
-
amountMinor: number; // integer >= 0, in the
|
|
140
|
+
amountMinor: number; // integer >= 0, as entered, in the charge's own mode (amountIncludesTax, else the order's; ADR-075)
|
|
108
141
|
taxClass?: string;
|
|
109
142
|
taxStatus: 'taxable' | 'none';
|
|
143
|
+
/** The cashier's mode for this charge (v2 "Amount includes tax"); absent means the order's. Never stored on a finalized order. */
|
|
144
|
+
amountIncludesTax?: boolean;
|
|
145
|
+
/** A fee's percentage of the cart (v2 Add Fee "%"): the builder sets `amountMinor` to it on every build. Fees only. Never stored on a finalized order. */
|
|
146
|
+
percent?: number;
|
|
110
147
|
taxLines: LineItem['taxLines'];
|
|
111
148
|
netMinor: number;
|
|
112
149
|
taxMicros: string;
|
|
113
150
|
}
|
|
114
151
|
export interface FeeLine extends ChargeLine {}
|
|
115
152
|
export interface ShippingLine extends ChargeLine { methodId?: string }
|
|
116
|
-
export interface ChargeInput { name: string; amountMinor: number; taxClass?: string; taxStatus?: 'taxable' | 'none' }
|
|
153
|
+
export interface ChargeInput { id?: string; name: string; amountMinor: number; taxClass?: string; taxStatus?: 'taxable' | 'none'; storeLineId?: string; amountIncludesTax?: boolean; percent?: number }
|
|
117
154
|
|
|
118
155
|
export interface LineTaxLine {
|
|
119
156
|
code?: string;
|
|
@@ -124,6 +161,7 @@ export interface LineTaxLine {
|
|
|
124
161
|
}
|
|
125
162
|
|
|
126
163
|
export interface Discount {
|
|
164
|
+
id?: string; // as an input, a restored discount's own (#742); a taken id throws
|
|
127
165
|
type: 'percentage' | 'fixed';
|
|
128
166
|
value: number; // percentage: percent (e.g. 10); fixed: integer minor units
|
|
129
167
|
label?: string;
|
|
@@ -137,15 +175,23 @@ export interface AppliedDiscount extends Discount {
|
|
|
137
175
|
|
|
138
176
|
export interface Payment {
|
|
139
177
|
id: string;
|
|
178
|
+
/** The store's payment record id for a leg it already holds */
|
|
179
|
+
storePaymentId?: string;
|
|
180
|
+
/** A leg the store already holds: never removed or moved, only sent back with its storePaymentId */
|
|
181
|
+
locked?: true;
|
|
140
182
|
method: string;
|
|
183
|
+
/** The payment method's own id on the platform, kept for labels and takings (`legMethodId`); `method` decides cash. */
|
|
184
|
+
methodId?: string;
|
|
141
185
|
/** Absent means captured; only captured legs count toward paidMinor. */
|
|
142
186
|
status?: PaymentLegStatus;
|
|
143
|
-
//
|
|
144
|
-
//
|
|
187
|
+
// Cash records the full tendered amount, except a leg taken for picked units with `tenderedMinor`:
|
|
188
|
+
// it records the pick's money here and keeps the amount handed over and the change.
|
|
145
189
|
amountMinor: number;
|
|
146
190
|
tenderedMinor?: number;
|
|
147
191
|
changeMinor?: number;
|
|
148
192
|
reference?: string;
|
|
193
|
+
/** The units of each line (`String(line id)`) this leg paid for, set when it was taken with unit picks (#1133). Absent for a leg taken by amount. */
|
|
194
|
+
units?: Readonly<Record<string, number>>;
|
|
149
195
|
}
|
|
150
196
|
|
|
151
197
|
export interface CustomerSummary {
|
|
@@ -156,6 +202,9 @@ export interface CustomerSummary {
|
|
|
156
202
|
* order.create 8 when the sale was taxed on one of them (#722). */
|
|
157
203
|
billing?: CustomerAddress;
|
|
158
204
|
shipping?: CustomerAddress;
|
|
205
|
+
/** The sale's tax ids (ADR-092 6a): set with `useSale().setTaxIds`, parked with the draft, stored on the order and sent
|
|
206
|
+
* at order.create 12 without `label`. A picked customer's own (`Customer.taxIds`) may be passed in `setCustomer`, which refuses a list `setTaxIds` would refuse. */
|
|
207
|
+
taxIds?: CustomerTaxId[];
|
|
159
208
|
}
|
|
160
209
|
|
|
161
210
|
export interface PaymentMethod {
|
|
@@ -166,7 +215,12 @@ export interface PaymentMethod {
|
|
|
166
215
|
}
|
|
167
216
|
|
|
168
217
|
export interface AddLineInput {
|
|
218
|
+
id?: string; // a restored line's own (#742), used when the line does not merge; a taken id throws
|
|
169
219
|
productId: string;
|
|
220
|
+
/** A kept store line: never merged */
|
|
221
|
+
storeLineId?: string;
|
|
222
|
+
/** Add as its own line: never merged into an equal line (a draft's lines restore one for one). */
|
|
223
|
+
separate?: true;
|
|
170
224
|
custom?: true;
|
|
171
225
|
taxStatus?: 'taxable' | 'none';
|
|
172
226
|
variantId?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { minorUnitDigits, woocommerceTax, woocommerceCoupons } from '@tallyui/core';
|
|
2
2
|
import type { TaxContext, WooRate } from '../tax/types';
|
|
3
|
+
import { roundMicrosToMinor } from '../tax/exact';
|
|
3
4
|
import type { RateTaxLine } from '../tax/exact';
|
|
4
5
|
import type { ChargeLine, LineItem, LineTaxLine, OrderCoupon } from './types';
|
|
5
6
|
import type { OrderCouponContext } from './order-builder';
|
|
@@ -100,6 +101,14 @@ export function woocommerceTotals(lines: readonly LineItem[], fees: readonly Cha
|
|
|
100
101
|
totalMinor: Math.round(woocommerceTax.roundHalfUp(woocommerceTax.roundHalfUp(amount + tax, 6), dp) * factor) };
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
/** A WooCommerce charge's tax in minor units as the store totals it (#1120): each rate rounded on its own, then summed,
|
|
105
|
+
* as woocommerceTaxByRate rounds its rows; the summed micros rounded once when the store rounds at subtotal. */
|
|
106
|
+
export function woocommerceChargeTaxMinor(charge: { taxLines: readonly LineTaxLine[]; taxMicros: string },
|
|
107
|
+
roundAtSubtotal: boolean, inclusive: boolean): number {
|
|
108
|
+
if (roundAtSubtotal) return roundMicrosToMinor(BigInt(charge.taxMicros));
|
|
109
|
+
return charge.taxLines.reduce((sum, tax) => sum + woocommerceTax.roundTaxTotal(Number(tax.taxMicros) / 1e6, 0, inclusive), 0);
|
|
110
|
+
}
|
|
111
|
+
|
|
103
112
|
/** Order-math's rate buckets, including zero rows; the last row takes the bounded order tax residue. */
|
|
104
113
|
export function woocommerceTaxByRate(lines: readonly { netMinor: number; taxInclusive: boolean; taxLines: readonly LineTaxLine[] }[],
|
|
105
114
|
roundAtSubtotal: boolean, taxLabels?: Record<number, string>, orderTaxMinor?: number): RateTaxLine[] {
|
package/src/outbox/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createHttpCommandTransport } from './http-transport';
|
|
2
2
|
export type { HttpTransportOptions } from './http-transport';
|
|
3
|
-
export { createOrderOutbox, isRequeueable } from './order-outbox';
|
|
3
|
+
export { createOrderOutbox, isRequeueable, isRequeueableOrder } from './order-outbox';
|
|
4
4
|
export type { OrderOutboxOptions, OrderOutbox } from './order-outbox';
|
|
5
5
|
export { createRegisterOutbox, isRegisterRequeueable } from './register-outbox';
|
|
6
6
|
export type { RegisterOutboxOptions, RegisterOutbox } from './register-outbox';
|