Esempio n. 1
0
        public virtual ActionResult ActivatePallet(string palletId, string lastScanText, Sound sound = Sound.None, string confirmPalletScan = null)
        {
            var model = new ScanToPalletViewModel
            {
                PalletLimit     = _service.GetPalletVolumeLimit(),
                Sound           = (char)sound,
                PalletId        = palletId,
                LastBoxId       = lastScanText,
                ConfirmScanText = confirmPalletScan
            };

            //TC1: When a box is scanned who is not on any pallet.
            if (string.IsNullOrEmpty(palletId))
            {
                return(View(this.Views.ScanToPallet, model));
            }
            var boxes = _service.GetBoxesOfPallet(palletId).ToArray();

            model.TotalBoxVolume     = boxes.Sum(p => p.Volume);
            model.CountBoxesOnPallet = boxes.Count();
            model.PalletLocationList = string.Join(",", boxes.Select(p => p.LocationId).Distinct());
            model.PalletAreaList     = string.Join(",", boxes.Select(p => p.IaId).Distinct());
            //TC2: When box(es) count is equal to zero.
            if (!boxes.Any())
            {
                AddStatusMessage(string.Format("Start scanning boxes to keep them on {0}.", palletId));
                return(View(this.Views.ScanToPallet, model));
            }
            else
            {
                //Validate boxes of pallet.
                foreach (var box in boxes)
                {
                    //TC3: Boxes are not valid.[i.e box is not verified or shipped].
                    if (!TryValidateModel(new BoxModel(box)) || (_uiType == UiType.ScanToPallet && box.VerifyDate == null) ||
                        (_uiType == UiType.ScanToPallet && !string.IsNullOrWhiteSpace(box.SmallShipmentFlag)))
                    {
                        if (_uiType == UiType.ScanToPallet && box.VerifyDate == null)
                        {
                            ModelState.AddModelError("box.VerifyDate", string.Format("Boxes of pallet {0} have not been verified yet.", palletId));
                        }
                        if (_uiType == UiType.ScanToPallet && !string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                        {
                            ModelState.AddModelError("box.SmallShipmentFlag", "Boxes of small shipments cannot be palletized.");
                        }
                        // Boxes are not appropriate for palletizing. Not Verified, shipped, etc.
                        return(View(this.Views.ScanToPallet, new ScanToPalletViewModel()));
                    }
                }
            }

            SortCriteria sortCriteria;

            try
            {
                sortCriteria = _service.EnsureCriteriaPure(boxes, _uiType == UiType.Vas);
            }
            catch (BoxManagerServiceException ex)
            {
                switch (ex.ErrorCode)
                {
                case BoxManagerServiceErrorCode.MultipleBucketPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple buckets {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultipleCustomerPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple customer {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultipleDcPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple Dc {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultiplePoPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple Po {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;
                }
                return(View(this.Views.ScanToPallet, new ScanToPalletViewModel()));
            }

            var firstBox = boxes.First();

            //Set sorting criteria
            model.CustomerId = firstBox.CustomerId;

            //TC4: if the AllowPoMixing  that are set in flag are also set in the HomeController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowPoMixing))
            {
                model.PoId = firstBox.PoId;
            }
            //TC5: if the AllowCustomerDcMixing  that are set in flag are also set in the HomeController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowCustomerDcMixing))
            {
                model.CustomerDcId = firstBox.CustomerDcId;
            }
            //TC6: if the AllowBucketMixing that are set in flag are also set in the HomeController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowBucketMixing))
            {
                model.BucketId = firstBox.BucketId;
            }
            model.PalletSuggestionList = _service.SuggestPallets(model.PalletId, model.CustomerId, model.BucketId, model.PoId, model.CustomerDcId, _uiType == UiType.Vas).Select(p => new PalletModel(p)).ToList();

            if (_uiType == UiType.Vas)
            {
                model.QualifyingBoxCount = _service.GetQualifyingBoxCountForVas(model.CustomerId);
            }
            else
            {
                model.QualifyingBoxCount = _service.GetQualifyingBoxCount(model.CustomerId, model.PoId, model.CustomerDcId, model.BucketId);
            }
            return(View(this.Views.ScanToPallet, model));
        }
Esempio n. 2
0
        /// <summary>
        ///  Returns source pallet information. If a box is scanned which is on a pallet
        ///  we consider it as equivalent to pallet scan.
        /// </summary>
        /// <returns>
        /// Returns source pallet information.
        /// </returns>
        public virtual ActionResult SourcePallet(IndexViewModel model)
        {
            //TC1: If the model state is not valid.[For eg: when no pallet is passed and press enter].
            if (!ModelState.IsValid)
            {
                return(View(Views.Index, model));
            }
            //TC2: If the entered value is a box.
            if (__regexUcc.IsMatch(model.ScanText))
            {
                // Box is on a pallet. Consider it equivalent to pallet scan.
                var box = _service.GetBox(model.ScanText, false);
                //TC3: If the entered box is not on any pallet.
                if (box == null || string.IsNullOrEmpty(box.PalletId))
                {
                    ModelState.AddModelError("", string.Format("Scanned Box {0} is not on any pallet.", model.ScanText));
                    return(View(Views.Index, model));
                }
                else
                {
                    //TC: Box is not valid.[i.e box is not verified or shipped].
                    if (!TryValidateModel(new BoxModel(box)) || box.VerifyDate == null || !string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                    {
                        if (box.VerifyDate == null)
                        {
                            ModelState.AddModelError("box.VerifyDate", "Box has not been verified yet.");
                        }
                        if (!string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                        {
                            ModelState.AddModelError("box.SmallShipmentFlag", "Boxes of small shipments cannot be palletized.");
                        }
                        // Box is not appropriate for palletizing. Not Verified, shipped, etc.
                        return(RedirectToAction(this.Actions.Index(Sound.Error)));
                    }
                }
                model.PalletId = box.PalletId;
            }
            //TC4: If the entered value is a pallet.
            else if (__regexPallet.IsMatch(model.ScanText))
            {
                model.PalletId = model.ScanText;
            }
            else
            {
                ModelState.AddModelError("", string.Format("Scan text {0} is not recognized.", model.ScanText));
                return(View(Views.Index, model));
            }
            var boxesOfPallet = _service.GetBoxesOfPallet(model.PalletId);

            //TC5: If an empty pallet is scanned.
            if (boxesOfPallet != null && !boxesOfPallet.Any())
            {
                //Pallet is empty,Can't move or merge.
                ModelState.AddModelError("", string.Format("Pallet {0} does not contain any boxes.", model.PalletId));
                return(View(Views.Index, model));
            }
            else
            {
                //Validate boxes of pallet.
                foreach (var box in boxesOfPallet)
                {
                    //TC: Boxes are not valid.[i.e box is not verified or shipped].
                    if (!TryValidateModel(new BoxModel(box)) || box.VerifyDate == null || !string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                    {
                        if (box.VerifyDate == null)
                        {
                            ModelState.AddModelError("box.VerifyDate", string.Format("Boxes of pallet {0} have not been verified yet.", model.PalletId));
                        }
                        if (!string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                        {
                            ModelState.AddModelError("box.SmallShipmentFlag", "Boxes of small shipments cannot be palletized.");
                        }
                        // Boxes are not appropriate for palletizing. Not Verified, shipped, etc.
                        return(RedirectToAction(this.Actions.Index(Sound.Error)));
                    }
                }
            }
            try
            {
                _service.EnsureCriteriaPure(boxesOfPallet, false);
            }
            catch (BoxManagerServiceException ex)
            {
                switch (ex.ErrorCode)
                {
                case BoxManagerServiceErrorCode.MultipleBucketPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple buckets {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultipleCustomerPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple customers {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultipleDcPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple DCs {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;

                case BoxManagerServiceErrorCode.MultiplePoPallet:
                    ModelState.AddModelError("", string.Format("Pallet {0} does not satisfy criteria because it contains boxes of multiple POs {1}.",
                                                               model.PalletId, ex.Data["Data"]));
                    break;
                }
                return(RedirectToAction(this.Actions.Index(Sound.Error)));
            }
            // Now ask for validation
            return(RedirectToAction(this.Actions.ValidatePallet(model.PalletId)));
        }