//GET:show the view of AdjustmentVouchers public IActionResult Index() { if (HttpContext.User.IsInRole("clerk")) { MyUser user = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).ToList().FirstOrDefault(); int userID = user.UserId; List <AdjustmentVoucher> originalList = _context.AdjustmentVoucher.Include(a => a.User).Where(b => b.UserId == userID).ToList(); List <newAVModel> anotherList = new List <newAVModel>(); foreach (AdjustmentVoucher abc in originalList) { int TotalPrice = 0; List <AVDetails> subList = _context.Avdetails.Include(x => x.Item).Where(a => a.AdjustId == abc.AdjustId).ToList(); for (int i = 0; i < subList.Count(); i++) { int onePrice = 0; if (subList[i].Qtychanged == null) { subList[i].Qtychanged = 0; } onePrice = (int)subList[i].Qtychanged * (int)subList[i].Item.Unitprice; TotalPrice = TotalPrice + onePrice; } newAVModel oaky = new newAVModel(); oaky.AdjustId = abc.AdjustId; oaky.UserName = abc.User.Name; oaky.Status = abc.Status; oaky.Amount = TotalPrice; anotherList.Add(oaky); } return(View(anotherList.ToList())); } else { return(NotFound()); } }
//GET: Pending,for manager or supervisor to view the pending requests. public async Task <IActionResult> Pending() { if (HttpContext.User.IsInRole("manager") || HttpContext.User.IsInRole("supervisor")) { MyUser user = _context.MyUser.Where(p => p.Email == HttpContext.User.Identity.Name).Include(p => p.Dept).ToList().FirstOrDefault(); int? deptheadDEPTID = user.DeptId; var sSISContext = _context.AdjustmentVoucher.Include(r => r.User).Where(d => d.User.DeptId == deptheadDEPTID && d.Status != "Pending"); var sSISContext1 = _context.Avdetails.Include(r => r.Item); List <AdjustmentVoucher> avlist = await sSISContext.ToListAsync(); List <newAVModel> managerList = new List <newAVModel>(); List <newAVModel> supervisorList = new List <newAVModel>(); List <AVDetails> avdlist = await sSISContext1.ToListAsync(); foreach (AdjustmentVoucher a in avlist) { int total = 0; foreach (AVDetails avd in avdlist) { if (avd.AdjustId == a.AdjustId) { if (avd.Qtychanged == null) { avd.Qtychanged = 0; } total += (int)avd.Item.Unitprice * (int)avd.Qtychanged; } } if (total > 250) { newAVModel nw = new newAVModel(); nw.AdjustId = a.AdjustId; nw.Amount = total; nw.Status = a.Status; nw.UserName = a.User.Name; managerList.Add(nw); } else if (total < 250) { newAVModel nw = new newAVModel(); nw.AdjustId = a.AdjustId; nw.Amount = total; nw.Status = a.Status; nw.UserName = a.User.Name; supervisorList.Add(nw); } //Assume that 250 is the absolute changing number,not the total earn or lost. } if (HttpContext.User.IsInRole("manager")) { return(View(managerList)); } else if (HttpContext.User.IsInRole("supervisor")) { return(View(supervisorList)); } return(View(await sSISContext.ToListAsync())); } else { return(NotFound()); } }