@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.
- package/dist/index.d.ts +466 -28
- package/dist/index.js +3194 -1574
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +57 -0
- package/src/cart/cart-line.tsx +32 -17
- package/src/cart/index.ts +1 -0
- package/src/checkout/cash-tendered.tsx +5 -7
- package/src/fonts/font-provider.tsx +65 -0
- package/src/fonts/index.ts +1 -0
- package/src/index.ts +40 -2
- package/src/lib/error-text.ts +5 -0
- package/src/order/index.ts +2 -0
- package/src/order/refund-form.tsx +205 -0
- package/src/order/refund-modal.tsx +32 -0
- package/src/product/category-tile.tsx +43 -0
- package/src/product/in-cart-badge.tsx +26 -0
- package/src/product/index.ts +2 -0
- package/src/register/closure-sheet.tsx +13 -2
- package/src/register/handover-slip.tsx +46 -0
- package/src/register/index.ts +2 -0
- package/src/register/movement-sheet.tsx +2 -1
- package/src/register/open-register-card.tsx +2 -1
- package/src/register/register-bar.tsx +57 -11
- package/src/register/register-column.tsx +2 -1
- package/src/register/register-count.tsx +30 -11
- package/src/register/register-panel.tsx +45 -4
- package/src/register/switch-confirm.tsx +102 -0
- package/src/reports/cards.tsx +197 -0
- package/src/reports/filters-bar.tsx +95 -0
- package/src/reports/hero.tsx +111 -0
- package/src/reports/index.ts +4 -0
- package/src/reports/sales-room.tsx +28 -0
- package/src/sale/cart.tsx +37 -21
- package/src/sale/catalogue.tsx +34 -5
- package/src/sale/customer-display-screen.tsx +92 -0
- package/src/sale/index.ts +5 -2
- package/src/sale/open-sale-tabs.tsx +67 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +4 -2
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +28 -4
- package/src/sale/product-filter-bar.tsx +58 -0
- package/src/sale/receipt.tsx +8 -2
- package/src/sale/tender-pane.tsx +179 -0
- package/src/sale/tender.tsx +20 -35
- package/src/scale/index.ts +3 -0
- package/src/scale/scale-provider.tsx +70 -0
- package/src/scale/use-pointer.ts +23 -0
- package/src/settings/display-settings.tsx +122 -0
- package/src/settings/index.ts +1 -0
- package/src/shell/app-shell.tsx +71 -0
- package/src/shell/index.ts +4 -0
- package/src/shell/nav-drawer.tsx +130 -0
- package/src/shell/nav-item.tsx +70 -0
- package/src/shell/nav-rail.tsx +58 -0
- package/src/shell/shell-context.ts +18 -0
- package/src/ui/icon/menu-icon.tsx +10 -0
- package/src/ui/text/font-text.tsx +25 -0
- package/src/ui/text/index.tsx +5 -4
- package/src/sale/split-tender.tsx +0 -81
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Pressable, Text, View } from 'react-native';
|
|
2
|
+
import { Image } from '@tallyui/primitives';
|
|
3
|
+
import { cn } from '@tallyui/theme';
|
|
4
|
+
|
|
5
|
+
export interface CategoryTileProps {
|
|
6
|
+
name: string;
|
|
7
|
+
/** The category's photo; without one the tile shows the name's initial on a tint. */
|
|
8
|
+
imageUrl?: string;
|
|
9
|
+
/** Products in the category, shown under the name when above 0. */
|
|
10
|
+
count?: number;
|
|
11
|
+
onPress?: () => void;
|
|
12
|
+
testID?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A category as a square tile: its photo full-bleed with the name over the foot, or the name's initial on a
|
|
18
|
+
* tint when there is no photo.
|
|
19
|
+
*
|
|
20
|
+
* Ported from WCPOS v2 `TermTile`, packages/core/src/screens/main/pos/products/browse/term-tile.tsx
|
|
21
|
+
* (MIT, WCPOS): the picture fills the square (`contentFit="cover"`), else a tint; the name bold over two
|
|
22
|
+
* lines with the count under it.
|
|
23
|
+
*/
|
|
24
|
+
export function CategoryTile({ name, imageUrl, count, onPress, testID, className }: CategoryTileProps) {
|
|
25
|
+
const id = testID ?? 'category-tile';
|
|
26
|
+
return (
|
|
27
|
+
<Pressable testID={testID} role="button" accessibilityLabel={name} onPress={onPress}
|
|
28
|
+
className={cn('aspect-square overflow-hidden rounded-lg border border-border', imageUrl ? 'bg-card' : 'bg-primary/10', className)}>
|
|
29
|
+
{imageUrl ? (
|
|
30
|
+
<Image.Root testID={`${id}-image`} source={{ uri: imageUrl }} alt="" contentFit="cover"
|
|
31
|
+
className="absolute inset-0" style={{ width: '100%', height: '100%' }} />
|
|
32
|
+
) : (
|
|
33
|
+
<View testID={`${id}-fallback`} className="absolute inset-0 items-center justify-center">
|
|
34
|
+
<Text className="text-3xl font-semibold text-primary">{name.trim().charAt(0).toUpperCase() || '?'}</Text>
|
|
35
|
+
</View>
|
|
36
|
+
)}
|
|
37
|
+
<View className={cn('absolute inset-x-0 bottom-0 px-2.5 py-2', imageUrl && 'bg-card/80')}>
|
|
38
|
+
<Text className="font-bold text-foreground" numberOfLines={2}>{name}</Text>
|
|
39
|
+
{count !== undefined && count > 0 ? <Text className="text-xs text-muted-foreground">{count === 1 ? '1 product' : `${count} products`}</Text> : null}
|
|
40
|
+
</View>
|
|
41
|
+
</Pressable>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Text, View } from 'react-native';
|
|
2
|
+
import { cn } from '@tallyui/theme';
|
|
3
|
+
|
|
4
|
+
export interface InCartBadgeProps {
|
|
5
|
+
/** How many of the product the cart holds (e.g. from `cartQuantities`); nothing renders at 0. */
|
|
6
|
+
count: number;
|
|
7
|
+
/** Placement, e.g. `absolute right-2 top-2` for a tile's top-right corner. */
|
|
8
|
+
className?: string;
|
|
9
|
+
testID?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* How many of a product are in the cart: a primary circle with the count, hidden while there are none.
|
|
14
|
+
*
|
|
15
|
+
* Ported from WCPOS v2 `InCartCount`, packages/core/src/screens/main/pos/products/rows/in-cart-count.tsx
|
|
16
|
+
* (MIT, WCPOS), without its count beat.
|
|
17
|
+
*/
|
|
18
|
+
export function InCartBadge({ count, className, testID }: InCartBadgeProps) {
|
|
19
|
+
if (count <= 0) return null;
|
|
20
|
+
return (
|
|
21
|
+
<View testID={testID} accessibilityLabel={`${count} in cart`}
|
|
22
|
+
className={cn('h-6 min-w-6 items-center justify-center rounded-full bg-primary px-1.5', className)}>
|
|
23
|
+
<Text className="text-xs font-semibold tabular-nums text-primary-foreground">{String(count)}</Text>
|
|
24
|
+
</View>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/product/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { ProductTable, defaultProductColumns, useDefaultProductColumns, type Pro
|
|
|
10
10
|
export { ProductList, type ProductListProps } from './product-list';
|
|
11
11
|
export { CategoryNav, type CategoryNavProps, type CategoryItem } from './category-nav';
|
|
12
12
|
export { ProductVariantPicker, type ProductVariantPickerProps, type VariantOption } from './product-variant-picker';
|
|
13
|
+
export { InCartBadge, type InCartBadgeProps } from './in-cart-badge';
|
|
14
|
+
export { CategoryTile, type CategoryTileProps } from './category-tile';
|
|
@@ -4,6 +4,7 @@ import type { useRegisterSession } from '@tallyui/pos';
|
|
|
4
4
|
import { countVariance, TAX_ROUNDING_MIXED_NOTE, varianceText } from '@tallyui/pos';
|
|
5
5
|
|
|
6
6
|
import { formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
|
+
import { errorText } from '../lib/error-text';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
9
10
|
import { Text } from '../ui/text';
|
|
@@ -81,7 +82,7 @@ export function ClosureSheet({ register, currency, onPrint, onDone }: ClosureShe
|
|
|
81
82
|
try {
|
|
82
83
|
await onPrint();
|
|
83
84
|
} catch (e) {
|
|
84
|
-
setError(
|
|
85
|
+
setError(errorText(e));
|
|
85
86
|
} finally {
|
|
86
87
|
setBusy(false);
|
|
87
88
|
}
|
|
@@ -135,7 +136,17 @@ export function ClosureSheet({ register, currency, onPrint, onDone }: ClosureShe
|
|
|
135
136
|
</View>
|
|
136
137
|
)}
|
|
137
138
|
{/* Not a figure: shows who approved the close even while blind. */}
|
|
138
|
-
{!!approvedBy &&
|
|
139
|
+
{!!approvedBy && (
|
|
140
|
+
<View className="flex-row flex-wrap gap-x-2">
|
|
141
|
+
<Text testID="closure-approved-by">Approved by {approvedBy}</Text>
|
|
142
|
+
{/* ADR-082 d9: the store has not yet applied this closure with its proof. */}
|
|
143
|
+
{register.closureApprovalStatus[closure.id] === 'unverified' && (
|
|
144
|
+
<Text testID="closure-approval-unverified" className="text-muted-foreground">
|
|
145
|
+
Approval not yet verified by the store
|
|
146
|
+
</Text>
|
|
147
|
+
)}
|
|
148
|
+
</View>
|
|
149
|
+
)}
|
|
139
150
|
{/* Not a figure either (#287). The wording is approved by the Front desk, 2026-09-30. */}
|
|
140
151
|
{closure.breakdowns.tax_rounding_mixed === true && (
|
|
141
152
|
<Text testID="closure-tax-rounding-mixed" className="text-muted-foreground">
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import type { HandoverSlipData } from '@tallyui/pos';
|
|
3
|
+
|
|
4
|
+
import { formatMoney } from '@tallyui/core';
|
|
5
|
+
import { Text } from '../ui/text';
|
|
6
|
+
import { tenderLabel } from './register-count';
|
|
7
|
+
import { countLine } from './switch-confirm';
|
|
8
|
+
|
|
9
|
+
export interface HandoverSlipProps {
|
|
10
|
+
/** `handoverSlip(...)`'s result; `document` is not read here (it is what prints). */
|
|
11
|
+
slip: Omit<HandoverSlipData, 'document'>;
|
|
12
|
+
/** ISO 4217 code, for the expected figures. */
|
|
13
|
+
currency: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The hand-over slip on screen: what a closing cashier hands the next one (v2's "Hand-over slip", the open session's
|
|
18
|
+
* X report naming the cashier; WCPOS v2 monorepo `main` 51e7c4351 `switch-confirm.tsx` and `use-session-report.ts`).
|
|
19
|
+
* No dialog: the host places it, for example in a print preview. No expected figures while blind.
|
|
20
|
+
*/
|
|
21
|
+
export function HandoverSlip({ slip, currency }: HandoverSlipProps) {
|
|
22
|
+
const register = [slip.registerName, slip.openedAtTime && `open since ${slip.openedAtTime}`, slip.openedByName]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(' · ');
|
|
25
|
+
return (
|
|
26
|
+
<View testID="handover-slip" className="gap-2">
|
|
27
|
+
<Text testID="handover-slip-title" className="text-lg font-semibold">Hand-over slip</Text>
|
|
28
|
+
<Text testID="handover-slip-register" className="text-muted-foreground">{register}</Text>
|
|
29
|
+
<Text testID="handover-slip-cashier">{`Handed over by ${slip.cashierName}`}</Text>
|
|
30
|
+
<Text testID="handover-slip-sales">{countLine(slip.salesCount, 'sale', 'sales')}</Text>
|
|
31
|
+
{Object.entries(slip.expected ?? {}).map(([method, amount]) => (
|
|
32
|
+
<Text key={method} testID={`handover-slip-expected-${method}`} className="tabular-nums">
|
|
33
|
+
{`Expected ${tenderLabel(method)} ${formatMoney({ amount, currency })}`}
|
|
34
|
+
</Text>
|
|
35
|
+
))}
|
|
36
|
+
{slip.unsentSales > 0 && (
|
|
37
|
+
<Text testID="handover-slip-unsent-sales">{countLine(slip.unsentSales, 'unsent sale', 'unsent sales')}</Text>
|
|
38
|
+
)}
|
|
39
|
+
{slip.unsentTillUpdates > 0 && (
|
|
40
|
+
<Text testID="handover-slip-unsent-till-updates">
|
|
41
|
+
{countLine(slip.unsentTillUpdates, 'unsent till update', 'unsent till updates')}
|
|
42
|
+
</Text>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/register/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { RegisterPanel, type RegisterPanelProps } from './register-panel';
|
|
|
10
10
|
export { RegisterColumn, type RegisterColumnProps } from './register-column';
|
|
11
11
|
export { RegisterCount, APPROVAL_REQUIRED_TEXT, type RegisterCountProps } from './register-count';
|
|
12
12
|
export { ClosureSheet, type ClosureSheetProps } from './closure-sheet';
|
|
13
|
+
export { SwitchConfirm, type SwitchConfirmProps } from './switch-confirm';
|
|
14
|
+
export { HandoverSlip, type HandoverSlipProps } from './handover-slip';
|
|
@@ -3,6 +3,7 @@ import type { MovementType, useRegisterSession } from '@tallyui/pos';
|
|
|
3
3
|
import { movementFieldError, normalizeAmount, parseMinor } from '@tallyui/pos';
|
|
4
4
|
|
|
5
5
|
import { currencySymbol, minorUnitDigits } from '@tallyui/core';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { Button } from '../ui/button';
|
|
7
8
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
8
9
|
import { Input } from '../ui/input';
|
|
@@ -63,7 +64,7 @@ export function MovementSheet({ register, type, currency, onDone, onOpenChange,
|
|
|
63
64
|
if (type === 'no_sale') onOpenDrawer?.();
|
|
64
65
|
onOpenChange(false);
|
|
65
66
|
} catch (e) {
|
|
66
|
-
setError(
|
|
67
|
+
setError(errorText(e));
|
|
67
68
|
} finally {
|
|
68
69
|
busyRef.current = false;
|
|
69
70
|
setBusy(false);
|
|
@@ -5,6 +5,7 @@ import { parseMinor, validAmount } from '@tallyui/pos';
|
|
|
5
5
|
|
|
6
6
|
import { currencySymbol, formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
7
|
import { cn } from '@tallyui/theme';
|
|
8
|
+
import { errorText } from '../lib/error-text';
|
|
8
9
|
import { Button } from '../ui/button';
|
|
9
10
|
import { Input } from '../ui/input';
|
|
10
11
|
import { Label } from '../ui/label';
|
|
@@ -48,7 +49,7 @@ export function OpenRegisterCard({ register, currency, configuredFloatMinor, cla
|
|
|
48
49
|
try {
|
|
49
50
|
await register.actions.openSession({ expectedFloatMinor, countedFloatMinor: countedMinor });
|
|
50
51
|
} catch (e) {
|
|
51
|
-
setError(
|
|
52
|
+
setError(errorText(e));
|
|
52
53
|
} finally {
|
|
53
54
|
setBusy(false);
|
|
54
55
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import { Pressable, View } from 'react-native';
|
|
2
3
|
import type { useRegisterSession } from '@tallyui/pos';
|
|
3
4
|
|
|
4
5
|
import { cn } from '@tallyui/theme';
|
|
6
|
+
import { useShell } from '../shell/shell-context';
|
|
7
|
+
import { Avatar } from '../ui/avatar';
|
|
5
8
|
import { Badge } from '../ui/badge';
|
|
6
9
|
import { Button } from '../ui/button';
|
|
7
10
|
import { HStack } from '../ui/hstack';
|
|
11
|
+
import { IconButton } from '../ui/icon-button';
|
|
12
|
+
import { MenuIcon } from '../ui/icon/menu-icon';
|
|
8
13
|
import { Text } from '../ui/text';
|
|
9
14
|
import { describeRegisterBarPill } from './register-bar.helpers';
|
|
10
15
|
|
|
@@ -21,17 +26,30 @@ export interface RegisterBarProps {
|
|
|
21
26
|
onOpenPanel: () => void;
|
|
22
27
|
/** Turns the pill into a button (opens the gate/picker or the panel) when given; the plain badge otherwise. */
|
|
23
28
|
onPressPill?: () => void;
|
|
29
|
+
/** The store's name. With `multiRegister` and a bound register the bar reads "Store · Register". */
|
|
30
|
+
storeName?: string;
|
|
31
|
+
/** The signed-in cashier: an initials avatar, pressable when `onPress` is given. */
|
|
32
|
+
cashier?: { name: string; onPress?: () => void };
|
|
33
|
+
/** The app's sync state (a badge or a line), drawn before the cashier. */
|
|
34
|
+
syncStatus?: ReactNode;
|
|
35
|
+
/** Opens the navigation; inside a phone `AppShell` the shell supplies it. Hidden when neither. */
|
|
36
|
+
onOpenMenu?: () => void;
|
|
24
37
|
className?: string;
|
|
25
38
|
}
|
|
26
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
|
+
|
|
27
44
|
/**
|
|
28
|
-
* The till's one status bar:
|
|
29
|
-
* (LEDGER 48),
|
|
30
|
-
* 1): WCPOS `next` `3b5331b5c`
|
|
45
|
+
* The till's one status bar: the menu (phones), the place (the store, and the register for
|
|
46
|
+
* multi-register stores), one status pill (LEDGER 48), the sync state, the button that opens the
|
|
47
|
+
* register panel, and the cashier. Port provenance (ADR-032 amendment 1): WCPOS `next` `3b5331b5c`
|
|
48
|
+
* `register-bar.tsx`; the menu, the place and the cashier from v2 `main` `51e7c4351`
|
|
49
|
+
* `packages/core/src/screens/main/pos/cart/register-bar.tsx` and `components/bar-controls`, MIT, WCPOS.
|
|
31
50
|
*
|
|
32
|
-
* Dropped for this neutral port: the user
|
|
33
|
-
* WooCommerce OAuth-return rehosting — all app/backend concerns `useRegisterSession` never
|
|
34
|
-
* carries. The drawer/menu button is gone too: TallyUI has no fixed navigation shell to open.
|
|
51
|
+
* Dropped for this neutral port: the user sheet, switch-store, the notification bell and the
|
|
52
|
+
* WooCommerce OAuth-return rehosting — all app/backend concerns `useRegisterSession` never carries.
|
|
35
53
|
*/
|
|
36
54
|
export function RegisterBar({
|
|
37
55
|
register,
|
|
@@ -41,9 +59,15 @@ export function RegisterBar({
|
|
|
41
59
|
multiRegister,
|
|
42
60
|
onOpenPanel,
|
|
43
61
|
onPressPill,
|
|
62
|
+
storeName,
|
|
63
|
+
cashier,
|
|
64
|
+
syncStatus,
|
|
65
|
+
onOpenMenu,
|
|
44
66
|
className,
|
|
45
67
|
}: RegisterBarProps) {
|
|
46
68
|
const { session, overdue, enabled, lastClosure, closing } = register;
|
|
69
|
+
const shell = useShell();
|
|
70
|
+
const openMenu = onOpenMenu ?? shell?.openMenu;
|
|
47
71
|
const pill = describeRegisterBarPill({
|
|
48
72
|
registerId,
|
|
49
73
|
online,
|
|
@@ -53,14 +77,24 @@ export function RegisterBar({
|
|
|
53
77
|
sessionsOn: enabled,
|
|
54
78
|
closing,
|
|
55
79
|
});
|
|
80
|
+
const named = multiRegister && registerId !== null && registerName ? registerName : '';
|
|
81
|
+
// Store · Register: the larger container first, as every v2 line that names both reads.
|
|
82
|
+
const place = storeName ? (named ? `${storeName} · ${named}` : storeName) : named;
|
|
56
83
|
return (
|
|
57
|
-
<HStack testID="register-bar" className={cn('bg-card border-border h-12 border-b px-
|
|
84
|
+
<HStack testID="register-bar" className={cn('bg-card border-border h-12 gap-2 border-b px-2', className)}>
|
|
85
|
+
{openMenu && (
|
|
86
|
+
<IconButton testID="register-bar-menu" accessibilityLabel="Open menu" onPress={openMenu}>
|
|
87
|
+
<View className="text-foreground">
|
|
88
|
+
<MenuIcon size={24} />
|
|
89
|
+
</View>
|
|
90
|
+
</IconButton>
|
|
91
|
+
)}
|
|
58
92
|
<View className="min-w-0 flex-1 shrink">
|
|
59
|
-
{
|
|
60
|
-
<Text testID="register-bar-name" numberOfLines={1}>
|
|
61
|
-
{
|
|
93
|
+
{place ? (
|
|
94
|
+
<Text testID="register-bar-name" className={storeName ? 'font-semibold' : undefined} numberOfLines={1}>
|
|
95
|
+
{place}
|
|
62
96
|
</Text>
|
|
63
|
-
)}
|
|
97
|
+
) : null}
|
|
64
98
|
</View>
|
|
65
99
|
{pill && (onPressPill ? (
|
|
66
100
|
<Pressable testID="register-bar-pill" accessibilityRole="button" accessibilityLabel={pill} onPress={onPressPill}>
|
|
@@ -69,6 +103,7 @@ export function RegisterBar({
|
|
|
69
103
|
) : (
|
|
70
104
|
<Badge testID="register-bar-pill" label={pill} variant="warning" />
|
|
71
105
|
))}
|
|
106
|
+
{syncStatus}
|
|
72
107
|
{(session || lastClosure) && (
|
|
73
108
|
<Button
|
|
74
109
|
variant="ghost"
|
|
@@ -80,6 +115,17 @@ export function RegisterBar({
|
|
|
80
115
|
<Text className={overdue ? 'text-warning' : undefined}>Register ›</Text>
|
|
81
116
|
</Button>
|
|
82
117
|
)}
|
|
118
|
+
{cashier && (
|
|
119
|
+
<Pressable
|
|
120
|
+
testID="register-bar-cashier"
|
|
121
|
+
accessibilityRole={cashier.onPress ? 'button' : undefined}
|
|
122
|
+
accessibilityLabel={`Cashier: ${cashier.name}`}
|
|
123
|
+
disabled={!cashier.onPress}
|
|
124
|
+
onPress={cashier.onPress}
|
|
125
|
+
>
|
|
126
|
+
<Avatar size="sm" fallback={initials(cashier.name)} />
|
|
127
|
+
</Pressable>
|
|
128
|
+
)}
|
|
83
129
|
</HStack>
|
|
84
130
|
);
|
|
85
131
|
}
|
|
@@ -2,6 +2,7 @@ import { useState, type ReactNode } from 'react';
|
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import type { useRegisterSession } from '@tallyui/pos';
|
|
4
4
|
|
|
5
|
+
import { errorText } from '../lib/error-text';
|
|
5
6
|
import { Button } from '../ui/button';
|
|
6
7
|
import { Text } from '../ui/text';
|
|
7
8
|
import { OpenRegisterCard } from './open-register-card';
|
|
@@ -96,7 +97,7 @@ function FinishClose({ register, busy, setBusy }: { register: ReturnType<typeof
|
|
|
96
97
|
// ignored for a session already closed), and the approval gate doesn't run again.
|
|
97
98
|
await register.actions.closeSession({ counted: register.session?.counted ?? {} });
|
|
98
99
|
} catch (e) {
|
|
99
|
-
setError(
|
|
100
|
+
setError(errorText(e));
|
|
100
101
|
} finally {
|
|
101
102
|
setBusy(false);
|
|
102
103
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
|
|
15
15
|
import { currencySymbol, formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
16
16
|
import { cn } from '@tallyui/theme';
|
|
17
|
+
import { errorText } from '../lib/error-text';
|
|
17
18
|
import { Button } from '../ui/button';
|
|
18
19
|
import { Input } from '../ui/input';
|
|
19
20
|
import { Label } from '../ui/label';
|
|
@@ -31,10 +32,6 @@ export function varianceWord(key: string): string {
|
|
|
31
32
|
return 'over';
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function errorMessage(error: unknown): string {
|
|
35
|
-
return error instanceof Error ? error.message : String(error);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
35
|
/**
|
|
39
36
|
* A tile's face value as a locale-aware whole amount ('€500', '€1') or fraction ('€0.50'), never
|
|
40
37
|
* a bare '.00' — `Intl`'s `trailingZeroDisplay` (`@tallyui/core`'s `formatMoney` has nothing
|
|
@@ -115,11 +112,20 @@ export interface RegisterCountProps {
|
|
|
115
112
|
/** ISO 4217 code: denomination faces, parsing and display. */
|
|
116
113
|
currency: string;
|
|
117
114
|
/**
|
|
118
|
-
* Above `register.varianceThreshold`, Close asks for this first
|
|
119
|
-
* stays; without it, Close refuses outright with
|
|
120
|
-
*
|
|
115
|
+
* Above `register.varianceThreshold`, Close asks for this first, with the count it would close
|
|
116
|
+
* on. `null` refuses and the count stays; without it, Close refuses outright with
|
|
117
|
+
* `APPROVAL_REQUIRED_TEXT`. Its `approvedBy`, `approvedByName`, `approval` (the store's opaque
|
|
118
|
+
* proof, ADR-082) and `approvedVariance` (from `actions.closureVariance`) go to `closeSession`,
|
|
119
|
+
* which enforces the same gate and puts the approver on the Z. A count edited while this is
|
|
120
|
+
* pending, or a variance that moved since (the hook's gate), asks again on the next Close.
|
|
121
|
+
* A zero-argument function still fits.
|
|
121
122
|
*/
|
|
122
|
-
approve?: (
|
|
123
|
+
approve?: (input: { counted: Record<string, number> }) => Promise<{
|
|
124
|
+
approvedBy: string;
|
|
125
|
+
approvedByName?: string;
|
|
126
|
+
approval?: string;
|
|
127
|
+
approvedVariance?: Record<string, number>;
|
|
128
|
+
} | null>;
|
|
123
129
|
className?: string;
|
|
124
130
|
}
|
|
125
131
|
|
|
@@ -172,6 +178,9 @@ export function RegisterCount({ register, currency, approve, className }: Regist
|
|
|
172
178
|
cash: amountMinor,
|
|
173
179
|
...Object.fromEntries(otherCounted.map(([method, value]) => [method, parseMinor(value, digits)])),
|
|
174
180
|
};
|
|
181
|
+
// The count on screen now, for an approval that resolves after the cashier edited it.
|
|
182
|
+
const shownCount = useRef('');
|
|
183
|
+
shownCount.current = JSON.stringify(counted);
|
|
175
184
|
|
|
176
185
|
const attempt = async (action: () => Promise<unknown>) => {
|
|
177
186
|
setBusy(true);
|
|
@@ -181,7 +190,7 @@ export function RegisterCount({ register, currency, approve, className }: Regist
|
|
|
181
190
|
} catch (e) {
|
|
182
191
|
// The hook's own gate (by name: components import no class from pos, ADR-064).
|
|
183
192
|
if (e instanceof Error && e.name === 'RegisterApprovalRequiredError') setRefusal(APPROVAL_REQUIRED_TEXT);
|
|
184
|
-
else setError(
|
|
193
|
+
else setError(errorText(e));
|
|
185
194
|
} finally {
|
|
186
195
|
setBusy(false);
|
|
187
196
|
}
|
|
@@ -197,13 +206,23 @@ export function RegisterCount({ register, currency, approve, className }: Regist
|
|
|
197
206
|
return;
|
|
198
207
|
}
|
|
199
208
|
if (needsApproval) {
|
|
209
|
+
const asked = shownCount.current;
|
|
200
210
|
void attempt(async () => {
|
|
201
|
-
const result = await approve!();
|
|
211
|
+
const result = await approve!({ counted });
|
|
202
212
|
if (!result) {
|
|
203
213
|
setRefusal('Approval was not granted. The count is unchanged.');
|
|
204
214
|
return;
|
|
205
215
|
}
|
|
206
|
-
|
|
216
|
+
// The approval is for the count it was asked with; one edited meanwhile asks again.
|
|
217
|
+
if (shownCount.current !== asked) {
|
|
218
|
+
setRefusal(APPROVAL_REQUIRED_TEXT);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const { approvedBy, approvedByName, approval, approvedVariance } = result;
|
|
222
|
+
await actions.closeSession({
|
|
223
|
+
counted, approvedBy, approvedByName,
|
|
224
|
+
...(approval ? { approval } : {}), ...(approvedVariance ? { approvedVariance } : {}),
|
|
225
|
+
});
|
|
207
226
|
});
|
|
208
227
|
return;
|
|
209
228
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { ScrollView, useWindowDimensions, View } from 'react-native';
|
|
3
|
-
import type { MovementType, useRegisterSession } from '@tallyui/pos';
|
|
3
|
+
import type { ApprovalNeeded, MovementType, useRegisterSession } from '@tallyui/pos';
|
|
4
4
|
|
|
5
5
|
import { formatMoney } from '@tallyui/core';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { Button } from '../ui/button';
|
|
7
8
|
import { Dialog, DialogClose, DialogContent, DialogTitle } from '../ui/dialog';
|
|
8
9
|
import { IconButton } from '../ui/icon-button';
|
|
@@ -24,6 +25,12 @@ export interface RegisterPanelProps {
|
|
|
24
25
|
registerName?: string;
|
|
25
26
|
open: boolean;
|
|
26
27
|
onOpenChange: (open: boolean) => void;
|
|
28
|
+
/**
|
|
29
|
+
* The host's gate for a closure the store refused (`register.approvalNeeded`, ADR-082 d7): it
|
|
30
|
+
* gets the refusal, including `liveAtStore`, and returns a new proof and approver, or `null`
|
|
31
|
+
* to leave it. Its result goes to `actions.reapproveClosure`. Without it, the card has no button.
|
|
32
|
+
*/
|
|
33
|
+
reapprove?: (needed: ApprovalNeeded) => Promise<{ approvedBy: string; approval: string } | null>;
|
|
27
34
|
className?: string;
|
|
28
35
|
}
|
|
29
36
|
|
|
@@ -36,8 +43,9 @@ export interface RegisterPanelProps {
|
|
|
36
43
|
* note): refused-movement Retry and "Unsynced" (no outbox here to refuse a movement), the
|
|
37
44
|
* X-report, Z and print/reprint, and the Reports deep link.
|
|
38
45
|
*/
|
|
39
|
-
export function RegisterPanel({ register, currency, registerName, open, onOpenChange, className }: RegisterPanelProps) {
|
|
40
|
-
const { session, expected, salesCount, blind, movements, lastClosure, actions } = register;
|
|
46
|
+
export function RegisterPanel({ register, currency, registerName, open, onOpenChange, reapprove, className }: RegisterPanelProps) {
|
|
47
|
+
const { session, expected, salesCount, blind, movements, lastClosure, approvalNeeded, actions } = register;
|
|
48
|
+
const [reapproving, setReapproving] = useState(false);
|
|
41
49
|
const otherTenders = Object.entries(expected).filter(([method, amount]) => method !== 'cash' && amount !== 0);
|
|
42
50
|
const { height: windowHeight } = useWindowDimensions();
|
|
43
51
|
const maxHeight = Math.max(280, windowHeight - DIALOG_VERTICAL_MARGIN);
|
|
@@ -48,7 +56,7 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
48
56
|
try {
|
|
49
57
|
await action();
|
|
50
58
|
} catch (e) {
|
|
51
|
-
setError(
|
|
59
|
+
setError(errorText(e));
|
|
52
60
|
}
|
|
53
61
|
};
|
|
54
62
|
// Refused cash keeps a panel open on its own in WCPOS; there is no outbox here to refuse a
|
|
@@ -78,6 +86,39 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
78
86
|
</View>
|
|
79
87
|
<Text testID="register-panel-sales-count">{salesCount} sale{salesCount === 1 ? '' : 's'} this session</Text>
|
|
80
88
|
<ScrollView testID="register-panel-body" className="flex-1" contentContainerClassName="gap-3">
|
|
89
|
+
{/* Here, not in RegisterCount: a refused closure's session is already closed, and the
|
|
90
|
+
panel is what still shows once a closure exists. Title and button: WCPOS v2's
|
|
91
|
+
`register.approval_needed` and `register.approve` (monorepo core.json:2974-2976). */}
|
|
92
|
+
{approvalNeeded && (
|
|
93
|
+
<View testID="register-panel-reapproval" className="bg-warning/10 gap-2 rounded-md p-3">
|
|
94
|
+
<Text className="font-semibold">Approval needed</Text>
|
|
95
|
+
<Text>The store refused this closure's manager approval. A manager must approve it again.</Text>
|
|
96
|
+
{reapprove && (
|
|
97
|
+
<Button
|
|
98
|
+
testID="register-panel-reapprove"
|
|
99
|
+
variant="outline"
|
|
100
|
+
className="min-h-11"
|
|
101
|
+
disabled={reapproving}
|
|
102
|
+
onPress={() =>
|
|
103
|
+
attempt(async () => {
|
|
104
|
+
setReapproving(true);
|
|
105
|
+
try {
|
|
106
|
+
const result = await reapprove(approvalNeeded);
|
|
107
|
+
if (!result) return;
|
|
108
|
+
await actions.reapproveClosure({
|
|
109
|
+
closureId: approvalNeeded.closureId, approval: result.approval, approvedBy: result.approvedBy,
|
|
110
|
+
});
|
|
111
|
+
} finally {
|
|
112
|
+
setReapproving(false);
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
>
|
|
117
|
+
<Text>Approve</Text>
|
|
118
|
+
</Button>
|
|
119
|
+
)}
|
|
120
|
+
</View>
|
|
121
|
+
)}
|
|
81
122
|
<View className="flex-row gap-2">
|
|
82
123
|
{(['paid_in', 'paid_out', 'no_sale'] as const).map((type) => (
|
|
83
124
|
<Button
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import type { SwitchKind, SwitchWarning, SwitchWarnings } from '@tallyui/pos';
|
|
3
|
+
|
|
4
|
+
import { Button } from '../ui/button';
|
|
5
|
+
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog';
|
|
6
|
+
import { Text } from '../ui/text';
|
|
7
|
+
|
|
8
|
+
/** `{n} {one}` or `{n} {other}`; shared with `HandoverSlip`, not exported from the package. */
|
|
9
|
+
export const countLine = (n: number, one: string, other: string) => `${n} ${n === 1 ? one : other}`;
|
|
10
|
+
|
|
11
|
+
const WARNING_LINES: Record<Exclude<SwitchWarning['code'], 'openSession'>, (n: number) => string> = {
|
|
12
|
+
unsentSales: (n) => countLine(n, 'unsent sale', 'unsent sales'),
|
|
13
|
+
unsentTillUpdates: (n) => countLine(n, 'unsent till update', 'unsent till updates'),
|
|
14
|
+
parkedSales: (n) => countLine(n, 'parked sale', 'parked sales'),
|
|
15
|
+
partlyPaidSale: () => 'A sale is partly paid',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface SwitchConfirmProps {
|
|
19
|
+
kind: SwitchKind;
|
|
20
|
+
warnings: SwitchWarnings;
|
|
21
|
+
/** The cashier or register switched to; unused for `signOut`. */
|
|
22
|
+
targetName?: string;
|
|
23
|
+
/** The bound register's name, for the descriptions and the sign-out title. */
|
|
24
|
+
registerName?: string;
|
|
25
|
+
/** A formatted expected cash amount for the sign-out title; omit while blind. */
|
|
26
|
+
amount?: string;
|
|
27
|
+
onConfirm: () => void;
|
|
28
|
+
onCancel: () => void;
|
|
29
|
+
/** Sign-out with an open session: renders "Close register", which calls this. */
|
|
30
|
+
onCloseRegister?: () => void;
|
|
31
|
+
/** Cashier switch: renders "Print hand-over slip", which calls this. */
|
|
32
|
+
onPrintHandover?: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Confirms a cashier switch, a register switch or a sign-out, naming what it leaves behind (v2 parity A12). Port
|
|
37
|
+
* provenance: WCPOS v2 monorepo `main` 51e7c4351 `packages/core/src/screens/main/pos/cart/switch-confirm.tsx`, with
|
|
38
|
+
* its English copy (`locales/en/core.json`, `register.*`). Not ported: the store switch and its drawer carry, and
|
|
39
|
+
* v2's "The POS reloads as …" lines (a TallyUI app's switch is its platform's own). New here: unsent sales add
|
|
40
|
+
* "anyway" to the confirm, and till updates, parked sales and a partly paid sale are listed too.
|
|
41
|
+
*/
|
|
42
|
+
export function SwitchConfirm({
|
|
43
|
+
kind, warnings, targetName = '', registerName, amount, onConfirm, onCancel, onCloseRegister, onPrintHandover,
|
|
44
|
+
}: SwitchConfirmProps) {
|
|
45
|
+
const anyway = warnings.unsentSales > 0 ? ' anyway' : '';
|
|
46
|
+
let title: string;
|
|
47
|
+
let description = '';
|
|
48
|
+
let confirm: string;
|
|
49
|
+
if (kind === 'cashier') {
|
|
50
|
+
title = `Hand the till to ${targetName}?`;
|
|
51
|
+
if (registerName) description = `The drawer stays open on ${registerName}.`;
|
|
52
|
+
confirm = `Hand over to ${targetName}${anyway}`;
|
|
53
|
+
} else if (kind === 'register') {
|
|
54
|
+
title = `Switch to ${targetName}?`;
|
|
55
|
+
description = warnings.sessionOpen && registerName
|
|
56
|
+
? `This device moves to ${targetName}. ${registerName}'s drawer stays open for whoever is there.`
|
|
57
|
+
: `This device moves to ${targetName}.`;
|
|
58
|
+
confirm = `Switch to ${targetName}${anyway}`;
|
|
59
|
+
} else if (warnings.sessionOpen) {
|
|
60
|
+
const name = registerName ?? 'The register';
|
|
61
|
+
title = amount ? `${name} is still open at ${amount}. Close it first?` : `${name} is still open. Close it first?`;
|
|
62
|
+
description = 'A till left open stays open for the next cashier. The closure records who closed it.';
|
|
63
|
+
confirm = 'Sign out anyway';
|
|
64
|
+
} else {
|
|
65
|
+
title = 'Sign out?';
|
|
66
|
+
confirm = `Sign out${anyway}`;
|
|
67
|
+
}
|
|
68
|
+
const lines = warnings.warnings.flatMap((w) =>
|
|
69
|
+
w.code === 'openSession' ? [] : [{ code: w.code, text: WARNING_LINES[w.code]('count' in w ? w.count : 0) }],
|
|
70
|
+
);
|
|
71
|
+
return (
|
|
72
|
+
<Dialog open onOpenChange={(open) => { if (!open) onCancel(); }}>
|
|
73
|
+
<DialogContent testID="switch-confirm">
|
|
74
|
+
<DialogTitle testID="switch-confirm-title">{title}</DialogTitle>
|
|
75
|
+
{!!description && <DialogDescription testID="switch-confirm-description">{description}</DialogDescription>}
|
|
76
|
+
{lines.length > 0 && (
|
|
77
|
+
<View testID="switch-confirm-warnings" className="gap-1">
|
|
78
|
+
{lines.map((line) => (
|
|
79
|
+
<Text key={line.code} testID={`switch-warning-${line.code}`} className="text-muted-foreground">{line.text}</Text>
|
|
80
|
+
))}
|
|
81
|
+
</View>
|
|
82
|
+
)}
|
|
83
|
+
<Button testID="switch-confirm-confirm" className="min-h-14" onPress={onConfirm}>
|
|
84
|
+
<Text>{confirm}</Text>
|
|
85
|
+
</Button>
|
|
86
|
+
{kind === 'signOut' && warnings.sessionOpen && !!onCloseRegister && (
|
|
87
|
+
<Button testID="switch-confirm-close-register" variant="outline" className="min-h-14" onPress={onCloseRegister}>
|
|
88
|
+
<Text>Close register</Text>
|
|
89
|
+
</Button>
|
|
90
|
+
)}
|
|
91
|
+
{kind === 'cashier' && !!onPrintHandover && (
|
|
92
|
+
<Button testID="switch-confirm-handover" variant="outline" className="min-h-14" onPress={onPrintHandover}>
|
|
93
|
+
<Text>Print hand-over slip</Text>
|
|
94
|
+
</Button>
|
|
95
|
+
)}
|
|
96
|
+
<Button testID="switch-confirm-cancel" variant="ghost" className="min-h-14" onPress={onCancel}>
|
|
97
|
+
<Text>Cancel</Text>
|
|
98
|
+
</Button>
|
|
99
|
+
</DialogContent>
|
|
100
|
+
</Dialog>
|
|
101
|
+
);
|
|
102
|
+
}
|