public ActionResult Create([Bind("ixInventoryUnit,sInventoryUnit,ixFacility,ixCompany,ixMaterial,ixInventoryState,ixHandlingUnit,ixInventoryLocation,nBaseUnitQuantity,sSerialNumber,sBatchNumber,dtExpireAt,ixStatus")] InventoryUnitsPost inventoryunits) { //Custom Code Start | Added Code Block var ixInventoryUnitTransactionContext = _inventoryunittransactioncontextsService.Index().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault(); //Custom Code End if (ModelState.IsValid) { inventoryunits.UserName = User.Identity.Name; //Custom Code Start | Replaced Code Block //Replaced Code Block Start //_inventoryunitsService.Create(inventoryunits); //Replaced Code Block End _inventoryunitsService.Create(inventoryunits, ixInventoryUnitTransactionContext); //Custom Code End return(RedirectToAction("Index")); } ViewBag.ixCompany = new SelectList(_inventoryunitsService.selectCompanies().Select(x => new { x.ixCompany, x.sCompany }), "ixCompany", "sCompany"); ViewBag.ixFacility = new SelectList(_inventoryunitsService.selectFacilities().Select(x => new { x.ixFacility, x.sFacility }), "ixFacility", "sFacility"); ViewBag.ixHandlingUnit = new SelectList(_inventoryunitsService.selectHandlingUnits().Select(x => new { x.ixHandlingUnit, x.sHandlingUnit }), "ixHandlingUnit", "sHandlingUnit"); ViewBag.ixInventoryLocation = new SelectList(_inventoryunitsService.selectInventoryLocations().Select(x => new { x.ixInventoryLocation, x.sInventoryLocation }), "ixInventoryLocation", "sInventoryLocation"); ViewBag.ixInventoryState = new SelectList(_inventoryunitsService.selectInventoryStates().Select(x => new { x.ixInventoryState, x.sInventoryState }), "ixInventoryState", "sInventoryState"); ViewBag.ixMaterial = new SelectList(_inventoryunitsService.selectMaterials().Select(x => new { x.ixMaterial, x.sMaterial }), "ixMaterial", "sMaterial"); ViewBag.ixStatus = new SelectList(_inventoryunitsService.selectStatuses().Select(x => new { x.ixStatus, x.sStatus }), "ixStatus", "sStatus"); return(View(inventoryunits)); }
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)); }