PHP最新计算个人所得税

/* PHP不使用速算扣除数计算个人所得税

   * @author 吴先成

   * @param float $salary 含税收入金额

   * @param float $deduction 保险等应当扣除的金额 默认值为0

   * @param float $threshold 起征金额 默认值为5000

   * @return float | false 返回值为应缴税金额 参数错误时返回false

  */

  function getPersonalIncomeTax($salary, $deduction=0, $threshold=5000){

    if(!is_numeric($salary) || !is_numeric($deduction) || !is_numeric($threshold)){

      return false;

    }

    if($salary <= $threshold){

      return 0;

    }

    $levels = array(3000, 12000, 25000, 35000, 55000, 80000, PHP_INT_MAX);

    $rates = array(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;

  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值