From 768405ab8a119d04f4d861f031b9ba38e84cf81c Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期三, 01 四月 2026 16:14:24 +0800
Subject: [PATCH] 1
---
WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs | 320 +++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 246 insertions(+), 74 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
index 8f4388d..98407dc 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
+++ b/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
{
@@ -193,110 +194,281 @@
return outStocks;
}
- //浣庢俯銆佽嵂姘村垎閰嶅簱瀛�
- public List<Dt_StockInfo> DWANDYSGetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode,string batchNo ,decimal needQuantity, out decimal residueQuantity)
+ /// <summary>
+ /// 浣庢俯銆佽嵂姘村垎閰嶅簱瀛�
+ /// </summary>
+ /// <param name="stockInfos"></param>
+ /// <param name="dt_OutboundOrderDetails"></param>
+ /// <param name="residueQuantitys"></param>
+ /// <returns></returns>
+ 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();
- if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
+ List<IStockInfoService.residueQuantity> newresidueQantity = new List<IStockInfoService.residueQuantity>();
+ List<Dt_StockInfo> notStocks = new List<Dt_StockInfo>(); ;
+ foreach(var dt_OutboundOrderDetail in dt_OutboundOrderDetails)
{
- int index = 0;
- while (needQuantity > 0)
+ 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 == 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)
+ Dt_StockInfo stockInfo = stockInfos[index];
+ Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
+ foreach (var detail in stockInfo.Details)
{
- x.OutboundQuantity = x.StockQuantity;
+ if (detail.BatchNo == dt_OutboundOrderDetail.BatchNo && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+ {
+ dt_StockInfoDetail = detail;
+ }
}
- });
- needQuantity -= useableStockQuantity;
+ 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
{
-
- stockInfo.Details.ForEach(x =>
+ for (int i = 0; i < stockInfos.Count; i++)
{
- if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ Dt_StockInfo stockInfo = stockInfos[i];
+ decimal useableStockQuantity = 0;
+ foreach (var detail in stockInfo.Details)
{
- if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+ if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode && detail.BatchNo == dt_OutboundOrderDetail.BatchNo)
{
- x.OutboundQuantity += needQuantity;
- needQuantity = 0;
+ 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;
+ }
+
+
+ /// <summary>
+ /// 鎴愬搧鍒嗛厤搴撳瓨
+ /// </summary>
+ /// <param name="stockInfos"></param>
+ /// <param name="dt_OutboundOrderDetails"></param>
+ /// <param name="residueQuantitys"></param>
+ /// <returns></returns>
+ public List<Dt_StockInfo> CPGetOutboundStocks(List<Dt_StockInfo> stockInfos, List<Dt_NewOutboundOrderDetail> 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.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);
+ decimal needQuantity = dt_OutboundOrderDetail.OrderQuantity - dt_OutboundOrderDetail.LockQuantity;
+ if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
+ {
+ int index = 0;
+ while (needQuantity > 0)
+ {
+
+ Dt_StockInfo stockInfo = stockInfos[index];
+ List<Dt_StockInfoDetail> dt_StockInfoDetails = new List<Dt_StockInfoDetail>();
+ foreach (var detail in stockInfo.Details)
+ {
+ if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+ {
+ dt_StockInfoDetails.Add(detail);
+ }
+ }
+ foreach(var dt_StockInfoDetail in dt_StockInfoDetails)
+ {
+ decimal useableStockQuantity = dt_StockInfoDetail.StockQuantity - dt_StockInfoDetail.OutboundQuantity;
+ if (useableStockQuantity < needQuantity)
+ {
+ foreach (var item in stockInfo.Details)
+ {
+ if(item.MaterielCode == dt_OutboundOrderDetail.MaterielCode && dt_StockInfoDetail.BatchNo == item.BatchNo)
+ {
+ item.OutboundQuantity = item.StockQuantity;
+ }
+ }
+ needQuantity -= useableStockQuantity;
}
else
{
- needQuantity -= (x.StockQuantity - x.OutboundQuantity);
- x.OutboundQuantity = x.StockQuantity;
+ 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
- {
- 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 =>
+ for (int i = 0; i < stockInfos.Count; i++)
{
- if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode && x.BatchNo == batchNo)
+ Dt_StockInfo stockInfo = stockInfos[i];
+ decimal useableStockQuantity = 0;
+ foreach (var detail in stockInfo.Details)
{
- if (x.StockQuantity - x.OutboundQuantity >= needQuantity)
+ if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
{
- x.OutboundQuantity += needQuantity;
- needQuantity = 0;
- }
- else
- {
- needQuantity -= (x.StockQuantity - x.OutboundQuantity);
- x.OutboundQuantity = x.StockQuantity;
+ useableStockQuantity += detail.StockQuantity - detail.OutboundQuantity;
}
}
- });
+
+ if (useableStockQuantity < needQuantity)
+ {
+ stockInfo.Details.ForEach(x => {
+ if (x.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+ {
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ });
+ needQuantity -= useableStockQuantity;
+ }
+ else
+ {
+ foreach (var detail in stockInfo.Details)
+ {
+ if(detail.StockQuantity > detail.OutboundQuantity && detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode)
+ {
+ if(detail.StockQuantity - detail.OutboundQuantity >= needQuantity)
+ {
+ detail.OutboundQuantity += needQuantity;
+ needQuantity = 0;
+ }
+ else
+ {
+ needQuantity -= (detail.StockQuantity - detail.OutboundQuantity);
+ detail.OutboundQuantity = detail.StockQuantity;
+ }
+ }
+ }
+ }
+ outStocks.Add(stockInfo);
+ }
}
- 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;
+ }
+
}
- residueQuantity = needQuantity;
+ residueQuantitys = newresidueQantity;
+ if (outStocks.Count() > 1)
+ {
+ outStocks.RemoveRange(0, outStocks.Count - 1);
+ }
return outStocks;
}
//瀵煎嚭
--
Gitblit v1.9.3