根据到手工资计算税前工资

计算税前工资

累加计税,指定税后(到手)工资,支持五险一金和附加扣除每月定制、中间离职再入职等情况,误差控制在1元内。

代码:

import openpyxl

def calculate_tax(taxable_income, year_tax):
    result = 0.00
    if taxable_income <= 36000.00:
        result = taxable_income * 0.03 - year_tax
    elif taxable_income <= 144000.00:
        result = taxable_income * 0.10 - 2520.00 - year_tax
    elif taxable_income <= 300000.00:
        result = taxable_income * 0.20 - 16920.00 - year_tax
    elif taxable_income <= 420000.00:
        result = taxable_income * 0.25 - 31920.0 - year_tax
    elif taxable_income <= 660000.00:
        result = taxable_income * 0.30 - 52920.0 - year_tax
    elif taxable_income <= 960000.00:
        result = taxable_income * 0.35 - 85920.0 - year_tax
    return max(result-0.10, 0.00)

# keep origin data(include formula)
origin_workbook = openpyxl.load_workbook('/home/zyd/file/excel/税前工资计算.xlsx')
origin_sheet = origin_workbook['05']
# read numerical value
workbook = openpyxl.load_workbook('/home/zyd/file/excel/税前工资计算.xlsx', data_only=True)
sheet = workbook['05']
for row in sheet.iter_rows():
    row_index = row[0].row
    # skip headline
    if row_index < 2 or row[1].value is None:
        continue
    # read necessary data
    month_salary_after_tax = row[2].value
    year_salary_before_tax = row[3].value
    month_count = row[4].value
    year_social_insurance = row[5].value
    month_social_insurance = row[6].value
    year_special_deduction = row[7].value
    month_special_deduction = row[8].value
    year_tax = row[9].value
    # start from 5000.00
    month_salary_before_tax = 5000.00
    basic_salary = 5000.00
    year_taxable_income = year_salary_before_tax - basic_salary*month_count - year_social_insurance - month_social_insurance - year_special_deduction - month_special_deduction
    tax = calculate_tax(year_taxable_income+month_salary_before_tax, year_tax)
    # check until reach the condition
    while month_salary_before_tax - tax - month_social_insurance - month_salary_after_tax < -1.00:
        month_salary_before_tax += 2.00
        tax = calculate_tax(year_taxable_income+month_salary_before_tax, year_tax)
    # set the tax
    origin_sheet.cell(row_index, 11, tax)
# save the result
origin_workbook.save('/home/zyd/file/excel/税前工资计算.xlsx')
origin_workbook.close()
workbook.close()

表格数据示例(五月开始入职):
在这里插入图片描述excel文件下载地址:
https://download.csdn.net/download/chunzhenzyd/87817773

验证:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值