个税计算器-springboot版实现

年关将至,该到了发年终奖的时候了。所以就到网上去找下,个税计算器,但是发现做的有点像病毒网站似的。所以计算结果也不太敢信,于是琢磨着,要不自己动手写一个个税计算器吧。

说干就干,先上国家税务局了解了下个税计算的公式,说简单也简单说复杂也复杂,个税计算,分几个种类:

1、综合税率表

一般来说,我们员工的工资就按这个税率表来计算。

2、经营所得

这个应该是个体工商户类的适用

3、劳务报酬

这个一般适用于,比如有个兼职,外包等,如果要纳税,就按这个税率表。

这个是2018年最新的个税税率,现在统一按5000元起征,也就是收入在5000元以下,是不用纳税的。

项目采用springboot开发,非常容易上手。

计算规则的代码:

   /**
     * 计算个人所得税
     * www.xcc.cn 版权所有
     * @param minusAmount 扣除社保的金额
     * @param minusAmount2 当月工资(扣除社保后)(算年终奖)
     * @param salaryType 收入类型
     * @param minimumAmount 个税基数,5000
     * */
    public GeshuiDto calc(double originAmount, double minusAmount, double minusAmount2, String salaryType, int minimumAmount) {
        GeshuiDto dto = new GeshuiDto();
        dto.originAmount = originAmount;
        dto.minusAmount = minusAmount;
        dto.taxAmount = 0;
        dto.finalAmount = 0;
        
        if(originAmount == 0){
            return dto;
        }
        
        //工资、薪金所得
        if(Objects.equal("1", salaryType)){
            double balanceAmount = BigDecimal.valueOf(originAmount)
                    .subtract(BigDecimal.valueOf(minusAmount))
                    .subtract(BigDecimal.valueOf(minimumAmount)).doubleValue();
            dto.balanceAmount = balanceAmount;
            if(minimumAmount == 5000) {
                if(balanceAmount >0 && balanceAmount <=3000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.03)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                }
                if(balanceAmount >3000 && balanceAmount <=12000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(210)).doubleValue();
                }
                if(balanceAmount >12000 && balanceAmount <=25000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(1410)).doubleValue();
                }
                if(balanceAmount >25000 && balanceAmount <=35000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.25)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(2660)).doubleValue();
                }
                if(balanceAmount >35000 && balanceAmount <=55000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(4410)).doubleValue();
                }
                if(balanceAmount >55000 && balanceAmount <=80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.35)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(7160)).doubleValue();
                }
                if(balanceAmount >80000 ){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.45)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(15160)).doubleValue();
                }
            }else {
                if(balanceAmount >0 && balanceAmount <=1500){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.03)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                }
                if(balanceAmount >1500 && balanceAmount <=4500){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(105)).doubleValue();
                }
                if(balanceAmount >4500 && balanceAmount <=9000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(555)).doubleValue();
                }
                if(balanceAmount >9000 && balanceAmount <=35000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.25)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(1005)).doubleValue();
                }
                if(balanceAmount >35000 && balanceAmount <=55000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(2755)).doubleValue();
                }
                if(balanceAmount >55000 && balanceAmount <=80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.35)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(5505)).doubleValue();
                }
                if(balanceAmount >80000 ){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.45)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(13505)).doubleValue();
                }
            }
            
        }else if(Objects.equal("2", salaryType)){ //个体工商户生产、经营所得
            double balanceAmount = originAmount;
            dto.balanceAmount = balanceAmount;
            if(balanceAmount >0 && balanceAmount <= 15000){
                dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.05)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            if(balanceAmount > 15000 && balanceAmount <= 30000){
                dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(750)).doubleValue();
            }
            if(balanceAmount > 30000 && balanceAmount <= 60000){
                dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(3750)).doubleValue();
            }
            if(balanceAmount > 60000 && balanceAmount <= 100000){
                dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(9750)).doubleValue();
            }
            if(balanceAmount > 100000){
                dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.35)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(14750)).doubleValue();
            }
        }else if(Objects.equal("3", salaryType)){ //年终奖所得
            double balanceAmount = 0;
            if(minusAmount2 - minimumAmount < 0){
                balanceAmount = BigDecimal.valueOf(originAmount).subtract(BigDecimal.valueOf(3500-minusAmount2)).doubleValue();
            }else{
                balanceAmount = originAmount;
            }
            dto.balanceAmount = balanceAmount;
            double avg_balanceAmount = balanceAmount/12;
            if(minimumAmount == 5000) {
                if(avg_balanceAmount >0 && avg_balanceAmount<=3000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.03)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                }
                if(avg_balanceAmount >3000 && avg_balanceAmount<=12000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(210)).doubleValue();
                }
                if(avg_balanceAmount >12000 && avg_balanceAmount<=25000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(1410)).doubleValue();
                }
                if(avg_balanceAmount >25000 && avg_balanceAmount<=35000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.25)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(2660)).doubleValue();
                }
                if(avg_balanceAmount >35000 && avg_balanceAmount<=55000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(4410)).doubleValue();
                }
                if(avg_balanceAmount >55000 && avg_balanceAmount<=80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.35)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(7160)).doubleValue();
                }
                if(avg_balanceAmount >80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.45)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(15160)).doubleValue();
                }
            }else {
                if(avg_balanceAmount >0 && avg_balanceAmount<=1500){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.03)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                }
                if(avg_balanceAmount >1500 && avg_balanceAmount<=4500){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.1)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(105)).doubleValue();
                }
                if(avg_balanceAmount >4500 && avg_balanceAmount<=9000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(555)).doubleValue();
                }
                if(avg_balanceAmount >9000 && avg_balanceAmount<=35000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.25)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(1005)).doubleValue();
                }
                if(avg_balanceAmount >35000 && avg_balanceAmount<=55000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(2775)).doubleValue();
                }
                if(avg_balanceAmount >55000 && avg_balanceAmount<=80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.35)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(5505)).doubleValue();
                }
                if(avg_balanceAmount >80000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.45)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(13505)).doubleValue();
                }
            }
            
        }else if(Objects.equal("4", salaryType)){ //劳务报酬所得
            dto.balanceAmount = originAmount;
            if(originAmount>0 && originAmount <= 800){
                dto.taxAmount =0;
            }else if(originAmount > 800){
                double balanceAmount = 0;
                if(originAmount >800 && originAmount <= 4000){
                    balanceAmount = originAmount-800;
                }
                if(originAmount > 4000){
                    balanceAmount = originAmount*0.8;
                }
                if(balanceAmount >0 && balanceAmount <= 20000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                }
                if(balanceAmount >20000 && balanceAmount <= 50000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(2000)).doubleValue();
                }
                if(balanceAmount >50000){
                    dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.4)).setScale(2, BigDecimal.ROUND_HALF_UP).subtract(BigDecimal.valueOf(7000)).doubleValue();
                }
            }
        }else if(Objects.equal("5", salaryType)){ //稿酬所得
            double balanceAmount = 0;
            if(originAmount >0 && originAmount <= 4000){
                balanceAmount = originAmount-800;
            }else if(originAmount > 4000){
                balanceAmount = originAmount*0.8;
            }
            dto.balanceAmount = balanceAmount;
            dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.14)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else if(Objects.equal("6", salaryType)){ //特许权使用费所得
            double balanceAmount = 0;
            if(originAmount >0 && originAmount <= 4000){
                balanceAmount = originAmount-800;
            }else if(originAmount > 4000){
                balanceAmount = originAmount*0.8;
            }
            dto.balanceAmount = balanceAmount;
            dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else if(Objects.equal("7", salaryType)){ //财产租赁所得
            double balanceAmount = 0;
            if(originAmount >0 && originAmount <= 4000){
                balanceAmount = originAmount-800;
            }else if(originAmount > 4000){
                balanceAmount = originAmount*0.8;
            }
            dto.balanceAmount = balanceAmount;
            dto.taxAmount = BigDecimal.valueOf(balanceAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else if(Objects.equal("8", salaryType)){ //财产转让所得
            dto.balanceAmount = originAmount;
            dto.taxAmount = BigDecimal.valueOf(originAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else if(Objects.equal("9", salaryType)){ //利息、股息、红利所得
            dto.balanceAmount = originAmount;
            dto.taxAmount = BigDecimal.valueOf(originAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else if(Objects.equal("10", salaryType)){ //偶然所得
            dto.balanceAmount = originAmount;
            dto.taxAmount = BigDecimal.valueOf(originAmount).multiply(BigDecimal.valueOf(0.2)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else{
            return dto;
        }
        if(Objects.equal("1", salaryType)){
            dto.finalAmount = BigDecimal.valueOf(originAmount)
                    .subtract(BigDecimal.valueOf(minusAmount))
                    .subtract(BigDecimal.valueOf(dto.taxAmount))
                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }else{
            dto.finalAmount = BigDecimal.valueOf(originAmount)
                    .subtract(BigDecimal.valueOf(dto.taxAmount))
                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        return dto;
    }

既然开发完了,就想着,弄个域名,挂个服务器给大家用一用,正好手头也有一个空着的域名xcc.cn,就搭建部署上线了。部署上,使用了jenkins+portainer,将项目打成了docker镜像,然后推到portainer部署启动。

个税计算器目前的公式上,可能有考虑不周的地方,大家可以指出来。

欢迎大家围观:个税计算器 ,各位下手轻点,别弄残了。

转载于:https://my.oschina.net/duwaiweb/blog/2993199

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值