From a474060ae47fc4c807120b2a6178e8d8f84c0863 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 27 一月 2026 15:07:25 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs |  131 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 131 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..b617a84 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;
@@ -20,6 +21,7 @@
 using WIDESEA_IStockRepository;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
+using static WIDESEA_IStockService.IStockInfoService;
 
 namespace WIDESEA_StockService
 {
@@ -192,6 +194,135 @@
             return outStocks;
         }
 
+        //浣庢俯銆佽嵂姘村垎閰嶅簱瀛�
+        public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos,List<Dt_OutboundOrderDetail> dt_OutboundOrderDetails, out List<IStockInfoService.residueQuantity> residueQuantitys)
+        {
+            List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+            List<IStockInfoService.residueQuantity> newresidueQantity = new List<IStockInfoService.residueQuantity>();
+            List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>(); ;
+            foreach(var dt_OutboundOrderDetail in dt_OutboundOrderDetails)
+            {
+                notStocks = stockInfos.Where(x => x.Details.Any(x => x.BatchNo == dt_OutboundOrderDetail.BatchNo && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)).OrderBy(x => x.Id).ToList();
+                if(notStocks.Count > 0)
+                {
+                    decimal stockTotalQuantity = stockInfos.SelectMany(x => x.Details).Where(d => d.BatchNo == dt_OutboundOrderDetail.BatchNo).Sum(v => v.StockQuantity - v.OutboundQuantity);
+                    decimal needQuantity = dt_OutboundOrderDetail.OrderQuantity - dt_OutboundOrderDetail.LockQuantity;
+                    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 == dt_OutboundOrderDetail.BatchNo && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+                                {
+                                    dt_StockInfoDetail = detail;
+                                }
+                            }
+                            decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
+                            if (useableStockQuantity < needQuantity)
+                            {
+                                stockInfo.Details.ForEach(x =>
+                                {
+                                    if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
+                                    {
+                                        x.OutboundQuantity = x.StockQuantity;
+                                    }
+                                });
+                                needQuantity -= useableStockQuantity;
+                            }
+                            else
+                            {
+
+                                stockInfo.Details.ForEach(x =>
+                                {
+                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.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 == dt_OutboundOrderDetail.MaterielCode && detail.BatchNo == dt_OutboundOrderDetail.BatchNo)
+                                {
+                                    useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity;
+                                }
+                            }
+
+                            if (useableStockQuantity < needQuantity)
+                            {
+                                stockInfo.Details.ForEach(x => {
+                                    if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
+                                    {
+                                        x.OutboundQuantity = x.StockQuantity;
+                                    }
+                                });
+                                needQuantity -= useableStockQuantity;
+                            }
+                            else
+                            {
+                                stockInfo.Details.ForEach(x =>
+                                {
+                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.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);
+                        }
+                    }
+                    IStockInfoService.residueQuantity newResidueQuantity = new IStockInfoService.residueQuantity();
+                    newResidueQuantity.MaterielCode = dt_OutboundOrderDetail.MaterielCode;
+                    newResidueQuantity.BatchNo = dt_OutboundOrderDetail.BatchNo;
+                    newResidueQuantity.NewNeendQuantity = needQuantity;
+                    newresidueQantity.Add(newResidueQuantity);
+                }
+                else
+                {
+                    continue;
+                }
+                           
+            }
+            residueQuantitys = newresidueQantity;
+            if(outStocks.Count() > 1)
+            {
+                outStocks.RemoveRange(0, outStocks.Count - 1);
+            }
+            return outStocks;
+        }
         //瀵煎嚭
         public override WebResponseContent Export(PageDataOptions options)
         {

--
Gitblit v1.9.3