Zum Inhalt springen

← Registry

Open items and ageing

Body

Lists every invoice not yet fully settled with the amount still open on it, then ages the open balance into not yet due, 1-30, 31-60, 61-90 and over 90 days overdue. Age is counted from the due date, not the invoice date, and each bucket includes its top edge, so 30 days is 1-30 and an invoice due today is not yet due; one with no due date ages from its date plus the default terms, and the strip says so. A payment or credit note not set against an invoice is unallocated credit on a line of its own, never netted into a bucket, so no bucket goes negative and an old debt never disappears. A disputed invoice is listed, marked and aged in its own column, so it cannot drive the over-90 figure. The shares are largest-remainder rounded to sum to exactly 100, an over-allocated invoice fails the document, and when nothing is overdue the strip is one line. All of it is one deriver.

npx dxcl add open-items-ageing
exportiert OpenItemsAgeing · löst zu 1 Nodes auf

Vorschaudaten

das JSON, mit dem diese Vorschau gebaut wurde
{
  "account": {
    "currency": "GBP",
    "statementDate": "2026-11-30",
    "defaultTermsDays": 30,
    "invoices": [
      {
        "number": "INV-2026-0004211",
        "date": "2026-06-12",
        "dueDate": "2026-07-12",
        "amount": 248750,
        "disputed": true
      },
      {
        "number": "INV-2026-0004290",
        "date": "2026-07-01",
        "dueDate": "2026-07-31",
        "amount": 54000
      },
      {
        "number": "INV-2026-0004388",
        "date": "2026-07-20",
        "dueDate": "2026-08-19",
        "amount": 1186420.5
      },
      {
        "number": "INV-2026-0004502",
        "date": "2026-08-28",
        "dueDate": "2026-09-27",
        "amount": 312980.75
      },
      {
        "number": "INV-2026-0004617",
        "date": "2026-09-30",
        "amount": 97640
      },
      {
        "number": "INV-2026-0004733",
        "date": "2026-10-15",
        "dueDate": "2026-11-14",
        "amount": 1048215.4
      },
      {
        "number": "INV-2026-0004851",
        "date": "2026-11-02",
        "dueDate": "2026-12-02",
        "amount": 655300
      }
    ],
    "credits": [
      {
        "type": "credit-note",
        "date": "2026-10-08",
        "number": "CN-2026-000412",
        "amount": 54000,
        "allocations": [
          {
            "invoice": "INV-2026-0004290",
            "amount": 54000
          }
        ]
      },
      {
        "type": "payment",
        "date": "2026-11-03",
        "number": "BACS-REMIT-20261103-000918",
        "amount": 400000,
        "allocations": [
          {
            "invoice": "INV-2026-0004388",
            "amount": 400000
          }
        ]
      },
      {
        "type": "credit-note",
        "date": "2026-11-18",
        "number": "CN-2026-000431",
        "amount": 18500,
        "allocations": [
          {
            "invoice": "INV-2026-0004502",
            "amount": 6250
          }
        ]
      },
      {
        "type": "payment",
        "date": "2026-11-26",
        "number": "BACS-REMIT-20261126-001147",
        "amount": 125000
      }
    ]
  }
}

Gerenderte Vorschau

jede Anordnung für sich gerendert
arrangement="across" Standard
The buckets side by side: name, amount and share in three rows.
Von Docxcelerate beim Build gerendert Open ↗
arrangement="down"
One row per bucket with its amount and share, for narrow columns and large figures.
Von Docxcelerate beim Build gerendert Open ↗

Aufgelöste Nodes

was ein Renderer erhält — 1 Nodes
open-items-ageing section

Die Dateien

was die Installation schreibt; die gewählte Datei ist die Komponente
your-project/
nodes/open-items-ageing.node.tsx
import { arrange, Cell, Paragraph, Row, Section, type Section as SectionComponent, Table, useDeriver, useState } from "docxcelerate/template";
import type { OpenItemsAgeingLines } from "../arrangements/open-items-ageing/lines.ts";
import { across } from "../arrangements/open-items-ageing/across.arrangement.tsx";
import { down } from "../arrangements/open-items-ageing/down.arrangement.tsx";
import openItemsAgeing from "../derivers/open-items-ageing.deriver.ts";

/**
 * An open-item statement: every invoice not yet fully settled, with the amount
 * still open on each, and that open balance aged into buckets. The decisions
 * it makes for the reader are the ones a collections call turns on.
 *
 * Age is counted from the due date, not the invoice date, so an invoice on
 * 30-day terms is not "1–30" the day it is raised. Each bucket includes its top
 * edge: 30 days overdue is 1–30, 31 is 31–60, and an invoice due today is not
 * yet due, which is why the last bucket is "Over 90", not "90+". An invoice
 * with no due date is aged from its date plus `defaultTermsDays`, and the
 * basis sentence says so; with no terms either, the deriver throws rather than
 * guess on a document that tells someone they are overdue.
 *
 * Unallocated credit gets its own line. A payment or credit note not set
 * against an invoice is shown beneath the buckets and never netted into the
 * oldest one, so no bucket goes negative and an old debt does not quietly
 * disappear.
 *
 * Disputed invoices are listed and marked, and aged in their own bucket, so
 * they do not inflate the Over 90 figure that drives escalation.
 *
 * Bad data throws. An over-allocated invoice or credit fails the document
 * rather than printing a negative open amount. The six buckets always sum to
 * the open balance, in integer minor units, and their shares (largest
 * remainder) to exactly 100%.
 *
 * Nothing overdue collapses the strip: when nothing undisputed is overdue it
 * becomes one sentence.
 *
 * Arrangement: only the ageing strip is placed by the `arrangement` prop. The
 * rows, the totals and every sentence are fixed here.
 *
 * Every figure is computed in one deriver, because all of it is arithmetic,
 * sorting and date maths on request data. The rows are a `.map()` over the
 * deriver's result, which publishes as a loop over `derived`. The node
 * branches only on the deriver's booleans and strings, about nine published
 * branches against the default `branchLimit` of 32.
 *
 * Installed by `dxcl add open-items-ageing`, which also installs its deriver.
 */

/** What this component reads. Add these fields to your document data type. */
export interface OpenItemsAgeingData {
  account: {
    /**
     * ISO 4217 code every amount is in: `"GBP"`, `"EUR"`, `"JPY"`. It also sets
     * the minor unit each amount is rounded to on the way in (pence for GBP,
     * none for JPY). Required: the deriver throws when it is missing or not a
     * code `Intl` knows.
     */
    currency: string;
    /**
     * The day the statement is drawn up, ISO 8601: `2026-11-30`. Every age is
     * counted to this day. Anything after the tenth character (a time) is
     * ignored. Required: throws when missing or not YYYY-MM-DD.
     */
    statementDate: string;
    /**
     * Days after its invoice date that an invoice with no `dueDate` falls due.
     * A whole number, 0 or more. Missing is fine while every open invoice has
     * a `dueDate`; the deriver throws, naming the invoice, when an open
     * invoice has no `dueDate` and this is missing, rather than guess terms on
     * a document that tells someone they are overdue. Throws when present but
     * not a non-negative integer.
     */
    defaultTermsDays?: number;
    /**
     * Every invoice on the account, including any that a credit's allocations
     * name, settled ones too: those are left out of the listing but have to be
     * here for an allocation to find. Missing or empty means none.
     */
    invoices?: Array<{
      /** The invoice number, printed as given. Required, non-blank, unique: a duplicate throws, because an allocation could not say which one it meant. */
      number: string;
      /** Invoice date, ISO 8601. Required: throws when missing or not a date. */
      date: string;
      /** Due date, ISO 8601. Missing means `date` plus `account.defaultTermsDays`. Throws when present but not a date. */
      dueDate?: string;
      /**
       * Gross amount in major units: `1186420.5`. Rounded once to the
       * currency's minor unit. Zero means settled and is left out. Negative
       * throws: a credit note belongs in `credits`. Not a finite number throws.
       */
      amount: number;
      /** The customer disputes it. Listed, marked "In dispute", and aged in the In dispute bucket whatever its age. Missing means false. */
      disputed?: boolean;
    }>;
    /** Payments and credit notes received. Missing or empty means none. */
    credits?: Array<{
      /** What it is, printed in the unallocated-credit sentence. Anything else throws. */
      type: "payment" | "credit-note";
      /** When it was received or issued, ISO 8601. Printed with the unallocated part. Required. */
      date: string;
      /** Its reference, printed as given. Required, non-blank. */
      number: string;
      /** Its amount in major units, rounded to the minor unit. Must be above zero, or it throws. */
      amount: number;
      /**
       * Which invoices it settles, and how much of each. Missing or empty means
       * none, and the whole credit is unallocated. Each `invoice` must name a
       * number in `invoices` and each `amount` must be above zero, or it
       * throws. Allocations above the credit's own amount throw.
       */
      allocations?: Array<{ invoice: string; amount: number }>;
    }>;
  };
}

