Contingency settlement statement
BodyThe closing statement a contingent or damages-based fee requires: the recovery, each deduction in the order the agreement and the law apply it, and the net to the client, in one column that adds up. Tiered rates are charged marginally by band, never the top rate on the whole sum, at the rate for the stage the case reached. The fee is worked out on gross or on recovery net of expenses as the agreement says, and the statement shows what the other base would have charged. A statutory cap (New York §474-a, California §6146, the UK DBA Regulations or the CFA Order) is computed and compared with the agreed fee, and the lower is charged. The DBA cap counts VAT and counsel's fees and leaves out future loss, and costs paid by the other side are credited. Liens come off the client's share after the fee unless marked otherwise. A recovery that does not cover everything prints as a shortfall with the agreement's terms on who carries it. All of it is worked out by one deriver that ships with the component.
npx dxcl add contingency-settlement-statement Preview data
the JSON this preview was built with{
"settlement": {
"regime": "contingency",
"currency": "USD",
"grossRecovery": 4850000,
"stage": "trial",
"base": "net",
"statutoryCap": "ny-medical-malpractice",
"schedule": [
{
"stage": "pre-suit",
"percent": 25
},
{
"stage": "filed",
"percent": 30
},
{
"stage": "trial",
"percent": 33.333333333333336
},
{
"stage": "appeal",
"percent": 40
}
],
"expenses": [
{
"label": "Expert witness fees: board-certified neurosurgeon, life-care planner and forensic economist",
"amount": 186450
},
{
"label": "Court reporter and videographer charges for fourteen depositions",
"amount": 38912.75
},
{
"label": "Medical records retrieval and certification, Mount Sinai and NYU Langone",
"amount": 6240.3
},
{
"label": "Index number, request for judicial intervention and jury demand filing fees",
"amount": 1335
},
{
"label": "Trial exhibits, demonstrative animations and courtroom technology",
"amount": 54780
}
],
"liens": [
{
"holder": "Centers for Medicare & Medicaid Services (Medicare Secondary Payer Recovery)",
"amount": 312480.66,
"reducedAmount": 198214.09
},
{
"holder": "Empire BlueCross BlueShield of New York, self-funded ERISA health plan",
"amount": 147905.12,
"reducedAmount": 98603.41
},
{
"holder": "New York State Workers' Compensation Board lien",
"amount": 64220
}
],
"shortfallTerms": "If the recovery does not cover the fee, expenses and liens, the firm waives any unrecovered expenses and the client remains responsible for the liens."
}
} Rendered preview
the component rendered on its ownResolved nodes
what a renderer receives — 1 nodescontingency-settlement section The files
what installing writes; the selected file is the componentnodes/contingency-settlement-statement.node.tsx import { Cell, type Nodes, Paragraph, Row, Section, Table, useDeriver, useState } from "docxcelerate/template";
import contingencySettlementStatement from "../derivers/contingency-settlement-statement.deriver.ts";
/**
* The closing statement a contingent or damages-based fee requires (ABA Model
* Rule 1.5(c); the UK DBA and CFA equivalents): the gross recovery, each
* deduction in the order the agreement and the law apply it, and the net to the
* client, as signed amounts in one column that adds up.
*
* Decisions already made for you:
*
* - Tiered percentages are marginal by band. The top rate is never applied to
* the whole recovery, and the fee is the sum of the rounded band charges, so
* the working in the method sentence adds up exactly.
* - The fee base follows the agreement: gross, or the recovery net of expenses.
* When expenses exist the statement also shows what the other base would have
* charged.
* - The rate comes from the stage the case reached, read from the data and never
* guessed. A missing stage throws when the schedule or the California cap needs one.
* - A statutory cap (NY Judiciary Law 474-a, CA B&P 6146, the UK DBA Regulations
* 2013, the CFA Order 2013) is computed as an amount, compared with the agreed
* fee, and the lower is charged. The DBA cap counts VAT and counsel's fees and
* leaves out future loss; costs paid by the other side are credited, never
* beyond what the client owes. The cap is chosen in the data, never inferred.
* - Liens come off the client's share after the fee. Only a lien marked
* `beforeFee` comes off first and lowers the fee base.
* - A recovery too small to cover everything prints as a shortfall, with the
* agreement's own words on who carries it, or an "incomplete" warning when
* those words were not given.
*
* All of it is decided in one deriver, because every step is arithmetic,
* sorting or formatting on request data, and publishing refuses all of those.
* The node computes nothing: every test is written inline so a publish build
* keeps each arm.
*
* The lines are sixteen fixed slots rather than a `.map()`. The resolver reads a
* published loop's collection from request data and ignores the derived scope,
* so a `.map()` over the deriver's rows would publish and then resolve to no
* rows; conditions and `{{derived.…}}` tokens do honour the derived scope.
*
* The node publishes 20 branches against the default `branchLimit` of 32: 16 row
* slots, other-base, cap and two shortfall arms.
*
* Installed by `dxcl add contingency-settlement-statement`.
*/
/** What this component reads. Add these fields to your document data type. */
export interface ContingencySettlementStatementData {
settlement: {
/**
* Which kind of agreement the fee is paid under.
* `contingency`: a percentage of the recovery (US-style contingent fee).
* `DBA`: an England & Wales damages-based agreement (DBA Regulations 2013).
* `CFA`: an England & Wales conditional fee agreement: base costs plus a
* success fee. Required: anything else throws.
*/
regime: "contingency" | "DBA" | "CFA";
/**
* ISO 4217 code every amount is in: "USD", "GBP". It also sets the minor
* unit (two decimals for USD and GBP, none for JPY). Required: throws when
* missing or not a code Intl knows.
*/
currency: string;
/**
* The total awarded or agreed, in major units, before anything is taken
* off it. That includes any benefits the compensator withholds for the
* CRU; list those as a lien with `cru: true`. Required: throws when missing,
* not finite, or negative. 0 is allowed and prints a shortfall if anything
* is owed.
*/
grossRecovery: number;
/**
* How far the case got, which picks the percentage. Missing is allowed only
* when no schedule row names a stage, and when `statutoryCap` is not
* "ca-medical-negligence". Otherwise it throws: the stage is never guessed.
*/
stage?: "pre-suit" | "filed" | "trial" | "appeal";
/**
* The agreement's percentages. For `contingency` and `DBA`, each row is a
* band of the fee base. For `CFA`, each row is the success-fee uplift on
* base costs. Required, non-empty.
*/
schedule: Array<{
/**
* The stage this row applies at. Rows for the given `stage` are used.
* When none match, rows with no stage are used. When none of those
* exist either, it throws.
*/
stage?: "pre-suit" | "filed" | "trial" | "appeal";
/**
* Upper edge of this band, cumulative, in major units: 250000 means
* "the first 250,000". Missing means the open top band ("everything
* above"). Among the rows used, exactly one must have no `upTo`, and the
* `upTo` values must be positive and distinct. Otherwise it throws.
* CFA: must be missing on every row, otherwise it throws.
*/
upTo?: number;
/**
* The rate, as a percentage from 0 to 100. A third is `100 / 3` and
* prints as 33.33%. For `DBA` it is the solicitor's charge before VAT.
* For `CFA` it is the uplift on base costs and may not exceed 100.
* Out of range throws.
*/
percent: number;
}>;
/**
* What the agreement applies the percentage to. "gross" is the whole
* recovery. "net" is the recovery after the case expenses below. Required
* for `contingency` and `DBA`, where missing throws. Ignored for `CFA`.
*/
base?: "gross" | "net";
/**
* A statutory fee cap that applies to this matter. `contingency` only:
* given with another regime, it throws. Missing means no statutory cap.
* The cap is chosen here and is never inferred from a jurisdiction.
*/
statutoryCap?: "ny-medical-malpractice" | "ca-medical-negligence";
/**
* Which DBA or CFA cap applies. Required for `DBA` and `CFA`, where
* missing throws. Ignored for `contingency`.
*/
claimType?: "personal-injury" | "employment" | "other";
/**
* The personal-injury heads of damage, in major units. Required when
* `claimType` is "personal-injury" under `DBA` or `CFA`, where missing
* throws. Ignored otherwise.
*/
damagesBreakdown?: {
/** General damages for pain, suffering and loss of amenity. */
general: number;
/** Past (pre-settlement) financial loss. */
pastLoss: number;
/**
* Future financial loss. It is never in a cap base. Printed in the cap
* sentence as excluded when above 0. Missing means 0.
*/
futureLoss?: number;
};
/**
* CFA base costs (hourly charges), before VAT, in major units. Required for
* `CFA`, where missing throws. Ignored otherwise.
*/
baseCosts?: number;
/**
* VAT on the solicitor's charges, as a percentage: 20. `DBA` and `CFA` only.
* Missing means 0, and no VAT row is printed.
*/
vatPercent?: number;
/**
* Counsel's fees, VAT included, in major units. `DBA` and `CFA` only. Under
* a DBA they are part of the capped payment. Missing means 0, and no row
* is printed.
*/
counselFees?: number;
/**
* Costs the opponent has paid or must pay, VAT included, in major units.
* `DBA` and `CFA` only. They are credited against what the client owes and
* never credited beyond it. Missing means 0, and no row is printed.
*/
recoverableCostsPaid?: number;
/**
* Case expenses and disbursements the client reimburses. Under a DBA they
* sit outside the cap. Each is printed as a row with its label as given.
* Missing or empty means none.
*/
expenses?: Array<{ label: string; amount: number }>;
/**
* Liens and subrogation claims paid from the recovery: medical, Medicare,
* health plan, workers' compensation, CRU. Missing or empty means none.
*/
liens?: Array<{
/** Who holds it, printed as given. Required, non-blank. */
holder: string;
/** The amount claimed, in major units. */
amount: number;
/**
* The amount actually payable after a negotiated or statutory reduction,
* such as Medicare's procurement-cost reduction or a hospital compromise.
* Used instead of `amount`, and the row says "reduced from <amount>".
* Throws when greater than `amount`. 0 is allowed (waived).
*/
reducedAmount?: number;
/**
* True only where the agreement or the lien statute says the lien comes
* off before the fee is worked out. It then reduces the fee base. Missing
* means false: paid from the client's share after the fee.
*/
beforeFee?: boolean;
/**
* True for benefits recoverable by the Compensation Recovery Unit. In a
* UK PI claim they are netted off past loss, never general damages, for
* the DBA and CFA caps. Missing means false.
*/
cru?: boolean;
}>;
/**
* The agreement's words on who carries a shortfall, printed verbatim after
* the shortfall sentence. Read only when there is a shortfall. Missing or
* empty there prints the "incomplete" warning instead.
*/
shortfallTerms?: string;
};
}
/**
* Prints the settlement table, the method sentence, and whichever of the
* other-base, cap and shortfall paragraphs apply.
*/
export const ContingencySettlementStatement: Nodes = async () => {
const [settlement] = useState((d: ContingencySettlementStatementData) => d.settlement);
const s = await useDeriver(contingencySettlementStatement, [settlement]);
return (
<Section id="contingency-settlement" title="Settlement statement">
<Table
id="contingency-settlement-table"
columns={[{ width: "auto" }, { width: 38, align: "right" }]}
>
<Row id="contingency-settlement-header" header>
<Cell>Item</Cell>
<Cell>Amount</Cell>
</Row>
<Row id="contingency-settlement-gross">
<Cell>Gross recovery</Cell>
<Cell>{s.gross}</Cell>
</Row>
{s.rows[0].label && (
<Row id="contingency-settlement-line-1">
<Cell>{s.rows[0].label}</Cell>
<Cell>{s.rows[0].amount}</Cell>
</Row>
)}
{s.rows[1].label && (
<Row id="contingency-settlement-line-2">
<Cell>{s.rows[1].label}</Cell>
<Cell>{s.rows[1].amount}</Cell>
</Row>
)}
{s.rows[2].label && (
<Row id="contingency-settlement-line-3">
<Cell>{s.rows[2].label}</Cell>
<Cell>{s.rows[2].amount}</Cell>
</Row>
)}
{s.rows[3].label && (
<Row id="contingency-settlement-line-4">
<Cell>{s.rows[3].label}</Cell>
<Cell>{s.rows[3].amount}</Cell>
</Row>
)}
{s.rows[4].label && (
<Row id="contingency-settlement-line-5">
<Cell>{s.rows[4].label}</Cell>
<Cell>{s.rows[4].amount}</Cell>
</Row>
)}
{s.rows[5].label && (
<Row id="contingency-settlement-line-6">
<Cell>{s.rows[5].label}</Cell>
<Cell>{s.rows[5].amount}</Cell>
</Row>
)}
{s.rows[6].label && (
<Row id="contingency-settlement-line-7">
<Cell>{s.rows[6].label}</Cell>
<Cell>{s.rows[6].amount}</Cell>
</Row>
)}
{s.rows[7].label && (
<Row id="contingency-settlement-line-8">
<Cell>{s.rows[7].label}</Cell>
<Cell>{s.rows[7].amount}</Cell>
</Row>
)}
{s.rows[8].label && (
<Row id="contingency-settlement-line-9">
<Cell>{s.rows[8].label}</Cell>
<Cell>{s.rows[8].amount}</Cell>
</Row>
)}
{s.rows[9].label && (
<Row id="contingency-settlement-line-10">
<Cell>{s.rows[9].label}</Cell>
<Cell>{s.rows[9].amount}</Cell>
</Row>
)}
{s.rows[10].label && (
<Row id="contingency-settlement-line-11">
<Cell>{s.rows[10].label}</Cell>
<Cell>{s.rows[10].amount}</Cell>
</Row>
)}
{s.rows[11].label && (
<Row id="contingency-settlement-line-12">
<Cell>{s.rows[11].label}</Cell>
<Cell>{s.rows[11].amount}</Cell>
</Row>
)}
{s.rows[12].label && (
<Row id="contingency-settlement-line-13">
<Cell>{s.rows[12].label}</Cell>
<Cell>{s.rows[12].amount}</Cell>
</Row>
)}
{s.rows[13].label && (
<Row id="contingency-settlement-line-14">
<Cell>{s.rows[13].label}</Cell>
<Cell>{s.rows[13].amount}</Cell>
</Row>
)}
{s.rows[14].label && (
<Row id="contingency-settlement-line-15">
<Cell>{s.rows[14].label}</Cell>
<Cell>{s.rows[14].amount}</Cell>
</Row>
)}
{s.rows[15].label && (
<Row id="contingency-settlement-line-16">
<Cell>{s.rows[15].label}</Cell>
<Cell>{s.rows[15].amount}</Cell>
</Row>
)}
<Row id="contingency-settlement-net">
<Cell>{s.netLabel}</Cell>
<Cell>{s.net}</Cell>
</Row>
</Table>
<Paragraph id="contingency-settlement-method">{s.method}</Paragraph>
{s.otherBase && <Paragraph id="contingency-settlement-other-base">{s.otherBase}</Paragraph>}
{s.cap && <Paragraph id="contingency-settlement-cap">{s.cap}</Paragraph>}
{s.outcome === "shortfall" && settlement.shortfallTerms && (
<Paragraph id="contingency-settlement-shortfall">
The recovery does not cover the fee, expenses and liens, which leaves a shortfall of {s.net}.{" "}
{settlement.shortfallTerms}
</Paragraph>
)}
{s.outcome === "shortfall" && !settlement.shortfallTerms && (
<Paragraph id="contingency-settlement-shortfall-incomplete">
Statement incomplete: the recovery does not cover the fee, expenses and liens, which leaves a shortfall of{" "}
{s.net}, and the agreement's terms on who carries a shortfall were not given. Add them before this statement
is sent.
</Paragraph>
)}
</Section>
);
}; derivers/contingency-settlement-statement.deriver.ts // deno-lint-ignore-file no-explicit-any
import { deriver } from "docxcelerate/template";
/**
* Works out a contingent or damages-based fee statement: every deduction in
* order, as signed amounts that sum to the net. Installed by
* `dxcl add contingency-settlement-statement`.
*
* 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 statutory table is declared inside `run`.
*/
export default deriver({
name: "contingencySettlementStatement",
run: (settlement: unknown) => {
const st = settlement as any;
const SLOTS = 16;
const STAGES = ["pre-suit", "filed", "trial", "appeal"];
// Currency first: the exponent decides how every amount is read and printed.
const currency = st?.currency;
let money: Intl.NumberFormat;
const locale = currency === "USD" ? "en-US" : "en-GB";
try {
// Intl accepts any three letters, so a code it does not know is checked separately.
if (typeof currency !== "string" || !(Intl as any).supportedValuesOf("currency").includes(currency)) {
throw new Error("unknown");
}
money = new Intl.NumberFormat(locale, { style: "currency", currency });
} catch {
throw new Error("settlement.currency must be an ISO 4217 code");
}
const exponent = money.resolvedOptions().maximumFractionDigits as number;
const unit = 10 ** exponent;
// A zero is never printed negative: Intl would write -$0.00.
const fmt = (minor: number) => money.format(minor === 0 ? 0 : minor / unit);
const pctFmt = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 });
const pct = (p: number) => pctFmt.format(p) + "%";
// Every computed figure is rounded once, half up, on a non-negative value.
const round = (x: number) => Math.round(x);
const amount = (value: unknown, field: string): number => {
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
throw new Error(field + " must be a finite amount of 0 or more");
}
return Math.round(value * unit);
};
const optAmount = (value: unknown, field: string) => value === undefined ? 0 : amount(value, field);
// ---- 1. Validate ----
if (st === null || typeof st !== "object") throw new Error("settlement is required");
const regime = st.regime;
if (regime !== "contingency" && regime !== "DBA" && regime !== "CFA") {
throw new Error('settlement.regime must be "contingency", "DBA" or "CFA"');
}
const uk = regime !== "contingency";
const gross = amount(st.grossRecovery, "settlement.grossRecovery");
const stage = st.stage;
if (stage !== undefined && !STAGES.includes(stage)) {
throw new Error("settlement.stage must be one of " + STAGES.join(", "));
}
if (!Array.isArray(st.schedule) || st.schedule.length === 0) {
throw new Error("settlement.schedule must have at least one row");
}
st.schedule.forEach((r: any, i: number) => {
const f = "settlement.schedule[" + i + "]";
if (r?.stage !== undefined && !STAGES.includes(r.stage)) throw new Error(f + ".stage is not a known stage");
if (typeof r?.percent !== "number" || !Number.isFinite(r.percent) || r.percent < 0 || r.percent > 100) {
throw new Error(f + ".percent must be between 0 and 100");
}
if (r.upTo !== undefined) {
if (regime === "CFA") throw new Error(f + ".upTo is not allowed for a CFA");
if (typeof r.upTo !== "number" || !Number.isFinite(r.upTo) || r.upTo <= 0) {
throw new Error(f + ".upTo must be a positive amount");
}
}
});
const base = st.base;
if (!uk || regime === "DBA") {
if (base !== "gross" && base !== "net") throw new Error('settlement.base must be "gross" or "net"');
}
const statutoryCap = st.statutoryCap;
if (statutoryCap !== undefined) {
if (regime !== "contingency") throw new Error("settlement.statutoryCap applies to a contingency fee only");
if (statutoryCap !== "ny-medical-malpractice" && statutoryCap !== "ca-medical-negligence") {
throw new Error("settlement.statutoryCap is not a known cap");
}
if (statutoryCap === "ca-medical-negligence" && stage === undefined) {
throw new Error("settlement.stage is required for the California cap");
}
}
const claimType = st.claimType;
let capBase = 0;
let capPct = 0;
let future = 0;
let personalInjury = false;
let general = 0;
let past = 0;
if (uk) {
if (claimType !== "personal-injury" && claimType !== "employment" && claimType !== "other") {
throw new Error('settlement.claimType must be "personal-injury", "employment" or "other"');
}
personalInjury = claimType === "personal-injury";
if (personalInjury) {
const d = st.damagesBreakdown;
if (d === null || typeof d !== "object") throw new Error("settlement.damagesBreakdown is required for a personal injury claim");
general = amount(d.general, "settlement.damagesBreakdown.general");
past = amount(d.pastLoss, "settlement.damagesBreakdown.pastLoss");
future = optAmount(d.futureLoss, "settlement.damagesBreakdown.futureLoss");
if (general + past > gross) {
throw new Error("settlement.damagesBreakdown: general plus pastLoss is above settlement.grossRecovery");
}
}
}
const baseCosts = regime === "CFA" ? amount(st.baseCosts, "settlement.baseCosts") : 0;
let vatPercent = 0;
if (uk && st.vatPercent !== undefined) {
if (typeof st.vatPercent !== "number" || !Number.isFinite(st.vatPercent) || st.vatPercent < 0) {
throw new Error("settlement.vatPercent must be a finite percentage of 0 or more");
}
vatPercent = st.vatPercent;
}
const counsel = uk ? optAmount(st.counselFees, "settlement.counselFees") : 0;
const recoverable = uk ? optAmount(st.recoverableCostsPaid, "settlement.recoverableCostsPaid") : 0;
const expenses: Array<{ label: string; minor: number }> = [];
if (st.expenses !== undefined && !Array.isArray(st.expenses)) throw new Error("settlement.expenses must be a list");
(st.expenses ?? []).forEach((e: any, i: number) => {
const f = "settlement.expenses[" + i + "]";
if (typeof e?.label !== "string" || e.label.trim() === "") throw new Error(f + ".label is required");
expenses.push({ label: e.label, minor: amount(e.amount, f + ".amount") });
});
const liens: Array<{ holder: string; amount: number; payable: number; reduced: boolean; before: boolean; cru: boolean }> = [];
if (st.liens !== undefined && !Array.isArray(st.liens)) throw new Error("settlement.liens must be a list");
(st.liens ?? []).forEach((l: any, i: number) => {
const f = "settlement.liens[" + i + "]";
if (typeof l?.holder !== "string" || l.holder.trim() === "") throw new Error(f + ".holder is required");
const a = amount(l.amount, f + ".amount");
const reduced = l.reducedAmount !== undefined;
const payable = reduced ? amount(l.reducedAmount, f + ".reducedAmount") : a;
if (payable > a) throw new Error(f + ".reducedAmount must not be greater than amount");
liens.push({ holder: l.holder, amount: a, payable, reduced, before: l.beforeFee === true, cru: l.cru === true });
});
// ---- 2. Totals ----
const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0);
const E = sum(expenses.map((e) => e.minor));
const Lb = sum(liens.filter((l) => l.before).map((l) => l.payable));
const cruTotal = sum(liens.filter((l) => l.cru).map((l) => l.payable));
// ---- 5. Schedule selection ----
if (stage === undefined && st.schedule.some((r: any) => r.stage !== undefined)) {
throw new Error("settlement.stage is required when settlement.schedule names a stage");
}
let rows5 = st.schedule.filter((r: any) => stage !== undefined && r.stage === stage);
if (rows5.length === 0) rows5 = st.schedule.filter((r: any) => r.stage === undefined);
if (rows5.length === 0) throw new Error('no rate in settlement.schedule for stage "' + stage + '"');
const stageWords: Record<string, string> = {
"pre-suit": "before suit was filed",
filed: "after filing",
trial: "at trial",
appeal: "on appeal",
};
const stagePhrase = stage === undefined ? "" : stageWords[stage];
let uplift = 0;
let bandRows: Array<{ top: number; percent: number }> = [];
if (regime === "CFA") {
if (rows5.length !== 1) throw new Error("settlement.schedule must give one uplift for a CFA");
uplift = rows5[0].percent;
} else {
if (rows5.filter((r: any) => r.upTo === undefined).length !== 1) {
throw new Error("settlement.schedule must have exactly one open band (no upTo)");
}
bandRows = rows5.map((r: any) => ({
top: r.upTo === undefined ? Infinity : Math.round(r.upTo * unit),
percent: r.percent,
}));
bandRows.sort((a, b) => a.top - b.top);
for (let i = 1; i < bandRows.length; i++) {
if (bandRows[i].top === bandRows[i - 1].top) throw new Error("settlement.schedule has two bands with the same upTo");
}
}
// ---- 6. Band charge ----
const bandsOf = (x: number, table: Array<{ top: number; percent: number }>) => {
let prev = 0;
let total = 0;
const reached: Array<{ prev: number; top: number; portion: number; percent: number; charge: number }> = [];
for (const band of table) {
const portion = Math.min(Math.max(x, prev), band.top) - prev;
const charge = round(portion * band.percent / 100);
total += charge;
reached.push({ prev, top: band.top, portion, percent: band.percent, charge });
if (x <= band.top) break;
prev = band.top;
}
return { total, reached };
};
// ---- 3. Fee base ----
const baseOf = (b: string) => Math.max(0, gross - (b === "net" ? E : 0) - Lb);
const B = regime === "CFA" ? 0 : baseOf(base);
// ---- 7. Regime ----
const out: Array<{ label: string; minor: number }> = [];
const push = (label: string, minor: number) => out.push({ label, minor });
const lienLabel = (l: (typeof liens)[number]) => l.reduced ? " (reduced from " + fmt(l.amount) + ")" : "";
if (regime !== "CFA" && base === "net") expenses.forEach((e) => push(e.label, -e.minor));
liens.filter((l) => l.before).forEach((l) => push(l.holder + ", paid before the fee" + lienLabel(l), -l.payable));
let capText = "";
let feeMinor = 0;
let otherBase = "";
const NY = [
{ top: 250000, percent: 30 },
{ top: 500000, percent: 25 },
{ top: 1000000, percent: 20 },
{ top: 1250000, percent: 15 },
{ top: Infinity, percent: 10 },
].map((b) => ({ top: b.top * unit, percent: b.percent }));
const S = Math.max(0, gross - E);
let statutory: number | undefined;
if (statutoryCap === "ny-medical-malpractice") statutory = bandsOf(S, NY).total;
if (statutoryCap === "ca-medical-negligence") statutory = round(S * (stage === "pre-suit" ? 25 : 33) / 100);
const bandInfo = bandsOf(B, bandRows);
let vat = 0;
// The charge of a regime on a given base, so `otherBase` can ask the same question again.
let dbaCap = 0;
const dbaCharge = (agreed: number) => {
const v = round(agreed * vatPercent / 100);
const payment = agreed + v + counsel;
return { vat: v, payment, charged: Math.min(payment, dbaCap) };
};
let actual = 0;
if (regime === "contingency") {
const agreed = bandInfo.total;
const fee = Math.min(agreed, statutory ?? agreed);
actual = fee;
feeMinor = fee;
push(statutory !== undefined && statutory < agreed ? "Contingent fee (statutory maximum)" : "Contingent fee", -fee);
if (statutoryCap === "ny-medical-malpractice") {
capText = "New York Judiciary Law § 474-a limits the fee in a medical malpractice action to " + fmt(statutory!) +
", worked out on the recovery after expenses (" + fmt(S) +
"): 30% of the first $250,000, 25% of the next $250,000, 20% of the next $500,000, 15% of the next $250,000 and 10% above $1,250,000.";
} else if (statutoryCap === "ca-medical-negligence") {
capText =
"California Business and Professions Code § 6146 limits the fee in a medical negligence action to 25% of the recovery after expenses if the case settles before a complaint or demand for arbitration is filed, and 33% after. This case " +
(stage === "pre-suit" ? "settled before filing" : "was filed") + ", so the limit is " + fmt(statutory!) + ".";
}
if (capText) {
capText += agreed <= statutory!
? " The agreement's fee of " + fmt(agreed) + " is within that limit, so it is charged."
: " The agreement's fee of " + fmt(agreed) + " is above it, so the statutory maximum is charged.";
}
} else if (regime === "DBA") {
if (claimType === "personal-injury") {
capBase = general + Math.max(0, past - cruTotal);
capPct = 25;
} else {
capBase = gross;
capPct = claimType === "employment" ? 35 : 50;
}
dbaCap = round(capBase * capPct / 100);
const agreed = bandInfo.total;
const d = dbaCharge(agreed);
vat = d.vat;
const credit = Math.min(recoverable, d.charged);
actual = d.charged;
feeMinor = d.charged - credit;
push("Payment under the agreement", -agreed);
if (vat > 0) push("VAT at " + pct(vatPercent) + " on the payment", -vat);
if (counsel > 0) push("Counsel's fees", -counsel);
if (d.payment - d.charged > 0) push("Reduced to the statutory maximum", d.payment - d.charged);
if (credit > 0) push("Costs paid by the other side, credited", credit);
const what = claimType === "personal-injury"
? "25% of general damages and past losses net of sums recoverable by the CRU (" + fmt(capBase) + ")" +
(future > 0 ? "; future loss of " + fmt(future) + " is excluded" : "")
: pct(capPct) + " of the sums recovered (" + fmt(capBase) + ")";
capText = "The Damages-Based Agreements Regulations 2013 limit the payment, including VAT and counsel's fees, to " +
what + ", which is " + fmt(dbaCap) + "." +
(d.payment <= dbaCap
? " The payment of " + fmt(d.payment) + " is within it."
: " The payment of " + fmt(d.payment) + " is above it, so it is reduced to " + fmt(dbaCap) + ".");
} else {
const sfFee = round(baseCosts * uplift / 100);
let cfaCap: number | undefined;
if (claimType === "personal-injury") {
capBase = general + Math.max(0, past - cruTotal);
// Before VAT: CFA Order 2013 art. 5 does not say "including VAT", unlike DBA reg 4(2).
cfaCap = round(capBase * 25 / 100);
}
const sfCharged = Math.min(sfFee, cfaCap ?? sfFee);
const baseVat = round(baseCosts * vatPercent / 100);
vat = baseVat + round(sfCharged * vatPercent / 100);
// The success fee is not recoverable from the opponent, so costs never offset it.
const credit = Math.min(recoverable, baseCosts + baseVat + counsel);
feeMinor = baseCosts + sfCharged + vat + counsel - credit;
push("Base costs", -baseCosts);
push("Success fee (" + pct(uplift) + " of base costs)", -sfFee);
if (sfFee - sfCharged > 0) push("Success fee reduced to the statutory maximum", sfFee - sfCharged);
if (vat > 0) push("VAT at " + pct(vatPercent), -vat);
if (counsel > 0) push("Counsel's fees", -counsel);
if (credit > 0) push("Costs paid by the other side, credited", credit);
if (cfaCap !== undefined) {
capText = "The Conditional Fee Agreements Order 2013 limits the success fee to 25% of general damages and past losses net of sums recoverable by the CRU (" +
fmt(capBase) + "), which is " + fmt(cfaCap) + "." +
(sfFee <= cfaCap
? " The success fee of " + fmt(sfFee) + " is within it."
: " The success fee of " + fmt(sfFee) + " is above it, so it is reduced to " + fmt(cfaCap) + ".");
}
}
// ---- 8. After the fee ----
if (regime === "CFA" || base === "gross") expenses.forEach((e) => push(e.label, -e.minor));
liens.filter((l) => !l.before).forEach((l) => push(l.holder + lienLabel(l), -l.payable));
// ---- 9. Slots ----
if (out.length > SLOTS) {
throw new Error("contingencySettlementStatement: " + out.length + " lines; this component prints at most " + SLOTS);
}
const rows = out.map((r) => ({ label: r.label, amount: fmt(r.minor) }));
while (rows.length < SLOTS) rows.push({ label: "", amount: "" });
// ---- 10. Net ----
const netMinor = gross + sum(out.map((r) => r.minor));
const shortfall = netMinor < 0;
// ---- 11. Method ----
const baseName = (b: string) => (b === "net" ? "the recovery after expenses" : "the gross recovery") +
(Lb > 0 ? " and the liens paid before the fee" : "");
let method: string;
if (regime === "CFA") {
method = "The success fee is " + pct(uplift) + " of base costs of " + fmt(baseCosts) +
(stagePhrase ? ", the rate the agreement sets " + stagePhrase : "") + ".";
} else if (B === 0) {
method = "There is nothing to work the fee out on, so no fee is charged.";
} else {
const noun = regime === "DBA" ? "payment" : "fee";
const tail = regime === "DBA"
? (vat > 0 && counsel > 0 ? ", plus VAT and counsel's fees" : vat > 0 ? ", plus VAT" : counsel > 0 ? ", plus counsel's fees" : "")
: "";
const reached = bandInfo.reached;
const on = baseName(base) + " (" + fmt(B) + ")";
if (reached.length === 1) {
method = "The " + noun + " is " + pct(reached[0].percent) + " of " + on +
(stagePhrase ? ", the rate the agreement sets " + stagePhrase : "") + tail + ".";
} else {
const parts = reached.map((b, i) => {
const last = i === reached.length - 1;
const where = i === 0
? "the first " + fmt(b.portion)
: !last
? "the next " + fmt(b.portion)
: b.top === Infinity
? "the amount above " + fmt(b.prev)
: "the remaining " + fmt(b.portion);
return pct(b.percent) + " of " + where + " (" + fmt(b.charge) + ")";
});
method = "The " + noun + " is worked out band by band on " + on +
(stagePhrase ? ", at the rates the agreement sets " + stagePhrase : "") + ": " +
parts.slice(0, -1).join(", ") + " and " + parts[parts.length - 1] + tail + ".";
}
}
// ---- 12. Other base ----
if (regime !== "CFA" && E > 0) {
const other = base === "net" ? "gross" : "net";
const agreed = bandsOf(baseOf(other), bandRows).total;
const alt = regime === "DBA" ? dbaCharge(agreed).charged : Math.min(agreed, statutory ?? agreed);
if (alt !== actual) {
otherBase = "Worked out on " + (other === "gross" ? "the gross recovery" : "the recovery after expenses") +
" instead, the " + (regime === "DBA" ? "payment" : "fee") + " would have been " + fmt(alt) + ".";
}
}
return {
gross: fmt(gross),
rows,
netLabel: shortfall ? "Shortfall" : "Net to you",
net: fmt(Math.abs(netMinor)),
outcome: shortfall ? "shortfall" : "remittance",
method,
otherBase,
cap: capText,
feeMinor,
netMinor,
};
},
});