Exemplo n.º 1
0
        //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 CreateAttendance(DateTime dateTime, List <Emp> _emp)
        {
            using (var ctx = new TAS2013Entities())
            {
                List <Roster> _Roster = new List <Roster>();
                _Roster = ctx.Rosters.Where(aa => aa.RosterDate == dateTime).ToList();
                List <RosterDetail> _NewRoster = new List <RosterDetail>();
                _NewRoster = ctx.RosterDetails.Where(aa => aa.RosterDate == dateTime).ToList();
                List <LvData> _LvData = new List <LvData>();
                _LvData = ctx.LvDatas.Where(aa => aa.AttDate == dateTime).ToList();
                List <LvShort> _lvShort = new List <LvShort>();
                _lvShort = ctx.LvShorts.Where(aa => aa.DutyDate == dateTime).ToList();
                List <AttData> _AttData  = ctx.AttDatas.Where(aa => aa.AttDate == dateTime).ToList();
                List <Holiday> _Holidays = ctx.Holidays.ToList();
                foreach (var emp in _emp)
                {
                    string empDate = emp.EmpID + dateTime.ToString("yyMMdd");
                    if (_AttData.Where(aa => aa.EmpDate == empDate).Count() == 0)
                    {
                        try
                        {
                            /////////////////////////////////////////////////////
                            //  Mark Everyone Absent while creating Attendance //
                            /////////////////////////////////////////////////////
                            //Set DUTYCODE = D, StatusAB = true, and Remarks = [Absent]
                            AttData att = new AttData();
                            att.AttDate  = dateTime.Date;
                            att.DutyCode = "D";
                            att.StatusAB = true;
                            att.Remarks  = "[Absent]";
                            if (emp.Shift != null)
                            {
                                att.DutyTime = emp.Shift.StartTime;
                            }
                            else
                            {
                                att.DutyTime = new TimeSpan(07, 45, 00);
                            }
                            att.EmpID   = emp.EmpID;
                            att.EmpNo   = emp.EmpNo;
                            att.EmpDate = emp.EmpID + dateTime.ToString("yyMMdd");
                            att.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(emp.Shift, dateTime.DayOfWeek);
                            //////////////////////////
                            //  Check for Rest Day //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusDO = true, and Remarks=[DO]
                            //Check for 1st Day Off of Shift
                            if (emp.Shift.DaysName.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek))
                            {
                                att.DutyCode = "R";
                                att.StatusAB = false;
                                att.StatusDO = true;
                                att.Remarks  = "[DO]";
                            }
                            //Check for 2nd Day Off of shift
                            if (emp.Shift.DaysName1.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek))
                            {
                                att.DutyCode = "R";
                                att.StatusAB = false;
                                att.StatusDO = true;
                                att.Remarks  = "[DO]";
                            }

                            //////////////////////////
                            //  Check for GZ Day //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ]
                            if (emp.Shift.GZDays == true)
                            {
                                foreach (var holiday in _Holidays)
                                {
                                    if (_Holidays.Where(hol => hol.HolDate.Month == att.AttDate.Value.Month && hol.HolDate.Day == att.AttDate.Value.Day).Count() > 0)
                                    {
                                        att.DutyCode = "G";
                                        att.StatusAB = false;
                                        att.StatusGZ = true;
                                        att.Remarks  = "[GZ]";
                                        att.ShifMin  = 0;
                                    }
                                }
                            }

                            //////////////////////////
                            //  Check for Roster   //
                            ////////////////////////
                            //If Roster DutyCode is Rest then change the StatusAB and StatusDO
                            foreach (var roster in _Roster.Where(aa => aa.EmpDate == att.EmpDate))
                            {
                                att.DutyCode = roster.DutyCode.Trim();
                                if (att.DutyCode == "R")
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.DutyCode = "R";
                                    att.Remarks  = "[DO]";
                                }

                                att.ShifMin  = roster.WorkMin;
                                att.DutyTime = roster.DutyTime;
                            }

                            ////New Roster
                            string empCdate     = "Emp" + emp.EmpID.ToString() + dateTime.ToString("yyMMdd");
                            string sectionCdate = "Section" + emp.SecID.ToString() + dateTime.ToString("yyMMdd");
                            string crewCdate    = "Crew" + emp.CrewID.ToString() + dateTime.ToString("yyMMdd");
                            string shiftCdate   = "Shift" + emp.ShiftID.ToString() + dateTime.ToString("yyMMdd");
                            if (_NewRoster.Where(aa => aa.CriteriaValueDate == empCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == empCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == sectionCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == sectionCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == crewCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == crewCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == shiftCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == shiftCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            ////////////////////////////
                            //TODO Check for Job Card//
                            //////////////////////////



                            ////////////////////////////
                            //  Check for Short Leave//
                            //////////////////////////
                            foreach (var sLeave in _lvShort.Where(aa => aa.EmpDate == att.EmpDate))
                            {
                                if (_lvShort.Where(lv => lv.EmpDate == att.EmpDate).Count() > 0)
                                {
                                    att.StatusSL = true;
                                    att.StatusAB = null;
                                    att.DutyCode = "L";
                                    att.Remarks  = "[Short Leave]";
                                }
                            }

                            //////////////////////////
                            //   Check for Leave   //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ]
                            foreach (var Leave in _LvData)
                            {
                                var _Leave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave != true);
                                if (_Leave.Count() > 0)
                                {
                                    att.StatusLeave = true;
                                    att.StatusAB    = false;
                                    att.DutyCode    = "L";
                                    att.StatusDO    = false;
                                    if (Leave.LvCode == "A")
                                    {
                                        att.Remarks = "[Casual Leave]";
                                    }
                                    else if (Leave.LvCode == "B")
                                    {
                                        att.Remarks = "[Annual Leave]";
                                    }
                                    else if (Leave.LvCode == "C")
                                    {
                                        att.Remarks = "[Sick Leave]";
                                    }
                                    else
                                    {
                                        att.Remarks = "[Leave]";
                                    }
                                }
                                else
                                {
                                    att.StatusLeave = false;
                                }
                            }

                            /////////////////////////
                            //Check for Half Leave///
                            ////////////////////////
                            var _HalfLeave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave == true);
                            if (_HalfLeave.Count() > 0)
                            {
                                att.StatusLeave = true;
                                att.StatusAB    = false;
                                att.DutyCode    = "L";
                                att.StatusDO    = false;
                                att.StatusHL    = true;
                                if (_HalfLeave.FirstOrDefault().LvCode == "A")
                                {
                                    att.Remarks = "[H-CL]";
                                }
                                else if (_HalfLeave.FirstOrDefault().LvCode == "B")
                                {
                                    att.Remarks = "[S-AL]";
                                }
                                else if (_HalfLeave.FirstOrDefault().LvCode == "C")
                                {
                                    att.Remarks = "[H-SL]";
                                }
                                else
                                {
                                    att.Remarks = "[Half Leave]";
                                }
                            }
                            else
                            {
                                att.StatusLeave = false;
                                att.StatusHL    = false;
                            }
                            ctx.AttDatas.AddObject(att);
                            ctx.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            _myHelperClass.WriteToLogFile("Error In Creating Attendance of Employee: " + emp.EmpNo);
                        }
                    }
                }
            }
            _myHelperClass.WriteToLogFile("Creating Attendance of Date: " + dateTime.ToString());
        }
Exemplo n.º 3
0
        public void CreateAttendance(DateTime dateTime)
        {
            using (var ctx = new TAS2013Entities())
            {
                List <Emp> _emp = new List <Emp>();
                _emp = ctx.Emps.Where(aa => aa.Status == true).ToList();
                List <Roster> _Roster = new List <Roster>();
                _Roster = context.Rosters.Where(aa => aa.RosterDate == dateTime).ToList();
                List <RosterDetail> _NewRoster = new List <RosterDetail>();
                _NewRoster = context.RosterDetails.Where(aa => aa.RosterDate == dateTime).ToList();
                List <LvData> _LvData = new List <LvData>();
                _LvData = context.LvDatas.Where(aa => aa.AttDate == dateTime).ToList();
                List <LvShort> _lvShort = new List <LvShort>();
                _lvShort = context.LvShorts.Where(aa => aa.DutyDate == dateTime).ToList();
                List <AttData> _AttData = context.AttDatas.Where(aa => aa.AttDate == dateTime).ToList();
                _myHelperClass.WriteToLogFile("**********************Attendance Creating Started: Total Employees are:" + _emp.Count + "*********************");
                List <Remark> remarks = new List <Remark>();
                remarks = ctx.Remarks.ToList();
                foreach (var emp in _emp)
                {
                    string empDate = emp.EmpID + dateTime.ToString("yyMMdd");
                    if (_AttData.Where(aa => aa.EmpDate == empDate).Count() == 0)
                    {
                        try
                        {
                            /////////////////////////////////////////////////////
                            //  Mark Everyone Absent while creating Attendance //
                            /////////////////////////////////////////////////////
                            //Set DUTYCODE = D, StatusAB = true, and Remarks = [Absent]
                            AttData att = new AttData();
                            att.AttDate  = dateTime.Date;
                            att.DutyCode = "D";
                            att.StatusAB = true;
                            att.Remarks  = "[Absent]";
                            if (emp.Shift != null)
                            {
                                att.DutyTime = emp.Shift.StartTime;
                            }
                            else
                            {
                                att.DutyTime = new TimeSpan(07, 45, 00);
                            }
                            att.EmpID   = emp.EmpID;
                            att.EmpNo   = emp.EmpNo;
                            att.EmpDate = emp.EmpID + dateTime.ToString("yyMMdd");
                            att.ShifMin = ProcessSupportFunc.CalculateShiftMinutes(emp.Shift, dateTime.DayOfWeek);
                            //////////////////////////
                            //  Check for Rest Day //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusDO = true, and Remarks=[DO]
                            //Check for 1st Day Off of Shift
                            if (emp.Shift.DaysName.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek))
                            {
                                att.DutyCode = "R";
                                att.StatusAB = false;
                                att.StatusDO = true;
                                att.Remarks  = "[DO]";
                            }
                            //Check for 2nd Day Off of shift
                            if (emp.Shift.DaysName1.Name == ProcessSupportFunc.ReturnDayOfWeek(dateTime.DayOfWeek))
                            {
                                att.DutyCode = "R";
                                att.StatusAB = false;
                                att.StatusDO = true;
                                att.Remarks  = "[DO]";
                            }
                            //////////////////////////
                            //  Check for Roster   //
                            ////////////////////////
                            //If Roster DutyCode is Rest then change the StatusAB and StatusDO
                            foreach (var roster in _Roster.Where(aa => aa.EmpDate == att.EmpDate))
                            {
                                att.DutyCode = roster.DutyCode.Trim();
                                if (att.DutyCode == "R")
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.DutyCode = "R";
                                    att.Remarks  = "[DO]";
                                }
                                att.ShifMin  = roster.WorkMin;
                                att.DutyTime = roster.DutyTime;
                            }

                            ////New Roster
                            string empCdate     = "Emp" + emp.EmpID.ToString() + dateTime.ToString("yyMMdd");
                            string sectionCdate = "Section" + emp.SecID.ToString() + dateTime.ToString("yyMMdd");
                            string crewCdate    = "Crew" + emp.CrewID.ToString() + dateTime.ToString("yyMMdd");
                            string shiftCdate   = "Shift" + emp.ShiftID.ToString() + dateTime.ToString("yyMMdd");
                            if (_NewRoster.Where(aa => aa.CriteriaValueDate == empCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == empCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                    att.ShifMin  = 0;
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == sectionCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == sectionCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                    att.ShifMin  = 0;
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == crewCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == crewCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                    att.ShifMin  = 0;
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }
                            else if (_NewRoster.Where(aa => aa.CriteriaValueDate == shiftCdate).Count() > 0)
                            {
                                var roster = _NewRoster.FirstOrDefault(aa => aa.CriteriaValueDate == shiftCdate);
                                if (roster.WorkMin == 0)
                                {
                                    att.StatusAB = false;
                                    att.StatusDO = true;
                                    att.Remarks  = "[DO]";
                                    att.DutyCode = "R";
                                    att.ShifMin  = 0;
                                }
                                else
                                {
                                    att.ShifMin  = roster.WorkMin;
                                    att.DutyCode = "D";
                                    att.DutyTime = roster.DutyTime;
                                }
                            }

                            //////////////////////////
                            //  Check for GZ Day //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ]
                            if (emp.Shift.GZDays == true)
                            {
                                foreach (var holiday in context.Holidays)
                                {
                                    if (context.Holidays.Where(hol => hol.HolDate.Month == att.AttDate.Value.Month && hol.HolDate.Day == att.AttDate.Value.Day).Count() > 0)
                                    {
                                        att.DutyCode = "G";
                                        att.StatusAB = false;
                                        att.StatusGZ = true;
                                        att.Remarks  = "[GZ]";
                                        att.ShifMin  = 0;
                                    }
                                }
                            }
                            ////////////////////////////
                            //  Check for Short Leave//
                            //////////////////////////
                            foreach (var sLeave in _lvShort.Where(aa => aa.EmpDate == att.EmpDate))
                            {
                                if (_lvShort.Where(lv => lv.EmpDate == att.EmpDate).Count() > 0)
                                {
                                    att.StatusSL = true;
                                    att.StatusAB = null;
                                    att.DutyCode = "L";
                                    att.Remarks  = "[Short Leave]";
                                }
                            }

                            //////////////////////////
                            //   Check for Leave   //
                            ////////////////////////
                            //Set DutyCode = R, StatusAB=false, StatusGZ = true, and Remarks=[GZ]
                            foreach (var Leave in _LvData)
                            {
                                var _Leave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave != true);
                                if (_Leave.Count() > 0)
                                {
                                    att.StatusLeave = true;
                                    att.StatusAB    = false;
                                    att.DutyCode    = "L";
                                    att.StatusDO    = false;
                                    if (Leave.LvCode == "A")
                                    {
                                        att.Remarks = "[CL]";
                                    }
                                    else if (Leave.LvCode == "B")
                                    {
                                        att.Remarks = "[AL]";
                                    }
                                    else if (Leave.LvCode == "C")
                                    {
                                        att.Remarks = "[SL]";
                                    }
                                    else
                                    {
                                        att.Remarks = "[" + _Leave.FirstOrDefault().LvType.LvDesc + "]";
                                    }
                                }
                            }

                            /////////////////////////
                            //Check for Half Leave///
                            ////////////////////////
                            var _HalfLeave = _LvData.Where(lv => lv.EmpDate == att.EmpDate && lv.HalfLeave == true);
                            if (_HalfLeave.Count() > 0)
                            {
                                att.StatusLeave = true;
                                att.StatusAB    = false;
                                att.DutyCode    = "L";
                                att.StatusHL    = true;
                                att.StatusDO    = false;
                                if (_HalfLeave.FirstOrDefault().LvCode == "A")
                                {
                                    att.Remarks = "[H-CL]";
                                }
                                else if (_HalfLeave.FirstOrDefault().LvCode == "B")
                                {
                                    att.Remarks = "[S-AL]";
                                }
                                else if (_HalfLeave.FirstOrDefault().LvCode == "C")
                                {
                                    att.Remarks = "[H-SL]";
                                }
                                else
                                {
                                    att.Remarks = "[Half Leave]";
                                }
                            }
                            ctx.AttDatas.AddObject(att);
                            ctx.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            _myHelperClass.WriteToLogFile("-------Error In Creating Attendance of Employee: " + emp.EmpNo + " ------" + ex.InnerException.Message);
                        }
                    }
                }
                _myHelperClass.WriteToLogFile("****************Creating Attendance Completed*****************");
                AttProcess attp = new AttProcess();
                attp.ProcessDate = dateTime;
                ctx.AttProcesses.AddObject(attp);
                ctx.SaveChanges();
                ////////////////////////////
                //Check for Job Card//
                //////////////////////////
                try
                {
                    ProcessJobCard jc = new ProcessJobCard();
                    jc.ProcessJobCards(dateTime);
                }
                catch (Exception ex)
                {
                    _myHelperClass.WriteToLogFile("Error at Create Function Process Job Card " + dateTime.ToString());
                }
                ctx.Dispose();
            }
            // reprocess attendance from last 5 days
            CreateMissingAttendance ca = new CreateMissingAttendance();

            ca.CreatemissingAttendance(dateTime.AddDays(-7), dateTime);
            _myHelperClass.WriteToLogFile("Creating Attendance of Date: " + dateTime.ToString());
        }