@tallyui/pos 4.2.0 → 5.1.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 +620 -166
- package/dist/index.js +1970 -1091
- package/package.json +7 -6
- package/src/index.ts +15 -12
- package/src/order/index.ts +1 -0
- package/src/order/order-builder.ts +64 -22
- package/src/order/order-drafts.ts +77 -25
- package/src/order/types.ts +9 -2
- package/src/order/woocommerce-tax.ts +9 -12
- package/src/outbox/http-transport.ts +16 -1
- package/src/outbox/index.ts +3 -1
- package/src/outbox/needs-admin-reason.ts +10 -0
- package/src/outbox/order-outbox.ts +27 -11
- package/src/outbox/register-outbox.ts +4 -3
- package/src/outbox/store-settlement.ts +136 -0
- package/src/outbox/types.ts +3 -1
- package/src/outbox/use-order-outbox.ts +54 -4
- package/src/pos-order/attention-handled.ts +2 -0
- package/src/pos-order/command.ts +31 -9
- package/src/pos-order/finalize.ts +9 -0
- package/src/pos-order/index.ts +3 -1
- package/src/pos-order/needs-attention.ts +8 -3
- package/src/pos-order/reopen.ts +9 -2
- package/src/pos-order/schema.ts +20 -2
- package/src/pos-order/store-order-left.ts +21 -0
- package/src/pos-order/store-settlement.ts +51 -0
- package/src/pos-order/types.ts +27 -1
- package/src/receipt/build-receipt-data.ts +8 -1
- package/src/receipt/reprint.ts +2 -0
- package/src/receipt/types.ts +2 -0
- package/src/receipt-template/template-data.ts +1 -1
- package/src/receipt-template/wcpos/from-orders.ts +5 -1
- package/src/refund/index.ts +1 -0
- package/src/refund/needs-admin-line.ts +6 -0
- package/src/refund/refundable-lines.ts +2 -91
- package/src/refund/send-order-refund.ts +6 -1
- package/src/refund/submit-order-refund.ts +33 -1
- package/src/register/closing.ts +15 -0
- package/src/register/closure-document.ts +13 -5
- package/src/register/closure-figures.ts +83 -0
- package/src/register/document-labels.ts +5 -3
- package/src/register/expected.ts +30 -9
- package/src/register/index.ts +3 -1
- package/src/register/register-adoption.ts +42 -4
- package/src/register/register-document.ts +17 -0
- package/src/register/session-store.ts +48 -12
- package/src/register/use-register-session.ts +53 -20
- package/src/reports/adapters.ts +5 -1
- package/src/reports/index.ts +1 -1
- package/src/reports/sales-figures.ts +33 -6
- package/src/reports/types.ts +3 -1
- package/src/sale/index.ts +1 -1
- package/src/sale/use-sale.ts +320 -134
- package/src/store-orders/index.ts +3 -0
- package/src/store-orders/sales-range-query.ts +18 -0
- package/src/store-orders/use-store-refunds-in-range.ts +179 -0
- package/src/tax/exact.ts +2 -10
- package/src/tender/cash-rounding.ts +57 -6
- package/src/tender/index.ts +1 -1
- package/src/tender/payment-legs.ts +5 -0
- package/src/tender/tender-figures.ts +3 -1
- package/src/outbox/types.test-d.ts +0 -27
- package/src/print/escpos/sinks.test-d.ts +0 -77
package/src/reports/adapters.ts
CHANGED
|
@@ -23,6 +23,7 @@ export function reportOrderFromPosOrder(order: PosOrder, join?: LineJoin, method
|
|
|
23
23
|
const taxes = recordedTaxByRate(order) ?? taxLinesByRate(taxedLines, order.taxMinor, undefined, order.taxRounding);
|
|
24
24
|
const till = tillPayments(order.payments);
|
|
25
25
|
const amountOf = (payments: readonly { amountMinor: number }[]) => payments.reduce((total, payment) => total + payment.amountMinor, 0);
|
|
26
|
+
const roundingMinor = (order.cashRoundings ?? []).reduce((total, entry) => total + entry.minor, 0);
|
|
26
27
|
return {
|
|
27
28
|
id: order.id, at: order.createdAt, totalMinor: order.totalMinor, taxMinor: order.taxMinor,
|
|
28
29
|
discountMinor: order.discountMinor, needsPayment: false, refunds: [],
|
|
@@ -43,6 +44,7 @@ export function reportOrderFromPosOrder(order: PosOrder, join?: LineJoin, method
|
|
|
43
44
|
return { method, ...(label ? { label } : {}), amountMinor: payment.amountMinor };
|
|
44
45
|
}),
|
|
45
46
|
...(order.storeOrderId !== undefined ? { paidEarlierMinor: amountOf(order.payments) - amountOf(till) } : {}),
|
|
47
|
+
...(roundingMinor !== 0 ? { roundingMinor } : {}),
|
|
46
48
|
taxes: taxes.map((row) => ({
|
|
47
49
|
ratePpm: row.ratePpm, ...(row.code !== undefined ? { code: row.code } : {}),
|
|
48
50
|
label: row.label ?? `Tax ${row.ratePpm / 10000}%`, taxMinor: row.amountMinor, netMinor: row.netMinor,
|
|
@@ -50,9 +52,10 @@ export function reportOrderFromPosOrder(order: PosOrder, join?: LineJoin, method
|
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
/** A store order as a report row, on its paid day (`paidAt`); an order with no `paidAt` (unpaid, or a store that records none) stays on its placed day. */
|
|
53
56
|
export function reportOrderFromStoreOrder(order: StoreOrder, join?: LineJoin): ReportOrder {
|
|
54
57
|
return {
|
|
55
|
-
id: order.id, at: order.placedAt, totalMinor: order.totalMinor, taxMinor: order.taxMinor, discountMinor: order.discountMinor,
|
|
58
|
+
id: order.id, at: order.paidAt ?? order.placedAt, totalMinor: order.totalMinor, taxMinor: order.taxMinor, discountMinor: order.discountMinor,
|
|
56
59
|
lines: order.lines.map((line) => ({
|
|
57
60
|
key: line.variantId || line.productId || line.name, name: line.name, quantity: line.quantity,
|
|
58
61
|
netMinor: line.totalMinor, taxMinor: line.taxMinor, ...joinedLine(line, join),
|
|
@@ -62,6 +65,7 @@ export function reportOrderFromStoreOrder(order: StoreOrder, join?: LineJoin): R
|
|
|
62
65
|
ratePpm, ...(code !== undefined ? { code } : {}), label, taxMinor: amountMinor, netMinor: null,
|
|
63
66
|
})),
|
|
64
67
|
refunds: order.refunds.map(({ id, amountMinor }) => ({ id, amountMinor })),
|
|
68
|
+
...(order.needsPayment !== undefined ? { needsPayment: order.needsPayment } : {}),
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
|
package/src/reports/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { salesFigures, marginOf, comparisonRange, daysOf, inRange } from './sales-figures';
|
|
1
|
+
export { salesFigures, marginOf, medianMinor, comparisonRange, daysOf, inRange } from './sales-figures';
|
|
2
2
|
export { presetRange, DATE_PRESETS, type DatePreset } from './presets';
|
|
3
3
|
export { reportOrderFromPosOrder, reportOrderFromStoreOrder, reportRefundFromPosRefund } from './adapters';
|
|
4
4
|
export type { StoreDay, DayRange, ReportCategory, ReportLine, ReportPayment, ReportTax, ReportOrder, ReportRefund, LineJoin } from './types';
|
|
@@ -15,12 +15,25 @@ export interface Margin {
|
|
|
15
15
|
export interface SalesTotals {
|
|
16
16
|
grossMinor: number; netMinor: number; taxMinor: number; discountMinor: number;
|
|
17
17
|
refundsMinor: number; embeddedRefundsMinor: number;
|
|
18
|
+
/**
|
|
19
|
+
* Σ cash roundings in gross; gross = net + tax + rounding (front desk, 22 Nov, Q3).
|
|
20
|
+
* Only orders built by `reportOrderFromPosOrder` carry one. A store-sourced order (`reportOrderFromStoreOrder`) carries no rounding figure:
|
|
21
|
+
* Woo stores its rounding as a plain fee line, so that order's rounding stays inside net (#1282, a documented limit).
|
|
22
|
+
*/
|
|
23
|
+
roundingMinor: number;
|
|
18
24
|
orderCount: number; averageMinor: number; items: number;
|
|
19
25
|
/** v2 ordersSummary: the middle order total, the mean of the two middles for an even count (rounded half up to the minor unit); 0 with no orders. */
|
|
20
26
|
medianMinor?: number;
|
|
21
27
|
/** v2 ordersSummary: the largest order total; null with no orders. */
|
|
22
28
|
largestMinor?: number | null;
|
|
23
29
|
margin: Margin;
|
|
30
|
+
/** Which refund figure `grossAfterRefundsMinor` subtracts: `refundsMinor` or `embeddedRefundsMinor`. A report never subtracts both. */
|
|
31
|
+
refundBasis: 'dated' | 'embedded';
|
|
32
|
+
/**
|
|
33
|
+
* `grossMinor` less the basis figure; negative when refunds exceed gross. Gross refunds come off gross only, never
|
|
34
|
+
* off `netMinor` or any row.
|
|
35
|
+
*/
|
|
36
|
+
grossAfterRefundsMinor: number;
|
|
24
37
|
}
|
|
25
38
|
export interface PaymentRow { method: string; label: string; amountMinor: number; orders: number }
|
|
26
39
|
export interface GroupRow { key: string; name: string; quantity: number; netMinor: number; margin: Margin }
|
|
@@ -28,6 +41,11 @@ export interface TaxRow { key: string; ratePpm: number; code?: string; label: st
|
|
|
28
41
|
export interface DayPoint { day: StoreDay; grossMinor: number; orderCount: number; refundsMinor: number }
|
|
29
42
|
export interface SalesFiguresInput {
|
|
30
43
|
orders: readonly ReportOrder[];
|
|
44
|
+
/**
|
|
45
|
+
* Dated refunds, for every period the report shows. Pass `undefined` (not `[]`) when the store has no dated refunds
|
|
46
|
+
* (no `listRefunds`, or the store does not support it), so the report uses its orders' embedded refunds.
|
|
47
|
+
* `useStoreRefundsInRange().refunds` is already in that shape; pass it only once the read is `complete`.
|
|
48
|
+
*/
|
|
31
49
|
refunds?: readonly ReportRefund[];
|
|
32
50
|
range: DayRange;
|
|
33
51
|
compare?: DayRange;
|
|
@@ -105,13 +123,18 @@ export function marginOf(lines: readonly ReportLine[]): Margin {
|
|
|
105
123
|
return margin;
|
|
106
124
|
}
|
|
107
125
|
|
|
126
|
+
/** The median of minor-unit values: 0 for none; an even count rounds the mean of the middle two (`Math.round`). */
|
|
127
|
+
export function medianMinor(values: readonly number[]): number {
|
|
128
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
129
|
+
const middle = Math.floor(sorted.length / 2);
|
|
130
|
+
if (!sorted.length) return 0;
|
|
131
|
+
return sorted.length % 2 ? sorted[middle] : Math.round((sorted[middle - 1] + sorted[middle]) / 2);
|
|
132
|
+
}
|
|
133
|
+
|
|
108
134
|
/** Median and largest order total. Port of WCPOS v2 `ordersSummary` (`screens/main/reports/cards/aggregate.ts`). */
|
|
109
135
|
function orderSpread(totals: number[]): { medianMinor: number; largestMinor: number | null } {
|
|
110
136
|
const values = [...totals].sort((a, b) => a - b);
|
|
111
|
-
|
|
112
|
-
if (!values.length) return { medianMinor: 0, largestMinor: null };
|
|
113
|
-
const medianMinor = values.length % 2 ? values[middle] : Math.round((values[middle - 1] + values[middle]) / 2);
|
|
114
|
-
return { medianMinor, largestMinor: values[values.length - 1] };
|
|
137
|
+
return { medianMinor: medianMinor(values), largestMinor: values.length ? values[values.length - 1] : null };
|
|
115
138
|
}
|
|
116
139
|
|
|
117
140
|
function periodFigures(input: SalesFiguresInput, range: DayRange) {
|
|
@@ -119,16 +142,18 @@ function periodFigures(input: SalesFiguresInput, range: DayRange) {
|
|
|
119
142
|
const refunds = (input.refunds ?? []).filter((refund) => inRange(refund.at, range, input.timezone));
|
|
120
143
|
const lines = orders.flatMap((order) => order.lines);
|
|
121
144
|
const totals: SalesTotals = {
|
|
122
|
-
grossMinor: 0, netMinor: 0, taxMinor: 0, discountMinor: 0, refundsMinor: 0, embeddedRefundsMinor: 0,
|
|
145
|
+
grossMinor: 0, netMinor: 0, taxMinor: 0, discountMinor: 0, refundsMinor: 0, embeddedRefundsMinor: 0, roundingMinor: 0,
|
|
123
146
|
orderCount: orders.length, averageMinor: 0,
|
|
124
147
|
items: lines.reduce((sum, line) => sum + (Number.isFinite(line.quantity) ? line.quantity : 0), 0),
|
|
125
148
|
margin: marginOf(lines),
|
|
149
|
+
refundBasis: input.refunds !== undefined ? 'dated' : 'embedded', grossAfterRefundsMinor: 0,
|
|
126
150
|
};
|
|
127
151
|
const series: DayPoint[] = daysOf(range).map((day) => ({ day, grossMinor: 0, orderCount: 0, refundsMinor: 0 }));
|
|
128
152
|
const byDay = new Map(series.map((point) => [point.day, point]));
|
|
129
153
|
for (const order of orders) {
|
|
130
154
|
totals.grossMinor += order.totalMinor;
|
|
131
155
|
totals.taxMinor += order.taxMinor;
|
|
156
|
+
totals.roundingMinor += order.roundingMinor ?? 0;
|
|
132
157
|
totals.discountMinor += order.discountMinor;
|
|
133
158
|
totals.embeddedRefundsMinor += order.refunds.reduce((sum, refund) => sum + Math.abs(refund.amountMinor), 0);
|
|
134
159
|
const point = byDay.get(businessDayOf(order.at, input.timezone))!;
|
|
@@ -139,7 +164,9 @@ function periodFigures(input: SalesFiguresInput, range: DayRange) {
|
|
|
139
164
|
totals.refundsMinor += Math.abs(refund.amountMinor);
|
|
140
165
|
byDay.get(businessDayOf(refund.at, input.timezone))!.refundsMinor += Math.abs(refund.amountMinor);
|
|
141
166
|
}
|
|
142
|
-
totals.netMinor = totals.grossMinor - totals.taxMinor;
|
|
167
|
+
totals.netMinor = totals.grossMinor - totals.taxMinor - totals.roundingMinor;
|
|
168
|
+
totals.grossAfterRefundsMinor =
|
|
169
|
+
totals.grossMinor - (totals.refundBasis === 'dated' ? totals.refundsMinor : totals.embeddedRefundsMinor);
|
|
143
170
|
totals.averageMinor = orders.length ? Math.round(totals.grossMinor / orders.length) : 0;
|
|
144
171
|
Object.assign(totals, orderSpread(orders.map((order) => order.totalMinor)));
|
|
145
172
|
return { orders, refunds, totals, series };
|
package/src/reports/types.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface ReportOrder {
|
|
|
48
48
|
taxes: ReportTax[];
|
|
49
49
|
/** Refunds embedded on the order, undated (a store order's own list). Positive. */
|
|
50
50
|
refunds: Array<{ id: string; amountMinor: number }>;
|
|
51
|
+
/** Σ the order's cash roundings, signed (ADR-094); absent when none. Always absent on a store-sourced order: its rounding is a plain fee, kept inside net (#1282). */
|
|
52
|
+
roundingMinor?: number;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/** A refund dated by when it was made, counted on that store day. */
|
|
@@ -56,7 +58,7 @@ export interface ReportRefund {
|
|
|
56
58
|
orderId: string;
|
|
57
59
|
/** ISO 8601 UTC instant the refund was made. */
|
|
58
60
|
at: string;
|
|
59
|
-
/**
|
|
61
|
+
/** Zero or more. Gross, tax included. */
|
|
60
62
|
amountMinor: number;
|
|
61
63
|
}
|
|
62
64
|
|
package/src/sale/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useSale, DISCOUNTS_UNSUPPORTED, SALE_SAVING, PAYMENT_IN_MOTION, SALE_PARTLY_PAID, SALE_IN_TENDER, SALE_HAS_PAYMENT, SALE_FINISHED, COUPONS_REPRICING, COUPON_CARRIED, COUPON_CARRY_STALE, TENDER_GATE_FAILED, TENDER_SALE_CHANGED, saleLogger } from './use-sale';
|
|
1
|
+
export { useSale, DISCOUNTS_UNSUPPORTED, SALE_SAVING, REGISTER_CLOSING, PAYMENT_IN_MOTION, SALE_PARTLY_PAID, SALE_CARD_IN_PROGRESS, SALE_IN_TENDER, SALE_HAS_PAYMENT, SALE_FINISHED, COUPONS_REPRICING, COUPON_CARRIED, COUPON_CARRY_STALE, TENDER_GATE_FAILED, TENDER_SALE_CHANGED, saleLogger } from './use-sale';
|
|
2
2
|
export { openSales, isPartlyPaid } from './open-sales';
|
|
3
3
|
export type { OpenSale } from './open-sales';
|
|
4
4
|
export type { SaleStage } from './use-sale';
|