Пример #1
0
        private void UpdateStock(List <BillDetail> foods, List <BillDetail> toys, List <BillDetail> costumes)
        {
            CredentialModel credential = JsonConvert.DeserializeObject <CredentialModel>(HttpContext.Session.GetString(Constants.VM));
            string          token      = credential.JwToken;

            //HTTP PUT FOOD
            foreach (var food in foods)
            {
                // get Current Inventory for ProductID
                FoodProduct stockFood = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == food.ProductId);

                // update stock amount
                stockFood.FoodAmount -= food.ProductAmount;

                // request update
                GetApiFoodProducts.UpdateStock(stockFood, token);
            }

            //HTTP PUT TOY
            foreach (var toy in toys)
            {
                // get Current Inventory for ProductID
                ToyProduct stock = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == toy.ProductId);

                // update stock amount
                stock.ToyAmount -= toy.ProductAmount;

                // request update
                GetApiToyProducts.UpdateStock(stock, token);
            }

            //HTTP PUT COSTUME
            foreach (var costume in costumes)
            {
                // get Size of billDetail
                string size = costume.NoteSize;

                // get Current Inventory for ProductID
                CostumeProduct stock = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == costume.ProductId && p.CostumeSize == costume.NoteSize);

                // update stock amount
                stock.CostumeAmountSize -= costume.ProductAmount;

                // request update
                GetApiCostumeProducts.UpdateStock(stock, token);
            }
        }
Пример #2
0
        public IActionResult CancelBill(int billId)
        {
            //get credential
            CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM);
            //get token
            string token = credential.JwToken;

            // get bill and billdetail
            Bill bill = GetApiMyBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId);
            List <BillDetailModel> billDetails = GetBills().SingleOrDefault(p => p.BillId == bill.BillId).BillDetail;

            // Update status for bill want to be canceled
            bill.IsCancel = true;
            UpdateBill(bill, credential);

            // update amount
            foreach (var detail in billDetails)
            {
                if (IsFood(detail.ProductId))
                {
                    FoodProduct food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == detail.ProductId);
                    food.FoodAmount += detail.Amount;
                    GetApiFoodProducts.UpdateStock(food, token);
                }
                else if (IsToy(detail.ProductId))
                {
                    ToyProduct toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == detail.ProductId);
                    toy.ToyAmount += detail.Amount;
                    GetApiToyProducts.UpdateStock(toy, token);
                }
                else
                {
                    CostumeProduct costume = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == detail.ProductId && p.CostumeSize == detail.NoteSize);
                    costume.CostumeAmountSize += detail.Amount;
                    GetApiCostumeProducts.UpdateStock(costume, token);
                }
            }

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public int GetAmountProduct(string slugName, string size = null)
        {
            Product product = GetApiProducts.GetProducts().SingleOrDefault(p => p.SlugName == slugName);
            string  slugCat = GetApiCategories.GetCategories().SingleOrDefault(p => p.CategoryId == product.CategoryId).CategoryName;

            int amount = 0;

            switch (slugCat)
            {
            case Constants.FOOD:
                amount = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == product.ProductId).FoodAmount;
                break;

            case Constants.TOY:
                amount = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == product.ProductId).ToyAmount;
                break;

            case Constants.COSTUME:
                amount = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == product.ProductId && p.CostumeSize == size).CostumeAmountSize;
                break;
            }

            return(amount);
        }
