@tallyui/components 3.18.0 → 3.20.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 +473 -37
  2. package/dist/index.js +3656 -1905
  3. package/package.json +9 -9
  4. package/src/cart/cart-columns.tsx +42 -4
  5. package/src/cart/cart-foot.tsx +2 -2
  6. package/src/cart/cart-line.tsx +42 -18
  7. package/src/cart/cart-note-input.tsx +10 -2
  8. package/src/cart/cart-panel.tsx +4 -1
  9. package/src/cart/cart-total.tsx +8 -5
  10. package/src/cart/index.ts +1 -1
  11. package/src/customer/customer-select.tsx +21 -3
  12. package/src/index.ts +27 -0
  13. package/src/input/search-input.tsx +1 -1
  14. package/src/order/index.ts +1 -0
  15. package/src/order/order-filter-bar.tsx +247 -0
  16. package/src/product/camera-scan-button.tsx +28 -0
  17. package/src/product/camera-scanner-panel.tsx +156 -0
  18. package/src/product/index.ts +5 -0
  19. package/src/product/product-table.tsx +14 -4
  20. package/src/product/scanner-viewfinder.tsx +76 -0
  21. package/src/product/variation-picker.tsx +128 -0
  22. package/src/register/register-bar.tsx +2 -6
  23. package/src/register/register-panel.tsx +47 -24
  24. package/src/register/register-side-sheet.tsx +175 -0
  25. package/src/reports/date-range-menu.tsx +109 -0
  26. package/src/reports/filters-bar.tsx +11 -21
  27. package/src/reports/hero.tsx +8 -4
  28. package/src/reports/index.ts +1 -0
  29. package/src/sale/cart.tsx +49 -10
  30. package/src/sale/catalogue.tsx +98 -21
  31. package/src/sale/charge-form.tsx +12 -6
  32. package/src/sale/customer-display-pairing.tsx +111 -0
  33. package/src/sale/index.ts +1 -0
  34. package/src/sale/line-popover.tsx +17 -1
  35. package/src/sale/order-reference.ts +1 -1
  36. package/src/sale/orders-list.tsx +1 -1
  37. package/src/settings/customer-display-settings.tsx +163 -0
  38. package/src/settings/index.ts +2 -0
  39. package/src/settings/tax-calculation-settings.tsx +97 -0
  40. package/src/shell/nav-drawer.tsx +1 -1
  41. package/src/tax/index.ts +1 -0
  42. package/src/tax/tax-based-on.tsx +196 -0
  43. package/src/ui/alert-dialog/index.tsx +1 -1
  44. package/src/ui/avatar/index.tsx +22 -4
  45. package/src/ui/button/index.tsx +1 -1
  46. package/src/ui/calendar/index.tsx +119 -0
  47. package/src/ui/calendar/month-grid.ts +40 -0
  48. package/src/ui/combobox/index.tsx +1 -1
  49. package/src/ui/dialog/index.tsx +21 -9
  50. package/src/ui/icon/chevron-down-icon.tsx +4 -0
  51. package/src/ui/icon/grip-icon.tsx +10 -0
  52. package/src/ui/icon/scan-icon.tsx +13 -0
  53. package/src/ui/icon/shopping-cart-icon.tsx +10 -0
  54. package/src/ui/icon-button/index.tsx +1 -1
  55. package/src/ui/index.ts +11 -1
  56. package/src/ui/input/index.tsx +1 -1
  57. package/src/ui/select/index.tsx +22 -4
  58. package/src/ui/slider/index.tsx +2 -2
  59. package/src/ui/switch/index.tsx +19 -8
  60. package/src/ui/textarea/index.tsx +1 -1
