public ActionResult PayLogData(int day = 0, int month = 0, int year = 0, int pay = 0, int type = 0, int page = 1, int total = 100) // thống kê nạp thẻ { if (page < 1) { return(new EmptyResult()); } day = day == 0 ? DateTime.Now.Day : day; month = month == 0 ? DateTime.Now.Month : month; year = year == 0 ? DateTime.Now.Year : year; var payLogs = PayDAO.GetAllPayLogs(); var filter = payLogs.Where(x => x.CreatedTime.Month == month && x.CreatedTime.Year == year && x.CreatedTime.Day == day); if (pay != 0) { filter = filter.Where(x => x.PayId == pay); } if (type != 0) { filter = filter.Where(x => x.CardType == type); } ViewBag.CurrentPage = page; ViewBag.TotalPage = Math.Ceiling(filter.Count() * 1.0 / total); // tổng số trang filter = filter.Skip((page - 1) * total).Take(total).OrderByDescending(x => x.CreatedTime); return(View(filter)); }
public ActionResult PayLogByDate(int month = 0, int year = 0, int pay = 0, int type = 0) { //if (page < 1) //{ // return new EmptyResult(); //} month = month == 0 ? DateTime.Now.Month : month; year = year == 0 ? DateTime.Now.Year : year; var payLogs = PayDAO.GetAllPayLogs(); var filter = payLogs.Where(x => x.CreatedTime.Month == month && x.CreatedTime.Year == year); if (pay != 0) { filter = filter.Where(x => x.PayId == pay); } if (type != 0) { filter = filter.Where(x => x.CardType == type); } var dateGroups = filter.GroupBy(x => x.CreatedTime.Date).OrderByDescending(x => x.Key); var datePayLogs = new List <DatePayLog>(); foreach (var dateGroup in dateGroups) { datePayLogs.Add(new DatePayLog() { DateString = dateGroup.Key.ToString("dd/MM/yyyy"), TotalSuccessTran = dateGroup.Count(x => x.Status == 1), TotalFailTran = dateGroup.Count(x => x.Status < 0), TotalPendingTran = dateGroup.Count(x => x.Status == 0), TotalTopup = dateGroup.Where(x => x.Status == 1).Sum(x => x.Amount) }); } ViewBag.TotalTopup = filter.Where(x => x.Status == 1).Sum(x => x.Amount); ViewBag.TotalSuccessTran = filter.Count(x => x.Status == 1); ViewBag.TotalFailTran = filter.Count(x => x.Status < 0); ViewBag.TotalPendingTran = filter.Count(x => x.Status == 0); //ViewBag.CurrentPage = page; //ViewBag.TotalPage = Math.Ceiling(datePayLogs.Count() * 1.0 / total); // tổng số trang //datePayLogs = datePayLogs.Skip((page - 1) * total).Take(total).ToList(); return(PartialView(datePayLogs)); }