@tallyui/components 3.20.0 → 4.0.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 +1114 -90
- package/dist/index.js +8077 -3352
- package/package.json +10 -11
- package/src/cart/cart-charge-line.tsx +58 -0
- package/src/cart/cart-columns-form.tsx +98 -0
- package/src/cart/cart-columns.tsx +49 -18
- package/src/cart/cart-foot.tsx +7 -2
- package/src/cart/cart-line-strip.tsx +59 -0
- package/src/cart/cart-line.tsx +20 -8
- package/src/cart/cart-note-row.tsx +30 -0
- package/src/cart/cart-panel.tsx +9 -1
- package/src/cart/cart-row-motion.tsx +125 -0
- package/src/cart/cart-total.tsx +44 -15
- package/src/cart/index.ts +2 -1
- package/src/checkout/cash-tendered.tsx +8 -7
- package/src/checkout/change-display.tsx +2 -1
- package/src/checkout/index.ts +1 -1
- package/src/checkout/payment-selector.tsx +6 -2
- package/src/checkout/payment-types.test-d.ts +28 -0
- package/src/customer/address-editor.tsx +87 -0
- package/src/customer/address-fields.tsx +120 -0
- package/src/customer/customer-dropdown.tsx +200 -0
- package/src/customer/customer-editor.tsx +99 -0
- package/src/customer/customer-form.tsx +39 -5
- package/src/customer/customer-picker.tsx +38 -14
- package/src/customer/customers-list.tsx +83 -0
- package/src/customer/index.ts +5 -0
- package/src/filter/filter-pills.tsx +63 -0
- package/src/i18n/locales/en/components.json +85 -0
- package/src/index.ts +40 -2
- package/src/input/decimal-entry.ts +21 -0
- package/src/layout/checkout-layout.tsx +1 -1
- package/src/layout/live-tab-screen.tsx +1 -1
- package/src/layout/pos-layout.tsx +80 -4
- package/src/layout/settings-layout.tsx +1 -1
- package/src/layout/store-settings-choice-screen.tsx +1 -1
- package/src/lib/current-row.ts +13 -0
- package/src/lib/money-input.ts +16 -0
- package/src/lib/motion.ts +22 -0
- package/src/lib/use-reduced-motion.ts +20 -0
- package/src/order/index.ts +1 -1
- package/src/order/order-detail.tsx +123 -5
- package/src/order/order-filter-bar.tsx +7 -57
- package/src/order/order-status-badge.tsx +42 -19
- package/src/order/refund-form.tsx +7 -5
- package/src/product/camera-scan-button.tsx +2 -0
- package/src/product/category-nav.tsx +8 -0
- package/src/product/category-tile.tsx +65 -15
- package/src/product/in-cart-badge.tsx +55 -6
- package/src/product/index.ts +1 -0
- package/src/product/press-veil.tsx +7 -0
- package/src/product/product-card.tsx +5 -1
- package/src/product/product-grid.tsx +5 -0
- package/src/product/product-price.tsx +6 -3
- package/src/product/product-stock-badge.tsx +3 -2
- package/src/product/product-table.tsx +96 -8
- package/src/product/products-screen-columns.tsx +74 -0
- package/src/product/variant-tile.tsx +68 -0
- package/src/product/variation-picker.tsx +3 -3
- package/src/product/view-toggle.tsx +33 -4
- package/src/register/cashier-sheet.tsx +195 -0
- package/src/register/closure-sheet.tsx +54 -3
- package/src/register/handover-slip.tsx +2 -1
- package/src/register/index.ts +2 -1
- package/src/register/movement-sheet.tsx +66 -7
- package/src/register/open-register-card.tsx +11 -11
- package/src/register/register-bar.helpers.ts +17 -4
- package/src/register/register-bar.tsx +26 -5
- package/src/register/register-count.tsx +158 -24
- package/src/register/register-panel.tsx +16 -5
- package/src/register/register-side-sheet.tsx +32 -8
- package/src/register/switch-confirm.tsx +2 -2
- package/src/reports/card-panel.tsx +131 -0
- package/src/reports/cards.tsx +53 -36
- package/src/reports/hero.tsx +2 -1
- package/src/reports/index.ts +1 -0
- package/src/reports/sales-room.tsx +4 -2
- package/src/sale/breadcrumb.tsx +48 -0
- package/src/sale/cart-bar.tsx +2 -1
- package/src/sale/cart.tsx +127 -38
- package/src/sale/catalogue-settings-form.tsx +92 -0
- package/src/sale/catalogue.tsx +304 -42
- package/src/sale/category-browse.tsx +27 -0
- package/src/sale/charge-form.tsx +85 -21
- package/src/sale/customer-display-screen.tsx +22 -6
- package/src/sale/discount-form.tsx +132 -28
- package/src/sale/index.ts +6 -3
- package/src/sale/line-popover.tsx +72 -36
- package/src/sale/offered-methods.ts +16 -0
- package/src/sale/open-sale-tabs.tsx +58 -10
- package/src/sale/order-note-sheet.tsx +37 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +76 -37
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +7 -5
- package/src/sale/product-filter-bar.tsx +38 -5
- package/src/sale/receipt-sheet.tsx +243 -0
- package/src/sale/receipt.tsx +19 -9
- package/src/sale/sync-status.tsx +10 -0
- package/src/sale/tender-ledger.tsx +92 -0
- package/src/sale/tender-pane.tsx +159 -73
- package/src/sale/tender.tsx +10 -7
- package/src/sale/use-tender.ts +63 -0
- package/src/scale/min-target.tsx +36 -0
- package/src/settings/barcode-scanning-settings.tsx +164 -0
- package/src/settings/connector-status.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +12 -25
- package/src/settings/index.ts +5 -0
- package/src/settings/printer-form.tsx +161 -0
- package/src/settings/printing-settings.tsx +268 -0
- package/src/settings/settings-group.tsx +2 -1
- package/src/settings/tax-calculation-settings.tsx +1 -1
- package/src/shell/added-to-cart-toast.tsx +61 -0
- package/src/shell/app-shell.tsx +5 -1
- package/src/shell/connectivity-toast.tsx +70 -0
- package/src/shell/index.ts +2 -0
- package/src/shell/nav-drawer.tsx +5 -2
- package/src/shell/nav-item.tsx +7 -4
- package/src/shell/nav-rail.tsx +9 -2
- package/src/ui/accordion/index.tsx +86 -8
- package/src/ui/alert-dialog/index.tsx +19 -5
- package/src/ui/combobox/index.tsx +21 -2
- package/src/ui/confirm-dialog/index.tsx +53 -0
- package/src/ui/dialog/index.tsx +68 -14
- package/src/ui/dialog/motion.ts +54 -0
- package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
- package/src/ui/icon/alert-circle-icon.tsx +5 -0
- package/src/ui/icon/alert-triangle-icon.tsx +7 -0
- package/src/ui/icon/banknote-icon.tsx +11 -0
- package/src/ui/icon/cash-register-icon.tsx +10 -0
- package/src/ui/icon/category-icon.tsx +7 -0
- package/src/ui/icon/chart-line-icon.tsx +5 -0
- package/src/ui/icon/check-icon.tsx +5 -0
- package/src/ui/icon/chevron-left-icon.tsx +4 -0
- package/src/ui/icon/chevron-right-icon.tsx +4 -0
- package/src/ui/icon/credit-card-icon.tsx +10 -0
- package/src/ui/icon/discount-icon.tsx +11 -0
- package/src/ui/icon/gift-icon.tsx +10 -0
- package/src/ui/icon/info-circle-icon.tsx +10 -0
- package/src/ui/icon/map-pin-icon.tsx +10 -0
- package/src/ui/icon/message-question-icon.tsx +7 -0
- package/src/ui/icon/pencil-icon.tsx +10 -0
- package/src/ui/icon/plus-icon.tsx +9 -0
- package/src/ui/icon/printer-icon.tsx +10 -0
- package/src/ui/icon/receipt-icon.tsx +7 -0
- package/src/ui/icon/settings-icon.tsx +10 -0
- package/src/ui/icon/sticky-note-icon.tsx +10 -0
- package/src/ui/icon/user-icon.tsx +4 -0
- package/src/ui/icon/users-icon.tsx +7 -0
- package/src/ui/icon/view-grid-icon.tsx +7 -0
- package/src/ui/icon/view-list-icon.tsx +7 -0
- package/src/ui/index.ts +24 -1
- package/src/ui/list-row/index.tsx +93 -0
- package/src/ui/notice/index.tsx +65 -0
- package/src/ui/select/index.tsx +2 -0
- package/src/ui/skeleton/index.tsx +37 -0
- package/src/ui/status-badge/index.tsx +43 -0
- package/src/ui/switch/index.tsx +1 -1
- package/src/ui/tabs/index.tsx +11 -2
- package/src/ui/toggle-group/index.tsx +3 -1
- package/src/ui/tone-disc/index.tsx +41 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Sales room card's figure in full: the side panel its head opens. Port of WCPOS v2
|
|
3
|
+
* `screens/main/reports/panels/` (`panel.tsx`, `specs.ts`, `export-csv.ts`); copy is v2's
|
|
4
|
+
* English. An unknown cost or margin shows `—`, never 0, as on the cards.
|
|
5
|
+
*/
|
|
6
|
+
import type { JSX } from 'react';
|
|
7
|
+
import { ScrollView } from 'react-native';
|
|
8
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
9
|
+
import { csvFromCells, type GroupRow, type Margin, type SalesFigures } from '@tallyui/pos';
|
|
10
|
+
import { cn } from '@tallyui/theme';
|
|
11
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '../ui/dialog';
|
|
12
|
+
import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from '../ui/table';
|
|
13
|
+
import { Button } from '../ui/button';
|
|
14
|
+
import { Text } from '../ui/text';
|
|
15
|
+
import { UNKNOWN, categoryLabel, paymentLabel, percent, productLabel, taxLabel } from './cards';
|
|
16
|
+
|
|
17
|
+
export type SalesPanelId = 'payments' | 'products' | 'categories' | 'taxes';
|
|
18
|
+
export interface SalesCardPanelProps {
|
|
19
|
+
/** The open card; null = closed. */
|
|
20
|
+
card: SalesPanelId | null;
|
|
21
|
+
figures: SalesFigures;
|
|
22
|
+
currency: string;
|
|
23
|
+
/** The scope line under the title, e.g. "Today · Front counter"; the app words it. */
|
|
24
|
+
scope?: string;
|
|
25
|
+
onClose: () => void;
|
|
26
|
+
/** Export CSV shows only when given; receives the CSV text and v2's file name. */
|
|
27
|
+
onExportCsv?: (csv: string, filename: string) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TITLES: Record<SalesPanelId, string> = {
|
|
31
|
+
payments: 'Sales by payment method', products: 'Top products', categories: 'Sales by category', taxes: 'Taxes collected',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** The panel's cells as shown (and exported): head, one line per row, the total row. */
|
|
35
|
+
function panelCells(card: SalesPanelId, figures: SalesFigures, money: (minor: number) => string) {
|
|
36
|
+
const { totals } = figures;
|
|
37
|
+
const share = (minor: number) => (totals.grossMinor === 0 ? '' : percent(minor / totals.grossMinor));
|
|
38
|
+
// Cost and Profit are unknown when no item was costed.
|
|
39
|
+
const margins = (margin: Margin, quantity: number) => {
|
|
40
|
+
const costed = margin.missingQuantity < quantity;
|
|
41
|
+
return [costed ? money(margin.costMinor) : UNKNOWN, costed ? money(margin.profitMinor) : UNKNOWN,
|
|
42
|
+
margin.marginPct === null ? UNKNOWN : percent(margin.marginPct)];
|
|
43
|
+
};
|
|
44
|
+
const groupRow = (row: GroupRow, label: string) => [label, String(row.quantity), money(row.netMinor), ...margins(row.margin, row.quantity)];
|
|
45
|
+
const groupTotal = (rows: GroupRow[], label: string) => [label, String(rows.reduce((sum, row) => sum + row.quantity, 0)),
|
|
46
|
+
money(rows.reduce((sum, row) => sum + row.netMinor, 0)), ...margins(totals.margin, totals.items)];
|
|
47
|
+
switch (card) {
|
|
48
|
+
case 'payments': return {
|
|
49
|
+
head: ['Method', 'Orders', 'Amount', 'Share'],
|
|
50
|
+
rows: figures.payments.rows.map((row) => [paymentLabel(row), String(row.orders), money(row.amountMinor), share(row.amountMinor)]),
|
|
51
|
+
total: ['Total', String(totals.orderCount), money(totals.grossMinor), ''],
|
|
52
|
+
};
|
|
53
|
+
case 'products': return {
|
|
54
|
+
head: ['Product', 'Qty', 'Amount', 'Cost', 'Profit', 'Margin %'],
|
|
55
|
+
rows: figures.products.map((row) => groupRow(row, productLabel(row))),
|
|
56
|
+
total: groupTotal(figures.products, 'All products'),
|
|
57
|
+
};
|
|
58
|
+
case 'categories': return {
|
|
59
|
+
head: ['Category', 'Qty', 'Amount', 'Cost', 'Profit', 'Margin %', 'Share'],
|
|
60
|
+
rows: figures.categories.map((row) => [...groupRow(row, categoryLabel(row)), share(row.netMinor)]),
|
|
61
|
+
total: [...groupTotal(figures.categories, 'Total'), ''],
|
|
62
|
+
};
|
|
63
|
+
case 'taxes': return {
|
|
64
|
+
head: ['Rate', 'Net', 'Tax', 'Gross'],
|
|
65
|
+
rows: figures.taxes.map((row) => [taxLabel(row), row.netMinor === null ? UNKNOWN : money(row.netMinor), money(row.taxMinor),
|
|
66
|
+
row.netMinor === null ? UNKNOWN : money(row.netMinor + row.taxMinor)]),
|
|
67
|
+
total: ['Total', money(totals.netMinor), money(totals.taxMinor), money(totals.grossMinor)],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 9 px per character covers text-sm digits and currency letters, plus the px-2 padding (16 px).
|
|
73
|
+
const columnWidth = (longestCellLength: number) => longestCellLength * 9 + 16;
|
|
74
|
+
|
|
75
|
+
function Cells({ cells, widths, head }: { cells: string[]; widths: number[]; head?: boolean }): JSX.Element {
|
|
76
|
+
const Cell = head ? TableHead : TableCell;
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
{cells.map((cell, i) => (
|
|
80
|
+
<Cell key={i} style={i === 0 ? { flex: 1, minWidth: 0 } : { width: widths[i] }} className="px-2 py-2">
|
|
81
|
+
<Text numberOfLines={i === 0 ? 1 : undefined} className={cn(!head && 'text-sm', i > 0 && 'text-right tabular-nums')}>{cell}</Text>
|
|
82
|
+
</Cell>
|
|
83
|
+
))}
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function SalesCardPanel({ card, figures, currency, scope, onClose, onExportCsv }: SalesCardPanelProps): JSX.Element {
|
|
89
|
+
const formatMoney = useFormatMoney();
|
|
90
|
+
const money = (minor: number) => formatMoney({ amount: minor, currency }) ?? '';
|
|
91
|
+
const { totals } = figures;
|
|
92
|
+
const cells = card === null ? null : panelCells(card, figures, money);
|
|
93
|
+
const lines = cells ? [cells.head, ...cells.rows, cells.total] : [];
|
|
94
|
+
const widths = (cells?.head ?? []).map((_, i) => columnWidth(Math.max(...lines.map((line) => line[i]?.length ?? 0))));
|
|
95
|
+
const costMissing = (card === 'products' || card === 'categories') && totals.margin.missingLines > 0
|
|
96
|
+
? ` · cost missing on ${totals.margin.missingQuantity} of ${totals.items} items` : '';
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Dialog open={card !== null} onOpenChange={(open) => !open && onClose()}>
|
|
100
|
+
{card !== null && cells && (
|
|
101
|
+
<DialogContent side="right" testID="detail-panel" className="max-w-2xl">
|
|
102
|
+
<DialogHeader>
|
|
103
|
+
<DialogTitle>{TITLES[card]}</DialogTitle>
|
|
104
|
+
{scope && <DialogDescription testID="detail-panel-scope">{scope}</DialogDescription>}
|
|
105
|
+
</DialogHeader>
|
|
106
|
+
<Table testID="detail-panel-table" className="flex-1">
|
|
107
|
+
<TableHeader><TableRow><Cells cells={cells.head} widths={widths} head /></TableRow></TableHeader>
|
|
108
|
+
<ScrollView className="flex-1">
|
|
109
|
+
<TableBody>
|
|
110
|
+
{cells.rows.map((row, i) => <TableRow key={i} testID={`detail-panel-row-${i}`}><Cells cells={row} widths={widths} /></TableRow>)}
|
|
111
|
+
</TableBody>
|
|
112
|
+
</ScrollView>
|
|
113
|
+
<TableFooter><TableRow testID="detail-panel-total" className="border-0"><Cells cells={cells.total} widths={widths} /></TableRow></TableFooter>
|
|
114
|
+
</Table>
|
|
115
|
+
<DialogFooter testID="detail-panel-footer" className="flex-row items-center gap-2">
|
|
116
|
+
<Text testID="detail-panel-status" className="flex-1 text-sm text-muted-foreground">
|
|
117
|
+
{`${totals.orderCount} orders · ${money(totals.grossMinor)}${costMissing}`}
|
|
118
|
+
</Text>
|
|
119
|
+
<Button testID="detail-panel-close" variant="outline" className="min-h-11" onPress={onClose}><Text>Close</Text></Button>
|
|
120
|
+
{onExportCsv && (
|
|
121
|
+
<Button testID="detail-panel-export" variant="outline" className="min-h-11"
|
|
122
|
+
onPress={() => onExportCsv(csvFromCells([cells.head, ...cells.rows, cells.total]), `sales-${card}-${figures.range.from}-${figures.range.to}.csv`)}>
|
|
123
|
+
<Text>Export CSV</Text>
|
|
124
|
+
</Button>
|
|
125
|
+
)}
|
|
126
|
+
</DialogFooter>
|
|
127
|
+
</DialogContent>
|
|
128
|
+
)}
|
|
129
|
+
</Dialog>
|
|
130
|
+
);
|
|
131
|
+
}
|
package/src/reports/cards.tsx
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { JSX, ReactNode } from 'react';
|
|
8
8
|
import { Pressable, Text, View } from 'react-native';
|
|
9
|
-
import {
|
|
10
|
-
import type { SalesFigures } from '@tallyui/pos';
|
|
9
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
10
|
+
import type { GroupRow, PaymentRow, SalesFigures, TaxRow } from '@tallyui/pos';
|
|
11
11
|
import { cn } from '@tallyui/theme';
|
|
12
12
|
import { Card } from '../ui/card';
|
|
13
|
+
import { ChevronRightIcon } from '../ui/icon/chevron-right-icon';
|
|
13
14
|
|
|
14
15
|
export type SalesCardId = 'orders' | 'payments' | 'products' | 'categories' | 'taxes' | 'refunds';
|
|
15
16
|
export interface SalesCardsProps {
|
|
@@ -17,33 +18,45 @@ export interface SalesCardsProps {
|
|
|
17
18
|
currency: string;
|
|
18
19
|
/** Opens the card's panel. */
|
|
19
20
|
onOpenCard?: (card: SalesCardId) => void;
|
|
21
|
+
/** Cards to leave out, e.g. one the backend's report cannot fill; the rest keep their order. Default: all six. */
|
|
22
|
+
hide?: SalesCardId[];
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const SWATCHES = ['bg-primary', 'bg-info', 'bg-success', 'bg-warning', 'bg-destructive'];
|
|
23
26
|
const OTHER_SWATCH = 'bg-muted-foreground';
|
|
24
27
|
const LEGEND_ROWS = 5;
|
|
25
28
|
const TOP_PRODUCTS = 4;
|
|
26
|
-
const UNKNOWN = '—';
|
|
27
|
-
const percent = (fraction: number) => `${(fraction * 100).toFixed(1)}%`;
|
|
29
|
+
export const UNKNOWN = '—';
|
|
30
|
+
export const percent = (fraction: number) => `${(fraction * 100).toFixed(1)}%`;
|
|
31
|
+
// The row names the cards and the detail panel (card-panel.tsx) share.
|
|
32
|
+
export const paymentLabel = (row: PaymentRow) =>
|
|
33
|
+
row.label || (row.method === 'unpaid' ? 'Unpaid' : row.method === 'unknown' ? 'Unknown' : row.method);
|
|
34
|
+
export const productLabel = (row: GroupRow) => row.name || 'Unknown';
|
|
35
|
+
export const categoryLabel = (row: GroupRow) => (row.key === '' ? 'Uncategorised' : row.name);
|
|
36
|
+
export const taxLabel = (row: TaxRow) => row.label || 'Tax';
|
|
28
37
|
|
|
29
38
|
interface Share { label: string; value: number; text: string; note?: string; swatch: string }
|
|
30
39
|
|
|
31
40
|
function ReportCard({ id, name, figure, onOpen, children }: {
|
|
32
41
|
id: SalesCardId; name: string; figure: string; onOpen?: (card: SalesCardId) => void; children: ReactNode;
|
|
33
42
|
}): JSX.Element {
|
|
34
|
-
const
|
|
35
|
-
|
|
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
|
-
);
|
|
43
|
+
const label = <Text className="text-sm text-muted-foreground">{name}</Text>;
|
|
44
|
+
const value = <Text testID={`card-${id}-figure`} className="text-lg font-semibold text-foreground">{figure}</Text>;
|
|
40
45
|
return (
|
|
41
46
|
<Card testID={`card-${id}`} className="min-w-72 flex-1 gap-3 p-4">
|
|
42
47
|
{onOpen ? (
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
// v2 card.tsx: a 44 pt head that dims on press, the chevron after the figure.
|
|
49
|
+
<Pressable testID={`card-${id}-open`} accessibilityRole="button" accessibilityLabel={name} onPress={() => onOpen(id)}
|
|
50
|
+
className="min-h-11 flex-row items-center justify-between gap-2 active:opacity-70">
|
|
51
|
+
{label}
|
|
52
|
+
<View className="flex-row items-center gap-1">
|
|
53
|
+
{value}
|
|
54
|
+
<ChevronRightIcon testID={`card-${id}-chevron`} size={16} className="text-muted-foreground" />
|
|
55
|
+
</View>
|
|
45
56
|
</Pressable>
|
|
46
|
-
) :
|
|
57
|
+
) : (
|
|
58
|
+
<View className="flex-row items-baseline justify-between gap-2">{label}{value}</View>
|
|
59
|
+
)}
|
|
47
60
|
{children}
|
|
48
61
|
</Card>
|
|
49
62
|
);
|
|
@@ -93,39 +106,43 @@ function Legend({ shares }: { shares: Share[] }): JSX.Element {
|
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
/** 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: (
|
|
109
|
+
function shares<T>(rows: T[], toShare: (row: T) => Omit<Share, 'swatch'>, otherText: (total: number) => string): Share[] {
|
|
97
110
|
const head = rows.slice(0, LEGEND_ROWS).map((row, i) => ({ ...toShare(row), swatch: SWATCHES[i % SWATCHES.length] }));
|
|
98
111
|
const rest = rows.slice(LEGEND_ROWS);
|
|
99
112
|
if (!rest.length) return head;
|
|
100
|
-
|
|
113
|
+
const total = rest.reduce((sum, row) => sum + toShare(row).value, 0);
|
|
114
|
+
return [...head, { label: 'Other', value: total, text: otherText(total), swatch: OTHER_SWATCH }];
|
|
101
115
|
}
|
|
102
116
|
|
|
103
|
-
export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps): JSX.Element {
|
|
117
|
+
export function SalesCards({ figures, currency, onOpenCard, hide }: SalesCardsProps): JSX.Element {
|
|
118
|
+
const formatMoney = useFormatMoney();
|
|
104
119
|
const money = (minor: number) => formatMoney({ amount: minor, currency }) ?? '';
|
|
105
120
|
const { totals, payments, products, categories, taxes, refunds } = figures;
|
|
106
121
|
const { margin } = totals;
|
|
107
122
|
const productNet = products.reduce((sum, row) => sum + row.netMinor, 0);
|
|
108
123
|
const categoryNet = categories.reduce((sum, row) => sum + row.netMinor, 0);
|
|
109
124
|
const paymentShares = shares(payments.rows, (row) => ({
|
|
110
|
-
label: row
|
|
111
|
-
|
|
112
|
-
}), (rest) => money(rest.reduce((sum, row) => sum + row.amountMinor, 0)));
|
|
125
|
+
label: paymentLabel(row), value: row.amountMinor, text: money(row.amountMinor), note: `${row.orders} orders`,
|
|
126
|
+
}), money);
|
|
113
127
|
const categoryShares = shares(categories, (row) => ({
|
|
114
|
-
label: row
|
|
115
|
-
}),
|
|
128
|
+
label: categoryLabel(row), value: row.netMinor, text: money(row.netMinor), note: `${row.quantity} sold`,
|
|
129
|
+
}), money);
|
|
116
130
|
const taxShares = shares(taxes, (row) => ({
|
|
117
|
-
label: row
|
|
131
|
+
label: taxLabel(row), value: row.taxMinor, text: money(row.taxMinor),
|
|
118
132
|
note: row.netMinor === null ? undefined : `on ${money(row.netMinor)}`,
|
|
119
|
-
}),
|
|
133
|
+
}), money);
|
|
120
134
|
const card = { onOpen: onOpenCard };
|
|
135
|
+
const shows = (id: SalesCardId) => !hide?.includes(id);
|
|
121
136
|
|
|
122
137
|
return (
|
|
123
138
|
<View testID="sales-cards" className="flex-row flex-wrap gap-4">
|
|
124
|
-
<ReportCard id="orders" name="Orders" figure={String(totals.orderCount)} {...card}>
|
|
139
|
+
{shows('orders') && (<ReportCard id="orders" name="Orders" figure={String(totals.orderCount)} {...card}>
|
|
125
140
|
{totals.orderCount === 0 ? <Empty testID="card-orders-empty">No orders in this period</Empty> : (
|
|
126
141
|
<View className="gap-2">
|
|
127
142
|
<StatGrid stats={[
|
|
128
143
|
{ label: 'Average order', value: money(totals.averageMinor) },
|
|
144
|
+
{ label: 'Median', value: totals.medianMinor === undefined ? UNKNOWN : money(totals.medianMinor), testID: 'card-orders-median' },
|
|
145
|
+
{ label: 'Largest', value: totals.largestMinor == null ? UNKNOWN : money(totals.largestMinor), testID: 'card-orders-largest' },
|
|
129
146
|
{ label: 'Items Sold', value: String(totals.items) },
|
|
130
147
|
{ label: 'Items per order', value: (totals.items / totals.orderCount).toFixed(1) },
|
|
131
148
|
{ label: 'Discounts', value: money(totals.discountMinor) },
|
|
@@ -138,13 +155,13 @@ export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps):
|
|
|
138
155
|
)}
|
|
139
156
|
</View>
|
|
140
157
|
)}
|
|
141
|
-
</ReportCard>
|
|
142
|
-
<ReportCard id="payments" name="Payments" figure={money(totals.grossMinor)} {...card}>
|
|
158
|
+
</ReportCard>)}
|
|
159
|
+
{shows('payments') && (<ReportCard id="payments" name="Payments" figure={money(totals.grossMinor)} {...card}>
|
|
143
160
|
{payments.rows.length === 0 ? <Empty testID="card-payments-empty">No payments in this period</Empty> : (
|
|
144
161
|
<><ProportionalBar shares={paymentShares} /><Legend shares={paymentShares} /></>
|
|
145
162
|
)}
|
|
146
|
-
</ReportCard>
|
|
147
|
-
<ReportCard id="products" name="Top products" figure={String(totals.items)} {...card}>
|
|
163
|
+
</ReportCard>)}
|
|
164
|
+
{shows('products') && (<ReportCard id="products" name="Top products" figure={String(totals.items)} {...card}>
|
|
148
165
|
{products.length === 0 ? <Empty testID="card-products-empty">No sales in this period</Empty> : (
|
|
149
166
|
<View className="gap-2">
|
|
150
167
|
{products.slice(0, TOP_PRODUCTS).map((row) => {
|
|
@@ -152,7 +169,7 @@ export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps):
|
|
|
152
169
|
return (
|
|
153
170
|
<View key={row.key} className="gap-1">
|
|
154
171
|
<View className="flex-row justify-between gap-2">
|
|
155
|
-
<Text className="flex-1 text-sm text-foreground" numberOfLines={1}>{row
|
|
172
|
+
<Text className="flex-1 text-sm text-foreground" numberOfLines={1}>{productLabel(row)}</Text>
|
|
156
173
|
<Text className="text-sm font-medium text-foreground">{money(row.netMinor)}</Text>
|
|
157
174
|
</View>
|
|
158
175
|
<View className="h-1.5 overflow-hidden rounded-md bg-muted">
|
|
@@ -164,13 +181,13 @@ export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps):
|
|
|
164
181
|
})}
|
|
165
182
|
</View>
|
|
166
183
|
)}
|
|
167
|
-
</ReportCard>
|
|
168
|
-
<ReportCard id="categories" name="Categories" figure={money(categoryNet)} {...card}>
|
|
184
|
+
</ReportCard>)}
|
|
185
|
+
{shows('categories') && (<ReportCard id="categories" name="Categories" figure={money(categoryNet)} {...card}>
|
|
169
186
|
{categories.length === 0 ? <Empty testID="card-categories-empty">No sales in this period</Empty> : (
|
|
170
187
|
<><ProportionalBar shares={categoryShares} /><Legend shares={categoryShares} /></>
|
|
171
188
|
)}
|
|
172
|
-
</ReportCard>
|
|
173
|
-
<ReportCard id="taxes" name="Taxes" figure={money(totals.taxMinor)} {...card}>
|
|
189
|
+
</ReportCard>)}
|
|
190
|
+
{shows('taxes') && (<ReportCard id="taxes" name="Taxes" figure={money(totals.taxMinor)} {...card}>
|
|
174
191
|
{taxes.length === 0 ? <Empty testID="card-taxes-empty">None in this period</Empty> : (
|
|
175
192
|
<>
|
|
176
193
|
<ProportionalBar shares={taxShares} /><Legend shares={taxShares} />
|
|
@@ -181,8 +198,8 @@ export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps):
|
|
|
181
198
|
]} />
|
|
182
199
|
</>
|
|
183
200
|
)}
|
|
184
|
-
</ReportCard>
|
|
185
|
-
<ReportCard id="refunds" name="Refunds" figure={money(refunds.amountMinor)} {...card}>
|
|
201
|
+
</ReportCard>)}
|
|
202
|
+
{shows('refunds') && (<ReportCard id="refunds" name="Refunds" figure={money(refunds.amountMinor)} {...card}>
|
|
186
203
|
{refunds.count === 0 ? <Empty testID="card-refunds-none">None in this period</Empty> : (
|
|
187
204
|
<StatGrid stats={[
|
|
188
205
|
{ label: 'Refunded', value: money(refunds.amountMinor) },
|
|
@@ -191,7 +208,7 @@ export function SalesCards({ figures, currency, onOpenCard }: SalesCardsProps):
|
|
|
191
208
|
value: totals.grossMinor === 0 ? UNKNOWN : percent((totals.grossMinor - refunds.amountMinor) / totals.grossMinor) },
|
|
192
209
|
]} />
|
|
193
210
|
)}
|
|
194
|
-
</ReportCard>
|
|
211
|
+
</ReportCard>)}
|
|
195
212
|
</View>
|
|
196
213
|
);
|
|
197
214
|
}
|
package/src/reports/hero.tsx
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { JSX } from 'react';
|
|
8
8
|
import { Pressable, Text, View } from 'react-native';
|
|
9
|
-
import {
|
|
9
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
10
10
|
import { daysOf, type SalesFigures } from '@tallyui/pos';
|
|
11
11
|
import { cn } from '@tallyui/theme';
|
|
12
12
|
import { Card } from '../ui/card';
|
|
@@ -46,6 +46,7 @@ function compareLabel(filters: SalesFilters): string {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function SalesHero({ figures, filters, onFiltersChange, currency }: SalesHeroProps): JSX.Element {
|
|
49
|
+
const formatMoney = useFormatMoney();
|
|
49
50
|
const money = (minor: number) => formatMoney({ amount: minor, currency }) ?? '';
|
|
50
51
|
const { totals, series } = figures;
|
|
51
52
|
const before = figures.comparison && figures.comparison.totals.orderCount > 0 ? figures.comparison.totals : undefined;
|
package/src/reports/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
export { SalesCardPanel, type SalesCardPanelProps, type SalesPanelId } from './card-panel';
|
|
4
5
|
export { SalesFiltersBar, type SalesFiltersBarProps, type SalesFilters, type SalesOption } from './filters-bar';
|
|
5
6
|
export { DateRangeMenu, type DateRangeMenuProps } from './date-range-menu';
|
|
@@ -15,14 +15,16 @@ export interface SalesRoomProps extends SalesFiltersBarProps {
|
|
|
15
15
|
currency: string;
|
|
16
16
|
/** Opens a card's panel. */
|
|
17
17
|
onOpenCard?: (card: SalesCardId) => void;
|
|
18
|
+
/** Forwarded to SalesCards as `hide`. */
|
|
19
|
+
hideCards?: SalesCardId[];
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export function SalesRoom({ figures, filters, onFiltersChange, currency, onOpenCard, ...bar }: SalesRoomProps): JSX.Element {
|
|
22
|
+
export function SalesRoom({ figures, filters, onFiltersChange, currency, onOpenCard, hideCards, ...bar }: SalesRoomProps): JSX.Element {
|
|
21
23
|
return (
|
|
22
24
|
<View testID="sales-room" className="gap-4">
|
|
23
25
|
<SalesFiltersBar filters={filters} onFiltersChange={onFiltersChange} {...bar} />
|
|
24
26
|
<SalesHero figures={figures} filters={filters} onFiltersChange={onFiltersChange} currency={currency} />
|
|
25
|
-
<SalesCards figures={figures} currency={currency} onOpenCard={onOpenCard} />
|
|
27
|
+
<SalesCards figures={figures} currency={currency} onOpenCard={onOpenCard} hide={hideCards} />
|
|
26
28
|
</View>
|
|
27
29
|
);
|
|
28
30
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Fragment, useEffect, useRef } from 'react';
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import { ChevronLeftIcon } from '../ui/icon/chevron-left-icon';
|
|
4
|
+
import { ChevronRightIcon } from '../ui/icon/chevron-right-icon';
|
|
5
|
+
|
|
6
|
+
type Crumb = { label: string; onPress: () => void; testID?: string };
|
|
7
|
+
|
|
8
|
+
// Port of v2 packages/components/src/breadcrumb/index.tsx: at phone width only the last parent shows, as
|
|
9
|
+
// "‹ label", with no separators; labels wrap and are never truncated. The caller passes `phone`, as Catalogue
|
|
10
|
+
// already knows it. Not ported: v2's decodeHtml, TextClassContext, min-h-ctl and the children slot.
|
|
11
|
+
export function Breadcrumb({ parents, here, autoFocus, phone, testID }: {
|
|
12
|
+
parents: readonly [Crumb, ...Crumb[]]; here?: string; autoFocus?: boolean; phone: boolean; testID?: string;
|
|
13
|
+
}) {
|
|
14
|
+
const backRef = useRef<View>(null);
|
|
15
|
+
// Focus is a mount action, never a response to later props. `preventScroll`, as v2: no scroll on focus.
|
|
16
|
+
const focusOnMount = useRef(autoFocus);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (focusOnMount.current) {
|
|
19
|
+
(backRef.current as unknown as { focus?: (options: { preventScroll: boolean }) => void } | null)
|
|
20
|
+
?.focus?.({ preventScroll: true });
|
|
21
|
+
}
|
|
22
|
+
}, []);
|
|
23
|
+
let sep = 0;
|
|
24
|
+
const separator = () => (
|
|
25
|
+
<View aria-hidden testID={`${testID}-sep-${sep++}`} className="text-muted-foreground"><ChevronRightIcon size={14} /></View>
|
|
26
|
+
);
|
|
27
|
+
return (
|
|
28
|
+
<View testID={testID} className="flex-row flex-wrap items-center gap-1 px-4 pt-2">
|
|
29
|
+
{parents.map((parent, index) => phone && index < parents.length - 1 ? null : (
|
|
30
|
+
<Fragment key={index}>
|
|
31
|
+
{!phone && index > 0 && separator()}
|
|
32
|
+
<Pressable ref={index === parents.length - 1 ? backRef : undefined} role="button" accessibilityLabel={parent.label}
|
|
33
|
+
onPress={parent.onPress} testID={parent.testID ?? `${testID}-parent-${index}`}
|
|
34
|
+
className="min-h-11 max-w-full justify-center rounded-md px-2">
|
|
35
|
+
<View className="max-w-full flex-row items-center gap-1 text-foreground">
|
|
36
|
+
{phone && <ChevronLeftIcon size={16} />}
|
|
37
|
+
<Text className="shrink font-medium text-foreground">{parent.label}</Text>
|
|
38
|
+
</View>
|
|
39
|
+
</Pressable>
|
|
40
|
+
</Fragment>
|
|
41
|
+
))}
|
|
42
|
+
{here !== undefined && <>
|
|
43
|
+
{!phone && separator()}
|
|
44
|
+
<Text testID={`${testID}-here`} className="shrink px-1 font-semibold text-foreground">{here}</Text>
|
|
45
|
+
</>}
|
|
46
|
+
</View>
|
|
47
|
+
);
|
|
48
|
+
}
|
package/src/sale/cart-bar.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Pressable, Text } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
3
3
|
import { buildReceiptData } from '@tallyui/pos';
|
|
4
4
|
import type { useSale } from '@tallyui/pos';
|
|
5
5
|
|
|
6
6
|
/** Phone mode's cart summary (medusapos ADR 0009): the whole bar is one button; the total is the cart's own Total row. */
|
|
7
7
|
export function CartBar({ sale, onOpen }: { sale: ReturnType<typeof useSale>; onOpen: () => void }) {
|
|
8
|
+
const formatMoney = useFormatMoney();
|
|
8
9
|
const { order } = sale;
|
|
9
10
|
const count = order.lineItems.reduce((sum, line) => sum + line.quantity, 0);
|
|
10
11
|
const total = formatMoney({ amount: buildReceiptData(order, { storeName: '' }).totals.totalMinor, currency: order.currency });
|