| | |
| | | @Value("${dept.smjzt}") |
| | | private String smjzt; |
| | | |
| | | @Value("${dept.smjhw}") |
| | | private String smjhw; |
| | | |
| | | @Value("${dept.sgb}") |
| | | private String sgb; |
| | | |
| | |
| | | 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)) { |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)|| |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjhw)) { |
| | | outBound.setBatchNumber(generateSMJContractCKNo()); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) { |
| | |
| | | // 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); |
| | | } |
| | | } |
| | | |
| | | //查询是否有后续阶段 |
| | |
| | | public R addContractOut(OutBoundAddDTO addDTO) { |
| | | //校验参数 |
| | | R<Contract> r = vailParam(addDTO); |
| | | if (!r.isOk()){ |
| | | if (!r.isOk()) { |
| | | return r; |
| | | } |
| | | Contract contract = r.getData(); |
| | | String batchNumber = genBatchNumber(); |
| | | //出库 |
| | | handleOutBound(contract,addDTO); |
| | | handleOutBound(batchNumber,contract, addDTO); |
| | | |
| | | //保存资金明细 |
| | | BigDecimal outBoundAmount = savePaymentConfirm(contract,addDTO); |
| | | BigDecimal outBoundAmount = savePaymentConfirm(contract, addDTO); |
| | | //更新合同状态及阶段 |
| | | contract.setOutBoundAmout(outBoundAmount); |
| | | updateContractSchedule(contract); |
| | | |
| | | return R.ok(); |
| | | return R.ok(batchNumber); |
| | | } |
| | | |
| | | private void updateContractSchedule(Contract contract) { |
| | | 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() + "应收"); |
| | |
| | | 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")); |
| | |
| | | currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1"))); |
| | | paymentConfirmMapper.insert(currentConfim); |
| | | //历史资金余额 |
| | | processService.handleBeforeRemain(currentConfim,contract); |
| | | processService.handleBeforeRemain(currentConfim, contract); |
| | | } |
| | | return outAmount; |
| | | } |
| | | |
| | | private void handleOutBound(Contract contract, OutBoundAddDTO addDTO) { |
| | | private void handleOutBound(String batchNumber,Contract contract, OutBoundAddDTO addDTO) { |
| | | addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()) |
| | |
| | | subjectMatter.setActualDeliveryDate(addDTO.getOutBoundTime()); |
| | | 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); |
| | | }); |
| | |
| | | |
| | | private String genBatchNumber() { |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) || |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) { |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)|| |
| | | StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjhw)) { |
| | | return generateSMJContractCKNo(); |
| | | } |
| | | if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) { |
| | |
| | | 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()); |