@@ -0,0 +1,128 @@
1
+ // Port of WCPOS v2 (monorepo next) packages/core/src/screens/main/pos/products/variations-popover/ (variations.tsx,
2
+ // buttons.tsx, select.tsx, stock-status.tsx): one option per attribute group, the match's stock, and Add; MIT, WCPOS.
3
+ import { useMemo, useState } from 'react';
4
+ import { Pressable, ScrollView, View } from 'react-native';
5
+ import type { StockLevel, VariantOptionGroup, VariantSummary } from '@tallyui/core';
6
+ import { disabledOptions, matchVariant, variantPriceLabel } from '@tallyui/pos';
7
+ import { cn } from '@tallyui/theme';
8
+ import { Button } from '../ui/button';
9
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
10
+ import { Text } from '../ui/text';
11
+
12
+ export interface VariationPickerProps {
13
+ /** The product name. */
14
+ title: string;
15
+ groups: VariantOptionGroup[];
16
+ variants: VariantSummary[];
17
+ currency: string;
18
+ /** Called with the matched variant and the picks for the variant's "Any" groups (empty when it has none). */
19
+ onAdd: (variant: VariantSummary, anyPicks: Record<string, string>) => void | Promise<void>;
20
+ /** Stock refuses Add when the variant is out of stock and this is true (v2 preventOverselling). Default false. */
21
+ preventOverselling?: boolean;
22
+ testID?: string;
23
+ }
24
+
25
+ // v2 shows buttons when a group's values total fewer than this many characters, a Select otherwise.
26
+ const CHIP_CHARACTERS = 15;
27
+
28
+ // ProductStockBadge's label vocabulary; v2 shows nothing for stock it does not track.
29
+ function stockLabel({ status, quantity }: StockLevel): string | null {
30
+ if (status === 'out_of_stock') return 'Out of Stock';
31
+ if (status === 'backorder') return 'On Backorder';
32
+ if (status === 'in_stock' && quantity != null) return `In Stock (${quantity})`;
33
+ return null;
34
+ }
35
+
36
+ /**
37
+ * v2's variations popover body: the cashier picks one value per option group (values no variant allows are
38
+ * dimmed), sees the matched variant's stock, and presses Add; a full match never adds on its own.
39
+ */
40
+ export function VariationPicker({ title, groups, variants, currency, onAdd, preventOverselling = false,
41
+ testID = 'variation-popover' }: VariationPickerProps) {
42
+ const [picks, setPicks] = useState<Record<string, string>>({});
43
+ const [adding, setAdding] = useState(false);
44
+ const disabled = useMemo(() => disabledOptions(variants, groups, picks), [variants, groups, picks]);
45
+ const complete = groups.every(({ name }) => picks[name] !== undefined);
46
+ const variant = complete ? matchVariant(variants, groups, picks) : undefined;
47
+ const stock = variant ? stockLabel(variant.stock) : null;
48
+ const price = variant ? variantPriceLabel(variant, currency) : undefined;
49
+ const refused = preventOverselling && variant?.stock.status === 'out_of_stock';
50
+
51
+ const pick = (name: string, value: string, toggle: boolean) => {
52
+ if (disabled[name]?.has(value)) return;
53
+ setPicks((current) => {
54
+ const { [name]: previous, ...rest } = current;
55
+ return toggle && previous === value ? rest : { ...rest, [name]: value };
56
+ });
57
+ };
58
+
59
+ const add = async () => {
60
+ if (!variant || adding || refused) return;
61
+ const anyPicks = Object.fromEntries(groups.filter(({ name }) =>
62
+ !Object.prototype.hasOwnProperty.call(variant.options ?? {}, name)).map(({ name }) => [name, picks[name]]));
63
+ const pending = onAdd(variant, anyPicks);
64
+ if (!(pending instanceof Promise)) return;
65
+ setAdding(true);
66
+ try {
67
+ await pending;
68
+ } finally {
69
+ setAdding(false);
70
+ }
71
+ };
72
+
73
+ return (
74
+ <View testID={testID} className="min-h-0 min-w-52 shrink gap-3">
75
+ <Text className="text-sm font-semibold">{title}</Text>
76
+ <ScrollView testID="variation-popover-options" className="shrink grow-0" contentContainerClassName="gap-3">
77
+ {groups.map(({ name, values }) => (
78
+ <View key={name} className="gap-1.5">
79
+ <Text className="text-xs font-semibold text-muted-foreground">{name}</Text>
80
+ {values.join('').length < CHIP_CHARACTERS ? (
81
+ <View className="flex-row flex-wrap gap-2">
82
+ {values.map((value) => {
83
+ const active = picks[name] === value;
84
+ const off = disabled[name]?.has(value) ?? false;
85
+ return (
86
+ <Pressable key={value} testID={`variation-option-${value}`} accessibilityRole="button"
87
+ accessibilityState={{ selected: active, disabled: off }} disabled={off}
88
+ onPress={() => pick(name, value, true)}
89
+ className={cn('rounded-lg border px-3 py-1.5', active ? 'border-primary bg-primary/10' : 'border-border bg-card',
90
+ off && 'opacity-40')}>
91
+ <Text className={cn('text-sm font-medium', active ? 'text-primary' : 'text-foreground')}>{value}</Text>
92
+ </Pressable>
93
+ );
94
+ })}
95
+ </View>
96
+ ) : (
97
+ <Select value={picks[name] ? { value: picks[name], label: picks[name] } : undefined}
98
+ onValueChange={(option) => { if (option) pick(name, option.value, false); }}>
99
+ <SelectTrigger testID={`variation-select-${name}`} accessibilityLabel={name}>
100
+ <SelectValue placeholder="Select an option" className="text-sm text-foreground" />
101
+ </SelectTrigger>
102
+ <SelectContent>
103
+ {values.map((value) => (
104
+ <SelectItem key={value} value={value} label={value} disabled={disabled[name]?.has(value)}
105
+ className={cn(disabled[name]?.has(value) && 'opacity-40')}>
106
+ <Text className="text-sm">{value}</Text>
107
+ </SelectItem>
108
+ ))}
109
+ </SelectContent>
110
+ </Select>
111
+ )}
112
+ </View>
113
+ ))}
114
+ </ScrollView>
115
+ {complete && !variant ? (
116
+ <Text testID="variation-popover-unavailable" className="text-sm text-muted-foreground">Variant not available</Text>
117
+ ) : null}
118
+ {variant ? (
119
+ <View className="gap-2">
120
+ {stock ? <Text testID="variation-popover-stock-badge" className="self-start text-xs font-semibold">{stock}</Text> : null}
121
+ <Button testID="variation-popover-add-to-cart" disabled={adding || refused} onPress={() => { void add(); }}>
122
+ <Text>{price ? `Add to Cart: ${price}` : 'Add to Cart'}</Text>
123
+ </Button>
124
+ </View>
125
+ ) : null}
126
+ </View>
127
+ );
128
+ }
@@ -4,7 +4,7 @@ import type { useRegisterSession } from '@tallyui/pos';
4
4
 