Пример #4
0
        public IActionResult AddToInventoryRecieveItems(int productId)
        {
            List <InventoryRecieveItem> inventoryRecieveItems = IRItems;
            Product product = GetApiProducts.GetProducts().SingleOrDefault(p => p.ProductId == productId);
            string  slugCat = GetApiCategories.GetCategories().SingleOrDefault(p => p.CategoryId == product.CategoryId).CategoryName;

            List <InventoryRecieveItem> addItems = new List <InventoryRecieveItem>();

            switch (slugCat)
            {
            case Constants.FOOD:
                addItems = GetApiFoodProducts.GetFoodProducts().Where(p => p.ProductId == product.ProductId)
                           .Select(p => new InventoryRecieveItem()
                {
                    ProductId    = product.ProductId,
                    SubProductId = p.FoodId,
                    ProductName  = product.ProductName,
                    ProductImg   = product.ProductImage,
                    Size         = "",
                    Amount       = 0,
                    Price        = product.ProductPrice
                }).ToList();
                break;

            case Constants.TOY:
                addItems = GetApiToyProducts.GetToyProducts().Where(p => p.ProductId == product.ProductId)
                           .Select(p => new InventoryRecieveItem()
                {
                    ProductId    = product.ProductId,
                    SubProductId = p.ToyId,
                    ProductName  = product.ProductName,
                    ProductImg   = product.ProductImage,
                    Size         = "",
                    Amount       = 1,
                    Price        = product.ProductPrice
                }).ToList();
                break;

            case Constants.COSTUME:
                addItems = GetApiCostumeProducts.GetCostumeProducts().Where(p => p.ProductId == product.ProductId)
                           .Select(p => new InventoryRecieveItem()
                {
                    ProductId    = product.ProductId,
                    SubProductId = p.CostumeId,
                    ProductName  = product.ProductName,
                    ProductImg   = product.ProductImage,
                    Size         = p.CostumeSize,
                    Amount       = 1,
                    Price        = product.ProductPrice
                }).ToList();
                break;
            }

            // distinct data
            foreach (var item in addItems)
            {
                if (inventoryRecieveItems.SingleOrDefault(p => p.ProductId == item.ProductId &&
                                                          p.SubProductId == item.SubProductId &&
                                                          p.Size == item.Size) == null)
                {
                    inventoryRecieveItems.Add(item);
                }
            }

            HttpContext.Session.SetObject("inventoryRecieveItems", inventoryRecieveItems);
            return(PartialView(inventoryRecieveItems));
        }
Пример #5
0
        public IActionResult InventoryReceivingNoteDetail(int id)
        {
            CredentialManage            credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <InventoryRecieveItem> details    = new List <InventoryRecieveItem>();

            // get foods
            List <InventoryRecieveItem> detailForFoods = GetApiInventoryReceivingNoteDetailForFoods
                                                         .GetInventoryReceivingNoteDetailForFoods(credential.JwToken)
                                                         .Where(p => p.InventoryReceivingId == id)
                                                         .Select(p => new InventoryRecieveItem()
            {
                ProductId = GetApiFoodProducts.GetFoodProducts()
                            .SingleOrDefault(k => k.FoodId == p.FoodProductId).ProductId,
                ProductName = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiFoodProducts.GetFoodProducts()
                                                                                                .SingleOrDefault(k => k.FoodId == p.FoodProductId).ProductId)).ProductName,
                SubProductId = p.FoodProductId,
                ProductImg   = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiFoodProducts.GetFoodProducts()
                                                                                                 .SingleOrDefault(k => k.FoodId == p.FoodProductId).ProductId)).ProductImage,
                Amount = p.FoodProductAmount,
                Size   = "",
                Price  = p.FoodProductPrice
            }).ToList();

            List <InventoryRecieveItem> detailForToys = GetApiInventoryReceiveNoteDetailForToys
                                                        .GetInventoryReceivingNoteDetailForToys(credential.JwToken)
                                                        .Where(p => p.InventoryReceivingId == id)
                                                        .Select(p => new InventoryRecieveItem()
            {
                ProductId = GetApiToyProducts.GetToyProducts()
                            .SingleOrDefault(k => k.ToyId == p.ToyProductId).ProductId,
                ProductName = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiToyProducts.GetToyProducts()
                                                                                                .SingleOrDefault(k => k.ToyId == p.ToyProductId).ProductId)).ProductName,
                SubProductId = p.ToyProductId,
                ProductImg   = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiToyProducts.GetToyProducts()
                                                                                                 .SingleOrDefault(k => k.ToyId == p.ToyProductId).ProductId)).ProductImage,
                Amount = p.ToyProductAmount,
                Size   = "",
                Price  = p.ToyProductPrice
            }).ToList();

            List <InventoryRecieveItem> detailForCostumes = GetApiInventoryReceiveNoteDetailForCostumes
                                                            .GetInventoryReceivingNoteDetailForCostumes(credential.JwToken)
                                                            .Where(p => p.InventoryReceivingId == id)
                                                            .Select(p => new InventoryRecieveItem()
            {
                ProductId = GetApiCostumeProducts.GetCostumeProducts()
                            .SingleOrDefault(k => k.CostumeId == p.CostumeProductId && k.CostumeSize == p.CostumeProductSize).ProductId,
                ProductName = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiCostumeProducts.GetCostumeProducts()
                                                                                                .SingleOrDefault(k => k.CostumeId == p.CostumeProductId && k.CostumeSize == p.CostumeProductSize).ProductId)).ProductName,
                SubProductId = p.CostumeProductId,
                ProductImg   = GetApiProducts.GetProducts().SingleOrDefault(h => h.ProductId == (GetApiCostumeProducts.GetCostumeProducts()
                                                                                                 .SingleOrDefault(k => k.CostumeId == p.CostumeProductId && k.CostumeSize == p.CostumeProductSize).ProductId)).ProductImage,
                Amount = p.CostumeProductAmount,
                Size   = p.CostumeProductSize,
                Price  = p.CostumeProductPrice
            }).ToList();

            details.AddRange(detailForFoods);
            details.AddRange(detailForToys);
            details.AddRange(detailForCostumes);

            InventoryReceivingNote note = GetApiInventoryReceiveNotes.GetInventoryReceivingNotes(credential.JwToken).SingleOrDefault(p => p.InventoryReceivingId == id);

            InventoryReceivingNoteDetailModelView inventoryReceivingNote = new InventoryReceivingNoteDetailModelView()
            {
                InventoryReceivingNote_ID  = note.InventoryReceivingId,
                InventoryReceivingNoteDate = note.InventoryReceivingDateReceiving,
                TotalPrice = note.InventoryReceivingTotalPrice,
                Details    = details
            };

            return(Json(inventoryReceivingNote));
        }
