コード例 #1
0
        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));
        }
コード例 #2
0
        //Custom Code Start | Replaced Code Block
        //Replaced Code Block Start
        //public Task<Int64> Create(InventoryUnitsPost inventoryunitsPost)
        //Replaced Code Block End
        public Task <Int64> Create(InventoryUnitsPost inventoryunitsPost, Int64 ixInventoryUnitTransactionContext)
        {
            //Custom Code End

            // Additional validations

            // Pre-process
            //Custom Code Start | Added Code Block
            _inventorylocations = _inventorylocationsService.GetPost(inventoryunitsPost.ixInventoryLocation);
            var newUtilizationPercent = _volumeAndWeight.getNewLocationUtilisationPercent(inventoryunitsPost, _inventorylocations);

            _inventorylocations.nUtilisationPercent = newUtilizationPercent;
            _inventorylocations.UserName            = inventoryunitsPost.UserName;
            _inventorylocationsService.Edit(_inventorylocations);
            //Custom Code End

            // Process
            this._inventoryunitsRepository.RegisterCreate(inventoryunitsPost);
            try
            {
                this._inventoryunitsRepository.Commit();
            }
            catch (Exception ex)
            {
                this._inventoryunitsRepository.Rollback();
                // Log exception
                throw;
            }

            // Post-process
            //Custom Code Start | Added Code Block

            //If bTrackUtilisation is true we update the location utilisation
            //Check if orders need to be batched (which means allocated)

            _inventoryunittransactions.ixInventoryUnit = inventoryunitsPost.ixInventoryUnit;
            _inventoryunittransactions.ixInventoryUnitTransactionContext = ixInventoryUnitTransactionContext;
            _inventoryunittransactions.ixFacilityAfter          = inventoryunitsPost.ixFacility;
            _inventoryunittransactions.ixCompanyAfter           = inventoryunitsPost.ixCompany;
            _inventoryunittransactions.ixMaterialAfter          = inventoryunitsPost.ixMaterial;
            _inventoryunittransactions.ixInventoryStateAfter    = inventoryunitsPost.ixInventoryState;
            _inventoryunittransactions.ixHandlingUnitAfter      = inventoryunitsPost.ixHandlingUnit;
            _inventoryunittransactions.ixInventoryLocationAfter = inventoryunitsPost.ixInventoryLocation;
            _inventoryunittransactions.nBaseUnitQuantityAfter   = inventoryunitsPost.nBaseUnitQuantity;
            _inventoryunittransactions.sSerialNumberAfter       = inventoryunitsPost.sSerialNumber;
            _inventoryunittransactions.sBatchNumberAfter        = inventoryunitsPost.sBatchNumber;
            _inventoryunittransactions.dtExpireAtAfter          = inventoryunitsPost.dtExpireAt;
            _inventoryunittransactions.ixStatusAfter            = inventoryunitsPost.ixStatus;
            _inventoryunittransactions.UserName = inventoryunitsPost.UserName;
            this._inventoryunittransactionsService.Create(_inventoryunittransactions);

            //Custom Code End

            return(Task.FromResult(inventoryunitsPost.ixInventoryUnit));
        }
