Direct debit collection notice
LegalReplaces the how-to-pay block on an invoice collected by direct debit, and words the advance notice for SEPA Core, UK Bacs or US ACH. The notice period is counted the way each scheme counts it: 14 calendar days under SEPA unless a shorter one was agreed, 10 working days under Bacs (never fewer than 3) skipping the bank holidays you supply, and 10 days under ACH only when the amount differs from the last debit. A notice issued too late says 'on or after' the earliest lawful date instead of the date asked for, and the date moves to the next day the scheme settles on, with TARGET2's Easter closing days worked out for the year. The SEPA creditor identifier's check digits are verified without the business code, and a bad one stops the document. The IBAN is shown by its last four characters only. SEPA states the 8-week refund right. Bacs prints the Direct Debit Guarantee only from the approved text you supply, and warns when it is missing. A zero or negative amount says nothing will be collected. All of it is one deriver.
npx dxcl add direct-debit-collection-notice debit.scheme Preview data
the JSON this preview was built with{
"debit": {
"scheme": "sepa-core",
"creditorName": "Northwind Facilities & Estates Management Services GmbH",
"creditorId": "IT58ZZZ0000012345678901",
"mandateReference": "MNDT-2026-NORTHFACILITIES-000048172",
"payerIban": "IT60 X054 2811 1010 0000 0123 456",
"requestedDate": "2027-03-26",
"amount": 1284750,
"first": true
},
"document": {
"issuedAt": "2027-03-08"
}
} {
"debit": {
"scheme": "ach",
"creditorName": "Northwind Facilities & Estates Management Services GmbH",
"creditorId": "IT58ZZZ0000012345678901",
"mandateReference": "MNDT-2026-NORTHFACILITIES-000048172",
"payerIban": "IT60 X054 2811 1010 0000 0123 456",
"requestedDate": "2027-03-26",
"amount": 1284750,
"first": true
},
"document": {
"issuedAt": "2027-03-08"
}
} Rendered preview
each arrangement, rendered on its ownResolved nodes
what a renderer receives — 1 nodesdirect-debit-notice section direct-debit-notice section The files
what installing writes; the selected file is the componentnodes/direct-debit-collection-notice.node.tsx import { arrange, Paragraph, Section, type Section as SectionComponent, useDeriver, useState } from "docxcelerate/template";
import type { DirectDebitCollectionNoticeLines } from "../arrangements/direct-debit-collection-notice/lines.ts";
import { stacked } from "../arrangements/direct-debit-collection-notice/stacked.arrangement.tsx";
import { table } from "../arrangements/direct-debit-collection-notice/table.arrangement.tsx";
import directDebitCollectionNotice from "../derivers/direct-debit-collection-notice.deriver.ts";
/**
* The "how you will pay" block for an invoice collected by direct debit: the
* advance notice the payer is owed, which says how much is collected, when, by
* whom and under which mandate. It is worded for the scheme the debit runs on,
* SEPA Core, UK Bacs or US ACH. Use it instead of `payment-summary`, not
* alongside it; the document decides which of the two to place.
*
* The decision it makes for the reader: the notice never names a collection
* date the scheme does not allow. A debit that goes through is still
* non-compliant if its notice was too short. SEPA counts the notice in
* calendar days (14, or a shorter period agreed with the payer) and moves the
* date to the next TARGET2 day, with the Easter closing days worked out for the
* year. Bacs counts working days (10, or an agreed period of at least 3) and
* skips the bank holidays the data supplies. ACH gives 10 days' notice of
* amount and date only when the amount differs from the last debit (Reg E
* 1005.10(d)). When the notice is issued inside the lead time, the requested
* date is replaced by "on or after" the earliest lawful date. A zero or
* negative amount says nothing will be collected.
*
* Scheme text is never paraphrased. The SEPA notice states the 8-week refund
* right. A Bacs notice prints the Direct Debit Guarantee only from the approved
* text the data supplies; if that is missing it prints a visible "incomplete"
* warning rather than inventing the wording. The SEPA creditor identifier is
* checked with its check digits, computed without the business code, and one
* that fails stops the document rather than reaching a payer.
*
* Every scheme and outcome test is written inline against `debit.scheme` or
* the deriver's result, never hoisted into a `const`: while publishing, a
* hoisted `===` is settled to a plain boolean at build time and every
* recipient gets the same arm.
*
* All calculation is in one deriver, because date arithmetic, rounding and
* formatting on request data cannot be done at publish time. It runs for every
* notice, whatever the outcome, so a bad identifier stops a zero-amount notice
* too.
*
* A publish build of this node emits 13 branches against the default
* `branchLimit` of 32.
*
* Arrangement: where the mandate details sit is a separate choice from what
* they say, made with the `arrangement` prop. This file decides every line;
* each arrangement, in `arrangements/direct-debit-collection-notice/`, only
* places them.
*
* Installed by `dxcl add direct-debit-collection-notice`, which also installs its deriver.
*/
/** What this component reads. Add these fields to your document data type. */
export interface DirectDebitCollectionNoticeData {
debit: {
/**
* Which scheme collects the payment. `sepa-core` is the SEPA Core scheme
* (euro), `bacs` is UK Direct Debit (sterling), `ach` is a US ACH debit
* (dollars). The currency follows the scheme. Required: anything else
* throws, because each scheme has its own lead time and its own wording.
*/
scheme: "sepa-core" | "bacs" | "ach";
/**
* Who collects, as the payer will see it on their statement:
* `"Northwind Facilities Ltd"`. Printed as given (trimmed). Required:
* missing or blank throws.
*/
creditorName: string;
/**
* SEPA only: the creditor identifier, e.g. `"DE98ZZZ09999999999"`. Spaces
* are removed and letters upper-cased before it is checked and printed.
* Required for `sepa-core`. If it is missing, has the wrong shape, or
* fails the check digits, the deriver throws. Ignored for other schemes.
*/
creditorId?: string;
/**
* Bacs only: the six-digit Service User Number. Spaces are removed.
* Required for `bacs`: missing or anything other than six digits throws.
* Ignored for other schemes.
*/
sun?: string;
/**
* The mandate reference (SEPA), Direct Debit reference (Bacs) or
* authorization reference (ACH). Printed as given (trimmed). Required:
* blank throws. Longer than 35 characters throws for `sepa-core`, and
* longer than 18 for `bacs`. ACH has no limit here.
*/
mandateReference: string;
/**
* The payer's IBAN. Only its last four characters are ever printed, as
* "IBAN ending 3456". Spaces are removed and letters upper-cased. Wins
* over `payerAccountLast4` when both are given. Fewer than four
* alphanumeric characters throws. Not checksum-validated.
*/
payerIban?: string;
/**
* The last four characters of the payer's account, printed as "Account
* ending 1234" (or "IBAN ending 1234" under SEPA). Anything other than
* exactly four letters or digits throws. When neither this nor
* `payerIban` is given, the account line is left out: the notice is
* lawful without it.
*/
payerAccountLast4?: string;
/**
* The date the creditor wants to collect, ISO 8601: `"2027-03-26"`.
* Anything after the tenth character is ignored. Required: missing, not
* YYYY-MM-DD, or not a real date (`2027-02-30`) throws. It may fall on a
* closed day or before the notice period ends. The printed date is moved
* to the earliest lawful open day.
*/
requestedDate: string;
/**
* What is collected, in major units of the scheme's currency: `1284.5`.
* Rounded to minor units before any comparison. Zero (after rounding)
* prints "nothing will be collected". Negative means the account is in
* credit, and also collects nothing. Required: not a finite number throws.
*/
amount: number;
/**
* ACH only: the amount of the last debit under this authorization, in
* dollars. When it differs from `amount` (compared in cents), Reg E's
* 10-day notice of amount and date applies and the notice says the amount
* changed. Missing means "not known to differ": no lead time applies.
* Not a finite number when present throws. Ignored for other schemes.
*/
previousAmount?: number;
/**
* True when this is the first collection under the mandate. Changes one
* sentence only. Missing means a recurring collection.
*/
first?: boolean;
/**
* A notice period the payer agreed to in place of the scheme default:
* calendar days under SEPA (any value replaces 14), working days under
* Bacs (values below 3 are raised to 3, the Bacs floor, so the notice
* stays lawful). Ignored for ACH, whose 10 days cannot be agreed away.
* Missing means the default. Not a non-negative integer throws.
*/
agreedNoticeDays?: number;
/**
* Bank holidays as ISO 8601 dates, on top of weekends. Bacs uses UK bank
* holidays for the payer's bank's nation. ACH uses Federal Reserve
* holidays. Required for `bacs` (an empty array means "none in range"):
* missing throws, because without it the notice period can end a working
* day early. Optional for `ach`, where missing means weekends only: the
* lead time there is in calendar days, so only the settlement date shifts.
* Ignored for SEPA, whose TARGET2 calendar is computed. Any entry that is
* not an ISO date throws.
*/
bankHolidays?: string[];
/**
* Bacs only: the Direct Debit Guarantee, exactly as approved by your
* sponsoring bank, one entry per paragraph (include the heading as the
* first entry if your approved text has one). Printed verbatim, one
* paragraph per entry. Missing, empty, or containing a blank or
* non-string entry prints the "Guarantee missing" warning in its place.
* Ignored for other schemes.
*/
guaranteeText?: string[];
};
document: {
/**
* When the notice is issued, ISO 8601. The notice period is counted from
* this day (the day itself is not counted). Required: missing or not a
* date throws.
*/
issuedAt: string;
};
}
/**
* Where the mandate details sit.
*
* - `stacked`: one labelled line under another. The default.
* - `table`: labels in a narrow column with the values beside them.
*/
export type DirectDebitCollectionNoticeArrangement = "stacked" | "table";
/** Props for {@linkcode DirectDebitCollectionNotice}. */
export interface DirectDebitCollectionNoticeProps {
/** Where the mandate details sit. Defaults to `"stacked"`. */
arrangement?: DirectDebitCollectionNoticeArrangement;
}
export const DirectDebitCollectionNotice: SectionComponent<DirectDebitCollectionNoticeProps> = async (
{ arrangement },
) => {
const [debit] = useState((data: DirectDebitCollectionNoticeData) => data.debit);
const [doc] = useState((data: DirectDebitCollectionNoticeData) => data.document);
const d = await useDeriver(directDebitCollectionNotice, [debit, doc.issuedAt]);
const lines: DirectDebitCollectionNoticeLines = {
creditorName: d.creditorName,
creditorIdLabel: d.creditorIdLabel,
creditorId: d.creditorId,
mandateLabel: d.mandateLabel,
mandateReference: d.mandateReference,
account: d.account,
};
return (
<Section id="direct-debit-notice" title={d.heading}>
{d.outcome === "clear" && (
<Paragraph id="dd-notice-nothing-clear">
There is nothing to pay on this invoice, so nothing will be collected by {d.schemeName}.
</Paragraph>
)}
{d.outcome === "credit" && (
<Paragraph id="dd-notice-nothing-credit">
Your account is {d.amount} in credit, so nothing will be collected by {d.schemeName} for this invoice.
</Paragraph>
)}
{d.outcome === "collect" && !d.late && (
<Paragraph id="dd-notice-collect-on">
We will collect {d.amount} from your account by {d.schemeName} on {d.date}.
</Paragraph>
)}
{d.outcome === "collect" && d.late && (
<Paragraph id="dd-notice-collect-after">
This notice is issued less than {d.noticeLabel} before the date we planned, so we will collect {d.amount}{" "}
from your account by {d.schemeName} on or after {d.date}, the earliest date the notice period allows.
</Paragraph>
)}
{d.outcome === "collect" && debit.scheme === "ach" && d.amountChanged && (
<Paragraph id="dd-notice-amount-changed">
This amount differs from your last payment of {d.previousAmount}.
</Paragraph>
)}
{d.outcome === "collect" && debit.first && (
<Paragraph id="dd-notice-first">
This is the first payment we will collect under this {d.mandateNoun}.
</Paragraph>
)}
{d.outcome === "collect" && !debit.first && (
<Paragraph id="dd-notice-recurring">
This is a regular payment under your existing {d.mandateNoun}.
</Paragraph>
)}
{d.outcome === "collect" && (
<>
{arrange(arrangement, {
stacked: () => stacked(lines),
table: () => table(lines),
})}
</>
)}
{d.outcome === "collect" && debit.scheme === "sepa-core" && (
<Paragraph id="dd-notice-sepa-refund">
You are entitled to a refund from your bank under the terms and conditions of your agreement with your
bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.
</Paragraph>
)}
{d.outcome === "collect" && debit.scheme === "bacs" && !d.guaranteeMissing &&
(debit.guaranteeText ?? []).map((entry) => <Paragraph id="dd-notice-guarantee">{entry}</Paragraph>)}
{d.outcome === "collect" && debit.scheme === "bacs" && d.guaranteeMissing && (
<Paragraph id="dd-notice-guarantee-missing">
Direct Debit Guarantee missing: a Direct Debit advance notice must carry the Guarantee in the wording your
sponsoring bank approved, and none was supplied. Add the approved text before this notice is issued.
</Paragraph>
)}
</Section>
);
}; derivers/direct-debit-collection-notice.deriver.ts import { deriver } from "docxcelerate/template";
/**
* Validates a direct debit and works out what its advance notice may say: the
* amount, the earliest lawful collection date for the scheme and the mandate
* details. Installed by `dxcl add direct-debit-collection-notice`.
*
* 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. The Easter
* calculation, the TARGET2 test, the check digits and the scheme tables all
* live inside `run`, and nothing in it needs BigInt.
*/
export default deriver({
name: "directDebitCollectionNotice",
run: (debitInput: unknown, issuedAtInput: unknown) => {
// deno-lint-ignore no-explicit-any
const debit = debitInput as any;
const DAY = 86_400_000;
const schemes = ["sepa-core", "bacs", "ach"];
if (!schemes.includes(debit?.scheme)) {
throw new Error("debit.scheme must be one of " + schemes.join(", "));
}
const scheme: string = debit.scheme;
const sepa = scheme === "sepa-core";
const bacs = scheme === "bacs";
const ach = scheme === "ach";
if (typeof debit.creditorName !== "string" || debit.creditorName.trim() === "") {
throw new Error("debit.creditorName is required");
}
const creditorName: string = debit.creditorName.trim();
// A UTC day number, or a throw naming the field. The round trip is what
// refuses 2027-02-30, which Date.UTC would quietly roll into March.
const dayOf = (value: unknown, field: string): number => {
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}/.test(value)) {
throw new Error(field + " must be an ISO 8601 date");
}
const y = Number(value.slice(0, 4));
const m = Number(value.slice(5, 7));
const d = Number(value.slice(8, 10));
const ms = Date.UTC(y, m - 1, d);
const back = new Date(ms);
if (back.getUTCFullYear() !== y || back.getUTCMonth() !== m - 1 || back.getUTCDate() !== d) {
throw new Error(field + " is not a real date");
}
return ms / DAY;
};
const issued = dayOf(issuedAtInput, "document.issuedAt");
const requested = dayOf(debit.requestedDate, "debit.requestedDate");
if (typeof debit.amount !== "number" || !Number.isFinite(debit.amount)) {
throw new Error("debit.amount must be a finite number");
}
const toMinor = (n: number) => Math.sign(n) * Math.round(Math.abs(n) * 100);
if (ach && debit.previousAmount !== undefined && debit.previousAmount !== null) {
if (typeof debit.previousAmount !== "number" || !Number.isFinite(debit.previousAmount)) {
throw new Error("debit.previousAmount must be a finite number");
}
}
let creditorIdLabel: string | null = null;
let creditorId: string | null = null;
if (sepa) {
if (typeof debit.creditorId !== "string") throw new Error("debit.creditorId is required for sepa-core");
const id = debit.creditorId.replace(/\s+/g, "").toUpperCase();
if (!/^[A-Z]{2}\d{2}[A-Z0-9]{3}[A-Z0-9]{1,28}$/.test(id) || id.length > 35) {
throw new Error("debit.creditorId is not a SEPA creditor identifier");
}
// The business code (characters 5 to 7) is left out of the check.
const digits = (id.slice(7) + id.slice(0, 2) + "00")
.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
let r = 0;
for (const ch of digits) r = (r * 10 + Number(ch)) % 97;
const expected = String(98 - r).padStart(2, "0");
if (id.slice(2, 4) !== expected) {
throw new Error("debit.creditorId has the wrong check digits: expected " + expected);
}
creditorIdLabel = "Creditor identifier";
creditorId = id;
} else if (bacs) {
const sun = typeof debit.sun === "string" ? debit.sun.replace(/\s+/g, "") : "";
if (!/^\d{6}$/.test(sun)) throw new Error("debit.sun must be a six-digit Service User Number");
creditorIdLabel = "Service User Number";
creditorId = sun;
}
if (typeof debit.mandateReference !== "string" || debit.mandateReference.trim() === "") {
throw new Error("debit.mandateReference is required");
}
const mandateReference: string = debit.mandateReference.trim();
const maxReference = sepa ? 35 : bacs ? 18 : Infinity;
if (mandateReference.length > maxReference) {
throw new Error("debit.mandateReference is longer than " + maxReference + " characters");
}
let account: string | null = null;
const prefix = sepa ? "IBAN ending " : "Account ending ";
if (debit.payerIban !== undefined && debit.payerIban !== null) {
const iban = typeof debit.payerIban === "string" ? debit.payerIban.replace(/\s+/g, "").toUpperCase() : "";
if (!/^[A-Z0-9]{4,}$/.test(iban)) throw new Error("debit.payerIban must have at least four letters or digits");
account = prefix + iban.slice(-4);
} else if (debit.payerAccountLast4 !== undefined && debit.payerAccountLast4 !== null) {
if (typeof debit.payerAccountLast4 !== "string" || !/^[A-Za-z0-9]{4}$/.test(debit.payerAccountLast4)) {
throw new Error("debit.payerAccountLast4 must be exactly four letters or digits");
}
account = prefix + debit.payerAccountLast4.toUpperCase();
}
const agreed = debit.agreedNoticeDays;
if (agreed !== undefined && agreed !== null && !(Number.isInteger(agreed) && agreed >= 0)) {
throw new Error("debit.agreedNoticeDays must be a non-negative integer");
}
const holidays: number[] = [];
if (bacs && !Array.isArray(debit.bankHolidays)) {
throw new Error("debit.bankHolidays is required for bacs");
}
if (!sepa && debit.bankHolidays !== undefined && debit.bankHolidays !== null) {
if (!Array.isArray(debit.bankHolidays)) throw new Error("debit.bankHolidays must be an array");
for (const h of debit.bankHolidays) holidays.push(dayOf(h, "debit.bankHolidays entry"));
}
const g = debit.guaranteeText;
// deno-lint-ignore no-explicit-any
const guaranteeMissing = bacs && (!Array.isArray(g) || g.length === 0 || g.some((e: any) => typeof e !== "string" || e.trim() === ""));
const minor = toMinor(debit.amount);
const outcome = minor > 0 ? "collect" : minor === 0 ? "clear" : "credit";
const currency = sepa ? "EUR" : bacs ? "GBP" : "USD";
const locale = ach ? "en-US" : "en-GB";
const money = new Intl.NumberFormat(locale, { style: "currency", currency });
const amountChanged = ach && debit.previousAmount !== undefined && debit.previousAmount !== null &&
toMinor(debit.previousAmount) !== minor;
const previousAmount = amountChanged ? money.format(Math.abs(toMinor(debit.previousAmount)) / 100) : null;
// Notice length and its label. ACH labels "10 days" whether or not it applies.
const plural = (n: number, unit: string) => n + " " + unit + (n === 1 ? "" : "s");
const days: number = sepa
? (agreed ?? 14)
: bacs
? Math.max(agreed ?? 10, 3)
: amountChanged
? 10
: 0;
const noticeLabel = sepa ? plural(days, "calendar day") : bacs ? plural(days, "working day") : "10 days";
// Whether the scheme settles on this day. TARGET2 recomputes Easter for the
// candidate's own year, since rolling forward can cross New Year.
const isOpen = (n: number): boolean => {
const date = new Date(n * DAY);
const dow = date.getUTCDay();
if (dow === 0 || dow === 6) return false;
if (!sepa) return !holidays.includes(n);
const y = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const dom = date.getUTCDate();
if ((month === 1 && dom === 1) || (month === 5 && dom === 1) || (month === 12 && (dom === 25 || dom === 26))) {
return false;
}
const a = y % 19;
const b = Math.floor(y / 100);
const c = y % 100;
const d = Math.floor(b / 4);
const e = b % 4;
const f = Math.floor((b + 8) / 25);
const gg = Math.floor((b - f + 1) / 3);
const h = (19 * a + b - d - gg + 15) % 30;
const i = Math.floor(c / 4);
const k = c % 4;
const l = (32 + 2 * e + 2 * i - h - k) % 7;
const m = Math.floor((a + 11 * h + 22 * l) / 451);
const easter = Date.UTC(y, Math.floor((h + l - 7 * m + 114) / 31) - 1, ((h + l - 7 * m + 114) % 31) + 1) / DAY;
return n !== easter - 2 && n !== easter + 1;
};
let late = false;
let date = "";
if (outcome === "collect") {
let earliest: number;
if (sepa) {
earliest = issued + days;
while (!isOpen(earliest)) earliest += 1;
} else if (bacs) {
earliest = issued;
for (let counted = 0; counted < days;) {
earliest += 1;
if (isOpen(earliest)) counted += 1;
}
} else {
earliest = amountChanged ? issued + 10 : issued;
}
// Compared before rolling: a requested date that only needs rolling is
// still the date the payer was promised, not a short notice.
late = requested < earliest;
let target = late ? earliest : requested;
while (!isOpen(target)) target += 1;
date = new Intl.DateTimeFormat(locale, { day: "numeric", month: "long", year: "numeric", timeZone: "UTC" })
.format(new Date(target * DAY));
}
return {
heading: sepa ? "Payment by SEPA Direct Debit" : bacs ? "Payment by Direct Debit" : "Payment by automatic debit (ACH)",
outcome,
schemeName: sepa ? "SEPA Direct Debit" : bacs ? "Direct Debit" : "ACH debit",
mandateNoun: sepa ? "mandate" : bacs ? "Direct Debit Instruction" : "authorization",
amount: money.format(Math.abs(minor) / 100),
previousAmount,
amountChanged,
late,
noticeLabel,
date,
creditorName,
creditorIdLabel,
creditorId,
mandateLabel: sepa ? "Mandate reference" : bacs ? "Direct Debit reference" : "Authorization reference",
mandateReference,
account,
guaranteeMissing,
};
},
}); arrangements/direct-debit-collection-notice/lines.ts /**
* What the direct debit collection notice hands each of its arrangements: the
* mandate details, already decided. An arrangement places these and decides
* nothing, so both print the same lines under the same conditions.
*
* A field that is `null` is a line this debit does not carry. Test it in the
* JSX, `{lines.account && …}`, so the test is compiled into a condition the
* engine settles per document.
*
* Installed by `dxcl add direct-debit-collection-notice`, with the arrangements.
*/
export interface DirectDebitCollectionNoticeLines {
/** Who collects, trimmed. */
creditorName: string;
/** "Creditor identifier" | "Service User Number", or null for ACH. */
creditorIdLabel: string | null;
/** The normalised identifier, or null for ACH. */
creditorId: string | null;
/** "Mandate reference" | "Direct Debit reference" | "Authorization reference". */
mandateLabel: string;
/** The mandate reference, trimmed. */
mandateReference: string;
/** "IBAN ending 3456" / "Account ending 1234", or null when none was given. */
account: string | null;
} arrangements/direct-debit-collection-notice/stacked.arrangement.tsx import { Paragraph, type Yield } from "docxcelerate/template";
import type { DirectDebitCollectionNoticeLines } from "./lines.ts";
/**
* One labelled mandate detail under another, down the text column. The
* default: it reads in any width, and nothing has to line up with anything.
*/
export const stacked = (lines: DirectDebitCollectionNoticeLines): Yield => (
<>
<Paragraph id="dd-notice-creditor">Collected by: {lines.creditorName}</Paragraph>
{lines.creditorId && (
<Paragraph id="dd-notice-creditor-id">{lines.creditorIdLabel}: {lines.creditorId}</Paragraph>
)}
<Paragraph id="dd-notice-mandate">{lines.mandateLabel}: {lines.mandateReference}</Paragraph>
{lines.account && <Paragraph id="dd-notice-account">From account: {lines.account}</Paragraph>}
</>
); arrangements/direct-debit-collection-notice/table.arrangement.tsx import { Cell, Row, Table, type Yield } from "docxcelerate/template";
import type { DirectDebitCollectionNoticeLines } from "./lines.ts";
/**
* Labels in a narrow column with the mandate details beside them, so the
* values line up and a payer checking a reference finds it in one place.
*/
export const table = (lines: DirectDebitCollectionNoticeLines): Yield => (
// 45mm holds the longest label, "Authorization reference", on one line.
<Table id="dd-notice-details" columns={[{ width: 45 }, { width: "auto" }]}>
<Row id="dd-notice-creditor">
<Cell>Collected by</Cell>
<Cell>{lines.creditorName}</Cell>
</Row>
{lines.creditorId && (
<Row id="dd-notice-creditor-id">
<Cell>{lines.creditorIdLabel}</Cell>
<Cell>{lines.creditorId}</Cell>
</Row>
)}
<Row id="dd-notice-mandate">
<Cell>{lines.mandateLabel}</Cell>
<Cell>{lines.mandateReference}</Cell>
</Row>
{lines.account && (
<Row id="dd-notice-account">
<Cell>From account</Cell>
<Cell>{lines.account}</Cell>
</Row>
)}
</Table>
);