/// <summary>
 /// Create a new Roster object.
 /// </summary>
 /// <param name="empDate">Initial value of the EmpDate property.</param>
 /// <param name="empID">Initial value of the EmpID property.</param>
 /// <param name="rosterDate">Initial value of the RosterDate property.</param>
 /// <param name="dutyCode">Initial value of the DutyCode property.</param>
 /// <param name="dutyTime">Initial value of the DutyTime property.</param>
 /// <param name="workMin">Initial value of the WorkMin property.</param>
 public static Roster CreateRoster(global::System.String empDate, global::System.Int32 empID, global::System.DateTime rosterDate, global::System.String dutyCode, global::System.TimeSpan dutyTime, global::System.Int16 workMin)
 {
     Roster roster = new Roster();
     roster.EmpDate = empDate;
     roster.EmpID = empID;
     roster.RosterDate = rosterDate;
     roster.DutyCode = dutyCode;
     roster.DutyTime = dutyTime;
     roster.WorkMin = workMin;
     return roster;
 }
Ejemplo n.º 2
0
        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
                {
                    ////------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 - _shift.EarlyIn);
                    //}
                    //if (attendanceRecord.LateOut != null && attendanceRecord.LateOut > _shift.LateOut)
                    //{
                    //    attendanceRecord.WorkMin = (short)(attendanceRecord.WorkMin - _shift.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);
                    }
                    if ((attendanceRecord.WorkMin - attendanceRecord.ShifMin) > 0)
                    {
                        attendanceRecord.OTMin = (short)(attendanceRecord.ShifMin - attendanceRecord.WorkMin);
                    }

                    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);
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Rosters EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRosters(Roster roster)
 {
     base.AddObject("Rosters", roster);
 }