コード例 #3
0
        public ActionResult Edit(long id)
        {
            InventoryLocationsPost inventorylocations = _inventorylocationsService.GetPost(id);

            if (inventorylocations == null)
            {
                return(NotFound());
            }
            ViewBag.ixCompany               = new SelectList(_inventorylocationsService.selectCompaniesNullable().Select(x => new { ixCompany = x.Key, sCompany = x.Value }), "ixCompany", "sCompany", inventorylocations.ixCompany);
            ViewBag.ixFacility              = new SelectList(_inventorylocationsService.selectFacilities().Select(x => new { x.ixFacility, x.sFacility }), "ixFacility", "sFacility", inventorylocations.ixFacility);
            ViewBag.ixFacilityAisleFace     = new SelectList(_inventorylocationsService.selectFacilityAisleFaces().Select(x => new { x.ixFacilityAisleFace, x.sFacilityAisleFace }), "ixFacilityAisleFace", "sFacilityAisleFace", inventorylocations.ixFacilityAisleFace);
            ViewBag.ixFacilityFloor         = new SelectList(_inventorylocationsService.selectFacilityFloors().Select(x => new { x.ixFacilityFloor, x.sFacilityFloor }), "ixFacilityFloor", "sFacilityFloor", inventorylocations.ixFacilityFloor);
            ViewBag.ixFacilityWorkArea      = new SelectList(_inventorylocationsService.selectFacilityWorkAreas().Select(x => new { x.ixFacilityWorkArea, x.sFacilityWorkArea }), "ixFacilityWorkArea", "sFacilityWorkArea", inventorylocations.ixFacilityWorkArea);
            ViewBag.ixFacilityZone          = new SelectList(_inventorylocationsService.selectFacilityZones().Select(x => new { x.ixFacilityZone, x.sFacilityZone }), "ixFacilityZone", "sFacilityZone", inventorylocations.ixFacilityZone);
            ViewBag.ixInventoryLocationSize = new SelectList(_inventorylocationsService.selectInventoryLocationSizesNullable().Select(x => new { ixInventoryLocationSize = x.Key, sInventoryLocationSize = x.Value }), "ixInventoryLocationSize", "sInventoryLocationSize", inventorylocations.ixInventoryLocationSize);
            ViewBag.ixLocationFunction      = new SelectList(_inventorylocationsService.selectLocationFunctions().Select(x => new { x.ixLocationFunction, x.sLocationFunction }), "ixLocationFunction", "sLocationFunction", inventorylocations.ixLocationFunction);
            ViewBag.ixXOffsetUnit           = new SelectList(_inventorylocationsService.selectUnitsOfMeasurementNullable().Select(x => new { ixUnitOfMeasurement = x.Key, sUnitOfMeasurement = x.Value }), "ixUnitOfMeasurement", "sUnitOfMeasurement", inventorylocations.ixXOffsetUnit);
            ViewBag.ixYOffsetUnit           = new SelectList(_inventorylocationsService.selectUnitsOfMeasurementNullable().Select(x => new { ixUnitOfMeasurement = x.Key, sUnitOfMeasurement = x.Value }), "ixUnitOfMeasurement", "sUnitOfMeasurement", inventorylocations.ixYOffsetUnit);
            ViewBag.ixZOffsetUnit           = new SelectList(_inventorylocationsService.selectUnitsOfMeasurementNullable().Select(x => new { ixUnitOfMeasurement = x.Key, sUnitOfMeasurement = x.Value }), "ixUnitOfMeasurement", "sUnitOfMeasurement", inventorylocations.ixZOffsetUnit);

            return(View(inventorylocations));
        }
コード例 #4
0
        private async Task <DialogTurnResult> DropInventoryUnitPrompt(
            WaterfallStepContext step,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            step.Values[DialogKey] = new DropInventoryUnitsPost();

            //Custom Code Start | Added Code Block
            var promptString = "";
            // We start by getting the suggested drop location
            var ixPickupInventoryLocation = _shipping.getDropLocationForPickBatch(((PickBatchPickingPost)step.Options).ixPickBatch);

            if (ixPickupInventoryLocation > 0)
            {
                promptString = $"The suggested drop location is {_inventorylocationsService.GetPost(ixPickupInventoryLocation).sInventoryLocation}.{Environment.NewLine} Please confirm the drop location.";
            }
            else
            {
                promptString = $"Please confirm the drop location.";
            }
            //Custom Code End


            return(await step.PromptAsync(
                       DropInventoryUnitPromptId,
                       new PromptOptions
            {
                //Custom Code Start | Replaced Code Block
                //Replaced Code Block Start
                //Prompt = MessageFactory.Text($"Please enter a DropInventoryUnit:"),
                //Replaced Code Block End
                Prompt = MessageFactory.Text(promptString),
                //Custom Code End
                RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."),
            },
                       cancellationToken));
        }
コード例 #5
0
        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);
        }
コード例 #6
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);
        }
