From 2bdf6b86c427cd8a0f433d6a559d532eed67b733 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 13 八月 2026 13:40:57 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_天津_意博凯信' into dev_天津_意博凯信

---
 src/main/resources/mapper/account/AccountStatementMapper.xml |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/src/main/resources/mapper/account/AccountStatementMapper.xml b/src/main/resources/mapper/account/AccountStatementMapper.xml
index 331c61b..324d243 100644
--- a/src/main/resources/mapper/account/AccountStatementMapper.xml
+++ b/src/main/resources/mapper/account/AccountStatementMapper.xml
@@ -40,4 +40,130 @@
             </if>
     ORDER BY lj.statement_month DESC
     </select>
+    <select id="selectVatDtoPage" resultType="com.ruoyi.purchase.dto.VatDto">
+        SELECT * FROM (
+            SELECT
+                asi.id,
+                asi.invoice_number AS invoiceNumber,
+                asi.issue_date AS issueDate,
+                'sales' AS type,
+                asi.invoice_type AS invoiceType,
+                asi.tax_price AS taxAmount,
+                asi.tax_inclusive_price AS totalAmount,
+                c.customer_name AS customerName,
+                NULL AS supplierName,
+                DATE_FORMAT(asi.issue_date, '%Y-%m') AS month
+            FROM account_sales_invoice asi
+            LEFT JOIN customer c ON c.id = asi.customer_id
+            WHERE (asi.status IS NULL OR asi.status = 0)
+            UNION ALL
+            SELECT
+                api.id,
+                api.invoice_number AS invoiceNumber,
+                api.issue_date AS issueDate,
+                'purchase' AS type,
+                api.invoice_type AS invoiceType,
+                api.tax_price AS taxAmount,
+                api.tax_inclusive_price AS totalAmount,
+                NULL AS customerName,
+                s.supplier_name AS supplierName,
+                DATE_FORMAT(api.issue_date, '%Y-%m') AS month
+            FROM account_purchase_invoice api
+            LEFT JOIN supplier_manage s ON s.id = api.supplier_id
+            WHERE (api.status IS NULL OR api.status = 0)
+        ) AS invoice_detail
+        <where>
+            <if test="month != null and month != ''">
+                AND month = #{month}
+            </if>
+            <if test="type != null and type != ''">
+                AND type = #{type}
+            </if>
+        </where>
+        ORDER BY issueDate DESC, type
+    </select>
+
+    <select id="selectVatSummary" resultType="com.ruoyi.purchase.dto.VatSummaryDto">
+        SELECT
+            month,
+            SUM(jTaxAmount) AS jTaxAmount,
+            SUM(xTaxAmount) AS xTaxAmount,
+            SUM(jTaxAmount) - SUM(xTaxAmount) AS taxAmount
+        FROM (
+            SELECT
+                DATE_FORMAT(issue_date, '%Y-%m') AS month,
+                SUM(tax_price) AS jTaxAmount,
+                0 AS xTaxAmount
+            FROM account_sales_invoice
+            WHERE (status IS NULL OR status = 0)
+            <if test="year != null and year != ''">
+                AND YEAR(issue_date) = #{year}
+            </if>
+            GROUP BY DATE_FORMAT(issue_date, '%Y-%m')
+            UNION ALL
+            SELECT
+                DATE_FORMAT(issue_date, '%Y-%m') AS month,
+                0 AS jTaxAmount,
+                SUM(tax_price) AS xTaxAmount
+            FROM account_purchase_invoice
+            WHERE (status IS NULL OR status = 0)
+            <if test="year != null and year != ''">
+                AND YEAR(issue_date) = #{year}
+            </if>
+            GROUP BY DATE_FORMAT(issue_date, '%Y-%m')
+        ) t
+        GROUP BY month
+        ORDER BY month
+    </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