public IActionResult CheckInventory() { InventoryAnalysis inventoryAnalysis = new InventoryAnalysis(); //ViewBag.getStore = // new Func<string, string>(getStore); return(View(inventoryAnalysis)); }
public IActionResult Index(string?Id) { int avgDay; int timeToShip; if (Id == null) { avgDay = 3; timeToShip = 100; } else { string[] str = Id.Split('_'); avgDay = Convert.ToInt32(str[0]); timeToShip = Convert.ToInt32(str[1]); } List <InventoryAnalysis> InventoryNeedRestock = new List <InventoryAnalysis>(); ViewBag.getProductName = new Func <int, string>(returnProductName); var product = _unitOfWork.Product.GetAll().Where(a => a.ReStock); foreach (Product prod in product) { if (prod.InventoryCount <= 0) { continue; } double NumOfAvgSell = 0; int Count = _unitOfWork.Order.GetAll().Where(a => a.ProductId == prod.Id && a.OrderStatus != SD.OrderStatusCancelled && a.UsDate.Date >= DateTime.Now.AddDays((avgDay * (-1))).Date&& a.UsDate.Date <= DateTime.Now.AddDays(-1).Date).Sum(a => a.Quantity); if (Count > 0) { NumOfAvgSell = (double)Count / avgDay; } if ((prod.MadeIn == SD.MadeInChina && (NumOfAvgSell * timeToShip) > (prod.InventoryCount + prod.OnTheWayInventory)) || (prod.MadeIn == SD.MadeInUSA && (NumOfAvgSell * 20) > prod.InventoryCount + prod.OnTheWayInventory)) { InventoryAnalysis InvObj = new InventoryAnalysis(); InvObj.ProductId = prod.Id; if (prod.MadeIn == SD.MadeInChina) { InvObj.MissingQuantity = (NumOfAvgSell * timeToShip) - (prod.InventoryCount + prod.OnTheWayInventory); } else { InvObj.MissingQuantity = (NumOfAvgSell * 20) - (prod.InventoryCount + prod.OnTheWayInventory); } InvObj.AvgSales = NumOfAvgSell; InvObj.Cost = prod.Cost; InvObj.InventoryCount = prod.InventoryCount; InvObj.OnTheWay = prod.OnTheWayInventory; InvObj.OwnByWarehouse = prod.OwnByWarehouse; InvObj.AvgDays = avgDay; InvObj.TimeToArrive = timeToShip; InventoryNeedRestock.Add(InvObj); } } return(View(InventoryNeedRestock)); }