PHP不使用速算扣除数计算个人所得税
2020-12-20 12:33
标签:php res += foreach 参数错误 返回 nali 计算 isset PHP不使用速算扣除数计算个人所得税 标签:php res += foreach 参数错误 返回 nali 计算 isset 原文地址:https://www.cnblogs.com/sgm4231/p/14046137.html/**
* PHP不使用速算扣除数计算个人所得税
* @param $salary float 含税收入金额
* @param int $deduction float $deduction 保险等应当扣除的金额 默认值为0
* @param int $threshold float $threshold 起征金额 默认值为5000
* @return bool|float|int float | false 返回值为应缴税金额 参数错误时返回false
*/
public static function getPersonalIncomeTax($salary, $deduction = 10, $threshold = 5000)
{
if (!is_numeric($salary) || !is_numeric($deduction) || !is_numeric($threshold)) {
return false;
}
if ($salary $threshold) {
return 0;
}
$levels = [3000, 12000, 25000, 35000, 55000, 80000, PHP_INT_MAX];
$rates = [0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45];
$taxableIncome = $salary - $threshold - $deduction;
$tax = 0;
foreach ($levels as $k => $level) {
$previousLevel = isset($levels[$k - 1]) ? $levels[$k - 1] : 0;
if ($taxableIncome $level) {
$tax += ($taxableIncome - $previousLevel) * $rates[$k];
break;
}
$tax += ($level - $previousLevel) * $rates[$k];
}
$tax = round($tax, 2);
return $tax;
}
上一篇:java 参数来带回方法运算结果
文章标题:PHP不使用速算扣除数计算个人所得税
文章链接:http://soscw.com/index.php/essay/37426.html