@tallyui/components 3.11.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?: ({
@@ -1275,7 +1275,7 @@ interface ConnectorStatusProps extends Omit<ViewProps, 'children'> {
1275
1275
  declare function ConnectorStatus({ name, status, lastSync, error, className, unsoldCount, unsoldStale, formatUnsold, ...viewProps }: ConnectorStatusProps): react_jsx_runtime.JSX.Element;
1276
1276
 
1277
1277
  /** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
1278
- declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses, afterSubtotal }: {
1278
+ declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }: {
1279
1279
  sale: ReturnType<typeof useSale>;
1280
1280
  taxLabel?: (ratePpm: number) => string;
1281
1281
  taxClasses?: ReadonlyArray<{
@@ -1293,6 +1293,10 @@ declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, taxClasses,
1293
1293
  }) => void;
1294
1294
  /** Rows under the totals' Subtotal, e.g. the platform's coupon chips (passed to CartTotal). */
1295
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;
1296
1300
  }): react_jsx_runtime.JSX.Element;
1297
1301
 
1298
1302
  /** Phone mode's cart summary (medusapos ADR 0009): the whole bar is one button; the total is the cart's own Total row. */
@@ -1369,7 +1373,7 @@ interface ChargeFormProps {
1369
1373
  declare function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, onApply, onClose }: ChargeFormProps): react_jsx_runtime.JSX.Element;
1370
1374
 
1371
1375
  declare function formatStockSyncTime(time: Date, locale?: string, hour12?: boolean, now?: Date): string;
1372
- 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 }: {
1373
1377
  products: Doc[];
1374
1378
  traits: ProductTraits<Doc>;
1375
1379
  currency: string;
@@ -1417,11 +1421,20 @@ declare function Catalogue<Doc>({ products, traits, currency, onSelect, statusTe
1417
1421
  items?: Doc[];
1418
1422
  /** Search text on every input change, for apps that filter items themselves. */
1419
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;
1420
1426
  }): react_jsx_runtime.JSX.Element;
1421
1427
 
1422
- /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
1423
- * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
1424
- 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
+ } & ({
1425
1438
  order: SentOrder;
1426
1439
  store: {
1427
1440
  name: string;
@@ -1429,18 +1442,26 @@ declare function Receipt({ order, posOrder, store, cashier, registerId, register
1429
1442
  };
1430
1443
  cashier: string;
1431
1444
  registerId: string;
1432
- newSale: () => void;
1433
1445
  /** The register's name, printed as `Register: <name>`; the id is never printed. */
1434
1446
  registerName?: string;
1435
1447
  /** The finalized order (useSale's receipt stage has it). With it the receipt prints its reference and time, the
1436
1448
  * same as Orders; without it (a preview before finalize) the sale id is marked as a draft. */
1437
1449
  posOrder?: PosOrder;
1438
- taxLabel?: (ratePpm: number) => string;
1439
- topInset?: number;
1440
- formatDate?: (iso: string) => string;
1441
- /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
1442
- footerSlot?: ReactNode;
1443
- }): 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;
1444
1465
 
1445
1466
  /** The order reference a visitor sees on the receipt and in Orders (front desk ruling, 2026-10-06): the finalized
1446
1467
  * PosOrder id's last 8 characters, then the backend's display id once the store has one. */
@@ -1479,14 +1500,16 @@ type OrderHistoryRow = {
1479
1500
  * `onRetry` is the outbox's `requeue`; `formatDate` replaces the app's date util; `footer` is the app's own content
1480
1501
  * (medusapos: the feedback link). The router and session redirect stay in the app. `stuck` is the outbox's
1481
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.
1482
1504
  * `history` adds read-only store order rows to Recent (ADR-052 amendment 1). */
1483
- declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history }: {
1505
+ declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history, onOpen }: {
1484
1506
  orders: PosOrder[];
1485
1507
  onRetry(orderIds: string[]): Promise<number>;
1486
1508
  formatDate?: (iso: string) => string;
1487
1509
  footer?: ReactNode;
1488
1510
  stuck?: OutboxState['stuck'];
1489
1511
  history?: OrderHistoryRow[];
1512
+ onOpen?: (row: PosOrder | OrderHistoryRow) => void;
1490
1513
  }): react_jsx_runtime.JSX.Element;
1491
1514
 
1492
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
@@ -4378,7 +4378,7 @@ function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, onApp
4378
4378
 
4379
4379
  // src/sale/cart.tsx
4380
4380
  import { Fragment as Fragment6, jsx as jsx93, jsxs as jsxs51 } from "react/jsx-runtime";
4381
- function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal }) {
4381
+ function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }) {
4382
4382
  const { order } = sale;
4383
4383
  const money = (amount) => ({ amount, currency: order.currency });
4384
4384
  const { totals } = buildReceiptData(order, { storeName: "" });
@@ -4536,8 +4536,8 @@ function Cart({ sale, taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`, canEditPr
4536
4536
  CartTotal,
4537
4537
  {
4538
4538
  subtotal: money(totals.subtotalMinor),
4539
- discount: money(totals.discountMinor),
4540
4539
  total: money(totals.totalMinor),
4540
+ discount: money(couponDiscountMinor === void 0 ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor)),
4541
4541
  taxLines: taxRows,
4542
4542
  taxInclusive: totals.taxInclusive,
4543
4543
  afterSubtotal
@@ -4825,7 +4825,8 @@ function Catalogue({
4825
4825
  items,
4826
4826
  onQueryChange,
4827
4827
  showCategoryNav = false,
4828
- categories
4828
+ categories,
4829
+ pickAnyOptions = false
4829
4830
  }) {
4830
4831
  const [initial] = useState22(() => {
4831
4832
  const state2 = normalizeCatalogueViewState({ ...DEFAULT_CATALOGUE_VIEW_STATE, ...defaultViewState });
@@ -4897,14 +4898,35 @@ function Catalogue({
4897
4898
  useEffect5(() => {
4898
4899
  if (chooserId !== null && choices.length === 0) setChooserId(null);
4899
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]);
4900
4916
  function select(entry) {
4901
- onSelect(entry);
4917
+ const picking = pickAnyOptions && anyGroupsOf(entry).length > 0;
4918
+ closePicker();
4919
+ if (picking) setPickEntry(entry);
4920
+ else onSelect(entry);
4902
4921
  setChooserId(null);
4903
4922
  }
4904
4923
  function selectProduct(product) {
4905
4924
  const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
4906
4925
  if (variants.length === 1) select(variants[0]);
4907
- else setChooserId(traits.getId(product));
4926
+ else {
4927
+ closePicker();
4928
+ setChooserId(traits.getId(product));
4929
+ }
4908
4930
  }
4909
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." });
4910
4932
  return /* @__PURE__ */ jsxs55(View62, { className: "flex-1", onLayout: (event) => setWidth(event.nativeEvent.layout.width), children: [
@@ -4945,7 +4967,24 @@ function Catalogue({
4945
4967
  onSelect: (id) => changeState({ type: "setCategory", categoryId: id === "" ? null : id })
4946
4968
  }
4947
4969
  ) : null,
4948
- 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: [
4949
4988
  choices.map((entry) => /* @__PURE__ */ jsxs55(
4950
4989
  Pressable32,
4951
4990
  {
@@ -5025,27 +5064,25 @@ function orderReference(order) {
5025
5064
  // src/sale/receipt.tsx
5026
5065
  import { Fragment as Fragment9, jsx as jsx98, jsxs as jsxs56 } from "react/jsx-runtime";
5027
5066
  var defaultFormatDate = (iso) => new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso));
5028
- function Receipt({
5029
- order,
5030
- posOrder,
5031
- store,
5032
- cashier,
5033
- registerId,
5034
- registerName,
5035
- newSale,
5036
- taxLabel = (ratePpm) => `Tax ${ratePpm / 1e4}%`,
5037
- topInset = 0,
5038
- formatDate = defaultFormatDate,
5039
- footerSlot
5040
- }) {
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;
5041
5077
  useEffect6(injectPrintStyle, []);
5042
- const receipt = buildReceiptData3(order, {
5043
- storeName: store.name,
5044
- storeAddress: store.address,
5045
- cashier,
5046
- register: registerId,
5047
- registerName
5048
- });
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;
5049
5086
  const money = (amount) => formatMoney16({ amount, currency: receipt.currency }) ?? "";
5050
5087
  const row = (label, amount, bold = false, key) => /* @__PURE__ */ jsxs56(View63, { accessibilityLabel: `${label}: ${amount}`, className: "flex-row justify-between gap-4", children: [
5051
5088
  /* @__PURE__ */ jsx98(Text41, { className: `text-foreground ${bold ? "font-semibold" : ""}`, children: label }),
@@ -5059,12 +5096,13 @@ function Receipt({
5059
5096
  /* @__PURE__ */ jsxs56(View63, { className: "w-full max-w-md self-center gap-3 p-4 bg-card", children: [
5060
5097
  /* @__PURE__ */ jsx98(Text41, { className: "text-lg font-semibold text-foreground", children: receipt.header.storeName }),
5061
5098
  receipt.header.storeAddress ? /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: receipt.header.storeAddress }) : null,
5062
- /* @__PURE__ */ jsx98(Text41, { testID: "receipt-order", className: "text-foreground", children: posOrder ? `Order ${orderReference(posOrder)}` : `Order ${receipt.header.orderNumber.slice(-8)} (draft)` }),
5063
- /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: formatDate(posOrder?.createdAt ?? receipt.header.date) }),
5064
- /* @__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: [
5065
5103
  "Cashier: ",
5066
5104
  receipt.header.cashier
5067
- ] }),
5105
+ ] }) : null,
5068
5106
  receipt.register.name ? /* @__PURE__ */ jsxs56(Text41, { testID: "receipt-register", className: "text-muted-foreground", children: [
5069
5107
  "Register: ",
5070
5108
  receipt.register.name
@@ -5077,10 +5115,10 @@ function Receipt({
5077
5115
  /* @__PURE__ */ jsx98(Text41, { className: "text-foreground", children: line.name }),
5078
5116
  Object.entries(line.attributes ?? {}).map(([name, value]) => /* @__PURE__ */ jsx98(Text41, { className: "text-muted-foreground", children: `${name}: ${value}` }, name)),
5079
5117
  row(`${line.quantity} \xD7 ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor)),
5080
- 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(
5081
5119
  order.lineItems[index].discounts[i],
5082
5120
  receipt.currency
5083
- )} off`, `\u2212${money(discount.amountMinor)}`) }, i))
5121
+ ) : discount.label} off`, `\u2212${money(discount.amountMinor)}`) }, i))
5084
5122
  ] }, index)),
5085
5123
  row("Subtotal", money(totals.subtotalMinor)),
5086
5124
  lineDiscountMinor > 0 ? row("Line discounts", `\u2212${money(lineDiscountMinor)}`) : null,
@@ -5090,18 +5128,18 @@ function Receipt({
5090
5128
  taxRows,
5091
5129
  row("Total", money(totals.totalMinor), true),
5092
5130
  receipt.payments.map((payment, index) => row(
5093
- payment.method === "cash" ? "Cash tendered" : "Card terminal",
5131
+ payment.method === "cash" ? "Cash tendered" : order || payment.method === "external" ? "Card terminal" : payment.method,
5094
5132
  money(payment.amountMinor) + (payment.reference ? ` \xB7 ${payment.reference}` : ""),
5095
5133
  false,
5096
5134
  index
5097
5135
  )),
5098
- row("Change", money(receipt.changeDueMinor)),
5136
+ order || receipt.changeDueMinor > 0 ? row("Change", money(receipt.changeDueMinor)) : null,
5099
5137
  footerSlot ? /* @__PURE__ */ jsx98(View63, { testID: "receipt-footer", className: "mt-3 items-center border-t border-dashed border-border pt-3", children: footerSlot }) : null,
5100
5138
  /* @__PURE__ */ jsxs56(View63, { dataSet: { print: "hide" }, className: "flex-row gap-4", children: [
5101
5139
  /* @__PURE__ */ jsx98(Pressable33, { accessibilityRole: "button", onPress: () => {
5102
5140
  if (typeof window !== "undefined" && typeof window.print === "function") window.print();
5103
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" }) }),
5104
- /* @__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 }) })
5105
5143
  ] })
5106
5144
  ] })
5107
5145
  ] });
@@ -5233,7 +5271,7 @@ function defaultFormatDate2(iso) {
5233
5271
  const date = new Date(iso);
5234
5272
  return Number.isNaN(date.getTime()) ? iso : new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short" }).format(date);
5235
5273
  }
5236
- function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history }) {
5274
+ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen }) {
5237
5275
  const retrying = useRef8(/* @__PURE__ */ new Set());
5238
5276
  const [retryingIds, setRetryingIds] = useState24(/* @__PURE__ */ new Set());
5239
5277
  const [expanded, setExpanded] = useState24(/* @__PURE__ */ new Set());
@@ -5266,7 +5304,18 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
5266
5304
  formatMoney17({ amount: row.totalMinor, currency: row.currency }),
5267
5305
  " \xB7 ",
5268
5306
  row.stateLabel
5269
- ] })
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
5270
5319
  ] }, `history:${row.id}`);
5271
5320
  }
