public IActionResult Index(PayrollSearchViewModel searchModel) { if (searchModel.DateRange == null) { searchModel.DateRange = new Areas.Admin.Models.DateRangeViewModel() { StrDate = DateTime.Now.AddDays(-7), EndDate = DateTime.Now }; } searchModel.EmpId = searchModel.EmpId == null ? "" : searchModel.EmpId; var list = (from pay in _db.Tblpayroll join e in _db.Tblemployee on pay.EmpId equals e.EmpId join d in _db.Tbldeparment on e.DepId equals d.DepId where pay.YyyMm == searchModel.DateRange.StrDate.ToString("yyyyMM") && e.EmpId.Contains(searchModel.EmpId) select new DetailsPayrollViewModel() { dpayroll = pay, DepNm = d.DepNm, EmpNm = e.EmpNm }).ToList(); ViewData["list_details"] = list; return(View(searchModel)); }
public ActionResult Search(string date = "", int employeeId = 0, int companyId = 0) { //get the last 3 months cutoffs var payrollDates = _payrollService.GetPayrollDates(6); var viewModel = new PayrollSearchViewModel { PayrollDates = payrollDates.Select(x => new SelectListItem { Text = x.FormattedDate, Value = x.SerializedDate }), EmployeeId = employeeId }; if (date != "") { var dates = date.Split('-'); var startDate = dates[0].DeserializeDate(); var endDate = dates[1].DeserializeDate(); var employeePayrollPerCompany = _employeePayrollService.GetByDateRange(startDate, endDate); if (employeeId > 0) { employeePayrollPerCompany = employeePayrollPerCompany.Where(x => x.EmployeeId == employeeId).ToList(); viewModel.EmployeeName = employeePayrollPerCompany.Any() ? employeePayrollPerCompany.First().Employee.FullName : ""; } if (companyId > 0) { employeePayrollPerCompany = employeePayrollPerCompany.Where(x => x.CompanyId == companyId).ToList(); viewModel.CompanyName = employeePayrollPerCompany.Any() ? employeePayrollPerCompany.First().Company.CompanyName : ""; viewModel.CompanyId = companyId; } var payrolls = MapEmployeePayrollToViewModel(employeePayrollPerCompany); var pagination = _webService.GetPaginationModel(Request, payrolls.Count()); viewModel.Payrolls = _webService.TakePaginationModel(payrolls, pagination); viewModel.Date = date; viewModel.Pagination = pagination; ViewBag.StartDate = startDate; ViewBag.EndDate = endDate; } return(View(viewModel)); }