function income_tax(val){
start=625.01;
tax=0;
incr=5.0;
tax_add=0.50;
itax=array("0"=>"0");
boundary=1455;
for(i=start;i<=boundary;i+=incr){
itax=tax;
tax+=tax_add;
}
start=1455.01;
tax=83.33;
incr=5;
tax_add=0.75;
boundary=2288;
for(i=start;i<=boundary;i+=incr){
itax=tax;
tax+=tax_add;
}
start=2288.01;
tax=208.67;
tax_add=1;
boundary=3123;
incr=5;
for(i=start;i<=boundary;i+=incr){
itax=tax;
tax+=tax_add;
}
start=3123.01;
tax=375.83;
incr=5;
tax_add=1.25;
boundary=3958;
for(i=start;i<=boundary;i+=incr){
itax=tax;
tax+=tax_add;
}
last='0';
foreach(itax as amount => tax){
if(val<amount){
tax=itax[last];
break;
}
last=amount;
}
return itax[last];
}
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
tax[round(625.01,1,'<')] may be valid expressions, but not tax[625.01]
Furthermore it is not clear for me, what the statement
itax=array("0"=>"0");
means.
Perhaps you should give some information about the programming language.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I think, the best way to implement this kind of calculation in NAV is to use some table (tax table) with the fields "Taxable Amount min." and "Income Tax Amount" and may be "Year" (This has the advantage to have a history if the calculation formulas change and on the other hand, the calculation is more transparent, because you can check the result by simply taking a look at the table). Primary key would be "Year" + "Taxable Amount min." - To find the tax, you simply have to put a filter on "Taxable Amount min." (and may be "Year" of course)
SETFILTER("Taxable Amount min.",'..%1',val) and find the last record. In order to create the tax table once a year, you may use some parts of the original code.