@tallyui/pos 5.0.0 → 5.2.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.
@@ -36,17 +36,25 @@ export function roundedRemainder(balanceMinor: number, entriesMinor: number, rou
36
36
  return unrounded <= 0 ? 0 : roundToIncrement(unrounded, rounding.incrementMinor, rounding.mode);
37
37
  }
38
38
 
39
- /** ADR-094 (cash picks): a cash part pick rounds its own target; 0 means cash cannot pay it. */
40
- export function roundedPickTarget(targetMinor: number, rounding: PaymentRounding | null | undefined): number {
41
- return rounding ? roundToIncrement(targetMinor, rounding.incrementMinor, rounding.mode) : targetMinor;
39
+ /** ADR-094 item 7 (carry): a cash part pick rounds its target less `entriesMinor`, the live entries the pick carries against; it defaults to 0, the 5.0.0 per-pick rounding. 0 means cash cannot pay it. */
40
+ export function roundedPickTarget(targetMinor: number, rounding: PaymentRounding | null | undefined, entriesMinor = 0): number {
41
+ if (!rounding) return targetMinor;
42
+ const unrounded = targetMinor - entriesMinor;
43
+ return unrounded <= 0 ? 0 : roundToIncrement(unrounded, rounding.incrementMinor, rounding.mode);
44
+ }
45
+
46
+ /** ADR-094 items 1 and 6: the live entries a remainder rounds against, every entry on the sale (cash-pick entries included since the carry rule). */
47
+ export function remainderEntriesMinor(order: { payments: readonly { id: string; method?: string; units?: Readonly<Record<string, number>> }[]; cashRoundings?: readonly { paymentId: string; minor: number }[] }): number {
48
+ return (order.cashRoundings ?? []).reduce((sum, entry) => sum + entry.minor, 0);
42
49
  }
43
50
 
44
- /** ADR-094: the live entries a remainder rounds against, leaving out a pick leg's own entry (its leg carries units). */
45
- export function remainderEntriesMinor(order: { payments: readonly { id: string; units?: Readonly<Record<string, number>> }[]; cashRoundings?: readonly { paymentId: string; minor: number }[] }): number {
46
- return (order.cashRoundings ?? []).reduce((sum, entry) => {
47
- const units = order.payments.find((leg) => leg.id === entry.paymentId)?.units;
48
- return !units || Object.keys(units).length === 0 ? sum + entry.minor : sum;
49
- }, 0);
51
+ /**
52
+ * ADR-094 item 1 (#1365, amended by the carry rule 2026-11-26): the zero-remainder write-off's leg, the last counting leg with
53
+ * wire method 'cash', else the last counting leg. A later cash leg rounds against a non-cash leg's write-off; `cashVoidRefusal` keeps the entries a stack.
54
+ */
55
+ export function writeOffLeg<L extends { id: string; method?: string; status?: PaymentLegStatus; units?: Readonly<Record<string, number>> }>(order: { payments: readonly L[] }): L | undefined {
56
+ const counted = order.payments.filter(countsTowardPaid);
57
+ return counted.filter((leg) => leg.method === 'cash').at(-1) ?? counted.at(-1);
50
58
  }
51
59
 
52
60
  /** Why a void is refused by ADR-094 item 6 (desk ruling (i), #1292): a later live cash leg's entry was computed against this leg's. */
@@ -7,7 +7,7 @@ export { tenderFigures, runsWholeOrder } from './tender-figures';
7
7
  export type { TenderFacts, TenderFigures } from './tender-figures';
8
8
  export { tenderVoidSchema, tenderVoidCollection } from './tender-void';
9
9
  export type { TenderVoid } from './tender-void';
10
- export { cashVoidRefusal, type CashVoidRefusal, nearestPayableCash, roundedPickTarget, remainderEntriesMinor, roundedDue, tenderRounding } from './cash-rounding';
10
+ export { cashVoidRefusal, type CashVoidRefusal, nearestPayableCash, roundedPickTarget, remainderEntriesMinor, writeOffLeg, roundedDue, tenderRounding } from './cash-rounding';
11
11
  export type { TenderRounding } from './cash-rounding';
12
12
  export { legStatus, countsTowardPaid, isInMotion, capturedMinor, inMotionMinor, canMoveLeg, canVoidLeg } from './payment-legs';
13
13
  export type { PaymentLegStatus } from './payment-legs';