private void CalculateShiftTimes(AttData attendanceRecord, Shift shift) { try { //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]"; //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 int _lateMin = (int)shift.LateIn; if (attendanceRecord.TimeIn.Value.TimeOfDay > (attendanceRecord.DutyTime + new TimeSpan(0, _lateMin, 0))) { 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,(short)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.Value > shiftEnd) { TimeSpan LateOutMinsSpan = (TimeSpan)(attendanceRecord.TimeOut.Value - 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.OTMin = null; attendanceRecord.StatusOT = null; attendanceRecord.Remarks.Replace("[OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); attendanceRecord.Remarks.Replace("[LO]", ""); } } else { attendanceRecord.StatusLO = null; attendanceRecord.LateOut = null; attendanceRecord.OTMin = null; attendanceRecord.StatusOT = null; attendanceRecord.Remarks.Replace("[OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); 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 = EI+OT, Compare margin with Shift OverTime //----to-do----- Handle from shift if (attendanceRecord.LateOut >0) { 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]"; } else { attendanceRecord.OTMin = null; attendanceRecord.StatusOT = null; attendanceRecord.Remarks.Replace("[OT]", ""); attendanceRecord.Remarks.Replace("[N-OT]", ""); } } //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) { } }
private DateTime CalculateShiftEndTime(Shift shift, DateTime _AttDate, TimeSpan _DutyTime,short ShiftMins) { DateTime _datetime = new DateTime(); TimeSpan _Time = new TimeSpan(0, ShiftMins, 0); _datetime = _AttDate.Date.Add(_DutyTime); _datetime = _datetime.Add(_Time); return _datetime; }
private Int16 CalculateShiftMinutes(Shift shift, DayOfWeek dayOfWeek) { Int16 workMins = 0; try { switch (dayOfWeek) { case DayOfWeek.Monday: workMins = shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } } catch (Exception ex) { } return workMins; }
private TimeSpan CalculateShiftEndTime(Shift shift,short ShiftMins) { return shift.StartTime + (new TimeSpan(0, ShiftMins, 0)); }
private DateTime CalculateShiftEndTime(Shift shift, DateTime _AttDate, TimeSpan _DutyTime) { Int16 workMins = 0; try { switch (_AttDate.Date.DayOfWeek) { case DayOfWeek.Monday: workMins = shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } } catch (Exception ex) { } DateTime _datetime = new DateTime(); TimeSpan _Time = new TimeSpan(0, workMins, 0); _datetime = _AttDate.Date.Add(_DutyTime); _datetime = _datetime.Add(_Time); return _datetime; }
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) { } }
private TimeSpan CalculateShiftEndTime(Shift shift, DayOfWeek dayOfWeek) { Int16 workMins = 0; try { switch (dayOfWeek) { case DayOfWeek.Monday: workMins = shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } } catch (Exception ex) { } return shift.StartTime + (new TimeSpan(0, workMins, 0)); }
private bool isRosterValueChanged(RosterAttributes roster, Shift _selectedShift) { DayOfWeek day = roster.DutyDate.DayOfWeek; bool isChanged = roster.DutyTime == _selectedShift.StartTime ? false : true; switch (day) { case DayOfWeek.Monday: if (roster.WorkMin != _selectedShift.MonMin) isChanged = true; break; case DayOfWeek.Tuesday: if (roster.WorkMin != _selectedShift.TueMin) isChanged = true; break; case DayOfWeek.Wednesday: if (roster.WorkMin != _selectedShift.WedMin) isChanged = true; break; case DayOfWeek.Thursday: if (roster.WorkMin != _selectedShift.ThuMin) isChanged = true; break; case DayOfWeek.Friday: if (roster.WorkMin != _selectedShift.FriMin) isChanged = true; break; case DayOfWeek.Saturday: if (roster.WorkMin != _selectedShift.SatMin) isChanged = true; break; case DayOfWeek.Sunday: if (roster.WorkMin != _selectedShift.SunMin) isChanged = true; break; } return isChanged; }
//for shift protected void chkCtrlShift_CheckedChanged(object sender, EventArgs e) { foreach (GridViewRow row in grid_Shift.Rows) { CheckBox ck = ((CheckBox)row.FindControl("chkCtrlShift")); Shift _Shift = new Shift(); _Shift.ShiftID = Convert.ToByte(row.Cells[1].Text); _Shift.ShiftName = row.Cells[2].Text; if (ck.Checked) { if (SelectedShifts.Where(aa => aa.ShiftID == _Shift.ShiftID).Count() == 0) SelectedShifts.Add(_Shift); } else { if (SelectedShifts.Where(aa => aa.ShiftID == _Shift.ShiftID).Count() > 0) { var shift = SelectedShifts.Where(aa => aa.ShiftID == _Shift.ShiftID).First(); SelectedShifts.Remove(shift); } } } }
private int CalculateShiftWorkMins(DateTime _StartDate, Shift shift) { int workMins = 0; switch (_StartDate.DayOfWeek) { case DayOfWeek.Monday: workMins=shift.MonMin; break; case DayOfWeek.Tuesday: workMins = shift.TueMin; break; case DayOfWeek.Wednesday: workMins = shift.WedMin; break; case DayOfWeek.Thursday: workMins = shift.ThuMin; break; case DayOfWeek.Friday: workMins = shift.FriMin; break; case DayOfWeek.Saturday: workMins = shift.SatMin; break; case DayOfWeek.Sunday: workMins = shift.SunMin; break; } return workMins; }
private void CreateRosterEntries(Shift _selectedShift, string criteria, int criteriaValue, DateTime startDate, int noOfDays, List<RosterAttributes> rosters, int _RotaAppID) { int _userID = Convert.ToInt32(Session["LogedUserID"].ToString()); foreach (var roster in rosters) { if (isRosterValueChanged(roster, _selectedShift)) { RosterDetail _RotaDetail = new RosterDetail(); _RotaDetail.CriteriaValueDate = criteria.ToString() + criteriaValue.ToString() + roster.DutyDate.ToString("yyMMdd"); _RotaDetail.CompanyID = _selectedShift.CompanyID; _RotaDetail.OpenShift = _selectedShift.OpenShift; _RotaDetail.UserID = _userID; _RotaDetail.RosterAppID = _RotaAppID; if (roster.WorkMin == 0) { _RotaDetail.DutyCode = "R"; } else { _RotaDetail.DutyCode = "D"; } if (roster.DutyTime == new TimeSpan(0, 0, 0)) { _RotaDetail.OpenShift = true; } else { _RotaDetail.OpenShift = false; } _RotaDetail.DutyTime = roster.DutyTime; _RotaDetail.WorkMin = (short)roster.WorkMin; _RotaDetail.RosterDate = roster.DutyDate; db.RosterDetails.Add(_RotaDetail); db.SaveChanges(); } } }
private List<RosterDetailAttributes> CalculateRosterDetails(List<Models.RosterDetail> rosterdetails, RosterApp rosterApp) { //List<RosterDetailModel> rdm = new List<RosterDetailModel>(); List<RosterDetailAttributes> rda = new List<RosterDetailAttributes>(); Shift shift = new Shift(); shift = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID); DateTime currentDate = rosterApp.DateStarted.Value; List<RosterDetail> tempRotaDetails = new List<RosterDetail>(); while (currentDate <= rosterApp.DateEnded) { RosterDetailAttributes rdaS = new RosterDetailAttributes(); tempRotaDetails = rosterdetails.Where(aa => aa.RosterDate == currentDate).ToList(); if (tempRotaDetails.Count > 0) { rdaS.Changed = true; rdaS.Day = tempRotaDetails.FirstOrDefault().RosterDate.Value.ToString("dddd"); rdaS.DutyCode = tempRotaDetails.FirstOrDefault().DutyCode; rdaS.DutyDate = tempRotaDetails.FirstOrDefault().RosterDate.Value; rdaS.DutyTime = (TimeSpan)tempRotaDetails.FirstOrDefault().DutyTime; rdaS.WorkMin = (short)tempRotaDetails.FirstOrDefault().WorkMin; } else { rdaS.Changed = false; rdaS.Day = currentDate.ToString("dddd"); int wrkMin = CalculateDutyCode(shift, currentDate); if (wrkMin == 0) rdaS.DutyCode = "R"; else rdaS.DutyCode = "D"; rdaS.DutyDate = currentDate; rdaS.DutyTime = shift.StartTime; rdaS.WorkMin = wrkMin; } rda.Add(rdaS); currentDate = currentDate.AddDays(1); } return rda; }
private int CalculateDutyCode(Shift shift, DateTime currentDate) { string dutyCode = "D"; int workMin = 0; switch (currentDate.DayOfWeek) { case DayOfWeek.Monday: workMin=shift.MonMin; break; case DayOfWeek.Tuesday: workMin = shift.TueMin; break; case DayOfWeek.Wednesday: workMin = shift.WedMin; break; case DayOfWeek.Thursday: workMin = shift.ThuMin; break; case DayOfWeek.Friday: workMin = shift.FriMin; break; case DayOfWeek.Saturday: workMin = shift.SatMin; break; case DayOfWeek.Sunday: workMin = shift.SunMin; break; } return workMin; }
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 if ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.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 { /////////// 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.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) { } }
public static 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 ((attendanceRecord.Emp.EmpType.CatID == 2 || attendanceRecord.Emp.EmpType.CatID == 4) && attendanceRecord.Emp.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 > 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.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) && attendanceRecord.Emp.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) { } }
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.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.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) { } }