Example #1
0
        public InventoryProducts FindProfitPerUnit(InventoryProducts inventoryProducts)//this works for new product thats added
        {
            var product = db.Products.Where(p => p.Id == inventoryProducts.ProductId).FirstOrDefault();

            inventoryProducts.ProfitToBeMadePerUnit = (product.PricePerUnitSelling - product.PricePerUnit);
            return(inventoryProducts);
        }
Example #2
0
        public InventoryProducts FindTotalValueOfProducts(InventoryProducts inventoryProducts)//this works for new product thats added
        {
            var product = db.Products.Where(p => p.Id == inventoryProducts.ProductId).FirstOrDefault();

            inventoryProducts.TotalValueOfProducts = (inventoryProducts.Units * product.PricePerUnit);
            return(inventoryProducts);
        }
Example #3
0
        public InventoryProducts FindHowMuchSold(InventoryProducts inventoryProducts)
        {
            var inventory            = db.Inventories.Where(i => i.Id == inventoryProducts.InventoryId).FirstOrDefault();
            var lastInventoryProduct = db.InventoryProducts.Where(l => l.InventoryId == inventory.LastInventoryId && l.ProductId == inventoryProducts.ProductId).FirstOrDefault();

            inventoryProducts.AmountSold = (lastInventoryProduct.Units - inventoryProducts.Units);
            return(inventoryProducts);
        }
Example #4
0
        // GET: InventoryProduct/Create
        public ActionResult Create(ProductViewModel productView, Inventory inventory)//comes here to create a new inventory
        {
            InventoryProducts inventoryProducts = new InventoryProducts();

            if (productView.ProductName == null)
            {
                LoopToAssignValuesToProductInventory(inventoryProducts, inventory);
                //return RedirectToAction("Index", "Inventory");
                return(RedirectToAction("SelectedInventoryDetails", "Inventory", inventory));
            }
            return(View(inventoryProducts));//For Initial Creation Only
        }
        // GET: SMS
        public ActionResult SendSms(InventoryProducts inventoryProducts)
        {
            TwilioClient.Init(PrivateKeys.AccountSID, PrivateKeys.AuthToken);

            var message = MessageResource.Create(
                body: inventoryProducts.ProductName + ", is under Par level of " + inventoryProducts.ParLevel + ". Please make sure to add it to your order.",
                from: new Twilio.Types.PhoneNumber(PrivateKeys.TwilioPhoneNumber),
                to: new Twilio.Types.PhoneNumber(PrivateKeys.MyPhoneNumber)
                );
            var inventory = db.Inventories.Where(i => i.Id == inventoryProducts.InventoryId).FirstOrDefault();

            return(RedirectToAction("SelectedInventoryDetails", "Inventory", inventory));
        }
Example #6
0
        public IHttpActionResult CreateInventory(NewInventoryViewModel NewInventory)
        {
            var InventoryName = _Context.Inventories.Where(a => NewInventory.Name.Contains(a.Name));

            if (InventoryName == null)
            {
                return(BadRequest());
            }


            var Inventory = new Inventory
            {
                Name = NewInventory.Name
            };

            _Context.Inventories.Add(Inventory);

            var Products = _Context.Products.Where(p => NewInventory.ProductIds.Contains(p.Id)).ToList();
            int i        = 0;

            foreach (var Product in Products)
            {
                var quantity = NewInventory.Quantity[i];

                Product.QuantityInStock -= quantity;

                if (Product.QuantityInStock < 0)
                {
                    return(BadRequest());
                }

                var InventoryProducts = new InventoryProducts
                {
                    Inventory     = Inventory,
                    InventoryName = NewInventory.Name,
                    Product       = Product
                };

                _Context.InventoryProducts.Add(InventoryProducts);

                i += 1;
            }

            _Context.SaveChanges();

            return(Ok());
        }
Example #7
0
 public ActionResult Edit(int id, InventoryProducts inventoryProducts)
 {
     if (ModelState.IsValid)
     {
         var iP = db.InventoryProducts.Where(p => p.Id == inventoryProducts.Id).FirstOrDefault();
         iP.Units           = inventoryProducts.Units;
         iP                 = FindTotalValueOfProducts(iP);
         iP                 = FindProfitPerUnit(iP);
         iP                 = FindGMROI(iP);
         iP                 = FindParLevel(iP);
         iP                 = FindHowMuchSold(iP);
         iP.GetDate         = DateTime.Now.ToShortDateString();
         db.Entry(iP).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("CalcInventoryValue", "Inventory", iP));
     }
     return(RedirectToAction("Index", "Inventory"));
 }
Example #8
0
 public InventoryProducts FindParLevel(InventoryProducts inventoryProducts)
 {
     try
     {
         var inventory            = db.Inventories.Find(inventoryProducts.InventoryId);
         var oldInventory         = db.InventoryProducts.Where(ip => ip.InventoryId == inventory.LastInventoryId).ToList();
         var lastInventoryProduct = oldInventory.Where(r => r.ProductId == inventoryProducts.ProductId).First();
         var usage     = (lastInventoryProduct.Units - inventoryProducts.Units);
         var safetyNet = db.Products.Where(s => s.Id == lastInventoryProduct.ProductId).FirstOrDefault();
         var result    = (usage * safetyNet.ProductSafetyNet);
         inventoryProducts.ParLevel = (usage + result);
         return(inventoryProducts);
     }
     catch
     {
         return(inventoryProducts);
     }
 }
