예제 #1
0
        public ActionResult EditIncome(AddIncomeViewModel fromModel)
        {
            AssingedEmployeeIncomeBL assingedEmployeeIncomeBL = new AssingedEmployeeIncomeBL();
            IncomeBL           bL      = new IncomeBL();
            AddIncomeViewModel toModel = new AddIncomeViewModel();
            Income             income  = new Income();

            toModel.Incomes = new SelectList(bL.GetActiveIncomes(), "IncomeId", "IncomeName", 1);
            toModel.UserPersonalInformationId = fromModel.UserPersonalInformationId;
            toModel.IncomeId = fromModel.IncomeId;
            toModel.Name     = fromModel.Name;
            //toModel.SelectedCustomAmount = fromModel.SelectedCustomAmount;

            income = bL.GetIncomesById(fromModel.IncomeId);
            if (income != null)
            {
                //toModel.SelectedIncomeAmount = income.IncomeValue;
                toModel.SelectedIncomeName = income.IncomeName;
            }
            else
            {
                toModel.SelectedIncomeAmount = fromModel.SelectedIncomeAmount;
                toModel.SelectedIncomeName   = fromModel.SelectedIncomeName;
            }



            AssignedEmployeeIncome toDB = new AssignedEmployeeIncome();


            if (ModelState.IsValid)
            {
                if (fromModel.IncomeId > 0)
                {
                    toDB.UserPersonalInformationID = toModel.UserPersonalInformationId;
                    //toDB.CustomAmount = toModel.SelectedCustomAmount;
                    toDB.IncomeAmount = toModel.SelectedIncomeAmount;
                    toDB.IncomeId     = toModel.IncomeId;

                    assingedEmployeeIncomeBL.UpdateEmployeeIncome(toDB);
                }
                else
                {
                    ModelState.AddModelError("", "Please select an income.");
                    return(View(toModel));
                }
            }
            else
            {
                ModelState.AddModelError("", "Error.");
                return(View(toModel));
            }
            return(RedirectToAction("AssignIncome", "Home", new { id = fromModel.UserPersonalInformationId }));
        }
예제 #2
0
        public ActionResult AddIncome(int id)
        {
            IncomeBL           bL         = new IncomeBL();
            AddIncomeViewModel viewModels = new AddIncomeViewModel();

            viewModels.Incomes = new SelectList(bL.GetActiveIncomes(), "IncomeId", "IncomeName", 1);
            viewModels.UserPersonalInformationId = id;


            return(View(viewModels));
        }
예제 #3
0
        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"));
            }
        }