Ejemplo n.º 1
0
        public ActionResult LoadIngredient(string ProductId, string StoreId, int productType)
        {
            IngredientFactory IngFactory            = new IngredientFactory();
            var listProductRecipe                   = _factory.GetListRecipeProduct(ProductId, StoreId, productType, listStoreId);
            RecipeProductIngredientViewModels model = new RecipeProductIngredientViewModels();
            var m_CompanyIds = GetListCompany().Select(x => x.Value).ToList();
            var listIng      = new List <IngredientModel>();

            if (m_CompanyIds.Count > 0)
            {
                listIng = IngFactory.GetIngredient("").Where(x => m_CompanyIds.Contains(x.CompanyId)).ToList();
            }
            else
            {
                listIng = IngFactory.GetIngredient("").ToList();
            }
            listIng = listIng.Where(x => x.IsActive == true).ToList();

            foreach (var item in listIng)
            {
                var ProIngre = new ProductIngredient()
                {
                    BaseUOM = item.BaseUOMName,

                    IngredientId   = item.Id,
                    IngredientName = item.Name,
                    Usage          = listProductRecipe.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() == null
                                                    ? 0 : listProductRecipe.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).Usage,

                    BaseUOMId = listProductRecipe.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() == null
                                                    ? item.BaseUOMId : listProductRecipe.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).UOMId,

                    IsSelect = listProductRecipe.Any(x => x.IngredientId.Equals(item.Id))
                };
                var lstItem = _UOMFactory.GetDataUOMRecipe(item.Id).ToList();
                if (lstItem != null)
                {
                    foreach (UnitOfMeasureModel uom in lstItem)
                    {
                        ProIngre.ListUOM.Add(new SelectListItem
                        {
                            Text     = uom.Name,
                            Value    = uom.Id,
                            Selected = uom.Id.Equals(ProIngre.BaseUOMId) == true ? true : false
                        });
                    }
                }
                model.ListItem.Add(ProIngre);
            }
            model.ListItem = model.ListItem.OrderByDescending(x => x.IsSelect ? 1 : 0).ThenBy(x => x.IngredientName).ToList();
            return(PartialView("_TableChooseIngredient", model));
        }
Ejemplo n.º 2
0
        public ActionResult AddIngredient(STIngredientViewModels data)
        {
            StockTransferModels model = new StockTransferModels();

            model.ListItem = new List <StockTransferDetailModels>();
            foreach (var item in data.ListItemView)
            {
                var itemDetail = new StockTransferDetailModels
                {
                    Id = "", // Add New

                    IngredientId   = item.IngredientId,
                    IngredientName = item.IngredientName,
                    IngredientCode = item.IngredientCode,

                    IsSelect   = item.IsSelect,
                    RequestQty = item.RequestQty,
                    IssueQty   = item.IssueQty,
                    ReceiveQty = item.ReceiveQty,

                    UOMId   = item.UOMId,
                    BaseUOM = item.BaseUOM,
                };
                var lstItem = _UOMFactory.GetDataUOMRecipe(item.IngredientId).ToList();
                if (lstItem != null)
                {
                    foreach (UnitOfMeasureModel uom in lstItem)
                    {
                        itemDetail.ListUOM.Add(new SelectListItem
                        {
                            Text  = uom.Name,
                            Value = uom.Id
                        });
                    }
                }
                model.ListItem.Add(itemDetail);
            }
            return(PartialView("_ListIngredients", model));
        }
Ejemplo n.º 3
0
        public ActionResult LoadIngredient(ReceiptNoteModels data)
        {
            IngredientFactory IngFactory = new IngredientFactory();

            //Get Data from Client
            List <ReceiptNoteIngredient> listReceiptNoteIngre = listReceiptNoteIngre = data.ListItem;

            ReceiptNoteModels model = new ReceiptNoteModels();

            //var m_CompanyIds = GetListCompany().Select(x => x.Value).ToList();
            //var listIng = new List<IngredientModel>();
            //if (m_CompanyIds.Count > 0)
            //    listIng = IngFactory.GetIngredient("").Where(x => m_CompanyIds.Contains(x.CompanyId)).ToList();
            //else
            //    listIng = IngFactory.GetIngredient("").ToList();

            ////==== Only get list Ingredients of the company of Receipt Note Store
            var lstStoreInfo = (List <StoreModels>)ViewBag.StoreID.Items;
            var compId       = lstStoreInfo.Where(w => w.Id == data.StoreId).Select(s => s.CompanyId).FirstOrDefault();

            var listIng = new List <IngredientModel>();

            if (!string.IsNullOrEmpty(compId))
            {
                listIng = _IngredientFactory.GetIngredient("").Where(x => x.CompanyId == compId).ToList();
                if (listIng != null && listIng.Any())
                {
                    listIng = listIng.Where(x => x.IsActive == true && !x.IsSelfMode).ToList();

                    foreach (var item in listIng)
                    {
                        var ProIngre = new ReceiptNoteIngredient()
                        {
                            BaseUOM        = item.BaseUOMName,
                            IngredientId   = item.Id,
                            IngredientCode = item.Code,
                            IngredientName = item.Name,
                            Description    = item.Description,

                            //=======Set Qty
                            Qty = listReceiptNoteIngre.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() == null
                                                            ? 1 : listReceiptNoteIngre.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).Qty,

                            //=====Set UOM: Priority| ReceivingUOM -> BaseUOM
                            BaseUOMId = listReceiptNoteIngre.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() != null
                                                            ? listReceiptNoteIngre.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).BaseUOMId
                                                            : item.ReceivingUOMId,
                            //=======Set Ing Select
                            IsSelect = listReceiptNoteIngre.Any(x => x.IngredientId.Equals(item.Id))
                        };

                        var lstItem = _UOMFactory.GetDataUOMRecipe(item.Id).ToList();
                        if (lstItem != null)
                        {
                            foreach (UnitOfMeasureModel uom in lstItem)
                            {
                                ProIngre.ListUOM.Add(new SelectListItem
                                {
                                    Text  = uom.Name,
                                    Value = uom.Id,
                                    //Selected = uom.Id.Equals(ProIngre.BaseUOMId) ? true :  false
                                });
                            }
                            //=====Reset UOM from BaseUOM If lstItemUOM not ReceivingUOM
                            var isExists = lstItem.Exists(z => z.Id.Equals(ProIngre.BaseUOMId));
                            if (!isExists)
                            {
                                ProIngre.BaseUOMId = item.BaseUOMId;
                            }
                        }
                        //======
                        model.ListItem.Add(ProIngre);
                    }
                    model.ListItem = model.ListItem.OrderByDescending(x => x.IsSelect ? 1 : 0).ThenBy(x => x.IngredientName).ToList();
                }
            }

            return(PartialView("_TableChooseIngredient", model));
        }