@tallyui/components 3.12.0 → 3.14.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.
Files changed (60) hide show
  1. package/dist/index.d.ts +466 -28
  2. package/dist/index.js +3194 -1574
  3. package/package.json +9 -9
  4. package/src/cart/cart-columns.tsx +57 -0
  5. package/src/cart/cart-line.tsx +32 -17
  6. package/src/cart/index.ts +1 -0
  7. package/src/checkout/cash-tendered.tsx +5 -7
  8. package/src/fonts/font-provider.tsx +65 -0
  9. package/src/fonts/index.ts +1 -0
  10. package/src/index.ts +40 -2
  11. package/src/lib/error-text.ts +5 -0
  12. package/src/order/index.ts +2 -0
  13. package/src/order/refund-form.tsx +205 -0
  14. package/src/order/refund-modal.tsx +32 -0
  15. package/src/product/category-tile.tsx +43 -0
  16. package/src/product/in-cart-badge.tsx +26 -0
  17. package/src/product/index.ts +2 -0
  18. package/src/register/closure-sheet.tsx +13 -2
  19. package/src/register/handover-slip.tsx +46 -0
  20. package/src/register/index.ts +2 -0
  21. package/src/register/movement-sheet.tsx +2 -1
  22. package/src/register/open-register-card.tsx +2 -1
  23. package/src/register/register-bar.tsx +57 -11
  24. package/src/register/register-column.tsx +2 -1
  25. package/src/register/register-count.tsx +30 -11
  26. package/src/register/register-panel.tsx +45 -4
  27. package/src/register/switch-confirm.tsx +102 -0
  28. package/src/reports/cards.tsx +197 -0
  29. package/src/reports/filters-bar.tsx +95 -0
  30. package/src/reports/hero.tsx +111 -0
  31. package/src/reports/index.ts +4 -0
  32. package/src/reports/sales-room.tsx +28 -0
  33. package/src/sale/cart.tsx +37 -21
  34. package/src/sale/catalogue.tsx +34 -5
  35. package/src/sale/customer-display-screen.tsx +92 -0
  36. package/src/sale/index.ts +5 -2
  37. package/src/sale/open-sale-tabs.tsx +67 -0
  38. package/src/sale/order-reference.ts +3 -0
  39. package/src/sale/orders-list.tsx +4 -2
  40. package/src/sale/parked-sales.tsx +2 -1
  41. package/src/sale/price-form.tsx +28 -4
  42. package/src/sale/product-filter-bar.tsx +58 -0
  43. package/src/sale/receipt.tsx +8 -2
  44. package/src/sale/tender-pane.tsx +179 -0
  45. package/src/sale/tender.tsx +20 -35
  46. package/src/scale/index.ts +3 -0
  47. package/src/scale/scale-provider.tsx +70 -0
  48. package/src/scale/use-pointer.ts +23 -0
  49. package/src/settings/display-settings.tsx +122 -0
  50. package/src/settings/index.ts +1 -0
  51. package/src/shell/app-shell.tsx +71 -0
  52. package/src/shell/index.ts +4 -0
  53. package/src/shell/nav-drawer.tsx +130 -0
  54. package/src/shell/nav-item.tsx +70 -0
  55. package/src/shell/nav-rail.tsx +58 -0
  56. package/src/shell/shell-context.ts +18 -0
  57. package/src/ui/icon/menu-icon.tsx +10 -0
  58. package/src/ui/text/font-text.tsx +25 -0
  59. package/src/ui/text/index.tsx +5 -4
  60. package/src/sale/split-tender.tsx +0 -81
@@ -3,10 +3,12 @@ import { Pressable, Text, View } from 'react-native';
3
3
  import { useStockOverlaid, useStockOverlayAsOf, type ProductTraits, type ProductCategory } from '@tallyui/core';
4
4
  import { catalogueEntries, findEntryByCode, searchProducts, variantPriceLabel, sortProducts, productSortValue,
5
5
  catalogueViewReducer, normalizeCatalogueViewState, resolveGridColumns, DEFAULT_CATALOGUE_VIEW_STATE,
6
- listCategories, inCategory,
7
- type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction } from '@tallyui/pos';
6
+ listCategories, inCategory, cartQuantities,
7
+ type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction, type CartQuantityLine } from '@tallyui/pos';
8
8
  import { ProductGrid, ProductImage, ProductPrice, ProductStockBadge, ProductTitle, ProductTable, ViewToggle, CategoryNav } from '../product';
9
9
  import { ProductVariantPicker } from '../product/product-variant-picker';
10
+ import { InCartBadge } from '../product/in-cart-badge';
11
+ import { ProductFilterBar, DEFAULT_PRODUCT_FILTERS, type ProductFilterChip, type ProductFilters } from './product-filter-bar';
10
12
  import { SearchInput } from '../input';
