Created
December 27, 2018 01:30
-
-
Save syfun/db593bdb17ad28e8f52160e10199b728 to your computer and use it in GitHub Desktop.
2019个税新算法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 保留2位小数四舍五入 | |
def round_two(value): | |
if isinstance(value, (int, float)): | |
return round(value, 2) | |
return value | |
# 校准 | |
def calibrate(func): | |
def _calibrate(*args, **kwargs): | |
return round_two(func(*args, **kwargs)) | |
return _calibrate | |
def compute_insurance_fund(base, configs): | |
return [(config[0], config[1], round_two(base * config[2]), round_two(base * config[3])) for config in configs] | |
@calibrate | |
def other_wage(other_count, month): | |
return sum([v for k, v in other_count.items() if k <= month]) | |
@calibrate | |
def tax(per_month_base, month, other_count): | |
total = per_month_base * month + other_wage(other_count, month) | |
if total <= 36000: | |
this = total * 0.03 | |
elif total <= 144000: | |
this = total * 0.1 - 2520 | |
elif total <= 300000: | |
this = total * 0.2 - 16920 | |
elif total <= 420000: | |
this = total * 0.25 - 31920 | |
elif total <= 660000: | |
this = total * 0.3 - 52920 | |
elif total <= 960000: | |
this = total * 0.35 - 85920 | |
else: | |
this = total * 0.45 - 181920 | |
if month == 1: | |
last = 0 | |
else: | |
last = sum([tax(per_month_base, i, other_count) for i in range(1, month)]) | |
return this - last | |
@calibrate | |
def wage(month, source, other_count, other_not_count, insurances, funds, free, specials): | |
count, not_count = other_count.get(month, 0), other_not_count.get(month, 0) | |
out = f'月份: {month}\n\t税前: {source}, 其他计税: {count}, 其他不计税: {not_count}\n' | |
person_insurance_fund = 0 | |
for value in insurances: | |
out += f'\t{value[1]}: 公司 {value[2]}, 个人 {value[3]}\n' | |
person_insurance_fund += value[3] | |
for value in funds: | |
out += f'\t{value[1]}: 公司 {value[2]}, 个人 {value[3]}\n' | |
person_insurance_fund += value[3] | |
per_month_base = source - person_insurance_fund - free - sum(specials) | |
t = tax(per_month_base, month, other_count) | |
after = round(source + count + not_count - person_insurance_fund - t, 2) | |
out += f'\t扣税: {t}, 税后: {after}' | |
print(out) | |
return after | |
if __name__ == '__main__': | |
# 月工资 | |
source = 15000 | |
# 五险基数 | |
insurance_base = 3054.95 | |
# 公积金基数 | |
fund_base = 15000 | |
# 免税部分 | |
free = 5000 | |
# 专项扣除 | |
specials = [] | |
insurance_configs = [ | |
# 养老保险, 公司20%, 个人8% | |
('endowment insurance', '养老保险', 0.2, 0.08), | |
# 医疗保险, 公司6%-10%, 个人2% | |
('medical insurance', '医疗保险', 0.06, 0.02), | |
# 失业保险, 公司1.5%, 个人0.5%-1% | |
('unemployment insurance', '失业保险', 0.015, 0.005), | |
# 工伤保险, 公司0.5%-1.2%, 个人无需缴纳 | |
('employment injury_insurance', '工伤保险', 0.005, 0), | |
# 生育保险, 公司0.8%, 个人无需缴纳 | |
('maternity insurance', '生育保险', 0.008, 0) | |
] | |
fund_configs = [ | |
# 公积金, 公司10%-12%, 个人10%-12% | |
('housing_provident_fund', '公积金', 0.12, 0.12) | |
] | |
# 每个月其他计税部分 | |
other_count = { | |
1: 0, | |
2: 0, | |
3: 0, | |
4: 0, | |
5: 0, | |
6: 0, | |
7: 0, | |
8: 0, | |
9: 0, | |
10: 0, | |
11: 0, | |
12: 0 | |
} | |
# 每个月其他不计税部分 | |
other_not_count = { | |
1: 300, | |
2: 300, | |
3: 300, | |
4: 300, | |
5: 300, | |
6: 300, | |
7: 300, | |
8: 300, | |
9: 300, | |
10: 300, | |
11: 300, | |
12: 300 | |
} | |
insurances = compute_insurance_fund(insurance_base, insurance_configs) | |
funds = compute_insurance_fund(fund_base, fund_configs) | |
months = [wage(m, source, other_count, other_not_count, insurances, funds, free, specials) for m in range(1, 13)] | |
print(f'\n总收入: {sum(months)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment