Royalty earnings by format
BodyEscalator tiers are counted on life-to-date copies, so a period that crosses a threshold is split into two lines at the copy where the rate changes, never paid at one rate. Each format is priced on its own basis, list price or net receipts. A high-discount sale earns a fraction of the rate, or the full rate on net receipts where the contract switches the base. Returns are charged at the highest rate reached and never pull the life-to-date count back below a tier. Subsidiary-rights income is shared after the licensee's withholding tax, which is shown once and not deducted again. Each line is rounded once in minor units and the total is the sum of the lines, the way a publisher's ledger adds up. A tier list that does not ascend, or a format with no basis, fails the document. All of it is one deriver.
npx dxcl add royalty-earnings-by-format Datos de vista previa
el JSON con el que se construyó esta vista previa{
"royalty": {
"currency": "GBP",
"highDiscount": {
"thresholdPercent": 55,
"treatment": "fraction",
"fraction": {
"numerator": 4,
"denominator": 5
},
"deeper": [
{
"thresholdPercent": 62.5,
"numerator": 3,
"denominator": 5
}
]
},
"formats": [
{
"format": "hardback",
"label": "Hardback (slipcased collector's edition with illustrated endpapers)",
"basis": "list",
"listPriceMinor": 2500,
"tiers": [
{
"fromUnit": 1,
"percent": 10
},
{
"fromUnit": 2501,
"percent": 12.5
},
{
"fromUnit": 5001,
"percent": 15
}
],
"lifeToDateUnitsBefore": 1850,
"sales": [
{
"units": 2400,
"discountPercent": 45
},
{
"units": 38600,
"discountPercent": 52
},
{
"units": 9200,
"discountPercent": 60
}
],
"returns": {
"units": 3150
}
},
{
"format": "paperback",
"label": "B-format paperback (export and open market edition)",
"basis": "list",
"listPriceMinor": 1099,
"tiers": [
{
"fromUnit": 1,
"percent": 7.5
},
{
"fromUnit": 150001,
"percent": 10
}
],
"lifeToDateUnitsBefore": 112480,
"sales": [
{
"units": 184300,
"discountPercent": 50
},
{
"units": 41900,
"discountPercent": 63
}
],
"returns": {
"units": 22750
}
},
{
"format": "ebook",
"basis": "net",
"tiers": [
{
"fromUnit": 1,
"percent": 25
}
],
"lifeToDateUnitsBefore": 63210,
"sales": [
{
"units": 58420,
"netReceiptsMinor": 23368000
}
]
},
{
"format": "audio",
"label": "Unabridged audiobook (download and streaming)",
"basis": "net",
"tiers": [
{
"fromUnit": 1,
"percent": 25
}
],
"lifeToDateUnitsBefore": 9400,
"sales": [
{
"units": 21800,
"netReceiptsMinor": 9810000
}
],
"returns": {
"units": 140,
"netReceiptsMinor": 63000
}
}
],
"subRights": [
{
"right": "Spanish-language translation (Latin America)",
"licensee": "Editorial Planeta Mexicana S.A. de C.V.",
"grossMinor": 4500000,
"foreignTaxWithheldMinor": 1125000,
"authorSharePercent": 80
},
{
"right": "First serial rights",
"licensee": "Guardian News & Media Limited",
"grossMinor": 1800000,
"authorSharePercent": 90
}
]
}
} Vista previa renderizada
el componente renderizado por su cuentaNodos resueltos
lo que recibe un renderizador — 1 nodosroyalty-earnings section Los archivos
lo que escribe la instalación; el archivo seleccionado es el componentenodes/royalty-earnings-by-format.node.tsx import { Cell, type Nodes, Paragraph, Row, Section, Table, useDeriver, useState } from "docxcelerate/template";
import royaltyEarningsByFormat from "../derivers/royalty-earnings-by-format.deriver.ts";
/**
* An author's royalty statement section: one period's unit sales, returns and
* subsidiary-rights income as royalty lines, one per format, escalator tier and
* discount band, then the period's total.
*
* Decisions already made for you:
*
* - Escalators count life-to-date copies, not the period's. A period that
* crosses a threshold is split into two lines at the copy where the rate
* changes, never paid at one rate.
* - Each format has its own basis: list price or net receipts.
* - High discount is the contract's choice, not ours. A list-price sale at or
* above the threshold earns a fraction of the tier rate, or the full rate on
* net receipts. It never earns a fraction of a list-price royalty when the
* contract switches the base.
* - Returns are charged at the highest rate reached so far, and never pull the
* life-to-date count back below a tier.
* - Subsidiary income is shared on the money actually received, after foreign
* withholding tax. The tax gets a row of its own and is not deducted again.
* - Each line is rounded once to the minor unit, and the total is the sum of the
* rounded lines, the way a publisher's ledger adds up. That can differ by a
* penny from rounding the exact sum.
*
* All of it is decided in one deriver, because every step does arithmetic or
* sorting on request data, and publishing refuses both. The node computes
* nothing: it reads the deriver's result and branches on it, with every test
* written inline so a publish build keeps each arm.
*
* Installed by `dxcl add royalty-earnings-by-format`.
*/
/** What this component reads. Add these fields to your document data type. */
export interface RoyaltyEarningsData {
royalty: {
/**
* ISO 4217 code every amount is in: `"GBP"`, `"USD"`, `"JPY"`. It also sets
* how many minor units make one major unit. Required: the deriver throws
* when it is missing or not a code `Intl` knows.
*/
currency: string;
/**
* One entry per format the contract pays on, in the order they should be
* printed. Two entries may share a `format` (a home and an export edition);
* give each a `label` so their lines can be told apart. Missing or empty
* means no format lines.
*/
formats?: Array<{
/**
* Which format this is. It names the line when `label` is missing:
* "Hardback", "Paperback", "Ebook", "Audiobook". Required: anything else
* throws.
*/
format: "hardback" | "paperback" | "ebook" | "audio";
/** The format's name as printed: `"Trade paperback (export)"`. Missing means the name above. */
label?: string;
/**
* What the royalty percentage is taken of. `"list"` is the recommended
* retail price per copy. `"net"` is what the publisher actually received.
* Required: a format with no basis throws, because guessing one gets
* every line wrong.
*/
basis: "list" | "net";
/**
* List price of one copy, in minor units (`2500` for £25.00). Required
* when `basis` is `"list"`, and throws without it. When `basis` is
* `"net"`, it is read only to work out net receipts for a sale that does
* not give them.
*/
listPriceMinor?: number;
/**
* The escalator. Each tier starts at a life-to-date copy number:
* `[{ fromUnit: 1, percent: 10 }, { fromUnit: 2501, percent: 12.5 }]`
* pays 10% on copies 1 to 2,500 and 12.5% from copy 2,501. The first tier
* must start at 1, and `fromUnit` must strictly ascend. The percent is
* 0 to 100 with at most two decimals. Anything else throws. Required and
* non-empty.
*/
tiers: Array<{ fromUnit: number; percent: number }>;
/**
* Copies sold on all earlier statements, before this period. Returns are
* never subtracted from it. Required, even when it is 0: a missing count
* would silently pay the first tier's rate, which is the exact mistake
* this component exists to prevent. Throws when it is not a non-negative
* integer.
*/
lifeToDateUnitsBefore: number;
/**
* This period's sales, in ledger order. When a threshold is crossed, the
* earlier rows fill the lower tier first. Missing or empty means none.
*/
sales?: Array<{
/** Copies sold. Non-negative integer, else throws. 0 is skipped. */
units: number;
/**
* Trade discount off list, 0 to 100. Missing means 0. It only decides
* the high-discount band, and only on a `"list"` format.
*/
discountPercent?: number;
/**
* What the publisher received for this whole row, in minor units. Used
* by a `"net"` format, and by a list-price sale that high discount has
* switched to net receipts. Missing means it is worked out as
* units × listPriceMinor × (100 − discountPercent) / 100. When both
* this and `listPriceMinor` are missing where it is needed, the deriver
* throws.
*/
netReceiptsMinor?: number;
}>;
/** Copies returned this period. Missing means none. */
returns?: {
/**
* A positive count: 120 returned copies is `120`. A negative value
* throws, because a sign applied by both the data and the component
* turns a debit into a credit. 0 prints nothing.
*/
units: number;
/**
* Net receipts credited back for those copies, in minor units.
* Required when `basis` is `"net"` and `units` is above 0, and throws
* without it. Ignored on a `"list"` format.
*/
netReceiptsMinor?: number;
};
}>;
/**
* The contract's high-discount clause, applied to `"list"` formats only.
* A net-receipts royalty already reflects the discount. Missing means the
* contract has no clause, and every sale earns the full tier rate.
*/
highDiscount?: {
/** The discount at or above which a sale is high-discount. Missing means 55. */
thresholdPercent?: number;
/**
* `"fraction"`: the tier rate times `fraction`, on list price.
* `"net"`: the full tier rate, on net receipts instead of list price.
* Missing means `"fraction"`.
*/
treatment?: "fraction" | "net";
/**
* For `"fraction"`. Missing means 4/5. `numerator` and `denominator`
* must be positive integers with numerator ≤ denominator, else throws.
*/
fraction?: { numerator: number; denominator: number };
/**
* Deeper steps for `"fraction"`, such as
* `[{ thresholdPercent: 62.5, numerator: 3, denominator: 5 }]`. The
* thresholds must strictly ascend from `thresholdPercent`, else throws.
* The deepest step a sale reaches applies. Ignored for `"net"`.
*/
deeper?: Array<{ thresholdPercent: number; numerator: number; denominator: number }>;
};
/**
* Income from rights the publisher sold on (translation, audio, serial),
* in the order they should be printed. Missing or empty means none.
*/
subRights?: Array<{
/** What was licensed, as printed: `"Spanish translation"`. Required, non-blank. */
right: string;
/** Who licensed it, as printed. Required, non-blank. */
licensee: string;
/**
* The licence fee before any withholding, in minor units. This is the
* amount the contract names, not the amount that reached the bank.
* Required, non-negative integer.
*/
grossMinor: number;
/**
* Foreign tax the licensee withheld from `grossMinor`, in minor units.
* Missing means 0. It throws when it exceeds `grossMinor`.
*/
foreignTaxWithheldMinor?: number;
/** The author's contractual share, 0 to 100 with at most two decimals: `50`, `80`. Required. */
authorSharePercent: number;
}>;
};
}
/**
* Prints the royalty lines for each format and sold right, then the total, and
* says so plainly when returns made it a debit. Always returns the section.
*/
export const RoyaltyEarningsByFormat: Nodes = async () => {
const [royalty] = useState((data: RoyaltyEarningsData) => data.royalty);
const p = await useDeriver(royaltyEarningsByFormat, [royalty]);
return (
<Section id="royalty-earnings" title="Royalties earned this period">
{p.outcome === "none" && (
<Paragraph id="royalty-earnings-none">
No copies were sold or returned, and no subsidiary income was received, in this period.
</Paragraph>
)}
{p.outcome === "lines" && (
<Table
id="royalty-earnings-lines"
columns={[
{ width: "auto" },
{ width: 22, align: "right" },
{ width: 34, align: "right" },
{ width: 26, align: "right" },
{ width: 28, align: "right" },
]}
>
<Row id="royalty-earnings-lines-header" header>
<Cell>Description</Cell>
<Cell>Copies</Cell>
<Cell>Basis</Cell>
<Cell>Rate</Cell>
<Cell>Royalty</Cell>
</Row>
{p.lines.map((line) => (
<Row id="royalty-earnings-line">
<Cell>{line.description}</Cell>
<Cell>{line.units}</Cell>
<Cell>{line.basis}</Cell>
<Cell>{line.rate}</Cell>
<Cell>{line.amount}</Cell>
</Row>
))}
<Row id="royalty-earnings-total">
<Cell>Total royalties this period</Cell>
<Cell></Cell>
<Cell></Cell>
<Cell></Cell>
<Cell>{p.total}</Cell>
</Row>
</Table>
)}
{p.hasMemo && (
<Paragraph id="royalty-earnings-tax-note">
Foreign tax rows are shown for your records. The tax was withheld before your share was calculated, so it is
not deducted again.
</Paragraph>
)}
{p.negative && (
<Paragraph id="royalty-earnings-debit">
Returns this period exceeded earnings, so this statement shows a debit of {p.totalAbs}.
</Paragraph>
)}
{p.lifeToDate && (
<Paragraph id="royalty-earnings-life-to-date">Copies sold to date, before returns: {p.lifeToDate}.</Paragraph>
)}
</Section>
);
}; derivers/royalty-earnings-by-format.deriver.ts // deno-lint-ignore-file no-explicit-any
import { deriver } from "docxcelerate/template";
/**
* Turns one period's sales, returns and subsidiary-rights income into royalty
* lines and their total. Installed by `dxcl add royalty-earnings-by-format`.
*
* 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 is declared inside `run`.
*/
export default deriver({
name: "royaltyEarningsByFormat",
run: (royaltyInput: unknown) => {
const royalty = royaltyInput as any;
const currency = royalty?.currency;
let money: Intl.NumberFormat;
try {
money = new Intl.NumberFormat("en-GB", { style: "currency", currency });
} catch {
throw new Error("royalty.currency must be an ISO 4217 code");
}
const exponent = money.resolvedOptions().maximumFractionDigits as number;
const fmtMoney = (minor: number) => money.format(minor / 10 ** exponent);
const counts = new Intl.NumberFormat("en-GB");
const nonNegInt = (v: unknown, field: string): number => {
if (typeof v !== "number" || !Number.isInteger(v) || v < 0) {
throw new Error(field + " must be a non-negative integer");
}
return v;
};
const posInt = (v: unknown, field: string): number => {
if (typeof v !== "number" || !Number.isInteger(v) || v < 1) {
throw new Error(field + " must be a positive integer");
}
return v;
};
// Basis points, so no percentage is ever carried as a float.
const toBp = (v: unknown, field: string): number => {
if (typeof v !== "number" || !Number.isFinite(v) || v < 0 || v > 100) {
throw new Error(field + " must be a percentage from 0 to 100");
}
const bp = Math.round(v * 100);
if (Math.abs(v * 100 - bp) > 1e-9) throw new Error(field + " must have at most two decimals");
return bp;
};
const pct = (bp: number) => String(bp / 100) + "%";
// Exact rationals; each line is rounded once, at the end.
type Q = { n: bigint; d: bigint };
const gcd = (a: bigint, b: bigint): bigint => {
a = a < 0n ? -a : a;
b = b < 0n ? -b : b;
while (b) [a, b] = [b, a % b];
return a;
};
const q = (n: bigint, d: bigint): Q => {
const g = gcd(n, d) || 1n;
return { n: n / g, d: d / g };
};
const add = (a: Q, b: Q): Q => q(a.n * b.d + b.n * a.d, a.d * b.d);
const roundHalfAway = (v: Q): number => {
const abs = v.n < 0n ? -v.n : v.n;
const out = (2n * abs + v.d) / (2n * v.d);
return Number(v.n < 0n ? -out : out);
};
// The high-discount clause, validated whether or not anything sells.
const hd = royalty.highDiscount;
const treatment: "fraction" | "net" = hd?.treatment ?? "fraction";
if (hd && treatment !== "fraction" && treatment !== "net") {
throw new Error('royalty.highDiscount.treatment must be "fraction" or "net"');
}
const steps: Array<{ bp: number; num: number; den: number }> = [];
if (hd) {
const stepOf = (t: unknown, num: unknown, den: unknown, field: string) => {
const n = posInt(num, field + ".numerator");
const d = posInt(den, field + ".denominator");
if (n > d) throw new Error(field + ".numerator must not exceed its denominator");
return { bp: toBp(t, field + ".thresholdPercent"), num: n, den: d };
};
steps.push(stepOf(hd.thresholdPercent ?? 55, hd.fraction?.numerator ?? 4, hd.fraction?.denominator ?? 5, "royalty.highDiscount" + (hd.fraction ? ".fraction" : "")));
if (treatment === "fraction") {
(Array.isArray(hd.deeper) ? hd.deeper : []).forEach((s: any, i: number) => {
const step = stepOf(s?.thresholdPercent, s?.numerator, s?.denominator, "royalty.highDiscount.deeper[" + i + "]");
if (step.bp <= steps[steps.length - 1].bp) {
throw new Error("royalty.highDiscount.deeper[" + i + "].thresholdPercent must ascend");
}
steps.push(step);
});
}
}
const names: any = { hardback: "Hardback", paperback: "Paperback", ebook: "Ebook", audio: "Audiobook" };
const rawFormats: any[] = royalty.formats === undefined || royalty.formats === null ? [] : royalty.formats;
if (!Array.isArray(rawFormats)) throw new Error("royalty.formats must be an array");
type Line = {
description: string;
units: string;
basis: string;
rate: string;
amount: string;
memo: boolean;
amountMinor: number;
};
const lines: Line[] = [];
const lifeToDate: string[] = [];
rawFormats.forEach((f: any, fi: number) => {
const at = "royalty.formats[" + fi + "]";
if (!Object.prototype.hasOwnProperty.call(names, f?.format)) {
throw new Error(at + '.format must be "hardback", "paperback", "ebook" or "audio"');
}
const name: string = typeof f.label === "string" && f.label !== "" ? f.label : names[f.format];
if (f.basis !== "list" && f.basis !== "net") throw new Error(at + '.basis must be "list" or "net"');
const isList = f.basis === "list";
const list: number | undefined = f.listPriceMinor === undefined
? undefined
: nonNegInt(f.listPriceMinor, at + ".listPriceMinor");
if (isList && list === undefined) throw new Error(at + ".listPriceMinor is required on a list basis");
if (!Array.isArray(f.tiers) || f.tiers.length === 0) throw new Error(at + ".tiers must be a non-empty array");
const tiers = f.tiers.map((t: any, i: number) => ({
from: posInt(t?.fromUnit, at + ".tiers[" + i + "].fromUnit"),
bp: toBp(t?.percent, at + ".tiers[" + i + "].percent"),
}));
if (tiers[0].from !== 1) throw new Error(at + ".tiers[0].fromUnit must be 1");
tiers.forEach((t: any, i: number) => {
if (i > 0 && t.from <= tiers[i - 1].from) throw new Error(at + ".tiers[" + i + "].fromUnit must ascend");
});
const tierAt = (copy: number) => {
let k = 0;
tiers.forEach((t: any, i: number) => {
if (t.from <= copy) k = i;
});
return k;
};
const before = nonNegInt(f.lifeToDateUnitsBefore, at + ".lifeToDateUnitsBefore");
const rawSales: any[] = f.sales === undefined || f.sales === null ? [] : f.sales;
if (!Array.isArray(rawSales)) throw new Error(at + ".sales must be an array");
const sales = rawSales.map((s: any, i: number) => {
const sf = at + ".sales[" + i + "]";
const units = nonNegInt(s?.units, sf + ".units");
const disc = s.discountPercent === undefined ? 0 : toBp(s.discountPercent, sf + ".discountPercent");
const given = s.netReceiptsMinor === undefined ? undefined : nonNegInt(s.netReceiptsMinor, sf + ".netReceiptsMinor");
return { units, disc, given, sf };
});
// Walk the sales, splitting each row where a tier boundary falls inside it.
const groups = new Map<number, { tier: number; band: number; royalty: Q; receipts: Q; units: number }>();
let c = before;
for (const s of sales) {
if (s.units === 0) continue;
// Band: -1 full, 0..n a fraction step, 1000 the net switch.
let band = -1;
if (isList && hd) {
steps.forEach((st, k) => {
if (s.disc >= st.bp) band = treatment === "net" ? 1000 : k;
});
}
const onNet = !isList || band === 1000;
let rowReceipts: Q = q(0n, 1n);
if (onNet) {
if (s.given !== undefined) rowReceipts = q(BigInt(s.given), 1n);
else if (list !== undefined) rowReceipts = q(BigInt(s.units) * BigInt(list) * BigInt(10000 - s.disc), 10000n);
else throw new Error(s.sf + ".netReceiptsMinor is required when the format has no listPriceMinor");
}
let pos = c + 1;
const last = c + s.units;
while (pos <= last) {
const ti = tierAt(pos);
const end = ti === tiers.length - 1 ? last : Math.min(last, tiers[ti + 1].from - 1);
const cu = BigInt(end - pos + 1);
const bp = BigInt(tiers[ti].bp);
let royaltyQ: Q;
let receiptsQ: Q = q(0n, 1n);
if (onNet) {
receiptsQ = q(rowReceipts.n * cu, rowReceipts.d * BigInt(s.units));
royaltyQ = q(receiptsQ.n * bp, receiptsQ.d * 10000n);
} else {
const num = band >= 0 ? BigInt(steps[band].num) : 1n;
const den = band >= 0 ? BigInt(steps[band].den) : 1n;
royaltyQ = q(cu * BigInt(list as number) * bp * num, 10000n * den);
}
const key = ti * 100000 + band + 1;
const g = groups.get(key) ?? { tier: ti, band, royalty: q(0n, 1n), receipts: q(0n, 1n), units: 0 };
g.royalty = add(g.royalty, royaltyQ);
g.receipts = add(g.receipts, receiptsQ);
g.units += end - pos + 1;
groups.set(key, g);
pos = end + 1;
}
c += s.units;
}
const after = c;
lifeToDate.push(name + " " + counts.format(after));
const sorted = [...groups.entries()].sort((a, b) => a[0] - b[0]).map((e) => e[1]);
for (const g of sorted) {
const t = tiers[g.tier];
const range = g.tier === tiers.length - 1
? "copies " + counts.format(t.from) + " and over"
: "copies " + counts.format(t.from) + "–" + counts.format(tiers[g.tier + 1].from - 1);
const high = g.band >= 0 && g.band !== 1000 ? steps[g.band] : g.band === 1000 ? steps[0] : undefined;
const minor = roundHalfAway(g.royalty);
lines.push({
description: name + ": " + range + (high ? ", high discount (" + String(high.bp / 100) + "% or more)" : ""),
units: counts.format(g.units),
basis: !isList || g.band === 1000
? fmtMoney(roundHalfAway(g.receipts)) + " net receipts"
: fmtMoney(list as number) + " list",
rate: g.band === 1000
? pct(t.bp) + " of net"
: g.band >= 0
? steps[g.band].num + "/" + steps[g.band].den + " of " + pct(t.bp)
: pct(t.bp),
amount: fmtMoney(minor),
memo: false,
amountMinor: minor,
});
}
// Returns: charged at the top tier reached, never reduced by high discount.
const ret = f.returns;
if (ret !== undefined && ret !== null) {
const ru = nonNegInt(ret.units, at + ".returns.units");
if (ru > 0) {
const t = tiers[after === 0 ? 0 : tierAt(after)];
let exact: Q;
let basis: string;
if (isList) {
exact = q(-BigInt(ru) * BigInt(list as number) * BigInt(t.bp), 10000n);
basis = fmtMoney(list as number) + " list";
} else {
const rr = nonNegInt(ret.netReceiptsMinor, at + ".returns.netReceiptsMinor");
exact = q(-BigInt(rr) * BigInt(t.bp), 10000n);
basis = fmtMoney(rr) + " net receipts";
}
const minor = roundHalfAway(exact);
lines.push({
description: name + ": returns",
units: counts.format(-ru),
basis,
rate: pct(t.bp),
amount: fmtMoney(minor),
memo: false,
amountMinor: minor,
});
}
}
});
const rawRights: any[] = royalty.subRights === undefined || royalty.subRights === null ? [] : royalty.subRights;
if (!Array.isArray(rawRights)) throw new Error("royalty.subRights must be an array");
let hasMemo = false;
rawRights.forEach((r: any, i: number) => {
const at = "royalty.subRights[" + i + "]";
for (const k of ["right", "licensee"]) {
if (typeof r?.[k] !== "string" || r[k].trim() === "") throw new Error(at + "." + k + " is required");
}
const gross = nonNegInt(r.grossMinor, at + ".grossMinor");
const tax = r.foreignTaxWithheldMinor === undefined ? 0 : nonNegInt(r.foreignTaxWithheldMinor, at + ".foreignTaxWithheldMinor");
if (tax > gross) throw new Error(at + ".foreignTaxWithheldMinor must not exceed grossMinor");
const shareBp = toBp(r.authorSharePercent, at + ".authorSharePercent");
// The tax is already out of the base, so the memo row below never touches the total.
const share = roundHalfAway(q(BigInt(gross - tax) * BigInt(shareBp), 10000n));
lines.push({
description: r.right + ", " + r.licensee,
units: "",
basis: tax > 0 ? fmtMoney(gross) + " less " + fmtMoney(tax) + " tax" : fmtMoney(gross),
rate: pct(shareBp),
amount: fmtMoney(share),
memo: false,
amountMinor: share,
});
if (tax > 0) {
hasMemo = true;
lines.push({
description: "Foreign tax withheld by " + r.licensee + " (" + r.right + "), already deducted",
units: "",
basis: fmtMoney(tax),
rate: "",
amount: "",
memo: true,
amountMinor: 0,
});
}
});
const none = lines.length === 0;
const totalMinor = lines.reduce((sum, l) => sum + l.amountMinor, 0);
return {
outcome: none ? "none" : "lines",
negative: totalMinor < 0,
hasMemo,
lines,
total: none ? "" : fmtMoney(totalMinor),
totalAbs: none ? "" : fmtMoney(Math.abs(totalMinor)),
totalMinor,
lifeToDate: lifeToDate.join("; "),
};
},
});