Commodity code summary
BodyPrints each goods line's tariff code, origin, preference claim, quantity, supplementary unit, net mass and value, then one summary row per tariff code, origin and preference, which is how customs splits a declaration. Codes are text, so 0901 stays 0901, and each is checked against the destination's length: 6 for HS, 8 for EU CN, 10 for UK and US. A short or missing code warns on its line. Masses in lb are converted, summed exactly and rounded once per group, and the total is the sum of the groups, so the summary always adds up. Net mass above the declared gross mass prints a warning. All of it is one deriver.
npx dxcl add commodity-code-summary Данные предпросмотра
JSON, на котором построен этот предпросмотр{
"customs": {
"currency": "GBP",
"destinationCodeLength": 10,
"grossMassKg": 27850.5,
"lines": [
{
"ref": "INV-2026-004817/0001",
"description": "Roasted arabica coffee beans, not decaffeinated, in 1 kg one-way valve bags",
"tariffCode": "0901210000",
"origin": "CO",
"preference": true,
"quantity": 12000,
"netMass": {
"value": 12000,
"unit": "kg"
},
"valueMinor": 15600000
},
{
"ref": "INV-2026-004817/0002",
"description": "Roasted arabica coffee beans, not decaffeinated, in 1 kg one-way valve bags",
"tariffCode": "0901210000",
"origin": "BR",
"quantity": 6000,
"netMass": {
"value": 6000,
"unit": "kg"
},
"valueMinor": 7245000
},
{
"ref": "INV-2026-004817/0003",
"description": "Men's leather lace-up boots with vulcanised rubber soles, assorted sizes UK 6 to 13",
"tariffCode": "6403919800",
"origin": "PT",
"preference": true,
"quantity": 2400,
"supplementaryUnit": {
"code": "pa",
"quantity": 2400
},
"netMass": {
"value": 1420.5,
"unit": "kg"
},
"valueMinor": 10080000
},
{
"ref": "INV-2026-004817/0004",
"description": "Men's leather lace-up boots with vulcanised rubber soles, assorted sizes UK 6 to 13",
"tariffCode": "6403919800",
"origin": "PT",
"preference": true,
"quantity": 1500,
"supplementaryUnit": {
"code": "pa",
"quantity": 1500
},
"netMass": {
"value": 1850.75,
"unit": "lb"
},
"valueMinor": 6300000
},
{
"ref": "INV-2026-004817/0005",
"description": "Red wine of fresh grapes with a protected designation of origin, in 75 cl glass bottles",
"tariffCode": "2204214200",
"origin": "FR",
"preference": true,
"quantity": 4800,
"supplementaryUnit": {
"code": "l",
"quantity": 3600
},
"netMass": {
"value": 5280,
"unit": "kg"
},
"valueMinor": 2052500
}
]
}
} Отрисованный предпросмотр
каждая компоновка, отрисованная сама по себеarrangement="lines-then-summary" по умолчанию arrangement="summary-first" Разрешённые узлы
что получает рендерер — узлов: 1commodity-code-summary section Файлы
что записывает установка; выбранный файл и есть компонентnodes/commodity-code-summary.node.tsx import { arrange, Paragraph, Section, type Section as SectionComponent, useDeriver, useState } from "docxcelerate/template";
import type { CommodityCodeSummaryLines } from "../arrangements/commodity-code-summary/lines.ts";
import { linesThenSummary } from "../arrangements/commodity-code-summary/lines-then-summary.arrangement.tsx";
import { summaryFirst } from "../arrangements/commodity-code-summary/summary-first.arrangement.tsx";
import commodityCodeSummary from "../derivers/commodity-code-summary.deriver.ts";
/**
* The customs block of a commercial invoice: each goods line's tariff code,
* origin, preference claim, quantity, supplementary unit, net mass and value,
* then the summary a customs declaration is keyed from.
*
* Decisions already made for the reader:
*
* - Tariff codes are text. A code supplied as a number warns, because its
* leading zero is already gone (0901 coffee becomes 901).
* - The digit count is checked against the destination: 6 is HS, 8 is EU CN,
* 10 is the UK and US tariffs. A short or missing code warns on its own line,
* since a 6-digit code passes a generic template but cannot be declared there.
* - Lines group on code, origin and preference together, never on code alone.
* Customs declares those combinations separately.
* - Mass is rounded once: lines are converted to exact grams, summed per group
* and rounded to whole grams there. The total is the sum of the rounded
* groups, so the summary always adds up.
* - Net mass above the declared gross mass warns, before a broker rejects it.
*
* All of it is one deriver, because every step does string checks, sorting,
* grouping or arithmetic on request data, and publishing refuses all of those.
* The tables loop over the deriver's rows with `.map()`, which the resolver
* reads by scope. The node computes nothing: it builds the lines the
* arrangements place and decides only whether there is anything to place.
*
* Arrangement: where the lines and the summary sit is a separate choice from
* what they say, made with the `arrangement` prop. An arrangement only places,
* so there is no summary-only one: it would drop the lines and their warnings.
*
* Installed by `dxcl add commodity-code-summary`, which also installs its deriver.
*/
/** What this component reads. Add these fields to your document data type. */
export interface CommodityCodeSummaryData {
customs: {
/**
* ISO 4217 code every `valueMinor` is in: "GBP", "EUR", "JPY". It also sets
* how many minor units make a major one. Required: the deriver throws when
* it is missing or not a code `Intl` knows.
*/
currency: string;
/**
* How many digits the destination's tariff needs: 6 (HS), 8 (EU Combined
* Nomenclature) or 10 (UK Global Tariff, US HTS). Every line's code is
* checked against it. Required: anything else throws, because a check
* against the wrong length passes codes that cannot be declared.
*/
destinationCodeLength: 6 | 8 | 10;
/**
* The declared gross mass of the whole shipment, in kilograms, packaging
* included. Printed under the summary and compared with the summed net
* mass. Missing means no gross line and no check. Throws when present but
* not a finite number of 0 or more.
*/
grossMassKg?: number;
/**
* The goods lines, in invoice order. They are printed in this order and
* grouped for the summary. Missing or empty prints one sentence saying
* there are no goods lines, and no tables.
*/
lines: Array<{
/**
* The invoice's own line reference, printed so a broker can quote it.
* Missing or empty prints the line's 1-based position ("Line 3").
*/
ref?: string;
/** The goods description as printed on the invoice. Missing prints nothing in its place. */
description?: string;
/**
* The tariff (commodity) code, as text: "0901210000". Spaces and dots
* are removed before checking ("0901 21 00 00" is fine). Missing or
* empty warns on the line and the line groups under "None". A number
* warns that leading zeros may have been lost, and is then checked as
* its digits. Anything left that is not digits warns. Fewer digits
* than `destinationCodeLength` warns. More digits is accepted and
* printed as given.
*/
tariffCode: string;
/**
* Country of origin, ISO 3166-1 alpha-2, trimmed and upper-cased: "CO".
* Missing or empty warns on the line and groups under "None". Anything
* that is not two letters after that warns, and groups as given.
*/
origin: string;
/**
* Whether preferential origin is claimed for this line. Missing means
* false. Claiming a preference without the proof behind it is the error
* that costs money, so the default is to claim nothing.
*/
preference?: boolean;
/**
* The invoice quantity, in the invoice's own units. Printed per line,
* never summed: it is not a declaration figure. Throws when it is not a
* finite number of 0 or more.
*/
quantity: number;
/**
* The supplementary unit the tariff asks for on this code, and the
* quantity in it: { code: "pa", quantity: 2400 } for pairs,
* { code: "l", quantity: 3600 } for litres. Missing means the code has
* none. Throws when present with an empty code, or a quantity that is
* not a finite number of 0 or more.
*/
supplementaryUnit?: { code: string; quantity: number };
/**
* Net mass of the line, without packaging. Required: throws when value
* is not a finite number of 0 or more, or unit is not "kg", "g" or "lb".
*/
netMass: { value: number; unit: "kg" | "g" | "lb" };
/**
* The line's value in integer minor units of `currency` (15600000 is
* £156,000.00). Required: throws when it is not a non-negative integer.
* A credit belongs in the invoice totals, not on a customs line.
*/
valueMinor: number;
}>;
};
}
/**
* Where the lines and the summary sit.
*
* - `lines-then-summary`: every line, then the summary under it. The default.
* - `summary-first`: the summary and its warnings first, the lines after, so
* the figures a declaration needs sit on the first page of a long invoice.
*/
export type CommodityCodeSummaryArrangement = "lines-then-summary" | "summary-first";
/** Props for {@linkcode CommodityCodeSummary}. */
export interface CommodityCodeSummaryProps {
/** Where the lines and the summary sit. Defaults to `"lines-then-summary"`. */
arrangement?: CommodityCodeSummaryArrangement;
}
export const CommodityCodeSummary: SectionComponent<CommodityCodeSummaryProps> = async ({ arrangement }) => {
const [customs] = useState((data: CommodityCodeSummaryData) => data.customs);
const result = await useDeriver(commodityCodeSummary, [customs]);
const lines: CommodityCodeSummaryLines = {
basis: result.basis,
attention: result.attention,
lines: result.lines,
groups: result.groups,
totalNetMass: result.totalNetMass,
totalValue: result.totalValue,
grossMass: result.grossMass,
grossWarning: result.grossWarning,
};
return (
<Section id="commodity-code-summary" title="Commodity codes">
{result.empty
? <Paragraph id="commodity-code-summary-none">There are no goods lines on this invoice.</Paragraph>
: arrange(arrangement, {
"lines-then-summary": () => linesThenSummary(lines),
"summary-first": () => summaryFirst(lines),
})}
</Section>
);
}; derivers/commodity-code-summary.deriver.ts import { deriver } from "docxcelerate/template";
/**
* Checks each goods line's tariff code, origin and mass, groups the lines the
* way a customs declaration is split, and totals them. Installed by
* `dxcl add commodity-code-summary`.
*
* It is self-contained on purpose: it travels to the engine as source text, so
* a module-level constant or helper would be a ReferenceError there. Every
* factor and message is declared inside `run`. Every string it returns is
* ready to print, and "" means there is nothing to print.
*/
export default deriver({
name: "commodityCodeSummary",
run: (customs: unknown) => {
// deno-lint-ignore no-explicit-any
const c = customs as any;
let money: Intl.NumberFormat;
try {
// Intl accepts any well-formed three letters, so XXZ would format; the list is what knows it is not a currency.
if (!Intl.supportedValuesOf("currency").includes(c?.currency)) throw new Error("unknown");
money = new Intl.NumberFormat("en-GB", { style: "currency", currency: c?.currency });
} catch {
throw new Error("customs.currency must be an ISO 4217 code");
}
const exponent = money.resolvedOptions().maximumFractionDigits as number;
const fmtMoney = (minor: number) => money.format(minor / 10 ** exponent);
const lengths = [6, 8, 10];
if (!lengths.includes(c?.destinationCodeLength)) {
throw new Error("customs.destinationCodeLength must be one of " + lengths.join(", "));
}
const L: number = c.destinationCodeLength;
const isNum = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v) && v >= 0;
const hasGross = c.grossMassKg !== undefined && c.grossMassKg !== null;
if (hasGross && !isNum(c.grossMassKg)) {
throw new Error("customs.grossMassKg must be a finite number of 0 or more");
}
const qtyFmt = new Intl.NumberFormat("en-GB", { maximumFractionDigits: 3 });
const kgFmt = new Intl.NumberFormat("en-GB", { minimumFractionDigits: 3, maximumFractionDigits: 3 });
// Strips binary noise (0.1 + 0.2) before anything is rounded or compared.
const clean = (n: number) => Math.round(n * 1e6) / 1e6;
const wholeGrams = (n: number) => Math.floor(clean(n) + 0.5);
const kg = (grams: number) => kgFmt.format(grams / 1000);
const factors: Record<string, number> = { kg: 1000, g: 1, lb: 453.59237 };
const raw: unknown[] = Array.isArray(c.lines) ? c.lines : [];
if (raw.length === 0) {
return {
empty: true,
basis: "",
attention: "",
lines: [],
groups: [],
totalNetMass: "",
totalValue: "",
grossMass: "",
grossWarning: "",
};
}
interface Entry {
code: string;
origin: string;
preference: boolean;
grams: number;
valueMinor: number;
supp: { code: string; quantity: number } | null;
}
const entries: Entry[] = [];
let flagged = 0;
const lines = raw.map((item, i) => {
// deno-lint-ignore no-explicit-any
const l = item as any;
const at = "customs.lines[" + i + "]";
if (!isNum(l?.quantity)) throw new Error(at + ".quantity must be a finite number of 0 or more");
if (!isNum(l.netMass?.value)) throw new Error(at + ".netMass.value must be a finite number of 0 or more");
if (factors[l.netMass.unit] === undefined) throw new Error(at + '.netMass.unit must be "kg", "g" or "lb"');
if (!Number.isInteger(l.valueMinor) || l.valueMinor < 0) {
throw new Error(at + ".valueMinor must be a non-negative integer");
}
const s = l.supplementaryUnit;
const hasSupp = s !== undefined && s !== null;
if (hasSupp && (typeof s.code !== "string" || s.code === "")) {
throw new Error(at + ".supplementaryUnit.code must not be empty");
}
if (hasSupp && !isNum(s.quantity)) {
throw new Error(at + ".supplementaryUnit.quantity must be a finite number of 0 or more");
}
const warnings: string[] = [];
const tariff = l.tariffCode;
if (typeof tariff === "number") {
warnings.push("The tariff code was supplied as a number, so a leading zero may have been lost. Supply it as text.");
}
const code = String(tariff ?? "").replace(/[\s.]/g, "");
if (code === "") {
warnings.push("No tariff code: this line cannot be declared.");
} else if (!/^\d+$/.test(code)) {
warnings.push("“" + String(tariff) + "” is not a tariff code.");
} else if (code.length < L) {
warnings.push("The tariff code has " + code.length + " digits; this destination needs " + L + ".");
}
const origin = String(l.origin ?? "").trim().toUpperCase();
if (origin === "") {
warnings.push("No country of origin.");
} else if (!/^[A-Z]{2}$/.test(origin)) {
warnings.push("“" + origin + "” is not a two-letter country code.");
}
const grams = clean(l.netMass.value * factors[l.netMass.unit]);
const preference = l.preference === true;
entries.push({
code,
origin,
preference,
grams,
valueMinor: l.valueMinor,
supp: hasSupp ? { code: s.code, quantity: s.quantity } : null,
});
if (warnings.length > 0) flagged += 1;
const ref = typeof l.ref === "string" ? l.ref.trim() : "";
const description = typeof l.description === "string" ? l.description : "";
return {
item: (ref === "" ? "Line " + (i + 1) : ref) + (description === "" ? "" : " — " + description),
tariffCode: code === "" ? "None" : code,
origin: origin === "" ? "None" : origin,
preference: preference ? "Yes" : "No",
quantity: qtyFmt.format(l.quantity),
supplementary: hasSupp ? qtyFmt.format(s.quantity) + " " + s.code : "",
netMass: kgFmt.format(wholeGrams(grams) / 1000),
value: fmtMoney(l.valueMinor),
warning: warnings.join(" "),
};
});
// Missing sorts last, so a broker scanning down finds real codes first.
const cmp = (a: string, b: string) => a === b ? 0 : a === "" ? 1 : b === "" ? -1 : a < b ? -1 : 1;
const buckets = new Map<string, Entry[]>();
for (const e of entries) {
const key = JSON.stringify([e.code, e.origin, e.preference]);
const bucket = buckets.get(key);
if (bucket) bucket.push(e);
else buckets.set(key, [e]);
}
const sorted = [...buckets.values()].sort((a, b) =>
cmp(a[0].code, b[0].code) || cmp(a[0].origin, b[0].origin) || Number(a[0].preference) - Number(b[0].preference)
);
let totalGrams = 0;
let totalMinor = 0;
const groups = sorted.map((members) => {
const first = members[0];
const grams = wholeGrams(members.reduce((sum, e) => sum + e.grams, 0));
const minor = members.reduce((sum, e) => sum + e.valueMinor, 0);
totalGrams += grams;
totalMinor += minor;
const given = members.filter((e) => e.supp !== null);
let supplementary = "";
let warning = "";
if (given.length > 0) {
const unit = given[0].supp!.code;
if (given.length === members.length && given.every((e) => e.supp!.code === unit)) {
supplementary = qtyFmt.format(clean(given.reduce((sum, e) => sum + e.supp!.quantity, 0))) + " " + unit;
} else {
warning = "The lines in this group give different supplementary units, so none is totalled.";
}
}
return {
tariffCode: first.code === "" ? "None" : first.code,
origin: first.origin === "" ? "None" : first.origin,
preference: first.preference ? "Yes" : "No",
lineCount: members.length === 1 ? "1 line" : members.length + " lines",
supplementary,
netMass: kg(grams),
value: fmtMoney(minor),
warning,
};
});
let grossMass = "";
let grossWarning = "";
if (hasGross) {
const grossGrams = Math.round(c.grossMassKg * 1000);
grossMass = kg(grossGrams);
if (totalGrams > grossGrams) {
grossWarning = "The net mass of the lines, " + kg(totalGrams) + " kg, is more than the declared gross mass of " +
grossMass + " kg. One of them is wrong.";
}
}
return {
empty: false,
basis: "Tariff codes are checked to " + L + " digits for this destination. Masses are net, in kilograms.",
attention: flagged === 0 ? "" : flagged + " of " + raw.length + " lines " + (flagged === 1 ? "needs" : "need") +
" attention before these goods can be declared.",
lines,
groups,
totalNetMass: kg(totalGrams),
totalValue: fmtMoney(totalMinor),
grossMass,
grossWarning,
};
},
}); arrangements/commodity-code-summary/lines.ts /**
* One goods line, every cell already decided and formatted. "" means nothing
* to print.
*
* Installed by `dxcl add commodity-code-summary`, with the arrangements.
*/
export interface CommodityCodeSummaryLine {
/** The invoice's line reference and description. */
item: string;
/** The tariff code as text, or "None". */
tariffCode: string;
/** The two-letter country of origin, or "None". */
origin: string;
/** "Yes" or "No". */
preference: string;
/** The invoice quantity. */
quantity: string;
/** Supplementary quantity and unit ("2,400 pa"), or "". */
supplementary: string;
/** Net mass in kilograms, 3 decimals. */
netMass: string;
/** The line's value, formatted in the invoice currency. */
value: string;
/** What is wrong with this line, or "". */
warning: string;
}
/** One summary row: lines sharing a tariff code, origin and preference claim. */
export interface CommodityCodeSummaryGroup {
/** The tariff code as text, or "None". */
tariffCode: string;
/** The two-letter country of origin, or "None". */
origin: string;
/** "Yes" or "No". */
preference: string;
/** "1 line" or "n lines". */
lineCount: string;
/** Summed supplementary quantity and unit, or "". */
supplementary: string;
/** Net mass in kilograms, rounded once from the exact sum. */
netMass: string;
/** The summed value, formatted in the invoice currency. */
value: string;
/** Why the supplementary quantity was not totalled, or "". */
warning: string;
}
/**
* What the commodity code summary hands each of its arrangements: every part
* of the block, already decided. An arrangement places these and decides
* nothing, so both print the same lines under the same conditions.
*
* A "" field is a line this invoice does not carry. Test it in the JSX,
* `{lines.attention && …}`, so the test is compiled into a condition the
* engine settles per document.
*
* Installed by `dxcl add commodity-code-summary`, with the arrangements.
*/
export interface CommodityCodeSummaryLines {
/** How the codes were checked and what the masses are. */
basis: string;
/** How many lines need attention, or "". */
attention: string;
/** The goods lines, in invoice order. */
lines: CommodityCodeSummaryLine[];
/** The summary rows, in tariff order. */
groups: CommodityCodeSummaryGroup[];
/** Net mass of the groups added together, in kilograms. */
totalNetMass: string;
/** Value of the groups added together. */
totalValue: string;
/** The declared gross mass in kilograms, or "". */
grossMass: string;
/** The net-over-gross warning, or "". */
grossWarning: string;
} arrangements/commodity-code-summary/lines-then-summary.arrangement.tsx import { Cell, Paragraph, Row, Table, type Yield } from "docxcelerate/template";
import type { CommodityCodeSummaryLines } from "./lines.ts";
/**
* Every goods line, then the summary under it, the way the invoice reads
* top to bottom and the declaration is keyed last.
*/
export const linesThenSummary = (lines: CommodityCodeSummaryLines): Yield => (
<>
<Paragraph id="commodity-code-summary-basis">{lines.basis}</Paragraph>
{lines.attention && <Paragraph id="commodity-code-summary-attention">{lines.attention}</Paragraph>}
{/* Item auto; 20mm code (10 digits), 10 origin, 9 pref., 13 quantity, 15 supp. unit, 17 mass ("12,000.000"), 23 value ("£1,485,000.00"): 107mm fixed, so Item keeps ~39mm on a 146mm column. */}
<Table
id="commodity-code-summary-lines"
columns={[
{ width: "auto" },
{ width: 20 },
{ width: 10 },
{ width: 9 },
{ width: 13, align: "right" },
{ width: 15, align: "right" },
{ width: 17, align: "right" },
{ width: 23, align: "right" },
]}
>
<Row id="commodity-code-summary-lines-header" header>
<Cell>Item</Cell>
<Cell>Tariff code</Cell>
<Cell>Origin</Cell>
<Cell>Pref.</Cell>
<Cell>Quantity</Cell>
<Cell>Supp. unit</Cell>
<Cell>Net mass (kg)</Cell>
<Cell>Value</Cell>
</Row>
{lines.lines.map((row) => (
<Row id="commodity-code-summary-line">
<Cell>
<Paragraph>{row.item}</Paragraph>
{row.warning && <Paragraph id="commodity-code-summary-line-warning">{row.warning}</Paragraph>}
</Cell>
<Cell>{row.tariffCode}</Cell>
<Cell>{row.origin}</Cell>
<Cell>{row.preference}</Cell>
<Cell>{row.quantity}</Cell>
<Cell>{row.supplementary}</Cell>
<Cell>{row.netMass}</Cell>
<Cell>{row.value}</Cell>
</Row>
))}
</Table>
{/* Code auto (it carries the warning); 10 origin, 9 pref., 13 lines, 15 supp. unit, 17 mass, 23 value. */}
<Table
id="commodity-code-summary-groups"
columns={[
{ width: "auto" },
{ width: 10 },
{ width: 9 },
{ width: 13, align: "right" },
{ width: 15, align: "right" },
{ width: 17, align: "right" },
{ width: 23, align: "right" },
]}
>
<Row id="commodity-code-summary-groups-header" header>
<Cell>Tariff code</Cell>
<Cell>Origin</Cell>
<Cell>Pref.</Cell>
<Cell>Lines</Cell>
<Cell>Supp. unit</Cell>
<Cell>Net mass (kg)</Cell>
<Cell>Value</Cell>
</Row>
{lines.groups.map((group) => (
<Row id="commodity-code-summary-group">
<Cell>
<Paragraph>{group.tariffCode}</Paragraph>
{group.warning && <Paragraph id="commodity-code-summary-group-warning">{group.warning}</Paragraph>}
</Cell>
<Cell>{group.origin}</Cell>
<Cell>{group.preference}</Cell>
<Cell>{group.lineCount}</Cell>
<Cell>{group.supplementary}</Cell>
<Cell>{group.netMass}</Cell>
<Cell>{group.value}</Cell>
</Row>
))}
<Row id="commodity-code-summary-total">
<Cell>Total</Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell>{lines.totalNetMass}</Cell>
<Cell>{lines.totalValue}</Cell>
</Row>
</Table>
{lines.grossMass && (
<Paragraph id="commodity-code-summary-gross">Declared gross mass: {lines.grossMass} kg.</Paragraph>
)}
{lines.grossWarning && <Paragraph id="commodity-code-summary-gross-warning">{lines.grossWarning}</Paragraph>}
</>
); arrangements/commodity-code-summary/summary-first.arrangement.tsx import { Cell, Paragraph, Row, Table, type Yield } from "docxcelerate/template";
import type { CommodityCodeSummaryLines } from "./lines.ts";
/**
* The summary and its warnings first, the lines after, so the figures a
* declaration is keyed from sit on the first page of a long invoice. The
* lines are placed, not dropped: a line with a short code still shows its warning.
*/
export const summaryFirst = (lines: CommodityCodeSummaryLines): Yield => (
<>
<Paragraph id="commodity-code-summary-basis">{lines.basis}</Paragraph>
{lines.attention && <Paragraph id="commodity-code-summary-attention">{lines.attention}</Paragraph>}
{/* Code auto (it carries the warning); 10 origin, 9 pref., 13 lines, 15 supp. unit, 17 mass, 23 value. */}
<Table
id="commodity-code-summary-groups"
columns={[
{ width: "auto" },
{ width: 10 },
{ width: 9 },
{ width: 13, align: "right" },
{ width: 15, align: "right" },
{ width: 17, align: "right" },
{ width: 23, align: "right" },
]}
>
<Row id="commodity-code-summary-groups-header" header>
<Cell>Tariff code</Cell>
<Cell>Origin</Cell>
<Cell>Pref.</Cell>
<Cell>Lines</Cell>
<Cell>Supp. unit</Cell>
<Cell>Net mass (kg)</Cell>
<Cell>Value</Cell>
</Row>
{lines.groups.map((group) => (
<Row id="commodity-code-summary-group">
<Cell>
<Paragraph>{group.tariffCode}</Paragraph>
{group.warning && <Paragraph id="commodity-code-summary-group-warning">{group.warning}</Paragraph>}
</Cell>
<Cell>{group.origin}</Cell>
<Cell>{group.preference}</Cell>
<Cell>{group.lineCount}</Cell>
<Cell>{group.supplementary}</Cell>
<Cell>{group.netMass}</Cell>
<Cell>{group.value}</Cell>
</Row>
))}
<Row id="commodity-code-summary-total">
<Cell>Total</Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell>{lines.totalNetMass}</Cell>
<Cell>{lines.totalValue}</Cell>
</Row>
</Table>
{lines.grossMass && (
<Paragraph id="commodity-code-summary-gross">Declared gross mass: {lines.grossMass} kg.</Paragraph>
)}
{lines.grossWarning && <Paragraph id="commodity-code-summary-gross-warning">{lines.grossWarning}</Paragraph>}
{/* Item auto; 20mm code (10 digits), 10 origin, 9 pref., 13 quantity, 15 supp. unit, 17 mass ("12,000.000"), 23 value ("£1,485,000.00"): 107mm fixed, so Item keeps ~39mm on a 146mm column. */}
<Table
id="commodity-code-summary-lines"
columns={[
{ width: "auto" },
{ width: 20 },
{ width: 10 },
{ width: 9 },
{ width: 13, align: "right" },
{ width: 15, align: "right" },
{ width: 17, align: "right" },
{ width: 23, align: "right" },
]}
>
<Row id="commodity-code-summary-lines-header" header>
<Cell>Item</Cell>
<Cell>Tariff code</Cell>
<Cell>Origin</Cell>
<Cell>Pref.</Cell>
<Cell>Quantity</Cell>
<Cell>Supp. unit</Cell>
<Cell>Net mass (kg)</Cell>
<Cell>Value</Cell>
</Row>
{lines.lines.map((row) => (
<Row id="commodity-code-summary-line">
<Cell>
<Paragraph>{row.item}</Paragraph>
{row.warning && <Paragraph id="commodity-code-summary-line-warning">{row.warning}</Paragraph>}
</Cell>
<Cell>{row.tariffCode}</Cell>
<Cell>{row.origin}</Cell>
<Cell>{row.preference}</Cell>
<Cell>{row.quantity}</Cell>
<Cell>{row.supplementary}</Cell>
<Cell>{row.netMass}</Cell>
<Cell>{row.value}</Cell>
</Row>
))}
</Table>
</>
);