/// <summary>
        /// LoadFairWageProject
        /// </summary>
        /// <param name="works">works</param>
        /// <param name="jobClassType">jobClassType</param>
        /// <param name="projectId">projectId</param>
        /// <param name="startDate">startDate</param>
        /// <param name="endDate">endDate</param>
        /// <param name="companyId">companyId</param>
        public void LoadFairWageProject(ArrayList works, ArrayList jobClassType, int projectId, DateTime startDate, DateTime endDate, int companyId, string month)
        {
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            string projectName = projectGateway.GetName(projectId);

            int clientId = projectGateway.GetClientID(projectId);
            CompaniesGateway companiesGateway = new CompaniesGateway();
            companiesGateway.LoadAllByCompaniesId(clientId, companyId);
            string clientName = companiesGateway.GetName(clientId);

            // General vars
            int overtimeByCountry = 40; //Default for USA Projects
            int refId = GetNewRefId();

            int countryId = 1; //Default Canada
            if (projectGateway.GetCountryID(projectId) == 2)
            {
                countryId = 2;//USA
            }

            // Foreach of Works (FLL, RA, JL, PR, MH Rehab, MOB, Other)
            foreach (string work_ in works)
            {
                // Load Functions by Work
                ProjectCostingSheetAddFunctionListGateway projectCostingSheetAddFunctionListGateway = new ProjectCostingSheetAddFunctionListGateway();
                projectCostingSheetAddFunctionListGateway.LoadByWork_(work_);

                // Foreach of Functions
                foreach (ProjectCostingSheetAddTDS.FunctionListRow functionListRow in (ProjectCostingSheetAddTDS.FunctionListDataTable)projectCostingSheetAddFunctionListGateway.Table)
                {
                    // Foreach of Job Class (Laborer Group 2, Laborer Group 6, Operator Group 1, Operator Group 2, Regular Rate)
                    foreach (string jobClassType_ in jobClassType)
                    {
                        // Get Fringe Rate by Job Class
                        decimal fringeRate = projectGateway.GetOperatorGroupFringeRate(projectId, jobClassType_);

                        // Load Employees with Timesheet by ProjectId, StartDate, EndDate, Work, Function and Job Class
                        ProjectCostingSheetAddEmployeeListGateway projectCostingSheetAddEmployeeListGateway = new ProjectCostingSheetAddEmployeeListGateway(Data);
                        projectCostingSheetAddEmployeeListGateway.LoadByProjectIdStartDateEndDateWorkFunctionJobClass(projectId, startDate, endDate, work_, functionListRow.Function_, jobClassType_, companyId);

                        // Foreach of Employees with Timesheet
                        foreach (ProjectCostingSheetAddTDS.EmployeeListRow employeeListRow in (ProjectCostingSheetAddTDS.EmployeeListDataTable)projectCostingSheetAddEmployeeListGateway.Table)
                        {
                            DateTime newStartDate = new DateTime();
                            newStartDate = startDate;

                            DateTime newEndDate = new DateTime();
                            newEndDate = endDate;

                            // If Project is from Canada we get overtime
                            if (projectGateway.GetCountryID(projectId) == 1)
                            {
                                // Get Category of Employee
                                EmployeeGateway employeeGateway = new EmployeeGateway();
                                employeeGateway.LoadByEmployeeId(employeeListRow.EmployeeID);

                                switch (employeeGateway.GetCategory(employeeListRow.EmployeeID))
                                {
                                    case "Special Forces":
                                        overtimeByCountry = 50;
                                        break;

                                    case "Field":
                                        overtimeByCountry = 50;
                                        break;

                                    case "Field 44":
                                        overtimeByCountry = 44;
                                        break;

                                    case "Office/Admin":
                                        overtimeByCountry = 44;
                                        break;

                                    case "Mechanic/Manufactoring":
                                        overtimeByCountry = 44;
                                        break;
                                }
                            }

                            // Load Cost Pay Periods of Employee by StartDate and EndDate
                            ProjectCostingSheetAddEmployeePayPeriodGateway projectCostingSheetAddEmployeePayPeriodGateway = new ProjectCostingSheetAddEmployeePayPeriodGateway(Data);
                            projectCostingSheetAddEmployeePayPeriodGateway.LoadByStartDateEndDateEmployeeId(startDate, endDate, employeeListRow.EmployeeID);

                            // If Employee has Cost Pay Periods between StartDate and EndDate
                            if (projectCostingSheetAddEmployeePayPeriodGateway.Table.Rows.Count > 0)
                            {
                                // Foreach of Cost Pay Periods
                                foreach (ProjectCostingSheetAddTDS.EmployeePayPeriodRow employeePayPeriodRow in (ProjectCostingSheetAddTDS.EmployeePayPeriodDataTable)projectCostingSheetAddEmployeePayPeriodGateway.Table)
                                {
                                    // Update newEndDate with Date of Cost Pay Period
                                    newEndDate = employeePayPeriodRow.Date_.AddDays(-1);

                                    // Load Project Times of Employee by ProjectId, StartDate, EndDate, Work, Function, Job Class
                                    ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                                    projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, newStartDate, newEndDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID);

                                    // If Employee has ProjectTime
                                    if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                                    {
                                        double lhQuantity = 0;
                                        double overtime = 0;
                                        decimal mealsQuantity = 0;
                                        decimal motelQuantity = 0;
                                        string employeeName = "";
                                        refId++;

                                        // Foreach original ProjectTime
                                        foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                        {
                                            employeeName = originalRow.EmployeeName;

                                            // Meal hours quantity
                                            if (!originalRow.IsMealsCountryNull())
                                            {
                                                if (originalRow.MealsAllowance > 0)
                                                {
                                                    mealsQuantity++;
                                                }
                                            }

                                            double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                            if (acumPeriod > overtimeByCountry)
                                            {
                                                overtime = overtime + originalRow.ProjectTime;
                                            }
                                            else
                                            {
                                                double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                                if (newAcumPeriod > overtimeByCountry)
                                                {
                                                    overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                                    lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                                }
                                                else
                                                {
                                                    lhQuantity = lhQuantity + originalRow.ProjectTime;
                                                }
                                            }
                                        }

                                        if (lhQuantity > 0)
                                        {
                                            ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                            if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                            {
                                                if (jobClassType_ != "Regular Rate")
                                                {
                                                    decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                    GetEmployeeDataFairWage(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate);
                                                }
                                                else
                                                {
                                                    GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow); // Is same to non fair wage project
                                                }
                                            }
                                            else
                                            {
                                                GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow); // Is same to non fair wage project
                                            }

                                            newRow.CostingSheetID = 0;
                                            newRow.Work_ = work_;
                                            newRow.EmployeeID = employeeListRow.EmployeeID;
                                            newRow.RefID = refId;
                                            newRow.LHQuantity = lhQuantity;
                                            newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                            if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                            if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                            newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                            newRow.MotelCostCad = 0;
                                            newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                            newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                            newRow.MotelCostUsd = 0;
                                            newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                            newRow.Deleted = false;
                                            newRow.InDatabase = false;
                                            newRow.COMPANY_ID = companyId;
                                            newRow.Name = employeeName;
                                            newRow.StartDate = newStartDate;
                                            newRow.EndDate = newEndDate;
                                            newRow.FromDatabase = true;
                                            newRow.Function_ = functionListRow.Function_;
                                            newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                            newRow.Month = month;
                                            newRow.ClientName = clientName;
                                            newRow.ProjectName = projectName;
                                            ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                        }

                                        if (overtime > 0)
                                        {
                                            refId++;
                                            ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                            if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                            {
                                                if (jobClassType_ != "Regular Rate")
                                                {
                                                    decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                    GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate);
                                                }
                                                else
                                                {
                                                    GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                                }
                                            }
                                            else
                                            {
                                                GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                            }

                                            newRowOt.CostingSheetID = 0;
                                            newRowOt.Work_ = work_;
                                            newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                            newRowOt.RefID = refId;
                                            newRowOt.LHQuantity = overtime;
                                            newRowOt.MealsQuantity = 0;
                                            newRowOt.MealsUnitOfMeasurement = "";
                                            newRowOt.MotelUnitOfMeasurement = "";
                                            newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                            newRowOt.MotelCostCad = 0;
                                            newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2));
                                            newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                            newRowOt.MotelCostUsd = 0;
                                            newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2));
                                            newRowOt.Deleted = false;
                                            newRowOt.InDatabase = false;
                                            newRowOt.COMPANY_ID = companyId;
                                            newRowOt.Name = employeeName + " - Overtime";
                                            newRowOt.StartDate = newStartDate;
                                            newRowOt.EndDate = newEndDate;
                                            newRowOt.FromDatabase = true;
                                            newRowOt.Function_ = functionListRow.Function_;
                                            newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                            newRowOt.Month = month;
                                            newRowOt.ClientName = clientName;
                                            newRowOt.ProjectName = projectName;
                                            ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                        }
                                    }

                                    newStartDate = newEndDate.AddDays(1);
                                }

                                if (newEndDate <= endDate)
                                {
                                    ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                                    projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, newStartDate, endDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID);

                                    if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                                    {
                                        double lhQuantity = 0;
                                        double overtime = 0;
                                        decimal mealsQuantity = 0;
                                        decimal motelQuantity = 0;
                                        string employeeName = "";
                                        refId++;

                                        foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                        {
                                            employeeName = originalRow.EmployeeName;

                                            // Meal hours quantity
                                            if (!originalRow.IsMealsCountryNull())
                                            {
                                                if (originalRow.MealsAllowance > 0)
                                                {
                                                    mealsQuantity++;
                                                }
                                            }

                                            double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                            if (acumPeriod > overtimeByCountry)
                                            {
                                                overtime = overtime + originalRow.ProjectTime;
                                            }
                                            else
                                            {
                                                double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                                if (newAcumPeriod > overtimeByCountry)
                                                {
                                                    overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                                    lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                                }
                                                else
                                                {
                                                    lhQuantity = lhQuantity + originalRow.ProjectTime;
                                                }
                                            }
                                        }

                                        if (lhQuantity > 0)
                                        {
                                            ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                            if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                            {
                                                if (jobClassType_ != "Regular Rate")
                                                {
                                                    decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                    GetEmployeeDataFairWage(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate);
                                                }
                                                else
                                                {
                                                    GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                                }
                                            }
                                            else
                                            {
                                                GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                            }
                                            newRow.CostingSheetID = 0;
                                            newRow.Work_ = work_;
                                            newRow.EmployeeID = employeeListRow.EmployeeID;
                                            newRow.RefID = refId;
                                            newRow.LHQuantity = lhQuantity;
                                            newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                            if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                            if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                            newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                            newRow.MotelCostCad = 0;
                                            newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                            newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                            newRow.MotelCostUsd = 0;
                                            newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                            newRow.Deleted = false;
                                            newRow.InDatabase = false;
                                            newRow.COMPANY_ID = companyId;
                                            newRow.Name = employeeName;
                                            newRow.StartDate = newStartDate;
                                            newRow.EndDate = endDate;
                                            newRow.FromDatabase = true;
                                            newRow.Function_ = functionListRow.Function_;
                                            newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                            newRow.Month = month;
                                            newRow.ClientName = clientName;
                                            newRow.ProjectName = projectName;
                                            ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                        }

                                        if (overtime > 0)
                                        {
                                            refId++;
                                            ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                            if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                            {
                                                if (jobClassType_ != "Regular Rate")
                                                {
                                                    decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                    GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate);
                                                }
                                                else
                                                {
                                                    GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                                }
                                            }
                                            else
                                            {
                                                GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                            }

                                            newRowOt.CostingSheetID = 0;
                                            newRowOt.Work_ = work_;
                                            newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                            newRowOt.RefID = refId;
                                            newRowOt.LHQuantity = overtime;
                                            newRowOt.MealsQuantity = 0;
                                            newRowOt.MealsUnitOfMeasurement = "";
                                            newRowOt.MotelUnitOfMeasurement = "";
                                            newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                            newRowOt.MotelCostCad = 0;
                                            newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2));
                                            newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                            newRowOt.MotelCostUsd = 0;
                                            newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2));
                                            newRowOt.Deleted = false;
                                            newRowOt.InDatabase = false;
                                            newRowOt.COMPANY_ID = companyId;
                                            newRowOt.Name = employeeName + " - Overtime";
                                            newRowOt.StartDate = newStartDate;
                                            newRowOt.EndDate = endDate;
                                            newRowOt.FromDatabase = true;
                                            newRowOt.Function_ = functionListRow.Function_;
                                            newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                            newRowOt.Month = month;
                                            newRowOt.ClientName = clientName;
                                            newRowOt.ProjectName = projectName;
                                            ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                                projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, startDate, endDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID);

                                if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                                {
                                    double lhQuantity = 0;
                                    double overtime = 0;
                                    decimal mealsQuantity = 0;
                                    decimal motelQuantity = 0;
                                    string employeeName = "";
                                    refId++;

                                    foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                    {
                                        employeeName = originalRow.EmployeeName;

                                        // Meal hours quantity
                                        if (!originalRow.IsMealsCountryNull())
                                        {
                                            if (originalRow.MealsAllowance > 0)
                                            {
                                                mealsQuantity++;
                                            }
                                        }

                                        double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                        if (acumPeriod > overtimeByCountry)
                                        {
                                            overtime = overtime + originalRow.ProjectTime;
                                        }
                                        else
                                        {
                                            double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                            if (newAcumPeriod > overtimeByCountry)
                                            {
                                                overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                                lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                            }
                                            else
                                            {
                                                lhQuantity = lhQuantity + originalRow.ProjectTime;
                                            }
                                        }
                                    }

                                    if (lhQuantity > 0)
                                    {
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                        {
                                            if (jobClassType_ != "Regular Rate")
                                            {
                                                decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                GetEmployeeDataFairWage(startDate, endDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate);
                                            }
                                            else
                                            {
                                                GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                            }
                                        }
                                        else
                                        {
                                            GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                        }
                                        newRow.CostingSheetID = 0;
                                        newRow.Work_ = work_;
                                        newRow.EmployeeID = employeeListRow.EmployeeID;
                                        newRow.RefID = refId;
                                        newRow.LHQuantity = lhQuantity;
                                        newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                        if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                        if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                        newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRow.MotelCostCad = 0;
                                        newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                        newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRow.MotelCostUsd = 0;
                                        newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                        newRow.Deleted = false;
                                        newRow.InDatabase = false;
                                        newRow.COMPANY_ID = companyId;
                                        newRow.Name = employeeName;
                                        newRow.StartDate = startDate;
                                        newRow.EndDate = endDate;
                                        newRow.FromDatabase = true;
                                        newRow.Function_ = functionListRow.Function_;
                                        newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRow.Month = month;
                                        newRow.ClientName = clientName;
                                        newRow.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                    }

                                    if (overtime > 0)
                                    {
                                        refId++;
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_))
                                        {
                                            if (jobClassType_ != "Regular Rate")
                                            {
                                                decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_);

                                                GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate);
                                            }
                                            else
                                            {
                                                GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                            }
                                        }
                                        else
                                        {
                                            GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project
                                        }

                                        newRowOt.CostingSheetID = 0;
                                        newRowOt.Work_ = work_;
                                        newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                        newRowOt.RefID = refId;
                                        newRowOt.LHQuantity = overtime;
                                        newRowOt.MealsQuantity = 0;
                                        newRowOt.MealsUnitOfMeasurement = "";
                                        newRowOt.MotelUnitOfMeasurement = "";
                                        newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRowOt.MotelCostCad = 0;
                                        newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2));
                                        newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRowOt.MotelCostUsd = 0;
                                        newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2));
                                        newRowOt.Deleted = false;
                                        newRowOt.InDatabase = false;
                                        newRowOt.COMPANY_ID = companyId;
                                        newRowOt.Name = employeeName + " - Overtime";
                                        newRowOt.StartDate = startDate;
                                        newRowOt.EndDate = endDate;
                                        newRowOt.FromDatabase = true;
                                        newRowOt.Function_ = functionListRow.Function_;
                                        newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRowOt.Month = month;
                                        newRowOt.ClientName = clientName;
                                        newRowOt.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Load
        /// </summary>
        /// <param name="works">works</param>
        /// <param name="projectId">projectId</param>
        /// <param name="startDate">startDate</param>
        /// <param name="endDate">endDate</param>
        /// <param name="companyId">companyId</param>
        public void Load(ArrayList works, int projectId, DateTime startDate, DateTime endDate, int companyId)
        {
            int refId = 0;

            // Foreach of Works (FLL, RA, JL, PR, MH Rehab, MOB, Other)
            foreach (string work_ in works)
            {
                // Load Functions by Work
                ProjectCostingSheetAddFunctionListGateway projectCostingSheetAddFunctionListGateway = new ProjectCostingSheetAddFunctionListGateway();
                projectCostingSheetAddFunctionListGateway.LoadByWork_(work_);

                // Foreach of Functions
                foreach (ProjectCostingSheetAddTDS.FunctionListRow functionListRow in (ProjectCostingSheetAddTDS.FunctionListDataTable)projectCostingSheetAddFunctionListGateway.Table)
                {
                    ProjectCostingSheetAddUnitListGateway projectCostingSheetAddUnitListGateway = new ProjectCostingSheetAddUnitListGateway(Data);
                    projectCostingSheetAddUnitListGateway.LoadByProjectIdStartDateEndDateWorkFunction(projectId, startDate, endDate, work_, functionListRow.Function_, companyId);

                    foreach (ProjectCostingSheetAddTDS.UnitListRow unitListRow in (ProjectCostingSheetAddTDS.UnitListDataTable)projectCostingSheetAddUnitListGateway.Table)
                    {
                        DateTime newStartDate = new DateTime();
                        newStartDate = startDate;
                        DateTime newEndDate = new DateTime();
                        newEndDate = endDate;

                        ProjectCostingSheetAddUnitPayPeriodGateway ProjectCostingSheetAddUnitPayPeriodGateway = new ProjectCostingSheetAddUnitPayPeriodGateway(Data);
                        ProjectCostingSheetAddUnitPayPeriodGateway.LoadByStartDateEndDateUnitId(startDate, endDate, unitListRow.UnitID);

                        if (ProjectCostingSheetAddUnitPayPeriodGateway.Table.Rows.Count > 0)
                        {
                            foreach (ProjectCostingSheetAddTDS.UnitPayPeriodRow unitPayPeriodRow in (ProjectCostingSheetAddTDS.UnitPayPeriodDataTable)ProjectCostingSheetAddUnitPayPeriodGateway.Table)
                            {
                                newEndDate = unitPayPeriodRow.Date_.AddDays(-1);

                                ProjectCostingSheetAddOriginalUnitGateway projectCostingSheetAddOriginalUnitGateway = new ProjectCostingSheetAddOriginalUnitGateway(Data);
                                projectCostingSheetAddOriginalUnitGateway.Load(projectId, newStartDate, newEndDate, work_, functionListRow.Function_, unitListRow.UnitID);

                                if (projectCostingSheetAddOriginalUnitGateway.Table.Rows.Count > 0)
                                {
                                    ArrayList days = new ArrayList();
                                    ArrayList daysTowed = new ArrayList();
                                    double quantity = 0;
                                    bool isTowedUnitId = false;

                                    PrintProjectCostingGateway verifGateway = new PrintProjectCostingGateway(new DataSet());

                                    foreach (ProjectCostingSheetAddTDS.OriginalUnitRow originalUnitRow in (ProjectCostingSheetAddTDS.OriginalUnitDataTable)projectCostingSheetAddOriginalUnitGateway.Table)
                                    {
                                        int towedUnitId = 0;
                                        if (!originalUnitRow.IsTowedUnitIDNull())
                                        {
                                            towedUnitId = Convert.ToInt32(originalUnitRow.TowedUnitID);
                                        }
                                        if (originalUnitRow.UnitID != towedUnitId)
                                        {
                                            if (!days.Contains(originalUnitRow.Date_))
                                            {
                                                int amountProjects = verifGateway.UnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountProjects > 1)
                                                {
                                                    double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                    int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }
                                                else
                                                {
                                                    double tempQuantity = 1;

                                                    int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }

                                                days.Add(originalUnitRow.Date_);
                                            }
                                        }
                                        else
                                        {
                                            isTowedUnitId = true;

                                            if (!daysTowed.Contains(originalUnitRow.Date_))
                                            {
                                                int amountProjects = verifGateway.TowedUnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountProjects > 1)
                                                {
                                                    double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                    int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }
                                                else
                                                {
                                                    double tempQuantity = 1;

                                                    int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }

                                                daysTowed.Add(originalUnitRow.Date_);
                                            }
                                        }
                                    }

                                    ProjectCostingSheetAddTDS.UnitsInformationRow newRow = ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).NewUnitsInformationRow();
                                    GetUnitData(newStartDate, newEndDate, unitListRow.UnitID, work_, newRow, isTowedUnitId);
                                    newRow.CostingSheetID = 0;
                                    newRow.Work_ = work_;
                                    newRow.UnitID = unitListRow.UnitID;
                                    newRow.RefID = refId++;
                                    newRow.Quantity = quantity;
                                    newRow.TotalCostCad = (Convert.ToDecimal(quantity) * newRow.CostCad);
                                    newRow.TotalCostUsd = (Convert.ToDecimal(quantity) * newRow.CostUsd);
                                    newRow.Deleted = false;
                                    newRow.InDatabase = false;
                                    newRow.COMPANY_ID = companyId;
                                    newRow.UnitCode = unitListRow.UnitCode;
                                    newRow.UnitDescription = unitListRow.Description;
                                    newRow.UnitOfMeasurement = unitListRow.UnitOfMeasurement;
                                    newRow.StartDate = newStartDate;
                                    newRow.EndDate = newEndDate;
                                    newRow.FromDatabase = true;
                                    newRow.Function_ = functionListRow.Function_;
                                    newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                    ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).AddUnitsInformationRow(newRow);
                                }

                                newStartDate = newEndDate.AddDays(1);
                            }

                            if (newEndDate <= endDate)
                            {
                                ProjectCostingSheetAddOriginalUnitGateway projectCostingSheetAddOriginalUnitGateway = new ProjectCostingSheetAddOriginalUnitGateway(Data);
                                projectCostingSheetAddOriginalUnitGateway.Load(projectId, newStartDate, endDate, work_, functionListRow.Function_, unitListRow.UnitID);

                                if (projectCostingSheetAddOriginalUnitGateway.Table.Rows.Count > 0)
                                {
                                    ArrayList days = new ArrayList();
                                    ArrayList daysTowed = new ArrayList();
                                    double quantity = 0;
                                    bool isTowedUnitId = false;

                                    PrintProjectCostingGateway verifGateway = new PrintProjectCostingGateway(new DataSet());

                                    foreach (ProjectCostingSheetAddTDS.OriginalUnitRow originalUnitRow in (ProjectCostingSheetAddTDS.OriginalUnitDataTable)projectCostingSheetAddOriginalUnitGateway.Table)
                                    {
                                        int towedUnitId = 0;
                                        if (!originalUnitRow.IsTowedUnitIDNull())
                                        {
                                            towedUnitId = Convert.ToInt32(originalUnitRow.TowedUnitID);
                                        }
                                        if (originalUnitRow.UnitID != towedUnitId)
                                        {
                                            if (!days.Contains(originalUnitRow.Date_))
                                            {
                                                int amountProjects = verifGateway.UnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountProjects > 1)
                                                {
                                                    double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                    int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }
                                                else
                                                {
                                                    double tempQuantity = 1;

                                                    int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }

                                                days.Add(originalUnitRow.Date_);
                                            }
                                        }
                                        else
                                        {
                                            isTowedUnitId = true;

                                            if (!daysTowed.Contains(originalUnitRow.Date_))
                                            {
                                                int amountProjects = verifGateway.TowedUnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountProjects > 1)
                                                {
                                                    double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                    int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }
                                                else
                                                {
                                                    double tempQuantity = 1;

                                                    int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                    if (amountFunctions > 0)
                                                    {
                                                        tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                    }

                                                    quantity = quantity + tempQuantity;
                                                }

                                                daysTowed.Add(originalUnitRow.Date_);
                                            }
                                        }
                                    }

                                    ProjectCostingSheetAddTDS.UnitsInformationRow newRow = ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).NewUnitsInformationRow();
                                    GetUnitData(newStartDate, endDate, unitListRow.UnitID, work_, newRow, isTowedUnitId);
                                    newRow.CostingSheetID = 0;
                                    newRow.Work_ = work_;
                                    newRow.UnitID = unitListRow.UnitID;
                                    newRow.RefID = refId++;
                                    newRow.Quantity = quantity;
                                    newRow.TotalCostCad = (Convert.ToDecimal(quantity) * newRow.CostCad);
                                    newRow.TotalCostUsd = (Convert.ToDecimal(quantity) * newRow.CostUsd);
                                    newRow.Deleted = false;
                                    newRow.InDatabase = false;
                                    newRow.COMPANY_ID = companyId;
                                    newRow.UnitCode = unitListRow.UnitCode;
                                    newRow.UnitDescription = unitListRow.Description;
                                    newRow.UnitOfMeasurement = unitListRow.UnitOfMeasurement;
                                    newRow.StartDate = newStartDate;
                                    newRow.EndDate = endDate;
                                    newRow.FromDatabase = true;
                                    newRow.Function_ = functionListRow.Function_;
                                    newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                    ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).AddUnitsInformationRow(newRow);
                                }
                            }
                        }
                        else
                        {
                            ProjectCostingSheetAddOriginalUnitGateway projectCostingSheetAddOriginalUnitGateway = new ProjectCostingSheetAddOriginalUnitGateway(Data);
                            projectCostingSheetAddOriginalUnitGateway.Load(projectId, startDate, endDate, work_, functionListRow.Function_, unitListRow.UnitID);

                            if (projectCostingSheetAddOriginalUnitGateway.Table.Rows.Count > 0)
                            {
                                ArrayList days = new ArrayList();
                                ArrayList daysTowed = new ArrayList();
                                double quantity = 0;
                                bool isTowedUnitId = false;

                                PrintProjectCostingGateway verifGateway = new PrintProjectCostingGateway(new DataSet());

                                foreach (ProjectCostingSheetAddTDS.OriginalUnitRow originalUnitRow in (ProjectCostingSheetAddTDS.OriginalUnitDataTable)projectCostingSheetAddOriginalUnitGateway.Table)
                                {
                                    int towedUnitId = 0; if (!originalUnitRow.IsTowedUnitIDNull()) towedUnitId = Convert.ToInt32(originalUnitRow.TowedUnitID);
                                    if (originalUnitRow.UnitID != towedUnitId)
                                    {
                                        if (!days.Contains(originalUnitRow.Date_))
                                        {
                                            int amountProjects = verifGateway.UnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                            if (amountProjects > 1)
                                            {
                                                double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountFunctions > 0)
                                                {
                                                    tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                }

                                                quantity = quantity + tempQuantity;
                                            }
                                            else
                                            {
                                                double tempQuantity = 1;

                                                int amountFunctions = verifGateway.UnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountFunctions > 0)
                                                {
                                                    tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                }

                                                quantity = quantity + tempQuantity;
                                            }

                                            days.Add(originalUnitRow.Date_);
                                        }
                                    }
                                    else
                                    {
                                        isTowedUnitId = true;

                                        if (!daysTowed.Contains(originalUnitRow.Date_))
                                        {
                                            int amountProjects = verifGateway.TowedUnitSameDayUseSeveralProjects(originalUnitRow.Date_, originalUnitRow.UnitID);

                                            if (amountProjects > 1)
                                            {
                                                double tempQuantity = 1 / Convert.ToDouble(amountProjects);

                                                int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountFunctions > 0)
                                                {
                                                    tempQuantity = tempQuantity / Convert.ToDouble(amountFunctions);
                                                }

                                                quantity = quantity + tempQuantity;
                                            }
                                            else
                                            {
                                                double tempQuantity = 1;

                                                int amountFunctions = verifGateway.TowedUnitSameDayUseSeveralWorkFunctions(projectId, originalUnitRow.Date_, originalUnitRow.UnitID);

                                                if (amountFunctions > 0)
                                                {
                                                    tempQuantity = 1 / Convert.ToDouble(amountFunctions);
                                                }

                                                quantity = quantity + tempQuantity;
                                            }

                                            daysTowed.Add(originalUnitRow.Date_);
                                        }
                                    }
                                }

                                ProjectCostingSheetAddTDS.UnitsInformationRow newRow = ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).NewUnitsInformationRow();
                                GetUnitData(startDate, endDate, unitListRow.UnitID, work_, newRow, isTowedUnitId);
                                newRow.CostingSheetID = 0;
                                newRow.Work_ = work_;
                                newRow.UnitID = unitListRow.UnitID;
                                newRow.RefID = refId++;
                                newRow.Quantity = quantity;
                                newRow.TotalCostCad = (Convert.ToDecimal(quantity) * newRow.CostCad);
                                newRow.TotalCostUsd = (Convert.ToDecimal(quantity) * newRow.CostUsd);
                                newRow.Deleted = false;
                                newRow.InDatabase = false;
                                newRow.COMPANY_ID = companyId;
                                newRow.UnitCode = unitListRow.UnitCode;
                                newRow.UnitDescription = unitListRow.Description;
                                newRow.UnitOfMeasurement = unitListRow.UnitOfMeasurement;
                                newRow.StartDate = startDate;
                                newRow.EndDate = endDate;
                                newRow.FromDatabase = true;
                                newRow.Function_ = functionListRow.Function_;
                                newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                ((ProjectCostingSheetAddTDS.UnitsInformationDataTable)Table).AddUnitsInformationRow(newRow);
                            }
                        }
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Load
        /// </summary>
        /// <param name="works">works</param>
        /// <param name="projectId">projectId</param>
        /// <param name="startDate">startDate</param>
        /// <param name="endDate">endDate</param>
        /// <param name="companyId">companyId</param>
        public void Load(ArrayList works, int projectId, DateTime startDate, DateTime endDate, int companyId, string month)
        {
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            string projectName = projectGateway.GetName(projectId);

            int clientId = projectGateway.GetClientID(projectId);
            CompaniesGateway companiesGateway = new CompaniesGateway();
            companiesGateway.LoadAllByCompaniesId(clientId, companyId);
            string clientName = companiesGateway.GetName(clientId);

            // General vars
            int overtimeByCountry = 40; //Default for USA Projects
            int refId = GetNewRefId();

            // Foreach of Works (FLL, RA, JL, PR, MH Rehab, MOB, Other)
            foreach (string work_ in works)
            {
                // Load Functions by Work
                ProjectCostingSheetAddFunctionListGateway projectCostingSheetAddFunctionListGateway = new ProjectCostingSheetAddFunctionListGateway();
                projectCostingSheetAddFunctionListGateway.LoadByWork_(work_);

                // Foreach of Functions
                foreach (ProjectCostingSheetAddTDS.FunctionListRow functionListRow in (ProjectCostingSheetAddTDS.FunctionListDataTable)projectCostingSheetAddFunctionListGateway.Table)
                {
                    // Load Employees by ProjectId, StartDate, EndDate, Work
                    ProjectCostingSheetAddEmployeeListGateway projectCostingSheetAddEmployeeListGateway = new ProjectCostingSheetAddEmployeeListGateway(Data);
                    projectCostingSheetAddEmployeeListGateway.LoadByProjectIdStartDateEndDateWorkFunction(projectId, startDate, endDate, work_, functionListRow.Function_, companyId);

                    foreach (ProjectCostingSheetAddTDS.EmployeeListRow employeeListRow in (ProjectCostingSheetAddTDS.EmployeeListDataTable)projectCostingSheetAddEmployeeListGateway.Table)
                    {
                        DateTime newStartDate = new DateTime();
                        newStartDate = startDate;
                        DateTime newEndDate = new DateTime();
                        newEndDate = endDate;

                        //If Project is from Canada we get overtime
                        if (projectGateway.GetCountryID(projectId) == 1)
                        {
                            //Get Category of Employee
                            EmployeeGateway employeeGateway = new EmployeeGateway();
                            employeeGateway.LoadByEmployeeId(employeeListRow.EmployeeID);

                            switch (employeeGateway.GetCategory(employeeListRow.EmployeeID))
                            {
                                case "Special Forces":
                                    overtimeByCountry = 50;
                                    break;

                                case "Field":
                                    overtimeByCountry = 50;
                                    break;

                                case "Field 44":
                                    overtimeByCountry = 44;
                                    break;

                                case "Office/Admin":
                                    overtimeByCountry = 44;
                                    break;

                                case "Mechanic/Manufactoring":
                                    overtimeByCountry = 44;
                                    break;
                            }
                        }

                        ProjectCostingSheetAddEmployeePayPeriodGateway projectCostingSheetAddEmployeePayPeriodGateway = new ProjectCostingSheetAddEmployeePayPeriodGateway(Data);
                        projectCostingSheetAddEmployeePayPeriodGateway.LoadByStartDateEndDateEmployeeId(startDate, endDate, employeeListRow.EmployeeID);

                        if (projectCostingSheetAddEmployeePayPeriodGateway.Table.Rows.Count > 0)
                        {
                            foreach (ProjectCostingSheetAddTDS.EmployeePayPeriodRow employeePayPeriodRow in (ProjectCostingSheetAddTDS.EmployeePayPeriodDataTable)projectCostingSheetAddEmployeePayPeriodGateway.Table)
                            {
                                newEndDate = employeePayPeriodRow.Date_.AddDays(-1);

                                ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                                projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, newStartDate, newEndDate, work_, functionListRow.Function_, employeeListRow.EmployeeID);

                                if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                                {
                                    double lhQuantity = 0;
                                    double overtime = 0;
                                    decimal mealsQuantity = 0;
                                    decimal motelQuantity = 0;
                                    string employeeName = "";
                                    refId++;

                                    foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                    {
                                        employeeName = originalRow.EmployeeName;

                                        // Meal hours quantity
                                        if (!originalRow.IsMealsCountryNull())
                                        {
                                            if (originalRow.MealsAllowance > 0)
                                            {
                                                mealsQuantity++;
                                            }
                                        }

                                        double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                        if (acumPeriod > overtimeByCountry)
                                        {
                                            overtime = overtime + originalRow.ProjectTime;
                                        }
                                        else
                                        {
                                            double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                            if (newAcumPeriod > overtimeByCountry)
                                            {
                                                overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                                lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                            }
                                            else
                                            {
                                                lhQuantity = lhQuantity + originalRow.ProjectTime;
                                            }
                                        }
                                    }

                                    if (lhQuantity > 0)
                                    {
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow);// ... Get Costs
                                        newRow.CostingSheetID = 0;
                                        newRow.Work_ = work_;
                                        newRow.EmployeeID = employeeListRow.EmployeeID;
                                        newRow.RefID = refId;
                                        newRow.LHQuantity = lhQuantity;
                                        newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                        if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                        if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                        newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRow.MotelCostCad = 0;
                                        newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                        newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRow.MotelCostUsd = 0;
                                        newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                        newRow.Deleted = false;
                                        newRow.InDatabase = false;
                                        newRow.COMPANY_ID = companyId;
                                        newRow.Name = employeeName;
                                        newRow.StartDate = newStartDate;
                                        newRow.EndDate = newEndDate;
                                        newRow.FromDatabase = true;
                                        newRow.Function_ = functionListRow.Function_;
                                        newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRow.Month = month;
                                        newRow.ClientName = clientName;
                                        newRow.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                    }

                                    if (overtime > 0)
                                    {
                                        refId++;
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime
                                        newRowOt.CostingSheetID = projectId;
                                        newRowOt.Work_ = work_;
                                        newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                        newRowOt.RefID = refId;
                                        newRowOt.LHQuantity = overtime;
                                        newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data
                                        mealsQuantity = 0;
                                        motelQuantity = 0;
                                        newRowOt.MealsUnitOfMeasurement = "";
                                        newRowOt.MotelUnitOfMeasurement = "";
                                        newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRowOt.MotelCostCad = 0;
                                        newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2));
                                        newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRowOt.MotelCostUsd = 0;
                                        newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2));
                                        newRowOt.Deleted = false;
                                        newRowOt.InDatabase = false;
                                        newRowOt.COMPANY_ID = companyId;
                                        newRowOt.Name = employeeName + " - Overtime";
                                        newRowOt.StartDate = newStartDate;
                                        newRowOt.EndDate = newEndDate;
                                        newRowOt.FromDatabase = true;
                                        newRowOt.Function_ = functionListRow.Function_;
                                        newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRowOt.Month = month;
                                        newRowOt.ClientName = clientName;
                                        newRowOt.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                    }
                                }

                                newStartDate = newEndDate.AddDays(1);
                            }

                            if (newEndDate <= endDate)
                            {
                                ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                                projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, newStartDate, endDate, work_, functionListRow.Function_, employeeListRow.EmployeeID);

                                if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                                {
                                    double lhQuantity = 0;
                                    double overtime = 0;
                                    decimal mealsQuantity = 0;
                                    decimal motelQuantity = 0;
                                    string employeeName = "";
                                    refId++;

                                    foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                    {
                                        employeeName = originalRow.EmployeeName;

                                        // Meal hours quantity
                                        if (!originalRow.IsMealsCountryNull())
                                        {
                                            if (originalRow.MealsAllowance > 0)
                                            {
                                                mealsQuantity++;
                                            }
                                        }

                                        double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                        if (acumPeriod > overtimeByCountry)
                                        {
                                            overtime = overtime + originalRow.ProjectTime;
                                        }
                                        else
                                        {
                                            double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                            if (newAcumPeriod > overtimeByCountry)
                                            {
                                                overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                                lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                            }
                                            else
                                            {
                                                lhQuantity = lhQuantity + originalRow.ProjectTime;
                                            }
                                        }
                                    }

                                    if (lhQuantity > 0)
                                    {
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                        newRow.CostingSheetID = 0;
                                        newRow.Work_ = work_;
                                        newRow.EmployeeID = employeeListRow.EmployeeID;
                                        newRow.RefID = refId;
                                        newRow.LHQuantity = lhQuantity;
                                        newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                        if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                        if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                        newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRow.MotelCostCad = 0;
                                        newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                        newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRow.MotelCostUsd = 0;
                                        newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                        newRow.Deleted = false;
                                        newRow.InDatabase = false;
                                        newRow.COMPANY_ID = companyId;
                                        newRow.Name = employeeName;
                                        newRow.StartDate = newStartDate;
                                        newRow.EndDate = endDate;
                                        newRow.FromDatabase = true;
                                        newRow.Function_ = functionListRow.Function_;
                                        newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRow.Month = month;
                                        newRow.ClientName = clientName;
                                        newRow.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                    }

                                    if (overtime > 0)
                                    {
                                        refId++;
                                        ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                        GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime
                                        newRowOt.CostingSheetID = 0;
                                        newRowOt.Work_ = work_;
                                        newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                        newRowOt.RefID = refId;
                                        newRowOt.LHQuantity = overtime;
                                        newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data
                                        mealsQuantity = 0;
                                        motelQuantity = 0;
                                        newRowOt.MealsUnitOfMeasurement = "";
                                        newRowOt.MotelUnitOfMeasurement = "";
                                        newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                        newRowOt.MotelCostCad = 0;
                                        newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2));
                                        newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                        newRowOt.MotelCostUsd = 0;
                                        newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2));
                                        newRowOt.Deleted = false;
                                        newRowOt.InDatabase = false;
                                        newRowOt.COMPANY_ID = companyId;
                                        newRowOt.Name = employeeName + " - Overtime";
                                        newRowOt.StartDate = newStartDate;
                                        newRowOt.EndDate = endDate;
                                        newRowOt.FromDatabase = true;
                                        newRowOt.Function_ = functionListRow.Function_;
                                        newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                        newRowOt.Month = month;
                                        newRowOt.ClientName = clientName;
                                        newRowOt.ProjectName = projectName;
                                        ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                    }
                                }
                            }
                        }
                        else
                        {
                            ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data);
                            projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, startDate, endDate, work_, functionListRow.Function_, employeeListRow.EmployeeID);

                            if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0)
                            {
                                double lhQuantity = 0;
                                double overtime = 0;
                                decimal mealsQuantity = 0;
                                decimal motelQuantity = 0;
                                string employeeName = "";
                                refId++;

                                foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table)
                                {
                                    employeeName = originalRow.EmployeeName;

                                    // Meal hours quantity
                                    if (!originalRow.IsMealsCountryNull())
                                    {
                                        if (originalRow.MealsAllowance > 0)
                                        {
                                            mealsQuantity++;
                                        }
                                    }

                                    double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID);

                                    if (acumPeriod > overtimeByCountry)
                                    {
                                        overtime = overtime + originalRow.ProjectTime;
                                    }
                                    else
                                    {
                                        double newAcumPeriod = acumPeriod + originalRow.ProjectTime;

                                        if (newAcumPeriod > overtimeByCountry)
                                        {
                                            overtime = overtime + (newAcumPeriod - overtimeByCountry);
                                            lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry));
                                        }
                                        else
                                        {
                                            lhQuantity = lhQuantity + originalRow.ProjectTime;
                                        }
                                    }
                                }

                                if (lhQuantity > 0)
                                {
                                    ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                    GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow);
                                    newRow.CostingSheetID = 0;
                                    newRow.Work_ = work_;
                                    newRow.EmployeeID = employeeListRow.EmployeeID;
                                    newRow.RefID = refId;
                                    newRow.LHQuantity = lhQuantity;
                                    newRow.MealsQuantity = Convert.ToInt32(mealsQuantity);
                                    if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = "";
                                    if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = "";
                                    newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                    newRow.MotelCostCad = 0;
                                    newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad);
                                    newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                    newRow.MotelCostUsd = 0;
                                    newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd);
                                    newRow.Deleted = false;
                                    newRow.InDatabase = false;
                                    newRow.COMPANY_ID = companyId;
                                    newRow.Name = employeeName;
                                    newRow.StartDate = startDate;
                                    newRow.EndDate = endDate;
                                    newRow.FromDatabase = true;
                                    newRow.Function_ = functionListRow.Function_;
                                    newRow.WorkFunction = work_ + " . " + functionListRow.Function_;
                                    newRow.Month = month;
                                    newRow.ClientName = clientName;
                                    newRow.ProjectName = projectName;
                                    ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow);
                                }

                                if (overtime > 0)
                                {
                                    refId++;
                                    ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow();
                                    GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime
                                    newRowOt.CostingSheetID = 0;
                                    newRowOt.Work_ = work_;
                                    newRowOt.EmployeeID = employeeListRow.EmployeeID;
                                    newRowOt.RefID = refId;
                                    newRowOt.LHQuantity = overtime;
                                    newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data
                                    mealsQuantity = 0;
                                    motelQuantity = 0;
                                    newRowOt.MealsUnitOfMeasurement = "";
                                    newRowOt.MotelUnitOfMeasurement = "";
                                    newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day");
                                    newRowOt.MotelCostCad = 0;
                                    newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2));
                                    newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day");
                                    newRowOt.MotelCostUsd = 0;
                                    newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2));
                                    newRowOt.Deleted = false;
                                    newRowOt.InDatabase = false;
                                    newRowOt.COMPANY_ID = companyId;
                                    newRowOt.Name = employeeName + " - Overtime";
                                    newRowOt.StartDate = startDate;
                                    newRowOt.EndDate = endDate;
                                    newRowOt.FromDatabase = true;
                                    newRowOt.Function_ = functionListRow.Function_;
                                    newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_;
                                    newRowOt.Month = month;
                                    newRowOt.ClientName = clientName;
                                    newRowOt.ProjectName = projectName;
                                    ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt);
                                }
                            }
                        }
                    }
                }
            }
        }