5
5
  import { cn } from '@tallyui/theme';
6
6
  import { useShell } from '../shell/shell-context';
7
- import { Avatar } from '../ui/avatar';
7
+ import { Avatar, avatarInitials } from '../ui/avatar';
8
8
  import { Badge } from '../ui/badge';
9
9
  import { Button } from '../ui/button';
10
10
  import { HStack } from '../ui/hstack';
@@ -37,10 +37,6 @@ export interface RegisterBarProps {
37
37
  className?: string;
38
38
  }
39
39
 
40
- function initials(name: string): string {
41
- return name.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('');
42
- }
43
-
44
40
  /**
45
41
  * The till's one status bar: the menu (phones), the place (the store, and the register for
46
42
  * multi-register stores), one status pill (LEDGER 48), the sync state, the button that opens the
@@ -123,7 +119,7 @@ export function RegisterBar({
123
119
  disabled={!cashier.onPress}
124
120
  onPress={cashier.onPress}
125
121
  >
126
- <Avatar size="sm" fallback={initials(cashier.name)} />
122
+ <Avatar size="sm" fallback={avatarInitials(cashier.name)} />
127
123
  </Pressable>
128
124
  )}
129
125
  </HStack>
@@ -11,6 +11,7 @@ import { XIcon } from '../ui/icon/x-icon';
11
11
  import { Text } from '../ui/text';
12
12
  import { MovementSheet } from './movement-sheet';
13
13
  import { tenderLabel } from './register-count';
14
+ import { RegisterSideFooter, RegisterSideHeader, RegisterSideHero, RegisterSideLedger } from './register-side-sheet';
14
15
 
15
16
  /** Margin kept clear above and below the dialog (LEDGER-free layout fix, 2026-09-28 review):
16
17
  * a phone-height viewport must never let the panel's top go under the page header. */
@@ -32,19 +33,34 @@ export interface RegisterPanelProps {
32
33
  */
33
34
  reapprove?: (needed: ApprovalNeeded) => Promise<{ approvedBy: string; approval: string } | null>;
34
35
  className?: string;
36
+ /**
37
+ * `'dialog'` (the default) is the centred panel; `'side'` is WCPOS v2's right-hand sheet (Paul,
38
+ * 2026-10-30: "Cashier and Register modal come from the right"): the cash expected, session
39
+ * sales, the drawer ledger, Other tenders, and a Print X-report / Close register footer.
40
+ */
41
+ presentation?: 'dialog' | 'side';
42
+ /** `'side'`: the store's name, first in the header line. */
43
+ storeName?: string;
44
+ /** `'side'`: builds and prints the X-report (`buildXReportDocument`); a rejection shows "Printing failed. Try again.". Without it, there is no button. */
45
+ onPrintXReport?: () => void | Promise<void>;
46
+ /** `'side'`: the clock for the session's age; defaults to `new Date()`. */
47
+ now?: () => Date;
35
48
  }
36
49
 
37
50
  /**
38
51
  * The register's drawer panel: expected figures, cash movements with Undo, and Close register.
39
52
  * Port provenance (ADR-032 amendment 1): WCPOS `next` `3b5331b5c` `register-panel.tsx` (LEDGER
40
- * 54, 56, 58).
53
+ * 54, 56, 58); `presentation="side"` follows WCPOS v2's side sheet (TallyUI#716).
41
54
  *
42
55
  * Leaves out (registers job c2 or a later job, per `useRegisterSession`'s own "Not ported"
43
56
  * note): refused-movement Retry and "Unsynced" (no outbox here to refuse a movement), the
44
- * X-report, Z and print/reprint, and the Reports deep link.
57
+ * Z, reprint and the print sheet, the last-closure badge, and the Reports deep link.
45
58
  */
