Exemple #1
0
        public ActionResult Details(int id)
        {
            var viewModel = new PayrollDetailsViewModel();

            viewModel.Payroll      = _employeePayrollService.GetById(id);
            viewModel.Deductions   = _employeePayrollDeductionService.GetByPayroll(id);
            viewModel.PayrollItems = _employeePayrollItemservice.GetByPayrollId(id);
            viewModel.Adjustments  = _employeeAdjustmentService.GetByPayrollId(id);

            return(View(viewModel));
        }
        public ActionResult Edit(Int32 id)
        {
            PayrollDetailsViewModel lPayroll = new PayrollDetailsViewModel();

            lPayroll.EmployeePayrolls = new List <EmployeePayrollViewModel>();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Payroll lFindPayroll = db.Payroll.Find(id);
                if (lFindPayroll != null)
                {
                    List <PayrollDetails> lFindDetails = lFindPayroll.Details.ToList();
                    lFindDetails.ForEach(x =>
                    {
                        EmployeePayrollViewModel lEmployeeDetails = new EmployeePayrollViewModel();
                        lEmployeeDetails.EmployeeId    = x.EmployeeId;
                        lEmployeeDetails.Name          = $"{x.Employee.LastName}, {x.Employee.FirstName}";
                        lEmployeeDetails.PayRateType   = x.Employee.RateType.ToString();
                        lEmployeeDetails.PayRate       = x.Employee.Rate;
                        lEmployeeDetails.StandardHours = x.HoursStandardWorked;
                        lEmployeeDetails.OvertimeHours = x.HoursOvertimeWorked;
                        lEmployeeDetails.Deductions    = x.Deductions;

                        if (x.Employee.RateType == PayRateType.Hourly)
                        {
                            lEmployeeDetails.GrossPay = ((x.HoursStandardWorked * x.Employee.Rate) + (1.5M * x.Employee.Rate * x.HoursOvertimeWorked)) - x.Deductions;
                        }
                        else
                        {
                            lEmployeeDetails.GrossPay = ((x.Employee.Rate / 2080) * 40) - x.Deductions;
                        }

                        lEmployeeDetails.NetPay = lEmployeeDetails.GrossPay - lEmployeeDetails.Deductions;
                        lPayroll.EmployeePayrolls.Add(lEmployeeDetails);
                    });
                }
            }

            return(View("EditPayroll", lPayroll));
        }