Beispiel #1
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);
        }
Beispiel #2
0
        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);
            }
                                             );
        }