46
- export function RegisterPanel({ register, currency, registerName, open, onOpenChange, reapprove, className }: RegisterPanelProps) {
47
- const { session, expected, salesCount, blind, movements, lastClosure, approvalNeeded, actions } = register;
59
+ export function RegisterPanel({
60
+ register, currency, registerName, open, onOpenChange, reapprove, className, presentation = 'dialog', storeName, onPrintXReport, now,
61
+ }: RegisterPanelProps) {
62
+ const { session, expected, salesCount, blind, movements, lastClosure, approvalNeeded, actions, terms } = register;
63
+ const side = presentation === 'side';
48
64
  const [reapproving, setReapproving] = useState(false);
49
65
  const otherTenders = Object.entries(expected).filter(([method, amount]) => method !== 'cash' && amount !== 0);
50
66
  const { height: windowHeight } = useWindowDimensions();
@@ -67,25 +83,36 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
67
83
  const activeMovements = movements.filter(
68
84
  (row) => row.type !== 'void' && !row.voided_by && !movements.some((entry) => entry.voids === row.id),
69
85
  );
86
+ const closeRegister = () =>
87
+ attempt(async () => {
88
+ await actions.startCounting();
89
+ onOpenChange(false);
90
+ });
91
+ // The side sheet is full height, so it needs no cap; its header and footer stay put, and only the body scrolls.
70
92
  return (
71
93
  <Dialog open={open} onOpenChange={onOpenChange}>
72
94
  <DialogContent
73
95
  testID="register-panel"
96
+ side={side ? 'right' : 'center'}
74
97
  className={`flex-col overflow-hidden ${className ?? ''}`}
75
- style={{ maxHeight }}
98
+ style={side ? undefined : { maxHeight }}
76
99
  >
77
100
  {/* The heading stays visible; a phone-height viewport must never push it under the page
78
101
  header (the Front desk review, 2026-09-28) — only the body below it scrolls. */}
79
102
  <View className="flex-row items-center justify-between gap-2">
80
- <DialogTitle testID="register-panel-amount">{registerName ?? 'Register'}</DialogTitle>
103
+ {side ? (
104
+ <RegisterSideHeader session={session} registerName={registerName} storeName={storeName} now={now} />
105
+ ) : (
106
+ <DialogTitle testID="register-panel-amount">{registerName ?? 'Register'}</DialogTitle>
107
+ )}
81
108
  <DialogClose asChild>
82
109
  <IconButton variant="ghost" size="sm" testID="register-panel-dismiss" accessibilityLabel="Close panel">
83
110
  <XIcon size={16} />
84
111
  </IconButton>
85
112
  </DialogClose>
86
113
  </View>
87
- <Text testID="register-panel-sales-count">{salesCount} sale{salesCount === 1 ? '' : 's'} this session</Text>
88
- <ScrollView testID="register-panel-body" className="flex-1" contentContainerClassName="gap-3">
114
+ {!side && <Text testID="register-panel-sales-count">{salesCount} sale{salesCount === 1 ? '' : 's'} this session</Text>}
115
+ <ScrollView testID="register-panel-body" className="flex-1" contentContainerClassName={side ? 'gap-4' : 'gap-3'}>
89
116
  {/* Here, not in RegisterCount: a refused closure's session is already closed, and the
90
117
  panel is what still shows once a closure exists. Title and button: WCPOS v2's
91
118
  `register.approval_needed` and `register.approve` (monorepo core.json:2974-2976). */}
@@ -119,6 +146,7 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
119
146
  )}
120
147
  </View>
121
148
  )}
149
+ {side && <RegisterSideHero terms={terms} blind={blind} currency={currency} salesCount={salesCount} />}
122
150
  <View className="flex-row gap-2">
123
151
  {(['paid_in', 'paid_out', 'no_sale'] as const).map((type) => (
124
152
  <Button
@@ -133,7 +161,8 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
133
161
  </Button>
134
162
  ))}
135
163
  </View>
