public EntryItemsReport GetReport()
        {
            var ledger           = GetLedger(Journal);
            var book             = new Book(Book);
            var accountPredicate = new QueryAccountPredicate(NoChildren ? AccountQuery : AccountQuery + ":**");
            var entryItems       = ledger.GetEntriesAtOrBetween(StartIndex, EndIndex).GetEntryItems(book, accountPredicate);
            var reportItems      = new List <EntryItemsReport.ReportItem>();

            foreach (var entryItem in entryItems)
            {
                var balanceItem = ledger.GetBalanceAt(book, entryItem.Entry.Index).Items.GetBalanceItem(entryItem.Account, entryItem.Asset);

                var reportItem = new EntryItemsReport.ReportItem();
                reportItem.Index         = entryItem.Entry.Index;
                reportItem.Account       = entryItem.Account;
                reportItem.Asset         = entryItem.Asset;
                reportItem.Debit         = entryItem.Debit;
                reportItem.Credit        = entryItem.Credit;
                reportItem.BalanceDebit  = balanceItem.BalanceDebit;
                reportItem.BalanceCredit = balanceItem.BalanceCredit;

                reportItems.Add(reportItem);
            }

            if (!string.IsNullOrEmpty(AssetQuery))
            {
                var assetPredicate = new QueryAssetPredicate(AssetQuery);

                reportItems = reportItems.Where(reportItem => assetPredicate.Matches(reportItem.Asset)).ToList();
            }

            return(new EntryItemsReport(reportItems.ToArray()));
        }
        public BalanceCheckReport GetReport()
        {
            var ledger       = GetLedger(Journal);
            var book         = new Book(Book);
            var balance      = ledger.GetBalanceAtOrBefore(book, Index);
            var balanceItems = balance.Items.GetBalanceItemsCombined(new TrueAccountPredicate());
            var reportItems  = new List <BalanceCheckReport.ReportItem>();

            foreach (var balanceItem in balanceItems)
            {
                var reportItem = new BalanceCheckReport.ReportItem();
                reportItem.Asset                = balanceItem.Asset;
                reportItem.Assets               = balance.Items.GetBalanceItemCombined(new QueryAccountPredicate("Assets:**"), balanceItem.Asset).BalanceDebitOrDefault();
                reportItem.Liabilities          = balance.Items.GetBalanceItemCombined(new QueryAccountPredicate("Liabilities:**"), balanceItem.Asset).BalanceDebitOrDefault();
                reportItem.Equity               = balance.Items.GetBalanceItemCombined(new QueryAccountPredicate("Equity:**"), balanceItem.Asset).BalanceDebitOrDefault();
                reportItem.LiabilitiesAndEquity = reportItem.Liabilities + reportItem.Equity;
                reportItem.Diff = reportItem.Assets + reportItem.LiabilitiesAndEquity;

                reportItems.Add(reportItem);
            }

            if (!string.IsNullOrEmpty(AssetQuery))
            {
                var assetPredicate = new QueryAssetPredicate(AssetQuery);

                reportItems = reportItems.Where(reportItem => assetPredicate.Matches(reportItem.Asset)).ToList();
            }

            reportItems = reportItems.OrderBy(reportItem => reportItem.Asset, new AssetComparer()).ToList();

            return(new BalanceCheckReport(reportItems.ToArray()));
        }
