예제 #1
0
        public static void NonRecordedAttendance(int EmpId, DateTime day)
        {
            // 1. Check ExceptionAttendance for employee id.
            // 2. If employee exists, mark employee as present
            // 3. Else check for applications, mark employee as absent based on that.

            MEAPSDbEntities     context = new MEAPSDbEntities();
            ExceptionAttendance ea      = context.ExceptionAttendances.SingleOrDefault(x => (x.EmpId == EmpId) && (x.Date == day));

            if (ea != null) // if in exception attendance, mark as full present.
            {
                LeaveStatus ls = new LeaveStatus();
                ls.Date          = day;
                ls.EmployeeEmpId = EmpId;
                ls.PresenceState = "FP";
                context.LeaveStatuses.Add(ls);
                context.SaveChanges();
            }
            else                           // else check for applications
            {
                LeaveStatus ls = new LeaveStatus();
                ls.Date          = day;
                ls.EmployeeEmpId = EmpId;
                ls.PresenceState = "A";

                LeaveApplication la = context.LeaveApplications.SingleOrDefault(x => (x.Date == day) && (x.EmployeeEmpId == EmpId));
                if (la != null)
                {
                    string type = la.Type;
                    switch (type)
                    {
                    case "CL":
                        ls.FCL = 1;
                        break;

                    case "ML":
                        ls.FML = 1;
                        break;

                    case "EL":
                        ls.EL = 1;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    ls.FCL = 1;
                }
                ls = LeaveDeduction.Deduct(ls);
                context.LeaveStatuses.Add(ls);
                context.SaveChanges();
            }
        }
        static void Main(string[] args)
        {
            MEAPSDbEntities context = new MEAPSDbEntities();

            Console.WriteLine("Tuples to insert:");
            int n = Int32.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                Holiday h = new Holiday();
                Console.Write("Date:");
                string dt = Console.ReadLine();
                h.Date = Convert.ToDateTime(dt);
                Console.Write("Comment:");
                h.Comment = Console.ReadLine();
                context.Holidays.Add(h);
                context.SaveChanges();
            }

            Console.Write("Date to check: ");
            string   dt1  = Console.ReadLine();
            DateTime dt2  = Convert.ToDateTime(dt1);
            bool     flag = WorkingDayChecker.IsWorkingDay(dt2);

            Console.WriteLine(flag.ToString());
            Console.ReadKey();
        }
        public static void Clean()
        {
            MEAPSDbEntities   context     = new MEAPSDbEntities();
            var               query       = from x in context.CSVDatas select x;
            List <CSVData>    unprocessed = query.ToList();
            List <Attendance> processed   = new List <Attendance>();

            foreach (CSVData item in unprocessed)
            {
                TimeSpan   inTime  = Convert.ToDateTime(item.In1).TimeOfDay;
                TimeSpan   outTime = Convert.ToDateTime(getOutTime(item)).TimeOfDay;
                DateTime   date    = DateTime.ParseExact(item.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                int        empid   = Convert.ToInt32(item.EmpId);
                Attendance record  = new Attendance();
                record.Date           = date;
                record.InTime         = inTime;
                record.OutTime        = outTime;
                record.Employee_EmpId = empid;
                processed.Add(record);
            }

            foreach (Attendance item in processed)
            {
                context.Attendances.Add(item);
                context.SaveChanges();
            }
        }
예제 #4
0
        public static void RecordedAttendance(int EmpId, DateTime day, TimeSpan EntryTime, TimeSpan ExitTime)
        {
            MEAPSDbEntities context          = new MEAPSDbEntities();
            TimeSpan        DefaultEntryTime = Convert.ToDateTime("9:50 AM").TimeOfDay;
            TimeSpan        DefaultExitTime  = Convert.ToDateTime("5:25 PM").TimeOfDay;
            LeaveStatus     ls = new LeaveStatus();

            ls.Date          = day;
            ls.EmployeeEmpId = EmpId;
            ls = Calculate(ls, EntryTime, ExitTime, day);
            ls = LeaveDeduction.Deduct(ls);
            context.LeaveStatuses.Add(ls);
            context.SaveChanges();
        }
        public static LeaveStatus Deduct(LeaveStatus ls)
        {
            MEAPSDbEntities context = new MEAPSDbEntities();
            int             EmpId   = ls.EmployeeEmpId;
            Employee        em      = context.Employees.SingleOrDefault(x => x.EmpId == EmpId);

            double reqCL = Convert.ToDouble(((ls.QCL_In ?? 0 + ls.QCL_Out ?? 0) * 0.25) + (ls.HCL ?? 0) * 0.5 + (ls.FCL ?? 0));
            double reqML = Convert.ToDouble((ls.FML ?? 0) + (ls.HML ?? 0) * 0.5);
            double reqEL = Convert.ToDouble(ls.EL ?? 0);
            double remCL = em.CL;
            double remML = em.ML;
            double remEL = em.EL;
            double LWP   = em.LWP;

            #region DedcutionLogic
            if (reqCL > remCL)
            {
                if (reqCL > remML)
                {
                    if (reqCL > remEL)
                    {
                        LWP       += reqCL;
                        ls.LWP     = reqCL;
                        ls.QCL_In  = null;
                        ls.QCL_Out = null;
                        ls.HCL     = null;
                        ls.FCL     = null;
                    }
                    else
                    {
                        remEL -= reqCL;
                    }
                }
                else
                {
                    remML -= reqCL;
                }
            }
            else
            {
                remCL -= reqCL;
            }

            if (reqML > remML)
            {
                if (reqML > remEL)
                {
                    LWP   += reqML;
                    ls.LWP = reqML;
                    ls.HML = null;
                    ls.FML = null;
                }
                else
                {
                    remEL -= reqML;
                }
            }
            else
            {
                remML -= reqML;
            }

            if (reqEL > remEL)
            {
                LWP   += reqEL;
                ls.LWP = reqEL;
                ls.EL  = null;
            }
            else
            {
                remEL -= reqML;
            }
            #endregion

            em.CL  = remCL;
            em.ML  = remML;
            em.EL  = remML;
            em.LWP = LWP;
            context.SaveChanges();

            return(ls);
        }
        static void Main(string[] args)
        {
            LeaveStatus ls = new LeaveStatus();

            Console.WriteLine("EmpId:");
            int empid = Int32.Parse(Console.ReadLine());

            ls.EmployeeEmpId = empid;
            Console.WriteLine("Date:");
            DateTime dt = Convert.ToDateTime(Console.ReadLine());

            ls.Date = dt;
            Console.WriteLine("Entry Time:");
            TimeSpan en = Convert.ToDateTime(Console.ReadLine()).TimeOfDay;

            Console.WriteLine("Exit Time:");
            TimeSpan ex = Convert.ToDateTime(Console.ReadLine()).TimeOfDay;

            Console.WriteLine("1: Enter leave application details. \n2. Delete. \n3. Continue...");
            int n = Int32.Parse(Console.ReadLine());

            if (n == 1)
            {
                MEAPSDbEntities  context = new MEAPSDbEntities();
                LeaveApplication la      = new LeaveApplication();
                Console.WriteLine("Enter type:");
                string type = Console.ReadLine();
                la.Date          = dt;
                la.EmployeeEmpId = empid;
                la.Type          = type;
                la.Remarks       = "test";
                context.LeaveApplications.Add(la);
                context.SaveChanges();
            }
            else if (n == 2)
            {
                MEAPSDbEntities  context = new MEAPSDbEntities();
                LeaveApplication la      = context.LeaveApplications.SingleOrDefault(x => (x.EmployeeEmpId == empid) && (x.Date == dt));
                context.LeaveApplications.Remove(la);
                context.SaveChanges();
            }

            Console.WriteLine("1: Enter time exception details. \n2. Delete. \n3. Continue...");
            n = Int32.Parse(Console.ReadLine());
            if (n == 1)
            {
                MEAPSDbEntities context = new MEAPSDbEntities();
                TimeException   te      = new TimeException();
                Console.WriteLine("Entry Time:");
                en = Convert.ToDateTime(Console.ReadLine()).TimeOfDay;
                Console.WriteLine("Exit Time:");
                ex      = Convert.ToDateTime(Console.ReadLine()).TimeOfDay;
                te.Date = dt; te.InTime = en; te.OutTime = ex;
                context.TimeExceptions.Add(te);
                context.SaveChanges();
            }
            if (n == 2)
            {
                MEAPSDbEntities context = new MEAPSDbEntities();
                TimeException   te      = context.TimeExceptions.SingleOrDefault(x => x.Date == dt);
                context.TimeExceptions.Remove(te);
                context.SaveChanges();
            }

            ls = Calculate(ls, en, ex, dt);

            Console.WriteLine("Date: " + ls.Date.ToShortDateString());
            Console.WriteLine("Employee ID: " + ls.EmployeeEmpId);
            Console.WriteLine("Presence: " + ls.PresenceState);
            Console.WriteLine("QCL In: " + ls.QCL_In);
            Console.WriteLine("QCL Out: " + ls.QCL_Out);
            Console.WriteLine("HCL: " + ls.HCL);
            Console.WriteLine("FCL: " + ls.FCL);
            Console.WriteLine("HML: " + ls.HML);
            Console.WriteLine("FML: " + ls.FML);
            Console.WriteLine("EL: " + ls.EL);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }