Ejemplo n.º 1
0
 public void ProcessDailyAttendance()
 {
     DateTime _dt = GlobalSettings._dateTime;
     DateTime dtTo = new DateTime(2015, 9, 28);
     DateTime dtFrom = new DateTime(2015, 9, 28);
     List<PollData> unprocessedPolls = context.PollDatas.Where(p => (p.Process == false)).OrderBy(e => e.EntTime).ToList();
     //List<PollData> unprocessedPolls = context.PollDatas.Where(p => (p.EntDate >= dtTo && p.EntDate <= dtFrom) && p.EmpID == 401).OrderBy(e => e.EntTime).ToList();
     foreach (PollData up in unprocessedPolls)
     {
         try
         {
             //Create Attendance if any poll date is not processed already
             if (context.AttProcesses.Where(ap => ap.ProcessDate == up.EntDate).Count() == 0)
             {
                 CreateAttendance(up.EntDate.Date);
             }
             //Check AttData with EmpDate
             if (context.AttDatas.Where(attd => attd.EmpDate == up.EmpDate).Count() > 0)
             {
                 AttData attendanceRecord = context.AttDatas.First(attd => attd.EmpDate == up.EmpDate);
                 employee = attendanceRecord.Emp;
                 Shift shift = employee.Shift;
                 //Set Time In and Time Out in AttData
                 if (attendanceRecord.Emp.Shift.OpenShift == true)
                 {
                     //Set Time In and Time Out for open shift
                     CalculateTimeINOUTOpenShift(attendanceRecord, up);
                 }
                 else
                 {
                     //Set Time In and Time Out
                     CalculateTimeINOUT(attendanceRecord, up);
                 }
                 if (employee.Shift.OpenShift == true)
                 {
                     if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd)
                     {
                         DateTime dt = up.EntDate.Date.AddDays(-1);
                         CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                     }
                 }
                 //If TimeIn and TimeOut are not null, then calculate other Atributes
                 if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null)
                 {
                     if (context.Rosters.Where(r => r.EmpDate == up.EmpDate).Count() > 0)
                     {
                         CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift);
                     }
                     else
                     {
                         if (shift.OpenShift == true)
                         {
                             if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd)
                             {
                                 DateTime dt = up.EntDate.Date.AddDays(-1);
                                 CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                 CalculateOpenShiftTimes(attendanceRecord, shift);
                             }
                             else
                             {
                                 //Calculate open shifft time of the same date
                                 CalculateOpenShiftTimes(attendanceRecord, shift);
                             }
                         }
                         else
                         {
                             CalculateShiftTimes(attendanceRecord, shift);
                         }
                     }
                 }
                 up.Process = true;
             }
         }
         catch (Exception ex)
         {
             string _error = "";
             if (ex.InnerException.Message != null)
                 _error = ex.InnerException.Message;
             else
                 _error = ex.Message;
             _myHelperClass.WriteToLogFile("Attendance Processing Error Level 1 " + _error);
         }
         context.SaveChanges();
     }
     _myHelperClass.WriteToLogFile("Attendance Processing Completed");
     context.Dispose();
 }
Ejemplo n.º 2
0
        public void ManualProcessAttendance(DateTime date,List<Emp> emps, List<AttData> _AttDatas)
        {
            BootstrapAttendance(date, emps, _AttDatas);
            DateTime dateEnd = date.AddDays(1);
            List<PollData> unprocessedPolls = context.PollDatas.Where(p => (p.EntDate >= date && p.EntDate <=dateEnd)).OrderBy(e => e.EntTime).ToList();
            foreach (PollData up in unprocessedPolls)
            {
                try
                {
                    //Check AttData with EmpDate
                    if (_AttDatas.Where(attd => attd.EmpDate == up.EmpDate).Count() > 0)
                    {
                        AttData attendanceRecord = _AttDatas.First(attd => attd.EmpDate == up.EmpDate);
                        employee = attendanceRecord.Emp;
                        Shift shift = employee.Shift;
                        //Set Time In and Time Out in AttData
                        if (attendanceRecord.Emp.Shift.OpenShift == true)
                        {
                            //Set Time In and Time Out for open shift
                            CalculateTimeINOUTOpenShift(attendanceRecord, up);
                        }
                        else
                        {
                            TimeSpan checkTimeEnd = new TimeSpan();
                            DateTime TimeInCheck = new DateTime();
                            if (attendanceRecord.TimeIn == null)
                            {
                                TimeInCheck = attendanceRecord.AttDate.Value.Add(attendanceRecord.DutyTime.Value);
                            }
                            else
                                TimeInCheck = attendanceRecord.TimeIn.Value;
                            if (attendanceRecord.ShifMin == 0)
                                checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, 480, 0));
                            else
                                checkTimeEnd = TimeInCheck.TimeOfDay.Add(new TimeSpan(0, (int)attendanceRecord.ShifMin, 0));
                            if (checkTimeEnd.Days > 0)
                            {
                                //if Time out occur at next day
                                if (up.RdrDuty == 5)
                                {
                                    DateTime dt = new DateTime();
                                    dt = up.EntDate.Date.AddDays(-1);
                                    var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID);
                                    if (_attData != null)
                                    {

                                        if (_attData.TimeIn != null)
                                        {
                                            if ((up.EntTime - _attData.TimeIn.Value).Hours < 18)
                                            {
                                                attendanceRecord = _attData;
                                                up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd");
                                            }

                                        }
                                        else
                                        {
                                            attendanceRecord = _attData;
                                            up.EmpDate = up.EmpID.ToString() + dt.Date.ToString("yyMMdd");
                                        }

                                    }
                                }
                            }
                            //Set Time In and Time Out
                            //Set Time In and Time Out
                            if (up.RdrDuty == 5)
                            {
                                if (attendanceRecord.TimeIn != null)
                                {
                                    TimeSpan dt = (TimeSpan)(up.EntTime.TimeOfDay - attendanceRecord.TimeIn.Value.TimeOfDay);
                                    if (dt.Minutes < 0)
                                    {
                                        DateTime dt1 = new DateTime();
                                        dt1 = up.EntDate.Date.AddDays(-1);
                                        var _attData = context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt1 && aa.EmpID == up.EmpID);
                                        attendanceRecord = _attData;
                                        up.EmpDate = up.EmpID.ToString() + dt1.Date.ToString("yyMMdd");
                                        CalculateTimeINOUT(attendanceRecord, up);
                                    }
                                    else
                                        CalculateTimeINOUT(attendanceRecord, up);
                                }
                                else
                                    CalculateTimeINOUT(attendanceRecord, up);
                            }
                            else
                                CalculateTimeINOUT(attendanceRecord, up);
                        }
                        if (employee.Shift.OpenShift == true)
                        {
                            if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd)
                            {
                                DateTime dt = up.EntDate.Date.AddDays(-1);
                                CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                            }
                        }
                        //If TimeIn and TimeOut are not null, then calculate other Atributes
                        if (context.AttDatas.First(attd => attd.EmpDate == up.EmpDate).TimeIn != null && context.AttDatas.First(attd => attd.EmpDate == up.EmpDate).TimeOut != null)
                        {
                            if (context.Rosters.Where(r => r.EmpDate == up.EmpDate).Count() > 0)
                            {
                                CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift);
                            }
                            else
                            {
                                if (shift.OpenShift == true)
                                {
                                    if (up.EntTime.TimeOfDay < OpenShiftThresholdEnd)
                                    {
                                        DateTime dt = up.EntDate.Date.AddDays(-1);
                                        CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                        CalculateOpenShiftTimes(attendanceRecord, shift);
                                    }
                                    else
                                    {
                                        //Calculate open shifft time of the same date
                                        CalculateOpenShiftTimes(attendanceRecord, shift);
                                    }
                                }
                                else
                                {
                                    CalculateShiftTimes(attendanceRecord, shift);
                                }
                            }
                        }
                        up.Process = true;
                    }
                }
                catch (Exception ex)
                {
                    string _error = "";
                    if (ex.InnerException.Message != null)
                        _error = ex.InnerException.Message;
                    else
                        _error = ex.Message;
                    _myHelperClass.WriteToLogFile("Attendance Processing Error Level 1 " + _error);
                }
                context.SaveChanges();
            }
            _myHelperClass.WriteToLogFile("Attendance Processing Completed");
            context.Dispose();
        }
        public bool processContractualMonthlyAttSingle(DateTime startDate, DateTime endDate, Emp _Emp, List<AttData> _EmpAttData)
        {
            string EmpMonth = _Emp.EmpID + startDate.Date.Month.ToString();
            //Attendance data of employee for selected dates
            try
            {
                EmpAttData = _EmpAttData;
            }
            catch (Exception ex)
            {
                string _error = "";
                if (ex.InnerException.Message != null)
                    _error = ex.InnerException.Message;
                else
                    _error = ex.Message;
                _myHelperClass.WriteToLogFile("Exception at Contactual Monthly Process: " + _error);

                return false;
            }
            //Check for already processed data
            if (context.AttMnDatas.Where(aa => aa.EmpMonth == EmpMonth).Count() > 0)
            {
                AttMnData _TempAttMn = context.AttMnDatas.Where(aa => aa.EmpMonth == EmpMonth).FirstOrDefault();
                _attMonth = _TempAttMn;
                _attMonth.OT1 = 0;
                _attMonth.OT2 = 0;
                _attMonth.OT3 = 0;
                _attMonth.OT4 = 0;
                _attMonth.OT5 = 0;
                _attMonth.OT6 = 0;
                _attMonth.OT7 = 0;
                _attMonth.OT8 = 0;
                _attMonth.OT9 = 0;
                _attMonth.OT10 = 0;
                _attMonth.OT11 = 0;
                _attMonth.OT12 = 0;
                _attMonth.OT13 = 0;
                _attMonth.OT14 = 0;
                _attMonth.OT15 = 0;
                _attMonth.OT16 = 0;
                _attMonth.OT17 = 0;
                _attMonth.OT18 = 0;
                _attMonth.OT19 = 0;
                _attMonth.OT20 = 0;
                _attMonth.OT21 = 0;
                _attMonth.OT22 = 0;
                _attMonth.OT23 = 0;
                _attMonth.OT24 = 0;
                _attMonth.OT25 = 0;
                _attMonth.OT26 = 0;
                _attMonth.OT27 = 0;
                _attMonth.OT28 = 0;
                _attMonth.OT29 = 0;
                _attMonth.OT30 = 0;
                _attMonth.OT31 = 0;
                _attMonth.L1 = null;
                _attMonth.L2 = null;
                _attMonth.L3 = null;
                _attMonth.L4 = null;
                _attMonth.L5 = null;
                _attMonth.L6 = null;
                _attMonth.L7 = null;
                _attMonth.L8 = null;
                _attMonth.L9 = null;
                _attMonth.L10 = null;
                _attMonth.L11 = null;
                _attMonth.L12 = null;
                _attMonth.L13 = null;
                _attMonth.L14 = null;
                _attMonth.L15 = null;
                _attMonth.L16 = null;
                _attMonth.L17 = null;
                _attMonth.L18 = null;
                _attMonth.L19 = null;
                _attMonth.L20 = null;
                _attMonth.L21 = null;
                _attMonth.L22 = null;
                _attMonth.L23 = null;
                _attMonth.L24 = null;
                _attMonth.L25 = null;
                _attMonth.L26 = null;
                _attMonth.L27 = null;
                _attMonth.L28 = null;
                _attMonth.L29 = null;
                _attMonth.L30 = null;
                _attMonth.L31 = null;

            }

            TDays = Convert.ToByte((endDate - startDate).Days + 1);
            List<LvData> _lvData = context.LvDatas.Where(aa => aa.AttDate >= startDate && aa.AttDate <= endDate).ToList();
            CalculateMonthlyAttendanceSheet(EmpAttData, _lvData);
            _attMonth.Period = startDate.Date.Month.ToString() + startDate.Date.Year.ToString();
            _attMonth.EmpMonth = _Emp.EmpID + startDate.Date.Month.ToString();
            _attMonth.EmpNo = _Emp.EmpNo;
            _attMonth.EmpID = _Emp.EmpID;
            _attMonth.EmpName = _Emp.EmpName;
            try
            {
                if (context.AttMnDatas.Where(aa => aa.EmpMonth == EmpMonth).Count() == 0)
                {
                    context.AttMnDatas.AddObject(_attMonth);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                string _error = "";
                if (ex.InnerException.Message != null)
                    _error = ex.InnerException.Message;
                else
                    _error = ex.Message;
                _myHelperClass.WriteToLogFile("Exception at Contactual Monthly Process 2: " + _error);
                return false;
            }
            return true;
        }
 /// <summary>
 /// Create a new Emp object.
 /// </summary>
 /// <param name="empID">Initial value of the EmpID property.</param>
 /// <param name="empNo">Initial value of the EmpNo property.</param>
 /// <param name="empName">Initial value of the EmpName property.</param>
 /// <param name="processAtt">Initial value of the ProcessAtt property.</param>
 /// <param name="processIn">Initial value of the ProcessIn property.</param>
 public static Emp CreateEmp(global::System.Int32 empID, global::System.String empNo, global::System.String empName, global::System.Boolean processAtt, global::System.Boolean processIn)
 {
     Emp emp = new Emp();
     emp.EmpID = empID;
     emp.EmpNo = empNo;
     emp.EmpName = empName;
     emp.ProcessAtt = processAtt;
     emp.ProcessIn = processIn;
     return emp;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Emps EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmps(Emp emp)
 {
     base.AddObject("Emps", emp);
 }
        public bool processPermanentMonthlyAttSingle(DateTime startDate, DateTime endDate, Emp _Emp, List<AttData> _EmpAttData)
        {
            //Get Attendance data of employee according to selected month
            try
            {
                EmpAttData = _EmpAttData;
            }
            catch (Exception ex)
            {
                string _error = "";
                if (ex.InnerException.Message != null)
                    _error = ex.InnerException.Message;
                else
                    _error = ex.Message;
                _myHelperClass.WriteToLogFile("Exception at Contactual Monthly Process: " + _error);
                return false;
            }
            string EmpMonth = _Emp.EmpID + endDate.Date.Month.ToString();
            //Check for already processed data
            if (context.AttMnDataPers.Where(aa => aa.EmpMonth == EmpMonth).Count() > 0)
            {
                AttMnDataPer _TempAttMn = context.AttMnDataPers.Where(aa => aa.EmpMonth == EmpMonth).FirstOrDefault();
                _attMonth = _TempAttMn;
                _attMonth.OT1 = 0;
                _attMonth.OT2 = 0;
                _attMonth.OT3 = 0;
                _attMonth.OT4 = 0;
                _attMonth.OT5 = 0;
                _attMonth.OT6 = 0;
                _attMonth.OT7 = 0;
                _attMonth.OT8 = 0;
                _attMonth.OT9 = 0;
                _attMonth.OT10 = 0;
                _attMonth.OT11 = 0;
                _attMonth.OT12 = 0;
                _attMonth.OT13 = 0;
                _attMonth.OT14 = 0;
                _attMonth.OT15 = 0;
                _attMonth.OT16 = 0;
                _attMonth.OT17 = 0;
                _attMonth.OT18 = 0;
                _attMonth.OT19 = 0;
                _attMonth.OT20 = 0;
                _attMonth.OT21 = 0;
                _attMonth.OT22 = 0;
                _attMonth.OT23 = 0;
                _attMonth.OT24 = 0;
                _attMonth.OT25 = 0;
                _attMonth.OT26 = 0;
                _attMonth.OT27 = 0;
                _attMonth.OT28 = 0;
                _attMonth.OT29 = 0;
                _attMonth.OT30 = 0;
                _attMonth.OT31 = 0;
            }

            TDays = Convert.ToByte((endDate - startDate).Days + 1);
            CalculateMonthlyAttendanceSheet(EmpAttData);
            _attMonth.Period = endDate.Date.Month.ToString() + endDate.Date.Year.ToString();
            _attMonth.EmpMonth = EmpMonth;
            _attMonth.EmpID = _Emp.EmpID;
            _attMonth.EmpNo = _Emp.EmpNo;
            _attMonth.EmpName = _Emp.EmpName;
            try
            {
                if (context.AttMnDataPers.Where(aa => aa.EmpMonth == EmpMonth).Count() == 0)
                {
                    context.AttMnDataPers.AddObject(_attMonth);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                string _error = "";
                if (ex.InnerException.Message != null)
                    _error = ex.InnerException.Message;
                else
                    _error = ex.Message;
                _myHelperClass.WriteToLogFile("Exception at Contactual Monthly Process: " + _error);
                return false;
            }
            return true;
        }