| | |
| | | /// <param name="needQuantity"></param> |
| | | /// <param name="residueQuantity"></param> |
| | | /// <returns></returns> |
| | | public List<Dt_StockInfo> GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity) |
| | | public (List<Dt_StockInfo>, Dictionary<int, decimal>) GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity) |
| | | { |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | // æå
è¿å
åºæåºï¼ææ¡ç ççäº§æ¥æï¼ |
| | | Dictionary<int, decimal> stockAllocations = new Dictionary<int, decimal>(); // è®°å½æ¯ä¸ªåºåæç»çåé
æ°é |
| | | |
| | | // æå
è¿å
åºæåºææç¸å
³çåºåæç» |
| | | var sortedStockDetails = stockInfos |
| | | .SelectMany(x => x.Details) |
| | | .Where(x => x.MaterielCode == materielCode && x.StockQuantity > x.OutboundQuantity) |
| | | .OrderBy(x => x.ProductionDate).ThenBy(x => x.StockId) |
| | | .Where(x => x.MaterielCode == materielCode && |
| | | x.StockQuantity > x.OutboundQuantity) // æå¯ç¨åºå |
| | | .OrderBy(x => x.ProductionDate) // æçäº§æ¥ææåºï¼å
è¿å
åº |
| | | .ThenBy(x => x.StockId) // ç¸åçäº§æ¥ææåºåIDæåº |
| | | .ToList(); |
| | | |
| | | if (!sortedStockDetails.Any()) |
| | | { |
| | | residueQuantity = needQuantity; |
| | | return (outStocks, stockAllocations); |
| | | } |
| | | |
| | | // è®¡ç®æ»å¯ç¨åºå |
| | | var stockTotalQuantity = sortedStockDetails.Sum(x => x.StockQuantity - x.OutboundQuantity); |
| | |
| | | if (stockTotalQuantity < needQuantity) |
| | | { |
| | | residueQuantity = needQuantity - stockTotalQuantity; |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | |
| | | decimal remainingNeed = needQuantity; |
| | | |
| | | // ææ¡ç åé
åºå |
| | | // æå
è¿å
åºé¡ºåºåé
åºå |
| | | foreach (var detail in sortedStockDetails) |
| | | { |
| | | if (remainingNeed <= 0) break; |
| | | |
| | | decimal availableQuantity = detail.StockQuantity - detail.OutboundQuantity; |
| | | if (availableQuantity <= 0) continue; |
| | | |
| | | decimal allocateQuantity = Math.Min(availableQuantity, remainingNeed); |
| | | |
| | | // æ´æ°åºåºæ°é |
| | | detail.OutboundQuantity += allocateQuantity; |
| | | remainingNeed -= allocateQuantity; |
| | | |
| | | // è®°å½åé
æ°é |
| | | stockAllocations[detail.Id] = allocateQuantity; |
| | | |
| | | // 妿è¿ä¸ªåºåè¿æ²¡æ·»å å°åºåºå表ä¸ï¼å°±æ·»å |
| | | var stockInfo = stockInfos.First(x => x.Id == detail.StockId); |
| | |
| | | } |
| | | |
| | | residueQuantity = remainingNeed; |
| | | return outStocks; |
| | | return (outStocks, stockAllocations); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®æ¡ç è·ååºåä¿¡æ¯ |
| | | /// </summary> |