| | |
| | | private final PaymentConfirmMapper paymentConfirmMapper; |
| | | private final CurrentOverdueMapper currentOverdueMapper; |
| | | private final BusinessCustomerMapper businessCustomerMapper; |
| | | private final MeterReadRecordMapper meterReadRecordMapper; |
| | | private final ContractExecDateMapper contractExecDateMapper; |
| | | private final RemoteFlowProcessService remoteFlowProcessService; |
| | | private final ContractTemplateMapper contractTemplateMapper; |
| | | private final RemoteDeptService remoteDeptService; |
| | |
| | | subjectMatter.setDeliveryStatus(0); |
| | | subjectMatter.setTotalAmount(contractSubjectMatterAddDTO.getQuantity().multiply(contractSubjectMatterAddDTO.getUnitPrice())); |
| | | contractSubjectMatterMapper.insert(subjectMatter); |
| | | //水电类必须有初次表号 |
| | | if (StrUtil.isNotEmpty(contractSubjectMatterAddDTO.getMeterReadCode()) && |
| | | ObjUtil.isNotNull(contractSubjectMatterAddDTO.getMeterReadNum())) { |
| | | MeterReadRecord record = BeanUtil.copyProperties(contractSubjectMatterAddDTO, MeterReadRecord.class,"id"); |
| | | record.setContractId(contract.getId()); |
| | | record.setMatterId(subjectMatter.getId()); |
| | | record.setContractName(contract.getContractName()); |
| | | record.setBusGuestId(contract.getPartyAId()); |
| | | record.setBusGuestName(contract.getPartyA()); |
| | | record.setMeterReadTime(new Date()); |
| | | meterReadRecordMapper.insert(record); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | if (ArrayUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) { |
| | |
| | | |
| | | } |
| | | |
| | | if (StrUtil.isNotEmpty(addDTO.getContractCategory()) && StrUtil.equals(addDTO.getContractCategory(), "water_house")) { |
| | | |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | |
| | | Contract contract = baseMapper.selectById(id); |
| | | contract.setContractStatus(2); |
| | | baseMapper.updateById(contract); |
| | | ContractPaymentSchedule fitstSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime).last("limit 1")); |
| | | if (fitstSchedule.getStageName().equals("合同签订")) { |
| | | //新增应收 |
| | | savePaymentConfirm(contract, fitstSchedule); |
| | | if (StrUtil.isNotEmpty(contract.getContractCategory()) && StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId,id)); |
| | | if (ArrayUtil.isNotEmpty(subjectMatterList.toArray())) { |
| | | subjectMatterList.stream().forEach(contractSubjectMatter -> { |
| | | |
| | | //新增合同履约记录 |
| | | ContractPaymentScheduleProcess process = new ContractPaymentScheduleProcess(); |
| | | process.setContractId(contract.getId()); |
| | | process.setContractName(contract.getContractName()); |
| | | process.setScheduleId(fitstSchedule.getId()); |
| | | process.setScheduleName(fitstSchedule.getStageName()); |
| | | process.setProcessDate(contract.getSignDate()); |
| | | contractPaymentScheduleProcessMapper.insert(process); |
| | | //循环日期 |
| | | Date execDate0 = DateUtil.offsetDay(contract.getSignDate(), contract.getExecDay()); |
| | | for (int i = 0; i < contract.getExecTimes(); i++) { |
| | | if (StrUtil.equals(contract.getExecFrequency(), "1")) { |
| | | Date execDatei = DateUtil.offsetWeek(execDate0, i); |
| | | ContractExecDate execDate = new ContractExecDate(); |
| | | execDate.setContractId(contract.getId()); |
| | | execDate.setMatterId(contractSubjectMatter.getId()); |
| | | execDate.setExecDate(execDatei); |
| | | execDate.setGenFlag("0"); |
| | | contractExecDateMapper.insert(execDate); |
| | | } |
| | | if (StrUtil.equals(contract.getExecFrequency(), "2")) { |
| | | Date execDatei = DateUtil.offsetMonth(execDate0, i ); |
| | | ContractExecDate execDate = new ContractExecDate(); |
| | | execDate.setContractId(contract.getId()); |
| | | execDate.setMatterId(contractSubjectMatter.getId()); |
| | | execDate.setExecDate(execDatei); |
| | | execDate.setGenFlag("0"); |
| | | contractExecDateMapper.insert(execDate); |
| | | } |
| | | if (StrUtil.equals(contract.getExecFrequency(), "3")) { |
| | | Date execDatei = DateUtil.offsetMonth(execDate0, i * 3); |
| | | ContractExecDate execDate = new ContractExecDate(); |
| | | execDate.setContractId(contract.getId()); |
| | | execDate.setMatterId(contractSubjectMatter.getId()); |
| | | execDate.setExecDate(execDatei); |
| | | execDate.setGenFlag("0"); |
| | | contractExecDateMapper.insert(execDate); |
| | | } |
| | | if (StrUtil.equals(contract.getExecFrequency(), "4")) { |
| | | Date execDatei = DateUtil.offsetMonth(execDate0, i * 6); |
| | | ContractExecDate execDate = new ContractExecDate(); |
| | | execDate.setContractId(contract.getId()); |
| | | execDate.setMatterId(contractSubjectMatter.getId()); |
| | | execDate.setExecDate(execDatei); |
| | | execDate.setGenFlag("0"); |
| | | contractExecDateMapper.insert(execDate); |
| | | } |
| | | if (StrUtil.equals(contract.getExecFrequency(), "5")) { |
| | | Date execDatei = DateUtil.offsetYear(execDate0, i); |
| | | ContractExecDate execDate = new ContractExecDate(); |
| | | execDate.setContractId(contract.getId()); |
| | | execDate.setMatterId(contractSubjectMatter.getId()); |
| | | execDate.setExecDate(execDatei); |
| | | execDate.setGenFlag("0"); |
| | | contractExecDateMapper.insert(execDate); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } else { |
| | | ContractPaymentSchedule fitstSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime).last("limit 1")); |
| | | if (fitstSchedule.getStageName().equals("合同签订")) { |
| | | //新增应收 |
| | | savePaymentConfirm(contract, fitstSchedule); |
| | | |
| | | //新增合同履约记录 |
| | | ContractPaymentScheduleProcess process = new ContractPaymentScheduleProcess(); |
| | | process.setContractId(contract.getId()); |
| | | process.setContractName(contract.getContractName()); |
| | | process.setScheduleId(fitstSchedule.getId()); |
| | | process.setScheduleName(fitstSchedule.getStageName()); |
| | | process.setProcessDate(contract.getSignDate()); |
| | | contractPaymentScheduleProcessMapper.insert(process); |
| | | // //当前为合同最后阶段 |
| | | // PaymentConfirm newConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,contract.getId()) |
| | | // .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | |
| | | // contract.setContractStatus(3); |
| | | // baseMapper.updateById(contract); |
| | | // } |
| | | } else if (fitstSchedule.getStageName().equals("发货前")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("无"); |
| | | baseMapper.updateById(contract); |
| | | } else if (fitstSchedule.getStageName().equals("货到签收")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("货到签收"); |
| | | baseMapper.updateById(contract); |
| | | } else if (fitstSchedule.getStageName().equals("调试完成或验收")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("调试完成或验收"); |
| | | baseMapper.updateById(contract); |
| | | } else { |
| | | //新增应收 |
| | | savePaymentConfirm(contract, fitstSchedule); |
| | | } |
| | | //查询是否有后续阶段 |
| | | List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, fitstSchedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, fitstSchedule.getStageOrder()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) { |
| | | //最后阶段生效时间 |
| | | ContractPaymentSchedule endSchedule = afterSchedule.get(0); |
| | | if (StrUtil.equals(endSchedule.getStageName(), "质保金")) { |
| | | } else if (fitstSchedule.getStageName().equals("发货前")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("无"); |
| | | baseMapper.updateById(contract); |
| | | } else if (fitstSchedule.getStageName().equals("货到签收")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("货到签收"); |
| | | baseMapper.updateById(contract); |
| | | } else if (fitstSchedule.getStageName().equals("调试完成或验收")) { |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName("调试完成或验收"); |
| | | baseMapper.updateById(contract); |
| | | } else { |
| | | //新增应收 |
| | | savePaymentConfirm(contract, fitstSchedule); |
| | | } |
| | | //查询是否有后续阶段 |
| | | List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, fitstSchedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, fitstSchedule.getStageOrder()) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime)); |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) { |
| | | //最后阶段生效时间 |
| | | ContractPaymentSchedule endSchedule = afterSchedule.get(0); |
| | | if (StrUtil.equals(endSchedule.getStageName(), "质保金")) { |
| | | // endSchedule.setEffectiveEndDate(DateUtil.offsetDay(new Date(),endSchedule.getAgreedDays())); |
| | | // contractPaymentScheduleMapper.updateById(endSchedule); |
| | | //最后阶段应收 |
| | | PaymentConfirm newConfim = new PaymentConfirm(); |
| | | newConfim.setBusinessType(endSchedule.getStageName() + "应收"); |
| | | newConfim.setBusGuestId(contract.getPartyAId()); |
| | | newConfim.setBusGuestName(contract.getPartyA()); |
| | | newConfim.setContractId(contract.getId()); |
| | | newConfim.setContractName(contract.getContractName()); |
| | | newConfim.setContractNo(contract.getContractNo()); |
| | | newConfim.setScheduleId(endSchedule.getId()); |
| | | newConfim.setScheduleName(endSchedule.getStageName()); |
| | | newConfim.setConfirmTime(new Date()); |
| | | newConfim.setTransationAmount(endSchedule.getPlannedAmount()); |
| | | newConfim.setReceivableAmount(endSchedule.getPlannedAmount()); |
| | | PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | BigDecimal lastNewTotal = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(lastNewConfirm)) { |
| | | lastNewTotal = lastNewConfirm.getTotalAmount(); |
| | | //最后阶段应收 |
| | | PaymentConfirm newConfim = new PaymentConfirm(); |
| | | newConfim.setBusinessType(endSchedule.getStageName() + "应收"); |
| | | newConfim.setBusGuestId(contract.getPartyAId()); |
| | | newConfim.setBusGuestName(contract.getPartyA()); |
| | | newConfim.setContractId(contract.getId()); |
| | | newConfim.setContractName(contract.getContractName()); |
| | | newConfim.setContractNo(contract.getContractNo()); |
| | | newConfim.setScheduleId(endSchedule.getId()); |
| | | newConfim.setScheduleName(endSchedule.getStageName()); |
| | | newConfim.setConfirmTime(new Date()); |
| | | newConfim.setTransationAmount(endSchedule.getPlannedAmount()); |
| | | newConfim.setReceivableAmount(endSchedule.getPlannedAmount()); |
| | | PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | BigDecimal lastNewTotal = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(lastNewConfirm)) { |
| | | lastNewTotal = lastNewConfirm.getTotalAmount(); |
| | | } |
| | | newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount())); |
| | | if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(newConfim); |
| | | } |
| | | } |
| | | newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount())); |
| | | if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(newConfim); |
| | | } |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(endSchedule.getStageName()); |
| | | baseMapper.updateById(contract); |
| | | } |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(endSchedule.getStageName()); |
| | | baseMapper.updateById(contract); |
| | | } |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) { |
| | | //第一阶段生效时间 |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) { |
| | | //第一阶段生效时间 |
| | | // fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays())); |
| | | // contractPaymentScheduleMapper.updateById(fitstSchedule); |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(afterSchedule.get(0).getStageName()); |
| | | baseMapper.updateById(contract); |
| | | } |
| | | //只有当前合同签字阶段 |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(afterSchedule.get(0).getStageName()); |
| | | baseMapper.updateById(contract); |
| | | } |
| | | //只有当前合同签字阶段 |
| | | // if(ArrayUtil.isEmpty(afterSchedule.toArray())){ |
| | | // fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays())); |
| | | // contractPaymentScheduleMapper.updateById(fitstSchedule); |
| | | // } |
| | | } |
| | | } |
| | | |
| | | private void savePaymentConfirm(Contract contract, ContractPaymentSchedule schedule) { |
| | |
| | | //更新当前阶段实际收款 和 收款状态 |
| | | schedule.setActualAmount(inConfirm.getTransationAmount()); |
| | | schedule.setPaymentStatus(2); |
| | | if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0){ |
| | | if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) { |
| | | inConfirm.setAdvanceAmount(inConfirm.getTotalAmount()); |
| | | }else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) { |
| | | } else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) { |
| | | inConfirm.setReceivableAmount(inConfirm.getTotalAmount().multiply(new BigDecimal("-1"))); |
| | | schedule.setActualAmount(currentInSum); |
| | | schedule.setPaymentStatus(1); |
| | |
| | | } |
| | | |
| | | |
| | | }else { |
| | | } else { |
| | | paymentConfirmMapper.insert(paymentConfirm); |
| | | } |
| | | } |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public R genCycleReceiced() { |
| | | List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery() |
| | | .le(ContractExecDate::getExecDate, DateUtil.today()).eq(ContractExecDate::getGenFlag,"0")); |
| | | if (ArrayUtil.isNotEmpty(execDateList.toArray())) { |
| | | execDateList.stream().forEach(contractExecDate -> { |
| | | Contract contract = baseMapper.selectById(contractExecDate.getContractId()); |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getContractId, contractExecDate.getContractId()) |
| | | .eq(ContractSubjectMatter::getId, contractExecDate.getMatterId())); |
| | | //生成抄表单 |
| | | if (StrUtil.isNotEmpty(subjectMatter.getMeterReadCode()) && |
| | | ObjUtil.isNotNull(subjectMatter.getMeterReadNum())) { |
| | | MeterReadRecord record = BeanUtil.copyProperties(subjectMatter, MeterReadRecord.class, "id","meterReadNum"); |
| | | record.setMatterId(subjectMatter.getId()); |
| | | record.setBusGuestId(contract.getPartyAId()); |
| | | record.setBusGuestName(contract.getPartyA()); |
| | | meterReadRecordMapper.insert(record); |
| | | }else { |
| | | //房屋租赁生成应收 |
| | | PaymentConfirm confirm = new PaymentConfirm(); |
| | | confirm.setBusinessType("房屋租赁应收"); |
| | | confirm.setBusGuestId(contract.getPartyAId()); |
| | | confirm.setBusGuestName(contract.getPartyA()); |
| | | confirm.setContractId(contract.getId()); |
| | | confirm.setContractName(contract.getContractName()); |
| | | confirm.setContractNo(contract.getContractNo()); |
| | | confirm.setConfirmTime(contractExecDate.getExecDate()); |
| | | confirm.setTransationAmount(subjectMatter.getUnitPrice().multiply(subjectMatter.getQuantity())); |
| | | confirm.setTotalAmount(confirm.getTransationAmount().multiply(new BigDecimal("-1"))); |
| | | PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) |
| | | .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | BigDecimal total = lastConfirm.getTotalAmount().add(confirm.getTotalAmount()); |
| | | if (total.compareTo(new BigDecimal("0")) > 0) { |
| | | confirm.setAdvanceAmount(total); |
| | | confirm.setTotalAmount(total); |
| | | } else if (total.compareTo(new BigDecimal("0")) == 0) { |
| | | confirm.setTotalAmount(total); |
| | | } else { |
| | | confirm.setReceivableAmount(total.multiply(new BigDecimal("-1"))); |
| | | confirm.setTotalAmount(total); |
| | | } |
| | | confirm.setCompId(contract.getCompId()); |
| | | paymentConfirmMapper.insert(confirm); |
| | | } else { |
| | | confirm.setReceivableAmount(confirm.getTransationAmount()); |
| | | confirm.setTotalAmount(confirm.getReceivableAmount().multiply(new BigDecimal("-1"))); |
| | | confirm.setCompId(contract.getCompId()); |
| | | paymentConfirmMapper.insert(confirm); |
| | | } |
| | | } |
| | | contractExecDate.setGenFlag("1"); |
| | | contractExecDateMapper.updateById(contractExecDate); |
| | | }); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |