| | |
| | | using System.Reflection.Emit; |
| | | using AutoMapper; |
| | | using AutoMapper; |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Mapster; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using Org.BouncyCastle.Crypto; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Reflection.Emit; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | |
| | | using WIDESEA_DTO.Base; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.CalcOut; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_DTO.ReturnMES; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEA_Model.Models.Check; |
| | | using static HslCommunication.Profinet.Knx.KnxCode; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | |
| | | private readonly IESSApiService _eSSApiService; |
| | | private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; |
| | | private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfoRepository; |
| | | public readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository; |
| | | public readonly IRepository<Dt_InboundOrder> _inboundOrderRepository; |
| | | public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository; |
| | | public readonly IRepository<Dt_LocationType> _locationTypeRepository; |
| | | |
| | | private Dictionary<string, string> stations = new Dictionary<string, string> |
| | | { |
| | |
| | | {"3-1","3-5" }, |
| | | }; |
| | | |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository) |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _eSSApiService = eSSApiService; |
| | | _allocateOrderRepository = allocateOrderRepository; |
| | | _allocateMaterialInfoRepository = allocateMaterialInfoRepository; |
| | | _inboundOrderDetailRepository = inboundOrderDetailRepository; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _locationTypeRepository = locationTypeRepository; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | } |
| | | |
| | | public WebResponseContent PrintFromData (string barcode) |
| | | { |
| | | var detail = _inboundOrderDetailRepository.QueryFirst(x => x.Barcode == barcode); |
| | | if(detail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error(); |
| | | } |
| | | |
| | | var inbound = _inboundOrderRepository.QueryFirst(x=>x.Id == detail.OrderId); |
| | | if(inbound == null) |
| | | { |
| | | return WebResponseContent.Instance.Error(); |
| | | } |
| | | var printFormData = new PrintFromDataDTO { |
| | | materialCode = detail.MaterielCode, |
| | | materialName = detail.MaterielName, |
| | | materialSpec = detail.Unit, |
| | | batchNo = detail.BatchNo, |
| | | pruchaseOrderNo = inbound.UpperOrderNo, |
| | | factoryArea = inbound.FactoryArea, |
| | | suplierCode = detail.SupplyCode, |
| | | quantity = detail.BarcodeQty |
| | | }; |
| | | |
| | | return WebResponseContent.Instance.OK(data:printFormData); |
| | | } |
| | | |
| | | #region åºåºåé
|
| | |
| | | PickingOutboundResponseDTO response = new PickingOutboundResponseDTO(); |
| | | decimal totalNeedAllocate = 0; // æ»éæ±åé
é |
| | | decimal totalActualAllocate = 0; // å®é
æ»åé
é |
| | | string targetWarehouse = string.Empty;// ç®æ ä»åº |
| | | string targetLocationCode = string.Empty; // ç®æ è´§ä½ |
| | | bool isWholeCaseOutbound = false; // æ¯å¦æ´ç®±åºåº |
| | | List<string> wholeCasePallets = new List<string>(); |
| | | Dictionary<string, string> palletLocationMap = new Dictionary<string, string>(); |
| | | Dictionary<string, bool> palletIsWholeCaseMap = new Dictionary<string, bool>(); |
| | | int? targetLocationType = null; |
| | | |
| | | |
| | | try |
| | | { |
| | |
| | | // è®°å½æ»éæ±æ°é |
| | | totalNeedAllocate = calculationResult.MaterielCalculations.Sum(x => x.UnallocatedQuantity); |
| | | |
| | | |
| | | // 2. å¤çç©æåé
|
| | | List<PickedStockDetailDTO> pickedDetails = new List<PickedStockDetailDTO>(); |
| | | Dt_OutboundOrder outboundOrder = calculationResult.OutboundOrder; |
| | |
| | | materielCalc.OutStockLockInfos.Add(item); |
| | | } |
| | | outStockLockInfos.Add(item); |
| | | } |
| | | |
| | | if (outboundOrder.OrderType == 117) |
| | | { |
| | | // å¹é
å½ååæ®çéå®è®°å½ |
| | | if (outboundOrder.OrderNo == item.OrderNo) |
| | | { |
| | | // æ¥è¯¢åºåä¿¡æ¯ |
| | | var stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == item.PalletCode); |
| | | if (stockInfo == null) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"æç{item.PalletCode}æªæ¥è¯¢å°åºåä¿¡æ¯ï¼æ æ³å¤çæ´ç®±åºåº"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | |
| | | // 计ç®åºåæ»éï¼å¤ææ¯å¦æ´ç®±ï¼å¢å 0å¼ä¿æ¤ï¼ |
| | | decimal stockQuantity = _stockDetailRepository.QueryData(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity); |
| | | if (stockQuantity > 0 && stockQuantity == item.AssignQuantity) |
| | | { |
| | | // æ è®°å½åæç为æ´ç®±ï¼æ ¸å¿ä¿®å¤ï¼ææç维度记å½ç¶æï¼ |
| | | if (!palletIsWholeCaseMap.ContainsKey(item.PalletCode)) |
| | | { |
| | | palletIsWholeCaseMap.Add(item.PalletCode, true); |
| | | } |
| | | else |
| | | { |
| | | palletIsWholeCaseMap[item.PalletCode] = true; |
| | | } |
| | | |
| | | // ç®æ ä»åº/è´§ä½ç±»ååªæ¥è¯¢ä¸æ¬¡ï¼æ§è½ä¼å+空å¼ä¿æ¤ï¼ |
| | | if (string.IsNullOrEmpty(targetWarehouse)) |
| | | { |
| | | targetWarehouse = GetToWarehouseByOrderNo(request.OrderNo); |
| | | if (string.IsNullOrEmpty(targetWarehouse)) |
| | | { |
| | | content = WebResponseContent.Instance.Error("æºä»è°æºä»æ´ç®±åºåºåæ®æªé
ç½®ç®æ ä»åº"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | |
| | | // æ¿æ¢First()为FirstOrDefault()ï¼é¿å
空å¼å¼å¸¸ |
| | | string warehouseAreaName = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>() |
| | | .Where(x => x.Code == targetWarehouse) |
| | | .Select(x => x.Name) |
| | | .First(); |
| | | if (string.IsNullOrEmpty(warehouseAreaName)) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"ç®æ ä»åº{targetWarehouse}æªæ¥è¯¢å°å¯¹åºçåºåºåç§°"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | |
| | | int? locationType = _locationTypeRepository.Db.Queryable<Dt_LocationType>() |
| | | .Where(x => string.Equals(x.LocationTypeDesc, warehouseAreaName, StringComparison.OrdinalIgnoreCase)) |
| | | .Select(x => x.LocationType) |
| | | .First(); |
| | | if (!locationType.HasValue) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"åºåº{warehouseAreaName}æªå¹é
å°å¯¹åºçè´§ä½ç±»å"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | targetLocationType = locationType.Value; |
| | | } |
| | | |
| | | // åé
ç®æ è´§ä½ï¼æ¯ä¸ªæçç¬ç«è´§ä½ï¼ |
| | | if (!palletLocationMap.ContainsKey(item.PalletCode) && targetLocationType.HasValue) |
| | | { |
| | | Dt_LocationInfo locationInfo = _locationInfoService.AssignLocation(targetLocationType.Value); |
| | | if (locationInfo == null || string.IsNullOrEmpty(locationInfo.LocationCode)) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"è´§ä½ç±»å{targetLocationType.Value}æªåé
å°å¯ç¨è´§ä½ï¼æçï¼{item.PalletCode}ï¼"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | palletLocationMap.Add(item.PalletCode, locationInfo.LocationCode); |
| | | } |
| | | |
| | | // å å
¥æ´ç®±æçå表 |
| | | if (!wholeCasePallets.Contains(item.PalletCode)) |
| | | { |
| | | wholeCasePallets.Add(item.PalletCode); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (!palletIsWholeCaseMap.ContainsKey(item.PalletCode)) |
| | | { |
| | | palletIsWholeCaseMap.Add(item.PalletCode, false); |
| | | } |
| | | else |
| | | { |
| | | palletIsWholeCaseMap[item.PalletCode] = false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // å¤çä»»å¡ |
| | | foreach (var item in materielPickedDetails.Tasks) |
| | | { |
| | | if (outboundOrder.OrderType == 117 |
| | | && palletIsWholeCaseMap.ContainsKey(item.PalletCode) |
| | | && palletIsWholeCaseMap[item.PalletCode] |
| | | && palletLocationMap.ContainsKey(item.PalletCode)) |
| | | { |
| | | item.TaskType = (int)TaskTypeEnum.Relocation; |
| | | item.TargetAddress = palletLocationMap[item.PalletCode]; |
| | | } |
| | | if (tasks.FirstOrDefault(x => x.PalletCode == item.PalletCode) == null) |
| | | tasks.Add(item); |
| | | } |
| | |
| | | foreach (var detail in materielCalc.Details) |
| | | { |
| | | if (remainingToLock <= 0) break; |
| | | decimal maxLockableQty = detail.OrderQuantity - detail.OverOutQuantity - detail.LockQuantity; |
| | | decimal maxLockableQty = detail.OrderQuantity - detail.OverOutQuantity; |
| | | if (maxLockableQty <= 0) continue; |
| | | decimal currentLockQty = Math.Min(remainingToLock, maxLockableQty); |
| | | detail.LockQuantity += currentLockQty; |
| | |
| | | UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.åºåºéå®.ObjToInt()); |
| | | UpdateLocationStatus(pickedDetails.Select(x => x.LocationCode).ToList(), LocationStatusEnum.Lock.ObjToInt()); |
| | | } |
| | | UpdateOutStockLockInfo(outStockLockInfos); |
| | | //鿣å䏿£éï¼å»æéå®è®°å½ååºï¼å次ç»çæ¶æ£é¤åæ¡ç |
| | | if (outboundOrder.OrderType != InOrderTypeEnum.ReCheck.ObjToInt()) |
| | | { |
| | | UpdateOutStockLockInfo(outStockLockInfos); |
| | | } |
| | | |
| | | if (tasks.Any()) _taskRepository.AddData(tasks); |
| | | |
| | | if (outboundOrder.OrderType == 117 && wholeCasePallets.Any()) |
| | | { |
| | | foreach (var palletCode in wholeCasePallets) |
| | | { |
| | | var completeReq = new OutboundCompletePalletRequestDTO |
| | | { |
| | | OrderNo = request.OrderNo, |
| | | PalletCode = palletCode |
| | | }; |
| | | |
| | | var res = CompleteOutboundWithPallet(completeReq); |
| | | if (!res.Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return res; |
| | | } |
| | | } |
| | | } |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | |
| | | string responseMsg = totalActualAllocate == totalNeedAllocate |
| | | ? "忣任å¡åé
æå" |
| | | : $"忣任å¡åé
宿ï¼å®é
åé
{totalActualAllocate}ï¼éæ±{totalNeedAllocate}ï¼åºåä¸è¶³é¨åæªåé
ï¼"; |
| | | Dt_OutboundOrder outboundOrder1 = _outboundRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == request.OrderNo).Includes(x=>x.Details).First(); |
| | | if(totalActualAllocate == 0 && !outboundOrder1.Details.Any(x=>x.LockQuantity >0)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, (int)OutOrderStatusEnum.æªå¼å§); |
| | | return WebResponseContent.Instance.Error("åé
åºåæ°é为0ï¼æ æ³åºåº"); |
| | | } |
| | | response.Success = true; |
| | | response.Message = responseMsg; |
| | | response.Tasks = tasks; |
| | |
| | | content = WebResponseContent.Instance.Error("å¤çæ£è´§åºåºå¤±è´¥ï¼" + ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ®å·è·åç®æ ä»åº |
| | | /// </summary> |
| | | /// <param name="orderNo"></param> |
| | | /// <returns></returns> |
| | | public String GetToWarehouseByOrderNo(string orderNo) |
| | | { |
| | | var order =_allocateOrderRepository.QueryFirst(x => x.OrderNo == orderNo); |
| | | return order.ToWarehouse; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | x => request.StockDetailIds.Contains(x.Id) |
| | | && x.MaterielCode == materielCalc.MaterielCode |
| | | && x.StockQuantity > 0 |
| | | && (x.Status == (int)StockStatusEmun.å
¥åºå®æ || x.Status == (int)StockStatusEmun.æå¨è§£é)); |
| | | && (x.Status == (int)StockStatusEmun.å
¥åºå®æ || x.Status == (int)StockStatusEmun.æå¨å»ç» || x.Status == (int)StockStatusEmun.æå¨è§£é || x.Status == (int)StockStatusEmun.è¿æ)); |
| | | |
| | | if (!specifiedStockDetails.Any()) |
| | | { |
| | |
| | | |
| | | List<int> stockIds = stockDetailList.GroupBy(x => x.StockId).Select(x => x.Key).ToList(); |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => |
| | | stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() || x.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()) |
| | | stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode)); |
| | | |
| | | foreach (var stockInfo in stockInfos) |
| | |
| | | decimal totalAllocatedQuantity = CalcTotalAllocatedQuantity(lockInfos, stockInfo.Id, detail.MaterielCode); |
| | | lockInfo.AssignQuantity += actualAllocatedQuantity; |
| | | lockInfo.AllocatedQuantity = totalAllocatedQuantity; |
| | | // åééå®è®°å½ä¹æ´æ°OriginalQuantity为æçæ»åºåï¼å¯éï¼ä¿ææ°æ®ä¸è´ï¼ |
| | | if (palletMaterielTotalStock > 0) |
| | | lockInfo.OriginalQuantity = palletMaterielTotalStock; |
| | | lockInfoList.Add(lockInfo); |
| | | } |
| | | else |
| | | { |
| | | // ===== æ ¸å¿ä¼å2ï¼OriginalQuantityèµå¼ä¸ºæçç©ææ»åºå ===== |
| | | decimal originalQuantity = palletMaterielTotalStock; // æ¿ä»£åæå±é¨æç»æ°é |
| | | decimal originalQuantity = palletMaterielTotalStock; |
| | | |
| | | List<string> allDetailIds = outboundOrder.Details.Where(x => |
| | | x.OrderId == outboundOrder.Id && x.MaterielCode == detail.MaterielCode |
| | |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo); |
| | | if (outboundOrder == null) return false; |
| | | outboundOrder.OrderStatus = status; |
| | | if(outboundOrder.CreateType == OrderCreateTypeEnum.CreateInSystem.ObjToInt()) |
| | | { |
| | | outboundOrder.ReturnToMESStatus = 5; |
| | | } |
| | | _outboundRepository.UpdateData(outboundOrder); |
| | | return true; |
| | | } |
| | |
| | | // æ´ç®±åºåºæ éæå
|
| | | PerformFullOutboundOperation(stockInfo, request, lockInfo.TaskNum.GetValueOrDefault()); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | if (outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | { |
| | | Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo); |
| | | if (allocateOrder != null) |
| | |
| | | } |
| | | _allocateMaterialInfoRepository.AddData(allocateMaterialInfos); |
| | | } |
| | | } |
| | | else if(outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()) |
| | | { |
| | | List<Dt_AllocateMaterialInfo> allocateMaterialInfos = new List<Dt_AllocateMaterialInfo>(); |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = item.Barcode??"", |
| | | BatchNo = item.BatchNo, |
| | | FactoryArea = item.FactoryArea, |
| | | MaterialCode = item.MaterielCode, |
| | | MaterialName = item.MaterielName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = item.StockQuantity, |
| | | SupplyCode = item.SupplyCode??"", |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode??"" |
| | | }; |
| | | allocateMaterialInfos.Add(allocateMaterialInfo); |
| | | } |
| | | _allocateMaterialInfoRepository.AddData(allocateMaterialInfos); |
| | | } |
| | | |
| | | decimal allocatedQuantity = actualOutboundQuantity; |
| | |
| | | { |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | if(item.ReturnToMESStatus == 0) |
| | | { |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | else |
| | | { |
| | | item.CurrentDeliveryQty += item.LockQuantity - item.OverOutQuantity; |
| | | } |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | |
| | | updateDetails.Add(item); |
| | |
| | | ContractResolver = new CamelCasePropertyNamesContractResolver() |
| | | }; |
| | | item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings); |
| | | //鿣åºåºä¸éè¦åä¼ |
| | | if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()) |
| | | { |
| | | item.ReturnJsonData = ""; |
| | | } |
| | | } |
| | | |
| | | lockInfo.SortedQuantity = lockInfo.SortedQuantity + actualOutboundQuantity; |
| | |
| | | response.Message = "åºåºå®æ"; |
| | | response.UpdatedDetails = updateDetails; |
| | | |
| | | if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails)) |
| | | { |
| | | Func<Dt_OutStockLockInfo, bool> supWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().SupplyCode) ? true : x.SupplyCode == outboundOrderDetails.First().SupplyCode; |
| | | |
| | | Func<Dt_OutStockLockInfo, bool> wareWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().WarehouseCode) ? true : x.WarehouseCode == outboundOrderDetails.First().WarehouseCode; |
| | | |
| | | List<Dt_OutStockLockInfo> stockLockInfos = _outboundLockInfoRepository.QueryData(x => |
| | | x.OrderNo == request.OrderNo && |
| | | x.MaterielCode == stockInfoDetail.MaterielCode).Where(supWhere).Where(wareWhere).ToList(); |
| | | if (stockLockInfos != null && stockLockInfos.Any()) |
| | | { |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(stockLockInfos, WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å é¤); |
| | | } |
| | | } |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.åºåºå®æ.ObjToInt()); |
| | | |
| | | if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt()&& outboundOrder.OrderType!= InOrderTypeEnum.ReCheck.ObjToInt()) |
| | | { |
| | | _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo); |
| | | } |
| | |
| | | _stockDetailHistoryRepository.AddData(historyRecords); |
| | | |
| | | // å é¤åºåæç»è®°å½ |
| | | _stockDetailRepository.DeleteData(stockInfo.Details); |
| | | var orderNo =_outboundRepository.QueryFirst(x => x.OrderNo == request.OrderNo); |
| | | if(orderNo.OrderType != 117) |
| | | { |
| | | _stockDetailRepository.DeleteData(stockInfo.Details); |
| | | } |
| | | _stockChangeRepository.AddData(changeRecords); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region æ£é |
| | |
| | | |
| | | MaterialCodeReturnDTO returnDTO = returnDTOs.First(x => x.Barcode == newBarcode); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()||outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | |
| | | { |
| | | PerformFullOutboundOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt() || outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | // 夿æ¯å¦æ¯è°æ¨å |
| | | if (outboundOrder.OrderType != 0) |
| | | // 夿æ¯å¦æ¯æºä»è°æºä»å |
| | | if ( outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | { |
| | | Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo); |
| | | if (allocateOrder != null) |
| | |
| | | { |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | if (item.ReturnToMESStatus == 0) |
| | | { |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | else |
| | | { |
| | | item.CurrentDeliveryQty += item.LockQuantity - item.OverOutQuantity; |
| | | } |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | |
| | | if (item.OverOutQuantity == item.OrderQuantity) |
| | | { |
| | | item.OrderDetailStatus = (int)OrderDetailStatusEnum.Over; |
| | | } |
| | | updateDetails.Add(item); |
| | | |
| | | List<Barcodes> barcodesList = new List<Barcodes>(); |
| | |
| | | _feedbackMesService.BarcodeFeedback(newBarcode); |
| | | } |
| | | |
| | | // å é¤éå®è®°å½ï¼å¦æåºåºæç»å
¨é¨å®æï¼ ä¸CalculateActualOutboundQuantityæ¹æ³é颿³¨é代ç 2é1ä½¿ç¨ |
| | | if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails.First())) |
| | | if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails)) |
| | | { |
| | | Func<Dt_OutStockLockInfo, bool> supWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().SupplyCode) ? true : x.SupplyCode == outboundOrderDetails.First().SupplyCode; |
| | | |
| | |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(stockLockInfos, WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å é¤); |
| | | } |
| | | } |
| | | |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.åºåºå®æ.ObjToInt()); |
| | | |
| | | if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt()) |
| | | if (outboundOrder.CreateType!=OrderCreateTypeEnum.CreateInSystem.ObjToInt()) |
| | | { |
| | | _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo); |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// <summary> |
| | | /// æ£æ¥åºåºåæç»æ¯å¦å®æ |
| | | /// </summary> |
| | | public bool CheckOutboundOrderDetailCompletedByMatCode(string orderNo, string materialCode, Dt_OutboundOrderDetail outboundOrderDetail) |
| | | public bool CheckOutboundOrderDetailCompletedByMatCode(string orderNo, string materialCode, List<Dt_OutboundOrderDetail> outboundOrderDetails) |
| | | { |
| | | if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(materialCode) || outboundOrderDetails == null || !outboundOrderDetails.Any()) |
| | | return false; |
| | | |
| | | // æ¥è¯¢ä¸»è®¢åï¼ä¸åå¨ç´æ¥è¿åfalse |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo); |
| | | if (outboundOrder == null) return false; |
| | | |
| | | List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && x.MaterielCode == materialCode && (string.IsNullOrEmpty(outboundOrderDetail.SupplyCode) || x.SupplyCode == outboundOrderDetail.SupplyCode) && (string.IsNullOrEmpty(outboundOrderDetail.WarehouseCode) || x.WarehouseCode == outboundOrderDetail.WarehouseCode)); |
| | | var firstDetail = outboundOrderDetails.FirstOrDefault(); |
| | | string supplyCode = firstDetail.SupplyCode; |
| | | string warehouseCode = firstDetail.WarehouseCode; |
| | | List<int> ids = outboundOrderDetails.Select(x => x.Id).ToList(); |
| | | |
| | | // æ£æ¥æææç»çå·²åºæ°éæ¯å¦é½çäºåæ®æ°é |
| | | List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => |
| | | x.OrderId == outboundOrder.Id |
| | | && x.MaterielCode == materialCode |
| | | && ids.Contains(x.Id) |
| | | && (string.IsNullOrEmpty(supplyCode) || x.SupplyCode == supplyCode) |
| | | && (string.IsNullOrEmpty(warehouseCode) || x.WarehouseCode == warehouseCode) |
| | | ); |
| | | |
| | | if (!details.Any()) return false; |
| | | |
| | | return details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty); |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync(); |
| | | |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == palletCode); |
| | | if (task != null) |
| | | { |
| | | return WebResponseContent.Instance.Error("ä»»å¡ä¿¡æ¯å表åå¨è¯¥æççä»»å¡ä¿¡æ¯ï¼ä¸å¯å走空箱ï¼è¯·æ£æ¥ä»»å¡æ¯å¦å®æ"); |
| | | } |
| | | |
| | | if (stock == null) |
| | | { |
| | |
| | | if (stock.Details.Count <= 0) |
| | | { |
| | | stock.PalletType = (int)PalletTypeEnum.Empty; |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.StockStatus = (int)StockStatusEmun.å
¥åºç¡®è®¤; |
| | | stock.LocationCode = ""; |
| | | } |
| | | else if (stock.Details.Count > 0) |
| | | { |
| | | Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x => |
| | | x.OrderNo == OrderNo && |
| | | x.StockId == stock.Id && |
| | | x.PalletCode == palletCode); |
| | | |
| | | if (lockInfo != null && lockInfo.SortedQuantity != lockInfo.AssignQuantity) |
| | | { |
| | | return content.Error($"æç{palletCode}åºåæªæ£éå®ä¸å
许ååº"); |
| | | return content.Error($"æç{palletCode}åºåï¼å¨åæ®{lockInfo.OrderNo}éé¢è¿æªæ£é宿ï¼ä¸å
许ååº"); |
| | | } |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.StockStatus = (int)StockStatusEmun.å
¥åºç¡®è®¤; |
| | | stock.LocationCode = ""; |
| | | } |
| | | |
| | |
| | | |
| | | // åé
æ°è´§ä½ |
| | | var newLocation = _locationInfoService.AssignLocation(stock.LocationType); |
| | | |
| | | if(newLocation == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("没æç©ºé²åºä½å¯ååº"); |
| | | } |
| | | |
| | | var newTask = new Dt_Task() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent RecheckPicking(RecheckPickingDTO pickingDTO) |
| | | { |
| | | try |
| | | { |
| | | Dt_ReCheckOrder reCheckOrder = _outboundRepository.Db.Queryable<Dt_ReCheckOrder>().Where(x => x.OrderNo == pickingDTO.orderNo && x.Result == 0).First(); |
| | | if(reCheckOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥å¾
鿣çåæ®{pickingDTO.orderNo}"); |
| | | } |
| | | Dt_StockInfoDetail stockInfoDetail = _stockDetailRepository.QueryFirst(x=>x.Barcode == pickingDTO.barCode && x.Status == StockStatusEmun.æå¨å»ç».ObjToInt() ); |
| | | if(stockInfoDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªå¨åºå䏿¾å°è¯¥å»ç»/é离æ¡ç {pickingDTO.barCode}"); |
| | | } |
| | | if (stockInfoDetail.MaterielCode != reCheckOrder.MaterielCode || stockInfoDetail.BatchNo != reCheckOrder.BatchNo) |
| | | { |
| | | return WebResponseContent.Instance.Error("该æ¡ç çç©æç¼ç åæ¹æ¬¡åè¯¥éæ£åä¸ç¬¦"); |
| | | } |
| | | stockInfoDetail.OrderNo = pickingDTO.orderNo; |
| | | stockInfoDetail.Status = StockStatusEmun.鿣ä¸.ObjToInt(); |
| | | var currentRemark = _outboundRepository.Db.Queryable<Dt_OutboundOrder>() |
| | | .Where(x => x.OrderNo == pickingDTO.orderNo) |
| | | .Select(x => x.Remark) |
| | | .First(); |
| | | |
| | | string newRemark; |
| | | if (string.IsNullOrWhiteSpace(currentRemark)) |
| | | { |
| | | newRemark = pickingDTO.barCode; |
| | | } |
| | | else |
| | | { |
| | | var existingCodes = currentRemark.Split(',', StringSplitOptions.RemoveEmptyEntries) |
| | | .Select(s => s.Trim()) |
| | | .ToList(); |
| | | |
| | | if (!existingCodes.Contains(pickingDTO.barCode)) |
| | | { |
| | | existingCodes.Add(pickingDTO.barCode); |
| | | newRemark = string.Join(",", existingCodes); |
| | | } |
| | | else |
| | | { |
| | | newRemark = currentRemark; |
| | | } |
| | | } |
| | | _outboundRepository.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.Remark == newRemark) |
| | | .SetColumns(x=>x.OrderStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | .Where(x => x.OrderNo == pickingDTO.orderNo) |
| | | .ExecuteCommand(); |
| | | _stockDetailRepository.UpdateData(stockInfoDetail); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | } |
| | | } |