| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.tax.TaxtUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.project.domain.*; |
| | |
| | | */ |
| | | @ApiOperation("新增费用汇总") |
| | | @Log(title = "新增费用汇总", businessType = BusinessType.INSERT) |
| | | @PostMapping("/addnew") |
| | | @PostMapping("/addOrUpdateNew") |
| | | @RepeatSubmit |
| | | @Options(useGeneratedKeys = true, keyProperty = "id") |
| | | public AjaxResult addnew(@RequestBody ServiceFundVO serviceFundVO) { |
| | | boolean b = serviceFundService.save(serviceFundVO); |
| | | Long id = serviceFundVO.getId(); |
| | | // if (b) { |
| | | // addReiSharedDatd(serviceFundVO, 1); |
| | | // } |
| | | public AjaxResult addOrUpdateNew(@RequestBody ServiceFundVO serviceFundVO) { |
| | | Long id = null; |
| | | if (serviceFundVO.getId() == null) { |
| | | boolean b = serviceFundService.save(serviceFundVO); |
| | | id = serviceFundVO.getId(); |
| | | } else { |
| | | serviceFundService.updateById(serviceFundVO); |
| | | id = serviceFundVO.getId(); |
| | | } |
| | | List<ServiceFunddetail> serviceFunddetails = serviceFundVO.getServiceFunddetails(); |
| | | // serviceFunddetails.forEach(item -> item.setFundid(id)); |
| | | |
| | | //taxBefore、taxAfter用来记录税前税后的总金额,不用管税率 |
| | | double taxBefore = 0.0; |
| | | double taxAfter = 0.0; |
| | | for (ServiceFunddetail serviceFunddetail : serviceFunddetails) { |
| | | |
| | | serviceFunddetail.setFundid(id); |
| | | if (serviceFunddetail.getTaxedamount() != 0.0 && serviceFunddetail.getAmount() != 0.0 && serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getTaxedamount() != null) { |
| | | // 税前税后都不为空 |
| | | if (serviceFunddetail.getId() == null) { |
| | | serviceFunddetailService.save(serviceFunddetail); |
| | | } else { |
| | | serviceFunddetailService.updateById(serviceFunddetail); |
| | | } |
| | | continue; |
| | | } else if (serviceFunddetail.getTaxedamount() != 0.0 && serviceFunddetail.getTaxedamount() != null) { |
| | | // 税后求税前 |
| | | Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()))); |
| | | // 税金 |
| | | String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore)); |
| | | serviceFunddetail.setAmount(Double.valueOf(taxationBefore)); |
| | | serviceFunddetail.setTaxamount(Double.parseDouble(taxation)); |
| | | // 税后求税前,如果是专家费申请 或 偷专家费申请 才会计算税前税后 |
| | | if (StringUtils.isNotEmpty(serviceFunddetail.getApplytype()) && serviceFunddetail.getApplytype().equals("1") || serviceFunddetail.getApplytype().equals("2")) { |
| | | Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()))); |
| | | // 税金 |
| | | String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore)); |
| | | serviceFunddetail.setAmount(Double.valueOf(taxationBefore)); |
| | | serviceFunddetail.setTaxamount(Double.parseDouble(taxation)); |
| | | } |
| | | } else if (serviceFunddetail.getAmount() != 0.0 && serviceFunddetail.getAmount() != null) { |
| | | // 税前求税后 |
| | | double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetail.getAmount()))); |
| | | BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(tax)); |
| | | serviceFunddetail.setTaxamount(tax); |
| | | serviceFunddetail.setTaxedamount(taxAfterMoney.doubleValue()); |
| | | // 税前求税后,如果是专家费申请 或 偷专家费申请 才会计算税前税后 |
| | | if (StringUtils.isNotEmpty(serviceFunddetail.getApplytype()) && serviceFunddetail.getApplytype().equals("1") || serviceFunddetail.getApplytype().equals("2")) { |
| | | double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetail.getAmount()))); |
| | | BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(tax)); |
| | | serviceFunddetail.setTaxamount(tax); |
| | | serviceFunddetail.setTaxedamount(taxAfterMoney.doubleValue()); |
| | | } |
| | | } |
| | | |
| | | //根据id判断是新增还是修改 |
| | | if (serviceFunddetail.getId() == null) { |
| | | serviceFunddetailService.save(serviceFunddetail); |
| | | } else { |
| | | serviceFunddetailService.updateById(serviceFunddetail); |
| | | } |
| | | taxBefore = taxBefore + serviceFunddetail.getAmount(); |
| | | taxAfter = taxAfter + serviceFunddetail.getTaxedamount(); |
| | |
| | | serviceFundVO.setPretaxcost(taxBefore); |
| | | serviceFundVO.setTaxedcost(taxAfter); |
| | | serviceFundService.updateById(serviceFundVO); |
| | | //将计算好的数据,保存到detail表中 |
| | | serviceFunddetailService.saveBatch(serviceFunddetails); |
| | | // //将计算好的数据,保存到detail表中 |
| | | // serviceFunddetailService.saveBatch(serviceFunddetails); |
| | | return AjaxResult.success(id); |
| | | } |
| | | |