-
- #!/usr/bin/evn python
- # coding=utf-8
- # 2019年新税率个人所得税计算器,本脚本仅供学习
- # blog: http://www.linuxyw.com
- # author: 戴儒锋
- wages = 25000 # 税前工资
- insurance = 2000 # 五险一金
- RAX_FREE = 5000 # 每月基本减除
- supertax = 1000 # 专项减免
- # 税率
- tax_rate_dict = {36000: 0.03, 144000: 0.1, 300000: 0.2, 420000: 0.25, 660000: 0.3, 960000: 0.35, "other": 0.45}
- # 速扣
- speek_dict = {36000: 0, 144000: 210 * 12, 300000: 1410 * 12, 420000: 2660 * 12, 660000: 4410 * 12, 960000: 7160 * 12, "other": 15160 * 12}
- def payTaxFree(month):
- """计算当月应纳税额"""
- return (wages - RAX_FREE - insurance - supertax) * month
- def getMoney(month):
- """当月预扣预缴税款(基础算法)"""
- tax_free = payTaxFree(month)
- tax_rate = taxCale("tax_rate", payTaxFree(month))
- speek = taxCale("speek", payTaxFree(month))
- return tax_free * tax_rate - speek
- def ExFunc(month):
- """当月预扣预缴税款(累计减去已扣税款)"""
- sum = [0]
- def InsFunc():
- s = getMoney(month)
- if month > 1:
- sum[0] += getMoney(month - 1)
- return s - sum[0]
- return InsFunc
- def taxCale(tag, value):
- """计算税率和速扣额"""
- if tag == "tax_rate":
- value_dict = tax_rate_dict
- else:
- value_dict = speek_dict
- keys = value_dict.keys()
- keys.sort()
- for k in keys:
- if value < = k:
- return value_dict.get(k)
- return value_dict.get("other")
- def printLine(num = 50):
- print "#" * num
- def main():
- sum = 0
- printLine()
- print "你税前工资:%d,五险一金:%d, 专项减免:%d" % (wages, insurance, supertax)
- printLine()
- for month in xrange(1, 13):
- myFunc = ExFunc(month)
- final_paying_amount = wages - insurance - myFunc()
- sum += final_paying_amount
- print "%2d月份实发工资:%d, 扣税:%d" % (month, final_paying_amount, wages - insurance - final_paying_amount)
- printLine()
- print "全年到手工资累计:%d 元" % sum
- printLine()
- if __name__ == "__main__":
- main()
图示:
本脚本已在本站实现了API,可在线查看:
URL:https://wx.linuxyw.com/api/tax/
方法:get
参数:
wages:税前工资
insurance: 五险一金
supertax: 专享税
mode: 视图模式(1:简易,2:正常)
如:https://wx.linuxyw.com/api/tax/?wages=25001&insurance=4800&supertax=2400&mode=2
返回参数包括每月实发工资列表,全年累计收入
2019 年 5 月 5 日 上午 12:57 沙发
文章不错支持一下吧