platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -141,7 +141,7 @@
   private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) {
      GenInvoiceInfoVo vo = new GenInvoiceInfoVo();
      BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId());
      vo.setPartyA(a.getRegisterName());
      vo.setPartyA(a.getCompanyName());
      vo.setPartyAOrgCode(a.getCreditCode());
      vo.setPartyAOpenBank(a.getBankName());
      vo.setPartyABankAccount(a.getBankAccount());
@@ -322,10 +322,12 @@
      if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
         //更新合同出库单状态
         genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
            ContractOutBound bound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
            bound.setInvoiceStatus("1");
            bound.setInvoiceNum(bound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
            contractOutBoundMapper.updateById(bound);
            ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
            contractOutBound.setInvoiceStatus("1");
            if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum()))<=0) {
               contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
            }
            contractOutBoundMapper.updateById(contractOutBound);
         });
      }else {
         //更新合同房租 水电 费开票状态
@@ -616,16 +618,22 @@
      data.put("billDate",DateUtil.format(contractInvoice.getInvoiceTime(),DatePattern.NORM_DATETIME_FORMAT));
      data.put("objectType","1");
      data.put("exchangeRate","1");
      data.put("exchangeRate",DateUtil.now());
      data.put("exchangeRateDate",DateUtil.now());
      data.put("_status","Insert");
      GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(contractInvoice.getInvoicePreview()), GenInvoiceInfoVo.class);
      JSONArray bodyItem = new JSONArray();
      for (InvoiceItemVo invoiceItemVo : vo.getInvoiceItemList()) {
         JSONObject item = new JSONObject();
         JSONObject freeCh = new JSONObject();
         freeCh.put("JT32","");
         item.put("freeChId",freeCh);
         item.put("invoiceNo",contractInvoice.getInvoiceNo());
         item.put("materialCode",invoiceItemVo.getErpCode());
         item.put("taxRate", invoiceItemVo.getTaxRate());
         item.put("oriTaxAmount", invoiceItemVo.getPriceTax());
         item.put("oriTaxExcludedAmount", invoiceItemVo.getPriceNoTax());
         item.put("oriTaxIncludedAmount", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()));
         item.put("_status","Insert");
@@ -701,33 +709,18 @@
         if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
            //合同状态
            if (StrUtil.equals(contract.getBillingStatus(), "2")) {
               if (ObjUtil.isNull(contract.getBillingAmout())) {
                  contract.setBillingAmout(vo.getTotalPrice());
                  if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
                     contract.setBillingStatus("3");
                  }
                  if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
                     contract.setBillingStatus("1");
                  }
                  contractMapper.updateById(contract);
               } else {
                  contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
                  if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
                     contract.setBillingStatus("3");
                  }
                  if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
                     contract.setBillingStatus("1");
                  }
                  contractMapper.updateById(contract);
               contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
               if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
                  contract.setBillingStatus("3");
               }
            } else {
               if (ObjUtil.isNull(contract.getBillingAmout())) {
                  contract.setBillingAmout(vo.getTotalPrice());
                  contractMapper.updateById(contract);
               } else {
                  contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
                  contractMapper.updateById(contract);
               if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
                  contract.setBillingStatus("1");
               }
               //防止重复审开票审核通过后 开票金额超出合同金额
               if (contract.getBillingAmout().compareTo(contract.getAmount())>0){
                  contract.setBillingAmout(contract.getAmount());
               }
               contractMapper.updateById(contract);
            }
         }else {
            //判断 循环是否完成
@@ -756,10 +749,10 @@
                  contract.setBillingStatus("2");
               }
            }
            if (ObjUtil.isNull(contract.getBillingAmout())) {
               contract.setBillingAmout(vo.getTotalPrice());
            } else {
               contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
            contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
            //防止重复审开票审核通过后 开票金额超出合同金额
            if (contract.getBillingAmout().compareTo(contract.getAmount())>0){
               contract.setBillingAmout(contract.getAmount());
            }
            contractMapper.updateById(contract);
         }
@@ -796,6 +789,10 @@
            }
         }
         contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax()));
         //防止重复审开票审核通过后 开票金额为负
         if (contract.getBillingAmout().compareTo(new BigDecimal("0"))<0){
            contract.setBillingAmout(new BigDecimal("0"));
         }
         //更新合同开票状态 前提出库完成
         contract.setBillingStatus("2");
         contractMapper.updateById(contract);
@@ -807,8 +804,10 @@
            if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
               outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
                  ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
                  contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
                  contractOutBoundMapper.updateById(contractOutBound);
                  if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum()))<=0) {
                     contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
                     contractOutBoundMapper.updateById(contractOutBound);
                  }
               });
            }
         }else {
@@ -841,8 +840,10 @@
            if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
               outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
                  ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
                  contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
                  contractOutBoundMapper.updateById(contractOutBound);
                  if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum()))<=0) {
                     contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
                     contractOutBoundMapper.updateById(contractOutBound);
                  }
               });
            }
         }else {