Skip to main content

Function: computePayRun()

computePayRun(companyId, period): Promise<PayRunPreview>

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

Compute (without persisting) the contractor pay for a bi-monthly period. Pulls each contractor's applicable assignment rate, their period time entries (payable statuses only), and approved holidays (in-house admins), then runs the pure pay engine. Assignment lines whose computed pay is <= 0 centavos are dropped (no empty payslip line); a contractor still appears as long as at least one assignment pays. Used by both the preview and the close action.

Parameters​

companyId​

string

Tenant scope; every query is filtered to this company.

period​

BiMonthlyPeriod

The bi-monthly half (year/month/half + start/end CalendarDates) to price.

Returns​

Promise<PayRunPreview>

A PayRunPreview: priced lines (one per paid assignment), totalCentavos (PHP centavos), the priced-scope/TOCTOU snapshot, warning day-counts, and per-contractor errors.

Remarks​

The domain rules (settling-week fetch window, approved-overage seam, holiday routing, deterministic assignment pick) live in the shared loader/assembly — see loadPayComputeInputs and payForAssignment in payInputs.ts. This function owns only what a pay RUN adds on top: warning day-counts, the in-period TOCTOU snapshot, per-contractor error capture, zero-pay line dropping, and skipping soft-deleted contractors.

This is read-only: it opens a service-role client and queries but persists nothing. A pay-engine failure for one contractor is captured in result.errors (not thrown); that contractor is skipped.

Throws​

MoneyError (via centavos) if an assignment's bimonthly_rate_centavos is somehow a non-integer or exceeds the JS safe-integer range; bigint storage makes this practically unreachable, but unlike pay-engine validation errors it aborts the whole run rather than being captured in errors.