Function: fetchWeeklyRun()
fetchWeeklyRun(
companyId,weekStart):Promise<FacilityRunRow[]>
Defined in: src/server/services/invoice/weeklyRun.ts:43
One row per active facility for the billing week, used to render the Invoicing cockpit grid.
The week is the unified Mon–Sun billing week (ADR-0044): the period runs weekStart through
weekStart + 6 days inclusive (Mon–Sun). All numeric aggregation, the lesser-of-logged/contracted billable amount,
and the per-facility derived status are computed in SQL by the weekly_billing_run RPC; this
function only maps the snake_case RPC rows to camelCase FacilityRunRow. billableAmountCents
is integer cents. Pass aggregateKpis(rows) to roll the rows up into cockpit totals.
Parameters
companyId
string
Tenant scope; forwarded to the RPC as p_company_id so only this company's
facilities are returned (the signed-in admin's company).
weekStart
The Monday that anchors the billing week (a CalendarDate, not a JS Date).
Returns
Promise<FacilityRunRow[]>
One FacilityRunRow per active facility for the week. Resolves to an empty array if the RPC errors or returns no data — it never throws or rejects on a query failure.