@burdenoff/microfe-movethewheels 2026.1107.6 → 2026.1108.1
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/components/CarrierRecommendationDialog.js +21 -0
- package/dist/components/DispatchDecisionCard.js +111 -97
- package/dist/components/InventoryCoverPanel.js +401 -0
- package/dist/components/ShipmentDecisionPanel.js +362 -0
- package/dist/components/ShipmentRiskDialog.js +134 -89
- package/dist/generated/tracking-quality-operations.d.ts +288 -0
- package/dist/generated/wspace-types.d.ts +1645 -0
- package/dist/hooks/useInventoryCoverPlan.js +70 -0
- package/dist/hooks/useShipmentDecision.js +111 -0
- package/dist/movethewheels/components/CarrierRecommendationDialog.d.ts +20 -0
- package/dist/movethewheels/components/DispatchDecisionCard.d.ts +5 -1
- package/dist/movethewheels/components/InventoryCoverPanel.d.ts +24 -0
- package/dist/movethewheels/components/ShipmentDecisionPanel.d.ts +14 -0
- package/dist/movethewheels/hooks/useDispatchPlan.d.ts +1 -1
- package/dist/movethewheels/hooks/useInventoryCoverPlan.d.ts +80 -0
- package/dist/movethewheels/hooks/useShipmentDecision.d.ts +67 -0
- package/dist/pages/DispatchPlanPage.js +198 -171
- package/dist/pages/InventoryPage.js +219 -214
- package/package.json +1 -1
- package/src/generated/tracking-quality-operations.ts +321 -0
- package/src/generated/wspace-types.ts +1861 -0
- package/src/movethewheels/components/CarrierRecommendationDialog.tsx +54 -0
- package/src/movethewheels/components/DispatchDecisionCard.tsx +17 -2
- package/src/movethewheels/components/InventoryCoverPanel.tsx +449 -0
- package/src/movethewheels/components/ShipmentDecisionPanel.tsx +459 -0
- package/src/movethewheels/components/ShipmentRiskDialog.tsx +67 -1
- package/src/movethewheels/hooks/useInventoryCoverPlan.ts +250 -0
- package/src/movethewheels/hooks/useShipmentDecision.ts +318 -0
- package/src/movethewheels/pages/DispatchPlanPage.tsx +30 -1
- package/src/movethewheels/pages/InventoryPage.tsx +8 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CarrierRecommendationDialog (BOFF-10908)
|
|
3
|
+
*
|
|
4
|
+
* Carrier recommendation cards for one PLANNED shipment, opened from the
|
|
5
|
+
* dispatch planner when the shipment should go with a carrier rather than the
|
|
6
|
+
* own fleet (no free vehicle, or the dispatcher prefers a carrier). Accepting
|
|
7
|
+
* a card assigns that carrier to the shipment; rejecting changes nothing.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from './ui';
|
|
11
|
+
import { ShipmentDecisionPanel } from './ShipmentDecisionPanel';
|
|
12
|
+
|
|
13
|
+
type Translate = (key: string, fallback: string) => string;
|
|
14
|
+
|
|
15
|
+
interface CarrierRecommendationDialogProps {
|
|
16
|
+
shipment: { id: string; number: string | null } | null;
|
|
17
|
+
onOpenChange: (open: boolean) => void;
|
|
18
|
+
onApplied?: () => void;
|
|
19
|
+
t: Translate;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function CarrierRecommendationDialog({
|
|
23
|
+
shipment,
|
|
24
|
+
onOpenChange,
|
|
25
|
+
onApplied,
|
|
26
|
+
t,
|
|
27
|
+
}: CarrierRecommendationDialogProps) {
|
|
28
|
+
return (
|
|
29
|
+
<Dialog open={shipment !== null} onOpenChange={onOpenChange}>
|
|
30
|
+
<DialogContent className="max-h-[90vh] max-w-xl overflow-y-auto">
|
|
31
|
+
<DialogHeader>
|
|
32
|
+
<DialogTitle>
|
|
33
|
+
{t('movethewheels.carrierDecision.title', 'Carrier recommendation')}
|
|
34
|
+
{shipment ? ` · ${shipment.number ?? shipment.id}` : ''}
|
|
35
|
+
</DialogTitle>
|
|
36
|
+
<DialogDescription>
|
|
37
|
+
{t(
|
|
38
|
+
'movethewheels.carrierDecision.description',
|
|
39
|
+
'Carriers ranked for this shipment’s lane from your own delivery history: on-time record on the lane and overall, and recorded lane cost. Nothing changes until you accept one.'
|
|
40
|
+
)}
|
|
41
|
+
</DialogDescription>
|
|
42
|
+
</DialogHeader>
|
|
43
|
+
{shipment && (
|
|
44
|
+
<ShipmentDecisionPanel
|
|
45
|
+
shipmentId={shipment.id}
|
|
46
|
+
kind="CARRIER_RECOMMENDATION"
|
|
47
|
+
onApplied={onApplied}
|
|
48
|
+
t={t}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
</DialogContent>
|
|
52
|
+
</Dialog>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* until the person applies their decisions.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { Check, Route as RouteIcon, Sparkles, Truck, User, X } from 'lucide-react';
|
|
15
|
+
import { Building2, Check, Route as RouteIcon, Sparkles, Truck, User, X } from 'lucide-react';
|
|
16
16
|
|
|
17
17
|
import { Badge, Button, Card, CardContent } from './ui';
|
|
18
18
|
import type { DispatchAssignment } from '../hooks/useDispatchPlan';
|
|
@@ -52,7 +52,8 @@ export function reasonLabel(reason: string, t: Translate): string {
|
|
|
52
52
|
return entry ? t(entry[0], entry[1]) : reason;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
/** Text colour for a 0..1 confidence; shared by every decision card. */
|
|
56
|
+
export function confidenceTone(confidence: number): string {
|
|
56
57
|
if (confidence >= 0.75) return 'text-status-success-text';
|
|
57
58
|
if (confidence >= 0.5) return 'text-status-warning-text';
|
|
58
59
|
return 'text-status-error-text';
|
|
@@ -66,6 +67,8 @@ interface DispatchDecisionCardProps {
|
|
|
66
67
|
disabled: boolean;
|
|
67
68
|
onChoose: (choice: DispatchChoice) => void;
|
|
68
69
|
onOpenRoute: (routeId: string) => void;
|
|
70
|
+
/** When set, an open card also offers a carrier recommendation for its shipment. */
|
|
71
|
+
onRecommendCarrier?: (shipmentId: string, shipmentNumber: string | null) => void;
|
|
69
72
|
t: Translate;
|
|
70
73
|
}
|
|
71
74
|
|
|
@@ -118,6 +121,7 @@ export function DispatchDecisionCard({
|
|
|
118
121
|
disabled,
|
|
119
122
|
onChoose,
|
|
120
123
|
onOpenRoute,
|
|
124
|
+
onRecommendCarrier,
|
|
121
125
|
t,
|
|
122
126
|
}: DispatchDecisionCardProps) {
|
|
123
127
|
const percent = Math.round(assignment.confidence * 100);
|
|
@@ -233,6 +237,17 @@ export function DispatchDecisionCard({
|
|
|
233
237
|
<X size={14} aria-hidden="true" />
|
|
234
238
|
{t('movethewheels.dispatch.reject', 'Reject')}
|
|
235
239
|
</Button>
|
|
240
|
+
{onRecommendCarrier && (
|
|
241
|
+
<Button
|
|
242
|
+
size="sm"
|
|
243
|
+
variant="ghost"
|
|
244
|
+
disabled={disabled}
|
|
245
|
+
onClick={() => onRecommendCarrier(assignment.shipmentId, assignment.shipmentNumber)}
|
|
246
|
+
>
|
|
247
|
+
<Building2 size={14} aria-hidden="true" />
|
|
248
|
+
{t('movethewheels.carrierDecision.useCarrier', 'Use a carrier instead')}
|
|
249
|
+
</Button>
|
|
250
|
+
)}
|
|
236
251
|
</div>
|
|
237
252
|
) : (
|
|
238
253
|
<DecisionOutcome assignment={assignment} onOpenRoute={onOpenRoute} t={t} />
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InventoryCoverPanel
|
|
3
|
+
*
|
|
4
|
+
* Inventory planning (BOFF-10926): weeks of stock cover per warehouse and
|
|
5
|
+
* SKU against forecast outbound demand, the week stock is projected to run
|
|
6
|
+
* out, and how much to reorder now to hold a target cover once the order
|
|
7
|
+
* lands. Outbound demand comes from the cargo lines of delivery jobs picked
|
|
8
|
+
* up at each warehouse, using the same closed-week history as the lane
|
|
9
|
+
* forecast.
|
|
10
|
+
*
|
|
11
|
+
* Read-only: the plan is computed by `inventoryCoverPlan` on request and
|
|
12
|
+
* never stored, so changing the lead time or the demand scenario has no
|
|
13
|
+
* side effects.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
import { CalendarClock, Info, RefreshCw } from 'lucide-react';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
Button,
|
|
21
|
+
Card,
|
|
22
|
+
CardContent,
|
|
23
|
+
CardDescription,
|
|
24
|
+
CardHeader,
|
|
25
|
+
CardTitle,
|
|
26
|
+
Input,
|
|
27
|
+
Label,
|
|
28
|
+
Select,
|
|
29
|
+
SelectContent,
|
|
30
|
+
SelectItem,
|
|
31
|
+
SelectTrigger,
|
|
32
|
+
SelectValue,
|
|
33
|
+
Skeleton,
|
|
34
|
+
Switch,
|
|
35
|
+
Table,
|
|
36
|
+
TableBody,
|
|
37
|
+
TableCell,
|
|
38
|
+
TableHead,
|
|
39
|
+
TableHeader,
|
|
40
|
+
TableRow,
|
|
41
|
+
} from './ui';
|
|
42
|
+
import { FormError } from './FormError';
|
|
43
|
+
import { formatDate } from '../utils/formatters';
|
|
44
|
+
import {
|
|
45
|
+
DEFAULT_COVER_REQUEST,
|
|
46
|
+
useInventoryCoverPlan,
|
|
47
|
+
type CoverPlanRequest,
|
|
48
|
+
type CoverPlanRow,
|
|
49
|
+
type CoverPlanSummary,
|
|
50
|
+
type CoverStatus,
|
|
51
|
+
} from '../hooks/useInventoryCoverPlan';
|
|
52
|
+
|
|
53
|
+
const ALL_WAREHOUSES = 'all';
|
|
54
|
+
const LIMITS = {
|
|
55
|
+
leadTime: { min: 0, max: 26 },
|
|
56
|
+
targetCover: { min: 1, max: 52 },
|
|
57
|
+
demandPct: { min: -100, max: 500 },
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
const STATUS_META: Record<CoverStatus, { label: string; className: string }> = {
|
|
61
|
+
OUT_OF_STOCK: {
|
|
62
|
+
label: 'Out of stock',
|
|
63
|
+
className: 'bg-status-error-bg-subtle text-status-error-text',
|
|
64
|
+
},
|
|
65
|
+
AT_RISK: {
|
|
66
|
+
label: 'Runs out before lead time',
|
|
67
|
+
className: 'bg-status-error-bg-subtle text-status-error-text',
|
|
68
|
+
},
|
|
69
|
+
REORDER: {
|
|
70
|
+
label: 'Reorder',
|
|
71
|
+
className: 'bg-status-warning-bg-subtle text-status-warning-text',
|
|
72
|
+
},
|
|
73
|
+
HEALTHY: {
|
|
74
|
+
label: 'Healthy',
|
|
75
|
+
className: 'bg-status-success-bg-subtle text-status-success-text',
|
|
76
|
+
},
|
|
77
|
+
NOT_ENOUGH_HISTORY: {
|
|
78
|
+
label: 'Not enough history',
|
|
79
|
+
className: 'bg-muted text-text-secondary',
|
|
80
|
+
},
|
|
81
|
+
NO_DEMAND: {
|
|
82
|
+
label: 'No demand',
|
|
83
|
+
className: 'bg-muted text-text-secondary',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const SUMMARY_TILES: { status: CoverStatus; key: keyof CoverPlanSummary }[] = [
|
|
88
|
+
{ status: 'OUT_OF_STOCK', key: 'outOfStock' },
|
|
89
|
+
{ status: 'AT_RISK', key: 'atRisk' },
|
|
90
|
+
{ status: 'REORDER', key: 'reorder' },
|
|
91
|
+
{ status: 'HEALTHY', key: 'healthy' },
|
|
92
|
+
{ status: 'NOT_ENOUGH_HISTORY', key: 'notEnoughHistory' },
|
|
93
|
+
{ status: 'NO_DEMAND', key: 'noDemand' },
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const formatUnits = (value: number | null, digits = 1): string => {
|
|
97
|
+
if (value === null) return '—';
|
|
98
|
+
return value.toLocaleString(undefined, { maximumFractionDigits: digits });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
interface DraftSettings {
|
|
102
|
+
warehouseId: string;
|
|
103
|
+
leadTime: string;
|
|
104
|
+
targetCover: string;
|
|
105
|
+
demandPct: string;
|
|
106
|
+
actionOnly: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const toDraft = (request: CoverPlanRequest): DraftSettings => ({
|
|
110
|
+
warehouseId: request.warehouseId ?? ALL_WAREHOUSES,
|
|
111
|
+
leadTime: String(request.leadTimeWeeks),
|
|
112
|
+
targetCover: String(request.targetCoverWeeks),
|
|
113
|
+
demandPct: String(request.demandChangePct),
|
|
114
|
+
actionOnly: request.actionOnly,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const inRange = (value: number, bounds: { min: number; max: number }): boolean =>
|
|
118
|
+
Number.isFinite(value) && value >= bounds.min && value <= bounds.max;
|
|
119
|
+
|
|
120
|
+
/** The request a draft describes, or the first problem with it. */
|
|
121
|
+
export function parseCoverDraft(
|
|
122
|
+
draft: DraftSettings
|
|
123
|
+
): { request: CoverPlanRequest; problem: null } | { request: null; problem: string } {
|
|
124
|
+
const leadTimeWeeks = draft.leadTime.trim() === '' ? Number.NaN : Number(draft.leadTime);
|
|
125
|
+
const targetCoverWeeks = draft.targetCover.trim() === '' ? Number.NaN : Number(draft.targetCover);
|
|
126
|
+
const demandChangePct = draft.demandPct.trim() === '' ? 0 : Number(draft.demandPct);
|
|
127
|
+
if (!inRange(leadTimeWeeks, LIMITS.leadTime)) {
|
|
128
|
+
return { request: null, problem: 'Lead time must be between 0 and 26 weeks.' };
|
|
129
|
+
}
|
|
130
|
+
if (!inRange(targetCoverWeeks, LIMITS.targetCover)) {
|
|
131
|
+
return { request: null, problem: 'Target cover must be between 1 and 52 weeks.' };
|
|
132
|
+
}
|
|
133
|
+
if (!inRange(demandChangePct, LIMITS.demandPct)) {
|
|
134
|
+
return { request: null, problem: 'Demand change must be between -100% and 500%.' };
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
request: {
|
|
138
|
+
warehouseId: draft.warehouseId === ALL_WAREHOUSES ? null : draft.warehouseId,
|
|
139
|
+
leadTimeWeeks,
|
|
140
|
+
targetCoverWeeks,
|
|
141
|
+
demandChangePct,
|
|
142
|
+
actionOnly: draft.actionOnly,
|
|
143
|
+
},
|
|
144
|
+
problem: null,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface InventoryCoverPanelProps {
|
|
149
|
+
warehouses: { id: string; name: string }[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function InventoryCoverPanel({ warehouses }: InventoryCoverPanelProps) {
|
|
153
|
+
const { plan, isLoading, error, run } = useInventoryCoverPlan(DEFAULT_COVER_REQUEST);
|
|
154
|
+
const [draft, setDraft] = useState<DraftSettings>(() => toDraft(DEFAULT_COVER_REQUEST));
|
|
155
|
+
const [formError, setFormError] = useState<string | null>(null);
|
|
156
|
+
|
|
157
|
+
const update = (patch: Partial<DraftSettings>) =>
|
|
158
|
+
setDraft((current) => ({ ...current, ...patch }));
|
|
159
|
+
|
|
160
|
+
const submit = (next: DraftSettings) => {
|
|
161
|
+
const parsed = parseCoverDraft(next);
|
|
162
|
+
setFormError(parsed.problem);
|
|
163
|
+
if (parsed.request) run(parsed.request);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<Card data-testid="inventory-cover-panel">
|
|
168
|
+
<CardHeader>
|
|
169
|
+
<CardTitle className="flex items-center gap-2">
|
|
170
|
+
<CalendarClock size={18} aria-hidden="true" />
|
|
171
|
+
Stock cover vs demand forecast
|
|
172
|
+
</CardTitle>
|
|
173
|
+
<CardDescription>
|
|
174
|
+
How many weeks your stock lasts at forecast outbound demand, when each item runs out, and
|
|
175
|
+
how much to reorder now so it lasts through the lead time and your target cover.
|
|
176
|
+
</CardDescription>
|
|
177
|
+
</CardHeader>
|
|
178
|
+
<CardContent className="space-y-6">
|
|
179
|
+
<form
|
|
180
|
+
className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5 lg:items-end"
|
|
181
|
+
onSubmit={(event) => {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
submit(draft);
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<div className="space-y-1.5">
|
|
187
|
+
<Label htmlFor="cover-warehouse">Warehouse</Label>
|
|
188
|
+
<Select
|
|
189
|
+
value={draft.warehouseId}
|
|
190
|
+
onValueChange={(value) => {
|
|
191
|
+
const next = { ...draft, warehouseId: value };
|
|
192
|
+
setDraft(next);
|
|
193
|
+
submit(next);
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<SelectTrigger id="cover-warehouse" aria-label="Warehouse">
|
|
197
|
+
<SelectValue placeholder="All warehouses" />
|
|
198
|
+
</SelectTrigger>
|
|
199
|
+
<SelectContent>
|
|
200
|
+
<SelectItem value={ALL_WAREHOUSES}>All warehouses</SelectItem>
|
|
201
|
+
{warehouses.map((warehouse) => (
|
|
202
|
+
<SelectItem key={warehouse.id} value={warehouse.id}>
|
|
203
|
+
{warehouse.name}
|
|
204
|
+
</SelectItem>
|
|
205
|
+
))}
|
|
206
|
+
</SelectContent>
|
|
207
|
+
</Select>
|
|
208
|
+
</div>
|
|
209
|
+
<div className="space-y-1.5">
|
|
210
|
+
<Label htmlFor="cover-lead-time">Lead time (weeks)</Label>
|
|
211
|
+
<Input
|
|
212
|
+
id="cover-lead-time"
|
|
213
|
+
type="number"
|
|
214
|
+
min={LIMITS.leadTime.min}
|
|
215
|
+
max={LIMITS.leadTime.max}
|
|
216
|
+
step="0.5"
|
|
217
|
+
value={draft.leadTime}
|
|
218
|
+
onChange={(e) => update({ leadTime: e.target.value })}
|
|
219
|
+
/>
|
|
220
|
+
</div>
|
|
221
|
+
<div className="space-y-1.5">
|
|
222
|
+
<Label htmlFor="cover-target">Target cover (weeks)</Label>
|
|
223
|
+
<Input
|
|
224
|
+
id="cover-target"
|
|
225
|
+
type="number"
|
|
226
|
+
min={LIMITS.targetCover.min}
|
|
227
|
+
max={LIMITS.targetCover.max}
|
|
228
|
+
step="0.5"
|
|
229
|
+
value={draft.targetCover}
|
|
230
|
+
onChange={(e) => update({ targetCover: e.target.value })}
|
|
231
|
+
/>
|
|
232
|
+
</div>
|
|
233
|
+
<div className="space-y-1.5">
|
|
234
|
+
<Label htmlFor="cover-demand">Demand change %</Label>
|
|
235
|
+
<Input
|
|
236
|
+
id="cover-demand"
|
|
237
|
+
type="number"
|
|
238
|
+
min={LIMITS.demandPct.min}
|
|
239
|
+
max={LIMITS.demandPct.max}
|
|
240
|
+
value={draft.demandPct}
|
|
241
|
+
onChange={(e) => update({ demandPct: e.target.value })}
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
<Button type="submit" disabled={isLoading}>
|
|
245
|
+
<RefreshCw size={16} aria-hidden="true" className="mr-1" />
|
|
246
|
+
{isLoading ? 'Planning…' : 'Update plan'}
|
|
247
|
+
</Button>
|
|
248
|
+
</form>
|
|
249
|
+
|
|
250
|
+
<div className="flex items-center gap-2">
|
|
251
|
+
<Switch
|
|
252
|
+
id="cover-action-only"
|
|
253
|
+
checked={draft.actionOnly}
|
|
254
|
+
onCheckedChange={(checked) => {
|
|
255
|
+
const next = { ...draft, actionOnly: checked === true };
|
|
256
|
+
setDraft(next);
|
|
257
|
+
submit(next);
|
|
258
|
+
}}
|
|
259
|
+
/>
|
|
260
|
+
<Label htmlFor="cover-action-only" className="font-normal">
|
|
261
|
+
Only items that need action
|
|
262
|
+
</Label>
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
<FormError message={formError} />
|
|
266
|
+
{error && !isLoading && (
|
|
267
|
+
<FormError message={`Couldn't load the stock cover plan: ${error.message}`} />
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
{isLoading && !plan && (
|
|
271
|
+
<div className="space-y-3">
|
|
272
|
+
<Skeleton className="h-16 w-full" />
|
|
273
|
+
<Skeleton className="h-40 w-full" />
|
|
274
|
+
</div>
|
|
275
|
+
)}
|
|
276
|
+
|
|
277
|
+
{plan && (
|
|
278
|
+
<>
|
|
279
|
+
<div
|
|
280
|
+
className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6"
|
|
281
|
+
data-testid="inventory-cover-summary"
|
|
282
|
+
>
|
|
283
|
+
{SUMMARY_TILES.map(({ status, key }) => (
|
|
284
|
+
<div key={status} className="rounded-lg border border-border/60 p-3">
|
|
285
|
+
<p className="text-xs text-text-secondary">{STATUS_META[status].label}</p>
|
|
286
|
+
<p className="text-xl font-semibold tabular-nums">{plan.summary[key]}</p>
|
|
287
|
+
</div>
|
|
288
|
+
))}
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
<PlanNotes
|
|
292
|
+
totalSuggested={plan.summary.totalSuggestedReorderQuantity}
|
|
293
|
+
historyStart={plan.historyStart}
|
|
294
|
+
historyEnd={plan.historyEnd}
|
|
295
|
+
historyWeeks={plan.historyWeeks}
|
|
296
|
+
demandChangePct={plan.demandChangePct}
|
|
297
|
+
unattributedUnits={plan.unattributedUnits}
|
|
298
|
+
unattributedJobs={plan.unattributedJobs}
|
|
299
|
+
truncated={plan.truncated}
|
|
300
|
+
/>
|
|
301
|
+
|
|
302
|
+
{plan.rows.length === 0 ? (
|
|
303
|
+
<p className="rounded-lg border border-border/60 p-4 text-sm text-text-secondary">
|
|
304
|
+
{plan.summary.totalItems === 0
|
|
305
|
+
? 'No stock lines to plan yet. Receive stock into a warehouse to see its cover here.'
|
|
306
|
+
: 'No items need action with these settings.'}
|
|
307
|
+
</p>
|
|
308
|
+
) : (
|
|
309
|
+
<CoverTable rows={plan.rows} />
|
|
310
|
+
)}
|
|
311
|
+
{plan.matchingItems > plan.rows.length && (
|
|
312
|
+
<p className="text-xs text-text-secondary">
|
|
313
|
+
Showing the {plan.rows.length} most urgent of {plan.matchingItems} items.
|
|
314
|
+
</p>
|
|
315
|
+
)}
|
|
316
|
+
</>
|
|
317
|
+
)}
|
|
318
|
+
</CardContent>
|
|
319
|
+
</Card>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface PlanNotesProps {
|
|
324
|
+
totalSuggested: number;
|
|
325
|
+
historyStart: string;
|
|
326
|
+
historyEnd: string;
|
|
327
|
+
historyWeeks: number;
|
|
328
|
+
demandChangePct: number;
|
|
329
|
+
unattributedUnits: number;
|
|
330
|
+
unattributedJobs: number;
|
|
331
|
+
truncated: boolean;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function PlanNotes(props: PlanNotesProps) {
|
|
335
|
+
const lastClosedDay = new Date(new Date(props.historyEnd).getTime() - 24 * 60 * 60 * 1000);
|
|
336
|
+
return (
|
|
337
|
+
<div className="flex items-start gap-2 rounded-lg border border-border/60 bg-muted/40 p-4 text-sm text-text-secondary">
|
|
338
|
+
<Info size={16} aria-hidden="true" className="mt-0.5 shrink-0" />
|
|
339
|
+
<div className="space-y-1" data-testid="inventory-cover-notes">
|
|
340
|
+
<p>
|
|
341
|
+
Suggested reorder across these items:{' '}
|
|
342
|
+
<span className="font-medium text-text-primary">
|
|
343
|
+
{props.totalSuggested.toLocaleString()} units
|
|
344
|
+
</span>
|
|
345
|
+
. Demand is forecast from the cargo lines of delivery jobs picked up at each warehouse
|
|
346
|
+
over the last {props.historyWeeks} closed weeks ({formatDate(props.historyStart)} –{' '}
|
|
347
|
+
{formatDate(lastClosedDay)})
|
|
348
|
+
{props.demandChangePct !== 0
|
|
349
|
+
? `, with a ${props.demandChangePct > 0 ? '+' : ''}${props.demandChangePct}% demand scenario`
|
|
350
|
+
: ''}
|
|
351
|
+
. Usable stock is on hand minus damaged.
|
|
352
|
+
</p>
|
|
353
|
+
{props.unattributedUnits > 0 && (
|
|
354
|
+
<p>
|
|
355
|
+
{formatUnits(props.unattributedUnits)} units on {props.unattributedJobs} delivery job
|
|
356
|
+
{props.unattributedJobs === 1 ? '' : 's'} could not be matched to a warehouse. Set{' '}
|
|
357
|
+
<code>warehouseId</code> or <code>warehouseCode</code> on the job's pickup address
|
|
358
|
+
to count them.
|
|
359
|
+
</p>
|
|
360
|
+
)}
|
|
361
|
+
{props.truncated && (
|
|
362
|
+
<p>This workspace has more history than one plan reads; the plan uses the newest.</p>
|
|
363
|
+
)}
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function StatusPill({ status }: { status: CoverStatus }) {
|
|
370
|
+
const meta = STATUS_META[status];
|
|
371
|
+
return (
|
|
372
|
+
<span
|
|
373
|
+
className={`inline-flex whitespace-nowrap rounded-full px-2 py-0.5 text-xs font-medium ${meta.className}`}
|
|
374
|
+
>
|
|
375
|
+
{meta.label}
|
|
376
|
+
</span>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function demandCell(row: CoverPlanRow): string {
|
|
381
|
+
if (row.demandStatus === 'NOT_ENOUGH_HISTORY') return 'Not enough history';
|
|
382
|
+
if (row.forecastWeeklyDemand === null) return 'None';
|
|
383
|
+
return `${formatUnits(row.forecastWeeklyDemand)}/wk`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function CoverTable({ rows }: { rows: CoverPlanRow[] }) {
|
|
387
|
+
return (
|
|
388
|
+
<div className="overflow-x-auto" data-testid="inventory-cover-table">
|
|
389
|
+
<Table>
|
|
390
|
+
<TableHeader>
|
|
391
|
+
<TableRow>
|
|
392
|
+
<TableHead>Item</TableHead>
|
|
393
|
+
<TableHead>Warehouse</TableHead>
|
|
394
|
+
<TableHead className="text-right">Usable stock</TableHead>
|
|
395
|
+
<TableHead className="text-right">Forecast demand</TableHead>
|
|
396
|
+
<TableHead className="text-right">Weeks of cover</TableHead>
|
|
397
|
+
<TableHead>Runs out</TableHead>
|
|
398
|
+
<TableHead className="text-right">Suggested order</TableHead>
|
|
399
|
+
<TableHead>Status</TableHead>
|
|
400
|
+
</TableRow>
|
|
401
|
+
</TableHeader>
|
|
402
|
+
<TableBody>
|
|
403
|
+
{rows.map((row) => (
|
|
404
|
+
<TableRow key={`${row.warehouseId}|${row.cargoItemId}`}>
|
|
405
|
+
<TableCell className="max-w-56">
|
|
406
|
+
<p className="truncate font-medium" title={row.name}>
|
|
407
|
+
{row.name}
|
|
408
|
+
</p>
|
|
409
|
+
<p className="text-xs text-text-secondary">{row.sku}</p>
|
|
410
|
+
</TableCell>
|
|
411
|
+
<TableCell className="max-w-40 truncate" title={row.warehouseName}>
|
|
412
|
+
{row.warehouseName}
|
|
413
|
+
</TableCell>
|
|
414
|
+
<TableCell className="text-right tabular-nums">
|
|
415
|
+
{row.usableStock.toLocaleString()}
|
|
416
|
+
</TableCell>
|
|
417
|
+
<TableCell
|
|
418
|
+
className="text-right tabular-nums"
|
|
419
|
+
title={
|
|
420
|
+
row.currentWeekUnits > 0
|
|
421
|
+
? `${formatUnits(row.currentWeekUnits)} shipped so far this week`
|
|
422
|
+
: undefined
|
|
423
|
+
}
|
|
424
|
+
>
|
|
425
|
+
{demandCell(row)}
|
|
426
|
+
</TableCell>
|
|
427
|
+
<TableCell className="text-right tabular-nums">
|
|
428
|
+
{formatUnits(row.weeksOfCover)}
|
|
429
|
+
</TableCell>
|
|
430
|
+
<TableCell>
|
|
431
|
+
{row.projectedStockOutWeek
|
|
432
|
+
? `Week of ${formatDate(row.projectedStockOutWeek)}`
|
|
433
|
+
: '—'}
|
|
434
|
+
</TableCell>
|
|
435
|
+
<TableCell className="text-right tabular-nums">
|
|
436
|
+
{row.suggestedReorderQuantity === null
|
|
437
|
+
? '—'
|
|
438
|
+
: row.suggestedReorderQuantity.toLocaleString()}
|
|
439
|
+
</TableCell>
|
|
440
|
+
<TableCell>
|
|
441
|
+
<StatusPill status={row.status} />
|
|
442
|
+
</TableCell>
|
|
443
|
+
</TableRow>
|
|
444
|
+
))}
|
|
445
|
+
</TableBody>
|
|
446
|
+
</Table>
|
|
447
|
+
</div>
|
|
448
|
+
);
|
|
449
|
+
}
|