Exemple #1
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));
        }
Exemple #2
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));
        }