Function: fetchFacilityShelf()
fetchFacilityShelf(
companyId,facilityId,weekStart):Promise<FacilityShelfData|null>
Defined in: src/server/services/invoice/weeklyRun.ts:434
Master-data profile for the facility shelf: contacts, active contract terms, and the assigned contractors with a per-week activity status.
Unlike fetchInvoiceShelf, the assignment query here DOES apply an active filter (this is a
roster view, not a billing preview), then collapses to one row per contractor with the same
latest-effective / primary-on-tie / lowest-id rule. Contractor status is derived from this week's
data: active if any payable time entry was logged, else leave if an approved leave overlaps the
week, else no_activity. renewalDue uses today's UTC date and flags contracts whose end or
renewal date is within the next 90 days.
Parameters
companyId
string
Tenant scope; every query is filtered by it (signed-in admin's company).
facilityId
string
The facility whose profile is requested.
weekStart
The Sunday anchoring the week (CalendarDate); used to window time
entries and overlapping leaves over weekStart..weekStart + 6.
Returns
Promise<FacilityShelfData | null>
The FacilityShelfData, or null if the facility does not exist for this company.
hourlyRateCents on the contract is integer cents.