Пример #6
0
        public IActionResult SaveInventoryReceiveNote()
        {
            // get credential
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            //prepair data
            List <InventoryRecieveItem> inventoryRecieveItems  = IRItems;
            InventoryReceiveNoteModel   inventoryReceivingNote = new InventoryReceiveNoteModel()
            {
                InventoryReceivingDateReceiving = DateTime.Now,
                InventoryReceivingTotalPrice    = inventoryRecieveItems.Sum(p => p.Total)
            };

            // create inventory Receive Note
            InventoryReceivingNote createdReceivingNote = CreateInventoryReceiveNote(inventoryReceivingNote, credential.JwToken);

            // get list toy, food, costume
            List <InventoryReceivingNoteDetailForFood> noteDetailForFoods = inventoryRecieveItems
                                                                            .Where(p => IsFood(p.ProductId))
                                                                            .Select(p => new InventoryReceivingNoteDetailForFood()
            {
                InventoryReceivingId = createdReceivingNote.InventoryReceivingId,
                FoodProductId        = GetApiFoodProducts.GetFoodProducts()
                                       .SingleOrDefault(k => k.ProductId == p.ProductId).FoodId,
                FoodProductAmount = p.Amount,
                FoodProductPrice  = p.Price
            }).ToList();

            List <InventoryReceivingNoteDetailForToy> noteDetailForToys = inventoryRecieveItems
                                                                          .Where(p => IsToy(p.ProductId))
                                                                          .Select(p => new InventoryReceivingNoteDetailForToy()
            {
                InventoryReceivingId = createdReceivingNote.InventoryReceivingId,
                ToyProductId         = GetApiToyProducts.GetToyProducts()
                                       .SingleOrDefault(k => k.ProductId == p.ProductId).ToyId,
                ToyProductAmount = p.Amount,
                ToyProductPrice  = p.Price
            }).ToList();

            List <InventoryReceivingNoteDetailForCostume> noteDetailForCostumes = inventoryRecieveItems
                                                                                  .Where(p => IsCostume(p.ProductId))
                                                                                  .Select(p => new InventoryReceivingNoteDetailForCostume()
            {
                InventoryReceivingId = createdReceivingNote.InventoryReceivingId,
                CostumeProductId     = GetApiCostumeProducts.GetCostumeProducts()
                                       .SingleOrDefault(k => k.ProductId == p.ProductId && k.CostumeSize == p.Size).CostumeId,
                CostumeProductAmount = p.Amount,
                CostumeProductSize   = p.Size,
                CostumeProductPrice  = p.Price
            }).ToList();

            // create IR food list
            foreach (var food in noteDetailForFoods)
            {
                //create
                GetApiInventoryReceivingNoteDetailForFoods.Post(food, credential.JwToken);
                //update amount for product
                FoodProduct foodProduct = GetApiFoodProducts.GetFoodProducts()
                                          .SingleOrDefault(p => p.FoodId == food.FoodProductId);
                foodProduct.FoodAmount += food.FoodProductAmount;

                GetApiFoodProducts.UpdateStock(foodProduct, credential.JwToken);
            }

            // create IR toy list
            foreach (var toy in noteDetailForToys)
            {
                GetApiInventoryReceiveNoteDetailForToys.Post(toy, credential.JwToken);
                //update amount for product
                ToyProduct toyProduct = GetApiToyProducts.GetToyProducts()
                                        .SingleOrDefault(p => p.ToyId == toy.ToyProductId);
                toy.ToyProductAmount += toy.ToyProductAmount;

                GetApiToyProducts.UpdateStock(toyProduct, credential.JwToken);
            }

            // create IR costume list
            foreach (var costume in noteDetailForCostumes)
            {
                GetApiInventoryReceiveNoteDetailForCostumes.Post(costume, credential.JwToken);
                //update amount for product
                CostumeProduct costumeProduct = GetApiCostumeProducts.GetCostumeProducts()
                                                .SingleOrDefault(p => p.CostumeId == costume.CostumeProductId &&
                                                                 p.CostumeSize == costume.CostumeProductSize);
                costumeProduct.CostumeAmountSize += costume.CostumeProductAmount;

                GetApiCostumeProducts.UpdateStock(costumeProduct, credential.JwToken);
            }

            HttpContext.Session.Remove("inventoryRecieveItems");
            return(Json(createdReceivingNote));
        }
