Beispiel #1
0
        public void allocateBatch(Int64 ixPickBatch, String UserName)
        {
            //We check that the batch is not already allocated and activated - if so we do nothing
            var pickBatch = _pickbatchesRepository.Get(ixPickBatch);

            if (pickBatch.Statuses.sStatus == "Inactive")
            {
                //We get the orders associated with the batch
                var ordersInBatch = _outboundordersRepository.IndexDb().Where(x => x.ixPickBatch == ixPickBatch && x.Statuses.sStatus == "Active").Select(x => new { x.ixOutboundOrder, x.ixFacility, x.ixCompany });
                ordersInBatch.ToList().ForEach(x =>
                {
                    var linesInOrders = _outboundorderlinesRepository.IndexDb().Where(l => l.ixOutboundOrder == x.ixOutboundOrder && l.Statuses.sStatus == "Active").Select(l => new { l.ixOutboundOrderLine, l.ixMaterial, l.nBaseUnitQuantityOrdered });
                    linesInOrders
                    .ToList().ForEach(l =>
                    {
                        var qtyAvailableToAllocate = getQtyAvailable(x.ixFacility, x.ixCompany, l.ixMaterial) - getQtyAllocated(x.ixFacility, x.ixCompany, l.ixMaterial);
                        if (qtyAvailableToAllocate > 0)
                        {
                            OutboundOrderLinesInventoryAllocationPost outboundOrderLineInventoryAllocation = new OutboundOrderLinesInventoryAllocationPost();
                            outboundOrderLineInventoryAllocation.ixOutboundOrderLine = l.ixOutboundOrderLine;
                            var orderLine = _outboundorderlinesRepository.GetPost(l.ixOutboundOrderLine);
                            if (qtyAvailableToAllocate >= l.nBaseUnitQuantityOrdered)
                            {
                                outboundOrderLineInventoryAllocation.nBaseUnitQuantityAllocated = l.nBaseUnitQuantityOrdered;
                                orderLine.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Allocated").Select(s => s.ixStatus).FirstOrDefault();
                                orderLine.UserName = UserName;
                                _outboundorderlinesService.Edit(orderLine);
                            }
                            else
                            {
                                outboundOrderLineInventoryAllocation.nBaseUnitQuantityAllocated = qtyAvailableToAllocate;
                                orderLine.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Partially Allocated").Select(s => s.ixStatus).FirstOrDefault();
                                orderLine.UserName = UserName;
                                _outboundorderlinesService.Edit(orderLine);
                            }
                            outboundOrderLineInventoryAllocation.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault();
                            outboundOrderLineInventoryAllocation.UserName = UserName;
                            _outboundorderlinesinventoryallocationService.Create(outboundOrderLineInventoryAllocation);
                        }
                    }
                                      );
                }
                                               );
            }
        }
        public ActionResult Edit([Bind("ixOutboundOrderLine,sOutboundOrderLine,ixOutboundOrder,sOrderLineReference,ixMaterial,sBatchNumber,sSerialNumber,nBaseUnitQuantityOrdered,nBaseUnitQuantityShipped,ixStatus")] OutboundOrderLinesPost outboundorderlines)
        {
            if (ModelState.IsValid)
            {
                outboundorderlines.UserName = User.Identity.Name;
                _outboundorderlinesService.Edit(outboundorderlines);
                return(RedirectToAction("Index"));
            }
            ViewBag.ixMaterial      = new SelectList(_outboundorderlinesService.selectMaterials().Select(x => new { x.ixMaterial, x.sMaterial }), "ixMaterial", "sMaterial", outboundorderlines.ixMaterial);
            ViewBag.ixOutboundOrder = new SelectList(_outboundorderlinesService.selectOutboundOrders().Select(x => new { x.ixOutboundOrder, x.sOutboundOrder }), "ixOutboundOrder", "sOutboundOrder", outboundorderlines.ixOutboundOrder);
            ViewBag.ixStatus        = new SelectList(_outboundorderlinesService.selectStatuses().Select(x => new { x.ixStatus, x.sStatus }), "ixStatus", "sStatus", outboundorderlines.ixStatus);

            return(View(outboundorderlines));
        }
Beispiel #3
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);
            }
                                             );
        }