| | |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IRecordService; |
| | |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | public IRepository<Dt_OutboundOrderDetail> Repository => BaseDal; |
| | | |
| | | |
| | | |
| | | private readonly IStockService _stockService; |
| | | |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly IBasicService _basicService; |
| | |
| | | _locationStatusChangeRecordService = locationStatusChangeRecordService; |
| | | _outboundOrderService = outboundOrderService; |
| | | _logger = logger; |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// åé
åºåºåºå æå
è¿å
åºåååé
|
| | | /// </summary> |
| | | public (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_OutboundOrderDetail> outboundOrderDetails) |
| | | public (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) |
| | | AssignStockOutbound(List<Dt_OutboundOrderDetail> outboundOrderDetails) |
| | | { |
| | | if (!outboundOrderDetails.Any()) |
| | | { |
| | |
| | | throw new Exception("请å¿åæ¶æä½å¤ä¸ªåæ®æç»"); |
| | | } |
| | | |
| | | var orderId = outboundOrderDetails.First().OrderId; |
| | | var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>() |
| | | .First(x => x.Id == outboundOrderDetails.First().OrderId); |
| | | .First(x => x.Id == orderId); |
| | | |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | |
| | | |
| | | // æç©æåæ¹æ¬¡åç»å¤ç |
| | | var groupDetails = outboundOrderDetails |
| | | .GroupBy(x => new { x.MaterielCode, x.BatchNo }) |
| | | .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode }) |
| | | .Select(x => new |
| | | { |
| | | MaterielCode = x.Key.MaterielCode, |
| | | BatchNo = x.Key.BatchNo, |
| | | SupplyCode = x.Key.SupplyCode, |
| | | Details = x.ToList(), |
| | | TotalNeedQuantity = x.Sum(v => v.OrderQuantity - v.OverOutQuantity - v.LockQuantity) |
| | | TotalNeedQuantity = x.Sum(v => v.OrderQuantity - v.OverOutQuantity - v.LockQuantity - v.MoveQty) |
| | | }) |
| | | .Where(x => x.TotalNeedQuantity > 0) |
| | | .ToList(); |
| | |
| | | var needQuantity = item.TotalNeedQuantity; |
| | | |
| | | // è·åå¯ç¨åºåï¼æå
è¿å
åºæåºï¼ |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo); |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode); |
| | | |
| | | if (!stockInfos.Any()) |
| | | { |
| | | throw new Exception($"ç©æ[{item.MaterielCode}]æ¹æ¬¡[{item.BatchNo}]æªæ¾å°å¯åé
åºå"); |
| | | } |
| | | |
| | | // åé
åºåï¼æå
è¿å
åºï¼ |
| | | var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks( |
| | | stockInfos, item.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | |
| | | if (residueQuantity > 0 && residueQuantity == needQuantity) |
| | | // æ£æ¥åé
ç»æï¼å¦æå®å
¨æ æ³åé
ï¼åé
æ°é为0ï¼ï¼åæ¥é |
| | | decimal allocatedQuantity = needQuantity - residueQuantity; |
| | | if (allocatedQuantity <= 0) |
| | | { |
| | | throw new Exception($"ç©æ[{item.MaterielCode}]åºåä¸è¶³ï¼éè¦{needQuantity}ï¼å¯ç¨{needQuantity - residueQuantity}"); |
| | | throw new Exception($"ç©æ[{item.MaterielCode}]æ¹æ¬¡[{item.BatchNo}]åºåä¸è¶³ï¼éè¦{needQuantity}ï¼ä½æ æ³åé
ä»»ä½åºå"); |
| | | } |
| | | |
| | | outStocks.AddRange(autoAssignStocks); |
| | | |
| | | // æå
è¿å
åºåååé
é宿°éå°å个æç» |
| | | DistributeLockQuantityByFIFO(item.Details, autoAssignStocks, stockAllocations, outStockLockInfos, outboundOrder); |
| | | var distributionResult = DistributeLockQuantityByFIFO(item.Details, autoAssignStocks, stockAllocations, outStockLockInfos, outboundOrder); |
| | | |
| | | if (!distributionResult.success) |
| | | { |
| | | throw new Exception(distributionResult.message); |
| | | } |
| | | |
| | | // æ´æ°åºåºåæç»ç¶æ |
| | | UpdateOrderDetailStatus(item.Details, allocatedQuantity, needQuantity); |
| | | } |
| | | |
| | | locationInfos.AddRange(_locationInfoService.GetLocationInfos(outStocks.Select(x => x.LocationCode).Distinct().ToList())); |
| | | if (outStocks.Any()) |
| | | { |
| | | locationInfos.AddRange(_locationInfoService.GetLocationInfos( |
| | | outStocks.Select(x => x.LocationCode).Distinct().ToList())); |
| | | } |
| | | |
| | | return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå
è¿å
åºåååé
é宿°éå°å个æç» - ä¿®å¤çæ¬ |
| | | /// </summary> |
| | | private void DistributeLockQuantityByFIFO( |
| | | List<Dt_OutboundOrderDetail> details, |
| | | List<Dt_StockInfo> assignStocks, |
| | | Dictionary<int, decimal> stockAllocations, |
| | | List<Dt_OutStockLockInfo> outStockLockInfos, |
| | | Dt_OutboundOrder outboundOrder) |
| | | private (bool success, string message) DistributeLockQuantityByFIFO( |
| | | List<Dt_OutboundOrderDetail> details, |
| | | List<Dt_StockInfo> assignStocks, |
| | | Dictionary<int, decimal> stockAllocations, |
| | | List<Dt_OutStockLockInfo> outStockLockInfos, |
| | | Dt_OutboundOrder outboundOrder) |
| | | { |
| | | // æå
è¿å
åºæåºåºåºåæç»ï¼å设å
å建çæç»éè¦ä¼å
æ»¡è¶³ï¼ |
| | | // æå
è¿å
åºæåºåºåºåæç»ï¼Idå°çä¼å
ï¼ |
| | | var sortedDetails = details |
| | | .Where(d => d.OrderQuantity - d.OverOutQuantity - d.LockQuantity > 0) // åªå¤çè¿éè¦åé
çæ°é |
| | | .Where(d => d.OrderQuantity - d.OverOutQuantity - d.LockQuantity - d.MoveQty > 0) |
| | | .OrderBy(x => x.Id) |
| | | .ToList(); |
| | | |
| | | if (!sortedDetails.Any()) return; |
| | | if (!sortedDetails.Any()) |
| | | return (true, "æ éåé
"); |
| | | |
| | | // è·åææåé
äºåºåçæç»ï¼æå
è¿å
åºæåº |
| | | var allocatedStockDetails = assignStocks |
| | | .SelectMany(x => x.Details) |
| | | .Where(x => stockAllocations.ContainsKey(x.Id)) |
| | | .OrderBy(x => x.ProductionDate) |
| | | .Where(x => stockAllocations.ContainsKey(x.Id) && stockAllocations[x.Id] > 0) |
| | | .OrderBy(x => x.CreateDate) |
| | | .ThenBy(x => x.StockId) |
| | | .ToList(); |
| | | |
| | | if (!allocatedStockDetails.Any()) |
| | | { |
| | | return (false, "没æå¯åé
çåºåæç»"); |
| | | } |
| | | |
| | | decimal totalNeedQuantity = sortedDetails.Sum(d => |
| | | d.OrderQuantity - d.OverOutQuantity - d.LockQuantity - d.MoveQty); |
| | | decimal allocatedQuantity = 0; |
| | | |
| | | // 为æ¯ä¸ªåºåæç»å建åé
è®°å½ |
| | | foreach (var stockDetail in allocatedStockDetails) |
| | | { |
| | | if (!stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQuantity)) |
| | | if (!stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQuantityForStock)) |
| | | continue; |
| | | |
| | | if (allocatedQuantity <= 0) continue; |
| | | if (allocatedQuantityForStock <= 0) continue; |
| | | |
| | | var stockInfo = assignStocks.First(x => x.Id == stockDetail.StockId); |
| | | decimal remainingAllocate = allocatedQuantity; |
| | | decimal remainingAllocate = allocatedQuantityForStock; |
| | | |
| | | // æé¡ºåºåé
ç»å个åºåºåæç» |
| | | foreach (var detail in sortedDetails) |
| | |
| | | if (remainingAllocate <= 0) break; |
| | | |
| | | // 计ç®è¿ä¸ªæç»è¿éè¦åé
çæ°é |
| | | var detailNeed = detail.OrderQuantity - detail.OverOutQuantity - detail.LockQuantity; |
| | | var detailNeed = detail.OrderQuantity - detail.OverOutQuantity - detail.LockQuantity - detail.MoveQty; |
| | | if (detailNeed <= 0) continue; |
| | | |
| | | // åé
æ°é |
| | |
| | | // éªè¯æ¡ç æ¯å¦åå¨ |
| | | if (string.IsNullOrEmpty(stockDetail.Barcode)) |
| | | { |
| | | throw new Exception($"åºåæç»ID[{stockDetail.Id}]çæ¡ç 为空"); |
| | | return (false, $"åºåæç»ID[{stockDetail.Id}]çæ¡ç 为空"); |
| | | } |
| | | |
| | | // å建åºåºéå®ä¿¡æ¯ |
| | |
| | | // æ´æ°æç»çé宿°é |
| | | detail.LockQuantity += assignQuantity; |
| | | remainingAllocate -= assignQuantity; |
| | | allocatedQuantity += assignQuantity; |
| | | } |
| | | |
| | | // å¦æè¿æå©ä½åé
æ°éï¼éæ°åé
æè®°å½è¦å |
| | | // å¦æè¿æå©ä½åé
æ°éï¼è®°å½è¦å |
| | | if (remainingAllocate > 0) |
| | | { |
| | | // éæ°åé
ç»å
¶ä»éè¦åé
çæç» |
| | | foreach (var detail in sortedDetails) |
| | | { |
| | | if (remainingAllocate <= 0) break; |
| | | |
| | | var detailNeed = detail.OrderQuantity - detail.OverOutQuantity - detail.LockQuantity; |
| | | if (detailNeed <= 0) continue; |
| | | |
| | | var assignQuantity = Math.Min(remainingAllocate, detailNeed); |
| | | |
| | | var lockInfo = _outStockLockInfoService.GetOutStockLockInfo( |
| | | outboundOrder, detail, stockInfo, assignQuantity, stockDetail.Barcode); |
| | | outStockLockInfos.Add(lockInfo); |
| | | |
| | | detail.LockQuantity += assignQuantity; |
| | | remainingAllocate -= assignQuantity; |
| | | } |
| | | |
| | | // å¦æè¿æå©ä½ï¼è®°å½è¦åä½ä¸æåºå¼å¸¸ |
| | | if (remainingAllocate > 0) |
| | | { |
| | | _logger.LogWarning($"åºååé
å仿å©ä½æ°éæªåé
: {remainingAllocate}, æ¡ç : {stockDetail.Barcode}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å建åºåºéå®ä¿¡æ¯ |
| | | /// </summary> |
| | | private void CreateOutStockLockInfos(Dt_OutboundOrder outboundOrder,List<Dt_OutboundOrderDetail> details, |
| | | List<Dt_StockInfo> assignStocks,List<Dt_OutStockLockInfo> outStockLockInfos) |
| | | { |
| | | foreach (var stock in assignStocks) |
| | | { |
| | | // è·å该åºåä¸ç¸å
³ç©æçå¯ç¨æ¡ç ä¿¡æ¯ |
| | | var stockDetails = stock.Details |
| | | .Where(x => details.Any(d => d.MaterielCode == x.MaterielCode) && |
| | | x.StockQuantity > x.OutboundQuantity) |
| | | .OrderBy(x => x.ProductionDate) // å
è¿å
åº |
| | | .ToList(); |
| | | if (!stockDetails.Any()) continue; |
| | | |
| | | var stockAssignQuantity = stockDetails.Sum(x => x.OutboundQuantity); |
| | | |
| | | |
| | | // æ¥æ¾è¿ä¸ªåºåå·²ç»åé
çæ°é |
| | | var existingAssign = outStockLockInfos |
| | | .Where(x => x.StockId == stock.Id && |
| | | details.Any(d => d.Id == x.OrderDetailId)) |
| | | .Sum(x => x.AssignQuantity); |
| | | |
| | | var availableAssign = stockAssignQuantity - existingAssign; |
| | | |
| | | if (availableAssign <= 0) continue; |
| | | |
| | | // æå
è¿å
åºåååé
æ¡ç |
| | | var barcodeAllocation = AllocateBarcodes(stockDetails, availableAssign); |
| | | |
| | | |
| | | // åé
ç»å个æç» |
| | | foreach (var detail in details.Where(d => d.LockQuantity > 0)) |
| | | { |
| | | var alreadyAssigned = outStockLockInfos |
| | | .Where(x => x.OrderDetailId == detail.Id && x.StockId == stock.Id) |
| | | .Sum(x => x.AssignQuantity); |
| | | |
| | | var canAssign = Math.Min(detail.LockQuantity - alreadyAssigned, availableAssign); |
| | | |
| | | if (canAssign > 0) |
| | | { |
| | | // 为è¿ä¸ªåé
ç¡®å®æ¡ç |
| | | var (barcode, barcodeQuantity) = GetBarcodeForAllocation(barcodeAllocation, canAssign); |
| | | |
| | | var lockInfo = _outStockLockInfoService.GetOutStockLockInfo( |
| | | outboundOrder, detail, stock, canAssign, barcode); |
| | | outStockLockInfos.Add(lockInfo); |
| | | |
| | | availableAssign -= canAssign; |
| | | |
| | | // æ´æ°æ¡ç åé
è®°å½ |
| | | UpdateBarcodeAllocation(barcodeAllocation, barcode, barcodeQuantity); |
| | | } |
| | | |
| | | if (availableAssign <= 0) break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå
è¿å
åºåååé
æ¡ç |
| | | /// </summary> |
| | | private Dictionary<string, decimal> AllocateBarcodes(List<Dt_StockInfoDetail> stockDetails, decimal totalQuantity) |
| | | { |
| | | var allocation = new Dictionary<string, decimal>(); |
| | | decimal remainingQuantity = totalQuantity; |
| | | |
| | | foreach (var detail in stockDetails.OrderBy(x => x.ProductionDate)) |
| | | { |
| | | if (remainingQuantity <= 0) break; |
| | | |
| | | decimal available = detail.StockQuantity - detail.OutboundQuantity; |
| | | decimal allocate = Math.Min(available, remainingQuantity); |
| | | |
| | | allocation[detail.Barcode] = allocate; |
| | | remainingQuantity -= allocate; |
| | | } |
| | | |
| | | return allocation; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 为åé
è·ååéçæ¡ç |
| | | /// </summary> |
| | | private (string barcode, decimal quantity) GetBarcodeForAllocation(Dictionary<string, decimal> barcodeAllocation, decimal requiredQuantity) |
| | | { |
| | | foreach (var (barcode, quantity) in barcodeAllocation) |
| | | { |
| | | if (quantity >= requiredQuantity) |
| | | { |
| | | return (barcode, requiredQuantity); |
| | | _logger.LogWarning($"åºååé
å仿å©ä½æ°éæªåé
: {remainingAllocate}, æ¡ç : {stockDetail.Barcode}"); |
| | | } |
| | | } |
| | | |
| | | // 妿å个æ¡ç æ°éä¸è¶³ï¼ä½¿ç¨ç¬¬ä¸ä¸ªæ¡ç |
| | | var first = barcodeAllocation.First(); |
| | | return (first.Key, Math.Min(first.Value, requiredQuantity)); |
| | | // éªè¯æ¯å¦è³å°åé
äºä¸é¨å |
| | | if (allocatedQuantity <= 0) |
| | | { |
| | | return (false, "åºååé
å¤±è´¥ï¼æ æ³åé
任使°é"); |
| | | } |
| | | |
| | | // è®°å½åé
ç»æ |
| | | if (allocatedQuantity < totalNeedQuantity) |
| | | { |
| | | _logger.LogWarning($"åºåé¨ååé
ï¼éè¦{totalNeedQuantity}ï¼å®é
åé
{allocatedQuantity}"); |
| | | } |
| | | else |
| | | { |
| | | _logger.LogInformation($"åºåå®å
¨åé
ï¼åé
æ°é{allocatedQuantity}"); |
| | | } |
| | | |
| | | return (true, "åé
æå"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°æ¡ç åé
è®°å½ |
| | | /// </summary> |
| | | private void UpdateBarcodeAllocation(Dictionary<string, decimal> barcodeAllocation, string barcode, decimal usedQuantity) |
| | | private void UpdateOrderDetailStatus(List<Dt_OutboundOrderDetail> details, |
| | | decimal allocatedQuantity, decimal needQuantity) |
| | | { |
| | | if (barcodeAllocation.ContainsKey(barcode)) |
| | | foreach (var detail in details) |
| | | { |
| | | barcodeAllocation[barcode] -= usedQuantity; |
| | | if (barcodeAllocation[barcode] <= 0) |
| | | var detailNeed = detail.OrderQuantity - detail.LockQuantity - detail.OverOutQuantity - detail.MoveQty; |
| | | |
| | | if (detailNeed <= 0) |
| | | { |
| | | barcodeAllocation.Remove(barcode); |
| | | // 该æç»å·²å®å
¨åé
|
| | | detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | } |
| | | else if (allocatedQuantity < needQuantity) |
| | | { |
| | | // æ´ä½é¨ååé
ï¼è¯¥æç»å¯è½è¿æéæ± |
| | | detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | // æ´ä½å®å
¨åé
|
| | | detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | } |
| | | } |
| | | } |
| | |
| | | /// <param name="locationStatus"></param> |
| | | /// <param name="tasks"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_OutboundOrderDetail> outboundOrderDetails, |
| | | List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, |
| | | public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_OutboundOrderDetail> outboundOrderDetails, |
| | | List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, |
| | | LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null) |
| | | { |
| | | try |
| | |
| | | // æ´æ°åºåç¶æ |
| | | stockInfos.ForEach(x => x.StockStatus = (int)StockStatusEmun.åºåºéå®); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | |
| | | |
| | | // æ´æ°åºåæç» |
| | | var stockDetails = stockInfos.SelectMany(x => x.Details).ToList(); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockDetails); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public override PageGridData<Dt_OutboundOrderDetail> GetPageData(PageDataOptions options) |
| | | { |
| | | //var pageGridData = base.GetPageData(options); |
| | | |
| | | ISugarQueryable<Dt_OutboundOrderDetail> sugarQueryable1 = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>(); |
| | | if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | |
| | | List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | int totalCount = 0; |
| | | if (searchParametersList.Count > 0) |
| | | { |
| | | { |
| | | SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrderDetail.OrderId).FirstLetterToLower()); |
| | | if (searchParameters != null) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1.Where(x => x.OrderId == searchParameters.Value.ObjToInt()); |
| | | var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount); |
| | | return new PageGridData<Dt_OutboundOrderDetail>(totalCount, dataList); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | return new PageGridData<Dt_OutboundOrderDetail>(); |
| | | } |
| | | |
| | | |
| | | public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews); |
| | | if (!checkResult.Item1) throw new Exception(checkResult.Item2); |
| | | |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | var originalNeedQuantity = outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity - outboundOrderDetail.MoveQty; |
| | | |
| | | var needQuantity = originalNeedQuantity; |
| | | |
| | | List<Dt_StockInfo> outStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList()); |
| | | var assignQuantity = 0m; |
| | | outStocks.ForEach(x => |
| | | { |
| | | x.Details.ForEach(v => |
| | | { |
| | | assignQuantity += v.StockQuantity - v.OutboundQuantity; |
| | | }); |
| | | }); |
| | | |
| | | outboundOrderDetail.LockQuantity += assignQuantity; |
| | | outStocks.ForEach(x => |
| | | { |
| | | x.Details.ForEach(v => |
| | | { |
| | | v.OutboundQuantity = v.StockQuantity; |
| | | }); |
| | | }); |
| | | needQuantity -= assignQuantity; |
| | | if (outboundOrderDetail.OrderQuantity > outboundOrderDetail.LockQuantity) |
| | | { |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(outboundOrderDetail.MaterielCode, outboundOrderDetail.BatchNo, ""); |
| | | stockInfos = stockInfos.Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode)).ToList(); |
| | | var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(stockInfos, outboundOrderDetail.MaterielCode, needQuantity, out decimal residueQuantity); |
| | | outboundOrderDetail.LockQuantity += needQuantity - residueQuantity; |
| | | outStocks.AddRange(autoAssignStocks); |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt(); |
| | | if (residueQuantity > 0) |
| | | { |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | } |
| | | } |
| | | |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = _outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetail, outStocks); |
| | | |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()); |
| | | |
| | | return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos); |
| | | } |
| | | private (bool, string) CheckSelectStockDeital(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | if (outboundOrderDetail == null) |
| | | { |
| | | return (false, "æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | if (outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt() && outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) |
| | | { |
| | | return (false, "该æç»ä¸å¯æä½"); |
| | | } |
| | | //if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity - outboundOrderDetail.MoveQty) |
| | | //{ |
| | | // return (false, "éæ©æ°éè¶
åºåæ®æ°é"); |
| | | //} |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | } |
| | | } |