コード例 #1
0
 /// <summary>
 /// Add the 0 entries to the report where the period and advisor/org exists but there happen to be no entries
 /// </summary>
 /// <param name="periods">the periods we are reporting on</param>
 /// <param name="reportLines">The lines we already have</param>
 /// <param name="byAdvisor">if true then pivoted by advisor otherwise, organisation is assumed</param>
 private static void AddZeroEntries(List <MLFSReportingPeriod> periods, List <IncomeReport> reportLines, bool byAdvisor)
 {
     foreach (MLFSReportingPeriod period in periods)
     {
         if (byAdvisor)
         {
             List <MLFSAdvisor> advisors = periods.SelectMany(x => x.Receipts).Select(y => y.Advisor).Distinct().ToList();
             foreach (MLFSAdvisor advisor in advisors)
             {
                 List <IncomeReport> entries = reportLines.Where(x => x.AdvisorId == advisor.Id && x.PeriodId == period.Id).ToList();
                 if (entries == null || entries.Count == 0)
                 {
                     IncomeReport entry = new IncomeReport()
                     {
                         Period          = period.Description,
                         PeriodId        = period.Id,
                         Advisor         = advisor.Fullname,
                         AdvisorId       = advisor.Id,
                         Organisation    = "",
                         Amount          = 0,
                         New_Amount      = 0,
                         Existing_Amount = 0
                     };
                     if (period.Budgets.Where(x => x.AdvisorId == advisor.Id).ToList().Count > 0)
                     {
                         entry.Budget = Tools.HandleNull(period.Budgets.Where(x => x.AdvisorId == advisor.Id).FirstOrDefault().Budget);
                     }
                     else
                     {
                         entry.Budget = 0;
                     }
                     reportLines.Add(entry);
                 }
             }
         }
         else
         {
             string[] orgs = periods.SelectMany(x => x.Receipts).Select(y => y.Organisation).Distinct().ToArray();
             foreach (string org in orgs)
             {
                 List <IncomeReport> entries = reportLines.Where(x => x.Organisation == org && x.PeriodId == period.Id).ToList();
                 if (entries == null || entries.Count == 0)
                 {
                     IncomeReport entry = new IncomeReport()
                     {
                         Period          = period.Description,
                         PeriodId        = period.Id,
                         Advisor         = "",
                         AdvisorId       = 0,
                         Organisation    = org,
                         Amount          = 0,
                         New_Amount      = 0,
                         Existing_Amount = 0
                     };
                     if (period.Budgets.Where(x => x.Advisor.Department == org).ToList().Count > 0)
                     {
                         entry.Budget = Tools.HandleNull(period.Budgets.Where(x => x.Advisor.Department == org).FirstOrDefault().Budget);
                     }
                     else
                     {
                         entry.Budget = 0;
                     }
                     reportLines.Add(entry);
                 }
             }
         }
     }
 }