-
-
Save yizems/37f6377403fcebe68e1d4c93d9443ec1 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
// 计算公积金缴存和无限缴存 | |
//http://www.ab126.com/goju/10770.html | |
//年终奖计算方式 | |
//https://www.sohu.com/a/294643118_569711 | |
/// 年度汇算,一年收入汇算 | |
fun main() { | |
val info = InputInfo( | |
// 月收入 | |
income = 70000, | |
/// 年终奖 | |
yearEndBonus = 1000000, | |
/// 公积金 | |
cpf = 3000, | |
/// 五险, 这块计算有点复杂,建议自己按照公司缴存比例,在网上找个网站,计算下自己出了多少钱 | |
p5 = 2000, | |
/// 其他需要计算税的补助 | |
otherInTax = 1000, | |
/// 其他不用交税的收入 | |
otherNoInTax = 2000, | |
/// 附加扣除项目金额 | |
taxCut = 1500, | |
// 税率开始金额 | |
start = 5000, | |
) | |
compute(info) | |
} | |
fun compute(info: InputInfo) { | |
// 开始计算 | |
val monthInfoList = ArrayList<Month>(12) | |
(1..12).forEach { | |
// 12薪 以上的计算方式,非年终奖 | |
val moreSalary = if (it == 12 && !info.isYearEndBonus && info.yearEndBonus > 0) { | |
info.yearEndBonus | |
} else { | |
0 | |
} | |
// 需要缴税的钱 | |
val taxMoney = (info.income + info.otherInTax) * it + moreSalary - info.start * it - info.taxCut * it - (info.p5 + info.cpf / 2) * it | |
val fuckMoney = if (taxMoney < 0) { | |
0 | |
} else { | |
val taxLevel = getMonthTaxLevel(taxMoney) | |
taxMoney * taxLevel.percent / 100 - monthInfoList.sumBy { it.tax } - taxLevel.fastCut | |
} | |
monthInfoList.add(Month( | |
it, | |
fuckMoney, | |
info.income - fuckMoney - info.p5 - info.cpf / 2 + info.otherNoInTax + moreSalary, | |
)) | |
} | |
println("月份\t\t税额 \t\t 到手收入") | |
monthInfoList.forEach { | |
println(it.toString()) | |
} | |
println("----月薪信息----") | |
val monthTotal = monthInfoList.sumBy { it.netIncome } | |
println("总到手金额: $monthTotal") | |
val monthTaxTotal = monthInfoList.sumBy { it.tax } | |
println("税: $monthTaxTotal") | |
val cpfTotal = info.cpf * 12 | |
println("公积金: $cpfTotal") | |
val p5Total = info.p5 * 12 * 4 | |
println("粗算五险入账(个人缴纳的4倍,只可能多,不可能少):${p5Total}") | |
if (info.isYearEndBonus && info.yearEndBonus > 0) { | |
println("----年终奖----") | |
val yearLevel = getYearTaxLevel(info.yearEndBonus) | |
val yearTax = info.yearEndBonus * yearLevel.percent / 100 - yearLevel.fastCut | |
val realYearEnd = info.yearEndBonus - yearTax | |
println("到手:$realYearEnd") | |
println("税:${yearTax}") | |
println("----汇总----") | |
println("到手:${realYearEnd + monthTotal}") | |
println("税:${yearTax + monthTaxTotal}") | |
println("加上五险一金总收入: ${monthTotal + p5Total + cpfTotal + realYearEnd}") | |
} else { | |
println("加上五险一金总收入: ${monthTotal + p5Total + cpfTotal}") | |
} | |
} | |
/// 月薪的税率和扣除数 | |
fun getMonthTaxLevel(income: Int): TaxLevel { | |
return when { | |
income <= 36000 -> TaxLevel(3, 0) | |
income in 36001..144000 -> TaxLevel(10, 2520) | |
income in 144001..300000 -> TaxLevel(20, 16920) | |
income in 300001..420000 -> TaxLevel(25, 31920) | |
income in 420001..660000 -> TaxLevel(30, 52920) | |
income in 660001..960000 -> TaxLevel(35, 85920) | |
income > 960000 -> TaxLevel(45, 181920) | |
else -> throw IllegalArgumentException("不支持的收入数: $income") | |
} | |
} | |
// 年终奖的税率和扣除数 | |
fun getYearTaxLevel(income: Int): TaxLevel { | |
val _income: Int = income / 12; | |
return when { | |
_income <= 3000 -> TaxLevel(3, 0) | |
_income in 3001..12000 -> TaxLevel(10, 210) | |
_income in 12001..25000 -> TaxLevel(20, 1410) | |
_income in 25001..35000 -> TaxLevel(25, 2660) | |
_income in 35001..50000 -> TaxLevel(30, 4410) | |
_income in 55001..80000 -> TaxLevel(35, 7160) | |
_income > 80000 -> TaxLevel(45, 15160) | |
else -> throw IllegalArgumentException("不支持的收入数: $income") | |
} | |
} | |
/// 输入信息 | |
data class InputInfo( | |
// 月收入 | |
val income: Int, | |
/// 年终奖 | |
val yearEndBonus: Int = 0, | |
/// 公积金 | |
val cpf: Int, | |
/// 五险, 这块计算有点复杂,建议自己按照公司缴存比例,在网上找个网站,计算下自己出了多少钱 | |
val p5: Int, | |
/// 其他需要计算税的补助 | |
val otherInTax: Int, | |
/// 其他不用交税的收入 | |
val otherNoInTax: Int, | |
/// 附加扣除项目金额 | |
val taxCut: Int, | |
// 税率开始金额 | |
val start: Int, | |
// 标识 yearEndBonus 是否是年终奖, 如果不是,那么就会成为 12月份的工资一起发,个税按月薪来算,所以这个月个税特别高 | |
var isYearEndBonus: Boolean = true | |
) | |
/// 税率和速算扣除数 | |
data class TaxLevel( | |
///税率 | |
val percent: Int, | |
/// 速算扣除数 | |
val fastCut: Int, | |
) | |
/** | |
* 每个月的计算结果 | |
* @property month 月份 | |
* @property tax 税额 | |
* @property netIncome 到手钱数 | |
*/ | |
data class Month( | |
val month: Int, | |
val tax: Int, | |
val netIncome: Int, | |
) { | |
override fun toString(): String { | |
return "$month \t\t $tax \t\t $netIncome" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kotlin