当前位置:网站首页>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,
]);
}
边栏推荐
- Kafka connect synchronizes Kafka data to MySQL
- [SolidWorks] modify the drawing format
- 快速熟知XML解析
- 【目标跟踪】|atom
- common commands
- 电路如图,R1=2kΩ,R2=2kΩ,R3=4kΩ,Rf=4kΩ。求输出与输入关系表达式。
- Version 2.0 de tapdata, Open Source Live Data Platform est maintenant disponible
- Urban land use distribution data / urban functional zoning distribution data / urban POI points of interest / vegetation type distribution
- 从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
- ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
猜你喜欢
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
Working principle of stm32gpio port
《ClickHouse原理解析与应用实践》读书笔记(7)
[target tracking] |atom
Get familiar with XML parsing quickly
很多小伙伴不太了解ORM框架的底层原理,这不,冰河带你10分钟手撸一个极简版ORM框架(赶快收藏吧)
进程和线程的退出
Sum of submatrix
nmap工具介绍及常用命令
Introduction to grpc for cloud native application development
随机推荐
微信小程序uniapp页面无法跳转:“navigateTo:fail can not navigateTo a tabbar page“
CV2 read video - and save image or video
QT build with built-in application framework -- Hello World -- use min GW 32bit
Exit of processes and threads
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
What kind of MES system is a good system
common commands
Is it safe to open an account on your mobile phone for small amount of stock speculation?
腾讯游戏客户端开发面试 (Unity + Cocos) 双重轰炸 社招6轮面试
Break algorithm --- map
Kafka connect synchronizes Kafka data to MySQL
软件测试笔试题你会吗?
ClickHouse原理解析与应用实践》读书笔记(8)
《ClickHouse原理解析与应用实践》读书笔记(7)
C language - modularization -clion (static library, dynamic library) use
DataWorks值班表
MySQL查询为什么没走索引?这篇文章带你全面解析
Working principle of stm32gpio port
PHP to get information such as audio duration
body有8px的神秘边距