累积计税法:算一算您一年缴了多少个税

前提:

上海、2021年的社保上限基数:31014, 个人缴费比例为10.5%(其中,社保8%,医疗生育2%, 失业0.5%)。 不考虑是每年中旬才调整的这个基数,我们就当全年都按照这个基数,来计算一下你的个人所得税,也不考虑年终奖金、股票等。

首先奉上结果:
在这里插入图片描述


Python代码如下所示:

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') #新建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  #水平方向
    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 #自动换行

    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 = [
    "年薪","社保公积金共计缴纳","共计交税","税后总收入"
]
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("年薪:%s" % str(salary))
    print("社保公积金共计缴纳:%s" % str(insurance))
    
    
    taxable_income = salary - insurance - 5000 * 12
    if taxable_income < 0:
        taxable_income = 0
    #print("需要纳税总额度:%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("共计缴纳税:%s" % str(tax))
    after_tax = salary - tax - insurance
    print("税后总收入:%s" % str(after_tax))
    print("%s\t%s\t%s\t%s" %(str(salary), str(insurance), str(tax), str(after_tax)))
    
    user["年薪"] = str(salary)
    user["社保公积金共计缴纳"] = str(insurance)
    user["共计交税"] = str(tax)
    user["税后总收入"] = 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)

配置表:

{
	"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 交金基数和比例
2021个人所得税新税率表
在这里插入图片描述

在这里插入图片描述

前提:2021年,上海的社保公积金上限是31014,假设你的年薪都按照工资计税,不按年终奖计税。
1、如果您2021年是100W的薪资,那么今年社保公积金缴纳了接近4W,你的个税缴纳了25W。,一年到手71w
2、如果您2021年是80W的薪资,那么今年社保公积金缴纳了接近4W,你的个税缴纳了17.5W,一年到手58.5w
3、如果您2021年是60W的薪资,那么今年社保公积金缴纳了接近4W,你的个税缴纳了11.5W,一年到手43.5w
4、如果您2021年是40W的薪资,那么今年社保公积金缴纳了接近4W,你的个税缴纳了5.8W,一年到手30.2w

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码改变世界ctw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值