private void UpdateBillRate(DataRow row) { foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Hours)) { decimal?billRate = ProjectWorkClass.GetBillRate(_headerRecord.ProjectId, timecode.MatchId, (string)row[colWorkClass.FieldName]); row[BillRateI(timecode)] = (object)billRate ?? DBNull.Value; if (row[colId.FieldName] != DBNull.Value) { LabourTimeDetail.SqlUpdateBillRate((int)row[colId.FieldName], timecode.MatchId, billRate); } } }
public void SetCurrent(LemHeader header) { _headerRecord = header; SetEnabled(_headerRecord.CheckEditable()); var changeOrderList = ChangeOrder.ListForProject(_headerRecord.ProjectId).Select(cs => new { EstimateId = cs.EstimateId, DisplayName = cs.DisplayName }).Distinct().ToList(); changeOrderList.Add(new { EstimateId = -1, DisplayName = "" }); luChangeOrder.DataSource = changeOrderList; tableLabour.Clear(); var list = LabourTimeEntry.GetLabourEntryList(header.Id).ToList(); list.ForEach(lte => { DataRow row = tableLabour.Rows.Add( lte.Id, lte.EmpNum, lte.EmpNum, lte.WorkClassCode, lte.ChangeOrderId, lte.Level1Id, lte.Level2Id, lte.Level3Id, lte.Level4Id, lte.Billable, lte.Manual, lte.IncludedHours, lte.TotalHours, lte.BillAmount); foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Hours)) { row[BillRateI(timecode)] = (object)ProjectWorkClass.GetBillRate(_headerRecord.ProjectId, timecode.MatchId, (string)row[colWorkClass.FieldName]) ?? DBNull.Value; row[EnterHoursI(timecode)] = (object)list.Find(x => x.Id == (int)row[colId.FieldName]).DetailList.SingleOrDefault(d => d.TimeCodeId == timecode.MatchId)?.WorkHours ?? DBNull.Value; } foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Dollars)) { row[EnterAmountI(timecode)] = (object)list.Find(x => x.Id == (int)row[colId.FieldName]).DetailList.SingleOrDefault(d => d.TimeCodeId == timecode.MatchId)?.Amount ?? DBNull.Value; } }); tableLabour.AcceptChanges(); gvLabour.BestFitColumns(true); }
public void SetCurrent(LemHeader header) { _headerRecord = header; tableLabour.Clear(); var table = LemHeader.GetEmployeeSummary(new List <int> { header.Id }); var list = table.Select().Select(r => new { EmpNum = Convert.ToInt32(r["EmpNum"]), WorkClassCode = Convert.ToString(r["WorkClassCode"]), ProjectId = Convert.ToInt32(r["ProjectId"]), TimeCodeId = Convert.ToInt32(r["TimeCodeId"]), SumWorkHour = ConvertEx.ToNullable <decimal>(r["SumWorkHour"]), SumAmount = ConvertEx.ToNullable <decimal>(r["SumAmount"]), }); var groupList = list.ToLookup(x => new { x.EmpNum, x.WorkClassCode, x.ProjectId, EmpName = Employee.GetEmployee(x.EmpNum)?.DisplayName, WorkClass = WorkClass.GetWorkClass(x.WorkClassCode).DisplayName }).OrderBy(x => x.Key.EmpName).ThenBy(x => x.Key.WorkClass).ToList(); groupList.ForEach(g => { var row = tableLabour.Rows.Add( g.Key.EmpNum, g.Key.EmpName, g.Key.WorkClass, null, null); decimal?billRate; decimal totalHours = 0; decimal billAmounts = 0; foreach (var timecode in TimeCode.ListForCompany()) { if (timecode.ValueType == EnumValueType.Hours) { billRate = ProjectWorkClass.GetBillRate(g.Key.ProjectId, timecode.MatchId, g.Key.WorkClassCode); row[BillRateI(timecode)] = (object)billRate ?? DBNull.Value; decimal hours = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumWorkHour) ?? 0; row[EnterValueI(timecode)] = hours != 0 ? (object)hours : DBNull.Value; totalHours += hours; billAmounts += (billRate ?? 0) * hours; } else { decimal amount = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumAmount) ?? 0; row[EnterValueI(timecode)] = amount != 0 ? (object)amount : DBNull.Value; billAmounts += amount; } row[colTotalHours.FieldName] = totalHours != 0 ? (object)totalHours : DBNull.Value; row[colBillAmount.FieldName] = billAmounts != 0 ? (object)billAmounts : DBNull.Value; } }); }
public void SetData(List <LemHeader> headerList) { tableLabour.Clear(); var table = LemHeader.GetCostCodeSummary(headerList.Select(x => x.Id).ToList()); var list = table.Select().Select(r => new { EmpNum = Convert.ToInt32(r["EmpNum"]), WorkClassCode = Convert.ToString(r["WorkClassCode"]), Billable = Convert.ToBoolean(r["Billable"]), ProjectId = Convert.ToInt32(r["ProjectId"]), ChangeOrderId = ConvertEx.ToNullable <int>(r["ChangeOrderId"]), Level1Id = ConvertEx.ToNullable <int>(r["Level1Id"]), Level2Id = ConvertEx.ToNullable <int>(r["Level2Id"]), Level3Id = ConvertEx.ToNullable <int>(r["Level3Id"]), Level4Id = ConvertEx.ToNullable <int>(r["Level4Id"]), TimeCodeId = Convert.ToInt32(r["TimeCodeId"]), SumWorkHour = ConvertEx.ToNullable <decimal>(r["SumWorkHour"]), SumAmount = ConvertEx.ToNullable <decimal>(r["SumAmount"]), }); var groupList = list.ToLookup(x => new { x.EmpNum, x.WorkClassCode, x.Billable, x.ProjectId, x.ChangeOrderId, x.Level1Id, x.Level2Id, x.Level3Id, x.Level4Id, EmpName = Employee.GetEmployee(x.EmpNum)?.DisplayName, WorkClass = WorkClass.GetWorkClass(x.WorkClassCode).DisplayName, Project = Project.GetProject(x.ProjectId), ChangeOrder = ChangeOrder.GetChangeOrder(x.ProjectId, x.ChangeOrderId)?.DisplayName, Level1 = LevelOneCode.GetLevelCode(x.Level1Id)?.DisplayName, Level2 = LevelTwoCode.GetLevelCode(x.Level2Id)?.DisplayName, Level3 = LevelThreeCode.GetLevelCode(x.Level3Id)?.DisplayName, Level4 = LevelFourCode.GetLevelCode(x.Level4Id)?.DisplayName }).OrderBy(x => x.Key.Level1).ThenBy(x => x.Key.Level2).ThenBy(x => x.Key.Level3).ThenBy(x => x.Key.Level4).ThenBy(x => x.Key.EmpName).ThenBy(x => x.Key.Project).ThenBy(x => x.Key.ChangeOrder).ThenBy(x => x.Key.WorkClass).ThenBy(x => x.Key.Billable).ToList(); groupList.ForEach(g => { DataRow row = tableLabour.Rows.Add( g.Key.EmpNum, g.Key.EmpName, g.Key.WorkClass, g.Key.Project, g.Key.ChangeOrder, g.Key.Level1, g.Key.Level2, g.Key.Level3, g.Key.Level4, g.Key.Billable, null, null); decimal?billRate; decimal totalHours = 0; decimal billAmounts = 0; foreach (var timecode in TimeCode.ListForCompany()) { if (timecode.ValueType == EnumValueType.Hours) { billRate = ProjectWorkClass.GetBillRate(g.Key.ProjectId, timecode.MatchId, g.Key.WorkClassCode); row[ColName.BillRateI(timecode)] = (object)billRate ?? DBNull.Value; decimal hours = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumWorkHour) ?? 0; row[ColName.EnterValueI(timecode)] = hours != 0 ? (object)hours : DBNull.Value; totalHours += hours; billAmounts += (billRate ?? 0) * hours; } else { decimal amount = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumAmount) ?? 0; row[ColName.EnterValueI(timecode)] = amount != 0 ? (object)amount : DBNull.Value; billAmounts += amount; } row[ColName.TotalHours] = totalHours != 0 ? (object)totalHours : DBNull.Value; row[ColName.BillAmount] = billAmounts != 0 ? (object)billAmounts : DBNull.Value; } }); }