@tallyui/components 3.18.0 → 3.19.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 +460 -34
- package/dist/index.js +3632 -1898
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +42 -4
- package/src/cart/cart-line.tsx +42 -18
- package/src/cart/cart-note-input.tsx +10 -2
- package/src/cart/index.ts +1 -1
- package/src/customer/customer-select.tsx +21 -3
- package/src/index.ts +27 -0
- package/src/order/index.ts +1 -0
- package/src/order/order-filter-bar.tsx +247 -0
- package/src/product/camera-scan-button.tsx +28 -0
- package/src/product/camera-scanner-panel.tsx +156 -0
- package/src/product/index.ts +5 -0
- package/src/product/scanner-viewfinder.tsx +76 -0
- package/src/product/variation-picker.tsx +128 -0
- package/src/register/register-bar.tsx +2 -6
- package/src/register/register-panel.tsx +47 -24
- package/src/register/register-side-sheet.tsx +175 -0
- package/src/reports/date-range-menu.tsx +109 -0
- package/src/reports/filters-bar.tsx +11 -21
- package/src/reports/hero.tsx +8 -4
- package/src/reports/index.ts +1 -0
- package/src/sale/cart.tsx +44 -8
- package/src/sale/catalogue.tsx +98 -21
- package/src/sale/charge-form.tsx +12 -6
- package/src/sale/customer-display-pairing.tsx +111 -0
- package/src/sale/index.ts +1 -0
- package/src/sale/line-popover.tsx +17 -1
- package/src/sale/order-reference.ts +1 -1
- package/src/sale/orders-list.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +163 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/tax-calculation-settings.tsx +97 -0
- package/src/tax/index.ts +1 -0
- package/src/tax/tax-based-on.tsx +196 -0
- package/src/ui/avatar/index.tsx +22 -4
- package/src/ui/button/index.tsx +1 -1
- package/src/ui/calendar/index.tsx +119 -0
- package/src/ui/calendar/month-grid.ts +40 -0
- package/src/ui/combobox/index.tsx +1 -1
- package/src/ui/dialog/index.tsx +20 -8
- package/src/ui/icon/chevron-down-icon.tsx +4 -0
- package/src/ui/icon/grip-icon.tsx +10 -0
- package/src/ui/icon/scan-icon.tsx +13 -0
- package/src/ui/icon/shopping-cart-icon.tsx +10 -0
- package/src/ui/icon-button/index.tsx +1 -1
- package/src/ui/index.ts +11 -1
- package/src/ui/input/index.tsx +1 -1
- package/src/ui/select/index.tsx +22 -4
- package/src/ui/switch/index.tsx +18 -7
- package/src/ui/textarea/index.tsx +1 -1
|
@@ -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 {
|
|
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
|
-
<
|
|
77
|
-
|
|
78
|
-
onChange={(
|
|
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}
|
package/src/reports/hero.tsx
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { JSX } from 'react';
|
|
8
8
|
import { Pressable, Text, View } from 'react-native';
|
|
9
9
|
import { formatMoney } from '@tallyui/core';
|
|
10
|
-
import type
|
|
10
|
+
import { daysOf, type SalesFigures } from '@tallyui/pos';
|
|
11
11
|
import { cn } from '@tallyui/theme';
|
|
12
12
|
import { Card } from '../ui/card';
|
|
13
13
|
import { dayLabel, type SalesFilters } from './filters-bar';
|
|
@@ -33,9 +33,13 @@ function Difference({ testID, text, diff, suffix }: { testID: string; text?: str
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** A custom range compares as pos `comparisonRange` does by day count: a day, a week (up to 7) or a month. */
|
|
37
|
+
const customDays = (filters: SalesFilters) => (filters.preset === 'custom' ? daysOf(filters.range).length : 0);
|
|
38
|
+
|
|
36
39
|
function compareLabel(filters: SalesFilters): string {
|
|
37
|
-
|
|
38
|
-
if (filters.preset === '
|
|
40
|
+
const days = customDays(filters);
|
|
41
|
+
if (filters.preset === 'thisWeek' || filters.preset === 'lastWeek' || (days > 1 && days <= 7)) return 'vs the week before';
|
|
42
|
+
if (filters.preset === 'thisMonth' || filters.preset === 'lastMonth' || days > 7) return 'vs the month before';
|
|
39
43
|
if (filters.compare === 'previous') return 'vs yesterday';
|
|
40
44
|
const weekday = new Intl.DateTimeFormat('en-GB', { weekday: 'long', timeZone: 'UTC' }).format(new Date(`${filters.range.from}T00:00:00Z`));
|
|
41
45
|
return `vs last ${weekday}`;
|
|
@@ -56,7 +60,7 @@ export function SalesHero({ figures, filters, onFiltersChange, currency }: Sales
|
|
|
56
60
|
const compareSeries = figures.comparison?.series ?? [];
|
|
57
61
|
const max = Math.max(0, ...series.map((point) => point.grossMinor), ...compareSeries.map((point) => point.grossMinor));
|
|
58
62
|
const height = (gross: number) => `${max > 0 ? (Math.max(0, gross) / max) * 100 : 0}%` as const;
|
|
59
|
-
const oneDay = filters.preset === 'today' || filters.preset === 'yesterday';
|
|
63
|
+
const oneDay = filters.preset === 'today' || filters.preset === 'yesterday' || customDays(filters) === 1;
|
|
60
64
|
|
|
61
65
|
return (
|
|
62
66
|
<Card testID="sales-hero" className="gap-4 p-4">
|
package/src/reports/index.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { SalesRoom, type SalesRoomProps } from './sales-room';
|
|
|
2
2
|
export { SalesHero, type SalesHeroProps } from './hero';
|
|
3
3
|
export { SalesCards, type SalesCardsProps, type SalesCardId } from './cards';
|
|
4
4
|
export { SalesFiltersBar, type SalesFiltersBarProps, type SalesFilters, type SalesOption } from './filters-bar';
|
|
5
|
+
export { DateRangeMenu, type DateRangeMenuProps } from './date-range-menu';
|
package/src/sale/cart.tsx
CHANGED
|
@@ -5,13 +5,17 @@ import { buildReceiptData } from '@tallyui/pos';
|
|
|
5
5
|
import type { useSale } from '@tallyui/pos';
|
|
6
6
|
import { CartColumnHeads, CartFoot, CartLine, CartLineActions, CartPanel, CartTotal, type CartFootAction } from '../cart';
|
|
7
7
|
import { cartShowsPrice } from '../cart/cart-columns';
|
|
8
|
+
import type { CartColumnSettings } from '../cart/cart-columns';
|
|
8
9
|
import { DiscountChips, DiscountForm } from './discount-form';
|
|
9
10
|
import { PriceForm } from './price-form';
|
|
10
11
|
import { ChargeForm } from './charge-form';
|
|
11
12
|
import { LinePopover } from './line-popover';
|
|
13
|
+
import { ShoppingCartIcon } from '../ui';
|
|
12
14
|
|
|
13
15
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
14
|
-
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, couponDiscountMinor, orderActions = true, checkout, lineEditor = 'inline'
|
|
16
|
+
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, couponDiscountMinor, orderActions = true, checkout, lineEditor = 'inline',
|
|
17
|
+
columns,
|
|
18
|
+
emptyIcon = <ShoppingCartIcon size={48} />, emptyText = 'Tap a product to start a sale' }:
|
|
15
19
|
{ sale: ReturnType<typeof useSale>; taxLabel?: (ratePpm: number) => string;
|
|
16
20
|
taxClasses?: ReadonlyArray<{ id: string; label: string }>;
|
|
17
21
|
/** Shows a Price action on each line. Pass the till's own permission; the control isn't shown without it. */
|
|
@@ -33,10 +37,22 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
33
37
|
* ⋮ menu lists `actions`. Absent: the Cash and Card terminal row. */
|
|
34
38
|
checkout?: { onCheckout: () => void; actions?: readonly CartFootAction[] };
|
|
35
39
|
/** `popover`: tapping a line's quantity or price opens v2's keypad (WCPOS cart cells/quantity-keypad.tsx and
|
|
36
|
-
* cells/price.tsx), the price one with the quick-discount keys
|
|
40
|
+
* cells/price.tsx), the price one with the quick-discount keys and the struck regular price. Popover mode draws no
|
|
41
|
+
* button row under the line: Discount, Price (narrow cart) and Remove are in the quantity popover, Discount in the
|
|
42
|
+
* price popover. Default `inline`: the − / + buttons and Price form. */
|
|
37
43
|
lineEditor?: 'inline' | 'popover';
|
|
44
|
+
/** v2's Cart Settings › Columns: which columns show, a Split link under a quantity above 1 (`quantity.split`) and the
|
|
45
|
+
* SKU under the name (`name.sku`). The defaults are today's cart: Qty, Item, Price (folding as before) and Total. */
|
|
46
|
+
columns?: CartColumnSettings;
|
|
47
|
+
/** The empty cart's icon, centred above `emptyText` and hidden from screen readers. Default: v2's cart icon in the
|
|
48
|
+
* muted colour. Pass `null` for no icon. */
|
|
49
|
+
emptyIcon?: ReactNode;
|
|
50
|
+
/** The empty cart's line. Default: v2's "Tap a product to start a sale". */
|
|
51
|
+
emptyText?: string;
|
|
38
52
|
}) {
|
|
39
53
|
const { order } = sale;
|
|
54
|
+
// v2's empty cart: an icon and a line, no heads and no foot. A fee or shipping row alone keeps the cart.
|
|
55
|
+
const empty = !order.lineItems.length && !order.fees?.length && !order.shipping?.length;
|
|
40
56
|
const money = (amount: number) => ({ amount, currency: order.currency });
|
|
41
57
|
// order.display's figures (TallyUI ADR-063), with its tax split by rate; never app arithmetic (medusapos ADR 0008).
|
|
42
58
|
const { totals } = buildReceiptData(order, { storeName: '' });
|
|
@@ -46,6 +62,12 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
46
62
|
const display = (lineId: string) => order.display.lines.find((line) => line.lineId === lineId)!;
|
|
47
63
|
const orderAmounts = order.discounts.length === 1
|
|
48
64
|
? [{ discountId: order.discounts[0].id, amountMinor: order.display.orderDiscountMinor }] : [];
|
|
65
|
+
// A line's Split refusal, shown under that line until its next split or another line's split attempt.
|
|
66
|
+
const [splitError, setSplitError] = useState<{ lineId: string; message: string } | null>(null);
|
|
67
|
+
const split = (lineId: string) => {
|
|
68
|
+
const refused = sale.splitLine(lineId);
|
|
69
|
+
setSplitError(refused === null ? null : { lineId, message: refused });
|
|
70
|
+
};
|
|
49
71
|
// One open form: a line's discount or price, the order's discount (lineId null), or a charge.
|
|
50
72
|
const [form, setForm] = useState<{ type: 'discount'; lineId: string | null } | { type: 'price'; lineId: string } | { type: 'charge' } | null>(null);
|
|
51
73
|
const chargesOffered = (sale.capabilities?.orderCreate ?? 0) >= 5;
|
|
@@ -72,12 +94,20 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
72
94
|
<CartLine name={line.name} attributes={line.attributes} quantity={line.quantity} unitPrice={money(line.unitPriceMinor)}
|
|
73
95
|
regularUnitPrice={line.regularUnitPriceMinor === undefined ? undefined : money(line.regularUnitPriceMinor)}
|
|
74
96
|
lineTotal={money(display(line.id).amountMinor)} showPrice={showPrice}
|
|
97
|
+
columns={columns} sku={line.sku} imageUrl={line.imageUrl} onSplit={() => split(line.id)}
|
|
75
98
|
quantitySlot={lineEditor === 'popover' ? <LinePopover kind="quantity" lineName={line.name} currency={order.currency}
|
|
76
|
-
value={line.quantity} onApply={(quantity) => { sale.setQuantity(line.id, quantity); return null; }}
|
|
99
|
+
value={line.quantity} onApply={(quantity) => { sale.setQuantity(line.id, quantity); return null; }} actions={[
|
|
100
|
+
...(!pricePopover ? [{ id: 'discount', label: 'Discount', onPress: () => setForm({ type: 'discount', lineId: line.id }) }] : []),
|
|
101
|
+
...(canEditPrice && !pricePopover ? [{ id: 'price', label: 'Price', onPress: () => setForm({ type: 'price', lineId: line.id }) }] : []),
|
|
102
|
+
{ id: 'remove', label: 'Remove', destructive: true, onPress: () => sale.remove(line.id) },
|
|
103
|
+
]} /> : undefined}
|
|
77
104
|
priceSlot={pricePopover ? <LinePopover kind="price" lineName={line.name} currency={order.currency} value={line.unitPriceMinor}
|
|
105
|
+
regularValue={line.regularUnitPriceMinor} actions={[{ id: 'discount', label: 'Discount', onPress: () => setForm({ type: 'discount', lineId: line.id }) }]}
|
|
78
106
|
quickDiscounts={quickDiscounts} textClassName="text-right text-muted-foreground" onApply={(amount) => applyPrice(line, amount)} /> : undefined} />
|
|
107
|
+
{splitError?.lineId === line.id ? <Text accessibilityRole="alert" testID="cart-line-split-error"
|
|
108
|
+
className="px-3 text-sm text-destructive">{splitError.message}</Text> : null}
|
|
79
109
|
<DiscountChips discounts={line.discounts} amounts={display(line.id).discounts} currency={order.currency} onRemove={sale.removeDiscount} />
|
|
80
|
-
<CartLineActions actions={[
|
|
110
|
+
{lineEditor === 'inline' ? <CartLineActions actions={[
|
|
81
111
|
{ id: 'discount', label: 'Discount', color: 'text-primary', onPress: () => setForm({ type: 'discount', lineId: line.id }) },
|
|
82
112
|
...(canEditPrice && !pricePopover ? [{ id: 'price', label: 'Price', color: 'text-primary', onPress: () => setForm({ type: 'price', lineId: line.id }) }] : []),
|
|
83
113
|
]}>
|
|
@@ -89,16 +119,22 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
89
119
|
<Pressable accessibilityRole="button" accessibilityLabel={`Remove ${line.name}`}
|
|
90
120
|
onPress={() => sale.remove(line.id)} className="rounded-md border border-border bg-card px-3 py-2 min-h-11 min-w-11 items-center justify-center"><Text className="text-center text-foreground">Remove</Text></Pressable>
|
|
91
121
|
</View>
|
|
92
|
-
</CartLineActions>
|
|
122
|
+
</CartLineActions> : null}
|
|
93
123
|
{discountForm(line.id, `Discount on ${line.name}`)}
|
|
94
124
|
{canEditPrice && !pricePopover && form?.type === 'price' && form.lineId === line.id ? <PriceForm key={line.id} lineName={line.name}
|
|
95
125
|
currency={order.currency} currentMinor={line.unitPriceMinor} quickDiscounts={quickDiscounts} onClose={() => setForm(null)}
|
|
96
126
|
onApply={(amount, reason) => applyPrice(line, amount, reason)} /> : null}
|
|
97
127
|
</>;
|
|
98
128
|
return <View dataSet={{ print: 'hide' }} className="flex-1 min-h-0" onLayout={(event) => setCartWidth(event.nativeEvent.layout.width)}>
|
|
99
|
-
<CartColumnHeads showPrice={showPrice} />
|
|
129
|
+
{empty ? null : <CartColumnHeads showPrice={showPrice} columns={columns} />}
|
|
100
130
|
<CartPanel items={order.lineItems} renderItem={renderItem}
|
|
101
|
-
emptyState={<
|
|
131
|
+
emptyState={empty ? <View testID="cart-empty" className="flex-1 items-center justify-center gap-3 px-3 py-6">
|
|
132
|
+
{emptyIcon === null ? null : <View aria-hidden accessibilityElementsHidden importantForAccessibility="no-hide-descendants"
|
|
133
|
+
className="text-muted-foreground">{emptyIcon}</View>}
|
|
134
|
+
<Text testID="cart-empty-text" className="text-center text-muted-foreground">{emptyText}</Text>
|
|
135
|
+
{/* The footer is gone, so a resume or coupon message on an empty cart shows here. */}
|
|
136
|
+
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
137
|
+
</View> : undefined}
|
|
102
138
|
afterItems={<>
|
|
103
139
|
{(['fees', 'shipping'] as const).map((kind) => order[kind]?.map((charge, index) =>
|
|
104
140
|
<View key={charge.id} testID={`cart-${kind === 'fees' ? 'fee' : 'shipping'}-${index}`} className="flex-row items-center gap-3 px-3 py-2">
|
|
@@ -128,7 +164,7 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
128
164
|
className="self-start rounded-md border border-border bg-card px-4 py-2 min-h-11 justify-center">
|
|
129
165
|
<Text className="text-foreground">Add charge</Text></Pressable> : null}
|
|
130
166
|
</View> : null}</>}
|
|
131
|
-
footer={<View testID="cart-footer" className="gap-3 pb-4">
|
|
167
|
+
footer={empty ? undefined : <View testID="cart-footer" className="gap-3 pb-4">
|
|
132
168
|
{/* Exclusive: subtotal − discount + tax = total. Inclusive: subtotal − discount = total, the tax "incl.", not added. */}
|
|
133
169
|
<CartTotal subtotal={money(totals.subtotalMinor)} total={money(totals.totalMinor)}
|
|
134
170
|
discount={money(couponDiscountMinor === undefined ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor))}
|