From 1ab612fa454477bfaec03b0fe9133f8881ce29cc Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 16 一月 2026 16:16:02 +0800
Subject: [PATCH] yys 回款---财务收入,付款---财务支出

---
 src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java |   57 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
index ec3be20..a32b6f6 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -124,7 +124,7 @@
             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");
@@ -151,18 +151,29 @@
     @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);
     }
 
@@ -464,16 +475,20 @@
     }
 
     @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

--
Gitblit v1.9.3