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
        public virtual ActionResult Destination(string palletId, Sound sound = Sound.None)
        {
            //TC17:When no pallet is passed during verifying the boxes with the correct quantity.
            if (palletId == null)
            {
                throw new ArgumentNullException("palletId");
            }
            var boxes = _service.GetBoxesOfPallet(palletId).ToArray();

            //TC18: When no box is passed/count of the box is zero.
            if (!boxes.Any())
            {
                ModelState.AddModelError("", string.Format("Pallet {0} does not contain any boxes.", palletId));
                return(RedirectToAction(this.Actions.Index(Sound.Error)));
            }
            else
            {
                foreach (var box in boxes)
                {
                    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.", palletId));
                        }
                        if (!string.IsNullOrWhiteSpace(box.SmallShipmentFlag))
                        {
                            ModelState.AddModelError("box.SmallShipmentFlag", "Boxes of small shipments cannot be palletized.");
                        }
                        return(RedirectToAction(this.Actions.Index(Sound.Error)));
                    }
                }
            }
            var firstBox = boxes.First();
            var model    = new DestinationViewModel
            {
                SourcePalletId         = palletId,
                TotalBoxVolume         = boxes.Sum(p => p.Volume),
                TotalBoxesOnPallet     = boxes.Count(),
                PalletVolumeLimit      = _service.GetPalletVolumeLimit(),
                SourcePalletLocationId = firstBox.LocationId,
                SourcePalletAreaId     = firstBox.IaId, //TODO: Show the short Name of Area instead of AreaId
                CustomerId             = firstBox.CustomerId,
                AppointmentDate        = firstBox.AppointmentDate,
                AppointmentNo          = firstBox.AppointmentNo,
                DoorId = firstBox.DoorId,
                Sound  = (char)sound
            };
            // Ensure that pallet is pure.
            var sortCriteria = _service.EnsureCriteriaPure(boxes, false);

            //TC19: if the AllowPoMixing  that are set in flag are also set in the MovePalletController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowPoMixing))
            {
                model.PoId = firstBox.PoId;
            }
            //TC20: if the AllowCustomerDcMixing  that are set in flag are also set in the MovePalletController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowCustomerDcMixing))
            {
                model.CustomerDcId = firstBox.CustomerDcId;
            }
            //TC21: if the AllowBucketMixing  that are set in flag are also set in the MovePalletController class.
            if (!sortCriteria.HasFlag(SortCriteria.AllowBucketMixing))
            {
                model.BucketId = firstBox.BucketId;
            }
            //Suggest location list.
            var suggestLocation = _service.SuggestLocation(model.CustomerId, model.BucketId, model.PoId, model.CustomerDcId, model.SourcePalletAreaId);

            model.LocationSuggestionList = suggestLocation.Select(p => new PalletModel(p)).ToList();
            return(View(Views.Destination, model));
        }