/**
 * Where the ageing strip sits.
 *
 * - `across`: the buckets side by side in three rows (name, amount, share), the way a statement usually prints them. The default.
 * - `down`: one row per bucket with its amount and share beside it, for a narrow column or seven-figure amounts.
 */
export type OpenItemsAgeingArrangement = "across" | "down";

/** Props for {@linkcode OpenItemsAgeing}. */
export interface OpenItemsAgeingProps {
  /** Where the ageing strip sits. Defaults to `"across"`. */
  arrangement?: OpenItemsAgeingArrangement;
}

export const OpenItemsAgeing: SectionComponent<OpenItemsAgeingProps> = async ({ arrangement }) => {
  const [account] = useState((data: OpenItemsAgeingData) => data.account);
  const a = await useDeriver(openItemsAgeing, [account]);

  const lines: OpenItemsAgeingLines = { overdue: a.overdue, buckets: a.buckets };

  return (
    <Section id="open-items-ageing" title="Open items">
      {a.empty && <Paragraph id="open-items-ageing-empty">{a.emptyLine}</Paragraph>}
      {!a.empty && <Paragraph id="open-items-ageing-basis">{a.basis}</Paragraph>}
      {a.hasItems && (
        <Table
          id="open-items-ageing-items"
          columns={[
            { width: "auto" },
            { width: 24 },
            { width: 24 },
            { width: 24 },
            { width: 30, align: "right" },
            { width: 30, align: "right" },
          ]}
        >
          <Row id="open-items-ageing-items-header">
            <Cell>Invoice</Cell>
            <Cell>Dated</Cell>
            <Cell>Due</Cell>
            <Cell>Overdue</Cell>
            <Cell>Amount</Cell>
            <Cell>Open</Cell>
          </Row>
          {a.items.map((item) => (
            <Row id="open-items-ageing-item">
              <Cell>{item.number}</Cell>
              <Cell>{item.date}</Cell>
              <Cell>{item.due}</Cell>
              <Cell>{item.age}</Cell>
              <Cell>{item.amount}</Cell>
              <Cell>{item.open}</Cell>
            </Row>
          ))}
        </Table>
      )}
      {arrange(arrangement, {
        across: () => across(lines),
        down: () => down(lines),
      })}
      {a.nothingOverdue && <Paragraph id="open-items-ageing-nothing-overdue">{a.nothingOverdue}</Paragraph>}
      {!a.empty && (
        <Table id="open-items-ageing-totals" columns={[{ width: "auto" }, { width: 40, align: "right" }]}>
          <Row id="open-items-ageing-total-open">
            <Cell>Open invoices</Cell>
            <Cell>{a.totalOpen}</Cell>
          </Row>
          {a.overdue && (
            <Row id="open-items-ageing-total-overdue">
              <Cell>Of which overdue</Cell>
              <Cell>{a.overdueTotal}</Cell>
            </Row>
          )}
          {a.hasUnallocated && (
            <Row id="open-items-ageing-total-unallocated">
              <Cell>Unallocated credit</Cell>
              <Cell>{a.unallocated}</Cell>
            </Row>
          )}
          <Row id="open-items-ageing-total-balance">
            <Cell>{a.balanceLabel}</Cell>
            <Cell>{a.balance}</Cell>
          </Row>
        </Table>
      )}
      {a.hasUnallocated && <Paragraph id="open-items-ageing-unallocated-detail">{a.unallocatedDetail}</Paragraph>}
    </Section>
  );
};