Programming logic for income tax calculation

13,179

Solution 1

function get_taxed_salary($salary){
  if ($salary <= 150 ){
    return $salary;
  };
  if ($salary <= 650){
    return ( 0.9 * $salary - 15.0 );
  };

 ...
}

later in your code you use that function like:

$taxed_salary = get_taxed_salary($salary);

Solution 2

In most countries, that is not how tax works - you don't pay tax at a certain percent based on how much you earn. If that was the case then people who's wages were just above a tax bracket would have a net income after tax lower than someone who earnt just under a tax bracket.

How it really works: you pay tax at different percentages, for each part of your income that falls within each tax bracket. So if you earn $11,000 and there is a tax bracket from 0 to 10,000 and another from 10,000 up to 20,000 then the first 10k earned will be taxed at the first bracket's rate and the remaining 1k will be taxed at the higher rate of the second tax bracket.

Code to calculate tax in this manner:

//the tops of each tax band
$band1_top = 14000;
$band2_top = 48000;
$band3_top = 70000;
//no top of band 4

//the tax rates of each band
$band1_rate = 0.105;
$band2_rate = 0.175;
$band3_rate = 0.30;
$band4_rate = 0.33;

$starting_income = $income = 71000; //set this to your income

$band1 = $band2 = $band3 = $band4 = 0;

if($income > $band3_top) {
    $band4 = ($income - $band3_top) * $band4_rate;
    $income = $band3_top;
}

if($income > $band2_top) {
    $band3 = ($income - $band2_top) * $band3_rate;
    $income = $band2_top;
}

if($income > $band1_top) {
    $band2 = ($income - $band1_top) * $band2_rate;
    $income = $band1_top;
}

$band1 = $income * $band1_rate;

$total_tax_paid = $band1 + $band2 + $band3 + $band4;

echo "Tax paid on $starting_income is $total_tax_paid";

?>

Solution 3

You should learn basic PHP. The solution is trivial.

function getTax($salary) {
    $percent = 0;
    $subt = 0;

    if ($salary >= 0 && $salary <= 150) {
        $percent = 10;
        $subt = 15;
    } elseif ($salary >= 151 && $salary <= 650) {
        ...
    } ...

    // do calculations here, ex:
    $final = $salary * $percent / 100 - $subt;
    return $final;
}

Edit: Thank you Constantin for the function reminder

Share:
13,179
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    Is any one who can help me to create PHP or mysql Code for our Office employee salary tax table. Here is the base for our tax regulation.

     If salary is >= 0 and <= 150 it will be 0% (Nill),
     If salary is >= 151 and <= 650 it will be 10% - 15.00,
     If salary is >= 651 and <= 1400 it will be 15% - 47.50,
     If salary is >= 1401 and <= 2350 it will be 20% -117.50,
     If salary is >= 2351 and <= 3550 it will be 25% - 235.00,
     If salary is >= 3551 and <= 5000 it will be 30% - 412.5,
     If salary is >= 5001 it will be 35% - 662.50