| | |
| | | */ |
| | | @Override |
| | | public Double getTaxByBeneFiciaryNo(TaxMoneyVO taxMoneyVo) { |
| | | Double sum = 0.00; |
| | | Double totalScore = 0.00; |
| | | // 金额累加必须用 BigDecimal:double 累加会引入浮点尾差,导致算出的个税出现分以下误差 |
| | | BigDecimal sum = BigDecimal.ZERO; |
| | | BigDecimal totalScore = BigDecimal.ZERO; |
| | | List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo); |
| | | if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) { |
| | | //计算申请金额总和,不包括当前传进来的 |
| | | sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getAmount).sum(); |
| | | sum = taxationByBeneFiciaryNo.stream() |
| | | .map(ServiceFunddetail::getAmount) |
| | | .filter(java.util.Objects::nonNull) |
| | | .map(BigDecimal::valueOf) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //不加本次薪酬的个税 |
| | | totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum(); |
| | | totalScore = taxationByBeneFiciaryNo.stream() |
| | | .map(ServiceFunddetail::getTaxamount) |
| | | .filter(java.util.Objects::nonNull) |
| | | .map(BigDecimal::valueOf) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | |
| | | sum = sum + new Double(taxMoneyVo.getMoney()); |
| | | sum = sum.add(new BigDecimal(taxMoneyVo.getMoney())); |
| | | //加上本次薪酬的总个税 |
| | | String taxation = TaxtUtils.getTaxation(new BigDecimal(sum)); |
| | | String taxation = TaxtUtils.getTaxation(sum); |
| | | |
| | | Double tax = Double.valueOf(taxation) - totalScore; |
| | | Double tax = new BigDecimal(taxation).subtract(totalScore).doubleValue(); |
| | | return tax; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public TaxedMoneyVO getTaxBeforeByAfterMoney(TaxMoneyVO taxMoneyVo) { |
| | | TaxedMoneyVO taxedMoneyVO = new TaxedMoneyVO(); |
| | | Double sum = 0.00; |
| | | Double totalScore = 0.00; |
| | | // 金额累加必须用 BigDecimal,避免浮点尾差影响税前/税额结果 |
| | | BigDecimal sum = BigDecimal.ZERO; |
| | | BigDecimal totalScore = BigDecimal.ZERO; |
| | | List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo); |
| | | if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) { |
| | | //计算出税后总金额(不包含本次) |
| | | sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxedamount).sum(); |
| | | sum = taxationByBeneFiciaryNo.stream() |
| | | .map(ServiceFunddetail::getTaxedamount) |
| | | .filter(java.util.Objects::nonNull) |
| | | .map(BigDecimal::valueOf) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //求出之前的总的个税 |
| | | totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum(); |
| | | totalScore = taxationByBeneFiciaryNo.stream() |
| | | .map(ServiceFunddetail::getTaxamount) |
| | | .filter(java.util.Objects::nonNull) |
| | | .map(BigDecimal::valueOf) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | //计算出总的税后薪酬(包含本次) |
| | | sum = sum + Double.valueOf(taxMoneyVo.getMoney()); |
| | | sum = sum.add(new BigDecimal(taxMoneyVo.getMoney())); |
| | | //税前总金额 |
| | | String taxationBefore = TaxtUtils.getTaxationBefore(new BigDecimal(sum)); |
| | | String taxationBefore = TaxtUtils.getTaxationBefore(sum); |
| | | //总个税 |
| | | BigDecimal tax = new BigDecimal(taxationBefore).subtract(new BigDecimal(sum)); |
| | | BigDecimal tax = new BigDecimal(taxationBefore).subtract(sum); |
| | | |
| | | //本次的税前金额 |
| | | String nowTaxMoney = TaxtUtils.getTaxationBefore(new BigDecimal(taxMoneyVo.getMoney())); |
| | |
| | | // 5.2.3 算税逻辑 |
| | | if (detail.getServicesscopename().contains("税后")) { |
| | | // 税后明细:累计税后金额,反推税前金额和税金 |
| | | if (idcard.equals("330103196704060019")) { |
| | | log.info("330103196704060019"); |
| | | } |
| | | // if (idcard.equals("362329199103224511")) { |
| | | // log.info("朱玮安"); |
| | | // } |
| | | BigDecimal newTaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(BigDecimal.valueOf(detail.getTaxedamount())); |
| | | String taxationBefore = TaxtUtils.getTaxationBefore(newTaxedAmounts); |
| | | BigDecimal amountNow = new BigDecimal(taxationBefore).subtract(BigDecimal.valueOf(taxSum.getAmounts())); |
| | |
| | | } else { |
| | | detail.setTaxTime(serviceFund1.getFundtaxtime()); |
| | | } |
| | | if (tax.doubleValue() < 0) { |
| | | log.info("小于0了"); |
| | | } |
| | | taxSum.setAmounts((BigDecimal.valueOf(taxSum.getAmounts()).add(amountNow)).doubleValue()); |
| | | taxSum.setTaxAmounts((BigDecimal.valueOf(taxSum.getTaxAmounts()).add(tax)).doubleValue()); |
| | | taxSum.setTaxedAmounts(newTaxedAmounts.doubleValue()); |
| | | } else { |
| | | // 税前明细:累计税前金额,算总税金,再算本次税金和税后金额 |
| | | BigDecimal newAmounts = BigDecimal.valueOf(taxSum.getAmounts()).add(BigDecimal.valueOf(detail.getAmount())); |
| | | if (idcard.equals("330103196704060019")) { |
| | | log.info("330103196704060019"); |
| | | } |
| | | // if (idcard.equals("362329199103224511")) { |
| | | // log.info("朱玮安"); |
| | | // } |
| | | String taxation = TaxtUtils.getTaxation(newAmounts); |
| | | |
| | | BigDecimal taxAmountNow = new BigDecimal(taxation).subtract(new BigDecimal(String.valueOf(taxSum.getTaxAmounts()))); |
| | | BigDecimal texdAfterNow = BigDecimal.valueOf(detail.getAmount()).subtract(taxAmountNow); |
| | | detail.setTaxamount(taxAmountNow.doubleValue()); |
| | | detail.setTaxedamount(texdAfterNow.doubleValue()); |
| | | if (taxAmountNow.doubleValue() < 0) { |
| | | log.info("小于0了"); |
| | | } |
| | | |
| | | if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) { |
| | | detail.setTaxTime(new Date()); |