5272
5321
  const count2 = order.lines.reduce((sum, line) => sum + line.quantity, 0);
@@ -5300,6 +5349,17 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
5300
5349
  ]
5301
5350
  }
5302
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,
5303
5363
  isExpanded ? /* @__PURE__ */ jsxs58(View65, { testID: `order-detail-${order.id}`, className: "mt-1 gap-1 border-t border-border pt-2", children: [
5304
5364
  order.lines.map((line) => /* @__PURE__ */ jsx100(Text43, { className: "text-foreground", children: `${line.quantity} \xD7 ${line.name}` }, line.id)),
5305
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.11.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.11.0",
32
- "@tallyui/primitives": "^3.11.0",
33
- "@tallyui/theme": "^3.11.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.11.0"
40
+ "@tallyui/pos": "3.12.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@tallyui/connector-medusa": "3.11.0",
44
- "@tallyui/connector-vendure": "3.11.0",
45
- "@tallyui/connector-woocommerce": "3.11.0",
46
- "@tallyui/mock-api": "3.11.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",
package/src/sale/cart.tsx CHANGED
@@ -9,7 +9,7 @@ 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, afterSubtotal }:
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. */
@@ -18,6 +18,10 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
18
18
  onPriceChange?: (change: { lineId: string; fromMinor: number; toMinor: number; reason?: string }) => void;
19
19
  /** Rows under the totals' Subtotal, e.g. the platform's coupon chips (passed to CartTotal). */
20
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;
21
25
  }) {
22
26
  const { order } = sale;
23
27
  const money = (amount: number) => ({ amount, currency: order.currency });
@@ -96,7 +100,8 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
96
100
  </View> : null}</>}
97
101
  footer={<View testID="cart-footer" className="gap-3 pb-4">
98
102
  {/* Exclusive: subtotal − discount + tax = total. Inclusive: subtotal − discount = total, the tax "incl.", not added. */}
99
- <CartTotal subtotal={money(totals.subtotalMinor)} discount={money(totals.discountMinor)} total={money(totals.totalMinor)}
103
+ <CartTotal subtotal={money(totals.subtotalMinor)} total={money(totals.totalMinor)}
104
+ discount={money(couponDiscountMinor === undefined ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor))}
100
105
  taxLines={taxRows} taxInclusive={totals.taxInclusive} afterSubtotal={afterSubtotal} />
101
106
  {sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
102
107
  <View className="flex-row gap-3">
@@ -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,9 +57,11 @@ 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}>
@@ -51,8 +69,8 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
51
69
  {Object.entries(line.attributes ?? {}).map(([name, value]) => <Text key={name} className="text-muted-foreground">{`${name}: ${value}`}</Text>)}
52
70
  {/* Before any discount, then the line's own discounts as sub-rows (TallyUI ADR-063); they add up to the subtotal. */}
53
71
  {row(`${line.quantity} × ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor))}
54
- {line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${discountLabel(
55
- 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>)}
56
74
  </View>)}
57
75
  {/* Each discount appears once in the totals: line discounts are itemised under their lines and summed once here;
58
76
  the order discount appears once. order.display's figures (ADR-063; medusapos ADR 0008). */}
@@ -64,15 +82,16 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
64
82
  {receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), false, index))}
65
83
  {taxRows}
66
84
  {row('Total', money(totals.totalMinor), true)}
67
- {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,
68
87
  money(payment.amountMinor) + (payment.reference ? ` · ${payment.reference}` : ''), false, index))}
69
- {row('Change', money(receipt.changeDueMinor))}
88
+ {order || receipt.changeDueMinor > 0 ? row('Change', money(receipt.changeDueMinor)) : null}
70
89
  {footerSlot ? <View testID="receipt-footer" className="mt-3 items-center border-t border-dashed border-border pt-3">{footerSlot}</View> : null}
71
90
  <View dataSet={{ print: 'hide' }} className="flex-row gap-4">
72
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">
73
92
  <Text className="text-center text-foreground">Print receipt</Text>
74
93
  </Pressable>
75
- <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>
76
95
  </View>
77
96
  </View></>;
78
97
  }