Renewal and price change notice
LegalWorks out the last day to cancel as the renewal date less the notice period, clamping month arithmetic so 31 March less a month is the end of February, and prints it as 'on or before'. Each law's window is measured from its own anchor: California's 2025 rules from the renewal date, the trial end and the price change's effective date; New York §5-903 from the cancellation deadline, for business service contracts as well as consumers. A late notice drops the deadline and says what the law gives the customer, including that a late New York notice makes the renewal unenforceable. A German consumer contract past its minimum term gets 'cancel at any time with one month's notice' instead of a date, and a longer notice period is flagged. UK subscription rules apply only to contracts started on or after a commencement date you can move. A price change shows old and new amounts, the difference and the percentage to one decimal place. All of it is one deriver.
npx dxcl add renewal-and-price-change-notice renewal.jurisdiction Vorschaudaten
das JSON, mit dem diese Vorschau gebaut wurde{
"renewal": {
"jurisdiction": "US-CA",
"customerType": "business",
"contractStart": "2024-05-31",
"initialTermMonths": 36,
"renewalTermMonths": 12,
"renewalDate": "2027-05-31",
"noticePeriod": {
"value": 3,
"unit": "months"
},
"sendDate": "2027-02-01",
"currency": "USD",
"currentAmount": 1284750,
"previousAmount": 1168000,
"priceChange": {
"newAmount": 1413225,
"effectiveDate": "2027-05-31"
},
"cancelInstructions": "Write to Contract Renewals at the address on your master services agreement, or sign in to the customer portal, open Agreements, choose the maintenance agreement and select Cancel automatic renewal, at least by the date above"
}
} {
"renewal": {
"jurisdiction": "US-NY",
"customerType": "business",
"contractStart": "2024-05-31",
"initialTermMonths": 36,
"renewalTermMonths": 12,
"renewalDate": "2027-05-31",
"noticePeriod": {
"value": 3,
"unit": "months"
},
"sendDate": "2027-02-01",
"currency": "USD",
"currentAmount": 1284750,
"previousAmount": 1168000,
"priceChange": {
"newAmount": 1413225,
"effectiveDate": "2027-05-31"
},
"cancelInstructions": "Write to Contract Renewals at the address on your master services agreement, or sign in to the customer portal, open Agreements, choose the maintenance agreement and select Cancel automatic renewal, at least by the date above"
}
} {
"renewal": {
"jurisdiction": "DE",
"customerType": "business",
"contractStart": "2024-05-31",
"initialTermMonths": 36,
"renewalTermMonths": 12,
"renewalDate": "2027-05-31",
"noticePeriod": {
"value": 3,
"unit": "months"
},
"sendDate": "2027-02-01",
"currency": "USD",
"currentAmount": 1284750,
"previousAmount": 1168000,
"priceChange": {
"newAmount": 1413225,
"effectiveDate": "2027-05-31"
},
"cancelInstructions": "Write to Contract Renewals at the address on your master services agreement, or sign in to the customer portal, open Agreements, choose the maintenance agreement and select Cancel automatic renewal, at least by the date above"
}
} {
"renewal": {
"jurisdiction": "UK",
"customerType": "business",
"contractStart": "2024-05-31",
"initialTermMonths": 36,
"renewalTermMonths": 12,
"renewalDate": "2027-05-31",
"noticePeriod": {
"value": 3,
"unit": "months"
},
"sendDate": "2027-02-01",
"currency": "USD",
"currentAmount": 1284750,
"previousAmount": 1168000,
"priceChange": {
"newAmount": 1413225,
"effectiveDate": "2027-05-31"
},
"cancelInstructions": "Write to Contract Renewals at the address on your master services agreement, or sign in to the customer portal, open Agreements, choose the maintenance agreement and select Cancel automatic renewal, at least by the date above"
}
} {
"renewal": {
"jurisdiction": "other",
"customerType": "business",
"contractStart": "2024-05-31",
"initialTermMonths": 36,
"renewalTermMonths": 12,
"renewalDate": "2027-05-31",
"noticePeriod": {
"value": 3,
"unit": "months"
},
"sendDate": "2027-02-01",
"currency": "USD",
"currentAmount": 1284750,
"previousAmount": 1168000,
"priceChange": {
"newAmount": 1413225,
"effectiveDate": "2027-05-31"
},
"cancelInstructions": "Write to Contract Renewals at the address on your master services agreement, or sign in to the customer portal, open Agreements, choose the maintenance agreement and select Cancel automatic renewal, at least by the date above"
}
} Gerenderte Vorschau
jede Anordnung für sich gerendertarrangement="stacked" Standard arrangement="table" arrangement="stacked" Standard arrangement="table" arrangement="stacked" Standard arrangement="table" Aufgelöste Nodes
was ein Renderer erhält — 1 Nodesrenewal-notice section renewal-notice section renewal-notice section renewal-notice section renewal-notice section Die Dateien
was die Installation schreibt; die gewählte Datei ist die Komponentenodes/renewal-and-price-change-notice.node.tsx import { arrange, Section, type Section as SectionComponent, useDeriver, useState } from "docxcelerate/template";
import type { RenewalAndPriceChangeNoticeLines } from "../arrangements/renewal-and-price-change-notice/lines.ts";
import { stacked } from "../arrangements/renewal-and-price-change-notice/stacked.arrangement.tsx";
import { table } from "../arrangements/renewal-and-price-change-notice/table.arrangement.tsx";
import renewalAndPriceChangeNotice from "../derivers/renewal-and-price-change-notice.deriver.ts";
/**
* The body of a renewal reminder or price-change notice: when the contract
* renews and at what price, the last day to cancel, how to cancel, and what
* the governing law adds. Every date is measured from the one that law uses.
*
* Cancel-by: the renewal date less the notice period, with month arithmetic
* clamped to the end of the month (31 March less a month is the end of
* February). Printed as "on or before". With no notice period the deadline is
* the day before the renewal, because "on or before the renewal date" would
* let a cancellation land after the charge.
*
* California (2025 Automatic Renewal Law): three windows, each against its own
* anchor: the renewal date, the end of a trial or introductory price over 31
* days, and the date a price change takes effect.
*
* New York (GOL section 5-903, consumers and businesses): the window is
* measured from the cancellation deadline, not the renewal. A late notice
* makes the automatic renewal unenforceable, and the notice says so.
*
* German consumer contracts past their minimum term run until cancelled, with
* at most a month's notice, so they get no fixed date. A longer contractual
* notice period is flagged and capped.
*
* UK subscription rules apply from a commencement date that is a parameter,
* because it has moved twice. Anything else gets contractual wording only.
*
* A late notice drops the fixed deadline and prints what the law gives the
* customer instead. A notice sent too early prints a "Check before sending"
* warning for whoever issues it.
*
* All of this is decided once, in one deriver: every step is date or money
* arithmetic on request data, which publishing refuses, and written as node
* arms the jurisdictions would spend most of the default `branchLimit` of 32.
* The node publishes 6 branches per arrangement.
*
* Arrangement: where the lines sit is a separate choice from what they say,
* made with the `arrangement` prop. This file decides every line; each
* arrangement, in `arrangements/renewal-and-price-change-notice/`, only
* places them.
*
* Installed by `dxcl add renewal-and-price-change-notice`, which also installs its deriver.
*/
/** What this component reads. Add these fields to your document data type. */
export interface RenewalAndPriceChangeNoticeData {
renewal: {
/**
* Whose rules apply. `"other"` means no statutory renewal rule here:
* contractual wording only. Required: anything else throws.
*/
jurisdiction: "US-CA" | "US-NY" | "DE" | "UK" | "other";
/**
* Who the customer is. California, Germany and the UK apply their rules to
* consumers only; New York §5-903 applies to both. Required: anything else throws.
*/
customerType: "consumer" | "business";
/**
* When the contract was entered, ISO 8601 (`2025-09-30`; anything after the
* tenth character is ignored). Decides whether the 2025 California rules,
* the 2022 German rule and the UK rules apply. It also starts the initial
* term and any trial. Required: throws when missing or not a real date.
*/
contractStart: string;
/**
* The latest date the contract was amended or extended (a renewal counts),
* ISO 8601. Read for US-CA only: the 2025 rules apply when this or
* `contractStart` is on or after 2025-07-01. Missing means never amended.
* Throws when present but not a date.
*/
amendedOn?: string;
/**
* Length of the first term in whole months. Decides whether California's
* renewal window applies (12 or more) and when a German contract's minimum
* term ends. Required: throws unless a positive integer.
*/
initialTermMonths: number;
/**
* Length of each renewal term (the billing interval once renewed) in whole
* months. Printed as the frequency ("every year", "every 3 months"), and
* decides whether New York §5-903 applies (more than 1). Required: throws
* unless a positive integer.
*/
renewalTermMonths: number;
/**
* The renewal this notice is about: the day the next term starts and is
* charged, ISO 8601. Ignored for a German consumer contract already past
* its minimum term. Required: throws when missing, not a date, before
* `contractStart`, or before `sendDate` (except in that German indefinite phase).
*/
renewalDate: string;
/**
* How much notice the contract requires the customer to give before the
* renewal date. `{ value: 0 }` means none: the deadline is then the day
* before the renewal, because "on or before the renewal date" would let a
* cancellation land after the charge. Required: throws unless `value` is a
* non-negative integer and `unit` is `"days"` or `"months"`.
*/
noticePeriod: { value: number; unit: "days" | "months" };
/**
* The day this notice is sent, ISO 8601. Every window is checked against
* it. Required: throws when missing or not a date. It is not defaulted to
* today, because a deriver has to give the same answer on every run.
*/
sendDate: string;
/** ISO 4217 code: `"USD"`, `"EUR"`, `"GBP"`. Required: throws when `Intl` does not know it. */
currency: string;
/**
* The price charged for each renewal term now, in major units
* (`1284750.00`). Required: throws unless a finite number of zero or more.
*/
currentAmount: number;
/**
* The last payment the customer made, in major units. Printed when given,
* with the increase when this renewal costs more. Missing omits the line.
* Under the UK rules it also prints a check warning, because a UK reminder
* must show it. Throws when present but not a finite number of zero or more.
*/
previousAmount?: number;
/**
* A price change. Missing means none. A `newAmount` equal to
* `currentAmount` once both are rounded to minor units is also treated as
* no change. Throws when present and `newAmount` is not a finite number of
* zero or more, or `effectiveDate` is not a date.
*/
priceChange?: { newAmount: number; effectiveDate: string };
/**
* When a free trial or introductory price ends, ISO 8601. The trial
* started on `contractStart`. Missing, or before `sendDate`, means no trial
* line. Throws when present but not a date.
*/
trialEnds?: string;
/**
* How to cancel, as it should be printed ("Sign in, open Billing, choose
* Cancel renewal"). Every regime prints it. Required: throws when missing
* or blank.
*/
cancelInstructions: string;
/**
* When the UK subscription-contract rules (DMCC Act 2024, Part 4 Chapter 2)
* take effect, ISO 8601. Missing means `"2027-01-01"`. It is a parameter
* because the date has moved twice. Throws when present but not a date.
*/
commencementDate?: string;
};
}
/**
* Where the lines sit.
*
* - `stacked`: one labelled line under another, down the text column. The default.
* - `table`: labels in a narrow column with the values beside them, like a
* key-facts box.
*/
export type RenewalAndPriceChangeNoticeArrangement = "stacked" | "table";
/** Props for {@linkcode RenewalAndPriceChangeNotice}. */
export interface RenewalAndPriceChangeNoticeProps {
/** Where the lines sit. Defaults to `"stacked"`. */
arrangement?: RenewalAndPriceChangeNoticeArrangement;
}
/** Prints the renewal notice: what renews, when, the price change if any, and how to cancel. */
export const RenewalAndPriceChangeNotice: SectionComponent<RenewalAndPriceChangeNoticeProps> = async (
{ arrangement },
) => {
const [renewal] = useState((data: RenewalAndPriceChangeNoticeData) => data.renewal);
const r = await useDeriver(renewalAndPriceChangeNotice, [renewal]);
const lines: RenewalAndPriceChangeNoticeLines = {
statement: r.statement,
renewal: r.renewal,
trial: r.trial,
priceChange: r.priceChange,
previousPayment: r.previousPayment,
cancelBy: r.cancelBy,
howToCancel: renewal.cancelInstructions,
consequence: r.consequence,
warning: r.warning,
};
return (
<Section id="renewal-notice" title={r.heading}>
{arrange(arrangement, {
stacked: () => stacked(lines),
table: () => table(lines),
})}
</Section>
);
}; derivers/renewal-and-price-change-notice.deriver.ts // deno-lint-ignore-file no-explicit-any
import { deriver } from "docxcelerate/template";
type Window = {
anchor: "renewal" | "cancel-by" | "trial-end" | "price-change";
from: string;
to: string;
status: "early" | "ok" | "late";
};
type Result = {
regime: "us-ca-arl" | "us-ny-5-903" | "de-consumer" | "uk-dmcc" | "contractual";
heading: string;
statement: string;
renewal: string;
trial: string | null;
priceChange: string | null;
previousPayment: string | null;
cancelBy: string | null;
consequence: string | null;
warning: string | null;
timing: "early" | "ok" | "late" | null;
cancelByIso: string | null;
windows: Window[];
};
/**
* Decides everything a renewal or price-change notice says: which law applies,
* the last day to cancel, whether the notice is early or late for that law's
* window, and the wording each case gets. Installed by
* `dxcl add renewal-and-price-change-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. Every
* helper and threshold is declared inside `run`.
*/
export default deriver({
name: "renewalAndPriceChangeNotice",
run: (input: unknown): Result => {
const r = input as any;
const DAY = 86_400_000;
const dayOf = (iso: string) => {
const [y, m, d] = iso.split("-").map(Number);
return Date.UTC(y, m - 1, d) / DAY;
};
const isoOf = (day: number) => new Date(day * DAY).toISOString().slice(0, 10);
const isoDate = (value: unknown, field: string): string => {
const iso = typeof value === "string" ? value.slice(0, 10) : "";
if (/^\d{4}-\d{2}-\d{2}$/.test(iso)) {
const [y, m, d] = iso.split("-").map(Number);
const t = new Date(Date.UTC(y, m - 1, d));
if (t.getUTCFullYear() === y && t.getUTCMonth() === m - 1 && t.getUTCDate() === d) return iso;
}
throw new Error(field + " must be an ISO 8601 date");
};
const optDate = (value: unknown, field: string) =>
value === undefined || value === null ? undefined : isoDate(value, field);
const optMoney = (value: unknown, field: string) => {
if (value === undefined || value === null) return undefined;
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
throw new Error(field + " must be a finite number of 0 or more");
}
return value;
};
const wholeMonths = (value: unknown, field: string) => {
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
throw new Error(field + " must be a positive whole number of months");
}
return value;
};
// Month arithmetic clamps to the end of the month: 31 March less a month is 28 or 29 February.
const addMonths = (iso: string, n: number) => {
const [y, m, d] = iso.split("-").map(Number);
const total = y * 12 + (m - 1) + n;
const ny = Math.floor(total / 12);
const nm = ((total % 12) + 12) % 12;
const last = new Date(Date.UTC(ny, nm + 1, 0)).getUTCDate();
return isoOf(Date.UTC(ny, nm, Math.min(d, last)) / DAY);
};
// 1. Validate, in the order the fields are documented.
const jurisdictions = ["US-CA", "US-NY", "DE", "UK", "other"];
if (!jurisdictions.includes(r?.jurisdiction)) {
throw new Error("renewal.jurisdiction must be one of " + jurisdictions.join(", "));
}
if (r.customerType !== "consumer" && r.customerType !== "business") {
throw new Error("renewal.customerType must be consumer or business");
}
const contractStart = isoDate(r.contractStart, "renewal.contractStart");
const amendedOn = optDate(r.amendedOn, "renewal.amendedOn");
const initialTermMonths = wholeMonths(r.initialTermMonths, "renewal.initialTermMonths");
const renewalTermMonths = wholeMonths(r.renewalTermMonths, "renewal.renewalTermMonths");
const renewalDate = isoDate(r.renewalDate, "renewal.renewalDate");
if (renewalDate < contractStart) throw new Error("renewal.renewalDate is before renewal.contractStart");
const np = r.noticePeriod;
if (
typeof np?.value !== "number" || !Number.isInteger(np.value) || np.value < 0 ||
(np.unit !== "days" && np.unit !== "months")
) {
throw new Error("renewal.noticePeriod must be a non-negative whole value in days or months");
}
const notice: { value: number; unit: "days" | "months" } = { value: np.value, unit: np.unit };
const sendDate = isoDate(r.sendDate, "renewal.sendDate");
const jurisdiction: string = r.jurisdiction;
const consumer = r.customerType === "consumer";
const locale = jurisdiction === "US-CA" || jurisdiction === "US-NY" ? "en-US" : "en-GB";
let money: Intl.NumberFormat;
try {
money = new Intl.NumberFormat(locale, { style: "currency", currency: r.currency });
} catch {
throw new Error("renewal.currency must be an ISO 4217 code");
}
const exp = money.resolvedOptions().maximumFractionDigits as number;
const currentAmount = optMoney(r.currentAmount ?? NaN, "renewal.currentAmount") as number;
const previousAmount = optMoney(r.previousAmount, "renewal.previousAmount");
const pc = r.priceChange;
if (pc !== undefined && pc !== null) {
optMoney(pc.newAmount ?? NaN, "renewal.priceChange.newAmount");
isoDate(pc.effectiveDate, "renewal.priceChange.effectiveDate");
}
const trialEnds = optDate(r.trialEnds, "renewal.trialEnds");
if (typeof r.cancelInstructions !== "string" || r.cancelInstructions.trim() === "") {
throw new Error("renewal.cancelInstructions is required");
}
const commencement = optDate(r.commencementDate, "renewal.commencementDate") ?? "2027-01-01";
const dates = new Intl.DateTimeFormat(locale, { dateStyle: "long", timeZone: "UTC" });
const fmt = (iso: string) => dates.format(new Date(iso + "T00:00:00Z"));
const toMinor = (x: number) => Math.round(Number((x * 10 ** exp).toPrecision(15)));
const fmtMinor = (minor: number) => money.format(minor / 10 ** exp);
const noun = consumer ? "subscription" : "contract";
const frequency = renewalTermMonths === 1
? "every month"
: renewalTermMonths === 12
? "every year"
: renewalTermMonths % 12 === 0
? "every " + renewalTermMonths / 12 + " years"
: "every " + renewalTermMonths + " months";
// The direction is a word, so "-0.0%" cannot appear.
const pctText = (diff: number, old: number) => {
if (old === 0) return null;
const p = Math.round(Number(((Math.abs(diff) / old) * 100 * 10).toPrecision(15))) / 10;
return p === 0 && diff !== 0 ? "less than 0.1%" : p.toFixed(1) + "%";
};
const periodText = (p: { value: number; unit: string }) =>
p.value === 0 || (p.unit === "days" && p.value === 1)
? "1 day"
: p.unit === "days"
? p.value + " days"
: p.value === 1
? "one month"
: p.value + " months";
const minus = (iso: string, p: { value: number; unit: string }) =>
p.unit === "days" || p.value === 0 ? isoOf(dayOf(iso) - Math.max(p.value, 1)) : addMonths(iso, -p.value);
// 2. Regime: the first rule that matches.
const lastChange = amendedOn && amendedOn > contractStart ? amendedOn : contractStart;
const regime: Result["regime"] = jurisdiction === "US-NY" && renewalTermMonths > 1
? "us-ny-5-903"
: jurisdiction === "US-CA" && consumer && lastChange >= "2025-07-01"
? "us-ca-arl"
: jurisdiction === "DE" && consumer && contractStart >= "2022-03-01"
? "de-consumer"
: jurisdiction === "UK" && consumer && contractStart >= commencement
? "uk-dmcc"
: "contractual";
// A German contract past its minimum term has no renewal date to measure from.
const termEnd = addMonths(contractStart, initialTermMonths);
const indefinite = regime === "de-consumer" && sendDate >= termEnd;
if (!indefinite && renewalDate < sendDate) throw new Error("renewal.renewalDate is before renewal.sendDate");
// 3-4. The configured deadline, and the German cap on it.
let period = notice;
const reference = indefinite ? termEnd : renewalDate;
let cancelByRaw = minus(reference, period);
const warnings: string[] = [];
if (regime === "de-consumer" && cancelByRaw < addMonths(reference, -1)) {
warnings.push(
"Check before sending: the contract's notice period of " + periodText(notice) +
" is longer than the one month German law allows for a consumer contract (BGB §309 No. 9); this notice uses one month.",
);
period = { value: 1, unit: "months" };
cancelByRaw = addMonths(reference, -1);
}
// 5. The deadline in use.
const cancelByIso = indefinite ? null : cancelByRaw;
// 6. The lines that decide windows.
const current = toMinor(currentAmount);
const change = pc !== undefined && pc !== null && toMinor(pc.newAmount) !== current ? pc : null;
const amountOn = (iso: string) => change && change.effectiveDate.slice(0, 10) <= iso ? toMinor(change.newAmount) : current;
const renewalMinor = indefinite ? amountOn(sendDate) : amountOn(renewalDate);
const trialShown = trialEnds !== undefined && trialEnds >= sendDate;
const trial = trialShown ? fmt(trialEnds) + "; from then " + fmtMinor(amountOn(trialEnds)) + " " + frequency : null;
let priceChange: string | null = null;
if (change) {
const diff = toMinor(change.newAmount) - current;
const pct = pctText(diff, current);
priceChange = "From " + fmt(change.effectiveDate.slice(0, 10)) + ": " + fmtMinor(current) + " to " +
fmtMinor(toMinor(change.newAmount)) + ", " + (diff > 0 ? "an increase of " : "a decrease of ") +
fmtMinor(Math.abs(diff)) + (pct ? " (" + pct + ")" : "");
}
let previousPayment: string | null = null;
if (previousAmount !== undefined) {
const prev = toMinor(previousAmount);
previousPayment = fmtMinor(prev);
if (renewalMinor > prev) {
const pct = pctText(renewalMinor - prev, prev);
previousPayment += ". This renewal is " + fmtMinor(renewalMinor - prev) + (pct ? " (" + pct + ")" : "") + " more";
}
} else if (regime === "uk-dmcc") {
warnings.push(
"Check before sending: a UK subscription reminder must show the customer's previous payment, and none was given.",
);
}
// 7. Windows and timing. Each is measured from its own anchor.
const windows: Window[] = [];
const phrase: Record<string, string> = {
renewal: "the renewal",
"cancel-by": "the cancellation deadline",
"trial-end": "your introductory period ends",
"price-change": "the new price takes effect",
};
const bounds: Record<string, [number, number]> = {
renewal: [45, 15],
"cancel-by": [30, 15],
"trial-end": [21, 3],
"price-change": [30, 7],
};
const anchors: Record<string, string> = {};
const addWindow = (anchor: Window["anchor"], date: string) => {
const [far, near] = bounds[anchor];
const from = isoOf(dayOf(date) - far);
const to = isoOf(dayOf(date) - near);
anchors[anchor] = date;
windows.push({ anchor, from, to, status: sendDate < from ? "early" : sendDate > to ? "late" : "ok" });
};
if (regime === "us-ca-arl") {
if (initialTermMonths >= 12) addWindow("renewal", renewalDate);
if (trialShown && dayOf(trialEnds) - dayOf(contractStart) > 31) addWindow("trial-end", trialEnds);
if (change) addWindow("price-change", change.effectiveDate.slice(0, 10));
} else if (regime === "us-ny-5-903") {
addWindow("cancel-by", cancelByRaw);
}
const rank = { ok: 0, early: 1, late: 2 };
const timing = windows.length === 0
? null
: windows.reduce((worst, w) => rank[w.status] > rank[worst] ? w.status : worst, "ok" as Window["status"]);
// 8. Statement, cancel-by, consequence and warning.
const nyLate = regime === "us-ny-5-903" && timing === "late";
const statement = regime === "de-consumer"
? indefinite
? "Your " + noun + " has passed its minimum term and continues until you cancel it."
: "Your " + noun + "'s minimum term ends on " + fmt(renewalDate) +
". Unless you cancel, it then continues until you cancel it, with " + periodText(period) + " notice."
: nyLate
? "Your " + noun + " was set to renew automatically on " + fmt(renewalDate) + "."
: "Your " + noun + " renews automatically on " + fmt(renewalDate) + " unless you cancel it.";
const renewal = indefinite
? "Continues until you cancel, at " + fmtMinor(renewalMinor) + " " + frequency
: fmt(renewalDate) + ", for " + fmtMinor(renewalMinor) + " " + frequency;
const passed = cancelByIso !== null && cancelByIso < sendDate;
const cancelBy = indefinite
? "None. You can cancel at any time; the " + noun + " then ends " + periodText(period) + " later."
: timing === "late" || passed
? null
: "On or before " + fmt(cancelByRaw);
let consequence: string | null = null;
if (nyLate) {
consequence =
"This notice is reaching you less than 15 days before the date you would have had to cancel by, so under New York General Obligations Law §5-903 the automatic renewal cannot be enforced against you. The " +
noun + " will not renew on " + fmt(renewalDate) + " unless you agree to continue.";
} else if (regime === "us-ca-arl" && timing === "late") {
consequence = windows.filter((w) => w.status === "late").map((w) =>
"California law requires notice " + bounds[w.anchor][1] + " to " + bounds[w.anchor][0] + " days before " +
phrase[w.anchor] + " on " + fmt(anchors[w.anchor]) +
", and this notice is later than that. No cancellation deadline applies: you can cancel at any time before " +
fmt(anchors[w.anchor]) + "."
).join(" ");
} else if (passed) {
consequence = "The last day to cancel before the renewal on " + fmt(renewalDate) + " was " + fmt(cancelByRaw) +
", so the " + noun + " will renew. You can still cancel before the renewal after that.";
}
for (const w of windows) {
if (w.status !== "early") continue;
const n = dayOf(w.from) - dayOf(sendDate);
warnings.push(
"Check before sending: " + (regime === "us-ny-5-903" ? "New York" : "California") + " law requires this notice " +
bounds[w.anchor][1] + " to " + bounds[w.anchor][0] + " days before " + phrase[w.anchor] + " on " +
fmt(anchors[w.anchor]) + "; sent on " + fmt(sendDate) + " it is " + n + (n === 1 ? " day" : " days") + " early.",
);
}
return {
regime,
heading: change ? "Price change notice" : trialShown ? "Your introductory period is ending" : "Renewal notice",
statement,
renewal,
trial,
priceChange,
previousPayment,
cancelBy,
consequence,
warning: warnings.length ? warnings.join(" ") : null,
timing,
cancelByIso,
windows,
};
},
}); arrangements/renewal-and-price-change-notice/lines.ts /**
* What the renewal and price change notice hands each of its arrangements:
* every line it may print, 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 notice does not carry. Test it in the
* JSX, `{lines.trial && …}`, so the test is compiled into a condition the
* engine settles per document.
*
* Installed by `dxcl add renewal-and-price-change-notice`, with the arrangements.
*/
export interface RenewalAndPriceChangeNoticeLines {
/** The opening sentence: when the contract renews, or that it continues until cancelled. */
statement: string;
/** The value of the "Renewal" line: the date and what is charged. */
renewal: string;
/** The value of the "Introductory period ends" line, or null when there is no trial. */
trial: string | null;
/** The value of the "Price change" line, or null when the price does not change. */
priceChange: string | null;
/** The value of the "Previous payment" line, or null when none was given. */
previousPayment: string | null;
/** The value of the "Cancellation deadline" line, or null when no fixed deadline applies. */
cancelBy: string | null;
/** How to cancel, as the document's data gives it. */
howToCancel: string;
/** What the law gives the customer when the deadline is gone or the notice is late, or null. */
consequence: string | null;
/** A "Check before sending" note for whoever issues the notice, or null. */
warning: string | null;
} arrangements/renewal-and-price-change-notice/stacked.arrangement.tsx import { Paragraph, type Yield } from "docxcelerate/template";
import type { RenewalAndPriceChangeNoticeLines } from "./lines.ts";
/**
* One labelled line 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: RenewalAndPriceChangeNoticeLines): Yield => (
<>
<Paragraph id="renewal-notice-statement">{lines.statement}</Paragraph>
<Paragraph id="renewal-notice-renewal">Renewal: {lines.renewal}</Paragraph>
{lines.trial && <Paragraph id="renewal-notice-trial">Introductory period ends: {lines.trial}</Paragraph>}
{lines.priceChange && <Paragraph id="renewal-notice-price-change">Price change: {lines.priceChange}</Paragraph>}
{lines.previousPayment && (
<Paragraph id="renewal-notice-previous-payment">Previous payment: {lines.previousPayment}</Paragraph>
)}
{lines.cancelBy && <Paragraph id="renewal-notice-cancel-by">Cancellation deadline: {lines.cancelBy}</Paragraph>}
<Paragraph id="renewal-notice-how-to-cancel">How to cancel: {lines.howToCancel}</Paragraph>
{lines.consequence && <Paragraph id="renewal-notice-consequence">{lines.consequence}</Paragraph>}
{lines.warning && <Paragraph id="renewal-notice-warning">{lines.warning}</Paragraph>}
</>
); arrangements/renewal-and-price-change-notice/table.arrangement.tsx import { Cell, Paragraph, Row, Table, type Yield } from "docxcelerate/template";
import type { RenewalAndPriceChangeNoticeLines } from "./lines.ts";
/**
* Labels in a narrow column with the values beside them: the key-facts box
* many reminders use. The consequence and warning stay full width below it,
* because they are sentences, not facts.
*/
export const table = (lines: RenewalAndPriceChangeNoticeLines): Yield => (
<>
<Paragraph id="renewal-notice-statement">{lines.statement}</Paragraph>
{/* 50mm holds the longest label, "Introductory period ends", on one line. */}
<Table id="renewal-notice-details" columns={[{ width: 50 }, { width: "auto" }]}>
<Row id="renewal-notice-renewal">
<Cell>Renewal</Cell>
<Cell>{lines.renewal}</Cell>
</Row>
{lines.trial && (
<Row id="renewal-notice-trial">
<Cell>Introductory period ends</Cell>
<Cell>{lines.trial}</Cell>
</Row>
)}
{lines.priceChange && (
<Row id="renewal-notice-price-change">
<Cell>Price change</Cell>
<Cell>{lines.priceChange}</Cell>
</Row>
)}
{lines.previousPayment && (
<Row id="renewal-notice-previous-payment">
<Cell>Previous payment</Cell>
<Cell>{lines.previousPayment}</Cell>
</Row>
)}
{lines.cancelBy && (
<Row id="renewal-notice-cancel-by">
<Cell>Cancellation deadline</Cell>
<Cell>{lines.cancelBy}</Cell>
</Row>
)}
<Row id="renewal-notice-how-to-cancel">
<Cell>How to cancel</Cell>
<Cell>{lines.howToCancel}</Cell>
</Row>
</Table>
{lines.consequence && <Paragraph id="renewal-notice-consequence">{lines.consequence}</Paragraph>}
{lines.warning && <Paragraph id="renewal-notice-warning">{lines.warning}</Paragraph>}
</>
);