11
13
  import { VStack } from '../ui';
12
14
 
@@ -35,7 +37,8 @@ function laterOf(a: Date | null | undefined, b: Date | null | undefined): Date |
35
37
  }
36
38
 
37
39
  export function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength,
38
- viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories, pickAnyOptions = false }: {
40
+ viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories, pickAnyOptions = false,
41
+ cartLines, showFilterBar = false, filterChips = ['inStock'], filters: filtersProp, onFiltersChange }: {
39
42
  products: Doc[];
40
43
  traits: ProductTraits<Doc>;
41
44
  currency: string;
@@ -85,6 +88,16 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
85
88
  onQueryChange?: (query: string) => void;
86
89
  /** 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
90
  pickAnyOptions?: boolean;
91
+ /** The open sale's lines (e.g. useSale's order.lineItems); each grid tile shows its product's summed quantity. */
92
+ cartLines?: readonly CartQuantityLine[];
93
+ /** Show v2's filter chips under the search box. Default false. */
94
+ showFilterBar?: boolean;
95
+ /** Which chips the bar shows. Default ['inStock'], the one Catalogue applies itself. */
96
+ filterChips?: readonly ProductFilterChip[];
97
+ /** Controlled filters; changes are reported through onFiltersChange. */
98
+ filters?: ProductFilters;
99
+ /** The cashier's next filters (requested filters when controlled). */
100
+ onFiltersChange?: (filters: ProductFilters) => void;
88
101
  }) {
89
102
  const [initial] = useState<{
90
103
  state: CatalogueViewState; loaded?: CatalogueViewState; pending?: Promise<unknown>; failed?: boolean; error?: unknown;
@@ -130,6 +143,14 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
130
143
  }
131
144
  }
132
145
 
146
+ const [internalFilters, setInternalFilters] = useState(DEFAULT_PRODUCT_FILTERS);
147
+ const filters = filtersProp ?? internalFilters;
148
+ function changeFilters(next: ProductFilters) {
149
+ if (filtersProp === undefined) setInternalFilters(next);
150
+ onFiltersChange?.(next);
151
+ }
152
+ const quantities = useMemo(() => cartQuantities(cartLines ?? []), [cartLines]);
153
+
133
154
  const isLoading = loading ?? (lastSyncedAt === null && pullError == null);
134
155
  // Idempotent (the adapter's overlay returns just the fields the stock map sets), so an app that already
135
156
  // merges the overlay itself keeps working, and can drop its own merge.
@@ -148,12 +169,16 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
148
169
  const [width, setWidth] = useState(0);
149
170
  const columns = resolveGridColumns(state.gridColumns, width);
150
171
  const entries = useMemo(() => catalogueEntries(shown, traits, { currency }), [shown, traits, currency]);
172
+ // v2's In Stock pill is stock_status 'instock', so it drops backorders too; a stock the backend did not report stays.
173
+ const stockFiltered = showFilterBar && filters.inStock;
151
174
  const results = useMemo(() => {
152
175
  if (items !== undefined) return suppliedItems;
153
- const filtered = searchProducts(activeCategory
176
+ const matched = searchProducts(activeCategory
154
177
  ? shown.filter((doc) => inCategory(doc, activeCategory.id, traits)) : shown, query, traits);
178
+ const filtered = stockFiltered
179
+ ? matched.filter((doc) => !['out_of_stock', 'backorder'].includes(traits.getStock(doc).status)) : matched;
155
180
  return state.sort ? sortProducts(filtered, state.sort, (doc, field) => productSortValue(doc, field, traits, { currency })) : filtered;
156
- }, [items, suppliedItems, shown, query, traits, state.sort, currency, showCategoryNav, activeCategory]);
181
+ }, [items, suppliedItems, shown, query, traits, state.sort, currency, showCategoryNav, activeCategory, stockFiltered]);
157
182
  const choices = useMemo(() => (chooserId === null ? []
158
183
  : entries.filter((entry) => traits.getId(entry.product) === chooserId)), [entries, chooserId, traits]);
159
184
  // A product that leaves the catalogue (a resync, or no longer sellable) closes its chooser.
@@ -197,6 +222,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
197
222
 
198
223
  const emptyState = <Text className="mt-10 text-center text-sm text-muted-foreground">
199
224
  {query.trim() ? `No products match "${query.trim()}".` : activeCategory ? `No products in ${activeCategory.name}.`
225
+ : stockFiltered && items === undefined && shown.length > 0 ? 'No products in stock.'
200
226
  : isLoading ? 'Loading products…' : 'No products yet.'}
