My Technical Notes

Tuesday, 24 November 2015

Calculating Salary

The following PowerShell Function will calculate your Tax, National Insurance and Pension contributions and tell you your net salary. Not that it only works for salaries between £10,600 and below the 40% tax threshold, £42,385.


Function Round([decimal]$val, [int]$places = 2) {
    [decimal]::Round($val, $places)
}

# all figures are monthly, unless otherwise stated
Function CalculateSalary(
    [decimal]$gross, 
    [decimal]$niSecondaryThreshold = 676, 
    [decimal]$niPrimaryThreshold = 672, 
    [decimal]$niPercentage = 0.106, 
    [decimal]$niRebatePercentage = 0.014,
    [decimal]$niLowerEarningLimit = 486,
    [decimal]$personalAllowanceAnnual = 10600, 
    [decimal]$pensionPercentage = 0.065
    ) 
{
    # start of NI Calculations

    $niOfBetweenThresholds =  Round (($niSecondaryThreshold - $niPrimaryThreshold) * $niPercentage)
    $niOfAboveGross = Round (($gross - $niSecondaryThreshold) * $niPercentage)
    $rebate = Round (($niPrimaryThreshold - $niLowerEarningLimit) * $niRebatePercentage); # this will not be used from April 2016 onwards
    $niTotal = $niOfBetweenThresholds + $niOfAboveGross - $rebate

    # end of NI Calculations

    # start of tax calculations
    
    $personalAllowanceMonth = Round ($personalAllowanceAnnual / 12) -places 0

    $taxableAmount = $gross - ($gross * $pensionPercentage) - $personalAllowanceMonth;
    $tax = Round ($taxableAmount * 0.2) -places 0;

    # end of tax calculations

    # start of pension 
    $pension = Round ($gross * $pensionPercentage);
    # end of pension

    # start of net
    $net = $gross - $tax - $pension - $niTotal
    # end of net

    "Pension: $pension"
    "Tax: $tax"
    "Employee NI: $niTotal"
    "Net Total: $net"
}

We call the function with a gross amount:


CalculateSalary -gross 2395.5

No comments: