Exemplo n.º 1
0
        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;
                }
            });
        }
Exemplo n.º 2
0
        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;
                }
            });
        }