@burdenoff/microfe-movethewheels 2026.1107.7 → 2026.1108.2

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.
Files changed (28) hide show
  1. package/dist/components/ForecastModelsPanel.js +132 -0
  2. package/dist/components/InventoryCoverPanel.js +401 -0
  3. package/dist/components/UpcomingDemandPanel.js +70 -65
  4. package/dist/generated/wspace-operations.d.ts +25 -0
  5. package/dist/generated/wspace-types.d.ts +3467 -134
  6. package/dist/hooks/useDemandForecast.js +1 -1
  7. package/dist/hooks/useForecastModelChoices.js +57 -0
  8. package/dist/hooks/useInventoryCoverPlan.js +70 -0
  9. package/dist/movethewheels/components/ForecastModelsPanel.d.ts +4 -0
  10. package/dist/movethewheels/components/InventoryCoverPanel.d.ts +24 -0
  11. package/dist/movethewheels/hooks/useDemandForecast.d.ts +9 -0
  12. package/dist/movethewheels/hooks/useForecastModelChoices.d.ts +34 -0
  13. package/dist/movethewheels/hooks/useInventoryCoverPlan.d.ts +80 -0
  14. package/dist/node_modules/lucide-react/dist/esm/icons/sigma.js +8 -0
  15. package/dist/pages/AnalyticsPage.js +83 -81
  16. package/dist/pages/InventoryPage.js +219 -214
  17. package/package.json +1 -1
  18. package/src/generated/wspace-operations.ts +13 -4
  19. package/src/generated/wspace-types.ts +3812 -134
  20. package/src/movethewheels/components/ForecastModelsPanel.tsx +188 -0
  21. package/src/movethewheels/components/InventoryCoverPanel.tsx +449 -0
  22. package/src/movethewheels/components/UpcomingDemandPanel.tsx +9 -2
  23. package/src/movethewheels/hooks/useDemandForecast.ts +13 -0
  24. package/src/movethewheels/hooks/useForecastModelChoices.ts +138 -0
  25. package/src/movethewheels/hooks/useInventoryCoverPlan.ts +250 -0
  26. package/src/movethewheels/pages/AnalyticsPage.tsx +7 -2
  27. package/src/movethewheels/pages/InventoryPage.tsx +8 -0
  28. package/src/operations/wspace/movethewheels/queries/forecast.graphql +22 -1
