@tallyui/pos 3.2.0 → 3.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { Money, TaxRounding, TallyConnector, SyncContext, StoreSettingsChoice, StoreSettings, StoreSettingsChoices, ProductTraits, PaymentMethodKind, CommandServerRefs, CommandWarning, CommandError, ServerCapabilities, OrderCreateEnvelope, RegisterCommandType, RegisterCommandResult, VariantSummary, TraitContext, CommandResult, AnyCommandEnvelope, CommandEnvelope, OrderCreatePayload, RegisterCommandEnvelope } from '@tallyui/core';
3
+ import { Money, TaxRounding, StoreSettings, TallyConnector, SyncContext, StoreSettingsChoice, StoreSettingsChoices, ProductTraits, OrderCreateLine, PaymentMethodKind, CommandServerRefs, CommandWarning, CommandError, ServerCapabilities, OrderCreateEnvelope, RegisterCommandType, RegisterCommandResult, VariantSummary, TraitContext, CommandResult, AnyCommandEnvelope, CommandEnvelope, OrderCreatePayload, RegisterCommandEnvelope } from '@tallyui/core';
4
4
  export { getProductStock, withStockOverlay } from '@tallyui/core';
5
5
  export { countFresh, readFresh, watchFresh } from '@tallyui/core/rxdb';
6
6
  import * as rxdb from 'rxdb';
@@ -97,6 +97,7 @@ interface RateTaxLine {
97
97
  }
