public async Task <IList <VMEmployee> > SearchAsync(VMEmployee searchEntity)
        {
            searchEntity.DefaultIfNullProperties();
            _logger.LogInformation("The search entity is {@searchEntity}", searchEntity);

            var createdDate = searchEntity.CreatedDate == null ? "%%" : $"%{searchEntity.CreatedDate}%";

            var result = await _dbContext.MEmployees
                         .Include(item => item.CreatedBy_Navigation)
                         .Include(item => item.MCompany_Navigation)
                         .Where(item => EF.Functions.Like(item.FirstName + " " + item.LastName, $"%{searchEntity.Name}%") &&
                                EF.Functions.Like(item.Code, $"%{searchEntity.Code}%") &&
                                EF.Functions.Like(item.MCompany_Navigation.Name, $"%{searchEntity.CompanyName}%") &&
                                EF.Functions.Like(item.CreatedBy_Navigation.UserName, $"%{searchEntity.CreatedBy}%")
                                //&& EF.Functions.Like(item.CreatedDate.ToString(), createdDate)
                                && item.IsDelete == false
                                )
                         .Select(item => new VMEmployee
            {
                Id          = item.Id,
                Code        = item.Code,
                Name        = $"{item.FirstName} {item.LastName}",
                CompanyName = $"{item.MCompany_Navigation.Name}",
                CreatedBy   = $"{item.CreatedBy_Navigation.UserName}",
                CreatedDate = item.CreatedDate.ToString("dd/MM/yyyy")
            })
                         .ToListAsync();

            return(result);
        }