@@ -0,0 +1,188 @@
1
+ /**
2
+ * ForecastModelsPanel
3
+ *
4
+ * Supply-chain planning v3 (BOFF-10925): which model forecasts each lane and
5
+ * customer, and why. A lane or customer with 26 closed weeks of history is
6
+ * back-tested with the moving-average heuristic, Holt linear and Holt-Winters
7
+ * exponential smoothing; the one with the lowest error (MAPE) on the last
8
+ * closed weeks produces its forecast. Shorter histories keep the heuristic.
9
+ *
10
+ * Read-only: the choices are recorded by each forecast recalculation.
11
+ */
12
+
13
+ import { useState } from 'react';
14
+ import { Sigma } from 'lucide-react';
15
+
16
+ import {
17
+ Badge,
18
+ Card,
19
+ CardContent,
20
+ CardDescription,
21
+ CardHeader,
22
+ CardTitle,
23
+ Skeleton,
24
+ Table,
25
+ TableBody,
26
+ TableCell,
27
+ TableHead,
28
+ TableHeader,
29
+ TableRow,
30
+ Tabs,
31
+ TabsContent,
32
+ TabsList,
33
+ TabsTrigger,
34
+ } from './ui';
35
+ import type { DemandForecastModel } from '../hooks/useDemandForecast';
36
+ import {
37
+ useForecastModelChoices,
38
+ type ForecastModelChoice,
39
+ type ForecastModelScore,
40
+ } from '../hooks/useForecastModelChoices';
41
+
42
+ /** Short display name of a forecast model. */
43
+ export const forecastModelLabel = (
44
+ model: DemandForecastModel,
45
+ seasonLengthWeeks?: number | null
46
+ ): string => {
47
+ switch (model) {
48
+ case 'HOLT_LINEAR':
49
+ return 'Holt (trend)';
50
+ case 'HOLT_WINTERS':
51
+ return seasonLengthWeeks
52
+ ? `Holt-Winters (${seasonLengthWeeks}-week cycle)`
53
+ : 'Holt-Winters (seasonal)';
54
+ // HEURISTIC_GROWTH_RATE is reserved and never produced; the API documents
55
+ // it as the moving-average heuristic, so it is labelled the same way.
56
+ case 'HEURISTIC_MOVING_AVG':
57
+ case 'HEURISTIC_GROWTH_RATE':
58
+ return 'Moving average';
59
+ default: {
60
+ // Exhaustive over the schema enum: a new model fails the type check here.
61
+ const unknownModel: never = model;
62
+ return String(unknownModel);
63
+ }
64
+ }
65
+ };
66
+
67
+ const formatMape = (mape: number | null): string =>
68
+ mape === null ? '—' : `${Math.round(mape * 1000) / 10}%`;
69
+
70
+ const scoreFor = (
71
+ choice: ForecastModelChoice,
72
+ model: DemandForecastModel
73
+ ): ForecastModelScore | undefined => choice.candidates.find((c) => c.model === model);
74
+
75
+ export function ForecastModelsPanel() {
76
+ const { laneChoices, customerChoices, isLoading, error, refetch } = useForecastModelChoices(5);
77
+ const [tab, setTab] = useState<'LANE' | 'CUSTOMER'>('LANE');
78
+
79
+ return (
80
+ <Card data-testid="forecast-models-panel">
81
+ <CardHeader>
82
+ <CardTitle className="flex items-center gap-2">
83
+ <Sigma size={18} aria-hidden="true" />
84
+ Forecast models
85
+ </CardTitle>
86
+ <CardDescription>
87
+ Lanes and customers with 26 closed weeks of history are back-tested on their last 8 closed
88
+ weeks. The model with the lowest error (MAPE) produces the forecast: the moving-average
89
+ heuristic, Holt (trend) or Holt-Winters (seasonal). Shorter histories use the moving
90
+ average.
91
+ </CardDescription>
92
+ </CardHeader>
93
+ <CardContent>
94
+ {error && !isLoading ? (
95
+ <div className="space-y-2 text-sm">
96
+ <p className="text-status-error-text font-medium">Couldn&apos;t load forecast models</p>
97
+ <p className="text-text-secondary">{error.message}</p>
98
+ <button
99
+ type="button"
100
+ onClick={refetch}
101
+ className="font-medium text-primary hover:underline"
102
+ >
103
+ Retry
104
+ </button>
105
+ </div>
106
+ ) : isLoading ? (
107
+ <div className="space-y-3">
108
+ <Skeleton className="h-10 w-full" />
109
+ <Skeleton className="h-10 w-full" />
110
+ </div>
111
+ ) : (
112
+ <Tabs value={tab} onValueChange={(value) => setTab(value as 'LANE' | 'CUSTOMER')}>
113
+ <TabsList>
114
+ <TabsTrigger value="LANE">Lanes</TabsTrigger>
115
+ <TabsTrigger value="CUSTOMER">Customers</TabsTrigger>
116
+ </TabsList>
117
+ <TabsContent value="LANE">
118
+ <ChoiceTable choices={laneChoices} nameHeader="Lane" />
119
+ </TabsContent>
120
+ <TabsContent value="CUSTOMER">
121
+ <ChoiceTable choices={customerChoices} nameHeader="Customer" />
122
+ </TabsContent>
123
+ </Tabs>
124
+ )}
125
+ </CardContent>
126
+ </Card>
127
+ );
128
+ }
129
+
130
+ interface ChoiceTableProps {
131
+ choices: ForecastModelChoice[];
132
+ nameHeader: string;
133
+ }
134
+
135
+ function ChoiceTable({ choices, nameHeader }: ChoiceTableProps) {
136
+ if (choices.length === 0) {
137
+ return (
138
+ <p className="py-4 text-sm text-text-secondary">
139
+ No forecasts yet. Model choices appear after the first forecast recalculation.
140
+ </p>
141
+ );
142
+ }
143
+ return (
144
+ <div className="overflow-x-auto">
145
+ <Table>
146
+ <TableHeader>
147
+ <TableRow>
148
+ <TableHead>{nameHeader}</TableHead>
149
+ <TableHead className="text-right">History</TableHead>
150
+ <TableHead>Model</TableHead>
151
+ <TableHead className="text-right">Model error</TableHead>
152
+ <TableHead className="text-right">Moving-average error</TableHead>
153
+ </TableRow>
154
+ </TableHeader>
155
+ <TableBody>
156
+ {choices.map((choice) => {
157
+ const selected = choice.candidates.find((c) => c.selected);
158
+ const heuristic = scoreFor(choice, 'HEURISTIC_MOVING_AVG');
159
+ return (
160
+ <TableRow key={`${choice.scopeType}-${choice.scopeKey}`}>
161
+ <TableCell className="max-w-[16rem]">
162
+ <p className="truncate font-medium" title={choice.scopeLabel}>
163
+ {choice.scopeLabel}
164
+ </p>
165
+ <p className="text-xs text-text-secondary whitespace-normal">{choice.reason}</p>
166
+ </TableCell>
167
+ <TableCell className="text-right whitespace-nowrap">
168
+ {choice.historyWeeks} wk
169
+ </TableCell>
170
+ <TableCell>
171
+ <Badge
172
+ variant={
173
+ choice.selectedModel === 'HEURISTIC_MOVING_AVG' ? 'outline' : 'default'
174
+ }
175
+ >
176
+ {forecastModelLabel(choice.selectedModel, selected?.seasonLengthWeeks)}
177
+ </Badge>
178
+ </TableCell>
179
+ <TableCell className="text-right">{formatMape(selected?.mape ?? null)}</TableCell>
180
+ <TableCell className="text-right">{formatMape(heuristic?.mape ?? null)}</TableCell>
181
+ </TableRow>
182
+ );
183
+ })}
184
+ </TableBody>
185
+ </Table>
186
+ </div>
187
+ );
188
+ }
@@ -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&apos;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
+ }
@@ -2,7 +2,8 @@
2
2
  * UpcomingDemandPanel
