public ActionResult Employees() { EmployeeListPayrollPeriodViewModel employeeListPayrollPeriod = new EmployeeListPayrollPeriodViewModel(); List <EmployeeListModel> employeeListModels = new List <EmployeeListModel>(); EmployeeListModel employee = new EmployeeListModel(); DepartmentBL department = new DepartmentBL(); List <UserPersonalInformation> listFromDB = employeeBL.GetAllEmployees(); PayrollPeriodBL payrollPeriodBL = new PayrollPeriodBL(); List <PayrollPeriod> payrollPeriods = new List <PayrollPeriod>(); payrollPeriods = payrollPeriodBL.GetPayrollPeriods(); foreach (UserPersonalInformation item in listFromDB) { employee = new EmployeeListModel(); employee.Active = Convert.ToBoolean(item.Active); employee.Address = item.Address; employee.EmployeeId = item.EmployeeId; employee.FirstName = item.FirstName; employee.LastName = item.LastName; employee.UserPersonalInformationID = item.UserPersonalInformationId; employee.Position = item.Position; employee.BasicPay = item.BasicPay; employee.Name = item.FirstName + " " + employee.LastName; if (item.DepartmentId > 0) { employee.Department = department.GetDepartmentById(item.DepartmentId).DepartmentName; } employeeListModels.Add(employee); } employeeListPayrollPeriod.EmployeeList = employeeListModels; employeeListPayrollPeriod.PayrollPeriods = new SelectList(payrollPeriods, "PayrollPeriodId", "PayPeriodFrom", 2); return(View(employeeListPayrollPeriod)); }
public ActionResult Index(int id) { PayrollPeriodBL payrollPeriodBL = new PayrollPeriodBL(); List <PayrollPeriod> payrollPeriods = new List <PayrollPeriod>(); payrollPeriods = payrollPeriodBL.GetPayrollPeriods(); PayrollTransactionsPeriodViewModels view = new PayrollTransactionsPeriodViewModels(); view.PayrollPeriods = new SelectList(payrollPeriods, "PayrollPeriodId", "PayPeriodFrom", 1); ViewBag.Id = id; return(View(view)); //PayrollTransactionBL payrollTransactionBL = new PayrollTransactionBL(); //PayrollPeriodBL payrollPeriodBL = new PayrollPeriodBL(); //EmployeeBL employeeBL = new EmployeeBL(); //AssingedEmployeeIncomeBL assingedEmployeeIncomeBL = new AssingedEmployeeIncomeBL(); //PayrollTransactionIncomeBL payrollTransactionIncomeBL = new PayrollTransactionIncomeBL(); //IncomeBL incomeBL = new IncomeBL(); ////PayrollTransaction payrollTransaction = new PayrollTransaction(); //List<PayrollPeriod> payrollPeriods = new List<PayrollPeriod>(); //PayrollPeriod payrollPeriod = new PayrollPeriod(); //List<PayrollTransactionIncome> payrollTransactionIncomes = new List<PayrollTransactionIncome>(); //PayrollTransactionIncome payrollTransactionIncome = new PayrollTransactionIncome(); //List<Income> incomes = new List<Income>(); //Income income = new Income(); //PayrollTransactionViewModels payrollTransactionsViewModels = new PayrollTransactionViewModels(); //List<PayrollTransactionIncomeViewModels> payrollTransactionIncomeViewModels = new List<PayrollTransactionIncomeViewModels>(); //PayrollTransactionIncomeViewModels payrollTransactionIncomeView = new PayrollTransactionIncomeViewModels(); //List<AssignedEmployeeIncome> assignedEmployeeIncomes = new List<AssignedEmployeeIncome>(); //AssignedEmployeeIncome assignedEmployeeIncome = new AssignedEmployeeIncome(); //payrollPeriods = payrollPeriodBL.GetPayrollPeriods(); //if (payrollPeriods != null) //{ // foreach (var item in payrollPeriods) // { // payrollPeriod = new PayrollPeriod(); // payrollPeriod.PayrollPeriodId = item.PayrollPeriodId; // break; // } // payrollTransactionsViewModels.PayrollPeriods = new SelectList(payrollPeriods, "PayrollPeriodId", "PayPeriodFrom", 1); // payrollTransactionsViewModels.UserPersonalInformationId = id; // //payrollTransaction = payrollTransactionBL.GetPayrollTransactionsByUserIdPayrollPeriodId(userPersonalInformationId, payrollPeriod.PayrollPeriodId); // int incomeId = 0; // payrollTransactionIncomes = payrollTransactionIncomeBL.GetAllPayrollTransactionIncomes(id, payrollPeriod.PayrollPeriodId); // if (payrollTransactionIncomes != null) // { // //i have an existing income // foreach (var item in payrollTransactionIncomes) // { // incomeId = 0; // payrollTransactionIncomeView = new PayrollTransactionIncomeViewModels(); // payrollTransactionIncomeView.CustomIncomeAmount = item.CustomIncomeAmount; // incomeId = item.IncomeId > 0 ? Convert.ToInt32(item.IncomeId) : 0; // income = incomeBL.GetIncomesById(incomeId); // payrollTransactionIncomeView.DefaultIncomeAmount = income.IncomeValue; // payrollTransactionIncomeView.IncomeId = incomeId; // payrollTransactionIncomeView.PayrollPeriodId = item.PayrollPeriodId; // payrollTransactionIncomeView.PayrollTransactionIncomeId = item.PayrollTransactionIncomeId; // payrollTransactionIncomeView.UserPersonalInformationid = item.UserPersonalInformationid; // payrollTransactionIncomeViewModels.Add(payrollTransactionIncomeView); // } // } // else // { // // i have an assigned income // assignedEmployeeIncomes = assingedEmployeeIncomeBL.GetAssignedEmployeeIncomes(id); // foreach (var item in assignedEmployeeIncomes) // { // incomeId = 0; // incomeId = item.IncomeId > 0 ? Convert.ToInt32(item.IncomeId) : 0; // income = incomeBL.GetIncomesById(incomeId); // payrollTransactionIncomeView = new PayrollTransactionIncomeViewModels(); // payrollTransactionIncomeView.DefaultIncomeAmount = income.IncomeValue; // payrollTransactionIncomeView.IncomeId = incomeId; // payrollTransactionIncomeView.CustomIncomeAmount = 0.0M; // payrollTransactionIncomeView.IncomeId = item.IncomeId; // payrollTransactionIncomeView.PayrollPeriodId = payrollPeriod.PayrollPeriodId; // payrollTransactionIncomeView.UserPersonalInformationid = item.UserPersonalInformationID; // payrollTransactionIncomeViewModels.Add(payrollTransactionIncomeView); // //insert in payrolltransactionsincome // payrollTransactionIncomeBL.InsertPayrollTransactionIncomes(payrollTransactionIncomeView); // } // } // payrollTransactionsViewModels.Incomes = payrollTransactionIncomeViewModels; //} //else //{ // ModelState.AddModelError("", "Create payroll periods first."); // return View(payrollTransactionsViewModels); //} //return View(payrollTransactionsViewModels); }
public ActionResult Payroll(FormCollection collection) { var payPeriodId = collection.GetValue("PayrollPeriodId").AttemptedValue; if (ModelState.IsValid) { if (payPeriodId.ToString().Length > 0) { List <EmployeeListModel> employeeListModels = new List <EmployeeListModel>(); EmployeeListModel employee = new EmployeeListModel(); DepartmentBL department = new DepartmentBL(); List <UserPersonalInformation> listFromDB = employeeBL.GetAllEmployees(); AssingedEmployeeIncomeBL assingedEmployeeIncomeBL = new AssingedEmployeeIncomeBL(); List <AssignedEmployeeIncomesViewModel> assignEmployeeIncomeViewModelList = new List <AssignedEmployeeIncomesViewModel>(); AssignedEmployeeIncomesViewModel assignEmployeeIncomeViewModel = new AssignedEmployeeIncomesViewModel(); List <Income> incomeDBList = new List <Income>(); Income incomeDB = new Income(); IncomeBL incomeBL = new IncomeBL(); PayrollPeriodBL payrollPeriodBL = new PayrollPeriodBL(); PayrollPeriod payrollPeriodDB = new PayrollPeriod(); List <Deduction> deductionDBList = new List <Deduction>(); Deduction deductionDB = new Deduction(); DeductionBL deductionBL = new DeductionBL(); List <PayrollTransactionIncome> payrollTransactionIncomes = new List <PayrollTransactionIncome>(); PayrollTransactionIncome payrollTransactionIncome = new PayrollTransactionIncome(); PayrollTransactionIncomeBL payrollTransactionIncomeBL = new PayrollTransactionIncomeBL(); PayrollTransactionDeduction payrollTransactionDeduction = new PayrollTransactionDeduction(); PayrollTransactionDeductionBL payrollTransactionDeductionBL = new PayrollTransactionDeductionBL(); List <PayrollTransactionDeductionViewModels> payrollTransactionDeductionViewModels = new List <PayrollTransactionDeductionViewModels>(); PayrollTransactionDeductionViewModels payrollTransactionDeductionViewModel = new PayrollTransactionDeductionViewModels(); List <PayrollTransactionIncomeViewModels> payrollTransactionIncomeViewModels = new List <PayrollTransactionIncomeViewModels>(); PayrollTransactionIncomeViewModels payrollTransactionIncomeViewModel = new PayrollTransactionIncomeViewModels(); foreach (UserPersonalInformation item in listFromDB) { employee = new EmployeeListModel(); employee.Active = Convert.ToBoolean(item.Active); employee.Address = item.Address; employee.EmployeeId = item.EmployeeId; employee.FirstName = item.FirstName; employee.LastName = item.LastName; employee.UserPersonalInformationID = item.UserPersonalInformationId; employee.Position = item.Position; employee.BasicPay = item.BasicPay; employee.Name = item.FirstName + " " + employee.LastName; #region incomes incomeDBList = incomeBL.GetActiveIncomes(); if (incomeDBList != null) { foreach (var dbIncome in incomeDBList) { payrollTransactionIncome = new PayrollTransactionIncome(); payrollTransactionIncome = payrollTransactionIncomeBL.GetPayrollTransactionIncome(item.UserPersonalInformationId, Convert.ToInt32(payPeriodId), dbIncome.IncomeId); if (payrollTransactionIncome != null) { payrollTransactionIncomeViewModel = new PayrollTransactionIncomeViewModels(); payrollTransactionIncomeViewModel.PayrollTransactionIncomeId = payrollTransactionIncome.PayrollTransactionIncomeId; payrollTransactionIncomeViewModel.UserPersonalInformationid = item.UserPersonalInformationId; payrollTransactionIncomeViewModel.PayrollPeriodId = Convert.ToInt32(payPeriodId); incomeDB = incomeBL.GetIncomesById(Convert.ToInt32(payrollTransactionIncome.IncomeId)); payrollTransactionIncomeViewModel.IncomeId = Convert.ToInt32(payrollTransactionIncome.IncomeId); payrollTransactionIncomeViewModel.CustomIncomeAmount = payrollTransactionIncome.CustomIncomeAmount > 0 ? Convert.ToDecimal(payrollTransactionIncome.CustomIncomeAmount) : 0.0M; //payrollTransactionIncomeViewModel.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; payrollTransactionIncomeViewModel.DefaultIncomeName = incomeDB.IncomeName; payrollTransactionIncomeViewModels.Add(payrollTransactionIncomeViewModel); } else { PayrollTransactionIncomeViewModels insertView = new PayrollTransactionIncomeViewModels(); insertView.CustomIncomeAmount = 0.0M; insertView.PayrollTransactionIncomeId = 0; insertView.UserPersonalInformationid = item.UserPersonalInformationId; incomeDB = incomeBL.GetIncomesById(Convert.ToInt32(dbIncome.IncomeId)); insertView.IncomeId = Convert.ToInt32(dbIncome.IncomeId); insertView.CustomIncomeAmount = 0.0M; //insertView.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; insertView.DefaultIncomeName = incomeDB.IncomeName; insertView.PayrollPeriodId = Convert.ToInt32(payPeriodId); payrollTransactionIncome = new PayrollTransactionIncome(); payrollTransactionIncome = payrollTransactionIncomeBL.InsertPayrollTransactionIncomes(insertView); insertView = new PayrollTransactionIncomeViewModels(); insertView.PayrollTransactionIncomeId = payrollTransactionIncome.PayrollTransactionIncomeId; insertView.UserPersonalInformationid = item.UserPersonalInformationId; insertView.PayrollPeriodId = Convert.ToInt32(payPeriodId); insertView.IncomeId = Convert.ToInt32(payrollTransactionIncome.IncomeId); insertView.CustomIncomeAmount = payrollTransactionIncome.CustomIncomeAmount > 0 ? Convert.ToDecimal(payrollTransactionIncome.CustomIncomeAmount) : 0.0M; //insertView.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; insertView.DefaultIncomeName = incomeDB.IncomeName; payrollTransactionIncomeViewModels.Add(insertView); } } } #endregion #region deductions deductionDBList = deductionBL.GetActiveDeductions(); if (deductionDBList != null) { foreach (var dbDeduction in deductionDBList) { payrollTransactionDeduction = new PayrollTransactionDeduction(); payrollTransactionDeduction = payrollTransactionDeductionBL.GetPayrollTransactionDeduction(item.UserPersonalInformationId, Convert.ToInt32(payPeriodId), dbDeduction.DeductionId); if (payrollTransactionDeduction != null) { payrollTransactionDeductionViewModel = new PayrollTransactionDeductionViewModels(); payrollTransactionDeductionViewModel.PayrollTransactionDeductionId = payrollTransactionDeduction.PayrollTransactionDeductionId; payrollTransactionDeductionViewModel.UserPersonalInformationid = item.UserPersonalInformationId; payrollTransactionDeductionViewModel.PayrollPeriodId = Convert.ToInt32(payPeriodId); deductionDB = deductionBL.GetDeductionById(Convert.ToInt32(payrollTransactionDeduction.DeductionId)); payrollTransactionDeductionViewModel.DeductionId = Convert.ToInt32(payrollTransactionDeduction.DeductionId); payrollTransactionDeductionViewModel.CustomDeductionAmount = payrollTransactionDeduction.CustomDeductionAmount > 0 ? Convert.ToDecimal(payrollTransactionDeduction.CustomDeductionAmount) : 0.0M; //payrollTransactionIncomeViewModel.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; payrollTransactionDeductionViewModel.DefaultDeductionName = deductionDB.DeductionName; payrollTransactionDeductionViewModels.Add(payrollTransactionDeductionViewModel); } else { PayrollTransactionDeductionViewModels deductionView = new PayrollTransactionDeductionViewModels(); deductionView.CustomDeductionAmount = 0.0M; deductionView.PayrollTransactionDeductionId = 0; deductionView.UserPersonalInformationid = item.UserPersonalInformationId; deductionDB = deductionBL.GetDeductionById(Convert.ToInt32(dbDeduction.DeductionId)); deductionView.DeductionId = Convert.ToInt32(dbDeduction.DeductionId); deductionView.CustomDeductionAmount = 0.0M; //insertView.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; deductionView.DefaultDeductionName = incomeDB.IncomeName; deductionView.PayrollPeriodId = Convert.ToInt32(payPeriodId); payrollTransactionDeduction = new PayrollTransactionDeduction(); payrollTransactionDeduction = payrollTransactionDeductionBL.InsertPayrollTransactionDeductions(deductionView); deductionView = new PayrollTransactionDeductionViewModels(); deductionView.PayrollTransactionDeductionId = payrollTransactionDeduction.PayrollTransactionDeductionId; deductionView.UserPersonalInformationid = item.UserPersonalInformationId; deductionView.PayrollPeriodId = Convert.ToInt32(payPeriodId); deductionView.DeductionId = Convert.ToInt32(payrollTransactionDeduction.DeductionId); deductionView.CustomDeductionAmount = payrollTransactionDeduction.CustomDeductionAmount > 0 ? Convert.ToDecimal(payrollTransactionDeduction.CustomDeductionAmount) : 0.0M; //insertView.DefaultIncomeAmount = dbIncome.IncomeAmount > 0 ? Convert.ToDecimal(dbIncome.IncomeAmount) : 0.0M; deductionView.DefaultDeductionName = incomeDB.IncomeName; payrollTransactionDeductionViewModels.Add(deductionView); } } } #endregion employee.Incomes = payrollTransactionIncomeViewModels; payrollTransactionIncomeViewModels = new List <PayrollTransactionIncomeViewModels>(); employee.Deductions = payrollTransactionDeductionViewModels; payrollTransactionDeductionViewModels = new List <PayrollTransactionDeductionViewModels>(); if (item.DepartmentId > 0) { employee.Department = department.GetDepartmentById(item.DepartmentId).DepartmentName; } #region EmployeeDetailsPayrollViewModel EmployeeDetailsPayrollViewModel employeeDetailsPayrollViewModel = new EmployeeDetailsPayrollViewModel(); employeeDetailsPayrollViewModel.BasicPay = employee.BasicPay > 0 ? Convert.ToDecimal(employee.BasicPay) : 0.0M; employeeDetailsPayrollViewModel.Department = employee.Department; employeeDetailsPayrollViewModel.EmployeeId = employee.EmployeeId; employeeDetailsPayrollViewModel.Name = employee.Name; #endregion #region EmployeePayPeriodDetailsPayrollViewModel payrollPeriodDB = payrollPeriodBL.GetPayrollPeriodById(Convert.ToInt32(payPeriodId)); EmployeePayPeriodDetailsPayrollViewModel employeePayPeriodDetailsPayrollViewModel = new EmployeePayPeriodDetailsPayrollViewModel(); employeePayPeriodDetailsPayrollViewModel.CurrentPeriodWorkDays = payrollPeriodDB.WorkDays > 0 ? Convert.ToDecimal(payrollPeriodDB.WorkDays) : 0.0M; employeePayPeriodDetailsPayrollViewModel.CurrentPeriodWorkHours = payrollPeriodDB.WorkHours > 0 ? Convert.ToDecimal(payrollPeriodDB.WorkHours) : 0.0M;; employeePayPeriodDetailsPayrollViewModel.Month = payrollPeriodDB.Month; employeePayPeriodDetailsPayrollViewModel.PayPeriodFrom = payrollPeriodDB.PayPeriodFrom; employeePayPeriodDetailsPayrollViewModel.PayPeriodTo = payrollPeriodDB.PayPeriodTo; employeePayPeriodDetailsPayrollViewModel.PayPeriodId = Convert.ToInt32(payPeriodId); #endregion employee.EmployeeDetailsPayrollViewModel = employeeDetailsPayrollViewModel; employee.EmployeePayPeriodDetailsPayrollViewModel = employeePayPeriodDetailsPayrollViewModel; employeeListModels.Add(employee); } return(View(employeeListModels)); } else { ModelState.AddModelError("", "Choose a pay period."); return(RedirectToAction("Employees", "Home")); } } else { ModelState.AddModelError("", "Choose a pay period."); return(RedirectToAction("Employees", "Home")); } }