@tallyui/pos 5.1.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.
@@ -12,10 +12,10 @@
12
12
  */
13
13
  import type { RxCollection } from 'rxdb';
14
14
  import { DEFAULT_TAX_ROUNDING, taxLinesByRate } from '../tax/exact';
15
- import { taxedLinesFor } from '../tax/taxed-lines';
15
+ import { storedCharges, taxedLinesFor } from '../tax/taxed-lines';
16
16
  import type { PosOrder } from '../pos-order/types';
17
17
  import { replacedOrderIds } from '../pos-order/reopened';
18
- import { tillPayments } from '../pos-order/till-payments';
18
+ import { countedTillPayments, settledAwayOnStore, tillPayments } from '../pos-order/till-payments';
19
19
  import type { PosRefund } from '../refund/pos-refund';
20
20
  import { readFresh } from '../rxdb';
21
21
  import { parkedCashRoundings, parkedTakenLegs } from '../order/order-drafts';
@@ -573,12 +573,13 @@ export async function writeClosure({
573
573
  const taxRateKey = (code: string | undefined, ratePpm: number) => `${ratePpm}:${(code ?? '').replace(/[%.[\]\\]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`)}`;
574
574
  const taxRates = new Map<string, { ratePpm: number; code?: string; net_minor: number; tax_minor: number }>();
575
575
  const roundings = new Set<string>();
576
- for (const order of bound) {
576
+ const transactions = bound.filter((order) => !settledAwayOnStore(order));
577
+ for (const order of transactions) {
577
578
  // Grouped by the rule applied: a `custom` sale used the default figures, so it joins the default's group.
578
579
  const recorded = order.taxRounding ?? DEFAULT_TAX_ROUNDING;
579
580
  const rounding = recorded.granularity === 'custom' ? DEFAULT_TAX_ROUNDING : recorded;
580
581
  roundings.add(rounding.granularity === 'woocommerce' ? `woocommerce ${rounding.roundAtSubtotal}` : `${rounding.granularity} ${rounding.mode}`);
581
- const taxedLines = taxedLinesFor(order.lines, [...(order.fees ?? []), ...(order.shipping ?? [])], order.pricesIncludeTax, order.taxRounding);
582
+ const taxedLines = taxedLinesFor(order.lines, storedCharges([...(order.fees ?? []), ...(order.shipping ?? [])]), order.pricesIncludeTax, order.taxRounding);
582
583
  for (const { ratePpm, code, netMinor, amountMinor } of taxLinesByRate(taxedLines, order.taxMinor, undefined, order.taxRounding)) {
583
584
  const existing = taxRates.get(taxRateKey(code, ratePpm));
584
585
  taxRates.set(taxRateKey(code, ratePpm), {
@@ -592,7 +593,7 @@ export async function writeClosure({
592
593
  // ADR-094: a bound order's rounding counts as its leg's money does (S3): a till leg, in the session that took it.
593
594
  // A parked or live sale's entries count by the same rule, against that sale's own taken legs (#1281).
594
595
  const cashRoundingMinor = sum(bound.flatMap((order) => {
595
- const legs = new Map(tillPayments(order.payments).map((payment) => [payment.id, payment]));
596
+ const legs = new Map(countedTillPayments(order).map((payment) => [payment.id, payment]));
596
597
  return (order.cashRoundings ?? []).filter((entry) => {
597
598
  const leg = legs.get(entry.paymentId);
598
599
  return leg !== undefined && (leg.sessionId ?? order.sessionId) === session.id;
@@ -654,7 +655,7 @@ export async function writeClosure({
654
655
  movements: entries.map(({ id, type, amountMinor, reason, voids, voided_by, created_at_gmt, created_by }) => ({
655
656
  id, type, amountMinor, reason, voids: voids ?? null, created_at_gmt, created_by: created_by ?? null, voided_by: voided_by ?? null,
656
657
  })),
657
- transaction_count: bound.length,
658
+ transaction_count: transactions.length,
658
659
  refund_count: countedRefunds.length,
659
660
  ...(refunds !== undefined ? {
660
661
  refund_ids: countedRefunds.map((refund) => refund.id),
@@ -3,7 +3,7 @@ import { tillPayments } from '../pos-order/till-payments';
3
3
  import type { PosOrder } from '../pos-order/types';
4
4
  import type { PosRefund } from '../refund/pos-refund';
5
5
  import { roundMicrosToMinor, taxLinesByRate } from '../tax/exact';
6
- import { recordedTaxByRate, taxedLinesFor } from '../tax/taxed-lines';
6
+ import { recordedTaxByRate, storedCharges, taxedLinesFor } from '../tax/taxed-lines';
7
7
  import type { LineJoin, ReportLine, ReportOrder, ReportRefund } from './types';
8
8
 
9
9
  function joinedLine(line: { productId?: string; variantId?: string; quantity: number }, join?: LineJoin): Pick<ReportLine, 'costMinor' | 'category'> {
@@ -19,7 +19,7 @@ function joinedLine(line: { productId?: string; variantId?: string; quantity: nu
19
19
  }
20
20
 
21
21
  export function reportOrderFromPosOrder(order: PosOrder, join?: LineJoin, methodTitle?: (methodId: string) => string | undefined): ReportOrder {
22
- const taxedLines = taxedLinesFor(order.lines, [...(order.fees ?? []), ...(order.shipping ?? [])], order.pricesIncludeTax, order.taxRounding);
22
+ const taxedLines = taxedLinesFor(order.lines, storedCharges([...(order.fees ?? []), ...(order.shipping ?? [])]), order.pricesIncludeTax, order.taxRounding);
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);
@@ -1,5 +1,13 @@
1
1
  import type { TaxRounding } from '@tallyui/core';
2
2
 
3
+ /** Undoes `finalize.ts`'s `storedCharge` for taxation: restores the entered mode and, for a generic charge, the entered net. */
4
+ export function storedCharges<C extends { entered?: { amountMinor: number; amountIncludesTax: boolean }; totalMinor?: number; netMinor?: number }>(
5
+ charges: readonly C[],
6
+ ): Array<C & { amountIncludesTax?: boolean }> {
7
+ return charges.map((charge) => charge.entered === undefined ? charge : { ...charge, amountIncludesTax: charge.entered.amountIncludesTax,
8
+ ...(charge.totalMinor === undefined ? { netMinor: charge.entered.amountMinor } : {}) });
9
+ }
10
+
3
11
  /** The lines and charges `taxLinesByRate` splits, each in the tax mode its tax was rounded in (ADR-065: the
4
12
  * receipt's figures, which every per-rate split must equal). Under `woocommerce` rounding a line with `netMicros`
5
13
  * is in the store's mode, since WooCommerce rounds every line that way. Otherwise a line keeps its own mode, and