201
227
  </Text>;
202
228
 
@@ -209,6 +235,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
209
235
  const entry = findEntryByCode(entries, query);
210
236
  if (entry) { select(entry); setQuery(''); }
211
237
  }} />
238
+ {showFilterBar ? <ProductFilterBar value={filters} onChange={changeFilters} chips={filterChips} /> : null}
212
239
  {(statusText || statusAccessory || showViewToggle) ? (
213
240
  <View testID="catalogue-status-row" className="flex-row items-center gap-2">
214
241
  {statusText ? <Text className="flex-1 text-xs text-muted-foreground" numberOfLines={statusAccessory ? 1 : undefined}>
@@ -265,6 +292,8 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
265
292
  <ProductPrice doc={product} />
266
293
  <ProductStockBadge doc={product} showAsOf={false} className="self-center" />
267
294
  </VStack>
295
+ <InCartBadge count={quantities.get(traits.getId(product)) ?? 0} className="absolute right-2 top-2"
296
+ testID={`in-cart-${traits.getId(product)}`} />
268
297
  </Pressable>
269
298
  )}
270
299
  emptyState={emptyState} />}
@@ -0,0 +1,92 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Image, ScrollView, Text, View } from 'react-native';
3
+ import { formatMoney } from '@tallyui/core';
4
+ import type { DisplayPayment, DisplayState, ReceiptData } from '@tallyui/pos';
5
+
6
+ // English copy from WCPOS v2's display (Pro packages/display/src/sample-snapshot.json); config.i18n overrides it.
7
+ const COPY = {
8
+ welcome: 'Welcome', your_items: 'Your items', items_appear_here: 'Your items will appear here', subtotal: 'Subtotal',
9
+ discount: 'Discount', total_tax: 'Tax', included_tax: 'Tax included', total: 'Total', paid_so_far: 'Paid so far',
10
+ present_card: 'Please present your card', approved: 'Approved', declined: 'Declined',
11
+ try_another_card: 'Please try another card or ask staff', paid_in_full: 'Paid in full', change: 'Change',
12
+ thank_you: 'Thank you',
13
+ };
14
+
15
+ const CARD = { started: 'bg-primary', approved: 'bg-success', complete: 'bg-success', declined: 'bg-destructive' };
16
+ const CARD_TEXT = { started: 'text-primary-foreground', approved: 'text-success-foreground',
17
+ complete: 'text-success-foreground', declined: 'text-destructive-foreground' };
18
+
19
+ /**
20
+ * What the customer sees on the second screen, laid out as WCPOS v2's default "Ledger" display
21
+ * (Pro templates/display.html): idle shows the store; cart and payment show the items on the left and a panel on the
22
+ * right with the totals, or the payment card.
23
+ */
24
+ export function CustomerDisplayScreen({ state }: { state: DisplayState }) {
25
+ const { config, view } = state;
26
+ const t = (key: keyof typeof COPY) => config?.i18n[key] ?? COPY[key];
27
+ if (view.screen === 'idle') {
28
+ const logo = config?.store.logo;
29
+ return <View testID="customer-display-idle" className="flex-1 items-center justify-center gap-6 bg-primary p-8">
30
+ {logo ? <Image source={{ uri: logo }} accessibilityLabel={config.store.name} resizeMode="contain" style={{ width: 320, height: 180 }} />
31
+ : <Text className="text-5xl font-bold text-primary-foreground">{config?.store.name ?? ''}</Text>}
32
+ <Text className="text-2xl text-primary-foreground">{t('welcome')}</Text>
33
+ </View>;
34
+ }
35
+ const { receipt } = view.cart;
36
+ const money = (amount: number) => formatMoney({ amount, currency: receipt.currency }, config?.store.locale) ?? '';
37
+ const row = (label: string, amount: string, key?: string) => <View key={key} className="flex-row justify-between gap-4 py-1">
38
+ <Text className="text-lg text-muted-foreground">{label}</Text><Text className="text-lg text-muted-foreground">{amount}</Text>
39
+ </View>;
40
+ const total = <View className="mt-3 flex-row items-baseline justify-between gap-4 border-t-2 border-foreground pt-4">
41
+ <Text className="text-base font-semibold uppercase text-foreground">{t('total')}</Text>
42
+ <Text className="text-4xl font-bold text-foreground">{money(receipt.totals.totalMinor)}</Text>
43
+ </View>;
44
+ return <View testID={`customer-display-${view.screen}`} className="flex-1 flex-col bg-card sm:flex-row">
45
+ <ScrollView className="flex-1" contentContainerClassName="p-8 sm:p-12">
46
+ <Text className="mb-5 text-sm font-semibold uppercase text-muted-foreground">{t('your_items')}</Text>
47
+ {receipt.lineItems.length === 0 ? <Text className="py-8 text-center text-xl text-muted-foreground">{t('items_appear_here')}</Text> : null}
48
+ {receipt.lineItems.map((line, index) => <View key={index} className="flex-row items-baseline gap-4 border-b border-border py-4">
49
+ <Text className="w-14 text-xl text-muted-foreground">{`${line.quantity} ×`}</Text>
50
+ <View className="flex-1">
51
+ <Text className="text-xl font-semibold text-foreground">{line.name}</Text>
52
+ {Object.entries(line.attributes ?? {}).map(([name, value]) => <Text key={name} className="text-base text-muted-foreground">{`${name}: ${value}`}</Text>)}
53
+ </View>
54
+ <Text className="text-xl font-semibold text-foreground">{money(line.displayAmountMinor)}</Text>
55
+ </View>)}
56
+ </ScrollView>
57
+ <View className="justify-end border-t border-border p-8 sm:w-96 sm:border-l sm:border-t-0">
58
+ <Text className="mb-auto text-lg font-bold text-foreground">{config?.store.name ?? receipt.header.storeName}</Text>
59
+ {view.screen === 'cart' ? <View>
60
+ {row(t('subtotal'), money(receipt.totals.subtotalMinor))}
61
+ {receipt.fees.map((charge, index) => row(charge.name, money(charge.amountMinor), `fee-${index}`))}
62
+ {receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), `shipping-${index}`))}
63
+ {receipt.totals.discountMinor > 0 ? row(t('discount'), `-${money(receipt.totals.discountMinor)}`) : null}
64
+ {receipt.totals.taxMinor > 0 ? row(t(receipt.totals.taxInclusive ? 'included_tax' : 'total_tax'), money(receipt.totals.taxMinor)) : null}
65
+ {total}
66
+ </View> : <PaymentCard receipt={receipt} payment={view.payment} money={money} t={t}>{total}</PaymentCard>}
67
+ </View>
68
+ </View>;
69
+ }
70
+
71
+ function PaymentCard({ receipt, payment, money, t, children }: {
72
+ receipt: ReceiptData; payment: DisplayPayment; money: (amount: number) => string; t: (key: keyof typeof COPY) => string;
73
+ children: ReactNode;
74
+ }) {
75
+ const paid = receipt.payments.reduce((sum, { amountMinor }) => sum + amountMinor, 0);
76
+ const due = Math.max(0, receipt.totals.totalMinor - paid);
77
+ const complete = payment.state === 'complete';
78
+ const title = { started: t('present_card'), approved: t('approved'), declined: t('declined'), complete: t('paid_in_full') }[payment.state];
79
+ const message = complete ? t('thank_you') : payment.message ?? (payment.state === 'declined' ? t('try_another_card') : undefined);
80
+ const text = CARD_TEXT[payment.state];
81
+ return <View className="gap-4">
82
+ {complete ? null : <View>{children}{paid > 0 ? <View className="flex-row justify-between py-1">
83
+ <Text className="text-lg text-success">{t('paid_so_far')}</Text><Text className="text-lg text-success">{money(paid)}</Text>
84
+ </View> : null}</View>}
85
+ <View className={`gap-2 rounded-xl p-6 ${CARD[payment.state]}`}>
86
+ <Text className={`text-sm font-semibold uppercase ${text}`}>{title}</Text>
87
+ <Text className={`text-4xl font-bold ${text}`}>{money(complete ? receipt.totals.totalMinor : payment.leg?.amountMinor ?? due)}</Text>
88
+ {complete && receipt.changeDueMinor > 0 ? <Text className={`text-lg ${text}`}>{`${t('change')} ${money(receipt.changeDueMinor)}`}</Text> : null}
89
+ {message ? <Text className={`text-lg ${text}`}>{message}</Text> : null}
90
+ </View>
91
+ </View>;
92
+ }
package/src/sale/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Cart } from './cart';
2
2
  export { CartBar } from './cart-bar';
