Ejemplo n.º 1
0
        public ActionResult Details(int id)
        {
            Deduction           deduction = deductionBL.GetDeductionById(id);
            DeductionViewModels model     = new DeductionViewModels();

            model        = new DeductionViewModels();
            model.Active = Convert.ToBoolean(deduction.Active);
            model.DeductionDescription = deduction.DeductionDescription;
            model.DeductionId          = deduction.DeductionId;
            model.DeductionName        = deduction.DeductionName;
            //model.DeductionValue = deduction.DeductionValue;
            model.Order = deduction.Order;
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult EditDeduction(AddDeductionViewModel fromModel)
        {
            AssignedEmployeeDeductionBL assingedEmployeeBL = new AssignedEmployeeDeductionBL();
            DeductionBL           bL        = new DeductionBL();
            AddDeductionViewModel toModel   = new AddDeductionViewModel();
            Deduction             deduction = new Deduction();

            toModel.Deductions = new SelectList(bL.GetActiveDeductions(), "DeductionId", "DeductionName", 1);
            toModel.UserPersonalInformationId = fromModel.UserPersonalInformationId;
            toModel.DeductionId = fromModel.DeductionId;
            toModel.Name        = fromModel.Name;
            //toModel.SelectedCustomAmount = fromModel.SelectedCustomAmount;

            deduction = bL.GetDeductionById(fromModel.DeductionId);
            if (deduction != null)
            {
                toModel.SelectedDeductionAmount = 0.0M;
                toModel.SelectedDeductionName   = deduction.DeductionName;
            }
            else
            {
                toModel.SelectedDeductionAmount = fromModel.SelectedDeductionAmount;
                toModel.SelectedDeductionName   = fromModel.SelectedDeductionName;
            }



            AssignedEmployeeDeduction toDB = new AssignedEmployeeDeduction();


            if (ModelState.IsValid)
            {
                if (fromModel.DeductionId > 0)
                {
                    toDB.UserPersonalInformationID = toModel.UserPersonalInformationId;
                    //toDB.CustomAmount = toModel.SelectedCustomAmount;
                    toDB.DeductionAmount = toModel.SelectedDeductionAmount;
                    toDB.DeductionId     = toModel.DeductionId;

                    assingedEmployeeBL.UpdateEmployeeDeduction(toDB);
                }
                else
                {
                    ModelState.AddModelError("", "Please select a Deduction.");
                    return(View(toModel));
                }
            }
            else
            {
                ModelState.AddModelError("", "Error.");
                return(View(toModel));
            }
            return(RedirectToAction("AssignDeduction", "Home", new { id = fromModel.UserPersonalInformationId }));
        }
Ejemplo n.º 3
0
        public ActionResult EditDeduction(int id, int deductionId)
        {
            AssignedEmployeeDeductionBL assingedEmployeeBL = new AssignedEmployeeDeductionBL();
            Deduction             deduction  = new Deduction();
            DeductionBL           bL         = new DeductionBL();
            AddDeductionViewModel viewModels = new AddDeductionViewModel();

            viewModels.UserPersonalInformationId = id;
            deduction = bL.GetDeductionById(deductionId);
            //viewModels.SelectedCustomAmount = assingedEmployeeBL.GetAssignedEmployeeDeductionsByDeductionId(id, deductionId);
            if (deduction != null)
            {
                //viewModels.SelectedDeductionAmount = deduction.DeductionValue;
                viewModels.SelectedDeductionName = deduction.DeductionName;
            }

            ViewBag.Name = employeeBL.GetEmployeeById(id);
            return(View(viewModels));
        }
Ejemplo n.º 4
0
        public List <AssignedEmployeeDeductionsViewModel> AssignDeduction(int id, out string fullName)
        {
            List <AssignedEmployeeDeductionsViewModel> assignEmployeeDeductionsViewModelList = new List <AssignedEmployeeDeductionsViewModel>();

            DeductionBL deductionBL = new DeductionBL();
            Deduction   deduction   = new Deduction();
            AssignedEmployeeDeductionBL assingedEmployeeDeductionBL = new AssignedEmployeeDeductionBL();


            AssignedEmployeeDeductionsViewModel assignEmployeeDeductionViewModel = new AssignedEmployeeDeductionsViewModel();


            UserPersonalInformation employee = GetEmployeesById(id);

            fullName = employee.FirstName + " " + employee.LastName;

            List <AssignedEmployeeDeduction> fromDB = assingedEmployeeDeductionBL.GetAssignedEmployeeDeductions(id);

            if (fromDB != null)
            {
                foreach (var item in fromDB)
                {
                    assignEmployeeDeductionViewModel      = new AssignedEmployeeDeductionsViewModel();
                    assignEmployeeDeductionViewModel.Name = fullName;
                    assignEmployeeDeductionViewModel.AssignedEmployeeDeductionsId = item.AssignedEmployeeDeductionID;
                    //assignEmployeeDeductionViewModel.CustomIncomeAmount = item.CustomAmount;
                    assignEmployeeDeductionViewModel.DeductionAmount = item.DeductionAmount;
                    assignEmployeeDeductionViewModel.DeductionId     = item.DeductionId;
                    deduction = deductionBL.GetDeductionById(item.DeductionId);
                    assignEmployeeDeductionViewModel.DeductionName             = deduction.DeductionName;
                    assignEmployeeDeductionViewModel.UserPersonalInformationId = item.UserPersonalInformationID;

                    assignEmployeeDeductionsViewModelList.Add(assignEmployeeDeductionViewModel);
                }
            }

            return(assignEmployeeDeductionsViewModelList);
        }
Ejemplo n.º 5
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"));
            }
        }