public List <CatalogueItemDTO> GetCatalogueItems(int employeeId)
        {
            List <CartDetail>       cartDetails    = GetAnyExistingCartDetails(employeeId);
            List <Stationery>       stationeries   = (List <Stationery>)stationeryRepo.FindAll();
            List <CatalogueItemDTO> catalogueItems = new List <CatalogueItemDTO>();

            //for each stationery in stationeries create a catalogueItemDTO
            foreach (Stationery s in stationeries)
            {
                CatalogueItemDTO catalogueItemDTO = new CatalogueItemDTO()
                {
                    Item          = s.Description,
                    UnitOfMeasure = s.UnitOfMeasure,
                    StationeryId  = s.Id
                };
                getCatalogueItemAvailability(catalogueItemDTO, s);
                catalogueItems.Add(catalogueItemDTO);
            }

            if (cartDetails != null)
            {
                foreach (CartDetail cd in cartDetails)
                {
                    CatalogueItemDTO catItemDTO = catalogueItems.Find(x => x.StationeryId == cd.StationeryId);
                    catItemDTO.OrderQtyInput = cd.Quantity;
                    catItemDTO.ReservedCount = getReservedBalanceForExistingCartItem(cd);
                    catItemDTO.WaitlistCount = cd.Quantity - catItemDTO.ReservedCount;
                    catItemDTO.Confirmation  = true;
                }
            }
            return(catalogueItems);
        }
        public CatalogueItemDTO AddCartDetail(int employeeId, int stationeryId, int inputQty)
        {
            Stationery s           = stationeryRepo.FindById(stationeryId);
            int        currBalance = getCurrentBalance(s);
            int        reserved    = 0;
            int        waitlist    = 0;

            if (inputQty > currBalance)
            {
                reserved = currBalance;
                waitlist = inputQty - currBalance;
            }
            else
            {
                reserved = inputQty;
            }
            CartDetail cd = new CartDetail {
                DateTime = DateTime.Now, EmployeeId = employeeId, Quantity = inputQty, StationeryId = stationeryId
            };

            cartDetailRepo.Create(cd); //persist new cart detail

            //can abstract into a method and share with above bbut must instantiate a new DTO first
            CatalogueItemDTO catalogueItemDTO = new CatalogueItemDTO()
            {
                ReservedCount = reserved, WaitlistCount = waitlist
            };

            getCatalogueItemAvailability(catalogueItemDTO, s);
            return(catalogueItemDTO);
        }
