CalOohPay API Documentation - v2.1.0
    Preparing search index...

    Class OnCallPaymentsCalculator

    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.

    Rates can be configured in two ways:

    1. Via Constructor - Pass custom rates when creating the calculator
    2. Via Config File - Use .caloohpay.json for organization-wide settings
    3. Default Rates - Falls back to:
      • Weekdays (Monday-Thursday): £50 per OOH day
      • Weekends (Friday-Sunday): £75 per OOH day

    These default rates maintain backward compatibility and can be accessed via:

    Total Compensation = (Weekday OOH Days × Weekday Rate) + (Weekend OOH Days × Weekend Rate)
    

    All calculation methods validate input to ensure:

    • User object is defined
    • User has on-call periods assigned
    • Rates are positive numbers (when provided)
    // Using default rates

    const user = new OnCallUser(
    'PXXXXXX',
    'John Doe',
    [
    new OnCallPeriod(
    new Date('2024-08-01T17:30:00Z'),
    new Date('2024-08-05T09:00:00Z'),
    'Europe/London'
    )
    ]
    );
    const calculator = new OnCallPaymentsCalculator();
    const amount = calculator.calculateOnCallPayment(onCallUser);

    // Using custom rates
    const customCalculator = new OnCallPaymentsCalculator(60, 90);
    const customAmount = customCalculator.calculateOnCallPayment(onCallUser);

    // Using rates from config file
    const loader = new ConfigLoader();
    const rates = loader.loadRates();
    const configCalculator = new OnCallPaymentsCalculator(
    rates.weekdayRate,
    rates.weekendRate
    );
    Index

    Constructors

    • Creates a new OnCallPaymentsCalculator with optional custom rates.

      Parameters

      • OptionalweekdayRate: number

        Custom weekday rate (defaults to WEEKDAY_RATE from Constants)

      • OptionalweekendRate: number

        Custom weekend rate (defaults to WEEKEND_RATE from Constants)

      Returns OnCallPaymentsCalculator

      If provided rates are not positive numbers

      // 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
      );

    Properties

    WeekDayRate: number = WEEKDAY_RATE

    Default compensation rate for weekday (Mon-Thu) OOH shifts. Fixed at £50 per OOH weekday.

    WeekEndRate: number = WEEKEND_RATE

    Default compensation rate for weekend (Fri-Sun) OOH shifts. Fixed at £75 per OOH weekend day.

    Methods

    • 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).

      Parameters

      • onCallUser: OnCallUser

        The user with calculated on-call periods

      Returns number

      Total compensation amount in GBP (£)

      If user is undefined or has no on-call periods

      Assumption: The input user's date range spans complete days.

      • since should be YYYY-MM-DDT00:00:00 (start of day)
      • until should be YYYY-MM-DDT23:59:59 (end of day)

      This ensures accurate day counting in the schedule's timezone.

      const user = new OnCallUser('PXXXXXX', 'John Doe', [
      new OnCallPeriod(startDate, endDate, 'Europe/London')
      ]);

      const calculator = new OnCallPaymentsCalculator();
      const payment = calculator.calculateOnCallPayment(user);
      // Returns: (1 × £50) + (3 × £75) = £275
    • 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.

      Parameters

      • onCallUsers: OnCallUser[]

        Array of users with calculated on-call periods

      Returns Record<string, number>

      Record mapping user IDs to compensation amounts

      If any user is undefined or has no on-call periods

      const users = [user1, user2, user3];
      const payments = calculator.calculateOnCallPayments(users);

      // Result: { 'PXXXXXX': 275, 'PYYYYYY': 150, 'PZZZZZZ': 400 }

      // Use for payroll
      for (const [userId, amount] of Object.entries(payments)) {
      console.log(`User ${userId}: £${amount}`);
      }
    • 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.

      Parameters

      • onCallUsers: OnCallUser[]

        Array of users with calculated on-call periods

      Returns Record<string, OnCallCompensation>

      Record mapping user IDs to detailed compensation records

      If any user is undefined or has no on-call periods

      Each record in the result contains:

      • Complete OnCallUser object with all periods
      • Breakdown of weekday and weekend OOH days
      • Calculated total compensation

      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}`);