98
98
  type TaxedLine = {
99
99
  netMinor: number;
100
+ netMicros?: string;
100
101
  discountMinor?: number;
101
102
  taxInclusive: boolean;
102
103
  taxLines: readonly {
@@ -117,12 +118,16 @@ type TaxedLine = {
117
118
  */
118
119
  declare function taxLinesByRate(lines: readonly TaxedLine[], orderTaxMinor: number, taxLabels?: Record<number, string>, rounding?: TaxRounding): RateTaxLine[];
119
120
 
121
+ type WooRate = NonNullable<StoreSettings['taxRates']>[string][number];
120
122
  /** Tax rates as integer parts per million (19% = 190000). */
121
123
  type TaxRateMap = {
122
124
  default: number;
123
125
  [taxClass: string]: number;
124
126
  };
125
127
  interface TaxContext {
128
+ getTaxRates?(taxClass?: string, options?: {
129
+ shipping?: boolean;
130
+ }): readonly WooRate[];
126
131
  /** Tax rate for a tax class as integer parts per million (19% = 190000); the default class when omitted or unknown. */
127
132
  getTaxRatePpm(taxClass?: string): number;
128
133
  /** The backend's name for that class's rate, when mapped: a `per_rate_group_items` store groups by name and value (#287). */
@@ -133,7 +138,8 @@ interface TaxContext {
133
138
  }
134
139
 
135
140
  declare const taxLogger: Logger;
136
- interface TaxProviderProps {
141
+ interface TaxProviderProps extends Pick<StoreSettings, 'taxRoundAtSubtotal' | 'shippingTaxClass' | 'taxClassSlugs'> {
142
+ taxRates?: StoreSettings['taxRates'];
137
143
  ratesPpm: Record<string, number>;
138
144
  pricesIncludeTax: boolean;
139
145
  /** `ServerCapabilities.taxRounding` (#287); a change restarts an idle sale under it. */
@@ -142,7 +148,7 @@ interface TaxProviderProps {
142
148
  rateCodes?: Record<string, string>;
143
149
  children: ReactNode;
144
150
  }
145
- declare function TaxProvider({ ratesPpm, pricesIncludeTax, rounding, rateCodes, children }: TaxProviderProps): react_jsx_runtime.JSX.Element;
151
+ declare function TaxProvider({ ratesPpm, pricesIncludeTax, rounding, rateCodes, taxRates, children }: TaxProviderProps): react_jsx_runtime.JSX.Element;
146
152
  declare function useTax(): TaxContext;
147
153
 
148
154
  type StoreSettingsResolution = {
@@ -245,6 +251,8 @@ interface Order {
245
251
  id: string;
246
252
  status: 'draft' | 'parked' | 'saved' | 'completed';
247
253
  lineItems: LineItem[];
254
+ fees?: FeeLine[];
255
+ shipping?: ShippingLine[];
248
256
  discounts: AppliedDiscount[];
249
257
  payments: Payment[];
250
258
  customer: CustomerSummary | null;
@@ -281,6 +289,16 @@ interface DisplayTotals {
281
289
  taxMinor: number;
282
290
  totalMinor: number;
283
291
  lines: DisplayLine[];
292
+ fees?: Array<{
293
+ id: string;
294
+ name: string;
295
+ amountMinor: number;
296
+ }>;
297
+ shipping?: Array<{
298
+ id: string;
299
+ name: string;
300
+ amountMinor: number;
301
+ }>;
284
302
  orderDiscountMinor: number;
285
303
  }
286
304
  /** One line in the display mode (ADR-063): before any discount, with its own discounts as sub-rows. */
@@ -295,6 +313,12 @@ interface DisplayLine {
295
313
  }
296
314
  interface LineItem {
297
315
  id: string;
316
+ taxClass?: string;
317
+ /** WooCommerce's stored net at rounding precision, in integer micro-minor units, and its rounded gross. */
318
+ netMicros?: string;
319
+ totalMinor?: number;
320
+ custom?: true;
321
+ taxStatus?: 'none';
298
322
  productId: string;
299
323
  variantId?: string;
300
324
  name: string;
@@ -312,8 +336,33 @@ interface LineItem {
312
336
  /** Set only when the price's tax mode differs from the order's; named price mode → order mode. */
313
337
  priceTaxModeConverted?: 'inclusive-to-exclusive' | 'exclusive-to-inclusive';
314
338
  }
339
+ interface ChargeLine {
340
+ id: string;
341
+ netMicros?: string;
342
+ totalMinor?: number;
343
+ name: string;
344
+ amountMinor: number;
345
+ taxClass?: string;
346
+ taxStatus: 'taxable' | 'none';
347
+ taxLines: LineItem['taxLines'];
348
+ netMinor: number;
349
+ taxMicros: string;
350
+ }
351
+ interface FeeLine extends ChargeLine {
352
+ }
353
+ interface ShippingLine extends ChargeLine {
354
+ methodId?: string;
355
+ }
356
+ interface ChargeInput {
357
+ name: string;
358
+ amountMinor: number;
359
+ taxClass?: string;
360
+ taxStatus?: 'taxable' | 'none';
361
+ }
315
362
  interface LineTaxLine {
316
363
  code?: string;
364
+ rateId?: number;
365
+ compound?: boolean;
317
366
  ratePpm: number;
318
367
  taxMicros: string;
319
368
  }
@@ -348,6 +397,8 @@ interface PaymentMethod {
348
397
  }
349
398
  interface AddLineInput {
350
399
  productId: string;
400
+ custom?: true;
401
+ taxStatus?: 'taxable' | 'none';
351
402
  variantId?: string;
352
403
  name: string;
353
404
  sku?: string;
@@ -375,6 +426,16 @@ interface OrderBuilder {
375
426
  quantity?: number;
376
427
  }): string;
377
428
  addLine(input: AddLineInput): string;
429
+ addFee(input: ChargeInput): string;
430
+ updateFee(id: string, patch: Partial<ChargeInput>): void;
431
+ removeFee(id: string): void;
432
+ addShipping(input: ChargeInput & {
433
+ methodId?: string;
434
+ }): string;
435
+ updateShipping(id: string, patch: Partial<ChargeInput & {
436
+ methodId?: string;
437
+ }>): void;
438
+ removeShipping(id: string): void;
378
439
  updateQuantity(lineId: string, quantity: number): void;
379
440
  /** Sets a line's unit price (a till price edit), in minor units of the order's currency and the line's own tax mode; its discounts and tax are recomputed. */
380
441
  setUnitPrice(lineId: string, amountMinor: number): void;
@@ -496,6 +557,14 @@ interface ReceiptData {
496
557
  register?: string;
497
558
  };
498
559
  lineItems: ReceiptLineItem[];
560
+ fees: Array<{
561
+ name: string;
562
+ amountMinor: number;
563
+ }>;
564
+ shipping: Array<{
565
+ name: string;
566
+ amountMinor: number;
567
+ }>;
499
568
  discounts: {
500
569
  label: string;
501
570
  amountMinor: number;
@@ -577,6 +646,8 @@ interface PosOrderLine {
577
646
  id: string;
578
647
  productId: string;
579
648
  variantId?: string;
649
+ custom?: OrderCreateLine['custom'];
650
+ taxStatus?: 'taxable' | 'none';
580
651
  name: string;
581
652
  sku: string;
582
653
  quantity: number;
@@ -584,6 +655,7 @@ interface PosOrderLine {
584
655
  /** Line discounts plus the allocated order-discount share, in the line's own tax mode (ADR-062). */
585
656
  discountMinor: number;
586
657
  netMinor: number;
658
+ netMicros?: string;
587
659
  taxLines: Array<{
588
660
  code?: string;
589
661
  ratePpm: number;
@@ -608,6 +680,8 @@ interface PosOrder {
608
680
  currency: string;
609
681
  pricesIncludeTax: boolean;
610
682
  lines: PosOrderLine[];
683
+ fees?: FeeLine[];
684
+ shipping?: ShippingLine[];
611
685
  subtotalMinor: number;
612
686
  discountMinor: number;
613
687
  taxMinor: number;
@@ -635,9 +709,9 @@ interface PosOrder {
635
709
  * The order.create version every attempt under this `commandId` goes out at: the outbox records it before the first
636
710
  * send, and lowers it only on a downgrade (ADR-065 amendment). Absent means not sent yet (or requeued).
637
711
  */
638
- sentVersion?: 1 | 2 | 3 | 4;
712
+ sentVersion?: 1 | 2 | 3 | 4 | 5;
639
713
  /** The version first tried, before the downgrade (the order's audit). */
640
- downgradedFrom?: 1 | 2 | 3 | 4;
714
+ downgradedFrom?: 1 | 2 | 3 | 4 | 5;
641
715
  /** ADR-065: the receipt's display figures, in integer minor units of `currency` at `exponent`. */
642
716
  display?: DisplayTotals & {
643
717
  currency: string;
@@ -721,6 +795,9 @@ declare function toOrderCreateEnvelope(order: PosOrder, deviceId: string, attemp
721
795
  * nothing else. Its migration sets it on every older row. It is one-way like version 5.
722
796
  * Version 7 adds `saleId`, the sale order's id (ADR-072; never sent), and changes nothing else. Its migration is the
723
797
  * identity: older orders have no `saleId`. It is one-way like version 6.
798
+ * Version 8 adds fees, shipping, custom lines (ADR-075) and the woocommerce tax rounding (ADR-076), and changes nothing else.
799
+ * It also stores the WooCommerce 6dp net (`netMicros`) under the woocommerce rounding (ADR-076 amendment).
800
+ * Its migration is the identity. It is one-way like version 7.
724
801
  */
725
802
  declare const posOrderSchema: RxJsonSchema<PosOrder>;
726
803
  /**
@@ -1886,6 +1963,37 @@ declare function useSale(settings: Pick<StoreSettings, 'currency'>, opts: {
1886
1963
  canContinue: boolean;
1887
1964
  add(entry: CatalogueEntry<any>, traits: ProductTraits<any>): void;
1888
1965
  setQuantity(lineId: string, quantity: number): void;
1966
+ /** ADR-075: adds a fee; returns its id or the builder's refusal. */
1967
+ addFee(input: ChargeInput): {
1968
+ id: string;
1969
+ } | string;
1970
+ /** ADR-075: updates a fee; returns a refusal or null. */
1971
+ updateFee(id: string, patch: Partial<ChargeInput>): string | null;
1972
+ /** ADR-075: removes a fee; returns a refusal or null. */
1973
+ removeFee(id: string): string | null;
1974
+ /** ADR-075: adds shipping; returns its id or the builder's refusal. */
1975
+ addShipping(input: ChargeInput & {
1976
+ methodId?: string;
1977
+ }): {
1978
+ id: string;
1979
+ } | string;
1980
+ /** ADR-075: updates shipping; returns a refusal or null. */
1981
+ updateShipping(id: string, patch: Partial<ChargeInput & {
1982
+ methodId?: string;
1983
+ }>): string | null;
1984
+ /** ADR-075: removes shipping; returns a refusal or null. */
1985
+ removeShipping(id: string): string | null;
1986
+ /** ADR-075: adds a distinct custom product line; returns its id or the builder's refusal. */
1987
+ addCustomLine(input: {
1988
+ name: string;
1989
+ priceMinor: number;
1990
+ quantity?: number;
1991
+ taxClass?: string;
1992
+ taxStatus?: "taxable" | "none";
1993
+ sku?: string;
1994
+ }): {
1995
+ id: string;
1996
+ } | string;
1889
1997
  /** Sets a line's unit price in minor units of its own tax mode, recomputing discounts and tax; returns a refusal or null. */
1890
1998
  setUnitPrice(lineId: string, amountMinor: number): string | null;
1891
1999
  remove(lineId: string): void;
@@ -1967,6 +2075,13 @@ declare class CartError extends Error {
1967
2075
  }
1968
2076
  declare function addEntryToCart<Doc>(builder: OrderBuilder, entry: CatalogueEntry<Doc>, traits: ProductTraits<Doc>, currency: string): string;
1969
2077
 
2078
+ /** Local-only context for a transport (ADR-076 amendment 1): never serialised, never part of a payload. */
2079
+ interface OrderTransportContext {
2080
+ /** The stored (frozen) order of each envelope in the batch, keyed by the envelope's `id` (its commandId). */
2081
+ local: {
2082
+ orders: ReadonlyMap<string, PosOrder>;
2083
+ };
2084
+ }
1970
2085
  type TransportOutcome = {
1971
2086
  kind: 'results';
1972
2087
  results: CommandResult[];
@@ -1985,7 +2100,7 @@ type TransportOutcome = {
1985
2100
  retryAfterMs?: number;
1986
2101
  };
1987
2102
  interface CommandTransport<E extends AnyCommandEnvelope = CommandEnvelope<OrderCreatePayload>> {
1988
- send(batch: E[]): Promise<TransportOutcome>;
2103
+ send(batch: E[], context?: OrderTransportContext): Promise<TransportOutcome>;
1989
2104
  }
1990
2105
  interface OutboxState {
1991
2106
  pending: number;
@@ -2329,4 +2444,4 @@ declare function planLegs(plan: TenderPlan, rowsSinceFrom: {
2329
2444
  };
2330
2445
  };
2331
2446
 
2332
- export { type Actor, type AddLineInput, type AppliedDiscount, type BackendNotFound, type BasketLine, CartError, type CashMovement, type CashMovementCollection, type CatalogueEntry, type Closure, type ClosureCollection, type ClosureContext, type ClosureScope, type CommandTransport, type Correction, CurrencyProvider, type CurrencyProviderProps, type CustomerSummary, DISCOUNTS_UNSUPPORTED, type Discount, type DisplayLine, type DisplayTotals, type FinalizeOptions, type HttpTransportOptions, type LedgerRow, type LineItem, type LineTaxLine, type LogEntry, type LogLevel, type LogSink, type Logger, MAX_TENDER_MINOR, MICROS_PER_MINOR, type Movement$1 as Movement, type MovementType, type Order, type OrderBuilder, type OrderBuilderOptions, OrderContentMismatchError, type OrderManager, type OrderManagerOptions, type OrderOutbox, type OrderOutboxOptions, type OrderTaxTotals, type OutboxState, type ParkedOrderSummary, type Payment, type PaymentMethod, type PaymentTransport, type PlanLeg, type PosOrder, type PosOrderLine, type PosOrderLocalWarning, PosOrderOpenClosedError, type PosOrderPayment, type PosOrderServerFailures, type PosOrderSyncStatus, type RateTaxLine, type ReceiptConfig, type ReceiptData, type ReceiptLineItem, type RecordedFigures, RegisterApprovalRequiredError, type RegisterBucket, RegisterCloseIncompleteError, type RegisterCommand, type RegisterCommandCollection, type RegisterCounters, type RegisterDocument, type RegisterFact, type RegisterHost, RegisterIdInvalidError, RegisterMovementAmountError, RegisterMovementReasonError, RegisterMovementStrandedError, type RegisterOutbox, type RegisterOutboxOptions, type RegisterSession, RegisterSessionAlreadyOpenError, RegisterSessionClosedError, type RegisterSessionCollection, RegisterSessionRequiredError, type RegisterStore, RegisterTenderInProgressError, type Repository, type ResolveStoreSettingsOptions, SALE_SAVING, type SaleStage, type SentOrder, type SplitTab, type StoreSettingsResolution, type StoreSettingsState, TAX_ROUNDING_MIXED_NOTE, type TaxContext, type TaxLineInput, TaxProvider, type TaxProviderProps, type TaxRateMap, type TenderAction, type TenderKey, type TenderLineId, type TenderPlan, type TenderState, type TenderView, type TransportOutcome, UnsupportedOrderVersionError, type UseOrderOutboxOptions, type UseOrderOutboxResult, type UseRegisterOutboxOptions, type UseRegisterOutboxResult, type UseRegisterSessionOptions, activePlan, addEntryToCart, addPosOrderCollection, advancePerpetual, allocateOrderDiscount, appliedMinor, backToSelling, bindRegister, buildClosureDocument, buildReceiptData, buildXReportDocument, callbackSink, cashMovementSchema, catalogueEntries, changeMinor, clampClosureScope, closeNeedsApproval, closeSession, closureCommand, closureSchema, computeOrderTax, consoleSink, countVariance, createBackendNotFound, createHttpCommandTransport, createLogger, createOrderBuilder, createOrderManager, createOrderOutbox, createRegisterOutbox, createRepository, denominationTotal, denominations, deriveExpected, deriveSettled, ensureRegister, evenSplitShareMinor, exportCsv, finalizeOrder, findEntryByCode, formatClosureDate, getBoundRegisterId, getDeviceId, initTenderState, initialTenderState, isServerDecimal, labelKeys, minorToDecimal, mintClosureNumber, mintUuid, movementCommand, movementFieldError, needsAttention, nextSaleCounter, normalizeAmount, observeRegister$, openSession, openSessionSelector, orderDraftSchema, outboxLogger, overThreshold, parkedOrderSummaries$, parseMinor, planLegs, posOrderCollection, posOrderSchema, posOrdersLogger, quickTenderedAmounts, ratePpmFromPercent, readBoundRegister, readRegister, reconcileRegisterCommands, recordMovement, recordRegisterFact, registerCommandCollection, registerCommandSchema, registerCommandsLogger, registerFactsLogger, registerSessionCollection, registerSessionSchema, requireOpenSession, resolveStoreSettings, restoreOrderDraft, roundMicrosToMinor, saleLogger, sameSale, searchProducts, selectClosureRows, sessionOpenCommand, sessionTransitionCommand, stampSession, startCounting, stockOverlay$, stockOverlayAsOf$, taxFiguresForBasket, taxLinesByRate, taxLogger, taxMicros, taxProviderProps, tenderReducer, toOrderCreateEnvelope, unbindRegister, useCurrencyCode, useCurrencyFormatter, useOrderOutbox, useParkedSales, useRegisterOutbox, useRegisterSession, useSale, useStoreSettings, useTax, uuidv7, validAmount, varianceText, variantPriceLabel, voidMovement, withPricingContext, writeClosure, writeOrderDraft };
2447
+ export { type Actor, type AddLineInput, type AppliedDiscount, type BackendNotFound, type BasketLine, CartError, type CashMovement, type CashMovementCollection, type CatalogueEntry, type ChargeInput, type ChargeLine, type Closure, type ClosureCollection, type ClosureContext, type ClosureScope, type CommandTransport, type Correction, CurrencyProvider, type CurrencyProviderProps, type CustomerSummary, DISCOUNTS_UNSUPPORTED, type Discount, type DisplayLine, type DisplayTotals, type FeeLine, type FinalizeOptions, type HttpTransportOptions, type LedgerRow, type LineItem, type LineTaxLine, type LogEntry, type LogLevel, type LogSink, type Logger, MAX_TENDER_MINOR, MICROS_PER_MINOR, type Movement$1 as Movement, type MovementType, type Order, type OrderBuilder, type OrderBuilderOptions, OrderContentMismatchError, type OrderManager, type OrderManagerOptions, type OrderOutbox, type OrderOutboxOptions, type OrderTaxTotals, type OrderTransportContext, type OutboxState, type ParkedOrderSummary, type Payment, type PaymentMethod, type PaymentTransport, type PlanLeg, type PosOrder, type PosOrderLine, type PosOrderLocalWarning, PosOrderOpenClosedError, type PosOrderPayment, type PosOrderServerFailures, type PosOrderSyncStatus, type RateTaxLine, type ReceiptConfig, type ReceiptData, type ReceiptLineItem, type RecordedFigures, RegisterApprovalRequiredError, type RegisterBucket, RegisterCloseIncompleteError, type RegisterCommand, type RegisterCommandCollection, type RegisterCounters, type RegisterDocument, type RegisterFact, type RegisterHost, RegisterIdInvalidError, RegisterMovementAmountError, RegisterMovementReasonError, RegisterMovementStrandedError, type RegisterOutbox, type RegisterOutboxOptions, type RegisterSession, RegisterSessionAlreadyOpenError, RegisterSessionClosedError, type RegisterSessionCollection, RegisterSessionRequiredError, type RegisterStore, RegisterTenderInProgressError, type Repository, type ResolveStoreSettingsOptions, SALE_SAVING, type SaleStage, type SentOrder, type ShippingLine, type SplitTab, type StoreSettingsResolution, type StoreSettingsState, TAX_ROUNDING_MIXED_NOTE, type TaxContext, type TaxLineInput, TaxProvider, type TaxProviderProps, type TaxRateMap, type TenderAction, type TenderKey, type TenderLineId, type TenderPlan, type TenderState, type TenderView, type TransportOutcome, UnsupportedOrderVersionError, type UseOrderOutboxOptions, type UseOrderOutboxResult, type UseRegisterOutboxOptions, type UseRegisterOutboxResult, type UseRegisterSessionOptions, activePlan, addEntryToCart, addPosOrderCollection, advancePerpetual, allocateOrderDiscount, appliedMinor, backToSelling, bindRegister, buildClosureDocument, buildReceiptData, buildXReportDocument, callbackSink, cashMovementSchema, catalogueEntries, changeMinor, clampClosureScope, closeNeedsApproval, closeSession, closureCommand, closureSchema, computeOrderTax, consoleSink, countVariance, createBackendNotFound, createHttpCommandTransport, createLogger, createOrderBuilder, createOrderManager, createOrderOutbox, createRegisterOutbox, createRepository, denominationTotal, denominations, deriveExpected, deriveSettled, ensureRegister, evenSplitShareMinor, exportCsv, finalizeOrder, findEntryByCode, formatClosureDate, getBoundRegisterId, getDeviceId, initTenderState, initialTenderState, isServerDecimal, labelKeys, minorToDecimal, mintClosureNumber, mintUuid, movementCommand, movementFieldError, needsAttention, nextSaleCounter, normalizeAmount, observeRegister$, openSession, openSessionSelector, orderDraftSchema, outboxLogger, overThreshold, parkedOrderSummaries$, parseMinor, planLegs, posOrderCollection, posOrderSchema, posOrdersLogger, quickTenderedAmounts, ratePpmFromPercent, readBoundRegister, readRegister, reconcileRegisterCommands, recordMovement, recordRegisterFact, registerCommandCollection, registerCommandSchema, registerCommandsLogger, registerFactsLogger, registerSessionCollection, registerSessionSchema, requireOpenSession, resolveStoreSettings, restoreOrderDraft, roundMicrosToMinor, saleLogger, sameSale, searchProducts, selectClosureRows, sessionOpenCommand, sessionTransitionCommand, stampSession, startCounting, stockOverlay$, stockOverlayAsOf$, taxFiguresForBasket, taxLinesByRate, taxLogger, taxMicros, taxProviderProps, tenderReducer, toOrderCreateEnvelope, unbindRegister, useCurrencyCode, useCurrencyFormatter, useOrderOutbox, useParkedSales, useRegisterOutbox, useRegisterSession, useSale, useStoreSettings, useTax, uuidv7, validAmount, varianceText, variantPriceLabel, voidMovement, withPricingContext, writeClosure, writeOrderDraft };