Leave entitlement proration¶
This document explains the proration logic used by StaffService when normalizing staff leave entitlements.
When proration runs¶
Proration runs only when entitlement dates are not manually supplied:
- If both
fromandtoare provided, they are validated (from <= to) and no automatic proration is performed. - If only one of
fromortois provided, the request is rejected. - If both are missing, the service derives period and prorated value automatically.
Automatic period resolution¶
When both dates are missing:
joinDateis mandatory.- The leave calendar covering
joinDateis loaded usingLeaveCalendarService.getCalendarFor(joinDate). - If not found, the request fails.
- Entitlement period is set to:
from = calendar.startto = min(calendar.end, termDate)whentermDateis present and earlier; otherwisecalendar.end.
Proration formula¶
Given:
fullPeriodEntitlement= entitlement provided in payload (for full calendar period)from/to= resolved entitlement periodeffectiveFrom = max(joinDate, from)effectiveTo = min(termDate, to)whentermDateexists, elseto
Rules:
- If the staff member is active for the whole period (
effectiveFrom == fromandeffectiveTo == to), keep the original entitlement. - Otherwise prorate by inclusive day counts:
totalPeriodDays = days_between(from, to) + 1effectiveDays = days_between(effectiveFrom, effectiveTo) + 1prorated = fullPeriodEntitlement * effectiveDays / totalPeriodDays- If
effectiveDays <= 0, entitlement becomes0.00. - Result is rounded to 2 decimal places using
HALF_UP.
Related validation failures¶
The service rejects entitlement normalization when:
- entitlement amount is missing
- leave type is missing or unknown
- period is invalid (
from > to) - only one period boundary is supplied
joinDateis missing for automatic period mode- no leave calendar can be found/generated for
joinDate