| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_IBasicRepository; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundRepository; |
| | |
| | | /// <summary> |
| | | /// åé
åºå |
| | | /// </summary> |
| | | public (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_OutSGOrderDetail> outboundOrderDetails) |
| | | public (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>,string) AssignStockOutbound(List<Dt_OutSGOrderDetail> outboundOrderDetails) |
| | | { |
| | | if (!outboundOrderDetails.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | string message = ""; |
| | | //è·åæææç¨ä¸»è¡¨ |
| | | List<Dt_OutSGOrder> outBSTOrders = _outboundRepository.OutSGOrderRepository.QueryData(x => outboundOrderDetails.Select(x=>x.OutSGOrderId).Distinct().Contains(x.Id)); |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | |
| | | foreach (var item in groupDetails) |
| | | { |
| | | decimal needQuantity = item.XqLen; |
| | | //è·åå¯ç¨åºå |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId); |
| | | //è·åæææ¡ç |
| | | List<string> palletCodes = outStocks.Select(x => x.PalletCode).ToList(); |
| | | //è·åèåç¼åå¯ç¨åºå |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseOldCacheStocks(item.MaterialNo, item.Width).Where(x => !palletCodes.Contains(x.PalletCode)).ToList() ?? new List<Dt_StockInfo>(); |
| | | //è·åç«åºå¯ç¨åºå |
| | | stockInfos.AddRange(_stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!palletCodes.Contains(x.PalletCode)).ToList()); |
| | | if (!stockInfos.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°å¯åé
åºå"); |
| | | message += $"ç©æï¼{item.MaterialNo},å¹
宽ï¼{item.Width}æ åºåï¼"; |
| | | continue; |
| | | } |
| | | |
| | | //åé
å®é
åºå |
| | | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, needQuantity).OrderBy(x => x.StockLength - x.StockOutLength).ToList(); |
| | | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList(); |
| | | //æ·»å åºååé
|
| | | outStocks.AddRange(autoAssignStocks); |
| | | //è·åææè¯¥ç©æåæ® |
| | |
| | | }); |
| | | for (int i = 0; i < details.Count; i++) |
| | | { |
| | | //è®¢åæ°é |
| | | ////è®¢åæ°é |
| | | //if ((details.Count-1) == i) |
| | | //{ |
| | | |
| | | //} |
| | | decimal orderQuantity = details[i].XqLen; |
| | | bool assignStop = true; |
| | | while (assignStop) |
| | |
| | | |
| | | decimal orderDetailNeedQuantity = details[i].XqLen - detailAssignQuantity; |
| | | |
| | | if (autoAssignStocks.Count==0) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | decimal useStockLength = autoAssignStocks[0].StockLength- autoAssignStocks[0].StockOutLength; |
| | | Dt_OutSGOrder? sGOrder = outBSTOrders.FirstOrDefault(x => x.Id == details[i].OutSGOrderId); |
| | | if (orderDetailNeedQuantity > useStockLength) |
| | | { |
| | | |
| | | //çæè¯¦æ
|
| | | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], useStockLength); |
| | | outStockLockInfos.Add(outStockLockInfo); |
| | | details[i].AssignTotalUsage += useStockLength; |
| | | autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], orderDetailNeedQuantity); |
| | | outStockLockInfos.Add(outStockLockInfo); |
| | | details[i].AssignTotalUsage = orderQuantity; |
| | | autoAssignStocks[0].StockOutLength-= orderDetailNeedQuantity; |
| | | autoAssignStocks[0].StockOutLength+= orderDetailNeedQuantity; |
| | | if (autoAssignStocks[0].StockOutLength== autoAssignStocks[0].StockLength) |
| | | { |
| | | autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | } |
| | | assignStop =false; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); |
| | | locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Where(x=>!x.LocationCode.IsNullOrEmpty() && !locationInfos.Select(x=>x.LocationCode).Contains(x.LocationCode)).Select(x => x.LocationCode).ToList())); |
| | | } |
| | | |
| | | return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos, message); |
| | | } |
| | | /// <summary> |
| | | /// åºåºåºååé
åï¼æ´æ°æ°æ®åºæ°æ® |
| | |
| | | { |
| | | try |
| | | { |
| | | stockInfos.Where(x => x.LocationCode.IsNullOrEmpty()).ToList().ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.åºåºå®æ.ObjToInt(); |
| | | }); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | BaseDal.UpdateData(outboundOrderDetails); |
| | | |
| | |
| | | } |
| | | |
| | | _outStockLockInfoService.Repository.AddData(addOutStockLockInfos); |
| | | List<Dt_OutStockLockInfo> addOutCacheInfos = addOutStockLockInfos.Where(x => x.LocationCode.Contains("èåç¼ååº")).ToList(); |
| | | List<Dt_OutLineView> outLineViewsAdd = addOutCacheInfos.Select(x => _mapper.Map<Dt_OutLineView>(x)).ToList(); |
| | | _outboundRepository.OutLineViewRepository.AddData(outLineViewsAdd); |
| | | } |
| | | List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); |
| | | if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) |