public ActionResult DeleteConfirmed(int id)
        {
            PayrollModels payrollModels = db.PayrollModels.Find(id);

            db.PayrollModels.Remove(payrollModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,ManagerId,ManagerName,PayRate,Position")] PayrollModels payrollModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(payrollModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(payrollModels));
 }
        public ActionResult Create([Bind(Include = "Id,Name,ManagerId,ManagerName,PayRate,Position")] PayrollModels payrollModels)
        {
            if (ModelState.IsValid)
            {
                db.PayrollModels.Add(payrollModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(payrollModels));
        }
        // GET: PayrollModels/Instructions
        public ActionResult Instructions(int?id)
        {
            PayrollModels payrollModels = db.PayrollModels.Find(id);

            if (ModelState.IsValid)
            {
                db.Entry(payrollModels).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Instructions"));
            }
            return(View(payrollModels));
        }
        // GET: PayrollModels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PayrollModels payrollModels = db.PayrollModels.Find(id);

            if (payrollModels == null)
            {
                return(HttpNotFound());
            }
            return(View(payrollModels));
        }
Example #6
0
        public JsonResult GeneratePayroll(string ids)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return(Json(new { status = "404" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                string[] arrID = ids.Split(',');
                if (arrID.Length > 0)
                {
                    bool   isValid = false;
                    string empID   = null;
                    for (int a = 0; a < arrID.Length; a++)
                    {
                        Guid attID = new Guid(arrID[a]);

                        //Approved Checked
                        bool isValidAtt = db.Attendance.Where(x => x.Id == attID).Select(x => x.Approved.HasValue).Single(); //return false jika Approved = NULL
                        if (!isValidAtt)
                        {
                            isValid = false;
                            break;
                        }
                        else
                        {
                            isValid = db.Attendance.Where(x => x.Id == attID).Select(x => x.Approved.Value).Single();
                            if (!isValid)
                            {
                                break;
                            }
                        }

                        //Same Employee Checked
                        string userID = db.Attendance.Where(x => x.Id == attID).Select(x => x.UserAccounts_Id).Single().ToString();
                        if (a == 0)
                        {
                            empID = userID;
                        }
                        else
                        {
                            isValid = (empID == userID) ? true : false;
                        }
                    }

                    if (!isValid)
                    {
                        return(Json(new { status = "405" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Guid _attID     = new Guid(arrID[0]);
                        Guid employeeID = db.Attendance.Where(x => x.Id == _attID).Select(x => x.UserAccounts_Id).Single();

                        PayrollModels pRoll = new PayrollModels();
                        pRoll.Id        = Guid.NewGuid();
                        pRoll.Timestamp = DateTime.Now;
                        pRoll.Employee_UserAccounts_Id = employeeID;
                        pRoll.Amount = 0;
                        Common.Master m = new Common.Master();
                        pRoll.No         = m.GetLastHexNo("payroll").ToString("00000");
                        pRoll.hasPayment = false;
                        db.Payroll.Add(pRoll);
                        db.SaveChanges();

                        for (int i = 0; i < arrID.Length; i++)
                        {
                            Guid attID           = new Guid(arrID[i]);
                            PayrollItemModels pi = new PayrollItemModels();
                            pi.Id          = Guid.NewGuid();
                            pi.Payrolls_Id = pRoll.Id;
                            pi.RefId       = attID;
                            pi.Description = string.Empty;
                            int     hours   = db.Attendance.Where(x => x.Id == attID).Select(x => x.Workshifts_DurationMinutes.Value).Single() / 60;
                            decimal payRate = db.Attendance.Where(x => x.Id == attID).Select(x => x.AttendancePayRates_Amount.Value).FirstOrDefault();
                            pi.Amount = hours * payRate;
                            pi.Notes  = string.Empty;
                            db.PayrollItem.Add(pi);
                            db.SaveChanges();

                            using (var ctx = new HrContext())
                            {
                                int result = ctx.Database.ExecuteSqlCommand("UPDATE Attendances SET PayrollItems_Id='" + pi.Id + "' WHERE Id='" + attID + "'");
                            }
                        }

                        decimal total_amount  = db.PayrollItem.Where(x => x.Payrolls_Id == pRoll.Id).Select(x => x.Amount).Sum();
                        int     update_amount = db.Database.ExecuteSqlCommand("UPDATE Payrolls SET Amount=" + total_amount + " WHERE Id='" + pRoll.Id + "'");

                        return(Json(new { status = "200" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { status = "404" }, JsonRequestBehavior.AllowGet));
                }
            } //end ids is not null/empty
        }     //end generate payroll