Exemplo n.º 2
0
        public void PostCreate(VMEmployee obj, VMLoggedUser LoggedInUser)
        {
            // Gets the single emoployee from the database
            Employee employeeObj = new Employee();

            employeeObj.OEmpID            = obj.OEmpID;
            employeeObj.EmployeeName      = obj.EmployeeName;
            employeeObj.FPID              = Convert.ToInt32(obj.OEmpID);
            employeeObj.ShiftID           = obj.ShiftID;
            employeeObj.CardNo            = obj.CardNo;
            employeeObj.JobTitleID        = null;
            employeeObj.GradeID           = 13;
            employeeObj.CompanyID         = 1;
            employeeObj.LocationID        = 211;
            employeeObj.OUID              = null;
            employeeObj.COUID             = null;
            employeeObj.DesigationID      = null;
            employeeObj.DateOfBirth       = obj.DateOfBirth;
            employeeObj.DOJ               = obj.DOJ;
            employeeObj.FatherName        = obj.FatherName;
            employeeObj.CNIC              = obj.CNIC;
            employeeObj.EmploymentTypeID  = null;
            employeeObj.CrewID            = obj.CrewID;
            employeeObj.Status            = "Active";
            employeeObj.Gender            = obj.Gender;
            employeeObj.CNIC              = obj.CNIC;
            employeeObj.ProcessAttendance = true;
            employeeObj.HasOneStep        = true;
            EmployeeRepository.Add(employeeObj);
            EmployeeRepository.Save();
            //UnitOfWork.Commit();
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            VMEmployee obj = new VMEmployee();

            CreateHelper(obj);
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult Edit(int?id)
        {
            VMEmployee obj = EmployeeService.GetEdit((int)id);

            EditHelper(obj);
            return(PartialView(obj));
        }
Exemplo n.º 5
0
        // GET: Attend_Punchtime
        public ActionResult PunchtimeIndex()
        {
            VMEmployee Emp = getLoginEmpData();

            //取得client IP
            //string REMOTE_ADDR = Request.ServerVariables["REMOTE_ADDR"];
            string REMOTE_ADDR = "118.160.81.252";

            //設定允許的IP位址
            string[] IPList =
            {
                //我家
                "61.231.60.147",
                //學校
                "118.160.81.252"
            };
            bool isPass = false;

            foreach (var item in IPList)
            {
                if (item == REMOTE_ADDR)
                {
                    isPass = true; break;
                }
            }

            ViewBag.REMOTE_ADDR = REMOTE_ADDR;
            ViewBag.isPass      = isPass;

            //謹慎使用
            //(new CPunchtimeHelper()).InsertPunchtime(Emp.id, new DateTime(2020, 9, 1), new DateTime(2020, 10, 15));

            //申請人的同部門&上級
            int Auth        = ((Emp.auth + 1) > 3) ? 3 : (Emp.auth + 1);
            var supervisors = from s in db.tEmployees
                              where s.fDepartment == Emp.department && s.fAuth == Auth
                              select new
            {
                s.fEmployeeId,
                s.fName
            };
            //轉SelectListItem
            List <SelectListItem> sup_items = new List <SelectListItem>();

            foreach (var item in supervisors)
            {
                sup_items.Add(new SelectListItem()
                {
                    Text  = item.fName,
                    Value = item.fEmployeeId.ToString()
                });
            }

            //ViewBag 傳前端
            ViewBag.Empname     = Emp.name;
            ViewBag.supervisors = sup_items;
            ViewBag.applycount  = EmpApplyPunchtimeCount(Emp.id);

            return(View());
        }
Exemplo n.º 6
0
        public ActionResult Edit(VMEmployee obj)
        {
            VMLoggedUser vmf = Session["LoggedInUser"] as VMLoggedUser;

            if (obj.LineManagerID == 0)
            {
                obj.LineManagerID = null;
            }
            if (obj.CardNo != null && obj.CardNo != "")
            {
                Expression <Func <Employee, bool> > SpecificEntries = c => c.CardNo == obj.CardNo && c.PEmployeeID != obj.PEmployeeID;
                if (EmpDBService.GetIndexSpecific(SpecificEntries).Count() > 0)
                {
                    ModelState.AddModelError("CardNo", "Duplicate Card Number");
                }
            }
            if (obj.OfficialEmail != null)
            {
                Match match = Regex.Match(obj.OfficialEmail, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                if (!match.Success)
                {
                    ModelState.AddModelError("OfficialEmail", "Invalid Email Address");
                }
            }
            if (ModelState.IsValid)
            {
                EmployeeService.PostEdit(obj, vmf);
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }
            EditHelper(obj);
            return(PartialView("Edit", obj));
        }
Exemplo n.º 7
0
        public ActionResult CreateLeave(VMLeave leave)
        {
            VMEmployee Emp = getLoginEmpData();

            //檢查時數是否超過
            var checkLeave = (new CLeaveHelper()).checkLeavehour(Emp.id, leave.leavesort, leave.timecount);

            if (checkLeave.isPass)
            {
                //請假儲存
                tLeave tLeave = new tLeave();
                tLeave.fEmployeeId = Emp.id;
                tLeave.fSort       = leave.leavesort;
                tLeave.fApplyDate  = DateTime.Now;
                tLeave.fActiveDate = leave.start;
                tLeave.fEndDate    = leave.end;
                tLeave.fTimeCount  = leave.timecount;
                tLeave.fReason     = leave.reason;

                db.tLeaves.Add(tLeave);
                db.SaveChanges();

                //簽核表
                tSignoff tSignoff = new tSignoff();
                tSignoff.fLeaveId = int.Parse(db.tLeaves
                                              .OrderByDescending(p => p.fId)
                                              .Select(r => r.fId)
                                              .First().ToString());
                tSignoff.fSupervisorId = leave.supervisorId;
                tSignoff.fApplyClass   = leave.leavesort;
                tSignoff.fStartdate    = DateTime.Now;
                tSignoff.fEnddate      = leave.start;

                db.tSignoffs.Add(tSignoff);
                db.SaveChanges();

                //通知
                //tNotify notify = new tNotify();
                //notify.fEmployeeId = Convert.ToInt32(leave.supervisorId);
                //notify.fTitle = "員工請假申請通知";
                //notify.fContent = "員工 " + Emp.name + " 申請" + leave.leavesort;
                //notify.fType = 0;
                //notify.fTime = DateTime.Now;
                //notify.fSort = leave.leavesort;

                //db.tNotifies.Add(notify);
                //db.SaveChanges();

                TempData["Attend_msg"] = leave.leavesort + " 申請成功";

                return(RedirectToAction("AttendIndex", "Attend"));
            }
            else
            {
                TempData["Attend_err_msg"] = checkLeave.err_msg;

                return(RedirectToAction("LeaveIndex", "Attend_Leave"));
            }
        }
Exemplo n.º 8
0
        //打卡
        public ActionResult punchTime(DateTime now, bool isDemo)
        {
            VMEmployee Emp = getLoginEmpData();

            var punchtime = (new CPunchtimeHelper()).punchtime(Emp.id, now, isDemo);

            return(Json(new { msg_type = punchtime.msg_type, msg = punchtime.msg }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        //取得員工的打卡紀錄
        public ActionResult getEmpPunchtimes()
        {
            VMEmployee Emp = getLoginEmpData();

            List <VMPunchtime> Emp_punchtimelist = (new VMPunchtime()).getlist(db.tPunchtimes.Where(m => m.fEmployeeId == Emp.id).ToList());

            return(Json(Emp_punchtimelist, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public ActionResult getLeaveChartData()
        {
            VMEmployee Emp = getLoginEmpData();

            List <VMLeavecount> list =
                (new VMLeavecount()).getlist(db.tLeavecounts.Where(m => m.fEmployeeId == Emp.id).ToList());

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 11
0
        public ActionResult Add(VMEmployee vmemployee)
        {
            TbEmployee employee = mapper.Map <VMEmployee, TbEmployee>(vmemployee);
            DateTime   zeroTime = new DateTime(1, 1, 1);

            employee.Age = (zeroTime + (DateTime.Now.Date - employee.BirthDate)).Year;
            unitOfWork.Employees.Add(employee);
            unitOfWork.Complete();
            vmemployee.Id = employee.Id;
            return(Ok(vmemployee));
        }
Exemplo n.º 12
0
        public ActionResult Create(VMEmployee obj)
        {
            VMLoggedUser vmf = Session["LoggedInUser"] as VMLoggedUser;

            if (ModelState.IsValid)
            {
                EmployeeService.PostCreate(obj, vmf);
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }
            return(PartialView("Create", obj));
        }
Exemplo n.º 13
0
        public static VMEmployee ToVMEmployee(this ORViewEmployeeData entity)
        {
            VMEmployee model = new VMEmployee();

            model.Id          = entity.ID;
            model.FirstName   = entity.FirstName;
            model.LastName    = entity.LastName;
            model.Salary      = (float)entity.Salary;
            model.Designation = entity.Designation;
            return(model);
        }
Exemplo n.º 14
0
        public VMEmployee getLoginEmpData()
        {
            //取目前登入使用者
            HttpCookie cookie = Request.Cookies["id"];

            int empId = Convert.ToInt32(cookie.Value);

            VMEmployee vmemp = new VMEmployee().convert(db.tEmployees.Where(m => m.fEmployeeId == empId).FirstOrDefault());

            return(vmemp);
        }
Exemplo n.º 15
0
        private void CreateHelper(VMEmployee obj)
        {
            VMLoggedUser vmf = Session["LoggedInUser"] as VMLoggedUser;

            ViewBag.DesigationID     = new SelectList(DDService.GetDesignation(vmf).ToList().OrderBy(aa => aa.DesignationName).ToList(), "PDesignationID", "DesignationName", obj.DesigationID);
            ViewBag.LocationID       = new SelectList(DDService.GetLocation(vmf).ToList().OrderBy(aa => aa.LocationName).ToList(), "PLocationID", "LocationName", obj.LocationID);
            ViewBag.DepartmentID     = new SelectList(DDService.GetOU(vmf).ToList().OrderBy(aa => aa.OUName).ToList(), "POUID", "OUName", obj.DepartmentID);
            ViewBag.EmploymentTypeID = new SelectList(DDService.GetEmploymentType(vmf).ToList().OrderBy(aa => aa.EmploymentTypeName).ToList(), "PEmploymentTypeID", "EmploymentTypeName", obj.EmploymentTypeID);
            ViewBag.ShiftID          = new SelectList(DDService.GetShift(vmf).ToList().OrderBy(aa => aa.ShiftName).ToList(), "PShiftID", "ShiftName", obj.ShiftID);
            ViewBag.CrewID           = new SelectList(DDService.GetCrew(vmf).ToList().OrderBy(aa => aa.CrewName).ToList(), "PCrewID", "CrewName", obj.CrewID);
            ViewBag.GradeID          = new SelectList(DDService.GetGrade(vmf).ToList().OrderBy(aa => aa.GradeName).ToList(), "PGradeID", "GradeName", obj.GradeID);
        }
Exemplo n.º 16
0
        public ActionResult Get(int id)
        {
            TbEmployee employee = unitOfWork.Employees.GetEagerLoaded(id);

            if (employee == null)
            {
                return(NotFound());
            }
            VMEmployee vmemployee = mapper.Map <TbEmployee, VMEmployee>(employee);

            return(Ok(vmemployee));
        }
Exemplo n.º 17
0
        public ActionResult getLeaverecord()
        {
            VMEmployee Emp = getLoginEmpData();

            List <VMsignoff> list = (new VMsignoff())
                                    .getList(db.tSignoffs.ToList())
                                    .Where(m => m.emp_id == Emp.id)
                                    .Take(10)
                                    .ToList();

            return(Json(new { data = list }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 18
0
        //取得假別統計
        public ActionResult getLeaveTotal()
        {
            VMEmployee Emp = getLoginEmpData();

            var leavetotal = from lt in db.tLeaves
                             where lt.fEmployeeId == Emp.id
                             group lt by lt.fSort into g
                             select new
            {
                label = g.Key,
                hour  = g.Sum(p => p.fTimeCount)
            };

            return(Json(leavetotal.ToList(), JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> OnGetSearch(VMEmployee employeeView)
        {
            try
            {
                var employees = await _mEmployeeService.SearchAsync(employeeView);

                return(Partial("MEmployeePartials/_MEmployeeViewListPartial", employees));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error occured, {@ex}", ex);

                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 20
0
 public ActionResult AddEmployee(VMEmployee Employee)
 {
     try
     {
         if (ModelState.IsValid)
         {
             tblUser user = Session[WebUtil.CURRENT_USER] as tblUser;
             if (!(user != null))
             {
                 return(RedirectToAction("RedirectToLogin", "user"));
             }
             Employee e   = new Employee();
             long     uno = DateTime.Now.Ticks;
             if (Employee.ImageUrl != null)
             {
                 HttpPostedFileBase file = Employee.ImageUrl;
                 if (!string.IsNullOrWhiteSpace(file.FileName))
                 {
                     string url  = $"~/DataImages/Employee/{uno}{file.FileName.Substring(file.FileName.LastIndexOf("."))}";
                     string path = Request.MapPath(url);
                     file.SaveAs(path);
                     e.ImageUrl = url;
                 }
             }
             e.CompanyId   = user.CompanyId;
             e.FirstName   = Employee.FirstName;
             e.LastName    = Employee.LastName;
             e.Designation = Employee.Designation;
             e.CreatedBy   = user.Id;
             e.CreatedDate = DateTime.Now;
             tblSalary s = new tblSalary();
             s.Salary      = Employee.Salary;
             s.CreatedBy   = user.CreatedBy;
             s.CreatedDate = DateTime.Now;
             s.EmployeeId  = 0;
             new EmployeeHandler().AddEmployee(e, s);
             return(JavaScript("showMessage('success', 'Employee added Successfully','bottom-right','Employee', 'Manage')"));
         }
         else
         {
             return(JavaScript("showMessage('error', 'All fields are required, Please try again','bottom-right','Employee', 'Manage')"));
         }
     }
     catch (Exception ex)
     {
         return(JavaScript("showMessage('error', 'Failed to Add Employee, Please Contact to Administrator','bottom-right','Employee', 'Manage')"));
     }
 }
Exemplo n.º 21
0
        public ActionResult CreateOverTime()
        {
            HttpCookie cookie = Request.Cookies["id"];
            int        u      = Convert.ToInt32(cookie.Value);
            int        fakeid = u;

            //取得該名員工資料
            Emp = (new VMEmployee())
                  .convert(db.tEmployees
                           .Where(m => m.fEmployeeId == fakeid)
                           .FirstOrDefault());

            //ViewBag 傳前端
            ViewBag.emp = Newtonsoft.Json.JsonConvert.SerializeObject(Emp);
            return(View());
        }
Exemplo n.º 22
0
        public ActionResult Update(VMEmployee vmemployee)
        {
            TbEmployee employee = unitOfWork.Employees.Get(vmemployee.Id);
            DateTime   zeroTime = new DateTime(1, 1, 1);

            employee.Age          = (zeroTime + (DateTime.Now.Date - vmemployee.BirthDate)).Year;
            employee.Name         = vmemployee.Name;
            employee.BirthDate    = vmemployee.BirthDate;
            employee.Email        = vmemployee.Email;
            employee.Phone        = vmemployee.Phone;
            employee.JobId        = vmemployee.JobId;
            employee.DepartmentId = vmemployee.DepartmentId;
            employee.Address      = vmemployee.Address;
            employee.ImagePath    = vmemployee.ImagePath;
            unitOfWork.Complete();
            return(Ok(vmemployee));
        }
Exemplo n.º 23
0
        // GET: Attend
        public ActionResult AttendIndex()
        {
            VMEmployee Emp = getLoginEmpData();

            var Todayrecord = from p in db.tPunchtimes.AsEnumerable()
                              where p.fDatetime.Date == DateTime.Now.Date && p.fEmployeeId == Emp.id
                              select new
            {
                status   = p.fstatus,
                datetime = p.fDatetime.ToLongTimeString()
            };

            //ViewBag 傳前端
            ViewBag.Todayrecord = Newtonsoft.Json.JsonConvert.SerializeObject(Todayrecord);

            return(View());
        }
        public ActionResult Create([Bind(Include = "EmployeeID,CityID,Name,Email,Salary")] VMEmployee vmemployee)
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                employee.Name   = vmemployee.Name;
                employee.Email  = vmemployee.Email;
                employee.Salary = vmemployee.Salary;
                employee.CityID = vmemployee.CityID;

                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            return(View(vmemployee));
        }
Exemplo n.º 25
0
        public ActionResult punchTimeApply(VMPunchtimeApply applyPunchtime)
        {
            VMEmployee Emp = getLoginEmpData();

            //用完申請紀錄
            if (EmpApplyPunchtimeCount(Emp.id) == 0)
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
            //重複申請
            if (db.tApplypunches.Where(m => m.fPunchTimeId == applyPunchtime.applyId).FirstOrDefault() != null)
            {
                return(Json("same", JsonRequestBehavior.AllowGet));
            }

            //申請補打卡
            tApplypunch Applypunch = new tApplypunch();

            Applypunch.fEmployeeId  = Emp.id;
            Applypunch.fPunchTimeId = applyPunchtime.applyId;
            Applypunch.fApplyDate   = DateTime.Now;
            Applypunch.fSort        = applyPunchtime.sort;
            Applypunch.fReason      = applyPunchtime.reason;

            db.tApplypunches.Add(Applypunch);
            db.SaveChanges();

            //簽核表 3天內審核完成
            tSignoff tSignoff = new tSignoff();

            tSignoff.fAlpplypunchId = int.Parse(db.tApplypunches
                                                .OrderByDescending(p => p.fId)
                                                .Select(r => r.fId)
                                                .First().ToString());
            tSignoff.fSupervisorId = applyPunchtime.supervisorId;
            tSignoff.fApplyClass   = applyPunchtime.sort;
            tSignoff.fStartdate    = DateTime.Now;
            tSignoff.fEnddate      = DateTime.Now.AddDays(3);

            db.tSignoffs.Add(tSignoff);
            db.SaveChanges();

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit([Bind(Include = "EmployeeID,CityID,Name,Email,Salary")] VMEmployee vmemployee)
        {
            if (ModelState.IsValid)
            {
                Employee employee = db.Employees.Find(vmemployee.EmployeeID);


                employee.Name   = vmemployee.Name;
                employee.Email  = vmemployee.Email;
                employee.Salary = vmemployee.Salary;
                employee.CityID = vmemployee.CityID;

                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vmemployee));
        }
Exemplo n.º 27
0
        private void EditHelper(VMEmployee obj)
        {
            VMLoggedUser vmf = Session["LoggedInUser"] as VMLoggedUser;

            ViewBag.LineManagerID    = new SelectList(AppAssistant.GetLineManagers(DDService.GetUser().ToList()), "PUserID", "UserName", obj.LineManagerID);
            ViewBag.OTPolicyID       = new SelectList(DDService.GetOTPolicy().ToList().OrderBy(aa => aa.OTPolicyName).ToList(), "POTPolicyID", "OTPolicyName", obj.OTPolicyID);
            ViewBag.ShiftID          = new SelectList(DDService.GetShift(vmf).ToList().OrderBy(aa => aa.ShiftName).ToList(), "PShiftID", "ShiftName", obj.ShiftID);
            ViewBag.ALPolicyID       = new SelectList(DDService.GetLeavePolicy().Where(aa => aa.LeaveTypeID == 1).ToList().OrderBy(aa => aa.LeavePolicyName).ToList(), "PLeavePolicyID", "LeavePolicyName", obj.ALPolicyID);
            ViewBag.SLPolicyID       = new SelectList(DDService.GetLeavePolicy().Where(aa => aa.LeaveTypeID == 3).ToList().OrderBy(aa => aa.LeavePolicyName).ToList(), "PLeavePolicyID", "LeavePolicyName", obj.SLPolicyID);
            ViewBag.CLPolicyID       = new SelectList(DDService.GetLeavePolicy().Where(aa => aa.LeaveTypeID == 2).ToList().OrderBy(aa => aa.LeavePolicyName).ToList(), "PLeavePolicyID", "LeavePolicyName", obj.CLPolicyID);
            ViewBag.CPLPolicyID      = new SelectList(DDService.GetLeavePolicy().Where(aa => aa.LeaveTypeID == 4).ToList().OrderBy(aa => aa.LeavePolicyName).ToList(), "PLeavePolicyID", "LeavePolicyName", obj.CPLPolicyID);
            ViewBag.CrewID           = new SelectList(DDService.GetCrew(vmf).ToList().OrderBy(aa => aa.CrewName).ToList(), "PCrewID", "CrewName", obj.CrewID);
            ViewBag.DesigationID     = new SelectList(DDService.GetDesignation(vmf).ToList().OrderBy(aa => aa.DesignationName).ToList(), "PDesignationID", "DesignationName", obj.DesigationID);
            ViewBag.LocationID       = new SelectList(DDService.GetLocation(vmf).ToList().OrderBy(aa => aa.LocationName).ToList(), "PLocationID", "LocationName", obj.LocationID);
            ViewBag.DepartmentID     = new SelectList(DDService.GetOU(vmf).ToList().OrderBy(aa => aa.OUName).ToList(), "POUID", "OUName", obj.DepartmentID);
            ViewBag.EmploymentTypeID = new SelectList(DDService.GetEmploymentType(vmf).ToList().OrderBy(aa => aa.EmploymentTypeName).ToList(), "PEmploymentTypeID", "EmploymentTypeName", obj.EmploymentTypeID);
            ViewBag.ShiftID          = new SelectList(DDService.GetShift(vmf).ToList().OrderBy(aa => aa.ShiftName).ToList(), "PShiftID", "ShiftName", obj.ShiftID);
            ViewBag.GradeID          = new SelectList(DDService.GetGrade(vmf).ToList().OrderBy(aa => aa.GradeName).ToList(), "PGradeID", "GradeName", obj.GradeID);
        }
Exemplo n.º 28
0
 public ActionResult UpdateEmployee(long Id)
 {
     try
     {
         tblUser user = Session[WebUtil.CURRENT_USER] as tblUser;
         if (!(user != null))
         {
             return(RedirectToAction("RedirectToLogin", "user"));
         }
         DAL.Employee  tblEmployee = new EmployeeHandler().GetEmployee(Id);
         DAL.tblSalary tblSalary   = new SalaryHandler().GetSalaryOfEmployee(Id);
         VMEmployee    Model       = new VMEmployee {
             Id = Id, Designation = tblEmployee.Designation, FirstName = tblEmployee.FirstName, LastName = tblEmployee.LastName, Salary = (float)tblSalary.Salary
         };
         return(PartialView("~/Views/Employee/_UpdateEmployee.cshtml", Model));
     }
     catch (Exception ex)
     {
         return(JavaScript("showMessage('error', 'Something went wrong','bottom-right','Employee', 'Manage')"));
     }
 }
Exemplo n.º 29
0
        // GET: Attend_Info
        public ActionResult InfoIndex()
        {
            //取目前登入使用者
            VMEmployee Emp = getLoginEmpData();

            //取得員工申請的紀錄
            List <VMsignoff> list = (new VMsignoff())
                                    .getList(db.tSignoffs
                                             .OrderByDescending(m => m.fId).ToList());

            Emp_list = list.Where(m => m.emp_id == Emp.id).ToList();

            //需要隨時更新
            //若此員工沒特休紀錄,載入一個
            var Leave_特休假 = db.tLeavecounts.Where(m => m.fEmployeeId == Emp.id && m.fSortId == 1).FirstOrDefault();

            if (Leave_特休假 == null)
            {
                (new CLeaveHelper()).Leavecount(Emp.id, "特休假", 0);
            }

            return(View());
        }
Exemplo n.º 30
0
        public ActionResult CreateOverTime(tOvertime o, tSignoff s, tEmployee t)
        {
            HttpCookie cookie = Request.Cookies["id"];
            int        u      = Convert.ToInt32(cookie.Value);
            int        fakeid = u;

            Emp = (new VMEmployee())
                  .convert(db.tEmployees
                           .Where(m => m.fEmployeeId == fakeid)
                           .FirstOrDefault());

            //ViewBag 傳前端
            ViewBag.emp = Newtonsoft.Json.JsonConvert.SerializeObject(Emp);
            //撈資料庫當月
            double TimeCountForMonth = (from a in db.tOvertimes.AsEnumerable()
                                        join ts4 in db.tSignoffs.AsEnumerable()
                                        on a.fId equals ts4.fOvertimeId
                                        where a.fActiveDate.Year == DateTime.Now.Year &&
                                        a.fActiveDate.Month == DateTime.Now.Month &&
                                        a.fEmployeeId == fakeid &&
                                        ts4.fIsAgreed == 1
                                        select a.fTimeCount).DefaultIfEmpty(0).Sum();

            ////撈資料庫上個月
            //double TimeCountLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                              where a.fActiveDate.Year == DateTime.Now.Year
            //                              && a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month
            //                              && a.fEmployeeId == fakeid
            //                              select a.fTimeCount).Sum();
            ////撈資料庫上上個月
            //double TimeCountBeforeLastMonth = (from a in db.tOvertimes.AsEnumerable()
            //                                   where a.fActiveDate.Year == DateTime.Now.Year
            //                                   && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month
            //                                   && a.fEmployeeId == fakeid
            //                                   select a.fTimeCount).Sum();
            if (string.IsNullOrEmpty(o.fSort) || string.IsNullOrEmpty(o.fReason))
            {
                TempData["Attend_msg"] = "請輸入加班類別或原因";
                return(View());
            }
            //本日加班查詢
            int    NowDateMonth   = o.fActiveDate.Month;
            int    NowDate        = o.fActiveDate.Day;
            double TimeCountToday = (from a in db.tOvertimes.AsEnumerable()
                                     join ts5 in db.tSignoffs.AsEnumerable()
                                     on a.fId equals ts5.fOvertimeId
                                     where a.fActiveDate.Month == NowDateMonth &&
                                     a.fActiveDate.Day == NowDate &&
                                     a.fEmployeeId == fakeid &&
                                     ts5.fIsAgreed == 1
                                     select a.fTimeCount).DefaultIfEmpty().Sum() + o.fTimeCount;
            //三個月加班合計
            //本月
            double TimeCountOne = (from b in db.tOvertimes.AsEnumerable()
                                   join ts6 in db.tSignoffs.AsEnumerable()
                                   on b.fId equals ts6.fOvertimeId
                                   where b.fActiveDate.Year == DateTime.Now.Year &&
                                   b.fActiveDate.Month == DateTime.Now.Month &&
                                   b.fEmployeeId == fakeid &&
                                   ts6.fIsAgreed == 1
                                   select b.fTimeCount).Sum();
            //上月
            double TimeCountTwo = (from c in db.tOvertimes.AsEnumerable()
                                   join ts7 in db.tSignoffs.AsEnumerable()
                                   on c.fId equals ts7.fOvertimeId
                                   where c.fActiveDate.Year == DateTime.Now.Year &&
                                   c.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month &&
                                   c.fEmployeeId == fakeid &&
                                   ts7.fIsAgreed == 1
                                   select c.fTimeCount).Sum();
            //上上月
            double TimeCountThree = (from d in db.tOvertimes.AsEnumerable()
                                     join ts8 in db.tSignoffs.AsEnumerable()
                                     on d.fId equals ts8.fOvertimeId
                                     where d.fActiveDate.Year == DateTime.Now.Year &&
                                     d.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month &&
                                     d.fEmployeeId == fakeid &&
                                     ts8.fIsAgreed == 1
                                     select d.fTimeCount).Sum();

            double TimeCountThreeMonth = TimeCountOne + TimeCountTwo + TimeCountThree;

            //第一層判斷他目前是不是已經超過加班上限了
            //if (TimeCountForMonth > 46)
            //{
            //    TempData["message"] = "你太累瞜~~當月加班時數超過上限";
            //    return View();
            //}
            if (TimeCountThreeMonth > 138)
            {
                TempData["Attend_msg"] = "你太累瞜~~三個月內累計加班時數超過上限";
                return(View());
            }

            if (o.fTimeCount > 4 || TimeCountToday > 4)
            {
                if (o.fSort == "平日加班")
                {
                    TempData["Attend_msg"] = "你太累瞜~~平日加班時數超過上限";
                    return(View());
                }
                else if (TimeCountToday > 12)
                {
                    TempData["Attend_msg"] = "你太累瞜~~當日加班總時數超過上限";
                    return(View());
                }
            }
            //假設系統撈出來的資料目前都沒有超過上限
            //新增時共有兩個Table,一個是加班申請,一個是簽核表插入
            s.fOvertimeId = o.fId;                           //簽核表編號=加班申請fid
            s.fApplyClass = o.fSort;                         //簽核表種類=加班申請
            o.fSubmitDate = DateTime.Now /*.ToLocalTime()*/; //申請日期等於Now
            o.fActiveDate = o.fActiveDate /*.ToLocalTime()*/;
            s.fStartdate  = o.fActiveDate;                   //簽核表申請日期=現在加班申請日期

            //s.tEmployee.fEmployeeId = fakeid;//簽核表寫入員工編號
            o.fEmployeeId = fakeid;//加班表寫入員工編號

            //查詢部門別及權限用來判斷核決主管是誰
            var Check = (from b in db.tEmployees
                         where b.fEmployeeId == fakeid
                         select new { b.fDepartment, b.fAuth }).FirstOrDefault();
            //先把物件取出來,登入者的資訊物件

            //這個是登入者的部門
            string department = Check.fDepartment.ToString();
            //這個是登入者的權限
            int auth = Check.fAuth;

            //帶入主管編號
            var SupervisorIdCheckJunior = (from a in db.tEmployees
                                           where a.fAuth == 2 && a.fDepartment == department
                                           select new { a.fEmployeeId }).FirstOrDefault();
            var SupervisorIdCheckSenior = (from a in db.tEmployees
                                           where a.fAuth == 3 && a.fDepartment == department
                                           select new { a.fEmployeeId }).FirstOrDefault();
            //這個是一般主管的代號
            int SupervisorJunior = SupervisorIdCheckJunior.fEmployeeId;
            //這個是最高權限的代號
            int SupervisorIdSenior = SupervisorIdCheckSenior.fEmployeeId;

            //寫入相對應的主管編號
            if (auth == 1)
            {
                s.fSupervisorId = SupervisorJunior;//主管權限
            }
            else
            {
                s.fSupervisorId = SupervisorIdSenior;//最高權限編號
            }

            s.fIsAgreed  = null;                           //寫入是否同意,預設為null(待審核)
            s.fEnddate   = o.fActiveDate;
            o.fTimeCount = Convert.ToDouble(o.fTimeCount); //選單輸入的文字轉成加班的數字並存回加班表
            //很遺憾的,可能有超時狀況,進入細項判斷式
            if (o.fTimeCount + TimeCountForMonth > 46 || o.fTimeCount + TimeCountThreeMonth > 138)
            {
                //這個是申請當月的月份
                int NowMonth        = s.fStartdate.Month;
                int LastMonth       = s.fStartdate.Month - 1;
                int BeforeLastMonth = s.fStartdate.Month - 2;

                //申請加班開始日期的月份已經請的時數
                double now = (from to in db.tOvertimes.AsEnumerable()
                              join ts1 in db.tSignoffs.AsEnumerable()
                              on to.fId equals ts1.fOvertimeId
                              where to.fActiveDate.Year == DateTime.Now.Year &&
                              to.fActiveDate.Month == NowMonth &&
                              to.fEmployeeId == fakeid &&
                              ts1.fIsAgreed == 1
                              select to.fTimeCount).DefaultIfEmpty(0).Sum();


                //申請加班開始日期的上個月已經請的時數
                double Last = (from a in db.tOvertimes.AsEnumerable()
                               join ts2 in db.tSignoffs.AsEnumerable()
                               on a.fId equals ts2.fOvertimeId
                               where a.fActiveDate.Year == DateTime.Now.Year &&
                               a.fActiveDate.Month == LastMonth &&
                               a.fEmployeeId == fakeid &&
                               ts2.fIsAgreed == 1
                               select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班開始日期的上上個月已經請的時數
                double BeforeLast = (from a in db.tOvertimes.AsEnumerable()
                                     join ts3 in db.tSignoffs.AsEnumerable()
                                     on a.fId equals ts3.fOvertimeId
                                     where a.fActiveDate.Year == DateTime.Now.Year &&
                                     a.fActiveDate.Month == BeforeLastMonth &&
                                     a.fEmployeeId == fakeid &&
                                     ts3.fIsAgreed == 1
                                     select a.fTimeCount).DefaultIfEmpty(0).Sum();

                //申請加班當月的時數已經超過上限
                if (now + o.fTimeCount > 46)
                {
                    TempData["Attend_msg"] = "你太累瞜~~當月加班時數超過上限";
                    return(View());
                }
                //申請加班的前三個月總時數已經超過上限
                else if (Last + BeforeLast + o.fTimeCount > 138)
                {
                    TempData["Attend_msg"] = "你太累瞜~~累計三個月內加班時數超過上限";
                    return(View());
                }
                //沒事,他有可能是申請上個月的加班,但是因為這個月已經滿了,才會進來這個鬼地方
                else
                {
                    //他可以出去判斷式了
                    db.tOvertimes.Add(o); //加入t物件(加班表)
                    db.tSignoffs.Add(s);  //加入s物件(簽核表)
                    db.SaveChanges();     //存檔
                    TempData["Attend_msg"] = "送出成功";
                    //return View();
                    return(RedirectToAction("AttendIndex", "Attend"));
                }
            }
            //他當月既沒有超過上限,三個月內也沒有超過上限
            db.tOvertimes.Add(o); //加入t物件(加班表)
            db.tSignoffs.Add(s);  //加入s物件(簽核表)
            db.SaveChanges();     //存檔
            TempData["Attend_msg"] = "送出成功";
            //return View();
            return(RedirectToAction("AttendIndex", "Attend"));
        }