From 8e14fa84f6f2dfdda8a739400fca80ac73dca874 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期四, 25 十二月 2025 11:06:21 +0800
Subject: [PATCH] yys  修改项目利润,供应商往来

---
 src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
index 731b5c5..b5baf13 100644
--- a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
+++ b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
@@ -6,28 +6,28 @@
 
 
     <select id="selectPurchaseReport" resultType="com.ruoyi.purchase.dto.InvoicePurchaseReportDto">
-        select sl.customer_contract_no,
-               sl.customer_name,
-               sl.project_name,
-               sl.contract_amount,
-               pl.contract_amount as purchase_amount,
-               sum(slp.tax_exclusive_total_price) as sale_tax_exclusive_total_price,
-               sum(pr.tax_exclusive_total_price) as tax_exclusive_total_price,
-               (sl.contract_amount-pl.contract_amount) as balance,
-        CONCAT(FORMAT((sl.contract_amount - pl.contract_amount) / sl.contract_amount * 100, 2), '%') AS balance_ratio,
-               sl.contract_amount-sum(slp.tax_exclusive_total_price)-(pl.contract_amount-sum(pr.tax_exclusive_total_price)) as balance_amount
-        from purchase_ledger pl
-                 left join sales_ledger sl on pl.sales_ledger_id = sl.id
-                 left join product_record pr on pr.purchase_ledger_id = pl.id
-                 left join sales_ledger_product slp on slp.sales_ledger_id = sl.id
-
-        group by sl.customer_contract_no, sl.customer_name, sl.project_name, sl.contract_amount, pl.contract_amount
-        having sl.customer_contract_no is not null
+        SELECT
+        sl.sales_contract_no AS customerContractNo,
+        sl.customer_name,
+        sl.contract_amount AS contract_amount,
+        SUM( pl.contract_amount ) AS purchase_amount,
+        (
+        sl.contract_amount - SUM( pl.contract_amount )) AS balance,
+        CONCAT( ROUND( ( sl.contract_amount - SUM( pl.contract_amount )) / sl.contract_amount * 100, 1 ), '%' ) AS balance_ratio
+        FROM
+        sales_ledger sl
+        INNER JOIN purchase_ledger pl ON sl.sales_contract_no = pl.sales_contract_no
         <where>
             <if test="c.customerName != null and c.customerName != ''">
-                and sl.customer_name like concat('%',#{c.customerName},'%')
+                AND sl.customer_name LIKE CONCAT('%', #{c.customerName}, '%')
             </if>
         </where>
+        GROUP BY
+        sl.sales_contract_no,
+        sl.customer_name,
+        sl.contract_amount
+        ORDER BY
+        sl.sales_contract_no;
     </select>
     <select id="listVat" resultType="com.ruoyi.purchase.dto.VatDto">
         select *
@@ -44,6 +44,7 @@
                                 LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id
                        WHERE il.invoice_no IS NOT NULL
                          AND invoice_type = '澧炰笓绁�'
+                         AND DATE_FORMAT(il.invoice_date, '%Y-%m') IS NOT NULL  -- 鏂板锛氳繃婊onth涓篘ULL鐨勬儏
                        GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m')
                    ) a1
                        LEFT JOIN (
@@ -102,12 +103,14 @@
                            LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id
                   WHERE il.invoice_no IS NOT NULL
                     AND invoice_type = '澧炰笓绁�'
+                    AND DATE_FORMAT(il.invoice_date, '%Y-%m') IS NOT NULL  -- 鏂板锛氳繃婊onth涓篘ULL鐨勬儏
                   GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m')
               ) a1 ON a1.month = a2.month
               WHERE a1.month IS NULL
               ORDER BY month
              )as a
         <where>
+            a.month is not null
             <if test="month != null">
                 and a.month = #{month}
             </if>

--
Gitblit v1.9.3