1
yangpeixing
2026-01-22 d669b42041dc62006413ba2578b385cd54cb5181
WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -21,6 +21,7 @@
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
using static WIDESEA_IStockService.IStockInfoService;
namespace WIDESEA_StockService
{
@@ -194,11 +195,18 @@
        }
        //低温、药水分配库存
        public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode,string batchNo ,decimal needQuantity, out decimal residueQuantity)
        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>();
            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();
            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;
@@ -209,7 +217,7 @@
                    Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
                    foreach(var detail in stockInfo.Details)
                    {
                        if(detail.BatchNo == batchNo && detail.MaterielCode == materielCode)
                                if (detail.BatchNo == dt_OutboundOrderDetail.BatchNo && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
                        {
                            dt_StockInfoDetail = detail;
                        }
@@ -219,7 +227,7 @@
                    {
                        stockInfo.Details.ForEach(x =>
                        {
                            if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
                                    if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
                            {
                                x.OutboundQuantity = x.StockQuantity;
                            }
@@ -231,7 +239,7 @@
                        stockInfo.Details.ForEach(x =>
                        {
                            if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
                            {
                                if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
                                {
@@ -258,7 +266,7 @@
                    decimal useableStockQuantity = 0;
                    foreach (var detail in stockInfo.Details)
                    {
                        if(detail.MaterielCode == materielCode && detail.BatchNo == batchNo)
                                if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode && detail.BatchNo == dt_OutboundOrderDetail.BatchNo)
                        {
                            useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity;
                        }
@@ -267,7 +275,7 @@
                    if (useableStockQuantity < needQuantity)
                    {
                        stockInfo.Details.ForEach(x => { 
                            if(x.MaterielCode == materielCode && x.BatchNo == batchNo)
                                    if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
                            {
                                x.OutboundQuantity = x.StockQuantity;
                            }
@@ -278,7 +286,7 @@
                    {
                        stockInfo.Details.ForEach(x =>
                        {
                            if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
                                    if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == dt_OutboundOrderDetail.MaterielCode && x.BatchNo == dt_OutboundOrderDetail.BatchNo)
                            {
                                if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
                                {
@@ -296,7 +304,23 @@
                    outStocks.Add(stockInfo);
                }
            }
            residueQuantity = needQuantity;
                    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;
        }
        //导出