From c6f6be2d942214580e61c2647c846d7e11e06f48 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期一, 19 一月 2026 15:42:11 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
index 029a2cd..8f4388d 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -1,6 +1,7 @@
 锘縰sing AutoMapper;
 using Magicodes.ExporterAndImporter.Core;
 using Magicodes.ExporterAndImporter.Excel;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using SqlSugar;
 using System;
@@ -192,6 +193,112 @@
             return outStocks;
         }
 
+        //浣庢俯銆佽嵂姘村垎閰嶅簱瀛�
+        public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode,string batchNo ,decimal needQuantity, out decimal residueQuantity)
+        {
+            List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+            decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.BatchNo == batchNo).Sum(v => v.StockQuantity - v.OutboundQuantity);
+            stockInfos = stockInfos.Where(x => x.Details.Any(x => x.BatchNo == batchNo)).OrderBy(x => x.Id).ToList();
+            if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
+            {
+                int index = 0;
+                while (needQuantity > 0)
+                {
+
+                    Dt_StockInfo stockInfo = stockInfos[index];
+                    Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
+                    foreach(var detail in stockInfo.Details)
+                    {
+                        if(detail.BatchNo == batchNo && detail.MaterielCode == materielCode)
+                        {
+                            dt_StockInfoDetail = detail;
+                        }
+                    }
+                    decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
+                    if (useableStockQuantity < needQuantity)
+                    {
+                        stockInfo.Details.ForEach(x =>
+                        {
+                            if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
+                            {
+                                x.OutboundQuantity = x.StockQuantity;
+                            }
+                        });
+                        needQuantity -= useableStockQuantity;
+                    }
+                    else
+                    {
+
+                        stockInfo.Details.ForEach(x =>
+                        {
+                            if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+                            {
+                                if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+                                {
+                                    x.OutboundQuantity += needQuantity;
+                                    needQuantity = 0;
+                                }
+                                else
+                                {
+                                    needQuantity -= (x.StockQuantity - x.OutboundQuantity);
+                                    x.OutboundQuantity = x.StockQuantity;
+                                }
+                            }
+                        });
+                    }
+                    outStocks.Add(stockInfo);
+                    index++;
+                }
+            }
+            else
+            {
+                for (int i = 0; i < stockInfos.Count; i++)
+                {
+                    Dt_StockInfo stockInfo = stockInfos[i];
+                    decimal useableStockQuantity = 0;
+                    foreach (var detail in stockInfo.Details)
+                    {
+                        if(detail.MaterielCode == materielCode && detail.BatchNo == batchNo)
+                        {
+                            useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity;
+                        }
+                    }
+                    
+                    if (useableStockQuantity < needQuantity)
+                    {
+                        stockInfo.Details.ForEach(x => { 
+                            if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
+                            {
+                                x.OutboundQuantity = x.StockQuantity;
+                            }
+                        });
+                        needQuantity -= useableStockQuantity;
+                    }
+                    else
+                    {
+                        stockInfo.Details.ForEach(x =>
+                        {
+                            if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+                            {
+                                if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+                                {
+                                    x.OutboundQuantity += needQuantity;
+                                    needQuantity = 0;
+                                }
+                                else
+                                {
+                                    needQuantity -= (x.StockQuantity - x.OutboundQuantity);
+                                    x.OutboundQuantity = x.StockQuantity;
+                                }
+                            }
+                        });
+                    }
+                    outStocks.Add(stockInfo);
+                }
+            }
+            residueQuantity = needQuantity;
+            return outStocks;
+        }
         //瀵煎嚭
         public override WebResponseContent Export(PageDataOptions options)
         {

--
Gitblit v1.9.3