public ActionResult SaveDTR(AF_DTRfiling Filing, string Reasons, string EmployeeNos, string DTRType, string concerns)
        {
            List <string> concernsList   = concerns.Split(',').ToList();
            List <string> ReasonsList    = Reasons.Split(',').ToList();
            List <string> EmployeeNosLis = EmployeeNos.Split(',').ToList();
            int           emploCounter   = 0;
            string        DTRRefNo       = helper.GenerateDTRRef();
            string        Section        = "";

            foreach (string reason in ReasonsList)
            {
                string       EmploNos = EmployeeNosLis[emploCounter];
                string       Concern  = concernsList[emploCounter];
                AF_DTRfiling dtrfile  = new AF_DTRfiling();
                dtrfile.DTR_RefNo   = DTRRefNo;
                dtrfile.BIPH_Agency = Filing.BIPH_Agency;
                dtrfile.EmployeeNo  = EmploNos;
                dtrfile.FileType    = Filing.FileType;
                dtrfile.Section     = (from c in db.M_Employee_CostCenter where c.EmployNo == EmploNos orderby c.ID descending select c.CostCenter_AMS).FirstOrDefault();
                Section             = (from c in db.M_Cost_Center_List where c.Cost_Center == dtrfile.Section orderby c.ID descending select c.GroupSection).FirstOrDefault();//otfile.Section;//dtrfile.Section;
                //dtrfile.Line_Team = 1;// (from c in db.M_Employee_Master_List where c.EmpNo == EmploNos select c.LineID).FirstOrDefault();
                dtrfile.OvertimeType = Filing.OvertimeType;
                dtrfile.DateFrom     = Filing.DateFrom.Date;
                dtrfile.DateTo       = Filing.DateTo.AddHours(23).AddMinutes(59).AddSeconds(59);
                dtrfile.OTin         = Filing.OTin;
                dtrfile.OTout        = Filing.OTout;
                dtrfile.Timein       = Filing.Timein;
                dtrfile.TimeOut      = Filing.TimeOut;
                dtrfile.Reason       = reason;
                dtrfile.Concerns     = Concern;
                dtrfile.Status       = 0;
                //if (EmploNos.Contains("BIPH"))
                //{
                dtrfile.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();    //DateTime.Now;;
                //}
                if (DTRType == "HR")
                {
                    dtrfile.StatusMax = (Filing.OvertimeType == "SundayHoliday") ? 4 : 2;
                }
                else
                {
                    dtrfile.StatusMax = 1; //Supervisor only
                }
                dtrfile.CreateID   = user.UserName;
                dtrfile.CreateDate = DateTime.Now;
                dtrfile.UpdateID   = user.UserName;
                dtrfile.UpdateDate = DateTime.Now;
                try
                {
                    db.AF_DTRfiling.Add(dtrfile);
                    db.SaveChanges();
                }
                catch (Exception err) {
                    Error_Logs error = new Error_Logs();
                    error.PageModule = "Application Form - DTR";
                    error.ErrorLog   = err.Message;
                    error.DateLog    = DateTime.Now;
                    error.Username   = user.UserName;
                    db.Error_Logs.Add(error);
                    db.SaveChanges();
                }
                emploCounter++;
            }

            #region GET approver & Email

            List <M_Section_Approver> approver = (from c in db.M_Section_Approver
                                                  where c.Section == Section &&
                                                  c.Position != "GeneralManager" &&
                                                  c.Position != "FactoryGeneralManager"
                                                  select c).ToList();


            #endregion

            #region Generate OT Status
            foreach (M_Section_Approver approv in approver)
            {
                M_Section_ApproverStatus approverstat = new M_Section_ApproverStatus();
                approverstat.Position     = approv.Position;
                approverstat.EmployeeNo   = approv.EmployeeNo;
                approverstat.Section      = Section;
                approverstat.RefNo        = DTRRefNo;
                approverstat.Approved     = 0;
                approverstat.OverTimeType = Filing.OvertimeType;
                approverstat.CreateID     = user.UserName;
                approverstat.CreateDate   = DateTime.Now;
                approverstat.UpdateID     = user.UserName;
                approverstat.UpdateDate   = DateTime.Now;
                db.M_Section_ApproverStatus.Add(approverstat);
                db.SaveChanges();
            }

            #endregion
            return(Json(new { DTRRefNo = DTRRefNo }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetEmployeeList(string Agency, string Section, Nullable <long> lINEID, string employeeNo, List <string> ChosenEmployees, long?Schedule, string TransType)
        {
            System.Web.HttpContext.Current.Session["Searchvalueot"] = Request["search[value]"];
            System.Web.HttpContext.Current.Session["lINEID"]        = lINEID;

            int    start       = (Convert.ToInt32(Request["start"]) == 0) ? 0 : (Convert.ToInt32(Request["start"]) / Convert.ToInt32(Request["length"]));
            int    length      = Convert.ToInt32(Request["length"]);
            string searchValue = Request["search[value]"];

            searchValue = (searchValue == null) ? "" : searchValue;
            string          sortColumnName           = Request["columns[" + Request["order[0][column]"] + "][name]"];
            string          sortDirection            = Request["order[0][dir]"];
            ObjectParameter totalCount               = new ObjectParameter("TotalCount", typeof(int));
            List <GET_Employee_OTFiling_Result> list = new List <GET_Employee_OTFiling_Result>();

            string currentRefno = "";

            switch (TransType)
            {
            case "OT":
                currentRefno = helper.GenerateOTRef();
                list         = db.GET_Employee_OTFiling(Agency, user.CostCode, lINEID, employeeNo, start, length, searchValue, totalCount).ToList();
                list         = list.OrderBy(x => x.EmpNo).ToList();
                //list = list.Where(x => x.Section == user.CostCode).ToList();
                //List<AF_OTfiling> AlreadyApplied = (from c in db.AF_OTfiling where c.OT_RefNo == currentRefno && c.Status >= 0 select c).ToList();
                //list = list.Where(p => !AlreadyApplied.Any(p2 => p2.EmployeeNo == p.EmpNo)).ToList();
                break;

            case "CS":
                currentRefno = helper.GenerateCSRef();
                list         = db.GET_Employee_OTFiling(Agency, user.CostCode, lINEID, employeeNo, start, length, searchValue, totalCount).ToList();
                list         = list.OrderBy(x => x.EmpNo).ToList();
                //if (Schedule != null)
                //{
                //    string Schedulename = (from c in db.M_Schedule where c.ID == Schedule select c.Timein + " - " + c.TimeOut).FirstOrDefault();
                //    list = list.Where(x => x.Schedule == Schedulename).ToList();
                //}
                // list = list.Where(x => x.Section == user.Section).ToList();
                // List<AF_ChangeSchedulefiling> AlreadyAppliedcs = (from c in db.AF_ChangeSchedulefiling where c.CS_RefNo == currentRefno && c.Status >= 0 select c).ToList();
                // list = list.Where(p => !AlreadyAppliedcs.Any(p2 => p2.EmployeeNo == p.EmpNo)).ToList();
                break;

            case "DTR":
                currentRefno = helper.GenerateDTRRef();
                list         = db.GET_Employee_OTFiling(Agency, user.CostCode, lINEID, employeeNo, start, length, searchValue, totalCount).ToList();
                list         = list.OrderBy(x => x.EmpNo).ToList();
                // list = list.Where(x => x.Section == user.Section).ToList();
                // List<AF_DTRfiling> AlreadyApplieddtr = (from c in db.AF_DTRfiling where c.DTR_RefNo == currentRefno && c.Status >= 0 select c).ToList();
                // list = list.Where(p => !AlreadyApplieddtr.Any(p2 => p2.EmployeeNo == p.EmpNo)).ToList();
                break;
            }

            if (ChosenEmployees != null)
            {
                #region null remover
                list = list.Where(xx => xx.EmpNo != null).ToList();
                list = list.Where(xx => xx.First_Name != null).ToList();
                list = list.Where(xx => xx.Family_Name != null).ToList();
                #endregion
                list = (from c in list
                        where ChosenEmployees.Contains(c.EmpNo)
                        select c).ToList();
            }
            int?totalrows = Convert.ToInt32(totalCount.Value);               //list.Count;
            int?totalrowsafterfiltering = Convert.ToInt32(totalCount.Value); //list.Count;
            return(Json(new { data = list, draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering }, JsonRequestBehavior.AllowGet));
        }