From d4b2252268142d9b6f35f6fdc590c4e7cf6f0df3 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期日, 28 六月 2026 20:37:20 +0800
Subject: [PATCH] fix: 销售台账根据合同号倒序

---
 src/main/resources/mapper/sales/InvoiceLedgerMapper.xml |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml b/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
index 0112361..8d95575 100644
--- a/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
+++ b/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
@@ -127,8 +127,8 @@
         LEFT JOIN (
             SELECT
                 sl.customer_id,
-                SUM(IFNULL(slp.shipped_quantity, 0) * IFNULL(slp.tax_inclusive_unit_price, 0)) AS receipt_payment_amount,
-                SUM((IFNULL(slp.stocked_quantity, 0) - IFNULL(slp.shipped_quantity, 0)) * IFNULL(slp.tax_inclusive_unit_price, 0)) AS unReceipt_payment_amount
+                SUM(IFNULL(slp.shipped_quantity, 0) * IF(IFNULL(slp.quantity, 0) > 0, slp.tax_inclusive_total_price / slp.quantity, 0)) AS receipt_payment_amount,
+                SUM((IFNULL(slp.stocked_quantity, 0) - IFNULL(slp.shipped_quantity, 0)) * IF(IFNULL(slp.quantity, 0) > 0, slp.tax_inclusive_total_price / slp.quantity, 0)) AS unReceipt_payment_amount
             FROM sales_ledger sl
             JOIN sales_ledger_product slp ON sl.id = slp.sales_ledger_id AND slp.type = 1
             GROUP BY sl.customer_id

--
Gitblit v1.9.3