Example #1
0
 public void SaveManualRequest(int empid, DateTime dts, DateTime dte)
 {
     try
     {
         if ((DateTime.Today.Day >= 1 && DateTime.Today.Day <= 4) || (DateTime.Today.Day > 25))
         {
             using (var db = new TAS2013Entities())
             {
                 int          DaysInPreviousMonth = System.DateTime.DaysInMonth(dts.Year, dts.Month);
                 DateTime     dt  = new DateTime(dts.Year, dts.Month, DaysInPreviousMonth);
                 AttProSystem aps = new AttProSystem();
                 aps.EmpID       = empid;
                 aps.StartDate   = dts;
                 aps.EndDate     = dt;
                 aps.CreatedDate = DateTime.Now;
                 aps.Status      = false;
                 db.AttProSystems.Add(aps);
                 db.SaveChanges();
                 db.Dispose();
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #2
0
        private bool AddBadliAttData(string _empDate, int _empID, DateTime _Date, int _userID, JobCardApp jcApp)
        {
            bool check = false;

            try
            {
                //Normal Duty
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    JobCard _jcCard  = context.JobCards.FirstOrDefault(aa => aa.WorkCardID == jcApp.CardType);
                    if (_attdata != null)
                    {
                        _attdata.DutyCode    = "D";
                        _attdata.StatusAB    = false;
                        _attdata.StatusLeave = false;
                        _attdata.StatusP     = true;
                        _attdata.Remarks     = _attdata.Remarks + "[Badli][Manual]";
                        _attdata.StatusMN    = true;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
Example #3
0
 public void BalanceLeaves(LvApplication lvappl, LvType LeaveType)
 {
     if (LeaveType.UpdateBalance == true)
     {
         using (var ctx = new TAS2013Entities())
         {
             List <LvConsumed> _lvConsumed = new List <LvConsumed>();
             string            empLvType   = lvappl.EmpID.ToString() + lvappl.LeaveTypeID + lvappl.FromDate.Year.ToString("0000");
             _lvConsumed = ctx.LvConsumeds.Where(aa => aa.EmpLvTypeYear == empLvType).ToList();
             float _NoOfDays = lvappl.NoOfDays;
             if (_lvConsumed.Count > 0)
             {
                 _lvConsumed.FirstOrDefault().YearRemaining       = (float)(_lvConsumed.FirstOrDefault().YearRemaining - _NoOfDays);
                 _lvConsumed.FirstOrDefault().GrandTotalRemaining = (float)(_lvConsumed.FirstOrDefault().GrandTotalRemaining - _NoOfDays);
                 if (lvappl.IsHalf == true)
                 {
                     AddHalfLeaveBalancceMonthQuota(_lvConsumed, lvappl);
                 }
                 else
                 {
                     AddBalancceMonthQuota(_lvConsumed, lvappl);
                 }
                 ctx.SaveChanges();
             }
             ctx.Dispose();
         }
     }
 }
Example #4
0
        private void AdjustPollData()
        {
            int      currentYear = DateTime.Today.Date.Year;
            int      StartYear   = currentYear - 3;
            DateTime endDate     = DateTime.Today.AddDays(2);
            DateTime startDate   = new DateTime(StartYear, 1, 1);

            using (var ctx = new TAS2013Entities())
            {
                List <PollData> polls = ctx.PollDatas.Where(aa => aa.EntDate <= startDate && aa.Process == false).ToList();
                foreach (var item in polls)
                {
                    item.Process = true;
                }
                ctx.SaveChanges();
                polls.Clear();
                polls = ctx.PollDatas.Where(aa => aa.EntDate >= endDate && aa.Process == false).ToList();
                foreach (var item in polls)
                {
                    item.Process = true;
                }
                ctx.SaveChanges();
                ctx.Dispose();
            }
        }
Example #5
0
        private bool AddLateInMarginAttData(string _empDate, int _empID, DateTime _Date, int _userID, short _WorkCardID, short _CompID)
        {
            bool check = false;

            try
            {
                //Late In Job Card
                short LateInMins = 0;
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    if (_attdata != null)
                    {
                        _attdata.StatusAB = false;
                        _attdata.Remarks.Replace("[LI]", "");
                        _attdata.Remarks  = _attdata.Remarks + "[LI Job Card]";
                        _attdata.LateIn   = 0;
                        _attdata.WorkMin  = (short)(_attdata.WorkMin + (short)LateInMins);
                        _attdata.StatusLI = false;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
Example #6
0
        public string CheckForUserRole(User user)
        {
            string val = "";

            using (var ctx = new TAS2013Entities())
            {
                string criteria = ctx.UserAccesses.Where(aa => aa.UserID == user.UserID).FirstOrDefault().Criteria;
                switch (criteria.Trim())
                {
                case "Z":
                    val = "Zone";
                    break;

                case "R":
                    val = "Region";
                    break;

                case "C":
                    val = "City";
                    break;

                case "L":
                    val = "Location";
                    break;

                case "S":
                    val = "SuperUser";
                    break;
                }
                ctx.Dispose();
            }
            return(val);
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Example #8
0
        private bool AddJCToAttData(string _empDate, int _empID, DateTime _Date, string dutyCode, bool statusAB, bool statusDO,
                                    bool statusLeave, bool statusGZ, bool statusP, string Remarks)
        {
            bool check = false;

            try
            {
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    if (_attdata != null)
                    {
                        if (statusAB == true)
                        {
                            _attdata.PDays     = 0;
                            _attdata.LeaveDays = 0;
                            _attdata.ABDays    = 1;
                        }
                        if (statusP == true)
                        {
                            _attdata.PDays     = 1;
                            _attdata.LeaveDays = 0;
                            _attdata.ABDays    = 0;
                        }
                        _attdata.DutyCode    = dutyCode;
                        _attdata.StatusAB    = statusAB;
                        _attdata.StatusDO    = statusDO;
                        _attdata.StatusLeave = statusLeave;
                        _attdata.StatusGZ    = statusGZ;
                        _attdata.StatusP     = statusP;
                        if (_attdata.StatusAB != true)
                        {
                            _attdata.WorkMin = _attdata.ShifMin;
                        }
                        else
                        {
                            _attdata.WorkMin = 0;
                        }
                        if (_attdata.StatusDO == true)
                        {
                            _attdata.WorkMin = 0;
                        }
                        _attdata.Remarks = Remarks;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
Example #9
0
        private bool ValidateJobCard(DateTime dateStart, short CardType)
        {
            bool check = false;

            using (var ctx = new TAS2013Entities())
            {
                List <JobCardApp> jcApp = new List <JobCardApp>();
                if (ctx.JobCardApps.Where(aa => aa.DateStarted == dateStart && aa.CardType == CardType).Count() > 0)
                {
                    check = true;
                }
                ctx.Dispose();
            }
            return(check);
        }
Example #10
0
        private bool AddJCNorrmalDayAttData(string _empDate, short _WorkCardID)
        {
            bool check = false;

            try
            {
                //Normal Duty
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    JobCard _jcCard  = context.JobCards.FirstOrDefault(aa => aa.WorkCardID == _WorkCardID);
                    if (_attdata != null)
                    {
                        _attdata.DutyCode    = "D";
                        _attdata.StatusAB    = false;
                        _attdata.StatusDO    = false;
                        _attdata.StatusLeave = false;
                        _attdata.StatusP     = true;
                        _attdata.WorkMin     = _jcCard.WorkMin;
                        _attdata.ShifMin     = _jcCard.WorkMin;
                        _attdata.Remarks     = "[Present][Manual]";
                        _attdata.TimeIn      = null;
                        _attdata.TimeOut     = null;
                        _attdata.EarlyIn     = null;
                        _attdata.EarlyOut    = null;
                        _attdata.LateIn      = null;
                        _attdata.LateOut     = null;
                        _attdata.OTMin       = null;
                        _attdata.StatusEI    = null;
                        _attdata.StatusEO    = null;
                        _attdata.StatusLI    = null;
                        _attdata.StatusLO    = null;
                        _attdata.StatusP     = true;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
Example #11
0
        private bool AddJCODDayToAttData(string _empDate, int _empID, DateTime _Date, int _userID, short _WorkCardID, short _CompID)
        {
            bool check = false;

            try
            {
                //Official Duty
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    if (_attdata != null)
                    {
                        _attdata.DutyCode    = "O";
                        _attdata.StatusAB    = false;
                        _attdata.StatusDO    = false;
                        _attdata.StatusLeave = false;
                        _attdata.StatusP     = true;
                        _attdata.WorkMin     = _attdata.ShifMin;
                        _attdata.Remarks     = "[Official Duty][Manual]";
                        _attdata.TimeIn      = null;
                        _attdata.TimeOut     = null;
                        _attdata.WorkMin     = null;
                        _attdata.EarlyIn     = null;
                        _attdata.EarlyOut    = null;
                        _attdata.LateIn      = null;
                        _attdata.LateOut     = null;
                        _attdata.OTMin       = null;
                        _attdata.StatusEI    = null;
                        _attdata.StatusEO    = null;
                        _attdata.StatusLI    = null;
                        _attdata.StatusLO    = null;
                        _attdata.StatusP     = null;
                        _attdata.StatusGZ    = false;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
        private bool AddDoubleDutyAttData(string _empDate, int _empID, DateTime _Date, short WorkMins)
        {
            bool check = false;

            try
            {
                //Normal Duty
                using (var context = new TAS2013Entities())
                {
                    AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == _empDate);
                    if (_attdata != null)
                    {
                        _attdata.DutyCode    = "D";
                        _attdata.StatusAB    = false;
                        _attdata.StatusDO    = false;
                        _attdata.StatusLeave = false;
                        _attdata.StatusP     = true;
                        _attdata.WorkMin     = WorkMins;
                        _attdata.Remarks     = _attdata.Remarks + "[DD][Manual]";
                        _attdata.StatusMN    = true;
                        _attdata.TimeIn      = null;
                        _attdata.TimeOut     = null;
                        _attdata.EarlyIn     = null;
                        _attdata.EarlyOut    = null;
                        _attdata.LateIn      = null;
                        _attdata.LateOut     = null;
                        _attdata.OTMin       = null;
                        _attdata.StatusEI    = null;
                        _attdata.StatusEO    = null;
                        _attdata.StatusLI    = null;
                        _attdata.StatusLO    = null;
                        _attdata.StatusP     = true;
                    }
                    context.SaveChanges();
                    if (context.SaveChanges() > 0)
                    {
                        check = true;
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
            return(check);
        }
 private void SetGlobalVaribale()
 {
     using (var db = new TAS2013Entities())
     {
         GlobalVaribales.ServerPath = db.Options.FirstOrDefault().ServerFilePath;
         if (db.LicenseInfoes.Count() > 0)
         {
             LicenseInfo li = new LicenseInfo();
             li = db.LicenseInfoes.FirstOrDefault();
             GlobalVaribales.NoOfDevices = StringCipher.Decrypt(li.NoOfDevices, "1234");
             GlobalVaribales.NoOfEmps    = StringCipher.Decrypt(li.NoOfEmps, "1234");
             GlobalVaribales.NoOfUsers   = StringCipher.Decrypt(li.NoOfUsers, "1234");
             GlobalVaribales.DeviceType  = StringCipher.Decrypt(li.DeviceType, "1234");
             GlobalVaribales.LicenseType = StringCipher.Decrypt(li.LicenseType, "1234");
         }
         db.Dispose();
     }
 }
Example #14
0
        public void UpdateHLeaveBalance(LvApplication lvappl)
        {
            float             LvDays      = (float)lvappl.NoOfDays;
            List <LvConsumed> _lvConsumed = new List <LvConsumed>();

            using (var ctx = new TAS2013Entities())
            {
                string empLvType = lvappl.EmpID.ToString() + lvappl.LeaveTypeID + lvappl.FromDate.Year.ToString("0000");
                _lvConsumed = ctx.LvConsumeds.Where(aa => aa.EmpLvTypeYear == empLvType).ToList();
                if (_lvConsumed.Count > 0)
                {
                    _lvConsumed.FirstOrDefault().YearRemaining       = (float)(_lvConsumed.FirstOrDefault().YearRemaining + LvDays);
                    _lvConsumed.FirstOrDefault().GrandTotalRemaining = (float)(_lvConsumed.FirstOrDefault().GrandTotalRemaining + LvDays);
                    SubtractHalfLeavesBalancceMonthQuota(_lvConsumed, lvappl);
                    ctx.SaveChanges();
                }
                ctx.Dispose();
            }
        }
Example #15
0
        //Add Job Card To Job Card Data
        private void AddJobCardAppToJobCardData()
        {
            using (var ctx = new TAS2013Entities())
            {
                List <JobCardApp> _jobCardApp = new List <JobCardApp>();
                _jobCardApp = ctx.JobCardApps.Where(aa => aa.Status == false).ToList();
                User       LoggedInUser = Session["LoggedUser"] as User;
                List <Emp> _Emp         = new List <Emp>();
                foreach (var jcApp in _jobCardApp)
                {
                    jcApp.Status = true;
                    switch (jcApp.JobCardCriteria)
                    {
                    case "S":
                        short _shiftID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.ShiftID == _shiftID && aa.CompanyID == LoggedInUser.CompanyID).ToList();
                        break;

                    case "C":
                        short _crewID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.CrewID == _crewID && aa.CompanyID == LoggedInUser.CompanyID).ToList();
                        break;

                    case "T":
                        short _secID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.SecID == _secID && aa.CompanyID == LoggedInUser.CompanyID).ToList();
                        break;

                    case "E":
                        int _EmpID = (int)jcApp.CriteriaData;
                        _Emp = ctx.Emps.Where(aa => aa.EmpID == _EmpID).ToList();
                        break;
                    }
                    foreach (var selectedEmp in _Emp)
                    {
                        AddJobCardData(selectedEmp, (short)jcApp.CardType, jcApp.DateStarted.Value, jcApp.DateEnded.Value);
                    }
                }
                ctx.SaveChanges();
                ctx.Dispose();
            }
        }
        //Work Times calculation controller
        public void ProcessDailyAttendance(AttData _attData)
        {
            try
            {
                AttData attendanceRecord = _attData;
                Emp     employee         = attendanceRecord.Emp;
                Shift   shift            = employee.Shift;
                //If TimeIn and TimeOut are not null, then calculate other Atributes
                if (attendanceRecord.TimeIn != null && attendanceRecord.TimeOut != null)
                {
                    //If TimeIn = TimeOut then calculate according to DutyCode
                    if (attendanceRecord.TimeIn == attendanceRecord.TimeOut)
                    {
                        CalculateInEqualToOut(attendanceRecord);
                    }
                    else
                    {
                        if (attendanceRecord.DutyTime == new TimeSpan(0, 0, 0))
                        {
                            CalculateOpenShiftTimes(attendanceRecord, shift);
                        }
                        else
                        {
                            //if (attendanceRecord.TimeIn.Value.Date.Day == attendanceRecord.TimeOut.Value.Date.Day)
                            //{
                            CalculateShiftTimes(attendanceRecord, shift);
                            //}
                            //else
                            //{
                            //    CalculateOpenShiftTimes(attendanceRecord, shift);
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            context.SaveChanges();
            context.Dispose();
        }
Example #17
0
        //Add Job Card To Job Card Data
        private void AddJobCardAppToJobCardData()
        {
            using (var ctx = new TAS2013Entities())
            {
                List <JobCardApp> _jobCardApp = new List <JobCardApp>();
                _jobCardApp = ctx.JobCardApps.Where(aa => aa.Status == false).ToList();
                List <Emp> _Emp = new List <Emp>();
                foreach (var jcApp in _jobCardApp)
                {
                    jcApp.Status = true;
                    switch (jcApp.JobCardCriteria)
                    {
                    case "S":
                        short _shiftID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.ShiftID == _shiftID).ToList();
                        break;

                    case "C":
                        short _crewID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.CrewID == _crewID).ToList();
                        break;

                    case "T":
                        short _secID = Convert.ToByte(jcApp.CriteriaData);
                        _Emp = ctx.Emps.Where(aa => aa.SecID == _secID).ToList();
                        break;

                    case "E":
                        int _EmpID = (int)jcApp.CriteriaData;
                        _Emp = ctx.Emps.Where(aa => aa.EmpID == _EmpID).ToList();
                        break;
                    }
                    foreach (var selectedEmp in _Emp)
                    {
                        AddJobCardData(selectedEmp, jcApp);
                    }
                }
                ctx.SaveChanges();
                ctx.Dispose();
            }
        }
Example #18
0
        private void CorrectAttEntriesWithWrongFlags(DateTime startdate, DateTime endDate)
        {
            using (var ctx = new TAS2013Entities())
            {
                // where StatusGZ ==1 and DutyCode != G
                List <AttData> _attDataForGZ = ctx.AttDatas.Where(aa => aa.AttDate >= startdate && aa.AttDate <= endDate && aa.StatusGZ == true && aa.DutyCode != "G").ToList();
                foreach (var item in _attDataForGZ)
                {
                    item.DutyCode = "G";
                }
                ctx.SaveChanges();

                // where StatusDO ==1 and DutyCode != R
                List <AttData> _attDataForDO = ctx.AttDatas.Where(aa => aa.AttDate >= startdate && aa.AttDate <= endDate && aa.StatusDO == true && aa.DutyCode != "R").ToList();
                foreach (var item in _attDataForGZ)
                {
                    item.DutyCode = "R";
                }
                ctx.SaveChanges();
                ctx.Dispose();
            }
        }
Example #19
0
        public void ManualProcessAttendance(DateTime date, List <Emp> emps)
        {
            BootstrapAttendance(date, emps);
            DateTime        dateEnd          = date.AddDays(1);
            List <AttData>  attData          = context.AttDatas.Where(aa => aa.AttDate >= date && aa.AttDate <= dateEnd).ToList();
            List <PollData> unprocessedPolls = context.PollDatas.Where(p => (p.EntDate >= date && p.EntDate <= dateEnd)).OrderBy(e => e.EntTime).ToList();

            foreach (var emp in emps)
            {
                List <PollData> polls = new List <PollData>();
                polls = unprocessedPolls.Where(p => p.EmpID == emp.EmpID).OrderBy(e => e.EntTime).ToList();
                foreach (PollData up in polls)
                {
                    try
                    {
                        //Check AttData with EmpDate
                        if (attData.Where(attd => attd.EmpDate == up.EmpDate).Count() > 0)
                        {
                            AttData attendanceRecord = attData.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
                                PlaceTimeInOuts.CalculateTimeINOUTOpenShift(attendanceRecord, up);
                                context.SaveChanges();
                            }
                            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)
                                            {
                                                TimeSpan t1 = new TimeSpan(11, 00, 00);
                                                if (up.EntTime.TimeOfDay < t1)
                                                {
                                                    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");
                                            PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                        }
                                        else
                                        {
                                            PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                        }
                                    }
                                    else
                                    {
                                        PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                    }
                                }
                                else
                                {
                                    PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                }
                            }
                            if (employee.Shift.OpenShift == true)
                            {
                                if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd)
                                {
                                    DateTime dt = up.EntDate.Date.AddDays(-1);
                                    using (var ctxx = new TAS2013Entities())
                                    {
                                        CalculateWorkMins.CalculateOpenShiftTimes(ctxx.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                        ctxx.SaveChanges();
                                        ctxx.Dispose();
                                    }
                                }
                            }
                            //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)
                                {
                                    CalculateWorkMins.CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift);
                                    context.SaveChanges();
                                }
                                else
                                {
                                    if (shift.OpenShift == true)
                                    {
                                        if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd)
                                        {
                                            DateTime dt = up.EntDate.Date.AddDays(-1);
                                            using (var ctx2 = new TAS2013Entities())
                                            {
                                                CalculateWorkMins.CalculateOpenShiftTimes(ctx2.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                                ctx2.SaveChanges();
                                                ctx2.Dispose();
                                            }
                                            CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift);
                                            context.SaveChanges();
                                        }
                                        else
                                        {
                                            //Calculate open shifft time of the same date
                                            CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift);
                                            context.SaveChanges();
                                        }
                                    }
                                    else
                                    {
                                        CalculateWorkMins.CalculateShiftTimes(attendanceRecord, shift);
                                        context.SaveChanges();
                                    }
                                }
                            }
                            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();
        }
Example #20
0
        public void ProcessManualEditAttendance(DateTime _dateStart, DateTime _dateEnd)
        {
            List <AttDataManEdit> _attEdit = new List <AttDataManEdit>();
            List <AttData>        _AttData = new List <AttData>();
            AttData _TempAttData           = new AttData();

            using (var ctx = new TAS2013Entities())
            {
                if (_dateStart == _dateEnd)
                {
                    _attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn == _dateStart).OrderBy(aa => aa.EditDateTime).ToList();
                    _dateEnd = _dateEnd + new TimeSpan(23, 59, 59);
                    //_attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && aa.NewTimeIn <= _dateEnd && (aa.EmpID == 472)).OrderBy(aa => aa.EditDateTime).ToList();
                    _AttData = ctx.AttDatas.Where(aa => aa.AttDate == _dateStart).ToList();
                }
                else
                {
                    _attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && aa.NewTimeOut <= _dateEnd).OrderBy(aa => aa.EditDateTime).ToList();
                    //_attEdit = ctx.AttDataManEdits.Where(aa => aa.NewTimeIn >= _dateStart && (aa.NewTimeOut <= _dateEnd && aa.EmpID == 472)).OrderBy(aa => aa.EditDateTime).ToList();
                    _AttData = ctx.AttDatas.Where(aa => aa.AttDate >= _dateStart && aa.AttDate <= _dateEnd).ToList();
                }


                foreach (var item in _attEdit)
                {
                    _TempAttData          = _AttData.First(aa => aa.EmpDate == item.EmpDate);
                    _TempAttData.TimeIn   = item.NewTimeIn;
                    _TempAttData.TimeOut  = item.NewTimeOut;
                    _TempAttData.DutyCode = item.NewDutyCode;
                    _TempAttData.DutyTime = item.NewDutyTime;
                    switch (_TempAttData.DutyCode)
                    {
                    case "D":
                        _TempAttData.StatusAB    = true;
                        _TempAttData.StatusP     = false;
                        _TempAttData.StatusMN    = true;
                        _TempAttData.StatusDO    = false;
                        _TempAttData.StatusGZ    = false;
                        _TempAttData.StatusLeave = false;
                        _TempAttData.StatusOT    = false;
                        _TempAttData.OTMin       = null;
                        _TempAttData.EarlyIn     = null;
                        _TempAttData.EarlyOut    = null;
                        _TempAttData.LateIn      = null;
                        _TempAttData.LateOut     = null;
                        _TempAttData.WorkMin     = null;
                        _TempAttData.GZOTMin     = null;
                        break;

                    case "G":
                        _TempAttData.StatusAB    = false;
                        _TempAttData.StatusP     = false;
                        _TempAttData.StatusMN    = true;
                        _TempAttData.StatusDO    = false;
                        _TempAttData.StatusGZ    = true;
                        _TempAttData.StatusLeave = false;
                        _TempAttData.StatusOT    = false;
                        _TempAttData.OTMin       = null;
                        _TempAttData.EarlyIn     = null;
                        _TempAttData.EarlyOut    = null;
                        _TempAttData.LateIn      = null;
                        _TempAttData.LateOut     = null;
                        _TempAttData.WorkMin     = null;
                        _TempAttData.GZOTMin     = null;
                        break;

                    case "R":
                        _TempAttData.StatusAB    = false;
                        _TempAttData.StatusP     = false;
                        _TempAttData.StatusMN    = true;
                        _TempAttData.StatusDO    = true;
                        _TempAttData.StatusGZ    = false;
                        _TempAttData.StatusLeave = false;
                        _TempAttData.StatusOT    = false;
                        _TempAttData.OTMin       = null;
                        _TempAttData.EarlyIn     = null;
                        _TempAttData.EarlyOut    = null;
                        _TempAttData.LateIn      = null;
                        _TempAttData.LateOut     = null;
                        _TempAttData.WorkMin     = null;
                        _TempAttData.GZOTMin     = null;
                        break;
                    }
                    if (_TempAttData.TimeIn != null && _TempAttData.TimeOut != null)
                    {
                        //If TimeIn = TimeOut then calculate according to DutyCode
                        if (_TempAttData.TimeIn == _TempAttData.TimeOut)
                        {
                            CalculateInEqualToOut(_TempAttData);
                        }
                        else
                        {
                            if (_TempAttData.DutyTime == new TimeSpan(0, 0, 0))
                            {
                                CalculateOpenShiftTimes(_TempAttData, _TempAttData.Emp.Shift);
                            }
                            else
                            {
                                //if (attendanceRecord.TimeIn.Value.Date.Day == attendanceRecord.TimeOut.Value.Date.Day)
                                //{
                                CalculateShiftTimes(_TempAttData, _TempAttData.Emp.Shift);
                                //}
                                //else
                                //{
                                //    CalculateOpenShiftTimes(attendanceRecord, shift);
                                //}
                            }
                        }

                        //If TimeIn = TimeOut then calculate according to DutyCode
                    }
                    ctx.SaveChanges();
                }
                ctx.Dispose();
            }
            _myHelperClass.WriteToLogFile("ProcessManual Attendance Completed: ");
        }
Example #21
0
        public void BootstrapAttendance(DateTime dateTime, List <Emp> emps)
        {
            using (var ctx = new TAS2013Entities())
            {
                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();
                List <AttData> _attData = new List <AttData>();
                _attData = ctx.AttDatas.Where(aa => aa.AttDate == dateTime).ToList();
                foreach (var emp in emps)
                {
                    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 = _attData.First(aa => aa.EmpDate == empDate);
                            //Reset Flags
                            att.TimeIn      = null;
                            att.TimeOut     = null;
                            att.Tin0        = null;
                            att.Tout0       = null;
                            att.Tin1        = null;
                            att.Tout1       = null;
                            att.Tin2        = null;
                            att.Tout2       = null;
                            att.Tin3        = null;
                            att.Tout3       = null;
                            att.Tin4        = null;
                            att.Tout4       = null;
                            att.Tin5        = null;
                            att.Tout5       = null;
                            att.Tin6        = null;
                            att.Tout6       = null;
                            att.Tin7        = null;
                            att.Tout7       = null;
                            att.Tin8        = null;
                            att.Tout8       = null;
                            att.StatusP     = null;
                            att.StatusDO    = null;
                            att.StatusEO    = null;
                            att.StatusGZ    = null;
                            att.StatusGZOT  = null;
                            att.StatusHD    = null;
                            att.StatusHL    = null;
                            att.StatusIN    = null;
                            att.StatusLeave = null;
                            att.StatusLI    = null;
                            att.StatusLO    = null;
                            att.StatusMN    = null;
                            att.StatusOD    = null;
                            att.StatusOT    = null;
                            att.StatusSL    = null;
                            att.WorkMin     = null;
                            att.LateIn      = null;
                            att.LateOut     = null;
                            att.OTMin       = null;
                            att.EarlyIn     = null;
                            att.EarlyOut    = null;
                            att.Remarks     = null;
                            att.ShifMin     = null;
                            att.SLMin       = null;

                            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)
                            {
                                if (context.Holidays.Where(hol => hol.HolDate == dateTime).Count() > 0)
                                {
                                    att.DutyCode = "G";
                                    att.StatusAB = false;
                                    att.StatusGZ = true;
                                    att.Remarks  = "[GZ]";
                                    att.ShifMin  = 0;
                                }
                            }
                            ////////////////////////////
                            //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 = "[CL]";
                                    }
                                    else if (Leave.LvCode == "B")
                                    {
                                        att.Remarks = "[AL]";
                                    }
                                    else if (Leave.LvCode == "C")
                                    {
                                        att.Remarks = "[SL]";
                                    }
                                    else
                                    {
                                        att.Remarks = "[" + _Leave.FirstOrDefault().LvType.LvDesc + "]";
                                    }
                                }
                                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.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]";
                                }
                            }
                            else
                            {
                                att.StatusLeave = false;
                            }
                            ctx.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            _myHelperClass.WriteToLogFile("-------Error In Creating Attendance of Employee: " + emp.EmpNo + " ------" + ex.InnerException.Message);
                        }
                    }
                }
                ctx.Dispose();
            }
        }
Example #22
0
        public void GenerateLeaveQuotaAttributes(List <Emp> _emp, List <LvType> _lvType, int AL, int CL, int SL)
        {
            using (var ctx = new TAS2013Entities())
            {
                foreach (var emp in _emp)
                {
                    List <LvConsumed> lvcon = ctx.LvConsumeds.Where(aa => aa.EmpID == emp.EmpID).ToList();
                    foreach (var lvType in _lvType)
                    {
                        string            empLvType        = emp.EmpID.ToString() + lvType.LvType1;
                        List <LvConsumed> lvConsumedlvType = new List <LvConsumed>();
                        if (lvcon.Where(aa => aa.EmpLvType == empLvType).Count() == 0)
                        {
                            string     empType    = emp.EmpID.ToString() + lvType.LvType1;
                            LvConsumed lvConsumed = new LvConsumed();
                            lvConsumed.EmpLvType      = empType;
                            lvConsumed.EmpID          = emp.EmpID;
                            lvConsumed.LeaveType      = lvType.LvType1;
                            lvConsumed.JanConsumed    = 0;
                            lvConsumed.FebConsumed    = 0;
                            lvConsumed.MarchConsumed  = 0;
                            lvConsumed.AprConsumed    = 0;
                            lvConsumed.MayConsumed    = 0;
                            lvConsumed.JuneConsumed   = 0;
                            lvConsumed.JulyConsumed   = 0;
                            lvConsumed.AugustConsumed = 0;
                            lvConsumed.SepConsumed    = 0;
                            lvConsumed.OctConsumed    = 0;
                            lvConsumed.NovConsumed    = 0;
                            lvConsumed.DecConsumed    = 0;
                            switch (lvType.LvType1)
                            {
                            case "A":    //CL
                                lvConsumed.TotalForYear        = CL;
                                lvConsumed.YearRemaining       = CL;
                                lvConsumed.GrandTotal          = CL;
                                lvConsumed.GrandTotalRemaining = CL;
                                break;

                            case "B":    //AL
                                lvConsumed.TotalForYear        = AL;
                                lvConsumed.YearRemaining       = AL;
                                lvConsumed.GrandTotal          = AL;
                                lvConsumed.GrandTotalRemaining = AL;
                                break;

                            case "C":    //SL
                                lvConsumed.TotalForYear        = SL;
                                lvConsumed.YearRemaining       = SL;
                                lvConsumed.GrandTotal          = SL;
                                lvConsumed.GrandTotalRemaining = SL;
                                break;
                            }
                            ctx.LvConsumeds.Add(lvConsumed);
                            ctx.SaveChanges();
                        }
                    }
                }

                ctx.Dispose();
            }
        }
Example #23
0
        public ActionResult Create([Bind(Include = "EmpID,EmpNo,EmpName,DesigID,JobID,Gender,ShiftID,LocID,TypeID,GradeID,SecID,CardNo,FpID,PinCode,NicNo,FatherName,BloodGroup,BirthDate,MarStatus,JoinDate,ValidDate,IssueDate,ResignDate,HomeAdd,ProcessAtt,ProcessIn,Status,PhoneNo,Remarks,Email,CellNo,CrewID,FlagFP,FlagFace,FlagCard,EmpImageID,CompanyID,HasOT,RegionID,CityID,ZoneID,PostedAs")] Emp emp)
        {
            string empNo = "";

            if (string.IsNullOrEmpty(emp.EmpNo))
            {
                ModelState.AddModelError("EmpNo", "Emp No field is required!");
            }
            if (string.IsNullOrEmpty(emp.EmpName))
            {
                ModelState.AddModelError("EmpName", "Namefield is required!");
            }
            if (emp.EmpNo != null)
            {
                if (emp.EmpNo.Length > 15)
                {
                    ModelState.AddModelError("EmpNo", "String length exceeds!");
                }
                if (db.Emps.Where(aa => aa.EmpNo.ToUpper() == emp.EmpNo.ToUpper() && aa.CompanyID == emp.CompanyID).Count() > 0)
                {
                    ModelState.AddModelError("EmpNo", "Emp No should be unique!");
                }
            }
            //if (emp.FpID != null)
            //{
            //    if (db.Emps.Where(aa => aa.FpID == emp.FpID).Count() > 0)
            //        ModelState.AddModelError("FpID", "FP ID should be unique!");
            //}
            if (emp.CardNo != null)
            {
                if (db.Emps.Where(aa => aa.CardNo == emp.CardNo).Count() > 0)
                {
                    ModelState.AddModelError("CardNo", "Card No should be unique!");
                }
                if (emp.CardNo.Length > 8)
                {
                    ModelState.AddModelError("CardNo", "String length exceeds!");
                }
            }
            if (emp.EmpName != null)
            {
                if (emp.EmpName.Length > 40)
                {
                    ModelState.AddModelError("EmpName", "String length exceeds!");
                }
            }
            if (emp.SecID == null)
            {
                ModelState.AddModelError("SecID", "Please Specify section!");
            }
            if (emp.TypeID == null)
            {
                ModelState.AddModelError("TypeID", "Please Specify Type!");
            }
            if (emp.GradeID == null)
            {
                ModelState.AddModelError("GradeID", "Please Specify Grade!");
            }

            if (ModelState.IsValid)
            {
                emp.ProcessAtt = true;
                emp.ProcessIn  = true;
                emp.EmpNo      = emp.EmpNo.ToUpper();
                empNo          = emp.EmpNo;
                db.Emps.Add(emp);
                db.SaveChanges();
                int _userID = Convert.ToInt32(Session["LogedUserID"].ToString());
                HelperClass.MyHelper.SaveAuditLog(_userID, (byte)MyEnums.FormName.Employee, (byte)MyEnums.Operation.Add, DateTime.Now);
                HttpPostedFileBase file = Request.Files["ImageData"];
                if (file != null)
                {
                    ImageConversion _Image  = new ImageConversion();
                    int             imageID = _Image.UploadImageInDataBase(file, emp.EmpNo);
                    if (imageID != 0)
                    {
                        using (var ctx = new TAS2013Entities())
                        {
                            var _emp = ctx.Emps.Where(aa => aa.EmpNo == empNo).ToList();
                            if (_emp.Count > 0)
                            {
                                _emp.FirstOrDefault().EmpImageID = imageID;
                                ctx.SaveChanges();
                                ctx.Dispose();
                            }
                        }
                    }
                    else
                    {
                    }
                }
                return(RedirectToAction("Index"));
            }
            var _wings = new List <Division>();

            using (TAS2013Entities context = new TAS2013Entities())
            {
                _wings       = context.Divisions.ToList();
                ViewBag.Wing = new SelectList(_wings, "WingID", "WingName");
                User LoggedInUser = Session["LoggedUser"] as User;
                ViewBag.CompanyID = new SelectList(db.Companies.OrderBy(aa => aa.CompName), "CompID", "CompName");
                ViewBag.CrewID    = new SelectList(db.Crews.OrderBy(aa => aa.CrewName), "CrewID", "CrewName");
                ViewBag.DesigID   = new SelectList(db.Designations.OrderBy(aa => aa.DesignationName), "DesignationID", "DesignationName");
                ViewBag.GradeID   = new SelectList(db.Grades.OrderBy(aa => aa.GradeName), "GradeID", "GradeName");
                ViewBag.JobID     = new SelectList(db.JobTitles.OrderBy(aa => aa.JobTitle1), "JobID", "JobTitle1");
                //ViewBag.LocID = new SelectList(db.Locations, "LocID", "LocName");
                ViewBag.SecID    = new SelectList(db.Sections.OrderBy(aa => aa.SectionName), "SectionID", "SectionName");
                ViewBag.ShiftID  = new SelectList(db.Shifts.OrderBy(aa => aa.ShiftName), "ShiftID", "ShiftName");
                ViewBag.TypeID   = new SelectList(db.EmpTypes.OrderBy(aa => aa.TypeName), "TypeID", "TypeName");
                ViewBag.EmpID    = new SelectList(db.EmpFaces, "EmpID", "Face1");
                ViewBag.EmpID    = new SelectList(db.EmpFps.OrderBy(aa => aa.Fp1), "EmpID", "Fp1");
                ViewBag.CatID    = new SelectList(db.Categories.OrderBy(aa => aa.CatName), "CatID", "CatName");
                ViewBag.DeptID   = new SelectList(db.Departments.OrderBy(aa => aa.DeptName), "DeptID", "DeptName");
                ViewBag.CityID   = new SelectList(db.Cities.OrderBy(aa => aa.CityName), "CityID", "CityName");
                ViewBag.ZoneID   = new SelectList(db.Zones.OrderBy(aa => aa.ZoneName), "ZoneID", "ZoneName");
                ViewBag.RegionID = new SelectList(db.Regions.OrderBy(aa => aa.RegionName), "RegionID", "RegionName");
                ViewBag.PostedAs = new SelectList(db.Designations.OrderBy(aa => aa.DesignationName), "DesignationID", "DesignationName");
            }
            return(View(emp));
            //if (ModelState.IsValid)
            //{
            //    db.Emps.Add(emp);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //ViewBag.CompanyID = new SelectList(db.Companies, "CompID", "CompName", emp.CompanyID);
            //ViewBag.CrewID = new SelectList(db.Crews, "CrewID", "CrewName", emp.CrewID);
            //ViewBag.DesigID = new SelectList(db.Designations, "DesignationID", "DesignationName", emp.DesigID);
            //ViewBag.GradeID = new SelectList(db.Grades, "GradeID", "GradeName", emp.GradeID);
            //ViewBag.JobID = new SelectList(db.JobTitles, "JobID", "JobTitle1", emp.JobID);
            //ViewBag.LocID = new SelectList(db.Locations, "LocID", "LocName", emp.LocID);
            //ViewBag.SecID = new SelectList(db.Sections, "SectionID", "SectionName", emp.SecID);
            //ViewBag.ShiftID = new SelectList(db.Shifts, "ShiftID", "ShiftName", emp.ShiftID);
            //ViewBag.TypeID = new SelectList(db.EmpTypes, "TypeID", "TypeName", emp.TypeID);
            //ViewBag.EmpID = new SelectList(db.EmpFaces, "EmpID", "Face1", emp.EmpID);
            //ViewBag.EmpID = new SelectList(db.EmpFps, "EmpID", "Fp1", emp.EmpID);
            //ViewBag.EmpID = new SelectList(db.LvQuotas, "EmpID", "EmpID", emp.EmpID);
            //return View(emp);
        }
Example #24
0
        public void GenerateLeaveQuotaAttributes(List <Emp> _emp, List <LvType> _lvType, float AL, float CL, float SL)
        {
            using (var ctx = new TAS2013Entities())
            {
                DateTime dt = DateTime.Today;
                if (dt.Month == 1 && dt.Day < 3)
                {
                    dt = new DateTime(dt.Year - 1, 12, 31);
                }
                foreach (var emp in _emp)
                {
                    List <LvConsumed> lvcon = ctx.LvConsumeds.Where(aa => aa.EmpID == emp.EmpID).ToList();
                    foreach (var lvType in _lvType)
                    {
                        string            empLvType        = emp.EmpID.ToString() + lvType.LvType1 + dt.Year.ToString();
                        List <LvConsumed> lvConsumedlvType = new List <LvConsumed>();
                        if (lvcon.Where(aa => aa.EmpLvTypeYear == empLvType).Count() == 0)
                        {
                            string     empType    = emp.EmpID.ToString() + lvType.LvType1;
                            LvConsumed lvConsumed = new LvConsumed();
                            lvConsumed.EmpLvType      = empType;
                            lvConsumed.EmpLvTypeYear  = empType + dt.Year.ToString();
                            lvConsumed.Year           = dt.Year.ToString();
                            lvConsumed.EmpID          = emp.EmpID;
                            lvConsumed.LeaveType      = lvType.LvType1;
                            lvConsumed.JanConsumed    = 0;
                            lvConsumed.FebConsumed    = 0;
                            lvConsumed.MarchConsumed  = 0;
                            lvConsumed.AprConsumed    = 0;
                            lvConsumed.MayConsumed    = 0;
                            lvConsumed.JuneConsumed   = 0;
                            lvConsumed.JulyConsumed   = 0;
                            lvConsumed.AugustConsumed = 0;
                            lvConsumed.SepConsumed    = 0;
                            lvConsumed.OctConsumed    = 0;
                            lvConsumed.NovConsumed    = 0;
                            lvConsumed.DecConsumed    = 0;
                            lvConsumed.CompanyID      = emp.CompanyID;
                            switch (lvType.LvType1)
                            {
                            case "A":    //CL
                                lvConsumed.TotalForYear        = CL;
                                lvConsumed.YearRemaining       = CL;
                                lvConsumed.GrandTotal          = CL;
                                lvConsumed.GrandTotalRemaining = CL;
                                break;

                            case "B":    //AL
                                lvConsumed.TotalForYear        = AL;
                                lvConsumed.YearRemaining       = AL;
                                lvConsumed.GrandTotal          = AL;
                                lvConsumed.GrandTotalRemaining = AL;
                                break;

                            case "C":    //SL
                                lvConsumed.TotalForYear        = SL;
                                lvConsumed.YearRemaining       = SL;
                                lvConsumed.GrandTotal          = SL;
                                lvConsumed.GrandTotalRemaining = SL;
                                break;
                                //case "E"://CPL
                                //    lvConsumed.TotalForYear = CPL;
                                //    lvConsumed.YearRemaining = CPL;
                                //    lvConsumed.GrandTotal = CPL;
                                //    lvConsumed.GrandTotalRemaining = CPL;
                                //    break;
                            }
                            ctx.LvConsumeds.Add(lvConsumed);
                            ctx.SaveChanges();
                        }
                    }
                }

                ctx.Dispose();
            }
        }
Example #25
0
        public void ProcessDailyAttendance()
        {
            DateTime        _dt              = GlobalSettings._dateTime;
            DateTime        dtTo             = new DateTime(2015, 12, 7);
            DateTime        dtFrom           = new DateTime(2015, 12, 8);
            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 == 180).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
                            PlaceTimeInOuts.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)
                                        {
                                            TimeSpan t1 = new TimeSpan(11, 00, 00);
                                            if (up.EntTime.TimeOfDay < t1)
                                            {
                                                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
                            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");
                                        PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                    }
                                    else
                                    {
                                        PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                    }
                                }
                                else
                                {
                                    PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                                }
                            }
                            else
                            {
                                PlaceTimeInOuts.CalculateTimeINOUT(attendanceRecord, up);
                            }
                        }
                        if (employee.Shift.OpenShift == true)
                        {
                            if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd)
                            {
                                DateTime dt = up.EntDate.Date.AddDays(-1);
                                CalculateWorkMins.CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                context.SaveChanges();
                            }
                        }
                        //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)
                            {
                                CalculateWorkMins.CalculateRosterTimes(attendanceRecord, context.Rosters.FirstOrDefault(r => r.EmpDate == up.EmpDate), shift);
                                context.SaveChanges();
                            }
                            else
                            {
                                if (shift.OpenShift == true)
                                {
                                    if (up.EntTime.TimeOfDay < PlaceTimeInOuts.OpenShiftThresholdEnd)
                                    {
                                        DateTime dt = up.EntDate.Date.AddDays(-1);
                                        CalculateWorkMins.CalculateOpenShiftTimes(context.AttDatas.FirstOrDefault(aa => aa.AttDate == dt && aa.EmpID == up.EmpID), shift);
                                        CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift);
                                        context.SaveChanges();
                                    }
                                    else
                                    {
                                        //Calculate open shifft time of the same date
                                        CalculateWorkMins.CalculateOpenShiftTimes(attendanceRecord, shift);
                                        context.SaveChanges();
                                    }
                                }
                                else
                                {
                                    CalculateWorkMins.CalculateShiftTimes(attendanceRecord, shift);
                                    context.SaveChanges();
                                }
                            }
                        }
                        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();
        }
Example #26
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());
        }
Example #27
0
        public ActionResult Create([Bind(Include = "EmpID,EmpNo,EmpName,DesigID,JobID,Gender,ShiftID,LocID,TypeID,GradeID,SecID,CardNo,FpID,PinCode,NicNo,FatherName,BloodGroup,BirthDate,MarStatus,JoinDate,ValidDate,IssueDate,ResignDate,HomeAdd,ProcessAtt,ProcessIn,Status,PhoneNo,Remarks,Email,CellNo,CrewID,FlagFP,FlagFace,FlagCard,EmpImageID,HasOT,Islamabad,Lahore,Karachi,Peshawar,Quetta,Gender")] Emp emp)
        {
            string empNo = "";

            emp.EmpNo = emp.EmpID.ToString();
            int cardno = Convert.ToInt32(emp.CardNo);

            emp.CardNo = cardno.ToString("0000000000");
            if (db.Emps.Where(aa => aa.Status == true && aa.Deleted != true).Count() >= 4000)
            {
                ModelState.AddModelError("EmpNo", "Active Number of employees are exceeded from license ");
            }
            if (string.IsNullOrEmpty(emp.EmpNo))
            {
                ModelState.AddModelError("EmpNo", "Emp No is required!");
            }
            if (string.IsNullOrEmpty(emp.EmpName))
            {
                ModelState.AddModelError("EmpName", "Name is required!");
            }
            if (emp.EmpID != null)
            {
                if (db.Emps.Where(aa => aa.EmpID == emp.EmpID).Count() > 0)
                {
                    ModelState.AddModelError("EmpID", "Emp ID should be unique!");
                }
            }
            else
            {
                ModelState.AddModelError("EmpID", "Emp ID is a required fields!");
            }

            if (emp.EmpNo != null)
            {
                if (emp.EmpNo.Length > 15)
                {
                    ModelState.AddModelError("EmpNo", "String length exceeds!");
                }
                if (db.Emps.Where(aa => aa.EmpNo.ToUpper() == emp.EmpNo.ToUpper()).Count() > 0)
                {
                    ModelState.AddModelError("EmpNo", "Emp No should be unique!");
                }
            }
            if (emp.CardNo != null)
            {
                if (db.Emps.Where(aa => aa.CardNo == emp.CardNo).Count() > 0)
                {
                    if (emp.CardNo != "0000000000")
                    {
                        ModelState.AddModelError("CardNo", "Card No should be unique!");
                    }
                }
                if (emp.CardNo.Length > 10)
                {
                    ModelState.AddModelError("CardNo", "String length exceeds!");
                }
            }
            if (emp.EmpName != null)
            {
                if (emp.EmpName.Length > 40)
                {
                    ModelState.AddModelError("EmpName", "String length exceeds!");
                }
            }
            if (emp.SecID == null)
            {
                ModelState.AddModelError("SecID", "Please Specify section!");
            }
            if (emp.TypeID == null)
            {
                ModelState.AddModelError("TypeID", "Please Specify Type!");
            }
            //if (emp.GradeID == null)
            //ModelState.AddModelError("GradeID", "Please Specify Grade!");
            if (db.Emps.Where(aa => aa.Status == true).Count() > 4000)
            {
                ModelState.AddModelError("EmpNo", "Your Employees has exceeded from License, Please upgrade your license");
            }
            if (ModelState.IsValid)
            {
                emp.ProcessAtt = true;
                //emp.ProcessI = true;
                emp.EmpNo = emp.EmpNo.ToUpper();
                if (emp.CardNo != "")
                {
                    int card = Convert.ToInt32(emp.CardNo);
                    emp.CardNo = card.ToString("0000000000");
                }
                else
                {
                    emp.CardNo = "0000000000";
                }
                empNo       = emp.EmpNo;
                emp.Deleted = false;
                AddEmpLocation(emp);
                //emp.FpID = emp.EmpID;
                db.Emps.Add(emp);
                //db.SaveChanges();
                SaveChanges(db);
                int _userID = Convert.ToInt32(Session["LogedUserID"].ToString());
                HelperClass.MyHelper.SaveAuditLog(_userID, (byte)MyEnums.FormName.Employee, (byte)MyEnums.Operation.Add, DateTime.Now);
                HttpPostedFileBase file = Request.Files["ImageData"];
                if (file != null)
                {
                    ImageConversion _Image  = new ImageConversion();
                    int             imageID = _Image.UploadImageInDataBase(file, emp.EmpNo);
                    if (imageID != 0)
                    {
                        using (var ctx = new TAS2013Entities())
                        {
                            var _emp = ctx.Emps.Where(aa => aa.EmpNo == empNo).ToList();
                            if (_emp.Count > 0)
                            {
                                _emp.FirstOrDefault().EmpImageID = imageID;
                                ctx.SaveChanges();
                                ctx.Dispose();
                            }
                        }
                    }
                    else
                    {
                    }
                }
                return(RedirectToAction("Index"));
            }
            //var _wings = new List<Division>();
            using (TAS2013Entities context = new TAS2013Entities())
            {
                //ViewBag.Wing = new SelectList(_wings.OrderBy(s=>s.DivisionName), "WingID", "WingName");
                User LoggedInUser = Session["LoggedUser"] as User;
                //ViewBag.CrewID = new SelectList(db.Crews.OrderBy(s=>s.CrewName), "CrewID", "CrewName");
                ViewBag.DesigID = new SelectList(db.Designations.OrderBy(s => s.DesignationName), "DesignationID", "DesignationName");
                //ViewBag.GradeID = new SelectList(db.Grades.OrderBy(s => s.GradeID), "GradeID", "GradeName");
                //ViewBag.GradeID = new SelectList(db.Grades.OrderBy(s=>s.GradeName), "GradeID", "GradeName");
                //ViewBag.JobID = new SelectList(db.JobTitles.OrderBy(s=>s.JobTitle1), "JobID", "JobTitle1");
                ViewBag.LocID   = new SelectList(db.Locations.OrderBy(s => s.LocName), "LocID", "LocName");
                ViewBag.SecID   = new SelectList(db.Sections.OrderBy(s => s.SectionName), "SectionID", "SectionName");
                ViewBag.ShiftID = new SelectList(db.Shifts.OrderBy(s => s.ShiftName), "ShiftID", "ShiftName");
                ViewBag.TypeID  = new SelectList(db.EmpTypes.OrderBy(s => s.TypeName), "TypeID", "TypeName");
                //ViewBag.CatID = new SelectList(db.Categories.OrderBy(s=>s.CatName), "CatID", "CatName");
                ViewBag.DeptID = new SelectList(db.Departments.OrderBy(s => s.DeptName), "DeptID", "DeptName");
            }
            return(View(emp));
        }