| | |
| | | using Microsoft.Extensions.Logging; |
| | | using Autofac.Core; |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | |
| | | |
| | | // æ´æ°åºåºåæç»ç¶æ |
| | | UpdateOrderDetailStatus(item.Details, allocatedQuantity, needQuantity); |
| | | |
| | | |
| | | // æ´æ°åºååæçç¶æ |
| | | UpdateNormalStocksAndPalletsStatus(autoAssignStocks, stockAllocations); |
| | | } |
| | | |
| | | if (outStocks.Any()) |
| | |
| | | |
| | | return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°åºååæçç¶æ |
| | | /// </summary> |
| | | private void UpdateNormalStocksAndPalletsStatus(List<Dt_StockInfo> stocks, Dictionary<int, decimal> stockAllocations) |
| | | { |
| | | foreach (var stock in stocks) |
| | | { |
| | | var stockDetail = stock.Details.First(); |
| | | if (stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQty) && allocatedQty > 0) |
| | | { |
| | | |
| | | _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>() |
| | | .SetColumns(x => new Dt_StockInfo |
| | | { |
| | | StockStatus = (int)StockStatusEmun.åºåºéå®, |
| | | }) |
| | | .Where(x => x.Id == stock.Id) |
| | | .ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ£æ¥è®¢åæ¯å¦å
è®¸éæ°åé
|
| | | /// </summary> |
| | |
| | | |
| | | // æ´æ°åºåºåæç»ç¶æ |
| | | UpdateOrderDetailStatus(item.Details, allocatedQuantity, needQuantity); |
| | | |
| | | // æ´æ°åºååæçç¶æä¸ºåºåºéå® |
| | | await UpdateStocksAndPalletsStatus(autoAssignStocks, stockAllocations); |
| | | } |
| | | |
| | | if (outStocks.Any()) |
| | |
| | | |
| | | return (outStocks, groupDetails.SelectMany(x => x.Details).ToList(), outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°åºååæçç¶æ |
| | | /// </summary> |
| | | private async Task UpdateStocksAndPalletsStatus(List<Dt_StockInfo> stocks, Dictionary<int, decimal> stockAllocations) |
| | | { |
| | | foreach (var stock in stocks) |
| | | { |
| | | var stockDetail = stock.Details.First(); |
| | | if (stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQty) && allocatedQty > 0) |
| | | { |
| | | |
| | | await _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>() |
| | | .SetColumns(x => new Dt_StockInfo |
| | | { |
| | | StockStatus = (int)StockStatusEmun.åºåºéå®, |
| | | }) |
| | | .Where(x => x.Id == stock.Id) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æå
è¿å
åºåååé
é宿°é |
| | | /// </summary> |
| | |
| | | if (userSelection == null) continue; |
| | | |
| | | // 计ç®è¯¥æçå®é
å¯ç¨æ°é |
| | | var availableQuantity = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode, |
| | | outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode); |
| | | var availableQuantity = CalculateAvailableQuantityByBarcode(stock, outboundOrderDetail.MaterielCode, |
| | | outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode, userSelection.Barcode); |
| | | |
| | | // ç¡®å®åé
æ°éï¼åç¨æ·éæ©æ°éãå¯ç¨æ°éåå©ä½éæ±çæå°å¼ |
| | | var assignQuantity = Math.Min(Math.Min(userSelection.UseableQuantity, availableQuantity),remainingNeedQuantity); |
| | | var assignQuantity = Math.Min(Math.Min(userSelection.UseableQuantity, availableQuantity), remainingNeedQuantity); |
| | | |
| | | if (assignQuantity <= 0) continue; |
| | | |
| | | // æ§è¡åé
|
| | | var actualAssigned = AssignStockQuantity(stock, outboundOrderDetail, assignQuantity); |
| | | // æ§è¡åé
ï¼ä½¿ç¨ç¨æ·éæ©çæ¡ç |
| | | var actualAssigned = AssignStockQuantity(stock, outboundOrderDetail, assignQuantity, userSelection.Barcode); |
| | | |
| | | if (actualAssigned > 0) |
| | | { |
| | | outStocks.Add(stock); |
| | | totalAssignedFromUserSelection += actualAssigned; |
| | | remainingNeedQuantity -= actualAssigned; |
| | | |
| | | // å建éå®è®°å½ |
| | | var lockInfo = CreateOutStockLockInfo(outboundOrder, outboundOrderDetail, stock, actualAssigned); |
| | | // å建éå®è®°å½ï¼ä½¿ç¨ç¨æ·éæ©çæ¡ç |
| | | var lockInfo = CreateOutStockLockInfo(outboundOrder, outboundOrderDetail, stock, actualAssigned, userSelection.Barcode); |
| | | outStockLockInfos.Add(lockInfo); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // æ´æ°é宿°é |
| | | outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection + totalAssignedFromUserSelection; |
| | | outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection; |
| | | |
| | | // æ´æ°ç¶æ |
| | | UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity); |
| | |
| | | |
| | | return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos); |
| | | } |
| | | private decimal CalculateAvailableQuantityByBarcode(Dt_StockInfo stock, string materielCode, string batchNo, string supplyCode, string barcode) |
| | | { |
| | | var query = stock.Details.AsQueryable() |
| | | .Where(d => d.MaterielCode == materielCode && |
| | | (d.StockQuantity - d.OutboundQuantity) > 0 && |
| | | d.Barcode == barcode); |
| | | |
| | | if (!string.IsNullOrEmpty(batchNo)) |
| | | { |
| | | query = query.Where(x => x.BatchNo == batchNo); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(supplyCode)) |
| | | { |
| | | query = query.Where(d => d.SupplyCode == supplyCode); |
| | | } |
| | | |
| | | return query.Sum(d => d.StockQuantity - d.OutboundQuantity); |
| | | } |
| | | // è¾
婿¹æ³ |
| | | private decimal CalculateAvailableQuantity(Dt_StockInfo stock, string materielCode, string batchNo, string supplyCode) |
| | | { |
| | |
| | | return relevantDetails.Sum(d => d.StockQuantity - d.OutboundQuantity); |
| | | } |
| | | |
| | | private decimal AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity) |
| | | private decimal AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity, string barcode) |
| | | { |
| | | decimal remainingAssign = assignQuantity; |
| | | |
| | | // æå
è¿å
åºåé
æå®æ¡ç çåºåæç» |
| | | var query = stock.Details.AsQueryable() |
| | | .Where(d => d.MaterielCode == detail.MaterielCode && |
| | | (d.StockQuantity - d.OutboundQuantity) > 0 && |
| | | d.Barcode == barcode); // åªåé
æå®æ¡ç |
| | | |
| | | if (!string.IsNullOrEmpty(detail.BatchNo)) |
| | | { |
| | | query = query.Where(x => x.BatchNo == detail.BatchNo); |
| | | } |
| | | // 妿åºåºåæä¾åºåè¦æ±ï¼æä¾åºåè¿æ»¤ |
| | | if (!string.IsNullOrEmpty(detail.SupplyCode)) |
| | | { |
| | | query = query.Where(d => d.SupplyCode == detail.SupplyCode); |
| | | } |
| | | var sortedDetails = query.ToList().OrderBy(d => d.CreateDate); |
| | | |
| | | foreach (var stockDetail in sortedDetails) |
| | | { |
| | | if (remainingAssign <= 0) break; |
| | | |
| | | var available = stockDetail.StockQuantity - stockDetail.OutboundQuantity; |
| | | var assign = Math.Min(available, remainingAssign); |
| | | |
| | | stockDetail.OutboundQuantity += assign; |
| | | remainingAssign -= assign; |
| | | } |
| | | |
| | | return assignQuantity - remainingAssign; // è¿åå®é
åé
æ°é |
| | | } |
| | | |
| | | private (decimal assignedQuantity, string barcode) AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity) |
| | | { |
| | | decimal remainingAssign = assignQuantity; |
| | | string assignedBarcode = string.Empty; |
| | | |
| | | // æå
è¿å
åºåé
åºåæç» |
| | | var query = stock.Details.AsQueryable() |
| | |
| | | |
| | | stockDetail.OutboundQuantity += assign; |
| | | remainingAssign -= assign; |
| | | if (string.IsNullOrEmpty(assignedBarcode) && assign > 0) |
| | | { |
| | | assignedBarcode = stockDetail.Barcode; |
| | | } |
| | | } |
| | | |
| | | return assignQuantity - remainingAssign; // è¿åå®é
åé
æ°é |
| | | |
| | | return (assignQuantity - remainingAssign, assignedBarcode); |
| | | } |
| | | |
| | | private Dt_OutStockLockInfo CreateOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail detail, |
| | | Dt_StockInfo stock, decimal quantity) |
| | | Dt_StockInfo stock, decimal quantity,string barcode="") |
| | | { |
| | | var barcode = stock.Details |
| | | .Where(d => !string.IsNullOrEmpty(d.Barcode)) |
| | | .Select(d => d.Barcode) |
| | | .FirstOrDefault(); |
| | | |
| | | |
| | | return _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, detail, stock, quantity, barcode); |
| | | } |
| | |
| | | return (false, $"æç[{selection.PalletCode}]ä¸åå¨"); |
| | | } |
| | | |
| | | var available = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode, |
| | | outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode); |
| | | var available = CalculateAvailableQuantityByBarcode(stock, outboundOrderDetail.MaterielCode, |
| | | outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode,selection.Barcode); |
| | | |
| | | if (available <= 0) |
| | | { |