Пример #7
0
        public IActionResult ProductDetail(string slugCategory = null, string slugProductName = null)
        {
            //get category
            Category category = CategoryByName(slugCategory);

            ViewBag.CategoryName = category.CategoryName;

            // get product by slugname
            Product product = ProductBySlugName(slugProductName);

            // init
            FoodProduct           food    = new FoodProduct();
            List <CostumeProduct> costume = new List <CostumeProduct>();
            ToyProduct            toy     = new ToyProduct();

            ProductModelViewDetail res = new ProductModelViewDetail();

            if (slugCategory == "food")
            {
                food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == product.ProductId);
                res  = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    FoodExpiredDate    = food.FoodExpiredDate,
                    IsActivated        = product.IsActivated,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = food.FoodAmount
                };

                res.Rating = getRatingProduct(res.ProductId);
            }
            else if (slugCategory == "costume")
            {
                costume = GetApiCostumeProducts.GetCostumeProducts().Where(p => p.ProductId == product.ProductId).Select(p => new CostumeProduct()
                {
                    ProductId         = p.ProductId,
                    CostumeId         = p.CostumeId,
                    CostumeAmountSize = p.CostumeAmountSize,
                    CostumeSize       = p.CostumeSize
                }).ToList();

                res = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    IsActivated        = product.IsActivated,
                    FoodExpiredDate    = DateTime.Now,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = 0
                };

                res.CostumeSize = costume.Select(p => new CostumeSizeModel()
                {
                    CostumeSize       = p.CostumeSize,
                    CostumeAmountSize = p.CostumeAmountSize
                }).ToList();

                res.Rating = getRatingProduct(res.ProductId);
            }
            else
            {
                toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == product.ProductId);
                res = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    IsActivated        = product.IsActivated,
                    FoodExpiredDate    = DateTime.Now,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = toy.ToyAmount
                };

                res.Rating = getRatingProduct(res.ProductId);
            }

            return(View(res));
        }