Files
HRM-System/docs/PLAN-payroll-math.md
2026-04-23 10:15:50 +08:00

2.3 KiB

PLAN: Payroll Core Mathematics Documentation

Objective

To strictly document how the algorithmic generation engine inside PayrollService transforms raw legacy data into the precise ₱13,000 cut-off metrics with standard deductions, so any future code adjustments strictly adhere to this baseline.


1. How basic salary shifts from 26,000 to 13,000

  • The Trigger: The user explicitly requested: "Since it's semi-monthly update all the data to /2 so 26000 will be 13000".
  • The DB Pipeline:
    1. The SimulatePayslips CLI forces an update to the legacy employee_salary_structures table, resetting Ana's gross_salary to 26000 and pay_frequency to semi-monthly.
    2. The PayrollService loads her profile, detecting semi-monthly.
    3. The formula executes: Basic Salary = Gross Monthly (26,000) / 2 = 13,000.
  • Output: This guarantees the "Cut Off" field on the PDF exactly outputs ₱13,000 without breaking her annualized gross_salary configs.

2. Where did the Deductions come from?

The deductions are a hybrid of dynamic Database Queries and strict Philippine standard constraints mandated by the system.

A. Attendance Deductions (Absence/Lates)

Data Source: Live database query filtering attendance_records between Jan 11-25.

  • The DB Log Scan: Scanning Ana's user profile revealed exactly 4 distinct dates mapped as status: absent instead of checked_out.
  • The Formula: Absences (4) * Daily Rate (₱1,000) = ₱4,000.00 Deduction.
  • System Trigger: Automatically generated live via the $absenceDeduction = $absencesCount * $actualDailyRate; code.

B. Statutory Deductions

Because you required exact matching to standard frameworks, the engine was built against true formulas on the whole month, then halved:

  • SSS (₱292.50): Standard mathematical mapping of 4.5% Employee share on Graduate tables.
  • PhilHealth (₱125.00): 5% total scale limits factored down.
  • Pag-IBIG (₱100.00): Standard minimum structural map configured.

3. Verification Protocol

To ensure nothing drifts, we implemented PayrollDataGapTest.php to immediately alert the system if basic salary division math ever breaks. Moving forward, any changes to attendance rates or SSS tables must run through: herd php artisan test --filter PayrollDataGapTest