platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
@@ -337,18 +337,6 @@
//                     beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
//                     scheduleMapper.updateById(beforeSchedule);
//                  }
                  //更新履约
                  ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
                  contractPaymentScheduleProcess.setContractId(schedule.getContractId());
                  contractPaymentScheduleProcess.setContractName(schedule.getContractName());
                  contractPaymentScheduleProcess.setScheduleId(schedule.getId());
                  contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
                  contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
                  ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
                        .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
                  if (ObjUtil.isNull(lastProcess)) {
                     scheduleProcessMapper.insert(contractPaymentScheduleProcess);
                  }
               }
               //查询是否有后续阶段
@@ -473,14 +461,15 @@
   public R addContractOut(OutBoundAddDTO addDTO) {
      //校验参数
      R<Contract> r = vailParam(addDTO);
      if (!r.isOk()){
      if (!r.isOk()) {
         return r;
      }
      Contract contract = r.getData();
      //出库
      handleOutBound(contract,addDTO);
      handleOutBound(contract, addDTO);
      //保存资金明细
      BigDecimal outBoundAmount = savePaymentConfirm(contract,addDTO);
      BigDecimal outBoundAmount = savePaymentConfirm(contract, addDTO);
      //更新合同状态及阶段
      contract.setOutBoundAmout(outBoundAmount);
      updateContractSchedule(contract);
@@ -492,35 +481,37 @@
      List<ContractSubjectMatter> unComOutList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
            .eq(ContractSubjectMatter::getContractId, contract.getId())
            .ne(ContractSubjectMatter::getDeliveryStatus, 2));
      if (CollUtil.isEmpty(unComOutList)){
      if (CollUtil.isEmpty(unComOutList)) {
         contract.setNextScheduleName("货到签收");
      }
      contract.setBillingStatus("2");
      contractMapper.updateById(contract);
   }
   private BigDecimal savePaymentConfirm(Contract contract,OutBoundAddDTO addDTO) {
   private BigDecimal savePaymentConfirm(Contract contract, OutBoundAddDTO addDTO) {
      //查询合同是否有出库阶段
      ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
            .eq(ContractPaymentSchedule::getStageName, "发货前").gt(ContractPaymentSchedule::getPaymentRatio,0).last("limit 1"));
      if (ObjUtil.isNull(schedule.getEffectiveDate())&&ObjUtil.isNull(schedule.getEffectiveEndDate())){
            .eq(ContractPaymentSchedule::getStageName, "发货前").last("limit 1"));
      if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
         schedule.setEffectiveDate(addDTO.getOutBoundTime());
         schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(),schedule.getAgreedDays()));
         schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
         scheduleMapper.updateById(schedule);
      }
      //履约几率
      processService.saveScheduleProcess(addDTO.getOutBoundTime(),schedule);
      BigDecimal outAmount = new BigDecimal("0");
      //计算出库价格
      BigDecimal outAmount = new BigDecimal("0");
      for (OutSubjectMatterAddDTO outSubjectMatterAddDTO : addDTO.getSubjectMatterList()) {
         ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
               .eq(ContractSubjectMatter::getContractId, contract.getId())
               .eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode())
               .eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
               .eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
               .last("limit 1"));
         outAmount = outAmount.add(outSubjectMatterAddDTO.getOutBoundNum().multiply(subjectMatter.getUnitPrice()));
      }
      //存在发货前收款阶段
      if (ObjUtil.isNotNull(schedule)) {
      if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
         //新增当前阶段应收
         PaymentConfirm currentConfim = new PaymentConfirm();
         currentConfim.setBusinessType(schedule.getStageName() + "应收");
@@ -533,7 +524,7 @@
         currentConfim.setScheduleName(schedule.getStageName());
         currentConfim.setConfirmTime(addDTO.getOutBoundTime());
         //按出库比例计算应收
         currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(),2,RoundingMode.HALF_UP)));
         currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(), 2, RoundingMode.HALF_UP)));
         currentConfim.setReceivableAmount(currentConfim.getTransationAmount());
         PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
               .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
@@ -547,7 +538,7 @@
         currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1")));
         paymentConfirmMapper.insert(currentConfim);
         //历史资金余额
         processService.handleBeforeRemain(currentConfim,contract);
         processService.handleBeforeRemain(currentConfim, contract);
      }
      return outAmount;
   }
@@ -581,7 +572,7 @@
         contractSubjectMatterMapper.updateById(subjectMatter);
         //保存erp出库
         String batchNumber = genBatchNumber();
         Long outBoundId = saveErpOutBound(contract,addDTO,outSubjectMatterAddDTO,batchNumber);
         Long outBoundId = saveErpOutBound(contract, addDTO, outSubjectMatterAddDTO, batchNumber);
         //保存合同出库记录
         saveContractOutBound(contract, addDTO, subjectMatter, outBoundId);
      });
@@ -607,7 +598,7 @@
      return "";
   }
   private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO,OutSubjectMatterAddDTO outSubjectMatterAddDTO,String batchNumber) {
   private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO, OutSubjectMatterAddDTO outSubjectMatterAddDTO, String batchNumber) {
      OutBound outBound = new OutBound();
      outBound.setBatchNumber(batchNumber);
      outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum());