| | |
| | | import com.by4cloud.platformx.business.vo.ContractPaymentScheduleVo; |
| | | import com.by4cloud.platformx.business.vo.ScheduleProcessVo; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | BigDecimal lastTotal = new BigDecimal("0"); |
| | | if (ObjUtil.isNotNull(lastConfirm)) { |
| | | lastTotal = lastConfirm.getTotalAmount(); |
| | | }else { |
| | | //客户付款完成合同 |
| | | List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId()) |
| | | .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount")); |
| | | if (ArrayUtil.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 (ArrayUtil.isNotEmpty(outAmountList.toArray())){ |
| | | BigDecimal currentSum = new BigDecimal("0"); |
| | | for (BigDecimal currentAmount:outAmountList |
| | | ) { |
| | | currentSum=currentSum.add(currentAmount); |
| | | //新增当前合同 资金转入 |
| | | PaymentConfirm inConfirm = BeanUtil.copyProperties(lastConfirm,PaymentConfirm.class,"id","transationAmount", |
| | | "advanceAmount","receivableAmount","overdueAmount","totalAmount"); |
| | | inConfirm.setBusinessType("资金转入"); |
| | | inConfirm.setConfirmTime(new Date()); |
| | | inConfirm.setTransationAmount(currentSum.subtract(currentAmount)); |
| | | inConfirm.setTotalAmount(lastConfirm.getTotalAmount().add(currentSum)); |
| | | 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"))); |
| | | } |
| | | paymentConfirmMapper.insert(inConfirm); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount())); |
| | | if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { |