| | |
| | | if (ArrayUtil.isEmpty(subjectMatterList.toArray())) { |
| | | return R.failed("没有查询到相关合同订单"); |
| | | } |
| | | Double outTotal = subjectMatterList.stream().mapToDouble(item -> { |
| | | // 优先判断 remainNum |
| | | if (item.getRemainingQuantity() != null && item.getRemainingQuantity().compareTo(new BigDecimal("0")) > 0) { |
| | | return item.getRemainingQuantity().doubleValue(); |
| | | } else { |
| | | // remainNum 为 null 或 0 时,使用 quantity |
| | | return item.getQuantity() == null ? 0.0 : item.getQuantity().doubleValue(); |
| | | } |
| | | }).sum(); |
| | | BigDecimal orderNum = addDTO.getSubjectMatterList().stream().map(OutSubjectMatterAddDTO::getOutBoundNum) |
| | | List<String> erpCodeList = subjectMatterList.stream().map(ContractSubjectMatter::getMaterialCode).collect(Collectors.toList()); |
| | | BigDecimal orderNum = subjectMatterList.stream().filter(item ->item.getDeliveryStatus()!=2) |
| | | .map(item ->item.getDeliveryStatus()==0?item.getQuantity():item.getRemainingQuantity()) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal outTotal = addDTO.getSubjectMatterList().stream() |
| | | .filter(item->erpCodeList.contains(item.getSubjectMatterCode())) |
| | | .map(OutSubjectMatterAddDTO::getOutBoundNum) |
| | | .filter(num -> num != null) // 过滤掉 null 值,防止 NullPointerException |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (new BigDecimal(outTotal).compareTo(orderNum) < 0) { |
| | | if (outTotal.compareTo(orderNum) > 0) { |
| | | return R.failed("出库数量超出合同订单数量"); |
| | | } |
| | | //当前入库标的物 |
| | |
| | | paymentConfirm.setTransationAmount(paymentConfirm.getTransationAmount().subtract(fhTotalAmount)); |
| | | paymentConfirm.setReceivableAmount(paymentConfirm.getTransationAmount()); |
| | | paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount())); |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | if(schedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | } |
| | | } else { |
| | | //不存在发货应收 出库总额 |
| | | paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount())); |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | if(schedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | } |
| | | } |
| | | } else { |
| | | //无之前阶段应收 |
| | | paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1"))); |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | if(schedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | } |
| | | } |
| | | |
| | | //更新发货前收款生效时间 |
| | |
| | | lastNewTotal = lastNewConfirm.getTotalAmount(); |
| | | } |
| | | newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount())); |
| | | paymentConfirmMapper.insert(newConfim); |
| | | if(endSchedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0) { |
| | | paymentConfirmMapper.insert(newConfim); |
| | | } |
| | | } |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(endSchedule.getStageName()); |