public Task <Int64> Create(MoveQueuesPost movequeuesPost) { // Additional validations // Pre-process // Process this._movequeuesRepository.RegisterCreate(movequeuesPost); try { this._movequeuesRepository.Commit(); } catch (Exception ex) { this._movequeuesRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block //We update the queued utilization if necesary if (movequeuesPost.ixMoveQueueType == _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault() //&& movequeuesPost.ixMoveQueueContext == _commonLookUps.getMoveQueueContexts().Where(x => x.sMoveQueueContext == "Putaway").Select(x => x.ixMoveQueueContext).FirstOrDefault() && movequeuesPost.ixSourceInventoryLocation != movequeuesPost.ixTargetInventoryLocation ) { var targetInventoryLocation = _inventorylocationsService.GetPost(movequeuesPost.ixTargetInventoryLocation ?? 0); var inventoryUnitsOnHandlingUnit = _inventoryunitsService.IndexDb().Where(x => x.ixHandlingUnit == movequeuesPost.ixTargetHandlingUnit).ToList(); targetInventoryLocation.nQueuedUtilisationPercent = _volumeAndWeight.getNewLocationQueuedUtilisationPercent(movequeuesPost.ixTargetHandlingUnit ?? 0, inventoryUnitsOnHandlingUnit, targetInventoryLocation, true); targetInventoryLocation.UserName = movequeuesPost.UserName; _inventorylocationsService.Edit(targetInventoryLocation); } if (movequeuesPost.ixMoveQueueType == _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Unit Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault() //&& movequeuesPost.ixMoveQueueContext == _commonLookUps.getMoveQueueContexts().Where(x => x.sMoveQueueContext == "Picking").Select(x => x.ixMoveQueueContext).FirstOrDefault() && movequeuesPost.ixSourceInventoryLocation != movequeuesPost.ixTargetInventoryLocation ) { var targetInventoryLocation = _inventorylocationsService.GetPost(movequeuesPost.ixTargetInventoryLocation ?? 0); var targetInventoryUnit = _inventoryunitsService.GetPost(movequeuesPost.ixTargetInventoryUnit ?? 0); targetInventoryLocation.nQueuedUtilisationPercent = _volumeAndWeight.getNewLocationQueuedUtilisationPercent(targetInventoryUnit, targetInventoryLocation, true); targetInventoryLocation.UserName = movequeuesPost.UserName; _inventorylocationsService.Edit(targetInventoryLocation); } //Custom Code End return(Task.FromResult(movequeuesPost.ixMoveQueue)); }
private async Task <DialogTurnResult> PackToHandlingUnitPrompt( WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var nBaseUnitQuantityPicked = step.Result; ((PickBatchPickingPost)step.Values[DialogKey]).nBaseUnitQuantityPicked = Convert.ToDouble(nBaseUnitQuantityPicked); //Custom Code Start | Added Code Block step.Values[IsCompleteInventoryUnitPickKey] = _picking.isCompleteInventoryUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked)); step.Values[IsHandlingUnitPickKey] = _picking.isHandlingUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked)); //We adjust the queued qty down var inventoryUnitPickedFrom = _inventoryunitsService.GetPost(((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit); inventoryUnitPickedFrom.nBaseUnitQuantityQueued -= (double)step.Values[PickSuggestionQtyKey]; inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(step.Context, () => _botUserData); //If we pick complete inventory unit we move it to the picker else we adjust and create/consolidate and then move to the picker if ((bool)step.Values[IsCompleteInventoryUnitPickKey]) { //We now create and execute the move queue for the pickup step.Values[PickedInventoryUnitKey] = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; MoveQueuesPost moveQueuePost = new MoveQueuesPost(); if (_picking.isHandlingUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked))) { moveQueuePost.ixMoveQueueType = _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Unit Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); } else { moveQueuePost.ixMoveQueueType = _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); } moveQueuePost.ixMoveQueueContext = _commonLookUps.getMoveQueueContexts().Where(x => x.sMoveQueueContext == "Picking").Select(x => x.ixMoveQueueContext).FirstOrDefault(); moveQueuePost.ixSourceInventoryUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; moveQueuePost.ixTargetInventoryUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; moveQueuePost.ixSourceInventoryLocation = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryLocation; moveQueuePost.ixTargetInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePost.ixSourceHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit > 0 ? ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit : null; moveQueuePost.ixTargetHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit > 0 ? ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit : null; moveQueuePost.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePost.nBaseUnitQuantity = Convert.ToDouble(nBaseUnitQuantityPicked); moveQueuePost.dtStartedAt = DateTime.Now; moveQueuePost.ixPickBatch = ((PickBatchPickingPost)step.Values[DialogKey]).ixPickBatch; moveQueuePost.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Active").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePost.UserName = step.Context.Activity.Conversation.Id; var ixMoveQueue = await _movequeuesService.Create(moveQueuePost); //We now complete the move queue for the pickup var moveQueuePickUp = _movequeuesService.GetPost(ixMoveQueue); moveQueuePickUp.dtCompletedAt = DateTime.Now; moveQueuePickUp.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePickUp.UserName = moveQueuePost.UserName; await _movequeuesService.Edit(moveQueuePickUp); } else { //Now we adjust the iu remaining down inventoryUnitPickedFrom.nBaseUnitQuantity -= Convert.ToDouble(nBaseUnitQuantityPicked); inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); //Now we either create or edit an iu for the qty picked inventoryUnitPickedFrom.nBaseUnitQuantity = Convert.ToDouble(nBaseUnitQuantityPicked); inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; inventoryUnitPickedFrom.ixInventoryLocation = currentBotUserData.ixInventoryLocation; if (_inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnitPickedFrom.ixFacility && x.ixCompany == inventoryUnitPickedFrom.ixCompany && x.ixMaterial == inventoryUnitPickedFrom.ixMaterial && x.ixInventoryState == inventoryUnitPickedFrom.ixInventoryState && x.ixHandlingUnit == inventoryUnitPickedFrom.ixHandlingUnit && x.ixInventoryLocation == inventoryUnitPickedFrom.ixInventoryLocation && x.sBatchNumber == inventoryUnitPickedFrom.sBatchNumber && x.dtExpireAt == inventoryUnitPickedFrom.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).Any() ) { //We edit the iu inventoryUnitPickedFrom.ixInventoryUnit = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnitPickedFrom.ixFacility && x.ixCompany == inventoryUnitPickedFrom.ixCompany && x.ixMaterial == inventoryUnitPickedFrom.ixMaterial && x.ixInventoryState == inventoryUnitPickedFrom.ixInventoryState && x.ixHandlingUnit == inventoryUnitPickedFrom.ixHandlingUnit && x.ixInventoryLocation == inventoryUnitPickedFrom.ixInventoryLocation && x.sBatchNumber == inventoryUnitPickedFrom.sBatchNumber && x.dtExpireAt == inventoryUnitPickedFrom.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).FirstOrDefault(); inventoryUnitPickedFrom.nBaseUnitQuantity = _inventoryunitsService.GetPost(inventoryUnitPickedFrom.ixInventoryUnit).nBaseUnitQuantity + Convert.ToDouble(nBaseUnitQuantityPicked); await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); step.Values[PickedInventoryUnitKey] = inventoryUnitPickedFrom.ixInventoryUnit; } else { //We create an iu step.Values[PickedInventoryUnitKey] = await _inventoryunitsService.Create(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); } } //We now allocate the picked qty to open allocation lines step.Values[LineQtysPickedKey] = new List <Tuple <Int64, double> >(); var pickedQtyNotAllocated = Convert.ToDouble(nBaseUnitQuantityPicked); _outboundorderlinesinventoryallocationService.IndexDbPost().Where(x => (x.nBaseUnitQuantityAllocated - x.nBaseUnitQuantityPicked) > 0).OrderBy(x => (x.nBaseUnitQuantityAllocated - x.nBaseUnitQuantityPicked) > 0).ToList() .Join(_picking.getOrderLinesInBatchForMaterial(((PickBatchPickingPost)step.Values[DialogKey]).ixPickBatch, ((InventoryUnits)step.Values[PickSuggestionKey]).ixMaterial), ol => ol.ixOutboundOrderLine, olb => olb, (ol, olb) => new { Ol = ol, Olb = olb }).ToList() .ForEach(y => { if ((y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked) <= pickedQtyNotAllocated && pickedQtyNotAllocated > 0) { ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).Add(new Tuple <long, double>(y.Ol.ixOutboundOrderLine, y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked)); y.Ol.nBaseUnitQuantityPicked += y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked; pickedQtyNotAllocated -= y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked; y.Ol.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinesinventoryallocationService.Edit(y.Ol); } else if ((y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked) > pickedQtyNotAllocated && pickedQtyNotAllocated > 0) { ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).Add(new Tuple <long, double>(y.Ol.ixOutboundOrderLine, pickedQtyNotAllocated)); y.Ol.nBaseUnitQuantityPicked += pickedQtyNotAllocated; pickedQtyNotAllocated -= pickedQtyNotAllocated; y.Ol.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinesinventoryallocationService.Edit(y.Ol); } } ); //Custom Code End //We have to figure out whether this is a pick of a complete Handling Unit. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //return await step.PromptAsync( // PackToHandlingUnitPromptId, // new PromptOptions // { // Prompt = MessageFactory.Text($"Please enter a PackToHandlingUnit:"), // RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), // }, // cancellationToken); //Replaced Code Block End if ((bool)step.Values[IsHandlingUnitPickKey]) { ((PickBatchPickingPost)step.Values[DialogKey]).sPackToHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).HandlingUnits.sHandlingUnit; ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).HandlingUnits.ixHandlingUnit; //We create the packing record var orderLinesToPack = ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).GroupBy(x => x.Item1).Select(x => new { ixOutboundOrderLine = x.Key, Total = x.Sum(s => s.Item2) }).ToList(); orderLinesToPack.ForEach(x => { //We check if there is an existing pack record we can use if ( _outboundorderlinepackingService.IndexDb().Where(p => p.ixHandlingUnit == ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit && p.ixOutboundOrderLine == x.ixOutboundOrderLine ).Any() ) { var outboundorderlinepack = _outboundorderlinepackingService.GetPost(_outboundorderlinepackingService.IndexDb().Where(p => p.ixHandlingUnit == ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit && p.ixOutboundOrderLine == x.ixOutboundOrderLine ).Select(p => p.ixOutboundOrderLinePack).FirstOrDefault() ); outboundorderlinepack.nBaseUnitQuantityPacked += x.Total; outboundorderlinepack.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinepackingService.Edit(outboundorderlinepack); } else { var outboundorderlinepack = new OutboundOrderLinePackingPost(); outboundorderlinepack.ixOutboundOrderLine = x.ixOutboundOrderLine; outboundorderlinepack.ixHandlingUnit = ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit; outboundorderlinepack.nBaseUnitQuantityPacked = x.Total; outboundorderlinepack.ixStatus = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); outboundorderlinepack.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinepackingService.Create(outboundorderlinepack); } } ); return(await step.EndDialogAsync( (PickBatchPickingPost)step.Values[DialogKey], cancellationToken)); } else { return(await step.PromptAsync( PackToHandlingUnitPromptId, new PromptOptions { //Custom Code Start | Replaced Code Block //Replaced Code Block Start //Prompt = MessageFactory.Text($"Please enter a PackToHandlingUnit:"), //Replaced Code Block End Prompt = MessageFactory.Text($"Please enter/scan the Pack To Handling Unit:"), //Custom Code End RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), }, cancellationToken)); } //Custom Code End }
public Task <Int64> Create(ReceivingPost receivingPost) { // Additional validations // Pre-process //Custom Code Start | Added Code Block //If the handling unit does not exist we create it if (!HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Any()) { HandlingUnitsPost handlingUnitsPost = new HandlingUnitsPost(); handlingUnitsPost.sHandlingUnit = receivingPost.sReceipt; handlingUnitsPost.ixHandlingUnitType = receivingPost.ixHandlingUnitType ?? 0; handlingUnitsPost.UserName = receivingPost.UserName; receivingPost.ixHandlingUnit = _handlingunitsService.Create(handlingUnitsPost).Result; } else { receivingPost.ixHandlingUnit = HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Select(x => x.ixHandlingUnit).FirstOrDefault(); } InventoryUnitsPost inventoryUnit = new InventoryUnitsPost(); var inboundOrder = _inboundordersService.GetPost(receivingPost.ixInboundOrder); inventoryUnit.ixFacility = inboundOrder.ixFacility; inventoryUnit.ixCompany = inboundOrder.ixCompany; inventoryUnit.ixMaterial = receivingPost.ixMaterial; inventoryUnit.ixInventoryState = receivingPost.ixInventoryState; inventoryUnit.ixHandlingUnit = receivingPost.ixHandlingUnit; inventoryUnit.ixInventoryLocation = receivingPost.ixInventoryLocation; inventoryUnit.sSerialNumber = receivingPost.sSerialNumber; inventoryUnit.sBatchNumber = receivingPost.sBatchNumber; inventoryUnit.dtExpireAt = receivingPost.dtExpireAt; inventoryUnit.UserName = receivingPost.UserName; if ((inventoryUnit.sSerialNumber ?? "").Trim() != "") { //We create an iu inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext); } else if (_inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnit.ixFacility && x.ixCompany == inventoryUnit.ixCompany && x.ixMaterial == inventoryUnit.ixMaterial && x.ixInventoryState == inventoryUnit.ixInventoryState && x.ixHandlingUnit == inventoryUnit.ixHandlingUnit && x.ixInventoryLocation == inventoryUnit.ixInventoryLocation && x.sBatchNumber == inventoryUnit.sBatchNumber && x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).Any() ) { //We edit the iu inventoryUnit.ixInventoryUnit = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnit.ixFacility && x.ixCompany == inventoryUnit.ixCompany && x.ixMaterial == inventoryUnit.ixMaterial && x.ixInventoryState == inventoryUnit.ixInventoryState && x.ixHandlingUnit == inventoryUnit.ixHandlingUnit && x.ixInventoryLocation == inventoryUnit.ixInventoryLocation && x.sBatchNumber == inventoryUnit.sBatchNumber && x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).FirstOrDefault(); inventoryUnit.nBaseUnitQuantity = _inventoryunitsService.GetPost(inventoryUnit.ixInventoryUnit).nBaseUnitQuantity + receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Edit(inventoryUnit, _ixInventoryUnitTransactionContext); } else { //We create an iu inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext); } //Custom Code End // Process this._receivingRepository.RegisterCreate(receivingPost); try { this._receivingRepository.Commit(); } catch (Exception ex) { this._receivingRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block //Now we update the inbound order lines - for now we apply entire qty to the matching line var _ixInboundOrderLine = _inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder && x.ixMaterial == receivingPost.ixMaterial).Select(x => x.ixInboundOrderLine).FirstOrDefault(); var inboundOrderLine = _inboundorderlinesService.GetPost(_ixInboundOrderLine); inboundOrderLine.nBaseUnitQuantityReceived += receivingPost.nBaseUnitQuantityReceived; inboundOrderLine.UserName = receivingPost.UserName; if ((inboundOrderLine.nBaseUnitQuantityExpected - inboundOrderLine.nBaseUnitQuantityReceived) == 0) { inboundOrderLine.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); } _inboundorderlinesService.Edit(inboundOrderLine); //If there are no open qtys we set the inbound order/line status to complete if (_inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder).Select(x => x.nBaseUnitQuantityExpected - x.nBaseUnitQuantityReceived).Sum() == 0) { var inboundorder = _inboundordersService.GetPost(receivingPost.ixInboundOrder); inboundorder.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); _inboundordersService.Edit(inboundorder); } //Custom Code End return(Task.FromResult(receivingPost.ixReceipt)); }
public Int64 getPutAwaySuggestion(Int64 ixHandlingUnit, Int64 ixCompany, Int64 ixFacility, Int64 ixInventoryLocationUser) { var inventoryLocationUserPost = _inventorylocationsService.GetPost(ixInventoryLocationUser); List <InventoryLocationsPost> putAwaySuggestions = new List <InventoryLocationsPost>(); //Receiving RC //Reserve Storage RV //Let Down Storage LD //Forward Pick Storage FP //Consolidation CN //Shipping SH //Staging ST //Trailer Doors TR //Person PE var allowedLocationFunctions = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "RV" || x.sLocationFunctionCode == "LD" || x.sLocationFunctionCode == "FP" ).Select(x => x.ixLocationFunction).ToList(); //We implement Proximity in bay to slotted location THEN Location type THEN Closest + Defaults var inventoryUnitsOnHandlingUnit = _inventoryunitsService.IndexDb().Where(x => x.ixHandlingUnit == ixHandlingUnit).ToList(); var materials = inventoryUnitsOnHandlingUnit.GroupBy(x => x.ixMaterial) .Select(y => new { ixMaterial = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ).ToList(); var ixMaterialDominant = materials.OrderByDescending(x => x.nTotalBaseUnits).Select(x => x.ixMaterial).FirstOrDefault(); var slottedLocations = _inventorylocationsslottingService.IndexDb().Where(x => x.ixMaterial == ixMaterialDominant && x.InventoryLocations.ixFacility == ixFacility).ToList(); if (slottedLocations.Count() > 0) //We have slotted locations { var locationsslotted = _inventorylocationsService.IndexDbPost().Where(x => slottedLocations.Select(y => y.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); //var slottedlocationsPost = locationsslotted.Select(l => _inventorylocationsService.GetPost(l.ixInventoryLocation)).ToList(); putAwaySuggestions = locationsslotted.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) { //We now apply the defaults - we look for the location with the most inventory var inventoryInSlottedLocations = _inventoryunitsService.IndexDbPost().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && putAwaySuggestions.Select(s => s.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); if (inventoryInSlottedLocations.Count() > 0) { var ixInventoryLocationSuggestion = inventoryInSlottedLocations.GroupBy(x => x.ixInventoryLocation) .Select(y => new { ixInventoryLocation = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ) .OrderByDescending(z => z.nTotalBaseUnits) .Select(s => s.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } else { return(putAwaySuggestions.Select(x => x.ixInventoryLocation).FirstOrDefault()); } } //else //Now we look for locations in the slotted locations bays closest to the slotted location (To be implemented) //{ //} } //Now we attempt to consolidate the inventory var existingInventoryLocations = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.ixMaterial == ixMaterialDominant && allowedLocationFunctions.Contains(x.InventoryLocations.ixLocationFunction)).ToList(); var existingInventoryLocationsPost = existingInventoryLocations.Select(l => _inventorylocationsService.GetPost(l.ixInventoryLocation)).Distinct().ToList(); putAwaySuggestions = existingInventoryLocationsPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have locations with existing inventory that fits. { //We now apply the defaults - we look for the location with the most inventory var existinginventoryInLocations = _inventoryunitsService.IndexDb().Where(x => putAwaySuggestions.Select(s => s.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); if (existinginventoryInLocations.Count() > 0) { var ixInventoryLocationSuggestion = existinginventoryInLocations.GroupBy(x => x.ixInventoryLocation) .Select(y => new { ixInventoryLocation = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ) .OrderByDescending(z => z.nTotalBaseUnits) .Select(s => s.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } else { return(putAwaySuggestions.Select(x => x.ixInventoryLocation).FirstOrDefault()); } } //Now we look for empty locations by function (LD and RV) and proximity to the user (To be refined for performance) var userLocation = _inventorylocationsService.GetPost(ixInventoryLocationUser); var ldLocactionsInFacility = _inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "LD").ToList(); var ldLocactionsInFacilityWithInventory = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.InventoryLocations.LocationFunctions.sLocationFunctionCode == "LD").ToList(); var ldLocactionsInFacilityEmpty = ldLocactionsInFacility.Select(x => x.ixInventoryLocation).Except(ldLocactionsInFacilityWithInventory.Select(x => x.ixInventoryLocation)).ToList(); var ldLocactionsInFacilityEmptyPost = ldLocactionsInFacilityEmpty.Select(l => _inventorylocationsService.GetPost(l)).Distinct().ToList(); putAwaySuggestions = ldLocactionsInFacilityEmptyPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have LD empty locations that fits. { var ixInventoryLocationSuggestion = putAwaySuggestions.Select(x => new { x.ixInventoryLocation, nProximity = Math.Abs(x.nSequence - inventoryLocationUserPost.nSequence) }).OrderBy(x => x.nProximity).Select(x => x.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } var rvLocactionsInFacility = _inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "RV").ToList(); var rvLocactionsInFacilityWithInventory = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.InventoryLocations.LocationFunctions.sLocationFunctionCode == "RV").ToList(); var rvLocactionsInFacilityEmpty = rvLocactionsInFacility.Select(x => x.ixInventoryLocation).Except(ldLocactionsInFacilityWithInventory.Select(x => x.ixInventoryLocation)).ToList(); var rvLocactionsInFacilityEmptyPost = rvLocactionsInFacilityEmpty.Select(l => _inventorylocationsService.GetPost(l)).Distinct().ToList(); putAwaySuggestions = rvLocactionsInFacilityEmptyPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have RV empty locations that fits. { var ixInventoryLocationSuggestion = putAwaySuggestions.Select(x => new { x.ixInventoryLocation, nProximity = Math.Abs(x.nSequence - inventoryLocationUserPost.nSequence) }).OrderBy(x => x.nProximity).Select(x => x.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } return(0); }
public Tuple <Int64, double> getPickSuggestion(Int64 ixPickBatch, BotUserData _botUserData) { Tuple <Int64, double> pickSuggestion = new Tuple <long, double>(0, 0); var pickBatch = _pickbatchesService.Get(ixPickBatch); if (pickBatch.PickBatchTypes.sPickBatchType.Contains("Discrete order picking")) //Order based picking { //We pick order by order var ordersInBatch = _outboundordersService.IndexDb().Where(x => x.ixPickBatch == ixPickBatch).OrderBy(x => x.ixOutboundOrder).Select(x => new { ixFacility = x.ixFacility, ixCompany = x.ixCompany, ixOutboundOrder = x.ixOutboundOrder }).ToList(); var orderLinesInBatch = _outboundorderlinesService.IndexDb().Select(x => new { ixOutboundOrder = x.ixOutboundOrder, ixOutboundOrderLine = x.ixOutboundOrderLine, ixMaterial = x.ixMaterial }) //.Where(x => ordersInBatch.Contains(x.ixOutboundOrder)).OrderBy(x => x.ixOutboundOrder).ThenBy(x => x.ixOutboundOrderLine) .Join(ordersInBatch, ol => ol.ixOutboundOrder, ob => ob.ixOutboundOrder, (ol, ob) => new { Ob = ob, Ol = ol }) .Select(lib => new { ixFacility = lib.Ob.ixFacility, ixCompany = lib.Ob.ixCompany, ixOutboundOrder = lib.Ol.ixOutboundOrder, ixOutboundOrderLine = lib.Ol.ixOutboundOrderLine, ixMaterial = lib.Ol.ixMaterial }) .ToList(); ordersInBatch.ForEach(o => { var orderLinesInOrder = orderLinesInBatch.Where(x => x.ixOutboundOrder == o.ixOutboundOrder).Select(x => x.ixOutboundOrderLine).ToList(); var openLinesToPick = _outboundorderlinesinventoryallocationService.IndexDb() .Where(x => orderLinesInOrder.Contains(x.ixOutboundOrderLine) && x.nBaseUnitQuantityAllocated > x.nBaseUnitQuantityPicked) .Join(orderLinesInBatch, op => op.ixOutboundOrderLine, ol => ol.ixOutboundOrderLine, (op, ol) => new { Op = op, Ol = ol }) .Select(x => new { ixOutboundOrder = x.Ol.ixOutboundOrder, ixOutboundOrderLine = x.Ol.ixOutboundOrderLine, ixMaterial = x.Ol.ixMaterial, nBaseUnitQuantityOpen = x.Op.nBaseUnitQuantityAllocated - x.Op.nBaseUnitQuantityPicked }).Distinct().ToList(); var inventoryUnitCandidates = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == o.ixFacility && x.ixCompany == o.ixCompany && _commonLookUps.getPickAndPlaceLocationFunctions().Select(lf => lf.ixLocationFunction).Contains(x.InventoryLocations.ixLocationFunction) && _commonLookUps.getAvailableInventoryStates().Select(s => s.ixInventoryState).Contains(x.ixInventoryState) ) .Join(openLinesToPick, iu => iu.ixMaterial, ol => ol.ixMaterial, (iu, ol) => new { Iu = iu, Ol = ol }) .Where(x => (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) >= 0) .ToList(); pickSuggestion = inventoryUnitCandidates.Select(x => new { ixInventoryUnit = x.Iu.ixInventoryUnit, bQtyMatch = x.Ol.nBaseUnitQuantityOpen == x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued ? true : false, bIsSingleIuHU = _inventoryunitsService.IndexDbPost().Where(iu => iu.ixHandlingUnit == x.Iu.ixHandlingUnit).Count() == 1 ? true : false, nLocationTypePreference = ( x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "FP").Select(f => f.ixLocationFunction).FirstOrDefault() ? 1 : x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "LD").Select(f => f.ixLocationFunction).FirstOrDefault() ? 2 : x.Iu.InventoryLocations.ixLocationFunction == _commonLookUps.getLocationFunctions().Where(f => f.sLocationFunctionCode == "LD").Select(f => f.ixLocationFunction).FirstOrDefault() ? 3 : 1000 ), nDistance = Math.Abs(x.Iu.InventoryLocations.nSequence - _inventorylocationsService.GetPost(_botUserData.ixInventoryLocation).nSequence), nPickQtyDiff = (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) - x.Ol.nBaseUnitQuantityOpen, nPickQty = (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) - x.Ol.nBaseUnitQuantityOpen >= 0 ? x.Ol.nBaseUnitQuantityOpen : (x.Iu.nBaseUnitQuantity - x.Iu.nBaseUnitQuantityQueued) } ) .OrderByDescending(i => i.bQtyMatch) .ThenByDescending(i => i.bIsSingleIuHU) .ThenBy(i => i.nLocationTypePreference) .ThenByDescending(i => i.nPickQtyDiff) .ThenBy(i => i.nDistance) .Select(ps => Tuple.Create(ps.ixInventoryUnit, ps.nPickQty)).FirstOrDefault(); if (pickSuggestion.Item1 > 0 && pickSuggestion.Item2 > 0) { return; } } ); } else { //We implement this later } return(pickSuggestion); }