public void ProcessManualEditAttendance(DateTime _dateStart, DateTime _dateEnd) { List <AttDataManEdit> _attEdit = new List <AttDataManEdit>(); List <AttData> _AttData = new List <AttData>(); AttData _TempAttData = new AttData(); using (var ctx = new TAS2013Entities()) { if (_dateStart == _dateEnd) { _attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn == _dateStart).OrderBy(aa => aa.EditDateTime).ToList(); _dateEnd = _dateEnd + new TimeSpan(23, 59, 59); //_attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && aa.NewTimeIn <= _dateEnd && (aa.EmpID == 472)).OrderBy(aa => aa.EditDateTime).ToList(); _AttData = ctx.AttDatas.Where(aa => aa.AttDate == _dateStart).ToList(); } else { _attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && aa.NewTimeOut <= _dateEnd).OrderBy(aa => aa.EditDateTime).ToList(); //_attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && (aa.NewTimeOut <= _dateEnd && aa.EmpID == 472)).OrderBy(aa => aa.EditDateTime).ToList(); _AttData = ctx.AttDatas.Where(aa => aa.AttDate >= _dateStart && aa.AttDate <= _dateEnd).ToList(); } foreach (var item in _attEdit) { _TempAttData = _AttData.First(aa => aa.EmpDate == item.EmpDate); _TempAttData.TimeIn = item.NewTimeIn; _TempAttData.TimeOut = item.NewTimeOut; _TempAttData.DutyCode = item.NewDutyCode; _TempAttData.DutyTime = item.NewDutyTime; switch (_TempAttData.DutyCode) { case "D": _TempAttData.StatusAB = true; _TempAttData.StatusP = false; _TempAttData.StatusMN = true; _TempAttData.StatusDO = false; _TempAttData.StatusGZ = false; _TempAttData.StatusLeave = false; _TempAttData.StatusOT = false; _TempAttData.OTMin = null; _TempAttData.EarlyIn = null; _TempAttData.EarlyOut = null; _TempAttData.LateIn = null; _TempAttData.LateOut = null; _TempAttData.WorkMin = null; _TempAttData.GZOTMin = null; break; case "G": _TempAttData.StatusAB = false; _TempAttData.StatusP = false; _TempAttData.StatusMN = true; _TempAttData.StatusDO = false; _TempAttData.StatusGZ = true; _TempAttData.StatusLeave = false; _TempAttData.StatusOT = false; _TempAttData.OTMin = null; _TempAttData.EarlyIn = null; _TempAttData.EarlyOut = null; _TempAttData.LateIn = null; _TempAttData.LateOut = null; _TempAttData.WorkMin = null; _TempAttData.GZOTMin = null; break; case "R": _TempAttData.StatusAB = false; _TempAttData.StatusP = false; _TempAttData.StatusMN = true; _TempAttData.StatusDO = true; _TempAttData.StatusGZ = false; _TempAttData.StatusLeave = false; _TempAttData.StatusOT = false; _TempAttData.OTMin = null; _TempAttData.EarlyIn = null; _TempAttData.EarlyOut = null; _TempAttData.LateIn = null; _TempAttData.LateOut = null; _TempAttData.WorkMin = null; _TempAttData.GZOTMin = null; break; } if (_TempAttData.TimeIn != null && _TempAttData.TimeOut != null) { //If TimeIn = TimeOut then calculate according to DutyCode if (_TempAttData.TimeIn == _TempAttData.TimeOut) { CalculateInEqualToOut(_TempAttData); } else { if (_TempAttData.DutyTime == new TimeSpan(0, 0, 0)) { CalculateOpenShiftTimes(_TempAttData, _TempAttData.Emp.Shift); } else { //if (attendanceRecord.TimeIn.Value.Date.Day == attendanceRecord.TimeOut.Value.Date.Day) //{ CalculateShiftTimes(_TempAttData, _TempAttData.Emp.Shift); //} //else //{ // CalculateOpenShiftTimes(attendanceRecord, shift); //} } } //If TimeIn = TimeOut then calculate according to DutyCode } ctx.SaveChanges(); } ctx.Dispose(); } _myHelperClass.WriteToLogFile("ProcessManual Attendance Completed: "); }
public static void CalculateOpenShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin if (attendanceRecord != null) { if (attendanceRecord.TimeOut != null && attendanceRecord.TimeIn != null) { attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; // RoundOff Overtime // if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.CompanyID == 1) if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4)) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } } else { if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(ProcessSupportFunc.CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; // CalculateShiftEndTime = ShiftStart + DutyHours //TimeSpan shiftEnd = ProcessSupportFunc.CalculateShiftEndTime(shift, attendanceRecord.AttDate.Value.DayOfWeek); attendanceRecord.WorkMin = (short)(mins.TotalMinutes); //Calculate OverTIme, if ((mins.TotalMinutes > (attendanceRecord.ShifMin + shift.OverTimeMin)) && attendanceRecord.Emp.HasOT == true) { attendanceRecord.OTMin = (Int16)(Convert.ToInt16(mins.TotalMinutes) - attendanceRecord.ShifMin); attendanceRecord.WorkMin = (short)((mins.TotalMinutes) - attendanceRecord.OTMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } //Calculate Early Out if (mins.TotalMinutes < (attendanceRecord.ShifMin - shift.EarlyOut)) { Int16 EarlyoutMin = (Int16)(attendanceRecord.ShifMin - Convert.ToInt16(mins.TotalMinutes)); if (EarlyoutMin > shift.EarlyOut) { attendanceRecord.EarlyOut = EarlyoutMin; attendanceRecord.StatusEO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > attendanceRecord.ShifMin && (attendanceRecord.WorkMin <= (attendanceRecord.ShifMin + shift.OverTimeMin))) { attendanceRecord.WorkMin = attendanceRecord.ShifMin; } // RoundOff Overtime // if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.CompanyID == 1) if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4)) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } } } catch (Exception ex) { } }
public bool AddLeaveToLeaveAttData(LvApplication lvappl, LvType lvType) { try { DateTime datetime = new DateTime(); datetime = lvappl.FromDate; for (int i = 0; i < lvappl.NoOfDays; i++) { string _EmpDate = lvappl.EmpID + datetime.Date.ToString("yyMMdd"); using (var context = new TAS2013Entities()) { if (context.AttProcesses.Where(aa => aa.ProcessDate == datetime).Count() > 0) { AttData _EmpAttData = new AttData(); _EmpAttData = context.AttDatas.First(aa => aa.EmpDate == _EmpDate); _EmpAttData.LateIn = null; _EmpAttData.LateOut = null; if (lvappl.IsHalf != true) { _EmpAttData.PDays = 0; _EmpAttData.ABDays = 0; _EmpAttData.LeaveDays = 1; _EmpAttData.StatusLeave = true; _EmpAttData.StatusHL = false; } else { if (_EmpAttData.WorkMin > 10) { _EmpAttData.PDays = 0.5; _EmpAttData.ABDays = 0; _EmpAttData.LeaveDays = 0.5; } else { _EmpAttData.PDays = 0; _EmpAttData.ABDays = 0.5; _EmpAttData.LeaveDays = 0.5; } _EmpAttData.StatusLeave = true; _EmpAttData.StatusHL = false; } _EmpAttData.EarlyIn = null; _EmpAttData.EarlyOut = null; _EmpAttData.StatusAB = false; _EmpAttData.StatusEI = null; _EmpAttData.StatusEO = null; _EmpAttData.EarlyOut = null; _EmpAttData.StatusLI = null; _EmpAttData.StatusLI = null; _EmpAttData.StatusLO = null; _EmpAttData.StatusDO = null; _EmpAttData.StatusGZ = null; _EmpAttData.StatusGZOT = null; _EmpAttData.StatusMN = null; _EmpAttData.StatusOD = null; _EmpAttData.Remarks = lvType.FldName; if (lvappl.IsHalf == true) { _EmpAttData.StatusHL = true; _EmpAttData.StatusLeave = false; _EmpAttData.Remarks = lvType.HalfLvCode; } context.SaveChanges(); } } datetime = datetime.AddDays(1); } } catch (Exception ex) { return(false); } return(true); }
private void MarkAttendanceEditedData(AttData _atData) { ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName"); }
public ActionResult EditAttWizardOne(FormCollection form) { try { ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName"); ViewBag.ShiftList = new SelectList(db.Shifts, "ShiftID", "ShiftName"); ViewBag.CrewList = new SelectList(db.Crews, "CrewID", "CrewName"); ViewBag.CompanyID = new SelectList(db.Companies, "CompID", "CompName"); ViewBag.SectionList = new SelectList(db.Sections, "SectionID", "SectionName"); ViewData["datef"] = Convert.ToDateTime(Request.Form["DateFrom"].ToString()).ToString("yyyy-MM-dd"); //ViewData["datef"] = Request.Form["DateFrom"].ToString(); if (Request.Form["EmpNo"].ToString() != "" && Request.Form["DateFrom"].ToString() != "") { string _EmpNo = Request.Form["EmpNo"].ToString(); DateTime _AttDataFrom = Convert.ToDateTime(Request.Form["DateFrom"].ToString()); Session["EditAttendanceDate"] = Request.Form["DateFrom"].ToString(); var _CompId = Request.Form["CompanyID"]; int compID = Convert.ToInt32(_CompId); AttData _attData = new AttData(); List <Emp> _Emp = new List <Emp>(); int EmpID = 0; _Emp = db.Emps.Where(aa => aa.EmpNo == _EmpNo && aa.CompanyID == compID).ToList(); if (_Emp.Count > 0) { EmpID = _Emp.FirstOrDefault().EmpID; } _attData = db.AttDatas.FirstOrDefault(aa => aa.EmpID == EmpID && aa.AttDate == _AttDataFrom); if (_attData != null) { List <PollData> _Polls = new List <PollData>(); string _EmpDate = _attData.EmpID.ToString() + _AttDataFrom.Date.ToString("yyMMdd"); _Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); ViewBag.EmpID = new SelectList(db.Emps, "EmpID", "EmpNo", _attData.EmpID); Session["NEmpNo"] = _attData.EmpNo; ViewBag.SucessMessage = ""; if (_attData.WorkMin != null) { ViewBag.WorkMin = (TimeSpan.FromMinutes((double)_attData.WorkMin)); } if (_attData.LateOut != null) { ViewBag.LateOut = TimeSpan.FromMinutes((double)_attData.LateOut); } if (_attData.LateIn != null) { ViewBag.LateIn = TimeSpan.FromMinutes((double)_attData.LateIn); } if (_attData.EarlyOut != null) { ViewBag.EarlyOut = TimeSpan.FromMinutes((double)_attData.EarlyOut); } if (_attData.EarlyIn != null) { ViewBag.EarlyIn = TimeSpan.FromMinutes((double)_attData.EarlyIn); } if (_attData.OTMin != null) { ViewBag.OT = TimeSpan.FromMinutes((double)_attData.OTMin); } if (_attData.GZOTMin != null) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_attData.GZOTMin); } return(View(_attData)); } else { return(View("Index")); } } else { return(View("Index")); } } catch (Exception ex) { if (ex.Message.Contains("Sequence")) { ViewBag.Message = "No Entry found on this particular date"; } return(View("Index")); } }
private void CalculateShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LI]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EI]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[G-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[R-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[N-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Manual]", ""); TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); attendanceRecord.WorkMin = (short)(mins.TotalMinutes); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.PDays = 0; attendanceRecord.ABDays = 0; attendanceRecord.LeaveDays = 0; attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[G-OT]"; attendanceRecord.ABDays = 0; attendanceRecord.PDays = 0; attendanceRecord.LeaveDays = 0; } //if Rest day then place all WorkMin in OTMin else if (attendanceRecord.StatusDO == true) { if (attendanceRecord.Emp.HasOT != false) { attendanceRecord.PDays = 0; attendanceRecord.ABDays = 0; attendanceRecord.LeaveDays = 0; attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; attendanceRecord.ABDays = 0; attendanceRecord.PDays = 0; attendanceRecord.LeaveDays = 0; } } else { /////////// to-do -----calculate Margins for those shifts which has break mins if (attendanceRecord.StatusBreak == true) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.BreakMin); attendanceRecord.ShifMin = (short)(ProcessSupportFunc.CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)attendanceRecord.BreakMin); } else { if (attendanceRecord.StatusHL == true && attendanceRecord.StatusLeave != true) { attendanceRecord.ABDays = 0; attendanceRecord.PDays = 0.5; attendanceRecord.LeaveDays = 0.5; } else { attendanceRecord.ABDays = 0; attendanceRecord.PDays = 1; attendanceRecord.LeaveDays = 0; } attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; #region -- Margins-- //Calculate Late IN, Compare margin with Shift Late In if (attendanceRecord.TimeIn.Value.TimeOfDay > attendanceRecord.DutyTime) { TimeSpan lateMinsSpan = (TimeSpan)(attendanceRecord.TimeIn.Value.TimeOfDay - attendanceRecord.DutyTime); if (lateMinsSpan.TotalMinutes > shift.LateIn) { attendanceRecord.LateIn = (short)lateMinsSpan.TotalMinutes; attendanceRecord.StatusLI = true; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LI]"; } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LI]", ""); } } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LI]", ""); } //Calculate Early In, Compare margin with Shift Early In if (attendanceRecord.TimeIn.Value.TimeOfDay < attendanceRecord.DutyTime) { TimeSpan EarlyInMinsSpan = (TimeSpan)(attendanceRecord.DutyTime - attendanceRecord.TimeIn.Value.TimeOfDay); if (EarlyInMinsSpan.TotalMinutes > shift.EarlyIn) { attendanceRecord.EarlyIn = (short)EarlyInMinsSpan.TotalMinutes; attendanceRecord.StatusEI = true; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EI]"; } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EI]", ""); } } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EI]", ""); } // CalculateShiftEndTime = ShiftStart + DutyHours DateTime shiftEnd = ProcessSupportFunc.CalculateShiftEndTimeWithAttData(attendanceRecord.AttDate.Value, attendanceRecord.DutyTime.Value, (short)(attendanceRecord.ShifMin + attendanceRecord.BreakMin)); //Calculate Early Out, Compare margin with Shift Early Out if (attendanceRecord.TimeOut < shiftEnd) { TimeSpan EarlyOutMinsSpan = (TimeSpan)(shiftEnd - attendanceRecord.TimeOut); if (EarlyOutMinsSpan.TotalMinutes > shift.EarlyOut) { attendanceRecord.EarlyOut = (short)EarlyOutMinsSpan.TotalMinutes; attendanceRecord.StatusEO = true; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); } //Calculate Late Out, Compare margin with Shift Late Out if (attendanceRecord.TimeOut > shiftEnd) { TimeSpan LateOutMinsSpan = (TimeSpan)(attendanceRecord.TimeOut - shiftEnd); if (LateOutMinsSpan.TotalMinutes > shift.LateOut) { attendanceRecord.LateOut = (short)LateOutMinsSpan.TotalMinutes; // Late Out cannot have an early out, In case of poll at multiple times before and after shiftend attendanceRecord.EarlyOut = null; attendanceRecord.StatusLO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LO]"; } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); } } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); } #endregion if ((attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) && attendanceRecord.Emp.HasOT == true) { if (attendanceRecord.LateOut != null) { if ((attendanceRecord.WorkMin - attendanceRecord.ShifMin) > shift.OverTimeMin) { attendanceRecord.OTMin = (short)(attendanceRecord.WorkMin - attendanceRecord.ShifMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } } } //Subtract EarlyIn and LateOut from Work Minutes if (shift.SubtractEIFromWork == true) { if (attendanceRecord.EarlyIn != null && attendanceRecord.EarlyIn > shift.EarlyIn) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.EarlyIn); } } if (shift.SubtractOTFromWork == true) { if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } } if (shift.AddEIInOT == true && attendanceRecord.Emp.HasOT == true) { if (attendanceRecord.EarlyIn != null) { if (attendanceRecord.OTMin != null) { attendanceRecord.OTMin = (short)(attendanceRecord.OTMin + attendanceRecord.EarlyIn); } else { attendanceRecord.OTMin = (short)attendanceRecord.EarlyIn; } } } if (shift.RoundOffWorkMin == true) { if (attendanceRecord.LateOut != null || attendanceRecord.EarlyIn != null) { if (attendanceRecord.WorkMin > attendanceRecord.ShifMin && (attendanceRecord.WorkMin <= (attendanceRecord.ShifMin + shift.OverTimeMin))) { attendanceRecord.WorkMin = attendanceRecord.ShifMin; } } } if (attendanceRecord.StatusHL == true) { attendanceRecord.PDays = 0.5; attendanceRecord.ABDays = 0; attendanceRecord.LeaveDays = 0.5; } else { attendanceRecord.PDays = 1; attendanceRecord.ABDays = 0; attendanceRecord.LeaveDays = 0; } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } catch (Exception ex) { } }
public ActionResult EditAttWizardOne(FormCollection form) { try { User LoggedInUser = Session["LoggedUser"] as User; if (Request.Form["EmpNo"].ToString() != "" && Request.Form["DateFrom"].ToString() != "") { string _EmpNo = Request.Form["EmpNo"].ToString(); DateTime _AttDataFrom = Convert.ToDateTime(Request.Form["DateFrom"].ToString()); Session["EditAttendanceDate"] = Request.Form["DateFrom"].ToString(); AttData _attData = new AttData(); List <EmpView> emps = new List <EmpView>(); int EmpID = 0; emps = db.EmpViews.Where(aa => aa.EmpNo == _EmpNo && aa.Status == true).ToList(); emps = AssistantQuery.GetFilteredEmps(emps, db.UserSections.Where(aa => aa.UserID == LoggedInUser.UserID).ToList()); if (emps.Count > 0) { EmpID = emps.FirstOrDefault().EmpID; if (db.AttDatas.Where(aa => aa.EmpID == EmpID && aa.AttDate == _AttDataFrom).Count() > 0) { _attData = db.AttDatas.FirstOrDefault(aa => aa.EmpID == EmpID && aa.AttDate == _AttDataFrom); List <PollData> _Polls = new List <PollData>(); string _EmpDate = _attData.EmpID.ToString() + _AttDataFrom.Date.ToString("yyMMdd"); _Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); ViewBag.EmpID = new SelectList(db.Emps.OrderBy(s => s.EmpName), "EmpID", "EmpNo", _attData.EmpID); Session["NEmpNo"] = _attData.EmpID; ViewBag.SucessMessage = ""; if (_attData.WorkMin != null) { ViewBag.WorkMin = (TimeSpan.FromMinutes((double)_attData.WorkMin)); } if (_attData.LateOut != null) { ViewBag.LateOut = TimeSpan.FromMinutes((double)_attData.LateOut); } if (_attData.LateIn != null) { ViewBag.LateIn = TimeSpan.FromMinutes((double)_attData.LateIn); } if (_attData.EarlyOut != null) { ViewBag.EarlyOut = TimeSpan.FromMinutes((double)_attData.EarlyOut); } if (_attData.EarlyIn != null) { ViewBag.EarlyIn = TimeSpan.FromMinutes((double)_attData.EarlyIn); } if (_attData.OTMin != null) { ViewBag.OT = TimeSpan.FromMinutes((double)_attData.OTMin); } if (_attData.GZOTMin != null) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_attData.GZOTMin); } return(View(_attData)); } else { ViewBag.Message = "Attendance Not Found"; return(View("Index")); } } else { ViewBag.Message = "No employee found"; } } else { ViewBag.Message = "Please fill all field"; } return(View("Index")); } catch (Exception ex) { if (ex.Message.Contains("Sequence")) { ViewBag.Message = "No Entry found on this particular date"; } return(View("Index")); } }
private void CalculateOpenShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin if (attendanceRecord != null) { if (attendanceRecord.TimeOut != null && attendanceRecord.TimeIn != null) { attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; } else { if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { // CalculateShiftEndTime = ShiftStart + DutyHours TimeSpan shiftEnd = CalculateShiftEndTime(shift, (short)attendanceRecord.ShifMin); attendanceRecord.WorkMin = (short)(mins.TotalMinutes); //Calculate OverTIme, if (mins.TotalMinutes > (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin)) { attendanceRecord.OTMin = (Int16)(Convert.ToInt16(mins.TotalMinutes) - CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek)); attendanceRecord.WorkMin = (short)((mins.TotalMinutes) - attendanceRecord.OTMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } //Calculate Early Out if (mins.TotalMinutes < (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - shift.EarlyOut)) { Int16 EarlyoutMin = (Int16)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - Convert.ToInt16(mins.TotalMinutes)); if (EarlyoutMin > shift.EarlyOut) { attendanceRecord.EarlyOut = EarlyoutMin; attendanceRecord.StatusEO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } } // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) && (attendanceRecord.WorkMin <= (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin))) { attendanceRecord.WorkMin = CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek); } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday) { if (attendanceRecord.DutyCode == "D") { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; attendanceRecord.Remarks.Replace("[LI]", ""); attendanceRecord.Remarks.Replace("[EI]", ""); attendanceRecord.Remarks.Replace("[EO]", ""); attendanceRecord.Remarks.Replace("[LO]", ""); } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } } } } catch (Exception ex) { } }
public ActionResult EditorOTNew([Bind(Include = "EmpDate,AttDate,EmpNo,EmpID,Tin0,Tout0,Tin1,Tout1,Tin2,Tout2,Tin3,Tout3")] AttDataOT _attDataOT, FormCollection from) { User LoggedInUser = Session["LoggedUser"] as User; try { AttDataOT attot = new AttDataOT(); string empdate = Request.Form["EmpDate"].ToString(); int empID = Convert.ToInt32(Request.Form["EmpID"].ToString()); DateTime _AttDataFrom = Convert.ToDateTime(Request.Form["AttDate"].ToString()); string Tin1 = Request.Form["Tin1"].ToString(); string Tout1 = Request.Form["Tout1"].ToString(); string Tin2 = Request.Form["Tin2"].ToString(); string Tout2 = Request.Form["Tout2"].ToString(); string Tin3 = Request.Form["Tin3"].ToString(); string Tout3 = Request.Form["Tout3"].ToString(); string Remarks = Request.Form["Remarks"].ToString(); TimeSpan ts = new TimeSpan(); bool change = false; if (db.AttDataOTs.Where(aa => aa.EmpDate == empdate).Count() > 0) { attot = db.AttDataOTs.First(aa => aa.EmpDate == empdate); } if (Tin1 != "0000" && Tout1 != "0000") { string Tin1H = Tin1.Substring(0, 2); string Tin1M = Tin1.Substring(2, 2); string Tout1H = Tout1.Substring(0, 2); string Tout1M = Tout1.Substring(2, 2); TimeSpan _TimeIn1 = new TimeSpan(Convert.ToInt16(Tin1H), Convert.ToInt16(Tin1M), 0); TimeSpan _TimeOut1 = new TimeSpan(Convert.ToInt16(Tout1H), Convert.ToInt16(Tout1M), 0); ts = ts + _TimeOut1 - _TimeIn1; if (_TimeOut1 < _TimeIn1) { attot.ETout1 = _AttDataFrom.AddDays(1) + _TimeOut1; attot.ETin1 = _AttDataFrom + _TimeIn1; } else { attot.ETout1 = _AttDataFrom + _TimeOut1; attot.ETin1 = _AttDataFrom + _TimeIn1; } change = true; } if (Tin2 != "0000" && Tout2 != "0000") { string Tin2H = Tin2.Substring(0, 2); string Tin2M = Tin2.Substring(2, 2); string Tout2H = Tout2.Substring(0, 2); string Tout2M = Tout2.Substring(2, 2); TimeSpan _TimeIn2 = new TimeSpan(Convert.ToInt16(Tin2H), Convert.ToInt16(Tin2M), 0); TimeSpan _TimeOut2 = new TimeSpan(Convert.ToInt16(Tout2H), Convert.ToInt16(Tout2M), 0); ts = ts + _TimeOut2 - _TimeIn2; change = true; if (_TimeOut2 < _TimeIn2) { attot.ETout2 = _AttDataFrom.AddDays(1) + _TimeOut2; attot.ETin2 = _AttDataFrom + _TimeIn2; } else { attot.ETout2 = _AttDataFrom + _TimeOut2; attot.ETin2 = _AttDataFrom + _TimeIn2; } } if (Tin3 != "0000" && Tout3 != "0000") { string Tin3H = Tin3.Substring(0, 2); string Tin3M = Tin3.Substring(2, 2); string Tout3H = Tout3.Substring(0, 2); string Tout3M = Tout3.Substring(2, 2); TimeSpan _TimeIn3 = new TimeSpan(Convert.ToInt16(Tin3H), Convert.ToInt16(Tin3M), 0); TimeSpan _TimeOut3 = new TimeSpan(Convert.ToInt16(Tout3H), Convert.ToInt16(Tout3M), 0); ts = ts + _TimeOut3 - _TimeIn3; change = true; if (_TimeOut3 < _TimeIn3) { attot.ETout3 = _AttDataFrom.AddDays(1) + _TimeOut3; attot.ETin3 = _AttDataFrom + _TimeIn3; } else { attot.ETout3 = _AttDataFrom + _TimeOut3; attot.ETin3 = _AttDataFrom + _TimeIn3; } } if (change == true) { attot.AttDate = _AttDataFrom; attot.EmpDate = empdate; attot.EmpID = empID; attot.Mins = (Int16)ts.TotalMinutes; if (db.AttDataOTs.Where(aa => aa.EmpDate == empdate).Count() == 0) { db.AttDataOTs.Add(attot); } attot.Remarks = Remarks; db.SaveChanges(); AttData attData = db.AttDatas.First(aa => aa.EmpDate == empdate); if (attData.DutyCode == "G") { attData.GZOTMin = attot.Mins; } else { attData.OTMin = attot.Mins; } db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { //ViewBag.SucessMessage = "An error occured while saving Entry"; //_attData = db.AttDatas.First(aa => aa.EmpDate == _EmpDate); //List<PollData> _Polls = new List<PollData>(); //_Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); //ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); //ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); //return View(_attData); } return(View()); }
public void ManualProcessAttendance(DateTime date, List <Emp> emps) { BootstrapAttendance(date, emps); DateTime dateEnd = date.AddDays(1); List <AttData> attData = context.AttDatas.Where(aa => aa.AttDate >= date && aa.AttDate <= dateEnd).ToList(); List <PollData> unprocessedPolls = context.PollDatas.Where(p => (p.EntDate >= date && p.EntDate <= dateEnd)).OrderBy(e => e.EntTime).ToList(); foreach (var emp in emps) { List <PollData> polls = new List <PollData>(); polls = unprocessedPolls.Where(p => p.EmpID == emp.EmpID).OrderBy(e => e.EntTime).ToList(); foreach (PollData up in polls) { try { //Check AttData with EmpDate if (attData.Where(attd => attd.EmpDate == up.EmpDate).Count() > 0) { AttData attendanceRecord = attData.First(attd => attd.EmpDate == up.EmpDate); employee = attendanceRecord.Emp; Shift shift = employee.Shift; //Set Time In and Time Out in AttData if (attendanceRecord.Emp.Shift.OpenShift == true) { //Set Time In and Time Out for open shift PlaceTimeInOuts.CalculateTimeINOUTOpenShift(attendanceRecord, up); context.SaveChanges(); } else { TimeSpan checkTimeEnd = new TimeSpan(); DateTime TimeInCheck = new DateTime(); if (attendanceRecord.TimeIn == null) { TimeInCheck = attendanceRecord.AttDate.Value.Add(attendanceRecord.DutyTime.Value); } else { TimeInCheck = attendanceRecord.TimeIn.Value; } if (attendanceRecord.ShifMin == 0) { checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, 480, 0)); } else { checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, (int)attendanceRecord.ShifMin, 0)); } if (checkTimeEnd.Days > 0) { //if Time out occur at next day if (up.RdrDuty == 5) { DateTime dt = new DateTime(); dt = up.EntDate.Date.AddDays(-1); var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID); if (_attData != null) { if (_attData.TimeIn != null) { TimeSpan t1 = new TimeSpan(11, 00, 00); if (up.EntTime.TimeOfDay < t1) { if ((up.EntTime - _attData.TimeIn.Value).Hours < 18) { attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd"); } } } else { attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd"); } } } } //Set Time In and Time Out //Set Time In and Time Out if (up.RdrDuty == 5) { if (attendanceRecord.TimeIn != null) { TimeSpan dt = (TimeSpan)(up.EntTime.TimeOfDay - attendanceRecord.TimeIn.Value.TimeOfDay); if (dt.Minutes < 0) { DateTime dt1 = new DateTime(); dt1 = up.EntDate.Date.AddDays(-1); var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt1 && aa.EmpID == up.EmpID); attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt1.Date.ToString("yyMMdd"); PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } if (employee.Shift.OpenShift == true) { if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd) { DateTime dt = up.EntDate.Date.AddDays(-1); using (var ctxx = new TAS2013Entities()) { CalculateWorkMins.CalculateOpenShiftTimes(ctxx.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift); ctxx.SaveChanges(); ctxx.Dispose(); } } } //If TimeIn and TimeOut are not null, then calculate other Atributes if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null) { if (context.Rosters.Where(r => r.EmpDate == up.EmpDate).Count() > 0) { CalculateWorkMins.CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift); context.SaveChanges(); } else { if (shift.OpenShift == true) { if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd) { DateTime dt = up.EntDate.Date.AddDays(-1); using (var ctx2 = new TAS2013Entities()) { CalculateWorkMins.CalculateOpenShiftTimes(ctx2.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift); ctx2.SaveChanges(); ctx2.Dispose(); } CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift); context.SaveChanges(); } else { //Calculate open shifft time of the same date CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift); context.SaveChanges(); } } else { CalculateWorkMins.CalculateShiftTimes(attendanceRecord, shift); context.SaveChanges(); } } } up.Process = true; } } catch (Exception ex) { string _error = ""; if (ex.InnerException.Message != null) { _error = ex.InnerException.Message; } else { _error = ex.Message; } _myHelperClass.WriteToLogFile("Attendance Processing Error Level 1 " + _error); } context.SaveChanges(); } } _myHelperClass.WriteToLogFile("Attendance Processing Completed"); context.Dispose(); }
public void BootstrapAttendance(DateTime dateTime, List <Emp> emps) { using (var ctx = new TAS2013Entities()) { List <Roster> _Roster = new List <Roster>(); _Roster = context.Rosters.Where(aa => aa.RosterDate == dateTime).ToList(); List <RosterDetail> _NewRoster = new List <RosterDetail>(); _NewRoster = context.RosterDetails.Where(aa => aa.RosterDate == dateTime).ToList(); List <LvData> _LvData = new List <LvData>(); _LvData = context.LvDatas.Where(aa => aa.AttDate == dateTime).ToList(); List <LvShort> _lvShort = new List <LvShort>(); _lvShort = context.LvShorts.Where(aa => aa.DutyDate == dateTime).ToList(); //List<AttData> _AttData = context.AttDatas.Where(aa => aa.AttDate == dateTime).ToList(); List <AttData> _attData = new List <AttData>(); _attData = ctx.AttDatas.Where(aa => aa.AttDate == dateTime).ToList(); foreach (var emp in emps) { string empDate = emp.EmpID + dateTime.ToString("yyMMdd"); if (_attData.Where(aa => aa.EmpDate == empDate).Count() > 0) { try { ///////////////////////////////////////////////////// // Mark Everyone Absent while creating Attendance // ///////////////////////////////////////////////////// //Set DUTYCODE = D, StatusAB = true, and Remarks = [Absent] AttData att = _attData.First(aa => aa.EmpDate == empDate); //Reset Flags att.TimeIn = null; att.TimeOut = null; att.Tin0 = null; att.Tout0 = null; att.Tin1 = null; att.Tout1 = null; att.Tin2 = null; att.Tout2 = null; att.Tin3 = null; att.Tout3 = null; att.Tin4 = null; att.Tout4 = null; att.Tin5 = null; att.Tout5 = null; att.Tin6 = null; att.Tout6 = null; att.Tin7 = null; att.Tout7 = null; att.Tin8 = null; att.Tout8 = null; att.StatusP = null; att.StatusDO = null; att.StatusEO = null; att.StatusGZ = null; att.StatusGZOT = null; att.StatusHD = null; att.StatusHL = null; att.StatusIN = null; att.StatusLeave = null; att.StatusLI = null; att.StatusLO = null; att.StatusMN = null; att.StatusOD = null; att.StatusOT = null; att.StatusSL = null; att.WorkMin = null; att.LateIn = null; att.LateOut = null; att.OTMin = null; att.EarlyIn = null; att.EarlyOut = null; att.Remarks = null; att.ShifMin = null; att.SLMin = null; att.AttDate = dateTime.Date; att.DutyCode = "D"; att.StatusAB = true; att.Remarks = "[Absent]"; if (emp.Shift != null) { att.DutyTime = emp.Shift.StartTime; } else { att.DutyTime = new TimeSpan(07, 45, 00); } att.EmpID = emp.EmpID; att.EmpNo = emp.EmpNo; att.EmpDate = emp.EmpID + dateTime.ToString("yyMMdd"); att.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(emp.Shift, dateTime.DayOfWeek); ////////////////////////// // Check for Rest Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusDO = true, and Remarks=[DO] //Check for 1st Day Off of Shift if (emp.Shift.DaysName.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } //Check for 2nd Day Off of shift if (emp.Shift.DaysName1.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } ////////////////////////// // Check for Roster // //////////////////////// //If Roster DutyCode is Rest then change the StatusAB and StatusDO foreach (var roster in _Roster.Where(aa => aa.EmpDate == att.EmpDate)) { att.DutyCode = roster.DutyCode.Trim(); if (att.DutyCode == "R") { att.StatusAB = false; att.StatusDO = true; att.DutyCode = "R"; att.Remarks = "[DO]"; } att.ShifMin = roster.WorkMin; att.DutyTime = roster.DutyTime; } ////New Roster string empCdate = "Emp" + emp.EmpID.ToString() + dateTime.ToString("yyMMdd"); string sectionCdate = "Section" + emp.SecID.ToString() + dateTime.ToString("yyMMdd"); string crewCdate = "Crew" + emp.CrewID.ToString() + dateTime.ToString("yyMMdd"); string shiftCdate = "Shift" + emp.ShiftID.ToString() + dateTime.ToString("yyMMdd"); if (_NewRoster.Where(aa => aa.CriteriaValueDate == empCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == empCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == sectionCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == sectionCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == crewCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == crewCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == shiftCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == shiftCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } ////////////////////////// // Check for GZ Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] if (emp.Shift.GZDays == true) { if (context.Holidays.Where(hol => hol.HolDate == dateTime).Count() > 0) { att.DutyCode = "G"; att.StatusAB = false; att.StatusGZ = true; att.Remarks = "[GZ]"; att.ShifMin = 0; } } //////////////////////////// //TODO Check for Job Card// ////////////////////////// //////////////////////////// // Check for Short Leave// ////////////////////////// foreach (var sLeave in _lvShort.Where(aa => aa.EmpDate == att.EmpDate)) { if (_lvShort.Where(lv => lv.EmpDate == att.EmpDate).Count() > 0) { att.StatusSL = true; att.StatusAB = null; att.DutyCode = "L"; att.Remarks = "[Short Leave]"; } } ////////////////////////// // Check for Leave // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] foreach (var Leave in _LvData) { var _Leave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave != true); if (_Leave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusDO = false; if (Leave.LvCode == "A") { att.Remarks = "[CL]"; } else if (Leave.LvCode == "B") { att.Remarks = "[AL]"; } else if (Leave.LvCode == "C") { att.Remarks = "[SL]"; } else { att.Remarks = "[" + _Leave.FirstOrDefault().LvType.LvDesc + "]"; } } else { att.StatusLeave = false; } } ////////////////////////// //Check for Half Leave/// ///////////////////////// var _HalfLeave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave == true); if (_HalfLeave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusHL = true; att.StatusDO = false; if (_HalfLeave.FirstOrDefault().LvCode == "A") { att.Remarks = "[H-CL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "B") { att.Remarks = "[S-AL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "C") { att.Remarks = "[H-SL]"; } else { att.Remarks = "[Half Leave]"; } } else { att.StatusLeave = false; } ctx.SaveChanges(); } catch (Exception ex) { _myHelperClass.WriteToLogFile("-------Error In Creating Attendance of Employee: " + emp.EmpNo + " ------" + ex.InnerException.Message); } } } ctx.Dispose(); } }
public static void CalculateTimeINOUT(AttData attendanceRecord, PollData up) { try { switch (up.RdrDuty) { case 1: //IN if (attendanceRecord.Tin0 == null) { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; } else if (attendanceRecord.Tin1 == null) { attendanceRecord.Tin1 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin2 == null) { attendanceRecord.Tin2 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin3 == null) { attendanceRecord.Tin3 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin4 == null) { attendanceRecord.Tin4 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin5 == null) { attendanceRecord.Tin5 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin6 == null) { attendanceRecord.Tin6 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin7 == null) { attendanceRecord.Tin7 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin8 == null) { attendanceRecord.Tin8 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin9 == null) { attendanceRecord.Tin9 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin10 == null) { attendanceRecord.Tin10 = up.EntTime; SortingInTime(attendanceRecord); } else { attendanceRecord.Tin11 = up.EntTime; SortingInTime(attendanceRecord); } break; case 5: //OUT if (attendanceRecord.Tout0 == null) { attendanceRecord.Tout0 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout1 == null) { attendanceRecord.Tout1 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout2 == null) { attendanceRecord.Tout2 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout3 == null) { attendanceRecord.Tout3 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout4 == null) { attendanceRecord.Tout4 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout5 == null) { attendanceRecord.Tout5 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout6 == null) { attendanceRecord.Tout6 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout7 == null) { attendanceRecord.Tout7 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout8 == null) { attendanceRecord.Tout8 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout9 == null) { attendanceRecord.Tout9 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else if (attendanceRecord.Tout10 == null) { attendanceRecord.Tout10 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } else { attendanceRecord.Tout11 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; SortingOutTime(attendanceRecord); } break; case 8: //DUTY if (attendanceRecord.Tin0 != null) { if (attendanceRecord.Tout0 == null) { attendanceRecord.Tout0 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin1 == null) { attendanceRecord.Tin1 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout1 == null) { attendanceRecord.Tout1 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin2 == null) { attendanceRecord.Tin2 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout2 == null) { attendanceRecord.Tout2 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin3 == null) { attendanceRecord.Tin3 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout3 == null) { attendanceRecord.Tout3 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin4 == null) { attendanceRecord.Tin4 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout4 == null) { attendanceRecord.Tout4 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin5 == null) { attendanceRecord.Tin5 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout5 == null) { attendanceRecord.Tout5 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin6 == null) { attendanceRecord.Tin6 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout6 == null) { attendanceRecord.Tout6 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } // else if (attendanceRecord.Tin7 == null) { attendanceRecord.Tin7 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout7 == null) { attendanceRecord.Tout7 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin8 == null) { attendanceRecord.Tin8 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout8 == null) { attendanceRecord.Tout8 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin9 == null) { attendanceRecord.Tin9 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout9 == null) { attendanceRecord.Tout9 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin10 == null) { attendanceRecord.Tin10 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout10 == null) { attendanceRecord.Tout10 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin11 == null) { attendanceRecord.Tin11 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout11 == null) { attendanceRecord.Tout11 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin12 == null) { attendanceRecord.Tin12 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tout12 == null) { attendanceRecord.Tout12 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else if (attendanceRecord.Tin13 == null) { attendanceRecord.Tin13 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } else { attendanceRecord.Tout13 = up.EntTime; attendanceRecord.TimeOut = up.EntTime; } } else { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; } break; } } catch (Exception ex) { } }
public static void CalculateTimeINOUTOpenShift(AttData attendanceRecord, PollData up) { try { TAS2013Entities context = new TAS2013Entities(); switch (up.RdrDuty) { case 1: //IN if (attendanceRecord.Tin0 == null) { if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd) { DateTime dt = new DateTime(); dt = up.EntDate.Date.AddDays(-1); var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID); if (_attData != null) { if (_attData.TimeIn != null) { if (_attData.TimeIn.Value.TimeOfDay > OpenShiftThresholdStart) { //attdata - 1 . multipleTimeIn = up.EntTime } else { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; attendanceRecord.StatusIN = true; } } else { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; attendanceRecord.StatusIN = true; } } else { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; attendanceRecord.StatusIN = true; } } else { attendanceRecord.Tin0 = up.EntTime; attendanceRecord.TimeIn = up.EntTime; attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks = null; attendanceRecord.StatusIN = true; } } else if (attendanceRecord.Tin1 == null) { attendanceRecord.Tin1 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin2 == null) { attendanceRecord.Tin2 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin3 == null) { attendanceRecord.Tin3 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin4 == null) { attendanceRecord.Tin4 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin5 == null) { attendanceRecord.Tin5 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin6 == null) { attendanceRecord.Tin6 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin7 == null) { attendanceRecord.Tin7 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin8 == null) { attendanceRecord.Tin8 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin9 == null) { attendanceRecord.Tin9 = up.EntTime; SortingInTime(attendanceRecord); } else if (attendanceRecord.Tin10 == null) { attendanceRecord.Tin10 = up.EntTime; SortingInTime(attendanceRecord); } else { attendanceRecord.Tin11 = up.EntTime; SortingInTime(attendanceRecord); } break; case 5: //OUT if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd) { DateTime dt = up.EntDate.AddDays(-1); if (context.AttDatas.Where(aa => aa.AttDate == dt && aa.EmpID == up.EmpID).Count() > 0) { AttData AttDataOfPreviousDay = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID); if (AttDataOfPreviousDay.TimeIn != null) { if (AttDataOfPreviousDay.TimeIn.Value.TimeOfDay > OpenShiftThresholdStart) { //AttDate -1, Possible TimeOut = up.entryTime MarkOUTForOpenShift(up.EntTime, AttDataOfPreviousDay); } else { // Mark as out of that day MarkOUTForOpenShift(up.EntTime, attendanceRecord); } } else { MarkOUTForOpenShift(up.EntTime, attendanceRecord); } } else { // Mark as out of that day MarkOUTForOpenShift(up.EntTime, attendanceRecord); } } else { //Mark as out of that day MarkOUTForOpenShift(up.EntTime, attendanceRecord); } //------------------------------------------------------- context.SaveChanges(); break; } } catch (Exception ex) { } }
public static void MarkOUTForOpenShift(DateTime _pollTime, AttData _attendanceRecord) { if (_attendanceRecord.Tout0 == null) { _attendanceRecord.Tout0 = _pollTime; _attendanceRecord.TimeOut = _pollTime; SortingOutTime(_attendanceRecord); } else if (_attendanceRecord.Tout1 == null) { _attendanceRecord.Tout1 = _pollTime; _attendanceRecord.TimeOut = _pollTime; SortingOutTime(_attendanceRecord); } else if (_attendanceRecord.Tout2 == null) { _attendanceRecord.Tout2 = _pollTime; _attendanceRecord.TimeOut = _pollTime; SortingOutTime(_attendanceRecord); } else if (_attendanceRecord.Tout3 == null) { _attendanceRecord.Tout3 = _pollTime; _attendanceRecord.TimeOut = _pollTime; SortingOutTime(_attendanceRecord); } else { _attendanceRecord.Tout4 = _pollTime; _attendanceRecord.TimeOut = _pollTime; SortingOutTime(_attendanceRecord); } //else if (_attendanceRecord.Tout5 == null) //{ // _attendanceRecord.Tout5 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else if (_attendanceRecord.Tout6 == null) //{ // _attendanceRecord.Tout6 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else if (_attendanceRecord.Tout7 == null) //{ // _attendanceRecord.Tout7 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else if (_attendanceRecord.Tout8 == null) //{ // _attendanceRecord.Tout8 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else if (_attendanceRecord.Tout9 == null) //{ // _attendanceRecord.Tout9 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else if (_attendanceRecord.Tout10 == null) //{ // _attendanceRecord.Tout10 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} //else //{ // _attendanceRecord.Tout11 = up.EntTime; // _attendanceRecord.TimeOut = up.EntTime; // SortingOutTime(_attendanceRecord); //} }
private void CalculateShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[G-OT]"; } //if Rest day then place all WorkMin in OTMin else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; } else { /////////// to-do -----calculate Margins for those shifts which has break mins if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { //Calculate Late IN, Compare margin with Shift Late In if (attendanceRecord.TimeIn.Value.TimeOfDay > attendanceRecord.DutyTime) { TimeSpan lateMinsSpan = (TimeSpan)(attendanceRecord.TimeIn.Value.TimeOfDay - attendanceRecord.DutyTime); if (lateMinsSpan.TotalMinutes > shift.LateIn) { attendanceRecord.LateIn = (short)lateMinsSpan.TotalMinutes; attendanceRecord.StatusLI = true; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LI]"; } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks.Replace("[LI]", ""); } } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks.Replace("[LI]", ""); } //Calculate Early In, Compare margin with Shift Early In if (attendanceRecord.TimeIn.Value.TimeOfDay < attendanceRecord.DutyTime) { TimeSpan EarlyInMinsSpan = (TimeSpan)(attendanceRecord.DutyTime - attendanceRecord.TimeIn.Value.TimeOfDay); if (EarlyInMinsSpan.TotalMinutes > shift.EarlyIn) { attendanceRecord.EarlyIn = (short)EarlyInMinsSpan.TotalMinutes; attendanceRecord.StatusEI = true; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EI]"; } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } // CalculateShiftEndTime = ShiftStart + DutyHours DateTime shiftEnd = CalculateShiftEndTime(shift, attendanceRecord.AttDate.Value, attendanceRecord.DutyTime.Value); //Calculate Early Out, Compare margin with Shift Early Out if (attendanceRecord.TimeOut < shiftEnd) { TimeSpan EarlyOutMinsSpan = (TimeSpan)(shiftEnd - attendanceRecord.TimeOut); if (EarlyOutMinsSpan.TotalMinutes > shift.EarlyOut) { attendanceRecord.EarlyOut = (short)EarlyOutMinsSpan.TotalMinutes; attendanceRecord.StatusEO = true; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } //Calculate Late Out, Compare margin with Shift Late Out if (attendanceRecord.TimeOut > shiftEnd) { TimeSpan LateOutMinsSpan = (TimeSpan)(attendanceRecord.TimeOut - shiftEnd); if (LateOutMinsSpan.TotalMinutes > shift.LateOut) { attendanceRecord.LateOut = (short)LateOutMinsSpan.TotalMinutes; // Late Out cannot have an early out, In case of poll at multiple times before and after shiftend attendanceRecord.EarlyOut = null; attendanceRecord.StatusLO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LO]"; } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } //Subtract EarlyIn and LateOut from Work Minutes //////-------to-do--------- Automate earlyin,lateout from shift setup attendanceRecord.WorkMin = (short)(mins.TotalMinutes); if (attendanceRecord.EarlyIn != null && attendanceRecord.EarlyIn > shift.EarlyIn) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.EarlyIn); } if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } if (attendanceRecord.LateOut != null || attendanceRecord.EarlyIn != null) { // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) && (attendanceRecord.WorkMin <= (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin))) { attendanceRecord.WorkMin = CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek); } } //Calculate OverTime = OT, Compare margin with Shift OverTime //----to-do----- Handle from shift //if (attendanceRecord.EarlyIn > shift.EarlyIn || attendanceRecord.LateOut > shift.LateOut) //{ // if (attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) // { // short _EarlyIn; // short _LateOut; // if (attendanceRecord.EarlyIn == null) // _EarlyIn = 0; // else // _EarlyIn = 0; // if (attendanceRecord.LateOut == null) // _LateOut = 0; // else // _LateOut = (short)attendanceRecord.LateOut; // attendanceRecord.OTMin = (short)(_EarlyIn + _LateOut); // attendanceRecord.StatusOT = true; // attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; // } //} if (attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) { if (attendanceRecord.LateOut != null) { attendanceRecord.OTMin = attendanceRecord.LateOut; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } else { attendanceRecord.OTMin = null; attendanceRecord.StatusOT = null; attendanceRecord.Remarks.Replace("[OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); } } else { attendanceRecord.OTMin = null; attendanceRecord.StatusOT = null; attendanceRecord.Remarks.Replace("[OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); } } } } catch (Exception ex) { } }
private void CalculateOpenShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin if (attendanceRecord != null) { if (attendanceRecord.TimeOut != null && attendanceRecord.TimeIn != null) { attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; // RoundOff Overtime if ((employee.EmpType.CatID == 2 || employee.EmpType.CatID == 4) && employee.CompanyID == 1) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } } else { if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; // CalculateShiftEndTime = ShiftStart + DutyHours TimeSpan shiftEnd = CalculateShiftEndTime(shift, attendanceRecord.AttDate.Value.DayOfWeek); attendanceRecord.WorkMin = (short)(mins.TotalMinutes); //Calculate OverTIme, if ((mins.TotalMinutes > (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin)) && employee.HasOT == true) { attendanceRecord.OTMin = (Int16)(Convert.ToInt16(mins.TotalMinutes) - CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek)); attendanceRecord.WorkMin = (short)((mins.TotalMinutes) - attendanceRecord.OTMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } //Calculate Early Out if (mins.TotalMinutes < (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - shift.EarlyOut)) { Int16 EarlyoutMin = (Int16)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - Convert.ToInt16(mins.TotalMinutes)); if (EarlyoutMin > shift.EarlyOut) { attendanceRecord.EarlyOut = EarlyoutMin; attendanceRecord.StatusEO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) && (attendanceRecord.WorkMin <= (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin))) { attendanceRecord.WorkMin = CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek); } // RoundOff Overtime if ((employee.EmpType.CatID == 2 || employee.EmpType.CatID == 4) && employee.CompanyID == 1) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } } } catch (Exception ex) { string _error = ""; if (ex.InnerException.Message != null) { _error = ex.InnerException.Message; } else { _error = ex.Message; } _myHelperClass.WriteToLogFile("Attendance Processing at Calculating Times; " + _error); } context.SaveChanges(); }
private void CalculateOpenShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin if (attendanceRecord != null) { if (attendanceRecord.TimeOut != null && attendanceRecord.TimeIn != null) { attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; } else { if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { // CalculateShiftEndTime = ShiftStart + DutyHours TimeSpan shiftEnd = CalculateShiftEndTime(shift, attendanceRecord.AttDate.Value.DayOfWeek); attendanceRecord.WorkMin = (short)(mins.TotalMinutes); //Calculate OverTIme, if (mins.TotalMinutes > (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin)) { attendanceRecord.OTMin = (Int16)(Convert.ToInt16(mins.TotalMinutes) - CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek)); attendanceRecord.WorkMin = (short)((mins.TotalMinutes) - attendanceRecord.OTMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } //Calculate Early Out if (mins.TotalMinutes < (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - shift.EarlyOut)) { Int16 EarlyoutMin = (Int16)(CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - Convert.ToInt16(mins.TotalMinutes)); if (EarlyoutMin > shift.EarlyOut) { attendanceRecord.EarlyOut = EarlyoutMin; attendanceRecord.StatusEO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) && (attendanceRecord.WorkMin <= (CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) + shift.OverTimeMin))) { attendanceRecord.WorkMin = CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek); } } } } } } catch (Exception ex) { string _error = ""; if (ex.InnerException.Message != null) { _error = ex.InnerException.Message; } else { _error = ex.Message; } _myHelperClass.WriteToLogFile("Attendance Processing at Calculating Times; " + _error); } }
private void CalculateRosterTimes(AttData attendanceRecord, Roster roster, Shift _shift) { try { TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); attendanceRecord.Remarks = ""; if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; // RoundOff Overtime if ((employee.EmpType.CatID == 2 || employee.EmpType.CatID == 4) && employee.CompanyID == 1) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } } else { attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; ////------to-do ----------handle shift break time //Calculate Late IN, Compare margin with Shift Late In if (attendanceRecord.TimeIn.Value.TimeOfDay > roster.DutyTime) { TimeSpan lateMinsSpan = (TimeSpan)(attendanceRecord.TimeIn.Value.TimeOfDay - attendanceRecord.DutyTime); if (lateMinsSpan.TotalMinutes > _shift.LateIn) { attendanceRecord.LateIn = (short)lateMinsSpan.TotalMinutes; attendanceRecord.StatusLI = true; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LI]"; } else { attendanceRecord.LateIn = null; attendanceRecord.StatusLI = null; attendanceRecord.Remarks.Replace("[LI]", ""); } } else { attendanceRecord.LateIn = null; attendanceRecord.StatusLI = null; attendanceRecord.Remarks.Replace("[LI]", ""); } //Calculate Early In, Compare margin with Shift Early In if (attendanceRecord.TimeIn.Value.TimeOfDay < attendanceRecord.DutyTime) { TimeSpan EarlyInMinsSpan = (TimeSpan)(attendanceRecord.DutyTime - attendanceRecord.TimeIn.Value.TimeOfDay); if (EarlyInMinsSpan.TotalMinutes > _shift.EarlyIn) { attendanceRecord.EarlyIn = (short)EarlyInMinsSpan.TotalMinutes; attendanceRecord.StatusEI = true; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EI]"; } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } // CalculateShiftEndTime = ShiftStart + DutyHours TimeSpan shiftEnd = (TimeSpan)attendanceRecord.DutyTime + (new TimeSpan(0, (int)roster.WorkMin, 0)); //Calculate Early Out, Compare margin with Shift Early Out if (attendanceRecord.TimeOut.Value.TimeOfDay < shiftEnd) { TimeSpan EarlyOutMinsSpan = (TimeSpan)(shiftEnd - attendanceRecord.TimeOut.Value.TimeOfDay); if (EarlyOutMinsSpan.TotalMinutes > _shift.EarlyOut) { attendanceRecord.EarlyOut = (short)EarlyOutMinsSpan.TotalMinutes; attendanceRecord.StatusEO = true; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } //Calculate Late Out, Compare margin with Shift Late Out if (attendanceRecord.TimeOut.Value.TimeOfDay > shiftEnd) { TimeSpan LateOutMinsSpan = (TimeSpan)(attendanceRecord.TimeOut.Value.TimeOfDay - shiftEnd); if (LateOutMinsSpan.TotalMinutes > _shift.LateOut) { attendanceRecord.LateOut = (short)LateOutMinsSpan.TotalMinutes; // Late Out cannot have an early out, In case of poll at multiple times before and after shiftend attendanceRecord.EarlyOut = null; attendanceRecord.StatusLO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LO]"; } else { attendanceRecord.LateOut = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } } else { attendanceRecord.LateOut = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } attendanceRecord.WorkMin = (short)(mins.TotalMinutes); if (attendanceRecord.EarlyIn != null && attendanceRecord.EarlyIn > _shift.EarlyIn) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.EarlyIn); } if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > _shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } if (attendanceRecord.EarlyIn == null && attendanceRecord.LateOut == null) { } //round off work minutes if (attendanceRecord.WorkMin > CalculateShiftMinutes(_shift, attendanceRecord.AttDate.Value.DayOfWeek) && (attendanceRecord.WorkMin <= (CalculateShiftMinutes(_shift, attendanceRecord.AttDate.Value.DayOfWeek) + _shift.OverTimeMin))) { attendanceRecord.WorkMin = CalculateShiftMinutes(_shift, attendanceRecord.AttDate.Value.DayOfWeek); } // RoundOff Overtime if ((employee.EmpType.CatID == 2 || employee.EmpType.CatID == 4) && employee.CompanyID == 1) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } ////Calculate OverTime, Compare margin with Shift OverTime //if (attendanceRecord.EarlyIn > _shift.EarlyIn || attendanceRecord.LateOut > _shift.LateOut) //{ // if (attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) // { // short _EarlyIn; // short _LateOut; // if (attendanceRecord.EarlyIn == null) // _EarlyIn = 0; // else // _EarlyIn = 0; // if (attendanceRecord.LateOut == null) // _LateOut = 0; // else // _LateOut = (short)attendanceRecord.LateOut; // attendanceRecord.OTMin = (short)(_EarlyIn + _LateOut); // attendanceRecord.StatusOT = true; // } //} if ((attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) && employee.HasOT == true) { if (attendanceRecord.LateOut != null) { attendanceRecord.OTMin = attendanceRecord.LateOut; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)_shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } catch (Exception ex) { string _error = ""; if (ex.InnerException.Message != null) { _error = ex.InnerException.Message; } else { _error = ex.Message; } _myHelperClass.WriteToLogFile("Attendance Processing Roster Times" + _error); } }
private void CalculateOpenShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin //Calculate WorkMin attendanceRecord.Remarks.Replace("[LI]", ""); attendanceRecord.Remarks.Replace("[EI]", ""); attendanceRecord.Remarks.Replace("[EO]", ""); attendanceRecord.Remarks.Replace("[LO]", ""); attendanceRecord.Remarks.Replace("[G-OT]", ""); attendanceRecord.Remarks.Replace("[R-OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); attendanceRecord.Remarks.Replace("[Manual]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks + "[Manual]"; if (attendanceRecord != null) { if (attendanceRecord.TimeOut != null && attendanceRecord.TimeIn != null) { attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); attendanceRecord.WorkMin = (short)mins.TotalMinutes; //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ-OT]"; } else if (attendanceRecord.StatusDO == true) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; } else { if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - shift.BreakMin); attendanceRecord.ShifMin = (short)(ProcessSupportFunc.CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)attendanceRecord.BreakMin); } else { attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; // CalculateShiftEndTime = ShiftStart + DutyHours //Calculate OverTIme, if ((mins.TotalMinutes > (attendanceRecord.ShifMin + shift.OverTimeMin)) && attendanceRecord.Emp.HasOT == true) { attendanceRecord.OTMin = (Int16)(Convert.ToInt16(mins.TotalMinutes) - attendanceRecord.ShifMin); attendanceRecord.WorkMin = (short)((mins.TotalMinutes) - attendanceRecord.OTMin); attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } //Calculate Early Out if (mins.TotalMinutes < (attendanceRecord.ShifMin - shift.EarlyOut)) { Int16 EarlyoutMin = (Int16)(attendanceRecord.ShifMin - Convert.ToInt16(mins.TotalMinutes)); if (EarlyoutMin > shift.EarlyOut) { attendanceRecord.EarlyOut = EarlyoutMin; attendanceRecord.StatusEO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); } if ((attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) && attendanceRecord.Emp.HasOT == true) { if (attendanceRecord.LateOut != null) { attendanceRecord.OTMin = attendanceRecord.LateOut; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } } if (shift.SubtractOTFromWork == true) { if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } } if (shift.RoundOffWorkMin == true) { if (attendanceRecord.LateOut != null || attendanceRecord.EarlyIn != null) { // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > attendanceRecord.ShifMin && (attendanceRecord.WorkMin <= (attendanceRecord.ShifMin + shift.OverTimeMin))) { attendanceRecord.WorkMin = attendanceRecord.ShifMin; } } } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } } } catch (Exception ex) { } }
public ActionResult UpdateEditor(VMLeaveEditor datas) { List <string> dropDownValues = new List <string>(); dropDownValues.Add("None"); dropDownValues.AddRange(db.JobCards.Select(aa => aa.WorkCardName).ToList()); dropDownValues.AddRange(db.LvTypes.Select(aa => aa.LvDesc).ToList()); dropDownValues.Add("HLV:Casual"); dropDownValues.Add("HLV:Annual"); datas.dropdowns = dropDownValues; if (datas.EmpNo != "" && datas.FromDate != null && datas.ToDate != null) { List <string> empDates = db.ViewAttDatas.Where(aa => aa.EmpNo == datas.EmpNo && aa.AttDate >= datas.FromDate && aa.AttDate <= datas.ToDate && aa.StatusAB == true).Select(aa => aa.EmpDate).ToList(); foreach (var empDate in empDates) { if (Request.Form["EmpDate" + empDate].ToString() != null && Request.Form["EmpDate" + empDate].ToString() != "" && Request.Form["EmpDate" + empDate].ToString() != "None") { AttData attData = db.AttDatas.First(aa => aa.EmpDate == empDate); string date = attData.AttDate.ToString(); var Name = Request.Form["EmpDate" + empDate].ToString(); if (Name.Count() > 0) { switch (Name) { case "JC:Official Duty": AddJobCardsIntoDatabse(empDate, datas, Name, date); break; case "JC:Field Visit": AddJobCardsIntoDatabse(empDate, datas, Name, date); break; case "JC:Training": AddJobCardsIntoDatabse(empDate, datas, Name, date); break; case "LV:Casual": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Annual": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "HLV:Casual": AddLeaveIntoDatabase(empDate, datas, Name, date, true); break; case "HLV:Annual": AddLeaveIntoDatabase(empDate, datas, Name, date, true); break; case "LV:Sick": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Ex Pakistan Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Study Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Optional Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Maternity Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Compensatory": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Special Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Recreation Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; case "LV:Extraordinary Leave": AddLeaveIntoDatabase(empDate, datas, Name, date, false); break; } } db.SaveChanges(); } } } datas.dbViewAttData = db.ViewAttDatas.Where(aa => aa.EmpNo == datas.EmpNo && aa.AttDate >= datas.FromDate && aa.AttDate <= datas.ToDate && aa.StatusAB == true).ToList(); return(View("Index", datas)); }
public ActionResult EditAttWizardData([Bind(Include = "EmpDate,AttDate,EmpNo,EmpID,DutyCode,DutyTime,TimeIn,TimeOut,WorkMin,LateIn,LateOut,EarlyIn,EarlyOut,OTMin,GZOTMin,BreakMin,SLMin,StatusP,StatusAB,StatusLI,StatusLO,StatusEI,StatusEO,StatusOT,StatusGZOT,StatusGZ,StatusDO,StatusHD,StatusSL,StatusOD,StatusLeave,StatusMN,StatusIN,StatusBreak,ShifMin,ShfSplit,ProcessIn,Remarks,Tin0,Tout0,Tin1,Tout1,Tin2,Tout2,Tin3,Tout3,Tin4,Tout4,Tin5,Tout5,Tin6,Tout6,Tin7,Tout7,Tin8,Tout8,Tin9,Tout9,Tin10,Tout10,Tin11,Tout11,Tin12,Tout12,Tin13,Tout13,Tin14,Tout14,Tin15,Tout15")] AttData _attData, FormCollection form, string NewDutyCode) { User LoggedInUser = Session["LoggedUser"] as User; string _EmpDate = _attData.EmpDate; ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName"); ViewBag.ShiftList = new SelectList(db.Shifts, "ShiftID", "ShiftName"); ViewBag.CrewList = new SelectList(db.Crews, "CrewID", "CrewName"); ViewBag.SectionList = new SelectList(db.Sections, "SectionID", "SectionName"); ViewBag.CompanyID = new SelectList(db.Companies, "CompID", "CompName", LoggedInUser.CompanyID); try { string STimeIn = form["Inhours"].ToString(); string STimeOut = form["OutHour"].ToString(); string STimeInH = STimeIn.Substring(0, 2); string STimeInM = STimeIn.Substring(2, 2); string STimeOutH = STimeOut.Substring(0, 2); string STimeOutM = STimeOut.Substring(2, 2); string DutyTime = form["DutyTime"].ToString(); string Remarks = form["NewRemarks"].ToString(); string SDutyH = DutyTime.Substring(0, 2); string SDutyM = DutyTime.Substring(2, 2); string ShiftMinString = form["ShiftMinHidden"].ToString(); if (TimeValid(STimeIn, STimeOut)) { TimeSpan _TimeIn = new TimeSpan(Convert.ToInt16(STimeInH), Convert.ToInt16(STimeInM), 0); TimeSpan _TimeOut = new TimeSpan(Convert.ToInt16(STimeOutH), Convert.ToInt16(STimeOutM), 0); TimeSpan _DutyTime = Convert.ToDateTime(form["DutyTime"].ToString()).TimeOfDay; //TimeSpan _DutyTime = new TimeSpan(Convert.ToInt16(SDutyH), Convert.ToInt16(SDutyM), 0); TimeSpan _ThresHoldTimeS = new TimeSpan(14, 00, 00); TimeSpan _ThresHoldTimeE = new TimeSpan(06, 00, 00); string date = Request.Form["Attdate"].ToString(); DateTime _AttDate = Convert.ToDateTime(date); short ShiftMins = Convert.ToInt16(ShiftMinString); DateTime _NewTimeIn = new DateTime(); DateTime _NewTimeOut = new DateTime(); _NewTimeIn = _AttDate + _TimeIn; if (_TimeOut < _TimeIn) { _NewTimeOut = _AttDate.AddDays(1) + _TimeOut; } else { _NewTimeOut = _AttDate + _TimeOut; } int _UserID = Convert.ToInt32(Session["LogedUserID"].ToString()); HelperClass.MyHelper.SaveAuditLog(_UserID, (byte)MyEnums.FormName.EditAttendance, (byte)MyEnums.Operation.Edit, DateTime.Now); ManualAttendanceProcess _pma = new ManualAttendanceProcess(_EmpDate, "", false, _NewTimeIn, _NewTimeOut, NewDutyCode, _UserID, _DutyTime, Remarks, ShiftMins); List <PollData> _Polls = new List <PollData>(); _Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); _attData = db.AttDatas.First(aa => aa.EmpDate == _EmpDate); ViewBag.SucessMessage = "Attendance record updated."; if (_attData.WorkMin != null) { ViewBag.WorkMin = TimeSpan.FromMinutes((double)_attData.WorkMin); } if (_attData.LateOut != null) { ViewBag.LateOut = TimeSpan.FromMinutes((double)_attData.LateOut); } if (_attData.LateIn != null) { ViewBag.LateIn = TimeSpan.FromMinutes((double)_attData.LateIn); } if (_attData.EarlyOut != null) { ViewBag.EarlyOut = TimeSpan.FromMinutes((double)_attData.EarlyOut); } if (_attData.EarlyIn != null) { ViewBag.EarlyIn = TimeSpan.FromMinutes((double)_attData.EarlyIn); } if (_attData.OTMin != null) { ViewBag.OT = TimeSpan.FromMinutes((double)_attData.OTMin); } if (_attData.StatusGZOT == true) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_attData.GZOTMin); } return(View("EditAttWizardOne", _attData)); } else { ViewBag.SucessMessage = "New Time In and New Time out is not valid"; _attData = db.AttDatas.First(aa => aa.EmpDate == _EmpDate); return(View(_attData)); } } catch (Exception ex) { ViewBag.SucessMessage = "An error occured while saving Entry"; _attData = db.AttDatas.First(aa => aa.EmpDate == _EmpDate); List <PollData> _Polls = new List <PollData>(); _Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); return(View(_attData)); } }
public void ProcessDailyAttendance() { DateTime _dt = GlobalSettings._dateTime; DateTime dtTo = new DateTime(2015, 12, 7); DateTime dtFrom = new DateTime(2015, 12, 8); List <PollData> unprocessedPolls = context.PollDatas.Where(p => (p.Process == false)).OrderBy(e => e.EntTime).ToList(); //List<PollData> unprocessedPolls = context.PollDatas.Where(p => (p.EntDate >= dtTo && p.EntDate <= dtFrom) && p.EmpID == 180).OrderBy(e => e.EntTime).ToList(); foreach (PollData up in unprocessedPolls) { try { //Create Attendance if any poll date is not processed already if (context.AttProcesses.Where(ap => ap.ProcessDate == up.EntDate).Count() == 0) { CreateAttendance(up.EntDate.Date); } //Check AttData with EmpDate if (context.AttDatas.Where(attd => attd.EmpDate == up.EmpDate).Count() > 0) { AttData attendanceRecord = context.AttDatas.First(attd => attd.EmpDate == up.EmpDate); employee = attendanceRecord.Emp; Shift shift = employee.Shift; //Set Time In and Time Out in AttData if (attendanceRecord.Emp.Shift.OpenShift == true) { //Set Time In and Time Out for open shift PlaceTimeInOuts.CalculateTimeINOUTOpenShift(attendanceRecord, up); } else { TimeSpan checkTimeEnd = new TimeSpan(); DateTime TimeInCheck = new DateTime(); if (attendanceRecord.TimeIn == null) { TimeInCheck = attendanceRecord.AttDate.Value.Add(attendanceRecord.DutyTime.Value); } else { TimeInCheck = attendanceRecord.TimeIn.Value; } if (attendanceRecord.ShifMin == 0) { checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, 480, 0)); } else { checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, (int)attendanceRecord.ShifMin, 0)); } if (checkTimeEnd.Days > 0) { //if Time out occur at next day if (up.RdrDuty == 5) { DateTime dt = new DateTime(); dt = up.EntDate.Date.AddDays(-1); var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID); if (_attData != null) { if (_attData.TimeIn != null) { TimeSpan t1 = new TimeSpan(11, 00, 00); if (up.EntTime.TimeOfDay < t1) { if ((up.EntTime - _attData.TimeIn.Value).Hours < 18) { attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd"); } } } else { attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd"); } } } } //Set Time In and Time Out if (up.RdrDuty == 5) { if (attendanceRecord.TimeIn != null) { TimeSpan dt = (TimeSpan)(up.EntTime.TimeOfDay - attendanceRecord.TimeIn.Value.TimeOfDay); if (dt.Minutes < 0) { DateTime dt1 = new DateTime(); dt1 = up.EntDate.Date.AddDays(-1); var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt1 && aa.EmpID == up.EmpID); attendanceRecord = _attData; up.EmpDate = up.EmpID.ToString() + dt1.Date.ToString("yyMMdd"); PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } else { PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up); } } if (employee.Shift.OpenShift == true) { if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd) { DateTime dt = up.EntDate.Date.AddDays(-1); CalculateWorkMins.CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift); context.SaveChanges(); } } //If TimeIn and TimeOut are not null, then calculate other Atributes if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null) { if (context.Rosters.Where(r => r.EmpDate == up.EmpDate).Count() > 0) { CalculateWorkMins.CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift); context.SaveChanges(); } else { if (shift.OpenShift == true) { if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd) { DateTime dt = up.EntDate.Date.AddDays(-1); CalculateWorkMins.CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift); CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift); context.SaveChanges(); } else { //Calculate open shifft time of the same date CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift); context.SaveChanges(); } } else { CalculateWorkMins.CalculateShiftTimes(attendanceRecord, shift); context.SaveChanges(); } } } up.Process = true; } } catch (Exception ex) { string _error = ""; if (ex.InnerException.Message != null) { _error = ex.InnerException.Message; } else { _error = ex.Message; } _myHelperClass.WriteToLogFile("Attendance Processing Error Level 1 " + _error); } context.SaveChanges(); } _myHelperClass.WriteToLogFile("Attendance Processing Completed"); context.Dispose(); }
public ActionResult PreviousEntry() { try { ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName"); ViewData["datef"] = Convert.ToDateTime(Session["EditAttendanceDate"]).ToString("yyyy-MM-dd"); string _EmpNo = Session["NEmpNo"].ToString(); if (_EmpNo != null) { DateTime _AttDataFrom = Convert.ToDateTime(ViewData["datef"].ToString()).AddDays(-1); AttData _attData = new AttData(); _attData = db.AttDatas.First(aa => aa.EmpNo == _EmpNo && aa.AttDate == _AttDataFrom); if (_attData != null) { Session["EditAttendanceDate"] = Convert.ToDateTime(ViewData["datef"]).AddDays(-1); ViewBag.EmpID = new SelectList(db.Emps, "EmpID", "EmpNo", _attData.EmpID); ViewBag.SucessMessage = ""; List <PollData> _Polls = new List <PollData>(); string _EmpDate = _attData.EmpID.ToString() + _AttDataFrom.Date.ToString("yyMMdd"); _Polls = db.PollDatas.Where(aa => aa.EmpDate == _EmpDate).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); if (_attData.WorkMin != null) { ViewBag.WorkMin = (TimeSpan.FromMinutes((double)_attData.WorkMin)); } if (_attData.LateOut != null) { ViewBag.LateOut = TimeSpan.FromMinutes((double)_attData.LateOut); } if (_attData.LateIn != null) { ViewBag.LateIn = TimeSpan.FromMinutes((double)_attData.LateIn); } if (_attData.EarlyOut != null) { ViewBag.EarlyOut = TimeSpan.FromMinutes((double)_attData.EarlyOut); } if (_attData.EarlyIn != null) { ViewBag.EarlyIn = TimeSpan.FromMinutes((double)_attData.EarlyIn); } if (_attData.OTMin != null) { ViewBag.OT = TimeSpan.FromMinutes((double)_attData.OTMin); } if (_attData.StatusGZOT == true) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_attData.GZOTMin); } return(View("EditAttWizardOne", _attData)); } else { return(View("Index")); } } else { return(View("Index")); } } catch (Exception ex) { if (ex.Message.Contains("Sequence")) { ViewBag.Message = "No Entry found on this particular date"; } return(View("Index")); } }
public void CreateAttendance(DateTime dateTime) { using (var ctx = new TAS2013Entities()) { List <Emp> _emp = new List <Emp>(); _emp = ctx.Emps.Where(aa => aa.Status == true).ToList(); List <Roster> _Roster = new List <Roster>(); _Roster = context.Rosters.Where(aa => aa.RosterDate == dateTime).ToList(); List <RosterDetail> _NewRoster = new List <RosterDetail>(); _NewRoster = context.RosterDetails.Where(aa => aa.RosterDate == dateTime).ToList(); List <LvData> _LvData = new List <LvData>(); _LvData = context.LvDatas.Where(aa => aa.AttDate == dateTime).ToList(); List <LvShort> _lvShort = new List <LvShort>(); _lvShort = context.LvShorts.Where(aa => aa.DutyDate == dateTime).ToList(); List <AttData> _AttData = context.AttDatas.Where(aa => aa.AttDate == dateTime).ToList(); _myHelperClass.WriteToLogFile("**********************Attendance Creating Started: Total Employees are:" + _emp.Count + "*********************"); List <Remark> remarks = new List <Remark>(); remarks = ctx.Remarks.ToList(); foreach (var emp in _emp) { string empDate = emp.EmpID + dateTime.ToString("yyMMdd"); if (_AttData.Where(aa => aa.EmpDate == empDate).Count() == 0) { try { ///////////////////////////////////////////////////// // Mark Everyone Absent while creating Attendance // ///////////////////////////////////////////////////// //Set DUTYCODE = D, StatusAB = true, and Remarks = [Absent] AttData att = new AttData(); att.AttDate = dateTime.Date; att.DutyCode = "D"; att.StatusAB = true; att.Remarks = "[Absent]"; if (emp.Shift != null) { att.DutyTime = emp.Shift.StartTime; } else { att.DutyTime = new TimeSpan(07, 45, 00); } att.EmpID = emp.EmpID; att.EmpNo = emp.EmpNo; att.EmpDate = emp.EmpID + dateTime.ToString("yyMMdd"); att.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(emp.Shift, dateTime.DayOfWeek); ////////////////////////// // Check for Rest Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusDO = true, and Remarks=[DO] //Check for 1st Day Off of Shift if (emp.Shift.DaysName.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } //Check for 2nd Day Off of shift if (emp.Shift.DaysName1.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } ////////////////////////// // Check for Roster // //////////////////////// //If Roster DutyCode is Rest then change the StatusAB and StatusDO foreach (var roster in _Roster.Where(aa => aa.EmpDate == att.EmpDate)) { att.DutyCode = roster.DutyCode.Trim(); if (att.DutyCode == "R") { att.StatusAB = false; att.StatusDO = true; att.DutyCode = "R"; att.Remarks = "[DO]"; } att.ShifMin = roster.WorkMin; att.DutyTime = roster.DutyTime; } ////New Roster string empCdate = "Emp" + emp.EmpID.ToString() + dateTime.ToString("yyMMdd"); string sectionCdate = "Section" + emp.SecID.ToString() + dateTime.ToString("yyMMdd"); string crewCdate = "Crew" + emp.CrewID.ToString() + dateTime.ToString("yyMMdd"); string shiftCdate = "Shift" + emp.ShiftID.ToString() + dateTime.ToString("yyMMdd"); if (_NewRoster.Where(aa => aa.CriteriaValueDate == empCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == empCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == sectionCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == sectionCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == crewCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == crewCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == shiftCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == shiftCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; att.ShifMin = 0; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } ////////////////////////// // Check for GZ Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] if (emp.Shift.GZDays == true) { foreach (var holiday in context.Holidays) { if (context.Holidays.Where(hol => hol.HolDate.Month == att.AttDate.Value.Month && hol.HolDate.Day == att.AttDate.Value.Day).Count() > 0) { att.DutyCode = "G"; att.StatusAB = false; att.StatusGZ = true; att.Remarks = "[GZ]"; att.ShifMin = 0; } } } //////////////////////////// // Check for Short Leave// ////////////////////////// foreach (var sLeave in _lvShort.Where(aa => aa.EmpDate == att.EmpDate)) { if (_lvShort.Where(lv => lv.EmpDate == att.EmpDate).Count() > 0) { att.StatusSL = true; att.StatusAB = null; att.DutyCode = "L"; att.Remarks = "[Short Leave]"; } } ////////////////////////// // Check for Leave // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] foreach (var Leave in _LvData) { var _Leave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave != true); if (_Leave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusDO = false; if (Leave.LvCode == "A") { att.Remarks = "[CL]"; } else if (Leave.LvCode == "B") { att.Remarks = "[AL]"; } else if (Leave.LvCode == "C") { att.Remarks = "[SL]"; } else { att.Remarks = "[" + _Leave.FirstOrDefault().LvType.LvDesc + "]"; } } } ///////////////////////// //Check for Half Leave/// //////////////////////// var _HalfLeave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave == true); if (_HalfLeave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusHL = true; att.StatusDO = false; if (_HalfLeave.FirstOrDefault().LvCode == "A") { att.Remarks = "[H-CL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "B") { att.Remarks = "[S-AL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "C") { att.Remarks = "[H-SL]"; } else { att.Remarks = "[Half Leave]"; } } ctx.AttDatas.AddObject(att); ctx.SaveChanges(); } catch (Exception ex) { _myHelperClass.WriteToLogFile("-------Error In Creating Attendance of Employee: " + emp.EmpNo + " ------" + ex.InnerException.Message); } } } _myHelperClass.WriteToLogFile("****************Creating Attendance Completed*****************"); AttProcess attp = new AttProcess(); attp.ProcessDate = dateTime; ctx.AttProcesses.AddObject(attp); ctx.SaveChanges(); //////////////////////////// //Check for Job Card// ////////////////////////// try { ProcessJobCard jc = new ProcessJobCard(); jc.ProcessJobCards(dateTime); } catch (Exception ex) { _myHelperClass.WriteToLogFile("Error at Create Function Process Job Card " + dateTime.ToString()); } ctx.Dispose(); } // reprocess attendance from last 5 days CreateMissingAttendance ca = new CreateMissingAttendance(); ca.CreatemissingAttendance(dateTime.AddDays(-7), dateTime); _myHelperClass.WriteToLogFile("Creating Attendance of Date: " + dateTime.ToString()); }
private void CreateAttendance(DateTime dateTime, List <Emp> _emp) { using (var ctx = new TAS2013Entities()) { List <Roster> _Roster = new List <Roster>(); _Roster = ctx.Rosters.Where(aa => aa.RosterDate == dateTime).ToList(); List <RosterDetail> _NewRoster = new List <RosterDetail>(); _NewRoster = ctx.RosterDetails.Where(aa => aa.RosterDate == dateTime).ToList(); List <LvData> _LvData = new List <LvData>(); _LvData = ctx.LvDatas.Where(aa => aa.AttDate == dateTime).ToList(); List <LvShort> _lvShort = new List <LvShort>(); _lvShort = ctx.LvShorts.Where(aa => aa.DutyDate == dateTime).ToList(); List <AttData> _AttData = ctx.AttDatas.Where(aa => aa.AttDate == dateTime).ToList(); List <Holiday> _Holidays = ctx.Holidays.ToList(); foreach (var emp in _emp) { string empDate = emp.EmpID + dateTime.ToString("yyMMdd"); if (_AttData.Where(aa => aa.EmpDate == empDate).Count() == 0) { try { ///////////////////////////////////////////////////// // Mark Everyone Absent while creating Attendance // ///////////////////////////////////////////////////// //Set DUTYCODE = D, StatusAB = true, and Remarks = [Absent] AttData att = new AttData(); att.AttDate = dateTime.Date; att.DutyCode = "D"; att.StatusAB = true; att.Remarks = "[Absent]"; if (emp.Shift != null) { att.DutyTime = emp.Shift.StartTime; } else { att.DutyTime = new TimeSpan(07, 45, 00); } att.EmpID = emp.EmpID; att.EmpNo = emp.EmpNo; att.EmpDate = emp.EmpID + dateTime.ToString("yyMMdd"); att.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(emp.Shift, dateTime.DayOfWeek); ////////////////////////// // Check for Rest Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusDO = true, and Remarks=[DO] //Check for 1st Day Off of Shift if (emp.Shift.DaysName.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } //Check for 2nd Day Off of shift if (emp.Shift.DaysName1.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek)) { att.DutyCode = "R"; att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; } ////////////////////////// // Check for GZ Day // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] if (emp.Shift.GZDays == true) { foreach (var holiday in _Holidays) { if (_Holidays.Where(hol => hol.HolDate.Month == att.AttDate.Value.Month && hol.HolDate.Day == att.AttDate.Value.Day).Count() > 0) { att.DutyCode = "G"; att.StatusAB = false; att.StatusGZ = true; att.Remarks = "[GZ]"; att.ShifMin = 0; } } } ////////////////////////// // Check for Roster // //////////////////////// //If Roster DutyCode is Rest then change the StatusAB and StatusDO foreach (var roster in _Roster.Where(aa => aa.EmpDate == att.EmpDate)) { att.DutyCode = roster.DutyCode.Trim(); if (att.DutyCode == "R") { att.StatusAB = false; att.StatusDO = true; att.DutyCode = "R"; att.Remarks = "[DO]"; } att.ShifMin = roster.WorkMin; att.DutyTime = roster.DutyTime; } ////New Roster string empCdate = "Emp" + emp.EmpID.ToString() + dateTime.ToString("yyMMdd"); string sectionCdate = "Section" + emp.SecID.ToString() + dateTime.ToString("yyMMdd"); string crewCdate = "Crew" + emp.CrewID.ToString() + dateTime.ToString("yyMMdd"); string shiftCdate = "Shift" + emp.ShiftID.ToString() + dateTime.ToString("yyMMdd"); if (_NewRoster.Where(aa => aa.CriteriaValueDate == empCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == empCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == sectionCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == sectionCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == crewCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == crewCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } else if (_NewRoster.Where(aa => aa.CriteriaValueDate == shiftCdate).Count() > 0) { var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == shiftCdate); if (roster.WorkMin == 0) { att.StatusAB = false; att.StatusDO = true; att.Remarks = "[DO]"; att.DutyCode = "R"; } else { att.ShifMin = roster.WorkMin; att.DutyCode = "D"; att.DutyTime = roster.DutyTime; } } //////////////////////////// //TODO Check for Job Card// ////////////////////////// //////////////////////////// // Check for Short Leave// ////////////////////////// foreach (var sLeave in _lvShort.Where(aa => aa.EmpDate == att.EmpDate)) { if (_lvShort.Where(lv => lv.EmpDate == att.EmpDate).Count() > 0) { att.StatusSL = true; att.StatusAB = null; att.DutyCode = "L"; att.Remarks = "[Short Leave]"; } } ////////////////////////// // Check for Leave // //////////////////////// //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ] foreach (var Leave in _LvData) { var _Leave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave != true); if (_Leave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusDO = false; if (Leave.LvCode == "A") { att.Remarks = "[Casual Leave]"; } else if (Leave.LvCode == "B") { att.Remarks = "[Annual Leave]"; } else if (Leave.LvCode == "C") { att.Remarks = "[Sick Leave]"; } else { att.Remarks = "[Leave]"; } } else { att.StatusLeave = false; } } ///////////////////////// //Check for Half Leave/// //////////////////////// var _HalfLeave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave == true); if (_HalfLeave.Count() > 0) { att.StatusLeave = true; att.StatusAB = false; att.DutyCode = "L"; att.StatusDO = false; att.StatusHL = true; if (_HalfLeave.FirstOrDefault().LvCode == "A") { att.Remarks = "[H-CL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "B") { att.Remarks = "[S-AL]"; } else if (_HalfLeave.FirstOrDefault().LvCode == "C") { att.Remarks = "[H-SL]"; } else { att.Remarks = "[Half Leave]"; } } else { att.StatusLeave = false; att.StatusHL = false; } ctx.AttDatas.AddObject(att); ctx.SaveChanges(); } catch (Exception ex) { _myHelperClass.WriteToLogFile("Error In Creating Attendance of Employee: " + emp.EmpNo); } } } } _myHelperClass.WriteToLogFile("Creating Attendance of Date: " + dateTime.ToString()); }
public static void CalculateShiftTimes(AttData attendanceRecord, Shift shift) { try { //Calculate WorkMin attendanceRecord.Remarks = ""; TimeSpan mins = (TimeSpan)(attendanceRecord.TimeOut - attendanceRecord.TimeIn); //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true) { attendanceRecord.GZOTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[G-OT]"; } //if Rest day then place all WorkMin in OTMin else if (attendanceRecord.StatusDO == true) { if (attendanceRecord.Emp.HasOT != false) { attendanceRecord.OTMin = (short)mins.TotalMinutes; attendanceRecord.WorkMin = (short)mins.TotalMinutes; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; // RoundOff Overtime //multi companies // if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.CompanyID == 1) //generic no companies if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4)) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } } } else { /////////// to-do -----calculate Margins for those shifts which has break mins if (shift.HasBreak == true) { attendanceRecord.WorkMin = (short)(mins.TotalMinutes - shift.BreakMin); attendanceRecord.ShifMin = (short)(ProcessSupportFunc.CalculateShiftMinutes(shift, attendanceRecord.AttDate.Value.DayOfWeek) - (short)shift.BreakMin); } else { attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; //Calculate Late IN, Compare margin with Shift Late In if (attendanceRecord.TimeIn.Value.TimeOfDay > attendanceRecord.DutyTime) { TimeSpan lateMinsSpan = (TimeSpan)(attendanceRecord.TimeIn.Value.TimeOfDay - attendanceRecord.DutyTime); if (lateMinsSpan.TotalMinutes > shift.LateIn) { attendanceRecord.LateIn = (short)lateMinsSpan.TotalMinutes; attendanceRecord.StatusLI = true; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LI]"; } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks.Replace("[LI]", ""); } } else { attendanceRecord.StatusLI = null; attendanceRecord.LateIn = null; attendanceRecord.Remarks.Replace("[LI]", ""); } //Calculate Early In, Compare margin with Shift Early In if (attendanceRecord.TimeIn.Value.TimeOfDay < attendanceRecord.DutyTime) { TimeSpan EarlyInMinsSpan = (TimeSpan)(attendanceRecord.DutyTime - attendanceRecord.TimeIn.Value.TimeOfDay); if (EarlyInMinsSpan.TotalMinutes > shift.EarlyIn) { attendanceRecord.EarlyIn = (short)EarlyInMinsSpan.TotalMinutes; attendanceRecord.StatusEI = true; attendanceRecord.LateIn = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EI]"; } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } } else { attendanceRecord.StatusEI = null; attendanceRecord.EarlyIn = null; attendanceRecord.Remarks.Replace("[EI]", ""); } // CalculateShiftEndTime = ShiftStart + DutyHours DateTime shiftEnd = ProcessSupportFunc.CalculateShiftEndTimeWithAttData(attendanceRecord.AttDate.Value, attendanceRecord.DutyTime.Value, attendanceRecord.ShifMin); //Calculate Early Out, Compare margin with Shift Early Out if (attendanceRecord.TimeOut < shiftEnd) { TimeSpan EarlyOutMinsSpan = (TimeSpan)(shiftEnd - attendanceRecord.TimeOut); if (EarlyOutMinsSpan.TotalMinutes > shift.EarlyOut) { attendanceRecord.EarlyOut = (short)EarlyOutMinsSpan.TotalMinutes; attendanceRecord.StatusEO = true; attendanceRecord.LateOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[EO]"; } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } } else { attendanceRecord.StatusEO = null; attendanceRecord.EarlyOut = null; attendanceRecord.Remarks.Replace("[EO]", ""); } //Calculate Late Out, Compare margin with Shift Late Out if (attendanceRecord.TimeOut > shiftEnd) { TimeSpan LateOutMinsSpan = (TimeSpan)(attendanceRecord.TimeOut - shiftEnd); if (LateOutMinsSpan.TotalMinutes > shift.LateOut) { attendanceRecord.LateOut = (short)LateOutMinsSpan.TotalMinutes; // Late Out cannot have an early out, In case of poll at multiple times before and after shiftend attendanceRecord.EarlyOut = null; attendanceRecord.StatusLO = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[LO]"; } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.Remarks.Replace("[LO]", ""); } //Subtract EarlyIn and LateOut from Work Minutes //////-------to-do--------- Automate earlyin,lateout from shift setup attendanceRecord.WorkMin = (short)(mins.TotalMinutes); if (attendanceRecord.EarlyIn != null && attendanceRecord.EarlyIn > shift.EarlyIn) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.EarlyIn); } if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } if (attendanceRecord.LateOut != null || attendanceRecord.EarlyIn != null) { // round off work mins if overtime less than shift.OverTimeMin > if (attendanceRecord.WorkMin > attendanceRecord.ShifMin && (attendanceRecord.WorkMin <= (attendanceRecord.ShifMin + shift.OverTimeMin))) { attendanceRecord.WorkMin = attendanceRecord.ShifMin; } } //Calculate OverTime = OT, Compare margin with Shift OverTime //----to-do----- Handle from shift //if (attendanceRecord.EarlyIn > shift.EarlyIn || attendanceRecord.LateOut > shift.LateOut) //{ // if (attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) // { // short _EarlyIn; // short _LateOut; // if (attendanceRecord.EarlyIn == null) // _EarlyIn = 0; // else // _EarlyIn = 0; // if (attendanceRecord.LateOut == null) // _LateOut = 0; // else // _LateOut = (short)attendanceRecord.LateOut; // attendanceRecord.OTMin = (short)(_EarlyIn + _LateOut); // attendanceRecord.StatusOT = true; // attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; // } //} if ((attendanceRecord.StatusGZ != true || attendanceRecord.StatusDO != true) && attendanceRecord.Emp.HasOT == true) { if (attendanceRecord.LateOut != null) { attendanceRecord.OTMin = attendanceRecord.LateOut; attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } } // RoundOff Overtime // if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.CompanyID == 1) if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4)) { if (attendanceRecord.OTMin > 0) { float OTmins = (float)attendanceRecord.OTMin; float remainder = OTmins / 60; int intpart = (int)remainder; double fracpart = remainder - intpart; if (fracpart < 0.5) { attendanceRecord.OTMin = (short)(intpart * 60); } } } //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.Remarks = "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.Remarks.Replace("[Absent]", ""); } } } } } catch (Exception ex) { } }