public ActionResult VerifyUser(string RefNo)
        {
            bool releasebtn                   = false;
            bool releasebtnCancel             = false;
            AF_ChangeSchedulefiling getStatus = (from c in db.AF_ChangeSchedulefiling where c.CS_RefNo == RefNo orderby c.Status descending 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));
        }
        public ActionResult CancelledRefNo(List <string> RefNo)
        {
            List <string> EmpnoCannotCancel = new List <string>();

            foreach (string data in RefNo)
            {
                long ID = Convert.ToInt64(data.Replace("CS_here_", ""));
                AF_ChangeSchedulefiling csrequest = (from c in db.AF_ChangeSchedulefiling where c.ID == ID select c).FirstOrDefault();
                if (csrequest.CreateID == user.UserName)
                {
                    csrequest.Status          = -10;
                    db.Entry(csrequest).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    EmpnoCannotCancel.Add(csrequest.EmployeeNo);
                }
            }
            return(Json(new { EmpnoCannotCancel = EmpnoCannotCancel }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RejectedCS(List <AF_CSModel> GetApproved, string ifalter)
        {
            string[] Position      = { "Supervisor", "Manager" };
            int      currentstatus = 0;
            string   CSRefNo       = "";

            foreach (AF_CSModel otrequest in GetApproved)
            {
                if (otrequest.Approved == true)
                {
                    CSRefNo = otrequest.CS_RefNo;
                    AF_ChangeSchedulefiling otfile = new AF_ChangeSchedulefiling();
                    otfile                 = (from c in db.AF_ChangeSchedulefiling where c.CS_RefNo == otrequest.CS_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].CS_RefNo;
            db.AF_EmailCSRequest_Rejected(CSRefNo);
            //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;
            approverstatus.ApprovedDate    = db.TT_GETTIME().FirstOrDefault();
            db.Entry(approverstatus).State = EntityState.Modified;
            db.SaveChanges();

            #endregion

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public ActionResult SaveCS(AF_ChangeSchedulefiling Filing, string Reasons, string EmployeeNos)
        {
            List <string> ReasonList     = Reasons.Split(',').ToList();
            List <string> EmployeeNosLis = EmployeeNos.Split(',').ToList();
            int           emploCounter   = 0;
            string        CSRefnow       = helper.GenerateCSRef();
            string        Section        = "";

            foreach (string reason in ReasonList)
            {
                string EmploNos = EmployeeNosLis[emploCounter];
                AF_ChangeSchedulefiling csfile = new AF_ChangeSchedulefiling();
                csfile.CS_RefNo    = CSRefnow;
                csfile.CSType      = Filing.CSType;
                csfile.BIPH_Agency = Filing.BIPH_Agency;
                csfile.EmployeeNo  = EmploNos;
                csfile.FileType    = Filing.FileType;
                csfile.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 == csfile.Section orderby c.ID descending select c.GroupSection).FirstOrDefault();//otfile.Section;//csfile.Section;
                csfile.DateFrom    = Filing.DateFrom.Date;
                csfile.DateTo      = Filing.DateTo.AddHours(23).AddMinutes(59).AddSeconds(59);
                csfile.CSin        = Filing.CSin;
                csfile.CSout       = Filing.CSout;
                csfile.Reason      = reason;
                csfile.Status      = 0;
                csfile.StatusMax   = 2;
                csfile.CreateID    = user.UserName;
                csfile.CreateDate  = DateTime.Now;
                csfile.UpdateID    = user.UserName;
                csfile.UpdateDate  = DateTime.Now;
                csfile.Schedule    = Filing.Schedule;
                //if (EmploNos.Contains("BIPH"))
                //{
                csfile.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();        //DateTime.Now;;
                //}
                try
                {
                    db.AF_ChangeSchedulefiling.Add(csfile);
                    db.SaveChanges();
                }
                catch (Exception err)
                {
                    Error_Logs error = new Error_Logs();
                    error.PageModule = "Application Form - Change Schedule";
                    error.ErrorLog   = err.Message;
                    error.DateLog    = db.TT_GETTIME().FirstOrDefault(); //DateTime.Now;;
                    error.Username   = user.UserName;
                    db.Error_Logs.Add(error);
                    db.SaveChanges();
                }

                emploCounter++;
            }

            #region Generate CS Status
            db.AF_EmailCSRequestApprovers();
            db.AF_EmailCSRequest(CSRefnow);
            #endregion


            #region REmoved
            //M_Section_ApproverStatus checker = (from c in db.M_Section_ApproverStatus where c.RefNo == CSRefnow 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
            //                                         && c.Position != "GeneralManager"
            //                                         && c.Position != "FactoryGeneralManager"
            //                                         select c).ToList();


            //    #endregion
            //    #region Generate CS Status


            //    db.AF_EmailCSRequestApprovers();
            //    //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 = CSRefnow;
            //    //    approverstat.Approved = 0;
            //    //    approverstat.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
            //}

            //db.AF_EmailCSRequest(CSRefnow);
            #endregion
            return(Json(new { CSRefnow = CSRefnow }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public JsonResult ReadUploadedFile()
        {
            try {
                var           file         = Request.Files[0];
                int           fileSize     = file.ContentLength;
                string        fileName     = file.FileName;
                string        TodayRefno   = helper.GenerateCSRef();
                string        Section      = "";
                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  = 14;
                    int            totalNoOfTableRow = 30;



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

                        try
                        {
                            Empno = worksheet.Cells[startRowForTable, 2].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_ChangeSchedulefiling bemodify = (from c in db.AF_ChangeSchedulefiling where c.EmployeeNo == Employee.EmpNo && c.CS_RefNo == TodayRefno select c).FirstOrDefault();

                                if (bemodify == null)
                                {
                                    #region Creating via upload
                                    //Section = user.Section;//Employee.Section;
                                    AF_ChangeSchedulefiling CSrequest = new AF_ChangeSchedulefiling();
                                    CSrequest.CS_RefNo    = TodayRefno;
                                    CSrequest.BIPH_Agency = Employee.Company;
                                    CSrequest.FileType    = 3;                                                                                                                           //Upload
                                    CSrequest.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 == CSrequest.Section orderby c.ID descending select c.GroupSection).FirstOrDefault(); //otfile.Section;

                                    CSrequest.EmployeeNo = Employee.EmpNo;
                                    CSrequest.CSType     = worksheet.Cells[startRowForTable, 4].Value.ToString();
                                    CSrequest.DateFrom   = Convert.ToDateTime(worksheet.Cells[startRowForTable, 5].Value);
                                    CSrequest.DateTo     = Convert.ToDateTime(worksheet.Cells[startRowForTable, 6].Value);
                                    DateTime csin  = Convert.ToDateTime(worksheet.Cells[startRowForTable, 7].Value.ToString());
                                    DateTime csout = Convert.ToDateTime(worksheet.Cells[startRowForTable, 8].Value.ToString());
                                    CSrequest.CSin  = csin.ToString("HH:mm");
                                    CSrequest.CSout = csout.ToString("HH:mm");
                                    //if (Employee.EmpNo.Contains("BIPH"))
                                    //{
                                    CSrequest.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();    //DateTime.Now;;
                                    //}

                                    CSrequest.Reason    = worksheet.Cells[startRowForTable, 9].Value.ToString();
                                    CSrequest.Status    = 0;
                                    CSrequest.StatusMax = 2;

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

                                    try
                                    {
                                        db.AF_ChangeSchedulefiling.Add(CSrequest);
                                        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.Section;
                                    bemodify.CS_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.CSType     = worksheet.Cells[startRowForTable, 4].Value.ToString();
                                    bemodify.DateFrom   = Convert.ToDateTime(worksheet.Cells[startRowForTable, 5].Value);
                                    bemodify.DateTo     = Convert.ToDateTime(worksheet.Cells[startRowForTable, 6].Value);
                                    DateTime csin  = Convert.ToDateTime(worksheet.Cells[startRowForTable, 7].Value.ToString());
                                    DateTime csout = Convert.ToDateTime(worksheet.Cells[startRowForTable, 8].Value.ToString());
                                    bemodify.CSin       = csin.ToString("HH:mm");
                                    bemodify.CSout      = csout.ToString("HH:mm");
                                    bemodify.Reason     = worksheet.Cells[startRowForTable, 9].Value.ToString();
                                    bemodify.Status     = 0;
                                    bemodify.StatusMax  = 2;
                                    bemodify.UpdateID   = user.UserName;
                                    bemodify.UpdateDate = DateTime.Now;;
                                    if (Employee.EmpNo.Contains("BIPH"))
                                    {
                                        bemodify.EmployeeAccept = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;;
                                    }
                                    try
                                    {
                                        db.Entry(bemodify).State = EntityState.Modified;
                                        db.SaveChanges();
                                    }
                                    catch (Exception err)
                                    {
                                        Error_Logs error = new Error_Logs();
                                        error.PageModule = "Application Form - CS 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);
                            }
                        }

                        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 CS 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.GenerateCSRef();
                            approverstat.Approved     = 0;
                            approverstat.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 { Unregistered = Unregistered, Failed = "" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception err)
            {
                return(Json(new { Failed = "Failed" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ApprovedCS(List <AF_CSModel> GetApproved, string ifalter)
        {
            string[] Position = { "Supervisor", "Manager" };
            int      currentstatus = 0;
            int      stat = 0, statmax = 0;
            string   refno = GetApproved[0].CS_RefNo;

            foreach (AF_CSModel csrequest in GetApproved)
            {
                if (csrequest.Approved == true)
                {
                    AF_ChangeSchedulefiling csfile = new AF_ChangeSchedulefiling();
                    csfile        = (from c in db.AF_ChangeSchedulefiling where c.Status > -1 && c.CS_RefNo == csrequest.CS_RefNo && c.EmployeeNo == csrequest.EmployeeNo select c).FirstOrDefault();
                    currentstatus = csfile.Status + 1;
                    csfile.Status = (csrequest.Approved == true) ? currentstatus : currentstatus - (currentstatus * 2);

                    if (csfile.Status >= csfile.StatusMax)
                    {
                        csfile.Status = 2;
                    }
                    db.Entry(csfile).State = EntityState.Modified;
                    db.SaveChanges();

                    stat    = csfile.Status;
                    statmax = csfile.StatusMax;
                }
                else
                {
                    AF_ChangeSchedulefiling csfile = new AF_ChangeSchedulefiling();
                    csfile        = (from c in db.AF_ChangeSchedulefiling where c.Status > -1 && c.CS_RefNo == csrequest.CS_RefNo && c.EmployeeNo == csrequest.EmployeeNo select c).FirstOrDefault();
                    currentstatus = csfile.Status + 1;
                    csfile.Status = (csrequest.Approved == true) ? currentstatus : currentstatus - (currentstatus * 2);
                    if (csfile.Status >= csfile.StatusMax)
                    {
                        csfile.Status = 2;
                    }
                    db.Entry(csfile).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            #region update Approver Status

            //string pos = (ifalter == "alter") ? "Alternative " + Position[currentstatus] : Position[currentstatus - 1];
            M_Section_ApproverStatus approverstatus = (from c in db.M_Section_ApproverStatus
                                                       where c.RefNo == refno &&
                                                       c.EmployeeNo == user.UserName
                                                       //&& c.EmployeeNo_CSRequest == csrequest.EmployeeNo
                                                       //&& c.Position == pos
                                                       select c).FirstOrDefault();

            approverstatus.ApprovedDate    = db.TT_GETTIME().FirstOrDefault();
            approverstatus.Approved        = 1;
            db.Entry(approverstatus).State = EntityState.Modified;
            db.SaveChanges();


            #endregion

            if (stat == statmax)
            {
                db.AF_UpdateApprovedSchedule(refno);
                //SendTheMail(GetApproved[0].CS_RefNo);
            }
            db.AF_EmailCSRequest(refno);
            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }