@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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Sales room's filters: the period presets (worked out in store time by pos `presetRange`),
|
|
3
|
+
* status, cashier and register. Port of WCPOS v2 `screens/main/reports/date-button.tsx` and the
|
|
4
|
+
* filter choices in its `LEDGER.md`; copy is v2's English (`core.json`).
|
|
5
|
+
*/
|
|
6
|
+
import { useState, type JSX } from 'react';
|
|
7
|
+
import { Pressable, Text, View } from 'react-native';
|
|
8
|
+
import { DATE_PRESETS, presetRange, type DatePreset, type DayRange } from '@tallyui/pos';
|
|
9
|
+
import { cn } from '@tallyui/theme';
|
|
10
|
+
|
|
11
|
+
export interface SalesOption { value: string; label: string }
|
|
12
|
+
export interface SalesFilters {
|
|
13
|
+
preset: DatePreset;
|
|
14
|
+
range: DayRange;
|
|
15
|
+
/** A single day's comparison: the day before or the same weekday last week. */
|
|
16
|
+
compare: 'previous' | 'week';
|
|
17
|
+
status: string;
|
|
18
|
+
cashierId: string | null;
|
|
19
|
+
registerId: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface SalesFiltersBarProps {
|
|
22
|
+
filters: SalesFilters;
|
|
23
|
+
onFiltersChange: (next: SalesFilters) => void;
|
|
24
|
+
/** IANA zone of the store, or 'device'. */
|
|
25
|
+
timezone: string;
|
|
26
|
+
/** The clock presets are worked out from; defaults to the time of the press. */
|
|
27
|
+
now?: () => Date;
|
|
28
|
+
statusOptions: SalesOption[];
|
|
29
|
+
cashierOptions: SalesOption[];
|
|
30
|
+
registerOptions: SalesOption[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const PRESET_LABELS: Record<DatePreset, string> = {
|
|
34
|
+
today: 'Today', yesterday: 'Yesterday', thisWeek: 'This Week',
|
|
35
|
+
lastWeek: 'Last Week', thisMonth: 'This Month', lastMonth: 'Last Month',
|
|
36
|
+
};
|
|
37
|
+
const ALL = 'all';
|
|
38
|
+
|
|
39
|
+
/** `10 Nov` for a store day. */
|
|
40
|
+
export const dayLabel = (day: string): string =>
|
|
41
|
+
new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' }).format(new Date(`${day}T00:00:00Z`));
|
|
42
|
+
|
|
43
|
+
function ChoiceSelect({ id, value, options, onChange }: {
|
|
44
|
+
id: string; value: string; options: SalesOption[]; onChange: (value: string) => void;
|
|
45
|
+
}): JSX.Element {
|
|
46
|
+
const [open, setOpen] = useState(false);
|
|
47
|
+
const chosen = options.find((option) => option.value === value);
|
|
48
|
+
return (
|
|
49
|
+
<View className="gap-1">
|
|
50
|
+
<Pressable testID={id} accessibilityRole="button" onPress={() => setOpen(!open)}
|
|
51
|
+
className="rounded-md border border-border bg-card px-3 py-2">
|
|
52
|
+
<Text className="text-sm text-foreground">{chosen?.label ?? value}</Text>
|
|
53
|
+
</Pressable>
|
|
54
|
+
{open && (
|
|
55
|
+
<View className="rounded-md border border-border bg-card py-1">
|
|
56
|
+
{options.map((option) => (
|
|
57
|
+
<Pressable key={option.value} testID={`${id}-option-${option.value}`} accessibilityRole="radio"
|
|
58
|
+
accessibilityState={{ checked: option.value === value }}
|
|
59
|
+
onPress={() => { setOpen(false); onChange(option.value); }}
|
|
60
|
+
className={cn('px-3 py-2', option.value === value && 'bg-muted')}>
|
|
61
|
+
<Text className="text-sm text-foreground">{option.label}</Text>
|
|
62
|
+
</Pressable>
|
|
63
|
+
))}
|
|
64
|
+
</View>
|
|
65
|
+
)}
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function SalesFiltersBar({
|
|
71
|
+
filters, onFiltersChange, timezone, now, statusOptions, cashierOptions, registerOptions,
|
|
72
|
+
}: SalesFiltersBarProps): JSX.Element {
|
|
73
|
+
const { range } = filters;
|
|
74
|
+
return (
|
|
75
|
+
<View testID="sales-filters" className="flex-row flex-wrap items-start gap-2">
|
|
76
|
+
<ChoiceSelect id="sales-filter-period" value={filters.preset}
|
|
77
|
+
options={DATE_PRESETS.map((preset) => ({ value: preset, label: PRESET_LABELS[preset] }))}
|
|
78
|
+
onChange={(value) => {
|
|
79
|
+
const preset = value as DatePreset;
|
|
80
|
+
onFiltersChange({ ...filters, preset, range: presetRange(preset, (now ?? (() => new Date()))(), timezone) });
|
|
81
|
+
}} />
|
|
82
|
+
<Text testID="sales-filter-dates" className="py-2 text-sm text-muted-foreground">
|
|
83
|
+
{range.from === range.to ? dayLabel(range.from) : `${dayLabel(range.from)} – ${dayLabel(range.to)}`}
|
|
84
|
+
</Text>
|
|
85
|
+
<ChoiceSelect id="sales-filter-status" value={filters.status} options={statusOptions}
|
|
86
|
+
onChange={(status) => onFiltersChange({ ...filters, status })} />
|
|
87
|
+
<ChoiceSelect id="sales-filter-cashier" value={filters.cashierId ?? ALL}
|
|
88
|
+
options={[{ value: ALL, label: 'Everyone' }, ...cashierOptions]}
|
|
89
|
+
onChange={(value) => onFiltersChange({ ...filters, cashierId: value === ALL ? null : value })} />
|
|
90
|
+
<ChoiceSelect id="sales-filter-register" value={filters.registerId ?? ALL}
|
|
91
|
+
options={[{ value: ALL, label: 'All registers' }, ...registerOptions]}
|
|
92
|
+
onChange={(value) => onFiltersChange({ ...filters, registerId: value === ALL ? null : value })} />
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Sales room's hero: the period's gross, its change against the comparison period and a
|
|
3
|
+
* daily chart of both. Port of WCPOS v2 `screens/main/reports/hero/index.tsx` (`Difference`, the
|
|
4
|
+
* companions Orders · Average order · Items) and the comparison labels of its `LEDGER.md`.
|
|
5
|
+
* The bars are Views with theme token classes, so the chart takes its colours from the theme.
|
|
6
|
+
*/
|
|
7
|
+
import type { JSX } 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
|
+
import { dayLabel, type SalesFilters } from './filters-bar';
|
|
14
|
+
|
|
15
|
+
export interface SalesHeroProps {
|
|
16
|
+
figures: SalesFigures;
|
|
17
|
+
filters: SalesFilters;
|
|
18
|
+
onFiltersChange: (next: SalesFilters) => void;
|
|
19
|
+
currency: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const NO_COMPARISON = '—';
|
|
23
|
+
const signed = (diff: number, format: (n: number) => string) =>
|
|
24
|
+
diff === 0 ? '±0' : `${diff > 0 ? '+' : '−'}${format(Math.abs(diff))}`;
|
|
25
|
+
|
|
26
|
+
/** A change against the comparison, or `—` when there is nothing to compare with. */
|
|
27
|
+
function Difference({ testID, text, diff, suffix }: { testID: string; text?: string; diff: number; suffix?: string }): JSX.Element {
|
|
28
|
+
const tone = text === undefined || diff === 0 ? 'text-muted-foreground' : diff > 0 ? 'text-success' : 'text-destructive';
|
|
29
|
+
return (
|
|
30
|
+
<Text testID={testID} className={cn('text-sm', tone)} accessibilityLabel={text === undefined ? 'No comparison' : undefined}>
|
|
31
|
+
{text === undefined ? NO_COMPARISON : suffix ? `${text} ${suffix}` : text}
|
|
32
|
+
</Text>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function compareLabel(filters: SalesFilters): string {
|
|
37
|
+
if (filters.preset === 'thisWeek' || filters.preset === 'lastWeek') return 'vs the week before';
|
|
38
|
+
if (filters.preset === 'thisMonth' || filters.preset === 'lastMonth') return 'vs the month before';
|
|
39
|
+
if (filters.compare === 'previous') return 'vs yesterday';
|
|
40
|
+
const weekday = new Intl.DateTimeFormat('en-GB', { weekday: 'long', timeZone: 'UTC' }).format(new Date(`${filters.range.from}T00:00:00Z`));
|
|
41
|
+
return `vs last ${weekday}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function SalesHero({ figures, filters, onFiltersChange, currency }: SalesHeroProps): JSX.Element {
|
|
45
|
+
const money = (minor: number) => formatMoney({ amount: minor, currency }) ?? '';
|
|
46
|
+
const { totals, series } = figures;
|
|
47
|
+
const before = figures.comparison && figures.comparison.totals.orderCount > 0 ? figures.comparison.totals : undefined;
|
|
48
|
+
const label = compareLabel(filters);
|
|
49
|
+
const grossDiff = before ? totals.grossMinor - before.grossMinor : 0;
|
|
50
|
+
const pct = before && before.grossMinor !== 0 ? Math.round((grossDiff / before.grossMinor) * 1000) / 10 : undefined;
|
|
51
|
+
const companions = [
|
|
52
|
+
{ id: 'orders', name: 'Orders', value: totals.orderCount, prev: before?.orderCount, format: String },
|
|
53
|
+
{ id: 'average', name: 'Average order', value: totals.averageMinor, prev: before?.averageMinor, format: money },
|
|
54
|
+
{ id: 'items', name: 'Items', value: totals.items, prev: before?.items, format: String },
|
|
55
|
+
];
|
|
56
|
+
const compareSeries = figures.comparison?.series ?? [];
|
|
57
|
+
const max = Math.max(0, ...series.map((point) => point.grossMinor), ...compareSeries.map((point) => point.grossMinor));
|
|
58
|
+
const height = (gross: number) => `${max > 0 ? (Math.max(0, gross) / max) * 100 : 0}%` as const;
|
|
59
|
+
const oneDay = filters.preset === 'today' || filters.preset === 'yesterday';
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Card testID="sales-hero" className="gap-4 p-4">
|
|
63
|
+
<View className="flex-row flex-wrap items-end gap-3">
|
|
64
|
+
<Text testID="hero-total" className="text-4xl font-bold text-foreground">{money(totals.grossMinor)}</Text>
|
|
65
|
+
<Difference testID="hero-delta" diff={pct ?? 0} suffix={label}
|
|
66
|
+
text={pct === undefined ? undefined : pct === 0 ? '±0%' : signed(pct, (n) => `${n.toFixed(1)}%`)} />
|
|
67
|
+
</View>
|
|
68
|
+
{oneDay ? (
|
|
69
|
+
<View className="flex-row gap-2">
|
|
70
|
+
{(['previous', 'week'] as const).map((compare) => (
|
|
71
|
+
<Pressable key={compare} testID={`hero-compare-${compare}`} accessibilityRole="radio"
|
|
72
|
+
accessibilityState={{ checked: filters.compare === compare }}
|
|
73
|
+
onPress={() => onFiltersChange({ ...filters, compare })}
|
|
74
|
+
className={cn('rounded-md border border-border px-3 py-1', filters.compare === compare && 'bg-muted')}>
|
|
75
|
+
<Text className="text-sm text-foreground">{compareLabel({ ...filters, compare })}</Text>
|
|
76
|
+
</Pressable>
|
|
77
|
+
))}
|
|
78
|
+
</View>
|
|
79
|
+
) : (
|
|
80
|
+
<Text testID="hero-compare" className="text-sm text-muted-foreground">{label}</Text>
|
|
81
|
+
)}
|
|
82
|
+
<View className="flex-row flex-wrap gap-6">
|
|
83
|
+
{companions.map(({ id, name, value, prev, format }) => (
|
|
84
|
+
<View key={id} className="gap-0.5">
|
|
85
|
+
<Text className="text-xs text-muted-foreground">{name}</Text>
|
|
86
|
+
<Text testID={`hero-${id}`} className="text-lg font-semibold text-foreground">{format(value)}</Text>
|
|
87
|
+
<Difference testID={`hero-${id}-delta`} diff={prev === undefined ? 0 : value - prev}
|
|
88
|
+
text={prev === undefined ? undefined : signed(value - prev, format)} />
|
|
89
|
+
</View>
|
|
90
|
+
))}
|
|
91
|
+
</View>
|
|
92
|
+
<View testID="hero-chart" className="h-40 flex-row items-end gap-1">
|
|
93
|
+
{series.map((point, i) => (
|
|
94
|
+
<View key={point.day} className="h-full flex-1 flex-row items-end gap-0.5">
|
|
95
|
+
{compareSeries[i] && (
|
|
96
|
+
<View testID={`hero-bar-compare-${i}`} className="flex-1 rounded-sm bg-muted-foreground opacity-30"
|
|
97
|
+
style={{ height: height(compareSeries[i].grossMinor) }} />
|
|
98
|
+
)}
|
|
99
|
+
<View testID={`hero-bar-${i}`} className="flex-1 rounded-sm bg-primary" style={{ height: height(point.grossMinor) }} />
|
|
100
|
+
</View>
|
|
101
|
+
))}
|
|
102
|
+
</View>
|
|
103
|
+
{series.length > 0 && (
|
|
104
|
+
<View className="flex-row justify-between">
|
|
105
|
+
<Text className="text-xs text-muted-foreground">{dayLabel(series[0].day)}</Text>
|
|
106
|
+
{series.length > 1 && <Text className="text-xs text-muted-foreground">{dayLabel(series[series.length - 1].day)}</Text>}
|
|
107
|
+
</View>
|
|
108
|
+
)}
|
|
109
|
+
</Card>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SalesRoom, type SalesRoomProps } from './sales-room';
|
|
2
|
+
export { SalesHero, type SalesHeroProps } from './hero';
|
|
3
|
+
export { SalesCards, type SalesCardsProps, type SalesCardId } from './cards';
|
|
4
|
+
export { SalesFiltersBar, type SalesFiltersBarProps, type SalesFilters, type SalesOption } from './filters-bar';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Reports screen's Sales room: filters, hero and cards over one `SalesFigures` result.
|
|
3
|
+
* Port of the WCPOS v2 Sales room layout (`screens/main/reports/`, `LEDGER.md`). It takes the
|
|
4
|
+
* figures and the filter state as props; the screen works the figures out and owns the state.
|
|
5
|
+
*/
|
|
6
|
+
import type { JSX } from 'react';
|
|
7
|
+
import { View } from 'react-native';
|
|
8
|
+
import type { SalesFigures } from '@tallyui/pos';
|
|
9
|
+
import { SalesCards, type SalesCardId } from './cards';
|
|
10
|
+
import { SalesFiltersBar, type SalesFiltersBarProps } from './filters-bar';
|
|
11
|
+
import { SalesHero } from './hero';
|
|
12
|
+
|
|
13
|
+
export interface SalesRoomProps extends SalesFiltersBarProps {
|
|
14
|
+
figures: SalesFigures;
|
|
15
|
+
currency: string;
|
|
16
|
+
/** Opens a card's panel. */
|
|
17
|
+
onOpenCard?: (card: SalesCardId) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function SalesRoom({ figures, filters, onFiltersChange, currency, onOpenCard, ...bar }: SalesRoomProps): JSX.Element {
|
|
21
|
+
return (
|
|
22
|
+
<View testID="sales-room" className="gap-4">
|
|
23
|
+
<SalesFiltersBar filters={filters} onFiltersChange={onFiltersChange} {...bar} />
|
|
24
|
+
<SalesHero figures={figures} filters={filters} onFiltersChange={onFiltersChange} currency={currency} />
|
|
25
|
+
<SalesCards figures={figures} currency={currency} onOpenCard={onOpenCard} />
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
package/src/sale/cart.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { PriceForm } from './price-form';
|
|
|
9
9
|
import { ChargeForm } from './charge-form';
|
|
10
10
|
|
|
11
11
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
12
|
-
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal }:
|
|
12
|
+
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, taxClasses, afterSubtotal, couponDiscountMinor }:
|
|
13
13
|
{ sale: ReturnType<typeof useSale>; taxLabel?: (ratePpm: number) => string;
|
|
14
14
|
taxClasses?: ReadonlyArray<{ id: string; label: string }>;
|
|
15
15
|
/** Shows a Price action on each line. Pass the till's own permission; the control isn't shown without it. */
|
|
@@ -18,6 +18,10 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
18
18
|
onPriceChange?: (change: { lineId: string; fromMinor: number; toMinor: number; reason?: string }) => void;
|
|
19
19
|
/** Rows under the totals' Subtotal, e.g. the platform's coupon chips (passed to CartTotal). */
|
|
20
20
|
afterSubtotal?: ReactNode;
|
|
21
|
+
/** The coupon amount the app itemises in `afterSubtotal` (e.g. Σ `order.display.coupons`), in integer minor units of
|
|
22
|
+
* the order's currency, in the display mode. When given, the Discount row shows the other discounts only (the
|
|
23
|
+
* totals' discount minus this) and is hidden when they come to 0. Absent: the Discount row is the whole discount. */
|
|
24
|
+
couponDiscountMinor?: number;
|
|
21
25
|
}) {
|
|
22
26
|
const { order } = sale;
|
|
23
27
|
const money = (amount: number) => ({ amount, currency: order.currency });
|
|
@@ -96,7 +100,8 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
96
100
|
</View> : null}</>}
|
|
97
101
|
footer={<View testID="cart-footer" className="gap-3 pb-4">
|
|
98
102
|
{/* Exclusive: subtotal − discount + tax = total. Inclusive: subtotal − discount = total, the tax "incl.", not added. */}
|
|
99
|
-
<CartTotal subtotal={money(totals.subtotalMinor)}
|
|
103
|
+
<CartTotal subtotal={money(totals.subtotalMinor)} total={money(totals.totalMinor)}
|
|
104
|
+
discount={money(couponDiscountMinor === undefined ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor))}
|
|
100
105
|
taxLines={taxRows} taxInclusive={totals.taxInclusive} afterSubtotal={afterSubtotal} />
|
|
101
106
|
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
102
107
|
<View className="flex-row gap-3">
|
package/src/sale/catalogue.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { catalogueEntries, findEntryByCode, searchProducts, variantPriceLabel, s
|
|
|
6
6
|
listCategories, inCategory,
|
|
7
7
|
type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction } from '@tallyui/pos';
|
|
8
8
|
import { ProductGrid, ProductImage, ProductPrice, ProductStockBadge, ProductTitle, ProductTable, ViewToggle, CategoryNav } from '../product';
|
|
9
|
+
import { ProductVariantPicker } from '../product/product-variant-picker';
|
|
9
10
|
import { SearchInput } from '../input';
|
|
10
11
|
import { VStack } from '../ui';
|
|
11
12
|
|
|
@@ -34,7 +35,7 @@ function laterOf(a: Date | null | undefined, b: Date | null | undefined): Date |
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength,
|
|
37
|
-
viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories }: {
|
|
38
|
+
viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categories, pickAnyOptions = false }: {
|
|
38
39
|
products: Doc[];
|
|
39
40
|
traits: ProductTraits<Doc>;
|
|
40
41
|
currency: string;
|
|
@@ -82,6 +83,8 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
82
83
|
items?: Doc[];
|
|
83
84
|
/** Search text on every input change, for apps that filter items themselves. */
|
|
84
85
|
onQueryChange?: (query: string) => void;
|
|
86
|
+
/** Ask for a value for each of a variant's local "Any" option groups before onSelect (#495); set it only when the store accepts order.create version 6. */
|
|
87
|
+
pickAnyOptions?: boolean;
|
|
85
88
|
}) {
|
|
86
89
|
const [initial] = useState<{
|
|
87
90
|
state: CatalogueViewState; loaded?: CatalogueViewState; pending?: Promise<unknown>; failed?: boolean; error?: unknown;
|
|
@@ -156,15 +159,40 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
156
159
|
// A product that leaves the catalogue (a resync, or no longer sellable) closes its chooser.
|
|
157
160
|
useEffect(() => { if (chooserId !== null && choices.length === 0) setChooserId(null); }, [chooserId, choices]);
|
|
158
161
|
|
|
162
|
+
// The picker step (#495): the entry waiting for its "Any" picks, and the cashier's picks so far.
|
|
163
|
+
const [pickEntry, setPickEntry] = useState<CatalogueEntry<Doc> | null>(null);
|
|
164
|
+
const [picks, setPicks] = useState<Record<string, string>>({});
|
|
165
|
+
// A variant's local "Any" groups: no backend id (global pa_* attributes are #572), no fixed value on the variant.
|
|
166
|
+
function anyGroupsOf(entry: CatalogueEntry<Doc>) {
|
|
167
|
+
const fixed = entry.variant.options ?? {};
|
|
168
|
+
return (traits.getVariantOptions?.(entry.product) ?? []).filter(({ id, name, values }) =>
|
|
169
|
+
id === undefined && !Object.prototype.hasOwnProperty.call(fixed, name) && values.length > 0);
|
|
170
|
+
}
|
|
171
|
+
const anyGroups = pickEntry ? anyGroupsOf(pickEntry) : [];
|
|
172
|
+
const allPicked = anyGroups.every(({ name }) => picks[name]);
|
|
173
|
+
|
|
174
|
+
function closePicker() {
|
|
175
|
+
setPickEntry(null);
|
|
176
|
+
setPicks({});
|
|
177
|
+
}
|
|
178
|
+
// An entry that leaves the catalogue (a resync, or no longer sellable) closes its picker.
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (pickEntry && !entries.some((entry) => traits.getId(entry.product) === traits.getId(pickEntry.product)
|
|
181
|
+
&& entry.variant.id === pickEntry.variant.id)) closePicker();
|
|
182
|
+
}, [pickEntry, entries, traits]);
|
|
183
|
+
|
|
159
184
|
function select(entry: CatalogueEntry<Doc>) {
|
|
160
|
-
|
|
185
|
+
const picking = pickAnyOptions && anyGroupsOf(entry).length > 0;
|
|
186
|
+
closePicker();
|
|
187
|
+
if (picking) setPickEntry(entry);
|
|
188
|
+
else onSelect(entry);
|
|
161
189
|
setChooserId(null);
|
|
162
190
|
}
|
|
163
191
|
|
|
164
192
|
function selectProduct(product: Doc) {
|
|
165
193
|
const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
|
|
166
194
|
if (variants.length === 1) select(variants[0]);
|
|
167
|
-
else setChooserId(traits.getId(product));
|
|
195
|
+
else { closePicker(); setChooserId(traits.getId(product)); }
|
|
168
196
|
}
|
|
169
197
|
|
|
170
198
|
const emptyState = <Text className="mt-10 text-center text-sm text-muted-foreground">
|
|
@@ -193,7 +221,19 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
193
221
|
{showCategoryNav ? <CategoryNav categories={[{ id: '', name: 'All products' }, ...categoryList]}
|
|
194
222
|
selectedId={activeCategory?.id ?? ''}
|
|
195
223
|
onSelect={(id) => changeState({ type: 'setCategory', categoryId: id === '' ? null : id })} /> : null}
|
|
196
|
-
{
|
|
224
|
+
{pickEntry ? (
|
|
225
|
+
<View accessibilityLabel="Choose options" className="gap-2">
|
|
226
|
+
<Text className="font-semibold text-foreground">{pickEntry.variant.title ?? traits.getName(pickEntry.product)}</Text>
|
|
227
|
+
<ProductVariantPicker options={anyGroups.map(({ name, values }) => ({ name, values }))} selected={picks} onSelect={setPicks} />
|
|
228
|
+
<Pressable accessibilityRole="button" disabled={!allPicked} onPress={() => { onSelect({ ...pickEntry, picks }); closePicker(); }}
|
|
229
|
+
className={`rounded-md border border-border bg-card px-4 py-3 ${allPicked ? '' : 'opacity-50'}`}>
|
|
230
|
+
<Text className="text-center text-foreground">Add to cart</Text>
|
|
231
|
+
</Pressable>
|
|
232
|
+
<Pressable accessibilityRole="button" onPress={closePicker} className="rounded-md border border-border bg-card px-4 py-3">
|
|
233
|
+
<Text className="text-center text-foreground">Cancel</Text>
|
|
234
|
+
</Pressable>
|
|
235
|
+
</View>
|
|
236
|
+
) : choices.length > 0 ? (
|
|
197
237
|
<View accessibilityLabel="Choose variant" className="gap-2">
|
|
198
238
|
{choices.map((entry) => (
|
|
199
239
|
<Pressable key={entry.variant.id} accessibilityRole="button" onPress={() => select(entry)}
|
package/src/sale/index.ts
CHANGED
|
@@ -12,3 +12,4 @@ export { injectPrintStyle } from './print-style';
|
|
|
12
12
|
export { SyncStatus } from './sync-status';
|
|
13
13
|
export { OrdersList, type OrderHistoryRow } from './orders-list';
|
|
14
14
|
export { ParkedSales, type ParkedSalesProps } from './parked-sales';
|
|
15
|
+
export { OpenSaleTabs, type OpenSaleTabsProps } from './open-sale-tabs';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
+
import { formatMoney } from '@tallyui/core';
|
|
4
|
+
import type { OpenSale } from '@tallyui/pos';
|
|
5
|
+
import { Text } from '../ui/text';
|
|
6
|
+
|
|
7
|
+
/** Pass `openSales(sale.order, useParkedSales(drafts).parked)`; `onSelect` and `onNew` call `sale.switchSale(id)` and `sale.switchSale(null)`. */
|
|
8
|
+
export interface OpenSaleTabsProps {
|
|
9
|
+
sales: OpenSale[];
|
|
10
|
+
currency: string;
|
|
11
|
+
onSelect: (id: string) => void;
|
|
12
|
+
onNew: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** v2 cart/tab-who.ts: the customer, or what is in the cart when the customer is a guest. */
|
|
16
|
+
function who(sale: OpenSale): string {
|
|
17
|
+
if (sale.customerName) return sale.customerName;
|
|
18
|
+
if (sale.itemCount === 0) return 'Guest';
|
|
19
|
+
return `Guest · ${sale.itemCount === 1 && sale.firstItem ? sale.firstItem : `${sale.itemCount} ${sale.itemCount === 1 ? 'item' : 'items'}`}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The open sales as cart tabs (v2 cart/tabs.tsx): who, then the Partly paid chip or else the total. The open sale's
|
|
24
|
+
* tab is underlined even when it is the only one; a blank cart has no tab, the + cell is its tab and reads "New".
|
|
25
|
+
*/
|
|
26
|
+
export function OpenSaleTabs({ sales, currency, onSelect, onNew }: OpenSaleTabsProps): JSX.Element {
|
|
27
|
+
const blank = !sales.some((sale) => sale.current);
|
|
28
|
+
return (
|
|
29
|
+
<View testID="open-sale-tabs" className="h-14 flex-row items-stretch border-t border-border bg-card">
|
|
30
|
+
<ScrollView horizontal accessibilityRole="tablist" showsHorizontalScrollIndicator={false} className="min-w-0 flex-1">
|
|
31
|
+
{sales.map((sale) => {
|
|
32
|
+
// isPartlyPaid from @tallyui/pos, inlined: components import only types from pos (v2 cart/tab-chip.tsx).
|
|
33
|
+
const partly = sale.paidMinor > 0 && sale.balanceDueMinor > 0;
|
|
34
|
+
const status = `Partly paid · ${formatMoney({ amount: sale.balanceDueMinor, currency })} due`;
|
|
35
|
+
return (
|
|
36
|
+
<Pressable key={sale.id} testID={`open-sale-tab-${sale.id}`} accessibilityRole="tab"
|
|
37
|
+
accessibilityState={{ selected: sale.current }} aria-selected={sale.current} onPress={() => onSelect(sale.id)}
|
|
38
|
+
className={`h-full justify-center border-b-2 px-3 ${sale.current ? 'border-primary' : 'border-transparent'}`}>
|
|
39
|
+
<Text testID={`open-sale-tab-${sale.id}-who`} numberOfLines={1}
|
|
40
|
+
className={sale.current ? 'font-semibold text-foreground' : 'font-medium text-muted-foreground'}>{who(sale)}</Text>
|
|
41
|
+
{partly && !sale.current ? (
|
|
42
|
+
// Inactive tabs carry the chip; the open tab keeps only the muted words (v2 TabChip).
|
|
43
|
+
<View testID={`open-sale-chip-${sale.id}`} className="flex-row items-center gap-1 self-start rounded-sm bg-info/15 px-1.5 py-0.5">
|
|
44
|
+
<View className="h-1.5 w-1.5 rounded-full bg-info" />
|
|
45
|
+
<Text className="text-xs font-semibold text-foreground">{status}</Text>
|
|
46
|
+
</View>
|
|
47
|
+
) : partly ? (
|
|
48
|
+
<Text testID={`open-sale-status-${sale.id}`} className="text-xs text-muted-foreground">{status}</Text>
|
|
49
|
+
) : (
|
|
50
|
+
<Text testID={`open-sale-tab-${sale.id}-amount`} className="text-xs text-muted-foreground tabular-nums">
|
|
51
|
+
{formatMoney({ amount: sale.totalMinor, currency })}
|
|
52
|
+
</Text>
|
|
53
|
+
)}
|
|
54
|
+
</Pressable>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
</ScrollView>
|
|
58
|
+
<Pressable testID="new-sale-tab" accessibilityRole="tab" accessibilityLabel="New order" accessibilityState={{ selected: blank }} aria-selected={blank}
|
|
59
|
+
// Already on the blank cart: + is a place, not an action (v2).
|
|
60
|
+
onPress={() => { if (!blank) onNew(); }}
|
|
61
|
+
className={`h-full flex-row items-center justify-center gap-1.5 px-3 ${blank ? 'border-b-2 border-primary' : ''}`}>
|
|
62
|
+
<Text className={blank ? 'text-primary' : 'text-foreground'}>+</Text>
|
|
63
|
+
{blank && <Text testID="new-sale-tab-label" className="font-semibold">New</Text>}
|
|
64
|
+
</Pressable>
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -4,3 +4,6 @@ export function orderReference(order: { id: string; serverRefs?: { displayId?: s
|
|
|
4
4
|
const local = order.id.slice(-8);
|
|
5
5
|
return order.serverRefs?.displayId ? `${local} · #${order.serverRefs.displayId}` : local;
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
/** The receipt and Orders say this under a note that went below order.create 7 (ADR-083 condition 2). */
|
|
9
|
+
export const NOTE_NOT_SENT = "The note couldn't be sent to the store.";
|
package/src/sale/orders-list.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
3
|
import { formatMoney, knownWarnings } from '@tallyui/core';
|
|
4
|
-
import { isRequeueable, needsAttention, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
5
|
-
import { orderReference } from './order-reference';
|
|
4
|
+
import { isRequeueable, needsAttention, noteDelivery, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
5
|
+
import { NOTE_NOT_SENT, orderReference } from './order-reference';
|
|
6
6
|
import { sinceText } from './since-text';
|
|
7
7
|
|
|
8
8
|
/** One order from the store's own history (ADR-052 amendment 1), mapped by the app from its platform. */
|
|
@@ -43,11 +43,13 @@ function defaultFormatDate(iso: string) {
|
|
|
43
43
|
* `onRetry` is the outbox's `requeue`; `formatDate` replaces the app's date util; `footer` is the app's own content
|
|
44
44
|
* (medusapos: the feedback link). The router and session redirect stay in the app. `stuck` is the outbox's
|
|
45
45
|
* `state.stuck` (`useOrderOutbox`): those pending orders need attention too, each with its own entry's reason and since.
|
|
46
|
+
* `onOpen` adds an Open button to each row that passes its order to the app.
|
|
46
47
|
* `history` adds read-only store order rows to Recent (ADR-052 amendment 1). */
|
|
47
|
-
export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history }: {
|
|
48
|
+
export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history, onOpen }: {
|
|
48
49
|
orders: PosOrder[]; onRetry(orderIds: string[]): Promise<number>; formatDate?: (iso: string) => string; footer?: ReactNode;
|
|
49
50
|
stuck?: OutboxState['stuck'];
|
|
50
51
|
history?: OrderHistoryRow[];
|
|
52
|
+
onOpen?: (row: PosOrder | OrderHistoryRow) => void;
|
|
51
53
|
}) {
|
|
52
54
|
const retrying = useRef(new Set<string>());
|
|
53
55
|
const [retryingIds, setRetryingIds] = useState(new Set<string>());
|
|
@@ -77,6 +79,11 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
77
79
|
return <View key={`history:${row.id}`} testID={`history-row-${row.id}`} className="gap-1 rounded-md border border-border bg-card p-3">
|
|
78
80
|
<Text className="text-foreground">{`Order ${row.reference} · ${row.itemCount} ${row.itemCount === 1 ? 'item' : 'items'}`}</Text>
|
|
79
81
|
<Text className="text-muted-foreground">{formatDate(row.placedAt)} · {formatMoney({ amount: row.totalMinor, currency: row.currency })} · {row.stateLabel}</Text>
|
|
82
|
+
{onOpen ? <Pressable accessibilityRole="button" accessibilityLabel={`Open order ${row.reference}`}
|
|
83
|
+
testID={`history-open-${row.id}`} onPress={() => onOpen(row)}
|
|
84
|
+
className="rounded-md border border-border px-4 py-2">
|
|
85
|
+
<Text className="text-center font-semibold text-foreground">Open</Text>
|
|
86
|
+
</Pressable> : null}
|
|
80
87
|
</View>;
|
|
81
88
|
}
|
|
82
89
|
const count = order.lines.reduce((sum, line) => sum + line.quantity, 0);
|
|
@@ -96,11 +103,17 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
96
103
|
<Text className="text-foreground">{`Order ${orderReference(order)} · ${count} ${count === 1 ? 'item' : 'items'}`}</Text>
|
|
97
104
|
<Text className="text-muted-foreground">{formatDate(order.createdAt)} · {formatMoney({ amount: order.totalMinor, currency: order.currency })} · {STATUS_LABEL[order.syncStatus]}</Text>
|
|
98
105
|
</Pressable>
|
|
106
|
+
{onOpen ? <Pressable accessibilityRole="button" accessibilityLabel={`Open order ${orderReference(order)}`}
|
|
107
|
+
testID={`order-open-${order.id}`} onPress={() => onOpen(order)}
|
|
108
|
+
className="rounded-md border border-border px-4 py-2">
|
|
109
|
+
<Text className="text-center font-semibold text-foreground">Open</Text>
|
|
110
|
+
</Pressable> : null}
|
|
99
111
|
{isExpanded ? <View testID={`order-detail-${order.id}`} className="mt-1 gap-1 border-t border-border pt-2">
|
|
100
112
|
{order.lines.map((line) => <Text key={line.id} className="text-foreground">{`${line.quantity} × ${line.name}`}</Text>)}
|
|
101
113
|
{order.payments.map((payment) => <Text key={payment.id} className="text-muted-foreground">
|
|
102
114
|
{`${payment.method === 'cash' ? 'Cash' : 'Card terminal'} ${formatMoney({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` · ${payment.reference}` : ''}`}
|
|
103
115
|
</Text>)}
|
|
116
|
+
{order.note ? <Text testID={`order-note-${order.id}`} className="text-foreground">{`Note: ${order.note}`}</Text> : null}
|
|
104
117
|
</View> : null}
|
|
105
118
|
{stuckEntry ? <Text className="text-destructive">
|
|
106
119
|
{/* The same words for any reason, with no reason code; the hour as the status line has it (numeric, #245). */}
|
|
@@ -115,6 +128,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
115
128
|
? `The customer's ${warning.field} couldn't be sent to the store, so the order isn't linked to them.`
|
|
116
129
|
: "The terminal's payment reference couldn't be kept; the payment is recorded without it."}
|
|
117
130
|
</Text>)}
|
|
131
|
+
{noteDelivery(order) === 'not_sent' ? <Text testID={`order-note-not-sent-${order.id}`} className="text-foreground">{NOTE_NOT_SENT}</Text> : null}
|
|
118
132
|
{/* Retry is offered only for a code the outbox resends (isRequeueable). */}
|
|
119
133
|
{section.title === 'Needs attention' && order.syncStatus === 'rejected' && isRequeueable(order.error?.code)
|
|
120
134
|
? <Pressable accessibilityRole="button" disabled={retryingIds.has(order.id)} onPress={async () => {
|
package/src/sale/receipt.tsx
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
import { useEffect, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, Text, View } from 'react-native';
|
|
3
3
|
import { formatMoney } from '@tallyui/core';
|
|
4
|
-
import { buildReceiptData, type SentOrder } from '@tallyui/pos';
|
|
4
|
+
import { buildReceiptData, noteDelivery, type ReceiptData, type SentOrder } from '@tallyui/pos';
|
|
5
5
|
import type { PosOrder } from '@tallyui/pos';
|
|
6
6
|
import { injectPrintStyle } from './print-style';
|
|
7
7
|
import { discountLabel } from './discount-form';
|
|
8
|
-
import { orderReference } from './order-reference';
|
|
8
|
+
import { NOTE_NOT_SENT, orderReference } from './order-reference';
|
|
9
9
|
|
|
10
10
|
const defaultFormatDate = (iso: string) => new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(iso));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
type ReceiptProps = {
|
|
13
|
+
newSale: () => void;
|
|
14
|
+
taxLabel?: (ratePpm: number) => string; topInset?: number; formatDate?: (iso: string) => string;
|
|
15
|
+
/** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
|
|
16
|
+
footerSlot?: ReactNode;
|
|
17
|
+
/** The second button's text; default `New sale`. */
|
|
18
|
+
doneLabel?: string;
|
|
19
|
+
} & ({
|
|
20
|
+
order: SentOrder; store: { name: string; address?: string }; cashier: string; registerId: string;
|
|
17
21
|
/** The register's name, printed as `Register: <name>`; the id is never printed. */
|
|
18
22
|
registerName?: string;
|
|
19
23
|
/** The finalized order (useSale's receipt stage has it). With it the receipt prints its reference and time, the
|
|
20
24
|
* same as Orders; without it (a preview before finalize) the sale id is marked as a draft. */
|
|
21
25
|
posOrder?: PosOrder;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
receipt?: never;
|
|
27
|
+
} | {
|
|
28
|
+
/** A prebuilt receipt, e.g. a reprint from `buildReceiptDataFromPosOrder`/`buildReceiptDataFromStoreOrder` (ADR-081). */
|
|
29
|
+
receipt: ReceiptData;
|
|
30
|
+
/** With it the receipt prints its reference, the same as Orders; without it, the receipt's own order number. */
|
|
31
|
+
posOrder?: PosOrder;
|
|
32
|
+
order?: never; store?: never; cashier?: never; registerId?: never; registerName?: never;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
|
|
36
|
+
* TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
|
|
37
|
+
export function Receipt(props: ReceiptProps) {
|
|
38
|
+
const { posOrder, newSale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`,
|
|
39
|
+
topInset = 0, formatDate = defaultFormatDate, footerSlot, doneLabel = 'New sale' } = props;
|
|
26
40
|
useEffect(injectPrintStyle, []);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
const order = props.receipt === undefined ? props.order : undefined;
|
|
42
|
+
const receipt = props.receipt === undefined ? buildReceiptData(props.order, {
|
|
43
|
+
storeName: props.store.name, storeAddress: props.store.address, cashier: props.cashier, register: props.registerId,
|
|
44
|
+
registerName: props.registerName,
|
|
45
|
+
}) : props.receipt;
|
|
30
46
|
const money = (amount: number) => formatMoney({ amount, currency: receipt.currency }) ?? '';
|
|
31
47
|
const row = (label: string, amount: string, bold = false, key?: number) => <View key={key} accessibilityLabel={`${label}: ${amount}`} className="flex-row justify-between gap-4">
|
|
32
48
|
<Text className={`text-foreground ${bold ? 'font-semibold' : ''}`}>{label}</Text>
|
|
@@ -41,9 +57,11 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
|
|
|
41
57
|
<View className="w-full max-w-md self-center gap-3 p-4 bg-card">
|
|
42
58
|
<Text className="text-lg font-semibold text-foreground">{receipt.header.storeName}</Text>
|
|
43
59
|
{receipt.header.storeAddress ? <Text className="text-muted-foreground">{receipt.header.storeAddress}</Text> : null}
|
|
44
|
-
<Text testID="receipt-order" className="text-foreground">{posOrder ? `Order ${orderReference(posOrder)}`
|
|
45
|
-
|
|
46
|
-
<Text className="text-
|
|
60
|
+
<Text testID="receipt-order" className="text-foreground">{posOrder ? `Order ${orderReference(posOrder)}`
|
|
61
|
+
: order ? `Order ${receipt.header.orderNumber.slice(-8)} (draft)` : `Order ${receipt.header.orderNumber}`}</Text>
|
|
62
|
+
{receipt.fiscal.is_reprint ? <Text testID="receipt-reprint" className="text-foreground">{`Reprint ${receipt.fiscal.reprint_count}`}</Text> : null}
|
|
63
|
+
<Text className="text-muted-foreground">{formatDate(order ? posOrder?.createdAt ?? receipt.header.date : receipt.header.date)}</Text>
|
|
64
|
+
{order || receipt.header.cashier ? <Text className="text-muted-foreground">Cashier: {receipt.header.cashier}</Text> : null}
|
|
47
65
|
{receipt.register.name ? <Text testID="receipt-register" className="text-muted-foreground">Register: {receipt.register.name}</Text> : null}
|
|
48
66
|
{receipt.header.customer && <Text className="text-muted-foreground">Customer: {receipt.header.customer}</Text>}
|
|
49
67
|
{receipt.lineItems.map((line, index) => <View key={index}>
|
|
@@ -51,8 +69,8 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
|
|
|
51
69
|
{Object.entries(line.attributes ?? {}).map(([name, value]) => <Text key={name} className="text-muted-foreground">{`${name}: ${value}`}</Text>)}
|
|
52
70
|
{/* Before any discount, then the line's own discounts as sub-rows (TallyUI ADR-063); they add up to the subtotal. */}
|
|
53
71
|
{row(`${line.quantity} × ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor))}
|
|
54
|
-
{line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${discountLabel(
|
|
55
|
-
order.lineItems[index].discounts[i], receipt.currency)} off`, `−${money(discount.amountMinor)}`)}</View>)}
|
|
72
|
+
{line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${order ? discountLabel(
|
|
73
|
+
order.lineItems[index].discounts[i], receipt.currency) : discount.label} off`, `−${money(discount.amountMinor)}`)}</View>)}
|
|
56
74
|
</View>)}
|
|
57
75
|
{/* Each discount appears once in the totals: line discounts are itemised under their lines and summed once here;
|
|
58
76
|
the order discount appears once. order.display's figures (ADR-063; medusapos ADR 0008). */}
|
|
@@ -64,15 +82,22 @@ export function Receipt({ order, posOrder, store, cashier, registerId, registerN
|
|
|
64
82
|
{receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), false, index))}
|
|
65
83
|
{taxRows}
|
|
66
84
|
{row('Total', money(totals.totalMinor), true)}
|
|
67
|
-
{receipt.payments.map((payment, index) => row(payment.method === 'cash' ? 'Cash tendered'
|
|
85
|
+
{receipt.payments.map((payment, index) => row(payment.method === 'cash' ? 'Cash tendered'
|
|
86
|
+
: order || payment.method === 'external' ? 'Card terminal' : payment.method,
|
|
68
87
|
money(payment.amountMinor) + (payment.reference ? ` · ${payment.reference}` : ''), false, index))}
|
|
69
|
-
{row('Change', money(receipt.changeDueMinor))}
|
|
88
|
+
{order || receipt.changeDueMinor > 0 ? row('Change', money(receipt.changeDueMinor)) : null}
|
|
89
|
+
{receipt.footer.note ? <View testID="receipt-note" className="gap-1">
|
|
90
|
+
<Text className="text-foreground">{receipt.footer.note}</Text>
|
|
91
|
+
{/* ADR-083 condition 2: for the cashier, so it is not printed. */}
|
|
92
|
+
{receipt.footer.noteNotSent || (posOrder !== undefined && noteDelivery(posOrder) === 'not_sent')
|
|
93
|
+
? <View dataSet={{ print: 'hide' }}><Text testID="receipt-note-not-sent" className="text-destructive">{NOTE_NOT_SENT}</Text></View> : null}
|
|
94
|
+
</View> : null}
|
|
70
95
|
{footerSlot ? <View testID="receipt-footer" className="mt-3 items-center border-t border-dashed border-border pt-3">{footerSlot}</View> : null}
|
|
71
96
|
<View dataSet={{ print: 'hide' }} className="flex-row gap-4">
|
|
72
97
|
<Pressable accessibilityRole="button" onPress={() => { if (typeof window !== 'undefined' && typeof window.print === 'function') window.print(); }} className="rounded-md border border-border bg-card px-4 py-3">
|
|
73
98
|
<Text className="text-center text-foreground">Print receipt</Text>
|
|
74
99
|
</Pressable>
|
|
75
|
-
<Pressable accessibilityRole="button" onPress={newSale} className="rounded-md bg-primary px-4 py-3"><Text className="text-center font-semibold text-primary-foreground">
|
|
100
|
+
<Pressable accessibilityRole="button" onPress={newSale} className="rounded-md bg-primary px-4 py-3"><Text className="text-center font-semibold text-primary-foreground">{doneLabel}</Text></Pressable>
|
|
76
101
|
</View>
|
|
77
102
|
</View></>;
|
|
78
103
|
}
|