Hi I am a newbe and writing a simple code for tax purposes. So far I have wrote a small code but I think there seems to be a problem with the function taxable_i($i)
which is not letting me make $taxable_i
NIL
. I have tried everything.
When I try to made $taxable_i
NIL
via function it wont let me do it. It shows me a result of £13900
. I think the program is echoing $taxable_i
rather then the tax payable.
If I delete the above all together then the tax payable comes to -£2199.80
, which is in minus.
Please note that I put $taxable_i <personal_allowance
so that the answer is zero but the result is not zero. I do not know why and what I am doing wrong.
Any help is most welcome.'
<?php
// VAT
define("vat_threshold",83000 );
define("vat_rate",0.2 );
// RELIEFS
define("personal_allowance",11000 );
//RATES
define("starting_rate",0 );
define("basic_rate",0.2 );
define("higher_rate",0.4 );
define("add_rate",0.45 );
define("divs_ord_rate",0.075 );
define("divs_uuper_rate",0.325 );
define("divs_add_rate",0.381 );
// THRESHOLDS
define("savings_income_band",5000 );
define("basic_rate_band",32000 );
define("higher_rate_band",150000 );
define("divs_allowance",5000 );
define ("band_0",0);
define("band_1",11000);
define("band_2",32000);
define("band_3",100000);
define("band_4",122000);
define("band_5",150000);
function taxable_i($i) {
if ($i <= band_1 ) {
$taxable_i = $i * 0;
return $taxable_i;
}
if ($i <= band_3 ) {
$taxable_i = $i - personal_allowance;
return $taxable_i;
}
if ($i >band_3 && $i <=band_4) {
$taxable_i = $i - (personal_allowance-($i - band_3)/2);
return $taxable_i;
}
if ($i > band_4) {
$taxable_i = $i;
return $taxable_i;
}
}
$starting_income = $i = 1;
echo $i;
$taxable_i = taxable_i($i);
echo $taxable_i;
switch ($taxable_i) {
case ($taxable_i > band_5):
$diff = $taxable_i - band_5;
$tax5 = $diff * add_rate;
$taxable_i = band_5;
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax5 + $tax4 + $tax3;
break;
case ($taxable_i > band_2 && $taxable_i <= band_5 ):
$diff = $taxable_i - band_2;
$tax4 = $diff * higher_rate;
$taxable_i = band_2;
$tax3 = $taxable_i * basic_rate;
$tax_payable = $tax4 + $tax3;
break;
case ($taxable_i < band_2):
$tax = $taxable_i * basic_rate;
$tax_payable = $tax;
break;
default:
$taxable_i <= band_0;
$tax_payable == 0;
break;
}
echo $tax_payable;
?>