当前位置:网站首页>PHP 计算个人所得税
PHP 计算个人所得税
2022-07-08 00:15:00 【棒洗啦】
前言
使用此种计算方式前,需要知道当年已纳税总额度以及本月应纳税额度。这两个参数需要自行根据各自系统数据计算出来,此方法只实现个税计算算法。此外,需要打开PHP的bc扩展。
参数
方法传入两个参数即可,当月应纳税额度以及本年已纳税总额度(不含当月)。
- $lauwen_monthly_tax_amount:当月应纳税额度。
- $lauwen_taxed_amount:当年已纳税总额度(不含当月)。
实现
首先是确认两个层级,一个是本年已纳税总额度所在税率层级(不含当月),另一个是本月之后本年已纳税总额度所在税率层级(含当月);最后在计算个税时使用了两种计算方式,一种是分别计算在每个税率层级的税额;另一种是使用速算扣除数进行计算,按需使用就好。
分级计算核心代码
// 分级法计算
$tax = '0';
while ($new_key >= $old_key) {
$level_amount = bcsub($lauwen_month_after_amount, $lauwen_tax_amounts[$new_key], 6);
if ($new_key == $old_key) {
$level_amount = bcsub($lauwen_month_after_amount, $lauwen_taxed_amount, 6);
}
$tax = bcadd($tax, bcmul($level_amount, $lauwen_tax_rates[$new_key]), 2);
$lauwen_month_after_amount = $lauwen_tax_amounts[$new_key];
$new_key --;
}
速算扣除计算核心代码
// 速算扣除法计算
$quickly_old_tax = bcsub(bcmul($lauwen_taxed_amount, $lauwen_tax_rates[$old_key], 6), $lauwen_tax_quickly[$old_key], 6);
$quickly_new_tax = bcsub(bcmul($lauwen_month_after_amount, $lauwen_tax_rates[$new_key], 6), $lauwen_tax_quickly[$new_key], 6);
$tax0 = bcsub($quickly_new_tax, $quickly_old_tax, 2);
全部代码
function personTax($lauwen_monthly_tax_amount, $lauwen_taxed_amount) {
$lauwen_tax_amounts = ['0', '36000', '144000', '300000', '420000', '660000', '960000'];
$lauwen_tax_rates = ['0.03', '0.1', '0.2', '0.25', '0.3', '0.35', '0.45'];
$lauwen_tax_quickly = ['0', '2520', '16920', '31920', '52920', '85920', '181920'];
$lauwen_taxed_amount = (string)$lauwen_taxed_amount;
$lauwen_monthly_tax_amount = (string)$lauwen_monthly_tax_amount;
$lauwen_month_after_amount = bcadd($lauwen_taxed_amount, $lauwen_monthly_tax_amount, 6);
// 确定当月前当年已纳税总额度所属级别,以及当月之后当年已纳税总额度所属级别
$old_key = 0; // 当月前级别
$new_key = 0; // 当月后级别
$end_key = count($lauwen_tax_amounts) - 1;
foreach ($lauwen_tax_amounts as $key => $val) {
if ($key == $end_key) { // 最后一级
if (bccomp($lauwen_taxed_amount, $val, 2) == 1) {
$old_key = $key;
}
if (bccomp($lauwen_month_after_amount, $val, 2) == 1) {
$new_key = $key;
}
} else { //
if (bccomp($lauwen_taxed_amount, $val, 2) == 1 && bccomp($lauwen_taxed_amount, $lauwen_tax_amounts[$key+1], 2) == -1) {
$old_key = $key;
}
if (bccomp($lauwen_month_after_amount, $val, 2) == 1 && bccomp($lauwen_month_after_amount, $lauwen_tax_amounts[$key+1], 2) == -1) {
$new_key = $key;
break;
}
}
}
// 速算扣除法计算
$quickly_old_tax = bcsub(bcmul($lauwen_taxed_amount, $lauwen_tax_rates[$old_key], 6), $lauwen_tax_quickly[$old_key], 6);
$quickly_new_tax = bcsub(bcmul($lauwen_month_after_amount, $lauwen_tax_rates[$new_key], 6), $lauwen_tax_quickly[$new_key], 6);
$tax0 = bcsub($quickly_new_tax, $quickly_old_tax, 2);
// 差额法计算
$tax = '0';
while ($new_key >= $old_key) {
$level_amount = bcsub($lauwen_month_after_amount, $lauwen_tax_amounts[$new_key], 6);
if ($new_key == $old_key) {
$level_amount = bcsub($lauwen_month_after_amount, $lauwen_taxed_amount, 6);
}
$tax = bcadd($tax, bcmul($level_amount, $lauwen_tax_rates[$new_key]), 2);
$lauwen_month_after_amount = $lauwen_tax_amounts[$new_key];
$new_key --;
}
return json_encode([
"normal" => $tax,
"quickly" => $tax0,
]);
}
边栏推荐
- Codeforces Round #649 (Div. 2)——A. XXXXX
- common commands
- Version 2.0 of tapdata, the open source live data platform, has been released
- Gnuradio3.9.4 create OOT module instances
- The numerical value of the number of figures thought of by the real-time update of the ranking list
- Redux使用
- COMSOL - Construction of micro resistance beam model - final temperature distribution and deformation - establishment of geometric model
- 生态 | 湖仓一体的优选:GBase 8a MPP + XEOS
- Different methods for setting headers of different pages in word (the same for footer and page number)
- 滑环在直驱电机转子的应用领域
猜你喜欢
Gnuradio3.9.4 create OOT module instances
Understanding of maximum likelihood estimation
Remote Sensing投稿经验分享
Kindle operation: transfer downloaded books and change book cover
SQLite3 data storage location created by Android
The beauty of Mathematics -- the principle of fine Fourier transform
Anaconda3 download address Tsinghua University open source software mirror station
Voice of users | winter goes and spring comes, waiting for flowers to bloom -- on gbase 8A learning comprehension
Sword finger offer II 041 Average value of sliding window
3、多智能体强化学习
随机推荐
Codeforces Round #649 (Div. 2)——A. XXXXX
Euler Lagrange equation
Redis cluster
powerbuilder 中使用线程的方法
日志特征选择汇总(基于天池比赛)
Gnuradio3.9.4 create OOT module instances
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
qt--將程序打包--不要安裝qt-可以直接運行
Introduction to grpc for cloud native application development
Capability contribution three solutions of gbase were selected into the "financial information innovation ecological laboratory - financial information innovation solutions (the first batch)"
The numerical value of the number of figures thought of by the real-time update of the ranking list
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
C语言-模块化-Clion(静态库,动态库)使用
SQLite3 data storage location created by Android
Understanding of prior probability, posterior probability and Bayesian formula
第七章 行为级建模
Chapter 7 behavior level modeling
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos