public QuarterlyHeadcountComparisonRow(string service, QuarterInformation quarter, QuarterInformation comparisonQuarter, int comparisonYear, bool isGroupTypeRow = false, bool isTotalRow = false)
 {
     Service           = service;
     Quarter           = quarter;
     ComparisonQuarter = comparisonQuarter;
     ComparisonYear    = comparisonYear;
     IsGroupTypeRow    = isGroupTypeRow;
     IsTotalRow        = isTotalRow;
 }
 public QuarterlyHeadcountComparisonRow(QuarterInformation totalQuarter, QuarterInformation comparisonQuarterInformation, int comparisonYear)
 {
     Service           = "Total";
     Quarter           = totalQuarter;
     ComparisonQuarter = comparisonQuarterInformation;
     ComparisonYear    = comparisonYear;
     IsGroupTypeRow    = false;
     IsTotalRow        = true;
 }
        public static QuarterInformation GetQuarteredStatistics(Group @group, DateTime startDateTime, DateTime?endDateTime, Dictionary <int, Quarter> quarters)
        {
            decimal q1 = quarters[1].StartDateTime == null
                ? 0.0m
                : HeadCountHelper.GetHeadCountForGroup(@group.Guid, quarters[1].StartDateTime.Value,
                                                       quarters[1].EndDateTime.Value) ?? 0.0m;
            decimal q2 = quarters[2].StartDateTime == null
                ? 0.0m
                : HeadCountHelper.GetHeadCountForGroup(@group.Guid, quarters[2].StartDateTime.Value,
                                                       quarters[2].EndDateTime.Value) ?? 0.0m;
            decimal q3 = quarters[3].StartDateTime == null
                ? 0.0m
                : HeadCountHelper.GetHeadCountForGroup(@group.Guid, quarters[3].StartDateTime.Value,
                                                       quarters[3].EndDateTime.Value) ?? 0.0m;
            decimal q4 = quarters[4].StartDateTime == null
                ? 0.0m
                : HeadCountHelper.GetHeadCountForGroup(@group.Guid, quarters[4].StartDateTime.Value,
                                                       quarters[4].EndDateTime.Value) ?? 0.0m;
            decimal total          = q1 + q2 + q3 + q4;
            decimal average        = total / (endDateTime.Value.Month - startDateTime.Month + 1);
            var     quarterResults = new QuarterInformation(total, q1, q2, q3, q4, average);

            return(quarterResults);
        }
        private void CreateRowsForGroupType(GroupType groupType, List <QuarterlyHeadcountComparisonRow> rows)
        {
            int comparisonYear = ddlComparisonYear.SelectedValue.AsInteger();
            var groups         = new ChildCheckInGroupGenerator().Get(groupType);

            // Add row to mark group type
            var groupTypeTitleRow = new QuarterlyHeadcountComparisonRow(groupType.Name);

            rows.Add(groupTypeTitleRow);

            // Add row for each group in groupType
            var groupRows = new List <QuarterlyHeadcountComparisonRow>();

            groupRows.AddRange(
                groups.Select(
                    g =>
            {
                return(_statisticCalculator.Calculate(g, _startDateTime, _endDateTime,
                                                      comparisonYear));
            }));

            // Generate total row
            var totalQuarter = new QuarterInformation(groupRows.Sum(qi => qi.Quarter.YearTotal),
                                                      groupRows.Sum(qi => qi.Quarter.Q1Total), groupRows.Sum(qi => qi.Quarter.Q2Total),
                                                      groupRows.Sum(qi => qi.Quarter.Q3Total), groupRows.Sum(qi => qi.Quarter.Q4Total), groupRows.Sum(qi => qi.Quarter.Average));

            var comparisonQuarter = new QuarterInformation(groupRows.Sum(qi => qi.ComparisonQuarter.YearTotal),
                                                           groupRows.Sum(qi => qi.ComparisonQuarter.Q1Total), groupRows.Sum(qi => qi.ComparisonQuarter.Q2Total),
                                                           groupRows.Sum(qi => qi.ComparisonQuarter.Q3Total), groupRows.Sum(qi => qi.ComparisonQuarter.Q4Total), groupRows.Sum(qi => qi.ComparisonQuarter.Average));

            var totalRow = new QuarterlyHeadcountComparisonRow(totalQuarter, comparisonQuarter, comparisonYear);

            // Add rows to the list of rows gStatistics will bind
            rows.AddRange(groupRows);
            rows.Add(totalRow);
        }