| | |
| | | currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount())); |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(currentConfim); |
| | | //更新当前阶段付款情况 |
| | | if (lastTotal.compareTo(new BigDecimal("0"))>0){ |
| | | if (currentConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) { |
| | | schedule.setPaymentStatus(2); |
| | | schedule.setPlannedAmount(schedule.getPlannedAmount()); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | }else { |
| | | schedule.setPaymentStatus(1); |
| | | schedule.setPlannedAmount(lastTotal); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | //查询是否有后续阶段 |
| | |
| | | newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount())); |
| | | if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(newConfim); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | } else if (schedule.getStageName().equals("调试完成或验收")){ |
| | | //新增当前阶段应收 |
| | | PaymentConfirm currentConfim = new PaymentConfirm(); |
| | | currentConfim.setBusinessType(schedule.getStageName() + "应收"); |
| | |
| | | currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount())); |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(currentConfim); |
| | | //更新当前阶段付款情况 |
| | | if (lastTotal.compareTo(new BigDecimal("0"))>0){ |
| | | if (currentConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) { |
| | | schedule.setPaymentStatus(2); |
| | | schedule.setPlannedAmount(schedule.getPlannedAmount()); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | }else { |
| | | schedule.setPaymentStatus(1); |
| | | schedule.setPlannedAmount(lastTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //查询是否有后续阶段 |
| | | List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, schedule.getContractId()) |
| | | .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())); |
| | | .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()) |
| | | .gt(ContractPaymentSchedule::getPaymentRatio,"0")); |
| | | if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) { |
| | | //最后阶段生效时间 |
| | | ContractPaymentSchedule endSchedule = afterSchedule.get(0); |
| | | if (StrUtil.equals(endSchedule.getStageName(), "质保金")) { |
| | | endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays())); |
| | | contractPaymentScheduleMapper.updateById(endSchedule); |
| | | //当前阶段生效时间 |
| | | schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays())); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | //最后阶段应收 |
| | | 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(schedule.getStageName()); |
| | | newConfim.setConfirmTime(addDTO.getProcessDate()); |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | // if (StrUtil.equals(endSchedule.getStageName(), "质保金")) { |
| | | // endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays())); |
| | | // contractPaymentScheduleMapper.updateById(endSchedule); |
| | | // //当前阶段生效时间 |
| | | // schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays())); |
| | | // contractPaymentScheduleMapper.updateById(schedule); |
| | | // //最后阶段应收 |
| | | // 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(schedule.getStageName()); |
| | | // newConfim.setConfirmTime(addDTO.getProcessDate()); |
| | | // 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); |
| | | // //更新当前阶段付款情况 |
| | | // if (lastNewTotal.compareTo(new BigDecimal("0"))>0){ |
| | | // if (newConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) { |
| | | // schedule.setPaymentStatus(2); |
| | | // schedule.setPlannedAmount(schedule.getPlannedAmount()); |
| | | // contractPaymentScheduleMapper.updateById(schedule); |
| | | // }else { |
| | | // schedule.setPaymentStatus(1); |
| | | // schedule.setPlannedAmount(lastNewTotal); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(endSchedule.getStageName()); |
| | | contractMapper.updateById(contract); |
| | |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } |
| | | }else { |
| | | |
| | | //最后阶段应收 |
| | | PaymentConfirm newConfim = new PaymentConfirm(); |
| | | newConfim.setBusinessType(schedule.getStageName() + "应收"); |
| | | newConfim.setBusGuestId(contract.getPartyAId()); |
| | | newConfim.setBusGuestName(contract.getPartyA()); |
| | | newConfim.setContractId(contract.getId()); |
| | | newConfim.setContractName(contract.getContractName()); |
| | | newConfim.setContractNo(contract.getContractNo()); |
| | | newConfim.setScheduleId(schedule.getId()); |
| | | newConfim.setScheduleName(schedule.getStageName()); |
| | | newConfim.setConfirmTime(addDTO.getProcessDate()); |
| | | newConfim.setTransationAmount(schedule.getPlannedAmount()); |
| | | newConfim.setReceivableAmount(schedule.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 (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |
| | | paymentConfirmMapper.insert(newConfim); |
| | | //更新当前阶段付款情况 |
| | | if (lastNewTotal.compareTo(new BigDecimal("0"))>0){ |
| | | if (newConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) { |
| | | schedule.setPaymentStatus(2); |
| | | schedule.setPlannedAmount(schedule.getPlannedAmount()); |
| | | }else { |
| | | schedule.setPaymentStatus(1); |
| | | schedule.setPlannedAmount(lastNewTotal); |
| | | } |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | } |
| | | } |
| | | //更新合同下个阶段 |
| | | contract.setNextScheduleName(""); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | |
| | | |