当前位置:网站首页>Cumulative tax law: calculate how much tax you have paid in a year
Cumulative tax law: calculate how much tax you have paid in a year
2022-06-13 02:12:00 【Code changes the world CTW】
Premise :
Shanghai 、2021 Social security ceiling base in :31014, The proportion of individual payment is 10.5%( among , social security 8%, Medical fertility 2%, unemployment 0.5%). It does not take into account that the base is adjusted only in the middle of each year , We should use this base for the whole year , To calculate your personal income tax , Don't consider the year-end bonus 、 Stocks, etc .
First of all, I would like to present the results :
Python The code is as follows :
import sys
import os
import shutil
import time
import random
import subprocess
import getopt
import json
import xlrd
import xlwt
def get_config():
with open('table.cfg', 'r') as f:
return json.load(f)
config = get_config()
percent = config["social_insurance"]["shanghai"]["2021"]["percent"]
base_limit = config["social_insurance"]["shanghai"]["2021"]["base_limit"]
tax_stages = config["tax_stage"]
tax_rates = config["tax_rate"]
reductions = config["reduction"]
def create_sheet(f,table_name,try_count):
if try_count <= 1:
return
try:
sheet1 = f.add_sheet(table_name + '-' + str(11 - try_count),cell_overwrite_ok=True)
return sheet1
except Exception as e:
return create_sheet(f,table_name,try_count-1)
def create_a_new_excel(excel_path,table_name,title_name,use_lists):
table1_invalid_start_x = 1;
table1_invalid_start_y = 2;
max_buf_len = []
if os.path.exists(excel_path):
os.remove(excel_path)
f = xlwt.Workbook(encoding='utf-8') # newly build excel
font = xlwt.Font()
font.bold = True
borders = xlwt.Borders()
borders.left = xlwt.Borders.THIN
borders.right = xlwt.Borders.THIN
borders.top = xlwt.Borders.THIN
borders.bottom = xlwt.Borders.THIN
alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_CENTER # horizontal direction
alignment.vert = xlwt.Alignment.VERT_TOP
style1 = xlwt.XFStyle()
style1.font = font
#style1.borders = borders
style1.alignment = alignment
style2 = xlwt.XFStyle()
style2.alignment.wrap = 1 # Word wrap
try:
sheet1 = f.add_sheet(table_name,cell_overwrite_ok=True)
except Exception as e:
sheet1 = create_sheet(f,table_name,10)
for item in range(0, len(title_name)):
sheet1.write(1, item+table1_invalid_start_x, title_name[item],style=style1)
max_buf_len.append(len(title_name[item]))
sheet1.col(1).width = 256 * (max_buf_len[item])
item = 0
column_len = len(title_name)
for use_list in use_lists:
for column_index in range(0, column_len):
if len(use_list[title_name[column_index]]) > max_buf_len[column_index]:
max_buf_len[column_index] = len(use_list[title_name[column_index]])
if max_buf_len[column_index] > 150:
max_buf_len[column_index] = 150
sheet1.col(column_index+table1_invalid_start_x).width = 256 * (max_buf_len[column_index] + 3)
sheet1.write(table1_invalid_start_y + item, column_index+table1_invalid_start_x, use_list[title_name[column_index]],style2)
item += 1
f.save(excel_path)
test_title = [
" Annual salary "," The social security accumulation fund is paid in total "," Total taxes paid "," Total after tax income "
]
user = {
}
test_use_list = [
]
def calculate_tax(salary): #salary year
if salary / 12 > base_limit:
base = base_limit
else:
base = salary / 12
insurance= base * 12 * percent / 100
print(" Annual salary :%s" % str(salary))
print(" The social security accumulation fund is paid in total :%s" % str(insurance))
taxable_income = salary - insurance - 5000 * 12
if taxable_income < 0:
taxable_income = 0
#print(" The total amount of tax to be paid :%s" % str(taxable_income))
i = 0
for tax_stage in tax_stages:
if taxable_income < tax_stage:
break
i = i + 1
tax = taxable_income * tax_rates[i] / 100 - reductions[i]
print(" Total taxes paid :%s" % str(tax))
after_tax = salary - tax - insurance
print(" Total after tax income :%s" % str(after_tax))
print("%s\t%s\t%s\t%s" %(str(salary), str(insurance), str(tax), str(after_tax)))
user[" Annual salary "] = str(salary)
user[" The social security accumulation fund is paid in total "] = str(insurance)
user[" Total taxes paid "] = str(tax)
user[" Total after tax income "] = str(after_tax)
test_use_list.append(user.copy())
if __name__ == '__main__':
print(str(sys.argv[0]) + " enter")
curdir = os.getcwd()
for i in range(6,101): # 6-100w
salary = i * 10000
calculate_tax(salary)
for i in range(1,51): # 110w - 500w
salary = i*100000 + 1000000
calculate_tax(salary)
print(test_use_list)
s_name = "1.xls"
create_a_new_excel(s_name,"table1",test_title, test_use_list)
Configuration table :
{
"social_insurance":
{
"shanghai":
{
"2021":
{
"percent":10.5,
"base_limit":31014
}
}
},
"tax_stage":
[
36000,
144000,
300000,
420000,
660000,
960000
],
"tax_rate":[3,10,20,25,30,35,45],
"reduction":
[
0,2520,16920,31920,52920,85920,181920
]
}
(backup)
2021 Base and proportion of payment
2021 New personal income tax rate table 

Premise :2021 year , The upper limit of social security accumulation fund in Shanghai is 31014, Suppose your annual salary is taxed according to your salary , Tax is not calculated according to the year-end bonus .
1、 If you 2021 Year is 100W Pay for , So this year, the social security accumulation fund has been paid close to 4W, Your personal income tax has been paid 25W., In a year 71w
2、 If you 2021 Year is 80W Pay for , So this year, the social security accumulation fund has been paid close to 4W, Your personal income tax has been paid 17.5W, In a year 58.5w
3、 If you 2021 Year is 60W Pay for , So this year, the social security accumulation fund has been paid close to 4W, Your personal income tax has been paid 11.5W, In a year 43.5w
4、 If you 2021 Year is 40W Pay for , So this year, the social security accumulation fund has been paid close to 4W, Your personal income tax has been paid 5.8W, In a year 30.2w
边栏推荐
- Basic exercises of test questions Fibonacci series
- Application and routine of C language typedef struct
- Test questions basic exercise 01 string
- Solution of depth learning for 3D anisotropic images
- Basic exercises of test questions letter graphics ※
- Stm32 mpu6050 servo pan tilt support follow
- JS get element
- Day 1 of the 10 day smart lock project (understand the SCM stm32f401ret6 and C language foundation)
- 【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records
- Rsync transport exclusion directory
猜你喜欢

(novice to) detailed tutorial on machine / in-depth learning with colab from scratch

Ruixing coffee 2022, extricating itself from difficulties and ushering in a smooth path

Get started quickly cmake

Use of Arduino series pressure sensors and detected data displayed by OLED (detailed tutorial)

Vivo released originos ocean, and the domestic customized system is getting better and better

如何解决通过new Date()获取时间写出数据库与当前时间相差8小时问题【亲测有效】

Installing Oracle with docker for Mac

Vscode configuration header file -- Take opencv and its own header file as an example

【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records

Learning notes 51 single chip microcomputer keyboard (non coding keyboard and coding keyboard, scanning mode of non coding keyboard, independent keyboard, matrix keyboard)
随机推荐
Learning notes 51 single chip microcomputer keyboard (non coding keyboard and coding keyboard, scanning mode of non coding keyboard, independent keyboard, matrix keyboard)
[work notes] the problem of high leakage current in standby mode of dw7888 motor driver chip
Ten thousand words make it clear that synchronized and reentrantlock implement locks in concurrency
[learning notes] xr872 audio driver framework analysis
华为设备配置私网IP路由FRR
cin,cin. get(),cin. Summary of the use of getline() and getline()
STM32F103 IIC OLED program migration complete engineering code
Ruixing coffee moves towards "national consumption"
[pytorch]fixmatch code explanation - data loading
Laptop touch pad operation
[analysis notes] source code analysis of siliconlabs efr32bg22 Bluetooth mesh sensorclient
Detailed explanation of C language conditional compilation
Yovo3 and yovo3 tiny structure diagram
记录:如何解决MultipartFile类的transferTo()上传图片报“系统找不到指定的路径“问题【亲测有效】
Opencv camera calibration (2): fish eye camera calibration
Use of Arduino series pressure sensors and detected data displayed by OLED (detailed tutorial)
Test questions basic exercise 01 string
Basic exercise of test questions Yanghui triangle (two-dimensional array and shallow copy)
(novice to) detailed tutorial on machine / in-depth learning with colab from scratch
Application and routine of C language typedef struct