3
- export { Tender } from './tender';
4
- export { SplitTender } from './split-tender';
3
+ export { Tender, SplitTender } from './tender';
4
+ export { TenderPane, type TenderPaneProps } from './tender-pane';
5
5
  export { DiscountForm, DiscountChips, parseDiscount, discountLabel } from './discount-form';
6
6
  export { PriceForm, parsePrice } from './price-form';
7
7
  export { ChargeForm, type ChargeFormProps } from './charge-form';
@@ -12,3 +12,6 @@ export { injectPrintStyle } from './print-style';
12
12
  export { SyncStatus } from './sync-status';
13
13
  export { OrdersList, type OrderHistoryRow } from './orders-list';
14
14
  export { ParkedSales, type ParkedSalesProps } from './parked-sales';
15
+ export { OpenSaleTabs, type OpenSaleTabsProps } from './open-sale-tabs';
16
+ export { ProductFilterBar, DEFAULT_PRODUCT_FILTERS, PRODUCT_FILTER_CHIPS, type ProductFilterBarProps, type ProductFilterChip, type ProductFilters } from './product-filter-bar';
17
+ export { CustomerDisplayScreen } from './customer-display-screen';
@@ -0,0 +1,67 @@
1
+ import type { JSX } from 'react';
2
+ import { Pressable, ScrollView, View } from 'react-native';
3
+ import { formatMoney } from '@tallyui/core';
4
+ import type { OpenSale } from '@tallyui/pos';
5
+ import { Text } from '../ui/text';
6
+
7
+ /** Pass `openSales(sale.order, useParkedSales(drafts).parked)`; `onSelect` and `onNew` call `sale.switchSale(id)` and `sale.switchSale(null)`. */
8
+ export interface OpenSaleTabsProps {
9
+ sales: OpenSale[];
10
+ currency: string;
11
+ onSelect: (id: string) => void;
12
+ onNew: () => void;
13
+ }
14
+
15
+ /** v2 cart/tab-who.ts: the customer, or what is in the cart when the customer is a guest. */
16
+ function who(sale: OpenSale): string {
17
+ if (sale.customerName) return sale.customerName;
18
+ if (sale.itemCount === 0) return 'Guest';
19
+ return `Guest · ${sale.itemCount === 1 && sale.firstItem ? sale.firstItem : `${sale.itemCount} ${sale.itemCount === 1 ? 'item' : 'items'}`}`;
20
+ }
21
+
22
+ /**
23
+ * The open sales as cart tabs (v2 cart/tabs.tsx): who, then the Partly paid chip or else the total. The open sale's
24
+ * tab is underlined even when it is the only one; a blank cart has no tab, the + cell is its tab and reads "New".
25
+ */
26
+ export function OpenSaleTabs({ sales, currency, onSelect, onNew }: OpenSaleTabsProps): JSX.Element {
27
+ const blank = !sales.some((sale) => sale.current);
28
+ return (
29
+ <View testID="open-sale-tabs" className="h-14 flex-row items-stretch border-t border-border bg-card">
30
+ <ScrollView horizontal accessibilityRole="tablist" showsHorizontalScrollIndicator={false} className="min-w-0 flex-1">
31
+ {sales.map((sale) => {
32
+ // isPartlyPaid from @tallyui/pos, inlined: components import only types from pos (v2 cart/tab-chip.tsx).
33
+ const partly = sale.paidMinor > 0 && sale.balanceDueMinor > 0;
34
+ const status = `Partly paid · ${formatMoney({ amount: sale.balanceDueMinor, currency })} due`;
35
+ return (
36
+ <Pressable key={sale.id} testID={`open-sale-tab-${sale.id}`} accessibilityRole="tab"
37
+ accessibilityState={{ selected: sale.current }} aria-selected={sale.current} onPress={() => onSelect(sale.id)}
38
+ className={`h-full justify-center border-b-2 px-3 ${sale.current ? 'border-primary' : 'border-transparent'}`}>
39
+ <Text testID={`open-sale-tab-${sale.id}-who`} numberOfLines={1}
40
+ className={sale.current ? 'font-semibold text-foreground' : 'font-medium text-muted-foreground'}>{who(sale)}</Text>
41
+ {partly && !sale.current ? (
42
+ // Inactive tabs carry the chip; the open tab keeps only the muted words (v2 TabChip).
43
+ <View testID={`open-sale-chip-${sale.id}`} className="flex-row items-center gap-1 self-start rounded-sm bg-info/15 px-1.5 py-0.5">
44
+ <View className="h-1.5 w-1.5 rounded-full bg-info" />
45
+ <Text className="text-xs font-semibold text-foreground">{status}</Text>
46
+ </View>
47
+ ) : partly ? (
48
+ <Text testID={`open-sale-status-${sale.id}`} className="text-xs text-muted-foreground">{status}</Text>
49
+ ) : (
50
+ <Text testID={`open-sale-tab-${sale.id}-amount`} className="text-xs text-muted-foreground tabular-nums">
51
+ {formatMoney({ amount: sale.totalMinor, currency })}
52
+ </Text>
53
+ )}
54
+ </Pressable>
55
+ );
56
+ })}
57
+ </ScrollView>
58
+ <Pressable testID="new-sale-tab" accessibilityRole="tab" accessibilityLabel="New order" accessibilityState={{ selected: blank }} aria-selected={blank}
59
+ // Already on the blank cart: + is a place, not an action (v2).
60
+ onPress={() => { if (!blank) onNew(); }}
61
+ className={`h-full flex-row items-center justify-center gap-1.5 px-3 ${blank ? 'border-b-2 border-primary' : ''}`}>
62
+ <Text className={blank ? 'text-primary' : 'text-foreground'}>+</Text>
63
+ {blank && <Text testID="new-sale-tab-label" className="font-semibold">New</Text>}
64
+ </Pressable>
65
+ </View>
66
+ );
67
+ }
@@ -4,3 +4,6 @@ export function orderReference(order: { id: string; serverRefs?: { displayId?: s
4
4
  const local = order.id.slice(-8);
5
5
  return order.serverRefs?.displayId ? `${local} · #${order.serverRefs.displayId}` : local;
6
6
  }
7
+
8
+ /** The receipt and Orders say this under a note that went below order.create 7 (ADR-083 condition 2). */
9
+ export const NOTE_NOT_SENT = "The note couldn't be sent to the store.";
@@ -1,8 +1,8 @@
1
1
  import { useEffect, useRef, useState, type ReactNode } from 'react';
2
2
  import { Pressable, ScrollView, Text, View } from 'react-native';
3
3
  import { formatMoney, knownWarnings } from '@tallyui/core';
4
- import { isRequeueable, needsAttention, type OutboxState, type PosOrder } from '@tallyui/pos';
5
- import { orderReference } from './order-reference';
4
+ import { isRequeueable, needsAttention, noteDelivery, type OutboxState, type PosOrder } from '@tallyui/pos';
5
+ import { NOTE_NOT_SENT, orderReference } from './order-reference';
6
6
  import { sinceText } from './since-text';
7
7
 
8
8
  /** One order from the store's own history (ADR-052 amendment 1), mapped by the app from its platform. */
@@ -113,6 +113,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
113
113
  {order.payments.map((payment) => <Text key={payment.id} className="text-muted-foreground">
114
114
  {`${payment.method === 'cash' ? 'Cash' : 'Card terminal'} ${formatMoney({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` · ${payment.reference}` : ''}`}
115
115
  </Text>)}
116
+ {order.note ? <Text testID={`order-note-${order.id}`} className="text-foreground">{`Note: ${order.note}`}</Text> : null}
116
117
  </View> : null}
117
118
  {stuckEntry ? <Text className="text-destructive">
118
119
  {/* The same words for any reason, with no reason code; the hour as the status line has it (numeric, #245). */}
@@ -127,6 +128,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
127
128
  ? `The customer's ${warning.field} couldn't be sent to the store, so the order isn't linked to them.`
128
129
  : "The terminal's payment reference couldn't be kept; the payment is recorded without it."}
129
130
  </Text>)}
