@tallyui/components 3.10.0 → 3.12.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
@@ -8,7 +8,7 @@ import { VariantProps } from 'class-variance-authority';
8
8
  import { SvgProps } from 'react-native-svg';
9
9
  import { Separator as Separator$1, Label as Label$1, Tabs as Tabs$1, Dialog as Dialog$1, AlertDialog as AlertDialog$1, Select as Select$1, Combobox as Combobox$1, DropdownMenu as DropdownMenu$1, ContextMenu as ContextMenu$1, Popover as Popover$1, Tooltip as Tooltip$1, HoverCard as HoverCard$1, Accordion as Accordion$1, Collapsible as Collapsible$1, Checkbox as Checkbox$1, Switch as Switch$1, RadioGroup as RadioGroup$1, Toggle as Toggle$1, ToggleGroup as ToggleGroup$1, Progress as Progress$1, Slider as Slider$1, Image } from '@tallyui/primitives';
10
10
  export { TextClassContext } from '@tallyui/primitives';
11
- import { CatalogueView, ProductSortValue, ProductSort, useRegisterSession, RegisterSession, MovementType, useSale, AppliedDiscount, Discount, CatalogueEntry, CatalogueViewState, SentOrder, PosOrder, OutboxState, ParkedOrderSummary } from '@tallyui/pos';
11
+ import { CatalogueView, ProductSortValue, ProductSort, useRegisterSession, RegisterSession, MovementType, useSale, AppliedDiscount, Discount, CatalogueEntry, CatalogueViewState, SentOrder, PosOrder, ReceiptData, OutboxState, ParkedOrderSummary } from '@tallyui/pos';
12
12
  import { ProductTraits, TraitContext, Money, CustomerTraits, Customer, CustomerInput, ProductCategory, SyncNotice, StoreSettingsChoices, StoreSettingsChoice } from '@tallyui/core';
13
13
 
