Created
January 31, 2024 23:17
-
-
Save walosha/c44de140de73cbcb8b43aaae8d965d9e to your computer and use it in GitHub Desktop.
PayeCalculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PayeCalculator { | |
constructor(basicSalary, housingAllowance, transportAllowance, otherAllowance) { | |
this.basicSalary = basicSalary; | |
this.housingAllowance = housingAllowance; | |
this.transportAllowance = transportAllowance; | |
this.otherAllowance = otherAllowance; | |
} | |
calculatePension() { | |
const grossIncome = this.basicSalary + this.housingAllowance + this.transportAllowance + this.otherAllowance; | |
const pensionRate = 0.08; | |
return pensionRate * grossIncome / 12; | |
} | |
calculateNHF() { | |
const grossIncome = this.basicSalary + this.housingAllowance + this.transportAllowance + this.otherAllowance; | |
const nhfRate = 0.025; | |
return nhfRate * grossIncome / 12; | |
} | |
calculateCRA() { | |
const grossIncome = this.basicSalary + this.housingAllowance + this.transportAllowance + this.otherAllowance; | |
const annualCraBase = grossIncome - this.calculatePension() - this.calculateNHF(); | |
return Math.max(0.01 * annualCraBase + 0.2 * annualCraBase, 200000); | |
} | |
calculateTaxableIncome() { | |
const annualCraBase = this.basicSalary + this.housingAllowance + this.transportAllowance + this.otherAllowance - this.calculatePension() - this.calculateNHF(); | |
return annualCraBase - this.calculateCRA(); | |
} | |
calculateTax() { | |
const taxableIncome = this.calculateTaxableIncome(); | |
let taxPayable = 0; | |
if (taxableIncome <= 300000) { | |
taxPayable = 0.07 * taxableIncome; | |
} else if (taxableIncome <= 600000) { | |
taxPayable = 21000 + 0.11 * (taxableIncome - 300000); | |
} else { | |
taxPayable = 54000 + 0.15 * (taxableIncome - 600000); | |
} | |
return taxPayable; | |
} | |
calculateNetSalary() { | |
const grossIncome = this.basicSalary + this.housingAllowance + this.transportAllowance + this.otherAllowance; | |
const monthlyGrossIncome = grossIncome / 12; | |
const finalTaxPayable = Math.max(0.01 * grossIncome - this.calculatePension() - this.calculateNHF(), this.calculateTax()); | |
return monthlyGrossIncome - (finalTaxPayable / 12) - this.calculatePension() - this.calculateNHF(); | |
} | |
} | |
// Example Usage | |
const payeCalculator = new PayeCalculator(360000, 240000, 240000, 360000); | |
console.log("Pension Contribution: NGN", payeCalculator.calculatePension().toFixed(2)); | |
console.log("NHF Contribution: NGN", payeCalculator.calculateNHF().toFixed(2)); | |
console.log("CRA: NGN", payeCalculator.calculateCRA().toFixed(2)); | |
console.log("Tax Payable: NGN", payeCalculator.calculateTax().toFixed(2)); | |
console.log("Net Salary: NGN", payeCalculator.calculateNetSalary().toFixed(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment