| | |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal())); |
| | | paymentRegistrationMapper.insert(paymentRegistration); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | // 2. 处理账户收入 |
| | | // 2. 处理账户支出 |
| | | AccountExpense accountExpense = new AccountExpense(); |
| | | accountExpense.setExpenseDate(purchaseLedger.getEntryDate()); |
| | | accountExpense.setExpenseType("0"); |
| | |
| | | @Override |
| | | public int updatePaymentRegistration(PaymentRegistration paymentRegistration) { |
| | | PaymentRegistration paymentRegistration1 = paymentRegistrationMapper.selectById(paymentRegistration.getId()); |
| | | |
| | | TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()==null?paymentRegistration1.getTicketRegistrationId():paymentRegistration.getTicketRegistrationId()); |
| | | |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() |
| | | .eq("ticket_registration_id", paymentRegistration.getTicketRegistrationId()).ne("id", paymentRegistration.getId())); |
| | | BigDecimal total = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | if (total.add(paymentRegistration.getCurrentPaymentAmount()).compareTo(ticketRegistration.getInvoiceAmount()) > 0) { |
| | | throw new RuntimeException("付款金额超出发票金额"); |
| | | if(null==paymentRegistration1) throw new RuntimeException("未找到付款登记"); |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration1.getSalesLedgerProductId()); |
| | | if(null==salesLedgerProduct) throw new RuntimeException("未找到采购单产品"); |
| | | // 判断付款金额不可大于待付款金额 |
| | | BigDecimal subtract = paymentRegistration.getCurrentPaymentAmount().subtract(paymentRegistration1.getCurrentPaymentAmount()); |
| | | if (subtract.compareTo(salesLedgerProduct.getPendingTicketsTotal()) > 0) { |
| | | throw new RuntimeException("付款金额超出待付款金额"); |
| | | } |
| | | |
| | | paymentRegistration.setUpdateTime(DateUtils.getNowDate()); |
| | | // 同步修改账户支出 |
| | | LambdaQueryWrapper<AccountExpense> accountExpenseLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | accountExpenseLambdaQueryWrapper.eq(AccountExpense::getBusinessId, paymentRegistration.getId()) |
| | | .eq(AccountExpense::getBusinessType, 1) |
| | | .last("limit 1"); |
| | | AccountExpense accountExpense = accountExpenseService.getOne(accountExpenseLambdaQueryWrapper); |
| | | if(null!=accountExpense){ |
| | | accountExpense.setExpenseMoney(paymentRegistration.getCurrentPaymentAmount()); |
| | | accountExpenseService.updateById(accountExpense); |
| | | } |
| | | // 修改采购产品付款金额 |
| | | salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().add(subtract)); |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getTicketsTotal())); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | return paymentRegistrationMapper.updateById(paymentRegistration); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int delPaymentRegistration(Long id) { |
| | | // PaymentRegistration paymentRegistration = paymentRegistrationMapper.selectById(id); |
| | | // TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()); |
| | | // if (ticketRegistration != null) { |
| | | // ticketRegistration.setPaymentAmountTotal(ticketRegistration.getPaymentAmountTotal().subtract(paymentRegistration.getCurrentPaymentAmount())); |
| | | // ticketRegistration.setUnPaymentAmountTotal(ticketRegistration.getUnPaymentAmountTotal().add(paymentRegistration.getCurrentPaymentAmount())); |
| | | // ticketRegistrationMapper.updateById(ticketRegistration); |
| | | // } |
| | | |
| | | return paymentRegistrationMapper.deleteById(id); |
| | | public int delPaymentRegistration(List<Long> ids) { |
| | | LambdaQueryWrapper<AccountExpense> accountExpenseLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | accountExpenseLambdaQueryWrapper.in(AccountExpense::getBusinessId, ids) |
| | | .eq(AccountExpense::getBusinessType, 1); |
| | | accountExpenseService.remove(accountExpenseLambdaQueryWrapper); |
| | | // 修改采购产品的已付款金额,待付款金额 |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectBatchIds(ids); |
| | | for (PaymentRegistration paymentRegistration : paymentRegistrations) { |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(paymentRegistration.getSalesLedgerProductId()); |
| | | salesLedgerProduct.setTicketsTotal(salesLedgerProduct.getTicketsTotal().subtract(paymentRegistration.getCurrentPaymentAmount())); |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getPendingTicketsTotal().add(paymentRegistration.getCurrentPaymentAmount())); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | return paymentRegistrationMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |