From 0c0aacce3755912bed0e576b209444411d54b5f7 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 19 八月 2026 10:19:55 +0800
Subject: [PATCH] feat: 销售台账新增未/已发货

---
 src/main/resources/mapper/sales/SalesLedgerMapper.xml |   65 +++++++++++++++++++++++++-------
 1 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/src/main/resources/mapper/sales/SalesLedgerMapper.xml b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
index 0240ec1..8b41173 100644
--- a/src/main/resources/mapper/sales/SalesLedgerMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
@@ -42,7 +42,7 @@
         </where>
     </select>
 
-    <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.pojo.SalesLedger">
+    <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.vo.SalesLedgerVo">
         SELECT T1.id,
         T1.sales_contract_no,
         T1.customer_contract_no,
@@ -62,8 +62,7 @@
         T1.payment_method,
         T1.delivery_date,
         DATEDIFF(T1.delivery_date, CURDATE()) AS delivery_days_diff,
-        IFNULL(shipping_status_counts.is_all_shipped, FALSE) AS is_fh,
-        IFNULL(production_exists.has_production, FALSE) AS has_production_record
+        IFNULL(shipping_status_counts.is_all_shipped, FALSE) AS is_fh
         FROM sales_ledger T1
         LEFT JOIN sys_user T2 ON T1.entry_person = T2.user_id
         LEFT JOIN (
@@ -75,13 +74,7 @@
         FROM shipping_info
         GROUP BY sales_ledger_id
         ) shipping_status_counts ON T1.id = shipping_status_counts.sales_ledger_id
-        LEFT JOIN (
-        SELECT DISTINCT po.sales_ledger_id,
-        TRUE AS has_production
-        FROM product_order po
-        INNER JOIN product_work_order wo ON wo.product_order_id = po.id
-        INNER JOIN production_product_main pm ON pm.work_order_id = wo.id
-        ) production_exists ON T1.id = production_exists.sales_ledger_id
+
         <where>
             <if test="salesLedgerDto.customerName != null and salesLedgerDto.customerName != '' ">
                 AND T1.customer_name LIKE CONCAT('%',#{salesLedgerDto.customerName},'%')
@@ -95,6 +88,30 @@
             <if test="salesLedgerDto.projectName != null and salesLedgerDto.projectName != '' ">
                 AND T1.project_name LIKE CONCAT('%',#{salesLedgerDto.projectName},'%')
             </if>
+            <if test="salesLedgerDto.shippingStatus != null and salesLedgerDto.shippingStatus != '' ">
+                AND T1.id IN (
+                SELECT slp.sales_ledger_id
+                FROM sales_ledger_product slp
+                LEFT JOIN (
+                SELECT si.sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) AS shipped_quantity
+                FROM shipping_info si
+                LEFT JOIN shipping_product_detail spd ON si.id = spd.shipping_info_id
+                WHERE si.status != '瀹℃牳鎷掔粷'
+                GROUP BY si.sales_ledger_product_id
+                ) ship ON ship.sales_ledger_product_id = slp.id
+                WHERE slp.type = 1
+                GROUP BY slp.sales_ledger_id
+                HAVING
+                <choose>
+                    <when test="'宸插彂璐�'.equals(salesLedgerDto.shippingStatus)">
+                        SUM(CASE WHEN IFNULL(slp.quantity, 0) - IFNULL(ship.shipped_quantity, 0) &gt; 0 THEN 1 ELSE 0 END) = 0
+                    </when>
+                    <otherwise>
+                        SUM(CASE WHEN IFNULL(slp.quantity, 0) - IFNULL(ship.shipped_quantity, 0) &gt; 0 THEN 1 ELSE 0 END) &gt; 0
+                    </otherwise>
+                </choose>
+                )
+            </if>
             <if test="salesLedgerDto.entryDateStart != null and salesLedgerDto.entryDateStart != '' ">
                 AND T1.entry_date &gt;= DATE_FORMAT(#{salesLedgerDto.entryDateStart},'%Y-%m-%d')
             </if>
@@ -102,7 +119,7 @@
                 AND T1.entry_date &lt;= DATE_FORMAT(#{salesLedgerDto.entryDateEnd},'%Y-%m-%d')
             </if>
         </where>
-        order by T1.entry_date desc
+        order by T1.entry_date desc, T1.sales_contract_no desc
     </select>
 
     <select id="selectIncomeStats" resultType="com.ruoyi.home.dto.IncomeExpenseAnalysisDto">
@@ -117,16 +134,34 @@
         FROM sales_ledger
         GROUP BY customer_name
     </select>
+
     <select id="listSalesLedgerAndShipped" resultType="com.ruoyi.sales.dto.SalesLedgerDto">
         select distinct sl.id as 'disId', sl.* from
         sales_ledger sl
         left join sales_ledger_product slp on sl.id = slp.sales_ledger_id
         left join shipping_info si on slp.id = si.sales_ledger_product_id
-        where si.status = '宸插彂璐�'
-        <if test="ew.customerName != null and ew.customerName != '' ">
-            and sl.customer_name like concat('%',#{ew.customerName},'%')
+        where si.status = '瀹℃牳閫氳繃'
+        <if test="ew.customerId != null and ew.customerId != '' ">
+            and sl.customer_id = #{ew.customerId}
         </if>
         order by sl.execution_date desc
     </select>
 
-</mapper>
\ No newline at end of file
+    <select id="selectPurchaseReportVoPage" resultType="com.ruoyi.purchase.vo.PurchaseReportVo">
+        select sl.sales_contract_no customerContractNo,
+               c.customer_name,
+               sl.project_name,
+               sl.contract_amount contractAmount,
+               pl.contract_amount purchaseAmount,
+               sl.contract_amount-pl.contract_amount balance,
+               (sl.contract_amount-pl.contract_amount)/sl.contract_amount balanceRatio
+        from sales_ledger sl
+        left join purchase_ledger pl on sl.id = pl.sales_ledger_id
+        left join customer c on sl.customer_id = c.id
+        where 1=1
+        <if test="customerName != null and customerName != '' ">
+            and c.customer_name like concat('%',#{customerName},'%')
+        </if>
+    </select>
+
+</mapper>

--
Gitblit v1.9.3