private IEnumerable <LabourWeekDetail> LabourDetailsForWeek(string proj) { Dictionary <DateTime, LabourWeekDetail> labourDetailsByWeek = new Dictionary <DateTime, LabourWeekDetail>(); IEnumerable <Timesheet> timesheets = _timeSheetRepository.GetTimesheets().Where(r => r.Status.ToString().Equals("Approved")) .OrderByDescending(r => r.WeekStarting); foreach (Timesheet ts in timesheets) { if (!labourDetailsByWeek.ContainsKey(ts.WeekStarting.Date)) { LabourWeekDetail detail = _timesheetService.BuildLabourWeekDetails(ts, this.Rates, proj); if (detail.TotalCost > 0) { labourDetailsByWeek.Add(ts.WeekStarting.Date, detail); } } else { //Update the labout details that are present LabourWeekDetail detail = labourDetailsByWeek[ts.WeekStarting.Date]; detail.ammendDetails(_timesheetService.BuildLabourWeekDetails(ts, this.Rates, proj)); } } return(labourDetailsByWeek.Values.ToList <LabourWeekDetail>()); }
public LabourWeekDetail BuildLabourWeekDetails(Timesheet ts, List <LabourRate> Rates, string proj) { //Retrieve details from timesheet and populate the LabourWeekDetail object LabourWeekDetail detail = new LabourWeekDetail(proj, ts.WeekStarting); Dictionary <string, double> hoursPerDay = RetrieveBreakdownOfHoursPerDay(ts, proj); PopulateLabourDetail(ts, Rates, detail, hoursPerDay); return(detail); }
private void WriteRow(SheetData sheetData, LabourWeekDetail detail, int rowIndex) { Row row; row = new Row() { RowIndex = UInt32.Parse(rowIndex.ToString()) }; sheetData.Append(row); Cell weekCell = new Cell(); weekCell.CellValue = new CellValue(detail.Week.ToShortDateString()); weekCell.DataType = new EnumValue <CellValues>(CellValues.String); Cell superVisorCell = new Cell(); superVisorCell.CellValue = new CellValue(detail.SupervisorCost.ToString()); superVisorCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell chargeHandCell = new Cell(); chargeHandCell.CellValue = new CellValue(detail.ChargehandCost.ToString()); chargeHandCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell electrR1Cell = new Cell(); electrR1Cell.CellValue = new CellValue(detail.ElecR1Cost.ToString()); electrR1Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell electrR2Cell = new Cell(); electrR2Cell.CellValue = new CellValue(detail.ElecR2Cost.ToString()); electrR2Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell electrR3Cell = new Cell(); electrR3Cell.CellValue = new CellValue(detail.ElecR3Cost.ToString()); electrR3Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell loc1Cell = new Cell(); loc1Cell.CellValue = new CellValue(detail.Loc1Cost.ToString()); loc1Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell loc2Cell = new Cell(); loc2Cell.CellValue = new CellValue(detail.Loc2Cost.ToString()); loc2Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell loc3Cell = new Cell(); loc3Cell.CellValue = new CellValue(detail.Loc3Cost.ToString()); loc3Cell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell tempCell = new Cell(); tempCell.CellValue = new CellValue(detail.TempCost.ToString()); tempCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell firstYearCell = new Cell(); firstYearCell.CellValue = new CellValue(detail.FirstYearApprenticeCost.ToString()); firstYearCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell secondYearCell = new Cell(); secondYearCell.CellValue = new CellValue(detail.SecondYearApprenticeCost.ToString()); secondYearCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell thirdYearCell = new Cell(); thirdYearCell.CellValue = new CellValue(detail.ThirdYearApprenticeCost.ToString()); thirdYearCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell fourthYearCell = new Cell(); fourthYearCell.CellValue = new CellValue(detail.FourthYearApprenticeCost.ToString()); fourthYearCell.DataType = new EnumValue <CellValues>(CellValues.Number); Cell totalLabourCell = new Cell(); totalLabourCell.CellValue = new CellValue(detail.TotalCost.ToString()); totalLabourCell.DataType = new EnumValue <CellValues>(CellValues.Number); row.InsertAt(weekCell, 0); row.InsertAt(superVisorCell, 1); row.InsertAt(chargeHandCell, 2); row.InsertAt(electrR1Cell, 3); row.InsertAt(electrR2Cell, 4); row.InsertAt(electrR3Cell, 5); row.InsertAt(loc1Cell, 6); row.InsertAt(loc2Cell, 7); row.InsertAt(loc3Cell, 8); row.InsertAt(tempCell, 9); row.InsertAt(firstYearCell, 10); row.InsertAt(secondYearCell, 11); row.InsertAt(thirdYearCell, 12); row.InsertAt(fourthYearCell, 13); row.InsertAt(totalLabourCell, 14); }
private void PopulateLabourDetail(Timesheet ts, List <LabourRate> Rates, LabourWeekDetail detail, Dictionary <string, double> hoursPerDay) { double rate = GetRate(ts, Rates); foreach (var item in hoursPerDay) { double hoursWorked = item.Value; switch (ts.Role) { case "Administrator": detail.AdministratorCost += ((hoursWorked) * 10); break; case "Supervisor": detail.SupervisorCost += ((hoursWorked) * rate); break; case "ChargeHand": detail.ChargehandCost += ((hoursWorked) * rate); break; case "ElectR1": detail.ElecR1Cost += ((hoursWorked) * rate); break; case "ElectR2": detail.ElecR2Cost += ((hoursWorked) * rate); break; case "ElectR3": detail.ElecR3Cost += ((hoursWorked) * rate); break; case "Loc1": detail.Loc1Cost += ((hoursWorked) * rate); break; case "Loc2": detail.Loc2Cost += ((hoursWorked) * rate); break; case "Loc3": detail.Loc3Cost += ((hoursWorked) * rate); break; case "Temp": detail.TempCost += ((hoursWorked) * rate); break; case "First Year Apprentice": detail.FirstYearApprenticeCost += ((hoursWorked) * rate); break; case "Second Year Apprentice": detail.SecondYearApprenticeCost += ((hoursWorked) * rate); break; case "Third Year Apprentice": detail.ThirdYearApprenticeCost += ((hoursWorked) * rate); break; case "Fourth Year Apprentice": detail.FourthYearApprenticeCost += ((hoursWorked) * rate); break; default: break; } } }