3
3
  *
4
4
  * Surfaces next-week demand forecasts by lane / customer alongside the
5
- * most recent closed-period variance (BOFF-4393). Pure read-side view
5
+ * most recent closed-period variance (BOFF-4393), naming the model behind
6
+ * the headline row (BOFF-10925). Pure read-side view
6
7
  * over `wspace-movethewheels-svc`'s DemandForecast surface.
7
8
  *
8
9
  * "Next week" is the first forecast week that has not begun yet: the current
@@ -16,6 +17,7 @@ import { Calendar, TrendingUp, TrendingDown, AlertCircle } from 'lucide-react';
16
17
  import { Card, CardContent, CardHeader, CardTitle, Skeleton } from './ui';
17
18
  import { formatCurrency } from '../utils/formatters';
18
19
 
20
+ import { forecastModelLabel } from './ForecastModelsPanel';
19
21
  import type { ForecastPoint, ForecastVariance } from '../hooks/useDemandForecast';
20
22
 
21
23
  interface UpcomingDemandPanelProps {
@@ -181,8 +183,13 @@ export function UpcomingDemandPanel({
181
183
  <p className="text-xs uppercase tracking-wide text-text-secondary">{totalLabel}</p>
182
184
  <p className="text-2xl font-bold">{total}</p>
183
185
  </div>
184
- <p className="text-xs text-text-secondary">
186
+ <p className="text-xs text-text-secondary text-right">
185
187
  {headlineRow ? formatConfidence(headlineRow.confidence) : ''}
188
+ {headlineRow ? (
189
+ <span className="block" data-testid="upcoming-demand-model">
190
+ {forecastModelLabel(headlineRow.model)}
191
+ </span>
192
+ ) : null}
186
193
  </p>
187
194
  </div>
188
195