From 620bb4712a31791231c4381581f0f60088f079fe Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 27 五月 2026 14:03:45 +0800
Subject: [PATCH] Merge branch 'refs/heads/dev_New_pro' into dev_宁夏_英泽防锈

---
 src/main/resources/mapper/basic/CustomerMapper.xml |   87 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/src/main/resources/mapper/basic/CustomerMapper.xml b/src/main/resources/mapper/basic/CustomerMapper.xml
index b2546d7..2957c7e 100644
--- a/src/main/resources/mapper/basic/CustomerMapper.xml
+++ b/src/main/resources/mapper/basic/CustomerMapper.xml
@@ -52,6 +52,7 @@
                 )
             </if>
         </where>
+        order by c.id desc
     </select>
 
     <select id="list" resultType="com.ruoyi.basic.vo.CustomerVo">
@@ -106,5 +107,91 @@
                 )
             </if>
         </where>
+        order by c.id desc
+    </select>
+    <select id="customewTransactions" resultType="com.ruoyi.sales.vo.CustomerTransactionsVo">
+        select T1.customer_id,
+               c.customer_name,
+               T1.contractAmounts,
+               IFNULL(T2.receiptPaymentAmount, 0) AS receiptPaymentAmount,
+               IFNULL(T3.outboundAmount, 0) - IFNULL(T4.returnAmount, 0) AS receiptableAmount
+        from (select customer_id, sum(contract_amount) as contractAmounts from sales_ledger group by customer_id) T1
+        left join (select customer_id, sum(collection_amount) as receiptPaymentAmount from account_sales_collection group by customer_id) T2 on T1.customer_id = T2.customer_id
+        left join (
+            SELECT
+                sl.customer_id,
+                sum(sor.stock_out_num * slp.tax_inclusive_unit_price) as outboundAmount
+            FROM stock_out_record sor
+            LEFT join shipping_info s on sor.record_id = s.id
+            LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
+            LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id
+            WHERE sor.record_type='13'
+                and sor.approval_status=1
+                and slp.type = 1
+            group by sl.customer_id
+        ) T3 on T3.customer_id=T1.customer_id
+        left join (
+            select
+                sl.customer_id,
+                sum(rm.refund_amount) as returnAmount
+            from return_management rm
+            left join shipping_info si on rm.shipping_id = si.id
+            left join sales_ledger sl on si.sales_ledger_id = sl.id
+            where rm.status=1
+            group by sl.customer_id
+        ) T4 on T4.customer_id=T1.customer_id
+        left join customer c on T1.customer_id = c.id
+        <where>
+            <if test="customerName!=null and customerName!=''">
+                AND c.customer_name LIKE CONCAT('%', #{customerName}, '%')
+            </if>
+        </where>
+        order by T1.customer_id desc
+    </select>
+    <select id="customewTransactionsDetails"
+            resultType="com.ruoyi.sales.vo.CustomerTransactionsDetailsVo">
+        select sl.id salesLedgerId,
+               sl.sales_contract_no,
+               sl.execution_date,
+               sl.contract_amount,
+               IFNULL(T1.receiptPaymentAmount, 0) AS receiptPaymentAmount,
+               IFNULL(T2.outboundAmount, 0) - IFNULL(T3.returnAmount, 0) AS receiptableAmount
+        from sales_ledger sl
+        left join (
+            select
+                sl.id,
+                sum(ascc.collection_amount) as receiptPaymentAmount
+            from account_sales_collection ascc
+            left join stock_out_record sor on FIND_IN_SET(sor.id, ascc.stock_out_record_ids) > 0
+            left join shipping_info s on sor.record_id = s.id
+            LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
+            WHERE sor.record_type='13'
+              and sor.approval_status=1
+            group by  sl.id
+        )T1 on T1.id = sl.id
+        left join (
+            SELECT
+                sl.id,
+                sum(sor.stock_out_num * slp.tax_inclusive_unit_price) as outboundAmount
+            FROM stock_out_record sor
+                     left join shipping_info s on sor.record_id = s.id
+                     LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
+                     LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id
+            WHERE sor.record_type='13'
+              and sor.approval_status=1
+              and slp.type = 1
+            group by  sl.id
+        )T2 on T2.id = sl.id
+        left join (
+            select sl.id,
+                   sum(rm.refund_amount) as returnAmount
+            from return_management rm
+                     left join shipping_info si on rm.shipping_id = si.id
+                     left join sales_ledger sl on si.sales_ledger_id = sl.id
+            where rm.status=1
+            group by sl.id
+        )T3 on T3.id = sl.id
+        where sl.customer_id = #{customerId}
+        order by sl.id desc
     </select>
 </mapper>

--
Gitblit v1.9.3