This directory contains guides for the three formula categories in the NSGI Builder payroll engine. Each guide explains what the formulas calculate, lists all available options with descriptions, provides worked examples, and suggests appropriate use cases.
Taxable earnings — basic pay, overtime, day rates, bonuses, and gross reductions
Taxable Income Deductions
Amounts subtracted from gross: loans, pension, withholding tax, loss-time pro-rating
Tax-exempt benefits: travel, meals, housing, NIS/PAYE refunds, overtime allowances
Builder
1. EmployeeTotalGrossSalary → uses Gross Salary Formulas
2. EmployeeTaxableIncomeDeduction → uses Deduction Formulas
3. EmployeeNetSalaryAfterDeduction (computed)
4. EmployeeNontaxableSalary → uses Allowance Formulas
5. EmployeeTotalNetSalary (computed)
All three categories use the same strategy pattern:
A database record holds input (amount, days, hours, or percentage) and options (including formula_name).
The relevant class (CustomizeSalary, CustomizeDeduction, or CustomizableAllowanceSalary) reads formula_name and calls FormulaRegistry::resolve*($formulaName).
The resolved formula class runs calculate(string $input, Collection $options, FormulaContext $context) and returns a Money value.
FormulaContext provides access to basic salary, overtime, no-pay days, NIS, PAYE, and other computed values so formulas can cross-reference related data.
The process is identical across all three categories:
Create a class implementing the relevant interface (SalaryFormula, DeductionFormula, or AllowanceFormula).
Add a name constant in FormulaRegistry.
Register the class in the appropriate boot*Formulas() method in FormulaRegistry.
Set formula_name on the database record.
See the individual guides for full step-by-step instructions and code templates.
src/Formulas/FormulaRegistry.php
Central registry — all formula name constants and registrations
src/Formulas/FormulaContext.php
Shared helper object passed to every formula's calculate() method
src/Formulas/Contracts/SalaryFormula.php
Interface for gross salary formulas
src/Formulas/Contracts/DeductionFormula.php
Interface for deduction formulas
src/Formulas/Contracts/AllowanceFormula.php
Interface for allowance formulas
src/Formulas/GrossSalary/
Standard gross salary formula implementations
src/Formulas/GrossSalary/Custom/
Client-specific gross salary formulas
Deduction formula implementations
Standard allowance formula implementations
src/Formulas/Allowance/Custom/
Client-specific allowance formulas