From cd0984bff3ac9c4480685671d4e033c8b082bfed Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 04 六月 2026 17:04:39 +0800
Subject: [PATCH] 发货去除库存数量限制,产品库存不足也可以发货,库存数量可以展示为负

---
 src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml |  240 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 127 insertions(+), 113 deletions(-)

diff --git a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
index 413f293..2a1425c 100644
--- a/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
+++ b/src/main/resources/mapper/purchase/InvoicePurchaseMapper.xml
@@ -7,130 +7,144 @@
 
     <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 *
-        from (SELECT
-                  COALESCE(a1.month, a2.month) AS month,
-                  IFNULL(a1.tax_amount, 0) AS j_tax_amount,
-                  IFNULL(a2.x_tax_amount, 0) AS x_tax_amount
-              FROM (
-                       -- 绗竴涓煡璇細鏉ヨ嚜 invoice_ledger 鐨勭◣棰�
-                       SELECT
-                           DATE_FORMAT(il.invoice_date, '%Y-%m') AS month,
-                           ROUND(SUM(pr.invoice_amount - pr.invoice_amount / (1 + pr.tax_rate / 100)), 2) AS tax_amount
-                       FROM invoice_ledger il
-                                LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id
-                       WHERE il.invoice_no IS NOT NULL
-                         AND invoice_type = '澧炰笓绁�'
-                       GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m')
-                   ) a1
-                       LEFT JOIN (
-                  -- 绗簩涓煡璇細鏉ヨ嚜 ticket_registration 鐨勭◣棰�
-                  SELECT
-                      DATE_FORMAT(a.issue_date, '%Y-%m') AS month,
-                      SUM(a.invoice_amount) AS x_tax_amount
-                  FROM (
-                           SELECT DISTINCT pr.id,
-                                           tr.issue_date,
-                                           ROUND(pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS un_tickets_price,
-                                           ROUND(pr.tickets_amount - pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS invoice_amount
-                           FROM product_record pr
-                                    LEFT JOIN purchase_ledger pl ON pl.id = pr.purchase_ledger_id
-                                    LEFT JOIN sales_ledger sl ON sl.id = pl.sales_ledger_id
-                                    LEFT JOIN ticket_registration tr ON tr.purchase_ledger_id = pl.id
-                                    LEFT JOIN product_model pm ON pm.id = pr.product_model_id
-                           WHERE type = 2
-                             AND tr.invoice_number IS NOT NULL
-                       ) a
-                  GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')
-              ) a2 ON a1.month = a2.month
+        <!--        select *-->
+        <!--        from (SELECT-->
+        <!--                  COALESCE(a1.month, a2.month) AS month,-->
+        <!--                  IFNULL(a1.tax_amount, 0) AS j_tax_amount,-->
+        <!--                  IFNULL(a2.x_tax_amount, 0) AS x_tax_amount-->
+        <!--              FROM (-->
+        <!--                       &#45;&#45; 绗竴涓煡璇細鏉ヨ嚜 invoice_ledger 鐨勭◣棰�-->
+        <!--                       SELECT-->
+        <!--                           DATE_FORMAT(il.invoice_date, '%Y-%m') AS month,-->
+        <!--                           ROUND(SUM(pr.invoice_amount - pr.invoice_amount / (1 + pr.tax_rate / 100)), 2) AS tax_amount-->
+        <!--                       FROM invoice_ledger il-->
+        <!--                                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  &#45;&#45; 鏂板锛氳繃婊onth涓篘ULL鐨勬儏-->
+        <!--                       GROUP BY DATE_FORMAT(il.invoice_date, '%Y-%m')-->
+        <!--                   ) a1-->
+        <!--                       LEFT JOIN (-->
+        <!--                  &#45;&#45; 绗簩涓煡璇細鏉ヨ嚜 ticket_registration 鐨勭◣棰�-->
+        <!--                  SELECT-->
+        <!--                      DATE_FORMAT(a.issue_date, '%Y-%m') AS month,-->
+        <!--                      SUM(a.invoice_amount) AS x_tax_amount-->
+        <!--                  FROM (-->
+        <!--                           SELECT DISTINCT pr.id,-->
+        <!--                                           tr.issue_date,-->
+        <!--                                           ROUND(pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS un_tickets_price,-->
+        <!--                                           ROUND(pr.tickets_amount - pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS invoice_amount-->
+        <!--                           FROM product_record pr-->
+        <!--                                    LEFT JOIN purchase_ledger pl ON pl.id = pr.purchase_ledger_id-->
+        <!--                                    LEFT JOIN sales_ledger sl ON sl.id = pl.sales_ledger_id-->
+        <!--                                    LEFT JOIN ticket_registration tr ON tr.purchase_ledger_id = pl.id-->
+        <!--                                    LEFT JOIN product_model pm ON pm.id = pr.product_model_id-->
+        <!--                           WHERE type = 2-->
+        <!--                             AND tr.invoice_number IS NOT NULL-->
+        <!--                       ) a-->
+        <!--                  GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')-->
+        <!--              ) a2 ON a1.month = a2.month-->
 
-              UNION ALL
+        <!--              UNION ALL-->
 
-              SELECT
-                  COALESCE(a1.month, a2.month) AS month,
-                  IFNULL(a1.tax_amount, 0) AS tax_amount,
-                  IFNULL(a2.x_tax_amount, 0) AS x_tax_amount
-              FROM (
-                       -- 绗簩涓煡璇細鏉ヨ嚜 ticket_registration 鐨勭◣棰濓紙鍙嶈繃鏉ヨˉ鍏ㄦ病鏈夊尮閰嶅埌鐨勶級
-                       SELECT
-                           DATE_FORMAT(a.issue_date, '%Y-%m') AS month,
-                           SUM(a.invoice_amount) AS x_tax_amount
-                       FROM (
-                                SELECT DISTINCT pr.id,
-                                                tr.issue_date,
-                                                ROUND(pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS un_tickets_price,
-                                                ROUND(pr.tickets_amount - pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS invoice_amount
-                                FROM product_record pr
-                                         LEFT JOIN purchase_ledger pl ON pl.id = pr.purchase_ledger_id
-                                         LEFT JOIN sales_ledger sl ON sl.id = pl.sales_ledger_id
-                                         LEFT JOIN ticket_registration tr ON tr.purchase_ledger_id = pl.id
-                                         LEFT JOIN product_model pm ON pm.id = pr.product_model_id
-                                WHERE type = 2
-                                  AND tr.invoice_number IS NOT NULL
-                            ) a
-                       GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')
-                   ) a2
-                       LEFT JOIN (
-                  -- 绗竴涓煡璇細鏉ヨ嚜 invoice_ledger 鐨勭◣棰�
-                  SELECT
-                      DATE_FORMAT(il.invoice_date, '%Y-%m') AS month,
-                      ROUND(SUM(pr.invoice_amount - pr.invoice_amount / (1 + pr.tax_rate / 100)), 2) AS tax_amount
-                  FROM invoice_ledger il
-                           LEFT JOIN invoice_registration_product pr ON pr.id = il.invoice_registration_product_id
-                  WHERE il.invoice_no IS NOT NULL
-                    AND invoice_type = '澧炰笓绁�'
-                  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
+        <!--              SELECT-->
+        <!--                  COALESCE(a1.month, a2.month) AS month,-->
+        <!--                  IFNULL(a1.tax_amount, 0) AS tax_amount,-->
+        <!--                  IFNULL(a2.x_tax_amount, 0) AS x_tax_amount-->
+        <!--              FROM (-->
+        <!--                       &#45;&#45; 绗簩涓煡璇細鏉ヨ嚜 ticket_registration 鐨勭◣棰濓紙鍙嶈繃鏉ヨˉ鍏ㄦ病鏈夊尮閰嶅埌鐨勶級-->
+        <!--                       SELECT-->
+        <!--                           DATE_FORMAT(a.issue_date, '%Y-%m') AS month,-->
+        <!--                           SUM(a.invoice_amount) AS x_tax_amount-->
+        <!--                       FROM (-->
+        <!--                                SELECT DISTINCT pr.id,-->
+        <!--                                                tr.issue_date,-->
+        <!--                                                ROUND(pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS un_tickets_price,-->
+        <!--                                                ROUND(pr.tickets_amount - pr.tickets_amount / (1 + pr.tax_rate / 100), 2) AS invoice_amount-->
+        <!--                                FROM product_record pr-->
+        <!--                                         LEFT JOIN purchase_ledger pl ON pl.id = pr.purchase_ledger_id-->
+        <!--                                         LEFT JOIN sales_ledger sl ON sl.id = pl.sales_ledger_id-->
+        <!--                                         LEFT JOIN ticket_registration tr ON tr.purchase_ledger_id = pl.id-->
+        <!--                                         LEFT JOIN product_model pm ON pm.id = pr.product_model_id-->
+        <!--                                WHERE type = 2-->
+        <!--                                  AND tr.invoice_number IS NOT NULL-->
+        <!--                            ) a-->
+        <!--                       GROUP BY DATE_FORMAT(a.issue_date, '%Y-%m')-->
+        <!--                   ) a2-->
+        <!--                       LEFT JOIN (-->
+        <!--                  &#45;&#45; 绗竴涓煡璇細鏉ヨ嚜 invoice_ledger 鐨勭◣棰�-->
+        <!--                  SELECT-->
+        <!--                      DATE_FORMAT(il.invoice_date, '%Y-%m') AS month,-->
+        <!--                      ROUND(SUM(pr.invoice_amount - pr.invoice_amount / (1 + pr.tax_rate / 100)), 2) AS tax_amount-->
+        <!--                  FROM invoice_ledger il-->
+        <!--                           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  &#45;&#45; 鏂板锛氳繃婊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>-->
+        <!--        </where>-->
+        select * from (
+        SELECT
+        month,
+        SUM(sales_tax_amount) AS j_tax_amount,
+        SUM(purchase_tax_amount) AS x_tax_amount
+        FROM (
+        SELECT
+        DATE_FORMAT(entry_date, '%Y-%m') AS month,
+        ROUND(SUM(contract_amount * 0.13), 2) AS sales_tax_amount,
+        0 AS purchase_tax_amount
+        FROM sales_ledger
+        WHERE entry_date IS NOT NULL
+        GROUP BY DATE_FORMAT(entry_date, '%Y-%m')
+
+        UNION ALL
+
+        SELECT
+        DATE_FORMAT(entry_date, '%Y-%m') AS month,
+        0 AS sales_tax_amount,
+        ROUND(SUM(contract_amount * 0.26), 2) AS purchase_tax_amount
+        FROM purchase_ledger
+        WHERE entry_date IS NOT NULL
+        GROUP BY DATE_FORMAT(entry_date, '%Y-%m')
+        ) t
+        GROUP BY month
+        ORDER BY month
+        ) a
         <where>
-            <if test="month != null">
+            a.month is not null
+            <if test="month != null and month != ''">
                 and a.month = #{month}
             </if>
         </where>

--
Gitblit v1.9.3