public ActionResult Preferences() { //Run auto meal scheduler Tasks task = new Tasks(); task.autoScheduler(); if (Session["user"] != null) { UserSessionModel session = (UserSessionModel)Session["user"]; if (session.acctype == "m") { string response = ""; PreferencesModel pm = new PreferencesModel(); pm.getPrefrences(); if (pm.response == "500") { response = "e"; } else { response = "s"; ViewBag.MealRate = pm.mealrate; ViewBag.ServiceCharge = pm.servicecharge; } ViewBag.PrefResponse = response; ViewBag.ManagerName = getManagerName(); return(View()); } else { return(RedirectToAction("UserLogin", "User")); } } else { return(RedirectToAction("UserLogin", "User")); } }
private void processReport(string month, string year) { //Get all users string response = ""; UsersModel usm = new UsersModel(); List <UsersModel> usList = new List <UsersModel>(); //Get preferences PreferencesModel pm = new PreferencesModel(); pm.getPrefrences(); foreach (UsersModel user in usm.getAllUsers()) { usList.Add(user); } if (usm.response == "500") { response = "e"; } else { response = "s"; int totalMeals = 0; int totalMealCost = 0; int serviceCharge = 0; int totalCost = 0; string showing = ""; string costInfo = ""; string details = ""; //Check for valid date input bool isValid = false; string date = year + "-" + month + "-01"; DateTime dt2; if (DateTime.TryParse(date, out dt2)) { isValid = true; int inM = (int)dt2.Month; int inY = (int)dt2.Year; month = inM.ToString(); year = inY.ToString(); } else { isValid = false; } //Get member's meal info foreach (UsersModel u in usList) { List <SelfMealsModel> smList = new List <SelfMealsModel>(); List <GuestMealsModel> gmList = new List <GuestMealsModel>(); SelfMealsModel smm = new SelfMealsModel(); GuestMealsModel gmm = new GuestMealsModel(); smm.memberId = u.id; gmm.memberId = u.id; foreach (SelfMealsModel sm in smm.getAllMealByMemberId()) { smList.Add(sm); } foreach (GuestMealsModel gm in gmm.getAllGuestMealByMemberId()) { gmList.Add(gm); } //List by month and year List <SelfMealsModel> smlistByMonth = new List <SelfMealsModel>(); List <GuestMealsModel> gmlistByMonth = new List <GuestMealsModel>(); //List by month if (isValid) { showing = getMonth(month) + ", " + year; //Get self list by month foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } else { //Get list by current month showing = "Current Month"; month = getCurrentMonth(); year = getCurrentYear(); foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } //Get totals int totalSelf = 0; int totalGuest = 0; foreach (SelfMealsModel s in smlistByMonth) { if (s.breakfast == "1") { totalSelf++; } if (s.lunch == "1") { totalSelf++; } if (s.dinner == "1") { totalSelf++; } } //Calculate guest meals foreach (GuestMealsModel g in gmlistByMonth) { if (g.breakfast == "1") { totalGuest++; } if (g.lunch == "1") { totalGuest++; } if (g.dinner == "1") { totalGuest++; } } //Process subtotal details int subTotalMeals = totalSelf + totalGuest; int subTotalCost = int.Parse(pm.mealrate) * subTotalMeals; details = details + "<tr>" + "<td>" + u.fullname + "</td>" + "<td>" + subTotalMeals + "</td>" + "<td>" + subTotalCost + " Tk</td>" + "</tr>"; ViewBag.Details = details; //Process total cost info totalMeals = totalMeals + subTotalMeals; totalMealCost = totalMealCost + subTotalCost; serviceCharge = serviceCharge + int.Parse(pm.servicecharge); } //Process info totalCost = totalMealCost + serviceCharge; costInfo = costInfo + "<h3 class='text-danger'>Total Meal: <span class='text-success'>" + totalMeals + "</span></h3>" + "<h3 class='text-danger'>Meal Rate: <span class='text-success'>" + pm.mealrate + " Tk</span></h3>" + "<h3 class='text-danger'>Total Meal Cost: <span class='text-success'>" + totalMealCost + " Tk</span></h3>" + "<h3 class='text-danger'>Service Charge: <span class='text-success'>" + serviceCharge + " Tk</span></h3><hr />" + "<h3 class='text-danger'>Total Cost: <span class='text-success'>" + totalCost + " Tk</span></h3>"; ViewBag.CostInfo = costInfo; ViewBag.Showing = showing; } ViewBag.ReportResponse = response; }
private void processReport(string month, string year) { //Get all meals string response = ""; List <SelfMealsModel> smList = new List <SelfMealsModel>(); List <GuestMealsModel> gmList = new List <GuestMealsModel>(); SelfMealsModel smm = new SelfMealsModel(); GuestMealsModel gmm = new GuestMealsModel(); UserSessionModel usm = (UserSessionModel)Session["user"]; smm.memberId = usm.userid; gmm.memberId = usm.userid; foreach (SelfMealsModel sm in smm.getAllMealByMemberId()) { smList.Add(sm); } foreach (GuestMealsModel gm in gmm.getAllGuestMealByMemberId()) { gmList.Add(gm); } //Get preferences PreferencesModel pm = new PreferencesModel(); pm.getPrefrences(); if (smm.response == "500" || gmm.response == "500" || pm.response == "500") { response = "e"; } else { response = "s"; string showing = ""; string mealInfo = ""; string costInfo = ""; string details = ""; bool isValid = false; List <SelfMealsModel> smlistByMonth = new List <SelfMealsModel>(); List <GuestMealsModel> gmlistByMonth = new List <GuestMealsModel>(); //Check for valid date input string date = year + "-" + month + "-01"; DateTime dt2; if (DateTime.TryParse(date, out dt2)) { isValid = true; int inM = (int)dt2.Month; int inY = (int)dt2.Year; month = inM.ToString(); year = inY.ToString(); } else { isValid = false; } //List by month if (isValid) { showing = getMonth(month) + ", " + year; //Get self list by month foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } else { //Get list by current month showing = "Current Month"; month = getCurrentMonth(); year = getCurrentYear(); foreach (SelfMealsModel item in smList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { smlistByMonth.Add(item); } } //Get guest list by month foreach (GuestMealsModel item in gmList) { DateTime dt = DateTime.ParseExact(item.date, "dd/MM/yyyy", null); int m = (int)dt.Month; int y = (int)dt.Year; string dbYear = y.ToString(); string dbMonth = m.ToString(); if (dbMonth == month && dbYear == year) { gmlistByMonth.Add(item); } } } //Get totals int totalSelf = 0; int totalGuest = 0; foreach (SelfMealsModel s in smlistByMonth) { int countB = 0; int countL = 0; int countD = 0; int subTotal = 0; int selfB = 0; int selfL = 0; int selfD = 0; if (s.breakfast == "1") { selfB++; } if (s.lunch == "1") { selfL++; } if (s.dinner == "1") { selfD++; } totalSelf = totalSelf + selfB + selfL + selfD; subTotal = subTotal + selfB + selfL + selfD; countB = countB + selfB; countL = countL + selfL; countD = countD + selfD; //Calculate guest meals string d = s.date; foreach (GuestMealsModel g in gmlistByMonth) { int guestB = 0; int guestL = 0; int guestD = 0; if (g.date == d) { if (g.breakfast == "1") { guestB++; } if (g.lunch == "1") { guestL++; } if (g.dinner == "1") { guestD++; } totalGuest = totalGuest + guestB + guestL + guestD; subTotal = subTotal + guestB + guestL + guestD; countB = countB + guestB; countL = countL + guestL; countD = countD + guestD; } } details = details + "<tr>" + "<td>" + d + "</td>" + "<td>" + countB + "</td>" + "<td>" + countL + "</td>" + "<td>" + countD + "</td>" + "<td>" + subTotal + "</td>" + "</tr>"; } //Generate results int totalMeal = totalSelf + totalGuest; mealInfo = "<p><b>Total Meal: <span class='text-success'>" + totalMeal + "</span></b></p>" + "<p><b>Self: <span class='text-success'>" + totalSelf + "</span></b></p>" + "<p><b>Guest: <span class='text-success'>" + totalGuest + "</span></b></p>"; int mealRate = int.Parse(pm.mealrate.Trim()); int serviceCharge = int.Parse(pm.servicecharge.Trim()); int totalMealCost = totalMeal * mealRate; int totalCost = totalMealCost + serviceCharge; costInfo = "<p><b>Meal rate: <span class='text-success'>" + pm.mealrate + " Tk/person</span></b></p>" + "<p><b>Meal cost: <span class='text-success'>" + totalMealCost + " Tk</span></b></p>" + "<p><b>Service charge: <span class='text-success'>" + pm.servicecharge + " Tk/person</span></b></p>" + "<p><b>Total cost: <span class='text-success'>" + totalCost + " Tk</span></b></p>"; ViewBag.Showing = showing; ViewBag.CostInfo = costInfo; ViewBag.Info = mealInfo; ViewBag.Details = details; } ViewBag.ReportResponse = response; }