| | |
| | | @Transactional |
| | | public Long addOrUpdateNew(ServiceFundVO serviceFundVO) { |
| | | Long id = null; |
| | | //将数据保存到fund表 |
| | | if (serviceFundVO.getId() == null) { |
| | | save(serviceFundVO); |
| | | id = serviceFundVO.getId(); |
| | |
| | | System.out.println("serviceFunddetails为空喽"); |
| | | return null; |
| | | } |
| | | // 用于记录税前、税后的总和 |
| | | double taxBefore = 0.0; |
| | | double taxAfter = 0.0; |
| | | |
| | | // 保存详情数据 |
| | | for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetails) { |
| | | serviceFunddetailVO.setFundid(id); |
| | | //將附件转成json |
| | | if (!CollectionUtils.isEmpty(serviceFunddetailVO.getAnnexfilesList())) { |
| | | serviceFunddetailVO.setAnnexfiles(JSON.toJSONString(serviceFunddetailVO.getAnnexfilesList())); |
| | | } |
| | | if (serviceFunddetailVO.getTaxedamount() != null && serviceFunddetailVO.getAmount() != null && serviceFunddetailVO.getTaxedamount() != 0.0 && serviceFunddetailVO.getAmount() != 0.0) { |
| | | // 税前税后都不为空 |
| | | ServiceFunddetail serviceFunddetail = DtoConversionUtils.sourceToTarget(serviceFunddetailVO, ServiceFunddetail.class); |
| | | |
| | | |
| | | if (serviceFunddetailVO.getId() == null) { |
| | | serviceFunddetailService.save(serviceFunddetail); |
| | | } else { |
| | | serviceFunddetailService.updateById(serviceFunddetail); |
| | | } |
| | | //计算税金 |
| | | if (serviceFunddetail.getAmount() != null) { |
| | | taxBefore = taxBefore + serviceFunddetail.getAmount(); |
| | | } |
| | | if (serviceFunddetail.getTaxedamount() != null) { |
| | | taxAfter = taxAfter + serviceFunddetail.getTaxedamount(); |
| | | } |
| | | continue; |
| | | } else if (serviceFunddetailVO.getTaxedamount() != null && serviceFunddetailVO.getTaxedamount() != 0.0) { |
| | | // 税后求税前,如果是专家费申请 或 伦理专家费申请 才会计算税前税后 |
| | | if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) { |
| | | Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetailVO.getTaxedamount()))); |
| | | // 税金 |
| | | String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore)); |
| | | serviceFunddetailVO.setAmount(Double.valueOf(taxationBefore)); |
| | | serviceFunddetailVO.setTaxamount(Double.parseDouble(taxation)); |
| | | } |
| | | } else if (serviceFunddetailVO.getAmount() != null && serviceFunddetailVO.getAmount() != 0.0) { |
| | | // 税前求税后,如果是专家费申请 或 伦理专家费申请 才会计算税前税后 |
| | | if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) { |
| | | double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetailVO.getAmount()))); |
| | | BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetailVO.getAmount()).subtract(BigDecimal.valueOf(tax)); |
| | | serviceFunddetailVO.setTaxamount(tax); |
| | | serviceFunddetailVO.setTaxedamount(taxAfterMoney.doubleValue()); |
| | | } |
| | | } |
| | | |
| | | //根据id判断是新增还是修改 |
| | | ServiceFunddetail serviceFunddetail = DtoConversionUtils.sourceToTarget(serviceFunddetailVO, ServiceFunddetail.class); |
| | | |
| | | if (serviceFunddetailVO.getId() == null) { |
| | | serviceFunddetailService.save(serviceFunddetail); |
| | | } else { |
| | | serviceFunddetailService.updateById(serviceFunddetail); |
| | | } |
| | | // if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) { |
| | | //如果是专家费申请 或 伦理专家费申请 才会计算税前税后 |
| | | if (serviceFunddetail.getAmount() != null) { |
| | | taxBefore = taxBefore + serviceFunddetail.getAmount(); |
| | | } |
| | | if (serviceFunddetail.getTaxedamount() != null) { |
| | | taxAfter = taxAfter + serviceFunddetail.getTaxedamount(); |
| | | } |
| | | } |
| | | //将税前、税后金额更新到fund表中 |
| | | serviceFundVO.setPretaxcost(taxBefore); |
| | | serviceFundVO.setTaxedcost(taxAfter); |
| | | //申请金额为含税金额 |
| | | if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) { |
| | | //个税 税前(有税) - 税 = 税后 |
| | | serviceFundVO.setAmountrequested(taxBefore); |
| | | } else { |
| | | //采购 税前(无税) + 税 = 税后(含税金额) |
| | | serviceFundVO.setAmountrequested(taxAfter); |
| | | } |
| | | |
| | | updateById(serviceFundVO); |
| | | |
| | | return id; |
| | | } |