public ViewResult SalaryAdvance(int?branchId, int?DepartmentId) { IEnumerable <SalaryAdvanceViewModel> q = SalaryAdvanceRepository.GetAllvwSalaryAdvance() .Select(item => new SalaryAdvanceViewModel { Id = item.Id, CreatedUserId = item.CreatedUserId, CreatedDate = item.CreatedDate, CodeAdvance = item.CodeAdvance, Pay = item.Pay, StaffId = item.StaffId, Status = item.Status, Name = item.Name, BranchDepartmentId = item.BranchDepartmentId, BranchName = item.BranchName, Sale_BranchId = item.Sale_BranchId, Staff_DepartmentId = item.Staff_DepartmentId }).ToList(); if (branchId != null && branchId.Value > 0) { q = q.Where(item => item.Sale_BranchId == branchId).ToList(); } if (DepartmentId != null && DepartmentId.Value > 0) { q = q.Where(item => item.BranchDepartmentId == DepartmentId).ToList(); } q = q.OrderByDescending(x => x.CreatedDate).Take(10).ToList(); return(View(q)); }
public ViewResult Index(string Code, string Name, string CodeStaff, string Status, int?branchId, int?DepartmentId) { var start = Request["start"]; var end = Request["end"]; IEnumerable <SalaryAdvanceViewModel> q = SalaryAdvanceRepository.GetAllvwSalaryAdvance() .Select(item => new SalaryAdvanceViewModel { Id = item.Id, CreatedUserId = item.CreatedUserId, //CreatedUserName = item.CreatedUserName, CreatedDate = item.CreatedDate, ModifiedUserId = item.ModifiedUserId, //ModifiedUserName = item.ModifiedUserName, ModifiedDate = item.ModifiedDate, CodeAdvance = item.CodeAdvance, Pay = item.Pay, StaffId = item.StaffId, Status = item.Status, Name = item.Name, ProfileImage = item.ProfileImage, CodeStaff = item.CodeStaff, BranchDepartmentId = item.BranchDepartmentId, BranchName = item.BranchName, Sale_BranchId = item.Sale_BranchId, Staff_DepartmentId = item.Staff_DepartmentId, Note = item.Note, DayAdvance = item.DayAdvance }).ToList(); if (!string.IsNullOrEmpty(Code)) { q = q.Where(item => Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(item.CodeAdvance).ToLower().Contains(Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(Code).ToLower())); } if (!string.IsNullOrEmpty(CodeStaff)) { q = q.Where(item => Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(item.CodeStaff).ToLower().Contains(Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(CodeStaff).ToLower())); } if (!string.IsNullOrEmpty(Name)) { q = q.Where(item => Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(item.Name).ToLower().Contains(Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(Name).ToLower())); } if (!string.IsNullOrEmpty(Status)) { q = q.Where(item => item.Status == Status); } if (branchId != null && branchId.Value > 0) { q = q.Where(item => item.Sale_BranchId == branchId); } if (DepartmentId != null && DepartmentId.Value > 0) { q = q.Where(item => item.BranchDepartmentId == DepartmentId); } if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end)) { DateTime start_d; if (DateTime.TryParseExact(start, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out start_d)) { DateTime end_d; if (DateTime.TryParseExact(end, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out end_d)) { end_d = end_d.AddHours(23); q = q.Where(x => start_d <= x.CreatedDate && x.CreatedDate <= end_d); } } } var user = userRepository.GetUserById(WebSecurity.CurrentUserId); //admin thì load toàn bộ dữ liệu các chi nhánh. if (user.UserTypeId == 1) { q = q.OrderByDescending(m => m.ModifiedDate); } else { //nếu có quyền thêm mới mà ko phải admin thì load dữ liệu theo chi nhánh người đăng nhập // ngược lại thì load dữ liệu theo người tạo. if (Erp.BackOffice.Filters.SecurityFilter.AccessRight("Create", "SalaryAdvance", "Staff")) { var a = q; q = q.Where(x => x.Status != App_GlobalResources.Wording.StatusSalaryAdvance_Cancel && x.Sale_BranchId == user.BranchId); a = a.Where(x => x.Status == App_GlobalResources.Wording.StatusSalaryAdvance_Cancel && x.CreatedUserId == user.Id); q = q.Union(a).OrderByDescending(m => m.ModifiedDate); } else { q = q.Where(x => x.Status != App_GlobalResources.Wording.StatusSalaryAdvance_Cancel && x.Sale_BranchId == user.BranchId).OrderByDescending(m => m.ModifiedDate); } } ViewBag.User = user.Id; ViewBag.SuccessMessage = TempData["SuccessMessage"]; ViewBag.FailedMessage = TempData["FailedMessage"]; ViewBag.AlertMessage = TempData["AlertMessage"]; return(View(q)); }