Created
August 4, 2023 13:02
-
-
Save mintsoft/4330dce3117e8cc3724919c29797cffd to your computer and use it in GitHub Desktop.
Adds functions to calculate income tax and national insurance on raw income
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
/** @CustomFunction */ | |
function incomeTax(pay: number): number { | |
var additionalTax = 0; | |
var higherTax = 0; | |
var basicTax = 0; | |
var personalAllowanceToRemove = Math.floor((pay - 100000) / 2); | |
var defaultPersonalAllowance = 12570; | |
var personalAllowance = defaultPersonalAllowance; | |
if (personalAllowanceToRemove > 0) { | |
personalAllowance -= personalAllowanceToRemove | |
personalAllowance = Math.max(personalAllowance, 0) | |
} | |
if (pay < personalAllowance) { | |
return 0; | |
} | |
var taxableAmount = pay - personalAllowance; | |
var additionalAmountThreshold = (125140) | |
var additionalAmount = taxableAmount - additionalAmountThreshold; | |
if (taxableAmount > additionalAmountThreshold) { | |
additionalTax = 0.45 * additionalAmount; | |
taxableAmount = additionalAmountThreshold; | |
} | |
var higherAmountThreshold = (50270 - defaultPersonalAllowance) | |
var higherAmount = taxableAmount - higherAmountThreshold; | |
if (taxableAmount > higherAmountThreshold) { | |
higherTax = 0.4 * higherAmount; | |
taxableAmount = higherAmountThreshold | |
} | |
var basicAmount = taxableAmount; | |
if (basicAmount > 0) { | |
basicTax = 0.2 * basicAmount; | |
} | |
console.log("persallowance:" + personalAllowance + "additional: " + additionalTax + " higher:" + higherTax + " basic: " + basicTax) | |
var totalTax = basicTax + higherTax + additionalTax | |
return totalTax | |
} | |
/** @CustomFunction */ | |
function nationalInsuranceClass1(pay: number): number { | |
var twelvePercentThreshold = 1048 * 12; | |
var twoPercentThreshold = 4189 * 12; | |
var nic = 0; | |
var applicableAmount = pay; | |
if (applicableAmount > twoPercentThreshold) { | |
nic += (applicableAmount - twoPercentThreshold) * 0.02 | |
applicableAmount = twoPercentThreshold; | |
} | |
if (applicableAmount > twelvePercentThreshold) { | |
nic += (applicableAmount - twelvePercentThreshold) * 0.12; | |
} | |
return nic; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment