Пример #1
0
 public ActionResult Save(int id, Employee employee)
 {
     if (!ModelState.IsValid)
     {
         return(View("Edit", employee));
     }
     if (id != employee.Id)
     {
         return(BadRequest());
     }
     using (var db = new nominaDBContext())
     {
         if (id == 0)
         {
             db.Employee.Add(employee);
         }
         else
         {
             var employeeInDb = db.Employee.Find(id);
             employeeInDb.Name        = employee.Name;
             employeeInDb.LastName    = employee.LastName;
             employeeInDb.Genre       = employee.Genre;
             employeeInDb.GrossSalary = employee.GrossSalary;
             employeeInDb.Active      = employee.Active;
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 // GET: Payroll/Edit/5
 public ActionResult Edit(int id)
 {
     using (var db = new nominaDBContext())
     {
         var viewModel = new PayrollViewModel()
         {
             Payroll      = new Payroll(),
             employeeList = db.Employee.Include(e => e.Payroll).Where(e => e.Payroll.Count() == 0 && e.Active).ToList()
         };
         return(View(viewModel));
     }
 }
Пример #3
0
        // GET: Employees/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                using (var db = new nominaDBContext())
                {
                    var employee = db.Employee.Find(id);
                    db.Employee.Remove(employee);

                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
        // GET: Payroll/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                using (var db = new nominaDBContext())
                {
                    var nominaInDb = db.Payroll.Find(id);
                    db.Payroll.Remove(nominaInDb);

                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Пример #5
0
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            Employee employee = new Employee();

            if (id != 0)
            {
                using (var db = new nominaDBContext())
                {
                    employee = db.Employee.Find(id);
                }
            }


            return(View(employee));
        }
        public ActionResult Save(Payroll payroll)
        {
            if (!ModelState.IsValid)
            {
                using (var db = new nominaDBContext())
                {
                    var viewModel = new PayrollViewModel()
                    {
                        employeeList = db.Employee.Include(e => e.Payroll).Where(e => e.Payroll.Count() == 0 && e.Active).ToList(),
                        Payroll      = payroll
                    };
                    return(View("Edit", viewModel));
                }
            }


            using (var db = new nominaDBContext())
            {
                var employeeInDb   = db.Employee.Find(payroll.EmployeeId);
                var afp            = Convert.ToDouble(employeeInDb.GrossSalary) * 0.0287;
                var ars            = Convert.ToDouble(employeeInDb.GrossSalary) * 0.0304;
                var taxableSalary  = employeeInDb.GrossSalary - Convert.ToDecimal((afp + ars));
                var isr            = calculateISR(Convert.ToDouble(taxableSalary));
                var retentionTotal = afp + ars + isr;

                var newPayroll = new Payroll()
                {
                    EmployeeId     = payroll.EmployeeId,
                    GrossSalary    = employeeInDb.GrossSalary,
                    RetentionAfp   = afp,
                    RetentionArs   = ars,
                    TaxableSalary  = taxableSalary,
                    RetentionIsr   = isr,
                    RetentionTotal = retentionTotal,
                    NetIncome      = employeeInDb.GrossSalary - Convert.ToDecimal(retentionTotal)
                };

                db.Payroll.Add(newPayroll);

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        // GET: Payroll
        public ActionResult Index(string genre = "", bool isReport = false)
        {
            var listaNominas = new List <Payroll>();

            using (var db = new nominaDBContext())
            {
                if (genre != "" && genre != null)
                {
                    listaNominas = db.Payroll.Include(n => n.Employee).Where(p => p.Employee.Genre == genre).ToList();
                }
                else
                {
                    listaNominas = db.Payroll.Include(n => n.Employee).ToList();
                }
            }

            return(View(new PayrollIndexViewModel()
            {
                payrollList = listaNominas, IsReport = isReport
            }));
        }
Пример #8
0
        // GET: Employees
        public ActionResult Index(string active = "", bool isReport = false)
        {
            var employeeList = new List <Employee>();

            using (var db = new nominaDBContext())
            {
                if (active != "" && active != null)
                {
                    employeeList = db.Employee.Where(e => e.Active == (active == "1" ? true : false)).ToList();
                }

                else
                {
                    employeeList = db.Employee.ToList();
                }
            }


            return(View(new EmployeeViewModel()
            {
                employeeList = employeeList, isReport = isReport
            }));
        }