Пример #3
0
        public BalanceReport GetReport()
        {
            var ledger           = GetLedger(Journal);
            var book             = new Book(Book);
            var accountPredicate = new QueryAccountPredicate(NoChildren ? AccountQuery : AccountQuery + ":**");
            var balance          = ledger.GetBalanceAtOrBefore(book, Index);
            var accountIds       = AllLevels ? GetAllAccountIds(balance, accountPredicate) : GetAccountIds(balance, accountPredicate);
            var reportItems      = new List <BalanceReport.ReportItem>();

            foreach (var accountId in accountIds)
            {
                if (!accountPredicate.Matches(new Account(accountId)))
                {
                    continue;
                }

                var predicate = new QueryAccountPredicate(!AllLevels ? accountId : accountId + ":**");

                foreach (var balanceItem in balance.Items.GetBalanceItemsCombined(predicate))
                {
                    var reportItem = new BalanceReport.ReportItem();
                    reportItem.Account       = new Account(accountId);
                    reportItem.Asset         = balanceItem.Asset;
                    reportItem.TotalDebit    = balanceItem.TotalDebit;
                    reportItem.TotalCredit   = balanceItem.TotalCredit;
                    reportItem.BalanceDebit  = reportItem.TotalDebit > reportItem.TotalCredit ? reportItem.TotalDebit - reportItem.TotalCredit : 0;
                    reportItem.BalanceCredit = reportItem.TotalCredit > reportItem.TotalDebit ? reportItem.TotalCredit - reportItem.TotalDebit : 0;

                    reportItems.Add(reportItem);
                }
            }

            if (!string.IsNullOrEmpty(AssetQuery))
            {
                var assetPredicate = new QueryAssetPredicate(AssetQuery);

                reportItems = reportItems.Where(reportItem => assetPredicate.Matches(reportItem.Asset)).ToList();
            }

            if (!IncludeZeroBalances)
            {
                reportItems = reportItems.Where(reportItem => reportItem.BalanceDebit != 0 || reportItem.BalanceCredit != 0).ToList();
            }

            reportItems = reportItems.OrderBy(reportItem => reportItem.Account, new AccountComparer()).ThenBy(reportItem => reportItem.Asset, new AssetComparer()).ToList();

            return(new BalanceReport(reportItems.ToArray()));
        }
Пример #4
0
        public ProfitLossReport GetReport()
        {
            var ledger       = GetLedger(Journal);
            var book         = new Book(Book);
            var startBalance = ledger.GetBalanceAt(book, StartIndex) ?? new Balance();
            var endBalance   = ledger.GetBalanceAt(book, EndIndex) ?? new Balance();
            var accountIds   = GetChildAccountIds(endBalance, AccountQuery);
            var reportItems  = new List <ProfitLossReport.ReportItem>();

            foreach (var accountId in accountIds)
            {
                foreach (var balanceItem in endBalance.Items.GetBalanceItemsCombined(new QueryAccountPredicate(accountId + ":**")))
                {
                    var reportItem = new ProfitLossReport.ReportItem();
                    reportItem.Account     = new Account(accountId);
                    reportItem.Asset       = balanceItem.Asset;
                    reportItem.TotalDebit  = balanceItem.TotalDebit;
                    reportItem.TotalCredit = balanceItem.TotalCredit;

                    reportItems.Add(reportItem);
                }
            }

            foreach (var reportItem in reportItems)
            {
                var startBalanceItem = startBalance.Items.GetBalanceItemCombined(new QueryAccountPredicate(reportItem.Account + ":**"), reportItem.Asset);

                if (startBalanceItem == null)
                {
                    continue;
                }

                reportItem.TotalDebit  -= startBalanceItem.TotalDebit;
                reportItem.TotalCredit -= startBalanceItem.TotalCredit;
            }

            foreach (var reportItem in reportItems)
            {
                reportItem.BalanceDebit  = reportItem.TotalDebit > reportItem.TotalCredit ? reportItem.TotalDebit - reportItem.TotalCredit : 0;
                reportItem.BalanceCredit = reportItem.TotalCredit > reportItem.TotalDebit ? reportItem.TotalCredit - reportItem.TotalDebit : 0;
            }

            foreach (var reportItem in reportItems)
            {
                var totalBalanceDebit  = reportItems.Where(x => x.Asset.Equals(reportItem.Asset)).Sum(x => x.BalanceDebit);
                var totalBalanceCredit = reportItems.Where(x => x.Asset.Equals(reportItem.Asset)).Sum(x => x.BalanceCredit);

                reportItem.BalanceDebitPercent  = totalBalanceDebit != 0 ? reportItem.BalanceDebit / totalBalanceDebit * 100 : 0;
                reportItem.BalanceCreditPercent = totalBalanceCredit != 0 ? reportItem.BalanceCredit / totalBalanceCredit * 100 : 0;
            }

            if (!string.IsNullOrEmpty(AssetQuery))
            {
                var assetPredicate = new QueryAssetPredicate(AssetQuery);

                reportItems = reportItems.Where(reportItem => assetPredicate.Matches(reportItem.Asset)).ToList();
            }

            reportItems = reportItems.Where(reportItem => reportItem.BalanceDebit != 0 || reportItem.BalanceCredit != 0).ToList();
            reportItems = reportItems.OrderBy(reportItem => reportItem.BalanceCredit - reportItem.BalanceDebit).ToList();

            return(new ProfitLossReport(reportItems.ToArray()));
        }