Esempio n. 1
0
        public virtual ActionResult Validate(OpenBoxViewModel model)
        {
            LogI("Validate");
            var results = model.Validate(Db);

            return(JsonGet(results));
        }
Esempio n. 2
0
        public virtual ActionResult OnCreateItem(long styleId)
        {
            LogI("OnCreateItem, styleId=" + styleId);

            var model = OpenBoxViewModel.BuildFromStyleId(Db, styleId);

            ViewBag.PartialViewName = "OpenBoxViewModel";
            return(View("EditNew", model));
        }
Esempio n. 3
0
        public virtual ActionResult OnUpdateItem(long openBoxId)
        {
            LogI("OnUpdateItem, openBoxId=" + openBoxId);

            var model = OpenBoxViewModel.BuildFromBoxId(Db, openBoxId);

            ViewBag.PartialViewName = "OpenBoxViewModel";
            return(View("EditNew", model));
        }
Esempio n. 4
0
        public virtual ActionResult GetPurchaseOrder(long id)
        {
            LogI("GetPurchaseOrder, id=" + id);

            var model         = OpenBoxViewModel.BuildFromBoxId(Db, id);
            var purchaseModel = new PurchaseOrderViewModel(model);

            return(JsonGet(new ValueResult <PurchaseOrderViewModel>(true, null, purchaseModel)));
        }
        public PurchaseOrderViewModel(OpenBoxViewModel box)
        {
            Id          = box.Id;
            StyleString = box.StyleString;
            ReceiveDate = box.CreateDateUtc;
            BoxQuantity = box.BoxQuantity;

            Sizes = box.StyleItems.Items;
        }
Esempio n. 6
0
        public virtual ActionResult GetOpenBox([DataSourceRequest] DataSourceRequest request, long styleId)
        {
            LogI("GetOpenBox, styleId=" + styleId);

            var items = OpenBoxViewModel.GetAll(Db,
                                                styleId,
                                                includeArchive: AccessManager.IsAdmin).ToList();
            var dataSource = items.ToDataSourceResult(request);

            return(new JsonResult {
                Data = dataSource, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Esempio n. 7
0
        public virtual ActionResult DeleteBox(int id)
        {
            LogI("DeleteBox, id=" + id);

            OpenBoxViewModel.Remove(Db,
                                    id,
                                    QuantityManager,
                                    Cache,
                                    Time.GetAppNowTime(),
                                    AccessManager.UserId);


            return(Json(MessageResult.Success(), JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public virtual ActionResult GetAll([DataSourceRequest] DataSourceRequest request)
        {
            LogI("GetOpenBox");

            var items = OpenBoxViewModel.GetAll(Db,
                                                null,
                                                includeArchive: true).ToList();

            var data = new GridResponse <OpenBoxViewModel>(items, items.Count, Time.GetAppNowTime());

            return(new JsonResult {
                Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Esempio n. 9
0
        public virtual ActionResult Submit(OpenBoxViewModel model)
        {
            LogI("Submit, model=" + model);

            //Save
            if (ModelState.IsValid)
            {
                var id = model.Apply(Db, QuantityManager, Time.GetAppNowTime(), AccessManager.UserId);

                Cache.RequestStyleIdUpdates(Db,
                                            new List <long>()
                {
                    model.StyleId
                },
                                            UpdateCacheMode.IncludeChild,
                                            AccessManager.UserId);

                return(Json(new UpdateRowViewModel(model, "OpenBox_" + id, null, true)));
            }
            return(View("OpenBoxViewModel", model));
        }
        public void Apply(IUnitOfWork db,
                          IQuantityManager quantityManager,
                          ILogService log,
                          ICacheService cache,
                          ISystemActionService actionService,
                          DateTime when,
                          long?by)
        {
            log.Info("AddSealedBoxWizardViewModel.Apply, StyleId=" + StyleId);

            if (IncomeType == (int)BoxIncomePackType.PPK)
            {
                var box = new SealedBoxViewModel();
                box.StyleId     = StyleId;
                box.BoxBarcode  = BoxBarcode;
                box.BoxQuantity = BoxQuantity;
                box.Price       = Price ?? 0;

                box.Owned    = Owned;
                box.PolyBags = false;
                box.Printed  = Printed;

                box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                box.StyleItems = new StyleItemCollection()
                {
                    Items = Sizes.Select(s => new StyleItemViewModel()
                    {
                        Id        = s.Id,
                        Breakdown = s.Breakdown,
                    }).ToList()
                };

                box.Apply(db, quantityManager, when, by);
            }

            if (IncomeType == (int)BoxIncomePackType.PolyBagged)
            {
                foreach (var size in Sizes.Where(si => si.Quantity > 0))
                {
                    var box = new SealedBoxViewModel();
                    box.StyleId     = StyleId;
                    box.BoxBarcode  = BoxBarcode;
                    box.BoxQuantity = size.Quantity ?? 0;
                    box.Price       = Price ?? 0;

                    box.Owned    = Owned;
                    box.PolyBags = true;
                    box.Printed  = Printed;

                    box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                    box.StyleItems = new StyleItemCollection()
                    {
                        Items = new List <StyleItemViewModel>()
                        {
                            new StyleItemViewModel()
                            {
                                Id        = size.Id,
                                Breakdown = UnitsPerBox
                            }
                        }
                    };

                    box.Apply(db, quantityManager, when, by);
                }
            }

            if (IncomeType == (int)BoxIncomePackType.Other)
            {
                var box = new OpenBoxViewModel();
                box.StyleId     = StyleId;
                box.BoxBarcode  = BoxBarcode;
                box.BoxQuantity = 1;
                box.Price       = Price ?? 0;

                box.Owned    = Owned;
                box.PolyBags = false;
                box.Printed  = Printed;

                box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                box.StyleItems = new StyleItemCollection()
                {
                    Items = Sizes.Select(s => new StyleItemViewModel()
                    {
                        Id       = s.Id,
                        Quantity = s.Quantity,
                    }).ToList()
                };

                box.Apply(db, quantityManager, when, by);
            }

            foreach (var size in Sizes)
            {
                var styleItem = db.StyleItems.Get(size.Id);
                if (size.UseBoxQuantity &&
                    styleItem.Quantity.HasValue)
                {
                    log.Info("Switch to box quantity, styleItemId=" + size.Id);

                    var oldQuantity = styleItem.Quantity;

                    styleItem.Quantity        = null;
                    styleItem.QuantitySetBy   = null;
                    styleItem.QuantitySetDate = null;
                    styleItem.RestockDate     = null;

                    db.Commit();

                    quantityManager.LogStyleItemQuantity(db,
                                                         styleItem.Id,
                                                         null,
                                                         oldQuantity,
                                                         QuantityChangeSourceType.UseBoxQuantity,
                                                         null,
                                                         null,
                                                         BoxBarcode,
                                                         when,
                                                         by);
                }
            }

            cache.RequestStyleIdUpdates(db,
                                        new List <long>()
            {
                StyleId
            },
                                        UpdateCacheMode.IncludeChild,
                                        by);

            SystemActionHelper.RequestQuantityDistribution(db, actionService, StyleId, by);
        }