package com.ruoyi.common.tax; 
 | 
  
 | 
import com.ruoyi.common.constant.Constants; 
 | 
import com.ruoyi.common.core.domain.entity.SysDictData; 
 | 
import com.ruoyi.common.core.redis.RedisCache; 
 | 
import com.ruoyi.common.utils.StringUtils; 
 | 
import com.ruoyi.common.utils.spring.SpringUtils; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
  
 | 
import java.math.BigDecimal; 
 | 
import java.math.RoundingMode; 
 | 
import java.text.DecimalFormat; 
 | 
import java.util.Collection; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * 劳务报酬个税计算规则 (可能不适合公共用法,用前先看看是否适合) 
 | 
 * 
 | 
 * @author ls 
 | 
 */ 
 | 
@Slf4j 
 | 
public class TaxtUtils { 
 | 
    /** 
 | 
     * 分隔符 
 | 
     */ 
 | 
    public static final String SEPARATOR = ","; 
 | 
  
 | 
    /** 
 | 
     * 获取税金 
 | 
     * 
 | 
     * @param money 报酬 (税前) 
 | 
     */ 
 | 
    public static String getTaxation(BigDecimal money) { 
 | 
        //当X<=800时,个税T=0 
 | 
        BigDecimal taxMoney = BigDecimal.valueOf(0.0); 
 | 
  
 | 
        //当800<X<=4000时,个税T=(X-800)*20% 
 | 
        if (money.doubleValue() > 800 && money.doubleValue() <= 4000) { 
 | 
            BigDecimal subtract = money.subtract(new BigDecimal(800)); 
 | 
            taxMoney = subtract.multiply(BigDecimal.valueOf(0.2)); 
 | 
        } 
 | 
  
 | 
        BigDecimal multiply = money.multiply(BigDecimal.valueOf(0.8)); 
 | 
        // 当X>4000时 
 | 
        //(1)当X*(1-20%)<=20000时,个税T=X*(1-20%)*20% 
 | 
        if (money.doubleValue() > 4000 && multiply.doubleValue() <= 20000) { 
 | 
            taxMoney = multiply.multiply(BigDecimal.valueOf(0.2)); 
 | 
        } 
 | 
  
 | 
        //(2)当20000<X*(1-20%)<=50000时,个税T=X*(1-20%)*30%-2000 
 | 
        if (multiply.doubleValue() > 20000 && multiply.doubleValue() <= 50000) { 
 | 
            taxMoney = multiply.multiply(BigDecimal.valueOf(0.3)).subtract(BigDecimal.valueOf(2000)); 
 | 
        } 
 | 
  
 | 
        //X*(1-20%)>50000时,个税T=X*(1-20%)*40%-7000 
 | 
        if (multiply.doubleValue() > 50000) { 
 | 
            taxMoney = multiply.multiply(BigDecimal.valueOf(0.4)).subtract(BigDecimal.valueOf(7000)); 
 | 
        } 
 | 
        DecimalFormat decimalFormat = new DecimalFormat("#0.00"); 
 | 
        //进一法 
 | 
        decimalFormat.setRoundingMode(RoundingMode.CEILING); 
 | 
        String format = decimalFormat.format(taxMoney); 
 | 
        log.info("税金为:{}", format); 
 | 
        return format; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 通过税后工资,算出税前工资 
 | 
     * 
 | 
     * @param money 
 | 
     * @return 
 | 
     */ 
 | 
    public static String getTaxationBefore(BigDecimal money) { 
 | 
        //当X<=800时,个税T=0 
 | 
        BigDecimal taxMoney = BigDecimal.valueOf(0.00); 
 | 
        if (money.doubleValue() <= 800) { 
 | 
            taxMoney = money; 
 | 
        } 
 | 
//第一个参数是除数,第二个参数代表保留几位小数,第三个代表的是使用的模式 
 | 
        if (money.doubleValue() > 800 && money.doubleValue() <= 3360) { 
 | 
            taxMoney = money.subtract(new BigDecimal(160)).divide(new BigDecimal(0.8), 2, BigDecimal.ROUND_CEILING); 
 | 
        } 
 | 
  
 | 
        if (money.doubleValue() > 3360 && money.doubleValue() <= 21000) { 
 | 
            taxMoney = money.divide(new BigDecimal(0.84), 2, BigDecimal.ROUND_CEILING); 
 | 
        } 
 | 
  
 | 
        if (money.doubleValue() > 21000 && money.doubleValue() <= 49500) { 
 | 
            money = money.subtract(new BigDecimal(2000)); 
 | 
            taxMoney = money.divide(new BigDecimal(0.76), 2, BigDecimal.ROUND_CEILING); 
 | 
        } 
 | 
  
 | 
        if (money.doubleValue() > 49500) { 
 | 
            money = money.subtract(new BigDecimal(7000)); 
 | 
            taxMoney = money.divide(new BigDecimal(0.68), 2, BigDecimal.ROUND_CEILING); 
 | 
        } 
 | 
  
 | 
  
 | 
        DecimalFormat decimalFormat = new DecimalFormat("#0.00"); 
 | 
        //进一法 
 | 
        decimalFormat.setRoundingMode(RoundingMode.CEILING); 
 | 
        String format = decimalFormat.format(taxMoney); 
 | 
        log.info("税前金额为:{}", format); 
 | 
        return format; 
 | 
    } 
 | 
  
 | 
  
 | 
    public static void main(String[] args) { 
 | 
        String taxation = getTaxation(BigDecimal.valueOf(43000)); 
 | 
        String taxationBefore = getTaxationBefore(BigDecimal.valueOf(205892.36)); 
 | 
  
 | 
  
 | 
        System.out.println("taxation:" + taxation + "============taxationBefore: " + taxationBefore); 
 | 
    } 
 | 
  
 | 
} 
 |