| | |
| | | //出库 |
| | | addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> { |
| | | OutBound outBound = BeanUtil.copyProperties(outSubjectMatterAddDTO, OutBound.class); |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)||StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smjsc)|| |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smjzt)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) || |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) { |
| | | outBound.setBatchNumber(generateSMJContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) { |
| | | outBound.setBatchNumber(generateGYBContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) { |
| | | outBound.setBatchNumber(generateYMJContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) { |
| | | outBound.setBatchNumber(generateTFContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) { |
| | | outBound.setBatchNumber(generateJXCContractCKNo()); |
| | | } |
| | | outBound.setBusGuestName(addDTO.getBusGuestName()); |
| | |
| | | //合同金额 |
| | | Contract contract = contractMapper.selectById(contractId); |
| | | //出库是否完成 |
| | | if (outPirce.compareTo(contract.getBillingAmout())>0) { |
| | | if (outPirce.compareTo(contract.getBillingAmout()) > 0) { |
| | | contract.setBillingStatus("2"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (outPirce.compareTo(contract.getBillingAmout())==0) { |
| | | if (outPirce.compareTo(contract.getBillingAmout()) == 0) { |
| | | contract.setBillingStatus("1"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (outPirce.compareTo(contract.getAmount()) == 0&& |
| | | outPirce.compareTo(contract.getBillingAmout())==0) { |
| | | if (outPirce.compareTo(contract.getAmount()) == 0 && |
| | | outPirce.compareTo(contract.getBillingAmout()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | |
| | | PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | if (lastNewConfirm.getTotalAmount().compareTo(new BigDecimal("0")) >= 0 |
| | | &&contract.getBillingAmout().compareTo(contract.getAmount())==0) { |
| | | && contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | //有预付且超过应收 关闭合同状态 |
| | | contract.setContractStatus(3); |
| | | contractMapper.updateById(contract); |
| | |
| | | contractOutBound.setBusGuestName(contract.getPartyA()); |
| | | contractOutBound.setSubjectMatterCode(subjectMatter.getMaterialCode()); |
| | | contractOutBound.setSubjectMatterName(subjectMatter.getMaterialInternalName()); |
| | | contractOutBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime())?addDTO.getOutBoundTime():new Date()); |
| | | contractOutBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime()) ? addDTO.getOutBoundTime() : new Date()); |
| | | contractOutBound.setOutBoundNum(subjectMatter.getLastDeliveredQuantity()); |
| | | contractOutBound.setOutBoundAttNames(addDTO.getOutBoundAttNames()); |
| | | contractOutBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths()); |
| | |
| | | contractOutBound.setInvoiceStatus("0"); |
| | | contractOutBound.setInvoiceNum(new BigDecimal("0")); |
| | | contractOutBoundMapper.insert(contractOutBound); |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | // 1. 确定用于比较的基准日期(优先级:计划交货日期 > 合同到期日期) |
| | | Date deadline = subjectMatter.getPlannedDeliveryDate(); |
| | | if (ObjUtil.isNull(deadline)) { |
| | |
| | | if (ObjUtil.isNull(contract)) { |
| | | return R.failed("合同信息查询失败"); |
| | | } |
| | | if (addDTO.getSubjectMatterList().stream().allMatch(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))==0)){ |
| | | if (addDTO.getSubjectMatterList().stream().allMatch(item -> item.getOutBoundNum().compareTo(new BigDecimal("0")) == 0)) { |
| | | return R.failed("出库数量不能都为为0"); |
| | | } |
| | | addDTO.setSubjectMatterList(addDTO.getSubjectMatterList().stream().filter(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); |
| | | addDTO.setSubjectMatterList(addDTO.getSubjectMatterList().stream().filter(item -> item.getOutBoundNum().compareTo(new BigDecimal("0")) > 0).collect(Collectors.toList())); |
| | | //出库数量校验 |
| | | for (OutSubjectMatterAddDTO outSubjectMatterAddDTO: addDTO.getSubjectMatterList()) { |
| | | for (OutSubjectMatterAddDTO outSubjectMatterAddDTO : addDTO.getSubjectMatterList()) { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId,contract.getId()) |
| | | .eq(ContractSubjectMatter::getMaterialCode,outSubjectMatterAddDTO.getSubjectMatterCode()) |
| | | .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo,outSubjectMatterAddDTO.getLineNo()) |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()) |
| | | .eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode()) |
| | | .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo()) |
| | | .last("limit 1")); |
| | | if (ObjUtil.isNull(subjectMatter)){ |
| | | if (ObjUtil.isNull(subjectMatter)) { |
| | | continue; |
| | | } |
| | | if (subjectMatter.getDeliveryStatus()==0){ |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity())>0){ |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"出库数不能超过合同中数量"); |
| | | if (subjectMatter.getDeliveryStatus() == 0) { |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity()) > 0) { |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "出库数不能超过合同中数量"); |
| | | } |
| | | } |
| | | if (subjectMatter.getDeliveryStatus()==1){ |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getRemainingQuantity())>0){ |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"出库数不能超过未出库数量"); |
| | | if (subjectMatter.getDeliveryStatus() == 1) { |
| | | if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getRemainingQuantity()) > 0) { |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "出库数不能超过未出库数量"); |
| | | } |
| | | } |
| | | if (subjectMatter.getDeliveryStatus()==2){ |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"已出库完成,不能超额出库"); |
| | | if (subjectMatter.getDeliveryStatus() == 2) { |
| | | return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "已出库完成,不能超额出库"); |
| | | } |
| | | } |
| | | |
| | | |
| | | addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId,contract.getId()) |
| | | .eq(ContractSubjectMatter::getMaterialCode,outSubjectMatterAddDTO.getSubjectMatterCode()) |
| | | .ne(ContractSubjectMatter::getDeliveryStatus,2) |
| | | .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo,outSubjectMatterAddDTO.getLineNo()) |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()) |
| | | .eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode()) |
| | | .ne(ContractSubjectMatter::getDeliveryStatus, 2) |
| | | .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo()) |
| | | .last("limit 1")); |
| | | if (ObjUtil.isNull(subjectMatter)){ |
| | | if (ObjUtil.isNull(subjectMatter)) { |
| | | return; |
| | | } |
| | | subjectMatter.setLastDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum()); |
| | |
| | | contractSubjectMatterMapper.updateById(subjectMatter); |
| | | // |
| | | OutBound outBound = new OutBound(); |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)||StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smjsc)|| |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smjzt)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) || |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) { |
| | | outBound.setBatchNumber(generateSMJContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) { |
| | | outBound.setBatchNumber(generateGYBContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) { |
| | | outBound.setBatchNumber(generateYMJContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) { |
| | | outBound.setBatchNumber(generateTFContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){ |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) { |
| | | outBound.setBatchNumber(generateJXCContractCKNo()); |
| | | } |
| | | outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum()); |
| | |
| | | outBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths()); |
| | | outBound.setBusGuestName(contract.getPartyA()); |
| | | outBound.setBusGuestId(contract.getPartyAId()); |
| | | outBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime())?addDTO.getOutBoundTime():new Date()); |
| | | outBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime()) ? addDTO.getOutBoundTime() : new Date()); |
| | | outBound.setSubjectMatterCode(outSubjectMatterAddDTO.getSubjectMatterCode()); |
| | | outBound.setSubjectMatterName(outSubjectMatterAddDTO.getSubjectMatterName()); |
| | | outBound.setOutBoundType("1"); |
| | | if (StrUtil.isEmpty(addDTO.getOutBoundType())){ |
| | | if (StrUtil.isEmpty(addDTO.getOutBoundType())) { |
| | | outBound.setOutBoundType("0"); |
| | | } |
| | | baseMapper.insert(outBound); |
| | |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()).ne(ContractSubjectMatter::getDeliveryStatus, 0)); |
| | | //查询合同是否有出库阶段 |
| | | ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()) |
| | | .eq(ContractPaymentSchedule::getStageName, "发货前")); |
| | | .eq(ContractPaymentSchedule::getStageName, "发货前").gt(ContractPaymentSchedule::getPaymentRatio,0).last("limit 1")); |
| | | //存在出库阶段 |
| | | if (ObjUtil.isNotNull(schedule)) { |
| | | //当前出库金额 |
| | |
| | | .map(item -> (item.getDeliveryStatus() == 1 ? item.getDeliveredQuantity().multiply(item.getUnitPrice()) : item.getQuantity().multiply(item.getUnitPrice()))) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //出库是否完成 |
| | | if (outPirce.compareTo(contract.getBillingAmout())>0) { |
| | | if (outPirce.compareTo(contract.getBillingAmout()) > 0) { |
| | | contract.setBillingStatus("2"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (outPirce.compareTo(contract.getBillingAmout())==0) { |
| | | if (outPirce.compareTo(contract.getBillingAmout()) == 0) { |
| | | contract.setBillingStatus("1"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | if (outPirce.compareTo(contract.getAmount()) == 0&& |
| | | outPirce.compareTo(contract.getBillingAmout())==0) { |
| | | if (outPirce.compareTo(contract.getAmount()) == 0 && |
| | | outPirce.compareTo(contract.getBillingAmout()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | //计算发货前应收更新资金明细 |
| | | PaymentConfirm paymentConfirm = new PaymentConfirm(); |
| | | paymentConfirm.setBusinessType("发货前应收"); |
| | | paymentConfirm.setBusGuestId(contract.getPartyAId()); |
| | | paymentConfirm.setBusGuestName(contract.getPartyA()); |
| | | paymentConfirm.setContractId(contract.getId()); |
| | | paymentConfirm.setContractName(contract.getContractName()); |
| | | paymentConfirm.setContractNo(contract.getContractNo()); |
| | | paymentConfirm.setScheduleId(schedule.getId()); |
| | | paymentConfirm.setScheduleName(schedule.getStageName()); |
| | | paymentConfirm.setConfirmTime(addDTO.getOutBoundTime()); |
| | | //计算出库金额 |
| | | BigDecimal outAmount = addDTO.getSubjectMatterList().stream().map(item->item.getUnitPrice().multiply(item.getOutBoundNum())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | paymentConfirm.setTransationAmount(outAmount.divide(new BigDecimal("100")).multiply(schedule.getPaymentRatio())); |
| | | if (ObjUtil.isNotNull(contract.getOutBoundAmout())){ |
| | | contract.setOutBoundAmout(outAmount.add(contract.getOutBoundAmout())); |
| | | }else { |
| | | contract.setOutBoundAmout(outAmount); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | //最近明细 |
| | | PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | //导入数据不生成应收 |
| | | if (targetContractNo.startsWith("ZB-")) { |
| | | //计算发货前应收更新资金明细 |
| | | PaymentConfirm paymentConfirm = new PaymentConfirm(); |
| | | paymentConfirm.setBusinessType("发货前应收"); |
| | | paymentConfirm.setBusGuestId(contract.getPartyAId()); |
| | | paymentConfirm.setBusGuestName(contract.getPartyA()); |
| | | paymentConfirm.setContractId(contract.getId()); |
| | | paymentConfirm.setContractName(contract.getContractName()); |
| | | paymentConfirm.setContractNo(contract.getContractNo()); |
| | | paymentConfirm.setScheduleId(schedule.getId()); |
| | | paymentConfirm.setScheduleName(schedule.getStageName()); |
| | | paymentConfirm.setConfirmTime(addDTO.getOutBoundTime()); |
| | | //计算出库金额 |
| | | BigDecimal outAmount = addDTO.getSubjectMatterList().stream().map(item -> item.getUnitPrice().multiply(item.getOutBoundNum())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | paymentConfirm.setTransationAmount(outAmount.divide(new BigDecimal("100")).multiply(schedule.getPaymentRatio())); |
| | | if (ObjUtil.isNotNull(contract.getOutBoundAmout())) { |
| | | contract.setOutBoundAmout(outAmount.add(contract.getOutBoundAmout())); |
| | | } else { |
| | | contract.setOutBoundAmout(outAmount); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | //最近明细 |
| | | PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | //不存在发货应收 出库总额 |
| | | paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount())); |
| | | if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0"))>0){ |
| | | if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirm.setAdvanceAmount(paymentConfirm.getTotalAmount()); |
| | | } |
| | | if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0"))<0){ |
| | | if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) { |
| | | paymentConfirm.setReceivableAmount(paymentConfirm.getTotalAmount().multiply(new BigDecimal("-1"))); |
| | | } |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | } |
| | | // } |
| | | } else { |
| | | //无之前阶段应收 |
| | | paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1"))); |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | //客户付款完成合同 |
| | | List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId()) |
| | | .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount")); |
| | | if (CollUtil.isNotEmpty(customerCompleteContractList)) { |
| | | List<BigDecimal> outAmountList = new ArrayList<>(); |
| | | for (Contract completeContract : customerCompleteContractList |
| | | ) { |
| | | PaymentConfirm contractLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, completeContract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | //查询客户付款完成合同中最后明细金额 有预收转入当前合同 |
| | | if (contractLastConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | //新增完成付款合同 资金转出 |
| | | PaymentConfirm outConfirm = BeanUtil.copyProperties(contractLastConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | | } else { |
| | | //无之前阶段应收 |
| | | paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1"))); |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | //客户付款完成合同 |
| | | List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId()) |
| | | .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount")); |
| | | if (CollUtil.isNotEmpty(customerCompleteContractList)) { |
| | | List<BigDecimal> outAmountList = new ArrayList<>(); |
| | | for (Contract completeContract : customerCompleteContractList |
| | | ) { |
| | | PaymentConfirm contractLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, completeContract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | //查询客户付款完成合同中最后明细金额 有预收转入当前合同 |
| | | if (contractLastConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | //新增完成付款合同 资金转出 |
| | | PaymentConfirm outConfirm = BeanUtil.copyProperties(contractLastConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | | "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount"); |
| | | outConfirm.setBusinessType("资金转出"); |
| | | outConfirm.setConfirmTime(new Date()); |
| | | outConfirm.setTransationAmount(contractLastConfirm.getTotalAmount()); |
| | | outConfirm.setTotalAmount(new BigDecimal("0")); |
| | | paymentConfirmMapper.insert(outConfirm); |
| | | outAmountList.add(outConfirm.getTransationAmount()); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(outAmountList)) { |
| | | BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //新增当前合同 资金转入 |
| | | PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | | "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount"); |
| | | outConfirm.setBusinessType("资金转出"); |
| | | outConfirm.setConfirmTime(new Date()); |
| | | outConfirm.setTransationAmount(contractLastConfirm.getTotalAmount()); |
| | | outConfirm.setTotalAmount(new BigDecimal("0")); |
| | | paymentConfirmMapper.insert(outConfirm); |
| | | outAmountList.add(outConfirm.getTransationAmount()); |
| | | inConfirm.setBusinessType("资金转入"); |
| | | inConfirm.setConfirmTime(new Date()); |
| | | inConfirm.setTransationAmount(currentInSum); |
| | | inConfirm.setTotalAmount(paymentConfirm.getTotalAmount().add(currentInSum)); |
| | | //更新当前阶段实际收款 和 收款状态 |
| | | schedule.setActualAmount(inConfirm.getTransationAmount()); |
| | | schedule.setPaymentStatus(2); |
| | | if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | inConfirm.setAdvanceAmount(inConfirm.getTotalAmount()); |
| | | } else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) { |
| | | inConfirm.setReceivableAmount(inConfirm.getTotalAmount().multiply(new BigDecimal("-1"))); |
| | | schedule.setActualAmount(paymentConfirm.getTotalAmount().subtract(currentInSum)); |
| | | schedule.setPaymentStatus(1); |
| | | } |
| | | paymentConfirmMapper.insert(inConfirm); |
| | | //更新当前阶段实际收款 和 收款状态 |
| | | scheduleMapper.updateById(schedule); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(outAmountList)) { |
| | | BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //新增当前合同 资金转入 |
| | | PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount", |
| | | "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount"); |
| | | inConfirm.setBusinessType("资金转入"); |
| | | inConfirm.setConfirmTime(new Date()); |
| | | inConfirm.setTransationAmount(currentInSum); |
| | | inConfirm.setTotalAmount(paymentConfirm.getTotalAmount().add(currentInSum)); |
| | | //更新当前阶段实际收款 和 收款状态 |
| | | schedule.setActualAmount(inConfirm.getTransationAmount()); |
| | | schedule.setPaymentStatus(2); |
| | | if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | inConfirm.setAdvanceAmount(inConfirm.getTotalAmount()); |
| | | } else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) { |
| | | inConfirm.setReceivableAmount(inConfirm.getTotalAmount().multiply(new BigDecimal("-1"))); |
| | | schedule.setActualAmount(paymentConfirm.getTotalAmount().subtract(currentInSum)); |
| | | schedule.setPaymentStatus(1); |
| | | } |
| | | paymentConfirmMapper.insert(inConfirm); |
| | | //更新当前阶段实际收款 和 收款状态 |
| | | scheduleMapper.updateById(schedule); |
| | | } |
| | | } |
| | | } |
| | |
| | | .eq(ContractPaymentSchedule::getContractId, schedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (CollUtil.isNotEmpty(afterSchedule)&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) { |
| | | if (CollUtil.isNotEmpty(afterSchedule) && contract.getOutBoundAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setNextScheduleName(afterSchedule.get(0).getStageName()); |
| | | contractMapper.updateById(contract); |
| | | } |
| | |
| | | PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | if (lastNewConfirm.getTotalAmount().compareTo(new BigDecimal("0")) >= 0 |
| | | &&contract.getBillingAmout().compareTo(contract.getAmount())==0) { |
| | | && contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | //有预付且超过应收 关闭合同状态 |
| | | contract.setContractStatus(3); |
| | | contractMapper.updateById(contract); |
| | |
| | | /** |
| | | * 生成格式为: yyyyMMdd + 4位序列号 (例如: 20260629000001) |
| | | */ |
| | | public String generateSMJContractCKNo() { |
| | | public String generateSMJContractCKNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-SMJ-CK-"+dateStr + seqStr; |
| | | return "ZB-SMJ-CK-" + dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateYMJContractCKNo() { |
| | | public String generateYMJContractCKNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-YMJ-CK-"+dateStr + seqStr; |
| | | return "ZB-YMJ-CK-" + dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateJXCContractCKNo() { |
| | | public String generateJXCContractCKNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-JXC-CK-"+dateStr + seqStr; |
| | | return "ZB-JXC-CK-" + dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateTFContractCKNo() { |
| | | public String generateTFContractCKNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-TF-CK-"+dateStr + seqStr; |
| | | return "ZB-TF-CK-" + dateStr + seqStr; |
| | | } |
| | | |
| | | public String generateGYBContractCKNo() { |
| | | public String generateGYBContractCKNo() { |
| | | // 1. 获取当前日期字符串 |
| | | String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
| | | |
| | |
| | | String seqStr = String.format("%04d", sequence); |
| | | |
| | | // 5. 拼接返回 |
| | | return "ZB-GYB-CK-"+dateStr + seqStr; |
| | | return "ZB-GYB-CK-" + dateStr + seqStr; |
| | | } |
| | | |
| | | @Override |
| | | public R delOutBound(String batchNumber) { |
| | | List<OutBound> outBoundList = baseMapper.selectList(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber)); |
| | | if (CollUtil.isEmpty(outBoundList)){ |
| | | List<OutBound> outBoundList = baseMapper.selectList(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber, batchNumber)); |
| | | if (CollUtil.isEmpty(outBoundList)) { |
| | | return R.failed("出库信息异常,请联系营销系统管理人员"); |
| | | } |
| | | List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | .in(ContractOutBound::getOutBoundId,outBoundList.stream().map(OutBound::getId).collect(Collectors.toList()))); |
| | | if (CollUtil.isEmpty(contractOutBoundList)){ |
| | | .in(ContractOutBound::getOutBoundId, outBoundList.stream().map(OutBound::getId).collect(Collectors.toList()))); |
| | | if (CollUtil.isEmpty(contractOutBoundList)) { |
| | | return R.failed("出库信息异常,请联系营销系统管理人员"); |
| | | } |
| | | boolean allZero = true; |
| | | for (ContractOutBound item : contractOutBoundList) { |
| | | // 假设 invoiceNum 是 Integer 对象 |
| | | if (item.getInvoiceNum() == null || item.getInvoiceNum().compareTo(new BigDecimal("0"))!=0) { |
| | | if (item.getInvoiceNum() == null || item.getInvoiceNum().compareTo(new BigDecimal("0")) != 0) { |
| | | allZero = false; |
| | | break; // 发现一个不符合即退出 |
| | | } |
| | | } |
| | | if (!allZero){ |
| | | if (!allZero) { |
| | | return R.failed("请先冲减所有蓝牌后在操作"); |
| | | } |
| | | for (ContractOutBound item : contractOutBoundList) { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId,item.getContractId()).eq(ContractSubjectMatter::getMaterialCode,item.getSubjectMatterCode()) |
| | | .eq(ContractSubjectMatter::getLineNo,item.getLineNo())); |
| | | if (ObjUtil.isNotNull(subjectMatter)){ |
| | | .eq(ContractSubjectMatter::getContractId, item.getContractId()).eq(ContractSubjectMatter::getMaterialCode, item.getSubjectMatterCode()) |
| | | .eq(ContractSubjectMatter::getLineNo, item.getLineNo())); |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | subjectMatter.setDeliveredQuantity(subjectMatter.getDeliveredQuantity().subtract(item.getOutBoundNum())); |
| | | subjectMatter.setRemainingQuantity(subjectMatter.getRemainingQuantity().add(item.getOutBoundNum())); |
| | | if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0"))==0){ |
| | | if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0")) == 0) { |
| | | subjectMatter.setDeliveryStatus(0); |
| | | } |
| | | if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0"))>0){ |
| | | if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0")) > 0) { |
| | | subjectMatter.setDeliveryStatus(1); |
| | | } |
| | | //标的物更新 |
| | |
| | | //出库记录删除 |
| | | contractOutBoundMapper.deleteById(item); |
| | | } |
| | | baseMapper.delete(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber)); |
| | | baseMapper.delete(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber, batchNumber)); |
| | | return R.ok(); |
| | | } |
| | | } |