From 0f746d8324fb2ce65119627890b9c26ba1eaadd0 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 24 六月 2026 14:56:06 +0800
Subject: [PATCH] fix(sales): 修复客户交易查询中的合同金额计算问题
---
src/main/java/com/ruoyi/procurementrecord/service/impl/ReturnManagementServiceImpl.java | 15 +++++++++++++--
src/main/resources/mapper/basic/CustomerMapper.xml | 2 +-
src/main/java/com/ruoyi/sales/pojo/SalesLedger.java | 3 +++
src/main/resources/mapper/sales/ShippingInfoMapper.xml | 5 +++--
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/procurementrecord/service/impl/ReturnManagementServiceImpl.java b/src/main/java/com/ruoyi/procurementrecord/service/impl/ReturnManagementServiceImpl.java
index 28bbb43..c49f6c6 100644
--- a/src/main/java/com/ruoyi/procurementrecord/service/impl/ReturnManagementServiceImpl.java
+++ b/src/main/java/com/ruoyi/procurementrecord/service/impl/ReturnManagementServiceImpl.java
@@ -21,6 +21,7 @@
import com.ruoyi.procurementrecord.service.ReturnSaleProductService;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.service.ShippingInfoService;
import lombok.RequiredArgsConstructor;
@@ -123,8 +124,18 @@
}
salesRefundAmountOrder.setRefundAmount(bigDecimal);
salesRefundAmountOrder.setNotRefundedAmount(salesRefundAmountOrder.getRefundedAmount());
- // 鍒嗘壒閫�娆�
-// salesRefundAmountOrderService.addSalesRefundAmountOrderDto(salesRefundAmountOrder);
+ // 鏇存柊閿�鍞彴璐︾殑閫�璐у悗鍚堝悓閲戦
+ if (byId.getShippingId() != null) {
+ ShippingInfo shippingInfo = shippingInfoService.getById(byId.getShippingId());
+ if (shippingInfo != null && shippingInfo.getSalesLedgerId() != null) {
+ SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId());
+ if (salesLedger != null && salesLedger.getContractAmount() != null) {
+ BigDecimal netAmount = salesLedger.getContractAmount().subtract(byId.getRefundAmount() != null ? byId.getRefundAmount() : BigDecimal.ZERO);
+ salesLedger.setNetContractAmount(netAmount);
+ salesLedgerMapper.updateById(salesLedger);
+ }
+ }
+ }
return true;
}
diff --git a/src/main/java/com/ruoyi/sales/pojo/SalesLedger.java b/src/main/java/com/ruoyi/sales/pojo/SalesLedger.java
index 00736ba..5f292b2 100644
--- a/src/main/java/com/ruoyi/sales/pojo/SalesLedger.java
+++ b/src/main/java/com/ruoyi/sales/pojo/SalesLedger.java
@@ -109,6 +109,9 @@
@Schema(description = "浠樻鏂瑰紡")
private String paymentMethod;
+ @Schema(description = "瀹為檯鍚堝悓閲戦")
+ private BigDecimal netContractAmount;
+
@TableField(exist = false)
@Schema(description = "鐢熶骇鐘舵��")
private String productionStatus = "鏈紑濮�";
diff --git a/src/main/resources/mapper/basic/CustomerMapper.xml b/src/main/resources/mapper/basic/CustomerMapper.xml
index 37886d5..f001387 100644
--- a/src/main/resources/mapper/basic/CustomerMapper.xml
+++ b/src/main/resources/mapper/basic/CustomerMapper.xml
@@ -126,7 +126,7 @@
<select id="customewTransactions" resultType="com.ruoyi.sales.vo.CustomerTransactionsVo">
select T1.customer_id,
c.customer_name,
- T1.contractAmounts,
+ T1.contractAmounts - IFNULL(T4.returnAmount, 0) AS contractAmounts,
IFNULL(T2.receiptPaymentAmount, 0) AS receiptPaymentAmount,
IFNULL(T3.outboundAmount, 0) - IFNULL(T4.returnAmount, 0) AS receiptableAmount
from (select customer_id, sum(contract_amount) as contractAmounts from sales_ledger group by customer_id) T1
diff --git a/src/main/resources/mapper/sales/ShippingInfoMapper.xml b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
index 762c2d4..6fc1842 100644
--- a/src/main/resources/mapper/sales/ShippingInfoMapper.xml
+++ b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
@@ -101,8 +101,9 @@
order by sor.id
</select>
<select id="getShippingInfoByCustomerName" resultType="com.ruoyi.sales.pojo.ShippingInfo">
- select * from shipping_info si
+ select distinct si.* from shipping_info si
left join sales_ledger sl on si.sales_ledger_id = sl.id
- where sl.customer_name = #{customerName}
+ inner join stock_out_record sor on sor.record_id = si.id and sor.record_type = '13' and sor.approval_status = 1
+ where sl.customer_name = #{customerName} and si.status = '瀹℃牳閫氳繃'
</select>
</mapper>
--
Gitblit v1.9.3