public static MyShift GetEmployeeShift(Att_Shift att_Shift) { MyShift shift = new MyShift(); shift.ShftID = att_Shift.ShftID; shift.StartTime = att_Shift.StartTime; shift.DayOff1 = att_Shift.DayOff1; shift.DayOff2 = att_Shift.DayOff2; shift.MonMin = att_Shift.MonMin; shift.TueMin = att_Shift.TueMin; shift.WedMin = att_Shift.WedMin; shift.ThuMin = att_Shift.ThuMin; shift.FriMin = att_Shift.FriMin; shift.SatMin = att_Shift.SatMin; shift.SunMin = att_Shift.SunMin; shift.LateIn = (short)att_Shift.LateIn; shift.EarlyIn = (short)att_Shift.EarlyIn; shift.EarlyOut = (short)att_Shift.EarlyOut; shift.LateOut = (short)att_Shift.LateOut; shift.OverTimeMin = (short)att_Shift.OverTimeMin; shift.MinHrs = (short)att_Shift.MinHrs; shift.HasBreak = (bool)att_Shift.HasBreak; shift.BreakMin = (short)att_Shift.BreakMin; shift.HalfDayBreakMin = (short)att_Shift.HalfDayBreakMin; shift.GZDays = (bool)att_Shift.GZDays; shift.OpenShift = (bool)att_Shift.OpenShift; shift.RoundOffWorkMin = (bool)att_Shift.RoundOffWorkMin; // shift.SubtractOTFromWork = (bool)att_Shift.SubtractOTFromWork; shift.SubtractEIFromWork = (bool)att_Shift.SubtractEIFromWork; // shift.AddEIInOT = (bool)att_Shift.AddEIInOT; shift.PresentAtIN = (bool)att_Shift.PresentAtIN; shift.CalDiffOnly = (bool)att_Shift.CalDiffOnly; return(shift); }
//Work Times calculation controller public void ProcessDailyAttendance(Att_DailyAttendance _attData) { try { Att_DailyAttendance attendanceRecord = _attData; HR_Employee employee = attendanceRecord.HR_Employee; List <Att_ShiftChngedEmp> _shiftEmpCh = new List <Att_ShiftChngedEmp>(); _shiftEmpCh = context.Att_ShiftChngedEmp.ToList(); List <Att_OutPass> _OutPasses = new List <Att_OutPass>(); _OutPasses = context.Att_OutPass.Where(aa => aa.EmpID == _attData.EmpID && aa.Dated == _attData.AttDate.Value).ToList(); List <Att_Shift> shifts = new List <Att_Shift>(); shifts = context.Att_Shift.ToList(); List <Att_ShiftChanged> cshifts = new List <Att_ShiftChanged>(); cshifts = context.Att_ShiftChanged.ToList(); if (_attData.StatusLeave == true) { _attData.ShifMin = 0; } //If TimeIn and TimeOut are not null, then calculate other Atributes if (_attData.TimeIn != null && _attData.TimeOut != null) { Att_Shift _shift = ProcessSupportFunc.GetEmployeeChangedShift(_attData.HR_Employee, _shiftEmpCh.Where(aa => aa.EmpID == _attData.EmpID).ToList(), _attData.AttDate.Value, shifts); MyShift shift = ProcessSupportFunc.GetEmployeeShift(_shift); if (_attData.StatusHL == true) { _attData.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(shift, _attData.AttDate.Value.DayOfWeek); _attData.ShifMin = (short)(_attData.ShifMin / 2); } //If TimeIn = TimeOut then calculate according to DutyCode if (_attData.TimeIn == _attData.TimeOut) { CalculateInEqualToOut(_attData); } else { if (_attData.DutyTime == new TimeSpan(0, 0, 0)) { //CalculateWorkMins.CalculateOpenShiftTimes(_attData, shift, _attData.HR_Employee.Att_OTPolicy); } Att_OutPass aop = new Att_OutPass(); if (_OutPasses.Where(aa => aa.Dated == _attData.AttDate && aa.EmpID == _attData.EmpID).Count() > 0) { aop = _OutPasses.First(aa => aa.Dated == _attData.AttDate && aa.EmpID == _attData.EmpID); } //CalculateWorkMins.CalculateShiftTimes(_attData, shift, _attData.HR_Employee.Att_OTPolicy, aop); } } else { CalculateInEqualToOut(_attData); } } catch (Exception ex) { } context.SaveChanges(); }
public static DateTime CalculateShiftEndTime(Att_Shift shift, DateTime _AttDate, TimeSpan _DutyTime) { Int16 workMins = 0; try { switch (_AttDate.Date.DayOfWeek) { case DayOfWeek.Monday: workMins = shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } } catch (Exception ex) { } DateTime _datetime = new DateTime(); TimeSpan _Time = new TimeSpan(0, workMins, 0); _datetime = _AttDate.Date.Add(_DutyTime); _datetime = _datetime.Add(_Time); return(_datetime); }
public ActionResult DeleteConfirmed(short id) { try { Att_Shift att_shift = db.Att_Shift.Find(id); db.Att_Shift.Remove(att_shift); db.SaveChanges(); ViewUserEmp loggedUser = Session["LoggedUser"] as ViewUserEmp; AuditManager.SaveAuditLog(loggedUser.UserID, Convert.ToInt16(AuditManager.AuditForm.Shift), Convert.ToInt16(AuditManager.AuditOperation.Delete), DateTime.Now, (int)att_shift.ShftID); return(RedirectToAction("Index")); } catch (Exception) { throw; } }
public static TimeSpan CalculateShiftEndTime(Att_Shift shift, DayOfWeek dayOfWeek) { Int16 workMins = 0; try { switch (dayOfWeek) { case DayOfWeek.Monday: workMins = shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } } catch (Exception ex) { } return(shift.StartTime + (new TimeSpan(0, workMins, 0))); }
// GET: /Attendance/Shift/Details/5 public ActionResult Details(short?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Att_Shift att_shift = db.Att_Shift.Find(id); if (att_shift == null) { return(HttpNotFound()); } return(View(att_shift)); } catch (Exception) { throw; } }
// GET: /Attendance/Shift/Edit/5 public ActionResult Edit(short?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Att_Shift att_shift = db.Att_Shift.Find(id); if (att_shift == null) { return(HttpNotFound()); } ViewBag.DayOff1 = new SelectList(db.Att_DaysName, "ID", "Name", att_shift.DayOff1); ViewBag.DayOff2 = new SelectList(db.Att_DaysName, "ID", "Name", att_shift.DayOff2); return(View(att_shift)); } catch (Exception) { throw; } }
internal static Att_Shift GetEmployeeChangedShift(HR_Employee emp, List <Att_ShiftChngedEmp> empshiftCh, DateTime currentDate, List <Att_Shift> shifts) { Att_Shift shift = emp.Att_Shift; foreach (var item in empshiftCh) { if (item.EndDate == null) { if (currentDate >= item.StartDate) { shift = shifts.First(aa => aa.ShftID == item.ShiftID); } } else { if (currentDate >= item.StartDate && currentDate <= item.EndDate) { shift = shifts.First(aa => aa.ShftID == item.ShiftID); } } } return(shift); }
public ActionResult Create([Bind(Include = "ShftID,ShiftName,StartTime,DayOff1,DayOff2,MonMin,TueMin,WedMin,ThuMin,FriMin,SatMin,SunMin,LateIn,EarlyIn,EarlyOut,LateOut,OverTimeMin,MinHrs,HasBreak,BreakMin,HalfDayBreakMin,GZDays,OpenShift,RoundOffWorkMin,SubtractLOFromWork,SubtractEIFromWork,PresentAtIN,CalDiffOnly")] Att_Shift att_shift) { try { att_shift.GZDays = (bool)ValueProvider.GetValue("GZDays").ConvertTo(typeof(bool)); att_shift.OpenShift = (bool)ValueProvider.GetValue("OpenShift").ConvertTo(typeof(bool)); att_shift.HasBreak = (bool)ValueProvider.GetValue("HasBreak").ConvertTo(typeof(bool)); att_shift.RoundOffWorkMin = (bool)ValueProvider.GetValue("RoundOffWorkMin").ConvertTo(typeof(bool)); att_shift.SubtractLOFromWork = (bool)ValueProvider.GetValue("SubtractLOFromWork").ConvertTo(typeof(bool)); att_shift.SubtractEIFromWork = (bool)ValueProvider.GetValue("SubtractEIFromWork").ConvertTo(typeof(bool)); att_shift.PresentAtIN = (bool)ValueProvider.GetValue("PresentAtIN").ConvertTo(typeof(bool)); #region -- Validation-- if (att_shift.ShiftName == null || att_shift.ShiftName == "") { ModelState.AddModelError("ShiftName", "Please add Name"); } if (att_shift.StartTime == null) { ModelState.AddModelError("StartTime", "Please add Start Time"); } if (att_shift.MonMin == null) { ModelState.AddModelError("MonMin", "Please add Minutes"); } if (att_shift.MonMin == null) { ModelState.AddModelError("MonMin", "Please add Minutes"); } if (att_shift.TueMin == null) { ModelState.AddModelError("TueMin", "Please add Minutes"); } if (att_shift.WedMin == null) { ModelState.AddModelError("WedMin", "Please add Minutes"); } if (att_shift.ThuMin == null) { ModelState.AddModelError("ThuMin", "Please add Minutes"); } if (att_shift.FriMin == null) { ModelState.AddModelError("FriMin", "Please add Minutes"); } if (att_shift.SatMin == null) { ModelState.AddModelError("SatMin", "Please add Minutes"); } if (att_shift.SunMin == null) { ModelState.AddModelError("SunMin", "Please add Minutes"); } if (att_shift.LateIn == null) { ModelState.AddModelError("LateIn", "Please add Minutes"); } if (att_shift.LateOut == null) { ModelState.AddModelError("LateOut", "Please add Minutes"); } if (att_shift.EarlyIn == null) { ModelState.AddModelError("EarlyIn", "Please add Minutes"); } if (att_shift.EarlyOut == null) { ModelState.AddModelError("EarlyOut", "Please add Minutes"); } if (att_shift.OverTimeMin == null) { ModelState.AddModelError("OverTimeMin", "Please add Minutes"); } if (att_shift.MinHrs == null) { ModelState.AddModelError("MinHrs", "Please add Minutes"); } if (att_shift.HasBreak == true) { if (att_shift.BreakMin == null) { ModelState.AddModelError("BreakMin", "Please add Break Minutes"); } if (att_shift.HalfDayBreakMin == null) { ModelState.AddModelError("HalfDayBreakMin", "Please add Half Day Break Minutes"); } } if (db.Att_Shift.Where(aa => aa.ShiftName == att_shift.ShiftName).Count() > 0) { ModelState.AddModelError("ShiftName", "Shift name must be unique"); } #endregion try { if (ModelState.IsValid) { if (att_shift.HasBreak == false) { att_shift.BreakMin = 0; att_shift.HalfDayBreakMin = 0; } db.Att_Shift.Add(att_shift); db.SaveChanges(); ViewUserEmp loggedUser = Session["LoggedUser"] as ViewUserEmp; AuditManager.SaveAuditLog(loggedUser.UserID, Convert.ToInt16(AuditManager.AuditForm.Shift), Convert.ToInt16(AuditManager.AuditOperation.Add), DateTime.Now, (int)att_shift.ShftID); return(RedirectToAction("Index")); } } catch (Exception ex) { return(View(ex)); } ViewBag.DayOff1 = new SelectList(db.Att_DaysName, "ID", "Name"); ViewBag.DayOff2 = new SelectList(db.Att_DaysName, "ID", "Name"); return(View(att_shift)); } catch (Exception) { throw; } }