コード例 #7
0
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            // use state accessor to extract the didBotWelcomeUser flag
            var didBotWelcomeUser = await _botSpielUserStateAccessors.DidBotWelcomeUser.GetAsync(turnContext, () => false);

            var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(turnContext, () => _botUserData);

            string        conCat          = "";
            List <string> existInEntities = new List <string>();
            bool          DeleteOK        = true;

            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Establish dialog state from the conversation state.
                DialogContext dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken);

                //Custom Code Start | Added Code Block
                if (turnContext.Activity.Text.ToLowerInvariant() == "cancel")
                {
                    await dc.CancelAllDialogsAsync(cancellationToken);
                }
                //Custom Code End

                // Continue any current dialog.
                DialogTurnResult dialogTurnResult = await dc.ContinueDialogAsync();

                // Process the result of any complete dialog.
                if (dialogTurnResult.Status is DialogTurnStatus.Complete)
                {
                    switch (dialogTurnResult.Result)
                    {
                    case BotUserEntityContext botUserEntityContext:
                        if (botUserEntityContext.module != "Choose an area")
                        {
                            // Store the results of the root dialog.
                            currentBotUserData.botUserEntityContext = botUserEntityContext;
                            await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                            await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                            await dc.PromptAsync(ConfirmPromptId, new PromptOptions { Prompt = MessageFactory.Text($"Please confirm that you want to {botUserEntityContext.entityIntent} {botUserEntityContext.entity}. Is that correct?") }, cancellationToken);
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("OK, Let's choose a different area.", cancellationToken : cancellationToken);

                            await dc.BeginDialogAsync(RootDialogId, null, cancellationToken);
                        }
                        break;

                    case bool botYesNo:
                        if (botYesNo)
                        {
                            switch (currentBotUserData.botUserEntityContext.entity)
                            {
                            case "PickBatchPicking":
                                if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                                {
                                    //Custom Code Start | Replaced Code Block
                                    //Replaced Code Block Start
                                    //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, null, cancellationToken);
                                    //Replaced Code Block End
                                    await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken);

                                    //Custom Code End
                                }
                                break;

                            case "PutAwayHandlingUnits":
                                if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                                {
                                    await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken);
                                }
                                break;

                            case "SetUpExecutionParameters":
                                if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                                {
                                    await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken);
                                }
                                break;

                            case "DropInventoryUnits":
                                if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                                {
                                    await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, null, cancellationToken);
                                }
                                break;

                            default:
                                // We shouldn't get here.
                                break;
                            }
                        }
                        else
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Text("OK, let's try again."), cancellationToken);

                            await dc.BeginDialogAsync(RootDialogId, null, cancellationToken);
                        }
                        break;

                    case GetPickBatchesPost getpickbatchesPost:
                        if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                        {
                            //Custom Code Start | Removed Block
                            //ixGetPickBatch = await _getpickbatchesService.Create(getpickbatchesPost);
                            //await turnContext.SendActivityAsync(MessageFactory.Text($"The GetPickBatch {ixGetPickBatch} was created"), cancellationToken);
                            //currentBotUserData.ixGetPickBatch = ixGetPickBatch;
                            //Custom Code End

                            await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                            await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                            //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken);

                            //Custom Code Start | Added Code Block
                            //We can now set the pick batch status to started
                            var pickbatch = _pickbatchesService.GetPost(_pickbatchesService.IndexDb().Where(x => x.sPickBatch == getpickbatchesPost.sGetPickBatch).Select(x => x.ixPickBatch).FirstOrDefault());
                            pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Started").Select(x => x.ixStatus).FirstOrDefault();
                            pickbatch.UserName = dc.Context.Activity.Conversation.Id;
                            await _pickbatchesService.Edit(pickbatch);

                            _pickbatchpickingPost.sPickBatchPick = getpickbatchesPost.sGetPickBatch;
                            await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, _pickbatchpickingPost, cancellationToken);

                            //Custom Code End
                        }
                        break;

                    case PickBatchPickingPost pickbatchpickingPost:
                        if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                        {
                            ixPickBatchPick = await _pickbatchpickingService.Create(pickbatchpickingPost);

                            //Custom Code Start | Removed Block
                            //await turnContext.SendActivityAsync(MessageFactory.Text($"The PickBatchPick {ixPickBatchPick} was created"), cancellationToken);
                            //Custom Code End
                            //Custom Code Start | Added Code Block
                            //We check if the batch is complete
                            if (!_picking.isPickBatchComplete(pickbatchpickingPost.ixPickBatch))
                            {
                                currentBotUserData.ixPickBatchPick = ixPickBatchPick;
                                await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                                await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                                await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, pickbatchpickingPost, cancellationToken);
                            }
                            else
                            {
                                currentBotUserData.ixPickBatchPick = 0;
                                await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                                await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                                //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken);
                                //We can now set the pick batch status to complete
                                var pickbatch = _pickbatchesService.GetPost(pickbatchpickingPost.ixPickBatch);
                                pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault();
                                pickbatch.UserName = dc.Context.Activity.Conversation.Id;
                                await _pickbatchesService.Edit(pickbatch);

                                //We begin the drop cycle
                                await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, pickbatchpickingPost, cancellationToken);
                            }
                            //Custom Code End
                        }
                        break;

                    case PutAwayHandlingUnitsPost putawayhandlingunitsPost:
                        if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                        {
                            ixPutAwayHandlingUnit = await _putawayhandlingunitsService.Create(putawayhandlingunitsPost);

                            //Custom Code Start | Removed Block
                            //await turnContext.SendActivityAsync(MessageFactory.Text($"The PutAwayHandlingUnit {ixPutAwayHandlingUnit} was created"), cancellationToken);
                            //Custom Code End
                            currentBotUserData.ixPutAwayHandlingUnit = ixPutAwayHandlingUnit;
                            await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                            await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                            //Custom Code Start | Replaced Code Block
                            //Replaced Code Block Start
                            //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken);
                            //Replaced Code Block End
                            await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken);

                            //Custom Code End
                        }
                        break;

                    case SetUpExecutionParametersPost setupexecutionparametersPost:
                        if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                        {
                            //Custom Code Start | Removed Block
                            //ixSetUpExecutionParameter = await _setupexecutionparametersService.Create(setupexecutionparametersPost);
                            //await turnContext.SendActivityAsync(MessageFactory.Text($"The SetUpExecutionParameter {ixSetUpExecutionParameter} was created"), cancellationToken);
                            //currentBotUserData.ixSetUpExecutionParameter = ixSetUpExecutionParameter;
                            //Custom Code End
                            //Custom Code Start | Added Code Block
                            currentBotUserData.ixFacility         = setupexecutionparametersPost.ixFacility;
                            currentBotUserData.ixCompany          = setupexecutionparametersPost.ixCompany;
                            currentBotUserData.ixFacilityWorkArea = setupexecutionparametersPost.ixFacilityWorkArea;
                            //We check if the user location exists - if not we create it
                            if (_userManager.Users.Where(x => x.UserName == dc.Context.Activity.Conversation.Id).Any())
                            {
                                if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Any())
                                {
                                    InventoryLocationsPost inventoryLocationsPost = new InventoryLocationsPost();
                                    inventoryLocationsPost.sInventoryLocation  = dc.Context.Activity.Conversation.Id.ToLower().Trim();
                                    inventoryLocationsPost.ixLocationFunction  = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "PE").Select(x => x.ixLocationFunction).FirstOrDefault();
                                    inventoryLocationsPost.ixFacility          = currentBotUserData.ixFacility;
                                    inventoryLocationsPost.ixFacilityFloor     = _inventorylocationsService.FacilityFloorsDb().Select(x => x.ixFacilityFloor).FirstOrDefault();
                                    inventoryLocationsPost.ixFacilityZone      = _inventorylocationsService.FacilityZonesDb().Select(x => x.ixFacilityZone).FirstOrDefault();
                                    inventoryLocationsPost.ixFacilityWorkArea  = _inventorylocationsService.FacilityWorkAreasDb().Select(x => x.ixFacilityWorkArea).FirstOrDefault();
                                    inventoryLocationsPost.ixFacilityAisleFace = _inventorylocationsService.FacilityAisleFacesDb().Select(x => x.ixFacilityAisleFace).FirstOrDefault();
                                    inventoryLocationsPost.nSequence           = 0;
                                    inventoryLocationsPost.bTrackUtilisation   = false;
                                    currentBotUserData.ixInventoryLocation     = await _inventorylocationsService.Create(inventoryLocationsPost);
                                }
                                else
                                {
                                    currentBotUserData.ixInventoryLocation = _inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Select(x => x.ixInventoryLocation).FirstOrDefault();
                                    var inventoryLocationsPost = _inventorylocationsService.GetPost(currentBotUserData.ixInventoryLocation);
                                    inventoryLocationsPost.ixFacility = currentBotUserData.ixFacility;
                                    await _inventorylocationsService.Edit(inventoryLocationsPost);
                                }
                            }
                            //Custom Code End
                            await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                            await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                            //Custom Code Start | Removed Block
                            //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken);
                            //Custom Code End
                            //Custom Code Start | Added Code Block
                            await turnContext.SendActivityAsync(MessageFactory.Text($"The setup parameters have been updated. Say/type putaway, pick or cancel."), cancellationToken);

                            //Custom Code End
                        }
                        break;

                    case DropInventoryUnitsPost dropinventoryunitsPost:
                        if (currentBotUserData.botUserEntityContext.entityIntent == "Create")
                        {
                            //Custom Code Start | Removed Block
                            //ixDropInventoryUnit = await _dropinventoryunitsService.Create(dropinventoryunitsPost);
                            //await turnContext.SendActivityAsync(MessageFactory.Text($"The DropInventoryUnit {ixDropInventoryUnit} was created"), cancellationToken);
                            //currentBotUserData.ixDropInventoryUnit = ixDropInventoryUnit;
                            //await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);
                            //await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);
                            //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken);
                            //Custom Code End
                            await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken);
                        }
                        break;

                    default:
                        // We shouldn't get here.
                        break;
                    }
                }

                // Proactively send a welcome message to a personal chat the first time
                // (and only the first time) a user initiates a personal chat.
                //Custom Code Start | Replaced Code Block
                //Replaced Code Block Start
                //if (didBotWelcomeUser == false)
                //Replaced Code Block End
                if (true == false)
                //Custom Code End
                {
                    // Update user state flag to reflect bot handled first user interaction.
                    await _botSpielUserStateAccessors.DidBotWelcomeUser.SetAsync(turnContext, true);

                    await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                    // the channel should sends the user name in the 'From' object
                    var userName = turnContext.Activity.From.Name;

                    // We give the user the opportunity to say or request something using natural language and funnel through recognizer
                    await turnContext.SendActivityAsync($"What would like to do? You can say things like ... or help me.", cancellationToken : cancellationToken);
                }
                //Custom Code Start | Added Code Block
                else if (!currentBotUserData.bIsInitialSetUpParametersSet)
                {
                    currentBotUserData.bIsInitialSetUpParametersSet      = true;
                    currentBotUserData.botUserEntityContext.module       = "Execution";
                    currentBotUserData.botUserEntityContext.entity       = "SetUpExecutionParameters";
                    currentBotUserData.botUserEntityContext.entityIntent = "Create";
                    await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                    await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                    await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken);
                }
                //Custom Code End
                else if ((dialogTurnResult.Status is DialogTurnStatus.Empty) || turnContext.Activity.Text.ToLowerInvariant() == "putaway" || turnContext.Activity.Text.ToLowerInvariant() == "cancel")
                {
                    var text = turnContext.Activity.Text.ToLowerInvariant();

                    // Now attempt to infer the context (NLP)
                    // Placeholder for code to added

                    switch (text)
                    {
                    //Custom Code Start | Removed Block
                    //case "help me":
                    //    await turnContext.SendActivityAsync($"You said: {text}.", cancellationToken: cancellationToken);
                    //    break;
                    //Custom Code End
                    //Custom Code Start | Added Code Block
                    case "putaway":
                        currentBotUserData.botUserEntityContext.module       = "Execution";
                        currentBotUserData.botUserEntityContext.entity       = "PutAwayHandlingUnits";
                        currentBotUserData.botUserEntityContext.entityIntent = "Create";
                        await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                        await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                        await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken);

                        break;

                    case "pick":
                        currentBotUserData.botUserEntityContext.module       = "Execution";
                        currentBotUserData.botUserEntityContext.entity       = "PickBatchPicking";
                        currentBotUserData.botUserEntityContext.entityIntent = "Create";
                        await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken);

                        await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

                        //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken);
                        await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken);

                        break;

                    case "cancel":
                        await dc.CancelAllDialogsAsync(cancellationToken);

                        break;

                    //Custom Code End
                    default:
                        if (dc.ActiveDialog == null && (dialogTurnResult.Status is DialogTurnStatus.Complete || dialogTurnResult.Status is DialogTurnStatus.Empty || dialogTurnResult.Status is DialogTurnStatus.Cancelled))
                        {
                            await turnContext.SendActivityAsync("I do not understand, let's try something different.", cancellationToken : cancellationToken);

                            await dc.BeginDialogAsync(RootDialogId, null, cancellationToken);
                        }
                        break;
                    }
                }
            }
            else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
            {
                if (turnContext.Activity.MembersAdded.Any())
                {
                    // Iterate over all new members added to the conversation
                    foreach (var member in turnContext.Activity.MembersAdded)
                    {
                        if (member.Id != turnContext.Activity.Recipient.Id)
                        {
                            await turnContext.SendActivityAsync($"Hi there - {member.Name}. {WelcomeMessage}", cancellationToken : cancellationToken);
                        }
                    }
                }
            }
            else
            {
                // Default behaviour for all other type of activities.
                await turnContext.SendActivityAsync($"{turnContext.Activity.Type} activity detected");
            }

            // save any state changes made to your state objects.
            await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext);

            await _botSpielUserStateAccessors.ConversationState.SaveChangesAsync(turnContext);
        }