Ejemplo n.º 3
0
        public JsonResult RemoveItemFromCart(int employeeId, int stationeryId)
        {
            CatalogueItemDTO catalogueItemDTO = requisitionCatalogueService.RemoveCartDetail(employeeId, stationeryId);

            return(Json(new
            {
                availstatus = catalogueItemDTO.StockAvailability.ToString(),
                lowstockcount = catalogueItemDTO.LowStockAvailability
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public JsonResult AddItemToCart(int employeeId, int stationeryId, int inputQty)
        {
            CatalogueItemDTO catalogueItemDTO = requisitionCatalogueService.AddCartDetail(employeeId, stationeryId, inputQty);

            return(Json(new
            {
                availstatus = catalogueItemDTO.StockAvailability.ToString(),
                lowstockcount = catalogueItemDTO.LowStockAvailability,
                reserved = catalogueItemDTO.ReservedCount,
                waitlist = catalogueItemDTO.WaitlistCount
            }, JsonRequestBehavior.AllowGet));
        }
        private void getCatalogueItemAvailability(CatalogueItemDTO catalogueItemDTO, Stationery s)
        {
            int currBalance   = getCurrentBalance(s);
            int?lowStockCount = null;
            StockAvailabilityEnum stockAvailEnum = getStockAvailabilityStatus(currBalance, s.ReorderLevel);

            if (stockAvailEnum == StockAvailabilityEnum.LowStock)
            {
                lowStockCount = currBalance;
            }
            catalogueItemDTO.StockAvailability    = stockAvailEnum;
            catalogueItemDTO.LowStockAvailability = lowStockCount;
        }
Ejemplo n.º 6
0
        public ActionResult CreateCatalogueItem(CatalogueItemDTO item)
        {
            //create catalogue item
            CatalogueItemEF catItem = new CatalogueItemEF()
            {
                ItemCode     = item.ItemCode,
                ReorderLevel = item.ReorderLevel,
                ReorderQty   = item.ReorderQty
            };

            stockService.CreateCatalogueItem(catItem);
            return(RedirectToAction("ViewCatalogueItem", new { catalogueId = catItem.CatalogueId }));
        }
Ejemplo n.º 7
0
        public async Task UpdateAsync(CatalogueItemDTO catalogueItem)
        {
            CatalogueItem catalogueItemModel = await _unitOfWork.CatalogueItemRepository.GetCatalogueItemByIdAsync(catalogueItem.Id);

            catalogueItemModel.Name  = catalogueItem.Name;
            catalogueItemModel.Price = catalogueItem.Price;
            if (catalogueItem.Category != null)
            {
                catalogueItemModel.CategoryId = catalogueItem.Category.Id;
            }

            await _unitOfWork.CommitAsync();
        }
        // *******************************************************************************************************************************
        #region -  Run  -

        protected override async Task RunAsync(CancellationToken?cancellationToken)
        {
            var familyId = Context.Get <string>("FamilyID");

            var family = await ProductFamilyMDAL.GetFamilyWithItemsAsync(familyId).ConfigureAwait(false);

            if (family.IsNotNull() && family.Items.IsPresent())
            {
                if (!family.Flags.HasAnyFlag(ProductFlagsEnum.Inactive))
                {
                    var catalogueItems = family.Items
                                         .GroupBy(x => new { x.Family_ID, x.ImageHash })
                                         .SelectMany(x =>
                    {
                        var productItem   = x.First();
                        var catalogueItem = new CatalogueItemDTO
                        {
                            Name      = productItem.Name,
                            Family_ID = productItem.Family_ID,
                            ImageHash = productItem.ImageHash,
                            ImageUrl  = productItem.ImageUrl,
                            //catalogueItem.DetailUrl = productItem.DetailUrl;
                            //catalogueItem.BrandUrl = productItem.BrandUrl;
                            Brand = productItem.Brand,
                            Room  = productItem.Room,
                            Size  = productItem.Size,
                            Color = productItem.Color,
                            Price = productItem.Price,

                            Search_ItemNOs = string.Join(",", x.Select(a => a.ItemNo))
                        };
                        //catalogueItem.Search_Colors = string.Join(",", x.Select(a => a.Color));

                        return(new[] { catalogueItem });
                    });

                    var msgCode = await CatalogueItemQDAL.BulkInsertItemsAsync(catalogueItems).ConfigureAwait(false);

                    if (!msgCode.IsSuccess())
                    {
                        throw new Exception(msgCode);
                    }
                    // ^^^^^^^^^^
                }
            }
            else
            {
                throw new Exception($"Cannot find family '{familyId}'");
            }
        }
        public CatalogueItemDTO RemoveCartDetail(int employeeId, int stationeryId)
        {
            Stationery s = stationeryRepo.FindById(stationeryId);
            //remove cd from db first
            CartDetail cd = cartDetailRepo.FindOneBy(x => x.EmployeeId == employeeId && x.StationeryId == stationeryId);

            if (cd != null)
            {
                cartDetailRepo.Delete(cd);
                CatalogueItemDTO catalogueItemDTO = new CatalogueItemDTO();
                getCatalogueItemAvailability(catalogueItemDTO, s);
                return(catalogueItemDTO);
            }
            return(null);
        }
Ejemplo n.º 10
0
        public ActionResult CreateCatalogueItem()
        {
            //get a list of itemCodes from stock that do not have a catalogue
            List <StockEF> itemsNotInCat       = stockService.FindItemsNotInCatalogue();
            IEnumerable <SelectListItem> items = itemsNotInCat
                                                 .Select(i => new SelectListItem()
            {
                Text  = i.ItemCode + ": " + i.Description,
                Value = i.ItemCode
            });

            ViewData["ItemCode"] = items;

            CatalogueItemDTO item = new CatalogueItemDTO();

            return(View(item));
        }
Ejemplo n.º 11
0
        public PredictReorderQtyDTO GetPredictModel(CatalogueItemDTO item)
        {
            using (var client = new HttpClient())
            {
                StockEF predictItem = stockEFF.FindStockByItemCode(item.ItemCode);

                //label encoding for the three features
                //contain the label encoding for category and also the average quantity based on category and uom
                int[] categoryAvgQty = LabelEncodeByCategory(predictItem.Category, predictItem.Uom);
                int   uom            = LabelEncodeByUOM(predictItem.Uom);
                int   popularity     = LabelEncodeByPopularity(predictItem.ItemCode, categoryAvgQty[1], uom);

                PredictReorderQtyDTO predModel = new PredictReorderQtyDTO(categoryAvgQty[0], popularity, uom);

                return(predModel);
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> UpdateCatalogueItem(CatalogueItemDTO item, string decision)
        {
            if (decision == "Cancel")
            {
                return(RedirectToAction("ViewCatalogueItem", new { catalogueId = item.CatalogueId }));
            }

            if (decision == "Predict Reorder Quantity")
            {
                // get prediction from service
                using (var client = new HttpClient())
                {
                    PredictReorderQtyDTO predModel = predictService.GetPredictModel(item);
                    // send a POST request to the server uri with the data and get the response as HttpResponseMessage object
                    HttpResponseMessage res = await client.PostAsJsonAsync("http://127.0.0.1:5000/", predModel);

                    // Return the result from the server if the status code is 200 (everything is OK)
                    if (res.IsSuccessStatusCode)
                    {
                        int prediction = int.Parse(res.Content.ReadAsStringAsync().Result);
                        ModelState.Remove("ReorderQty");
                        item.ReorderQty = prediction;
                    }
                    else
                    {
                        //set error message or view
                    }

                    // set it and throw it back to the update catalogue view
                    return(View(item));
                }
            }

            // decision == Save
            CatalogueItemEF catItem = new CatalogueItemEF()
            {
                CatalogueId  = item.CatalogueId,
                ItemCode     = item.ItemCode,
                ReorderLevel = item.ReorderLevel,
                ReorderQty   = item.ReorderQty
            };

            stockService.UpdateCatalogueItem(catItem);
            return(RedirectToAction("ViewCatalogueItem", new { catalogueId = catItem.CatalogueId }));
        }
Ejemplo n.º 13
0
        public ActionResult UpdateCatalogueItem(int catalogueId)
        {
            CatalogueItemEF catItem = stockService.FindCatalogueItemById(catalogueId);

            if (catItem == null)
            {
                return(View("Error"));
            }
            CatalogueItemDTO item = new CatalogueItemDTO()
            {
                CatalogueId  = catItem.CatalogueId,
                ItemCode     = catItem.ItemCode,
                Description  = catItem.Stock.Description,
                ReorderLevel = catItem.ReorderLevel,
                ReorderQty   = catItem.ReorderQty
            };

            return(View(item));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> UpdateCatalogueItem(int providerId, int itemId, CatalogueItemDTO catalogueItem)
        {
            try
            {
                if (await _providerSevice.GetByIdAsync(providerId, false) == null)
                {
                    return(NotFound("No provider with the specified id exists."));
                }

                if (await _catalogueItemService.GetCatalogueItemByIdAsync(itemId) == null)
                {
                    return(NotFound("No catalogue item with the specified id exists."));
                }

                if (itemId != catalogueItem.Id)
                {
                    ModelState.AddModelError("Identifier", "Specified id does not match request body.");
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                await _catalogueItemService.UpdateAsync(catalogueItem);

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "An error occured."));
            }
        }