Creates a new OnCallPaymentsCalculator with optional custom rates.
OptionalweekdayRate: numberCustom weekday rate (defaults to WEEKDAY_RATE from Constants)
OptionalweekendRate: numberCustom weekend rate (defaults to WEEKEND_RATE from Constants)
// Use default rates
const defaultCalculator = new OnCallPaymentsCalculator();
// Use custom rates (e.g., USD rates)
const usdCalculator = new OnCallPaymentsCalculator(60, 90);
// Use rates from config
const config = new ConfigLoader().loadRates();
const configCalculator = new OnCallPaymentsCalculator(
config.weekdayRate,
config.weekendRate
);
Static ReadonlyWeekDefault compensation rate for weekday (Mon-Thu) OOH shifts. Fixed at £50 per OOH weekday.
Static ReadonlyWeekDefault compensation rate for weekend (Fri-Sun) OOH shifts. Fixed at £75 per OOH weekend day.
Calculates the total compensation for a single user's on-call duty.
Computes payment based on the user's OOH weekday and weekend day counts, applying the standard rates (£50 for weekdays, £75 for weekends).
The user with calculated on-call periods
Total compensation amount in GBP (£)
Calculates compensation for multiple users in batch.
Processes an array of users and returns a mapping of user IDs to their compensation amounts. Useful for generating payroll reports.
Array of users with calculated on-call periods
Record mapping user IDs to compensation amounts
Generates detailed auditable compensation records for multiple users.
Creates comprehensive records that include both the full user object (with all on-call periods and breakdowns) and the calculated compensation. These records are suitable for audit trails, detailed reports, and CSV export.
Array of users with calculated on-call periods
Record mapping user IDs to detailed compensation records
Each record in the result contains:
This format is used by the CSV export functionality and provides full transparency for payroll auditing.
const records = calculator.getAuditableOnCallPaymentRecords([user1, user2]);
// Result structure:
// {
// 'PXXXXXX': {
// OnCallUser: user1, // Full object with periods
// totalCompensation: 275
// },
// 'PYYYYYY': {
// OnCallUser: user2,
// totalCompensation: 150
// }
// }
// Access details for audit
const record = records['PXXXXXX'];
console.log(`User: ${record.OnCallUser.name}`);
console.log(`Weekdays: ${record.OnCallUser.getTotalOohWeekDays()}`);
console.log(`Weekends: ${record.OnCallUser.getTotalOohWeekendDays()}`);
console.log(`Total: £${record.totalCompensation}`);
Calculates on-call compensation for users based on their OOH (Out of Hours) shifts.
This class implements the business logic for computing monetary compensation for on-call duty. It supports configurable rates for weekday and weekend OOH shifts and provides methods for both simple payment calculations and detailed auditable records.
Remarks
Compensation Rates
Rates can be configured in two ways:
.caloohpay.jsonfor organization-wide settingsThese default rates maintain backward compatibility and can be accessed via:
Calculation Formula
Validation
All calculation methods validate input to ensure:
Example