From e4a391c581aaca1fa7b0239bc96375d0c0cb8de6 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期三, 04 二月 2026 08:55:49 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs |   81 +++++++++++++++++++++-------------------
 1 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
index c5805da..98407dc 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -342,10 +342,12 @@
         {
             List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
             List<IStockInfoService.residueQuantity> newresidueQantity = new List<IStockInfoService.residueQuantity>();
-            List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>(); ;
+            List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>();
+
             foreach (var dt_OutboundOrderDetail in dt_OutboundOrderDetails)
             {
                 notStocks = stockInfos.Where(x => x.Details.Any(x =>x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)).OrderBy(x => x.Id).ToList();
+
                 if (notStocks.Count > 0)
                 {
                     decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.MaterielCode == dt_OutboundOrderDetail.MaterielCode).Sum(v => v.StockQuantity - v.OutboundQuantity);
@@ -357,48 +359,51 @@
                         {
 
                             Dt_StockInfo stockInfo = stockInfos[index];
-                            Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
+                            List<Dt_StockInfoDetail> dt_StockInfoDetails = new List<Dt_StockInfoDetail>();
                             foreach (var detail in stockInfo.Details)
                             {
                                 if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
                                 {
-                                    dt_StockInfoDetail = detail;
+                                    dt_StockInfoDetails.Add(detail);
                                 }
                             }
-                            decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
-                            if (useableStockQuantity < needQuantity)
+                            foreach(var dt_StockInfoDetail in dt_StockInfoDetails)
                             {
-                                stockInfo.Details.ForEach(x =>
+                                decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
+                                if (useableStockQuantity < needQuantity)
                                 {
-                                    if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+                                    foreach (var item in stockInfo.Details)
                                     {
-                                        x.OutboundQuantity = x.StockQuantity;
-                                    }
-                                });
-                                needQuantity -= useableStockQuantity;
-                            }
-                            else
-                            {
-
-                                stockInfo.Details.ForEach(x =>
-                                {
-                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
-                                    {
-                                        if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+                                        if(item.MaterielCode == dt_OutboundOrderDetail.MaterielCode && dt_StockInfoDetail.BatchNo == item.BatchNo)
                                         {
-                                            x.OutboundQuantity += needQuantity;
-                                            needQuantity = 0;
-                                        }
-                                        else
-                                        {
-                                            needQuantity -= (x.StockQuantity - x.OutboundQuantity);
-                                            x.OutboundQuantity = x.StockQuantity;
+                                            item.OutboundQuantity = item.StockQuantity;
                                         }
                                     }
-                                });
+                                    needQuantity -= useableStockQuantity;
+                                }
+                                else
+                                {
+                                    foreach (var item in stockInfo.Details)
+                                    {
+                                        if(item.StockQuantity > item.OutboundQuantity && item.MaterielCode == dt_StockInfoDetail.MaterielCode && item.BatchNo == dt_StockInfoDetail.BatchNo)
+                                        {
+                                            if (item.StockQuantity - item.OutboundQuantity >= needQuantity)
+                                            {
+                                                dt_StockInfoDetail.OutboundQuantity += needQuantity;
+                                                needQuantity = 0;
+                                            }
+                                            else
+                                            {
+                                                needQuantity -= (item.StockQuantity - item.OutboundQuantity);
+                                                item.OutboundQuantity = item.StockQuantity;
+                                            }
+                                        }
+                                    }
+                                }
+                                outStocks.Add(stockInfo);
+                                index++;
+                                if (needQuantity == 0) break;
                             }
-                            outStocks.Add(stockInfo);
-                            index++;
                         }
                     }
                     else
@@ -411,7 +416,7 @@
                             {
                                 if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
                                 {
-                                    useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity;
+                                    useableStockQuantity += detail.StockQuantity - detail.OutboundQuantity;
                                 }
                             }
 
@@ -427,22 +432,22 @@
                             }
                             else
                             {
-                                stockInfo.Details.ForEach(x =>
+                                foreach (var detail in stockInfo.Details)
                                 {
-                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+                                    if(detail.StockQuantity > detail.OutboundQuantity && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
                                     {
-                                        if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+                                        if(detail.StockQuantity - detail.OutboundQuantity >= needQuantity)
                                         {
-                                            x.OutboundQuantity += needQuantity;
+                                            detail.OutboundQuantity += needQuantity;
                                             needQuantity = 0;
                                         }
                                         else
                                         {
-                                            needQuantity -= (x.StockQuantity - x.OutboundQuantity);
-                                            x.OutboundQuantity = x.StockQuantity;
+                                            needQuantity -= (detail.StockQuantity - detail.OutboundQuantity);
+                                            detail.OutboundQuantity = detail.StockQuantity;
                                         }
                                     }
-                                });
+                                }
                             }
                             outStocks.Add(stockInfo);
                         }

--
Gitblit v1.9.3