public List<AttendanceLogReport> GetAttendanceLogReportList(int iCompany, int iDepartment, DateTime beginDate, DateTime endDate)
        {
            List<AttendanceReport> attendanceReports = GetAttendanceReport(iCompany, iDepartment, beginDate, endDate, 0, true);
            if (attendanceReports.Count == 0)
                return null;

            List<string> lEmplNumbers = GetEmployeeNumberList(iCompany, iDepartment);
            if (lEmplNumbers == null || lEmplNumbers.Count == 0)
                return null;
            string sEmplNumbers = string.Join(",", lEmplNumbers.ToArray());

            OleDbCommand odCom = BuildSelectCmd("Department INNER JOIN Employee ON Department.ID = Employee.DepartmentID",
                "Employee.EmployeeNumber,Employee.FirstName,Employee.LastName,Employee.PayrollNumber,Employee.JobDescription,Department.Name as DepartmentName",
                "EmployeeNumber in(" + sEmplNumbers + ")");

            OleDbDataAdapter odApt = new OleDbDataAdapter(odCom);
            DataTable dtEmpl = new DataTable();
            odApt.Fill(dtEmpl);

            List<AttendanceLogReport> attLogs = new List<AttendanceLogReport>();
            AttendanceLogReport _attLog = null;

            foreach (AttendanceReport attRp in attendanceReports)
            {
                _attLog = new AttendanceLogReport();

                DataRow[] rdEmpl = dtEmpl.Select("EmployeeNumber=" + attRp.EmployeeNumber);
                if (rdEmpl.Length > 0)
                {
                    _attLog.FullName = rdEmpl[0]["LastName"] + ", " + rdEmpl[0]["FirstName"];
                    _attLog.PayrollNumber = (int)rdEmpl[0]["PayrollNumber"];
                    _attLog.JobDescription = rdEmpl[0]["JobDescription"].ToString();
                    _attLog.Department = rdEmpl[0]["DepartmentName"].ToString();
                }

                _attLog.AttendanceRecordIDList = attRp.AttendanceRecordIDList;
                _attLog.DayTypeID = attRp.DayTypeID;
                _attLog.EmployeeNumber = attRp.EmployeeNumber;
                _attLog.OvertimeHour1 = attRp.OvertimeHour1;
                _attLog.OvertimeHour2 = attRp.OvertimeHour2;
                _attLog.OvertimeHour3 = attRp.OvertimeHour3;
                _attLog.OvertimeHour4 = attRp.OvertimeHour4;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.PayPeriodID = attRp.PayPeriodID;
                _attLog.RegularHour = 8;
                _attLog.RegularRate = attRp.RegularRate;
                _attLog.TotalHour = attRp.RegularHour + attRp.OvertimeHour1 + attRp.OvertimeHour2 + attRp.OvertimeHour3 + attRp.OvertimeHour4;
                _attLog.WorkingHour = attRp.RegularHour;
                _attLog.WorkFrom = attRp.WorkFrom;
                _attLog.WorkTo = attRp.WorkTo;

                attLogs.Add(_attLog);
            }
            return attLogs;
        }
        private AttendanceLogReport GetRegularOvertime(AttendanceLogReport _attReport, double ptotalHour)
        {
            double _totalHour = ptotalHour;
            double _regularHour = _attReport.WorkingHour;
            double _overtimeHour1 = _attReport.OvertimeHour1;
            double _overtimeHour2 = _attReport.OvertimeHour2;
            double _overtimeHour3 = _attReport.OvertimeHour3;
            double _overtimeHour4 = _attReport.OvertimeHour4;

            double totalHour = 0;
            double overtimeHour1 = 0;
            double overtimeHour2 = 0;
            double overtimeHour3 = 0;
            double overtimeHour4 = 0;

            if (_totalHour > _regularHour)
            {
                totalHour = _regularHour;
                _totalHour -= _regularHour;

                if (_totalHour > _overtimeHour1)
                {
                    overtimeHour1 = _overtimeHour1;
                    _totalHour -= _overtimeHour1;

                    if (_totalHour > _overtimeHour2)
                    {
                        overtimeHour2 = _overtimeHour2;
                        _totalHour -= _overtimeHour2;

                        if (_totalHour > _overtimeHour3)
                        {
                            overtimeHour3 = _overtimeHour3;
                            _totalHour -= _overtimeHour3;

                            overtimeHour4 = _totalHour;
                        }
                        else
                            overtimeHour3 = _totalHour;
                    }
                    else
                        overtimeHour2 = _totalHour;
                }
                else
                    overtimeHour1 = _totalHour;
            }
            else
                totalHour = _totalHour;

            AttendanceLogReport attReport = _attReport;

            attReport.OvertimeHour1 = Math.Round(overtimeHour1, 2);
            attReport.OvertimeHour2 = Math.Round(overtimeHour2, 2);
            attReport.OvertimeHour3 = Math.Round(overtimeHour3, 2);
            attReport.OvertimeHour4 = Math.Round(overtimeHour4, 2);
            attReport.WorkingHour = Math.Round(totalHour, 2);

            return attReport;
        }
        private List<AttendanceLogReport> GetAttendanceLogReportList(int employeeNumber, DateTime beginDate, DateTime endDate)
        {
            List<AttendanceLogReport> attLogs = new List<AttendanceLogReport>();

            List<AttendanceReport> attReportList = GetAttendanceReport(employeeNumber, beginDate, endDate);
            if (attReportList.Count == 0)
                return attLogs;

            OleDbCommand odCom = BuildSelectCmd("Department INNER JOIN Employee ON Department.ID = Employee.DepartmentID",
                "Employee.EmployeeNumber, Employee.FirstName, Employee.LastName, Employee.PayrollNumber, Employee.JobDescription, Department.Name AS DepartmentName",
                "EmployeeNumber = @Empl AND Active=TRUE", new object[] { "@Empl", employeeNumber });

            OleDbDataReader odRdr = odCom.ExecuteReader();

            string employeeName = "", jobDescription = "", departmentName = "";
            int payrollNumber = 0;
            if (odRdr.Read())
            {
                employeeName = odRdr["LastName"] + ", " + odRdr["FirstName"];
                jobDescription = odRdr["JobDescription"].ToString();
                departmentName = odRdr["DepartmentName"].ToString();
                payrollNumber = (int)odRdr["PayrollNumber"];
            }
            odRdr.Close();

            AttendanceLogReport attLog = null;
            Hashtable emplNumberOfRegularHours = new Hashtable();
            double numberOfRegularHours = 0;
            foreach (AttendanceReport attReport in attReportList)
            {

                if (emplNumberOfRegularHours.ContainsKey(attReport.EmployeeNumber))
                    numberOfRegularHours = (double)emplNumberOfRegularHours[attReport.EmployeeNumber];
                else
                {
                    PaymentRate pRate = GetPaymentRateByEmployeeAndWorkDay(attReport.EmployeeNumber, attReport.WorkFrom);
                    numberOfRegularHours = pRate.NumberOfRegularHours;
                    emplNumberOfRegularHours.Add(attReport.EmployeeNumber, numberOfRegularHours);
                }

                attLog = new AttendanceLogReport();

                attLog.FullName = employeeName;
                attLog.PayrollNumber = payrollNumber;
                attLog.JobDescription = jobDescription;
                attLog.Department = departmentName;

                attLog.AttendanceRecordIDList = attReport.AttendanceRecordIDList;
                attLog.DayTypeID = attReport.DayTypeID;
                attLog.EmployeeNumber = attReport.EmployeeNumber;
                attLog.OvertimeHour1 = attReport.OvertimeHour1;
                attLog.OvertimeHour2 = attReport.OvertimeHour2;
                attLog.OvertimeHour3 = attReport.OvertimeHour3;
                attLog.OvertimeHour4 = attReport.OvertimeHour4;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.PayPeriodID = attReport.PayPeriodID;
                attLog.RegularHour = numberOfRegularHours;
                attLog.RegularRate = attReport.RegularRate;
                attLog.TotalHour = attReport.RegularHour + attReport.OvertimeHour1 + attReport.OvertimeHour2 + attReport.OvertimeHour3 + attReport.OvertimeHour4;
                attLog.WorkingHour = attReport.RegularHour;
                attLog.WorkFrom = attReport.WorkFrom;
                attLog.WorkTo = attReport.WorkTo;

                attLogs.Add(attLog);
            }
            return attLogs;
        }
        private List<AttendanceLogReport> GetAttendanceLogReportList(int employeeNumber, DateTime beginDate, DateTime endDate)
        {
            List<AttendanceLogReport> attLogs = new List<AttendanceLogReport>();

            List<AttendanceReport> attReportList = GetAttendanceReport(employeeNumber, beginDate, endDate);
            if (attReportList.Count == 0)
                return attLogs;

            OleDbCommand odCom = BuildSelectCmd("Department INNER JOIN Employee ON Department.ID = Employee.DepartmentID",
                "Employee.EmployeeNumber, Employee.FirstName, Employee.LastName, Employee.PayrollNumber, Employee.JobDescription, Department.Name AS DepartmentName",
                "EmployeeNumber = @Empl AND Active=TRUE", new object[] { "@Empl", employeeNumber });

            OleDbDataReader odRdr = odCom.ExecuteReader();

            string employeeName = "", jobDescription = "", departmentName = "";
            int payrollNumber = 0;
            if (odRdr.Read())
            {
                employeeName = odRdr["LastName"] + ", " + odRdr["FirstName"];
                jobDescription = odRdr["PayrollNumber"].ToString(); //TODO what's the hell here?
                departmentName = odRdr["PayrollNumber"].ToString();
                payrollNumber = (int)odRdr["PayrollNumber"];
            }
            odRdr.Close();

            AttendanceLogReport attLog = null;

            foreach (AttendanceReport attReport in attReportList)
            {
                attLog = new AttendanceLogReport();

                attLog.FullName = employeeName;
                attLog.PayrollNumber = payrollNumber;
                attLog.JobDescription = jobDescription;
                attLog.Department = departmentName;

                attLog.AttendanceRecordIDList = attReport.AttendanceRecordIDList;
                attLog.DayTypeID = attReport.DayTypeID;
                attLog.EmployeeNumber = attReport.EmployeeNumber;
                attLog.OvertimeHour1 = attReport.OvertimeHour1;
                attLog.OvertimeHour2 = attReport.OvertimeHour2;
                attLog.OvertimeHour3 = attReport.OvertimeHour3;
                attLog.OvertimeHour4 = attReport.OvertimeHour4;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.OvertimeRate1 = attReport.OvertimeRate1;
                attLog.PayPeriodID = attReport.PayPeriodID;
                attLog.RegularHour = 8; //TODO ??
                attLog.RegularRate = attReport.RegularRate;
                attLog.TotalHour = attReport.RegularHour + attReport.OvertimeHour1 + attReport.OvertimeHour2 + attReport.OvertimeHour3 + attReport.OvertimeHour4;
                attLog.WorkingHour = attReport.RegularHour;
                attLog.WorkFrom = attReport.WorkFrom;
                attLog.WorkTo = attReport.WorkTo;

                attLogs.Add(attLog);
            }
            return attLogs;
        }
        public List<AttendanceLogReport> GetAttendanceLogReportList(int iCompany, int iDepartment, DateTime beginDate, DateTime endDate)
        {
            List<AttendanceReport> attendanceReports = GetAttendanceReport(iCompany, iDepartment, beginDate, endDate, 0, true);
            if (attendanceReports.Count == 0)
                return null;

            List<string> lEmplNumbers = GetEmployeeNumberList(iCompany, iDepartment);
            if (lEmplNumbers == null || lEmplNumbers.Count == 0)
                return null;
            string sEmplNumbers = string.Join(",", lEmplNumbers.ToArray());

            OleDbCommand odCom = BuildSelectCmd("Department INNER JOIN Employee ON Department.ID = Employee.DepartmentID",
                "Employee.EmployeeNumber,Employee.FirstName,Employee.LastName,Employee.PayrollNumber,Employee.JobDescription,Department.Name as DepartmentName",
                "EmployeeNumber in(" + sEmplNumbers + ") AND Active=TRUE");

            OleDbDataReader odRdr = odCom.ExecuteReader();

            List<Employee> employeeList = new List<Employee>();
            Employee empl;
            while (odRdr.Read())
            {
                empl = new Employee();
                empl.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                empl.PayrollNumber = (int)odRdr["PayrollNumber"];
                empl.LastName = odRdr["LastName"].ToString();
                empl.FirstName = odRdr["FirstName"].ToString();
                empl.JobDescription = odRdr["JobDescription"].ToString();
                //loan
                empl.FaceData1 = odRdr["DepartmentName"].ToString();
                employeeList.Add(empl);
            }
            odRdr.Close();

            //OleDbDataAdapter odApt = new OleDbDataAdapter(odCom);
            //DataTable dtEmpl = new DataTable();
            //odApt.Fill(dtEmpl);

            List<AttendanceLogReport> attLogs = new List<AttendanceLogReport>();
            AttendanceLogReport _attLog = null;

            Hashtable emplNumberOfRegularHours = new Hashtable();

            double numberOfRegularHours = 0;
            foreach (AttendanceReport attRp in attendanceReports)
            {
                _attLog = new AttendanceLogReport();

                if (emplNumberOfRegularHours.ContainsKey(attRp.EmployeeNumber))
                    numberOfRegularHours = (double)emplNumberOfRegularHours[attRp.EmployeeNumber];
                else
                {
                    PaymentRate pRate = GetPaymentRateByEmployeeAndWorkDay(attRp.EmployeeNumber, attRp.WorkFrom);
                    numberOfRegularHours = pRate.NumberOfRegularHours;
                    emplNumberOfRegularHours.Add(attRp.EmployeeNumber, numberOfRegularHours);
                }
                Employee employee = employeeList.Find(delegate(Employee e) { return e.EmployeeNumber == attRp.EmployeeNumber; });

                _attLog.FullName = employee.LastName + ", " + employee.FirstName;
                _attLog.PayrollNumber = employee.PayrollNumber;
                _attLog.JobDescription = employee.JobDescription;
                _attLog.Department = employee.FaceData1;

                _attLog.AttendanceRecordIDList = attRp.AttendanceRecordIDList;
                _attLog.DayTypeID = attRp.DayTypeID;
                _attLog.EmployeeNumber = attRp.EmployeeNumber;
                _attLog.OvertimeHour1 = attRp.OvertimeHour1;
                _attLog.OvertimeHour2 = attRp.OvertimeHour2;
                _attLog.OvertimeHour3 = attRp.OvertimeHour3;
                _attLog.OvertimeHour4 = attRp.OvertimeHour4;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.PayPeriodID = attRp.PayPeriodID;
                _attLog.RegularHour = numberOfRegularHours;
                _attLog.RegularRate = attRp.RegularRate;
                _attLog.TotalHour = attRp.RegularHour + attRp.OvertimeHour1 + attRp.OvertimeHour2 + attRp.OvertimeHour3 + attRp.OvertimeHour4;
                _attLog.WorkingHour = attRp.RegularHour;
                _attLog.WorkFrom = attRp.WorkFrom;
                _attLog.WorkTo = attRp.WorkTo;

                attLogs.Add(_attLog);
            }
            return attLogs;
        }