From 2f46221d32e25045a1f4d9eff852d9a612e47dbc Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 23 六月 2026 10:07:36 +0800
Subject: [PATCH] fix: 出入库金额查询产品明细表

---
 src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml b/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
index 0eebf30..40a29ff 100644
--- a/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
+++ b/src/main/resources/mapper/purchase/PaymentRegistrationMapper.xml
@@ -206,8 +206,8 @@
         LEFT JOIN (
             SELECT
                 pl.supplier_id,
-                SUM(IFNULL(slp.stocked_quantity, 0) * IFNULL(slp.tax_inclusive_unit_price, 0)) AS paymentAmount,
-                SUM((IFNULL(slp.quantity, 0) - IFNULL(slp.stocked_quantity, 0)) * IFNULL(slp.tax_inclusive_unit_price, 0)) AS payableAmount
+                SUM(IFNULL(slp.stocked_quantity, 0) * IF(IFNULL(slp.quantity, 0) > 0, slp.tax_inclusive_total_price / slp.quantity, 0)) AS paymentAmount,
+                SUM((IFNULL(slp.quantity, 0) - IFNULL(slp.stocked_quantity, 0)) * IF(IFNULL(slp.quantity, 0) > 0, slp.tax_inclusive_total_price / slp.quantity, 0)) AS payableAmount
             FROM purchase_ledger pl
             JOIN sales_ledger_product slp ON pl.id = slp.sales_ledger_id AND slp.type = 2
             GROUP BY pl.supplier_id
@@ -226,8 +226,8 @@
         LEFT JOIN (
             SELECT
                 sales_ledger_id,
-                SUM(IFNULL(stocked_quantity, 0) * IFNULL(tax_inclusive_unit_price, 0)) AS paymentAmount,
-                SUM((IFNULL(quantity, 0) - IFNULL(stocked_quantity, 0)) * IFNULL(tax_inclusive_unit_price, 0)) AS payableAmount
+                SUM(IFNULL(stocked_quantity, 0) * IF(IFNULL(quantity, 0) > 0, tax_inclusive_total_price / quantity, 0)) AS paymentAmount,
+                SUM((IFNULL(quantity, 0) - IFNULL(stocked_quantity, 0)) * IF(IFNULL(quantity, 0) > 0, tax_inclusive_total_price / quantity, 0)) AS payableAmount
             FROM sales_ledger_product
             WHERE type = 2
             GROUP BY sales_ledger_id

--
Gitblit v1.9.3