コード例 #1
0
        public ActionResult RejectedOT(List <AF_OTModel> GetApproved, string ifalter)
        {
            string[] Position      = { "Supervisor", "Manager", "GeneralManager", "FactoryGeneralManager" };
            int      currentstatus = 0;

            foreach (AF_OTModel otrequest in GetApproved)
            {
                if (otrequest.Approved == true)
                {
                    AF_OTfiling otfile = new AF_OTfiling();
                    otfile                 = (from c in db.AF_OTfiling where c.OT_RefNo == otrequest.OT_RefNo && c.EmployeeNo == otrequest.EmployeeNo select c).FirstOrDefault();
                    currentstatus          = (otfile.Status + 1) * -1;
                    otfile.Status          = currentstatus;
                    db.Entry(otfile).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            #region update Approver Status
            //string refno = GetApproved[0].OT_RefNo;
            //string pos = (ifalter == "alter") ? "Alternative " + Position[currentstatus - 1] : Position[currentstatus - 1];
            //M_Section_ApproverStatus approverstatus = (from c in db.M_Section_ApproverStatus
            //                                           where c.RefNo == refno
            //                                           && c.EmployeeNo == user.UserName
            //                                           && c.Position == pos
            //                                           select c).FirstOrDefault();


            //approverstatus.Approved = -1;
            //db.Entry(approverstatus).State = EntityState.Modified;
            //db.SaveChanges();

            #endregion

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult VerifyUser(string RefNo, string ifalter)
        {
            bool        releasebtn       = false;
            bool        releasebtnCancel = false;
            AF_OTfiling getStatus        = (from c in db.AF_OTfiling where c.OT_RefNo == RefNo orderby c.Status descending select c).FirstOrDefault();
            //M_Section_Approver approver = (from c in db.M_Section_Approver where c.Section == getStatus.Section select c).FirstOrDefault();


            List <M_Section_ApproverStatus> approver = (from c in db.M_Section_ApproverStatus where c.RefNo == RefNo select c).ToList();

            switch (getStatus.Status)
            {
            case 0:
                approver = approver.Where(x => x.Position == "Supervisor").ToList();
                break;

            case 1:
                approver = approver.Where(x => x.Position == "Manager").ToList();
                break;

            case 2:
                approver = approver.Where(x => x.Position == "GeneralManager").ToList();
                break;
            }
            List <string> userlist = new List <string>();

            foreach (M_Section_ApproverStatus username in approver)
            {
                userlist.Add(username.EmployeeNo);
            }

            //Checker if allowed to approved yet
            var dateAndTime = DateTime.Now;
            var date        = dateAndTime.Date;
            var Requestdate = getStatus.CreateDate.Date;

            if (userlist.Contains(user.UserName) && Requestdate < date)
            {
                releasebtn = true;
            }

            if (getStatus.CreateID == user.UserName)
            {
                releasebtnCancel = true;
            }

            return(Json(new { releasebtn = releasebtn, releasebtnCancel = releasebtnCancel }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult CancelledRefNo(List <string> RefNo)
        {
            List <string> EmpnoCannotCancel = new List <string>();

            foreach (string data in RefNo)
            {
                long        ID        = Convert.ToInt64(data.Replace("OT_here_", ""));
                AF_OTfiling otrequest = (from c in db.AF_OTfiling where c.ID == ID select c).FirstOrDefault();
                if (otrequest.CreateID == user.UserName)
                {
                    otrequest.Status          = -10;
                    db.Entry(otrequest).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    EmpnoCannotCancel.Add(otrequest.EmployeeNo);
                }
            }

            return(Json(new { EmpnoCannotCancel = EmpnoCannotCancel }, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult ApprovedOT(List <AF_OTModel> GetApproved, string ifalter, string OTType)
        {
            string[] Position = { "Supervisor", "Manager", "GeneralManager", "FactoryGeneralManager" };
            int      currentstatus = 0;
            int      stat = 0, statmax = 0;

            foreach (AF_OTModel otrequest in GetApproved)
            {
                if (otrequest.Approved == true)
                {
                    AF_OTfiling otfile = new AF_OTfiling();
                    otfile                 = (from c in db.AF_OTfiling where c.Status > -1 && c.OT_RefNo == otrequest.OT_RefNo && c.EmployeeNo == otrequest.EmployeeNo && c.OvertimeType == OTType select c).FirstOrDefault();
                    currentstatus          = otfile.Status + 1;
                    otfile.Status          = (otrequest.Approved == true) ? currentstatus : currentstatus - (currentstatus * 2);
                    db.Entry(otfile).State = EntityState.Modified;


                    if (otfile.StatusMax == otfile.Status)
                    {
                        #region Cumulative OT
                        //Save Cummulative
                        AF_OTfiling_Cumulative Employee_Cumulative = new AF_OTfiling_Cumulative();
                        Employee_Cumulative.OT_RefNo = otfile.OT_RefNo;
                        Employee_Cumulative.Schedule = (from c in db.M_Employee_Master_List_Schedule where c.EmployeeNo == otrequest.EmployeeNo orderby c.ScheduleID descending select c.ScheduleID).FirstOrDefault();
                        Employee_Cumulative.ShiftIn  = (from c in db.M_Schedule where c.ID == Employee_Cumulative.Schedule select c.Timein).FirstOrDefault();
                        Employee_Cumulative.ShiftOut = (from c in db.M_Schedule where c.ID == Employee_Cumulative.Schedule select c.TimeOut).FirstOrDefault();
                        Employee_Cumulative.OTIn     = otfile.OTin;
                        Employee_Cumulative.OTOut    = otfile.OTout;
                        Employee_Cumulative.OTDate   = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm tt"), "yyyy-MM-dd HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);

                        DateTime ShiftStart = DateTime.Parse(Employee_Cumulative.ShiftIn.ToString());
                        DateTime ShiftEnd   = DateTime.Parse(Employee_Cumulative.ShiftOut.ToString());
                        DateTime OTStart    = DateTime.Parse(Employee_Cumulative.OTIn.ToString());
                        DateTime OTEnd      = DateTime.Parse(Employee_Cumulative.OTOut.ToString());
                        TimeSpan duration   = new TimeSpan();
                        if (ShiftStart > ShiftEnd)
                        {
                            ShiftEnd = ShiftEnd.AddDays(1);
                        }
                        if (OTStart > OTEnd)
                        {
                            OTEnd = OTEnd.AddDays(1);
                        }
                        if (ShiftEnd == OTStart)
                        {
                            duration = OTEnd.Subtract(ShiftEnd);
                        }
                        else if (OTStart < ShiftEnd)
                        {
                            //  OTStart = ShiftEnd;
                            duration = OTEnd.Subtract(OTStart);
                        }
                        else
                        {
                            duration = OTEnd.Subtract(OTStart);
                        }
                        double Diffminutes    = duration.TotalMinutes;
                        double Cummulativenow = Diffminutes / 60;
                        Employee_Cumulative.OTHours    = Convert.ToDecimal(Cummulativenow);
                        Employee_Cumulative.EmployeeNo = otfile.EmployeeNo;
                        //Employee_Cumulative.OTDate = Filing.DateFrom;

                        Employee_Cumulative.CreateID   = user.UserName;
                        Employee_Cumulative.CreateDate = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm tt"), "yyyy-MM-dd HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);
                        Employee_Cumulative.UpdateID   = user.UserName;
                        Employee_Cumulative.UpdateDate = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm tt"), "yyyy-MM-dd HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);

                        db.AF_OTfiling_Cumulative.Add(Employee_Cumulative);

                        db.SaveChanges();

                        #endregion
                    }
                    stat    = otfile.Status;
                    statmax = otfile.StatusMax;
                    db.SaveChanges();
                }
                else
                {
                    AF_OTfiling otfile = new AF_OTfiling();
                    otfile                 = (from c in db.AF_OTfiling where c.Status > -1 && c.OT_RefNo == otrequest.OT_RefNo && c.EmployeeNo == otrequest.EmployeeNo && c.OvertimeType == OTType select c).FirstOrDefault();
                    currentstatus          = otfile.Status + 1;
                    otfile.Status          = (otrequest.Approved == true) ? currentstatus : currentstatus - (currentstatus * 2);
                    db.Entry(otfile).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            if (stat == statmax)
            {
                SendTheMail(GetApproved[0].OT_RefNo);
            }


            #region update Approver Status
            string refno = GetApproved[0].OT_RefNo;
            string pos   = (ifalter == "alter")? "Alternative " + Position[currentstatus - 1] : Position[currentstatus - 1];
            M_Section_ApproverStatus approverstatus = (from c in db.M_Section_ApproverStatus
                                                       where c.RefNo == refno &&
                                                       c.EmployeeNo == user.UserName &&
                                                       c.Position == pos &&
                                                       c.OverTimeType == OTType
                                                       select c).FirstOrDefault();

            approverstatus.Approved        = 1;
            db.Entry(approverstatus).State = EntityState.Modified;
            db.SaveChanges();
            #endregion

            db.AF_EmailOTRequest(refno);
            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public JsonResult ReadUploadedFile()
        {
            try {
                var                file         = Request.Files[0];
                int                fileSize     = file.ContentLength;
                string             fileName     = file.FileName;
                string             TodayRefno   = helper.GenerateOTRef();
                string             Section      = "";
                string             OTType       = "";
                List <AF_OTfiling> OTFilingList = new List <AF_OTfiling>();
                List <string>      Unregistered = new List <string>();
                using (var package = new ExcelPackage(file.InputStream))
                {
                    ExcelWorksheet worksheet         = package.Workbook.Worksheets[1];
                    int            noOfCol           = worksheet.Dimension.End.Column;
                    int            noOfRow           = worksheet.Dimension.End.Row;
                    int            endColumn         = worksheet.Dimension.Start.Column;
                    int            startColumn       = endColumn;
                    int            startRowForTable  = 16;
                    int            totalNoOfTableRow = 25;

                    #region Find Type
                    if (worksheet.Cells[12, 3].Value.ToString().ToLower().Contains("x"))
                    {
                        OTType = "SundayHoliday";
                    }
                    else if (worksheet.Cells[11, 6].Value.ToString().ToLower().Contains("x"))
                    {
                        OTType = "LegalHoliday";
                    }
                    else if (worksheet.Cells[12, 6].Value.ToString().ToLower().Contains("x"))
                    {
                        OTType = "SpecialHoliday";
                    }
                    else
                    {
                        OTType = "Regular";
                    }
                    #endregion


                    for (int x = 0; x < totalNoOfTableRow; x++)
                    {
                        string Empno = "";

                        try
                        {
                            Empno = worksheet.Cells[startRowForTable, 3].Value.ToString();
                            M_Employee_Master_List Employee = (from c in db.M_Employee_Master_List
                                                               where c.EmpNo == Empno
                                                               select c).FirstOrDefault();

                            if (Employee != null)
                            {
                                AF_OTfiling bemodify = (from c in db.AF_OTfiling where c.EmployeeNo == Employee.EmpNo && c.OT_RefNo == TodayRefno select c).FirstOrDefault();

                                if (bemodify == null)
                                {
                                    #region Creating via upload
                                    AF_OTfiling OTrequest = new AF_OTfiling();
                                    OTrequest.OT_RefNo    = TodayRefno;
                                    OTrequest.BIPH_Agency = Employee.Company;
                                    OTrequest.FileType    = 3;                                                                                                                           //Upload
                                    OTrequest.Section     = (from c in db.M_Employee_CostCenter where c.EmployNo == Empno orderby c.ID descending select c.CostCenter_AMS).FirstOrDefault();
                                    Section = (from c in db.M_Cost_Center_List where c.Cost_Center == OTrequest.Section orderby c.ID descending select c.GroupSection).FirstOrDefault(); //otfile.Section;

                                    OTrequest.EmployeeNo   = Employee.EmpNo;
                                    OTrequest.OvertimeType = OTType;
                                    OTrequest.DateFrom     = Convert.ToDateTime(worksheet.Cells[6, 9].Value);
                                    OTrequest.DateTo       = Convert.ToDateTime(worksheet.Cells[6, 9].Value);

                                    OTrequest.OTin  = worksheet.Cells[startRowForTable, 5].Value.ToString();
                                    OTrequest.OTout = worksheet.Cells[startRowForTable, 6].Value.ToString();

                                    OTrequest.Purpose   = worksheet.Cells[startRowForTable, 8].Value.ToString();
                                    OTrequest.Status    = 0;
                                    OTrequest.StatusMax = (OTrequest.OvertimeType == "SundayHoliday") ? 4 : 2;

                                    OTrequest.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();

                                    OTrequest.CreateID   = user.UserName;
                                    OTrequest.CreateDate = DateTime.Now;;
                                    OTrequest.UpdateID   = user.UserName;
                                    OTrequest.UpdateDate = DateTime.Now;;

                                    try
                                    {
                                        db.AF_OTfiling.Add(OTrequest);
                                        db.SaveChanges();
                                    }
                                    catch (Exception err)
                                    {
                                        Error_Logs error = new Error_Logs();
                                        error.PageModule = "Application Form - OT Request";
                                        error.ErrorLog   = err.Message;
                                        error.DateLog    = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                                        error.Username   = user.UserName;
                                        db.Error_Logs.Add(error);
                                        db.SaveChanges();
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region modifying via upload
                                    //Section = Employee.CostCode;
                                    bemodify.OT_RefNo    = TodayRefno;
                                    bemodify.BIPH_Agency = Employee.Company;
                                    bemodify.FileType    = 3;                                                                                                                           //Upload
                                    bemodify.Section     = (from c in db.M_Employee_CostCenter where c.EmployNo == Empno orderby c.ID descending select c.CostCenter_AMS).FirstOrDefault();
                                    Section = (from c in db.M_Cost_Center_List where c.Cost_Center == bemodify.Section orderby c.ID descending select c.GroupSection).FirstOrDefault(); //otfile.Section;

                                    bemodify.EmployeeNo   = Employee.EmpNo;
                                    bemodify.OvertimeType = OTType;
                                    bemodify.DateFrom     = Convert.ToDateTime(worksheet.Cells[6, 8].Value);
                                    bemodify.DateTo       = Convert.ToDateTime(worksheet.Cells[6, 8].Value);
                                    bemodify.OTin         = worksheet.Cells[startRowForTable, 4].Value.ToString();
                                    bemodify.OTout        = worksheet.Cells[startRowForTable, 5].Value.ToString();
                                    bemodify.Purpose      = worksheet.Cells[startRowForTable, 7].Value.ToString();
                                    bemodify.Status       = 0;
                                    bemodify.StatusMax    = (bemodify.OvertimeType == "SundayHoliday") ? 4 : 2;

                                    bemodify.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();

                                    bemodify.UpdateID   = user.UserName;
                                    bemodify.UpdateDate = DateTime.Now;;

                                    try
                                    {
                                        db.Entry(bemodify).State = EntityState.Modified;
                                        db.SaveChanges();
                                    }
                                    catch (Exception err)
                                    {
                                        Error_Logs error = new Error_Logs();
                                        error.PageModule = "Application Form - OT Request";
                                        error.ErrorLog   = err.Message;
                                        error.DateLog    = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                                        error.Username   = user.UserName;
                                        db.Error_Logs.Add(error);
                                        db.SaveChanges();
                                    }
                                    #endregion
                                }
                            }
                            else
                            {
                                if (Empno != "")
                                {
                                    Unregistered.Add(Empno);
                                }
                            }
                        }
                        catch (Exception err)
                        {
                            if (Empno != "")
                            {
                                Unregistered.Add(Empno);
                            }
                            Error_Logs error = new Error_Logs();
                            error.PageModule = "Application Form - OT Request";
                            error.ErrorLog   = err.Message;
                            error.DateLog    = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                            error.Username   = user.UserName;
                            db.Error_Logs.Add(error);
                            db.SaveChanges();
                            //return Json(new { Failed = "Failed" }, JsonRequestBehavior.AllowGet);
                        }

                        startRowForTable++;
                    }

                    M_Section_ApproverStatus checker = (from c in db.M_Section_ApproverStatus where c.RefNo == TodayRefno select c).FirstOrDefault();
                    if (checker == null)
                    {
                        #region GET approver & Email
                        //string SectionID = (from c in db.M_Cost_Center_List
                        //                    where c.Cost_Center == Section
                        //                    select c.ID).FirstOrDefault().ToString();
                        List <M_Section_Approver> approver = (from c in db.M_Section_Approver where c.Section == Section 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        = helper.GenerateOTRef();
                            approverstat.Approved     = 0;
                            approverstat.OverTimeType = OTType;
                            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 { Unregistered = Unregistered, Failed = "" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception err)
            {
                return(Json(new { Failed = "Failed" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #6
0
        public ActionResult TimeValidate(List <string> list, DateTime DateFrom, string OTin, string OTOut, string Type)
        {
            bool          Allow       = true;
            List <string> EmpConflict = new List <string>();
            List <string> EmpAlready  = new List <string>();
            long?         GetSchedID;

            if (Type != "Regular")
            {
                foreach (string emp in list)
                {
                    string      currentRefno = helper.GenerateOTRef();
                    DateTime    a            = DateFrom.Date;
                    AF_OTfiling otnow        = (from c in db.AF_OTfiling where c.DateFrom == a && c.EmployeeNo == emp select c).FirstOrDefault();
                    //AF_OTfiling otnow2 = (from c in db.AF_OTfiling where c.OT_RefNo == currentRefno && c.OTout == OTOut && c.Status >= 0 && c.EmployeeNo == emp select c).FirstOrDefault();

                    if (otnow != null)// || otnow2 != null)
                    {
                        EmpAlready.Add(list[0]);
                        Allow = false;
                    }
                    else
                    {
                        Allow = true;
                    }
                }
            }
            else
            {
                foreach (string emp in list)
                {
                    M_Employee_Master_List Employee = (from c in db.M_Employee_Master_List where c.EmpNo == emp select c).FirstOrDefault();
                    GetSchedID = (from c in db.M_Employee_Master_List_Schedule where c.EmployeeNo == emp orderby c.ID descending select c.ScheduleID).FirstOrDefault();

                    string Schedule = (from c in db.M_Schedule where c.ID == GetSchedID select c.Type).FirstOrDefault();

                    M_Schedule schedcheck   = (from c in db.M_Schedule where c.Type == Schedule select c).FirstOrDefault();
                    DateTime   ShiftStart   = DateTime.Parse(schedcheck.Timein.ToString());
                    DateTime   ShiftEnd     = DateTime.Parse(schedcheck.TimeOut.ToString());
                    DateTime   TimecheckIN  = DateTime.Parse(OTin);
                    DateTime   TimecheckOUT = DateTime.Parse(OTOut);
                    if (ShiftStart > ShiftEnd)
                    {
                        ShiftEnd = ShiftEnd.AddDays(1);
                    }
                    //if ((ShiftStart > TimecheckIN
                    //    && TimecheckIN < ShiftEnd)
                    //    ||( ShiftStart > TimecheckOUT
                    //    && TimecheckOUT < ShiftEnd))
                    //{
                    if (TimecheckIN.ToString("HH:mm") == ShiftEnd.ToString("HH:mm") || TimecheckOUT.ToString("HH:mm") == ShiftStart.ToString("HH:mm"))
                    {
                        Allow = (Allow == false) ? false : true;
                    }
                    else
                    {
                        EmpConflict.Add(emp);
                        Allow = false;
                        //break;
                    }
                    string      currentRefno = helper.GenerateOTRef();
                    DateTime    a            = DateFrom.Date;
                    AF_OTfiling otnow        = (from c in db.AF_OTfiling where c.OT_RefNo == currentRefno && c.OTin == OTin && c.Status >= 0 && c.DateFrom == a && c.EmployeeNo == emp select c).FirstOrDefault();
                    //AF_OTfiling otnow2 = (from c in db.AF_OTfiling where c.OT_RefNo == currentRefno && c.OTout == OTOut && c.Status >= 0 && c.EmployeeNo == emp select c).FirstOrDefault();

                    if (otnow != null)// || otnow2 != null)
                    {
                        EmpAlready.Add(list[0]);
                        Allow = false;
                    }
                }
            }
            return(Json(new { Allow = Allow, EmpConflict = EmpConflict, EmpAlready = EmpAlready }, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        public ActionResult SaveOT(AF_OTfiling Filing, string Purposes, string EmployeeNos)
        {
            try
            {
                List <string> PurposeList    = Purposes.Split(',').ToList();
                List <string> EmployeeNosLis = EmployeeNos.Split(',').ToList();
                int           emploCounter   = 0;
                string        OTRefnow       = helper.GenerateOTRef();
                //long SectionID = 0;
                string Section = "";
                foreach (string purpose in PurposeList)
                {
                    string      EmploNos = EmployeeNosLis[emploCounter];
                    AF_OTfiling otfile   = new AF_OTfiling();
                    otfile.OT_RefNo    = OTRefnow;
                    otfile.BIPH_Agency = Filing.BIPH_Agency;
                    otfile.EmployeeNo  = EmploNos;
                    otfile.FileType    = Filing.FileType;
                    long?Schedule_current = (from c in db.M_Employee_Master_List_Schedule where c.EmployeeNo == EmploNos orderby c.ID descending select c.ScheduleID).FirstOrDefault();

                    otfile.ScheduleID = Schedule_current;
                    otfile.Section    = (from c in db.M_Employee_CostCenter where c.EmployNo == EmploNos orderby c.ID descending select c.CostCenter_AMS).FirstOrDefault();
                    //SectionID = otfile.Section;
                    Section             = (from c in db.M_Cost_Center_List where c.Cost_Center == otfile.Section orderby c.ID descending select c.GroupSection).FirstOrDefault();//otfile.Section;
                    otfile.OvertimeType = Filing.OvertimeType;
                    otfile.DateFrom     = Filing.DateFrom.Date;
                    otfile.DateTo       = Filing.DateFrom.Date;
                    otfile.OTin         = Filing.OTin;
                    otfile.OTout        = Filing.OTout;
                    otfile.Purpose      = purpose;
                    otfile.Status       = 0;
                    otfile.StatusMax    = (otfile.OvertimeType == "SundayHoliday") ? 4 : 2;
                    //if (EmploNos.Contains("BIPH"))
                    //{
                    otfile.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();    //DateTime.Now;;
                    //}
                    otfile.CreateID   = user.UserName;
                    otfile.CreateDate = DateTime.Now;
                    otfile.UpdateID   = user.UserName;
                    otfile.UpdateDate = DateTime.Now;;

                    try
                    {
                        db.AF_OTfiling.Add(otfile);
                        db.SaveChanges();
                    }
                    catch (Exception err)
                    {
                        Error_Logs error = new Error_Logs();
                        error.PageModule = "Application Form - OT Request";
                        error.ErrorLog   = err.Message;
                        error.DateLog    = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                        error.Username   = user.UserName;
                        db.Error_Logs.Add(error);
                        db.SaveChanges();
                    }
                    emploCounter++;
                }
                M_Section_ApproverStatus checker = (from c in db.M_Section_ApproverStatus where c.RefNo == OTRefnow && c.OverTimeType == Filing.OvertimeType select c).FirstOrDefault();
                if (checker == null)
                {
                    #region GET approver & Email
                    //string SectionID = (from c in db.M_Cost_Center_List
                    //                    where c.Cost_Center == Section
                    //                    select c.ID).FirstOrDefault().ToString();
                    List <M_Section_Approver> approver = (from c in db.M_Section_Approver where c.Section == Section select c).ToList();

                    #region EMAIL FUNCTION TRANSFER TO SERVER JOBS
                    //try
                    //{
                    //    db.AF_EmailOTRequest();
                    //}
                    //catch (Exception err)
                    //{
                    //    Error_Logs error = new Error_Logs();
                    //    error.PageModule = "Application Form - OT Request";
                    //    error.ErrorLog = err.Message;
                    //    error.DateLog = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                    //    error.Username = user.UserName;
                    //    db.Error_Logs.Add(error);
                    //    db.SaveChanges();
                    //}


                    //EmailApproverController email = new EmailApproverController();
                    ////M_Employee_Master_List getSupervisor = (from c in db.M_Employee_Master_List where c.EmpNo == approver.Supervisor select c).FirstOrDefault();
                    //email.sendMail("OT Approval", approver, OTRefnow, Session["emailpath"].ToString());
                    #endregion
                    #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        = OTRefnow;
                        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 { OTRefnow = OTRefnow }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception err)
            {
                Error_Logs error = new Error_Logs();
                error.PageModule = "Application Form - OT Request";
                error.ErrorLog   = err.Message;
                error.DateLog    = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                error.Username   = user.UserName;
                db.Error_Logs.Add(error);
                db.SaveChanges();
                return(Json(new { OTRefnow = "" }, JsonRequestBehavior.AllowGet));
            }
        }