liusheng
2023-08-02 0c3f8972c92d0d5ce5912be6c460a3f2165ec04c
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java
@@ -12,6 +12,7 @@
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.*;
@@ -23,6 +24,7 @@
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -41,6 +43,7 @@
 * @author ruoyi
 * @date 2022-01-24
 */
@Slf4j
@Api("费用申请主")
@RestController
@RequestMapping("/project/fund")
@@ -427,51 +430,73 @@
     */
    @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) {
            log.info("serviceFunddetail的值为 : {}", serviceFunddetail);
            if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getAmount() != null && serviceFunddetail.getTaxedamount() != 0.0 && serviceFunddetail.getAmount() != 0.0) {
                // 税前税后都不为空
                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));
            } 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());
            } else if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getTaxedamount() != 0.0) {
                // 税后求税前,如果是专家费申请  或 伦理专家费申请   才会计算税前税后
                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.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() != null && serviceFunddetail.getAmount() != 0.0) {
                // 税前求税后,如果是专家费申请  或 伦理专家费申请   才会计算税前税后
                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.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());
                }
            }
            taxBefore = taxBefore + serviceFunddetail.getAmount();
            taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
            //根据id判断是新增还是修改
            if (serviceFunddetail.getId() == null) {
                serviceFunddetailService.save(serviceFunddetail);
            } else {
                serviceFunddetailService.updateById(serviceFunddetail);
            }
            if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
                //如果是专家费申请  或 伦理专家费申请   才会计算税前税后
                taxBefore = taxBefore + serviceFunddetail.getAmount();
                taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
            }
        }
        //将税前、税后金额更新到fund表中
        serviceFundVO.setPretaxcost(taxBefore);
        serviceFundVO.setTaxedcost(taxAfter);
        serviceFundService.updateById(serviceFundVO);
        //将计算好的数据,保存到detail表中
        serviceFunddetailService.saveBatch(serviceFunddetails);
//        //将计算好的数据,保存到detail表中
//        serviceFunddetailService.saveBatch(serviceFunddetails);
        return AjaxResult.success(id);
    }
    /**
     * 审核费用
@@ -624,7 +649,7 @@
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody ServiceFund serviceFund) {
        List<ServiceFund> infoByInfoIdList = serviceFundService.getInfoByInfoId(serviceFund.getInfoid());
        List<ServiceFund> infoByInfoIdList = serviceFundService.queryInfoById(serviceFund);
        for (ServiceFund sf : infoByInfoIdList) {
            //如果等于100,说明已经走到医院财务那边了;财务那边取数据是从分享表取,所以,这里直接往分享表里添加数据就行了
            if (sf.getBackflowlevel() == 100 || sf.getBackflowlevel() == 199) {
@@ -719,11 +744,11 @@
        dataMap.put("JXZXM", serviceFund.getDonorname() == null ? "" : serviceFund.getDonorname());
        dataMap.put("JSR", serviceFund.getUsername() == null ? "" : serviceFund.getUsername());
//        dataMap.put("FYXM1", "支付专家费用,其中税前金额" + serviceFund.getPretaxcost() + "元,税后金额" + serviceFund.getTaxedcost() + "元。");
        dataMap.put("FYXM1", "人体器官捐献专家劳务费:" + serviceFund.getTaxedcost() + "元 (其中税后费用由中心承担税费)。");
        dataMap.put("FYXM1", "人体器官捐献专家劳务费:" + serviceFund.getPretaxcost() + "元 (其中税后费用由中心承担税费)。");
        dataMap.put("FYXM2", "");
        dataMap.put("FYXM3", "");
        dataMap.put("JEXS", serviceFund.getAmountrequested());
        dataMap.put("JEDS", convert(serviceFund.getAmountrequested()) + "整");
        dataMap.put("JEXS", serviceFund.getPretaxcost());
        dataMap.put("JEDS", convert(serviceFund.getPretaxcost()) + "整");
        dataMap.put("BXBZ", serviceFund.getRemark() == null ? "" : serviceFund.getRemark());