public PayrollResponse GetAllPayrolls(PayrollSearchRequest payrollSearchRequest)
        {
            int fromRow = (payrollSearchRequest.PageNo - 1) * payrollSearchRequest.PageSize;
            int toRow   = payrollSearchRequest.PageSize;

            if (payrollSearchRequest.Date.Year.Equals(1))
            {
                payrollSearchRequest.Date = DateTime.UtcNow;
            }
            Expression <Func <EmployeePayroll, bool> > query =
                s =>
                (
                    (payrollSearchRequest.EmployeeId == 0 || payrollSearchRequest.EmployeeId.Equals(s.EmployeeId)) &&
                    ((payrollSearchRequest.Date.Month.Equals(s.AllowanceMonth.Month) && (payrollSearchRequest.Date.Year.Equals(s.AllowanceMonth.Year))))
                );

            var basicSalaryId = Convert.ToInt64(ConfigurationManager.AppSettings["BasicSalaryId"].ToString());
            IEnumerable <PayRollGroupByModel> payrolls = payrollSearchRequest.IsAsc
                ? DbSet
                                                         .Where(query)
                                                         .OrderBy(orderClause[payrollSearchRequest.OrderByColumn])
                                                         .Skip(fromRow)
                                                         .Take(toRow)
                                                         .GroupBy(x => new { x.EmployeeId })
                                                         .Select(x => new PayRollGroupByModel
            {
                EmployeeId      = x.Key.EmployeeId,
                TotalAllowances = x.Where(y => y.AllowanceTypeId != basicSalaryId).Sum(z => z.Amount),
                EmployeeName    = x.First().Employee.FullName,
                AllowanceDate   = x.First().AllowanceMonth,
                BasicSalary     = x.First(y => y.AllowanceTypeId.Equals(basicSalaryId)).Amount,
                TotalAmount     = x.Sum(y => y.Amount)
            })
                                                         .ToList()
                : DbSet
                                                         .Where(query)
                                                         .OrderBy(orderClause[payrollSearchRequest.OrderByColumn])
                                                         .GroupBy(x => new { x.EmployeeId })
                                                         .Select(x => new PayRollGroupByModel
            {
                EmployeeId      = x.Key.EmployeeId,
                TotalAllowances = x.Where(y => y.AllowanceTypeId != basicSalaryId).Sum(z => z.Amount),
                EmployeeName    = x.First().Employee.FullName,
                AllowanceDate   = x.First().AllowanceMonth,
                BasicSalary     = x.First(y => y.AllowanceTypeId.Equals(basicSalaryId)).Amount,
                TotalAmount     = x.Sum(y => y.Amount)
            })
                                                         .Skip(fromRow)
                                                         .Take(toRow)
                                                         .ToList();

            return(new PayrollResponse {
                EmployeePayrollGroupBy = payrolls.ToList(), TotalCount = DbSet.Count(query), FilteredCount = DbSet.Count(query)
            });
        }
Ejemplo n.º 2
0
        public JsonResult Index(PayrollSearchRequest searchRequest)
        {
            if (!(User.IsInRole("Admin") || User.IsInRole("HR")))
            {
                searchRequest.EmployeeId = (int)Session["EmployeeID"];
            }
            var payrollResponse = payrollService.GetAllPayrolls(searchRequest);
            var payrollList     = payrollResponse.EmployeePayrollGroupBy.ToList().Select(x => x.CreatePayRollFromServerToClient()).ToList();
            var model           = new PayrollListViewModel
            {
                data            = payrollList,
                recordsFiltered = payrollResponse.FilteredCount,
                recordsTotal    = payrollResponse.TotalCount
            };

            //var obj = new {data = model.EmployeePayrolls, model};
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
 public PayrollListViewModel()
 {
     //EmployeePayrolls=new List<EmployeePayrollModel>();
     PayrollSearchRequest = new PayrollSearchRequest();
     data = new List <PayRollListWebModel>();
 }
Ejemplo n.º 4
0
        public PayrollResponse GetAllPayrolls(PayrollSearchRequest searchRequest)
        {
            var payrolls = payrollRepository.GetAllPayrolls(searchRequest);

            return(payrolls);
        }