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→ incrementsreadyCount/readyCentsand adds tobillableCents.review→ incrementsreviewCount/reviewCentsand adds tobillableCents.gap→ incrementsgapCountonly (no amount).sent→ incrementssentCount/sentCentsonly (NOT counted inbillableCents).none(and any other value, as theelsebranch) → incrementsnoneCountonly.
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
The aggregated KPIs. For an empty input, every count/amount is 0 and total is 0.