131
+ {noteDelivery(order) === 'not_sent' ? <Text testID={`order-note-not-sent-${order.id}`} className="text-foreground">{NOTE_NOT_SENT}</Text> : null}
130
132
  {/* Retry is offered only for a code the outbox resends (isRequeueable). */}
131
133
  {section.title === 'Needs attention' && order.syncStatus === 'rejected' && isRequeueable(order.error?.code)
132
134
  ? <Pressable accessibilityRole="button" disabled={retryingIds.has(order.id)} onPress={async () => {
@@ -2,6 +2,7 @@ import { useState, type JSX } from 'react';
2
2
  import { ScrollView, useWindowDimensions, View } from 'react-native';
3
3
  import { formatMoney } from '@tallyui/core';
4
4
  import type { ParkedOrderSummary, useSale } from '@tallyui/pos';
5
+ import { errorText } from '../lib/error-text';
5
6
  import { Button } from '../ui/button';
6
7
  import { Dialog, DialogClose, DialogContent, DialogTitle } from '../ui/dialog';
7
8
  import { IconButton } from '../ui/icon-button';
@@ -33,7 +34,7 @@ export function ParkedSales({ sale, parked, onDiscard, onPark, onResume, currenc
33
34
  try {
34
35
  await action();
35
36
  } catch (e) {
36
- setError(String(e));
37
+ setError(errorText(e));
37
38
  }
38
39
  };
39
40
 
@@ -15,26 +15,50 @@ export function parsePrice(text: string, currency: string): number | string {
15
15
  }
16
16
 
17
17
  const button = 'rounded-md border border-border px-3 py-2 min-h-11 items-center justify-center';
18
+ /** v2's price keypad draws three quick keys (`QUICK_KEYS`, WCPOS `components/src/price-keypad/index.tsx`). */
19
+ const QUICK_KEYS = 3;
20
+
21
+ /** `currentMinor` less `percent` (to two places), half up at the minor unit, as v2's `draftPrice` rounds. */
22
+ const lessPercent = (currentMinor: number, percent: number) =>
23
+ Math.round(currentMinor * (10000 - Math.round(percent * 100)) / 10000);
18
24
 
19
25
  /** `onApply` returns a refusal to show inline, or null once applied. */
20
- export function PriceForm({ lineName, currency, currentMinor, onApply, onClose }: {
26
+ export function PriceForm({ lineName, currency, currentMinor, onApply, onClose, quickDiscounts = [] }: {
21
27
  lineName: string; currency: string; currentMinor: number;
22
28
  onApply: (amountMinor: number, reason?: string) => string | null; onClose: () => void;
29
+ /** Percentages off the current price, as v2's price-keypad keys; the first three valid ones (0 < n ≤ 100) are drawn. */
30
+ quickDiscounts?: readonly number[];
23
31
  }): JSX.Element {
24
32
  const [text, setText] = useState('');
25
33
  const [reason, setReason] = useState('');
26
34
  const [error, setError] = useState<string | null>(null);
35
+ // The lit key (v2's reducer): pressing it again puts the current price back; typing starts over.
36
+ const [percent, setPercent] = useState<number | undefined>();
37
+ const keys = quickDiscounts.filter((n) => Number.isFinite(n) && n > 0 && n <= 100).slice(0, QUICK_KEYS);
27
38
  const title = `Price for ${lineName}`;
39
+ const current = formatMoney({ amount: currentMinor, currency });
40
+ const draft = percent === undefined ? undefined : lessPercent(currentMinor, percent);
28
41
  function apply() {
29
- const parsed = parsePrice(text, currency);
42
+ const parsed = draft ?? parsePrice(text, currency);
30
43
  const refused = typeof parsed === 'string' ? parsed : onApply(parsed, reason.trim() || undefined);
31
44
  setError(refused);
32
45
  if (refused === null) onClose();
33
46
  }
34
47
  return <View testID="price-form" role="group" accessibilityLabel={title} className="gap-2 px-3 py-2">
35
48
  <Text className="font-semibold text-foreground">{title}</Text>
36
- <Text className="text-muted-foreground">{formatMoney({ amount: currentMinor, currency })}</Text>
37
- <TextInput testID="price-input" accessibilityLabel="Price value" value={text} onChangeText={setText}
49
+ {draft === undefined ? <Text className="text-muted-foreground">{current}</Text>
50
+ : <Text testID="price-quick-draft" className="text-muted-foreground">
51
+ {`${current} −${percent}% → ${formatMoney({ amount: draft, currency })}`}</Text>}
52
+ {keys.length ? <View testID="price-quick-discounts" className="flex-row gap-2">
53
+ {keys.map((key) => <Pressable key={key} testID={`price-discount-${key}`} accessibilityRole="button"
54
+ accessibilityLabel={`Discount (${key}%)`} accessibilityState={{ selected: key === percent }}
55
+ aria-selected={key === percent} onPress={() => { setPercent(key === percent ? undefined : key); setText(''); setError(null); }}
56
+ className={`${button} flex-1 ${key === percent ? 'bg-primary' : 'bg-card'}`}>
57
+ <Text className={key === percent ? 'text-primary-foreground' : 'text-foreground'}>{`−${key}%`}</Text>
58
+ </Pressable>)}
59
+ </View> : null}
60
+ <TextInput testID="price-input" accessibilityLabel="Price value" value={text}
61
+ onChangeText={(next) => { setText(next); setPercent(undefined); }}
38
62
  onSubmitEditing={apply} inputMode="decimal" placeholder={currency}
39
63
  className="min-w-0 rounded-md border border-border bg-background px-3 py-2 text-foreground" />
40
64
  <TextInput testID="price-reason" accessibilityLabel="Reason (optional)" placeholder="Reason (optional)"
@@ -0,0 +1,58 @@
1
+ import { Pressable, ScrollView, Text, View } from 'react-native';
2
+ import { cn } from '@tallyui/theme';
3
+ import { XIcon } from '../ui/icon/x-icon';
4
+
5
+ // v2's built-in pills, in its order: packages/core/src/screens/main/pos/products/filter-bar/filter-bar-layout.ts
6
+ // `BUILT_IN_PILL_IDS` (MIT, WCPOS).
7
+ export type ProductFilterChip = 'inStock' | 'featured' | 'onSale' | 'category' | 'tag' | 'brand';
8
+ type ToggleChip = 'inStock' | 'featured' | 'onSale';
9
+ type TermChip = 'category' | 'tag' | 'brand';
10
+
11
+ export interface ProductFilters { inStock: boolean; featured: boolean; onSale: boolean }
12
+
13
+ /** In Stock starts on, as v2's `stock_status: 'instock'` does while "show out-of-stock products" is off (its default). */
14
+ export const DEFAULT_PRODUCT_FILTERS: ProductFilters = { inStock: true, featured: false, onSale: false };
15
+ export const PRODUCT_FILTER_CHIPS: readonly ProductFilterChip[] = ['inStock', 'featured', 'onSale', 'category', 'tag', 'brand'];
16
+
17
+ const LABELS: Record<ProductFilterChip, string> = {
18
+ inStock: 'In Stock', featured: 'Featured', onSale: 'On Sale', category: 'Category', tag: 'Tag', brand: 'Brand',
19
+ };
20
+
21
+ export interface ProductFilterBarProps {
22
+ value: ProductFilters;
23
+ onChange: (next: ProductFilters) => void;
24
+ /** Which chips to show, in this order. Default PRODUCT_FILTER_CHIPS. */
25
+ chips?: readonly ProductFilterChip[];
26
+ /** Opens the app's term picker; the category, tag and brand chips render only when it is given. */
27
+ onTermPress?: (chip: TermChip) => void;
28
+ className?: string;
29
+ }
30
+
31
+ function isToggle(chip: ProductFilterChip): chip is ToggleChip {
32
+ return chip === 'inStock' || chip === 'featured' || chip === 'onSale';
33
+ }
34
+
35
+ /**
36
+ * v2's always-on filter chips above the product grid: In Stock, Featured and On Sale toggle; Category, Tag
37
+ * and Brand open the app's term picker. Ported from WCPOS v2 `FilterBar`,
38
+ * packages/core/src/screens/main/pos/products/filter-bar/filter-bar.tsx (MIT, WCPOS).
39
+ */
40
+ export function ProductFilterBar({ value, onChange, chips = PRODUCT_FILTER_CHIPS, onTermPress, className }: ProductFilterBarProps) {
41
+ const shown = chips.filter((chip) => isToggle(chip) || onTermPress);
42
+ return (
43
+ <ScrollView horizontal showsHorizontalScrollIndicator={false} className={className} contentContainerClassName="flex-row gap-2">
44
+ {shown.map((chip) => {
45
+ const on = isToggle(chip) && value[chip];
46
+ return (
47
+ <Pressable key={chip} testID={`filter-chip-${chip}`} role="button" aria-pressed={isToggle(chip) ? on : undefined}
48
+ onPress={() => (isToggle(chip) ? onChange({ ...value, [chip]: !value[chip] }) : onTermPress?.(chip))}
49
+ className={cn('min-h-11 flex-row items-center gap-1.5 rounded-full border px-3',
50
+ on ? 'border-primary/30 bg-primary/10' : 'border-border bg-card')}>
51
+ <Text className={cn('text-sm', on ? 'text-primary' : 'text-foreground')}>{LABELS[chip]}</Text>
52
+ {on && chip === 'inStock' ? <View className="text-primary"><XIcon size={14} /></View> : null}
53
+ </Pressable>
54
+ );
55
+ })}
56
+ </ScrollView>
57
+ );
58
+ }
@@ -1,11 +1,11 @@
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 ReceiptData, type SentOrder } from '@tallyui/pos';
4
+ import { buildReceiptData, noteDelivery, 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';
8
- import { orderReference } from './order-reference';
8
+ import { NOTE_NOT_SENT, 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
 
@@ -86,6 +86,12 @@ export function Receipt(props: ReceiptProps) {
86
86
  : order || payment.method === 'external' ? 'Card terminal' : payment.method,
87
87
  money(payment.amountMinor) + (payment.reference ? ` · ${payment.reference}` : ''), false, index))}
88
88
  {order || receipt.changeDueMinor > 0 ? row('Change', money(receipt.changeDueMinor)) : null}
89
+ {receipt.footer.note ? <View testID="receipt-note" className="gap-1">
90
+ <Text className="text-foreground">{receipt.footer.note}</Text>
91
+ {/* ADR-083 condition 2: for the cashier, so it is not printed. */}
92
+ {receipt.footer.noteNotSent || (posOrder !== undefined && noteDelivery(posOrder) === 'not_sent')
93
+ ? <View dataSet={{ print: 'hide' }}><Text testID="receipt-note-not-sent" className="text-destructive">{NOTE_NOT_SENT}</Text></View> : null}
94
+ </View> : null}
89
95
  {footerSlot ? <View testID="receipt-footer" className="mt-3 items-center border-t border-dashed border-border pt-3">{footerSlot}</View> : null}
90
96
  <View dataSet={{ print: 'hide' }} className="flex-row gap-4">
91
97
  <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">