public ActionResult Edit([Bind("ixOutboundOrderLineInventoryAllocation,sOutboundOrderLineInventoryAllocation,ixOutboundOrderLine,nBaseUnitQuantityAllocated,nBaseUnitQuantityPicked,ixStatus")] OutboundOrderLinesInventoryAllocationPost outboundorderlinesinventoryallocation) { if (ModelState.IsValid) { outboundorderlinesinventoryallocation.UserName = User.Identity.Name; _outboundorderlinesinventoryallocationService.Edit(outboundorderlinesinventoryallocation); return(RedirectToAction("Index")); } ViewBag.ixOutboundOrderLine = new SelectList(_outboundorderlinesinventoryallocationService.selectOutboundOrderLines().Select(x => new { x.ixOutboundOrderLine, x.sOutboundOrderLine }), "ixOutboundOrderLine", "sOutboundOrderLine", outboundorderlinesinventoryallocation.ixOutboundOrderLine); ViewBag.ixStatus = new SelectList(_outboundorderlinesinventoryallocationService.selectStatuses().Select(x => new { x.ixStatus, x.sStatus }), "ixStatus", "sStatus", outboundorderlinesinventoryallocation.ixStatus); return(View(outboundorderlinesinventoryallocation)); }
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 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); } ); }