Created
October 16, 2018 07:06
-
-
Save zeayes/1698a7d99f097a4226b6995a8f3a7c5d to your computer and use it in GitHub Desktop.
新旧版个税计算
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
# -*- coding: utf-8 -*- | |
import sys | |
# 旧版个税表 | |
# 应税工资,税率,速算扣除额度,最少缴税额度 | |
old_table = [ | |
(3500, 0.03, 0, 0), # | |
(5000, 0.1, 105, 45), | |
(8000, 0.2, 555, 345), | |
(12500, 0.25, 1005, 1245), | |
(38500, 0.3, 2755, 7745), | |
(58500, 0.35, 5505, 13745), | |
(83500, 0.45, 13505, 22495) | |
] | |
# 新版个税表 | |
new_table = [ | |
(5000, 0.03, 0, 0), | |
(8000, 0.1, 210, 90), | |
(17000, 0.2, 1410, 990), | |
(30000, 0.25, 2660, 3590), | |
(40000, 0.3, 4410, 6090), | |
(60000, 0.35, 7160, 12090), | |
(85000, 0.45, 15160, 20840) | |
] | |
def get_tax_by_incoming(incoming, is_new): | |
''' 通过应税工资计算出个税值 ''' | |
table, base = (new_table, 5000) if is_new else (old_table, 3500) | |
# 个税起征点 | |
if incoming <= base: | |
return 0 | |
for index in range(len(table)): | |
before, after = table[index], (table[index + 1][0] if index < len(table) - 1 else sys.maxsize) | |
if before[0] <= incoming < after: | |
return (incoming - base) * before[1] - before[2] | |
continue | |
def get_incoming_by_tax(tax, is_new): | |
''' 通过个税值计算出应税工资 ''' | |
table, base = (new_table, 5000) if is_new else (old_table, 3500) | |
for index in range(len(table)): | |
before, after = table[index], (table[index + 1][3] if index < len(table) - 1 else sys.maxsize) | |
if before[3] <= int(tax) < after: | |
return (tax + before[2]) / before[1] + base | |
def diving_tax(tax): | |
current, delta = None, None | |
for i in range(1, 10, 1): | |
old = get_incoming_by_tax(i * tax / 10, False) | |
new = get_incoming_by_tax((10 - i) * tax / 10, True) | |
if delta is None or delta > abs(new - old): | |
delta = abs(new - old) | |
current = (old, i * tax / 10, new, (10 - i) * tax / 10) | |
return current | |
if __name__ == "__main__": | |
for incoming in [3500, 5000, 8000, 12500, 38500, 58500, 83500]: | |
tax = get_tax_by_incoming(incoming, False) | |
inc = get_incoming_by_tax(tax, False) | |
print(incoming, tax, int(inc) == incoming) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment