Skip to main content

Function: aggregateKpis()

aggregateKpis(rows): RunKpis

Defined in: src/lib/invoice/run.ts:127

Aggregate a set of facility rows into roll-up RunKpis for the weekly billing run.

Pure and side-effect free; safe to unit-test without the data layer. Buckets each row by its SQL-derived RunStatus:

  • ready → increments readyCount/readyCents and adds to billableCents.
  • review → increments reviewCount/reviewCents and adds to billableCents.
  • gap → increments gapCount only (no amount).
  • sent → increments sentCount/sentCents only (NOT counted in billableCents).
  • none (and any other value, as the else branch) → increments noneCount only.

All *Cents results are integer cents, summed from each row's billableAmountCents.

Parameters

rows

readonly FacilityRunRow[]

The per-facility run rows to aggregate. Read-only; never mutated. total is set to rows.length.

Returns

RunKpis

The aggregated KPIs. For an empty input, every count/amount is 0 and total is 0.