当前位置:网站首页>PHP calculates personal income tax
PHP calculates personal income tax
2022-07-08 01:54:00 【Great wash】
Preface
Before using this calculation , You need to know the total amount of tax paid in that year and the amount of tax payable in this month . These two parameters need to be calculated according to their respective system data , This method only implements the individual income tax calculation algorithm . Besides , Need to open PHP Of bc Expand .
Parameters
Method passes in two parameters , The taxable amount of the current month as well as The total amount of tax paid this year ( Excluding the current month ).
- $lauwen_monthly_tax_amount: The taxable amount of the current month .
- $lauwen_taxed_amount: The total amount of tax paid in that year ( Excluding the current month ).
Realization
The first is to confirm two levels , One is the tax rate level of the total amount of tax paid this year ( Excluding the current month ), The other is the tax rate level of the total amount of tax paid this year after this month ( Including current month ); Finally, two calculation methods are used in the calculation of individual income tax , One is to calculate the tax at each tax rate level separately ; The other is to use quick calculation deduction to calculate , Just use it as needed .
Hierarchical computing core code
// Calculation by grading method
$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 --;
}Quick calculation deduction calculation core code
// Quick calculation deduction method
$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);All the code
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);
// Determine the level of the total amount of tax paid in the current year before the current month , And the level of the total amount of tax paid in the current year after the current month
$old_key = 0; // Level before the month
$new_key = 0; // Level after the month
$end_key = count($lauwen_tax_amounts) - 1;
foreach ($lauwen_tax_amounts as $key => $val) {
if ($key == $end_key) { // The last level
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;
}
}
}
// Quick calculation deduction method
$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);
// The difference method
$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,
]);
}边栏推荐
- QT build with built-in application framework -- Hello World -- use min GW 32bit
- Urban land use distribution data / urban functional zoning distribution data / urban POI points of interest / vegetation type distribution
- Sword finger offer II 041 Average value of sliding window
- 【目标跟踪】|DiMP: Learning Discriminative Model Prediction for Tracking
- If time is a river
- C语言-Cmake-CMakeLists.txt教程
- Is NPDP recognized in China? Look at it and you'll see!
- Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
- mysql/mariadb怎样生成core文件
- Tencent game client development interview (unity + cocos) double bombing social recruitment 6 rounds of interviews
猜你喜欢

Redux使用

Nmap tool introduction and common commands

滑环在直驱电机转子的应用领域

pb9.0 insert ole control 错误的修复工具

Reading notes of Clickhouse principle analysis and Application Practice (7)

如何制作企业招聘二维码?
![[SolidWorks] modify the drawing format](/img/3c/b00e4510b1e129069140c2666c0727.png)
[SolidWorks] modify the drawing format

Voice of users | understanding of gbase 8A database learning

ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版

静态路由配置全面详解,静态路由快速入门指南
随机推荐
Usage of hydraulic rotary joint
pb9.0 insert ole control 错误的修复工具
Nmap tool introduction and common commands
nmap工具介绍及常用命令
How to make the conductive slip ring signal better
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
云原生应用开发之 gRPC 入门
Cross modal semantic association alignment retrieval - image text matching
项目经理有必要考NPDP吗?我告诉你答案
The function of carbon brush slip ring in generator
如何制作企业招聘二维码?
城市土地利用分布数据/城市功能区划分布数据/城市poi感兴趣点/植被类型分布
软件测试笔试题你会吗?
Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences
common commands
CV2 read video - and save image or video
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟
Anaconda3 download address Tsinghua University open source software mirror station
微软 AD 超基础入门