コード例 #1
0
ファイル: YearlyReport.cs プロジェクト: SwarmCorp/Swarmops
        public static YearlyReport Create (Organization organization, int year, FinancialAccountType accountType)
        {
            YearlyReport report = new YearlyReport();
            report.Organization = organization;
            report.Year = year;
            report._accountType = accountType;

            // Get accounts

            FinancialAccounts accounts = FinancialAccounts.ForOrganization(organization, accountType);

            // Remove unwanted accounts

            FinancialAccount resultsAccount = organization.FinancialAccounts.CostsYearlyResult;

            foreach (FinancialAccount account in accounts)
            {
                // For now, just remove the "results" account. TODO: Remove inactive accounts, too.

                if (account.Identity == resultsAccount.Identity)
                {
                    accounts.Remove(account);
                    break;
                }
            }

            // Build tree (there should be a template for this)

            report._treeMap = new Dictionary<int, List<FinancialAccount>>();

            foreach (FinancialAccount account in accounts)
            {
                if (!report._treeMap.ContainsKey(account.ParentIdentity))
                {
                    report._treeMap[account.ParentIdentity] = new List<FinancialAccount>();
                }

                report._treeMap[account.ParentIdentity].Add(account);
            }


            FinancialAccounts orderedList = new FinancialAccounts(); // This list is guaranteed to have parents before children

            report.PopulateOrderedList(orderedList, 0);  // recursively add nodes parents-first
            report.PopulateLookups(orderedList);         // populate the lookup tables for results per account
            report.PopulateTotals();

            report.ReportLines = new List<YearlyReportLine>();
            report.RecurseAddLines(report.ReportLines, 0);

            // Aggregate accounts, if appropriate

            if (report._treeMap[0].Count > 3)
            {
                // regroup list

                report.AggregateAccounts();
            }

            return report;
        }
コード例 #2
0
        public static YearlyReport Create(Organization organization, int year, FinancialAccountType accountType)
        {
            YearlyReport report = new YearlyReport();

            report.Organization = organization;
            report.Year         = year;
            report._accountType = accountType;

            // Get accounts

            FinancialAccounts accounts = FinancialAccounts.ForOrganization(organization, accountType);

            // Remove unwanted accounts

            FinancialAccount resultsAccount = organization.FinancialAccounts.CostsYearlyResult;

            foreach (FinancialAccount account in accounts)
            {
                // For now, just remove the "results" account. TODO: Remove inactive accounts, too.

                if (account.Identity == resultsAccount.Identity)
                {
                    accounts.Remove(account);
                    break;
                }
            }

            // Build tree (there should be a template for this)

            report._treeMap = new Dictionary <int, List <FinancialAccount> >();

            foreach (FinancialAccount account in accounts)
            {
                if (!report._treeMap.ContainsKey(account.ParentIdentity))
                {
                    report._treeMap[account.ParentIdentity] = new List <FinancialAccount>();
                }

                report._treeMap[account.ParentIdentity].Add(account);
            }


            FinancialAccounts orderedList = new FinancialAccounts(); // This list is guaranteed to have parents before children

            report.PopulateOrderedList(orderedList, 0);              // recursively add nodes parents-first
            report.PopulateLookups(orderedList);                     // populate the lookup tables for results per account
            report.PopulateTotals();

            report.ReportLines = new List <YearlyReportLine>();
            report.RecurseAddLines(report.ReportLines, 0);

            // Aggregate accounts, if appropriate

            if (report._treeMap[0].Count > 3)
            {
                // regroup list

                report.AggregateAccounts();
            }

            return(report);
        }