| | |
| | | { |
| | | 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); |
| | |
| | | { |
| | | |
| | | 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 |
| | |
| | | { |
| | | if (detail.MaterielCode == dt_OutboundOrderDetail.MaterielCode) |
| | | { |
| | | useableStockQuantity = detail.StockQuantity - detail.OutboundQuantity; |
| | | useableStockQuantity += detail.StockQuantity - detail.OutboundQuantity; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | 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); |
| | | } |