@burdenoff/microfe-movethewheels 2026.1102.1 → 2026.1107.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.
Files changed (42) hide show
  1. package/dist/MoveTheWheelsRoot.js +148 -140
  2. package/dist/MoveTheWheelsRoutes.js +29 -25
  3. package/dist/components/freight-cost/FreightCommercialFactEditor.js +46 -46
  4. package/dist/components/freight-cost/FreightCommercialHistory.js +7 -7
  5. package/dist/components/freight-cost/FreightDraftForm.js +20 -20
  6. package/dist/components/freight-invoice/InvoiceReviewPanel.js +255 -0
  7. package/dist/components/freight-invoice/InvoiceReviewQueue.js +93 -0
  8. package/dist/generated/freight-invoice-operations.d.ts +461 -0
  9. package/dist/generated/tracking-quality-operations.d.ts +467 -1
  10. package/dist/generated/wspace-types.d.ts +9779 -330
  11. package/dist/hooks/useInvoiceComparisonRecovery.js +26 -26
  12. package/dist/hooks/useInvoiceReviewPermissions.js +14 -0
  13. package/dist/movethewheels/components/freight-invoice/InvoiceReviewPanel.d.ts +11 -0
  14. package/dist/movethewheels/components/freight-invoice/InvoiceReviewQueue.d.ts +22 -0
  15. package/dist/movethewheels/hooks/useInvoiceReviewPermissions.d.ts +5 -0
  16. package/dist/movethewheels/pages/FinancePage.d.ts +3 -1
  17. package/dist/movethewheels/pages/ReportsPage.d.ts +1 -0
  18. package/dist/movethewheels/utils/invoiceReview.d.ts +26 -0
  19. package/dist/movethewheels/utils/reports.d.ts +132 -0
  20. package/dist/node_modules/lucide-react/dist/esm/icons/file-chart-column-increasing.js +26 -0
  21. package/dist/pages/FinancePage.js +109 -67
  22. package/dist/pages/FreightEstimatePage.js +89 -89
  23. package/dist/pages/FreightInvoicePage.js +138 -120
  24. package/dist/pages/ReportsPage.js +718 -0
  25. package/dist/src/generated/freight-invoice-operations.js +2100 -1
  26. package/dist/utils/invoiceReview.js +84 -0
  27. package/dist/utils/reports.js +202 -0
  28. package/package.json +4 -3
  29. package/src/generated/freight-invoice-operations.ts +245 -1
  30. package/src/generated/tracking-quality-operations.ts +569 -1
  31. package/src/generated/wspace-types.ts +11263 -380
  32. package/src/movethewheels/MoveTheWheelsRoot.tsx +8 -0
  33. package/src/movethewheels/MoveTheWheelsRoutes.tsx +4 -0
  34. package/src/movethewheels/components/freight-invoice/InvoiceReviewPanel.tsx +319 -0
  35. package/src/movethewheels/components/freight-invoice/InvoiceReviewQueue.tsx +96 -0
  36. package/src/movethewheels/hooks/useInvoiceReviewPermissions.ts +25 -0
  37. package/src/movethewheels/pages/FinancePage.tsx +34 -2
  38. package/src/movethewheels/pages/FreightInvoicePage.tsx +44 -3
  39. package/src/movethewheels/pages/ReportsPage.tsx +989 -0
  40. package/src/movethewheels/utils/invoiceReview.ts +146 -0
  41. package/src/movethewheels/utils/reports.ts +419 -0
  42. package/src/operations/freight-invoice/review.graphql +26 -0
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Freight invoice review helpers (BOFF-10588): labels, the steps a viewer can
3
+ * take, and the exact mutation inputs. The server enforces every rule again;
4
+ * these only keep the page from offering a step that would be refused.
5
+ */
6
+ import type {
7
+ DecideMtwFreightInvoiceInput,
8
+ HandOffMtwFreightInvoiceSettlementInput,
9
+ InvoiceReviewFragment,
10
+ MtwFreightInvoiceDecision,
11
+ MtwFreightInvoiceResolution,
12
+ MtwFreightInvoiceReviewAction,
13
+ MtwFreightInvoiceReviewStatus,
14
+ RecordMtwFreightInvoiceSupplierResponseInput,
15
+ ResolveMtwFreightInvoiceDisputeInput,
16
+ } from '../../generated/freight-invoice-operations';
17
+
18
+ export const REVIEW_STATUS_LABELS: Record<MtwFreightInvoiceReviewStatus, string> = {
19
+ AWAITING_REVIEW: 'Awaiting review',
20
+ ACCEPTED: 'Accepted',
21
+ ACCEPTED_WITH_VARIANCE: 'Accepted with variance',
22
+ DISPUTED: 'Disputed',
23
+ SUPPLIER_RESPONDED: 'Supplier responded',
24
+ SETTLEMENT_HANDED_OFF: 'Handed to Billing',
25
+ SUPERSEDED: 'Superseded by a correction',
26
+ };
27
+
28
+ export const REVIEW_EVENT_LABELS: Record<InvoiceReviewFragment['events'][number]['kind'], string> =
29
+ {
30
+ DECISION: 'Review decision',
31
+ SUPPLIER_RESPONSE: 'Supplier response',
32
+ DISPUTE_RESOLUTION: 'Dispute resolved',
33
+ SETTLEMENT_HANDOFF: 'Handed to Billing for settlement',
34
+ };
35
+
36
+ /** Statuses a reviewer can filter the queue by; SUPERSEDED never appears in the queue. */
37
+ export const REVIEW_QUEUE_STATUSES: MtwFreightInvoiceReviewStatus[] = [
38
+ 'AWAITING_REVIEW',
39
+ 'DISPUTED',
40
+ 'SUPPLIER_RESPONDED',
41
+ 'ACCEPTED',
42
+ 'ACCEPTED_WITH_VARIANCE',
43
+ 'SETTLEMENT_HANDED_OFF',
44
+ ];
45
+
46
+ export interface ReviewPermissions {
47
+ canRead: boolean;
48
+ canUpdate: boolean;
49
+ canApprove: boolean;
50
+ }
51
+
52
+ const PERMISSION_FOR_ACTION: Record<MtwFreightInvoiceReviewAction, keyof ReviewPermissions> = {
53
+ DECIDE: 'canApprove',
54
+ RECORD_SUPPLIER_RESPONSE: 'canUpdate',
55
+ RESOLVE_DISPUTE: 'canApprove',
56
+ HAND_OFF_SETTLEMENT: 'canApprove',
57
+ };
58
+
59
+ /** Steps the server says are open (author separation included) that this viewer is also permitted to take. */
60
+ export function availableReviewActions(
61
+ review: Pick<InvoiceReviewFragment, 'allowedActions'>,
62
+ permissions: ReviewPermissions
63
+ ): MtwFreightInvoiceReviewAction[] {
64
+ return review.allowedActions.filter((action) => permissions[PERMISSION_FOR_ACTION[action]]);
65
+ }
66
+
67
+ /** Why the author sees no decision: the server withholds it, so say so instead of showing nothing. */
68
+ export function authorNotice(
69
+ review: Pick<InvoiceReviewFragment, 'viewerIsAuthor' | 'status'>
70
+ ): string | null {
71
+ if (!review.viewerIsAuthor) return null;
72
+ if (
73
+ review.status === 'AWAITING_REVIEW' ||
74
+ review.status === 'DISPUTED' ||
75
+ review.status === 'SUPPLIER_RESPONDED'
76
+ )
77
+ return 'You recorded this comparison, so another reviewer must accept, dispute or resolve it.';
78
+ return null;
79
+ }
80
+
81
+ function text(value: string): string | null {
82
+ const trimmed = value.trim();
83
+ return trimmed ? trimmed : null;
84
+ }
85
+
86
+ interface Common {
87
+ review: Pick<InvoiceReviewFragment, 'shipmentId' | 'comparisonId' | 'sequence'>;
88
+ idempotencyKey: string;
89
+ }
90
+ function common({ review, idempotencyKey }: Common) {
91
+ return {
92
+ shipmentId: review.shipmentId,
93
+ comparisonId: review.comparisonId,
94
+ expectedSequence: review.sequence,
95
+ idempotencyKey,
96
+ };
97
+ }
98
+
99
+ export type DraftProblem = 'REASON_REQUIRED' | 'LINES_REQUIRED' | 'RESPONSE_REQUIRED';
100
+ export const DRAFT_PROBLEM_LABELS: Record<DraftProblem, string> = {
101
+ REASON_REQUIRED: 'Give a reason for a dispute, a variance or a resolution.',
102
+ LINES_REQUIRED: 'Choose at least one invoice line you dispute.',
103
+ RESPONSE_REQUIRED: "Record the supplier's response.",
104
+ };
105
+
106
+ export function decisionInput(
107
+ base: Common,
108
+ decision: MtwFreightInvoiceDecision,
109
+ reason: string,
110
+ disputedLineIds: readonly string[]
111
+ ): DecideMtwFreightInvoiceInput | DraftProblem {
112
+ const why = text(reason);
113
+ if (decision !== 'ACCEPTED' && !why) return 'REASON_REQUIRED';
114
+ if (decision === 'DISPUTED' && disputedLineIds.length === 0) return 'LINES_REQUIRED';
115
+ return {
116
+ ...common(base),
117
+ decision,
118
+ reason: why,
119
+ disputedLineIds: decision === 'DISPUTED' ? [...new Set(disputedLineIds)] : [],
120
+ };
121
+ }
122
+
123
+ export function supplierResponseInput(
124
+ base: Common,
125
+ response: string
126
+ ): RecordMtwFreightInvoiceSupplierResponseInput | DraftProblem {
127
+ const said = text(response);
128
+ return said ? { ...common(base), response: said } : 'RESPONSE_REQUIRED';
129
+ }
130
+
131
+ export function resolutionInput(
132
+ base: Common,
133
+ resolution: MtwFreightInvoiceResolution,
134
+ reason: string
135
+ ): ResolveMtwFreightInvoiceDisputeInput | DraftProblem {
136
+ const why = text(reason);
137
+ return why ? { ...common(base), resolution, reason: why } : 'REASON_REQUIRED';
138
+ }
139
+
140
+ export function handOffInput(base: Common, note: string): HandOffMtwFreightInvoiceSettlementInput {
141
+ return { ...common(base), note: text(note) };
142
+ }
143
+
144
+ export function isDraftProblem(value: unknown): value is DraftProblem {
145
+ return typeof value === 'string' && value in DRAFT_PROBLEM_LABELS;
146
+ }
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Reports — client side of wspace-movethewheels-svc's saved reports
3
+ * (BOFF-3989).
4
+ *
5
+ * The service owns validation, scheduling and generation; this module holds
6
+ * the GraphQL documents, the form model and the display helpers for report
7
+ * runs. Kept free of React so the contract can be unit-tested against the
8
+ * subgraph schema.
9
+ */
10
+
11
+ export type MtwReportType = 'OPERATIONS' | 'FINANCE' | 'FLEET' | 'CUSTOMERS' | 'INVENTORY';
12
+ export type MtwReportFrequency = 'NONE' | 'DAILY' | 'WEEKLY' | 'MONTHLY';
13
+ export type MtwReportFormat = 'CSV' | 'JSON';
14
+ export type MtwReportCell = string | number | boolean | null;
15
+
16
+ export interface MtwReportColumn {
17
+ key: string;
18
+ label: string;
19
+ kind: 'TEXT' | 'NUMBER' | 'CURRENCY' | 'DATE' | 'BOOLEAN' | string;
20
+ }
21
+
22
+ export interface MtwReportMetric {
23
+ key: string;
24
+ label: string;
25
+ value: number | null;
26
+ kind: 'NUMBER' | 'CURRENCY' | 'PERCENT' | 'DISTANCE' | 'WEIGHT' | string;
27
+ currency: string | null;
28
+ }
29
+
30
+ export interface MtwReportRunSummary {
31
+ id: string;
32
+ reportId: string;
33
+ reportType: MtwReportType;
34
+ trigger: 'MANUAL' | 'SCHEDULED' | string;
35
+ status: 'RUNNING' | 'COMPLETED' | 'FAILED' | string;
36
+ periodStart: string;
37
+ periodEnd: string;
38
+ rowCount: number;
39
+ truncated: boolean;
40
+ error: string | null;
41
+ durationMs: number | null;
42
+ startedAt: string;
43
+ finishedAt: string | null;
44
+ }
45
+
46
+ export interface MtwReportRunDetail extends MtwReportRunSummary {
47
+ metrics: MtwReportMetric[];
48
+ columns: MtwReportColumn[];
49
+ rows: Record<string, MtwReportCell>[];
50
+ }
51
+
52
+ export interface MtwReport {
53
+ id: string;
54
+ name: string;
55
+ description: string | null;
56
+ type: MtwReportType;
57
+ periodDays: number;
58
+ frequency: MtwReportFrequency;
59
+ runHour: number;
60
+ runWeekday: number;
61
+ runMonthDay: number;
62
+ timezone: string;
63
+ isActive: boolean;
64
+ nextRunAt: string | null;
65
+ lastGeneratedAt: string | null;
66
+ lastRunStatus: string | null;
67
+ lastError: string | null;
68
+ updatedAt: string;
69
+ latestRun: MtwReportRunSummary | null;
70
+ }
71
+
72
+ export interface MtwReportExport {
73
+ filename: string;
74
+ contentType: string;
75
+ content: string;
76
+ rowCount: number;
77
+ truncated: boolean;
78
+ }
79
+
80
+ /** What the create/edit form sends; the service fills in the rest. */
81
+ export interface MtwReportInput {
82
+ name: string;
83
+ type: MtwReportType;
84
+ description: string;
85
+ periodDays: number;
86
+ frequency: MtwReportFrequency;
87
+ runHour: number;
88
+ runWeekday: number;
89
+ runMonthDay: number;
90
+ timezone: string;
91
+ isActive: boolean;
92
+ }
93
+
94
+ /** Mirrors the service limits. */
95
+ export const NAME_MAX = 120;
96
+ export const DESCRIPTION_MAX = 1000;
97
+ export const PERIOD_DAYS_MIN = 1;
98
+ export const PERIOD_DAYS_MAX = 366;
99
+ /** Rows shown in the in-page preview; the download holds every stored row. */
100
+ export const PREVIEW_ROWS = 50;
101
+
102
+ export const REPORT_TYPE_OPTIONS: ReadonlyArray<{
103
+ value: MtwReportType;
104
+ label: string;
105
+ description: string;
106
+ }> = [
107
+ {
108
+ value: 'OPERATIONS',
109
+ label: 'Operations',
110
+ description:
111
+ 'Shipments booked in the period: status, lanes, on-time delivery and freight cost.',
112
+ },
113
+ {
114
+ value: 'FINANCE',
115
+ label: 'Finance',
116
+ description:
117
+ 'Order revenue, delivered and outstanding amounts, and freight cost, per currency.',
118
+ },
119
+ {
120
+ value: 'FLEET',
121
+ label: 'Fleet',
122
+ description: 'Every vehicle with its orders, completed routes, distance, fuel cost and CO2e.',
123
+ },
124
+ {
125
+ value: 'CUSTOMERS',
126
+ label: 'Customers',
127
+ description: 'Every customer with their orders, deliveries and revenue in the period.',
128
+ },
129
+ {
130
+ value: 'INVENTORY',
131
+ label: 'Inventory',
132
+ description: 'Every stock line with its levels, value and movements in the period.',
133
+ },
134
+ ];
135
+
136
+ export const FREQUENCY_OPTIONS: ReadonlyArray<{ value: MtwReportFrequency; label: string }> = [
137
+ { value: 'NONE', label: 'Only when I generate it' },
138
+ { value: 'DAILY', label: 'Every day' },
139
+ { value: 'WEEKLY', label: 'Every week' },
140
+ { value: 'MONTHLY', label: 'Every month' },
141
+ ];
142
+
143
+ export const WEEKDAY_LABELS = [
144
+ 'Monday',
145
+ 'Tuesday',
146
+ 'Wednesday',
147
+ 'Thursday',
148
+ 'Friday',
149
+ 'Saturday',
150
+ 'Sunday',
151
+ ] as const;
152
+
153
+ const RUN_FIELDS = `
154
+ id
155
+ reportId
156
+ reportType
157
+ trigger
158
+ status
159
+ periodStart
160
+ periodEnd
161
+ rowCount
162
+ truncated
163
+ error
164
+ durationMs
165
+ startedAt
166
+ finishedAt
167
+ `;
168
+
169
+ const REPORT_FIELDS = `
170
+ id
171
+ name
172
+ description
173
+ type
174
+ periodDays
175
+ frequency
176
+ runHour
177
+ runWeekday
178
+ runMonthDay
179
+ timezone
180
+ isActive
181
+ nextRunAt
182
+ lastGeneratedAt
183
+ lastRunStatus
184
+ lastError
185
+ updatedAt
186
+ latestRun {
187
+ ${RUN_FIELDS}
188
+ }
189
+ `;
190
+
191
+ export const MTW_REPORTS_QUERY = `
192
+ query MtwReports($pagination: PaginationInput) {
193
+ mtwReports(pagination: $pagination) {
194
+ ${REPORT_FIELDS}
195
+ }
196
+ }
197
+ `;
198
+
199
+ export const MTW_REPORT_RUNS_QUERY = `
200
+ query MtwReportRuns($reportId: ID!, $pagination: PaginationInput) {
201
+ mtwReportRuns(reportId: $reportId, pagination: $pagination) {
202
+ ${RUN_FIELDS}
203
+ }
204
+ }
205
+ `;
206
+
207
+ export const MTW_REPORT_RUN_QUERY = `
208
+ query MtwReportRun($id: ID!, $rows: PaginationInput) {
209
+ mtwReportRun(id: $id) {
210
+ ${RUN_FIELDS}
211
+ metrics {
212
+ key
213
+ label
214
+ value
215
+ kind
216
+ currency
217
+ }
218
+ columns {
219
+ key
220
+ label
221
+ kind
222
+ }
223
+ rows(pagination: $rows)
224
+ }
225
+ }
226
+ `;
227
+
228
+ export const MTW_REPORT_RUN_EXPORT_QUERY = `
229
+ query MtwReportRunExport($runId: ID!, $format: MtwReportFormat!) {
230
+ mtwReportRunExport(runId: $runId, format: $format) {
231
+ filename
232
+ contentType
233
+ content
234
+ rowCount
235
+ truncated
236
+ }
237
+ }
238
+ `;
239
+
240
+ export const CREATE_MTW_REPORT_MUTATION = `
241
+ mutation CreateMtwReport($input: MtwCreateReportInput!) {
242
+ createMtwReport(input: $input) {
243
+ ${REPORT_FIELDS}
244
+ }
245
+ }
246
+ `;
247
+
248
+ export const UPDATE_MTW_REPORT_MUTATION = `
249
+ mutation UpdateMtwReport($id: ID!, $input: MtwUpdateReportInput!) {
250
+ updateMtwReport(id: $id, input: $input) {
251
+ ${REPORT_FIELDS}
252
+ }
253
+ }
254
+ `;
255
+
256
+ export const DELETE_MTW_REPORT_MUTATION = `
257
+ mutation DeleteMtwReport($id: ID!) {
258
+ deleteMtwReport(id: $id)
259
+ }
260
+ `;
261
+
262
+ export const GENERATE_MTW_REPORT_MUTATION = `
263
+ mutation GenerateMtwReport($id: ID!) {
264
+ generateMtwReport(id: $id) {
265
+ ${RUN_FIELDS}
266
+ }
267
+ }
268
+ `;
269
+
270
+ /** The form's starting point for a new report. */
271
+ export function newReportInput(timezone: string): MtwReportInput {
272
+ return {
273
+ name: '',
274
+ type: 'OPERATIONS',
275
+ description: '',
276
+ periodDays: 30,
277
+ frequency: 'NONE',
278
+ runHour: 6,
279
+ runWeekday: 1,
280
+ runMonthDay: 1,
281
+ timezone,
282
+ isActive: true,
283
+ };
284
+ }
285
+
286
+ export function reportToInput(report: MtwReport): MtwReportInput {
287
+ return {
288
+ name: report.name,
289
+ type: report.type,
290
+ description: report.description ?? '',
291
+ periodDays: report.periodDays,
292
+ frequency: report.frequency,
293
+ runHour: report.runHour,
294
+ runWeekday: report.runWeekday,
295
+ runMonthDay: report.runMonthDay,
296
+ timezone: report.timezone,
297
+ isActive: report.isActive,
298
+ };
299
+ }
300
+
301
+ /** The look-back window that matches a frequency: the gap between two runs. */
302
+ export function suggestedPeriodDays(frequency: MtwReportFrequency): number {
303
+ if (frequency === 'DAILY') return 1;
304
+ if (frequency === 'WEEKLY') return 7;
305
+ return 30;
306
+ }
307
+
308
+ /** The first problem with the form, or null when the service would accept it. */
309
+ export function reportInputError(input: MtwReportInput): string | null {
310
+ const name = input.name.trim();
311
+ if (!name) return 'Give the report a name.';
312
+ if (name.length > NAME_MAX) return `The name can be at most ${NAME_MAX} characters.`;
313
+ if (input.description.trim().length > DESCRIPTION_MAX)
314
+ return `The description can be at most ${DESCRIPTION_MAX} characters.`;
315
+ if (
316
+ !Number.isInteger(input.periodDays) ||
317
+ input.periodDays < PERIOD_DAYS_MIN ||
318
+ input.periodDays > PERIOD_DAYS_MAX
319
+ )
320
+ return `The period must be a whole number of days from ${PERIOD_DAYS_MIN} to ${PERIOD_DAYS_MAX}.`;
321
+ return null;
322
+ }
323
+
324
+ /** The input sent to createMtwReport / updateMtwReport. */
325
+ export function toServiceInput(input: MtwReportInput): Record<string, unknown> {
326
+ return {
327
+ name: input.name.trim(),
328
+ type: input.type,
329
+ description: input.description.trim(),
330
+ periodDays: input.periodDays,
331
+ frequency: input.frequency,
332
+ runHour: input.runHour,
333
+ runWeekday: input.runWeekday,
334
+ runMonthDay: input.runMonthDay,
335
+ timezone: input.timezone,
336
+ isActive: input.isActive,
337
+ };
338
+ }
339
+
340
+ export function reportTypeLabel(type: string): string {
341
+ return REPORT_TYPE_OPTIONS.find((option) => option.value === type)?.label ?? type;
342
+ }
343
+
344
+ function hourLabel(hour: number): string {
345
+ return `${String(hour).padStart(2, '0')}:00`;
346
+ }
347
+
348
+ function ordinal(day: number): string {
349
+ const suffix =
350
+ day % 10 === 1 && day !== 11
351
+ ? 'st'
352
+ : day % 10 === 2 && day !== 12
353
+ ? 'nd'
354
+ : day % 10 === 3 && day !== 13
355
+ ? 'rd'
356
+ : 'th';
357
+ return `${day}${suffix}`;
358
+ }
359
+
360
+ /** "Every Monday at 06:00 (Asia/Kolkata)", "Paused", or "On demand". */
361
+ export function scheduleSummary(
362
+ report: Pick<
363
+ MtwReport,
364
+ 'frequency' | 'runHour' | 'runWeekday' | 'runMonthDay' | 'timezone' | 'isActive'
365
+ >
366
+ ): string {
367
+ if (report.frequency === 'NONE') return 'On demand';
368
+ const zone = report.timezone.replace(/_/g, ' ');
369
+ const at = `at ${hourLabel(report.runHour)} (${zone})`;
370
+ let when: string;
371
+ if (report.frequency === 'DAILY') when = `Every day ${at}`;
372
+ else if (report.frequency === 'WEEKLY')
373
+ when = `Every ${WEEKDAY_LABELS[report.runWeekday - 1] ?? 'week'} ${at}`;
374
+ else when = `On the ${ordinal(report.runMonthDay)} of every month ${at}`;
375
+ return report.isActive ? when : `Paused · ${when}`;
376
+ }
377
+
378
+ export interface MetricFormatters {
379
+ currency: (amount: number, currency?: string) => string;
380
+ distance: (km: number) => string;
381
+ weight: (kg: number) => string;
382
+ }
383
+
384
+ /** Display value for one headline metric, in the workspace's units. */
385
+ export function formatMetric(metric: MtwReportMetric, format: MetricFormatters): string {
386
+ if (metric.value === null || metric.value === undefined) return '—';
387
+ switch (metric.kind) {
388
+ case 'PERCENT':
389
+ return `${(metric.value * 100).toFixed(1)}%`;
390
+ case 'CURRENCY':
391
+ return format.currency(metric.value, metric.currency ?? undefined);
392
+ case 'DISTANCE':
393
+ return format.distance(metric.value);
394
+ case 'WEIGHT':
395
+ return format.weight(metric.value);
396
+ default:
397
+ return metric.value.toLocaleString();
398
+ }
399
+ }
400
+
401
+ /** A metric's label with its currency, so per-currency figures stay apart. */
402
+ export function metricLabel(metric: MtwReportMetric): string {
403
+ return metric.kind === 'CURRENCY' && metric.currency
404
+ ? `${metric.label} (${metric.currency})`
405
+ : metric.label;
406
+ }
407
+
408
+ /** Display value for one detail cell. */
409
+ export function formatCell(
410
+ value: MtwReportCell | undefined,
411
+ column: MtwReportColumn,
412
+ formatDate: (value: string) => string
413
+ ): string {
414
+ if (value === null || value === undefined || value === '') return '—';
415
+ if (column.kind === 'BOOLEAN' || typeof value === 'boolean') return value ? 'Yes' : 'No';
416
+ if (column.kind === 'DATE' && typeof value === 'string') return formatDate(value);
417
+ if (typeof value === 'number') return value.toLocaleString();
418
+ return String(value);
419
+ }
@@ -0,0 +1,26 @@
1
+ fragment InvoiceReview on MtwFreightInvoiceReview {
2
+ comparisonId shipmentId invoiceIdentityId revision latestRevision supersededByComparisonId
3
+ supplierReference supplierLabel invoiceReference currency { code minorUnitDigits }
4
+ knownInvoiceAmountMinor invoiceAmountComplete comparisonRecordedAt comparisonCreatedBy
5
+ status resolvedByCorrection sequence allowedActions viewerIsAuthor settlementReference
6
+ events { id sequence kind decision statusAfter reason disputedLineIds settlementReference recordedAt createdBy }
7
+ }
8
+ query InvoiceReviewExact($shipmentId: ID!, $comparisonId: ID!) {
9
+ mtwFreightInvoiceReview(shipmentId: $shipmentId, comparisonId: $comparisonId) { ...InvoiceReview }
10
+ }
11
+ query InvoiceReviewQueue($status: MtwFreightInvoiceReviewStatus, $pagination: MtwContainerPagination) {
12
+ mtwFreightInvoiceReviewPage(status: $status, pagination: $pagination) {
13
+ items { ...InvoiceReview } total limit offset hasMore nextOffset
14
+ }
15
+ }
16
+ query InvoiceReviewSummary {
17
+ mtwFreightInvoiceReviewSummary { total awaitingReview accepted acceptedWithVariance disputed supplierResponded settlementHandedOff }
18
+ }
19
+ mutation DecideInvoiceReview($input: DecideMtwFreightInvoiceInput!) { decideMtwFreightInvoice(input: $input) { ...InvoiceReview } }
20
+ mutation RecordInvoiceSupplierResponse($input: RecordMtwFreightInvoiceSupplierResponseInput!) {
21
+ recordMtwFreightInvoiceSupplierResponse(input: $input) { ...InvoiceReview }
22
+ }
23
+ mutation ResolveInvoiceDispute($input: ResolveMtwFreightInvoiceDisputeInput!) { resolveMtwFreightInvoiceDispute(input: $input) { ...InvoiceReview } }
24
+ mutation HandOffInvoiceSettlement($input: HandOffMtwFreightInvoiceSettlementInput!) {
25
+ handOffMtwFreightInvoiceSettlement(input: $input) { ...InvoiceReview }
26
+ }