136
- {!blind && (
164
+ {side && <RegisterSideLedger terms={terms} blind={blind} currency={currency} />}
165
+ {!side && !blind && (
137
166
  <View testID="register-panel-expected" className="gap-1">
138
167
  <Text className="text-muted-foreground text-sm font-semibold">Expected in the drawer</Text>
139
168
  {Object.entries(expected).filter(([method]) => method === 'cash').map(([method, amount]) => (
@@ -144,7 +173,7 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
144
173
  ))}
145
174
  </View>
146
175
  )}
147
- {!blind && otherTenders.length > 0 && (
176
+ {!side && !blind && otherTenders.length > 0 && (
148
177
  <View testID="register-panel-other-tenders" className="gap-1">
149
178
  <Text className="text-muted-foreground text-sm font-semibold">Other tenders</Text>
150
179
  {otherTenders.map(([method, amount]) => (
@@ -182,21 +211,15 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
182
211
  </View>
183
212
  ))}
184
213
  {!!error && <Text className="text-destructive">{error}</Text>}
185
- <Button
186
- testID="register-panel-close"
187
- disabled={!session}
188
- variant="outline"
189
- className="min-h-14"
190
- onPress={() =>
191
- attempt(async () => {
192
- await actions.startCounting();
193
- onOpenChange(false);
194
- })
195
- }
196
- >
197
- <Text>Close register</Text>
198
- </Button>
214
+ {!side && (
215
+ <Button testID="register-panel-close" disabled={!session} variant="outline" className="min-h-14" onPress={closeRegister}>
216
+ <Text>Close register</Text>
217
+ </Button>
218
+ )}
199
219
  </ScrollView>
220
+ {side && (
221
+ <RegisterSideFooter canPrint={!blind && !!session} onPrintXReport={onPrintXReport} canClose={!!session} onClose={closeRegister} />
222
+ )}
200
223
  {movementType && (
201
224
  <MovementSheet
202
225
  register={register}
@@ -0,0 +1,175 @@
1
+ import { useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Path, Rect } from 'react-native-svg';
4
+ import type { DrawerTerms, RegisterSession } from '@tallyui/pos';
5
+
6
+ import { formatMoney } from '@tallyui/core';
7
+ import { Button } from '../ui/button';
8
+ import { DialogDescription, DialogTitle } from '../ui/dialog';
9
+ import { createSvgIcon } from '../ui/icon/svg-icon';
10
+ import { Text } from '../ui/text';
11
+ import { tenderLabel } from './register-count';
12
+
13
+ /** The panel header's register mark (v2 `ToneDisc icon="register"`). */
14
+ export const RegisterIcon = createSvgIcon('RegisterIcon', () => (
15
+ <>
16
+ <Rect x={6} y={3} width={12} height={6} rx={1} />
17
+ <Path d="M12 9v3" />
18
+ <Rect x={3} y={12} width={18} height={9} rx={1} />
19
+ <Path d="M3 16h18" />
20
+ </>
21
+ ));
22
+
23
+ const clock = (date: Date) => `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
24
+
25
+ /**
26
+ * v2's header line (`register-panel.tsx:318-326`): store · open since {time} (or closed {time})
27
+ * · age · opener. The session row holds only the opener's id, never a name, so the opener is
28
+ * v2's own fallback, "Cashier" (`register.unknown_cashier`).
29
+ */
30
+ export function describeSession(session: RegisterSession | null, storeName: string | undefined, now: Date) {
31
+ const parts = [storeName];
32
+ if (session) {
33
+ const opened = new Date(session.opened_at_gmt);
34
+ const closed = session.status === 'closed' && session.closed_at_gmt ? new Date(session.closed_at_gmt) : null;
35
+ const minutes = Math.max(0, Math.floor(((closed ?? now).getTime() - opened.getTime()) / 60_000));
36
+ parts.push(closed ? `closed ${clock(closed)}` : `open since ${clock(opened)}`,
37
+ minutes >= 60 ? `${Math.floor(minutes / 60)} h ${minutes % 60} m` : `${minutes} m`, 'Cashier');
38
+ }
39
+ return parts.filter(Boolean).join(' · ');
40
+ }
41
+
42
+ /** The sheet's title block: the register mark, the register's name and the header line. */
43
+ export function RegisterSideHeader({ session, registerName, storeName, now }: {
44
+ session: RegisterSession | null; registerName?: string; storeName?: string; now?: () => Date;
45
+ }) {
46
+ return (
47
+ <View className="flex-1 flex-row items-center gap-3">
48
+ <View className="h-9 w-9 items-center justify-center rounded-md bg-muted">
49
+ <RegisterIcon size={18} />
50
+ </View>
51
+ <View className="flex-1 gap-1">
52
+ <DialogTitle testID="register-panel-title">{registerName ?? 'Register'}</DialogTitle>
53
+ <DialogDescription testID="register-panel-description">
54
+ {describeSession(session, storeName, now ? now() : new Date())}
55
+ </DialogDescription>
56
+ </View>
57
+ </View>
58
+ );
59
+ }
60
+
61
+ /**
62
+ * The fixed footer: Print X-report (when the host prints one; off while blind, without a
63
+ * session or while printing, and v2's "Printing failed. Try again." on a rejection) and Close
64
+ * register. v2's overdue label needs the close time, which `useRegisterSession` does not return.
65
+ */
66
+ export function RegisterSideFooter({ canPrint, onPrintXReport, canClose, onClose }: {
67
+ canPrint: boolean; onPrintXReport?: () => void | Promise<void>; canClose: boolean; onClose: () => void;
68
+ }) {
69
+ const [printing, setPrinting] = useState(false);
70
+ const [failed, setFailed] = useState(false);
71
+ const print = async (run: () => void | Promise<void>) => {
72
+ setPrinting(true);
73
+ setFailed(false);
74
+ try {
75
+ await run();
76
+ } catch {
77
+ setFailed(true);
78
+ } finally {
79
+ setPrinting(false);
80
+ }
81
+ };
82
+ return (
83
+ <View testID="register-panel-footer" className="gap-2 border-t border-border pt-4">
84
+ {failed && <Text testID="register-panel-print-error" className="text-destructive">Printing failed. Try again.</Text>}
85
+ <View className="flex-row gap-2">
86
+ {onPrintXReport && (
87
+ <Button
88
+ testID="register-panel-print"
89
+ variant="outline"
90
+ className="min-h-11 flex-1"
91
+ disabled={!canPrint || printing}
92
+ onPress={() => void print(onPrintXReport)}
93
+ >
94
+ <Text>Print X-report</Text>
95
+ </Button>
96
+ )}
97
+ <Button testID="register-panel-close" className="min-h-11 flex-1" disabled={!canClose} onPress={onClose}>
98
+ <Text>Close register</Text>
99
+ </Button>
100
+ </View>
101
+ </View>
102
+ );
103
+ }
104
+
105
+ function Line({ label, amount, testID, strong }: { label: string; amount?: string; testID?: string; strong?: boolean }) {
106
+ const weight = strong ? 'font-semibold' : '';
107
+ return (
108
+ <View testID={testID} className="min-h-11 flex-row items-center justify-between gap-2 border-b border-border">
109
+ <Text className={weight}>{label}</Text>
110
+ {amount !== undefined && <Text className={`tabular-nums ${weight}`}>{amount}</Text>}
111
+ </View>
112
+ );
113
+ }
114
+
115
+ interface FiguresProps {
116
+ terms: DrawerTerms | null;
117
+ blind: boolean;
118
+ currency: string;
119
+ }
120
+
121
+ /** The hero (cash expected, "in the drawer") and the session sales line; `—` and no sales while blind. */
122
+ export function RegisterSideHero({ terms, blind, currency, salesCount }: FiguresProps & { salesCount: number }) {
123
+ const shown = !blind && terms ? terms : null;
124
+ return (
125
+ <View className="gap-1">
126
+ <View testID="register-panel-hero" className="flex-row flex-wrap items-baseline gap-2">
127
+ <Text className="text-4xl font-semibold tabular-nums">
128
+ {shown ? formatMoney({ amount: shown.expected.cash ?? 0, currency }) : '—'}
129
+ </Text>
130
+ <Text className="text-muted-foreground">in the drawer</Text>
131
+ </View>
132
+ {shown && (
133
+ <View testID="register-panel-session-sales" className="flex-row flex-wrap gap-2">
134
+ <Text className="text-muted-foreground">Session sales</Text>
135
+ <Text className="font-semibold tabular-nums">
136
+ {`${formatMoney({ amount: shown.sessionSalesMinor, currency })} · ${salesCount} sale${salesCount === 1 ? '' : 's'}`}
137
+ </Text>
138
+ </View>
139
+ )}
140
+ </View>
141
+ );
142
+ }
143
+
144
+ /** The drawer ledger (v2 `register-panel.tsx:450-536`) and Other tenders; nothing while blind. */
145
+ export function RegisterSideLedger({ terms, blind, currency }: FiguresProps) {
146
+ if (blind || !terms) return null;
147
+ const money = (amount: number) => formatMoney({ amount, currency }) ?? '';
148
+ const rows = [
149
+ { label: 'Cash sales', term: terms.cashSales, sign: '' },
150
+ { label: 'Cash refunds', term: terms.cashRefunds, sign: '−' },
151
+ { label: 'Paid in', term: terms.paidIn, sign: '' },
152
+ { label: 'Paid out', term: terms.paidOut, sign: '−' },
153
+ ].filter((row) => row.term.count > 0);
154
+ const others = Object.entries(terms.otherTenders);
155
+ return (
156
+ <>
157
+ <View testID="register-panel-ledger">
158
+ <Line label="Float" amount={money(terms.floatMinor)} />
159
+ {rows.map(({ label, term, sign }) => (
160
+ <Line key={label} label={`${label} · ${term.count}`} amount={`${sign}${money(term.amountMinor)}`} />
161
+ ))}
162
+ {terms.noSales > 0 && <Line label={`No sale · ${terms.noSales}`} />}
163
+ <Line testID="register-panel-expected" label="Expected in the drawer" amount={money(terms.expected.cash ?? 0)} strong />
164
+ </View>
165
+ {others.length > 0 && (
166
+ <View testID="register-panel-other-tenders">
167
+ <Text className="text-muted-foreground text-sm font-semibold">Other tenders</Text>
168
+ {others.map(([method, term]) => (
169
+ <Line key={method} label={`${tenderLabel(method)} · ${term.count}`} amount={money(term.amountMinor)} />
170
+ ))}
171
+ </View>
172
+ )}
173
+ </>
174
+ );
175
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The Reports period menu: the date presets beside a range calendar, for a custom range. Port of
3
+ * WCPOS v2 `screens/main/reports/date-button.tsx` without its Pro licence locks; copy is v2's
4
+ * English (`core.json`). Presets are worked out in store time by pos `presetRange`.
5
+ */
6
+ import { useState, type JSX } from 'react';
7
+ import { Pressable, Text, useWindowDimensions, View } from 'react-native';
8
+ import { DATE_PRESETS, presetRange, type DatePreset, type DayRange, type StoreDay } from '@tallyui/pos';
9
+ import { cn } from '@tallyui/theme';
10
+ import { Calendar } from '../ui/calendar';
11
+ import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
12
+
13
+ export interface DateRangeMenuProps {
14
+ value: { preset: DatePreset | 'custom'; range: DayRange };
15
+ /** Called on a preset row (immediately) and on Done (the custom range). */
16
+ onChange: (next: { preset: DatePreset | 'custom'; range: DayRange }) => void;
17
+ /** IANA zone of the store, or 'device'. */
18
+ timezone: string;
19
+ /** The clock presets and today are worked out from; defaults to the time of the press. */
20
+ now?: () => Date;
21
+ /** The earliest store day the data covers; the calendar's min. Omitted: no min. */
22
+ earliestDay?: StoreDay;
23
+ testID?: string;
24
+ }
25
+
26
+ export const PRESET_LABELS: Record<DatePreset, string> = {
27
+ today: 'Today', yesterday: 'Yesterday', thisWeek: 'This Week',
28
+ lastWeek: 'Last Week', thisMonth: 'This Month', lastMonth: 'Last Month',
29
+ };
30
+ // v2's phone boundary (app-shell.tsx); below it the presets stack above the calendar.
31
+ const WIDE_MIN_WIDTH = 768;
32
+
33
+ const format = (day: string, options: Intl.DateTimeFormatOptions) =>
34
+ new Intl.DateTimeFormat('en-GB', { ...options, timeZone: 'UTC' }).format(new Date(`${day}T00:00:00Z`));
35
+ /** `10 Nov` for a store day. */
36
+ export const dayLabel = (day: string): string => format(day, { day: 'numeric', month: 'short' });
37
+ /** `10 Nov`, `3–10 Nov` or `28 Oct – 3 Nov`, as v2's `periodLabel`. */
38
+ export function rangeLabel({ from, to }: DayRange): string {
39
+ if (from === to) return dayLabel(from);
40
+ if (from.slice(0, 7) === to.slice(0, 7)) return `${format(from, { day: 'numeric' })}–${dayLabel(to)}`;
41
+ return `${dayLabel(from)} – ${dayLabel(to)}`;
42
+ }
43
+
44
+ export function DateRangeMenu({
45
+ value, onChange, timezone, now, earliestDay, testID = 'reports-period',
46
+ }: DateRangeMenuProps): JSX.Element {
47
+ const [open, setOpen] = useState(false);
48
+ const [draft, setDraft] = useState<DayRange>(value.range);
49
+ const { width } = useWindowDimensions();
50
+ const wide = width >= WIDE_MIN_WIDTH;
51
+ const clock = () => (now ?? (() => new Date()))();
52
+ const today = presetRange('today', clock(), timezone).from;
53
+ const openChange = (next: boolean) => {
54
+ if (next) setDraft(value.range);
55
+ setOpen(next);
56
+ };
57
+ const choose = (preset: DatePreset) => {
58
+ setOpen(false);
59
+ onChange({ preset, range: presetRange(preset, clock(), timezone) });
60
+ };
61
+ const done = () => {
62
+ const at = clock();
63
+ const preset = DATE_PRESETS.find((key) => {
64
+ const range = presetRange(key, at, timezone);
65
+ return range.from === draft.from && range.to === draft.to;
66
+ });
67
+ setOpen(false);
68
+ onChange({ preset: preset ?? 'custom', range: draft });
69
+ };
70
+ const label = value.preset === 'custom' ? 'Custom range' : PRESET_LABELS[value.preset];
71
+
72
+ return (
73
+ <Popover open={open} onOpenChange={openChange}>
74
+ <PopoverTrigger testID={testID} accessibilityRole="button"
75
+ className="rounded-md border border-border bg-card px-3 py-2">
76
+ <Text className="text-sm text-foreground">{`${label} · ${rangeLabel(value.range)}`}</Text>
77
+ </PopoverTrigger>
78
+ <PopoverContent testID={`${testID}-menu`} align="start" className="p-0"
79
+ style={{ width: wide ? Math.min(556, width) : Math.min(360, width) }}>
80
+ <View className={cn(wide && 'flex-row')}>
81
+ <View className={cn('gap-0.5 p-2', wide && 'w-48 shrink-0')}>
82
+ <Text className="px-2 py-1 text-xs font-medium text-muted-foreground">Date Range</Text>
83
+ {DATE_PRESETS.map((preset) => {
84
+ const selected = value.preset === preset;
85
+ return (
86
+ <Pressable key={preset} testID={`${testID}-${preset}`} accessibilityRole="button"
87
+ accessibilityState={{ selected }} aria-selected={selected} onPress={() => choose(preset)}
88
+ className={cn('rounded-md px-2 py-2 active:bg-accent', selected && 'bg-muted')}>
89
+ <Text className={cn('text-sm text-foreground', selected && 'font-medium')}>{PRESET_LABELS[preset]}</Text>
90
+ </Pressable>
91
+ );
92
+ })}
93
+ </View>
94
+ <View className="flex-1 p-2">
95
+ <Calendar testID={`${testID}-calendar`} mode="range" value={draft} onChange={setDraft}
96
+ today={today} max={today} min={earliestDay} />
97
+ </View>
98
+ </View>
99
+ <View className="flex-row items-center gap-2 border-t border-border p-2">
100
+ <Text className="flex-1 text-sm text-muted-foreground">Tap a day, or two days for a range.</Text>
101
+ <Pressable testID={`${testID}-apply`} accessibilityRole="button" onPress={done}
102
+ className="h-10 justify-center rounded-md bg-primary px-4 active:opacity-90">
103
+ <Text className="text-sm font-medium text-primary-foreground">Done</Text>
104
+ </Pressable>
105
+ </View>
106
+ </PopoverContent>
107
+ </Popover>
108
+ );
109
+ }
@@ -5,12 +5,15 @@
5
5
  */
6
6
  import { useState, type JSX } from 'react';
7
7
  import { Pressable, Text, View } from 'react-native';
8
- import { DATE_PRESETS, presetRange, type DatePreset, type DayRange } from '@tallyui/pos';
8
+ import type { DatePreset, DayRange, StoreDay } from '@tallyui/pos';
9
9
  import { cn } from '@tallyui/theme';
10
+ import { DateRangeMenu } from './date-range-menu';
11
+
12
+ export { dayLabel } from './date-range-menu';
10
13
 
11
14
  export interface SalesOption { value: string; label: string }
12
15
  export interface SalesFilters {
13
- preset: DatePreset;
16
+ preset: DatePreset | 'custom';
14
17
  range: DayRange;
15
18
  /** A single day's comparison: the day before or the same weekday last week. */
16
19
  compare: 'previous' | 'week';
@@ -25,21 +28,15 @@ export interface SalesFiltersBarProps {
25
28
  timezone: string;
26
29
  /** The clock presets are worked out from; defaults to the time of the press. */
27
30
  now?: () => Date;
31
+ /** The earliest store day the data covers; the calendar's min. */
32
+ earliestDay?: StoreDay;
28
33
  statusOptions: SalesOption[];
29
34
  cashierOptions: SalesOption[];
30
35
  registerOptions: SalesOption[];
31
36
  }
32
37
 
33
- const PRESET_LABELS: Record<DatePreset, string> = {
34
- today: 'Today', yesterday: 'Yesterday', thisWeek: 'This Week',
35
- lastWeek: 'Last Week', thisMonth: 'This Month', lastMonth: 'Last Month',
36
- };
37
38
  const ALL = 'all';
38
39
 
39
- /** `10 Nov` for a store day. */
40
- export const dayLabel = (day: string): string =>
41
- new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' }).format(new Date(`${day}T00:00:00Z`));
42
-
43
40
  function ChoiceSelect({ id, value, options, onChange }: {
44
41
  id: string; value: string; options: SalesOption[]; onChange: (value: string) => void;
45
42
  }): JSX.Element {
@@ -68,20 +65,13 @@ function ChoiceSelect({ id, value, options, onChange }: {
68
65
  }
69
66
 
70
67
  export function SalesFiltersBar({
71
- filters, onFiltersChange, timezone, now, statusOptions, cashierOptions, registerOptions,
68
+ filters, onFiltersChange, timezone, now, earliestDay, statusOptions, cashierOptions, registerOptions,
72
69
  }: SalesFiltersBarProps): JSX.Element {
73
- const { range } = filters;
74
70
  return (
75
71
  <View testID="sales-filters" className="flex-row flex-wrap items-start gap-2">
76
- <ChoiceSelect id="sales-filter-period" value={filters.preset}
77
- options={DATE_PRESETS.map((preset) => ({ value: preset, label: PRESET_LABELS[preset] }))}
78
- onChange={(value) => {
79
- const preset = value as DatePreset;
80
- onFiltersChange({ ...filters, preset, range: presetRange(preset, (now ?? (() => new Date()))(), timezone) });
81
- }} />
82
- <Text testID="sales-filter-dates" className="py-2 text-sm text-muted-foreground">
83
- {range.from === range.to ? dayLabel(range.from) : `${dayLabel(range.from)} – ${dayLabel(range.to)}`}
84
- </Text>
72
+ <DateRangeMenu testID="sales-filter-period" value={{ preset: filters.preset, range: filters.range }}
73
+ timezone={timezone} now={now} earliestDay={earliestDay}
74
+ onChange={({ preset, range }) => onFiltersChange({ ...filters, preset, range })} />
85
75
  <ChoiceSelect id="sales-filter-status" value={filters.status} options={statusOptions}
86
76
  onChange={(status) => onFiltersChange({ ...filters, status })} />
87
77
  <ChoiceSelect id="sales-filter-cashier" value={filters.cashierId ?? ALL}