public IActionResult admin(log_in log, [Optional] String date) { ViewBag.supliers_count = _context.Supliers.Count(); List <Suppliers> x = new List <Suppliers>(); //bind dropdown x = _context.Supliers.ToList(); x.Insert(0, new Suppliers { id = 0, Company_name = "--Select supplier--" }); ViewBag.Drop_sulier = x; expiries_set(); //LETS CALCULATE SHOP NET WORTH var get_all = _context.Shop_items.Where(x => x.Quantity > 0); int i, j; float sum = 0, total; j = get_all.Count(); foreach (var item in get_all) { sum = sum + (item.Quantity * item.Item_price); ViewBag.Net_worth = sum; } DateTime _date; string day; //SOLD ITEMS FOR TODAY List <sold_items> list_of_sold = _context.sold_items.Where(x => x.DateTime == today).ToList(); List <shop_items> list_of_brandss = _context.Shop_items.ToList(); List <join_sold_item> joinList1 = new List <join_sold_item>(); var results1 = (from pd in list_of_sold join od in list_of_brandss on pd.Item_id equals od.id select new { pd.DateTime, pd.quantity_sold, pd.Total_cash_made, od.Item_price, od.Item_name, pd.Total_Cost_cash, pd.id, pd.Item_id }).ToList(); foreach (var item in results1) { join_sold_item JoinObject = new join_sold_item(); JoinObject.Item_name = item.Item_name; JoinObject.Item_price = item.Item_price; JoinObject.DateTime = item.DateTime; JoinObject.quantity_sold = item.quantity_sold; JoinObject.Total_cash_made = item.Total_cash_made; JoinObject.Item_price = item.Item_price; JoinObject.Item_name = item.Item_name; JoinObject.Total_Cost_cash = item.Total_Cost_cash; JoinObject.Item_id = item.Item_id.ToString(); JoinObject.id = item.id; joinList1.Add(JoinObject); } var JoinListToViewbag1 = joinList1.ToList(); ViewBag.JoinList1 = JoinListToViewbag1; if (date == null) { //SOLD ITEMS FOR THE FIRST MODAL List <sold_items> list_of_sold_second = _context.sold_items.ToList(); List <shop_items> list_of_brands_second = _context.Shop_items.ToList(); List <join_sold_item> joinList_second = new List <join_sold_item>(); var results_second = (from pd in list_of_sold_second join od in list_of_brands_second on pd.Item_id equals od.id select new { pd.DateTime, pd.quantity_sold, pd.Total_cash_made, od.Item_price, od.Item_name, pd.Total_Cost_cash }).ToList(); foreach (var item in results_second) { join_sold_item JoinObject_second = new join_sold_item(); JoinObject_second.Item_name = item.Item_name; JoinObject_second.Item_price = item.Item_price; JoinObject_second.Total_Cost_cash = item.Total_Cost_cash; JoinObject_second.DateTime = item.DateTime; JoinObject_second.quantity_sold = item.quantity_sold; JoinObject_second.Total_cash_made = item.Total_cash_made; JoinObject_second.Item_price = item.Item_price; JoinObject_second.Item_name = item.Item_name; joinList_second.Add(JoinObject_second); } var JoinListToViewbag_second = joinList_second.ToList(); ViewBag.JoinList12 = JoinListToViewbag_second; } else { _date = DateTime.Parse(date); day = _date.ToString("dd/MM/yyyy"); //LETS COMPUTE IF COMMAND IS FILTER List <sold_items> list_of_sold_third = _context.sold_items.Where(x => x.DateTime == day).ToList(); List <shop_items> list_of_brands_third = _context.Shop_items.ToList(); List <join_sold_ite_filtered> joinList_third = new List <join_sold_ite_filtered>(); var results_third = (from pd in list_of_sold_third join od in list_of_brands_third on pd.Item_id equals od.id select new { pd.DateTime, pd.quantity_sold, pd.Total_cash_made, od.Item_price, od.Item_name, }).ToList(); foreach (var item in results_third) { join_sold_ite_filtered JoinObject_third = new join_sold_ite_filtered(); JoinObject_third.Item_name = item.Item_name; JoinObject_third.DateTime = item.DateTime; JoinObject_third.quantity_sold = item.quantity_sold; JoinObject_third.Total_cash_made = item.Total_cash_made; JoinObject_third.Item_price = item.Item_price; JoinObject_third.Item_name = item.Item_name; joinList_third.Add(JoinObject_third); } var JoinListToViewbag_third = joinList_third.ToList(); var count = joinList_third.Count(); var sum_of_cash = joinList_third.Sum(x => x.Total_cash_made); TempData["popup"] = 4; //TempData["popup"] = "2"; //TempData["popup"] = "Successfully working!"; TempData["message"] = count + " records found totaling to Ksh. " + sum_of_cash; TempData["total"] = sum_of_cash; ViewBag.JoinList_general_third = JoinListToViewbag_third; } ViewBag.allBrands = _context.Shop_items.Where(x => x.Quantity > 0).ToList(); ViewBag.allBrands_0 = _context.Shop_items.ToList(); ViewBag.id = HttpContext.Session.GetString("id"); ViewBag.count_below = _context.Shop_items.Count(x => x.Quantity <= 0); ViewBag.to_restock = _context.Shop_items.Where(x => x.Quantity <= 0); ViewBag.count_all = _context.Shop_items.Sum(x => x.Quantity); var sold = _context.sold_items.ToList(); if (sold.Count() == 0) { ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold); } else { ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold); } ViewBag.sold_general = _context.sold_items; ViewBag.shop_name = HttpContext.Session.GetString("shop_name"); ViewBag.name = HttpContext.Session.GetString("Name"); ViewBag.id = HttpContext.Session.GetString("id"); var phone = HttpContext.Session.GetString("phone"); //RESTOCKING ITEMS HISTORY List <Restock_history> list_of_restocked = _context.Restock_history.ToList(); List <shop_items> list_of_brands = _context.Shop_items.ToList(); List <join_tables> joinList = new List <join_tables>(); var shop_items = _context.Shop_items; var restock_item = _context.Restock_history; var results = (from pd in list_of_restocked join od in list_of_brands on pd.Item_id equals od.id select new { pd.Date_restock, pd.Prev_quantity, pd.new_quanity, od.Item_name, od.Item_price, pd.quantity, od.id, pd.Supplier, }).ToList(); foreach (var item in results) { join_tables JoinObject = new join_tables(); JoinObject.Item_id = item.id.ToString(); JoinObject.Item_name = item.Item_name; JoinObject.Item_price = item.Item_price; JoinObject.new_quanity = item.new_quanity; JoinObject.Prev_quantity = item.Prev_quantity; JoinObject.quantity = item.quantity; JoinObject.Supplier = item.Supplier; JoinObject.Date_restock = item.Date_restock; joinList.Add(JoinObject); } var JoinListToViewbag = joinList.ToList(); ViewBag.JoinList = JoinListToViewbag; //TempData["message"] = "success you have deleted the attendant successfully!"; //GETTING ALL BRANDS ViewBag.allBrands = _context.Shop_items.ToList(); // GETTING ALL ATTENDANTS //var phone = @User.Claims.FirstOrDefault(c => c.Type == "User_id").Value; ViewBag.all_attendants = _context.Log_in.Where(item => item.strRole == 2).ToList(); //var getting_quanity = _context.Shop_items.FirstOrDefault(); //ViewBag.stock=getting_quanity. var count_brand = _context.Shop_items.Count(); var count_below = _context.Shop_items.Where(x => x.Quantity < 0).Count(); if (count_below == null) { ViewBag.count_below = 0; } else { ViewBag.count_below = count_below; } //ViewBag.manager_name = _context.Log_in.Where(item=>item.id.ToString()==phone).ToList(); //TempData["popup"] = "2"; return(View()); }
public IActionResult attendant() { ViewBag.time = today; string printer = HttpContext.Request.Cookies["printer_name"]; ViewBag.printer = printer; expiries_set(); List <sold_items> list_of_sold = _context.sold_items.Where(x => x.DateTime == today).ToList(); List <shop_items> list_of_brands = _context.Shop_items.ToList(); List <join_sold_item> joinList = new List <join_sold_item>(); var results = (from pd in list_of_sold join od in list_of_brands on pd.Item_id equals od.id select new { pd.DateTime, pd.quantity_sold, pd.Total_cash_made, od.Item_price, od.Item_name, }).ToList(); foreach (var item in results) { join_sold_item JoinObject = new join_sold_item(); JoinObject.Item_name = item.Item_name; JoinObject.Item_price = item.Item_price; JoinObject.DateTime = item.DateTime; JoinObject.quantity_sold = item.quantity_sold; JoinObject.Total_cash_made = item.Total_cash_made; JoinObject.Item_price = item.Item_price; JoinObject.Item_name = item.Item_name; joinList.Add(JoinObject); } var JoinListToViewbag = joinList.ToList(); ViewBag.JoinList = JoinListToViewbag; ViewBag.allBrands = _context.Shop_items.Where(x => x.Quantity > 0).ToList(); ViewBag.allBrands_0 = _context.Shop_items.ToList(); ViewBag.count_below = _context.Shop_items.Count(x => x.Quantity <= 0); ViewBag.to_restock = _context.Shop_items.Where(x => x.Quantity <= 0); ViewBag.count_all = _context.Shop_items.Sum(x => x.Quantity); var sold = _context.sold_items.ToList(); if (sold.Count() == 0) { ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold); } else { ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold); } ViewBag.shop_name = HttpContext.Session.GetString("shop_name"); ViewBag.name = HttpContext.Session.GetString("Name"); ViewBag.phone = HttpContext.Session.GetString("phone"); ViewBag.id = HttpContext.Session.GetString("id"); var phone = HttpContext.Session.GetString("phone"); var pass = _context.Log_in.SingleOrDefault(z => z.Phone == phone); Random r = new Random(); ViewBag.Random = r.Next(1000000, 9999999); return(View()); }