当前位置:网站首页>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,
]);
}边栏推荐
- body有8px的神秘边距
- ANSI / nema- mw- 1000-2020 magnetic iron wire standard Latest original
- ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
- How to realize batch control? MES system gives you the answer
- 系统测试的类型有哪些,我给你介绍
- 如何让导电滑环信号更好
- Mouse event - event object
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- How mysql/mariadb generates core files
- What are the types of system tests? Let me introduce them to you
猜你喜欢

Matlab r2021b installing libsvm

SQLite3 data storage location created by Android

Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list

ClickHouse原理解析与应用实践》读书笔记(8)

Flutter 3.0框架下的小程序运行

Voice of users | winter goes and spring comes, waiting for flowers to bloom -- on gbase 8A learning comprehension

PB9.0 insert OLE control error repair tool

《ClickHouse原理解析与应用实践》读书笔记(7)

Anaconda3 download address Tsinghua University open source software mirror station

不算不知道,花呗分期的真实利率居然这么高
随机推荐
Codeforces Round #643 (Div. 2)——B. Young Explorers
MySQL数据库(2)
Remote sensing contribution experience sharing
Can you write the software test questions?
Is it necessary for project managers to take NPDP? I'll tell you the answer
碳刷滑环在发电机中的作用
ClickHouse原理解析与应用实践》读书笔记(8)
[error] error loading H5 weight attributeerror: 'STR' object has no attribute 'decode‘
cv2-drawline
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
Matlab r2021b installing libsvm
Partage d'expériences de contribution à distance
静态路由配置全面详解,静态路由快速入门指南
Exit of processes and threads
How to realize batch control? MES system gives you the answer
2022国内十大工业级三维视觉引导企业一览
CV2 read video - and save image or video
Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
Nacos microservice gateway component +swagger2 interface generation
body有8px的神秘边距