是否有人可以帮助我为我们的Office员工工资税表创建PHP或mysql代码。 这是我们税收监管的基础。
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
答案 0 :(得分:2)
function get_taxed_salary($salary){
if ($salary <= 150 ){
return $salary;
};
if ($salary <= 650){
return ( 0.9 * $salary - 15.0 );
};
...
}
稍后在您的代码中使用该函数,如:
$taxed_salary = get_taxed_salary($salary);
答案 1 :(得分:2)
在大多数国家,这不是税收的方式 - 根据您的收入,您不需要缴纳一定比例的税款。如果是这种情况,那么工资高于税率的人的税后净收入会低于税率范围内的人。
它是如何运作的:您为每个税收范围内的收入的每个部分按不同的百分比纳税。因此,如果您的收入为11,000美元且税率从0到10,000,另一个从10,000到20,000,那么第一个10k的收入将按照第一个包括的税率征税,其余的1k将按第二个税率的较高税率征税。支架
以这种方式计算税收的代码:
//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";
?>
答案 2 :(得分:1)
你应该学习基本的PHP。解决方案很简单。
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;
}
编辑:感谢Constantin的功能提醒
答案 3 :(得分:-1)
检查这个,PHP中的逻辑和的Perl。
function calc_tax($salary) {
$params = array(array(5001,662.50), array(3551,412.5), array(2351,235.00), array(1401,117.50), array(651,47.50), array(151,15.00), array(0,0));
foreach ($params as $p) {
if($salary >= $p[0]) {
return $p[1];
}
}
return 0;
}
foreach (array(100,150,3500,8900) as $sal) {
echo $sal."==".calc_tax($sal)."\n";
}
的Perl:
sub calc_tax {
my $sal = shift;
my @params = ( [ 5001, 662.50 ], [ 3551, 412.5 ], [ 2351, 235.00 ], [ 1401, 117.50 ], [ 651, 47.50 ], [ 151, 15.00 ], [ 0, 0 ] );
foreach $p (@params) {
if ( $sal >= $p->[0] ) {
return $p->[1];
}
}
return 0;
}
foreach my $sal (qw[160 3200 8900]) {
print $sal,"==",calc_tax($sal),"\n";
}