14
14
  declare const textVariants: (props?: ({
@@ -589,6 +589,8 @@ declare function ProductVariantPicker({ options, selected, onSelect, className,
589
589
 
590
590
  interface CartLineProps extends Omit<HStackProps, 'children'> {
591
591
  name: string;
592
+ /** The variant's chosen options, one "Name: Value" row each under the name. */
593
+ attributes?: Record<string, string>;
592
594
  quantity: number;
593
595
  unitPrice: Money;
594
596
  lineTotal: Money;
@@ -602,7 +604,7 @@ interface CartLineProps extends Omit<HStackProps, 'children'> {
602
604
  * <CartLine name="Coffee" quantity={2} unitPrice={unitPrice} lineTotal={lineTotal} />
603
605
  * ```
604
606
  */
605
- declare function CartLine({ name, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps): react_jsx_runtime.JSX.Element;
607
+ declare function CartLine({ name, attributes, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps): react_jsx_runtime.JSX.Element;
606
608
 
607
609
  interface CartTotalProps extends Omit<VStackProps, 'children'> {
608
610
  subtotal: Money;
@@ -616,6 +618,8 @@ interface CartTotalProps extends Omit<VStackProps, 'children'> {
616
618
  taxInclusive?: boolean;
617
619
  locale?: string;
618
620
  className?: string;
621
+ /** Rows rendered directly under Subtotal, e.g. a platform's coupon chips. */
622
+ afterSubtotal?: ReactNode;
619
623
  }
620
624
  /**
621
625
  * Displays a cart summary: subtotal, optional discount, optional tax, and total, in the receipt's order.
@@ -624,7 +628,7 @@ interface CartTotalProps extends Omit<VStackProps, 'children'> {
624
628
  * <CartTotal subtotal={subtotal} discount={discount} taxLines={taxLines} total={total} />
625
629
  * ```
626
630
  */
627
- declare function CartTotal({ subtotal, taxLines, discount, total, taxInclusive, locale, className, ...props }: CartTotalProps): react_jsx_runtime.JSX.Element;
631
+ declare function CartTotal({ subtotal, taxLines, discount, total, taxInclusive, locale, className, afterSubtotal, ...props }: CartTotalProps): react_jsx_runtime.JSX.Element;
628
632
 
629
633
  interface CartPanelProps<T> extends Omit<VStackProps, 'children'> {
630
634
  /** Cart line items to render */
@@ -1271,7 +1275,7 @@ interface ConnectorStatusProps extends Omit<ViewProps, 'children'> {
1271
1275
  declare function ConnectorStatus({ name, status, lastSync, error, className, unsoldCount, unsoldStale, formatUnsold, ...viewProps }: ConnectorStatusProps): react_jsx_runtime.JSX.Element;
1272
1276
 
1273
1277
  /** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
1274
- declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses }: {
1278
+ declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }: {
1275
1279
  sale: ReturnType<typeof useSale>;
1276
1280
  taxLabel?: (ratePpm: number) => string;
1277
1281
  taxClasses?: ReadonlyArray<{
@@ -1287,6 +1291,12 @@ declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses
1287
1291
  toMinor: number;
1288
1292
  reason?: string;
1289
1293
  }) => void;
1294
+ /** Rows under the totals' Subtotal, e.g. the platform's coupon chips (passed to CartTotal). */
1295
+ afterSubtotal?: ReactNode;
1296
+ /** The coupon amount the app itemises in `afterSubtotal` (e.g. Σ `order.display.coupons`), in integer minor units of
1297
+ * the order's currency, in the display mode. When given, the Discount row shows the other discounts only (the
1298
+ * totals' discount minus this) and is hidden when they come to 0. Absent: the Discount row is the whole discount. */
1299
+ couponDiscountMinor?: number;
1290
1300
  }): react_jsx_runtime.JSX.Element;
1291
1301
 
1292
1302
  /** Phone mode's cart summary (medusapos ADR 0009): the whole bar is one button; the total is the cart's own Total row. */
@@ -1363,7 +1373,7 @@ interface ChargeFormProps {
1363
1373
  declare function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, onApply, onClose }: ChargeFormProps): react_jsx_runtime.JSX.Element;
1364
1374
 
1365
1375
  declare function formatStockSyncTime(time: Date, locale?: string, hour12?: boolean, now?: Date): string;
1366
- declare function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength, viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle, items, onQueryChange, showCategoryNav, categories }: {
1376
+ declare function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength, viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle, items, onQueryChange, showCategoryNav, categories, pickAnyOptions }: {
1367
1377
  products: Doc[];
1368
1378
  traits: ProductTraits<Doc>;
1369
1379
  currency: string;
@@ -1411,11 +1421,20 @@ declare function Catalogue<Doc>({ products, traits, currency, onSelect, statusTe
1411
1421
  items?: Doc[];
1412
1422
  /** Search text on every input change, for apps that filter items themselves. */
1413
1423
  onQueryChange?: (query: string) => void;
1424
+ /** Ask for a value for each of a variant's local "Any" option groups before onSelect (#495); set it only when the store accepts order.create version 6. */
1425
+ pickAnyOptions?: boolean;
1414
1426
  }): react_jsx_runtime.JSX.Element;
1415
1427
 
1416
- /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
1417
- * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
1418
- declare function Receipt({ order, posOrder, store, cashier, registerId, registerName, newSale, taxLabel, topInset, formatDate, footerSlot }: {
1428
+ type ReceiptProps = {
1429
+ newSale: () => void;
1430
+ taxLabel?: (ratePpm: number) => string;
1431
+ topInset?: number;
1432
+ formatDate?: (iso: string) => string;
1433
+ /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
1434
+ footerSlot?: ReactNode;
1435
+ /** The second button's text; default `New sale`. */
1436
+ doneLabel?: string;
1437
+ } & ({
1419
1438
  order: SentOrder;
1420
1439
  store: {
1421
1440
  name: string;
@@ -1423,18 +1442,26 @@ declare function Receipt({ order, posOrder, store, cashier, registerId, register
1423
1442
  };
1424
1443
  cashier: string;
1425
1444
  registerId: string;
1426
- newSale: () => void;
1427
1445
  /** The register's name, printed as `Register: <name>`; the id is never printed. */
1428
1446
  registerName?: string;
1429
1447
  /** The finalized order (useSale's receipt stage has it). With it the receipt prints its reference and time, the
1430
1448
  * same as Orders; without it (a preview before finalize) the sale id is marked as a draft. */
1431
1449
  posOrder?: PosOrder;
1432
- taxLabel?: (ratePpm: number) => string;
1433
- topInset?: number;
1434
- formatDate?: (iso: string) => string;
1435
- /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
1436
- footerSlot?: ReactNode;
1437
- }): react_jsx_runtime.JSX.Element;
1450
+ receipt?: never;
1451
+ } | {
1452
+ /** A prebuilt receipt, e.g. a reprint from `buildReceiptDataFromPosOrder`/`buildReceiptDataFromStoreOrder` (ADR-081). */
1453
+ receipt: ReceiptData;
1454
+ /** With it the receipt prints its reference, the same as Orders; without it, the receipt's own order number. */
1455
+ posOrder?: PosOrder;
1456
+ order?: never;
1457
+ store?: never;
1458
+ cashier?: never;
1459
+ registerId?: never;
1460
+ registerName?: never;
1461
+ });
1462
+ /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
1463
+ * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
1464
+ declare function Receipt(props: ReceiptProps): react_jsx_runtime.JSX.Element;
1438
1465
 
1439
1466
  /** The order reference a visitor sees on the receipt and in Orders (front desk ruling, 2026-10-06): the finalized
1440
1467
  * PosOrder id's last 8 characters, then the backend's display id once the store has one. */
@@ -1473,14 +1500,16 @@ type OrderHistoryRow = {
1473
1500
  * `onRetry` is the outbox's `requeue`; `formatDate` replaces the app's date util; `footer` is the app's own content
1474
1501
  * (medusapos: the feedback link). The router and session redirect stay in the app. `stuck` is the outbox's
1475
1502
  * `state.stuck` (`useOrderOutbox`): those pending orders need attention too, each with its own entry's reason and since.
1503
+ * `onOpen` adds an Open button to each row that passes its order to the app.
1476
1504
  * `history` adds read-only store order rows to Recent (ADR-052 amendment 1). */
1477
- declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history }: {
1505
+ declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history, onOpen }: {
1478
1506
  orders: PosOrder[];
1479
1507
  onRetry(orderIds: string[]): Promise<number>;
1480
1508
  formatDate?: (iso: string) => string;
1481
1509
  footer?: ReactNode;
1482
1510
  stuck?: OutboxState['stuck'];
1483
1511
  history?: OrderHistoryRow[];
1512
+ onOpen?: (row: PosOrder | OrderHistoryRow) => void;
1484
1513
  }): react_jsx_runtime.JSX.Element;
1485
1514
 
1486
1515
  /** Pass `useParkedSales(drafts)`'s `parked` and `discard`, or your own parked store's list and handlers (`onPark`, `onResume`, `onDiscard`) with the same results. */
package/dist/index.js CHANGED
@@ -2126,10 +2126,11 @@ function ProductVariantPicker({
2126
2126
  import { formatMoney as formatMoney2 } from "@tallyui/core";
2127
2127
  import { cn as cn48 } from "@tallyui/theme";
2128
2128
  import { jsx as jsx51, jsxs as jsxs13 } from "react/jsx-runtime";
2129
- function CartLine({ name, quantity, unitPrice, lineTotal, locale, className, ...props }) {
2129
+ function CartLine({ name, attributes, quantity, unitPrice, lineTotal, locale, className, ...props }) {
2130
2130
  return /* @__PURE__ */ jsxs13(HStack, { className: cn48("px-3 py-2.5", className), ...props, children: [
2131
2131
  /* @__PURE__ */ jsxs13(VStack, { space: "none", className: "flex-1 gap-0.5", children: [
2132
2132
  /* @__PURE__ */ jsx51(Text, { className: "text-sm font-medium", numberOfLines: 1, children: name }),
2133
+ Object.entries(attributes ?? {}).map(([key, value]) => /* @__PURE__ */ jsx51(Text, { className: "text-xs text-muted-foreground", children: `${key}: ${value}` }, key)),
2133
2134
  /* @__PURE__ */ jsx51(Text, { className: "text-xs text-muted-foreground", children: `${formatMoney2(unitPrice, locale) ?? "\u2014"} \xD7 ${quantity}` })
2134
2135
  ] }),
2135
2136
  /* @__PURE__ */ jsx51(Text, { className: "text-sm font-semibold", children: formatMoney2(lineTotal, locale) ?? "\u2014" })
@@ -2148,6 +2149,7 @@ function CartTotal({
2148
2149
  taxInclusive,
2149
2150
  locale,
2150
2151
  className,
2152
+ afterSubtotal,
2151
2153
  ...props
2152
2154
  }) {
2153
2155
  return /* @__PURE__ */ jsxs14(VStack, { space: "none", className: cn49("gap-1.5 px-3 py-3", className), ...props, children: [
@@ -2155,6 +2157,7 @@ function CartTotal({
2155
2157
  /* @__PURE__ */ jsx52(Text, { className: "text-sm text-muted-foreground", children: "Subtotal" }),
2156
2158
  /* @__PURE__ */ jsx52(Text, { className: "text-sm", children: formatMoney3(subtotal, locale) ?? "\u2014" })
2157
2159
  ] }),
2160
+ afterSubtotal,
2158
2161
  discount && discount.amount > 0 && /* @__PURE__ */ jsxs14(HStack, { space: "none", className: "justify-between", children: [
2159
2162
  /* @__PURE__ */ jsx52(Text, { className: "text-sm text-muted-foreground", children: "Discount" }),
2160
2163
  /* @__PURE__ */ jsxs14(Text, { className: "text-sm", children: [
@@ -4375,7 +4378,7 @@ function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, onApp
4375
4378
 
4376
4379
  // src/sale/cart.tsx
4377
4380
  import { Fragment as Fragment6, jsx as jsx93, jsxs as jsxs51 } from "react/jsx-runtime";
4378
- function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPrice = false, onPriceChange, taxClasses }) {
4381
+ function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }) {
4379
4382
  const { order } = sale;
4380
4383
  const money = (amount) => ({ amount, currency: order.currency });
4381
4384
  const { totals } = buildReceiptData(order, { storeName: "" });
@@ -4403,6 +4406,7 @@ function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPr
4403
4406
  CartLine,
4404
4407
  {
4405
4408
  name: line.name,
4409
+ attributes: line.attributes,
4406
4410
  quantity: line.quantity,
4407
4411
  unitPrice: money(line.unitPriceMinor),
4408
4412
  lineTotal: money(display(line.id).amountMinor)
@@ -4532,10 +4536,11 @@ function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPr
4532
4536
  CartTotal,
4533
4537
  {
4534
4538
  subtotal: money(totals.subtotalMinor),
4535
- discount: money(totals.discountMinor),
4536
4539
  total: money(totals.totalMinor),
4540
+ discount: money(couponDiscountMinor === void 0 ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor)),
4537
4541
  taxLines: taxRows,
4538
- taxInclusive: totals.taxInclusive
4542
+ taxInclusive: totals.taxInclusive,
4543
+ afterSubtotal
4539
4544
  }
4540
4545
  ),
4541
4546
  sale.error ? /* @__PURE__ */ jsx93(Text36, { accessibilityRole: "alert", className: "text-destructive", children: sale.error }) : null,
@@ -4820,7 +4825,8 @@ function Catalogue({
4820
4825
  items,
4821
4826
  onQueryChange,
4822
4827
  showCategoryNav = false,
4823
- categories
4828
+ categories,
4829
+ pickAnyOptions = false
4824
4830
  }) {
4825
4831
  const [initial] = useState22(() => {
4826
4832
  const state2 = normalizeCatalogueViewState({ ...DEFAULT_CATALOGUE_VIEW_STATE, ...defaultViewState });
@@ -4892,14 +4898,35 @@ function Catalogue({
4892
4898
  useEffect5(() => {
4893
4899
  if (chooserId !== null && choices.length === 0) setChooserId(null);
4894
4900
  }, [chooserId, choices]);
4901
+ const [pickEntry, setPickEntry] = useState22(null);
4902
+ const [picks, setPicks] = useState22({});
4903
+ function anyGroupsOf(entry) {
4904
+ const fixed = entry.variant.options ?? {};
4905
+ return (traits.getVariantOptions?.(entry.product) ?? []).filter(({ id, name, values }) => id === void 0 && !Object.prototype.hasOwnProperty.call(fixed, name) && values.length > 0);
4906
+ }
4907
+ const anyGroups = pickEntry ? anyGroupsOf(pickEntry) : [];
4908
+ const allPicked = anyGroups.every(({ name }) => picks[name]);
4909
+ function closePicker() {
4910
+ setPickEntry(null);
4911
+ setPicks({});
4912
+ }
4913
+ useEffect5(() => {
4914
+ if (pickEntry && !entries.some((entry) => traits.getId(entry.product) === traits.getId(pickEntry.product) && entry.variant.id === pickEntry.variant.id)) closePicker();
4915
+ }, [pickEntry, entries, traits]);
4895
4916
  function select(entry) {
4896
- onSelect(entry);
4917
+ const picking = pickAnyOptions && anyGroupsOf(entry).length > 0;
4918
+ closePicker();
4919
+ if (picking) setPickEntry(entry);
4920
+ else onSelect(entry);
4897
4921
  setChooserId(null);
4898
4922
  }
4899
4923
  function selectProduct(product) {
4900
4924
  const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
4901
4925
  if (variants.length === 1) select(variants[0]);
4902
- else setChooserId(traits.getId(product));
4926
+ else {
4927
+ closePicker();
4928
+ setChooserId(traits.getId(product));
4929
+ }
4903
4930
  }
4904
4931
  const emptyState = /* @__PURE__ */ jsx97(Text40, { className: "mt-10 text-center text-sm text-muted-foreground", children: query.trim() ? `No products match "${query.trim()}".` : activeCategory ? `No products in ${activeCategory.name}.` : isLoading ? "Loading products\u2026" : "No products yet." });
4905
4932
  return /* @__PURE__ */ jsxs55(View62, { className: "flex-1", onLayout: (event) => setWidth(event.nativeEvent.layout.width), children: [
@@ -4940,7 +4967,24 @@ function Catalogue({
4940
4967
  onSelect: (id) => changeState({ type: "setCategory", categoryId: id === "" ? null : id })
4941
4968
  }
4942
4969
  ) : null,
4943
- choices.length > 0 ? /* @__PURE__ */ jsxs55(View62, { accessibilityLabel: "Choose variant", className: "gap-2", children: [
4970
+ pickEntry ? /* @__PURE__ */ jsxs55(View62, { accessibilityLabel: "Choose options", className: "gap-2", children: [
4971
+ /* @__PURE__ */ jsx97(Text40, { className: "font-semibold text-foreground", children: pickEntry.variant.title ?? traits.getName(pickEntry.product) }),
4972
+ /* @__PURE__ */ jsx97(ProductVariantPicker, { options: anyGroups.map(({ name, values }) => ({ name, values })), selected: picks, onSelect: setPicks }),
4973
+ /* @__PURE__ */ jsx97(
4974
+ Pressable32,
4975
+ {
4976
+ accessibilityRole: "button",
4977
+ disabled: !allPicked,
4978
+ onPress: () => {
4979
+ onSelect({ ...pickEntry, picks });
4980
+ closePicker();
4981
+ },
4982
+ className: `rounded-md border border-border bg-card px-4 py-3 ${allPicked ? "" : "opacity-50"}`,
4983
+ children: /* @__PURE__ */ jsx97(Text40, { className: "text-center text-foreground", children: "Add to cart" })
4984
+ }
4985
+ ),
4986
+ /* @__PURE__ */ jsx97(Pressable32, { accessibilityRole: "button", onPress: closePicker, className: "rounded-md border border-border bg-card px-4 py-3", children: /* @__PURE__ */ jsx97(Text40, { className: "text-center text-foreground", children: "Cancel" }) })
4987
+ ] }) : choices.length > 0 ? /* @__PURE__ */ jsxs55(View62, { accessibilityLabel: "Choose variant", className: "gap-2", children: [
4944
4988
  choices.map((entry) => /* @__PURE__ */ jsxs55(
4945
4989
  Pressable32,
4946
4990
  {
@@ -5020,27 +5064,25 @@ function orderReference(order) {
5020
5064
  // src/sale/receipt.tsx
5021
5065
  import { Fragment as Fragment9, jsx as jsx98, jsxs as jsxs56 } from "react/jsx-runtime";
5022
5066
  var defaultFormatDate = (iso) => new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso));
5023
- function Receipt({
5024
- order,
5025
- posOrder,
5026
- store,
5027
- cashier,
5028
- registerId,
5029
- registerName,
5030
- newSale,
5031
- taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`,
5032
- topInset = 0,
5033
- formatDate = defaultFormatDate,
5034
- footerSlot
5035
- }) {
5067
+ function Receipt(props) {
5068
+ const {
5069
+ posOrder,
5070
+ newSale,
5071
+ taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`,
5072
+ topInset = 0,
5073
+ formatDate = defaultFormatDate,
5074
+ footerSlot,
5075
+ doneLabel = "New sale"
5076
+ } = props;
5036
5077
  useEffect6(injectPrintStyle, []);
5037
- const receipt = buildReceiptData3(order, {
5038
- storeName: store.name,
5039
- storeAddress: store.address,
5040
- cashier,
5041
- register: registerId,
5042
- registerName
5043
- });
5078
+ const order = props.receipt === void 0 ? props.order : void 0;
5079
+ const receipt = props.receipt === void 0 ? buildReceiptData3(props.order, {
5080
+ storeName: props.store.name,
5081
+ storeAddress: props.store.address,
5082
+ cashier: props.cashier,
5083
+ register: props.registerId,
5084
+ registerName: props.registerName
5085
+ }) : props.receipt;
5044
5086
  const money = (amount) => formatMoney16({ amount, currency: receipt.currency }) ?? "";
5045
5087
  const row = (label, amount, bold = false, key) => /* @__PURE__ */ jsxs56(View63, { accessibilityLabel: `${label}: ${amount}`, className: "flex-row justify-between gap-4", children: [
5046
5088
  /* @__PURE__ */ jsx98(Text41, { className: `text-foreground ${bold ? "font-semibold" : ""}`, children: label }),
@@ -5054,12 +5096,13 @@ function Receipt({
5054
5096
  /* @__PURE__ */ jsxs56(View63, { className: "w-full max-w-md self-center gap-3 p-4 bg-card", children: [
5055
5097
  /* @__PURE__ */ jsx98(Text41, { className: "text-lg font-semibold text-foreground", children: receipt.header.storeName }),
5056
5098
  receipt.header.storeAddress ? /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: receipt.header.storeAddress }) : null,
5057
- /* @__PURE__ */ jsx98(Text41, { testID: "receipt-order", className: "text-foreground", children: posOrder ? `Order ${orderReference(posOrder)}` : `Order ${receipt.header.orderNumber.slice(-8)} (draft)` }),
5058
- /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: formatDate(posOrder?.createdAt ?? receipt.header.date) }),
5059
- /* @__PURE__ */ jsxs56(Text41, { className: "text-muted-foreground", children: [
5099
+ /* @__PURE__ */ jsx98(Text41, { testID: "receipt-order", className: "text-foreground", children: posOrder ? `Order ${orderReference(posOrder)}` : order ? `Order ${receipt.header.orderNumber.slice(-8)} (draft)` : `Order ${receipt.header.orderNumber}` }),
5100
+ receipt.fiscal.is_reprint ? /* @__PURE__ */ jsx98(Text41, { testID: "receipt-reprint", className: "text-foreground", children: `Reprint ${receipt.fiscal.reprint_count}` }) : null,
5101
+ /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: formatDate(order ? posOrder?.createdAt ?? receipt.header.date : receipt.header.date) }),
5102
+ order || receipt.header.cashier ? /* @__PURE__ */ jsxs56(Text41, { className: "text-muted-foreground", children: [
5060
5103
  "Cashier: ",
5061
5104
  receipt.header.cashier
5062
- ] }),
5105
+ ] }) : null,
5063
5106
  receipt.register.name ? /* @__PURE__ */ jsxs56(Text41, { testID: "receipt-register", className: "text-muted-foreground", children: [
5064
5107
  "Register: ",
5065
5108
  receipt.register.name
@@ -5070,11 +5113,12 @@ function Receipt({
5070
5113
  ] }),
5071
5114
  receipt.lineItems.map((line, index) => /* @__PURE__ */ jsxs56(View63, { children: [
5072
5115
  /* @__PURE__ */ jsx98(Text41, { className: "text-foreground", children: line.name }),
5116
+ Object.entries(line.attributes ?? {}).map(([name, value]) => /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: `${name}: ${value}` }, name)),
5073
5117
  row(`${line.quantity} \xD7 ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor)),
5074
- line.displayDiscounts.map((discount, i) => /* @__PURE__ */ jsx98(View63, { className: "pl-4", children: row(`${discountLabel(
5118
+ line.displayDiscounts.map((discount, i) => /* @__PURE__ */ jsx98(View63, { className: "pl-4", children: row(`${order ? discountLabel(
5075
5119
  order.lineItems[index].discounts[i],
5076
5120
  receipt.currency
5077
- )} off`, `\u2212${money(discount.amountMinor)}`) }, i))
5121
+ ) : discount.label} off`, `\u2212${money(discount.amountMinor)}`) }, i))
5078
5122
  ] }, index)),
5079
5123
  row("Subtotal", money(totals.subtotalMinor)),
5080
5124
  lineDiscountMinor > 0 ? row("Line discounts", `\u2212${money(lineDiscountMinor)}`) : null,
@@ -5084,18 +5128,18 @@ function Receipt({
5084
5128
  taxRows,
5085
5129
  row("Total", money(totals.totalMinor), true),
5086
5130
  receipt.payments.map((payment, index) => row(
5087
- payment.method === "cash" ? "Cash tendered" : "Card terminal",
5131
+ payment.method === "cash" ? "Cash tendered" : order || payment.method === "external" ? "Card terminal" : payment.method,
5088
5132
  money(payment.amountMinor) + (payment.reference ? ` \xB7 ${payment.reference}` : ""),
5089
5133
  false,
5090
5134
  index
5091
5135
  )),
5092
- row("Change", money(receipt.changeDueMinor)),
5136
+ order || receipt.changeDueMinor > 0 ? row("Change", money(receipt.changeDueMinor)) : null,
5093
5137
  footerSlot ? /* @__PURE__ */ jsx98(View63, { testID: "receipt-footer", className: "mt-3 items-center border-t border-dashed border-border pt-3", children: footerSlot }) : null,
5094
5138
  /* @__PURE__ */ jsxs56(View63, { dataSet: { print: "hide" }, className: "flex-row gap-4", children: [
5095
5139
  /* @__PURE__ */ jsx98(Pressable33, { accessibilityRole: "button", onPress: () => {
5096
5140
  if (typeof window !== "undefined" && typeof window.print === "function") window.print();
5097
5141
  }, className: "rounded-md border border-border bg-card px-4 py-3", children: /* @__PURE__ */ jsx98(Text41, { className: "text-center text-foreground", children: "Print receipt" }) }),
5098
- /* @__PURE__ */ jsx98(Pressable33, { accessibilityRole: "button", onPress: newSale, className: "rounded-md bg-primary px-4 py-3", children: /* @__PURE__ */ jsx98(Text41, { className: "text-center font-semibold text-primary-foreground", children: "New sale" }) })
5142
+ /* @__PURE__ */ jsx98(Pressable33, { accessibilityRole: "button", onPress: newSale, className: "rounded-md bg-primary px-4 py-3", children: /* @__PURE__ */ jsx98(Text41, { className: "text-center font-semibold text-primary-foreground", children: doneLabel }) })
5099
5143
  ] })
5100
5144
  ] })
5101
5145
  ] });
@@ -5227,7 +5271,7 @@ function defaultFormatDate2(iso) {
5227
5271
  const date = new Date(iso);
5228
5272
  return Number.isNaN(date.getTime()) ? iso : new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short" }).format(date);
5229
5273
  }
5230
- function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history }) {
5274
+ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen }) {
5231
5275
  const retrying = useRef8(/* @__PURE__ */ new Set());
5232
5276
  const [retryingIds, setRetryingIds] = useState24(/* @__PURE__ */ new Set());
5233
5277
  const [expanded, setExpanded] = useState24(/* @__PURE__ */ new Set());
@@ -5260,7 +5304,18 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
5260
5304
  formatMoney17({ amount: row.totalMinor, currency: row.currency }),
5261
5305
  " \xB7 ",
5262
5306
  row.stateLabel
5263
- ] })
5307
+ ] }),
5308
+ onOpen ? /* @__PURE__ */ jsx100(
5309
+ Pressable34,
5310
+ {
5311
+ accessibilityRole: "button",
5312
+ accessibilityLabel: `Open order ${row.reference}`,
5313
+ testID: `history-open-${row.id}`,
5314
+ onPress: () => onOpen(row),
5315
+ className: "rounded-md border border-border px-4 py-2",
5316
+ children: /* @__PURE__ */ jsx100(Text43, { className: "text-center font-semibold text-foreground", children: "Open" })
5317
+ }
5318
+ ) : null
5264
5319
  ] }, `history:${row.id}`);
5265
5320
  }
5266
5321
  const count2 = order.lines.reduce((sum, line) => sum + line.quantity, 0);
@@ -5294,6 +5349,17 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
5294
5349
  ]
5295
5350
  }
5296
5351
  ),
5352
+ onOpen ? /* @__PURE__ */ jsx100(
5353
+ Pressable34,
5354
+ {
5355
+ accessibilityRole: "button",
5356
+ accessibilityLabel: `Open order ${orderReference(order)}`,
5357
+ testID: `order-open-${order.id}`,
5358
+ onPress: () => onOpen(order),
5359
+ className: "rounded-md border border-border px-4 py-2",
5360
+ children: /* @__PURE__ */ jsx100(Text43, { className: "text-center font-semibold text-foreground", children: "Open" })
5361
+ }
5362
+ ) : null,
5297
5363
  isExpanded ? /* @__PURE__ */ jsxs58(View65, { testID: `order-detail-${order.id}`, className: "mt-1 gap-1 border-t border-border pt-2", children: [
5298
5364
  order.lines.map((line) => /* @__PURE__ */ jsx100(Text43, { className: "text-foreground", children: `${line.quantity} \xD7 ${line.name}` }, line.id)),
5299
5365
  order.payments.map((payment) => /* @__PURE__ */ jsx100(Text43, { className: "text-muted-foreground", children: `${payment.method === "cash" ? "Cash" : "Card terminal"} ${formatMoney17({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` \xB7 ${payment.reference}` : ""}` }, payment.id))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/components",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "type": "module",
5
5
  "description": "Universal POS UI components for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -28,22 +28,22 @@
28
28
  "directory": "packages/components"
29
29
  },
30
30
  "peerDependencies": {
31
- "@tallyui/core": "^3.10.0",
32
- "@tallyui/primitives": "^3.10.0",
33
- "@tallyui/theme": "^3.10.0",
31
+ "@tallyui/core": "^3.12.0",
32
+ "@tallyui/primitives": "^3.12.0",
33
+ "@tallyui/theme": "^3.12.0",
34
34
  "react": ">=18",
35
35
  "react-native": ">=0.74",
36
36
  "react-native-svg": ">=15"
37
37
  },
38
38
  "dependencies": {
39
39
  "class-variance-authority": "^0.7.1",
40
- "@tallyui/pos": "3.10.0"
40
+ "@tallyui/pos": "3.12.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@tallyui/connector-medusa": "3.10.0",
44
- "@tallyui/connector-vendure": "3.10.0",
45
- "@tallyui/connector-woocommerce": "3.10.0",
46
- "@tallyui/mock-api": "3.10.0",
43
+ "@tallyui/connector-medusa": "3.12.0",
44
+ "@tallyui/connector-vendure": "3.12.0",
45
+ "@tallyui/connector-woocommerce": "3.12.0",
46
+ "@tallyui/mock-api": "3.12.0",
47
47
  "@types/react": ">=18",
48
48
  "react": "^19.2.4",
49
49
  "react-native-svg": "15.12.1",
@@ -4,6 +4,8 @@ import { Text, HStack, VStack, type HStackProps } from '../ui';
4
4
 
5
5
  export interface CartLineProps extends Omit<HStackProps, 'children'> {
6
6
  name: string;
7
+ /** The variant's chosen options, one "Name: Value" row each under the name. */
8
+ attributes?: Record<string, string>;
7
9
  quantity: number;
8
10
  unitPrice: Money;
9
11
  lineTotal: Money;
@@ -18,11 +20,14 @@ export interface CartLineProps extends Omit<HStackProps, 'children'> {
18
20
  * <CartLine name="Coffee" quantity={2} unitPrice={unitPrice} lineTotal={lineTotal} />
19
21
  * ```
20
22
  */
21
- export function CartLine({ name, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps) {
23
+ export function CartLine({ name, attributes, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps) {
22
24
  return (
23
25
  <HStack className={cn('px-3 py-2.5', className)} {...props}>
24
26
  <VStack space="none" className="flex-1 gap-0.5">
25
27
  <Text className="text-sm font-medium" numberOfLines={1}>{name}</Text>
28
+ {Object.entries(attributes ?? {}).map(([key, value]) => (
29
+ <Text key={key} className="text-xs text-muted-foreground">{`${key}: ${value}`}</Text>
30
+ ))}
26
31
  <Text className="text-xs text-muted-foreground">
27
32
  {`${formatMoney(unitPrice, locale) ?? '—'} × ${quantity}`}
28
33
  </Text>
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from 'react';
1
2
  import { formatMoney, type Money } from '@tallyui/core';
2
3
  import { cn } from '@tallyui/theme';
3
4
  import { Text, HStack, VStack, type VStackProps } from '../ui';
@@ -11,6 +12,8 @@ export interface CartTotalProps extends Omit<VStackProps, 'children'> {
11
12
  taxInclusive?: boolean;
12
13
  locale?: string;
13
14
  className?: string;
15
+ /** Rows rendered directly under Subtotal, e.g. a platform's coupon chips. */
16
+ afterSubtotal?: ReactNode;
14
17
  }
15
18
 
16
19
  /**
@@ -28,6 +31,7 @@ export function CartTotal({
28
31
  taxInclusive,
29
32
  locale,
30
33
  className,
34
+ afterSubtotal,
31
35
  ...props
32
36
  }: CartTotalProps) {
33
37
  return (
@@ -37,6 +41,8 @@ export function CartTotal({
37
41
  <Text className="text-sm">{formatMoney(subtotal, locale) ?? '—'}</Text>
38
42
  </HStack>
39
43
 
44
+ {afterSubtotal}
45
+
40
46
  {discount && discount.amount > 0 && (
41
47
  <HStack space="none" className="justify-between">
42
48
  <Text className="text-sm text-muted-foreground">Discount</Text>
package/src/sale/cart.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useState } from 'react';
1
+ import { useState, type ReactNode } from 'react';
2
2
  import { Pressable, Text, View } from 'react-native';
3
3
  import { formatMoney } from '@tallyui/core';
4
4
  import { buildReceiptData } from '@tallyui/pos';
@@ -9,13 +9,19 @@ import { PriceForm } from './price-form';
9
9
  import { ChargeForm } from './charge-form';
10
10
 
11
11
  /** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
12
- export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, taxClasses }:
12
+ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }:
13
13
  { sale: ReturnType<typeof useSale>; taxLabel?: (ratePpm: number) => string;
14
14
  taxClasses?: ReadonlyArray<{ id: string; label: string }>;
15
15
  /** Shows a Price action on each line. Pass the till's own permission; the control isn't shown without it. */
16
16
  canEditPrice?: boolean;
17
17
  /** Called after a price is applied, for the app's audit log. The reason is kept only here. */
18
18
  onPriceChange?: (change: { lineId: string; fromMinor: number; toMinor: number; reason?: string }) => void;
19
+ /** Rows under the totals' Subtotal, e.g. the platform's coupon chips (passed to CartTotal). */
20
+ afterSubtotal?: ReactNode;
21
+ /** The coupon amount the app itemises in `afterSubtotal` (e.g. Σ `order.display.coupons`), in integer minor units of
22
+ * the order's currency, in the display mode. When given, the Discount row shows the other discounts only (the
23
+ * totals' discount minus this) and is hidden when they come to 0. Absent: the Discount row is the whole discount. */
24
+ couponDiscountMinor?: number;
19
25
  }) {
20
26
  const { order } = sale;
21
27
  const money = (amount: number) => ({ amount, currency: order.currency });
@@ -39,7 +45,7 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
39
45
  { id: 'discount', label: 'Discount', color: 'text-primary', onPress: () => setForm({ type: 'discount', lineId: line.id }) },
40
46
  ...(canEditPrice ? [{ id: 'price', label: 'Price', color: 'text-primary', onPress: () => setForm({ type: 'price', lineId: line.id }) }] : []),
41
47
  ]}>
42
- <CartLine name={line.name} quantity={line.quantity} unitPrice={money(line.unitPriceMinor)}
48
+ <CartLine name={line.name} attributes={line.attributes} quantity={line.quantity} unitPrice={money(line.unitPriceMinor)}
43
49
  lineTotal={money(display(line.id).amountMinor)} />
44
50
  </CartLineActions>
45
51
  <DiscountChips discounts={line.discounts} amounts={display(line.id).discounts} currency={order.currency} onRemove={sale.removeDiscount} />
@@ -94,8 +100,9 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
94
100
  </View> : null}</>}
95
101
  footer={<View testID="cart-footer" className="gap-3 pb-4">
96
102
  {/* Exclusive: subtotal − discount + tax = total. Inclusive: subtotal − discount = total, the tax "incl.", not added. */}
97
- <CartTotal subtotal={money(totals.subtotalMinor)} discount={money(totals.discountMinor)} total={money(totals.totalMinor)}
98
- taxLines={taxRows} taxInclusive={totals.taxInclusive} />
103
+ <CartTotal subtotal={money(totals.subtotalMinor)} total={money(totals.totalMinor)}
104
+ discount={money(couponDiscountMinor === undefined ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor))}
105
+ taxLines={taxRows} taxInclusive={totals.taxInclusive} afterSubtotal={afterSubtotal} />
99
106
  {sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
100
107
  <View className="flex-row gap-3">
101
108
  <Pressable accessibilityRole="button" disabled={!order.lineItems.length} onPress={() => sale.startTender('cash')} className={pay}>
@@ -6,6 +6,7 @@ import { catalogueEntries, findEntryByCode, searchProducts, variantPriceLabel, s
6
6
  listCategories, inCategory,
7
7
  type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction } from '@tallyui/pos';
8
8
  import { ProductGrid, ProductImage, ProductPrice, ProductStockBadge, ProductTitle, ProductTable, ViewToggle, CategoryNav } from '../product';
9
+ import { ProductVariantPicker } from '../product/product-variant-picker';
9
10
  import { SearchInput } from '../input';
10
11
  import { VStack } from '../ui';
11
12
 
@@ -34,7 +35,7 @@ function laterOf(a: Date | null | undefined, b: Date | null | undefined): Date |
34
35
  }
35
36
 
36
37
  export function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength,
37
- viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories }: {
38
+ viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories, pickAnyOptions = false }: {
38
39
  products: Doc[];
39
40
  traits: ProductTraits<Doc>;
40
41
  currency: string;
@@ -82,6 +83,8 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
82
83
  items?: Doc[];
83
84
  /** Search text on every input change, for apps that filter items themselves. */
84
85
  onQueryChange?: (query: string) => void;
86
+ /** Ask for a value for each of a variant's local "Any" option groups before onSelect (#495); set it only when the store accepts order.create version 6. */
87
+ pickAnyOptions?: boolean;
85
88
  }) {
86
89
  const [initial] = useState<{
87
90
  state: CatalogueViewState; loaded?: CatalogueViewState; pending?: Promise<unknown>; failed?: boolean; error?: unknown;
@@ -156,15 +159,40 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
156
159
  // A product that leaves the catalogue (a resync, or no longer sellable) closes its chooser.
157
160
  useEffect(() => { if (chooserId !== null && choices.length === 0) setChooserId(null); }, [chooserId, choices]);
158
161
 
162
+ // The picker step (#495): the entry waiting for its "Any" picks, and the cashier's picks so far.
163
+ const [pickEntry, setPickEntry] = useState<CatalogueEntry<Doc> | null>(null);
164
+ const [picks, setPicks] = useState<Record<string, string>>({});
165
+ // A variant's local "Any" groups: no backend id (global pa_* attributes are #572), no fixed value on the variant.
166
+ function anyGroupsOf(entry: CatalogueEntry<Doc>) {
167
+ const fixed = entry.variant.options ?? {};
168
+ return (traits.getVariantOptions?.(entry.product) ?? []).filter(({ id, name, values }) =>
169
+ id === undefined && !Object.prototype.hasOwnProperty.call(fixed, name) && values.length > 0);
170
+ }
171
+ const anyGroups = pickEntry ? anyGroupsOf(pickEntry) : [];
172
+ const allPicked = anyGroups.every(({ name }) => picks[name]);
173
+
174
+ function closePicker() {
175
+ setPickEntry(null);
176
+ setPicks({});
177
+ }
178
+ // An entry that leaves the catalogue (a resync, or no longer sellable) closes its picker.
179
+ useEffect(() => {
180
+ if (pickEntry && !entries.some((entry) => traits.getId(entry.product) === traits.getId(pickEntry.product)
181
+ && entry.variant.id === pickEntry.variant.id)) closePicker();
182
+ }, [pickEntry, entries, traits]);
183
+
159
184
  function select(entry: CatalogueEntry<Doc>) {
160
- onSelect(entry);
185
+ const picking = pickAnyOptions && anyGroupsOf(entry).length > 0;
186
+ closePicker();
187
+ if (picking) setPickEntry(entry);
188
+ else onSelect(entry);
161
189
  setChooserId(null);
162
190
  }
163
191
 
164
192
  function selectProduct(product: Doc) {
165
193
  const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
166
194
  if (variants.length === 1) select(variants[0]);
167
- else setChooserId(traits.getId(product));
195
+ else { closePicker(); setChooserId(traits.getId(product)); }
168
196
  }
169
197
 
170
198
  const emptyState = <Text className="mt-10 text-center text-sm text-muted-foreground">
@@ -193,7 +221,19 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
193
221
  {showCategoryNav ? <CategoryNav categories={[{ id: '', name: 'All products' }, ...categoryList]}
194
222
  selectedId={activeCategory?.id ?? ''}
195
223
  onSelect={(id) => changeState({ type: 'setCategory', categoryId: id === '' ? null : id })} /> : null}
196
- {choices.length > 0 ? (
224
+ {pickEntry ? (
225
+ <View accessibilityLabel="Choose options" className="gap-2">
226
+ <Text className="font-semibold text-foreground">{pickEntry.variant.title ?? traits.getName(pickEntry.product)}</Text>
227
+ <ProductVariantPicker options={anyGroups.map(({ name, values }) => ({ name, values }))} selected={picks} onSelect={setPicks} />
228
+ <Pressable accessibilityRole="button" disabled={!allPicked} onPress={() => { onSelect({ ...pickEntry, picks }); closePicker(); }}
229
+ className={`rounded-md border border-border bg-card px-4 py-3 ${allPicked ? '' : 'opacity-50'}`}>
230
+ <Text className="text-center text-foreground">Add to cart</Text>
231
+ </Pressable>
232
+ <Pressable accessibilityRole="button" onPress={closePicker} className="rounded-md border border-border bg-card px-4 py-3">
233
+ <Text className="text-center text-foreground">Cancel</Text>
234
+ </Pressable>
235
+ </View>
236
+ ) : choices.length > 0 ? (
197
237
  <View accessibilityLabel="Choose variant" className="gap-2">
198
238
  {choices.map((entry) => (
199
239
  <Pressable key={entry.variant.id} accessibilityRole="button" onPress={() => select(entry)}
@@ -43,11 +43,13 @@ function defaultFormatDate(iso: string) {
43
43
  * `onRetry` is the outbox's `requeue`; `formatDate` replaces the app's date util; `footer` is the app's own content
44
44
  * (medusapos: the feedback link). The router and session redirect stay in the app. `stuck` is the outbox's
45
45
  * `state.stuck` (`useOrderOutbox`): those pending orders need attention too, each with its own entry's reason and since.
46
+ * `onOpen` adds an Open button to each row that passes its order to the app.
46
47
  * `history` adds read-only store order rows to Recent (ADR-052 amendment 1). */
47
- export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history }: {
48
+ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history, onOpen }: {
48
49
  orders: PosOrder[]; onRetry(orderIds: string[]): Promise<number>; formatDate?: (iso: string) => string; footer?: ReactNode;
49
50
  stuck?: OutboxState['stuck'];
50
51
  history?: OrderHistoryRow[];
52
+ onOpen?: (row: PosOrder | OrderHistoryRow) => void;
51
53
  }) {
52
54
  const retrying = useRef(new Set<string>());
53
55
  const [retryingIds, setRetryingIds] = useState(new Set<string>());
@@ -77,6 +79,11 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
77
79
  return <View key={`history:${row.id}`} testID={`history-row-${row.id}`} className="gap-1 rounded-md border border-border bg-card p-3">
78
80
  <Text className="text-foreground">{`Order ${row.reference} · ${row.itemCount} ${row.itemCount === 1 ? 'item' : 'items'}`}</Text>
79
81
  <Text className="text-muted-foreground">{formatDate(row.placedAt)} · {formatMoney({ amount: row.totalMinor, currency: row.currency })} · {row.stateLabel}</Text>
82
+ {onOpen ? <Pressable accessibilityRole="button" accessibilityLabel={`Open order ${row.reference}`}
83
+ testID={`history-open-${row.id}`} onPress={() => onOpen(row)}
84
+ className="rounded-md border border-border px-4 py-2">
85
+ <Text className="text-center font-semibold text-foreground">Open</Text>
86
+ </Pressable> : null}
80
87
  </View>;
81
88
  }
82
89
  const count = order.lines.reduce((sum, line) => sum + line.quantity, 0);
@@ -96,6 +103,11 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
96
103
  <Text className="text-foreground">{`Order ${orderReference(order)} · ${count} ${count === 1 ? 'item' : 'items'}`}</Text>
97
104
  <Text className="text-muted-foreground">{formatDate(order.createdAt)} · {formatMoney({ amount: order.totalMinor, currency: order.currency })} · {STATUS_LABEL[order.syncStatus]}</Text>
98
105
  </Pressable>
106
+ {onOpen ? <Pressable accessibilityRole="button" accessibilityLabel={`Open order ${orderReference(order)}`}
107
+ testID={`order-open-${order.id}`} onPress={() => onOpen(order)}
108
+ className="rounded-md border border-border px-4 py-2">
109
+ <Text className="text-center font-semibold text-foreground">Open</Text>
110
+ </Pressable> : null}
99
111
  {isExpanded ? <View testID={`order-detail-${order.id}`} className="mt-1 gap-1 border-t border-border pt-2">
100
112
  {order.lines.map((line) => <Text key={line.id} className="text-foreground">{`${line.quantity} × ${line.name}`}</Text>)}
101
113
  {order.payments.map((payment) => <Text key={payment.id} className="text-muted-foreground">
@@ -1,7 +1,7 @@
1
1
  import { useEffect, type ReactNode } from 'react';
2
2
  import { Pressable, Text, View } from 'react-native';
3
3
  import { formatMoney } from '@tallyui/core';
4
- import { buildReceiptData, type SentOrder } from '@tallyui/pos';
4
+ import { buildReceiptData, type ReceiptData, type SentOrder } from '@tallyui/pos';
5
5
  import type { PosOrder } from '@tallyui/pos';
6
6
  import { injectPrintStyle } from './print-style';
7
7
  import { discountLabel } from './discount-form';
@@ -9,24 +9,40 @@ import { orderReference } from './order-reference';
9
9
 
10
10
  const defaultFormatDate = (iso: string) => new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(iso));
11
11
 
12
- /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
13
- * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
14
- export function Receipt({ order, posOrder, store, cashier, registerId, registerName, newSale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`,
15
- topInset = 0, formatDate = defaultFormatDate, footerSlot }: {
16
- order: SentOrder; store: { name: string; address?: string }; cashier: string; registerId: string; newSale: () => void;
12
+ type ReceiptProps = {
13
+ newSale: () => void;
14
+ taxLabel?: (ratePpm: number) => string; topInset?: number; formatDate?: (iso: string) => string;
15
+ /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
16
+ footerSlot?: ReactNode;
17
+ /** The second button's text; default `New sale`. */
18
+ doneLabel?: string;
19
+ } & ({
20
+ order: SentOrder; store: { name: string; address?: string }; cashier: string; registerId: string;
17
21
  /** The register's name, printed as `Register: <name>`; the id is never printed. */
18
22
  registerName?: string;
19
23
  /** The finalized order (useSale's receipt stage has it). With it the receipt prints its reference and time, the
20
24
  * same as Orders; without it (a preview before finalize) the sale id is marked as a draft. */
21
25
  posOrder?: PosOrder;
22
- taxLabel?: (ratePpm: number) => string; topInset?: number; formatDate?: (iso: string) => string;
23
- /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
24
- footerSlot?: ReactNode;
25
- }) {
26
+ receipt?: never;
27
+ } | {
28
+ /** A prebuilt receipt, e.g. a reprint from `buildReceiptDataFromPosOrder`/`buildReceiptDataFromStoreOrder` (ADR-081). */
29
+ receipt: ReceiptData;
30
+ /** With it the receipt prints its reference, the same as Orders; without it, the receipt's own order number. */
31
+ posOrder?: PosOrder;
32
+ order?: never; store?: never; cashier?: never; registerId?: never; registerName?: never;
33
+ });
34
+
35
+ /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
36
+ * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
37
+ export function Receipt(props: ReceiptProps) {
38
+ const { posOrder, newSale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`,
39
+ topInset = 0, formatDate = defaultFormatDate, footerSlot, doneLabel = 'New sale' } = props;
26
40
  useEffect(injectPrintStyle, []);
27
- const receipt = buildReceiptData(order, {
28
- storeName: store.name, storeAddress: store.address, cashier, register: registerId, registerName,
29
- });
41
+ const order = props.receipt === undefined ? props.order : undefined;
42
+ const receipt = props.receipt === undefined ? buildReceiptData(props.order, {
43
+ storeName: props.store.name, storeAddress: props.store.address, cashier: props.cashier, register: props.registerId,
44
+ registerName: props.registerName,
45
+ }) : props.receipt;
30
46
  const money = (amount: number) => formatMoney({ amount, currency: receipt.currency }) ?? '';
31
47
  const row = (label: string, amount: string, bold = false, key?: number) => <View key={key} accessibilityLabel={`${label}: ${amount}`} className="flex-row justify-between gap-4">
32
48
  <Text className={`text-foreground ${bold ? 'font-semibold' : ''}`}>{label}</Text>
@@ -41,17 +57,20 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
41
57
  <View className="w-full max-w-md self-center gap-3 p-4 bg-card">
42
58
  <Text className="text-lg font-semibold text-foreground">{receipt.header.storeName}</Text>
43
59
  {receipt.header.storeAddress ? <Text className="text-muted-foreground">{receipt.header.storeAddress}</Text> : null}
44
- <Text testID="receipt-order" className="text-foreground">{posOrder ? `Order ${orderReference(posOrder)}` : `Order ${receipt.header.orderNumber.slice(-8)} (draft)`}</Text>
45
- <Text className="text-muted-foreground">{formatDate(posOrder?.createdAt ?? receipt.header.date)}</Text>
46
- <Text className="text-muted-foreground">Cashier: {receipt.header.cashier}</Text>
60
+ <Text testID="receipt-order" className="text-foreground">{posOrder ? `Order ${orderReference(posOrder)}`
61
+ : order ? `Order ${receipt.header.orderNumber.slice(-8)} (draft)` : `Order ${receipt.header.orderNumber}`}</Text>
62
+ {receipt.fiscal.is_reprint ? <Text testID="receipt-reprint" className="text-foreground">{`Reprint ${receipt.fiscal.reprint_count}`}</Text> : null}
63
+ <Text className="text-muted-foreground">{formatDate(order ? posOrder?.createdAt ?? receipt.header.date : receipt.header.date)}</Text>
64
+ {order || receipt.header.cashier ? <Text className="text-muted-foreground">Cashier: {receipt.header.cashier}</Text> : null}
47
65
  {receipt.register.name ? <Text testID="receipt-register" className="text-muted-foreground">Register: {receipt.register.name}</Text> : null}
48
66
  {receipt.header.customer && <Text className="text-muted-foreground">Customer: {receipt.header.customer}</Text>}
49
67
  {receipt.lineItems.map((line, index) => <View key={index}>
50
68
  <Text className="text-foreground">{line.name}</Text>
69
+ {Object.entries(line.attributes ?? {}).map(([name, value]) => <Text key={name} className="text-muted-foreground">{`${name}: ${value}`}</Text>)}
51
70
  {/* Before any discount, then the line's own discounts as sub-rows (TallyUI ADR-063); they add up to the subtotal. */}
52
71
  {row(`${line.quantity} × ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor))}
53
- {line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${discountLabel(
54
- order.lineItems[index].discounts[i], receipt.currency)} off`, `−${money(discount.amountMinor)}`)}</View>)}
72
+ {line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${order ? discountLabel(
73
+ order.lineItems[index].discounts[i], receipt.currency) : discount.label} off`, `−${money(discount.amountMinor)}`)}</View>)}
55
74
  </View>)}
56
75
  {/* Each discount appears once in the totals: line discounts are itemised under their lines and summed once here;
57
76
  the order discount appears once. order.display's figures (ADR-063; medusapos ADR 0008). */}
@@ -63,15 +82,16 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
63
82
  {receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), false, index))}
64
83
  {taxRows}
65
84
  {row('Total', money(totals.totalMinor), true)}
66
- {receipt.payments.map((payment, index) => row(payment.method === 'cash' ? 'Cash tendered' : 'Card terminal',
85
+ {receipt.payments.map((payment, index) => row(payment.method === 'cash' ? 'Cash tendered'
86
+ : order || payment.method === 'external' ? 'Card terminal' : payment.method,
67
87
  money(payment.amountMinor) + (payment.reference ? ` · ${payment.reference}` : ''), false, index))}
68
- {row('Change', money(receipt.changeDueMinor))}
88
+ {order || receipt.changeDueMinor > 0 ? row('Change', money(receipt.changeDueMinor)) : null}
69
89
  {footerSlot ? <View testID="receipt-footer" className="mt-3 items-center border-t border-dashed border-border pt-3">{footerSlot}</View> : null}
70
90
  <View dataSet={{ print: 'hide' }} className="flex-row gap-4">
71
91
  <Pressable accessibilityRole="button" onPress={() => { if (typeof window !== 'undefined' && typeof window.print === 'function') window.print(); }} className="rounded-md border border-border bg-card px-4 py-3">
72
92
  <Text className="text-center text-foreground">Print receipt</Text>
73
93
  </Pressable>
74
- <Pressable accessibilityRole="button" onPress={newSale} className="rounded-md bg-primary px-4 py-3"><Text className="text-center font-semibold text-primary-foreground">New sale</Text></Pressable>
94
+ <Pressable accessibilityRole="button" onPress={newSale} className="rounded-md bg-primary px-4 py-3"><Text className="text-center font-semibold text-primary-foreground">{doneLabel}</Text></Pressable>
75
95
  </View>
76
96
  </View></>;
77
97
  }