Skip to main content

Function: estimateContractorPay()

estimateContractorPay(companyId, contractorId, period): Promise<ContractorPayEstimate | null>

Defined in: src/server/services/payroll.ts:453

Estimate one contractor's pay for a period from the hours logged so far — the same engine and inputs as the period close, scoped to a single (own) contractor. Returns null when the contractor has no rate-bearing assignment overlapping the period. Read-only; safe to show the contractor.

Parameters

companyId

string

Tenant scope; every query is filtered to this company.

contractorId

string

The contractor whose own estimate is requested (their dashboard view).

period

BiMonthlyPeriod

The bi-monthly half to estimate.

Returns

Promise<ContractorPayEstimate | null>

A ContractorPayEstimate aggregated across the contractor's assignments, or null if they have no rate-bearing assignment overlapping the period.

Remarks

Mirrors computePayRun for a single contractor: same settling-week fetch window (Mon–Sun settled by Sunday, ADR-0044), same approved-overage translation (Sunday billing week → ISO Monday pay week), same payable-status filter, and the same holiday rule (credited only for in_house_admin, only on the primary assignment). Per assignment, pay caps at the contracted rate unless that week's overage was approved. A contractor with no row defaults to 'outsourced'. Assignments whose pay-engine Result is an error are silently skipped (this is an estimate, not the authoritative close). The silent-skip tolerance covers only that Result error branch: a non-integer or unsafe bimonthly_rate_centavos still throws MoneyError via centavos() and aborts the estimate (unreachable in practice because the column is a bigint).