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); }
private async Task <DialogTurnResult> InventoryDropLocationPrompt( WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var sPutAwayHandlingUnit = (string)step.Result; ((PutAwayHandlingUnitsPost)step.Values[DialogKey]).sPutAwayHandlingUnit = sPutAwayHandlingUnit; //Custom Code Start | Added Code Block var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(step.Context, () => _botUserData); var ixHandlingUnit = _handlingunitsService.IndexDb().Where(x => x.sHandlingUnit.Trim().ToLower() == sPutAwayHandlingUnit).Select(x => x.ixHandlingUnit).FirstOrDefault(); ((PutAwayHandlingUnitsPost)step.Values[DialogKey]).ixHandlingUnit = ixHandlingUnit; //We now create and execute the move queue for the pickup MoveQueuesPost moveQueuePost = new MoveQueuesPost(); moveQueuePost.ixMoveQueueType = _movequeuetypesService.IndexDb().Where(x => x.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); moveQueuePost.ixMoveQueueContext = _movequeuecontextsService.IndexDb().Where(x => x.sMoveQueueContext == "Putaway").Select(x => x.ixMoveQueueContext).FirstOrDefault(); moveQueuePost.ixSourceInventoryLocation = _inventoryunitsService.IndexDbPost().Where(x => x.ixHandlingUnit == ixHandlingUnit).Select(x => x.ixInventoryLocation).FirstOrDefault(); moveQueuePost.ixTargetInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePost.ixSourceHandlingUnit = ixHandlingUnit; moveQueuePost.ixTargetHandlingUnit = ixHandlingUnit; moveQueuePost.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePost.nBaseUnitQuantity = 0; moveQueuePost.dtStartedAt = DateTime.Now; moveQueuePost.ixStatus = _statusesService.IndexDb().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 = _statusesService.IndexDb().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePickUp.UserName = moveQueuePost.UserName; await _movequeuesService.Edit(moveQueuePickUp); var ixInventoryLocationSuggestion = _putAway.getPutAwaySuggestion(ixHandlingUnit, currentBotUserData.ixCompany, currentBotUserData.ixFacility, currentBotUserData.ixInventoryLocation); string sPutAwaySuggestion = ""; if (_inventorylocationsService.IndexDb().Where(x => x.ixInventoryLocation == ixInventoryLocationSuggestion).Any()) { sPutAwaySuggestion = _inventorylocationsService.IndexDb().Where(x => x.ixInventoryLocation == ixInventoryLocationSuggestion).Select(x => x.sInventoryLocation).FirstOrDefault(); //We now create the move queue for the drop MoveQueuesPost moveQueuePostDrop = new MoveQueuesPost(); moveQueuePostDrop.ixMoveQueueType = moveQueuePost.ixMoveQueueType; moveQueuePostDrop.ixMoveQueueContext = moveQueuePost.ixMoveQueueContext; moveQueuePostDrop.ixSourceInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePostDrop.ixTargetInventoryLocation = ixInventoryLocationSuggestion; moveQueuePostDrop.ixSourceHandlingUnit = ixHandlingUnit; moveQueuePostDrop.ixTargetHandlingUnit = ixHandlingUnit; moveQueuePostDrop.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePostDrop.nBaseUnitQuantity = 0; moveQueuePostDrop.dtStartedAt = DateTime.Now; moveQueuePostDrop.ixStatus = _statusesService.IndexDb().Where(x => x.sStatus == "Active").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePostDrop.UserName = step.Context.Activity.Conversation.Id; var ixMoveQueueDrop = await _movequeuesService.Create(moveQueuePostDrop); step.Values[MoveQueuePostDropKey] = moveQueuePostDrop; } else { sPutAwaySuggestion = "No Suggestion"; } step.Values[PutAwaySuggestionKey] = sPutAwaySuggestion; currentBotUserData.sPutAwaySuggestion = sPutAwaySuggestion; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(step.Context, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(step.Context); //Custom Code End return(await step.PromptAsync( InventoryDropLocationPromptId, new PromptOptions { Prompt = MessageFactory.Text($"The suggested drop location is {sPutAwaySuggestion}.{Environment.NewLine} Please enter/scan the Inventory Drop Location."), RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), }, cancellationToken)); }
public Task Edit(MoveQueuesPost movequeuesPost) { // Additional validations // Pre-process // Process this._movequeuesRepository.RegisterEdit(movequeuesPost); try { this._movequeuesRepository.Commit(); } catch (Exception ex) { this._movequeuesRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block 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 ) { _inventoryunitsService.IndexDbPost().Where(x => x.ixHandlingUnit == movequeuesPost.ixTargetHandlingUnit).ToList().ForEach(iu => { iu.ixInventoryLocation = movequeuesPost.ixTargetInventoryLocation ?? 0; iu.UserName = movequeuesPost.UserName; _inventoryunitsService.Edit(iu, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Move Queue Execution").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); } ); 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, false); 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 == "Putaway").Select(x => x.ixMoveQueueContext).FirstOrDefault() && movequeuesPost.ixSourceInventoryLocation != movequeuesPost.ixTargetInventoryLocation ) { var targetInventoryUnit = _inventoryunitsService.GetPost(movequeuesPost.ixTargetInventoryUnit ?? 0); targetInventoryUnit.ixInventoryLocation = movequeuesPost.ixTargetInventoryLocation ?? 0; targetInventoryUnit.UserName = movequeuesPost.UserName; _inventoryunitsService.Edit(targetInventoryUnit, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Move Queue Execution").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); var targetInventoryLocation = _inventorylocationsService.GetPost(movequeuesPost.ixTargetInventoryLocation ?? 0); targetInventoryLocation.nQueuedUtilisationPercent = _volumeAndWeight.getNewLocationQueuedUtilisationPercent(targetInventoryUnit, targetInventoryLocation, false); targetInventoryLocation.UserName = movequeuesPost.UserName; _inventorylocationsService.Edit(targetInventoryLocation); } //Custom Code End return(Task.CompletedTask); }
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); }
public void shipInventoryForManifest(Int64 ixOutboundCarrierManifest, string UserName) { var ixStatusActive = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); var ixStatusInactive = _commonLookUps.getStatuses().Where(s => s.sStatus == "Inactive").Select(s => s.ixStatus).FirstOrDefault(); var ixStatusComplete = _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault(); var ixInventoryUnitTransactionContext = _commonLookUps.getInventoryUnitTransactionContext().Where(c => c.sInventoryUnitTransactionContext == "Handling Units Shipping").Select(c => c.ixInventoryUnitTransactionContext).FirstOrDefault(); var outboundshipments = _outboundshipmentsService.IndexDb().Where(sh => sh.ixOutboundCarrierManifest == ixOutboundCarrierManifest && sh.ixStatus == ixStatusActive) .Select(sh => sh.ixOutboundShipment).ToList(); var outboundorders = _outboundordersRepository.IndexDb().Where(o => o.ixStatus == ixStatusActive) .Join(outboundshipments, o => o.ixOutboundShipment, sh => sh, (o, sh) => new { O = o, Sh = sh }) .Select(x => x.O.ixOutboundOrder).ToList(); var outboundorderlines = _outboundorderlinesService.IndexDb() .Join(outboundorders, ol => ol.ixOutboundOrder, o => o, (ol, o) => new { Ol = ol, O = o }) .Select(x => x.Ol.ixOutboundOrderLine).ToList(); var outboundorderlinesinventoryallocation = _outboundorderlinesinventoryallocationService.IndexDb() .Join(outboundorderlines, ola => ola.ixOutboundOrderLine, ol => ol, (ola, ol) => new { Ola = ola, Ol = ol }) .Where(x => x.Ola.nBaseUnitQuantityPicked == x.Ola.nBaseUnitQuantityAllocated).Select(x => x.Ola.ixOutboundOrderLineInventoryAllocation).ToList(); var outboundorderlinepacking = _outboundorderlinepackingService.IndexDb().Where(x => x.ixStatus == ixStatusActive) .Join(outboundorderlines, p => p.ixOutboundOrderLine, ol => ol, (p, ol) => new { P = p, Ol = ol }) .Select(x => x.P.ixOutboundOrderLinePack).ToList(); var outboundorderlinesshipped = _outboundorderlinepackingService.IndexDb().Where(x => x.ixStatus == ixStatusActive) .Join(outboundorderlines, p => p.ixOutboundOrderLine, ol => ol, (p, ol) => new { P = p, Ol = ol }) .Select(x => new { ixOutboundOrderLine = x.P.ixOutboundOrderLine, nBaseUnitQuantityPacked = x.P.nBaseUnitQuantityPacked }).ToList(); var handlingunitsToShip = _outboundorderlinepackingService.IndexDb().Where(x => x.ixStatus == ixStatusActive) .Join(outboundorderlines, p => p.ixOutboundOrderLine, ol => ol, (p, ol) => new { P = p, Ol = ol }) .Select(x => x.P.ixHandlingUnit).Distinct().ToList(); var inventoryunitsToShip = _inventoryunitsService.IndexDbPost().Where(x => x.nBaseUnitQuantity > 0) .Join(handlingunitsToShip, iu => iu.ixHandlingUnit, hu => hu, (iu, hu) => new { Iu = iu, Hu = hu }) .Select(x => x.Iu.ixInventoryUnit).Distinct().ToList(); inventoryunitsToShip.ForEach(x => { var inventoryunit = _inventoryunitsService.GetPost(x); inventoryunit.nBaseUnitQuantity = 0; inventoryunit.ixStatus = ixStatusInactive; inventoryunit.UserName = UserName; _inventoryunitsService.Edit(inventoryunit, ixInventoryUnitTransactionContext); } ); handlingunitsToShip.ForEach(x => { var handlingunit = _handlingunitsService.GetPost(x); handlingunit.ixStatus = ixStatusInactive; handlingunit.UserName = UserName; _handlingunitsService.Edit(handlingunit); } ); //Now we set the statuses to complete var outboundcarriermanifest = _outboundcarriermanifestsService.GetPost(ixOutboundCarrierManifest); outboundcarriermanifest.ixStatus = ixStatusComplete; outboundcarriermanifest.UserName = UserName; _outboundcarriermanifestsService.Edit(outboundcarriermanifest); outboundshipments.ForEach(x => { var outboundshipment = _outboundshipmentsService.GetPost(x); outboundshipment.ixStatus = ixStatusComplete; outboundshipment.UserName = UserName; _outboundshipmentsService.Edit(outboundshipment); } ); outboundorders.ForEach(x => { var outboundorder = _outboundordersRepository.GetPost(x); outboundorder.ixStatus = ixStatusComplete; outboundorder.UserName = UserName; _outboundordersRepository.RegisterEdit(outboundorder); _outboundordersRepository.Commit(); } ); outboundorderlines .Join(outboundorderlinesshipped, ol => ol, ols => ols.ixOutboundOrderLine, (ol, ols) => new { OL = ol, Ols = ols }) .Select(o => new { ixOutboundOrderLine = o.Ols.ixOutboundOrderLine, nBaseUnitQuantityPacked = o.Ols.nBaseUnitQuantityPacked }).ToList() .ForEach(x => { var outboundorderline = _outboundorderlinesService.GetPost(x.ixOutboundOrderLine); outboundorderline.nBaseUnitQuantityShipped += x.nBaseUnitQuantityPacked; outboundorderline.ixStatus = ixStatusComplete; outboundorderline.UserName = UserName; _outboundorderlinesService.Edit(outboundorderline); } ); outboundorderlinesinventoryallocation.ForEach(x => { var outboundorderlineinventoryallocation = _outboundorderlinesinventoryallocationService.GetPost(x); outboundorderlineinventoryallocation.ixStatus = ixStatusComplete; outboundorderlineinventoryallocation.UserName = UserName; _outboundorderlinesinventoryallocationService.Edit(outboundorderlineinventoryallocation); } ); outboundorderlinepacking.ForEach(x => { var outboundorderlinepack = _outboundorderlinepackingService.GetPost(x); outboundorderlinepack.ixStatus = ixStatusComplete; outboundorderlinepack.UserName = UserName; _outboundorderlinepackingService.Edit(outboundorderlinepack); } ); }