@tallyui/components 3.11.0 → 3.13.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 +230 -17
- package/dist/index.js +2207 -1286
- package/package.json +9 -9
- package/src/fonts/font-provider.tsx +65 -0
- package/src/fonts/index.ts +1 -0
- package/src/index.ts +23 -1
- package/src/order/index.ts +2 -0
- package/src/order/refund-form.tsx +204 -0
- package/src/order/refund-modal.tsx +32 -0
- package/src/register/closure-sheet.tsx +11 -1
- 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 +7 -2
- package/src/sale/catalogue.tsx +44 -4
- package/src/sale/index.ts +1 -0
- package/src/sale/open-sale-tabs.tsx +67 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +17 -3
- package/src/sale/receipt.tsx +47 -22
- 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/ui/text/font-text.tsx +25 -0
- package/src/ui/text/index.tsx +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal POS UI components for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"directory": "packages/components"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tallyui/core": "^3.
|
|
32
|
-
"@tallyui/primitives": "^3.
|
|
33
|
-
"@tallyui/theme": "^3.
|
|
31
|
+
"@tallyui/core": "^3.13.0",
|
|
32
|
+
"@tallyui/primitives": "^3.13.0",
|
|
33
|
+
"@tallyui/theme": "^3.13.0",
|
|
34
34
|
"react": ">=18",
|
|
35
35
|
"react-native": ">=0.74",
|
|
36
36
|
"react-native-svg": ">=15"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"class-variance-authority": "^0.7.1",
|
|
40
|
-
"@tallyui/pos": "3.
|
|
40
|
+
"@tallyui/pos": "3.13.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tallyui/connector-medusa": "3.
|
|
44
|
-
"@tallyui/connector-vendure": "3.
|
|
45
|
-
"@tallyui/connector-woocommerce": "3.
|
|
46
|
-
"@tallyui/mock-api": "3.
|
|
43
|
+
"@tallyui/connector-medusa": "3.13.0",
|
|
44
|
+
"@tallyui/connector-vendure": "3.13.0",
|
|
45
|
+
"@tallyui/connector-woocommerce": "3.13.0",
|
|
46
|
+
"@tallyui/mock-api": "3.13.0",
|
|
47
47
|
"@types/react": ">=18",
|
|
48
48
|
"react": "^19.2.4",
|
|
49
49
|
"react-native-svg": "15.12.1",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Port of WCPOS v2 packages/core/src/contexts/theme-traits/index.tsx (useThemeType).
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
SYSTEM_TYPE, TYPE_SETS, familiesForType, resolveTypeSet,
|
|
5
|
+
type ThemeFontFamily, type ThemeType, type TypeSetId,
|
|
6
|
+
} from '@tallyui/theme';
|
|
7
|
+
|
|
8
|
+
export type FontStatus = 'loading' | 'loaded' | 'failed';
|
|
9
|
+
export interface FontState { setId: TypeSetId; type: ThemeType; status: FontStatus }
|
|
10
|
+
export interface FontProviderProps {
|
|
11
|
+
/** The app's stored `ui.font` setting (from `useAppSettings` in `@tallyui/pos`); missing or unknown means Auto. */
|
|
12
|
+
font?: string | null;
|
|
13
|
+
/** The set Auto resolves to. Default `'system'`: TallyUI themes carry no type set. */
|
|
14
|
+
autoTypeSet?: TypeSetId;
|
|
15
|
+
/**
|
|
16
|
+
* Registers the bundled faces of these families, e.g. with expo-font `loadAsync`. The app owns
|
|
17
|
+
* the OFL files. Without a loader the faces are taken as already registered (e.g. web @font-face).
|
|
18
|
+
*/
|
|
19
|
+
loadFonts?: (families: ThemeFontFamily[]) => Promise<void>;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const FontContext = React.createContext<FontState>({ setId: 'system', type: SYSTEM_TYPE, status: 'loaded' });
|
|
24
|
+
|
|
25
|
+
export function FontProvider({ font, autoTypeSet, loadFonts, children }: FontProviderProps): React.JSX.Element {
|
|
26
|
+
const setId = resolveTypeSet(font, autoTypeSet);
|
|
27
|
+
const [loadState, setLoadState] = React.useState<{ setId: TypeSetId; status: FontStatus }>();
|
|
28
|
+
const hasLoader = loadFonts !== undefined;
|
|
29
|
+
const loaderRef = React.useRef(loadFonts);
|
|
30
|
+
|
|
31
|
+
React.useLayoutEffect(() => {
|
|
32
|
+
loaderRef.current = loadFonts;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const loadFonts = loaderRef.current;
|
|
37
|
+
const families = familiesForType(TYPE_SETS[setId]);
|
|
38
|
+
if (!families.length || !loadFonts) return;
|
|
39
|
+
let stale = false;
|
|
40
|
+
loadFonts(families).then(
|
|
41
|
+
() => {
|
|
42
|
+
if (!stale) setLoadState({ setId, status: 'loaded' });
|
|
43
|
+
},
|
|
44
|
+
(error: unknown) => {
|
|
45
|
+
if (stale) return;
|
|
46
|
+
console.warn('Failed to load fonts', error);
|
|
47
|
+
setLoadState({ setId, status: 'failed' });
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
return () => { stale = true; };
|
|
51
|
+
}, [setId, hasLoader]);
|
|
52
|
+
|
|
53
|
+
const status: FontStatus = !loadFonts || !familiesForType(TYPE_SETS[setId]).length
|
|
54
|
+
? 'loaded'
|
|
55
|
+
: loadState?.setId === setId ? loadState.status : 'loading';
|
|
56
|
+
const value = React.useMemo<FontState>(() => ({
|
|
57
|
+
setId, status, type: status === 'loaded' ? TYPE_SETS[setId] : SYSTEM_TYPE,
|
|
58
|
+
}), [setId, status]);
|
|
59
|
+
|
|
60
|
+
return <FontContext.Provider value={value}>{children}</FontContext.Provider>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function useFontType(): FontState {
|
|
64
|
+
return React.useContext(FontContext);
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FontProvider, useFontType, type FontProviderProps, type FontState, type FontStatus } from './font-provider';
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
// Generic UI components
|
|
4
4
|
export * from './ui';
|
|
5
5
|
|
|
6
|
+
// Scale
|
|
7
|
+
export {
|
|
8
|
+
ScaleProvider, useScale, usePointer,
|
|
9
|
+
type ScaleProviderProps, type ScaleScopeProps, type ScaleState,
|
|
10
|
+
} from './scale';
|
|
11
|
+
|
|
6
12
|
// Product components
|
|
7
13
|
export {
|
|
8
14
|
ProductTitle,
|
|
@@ -114,6 +120,11 @@ export {
|
|
|
114
120
|
OrderDetail,
|
|
115
121
|
type OrderDetailProps,
|
|
116
122
|
type OrderDetailLineItem,
|
|
123
|
+
RefundForm,
|
|
124
|
+
type RefundFormProps,
|
|
125
|
+
type RefundFormValue,
|
|
126
|
+
RefundModal,
|
|
127
|
+
type RefundModalProps,
|
|
117
128
|
} from './order';
|
|
118
129
|
|
|
119
130
|
// Register components
|
|
@@ -157,6 +168,8 @@ export {
|
|
|
157
168
|
ConnectorStatus,
|
|
158
169
|
type ConnectorStatusProps,
|
|
159
170
|
type ConnectionStatus,
|
|
171
|
+
DisplaySettings,
|
|
172
|
+
type DisplaySettingsProps,
|
|
160
173
|
} from './settings';
|
|
161
174
|
|
|
162
175
|
// Sale components
|
|
@@ -165,7 +178,7 @@ export {
|
|
|
165
178
|
PriceForm, parsePrice,
|
|
166
179
|
ChargeForm, type ChargeFormProps,
|
|
167
180
|
Catalogue, formatStockSyncTime, Receipt, injectPrintStyle, SyncStatus, OrdersList, type OrderHistoryRow, orderReference,
|
|
168
|
-
ParkedSales, type ParkedSalesProps,
|
|
181
|
+
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps,
|
|
169
182
|
} from './sale';
|
|
170
183
|
|
|
171
184
|
// Layout components
|
|
@@ -182,3 +195,12 @@ export {
|
|
|
182
195
|
StoreSettingsChoiceScreen,
|
|
183
196
|
type StoreSettingsChoiceScreenProps,
|
|
184
197
|
} from './layout';
|
|
198
|
+
|
|
199
|
+
// Reports components
|
|
200
|
+
export {
|
|
201
|
+
SalesRoom, type SalesRoomProps, SalesHero, type SalesHeroProps, SalesCards, type SalesCardsProps, type SalesCardId,
|
|
202
|
+
SalesFiltersBar, type SalesFiltersBarProps, type SalesFilters, type SalesOption,
|
|
203
|
+
} from './reports';
|
|
204
|
+
|
|
205
|
+
// Fonts
|
|
206
|
+
export { FontProvider, useFontType, type FontProviderProps, type FontState, type FontStatus } from './fonts';
|
package/src/order/index.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { OrderStatusBadge, type OrderStatusBadgeProps, type OrderStatus } from '
|
|
|
2
2
|
export { OrderCard, type OrderCardProps } from './order-card';
|
|
3
3
|
export { OrderList, type OrderListProps } from './order-list';
|
|
4
4
|
export { OrderDetail, type OrderDetailProps, type OrderDetailLineItem } from './order-detail';
|
|
5
|
+
export { RefundForm, type RefundFormProps, type RefundFormValue } from './refund-form';
|
|
6
|
+
export { RefundModal, type RefundModalProps } from './refund-modal';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { useRef, useState, type JSX } from 'react';
|
|
2
|
+
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
+
import { formatMoney, type OrderRefundPayload } from '@tallyui/core';
|
|
4
|
+
import { priceRefund, refundableLines, type EarlierRefund, type RefundableOrderLine } from '@tallyui/pos';
|
|
5
|
+
import { QuantityStepper } from '../input/quantity-stepper';
|
|
6
|
+
import { parsePrice } from '../sale/price-form';
|
|
7
|
+
import { Button } from '../ui/button';
|
|
8
|
+
import { Checkbox } from '../ui/checkbox';
|
|
9
|
+
import { Input } from '../ui/input';
|
|
10
|
+
import { Label } from '../ui/label';
|
|
11
|
+
import { Text } from '../ui/text';
|
|
12
|
+
|
|
13
|
+
/** What the form hands back: the order.refund v1 payload minus the ids, session and clock the caller adds. */
|
|
14
|
+
export type RefundFormValue = Pick<OrderRefundPayload,
|
|
15
|
+
'lines' | 'shippingMinor' | 'adjustmentMinor' | 'totalMinor' | 'destination' | 'reason'>;
|
|
16
|
+
|
|
17
|
+
export interface RefundFormProps {
|
|
18
|
+
/** The order's lines; a StoreOrderLine fits. */
|
|
19
|
+
lines: ReadonlyArray<RefundableOrderLine & { name: string }>;
|
|
20
|
+
/** Earlier refunds' lines, subtracted by order line id. */
|
|
21
|
+
refunds: readonly EarlierRefund[];
|
|
22
|
+
currency: string;
|
|
23
|
+
/** The order number the store shows, for the confirmation. */
|
|
24
|
+
orderReference: string;
|
|
25
|
+
/** The order total with tax. */
|
|
26
|
+
orderTotalMinor: number;
|
|
27
|
+
/** Money already refunded on the order, positive; default 0. */
|
|
28
|
+
refundedMinor?: number;
|
|
29
|
+
/** Shipping still refundable, with tax; 0 or absent hides the shipping field. */
|
|
30
|
+
refundableShippingMinor?: number;
|
|
31
|
+
/** The sale's payment method; omit for a cash sale, which always refunds in cash. */
|
|
32
|
+
originalMethod?: { title: string; available: boolean };
|
|
33
|
+
/** Each line's restock starting value; default true. */
|
|
34
|
+
defaultRestock?: boolean;
|
|
35
|
+
/** Refunds are online only (ADR-080); false disables confirming. Default true. */
|
|
36
|
+
online?: boolean;
|
|
37
|
+
/** A refusal from the caller's last attempt, shown above the actions. */
|
|
38
|
+
error?: string;
|
|
39
|
+
/** Called once per confirmation; the form stays busy until a returned promise settles. */
|
|
40
|
+
onConfirm: (refund: RefundFormValue) => void | Promise<unknown>;
|
|
41
|
+
onCancel: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function parseAmount(text: string, currency: string, signed = false): number | string {
|
|
45
|
+
const trimmed = text.trim();
|
|
46
|
+
if (!trimmed) return 0;
|
|
47
|
+
const negative = signed && trimmed.startsWith('-');
|
|
48
|
+
const parsed = parsePrice(negative ? trimmed.slice(1) : trimmed, currency);
|
|
49
|
+
return negative && typeof parsed === 'number' && parsed !== 0 ? -parsed : parsed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Ports WCPOS v2 form.tsx, monorepo main 5ac185b0e; the till never prices lines itself (priceRefund). */
|
|
53
|
+
export function RefundForm({
|
|
54
|
+
lines, refunds, currency, orderReference, orderTotalMinor, refundedMinor = 0,
|
|
55
|
+
refundableShippingMinor = 0, originalMethod, defaultRestock = true, online = true,
|
|
56
|
+
error, onConfirm, onCancel,
|
|
57
|
+
}: RefundFormProps): JSX.Element {
|
|
58
|
+
const [quantities, setQuantities] = useState<Record<string, number>>({});
|
|
59
|
+
const [restock, setRestock] = useState<Record<string, boolean>>({});
|
|
60
|
+
const [shippingText, setShippingText] = useState('');
|
|
61
|
+
const [adjustmentText, setAdjustmentText] = useState('');
|
|
62
|
+
const [reason, setReason] = useState('');
|
|
63
|
+
const [picked, setPicked] = useState<'original_method' | 'cash' | null>(null);
|
|
64
|
+
const [confirming, setConfirming] = useState(false);
|
|
65
|
+
const [busy, setBusy] = useState(false);
|
|
66
|
+
const busyRef = useRef(false);
|
|
67
|
+
const [thrown, setThrown] = useState('');
|
|
68
|
+
const fmt = (amount: number) => formatMoney({ amount, currency }) ?? '';
|
|
69
|
+
const available = refundableLines(lines, refunds);
|
|
70
|
+
const request = available.map(({ orderLineId, refundableQuantity }) => ({
|
|
71
|
+
orderLineId,
|
|
72
|
+
quantity: Math.min(quantities[orderLineId] ?? 0, refundableQuantity),
|
|
73
|
+
restock: restock[orderLineId] ?? defaultRestock,
|
|
74
|
+
})).filter(({ quantity }) => quantity > 0);
|
|
75
|
+
const priced = priceRefund(lines, refunds, request);
|
|
76
|
+
const shippingMinor = refundableShippingMinor > 0 ? parseAmount(shippingText, currency) : 0;
|
|
77
|
+
const adjustmentMinor = parseAmount(adjustmentText, currency, true);
|
|
78
|
+
const totalMinor = typeof shippingMinor === 'number' && typeof adjustmentMinor === 'number'
|
|
79
|
+
? priced.totalMinor + shippingMinor + adjustmentMinor : undefined;
|
|
80
|
+
const destination = originalMethod?.available ? (picked ?? 'original_method') : 'cash';
|
|
81
|
+
const invalid = typeof shippingMinor === 'string' ? shippingMinor
|
|
82
|
+
: typeof adjustmentMinor === 'string' ? adjustmentMinor
|
|
83
|
+
: shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.`
|
|
84
|
+
: priced.lines.length === 0 && shippingMinor === 0 && adjustmentMinor === 0 ? 'Choose something to refund.'
|
|
85
|
+
: totalMinor! <= 0 ? 'The refund total must be more than 0.'
|
|
86
|
+
: totalMinor! > orderTotalMinor - refundedMinor ? `You can refund at most ${fmt(orderTotalMinor - refundedMinor)}.`
|
|
87
|
+
: reason.trim() === '' ? 'Enter a reason.' : null;
|
|
88
|
+
const disabled = !!invalid || online === false || busy;
|
|
89
|
+
const confirm = async () => {
|
|
90
|
+
if (invalid || online === false || busyRef.current) return;
|
|
91
|
+
busyRef.current = true;
|
|
92
|
+
setBusy(true);
|
|
93
|
+
setThrown('');
|
|
94
|
+
// The parse errors above prevent confirmation until all three amounts are numbers.
|
|
95
|
+
const value: RefundFormValue = {
|
|
96
|
+
lines: priced.lines,
|
|
97
|
+
shippingMinor: shippingMinor as number,
|
|
98
|
+
adjustmentMinor: adjustmentMinor as number,
|
|
99
|
+
totalMinor: totalMinor!,
|
|
100
|
+
destination,
|
|
101
|
+
reason: reason.trim(),
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
await onConfirm(value);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
setThrown(String(e));
|
|
107
|
+
} finally {
|
|
108
|
+
busyRef.current = false;
|
|
109
|
+
setBusy(false);
|
|
110
|
+
setConfirming(false);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<View testID="refund-form" className="flex-1 flex-col gap-4">
|
|
116
|
+
<ScrollView className="flex-1" contentContainerClassName="gap-4">
|
|
117
|
+
<View className="flex-row justify-between gap-2">
|
|
118
|
+
<Text>Total</Text><Text testID="refund-order-total">{fmt(orderTotalMinor)}</Text>
|
|
119
|
+
</View>
|
|
120
|
+
{refundedMinor > 0 && <View className="flex-row justify-between gap-2">
|
|
121
|
+
<Text>Previously Refunded</Text><Text testID="refund-previously-refunded">{fmt(-refundedMinor)}</Text>
|
|
122
|
+
</View>}
|
|
123
|
+
<View className="flex-row flex-wrap items-center gap-2">
|
|
124
|
+
<Text className="flex-[3]">Product</Text><Text>Qty</Text><Text>Refund Qty</Text>
|
|
125
|
+
<Text>Refund Amount</Text><Text>Restock</Text>
|
|
126
|
+
</View>
|
|
127
|
+
{lines.map(({ id, name }, index) => {
|
|
128
|
+
const { refundableQuantity } = available[index];
|
|
129
|
+
return <View key={id} testID={`refund-line-${id}`} className="flex-row flex-wrap items-center gap-2 border-b border-border py-2">
|
|
130
|
+
<Text className="flex-[3]" numberOfLines={1}>{name}</Text>
|
|
131
|
+
<Text testID={`refund-remaining-${id}`}>{refundableQuantity}</Text>
|
|
132
|
+
<QuantityStepper testID={`refund-qty-${id}`} min={0} max={refundableQuantity}
|
|
133
|
+
quantity={Math.min(quantities[id] ?? 0, refundableQuantity)}
|
|
134
|
+
onChangeQuantity={(quantity) => setQuantities((current) => ({ ...current, [id]: quantity }))} />
|
|
135
|
+
<Text testID={`refund-line-amount-${id}`}>{fmt(priced.priced.find((line) => line.orderLineId === id)?.totalMinor ?? 0)}</Text>
|
|
136
|
+
<Checkbox testID={`refund-restock-${id}`} accessibilityLabel={`Restock ${name}`}
|
|
137
|
+
checked={restock[id] ?? defaultRestock}
|
|
138
|
+
onCheckedChange={(checked) => setRestock((current) => ({ ...current, [id]: checked }))} />
|
|
139
|
+
</View>;
|
|
140
|
+
})}
|
|
141
|
+
{refundableShippingMinor > 0 && <View className="gap-2">
|
|
142
|
+
<Label nativeID="refund-shipping-label">Shipping</Label>
|
|
143
|
+
<Input><Input.Field testID="refund-shipping" accessibilityLabel="Shipping"
|
|
144
|
+
accessibilityLabelledBy="refund-shipping-label" keyboardType="decimal-pad" placeholder={fmt(0)}
|
|
145
|
+
value={shippingText} onChangeText={setShippingText} /></Input>
|
|
146
|
+
<Text className="text-muted-foreground">{`Up to ${fmt(refundableShippingMinor)}`}</Text>
|
|
147
|
+
</View>}
|
|
148
|
+
<View className="gap-2">
|
|
149
|
+
<Label nativeID="refund-adjustment-label">Adjustment</Label>
|
|
150
|
+
<Input><Input.Field testID="refund-adjustment" accessibilityLabel="Adjustment"
|
|
151
|
+
accessibilityLabelledBy="refund-adjustment-label" placeholder={fmt(0)}
|
|
152
|
+
value={adjustmentText} onChangeText={setAdjustmentText} /></Input>
|
|
153
|
+
<Text className="text-muted-foreground">A minus sign takes the amount off the refund.</Text>
|
|
154
|
+
</View>
|
|
155
|
+
<View className="gap-2">
|
|
156
|
+
<Label nativeID="refund-reason-label">Reason</Label>
|
|
157
|
+
<Input><Input.Field testID="refund-reason" accessibilityLabel="Reason"
|
|
158
|
+
accessibilityLabelledBy="refund-reason-label" placeholder="Reason for refund" maxLength={500}
|
|
159
|
+
value={reason} onChangeText={setReason} /></Input>
|
|
160
|
+
</View>
|
|
161
|
+
{originalMethod && <View className="gap-2">
|
|
162
|
+
<Text>Refund destination</Text>
|
|
163
|
+
<View className="flex-row flex-wrap gap-2">
|
|
164
|
+
{(['original_method', 'cash'] as const).map((option) => <Pressable key={option}
|
|
165
|
+
testID={`refund-destination-${option}`} accessibilityRole="button"
|
|
166
|
+
accessibilityState={{ selected: destination === option }} aria-selected={destination === option}
|
|
167
|
+
disabled={option === 'original_method' && !originalMethod.available} onPress={() => setPicked(option)}
|
|
168
|
+
className={`rounded-md border border-border px-3 py-2 min-h-11 ${destination === option ? 'bg-primary' : 'bg-card'}`}>
|
|
169
|
+
<Text className={destination === option ? 'text-primary-foreground' : 'text-foreground'}>
|
|
170
|
+
{option === 'original_method' ? `Refund to ${originalMethod.title}` : 'Refund via cash'}
|
|
171
|
+
</Text>
|
|
172
|
+
</Pressable>)}
|
|
173
|
+
</View>
|
|
174
|
+
{!originalMethod.available && <Text className="text-muted-foreground">
|
|
175
|
+
Original payment method refunds are unavailable for this order.
|
|
176
|
+
</Text>}
|
|
177
|
+
</View>}
|
|
178
|
+
<View className="flex-row justify-between gap-2">
|
|
179
|
+
<Text className="font-semibold">Refund Total</Text>
|
|
180
|
+
<Text testID="refund-total" className="font-semibold">{fmt(totalMinor ?? 0)}</Text>
|
|
181
|
+
</View>
|
|
182
|
+
</ScrollView>
|
|
183
|
+
{online === false && <Text testID="refund-offline-reason" className="text-muted-foreground">Refunds need a connection</Text>}
|
|
184
|
+
{invalid && online !== false && <Text testID="refund-invalid" className="text-muted-foreground">{invalid}</Text>}
|
|
185
|
+
{!!(error ?? thrown) && <Text testID="refund-error" className="text-destructive">{error ?? thrown}</Text>}
|
|
186
|
+
{!confirming ? <View className="flex-row gap-2">
|
|
187
|
+
<Button testID="refund-cancel" variant="outline" onPress={onCancel}><Text>Cancel</Text></Button>
|
|
188
|
+
<Button testID="refund-submit" disabled={disabled} onPress={() => setConfirming(true)}>
|
|
189
|
+
<Text>{disabled ? 'Process Refund'
|
|
190
|
+
: `Refund ${fmt(totalMinor ?? 0)} ${destination === 'cash' ? 'in cash' : 'to the original method'}`}</Text>
|
|
191
|
+
</Button>
|
|
192
|
+
</View> : <>
|
|
193
|
+
<Text className="font-semibold">Confirm Refund</Text>
|
|
194
|
+
<Text testID="refund-confirm-text">{`Refund ${fmt(totalMinor ?? 0)} for Order #${orderReference}?`}</Text>
|
|
195
|
+
<View className="flex-row gap-2">
|
|
196
|
+
<Button testID="refund-confirm" variant="destructive" disabled={disabled} onPress={confirm}>
|
|
197
|
+
<Text>{busy ? 'Refunding…' : 'Process Refund'}</Text>
|
|
198
|
+
</Button>
|
|
199
|
+
<Button testID="refund-confirm-cancel" variant="outline" onPress={() => setConfirming(false)}><Text>Cancel</Text></Button>
|
|
200
|
+
</View>
|
|
201
|
+
</>}
|
|
202
|
+
</View>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { Dialog, DialogClose, DialogContent, DialogTitle } from '../ui/dialog';
|
|
4
|
+
import { IconButton } from '../ui/icon-button';
|
|
5
|
+
import { XIcon } from '../ui/icon/x-icon';
|
|
6
|
+
import { RefundForm, type RefundFormProps } from './refund-form';
|
|
7
|
+
|
|
8
|
+
export interface RefundModalProps extends Omit<RefundFormProps, 'onCancel'> {
|
|
9
|
+
open: boolean;
|
|
10
|
+
onOpenChange: (open: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Ports WCPOS v2 modal.tsx: a bounded panel around the refund form. */
|
|
14
|
+
export function RefundModal({ open, onOpenChange, ...formProps }: RefundModalProps): JSX.Element {
|
|
15
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
16
|
+
const maxHeight = Math.max(320, windowHeight - 64);
|
|
17
|
+
return (
|
|
18
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
19
|
+
<DialogContent testID="refund-modal" className="flex-col overflow-hidden" style={{ maxHeight }}>
|
|
20
|
+
<View className="flex-row items-center justify-between gap-2">
|
|
21
|
+
<DialogTitle>{`Refund Order #${formProps.orderReference}`}</DialogTitle>
|
|
22
|
+
<DialogClose asChild>
|
|
23
|
+
<IconButton variant="ghost" size="sm" testID="refund-modal-dismiss" accessibilityLabel="Close panel">
|
|
24
|
+
<XIcon size={16} />
|
|
25
|
+
</IconButton>
|
|
26
|
+
</DialogClose>
|
|
27
|
+
</View>
|
|
28
|
+
<RefundForm {...formProps} onCancel={() => onOpenChange(false)} />
|
|
29
|
+
</DialogContent>
|
|
30
|
+
</Dialog>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -135,7 +135,17 @@ export function ClosureSheet({ register, currency, onPrint, onDone }: ClosureShe
|
|
|
135
135
|
</View>
|
|
136
136
|
)}
|
|
137
137
|
{/* Not a figure: shows who approved the close even while blind. */}
|
|
138
|
-
{!!approvedBy &&
|
|
138
|
+
{!!approvedBy && (
|
|
139
|
+
<View className="flex-row flex-wrap gap-x-2">
|
|
140
|
+
<Text testID="closure-approved-by">Approved by {approvedBy}</Text>
|
|
141
|
+
{/* ADR-082 d9: the store has not yet applied this closure with its proof. */}
|
|
142
|
+
{register.closureApprovalStatus[closure.id] === 'unverified' && (
|
|
143
|
+
<Text testID="closure-approval-unverified" className="text-muted-foreground">
|
|
144
|
+
Approval not yet verified by the store
|
|
145
|
+
</Text>
|
|
146
|
+
)}
|
|
147
|
+
</View>
|
|
148
|
+
)}
|
|
139
149
|
{/* Not a figure either (#287). The wording is approved by the Front desk, 2026-09-30. */}
|
|
140
150
|
{closure.breakdowns.tax_rounding_mixed === true && (
|
|
141
151
|
<Text testID="closure-tax-rounding-mixed" className="text-muted-foreground">
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Sales room's cards over unit 10's figures. Port of WCPOS v2 `screens/main/reports/cards/`
|
|
3
|
+
* (`card.tsx`, `primitives.tsx`, `orders.tsx`, `payments.tsx`, `top-products.tsx`,
|
|
4
|
+
* `categories.tsx`, `taxes.tsx`, `refunds.tsx`); copy is v2's English (`core.json`). An unknown
|
|
5
|
+
* figure (margin with no costed line, kept share of no sales) shows `—`, never 0.
|
|
6
|
+
*/
|
|
7
|
+
import type { JSX, ReactNode } from 'react';
|
|
8
|
+
import { Pressable, Text, View } from 'react-native';
|
|
9
|
+
import { formatMoney } from '@tallyui/core';
|
|
10
|
+
import type { SalesFigures } from '@tallyui/pos';
|
|
11
|
+
import { cn } from '@tallyui/theme';
|
|
12
|
+
import { Card } from '../ui/card';
|
|
13
|
+
|
|
14
|
+
export type SalesCardId = 'orders' | 'payments' | 'products' | 'categories' | 'taxes' | 'refunds';
|
|
15
|
+
export interface SalesCardsProps {
|
|
16
|
+
figures: SalesFigures;
|
|
17
|
+
currency: string;
|
|
18
|
+
/** Opens the card's panel. */
|
|
19
|
+
onOpenCard?: (card: SalesCardId) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const SWATCHES = ['bg-primary', 'bg-info', 'bg-success', 'bg-warning', 'bg-destructive'];
|
|
23
|
+
const OTHER_SWATCH = 'bg-muted-foreground';
|
|
24
|
+
const LEGEND_ROWS = 5;
|
|
25
|
+
const TOP_PRODUCTS = 4;
|
|
26
|
+
const UNKNOWN = '—';
|
|
27
|
+
const percent = (fraction: number) => `${(fraction * 100).toFixed(1)}%`;
|
|
28
|
+
|
|
29
|
+
interface Share { label: string; value: number; text: string; note?: string; swatch: string }
|
|
30
|
+
|
|
31
|
+
function ReportCard({ id, name, figure, onOpen, children }: {
|
|
32
|
+
id: SalesCardId; name: string; figure: string; onOpen?: (card: SalesCardId) => void; children: ReactNode;
|
|
33
|
+
}): JSX.Element {
|
|
34
|
+
const head = (
|
|
35
|
+
<View className="flex-row items-baseline justify-between gap-2">
|
|
36
|
+
<Text className="text-sm text-muted-foreground">{name}</Text>
|
|
37
|
+
<Text testID={`card-${id}-figure`} className="text-lg font-semibold text-foreground">{figure}</Text>
|
|
38
|
+
</View>
|
|
39
|
+
);
|
|
40
|
+
return (
|
|
41
|
+
<Card testID={`card-${id}`} className="min-w-72 flex-1 gap-3 p-4">
|
|
42
|
+
{onOpen ? (
|
|
43
|
+
<Pressable testID={`card-${id}-open`} accessibilityRole="button" accessibilityLabel={name} onPress={() => onOpen(id)}>
|
|
44
|
+
{head}
|
|
45
|
+
</Pressable>
|
|
46
|
+
) : head}
|
|
47
|
+
{children}
|
|
48
|
+
</Card>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const Empty = ({ testID, children }: { testID: string; children: string }) => (
|
|
53
|
+
<Text testID={testID} className="text-sm text-muted-foreground">{children}</Text>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
function StatGrid({ stats }: { stats: { label: string; value: string; testID?: string }[] }): JSX.Element {
|
|
57
|
+
return (
|
|
58
|
+
<View className="flex-row flex-wrap gap-y-2">
|
|
59
|
+
{stats.map((stat) => (
|
|
60
|
+
<View key={stat.label} className="basis-1/3 gap-0.5">
|
|
61
|
+
<Text className="text-xs text-muted-foreground">{stat.label}</Text>
|
|
62
|
+
<Text testID={stat.testID} className="text-sm font-medium text-foreground">{stat.value}</Text>
|
|
63
|
+
</View>
|
|
64
|
+
))}
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ProportionalBar({ shares }: { shares: Share[] }): JSX.Element {
|
|
70
|
+
const positive = shares.filter((share) => share.value > 0);
|
|
71
|
+
return (
|
|
72
|
+
<View className="h-2 flex-row gap-0.5 overflow-hidden rounded-md">
|
|
73
|
+
{positive.length ? positive.map((share, i) => (
|
|
74
|
+
<View key={i} className={share.swatch} style={{ flex: share.value }} />
|
|
75
|
+
)) : <View className="flex-1 bg-muted" />}
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function Legend({ shares }: { shares: Share[] }): JSX.Element {
|
|
81
|
+
return (
|
|
82
|
+
<View className="gap-1.5">
|
|
83
|
+
{shares.map((share, i) => (
|
|
84
|
+
<View key={i} className="flex-row items-center gap-2">
|
|
85
|
+
<View className={cn('h-2.5 w-2.5 rounded-sm', share.swatch)} />
|
|
86
|
+
<Text className="flex-1 text-sm text-foreground" numberOfLines={1}>{share.label}</Text>
|
|
87
|
+
{share.note && <Text className="text-xs text-muted-foreground">{share.note}</Text>}
|
|
88
|
+
<Text className="text-sm font-medium text-foreground">{share.text}</Text>
|
|
89
|
+
</View>
|
|
90
|
+
))}
|
|
91
|
+
</View>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The first rows with their own swatch, the rest folded into Other. */
|
|
96
|
+
function shares<T>(rows: T[], toShare: (row: T) => Omit<Share, 'swatch'>, otherText: (rest: T[]) => string): Share[] {
|
|
97
|
+
const head = rows.slice(0, LEGEND_ROWS).map((row, i) => ({ ...toShare(row), swatch: SWATCHES[i % SWATCHES.length] }));
|
|
98
|
+
const rest = rows.slice(LEGEND_ROWS);
|
|
99
|
+
if (!rest.length) return head;
|
|
100
|
+
return [...head, { label: 'Other', value: rest.reduce((sum, row) => sum + toShare(row).value, 0), text: otherText(rest), swatch: OTHER_SWATCH }];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps): JSX.Element {
|
|
104
|
+
const money = (minor: number) => formatMoney({ amount: minor, currency }) ?? '';
|
|
105
|
+
const { totals, payments, products, categories, taxes, refunds } = figures;
|
|
106
|
+
const { margin } = totals;
|
|
107
|
+
const productNet = products.reduce((sum, row) => sum + row.netMinor, 0);
|
|
108
|
+
const categoryNet = categories.reduce((sum, row) => sum + row.netMinor, 0);
|
|
109
|
+
const paymentShares = shares(payments.rows, (row) => ({
|
|
110
|
+
label: row.label || (row.method === 'unpaid' ? 'Unpaid' : row.method === 'unknown' ? 'Unknown' : row.method),
|
|
111
|
+
value: row.amountMinor, text: money(row.amountMinor), note: `${row.orders} orders`,
|
|
112
|
+
}), (rest) => money(rest.reduce((sum, row) => sum + row.amountMinor, 0)));
|
|
113
|
+
const categoryShares = shares(categories, (row) => ({
|
|
114
|
+
label: row.key === '' ? 'Uncategorised' : row.name, value: row.netMinor, text: money(row.netMinor), note: `${row.quantity} sold`,
|
|
115
|
+
}), (rest) => money(rest.reduce((sum, row) => sum + row.netMinor, 0)));
|
|
116
|
+
const taxShares = shares(taxes, (row) => ({
|
|
117
|
+
label: row.label || 'Tax', value: row.taxMinor, text: money(row.taxMinor),
|
|
118
|
+
note: row.netMinor === null ? undefined : `on ${money(row.netMinor)}`,
|
|
119
|
+
}), (rest) => money(rest.reduce((sum, row) => sum + row.taxMinor, 0)));
|
|
120
|
+
const card = { onOpen: onOpenCard };
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<View testID="sales-cards" className="flex-row flex-wrap gap-4">
|
|
124
|
+
<ReportCard id="orders" name="Orders" figure={String(totals.orderCount)} {...card}>
|
|
125
|
+
{totals.orderCount === 0 ? <Empty testID="card-orders-empty">No orders in this period</Empty> : (
|
|
126
|
+
<View className="gap-2">
|
|
127
|
+
<StatGrid stats={[
|
|
128
|
+
{ label: 'Average order', value: money(totals.averageMinor) },
|
|
129
|
+
{ label: 'Items Sold', value: String(totals.items) },
|
|
130
|
+
{ label: 'Items per order', value: (totals.items / totals.orderCount).toFixed(1) },
|
|
131
|
+
{ label: 'Discounts', value: money(totals.discountMinor) },
|
|
132
|
+
{ label: 'Margin %', value: margin.marginPct === null ? UNKNOWN : percent(margin.marginPct), testID: 'card-orders-margin' },
|
|
133
|
+
]} />
|
|
134
|
+
{margin.missingLines > 0 && (
|
|
135
|
+
<Text testID="card-orders-cost-missing" className="text-xs text-muted-foreground">
|
|
136
|
+
{`Cost missing on ${margin.missingQuantity} of ${totals.items} items`}
|
|
137
|
+
</Text>
|
|
138
|
+
)}
|
|
139
|
+
</View>
|
|
140
|
+
)}
|
|
141
|
+
</ReportCard>
|
|
142
|
+
<ReportCard id="payments" name="Payments" figure={money(totals.grossMinor)} {...card}>
|
|
143
|
+
{payments.rows.length === 0 ? <Empty testID="card-payments-empty">No payments in this period</Empty> : (
|
|
144
|
+
<><ProportionalBar shares={paymentShares} /><Legend shares={paymentShares} /></>
|
|
145
|
+
)}
|
|
146
|
+
</ReportCard>
|
|
147
|
+
<ReportCard id="products" name="Top products" figure={String(totals.items)} {...card}>
|
|
148
|
+
{products.length === 0 ? <Empty testID="card-products-empty">No sales in this period</Empty> : (
|
|
149
|
+
<View className="gap-2">
|
|
150
|
+
{products.slice(0, TOP_PRODUCTS).map((row) => {
|
|
151
|
+
const share = productNet > 0 ? Math.min(1, Math.max(0, row.netMinor / productNet)) : 0;
|
|
152
|
+
return (
|
|
153
|
+
<View key={row.key} className="gap-1">
|
|
154
|
+
<View className="flex-row justify-between gap-2">
|
|
155
|
+
<Text className="flex-1 text-sm text-foreground" numberOfLines={1}>{row.name || 'Unknown'}</Text>
|
|
156
|
+
<Text className="text-sm font-medium text-foreground">{money(row.netMinor)}</Text>
|
|
157
|
+
</View>
|
|
158
|
+
<View className="h-1.5 overflow-hidden rounded-md bg-muted">
|
|
159
|
+
<View className="h-full bg-primary" style={{ width: `${share * 100}%` }} />
|
|
160
|
+
</View>
|
|
161
|
+
<Text className="text-xs text-muted-foreground">{`${percent(share)} · ${row.quantity} sold`}</Text>
|
|
162
|
+
</View>
|
|
163
|
+
);
|
|
164
|
+
})}
|
|
165
|
+
</View>
|
|
166
|
+
)}
|
|
167
|
+
</ReportCard>
|
|
168
|
+
<ReportCard id="categories" name="Categories" figure={money(categoryNet)} {...card}>
|
|
169
|
+
{categories.length === 0 ? <Empty testID="card-categories-empty">No sales in this period</Empty> : (
|
|
170
|
+
<><ProportionalBar shares={categoryShares} /><Legend shares={categoryShares} /></>
|
|
171
|
+
)}
|
|
172
|
+
</ReportCard>
|
|
173
|
+
<ReportCard id="taxes" name="Taxes" figure={money(totals.taxMinor)} {...card}>
|
|
174
|
+
{taxes.length === 0 ? <Empty testID="card-taxes-empty">None in this period</Empty> : (
|
|
175
|
+
<>
|
|
176
|
+
<ProportionalBar shares={taxShares} /><Legend shares={taxShares} />
|
|
177
|
+
<StatGrid stats={[
|
|
178
|
+
{ label: 'Net', value: money(totals.netMinor) },
|
|
179
|
+
{ label: 'Tax', value: money(totals.taxMinor) },
|
|
180
|
+
{ label: 'Gross', value: money(totals.grossMinor) },
|
|
181
|
+
]} />
|
|
182
|
+
</>
|
|
183
|
+
)}
|
|
184
|
+
</ReportCard>
|
|
185
|
+
<ReportCard id="refunds" name="Refunds" figure={money(refunds.amountMinor)} {...card}>
|
|
186
|
+
{refunds.count === 0 ? <Empty testID="card-refunds-none">None in this period</Empty> : (
|
|
187
|
+
<StatGrid stats={[
|
|
188
|
+
{ label: 'Refunded', value: money(refunds.amountMinor) },
|
|
189
|
+
{ label: 'Orders', value: `${refunds.orders} of ${totals.orderCount}` },
|
|
190
|
+
{ label: 'Kept', testID: 'card-refunds-kept',
|
|
191
|
+
value: totals.grossMinor === 0 ? UNKNOWN : percent((totals.grossMinor - refunds.amountMinor) / totals.grossMinor) },
|
|
192
|
+
]} />
|
|
193
|
+
)}
|
|
194
|
+
</ReportCard>
|
|
195
|
+
</View>
|
|
196
|
+
);
|
|
197
|
+
}
|