Example #9
0
 public InventoryProducts FindGMROI(InventoryProducts inventoryProducts)
 {
     try
     {
         var    product     = db.Products.Where(p => p.Id == inventoryProducts.ProductId).FirstOrDefault();
         double totalProfit = (product.PricePerUnitSelling * inventoryProducts.Units);
         if (totalProfit == 0)
         {
             inventoryProducts.GMROI = 0;
             return(inventoryProducts);
         }
         inventoryProducts.GMROI = Math.Round(totalProfit / inventoryProducts.TotalValueOfProducts, 2);
         return(inventoryProducts);
     }
     catch
     {
         return(inventoryProducts);
     }
 }
Example #10
0
        public ActionResult AddInventory(int id, InventoryProducts inventoryProducts)
        {
            if (ModelState.IsValid)
            {
                var ip = db.InventoryProducts.Where(p => p.Id == id).FirstOrDefault();
                ip.TimesOrdered++;
                ip.AmountOrdered += inventoryProducts.Units;
                ip.Units          = (ip.Units + inventoryProducts.Units);
                ip = FindTotalValueOfProducts(ip);
                ip = FindProfitPerUnit(ip);
                ip = FindGMROI(ip);
                //ip = FindParLevel(ip);
                ip.GetDate         = DateTime.Now.ToShortDateString();
                db.Entry(ip).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details"));
            }
            return(RedirectToAction("Details"));
        }
Example #11
0
        public ActionResult PastHistoricalDataForSpecificProduct(InventoryProducts inventoryProducts)//Shows the trends of selected product
        {
            inventoryProducts = db.InventoryProducts.Where(ip => ip.Id == inventoryProducts.Id).FirstOrDefault();
            var inventory               = db.Inventories.Where(i => i.Id == inventoryProducts.InventoryId).FirstOrDefault();
            var inventories             = db.Inventories.Where(i => i.BusinessId == inventory.BusinessId).ToList();
            var invProducts             = db.InventoryProducts.Where(ip => ip.ProductId == inventoryProducts.ProductId).ToList();
            List <DataPoint> dataPoints = new List <DataPoint> {
            };

            for (int i = 0; i < inventories.Count; i++)
            {
                if (invProducts[i].InventoryId == inventories[i].Id)
                {
                    dataPoints.Add(new DataPoint(invProducts[i].AmountSold, inventories[i].GetDate));
                }
            }
            ViewBag.DataPoints = JsonConvert.SerializeObject(dataPoints);
            ViewBag.Title      = JsonConvert.SerializeObject(inventoryProducts.ProductName + "'s Sold");
            ViewBag.Key        = true;
            return(View());
        }
Example #12
0
        public void LoopToAssignValuesToProductInventory(InventoryProducts inventoryProducts, Inventory inventory) //after create sent here to a ssign values
        {                                                                                                          //This assigns values to all of the product when the new inventoryProducts is instantiated
            inventoryProducts.InventoryId = inventory.Id;
            var products = db.InventoryProducts.Where(ip => ip.InventoryId == inventory.LastInventoryId).ToList();

            for (int i = 0; i < products.Count; i++)
            {
                inventoryProducts.InventoryId           = inventory.Id;
                inventoryProducts.ProductId             = products[i].ProductId;
                inventoryProducts.GetDate               = DateTime.Now.ToShortDateString();
                inventoryProducts.ProductName           = products[i].ProductName;
                inventoryProducts.ProfitToBeMadePerUnit = 0;
                inventoryProducts.Units = 0;
                inventoryProducts.TotalValueOfProducts = 0;
                inventoryProducts.TimesOrdered         = 0;
                inventoryProducts.AmountOrdered        = 0;//Add GMROI to 0
                db.InventoryProducts.Add(inventoryProducts);
                db.SaveChanges();
            }
            //return RedirectToAction("Index", "Inventory");
        }
        public ActionResult CalcInventoryValue(InventoryProducts inventoryProducts)//Running total calculation
        {
            var inventory = db.Inventories.Where(i => i.Id == inventoryProducts.InventoryId).FirstOrDefault();

            inventory.TotalInventoryWorth += inventoryProducts.TotalValueOfProducts;
            inventory.ProfitMargin        += (inventoryProducts.ProfitToBeMadePerUnit * inventoryProducts.Units);
            if (inventory.ProfitMargin == 0 && inventory.TotalInventoryWorth == 0)
            {
                inventory.GMROI = 0;
            }
            else if (inventory.ProfitMargin != 0 || inventory.TotalInventoryWorth != 0)
            {
                inventory.GMROI = Math.Round(inventory.ProfitMargin / inventory.TotalInventoryWorth, 2);
            }
            db.Entry(inventory).State = EntityState.Modified;
            db.SaveChanges();
            if (inventoryProducts.Units < inventoryProducts.ParLevel)
            {
                return(RedirectToAction("SendSms", "SMS", inventoryProducts));
            }
            return(RedirectToAction("SelectedInventoryDetails", inventory));
        }
Example #14
0
 public ActionResult Create(InventoryProducts inventoryProducts, ProductViewModel productView)//For Initial Creation Only
 {
     try
     {
         inventoryProducts.InventoryId = productView.InventoryId;
         inventoryProducts.ProductId   = productView.ProductId;
         inventoryProducts.GetDate     = DateTime.Now.ToShortDateString();
         inventoryProducts             = FindTotalValueOfProducts(inventoryProducts);
         inventoryProducts             = FindProfitPerUnit(inventoryProducts);
         inventoryProducts             = FindGMROI(inventoryProducts);
         db.InventoryProducts.Add(inventoryProducts);
         db.SaveChanges();
         var inventory = db.Inventories.Where(i => i.Id == productView.InventoryId).FirstOrDefault();
         inventory.TotalInventoryWorth += inventoryProducts.TotalValueOfProducts;
         inventory.ProfitMargin        += (inventoryProducts.ProfitToBeMadePerUnit * inventoryProducts.Units);
         db.Entry(inventory).State      = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Inventory"));
     }
     catch
     {
         return(View());
     }
 }