Last active
January 29, 2019 10:51
-
-
Save lsongdev/c34b0a38126cb993cbc5d0b8581203e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const beijing = { | |
social_fund: { | |
min: 2820, | |
max: 14096, | |
// rate: .105 | |
rate: { | |
medical: .02, | |
endowment: .08, | |
unemployment: .005 | |
} | |
}, | |
accumulation_fund: { | |
min: 2010, | |
max: 24311, | |
rate: .12 | |
}, | |
table: [ | |
{ level: 1, min: 0, max: 36000, rate: 0.03, quickCalculateDeducting: 0 }, | |
{ level: 2, min: 36000, max: 144000, rate: 0.10, quickCalculateDeducting: 2520 }, | |
{ level: 3, min: 144000, max: 300000, rate: 0.20, quickCalculateDeducting: 16920 }, | |
{ level: 4, min: 300000, max: 420000, rate: 0.25, quickCalculateDeducting: 31920 }, | |
{ level: 5, min: 420000, max: 660000, rate: 0.30, quickCalculateDeducting: 52920 }, | |
{ level: 6, min: 660000, max: 960000, rate: 0.35, quickCalculateDeducting: 85920 }, | |
{ level: 7, min: 960000, max: Infinity, rate: 0.45, quickCalculateDeducting: 181920 }, | |
] | |
}; | |
const range = (v, { min, max }) => { | |
return Math.min(Math.max(v, min), max); | |
}; | |
const inRange = (v, rule) => { | |
return (v > rule.min && v <= rule.max) && rule; | |
}; | |
const calcSocialfund = (money, profile = beijing.social_fund) => { | |
const { rate } = profile; | |
const base = range(money, profile); | |
const medical = base * rate.medical; | |
const endowment = base * rate.endowment; | |
const unemployment = base * rate.unemployment; | |
return { | |
base, | |
money, | |
medical, | |
endowment, | |
unemployment, | |
patTax: medical + endowment + unemployment | |
}; | |
}; | |
const calcAccumulationFund = (money, profile = beijing.accumulation_fund) => { | |
const { rate } = profile; | |
const base = range(money, profile); | |
return { | |
base, | |
money, | |
patTax: base * rate | |
}; | |
}; | |
const taxRate = ({ | |
salary, | |
deducted = 5000, | |
specialDeducted, | |
sixSpecialDeducted | |
}, profile) => { | |
const { table } = profile; | |
specialDeducted = specialDeducted || [ | |
calcSocialfund(salary), | |
calcAccumulationFund(salary) | |
].reduce((a,b) => a+b.patTax, 0); | |
const byMonth = month => { | |
const x | |
= (salary * month) | |
- (deducted * month) | |
- (specialDeducted * month) | |
- (sixSpecialDeducted * month); | |
const rule = table.find(rule => inRange(x, rule)); | |
var historyAmount = 0; | |
if(month > 1){ | |
historyAmount = [...new Array(month - 1)] | |
.reduce((amount, _, i) => amount + byMonth(i+1), 0); | |
} | |
return x * rule.rate - rule.quickCalculateDeducting - historyAmount; | |
}; | |
return byMonth; | |
}; | |
const calc = taxRate({ | |
salary: 38060, | |
// deducted: 5000, | |
// specialDeducted: 4500, | |
sixSpecialDeducted: 2000, | |
}, beijing); | |
const months = [...Array(12).keys()].map(m => m + 1); | |
months.forEach(month => { | |
console.log('=>', month, calc(month)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment