/// <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); } } } } } } } }
/// <summary> /// FillData2 /// </summary> private void FillData2() { PrintHoursForPayrollPeriodOriginalGateway originalGateway = new PrintHoursForPayrollPeriodOriginalGateway(Data); foreach (PrintHoursForPayrollPeriodTDS.OriginalRow originalRow in (PrintHoursForPayrollPeriodTDS.OriginalDataTable)originalGateway.Table) { PrintHoursForPayrollPeriodTDS.PrintHoursForPayrollPeriodRow newRow = ((PrintHoursForPayrollPeriodTDS.PrintHoursForPayrollPeriodDataTable)Table).NewPrintHoursForPayrollPeriodRow(); newRow.EmployeeID = originalRow.EmployeeID; newRow.EmployeeName = originalRow.EmployeeName; newRow.CountryID = originalRow.CountryID; newRow.CountryName = originalRow.CountryName; newRow.Date_ = originalRow.Date_; newRow.ProjectName = originalRow.ProjectName; if (!originalRow.IsWork_Null()) newRow.Work_ = originalRow.Work_; else newRow.SetWork_Null(); if (!originalRow.IsFunction_Null()) newRow.Function_ = originalRow.Function_; else newRow.SetFunction_Null(); if (!originalRow.IsStartTimeNull()) newRow.StartTime = originalRow.StartTime; else newRow.SetStartTimeNull(); if (!originalRow.IsEndTimeNull()) newRow.EndTime = originalRow.EndTime; else newRow.SetEndTimeNull(); if (!originalRow.IsOffsetNull()) newRow.Offset = originalRow.Offset; else newRow.SetOffsetNull(); newRow.FairWage = false; originalRow.FairWage = false; if (!originalRow.IsJobClassTypeNull()) newRow.JobClassType = originalRow.JobClassType; else newRow.JobClassType = " "; if (originalRow.CountryID == 1) { newRow.TimeCA = originalRow.ProjectTime; newRow.TimeUS = originalRow.ProjectTime; } else { newRow.TimeCA = originalRow.ProjectTime; newRow.TimeUS = originalRow.ProjectTime; } newRow.TimeFairWage = 0; newRow.TimeFairWageOt = 0; newRow.TimeMob = 0; newRow.TimeMobOt = 0; newRow.TimeStandard = 0; newRow.TimeStandardOt = 0; if (!originalRow.IsStartTimeNull() && !originalRow.IsEndTimeNull()) { if (originalRow.IsWork_Null()) originalRow.Work_ = ""; if (originalRow.IsFunction_Null()) originalRow.Function_ = ""; ProjectGateway projectGateway = new ProjectGateway(null); ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(); projectTimeGateway.LoadByProjectTimeId(originalRow.ProjectTimeID); if (projectGateway.IsFairWageProjectWorkFunction(projectTimeGateway.GetProjectId(originalRow.ProjectTimeID), originalRow.Work_, originalRow.Function_)) { newRow.FairWage = true; originalRow.FairWage = true; } int overtime = 40; //Default for USA // Canada if (originalRow.CountryID == 1) { switch (originalRow.Category) { case "Special Forces": overtime = 50; break; case "Field": overtime = 50; break; case "Field 44": overtime = 44; break; case "Office/Admin": overtime = 44; break; case "Mechanic/Manufactoring": overtime = 44; break; } if ((originalRow.Work_ == "Mobilization") && (originalRow.Function_ == "Prevail/Min Wage")) { double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtime) { newRow.TimeMob = 0; newRow.TimeMobOt = originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtime) { newRow.TimeMobOt = newAcumPeriod - overtime; newRow.TimeMob = originalRow.ProjectTime - newRow.TimeMobOt; } else { newRow.TimeMob = originalRow.ProjectTime; newRow.TimeMobOt = 0; } } } else { if ((originalRow.FairWage) && (originalRow.Work_ != "Mobilization")) { double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtime) { newRow.TimeFairWage = 0; newRow.TimeFairWageOt = originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtime) { newRow.TimeFairWageOt = newAcumPeriod - overtime; newRow.TimeFairWage = originalRow.ProjectTime - newRow.TimeFairWageOt; } else { newRow.TimeFairWage = originalRow.ProjectTime; newRow.TimeFairWageOt = 0; } } } else { double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtime) { newRow.TimeStandard = 0; newRow.TimeStandardOt = originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtime) { newRow.TimeStandardOt = newAcumPeriod - overtime; newRow.TimeStandard = originalRow.ProjectTime - newRow.TimeStandardOt; } else { newRow.TimeStandard = originalRow.ProjectTime; newRow.TimeStandardOt = 0; } } } } } else //USA { if ((originalRow.FairWage) && (originalRow.Work_ != "Mobilization")) { double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtime) { newRow.TimeFairWage = 0; newRow.TimeFairWageOt = originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtime) { newRow.TimeFairWageOt = newAcumPeriod - overtime; newRow.TimeFairWage = originalRow.ProjectTime - newRow.TimeFairWageOt; } else { newRow.TimeFairWage = originalRow.ProjectTime; newRow.TimeFairWageOt = 0; } } } else { double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtime) { newRow.TimeStandard = 0; newRow.TimeStandardOt = originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtime) { newRow.TimeStandardOt = newAcumPeriod - overtime; newRow.TimeStandard = originalRow.ProjectTime - newRow.TimeStandardOt; } else { newRow.TimeStandard = originalRow.ProjectTime; newRow.TimeStandardOt = 0; } } } } } if ((originalRow.WorkingDetails == "Sick Day") || (originalRow.WorkingDetails == "Holiday") || (originalRow.WorkingDetails == "Vacation / Other") || (originalRow.WorkingDetails == "Day Off - No Pay")) { newRow.WorkingDetails = originalRow.WorkingDetails; } else { newRow.WorkingDetails = ""; } newRow.ClientName = originalRow.ClientName; newRow.Location = originalRow.Location; if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsCountry == 1) { newRow.MealsCA = true; newRow.MealsUS = false; } else { newRow.MealsCA = false; newRow.MealsUS = true; } } else { newRow.MealsCA = false; newRow.MealsUS = false; } if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsCountry == 1) { newRow.TotalCA = originalRow.MealsAllowance; newRow.TotalUS = 0; } else { newRow.TotalCA = 0; newRow.TotalUS = originalRow.MealsAllowance; } } else { newRow.TotalCA = 0; newRow.TotalUS = 0; } if (!originalRow.IsProjectTimeStateNull()) { if (originalRow.ProjectTimeState == "Approved") { newRow.IsApproved = true; } else { newRow.IsApproved = false; } } else { newRow.IsApproved = false; } if (!originalRow.IsApprovedByNull()) { newRow.ApprovedBy = originalRow.ApprovedBy; } else { newRow.ApprovedBy = ""; } if (!originalRow.IsProjectTimeStateNull()) { string projectTimeState = originalRow.ProjectTimeState; if (projectTimeState == "Approved") { newRow.ProjectTimeState = originalRow.ApprovedBy; } else { newRow.ProjectTimeState = "--"; } } else { newRow.ProjectTimeState = "--"; } if (!originalRow.IsJobClassProjectTimeNull()) { string jobClassProjectTime = originalRow.JobClassProjectTime; switch (jobClassProjectTime) { case "Laborer Group 2": originalRow.JobClassProjectTime = "Lab 2"; break; case "Laborer Group 6": originalRow.JobClassProjectTime = "Lab 6"; break; case "Operator Group 1": originalRow.JobClassProjectTime = "Op 1"; break; case "Operator Group 2": originalRow.JobClassProjectTime = "Op 2"; break; case "Regular Rate": originalRow.JobClassProjectTime = "Reg Rate"; break; } } // Show or not Job Class Project Time if (!originalRow.IsWork_Null()) { if (originalRow.Work_ != "Mobilization") { if (!originalRow.IsJobClassProjectTimeNull()) { newRow.JobClassProjectTime = originalRow.JobClassProjectTime; } else { newRow.JobClassProjectTime = ""; } } else { newRow.JobClassProjectTime = ""; } } else { if (!originalRow.IsJobClassProjectTimeNull()) { newRow.JobClassProjectTime = originalRow.JobClassProjectTime; } else { newRow.JobClassProjectTime = ""; } } if (!originalRow.IsCommentsNull()) newRow.Comments = originalRow.Comments; else newRow.SetCommentsNull(); ((PrintHoursForPayrollPeriodTDS.PrintHoursForPayrollPeriodDataTable)Table).AddPrintHoursForPayrollPeriodRow(newRow); } }