个人所得税计算


tax_table = [
[0, 36000, 3],
[36000, 144000, 10],
[144000, 300000, 20],
[300000, 420000, 25],
[420000, 660000,30],
[660000,960000,35],
[960000,999999999999, 45],
]

def get_tax_rate(p):
    tax_rate = 45
    for i in range(len(tax_table)):
        if tax_table[i][0] < p and p < tax_table[i][1]:
            tax_rate = tax_table[i][2]
            break
    return tax_rate/100

def get_next_tax_stage(p):
    next_stage = 36000
    for i in range(len(tax_table)):
        if p < tax_table[i][1]:
            next_stage = tax_table[i][1]
            break
    return next_stage

def calc_one_year_tax(month_get, wuxianyijin=3800):
    tax_start = 5000
    tax_sum = 0
    should_tax_sum = 0
    one_month_should_tax = 0
    one_month_tax = 0
    total_one_year_get = 0

    for i in range(12):
        one_month_should_tax = max(0, month_get-wuxianyijin-tax_start)

        last_month_tax_rate = get_tax_rate(should_tax_sum)
        now_month_tax_rate = get_tax_rate(should_tax_sum+one_month_should_tax)

        # 这个月份的应纳税部分有两个阶段的话
        if now_month_tax_rate-last_month_tax_rate>0.00001:
            next_stage = get_next_tax_stage(should_tax_sum)
            last_stage_should_tax = next_stage - should_tax_sum
            now_stage_should_tax = should_tax_sum+one_month_should_tax-next_stage
            one_month_tax = last_stage_should_tax*last_month_tax_rate+now_stage_should_tax*now_month_tax_rate
        else:
            one_month_tax = one_month_should_tax*now_month_tax_rate
        print("第{0}个月的税收:{1}".format(i+1, one_month_tax))
        tax_sum += one_month_tax
        total_one_year_get += (month_get-wuxianyijin-one_month_tax)
        should_tax_sum += one_month_should_tax
    average_one_month_get = total_one_year_get/12
    average_one_month_tax = tax_sum/12
    print("每月工资:{0}".format(month_get))
    print("每月五险一金总额:{0}".format(wuxianyijin))
    print("一年实际总收入:{0}".format(total_one_year_get))
    print("一年实际税收总额:{0}".format(tax_sum))
    print("平均每月收入:{0}".format(average_one_month_get))
    print("平均每月税收:{0}".format(average_one_month_tax))


if __name__ == '__main__':
    month_get = 25000
    # month_get = 30000
    tax_sum = calc_one_year_tax(month_get)

文章目录