Function: calculateContractorPay()
calculateContractorPay(
input):Result<PayBreakdown,PayError>
Defined in: src/lib/pay/index.ts:294
Compute one contractor's pay for one bi-monthly period. Pure and deterministic — no I/O, no clock. All money is integer PHP Centavos.
Dispatches by CalculatePayInput.contractorType:
in_house_admin→ one period-level proration (no overage; PTO credited; ratio capped at 1).outsourcedwith anassignmentEndDateinside the period → day-prorated final partial period (mid-period offboard), so the last active days are never dropped by the next, ended-out run.outsourcedotherwise → whole ISO Mon–Sun weeks, each settled in the period holding its Sunday, with the rate split equally across settling weeks. Hours overweeklyContractedHoursare withheld unless that week's Monday key is inapprovedOverageWeeks.
Validation runs first and short-circuits to the err branch — no money is computed on bad input.
Parameters
input
All inputs for the contractor/period; see CalculatePayInput.
Returns
Result<PayBreakdown, PayError>
ok(PayBreakdown) on success, whose totalCentavos exactly equals the sum of the per-row
payCentavos. Returns err(PayError) for invalid_rate (rate < 0),
invalid_contracted_hours (weeklyContractedHours <= 0), or invalid_hours (any
negative time-entry). Never throws for these; this is a Result, not an exception path.