From f0efc10af370936b4db47b8428eb1ca4686431f9 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 06 八月 2026 15:11:56 +0800
Subject: [PATCH] feat(home): 添加报表日期范围筛选功能并完善设备维护管理

---
 src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml |  103 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 66 insertions(+), 37 deletions(-)

diff --git a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
index af6e508..5f4f0f4 100644
--- a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
+++ b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
@@ -7,49 +7,27 @@
 
     <select id="selectPurchaseReport" resultType="com.ruoyi.purchase.dto.InvoicePurchaseReportDto">
         SELECT
-        A.*,
-        FORMAT(A.sales_tax_amount - A.purchase_tax_amount, 2) AS balance_amount
-        FROM (
-        SELECT
-        sl.customer_contract_no,
-        sl.id,
-        pl.id AS pl_id,
+        sl.sales_contract_no AS customerContractNo,
         sl.customer_name,
-        sl.project_name,
-        slp.tax_inclusive_total_price - slp.tax_exclusive_total_price AS contract_amount,
-        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS purchase_amount,
-        (slp.tax_exclusive_total_price) / COUNT(slp.id) AS sale_tax_exclusive_total_price,
-        SUM(slp1.tax_exclusive_total_price) AS tax_exclusive_total_price,
-        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) -
-        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS balance,
-        CONCAT(
-        FORMAT(
-        ((slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) -
-        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price)) /
-        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) * 100,
-        2),
-        '%'
-        ) AS balance_ratio,
-        (slp.tax_inclusive_total_price - slp.tax_exclusive_total_price) AS sales_tax_amount,
-        SUM(slp1.tax_inclusive_total_price - slp1.tax_exclusive_total_price) AS purchase_tax_amount
+        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
-        purchase_ledger pl
-        LEFT JOIN
-        sales_ledger sl ON pl.sales_ledger_id = sl.id
-        LEFT JOIN
-        sales_ledger_product slp ON slp.sales_ledger_id = sl.id AND slp.type = 1
-        LEFT JOIN
-        sales_ledger_product slp1 ON slp1.sales_ledger_id = pl.id AND slp1.type = 2
-        GROUP BY
-        sl.customer_contract_no, sl.customer_name, sl.project_name, sl.id, pl.id
-        HAVING
-        sl.customer_contract_no IS NOT NULL
-        ) A
+        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 A.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 *
@@ -165,4 +143,55 @@
 #         GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')
     </select>
 
+    <select id="listVatDetail" resultType="com.ruoyi.purchase.dto.VatDto">
+        SELECT *
+        FROM (
+            -- 杩涢」绋庢槑缁嗭紙閲囪喘璁㈠崟锛�
+            SELECT
+                pl.purchase_contract_number AS invoiceNo,
+                pl.sales_contract_no AS salesContractNo,
+                pl.supplier_name AS supplierName,
+                NULL AS customerName,
+                '杩涢」' AS orderType,
+                pl.entry_date AS invoiceDate,
+                slp.tax_rate AS taxRate,
+                ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS jTaxAmount,
+                0 AS xTaxAmount,
+                ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS taxAmount
+            FROM sales_ledger_product slp
+            LEFT JOIN purchase_ledger pl ON pl.id = slp.sales_ledger_id
+            WHERE slp.type = 2
+              AND slp.tax_rate IS NOT NULL
+              AND slp.tax_rate > 0
+            GROUP BY pl.id
+
+            UNION ALL
+
+            -- 閿�椤圭◣鏄庣粏锛堥攢鍞鍗曪級
+            SELECT
+                sl.sales_contract_no AS invoiceNo,
+                sl.sales_contract_no AS salesContractNo,
+                NULL AS supplierName,
+                sl.customer_name AS customerName,
+                '閿�椤�' AS orderType,
+                sl.entry_date AS invoiceDate,
+                slp.tax_rate AS taxRate,
+                0 AS jTaxAmount,
+                ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS xTaxAmount,
+                ROUND(SUM(slp.tax_inclusive_total_price - slp.tax_exclusive_total_price), 2) AS taxAmount
+            FROM sales_ledger_product slp
+            LEFT JOIN sales_ledger sl ON sl.id = slp.sales_ledger_id
+            WHERE slp.type = 1
+              AND slp.tax_rate IS NOT NULL
+              AND slp.tax_rate > 0
+            GROUP BY sl.id
+        ) a
+        <where>
+            <if test="month != null and month != ''">
+                AND DATE_FORMAT(a.invoiceDate, '%Y-%m') = #{month}
+            </if>
+        </where>
+        ORDER BY a.invoiceDate DESC
+    </select>
+
 </mapper>

--
Gitblit v1.9.3