//Work Times calculation controller public void ProcessDailyAttendance(Att_DailyAttendance _attData) { try { Att_DailyAttendance attendanceRecord = _attData; HR_Employee employee = attendanceRecord.HR_Employee; List <Att_ShiftChngedEmp> _shiftEmpCh = new List <Att_ShiftChngedEmp>(); _shiftEmpCh = context.Att_ShiftChngedEmp.ToList(); List <Att_OutPass> _OutPasses = new List <Att_OutPass>(); _OutPasses = context.Att_OutPass.Where(aa => aa.EmpID == _attData.EmpID && aa.Dated == _attData.AttDate.Value).ToList(); List <Att_Shift> shifts = new List <Att_Shift>(); shifts = context.Att_Shift.ToList(); List <Att_ShiftChanged> cshifts = new List <Att_ShiftChanged>(); cshifts = context.Att_ShiftChanged.ToList(); if (_attData.StatusLeave == true) { _attData.ShifMin = 0; } //If TimeIn and TimeOut are not null, then calculate other Atributes if (_attData.TimeIn != null && _attData.TimeOut != null) { Att_Shift _shift = ProcessSupportFunc.GetEmployeeChangedShift(_attData.HR_Employee, _shiftEmpCh.Where(aa => aa.EmpID == _attData.EmpID).ToList(), _attData.AttDate.Value, shifts); MyShift shift = ProcessSupportFunc.GetEmployeeShift(_shift); if (_attData.StatusHL == true) { _attData.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(shift, _attData.AttDate.Value.DayOfWeek); _attData.ShifMin = (short)(_attData.ShifMin / 2); } //If TimeIn = TimeOut then calculate according to DutyCode if (_attData.TimeIn == _attData.TimeOut) { CalculateInEqualToOut(_attData); } else { if (_attData.DutyTime == new TimeSpan(0, 0, 0)) { //CalculateWorkMins.CalculateOpenShiftTimes(_attData, shift, _attData.HR_Employee.Att_OTPolicy); } Att_OutPass aop = new Att_OutPass(); if (_OutPasses.Where(aa => aa.Dated == _attData.AttDate && aa.EmpID == _attData.EmpID).Count() > 0) { aop = _OutPasses.First(aa => aa.Dated == _attData.AttDate && aa.EmpID == _attData.EmpID); } //CalculateWorkMins.CalculateShiftTimes(_attData, shift, _attData.HR_Employee.Att_OTPolicy, aop); } } else { CalculateInEqualToOut(_attData); } } catch (Exception ex) { } context.SaveChanges(); }
private void SaveOldAttData(Att_DailyAttendance _OldAttData, int Userid) { try { _ManualEditData.OldDutyCode = _OldAttData.DutyCode; _ManualEditData.OldTimeIn = _OldAttData.TimeIn; _ManualEditData.OldTimeOut = _OldAttData.TimeOut; _ManualEditData.EmpDate = _OldAttData.EmpDate; _ManualEditData.UserID = Userid; _ManualEditData.EditDateTime = DateTime.Now; _ManualEditData.EmpID = _OldAttData.EmpID; _ManualEditData.OldRemarks = _OldAttData.Remarks; } catch (Exception ex) { } }
public ActionResult SaveEditEntriesDateWise(AttEditSingleEmployee Model) { try { int _UserID = Convert.ToInt32(Session["LoggedUserID"].ToString()); int count = Convert.ToInt32(Request.Form["Count"].ToString()); DateTime dt = Convert.ToDateTime(Request.Form["Date"].ToString()); string Criteria = Request.Form["Criteria"].ToString(); int CriteriaData = Convert.ToInt32(Request.Form["CriteriaData"].ToString()); List <Att_DailyAttendance> oldAttendance = new List <Att_DailyAttendance>(); oldAttendance = db.Att_DailyAttendance.Where(aa => aa.AttDate == dt).ToList(); string Message = ""; for (int i = 0; i < count; i++) { int EmpID = Convert.ToInt32(Request.Form["Row" + i.ToString()].ToString()); string empDate = Request.Form["EmpDate" + i.ToString()].ToString(); Att_DailyAttendance att = oldAttendance.First(aa => aa.EmpDate == empDate); string DutyCode = Request.Form["DutyCode" + i.ToString()].ToString(); string DutyTime = Request.Form["DutyTime" + i.ToString()].ToString(); string ShiftTime = Request.Form["ShiftTime" + i.ToString()].ToString(); //string TimeIn = Request.Form["TimeIn" + i.ToString()].ToString(); //string TimeOut = Request.Form["TimeOut" + i.ToString()].ToString(); string TIn1 = Request.Form["TimeIn1" + i.ToString()].ToString(); string TOut1 = Request.Form["TimeOut1" + i.ToString()].ToString(); string TIn2 = Request.Form["TimeIn2" + i.ToString()].ToString(); string TOut2 = Request.Form["TimeOut2" + i.ToString()].ToString(); string TIn3 = Request.Form["TimeIn3" + i.ToString()].ToString(); string TOut3 = Request.Form["TimeOut3" + i.ToString()].ToString(); string Remarks = Request.Form["Remarks" + i.ToString()].ToString(); EditAttendanceList editlist = EditAttManager.GetEditAttendanceList(empDate, DutyCode, DutyTime, ShiftTime, TIn1, TOut1, TIn2, TOut2, TIn3, TOut3, Remarks); if (EditAttManager.CheckRecordIsEdited(att, editlist)) { DateTime _NewTimeIn = new DateTime(); DateTime _NewTimeOut = new DateTime(); DateTime?_NewTimeIn1; DateTime?_NewTimeOut1; DateTime?_NewTimeIn2; DateTime?_NewTimeOut2; DateTime?_NewTimeIn3; DateTime?_NewTimeOut3; _NewTimeIn = (DateTime)(att.AttDate + editlist.TimeIn); if (editlist.TimeIn != null && editlist.TimeOut != null) { if (editlist.TimeIn1 != null) { _NewTimeIn1 = (DateTime)(att.AttDate + editlist.TimeIn1); } else { _NewTimeIn1 = null; } if (editlist.TimeIn2 != null) { _NewTimeIn2 = (DateTime)(att.AttDate + editlist.TimeIn2); } else { _NewTimeIn2 = null; } if (editlist.TimeIn3 != null) { _NewTimeIn3 = (DateTime)(att.AttDate + editlist.TimeIn3); } else { _NewTimeIn3 = null; } if (editlist.TimeOut1 != null) { _NewTimeOut1 = (DateTime)(att.AttDate + editlist.TimeOut1); } else { _NewTimeOut1 = null; } if (editlist.TimeOut2 != null) { _NewTimeOut2 = (DateTime)(att.AttDate + editlist.TimeOut2); } else { _NewTimeOut2 = null; } if (editlist.TimeOut3 != null) { _NewTimeOut3 = (DateTime)(att.AttDate + editlist.TimeOut3); } else { _NewTimeOut3 = null; } if (editlist.TimeOut < editlist.TimeIn) { _NewTimeOut = att.AttDate.Value.AddDays(1) + editlist.TimeOut; } else { _NewTimeOut = (DateTime)(att.AttDate + editlist.TimeOut); } if (editlist.TimeOut1 < editlist.TimeIn1) { _NewTimeOut1 = att.AttDate.Value.AddDays(1) + editlist.TimeOut1; } if (editlist.TimeOut2 < editlist.TimeIn2) { _NewTimeOut2 = att.AttDate.Value.AddDays(1) + editlist.TimeOut2; } if (editlist.TimeOut3 < editlist.TimeIn3) { _NewTimeOut3 = att.AttDate.Value.AddDays(1) + editlist.TimeOut3; } ManualAttendanceProcess _pma = new ManualAttendanceProcess(editlist.EmpDate, "", false, _NewTimeIn, _NewTimeOut, editlist.DutyCode, _UserID, editlist.DutyTime, "", (short)editlist.ShiftTime.TotalMinutes, _NewTimeIn1, _NewTimeOut1, _NewTimeIn2, _NewTimeOut2, _NewTimeIn3, _NewTimeOut3, Remarks); } } else { } } using (var ctx = new HRMEntities()) { List <Att_DailyAttendance> dailyAttendance = new List <Att_DailyAttendance>(); switch (Criteria) { case "rbAll": dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); Criteria = "rbAll"; break; case "rbShift": dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.ShiftID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); Criteria = "rbShift"; break; case "rbLocation": dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.LocationID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); Criteria = "rbLocation"; break; //case "rbGroup": // dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.GroupID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); // Criteria = "rbGroup"; // break; //case "rbDivision": // dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.HR_Section.HR_Department.DivsionID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); // Criteria = "rbDivision"; // break; case "rbDepartment": dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.HR_Section.DepartmentID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); Criteria = "rbDepartment"; break; case "rbSection": dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.HR_Employee.SectionID == CriteriaData && aa.AttDate == dt).OrderByDescending(aa => aa.EmpID).ToList(); Criteria = "rbSection"; break; } return(View("EditDateWiseEntries", EditAttManager.GetAttendanceAttributesDateWise(dailyAttendance, dt, Criteria, CriteriaData))); } } catch (Exception) { throw; } }
public ActionResult Edit(FormCollection form) { try { User LoggedInUser = Session["LoggedUser"] as User; //ViewBag.JobCardType = new SelectList(db.JobCards.OrderBy(s => s.WorkCardName), "WorkCardID", "WorkCardName"); ViewBag.ShiftList = new SelectList(db.Att_Shift.OrderBy(s => s.ShiftName), "ShftID", "ShiftName"); //ViewBag.CrewList = new SelectList(db.Crews.OrderBy(s => s.CrewName), "CrewID", "CrewName"); //ViewBag.CompanyID = new SelectList(db.Companies.OrderBy(s => s.CompName), "CompID", "CompName", LoggedInUser.CompanyID); //ViewBag.CompanyIDJobCard = new SelectList(db.Companies, "CompID", "CompName"); ViewBag.SectionList = new SelectList(db.HR_Section.OrderBy(s => s.SectionName), "SecID", "SectionName"); ViewData["datef"] = Convert.ToDateTime(Request.Form["DateFrom"].ToString()).ToString("yyyy-MM-dd"); ViewBag.DesignationID = new SelectList(db.HR_Designation.OrderBy(s => s.DesignationName), "DesignationID", "DesignationName"); 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); Att_DailyAttendance _attData = new Att_DailyAttendance(); List <HR_Employee> _Emp = new List <HR_Employee>(); int EmpID = 0; //_Emp = db.HR_Employee.Where(aa => aa.EmpNo == _EmpNo && aa.CompanyID ==compID && aa.Status==true).ToList(); _Emp = db.HR_Employee.Where(aa => aa.EmpNo == _EmpNo).ToList(); if (_Emp.Count > 0) { EmpID = _Emp.FirstOrDefault().EmployeeID; } _attData = db.Att_DailyAttendance.FirstOrDefault(aa => aa.EmpID == EmpID && aa.AttDate == _AttDataFrom); if (_attData != null) { List <Att_DeviceData> _Polls = new List <Att_DeviceData>(); string _EmpDate = _attData.EmpID.ToString() + _AttDataFrom.Date.ToString("yyMMdd"); _Polls = db.Att_DeviceData.Where(aa => aa.EntDate == _AttDataFrom && aa.EmpID == _attData.EmpID).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.HR_Employee.OrderBy(s => s.FullName), "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.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")); } }
public ActionResult SaveEditEntries(AttEditSingleEmployee Model) { try { bool edited = false; int _UserID = Convert.ToInt32(Session["LoggedUserID"].ToString()); int empID = Convert.ToInt32(Request.Form["empID"].ToString()); DateTime dtFrom = Convert.ToDateTime(Request.Form["dateFrom"].ToString()); DateTime dtTo = Convert.ToDateTime(Request.Form["dateTo"].ToString()); List <Att_DailyAttendance> oldAttendance = new List <Att_DailyAttendance>(); oldAttendance = db.Att_DailyAttendance.Where(aa => aa.EmpID == empID && aa.AttDate >= dtFrom && aa.AttDate <= dtTo).ToList(); for (int i = 0; i < oldAttendance.Count; i++) { string empDate = Request.Form["EmpDate" + i.ToString()].ToString(); Att_DailyAttendance att = oldAttendance.First(aa => aa.EmpDate == empDate); string DutyCode = Request.Form["DutyCode" + i.ToString()].ToString(); string DutyTime = Request.Form["DutyTime" + i.ToString()].ToString(); string ShiftTime = Request.Form["ShiftTime" + i.ToString()].ToString(); //string TimeIn = Request.Form["TimeIn" + i.ToString()].ToString(); //string TimeOut = Request.Form["TimeOut" + i.ToString()].ToString(); string TIn1 = Request.Form["TimeIn1" + i.ToString()].ToString(); string TOut1 = Request.Form["TimeOut1" + i.ToString()].ToString(); string TIn2 = Request.Form["TimeIn2" + i.ToString()].ToString(); string TOut2 = Request.Form["TimeOut2" + i.ToString()].ToString(); string TIn3 = Request.Form["TimeIn3" + i.ToString()].ToString(); string TOut3 = Request.Form["TimeOut3" + i.ToString()].ToString(); string Remarks = Request.Form["Remarks" + i.ToString()].ToString(); EditAttendanceList editlist = EditAttManager.GetEditAttendanceList(empDate, DutyCode, DutyTime, ShiftTime, TIn1, TOut1, TIn2, TOut2, TIn3, TOut3, Remarks); if (EditAttManager.CheckRecordIsEdited(att, editlist)) { edited = true; DateTime _NewTimeIn = new DateTime(); DateTime _NewTimeOut = new DateTime(); DateTime?_NewTimeIn1; DateTime?_NewTimeOut1; DateTime?_NewTimeIn2; DateTime?_NewTimeOut2; DateTime?_NewTimeIn3; DateTime?_NewTimeOut3; _NewTimeIn = (DateTime)(att.AttDate + editlist.TimeIn); if (editlist.TimeIn != null && editlist.TimeOut != null) { if (editlist.TimeIn1 != null) { _NewTimeIn1 = (DateTime)(att.AttDate + editlist.TimeIn1); } else { _NewTimeIn1 = null; } if (editlist.TimeIn2 != null) { _NewTimeIn2 = (DateTime)(att.AttDate + editlist.TimeIn2); } else { _NewTimeIn2 = null; } if (editlist.TimeIn3 != null) { _NewTimeIn3 = (DateTime)(att.AttDate + editlist.TimeIn3); } else { _NewTimeIn3 = null; } if (editlist.TimeOut1 != null) { _NewTimeOut1 = (DateTime)(att.AttDate + editlist.TimeOut1); } else { _NewTimeOut1 = null; } if (editlist.TimeOut2 != null) { _NewTimeOut2 = (DateTime)(att.AttDate + editlist.TimeOut2); } else { _NewTimeOut2 = null; } if (editlist.TimeOut3 != null) { _NewTimeOut3 = (DateTime)(att.AttDate + editlist.TimeOut3); } else { _NewTimeOut3 = null; } if (editlist.TimeOut < editlist.TimeIn) { _NewTimeOut = att.AttDate.Value.AddDays(1) + editlist.TimeOut; } else { _NewTimeOut = (DateTime)(att.AttDate + editlist.TimeOut); } if (editlist.TimeOut1 < editlist.TimeIn1) { _NewTimeOut1 = att.AttDate.Value.AddDays(1) + editlist.TimeOut1; } if (editlist.TimeOut2 < editlist.TimeIn2) { _NewTimeOut2 = att.AttDate.Value.AddDays(1) + editlist.TimeOut2; } if (editlist.TimeOut3 < editlist.TimeIn3) { _NewTimeOut3 = att.AttDate.Value.AddDays(1) + editlist.TimeOut3; } ManualAttendanceProcess _pma = new ManualAttendanceProcess(editlist.EmpDate, "", false, _NewTimeIn, _NewTimeOut, editlist.DutyCode, _UserID, editlist.DutyTime, "", (short)editlist.ShiftTime.TotalMinutes, _NewTimeIn1, _NewTimeOut1, _NewTimeIn2, _NewTimeOut2, _NewTimeIn3, _NewTimeOut3, Remarks); } else { if (editlist.TimeIn.TotalMinutes > 0) { _NewTimeIn = (DateTime)(att.AttDate + editlist.TimeIn); } if (editlist.TimeOut.TotalMinutes > 0) { _NewTimeOut = (DateTime)(att.AttDate + editlist.TimeOut); } ManualAttendanceProcess _pma = new ManualAttendanceProcess(editlist.EmpDate, "", false, _NewTimeIn, _NewTimeOut, editlist.DutyCode, _UserID, editlist.DutyTime, "", (short)editlist.ShiftTime.TotalMinutes); } } else { } } if (edited == true) { DateTime dt = oldAttendance.OrderByDescending(aa => aa.AttDate).FirstOrDefault().AttDate.Value; //Process Monthly if date is greater than 20 from start ProcessSupportFunc.ProcessAttendanceRequestMonthly(new DateTime(dt.Year, dt.Month, 1), DateTime.Today, oldAttendance.FirstOrDefault().EmpID.ToString()); } using (var ctx = new HRMEntities()) { List <Att_DailyAttendance> dailyAttendance = new List <Att_DailyAttendance>(); dailyAttendance = ctx.Att_DailyAttendance.Where(aa => aa.EmpID == empID && aa.AttDate >= dtFrom && aa.AttDate <= dtTo).ToList(); return(View("EditMultipleEntries", EditAttManager.GetAttendanceAttributes(dailyAttendance, dtFrom, dtTo))); } } catch (Exception) { throw; } }
public ActionResult PreviousEntry() { try { ViewData["datef"] = Convert.ToDateTime(Session["EditAttendanceDate"]).ToString("yyyy-MM-dd"); int _EmpID = Convert.ToInt32(Session["NEmpNo"]); if (_EmpID != null) { DateTime _AttDataFrom = Convert.ToDateTime(ViewData["datef"].ToString()).AddDays(-1); Att_DailyAttendance _attData = new Att_DailyAttendance(); _attData = db.Att_DailyAttendance.First(aa => aa.EmpID == _EmpID && aa.AttDate == _AttDataFrom); if (_attData != null) { Session["EditAttendanceDate"] = Convert.ToDateTime(ViewData["datef"]).AddDays(-1); ViewBag.EmpID = new SelectList(db.HR_Employee.OrderBy(s => s.EmpNo), "EmpID", "EmpNo", _attData.EmpID); ViewBag.SucessMessage = ""; List <Att_DeviceData> _Polls = new List <Att_DeviceData>(); string _EmpDate = _attData.EmpID.ToString() + _AttDataFrom.Date.ToString("yyMMdd"); _Polls = db.Att_DeviceData.Where(aa => aa.EntDate == _AttDataFrom && aa.EmpID == _attData.EmpID).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.NOTMin != null) { ViewBag.OT = TimeSpan.FromMinutes((double)_attData.NOTMin); } if (_attData.StatusGZOT == true) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_attData.GZOTMin); } return(View("Edit", _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 ActionResult EditData([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")] Att_DailyAttendance _attData, FormCollection form, string NewDutyCode) { // User LoggedInUser = Session["LoggedUser"] as User; string _EmpDate = _attData.EmpDate; //ViewBag.JobCardType = new SelectList(db.JobCards.OrderBy(s=>s.WorkCardName), "WorkCardID", "WorkCardName"); ViewBag.ShiftList = new SelectList(db.Att_Shift.OrderBy(s => s.ShiftName), "ShiftID", "ShiftName"); //ViewBag.CrewList = new SelectList(db.Crews.OrderBy(s=>s.CrewName), "CrewID", "CrewName"); ViewBag.SectionList = new SelectList(db.HR_Section.OrderBy(s => s.SectionName), "SectionID", "SectionName"); //ViewBag.CompanyID = new SelectList(db.Companies, "CompID", "CompName", LoggedInUser.CompanyID); //ViewBag.CompanyIDJobCard = new SelectList(db.Companies, "CompID", "CompName", LoggedInUser.CompanyID); ViewBag.DesignationID = new SelectList(db.HR_Designation.OrderBy(s => s.DesignationName), "DesignationID", "DesignationName"); try { string STimeIn = form["Inhours"].ToString(); if (STimeIn.Count() < 4) { STimeIn = "0" + STimeIn; } string STimeOut = form["OutHour"].ToString(); if (STimeOut.Count() < 4) { STimeOut = "0" + STimeOut; } 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["LoggedUserID"].ToString()); ManualAttendanceProcess _pma = new ManualAttendanceProcess(_EmpDate, "", false, _NewTimeIn, _NewTimeOut, NewDutyCode, _UserID, _DutyTime, Remarks, ShiftMins); List <Att_DeviceData> _Polls = new List <Att_DeviceData>(); _Polls = db.Att_DeviceData.Where(aa => aa.EntDate == _AttDate && aa.EmpID == _attData.EmpID).OrderBy(a => a.EntTime).ToList(); ViewBag.PollsDataIn = _Polls.Where(aa => aa.RdrDuty == 1); ViewBag.PollsDataOut = _Polls.Where(aa => aa.RdrDuty == 5); //_attData = db.Att_DeviceData.First(aa => aa.EmpDate == _EmpDate); Att_DailyAttendance _myAttData = new Att_DailyAttendance(); using (var ctx = new HRMEntities()) { _myAttData = db.Att_DailyAttendance.FirstOrDefault(aa => aa.EmpDate == _EmpDate); } ViewBag.SucessMessage = "Attendance record updated."; if (_myAttData.WorkMin != null) { ViewBag.WorkMin = TimeSpan.FromMinutes((double)_myAttData.WorkMin); } if (_myAttData.LateOut != null) { ViewBag.LateOut = TimeSpan.FromMinutes((double)_myAttData.LateOut); } if (_myAttData.LateIn != null) { ViewBag.LateIn = TimeSpan.FromMinutes((double)_myAttData.LateIn); } if (_myAttData.EarlyOut != null) { ViewBag.EarlyOut = TimeSpan.FromMinutes((double)_myAttData.EarlyOut); } if (_myAttData.EarlyIn != null) { ViewBag.EarlyIn = TimeSpan.FromMinutes((double)_myAttData.EarlyIn); } if (_myAttData.StatusGZOT == true) { ViewBag.GZOT = TimeSpan.FromMinutes((double)_myAttData.GZOTMin); } return(View("Edit", _myAttData)); } else { ViewBag.SucessMessage = "New Time In and New Time out is not valid"; //_attData = db.Att_DeviceData.First(aa => aa.EmpDate == _EmpDate); return(View(_attData)); } } catch (Exception ex) { ViewBag.SucessMessage = "An error occured while saving Entry"; //_attData = db.Att_DeviceData.First(aa => aa.EmpDate == _EmpDate); List <Att_DeviceData> _Polls = new List <Att_DeviceData>(); _Polls = db.Att_DeviceData.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 ManualAttendanceProcess(string EmpDate, string JobCardName, bool JobCardStatus, DateTime NewTimeIn, DateTime NewTimeOut, string NewDutyCode, int _UserID, TimeSpan _NewDutyTime, string _Remarks, short _ShiftMins, DateTime?NewTin1, DateTime?NewTout1, DateTime?NewTin2, DateTime?NewTout2, DateTime?NewTin3, DateTime?NewTout3, string Remarks) { _OldAttData = context.Att_DailyAttendance.First(aa => aa.EmpDate == EmpDate); if (_OldAttData != null) { if (JobCardStatus == false) { SaveOldAttData(_OldAttData, _UserID); if (SaveNewAttData(NewTimeIn, NewTimeOut, NewDutyCode, _NewDutyTime, _Remarks, _ShiftMins, NewTin1, NewTout1, NewTin2, NewTout2, NewTin3, NewTout3)) { if (NewTimeIn != NewTimeOut) { _OldAttData.TimeIn = NewTimeIn; _OldAttData.TimeOut = NewTimeOut; } else { _OldAttData.TimeIn = null; _OldAttData.TimeOut = null; } if (NewTin1 != null) { _OldAttData.Tin0 = NewTin1; } else { _OldAttData.Tin0 = null; } if (NewTout1 != null) { _OldAttData.Tout0 = NewTout1; } else { _OldAttData.Tout0 = null; } if (NewTin2 != null) { _OldAttData.Tin1 = NewTin2; } else { _OldAttData.Tin1 = null; } if (NewTout2 != null) { _OldAttData.Tout1 = NewTout2; } else { _OldAttData.Tout1 = null; } if (NewTin3 != null) { _OldAttData.Tin2 = NewTin3; } else { _OldAttData.Tin2 = null; } if (NewTout3 != null) { _OldAttData.Tout2 = NewTout3; } else { _OldAttData.Tout2 = null; } _OldAttData.DutyCode = NewDutyCode; _OldAttData.DutyTime = _NewDutyTime; _OldAttData.WorkMin = 0; _OldAttData.PDays = 0; _OldAttData.AbDays = 0; _OldAttData.LeaveDays = 0; _OldAttData.LateIn = 0; _OldAttData.LateOut = 0; _OldAttData.EarlyIn = 0; _OldAttData.EarlyOut = 0; _OldAttData.NOTMin = 0; _OldAttData.GZOTMin = 0; _OldAttData.TotalShortMin = 0; _OldAttData.SLMin = 0; _OldAttData.ExtraMin = 0; _OldAttData.StatusP = false; _OldAttData.StatusAB = false; _OldAttData.StatusLI = false; _OldAttData.StatusLO = false; _OldAttData.StatusEI = false; _OldAttData.StatusEO = false; _OldAttData.StatusOT = false; _OldAttData.StatusGZOT = false; _OldAttData.StatusGZ = false; _OldAttData.StatusDO = false; _OldAttData.StatusSL = false; _OldAttData.StatusOD = false; _OldAttData.StatusHL = false; _OldAttData.StatusLeave = false; _OldAttData.StatusMN = true; _OldAttData.StatusIN = false; _OldAttData.ShifMin = _ShiftMins; _OldAttData.Remarks = Remarks; if (NewDutyCode == "G") { _OldAttData.StatusGZ = true; } else { _OldAttData.StatusGZ = false; } if (NewDutyCode == "R") { _OldAttData.StatusDO = true; } else { _OldAttData.StatusDO = false; } if (_Remarks != "") { _OldAttData.Remarks = "[" + _Remarks + "]"; } _OldAttData.StatusLeave = null; ProcessDailyAttendance(_OldAttData); context.SaveChanges(); } } } }
private void CalculateInEqualToOut(Att_DailyAttendance attendanceRecord) { 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]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[M]", ""); switch (attendanceRecord.DutyCode) { case "G": attendanceRecord.StatusAB = false; attendanceRecord.StatusGZ = true; attendanceRecord.WorkMin = 0; attendanceRecord.EarlyIn = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.NOTMin = 0; attendanceRecord.PDays = 0; attendanceRecord.AbDays = 0; attendanceRecord.LeaveDays = 0; attendanceRecord.GZOTMin = 0; attendanceRecord.StatusGZOT = false; attendanceRecord.TimeIn = null; attendanceRecord.TimeOut = null; attendanceRecord.Remarks = attendanceRecord.Remarks + "[GZ][M]"; break; case "R": attendanceRecord.StatusAB = false; attendanceRecord.StatusGZ = false; attendanceRecord.WorkMin = 0; attendanceRecord.EarlyIn = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.ROTMin = 0; attendanceRecord.GZOTMin = 0; attendanceRecord.StatusGZOT = false; attendanceRecord.TimeIn = null; attendanceRecord.TimeOut = null; attendanceRecord.StatusDO = true; attendanceRecord.PDays = 0; attendanceRecord.AbDays = 0; attendanceRecord.LeaveDays = 0; attendanceRecord.Remarks = attendanceRecord.Remarks + "[DO][M]"; break; case "D": if (attendanceRecord.StatusLeave == true) { attendanceRecord.AbDays = 0; attendanceRecord.PDays = 0; attendanceRecord.LeaveDays = 1; attendanceRecord.StatusGZ = false; attendanceRecord.WorkMin = 0; attendanceRecord.EarlyIn = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.NOTMin = 0; attendanceRecord.GZOTMin = 0; attendanceRecord.StatusGZOT = false; attendanceRecord.TimeIn = null; attendanceRecord.TimeOut = null; attendanceRecord.StatusDO = false; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[M]"; } else if (attendanceRecord.StatusHL == true) { attendanceRecord.AbDays = 0.5; attendanceRecord.PDays = 0; attendanceRecord.LeaveDays = 0.5; attendanceRecord.StatusHL = true; attendanceRecord.StatusAB = true; attendanceRecord.StatusGZ = false; attendanceRecord.WorkMin = 0; attendanceRecord.EarlyIn = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.NOTMin = 0; attendanceRecord.GZOTMin = 0; attendanceRecord.StatusGZOT = false; attendanceRecord.TimeIn = null; attendanceRecord.TimeOut = null; attendanceRecord.StatusDO = false; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[HA][M]"; } else { attendanceRecord.AbDays = 1; attendanceRecord.PDays = 0; attendanceRecord.LeaveDays = 0; attendanceRecord.StatusAB = true; attendanceRecord.StatusGZ = false; attendanceRecord.WorkMin = 0; attendanceRecord.EarlyIn = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.NOTMin = 0; attendanceRecord.GZOTMin = 0; attendanceRecord.StatusGZOT = false; attendanceRecord.TimeIn = null; attendanceRecord.TimeOut = null; attendanceRecord.StatusDO = false; attendanceRecord.StatusP = false; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent][M]"; } break; } }
//Replace New TimeIn and Out with Old TimeIN and Out in Attendance Data public ManualAttendanceProcess(string EmpDate, string JobCardName, bool JobCardStatus, DateTime NewTimeIn, DateTime NewTimeOut, string NewDutyCode, int _UserID, TimeSpan _NewDutyTime, string _Remarks, short _ShiftMins) { _OldAttData = context.Att_DailyAttendance.First(aa => aa.EmpDate == EmpDate); if (_OldAttData != null) { if (JobCardStatus == false) { SaveOldAttData(_OldAttData, _UserID); if (SaveNewAttData(NewTimeIn, NewTimeOut, NewDutyCode, _NewDutyTime, _Remarks, _ShiftMins)) { _OldAttData.TimeIn = NewTimeIn; _OldAttData.TimeOut = NewTimeOut; _OldAttData.Tin0 = NewTimeIn; _OldAttData.Tout0 = NewTimeOut; _OldAttData.DutyCode = NewDutyCode; _OldAttData.DutyTime = _NewDutyTime; _OldAttData.WorkMin = 0; _OldAttData.GZOTMin = 0; _OldAttData.NOTMin = 0; _OldAttData.ROTMin = 0; _OldAttData.LateIn = 0; _OldAttData.EarlyIn = 0; _OldAttData.EarlyOut = 0; _OldAttData.LateOut = 0; _OldAttData.ExtraMin = 0; _OldAttData.TotalShortMin = 0; _OldAttData.StatusAB = false; _OldAttData.StatusP = true; _OldAttData.StatusEO = null; _OldAttData.StatusEI = null; _OldAttData.StatusOT = null; _OldAttData.StatusLI = null; _OldAttData.StatusLO = null; _OldAttData.StatusDO = null; _OldAttData.StatusGZOT = null; _OldAttData.StatusLeave = null; _OldAttData.ExtraMin = null; _OldAttData.StatusMN = true; _OldAttData.ShifMin = _ShiftMins; _OldAttData.Remarks = ""; if (NewDutyCode == "G") { _OldAttData.StatusGZ = true; } else { _OldAttData.StatusGZ = false; } if (NewDutyCode == "R") { _OldAttData.StatusDO = true; } else { _OldAttData.StatusDO = false; } if (_Remarks != "") { _OldAttData.Remarks = "[" + _Remarks + "]"; } _OldAttData.StatusLeave = null; ProcessDailyAttendance(_OldAttData); } } } }
public static void CalculateShiftTimes(Att_DailyAttendance attendanceRecord, MyShift shift, Att_OTPolicy otPolicy, Att_OutPass op) { try { attendanceRecord.TimeIn = attendanceRecord.TimeIn.Value.Trim(TimeSpan.TicksPerMinute); attendanceRecord.TimeOut = attendanceRecord.TimeOut.Value.Trim(TimeSpan.TicksPerMinute); // Break start and End Times DateTime ts = attendanceRecord.TimeIn.Value.Date + new TimeSpan(13, 0, 0); DateTime te = attendanceRecord.TimeIn.Value.Date + new TimeSpan(14, 0, 0); //Work Mins TimeSpan mins = attendanceRecord.TimeOut.Value.TimeOfDay - attendanceRecord.TimeOut.Value.TimeOfDay; double _workHours = mins.TotalHours; attendanceRecord.WorkMin = (short)(mins.TotalMinutes); if (attendanceRecord.WorkMin > 0) { if (attendanceRecord.Remarks != null) { attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Manual]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LI]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[M]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[N-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EI]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[R-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[G-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[HA]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[DO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[GZ]", ""); } else { attendanceRecord.Remarks = ""; } if (attendanceRecord.StatusMN == true) { attendanceRecord.Remarks = "[M]" + attendanceRecord.Remarks; } //Check if GZ holiday then place all WorkMin in GZOTMin if (attendanceRecord.StatusGZ == true && attendanceRecord.DutyCode == "G") { #region -- GZ Calculation-- if (otPolicy.CalculateGZOT == true) { if ((_workHours >= otPolicy.PerDayGOTStartLimitHour) && (_workHours <= otPolicy.PerDayGOTEndLimitHour)) { int hour = (int)(mins.TotalMinutes / 60); int min = hour * 60; int remainingmin = (int)mins.TotalMinutes - min; if (remainingmin >= otPolicy.MinMinutesForOneHour) { attendanceRecord.GZOTMin = (short)((hour + 1) * 60); } else { attendanceRecord.GZOTMin = (short)((hour) * 60); } } else { if (_workHours < otPolicy.PerDayGOTStartLimitHour) { attendanceRecord.GZOTMin = 0; } else { int policyOTLimitMin = (int)(otPolicy.PerDayGOTEndLimitHour * 60.0); attendanceRecord.GZOTMin = (short)policyOTLimitMin; } } } else { attendanceRecord.WorkMin = 0; attendanceRecord.ExtraMin = (short)mins.TotalMinutes; } if (attendanceRecord.GZOTMin > 0) { attendanceRecord.StatusGZOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[G-OT]"; } #endregion } //if Rest day then place all WorkMin in OTMin else if (attendanceRecord.StatusDO == true && attendanceRecord.DutyCode == "R") { #region -- Rest Calculation -- if (otPolicy.CalculateRestOT == true) { if ((_workHours >= otPolicy.PerDayROTStartLimitHour) && (_workHours <= otPolicy.PerDayROTEndLimitHour)) { if (mins.TotalMinutes < otPolicy.MinMinutesForOneHour) { attendanceRecord.ROTMin = 0; } else if (attendanceRecord.ROTMin >= otPolicy.MinMinutesForOneHour && attendanceRecord.ROTMin <= 61) { attendanceRecord.ROTMin = 60; } else { int hour = (int)(mins.TotalMinutes / 60); int min = hour * 60; int remainingmin = (int)mins.TotalMinutes - min; if (remainingmin >= otPolicy.MinMinutesForOneHour) { attendanceRecord.ROTMin = (short)((hour + 1) * 60); } else { attendanceRecord.ROTMin = (short)((hour) * 60); } } } else { if (_workHours < otPolicy.PerDayROTStartLimitHour) { attendanceRecord.ROTMin = 0; } else { int policyOTLimitMin = (int)(otPolicy.PerDayROTEndLimitHour * 60.0); attendanceRecord.ROTMin = (short)policyOTLimitMin; } } } else { attendanceRecord.WorkMin = 0; attendanceRecord.ExtraMin = (short)mins.TotalMinutes; } if (attendanceRecord.ROTMin > 0) { attendanceRecord.StatusROT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[R-OT]"; } #endregion } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; attendanceRecord.ExtraMin = 0; #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.Minutes > 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 #region -- Shift Things //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.SubtractLOFromWork == true) { if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > shift.LateOut) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.LateOut); } } // Deduct break if (attendanceRecord.DutyCode == "D") { //Normal if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null) { if (attendanceRecord.TimeIn < ts && attendanceRecord.TimeOut > te) { attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - attendanceRecord.BreakMin); } else { if (attendanceRecord.TotalShortMin > 0) { attendanceRecord.TotalShortMin = (short)(attendanceRecord.TotalShortMin + attendanceRecord.BreakMin); } } } } #endregion #region -- OT Calculation -- //if (otPolicy.CalculateNOT == true && attendanceRecord.LateOut > 0) // attendanceRecord.NOTMin = (short)attendanceRecord.LateOut; //else if (otPolicy.CalculateNOT == false) //{ // if (attendanceRecord.LateOut > 0) // attendanceRecord.ExtraMin = (short)(attendanceRecord.LateOut + attendanceRecord.ExtraMin); // if (attendanceRecord.EarlyIn > 0) // attendanceRecord.ExtraMin = (short)(attendanceRecord.EarlyIn + attendanceRecord.ExtraMin); //} short totalOTMins = 0; if (otPolicy.CalculateNOT == true) { if (otPolicy.AddEIinOT == true) { if (attendanceRecord.EarlyIn > 0) { totalOTMins = (short)attendanceRecord.EarlyIn; } if (attendanceRecord.LateOut > 0) { totalOTMins = (short)(attendanceRecord.LateOut + totalOTMins); } } else { totalOTMins = (short)attendanceRecord.LateOut; } } else { //attendanceRecord.WorkMin = (short)mins.TotalMinutes; } // Check OT with Work Minutes if (totalOTMins > 0) { //if (attendanceRecord.WorkMin < attendanceRecord.ShifMin) //{ // totalOTMins = (short)(totalOTMins - (short)(attendanceRecord.ShifMin - attendanceRecord.WorkMin)); //} float otHour = (float)(totalOTMins / 60.0); if (otHour < otPolicy.PerDayOTStartLimitHour) { attendanceRecord.NOTMin = 0; } else if (otHour >= otPolicy.PerDayOTStartLimitHour && otHour <= otPolicy.PerDayOTStartLimitHour) { if (otPolicy.MinMinutesForOneHour == 0) { attendanceRecord.NOTMin = (short)totalOTMins; } else { if (totalOTMins < otPolicy.MinMinutesForOneHour) { attendanceRecord.NOTMin = 0; } else if (totalOTMins >= otPolicy.MinMinutesForOneHour && totalOTMins <= 61) { attendanceRecord.NOTMin = 60; } else { if (totalOTMins > 0) { int hour = (int)(totalOTMins / 60); int min = hour * 60; int remainingmin = (int)totalOTMins - min; if (remainingmin >= otPolicy.MinMinutesForOneHour) { attendanceRecord.NOTMin = (short)((hour + 1) * 60); } else { attendanceRecord.NOTMin = (short)min; } } } } } else if (otHour >= otPolicy.PerDayOTEndLimitHour) { int policyOTLimitMin = (int)(otPolicy.PerDayOTEndLimitHour * 60.0); attendanceRecord.NOTMin = (short)policyOTLimitMin; } if (attendanceRecord.NOTMin > 0) { attendanceRecord.StatusOT = true; attendanceRecord.Remarks = attendanceRecord.Remarks + "[N-OT]"; } } else { } #endregion #region --- Half Absent and Short Time --- if (attendanceRecord.StatusHL == true) { attendanceRecord.TotalShortMin = 0; attendanceRecord.EarlyOut = 0; attendanceRecord.LateIn = 0; attendanceRecord.LateOut = 0; attendanceRecord.NOTMin = 0; attendanceRecord.ExtraMin = 0; attendanceRecord.TotalShortMin = 0; attendanceRecord.StatusLI = false; attendanceRecord.StatusEO = false; attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LI]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[EO]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[N-OT]", ""); attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[LO]", ""); attendanceRecord.PDays = 0.5; attendanceRecord.AbDays = 0; attendanceRecord.LeaveDays = 0.5; // update if lateout } else { attendanceRecord.PDays = 1; attendanceRecord.AbDays = 0; attendanceRecord.LeaveDays = 0; short totalshortMin = 0; if (attendanceRecord.LateIn > 0) { totalshortMin = (short)attendanceRecord.LateIn; } if (attendanceRecord.EarlyOut > 0) { totalshortMin = (short)(totalshortMin + attendanceRecord.EarlyOut); } attendanceRecord.TotalShortMin = totalshortMin; int marginForST = 10; if (shift.LateIn > 0) { marginForST = shift.LateIn; } if (attendanceRecord.WorkMin < (attendanceRecord.ShifMin - marginForST)) { attendanceRecord.TotalShortMin = (Int16)(attendanceRecord.TotalShortMin + (attendanceRecord.ShifMin - (attendanceRecord.WorkMin + totalshortMin))); } if (otPolicy.CalculateNOT == true) { if (attendanceRecord.NOTMin > 0) { //if (attendanceRecord.TotalShortMin > 0) // attendanceRecord.ApprovedOT = (short)(attendanceRecord.NOTMin - attendanceRecord.TotalShortMin); } } } #endregion #region -- Mark Absent -- //Mark Absent if less than 4 hours if (attendanceRecord.AttDate.Value.DayOfWeek != DayOfWeek.Friday && attendanceRecord.StatusDO != true && attendanceRecord.StatusGZ != true) { if (attendanceRecord.StatusHL != true) { short MinShiftMin = (short)shift.MinHrs; if (attendanceRecord.WorkMin < MinShiftMin) { attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Absent]", ""); attendanceRecord.StatusAB = true; attendanceRecord.StatusP = false; attendanceRecord.PDays = 0; attendanceRecord.AbDays = 1; attendanceRecord.LeaveDays = 0; attendanceRecord.Remarks = attendanceRecord.Remarks + "[Absent]"; } else { attendanceRecord.StatusAB = false; attendanceRecord.StatusP = true; 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; } attendanceRecord.Remarks = attendanceRecord.Remarks.Replace("[Absent]", ""); } } } #endregion //RoundOff Work Minutes if (shift.RoundOffWorkMin == true) { if (attendanceRecord.WorkMin >= (attendanceRecord.ShifMin - shift.LateIn) && (attendanceRecord.WorkMin <= ((attendanceRecord.ShifMin) + shift.LateIn))) { attendanceRecord.WorkMin = (short)(attendanceRecord.ShifMin); } if (attendanceRecord.WorkMin > 0 && attendanceRecord.StatusHL != true) { if (attendanceRecord.ShifMin <= attendanceRecord.WorkMin + attendanceRecord.TotalShortMin) { attendanceRecord.WorkMin = attendanceRecord.ShifMin; } } if (attendanceRecord.WorkMin > 0 && attendanceRecord.StatusHL == true) { attendanceRecord.WorkMin = (short)(attendanceRecord.ShifMin); } } } #region -- Break for GZ, Rest and Normal Day //GZ Break //if (attendanceRecord.DutyCode == "G") //{ // if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null) // { // if (attendanceRecord.TimeIn < ts && attendanceRecord.TimeOut > te) // { // if (attendanceRecord.GZOTMin > 0) // { // attendanceRecord.GZOTMin = (short)(attendanceRecord.GZOTMin - attendanceRecord.BreakMin); // } // if (attendanceRecord.ExtraMin > 0) // { // attendanceRecord.ExtraMin = (short)(attendanceRecord.ExtraMin - attendanceRecord.BreakMin); // } // } // } //} //Rest //else if (attendanceRecord.DutyCode == "R") //{ // if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null) // { // if (attendanceRecord.TimeIn < ts && attendanceRecord.TimeOut > te) // { // if (attendanceRecord.OTMin > 0) // { // attendanceRecord.OTMin = (short)(attendanceRecord.OTMin - attendanceRecord.BreakMin); // } // if (attendanceRecord.ExtraMin > 0) // { // attendanceRecord.ExtraMin = (short)(attendanceRecord.ExtraMin - attendanceRecord.BreakMin); // } // } // } //} #endregion } } catch (Exception ex) { } }