Ejemplo n.º 1
0
        public void DisplayFilterPosts_Constructor_CreatesTempAccounts()
        {
            Report      report  = new Report(new Session());
            PostHandler handler = new PostHandler(null);

            DisplayFilterPosts displayFilterPosts = new DisplayFilterPosts(handler, report, true);

            Assert.Equal("<Adjustment>", displayFilterPosts.RoundingAccount.Name);
            Assert.Equal("<Revalued>", displayFilterPosts.RevaluedAccount.Name);
        }
Ejemplo n.º 2
0
        public void DisplayFilterPosts_Constructor_PopulatesProperties()
        {
            Report      report  = new Report(new Session());
            PostHandler handler = new PostHandler(null);

            DisplayFilterPosts displayFilterPosts = new DisplayFilterPosts(handler, report, true);

            Assert.Equal(handler, displayFilterPosts.Handler);
            Assert.Equal(report, displayFilterPosts.Report);
            Assert.Equal(report.DisplayAmountHandler.Expr, displayFilterPosts.DisplayAmountExpr);
            Assert.Equal(report.DisplayTotalHandler.Expr, displayFilterPosts.DisplayTotalExpr);
            Assert.True(displayFilterPosts.ShowRounding);
            Assert.NotNull(displayFilterPosts.Temps);
        }
Ejemplo n.º 3
0
        public static PostHandler ChainPostHandlers(PostHandler baseHandler, Report report, bool forAccountsReport = false)
        {
            PostHandler        handler          = baseHandler;
            Predicate          displayPredicate = null;
            Predicate          onlyPredicate    = null;
            DisplayFilterPosts displayFilter    = null;

            Expr expr = report.AmountHandler.Expr;

            expr.Context = report;

            report.TotalHandler.Expr.Context         = report;
            report.DisplayAmountHandler.Expr.Context = report;
            report.DisplayTotalHandler.Expr.Context  = report;

            if (!forAccountsReport)
            {
                // Make sure only forecast postings which match are allowed through
                if (report.ForecastWhileHandler.Handled)
                {
                    handler = new FilterPosts(handler, new Predicate(report.ForecastWhileHandler.Str(), report.WhatToKeep()), report);
                }

                // truncate_xacts cuts off a certain number of _xacts_ from being
                // displayed.  It does not affect calculation.
                if (report.HeadHandler.Handled || report.TailHandler.Handled)
                {
                    handler = new TruncateXacts(handler,
                                                report.HeadHandler.Handled ? Int32.Parse(report.HeadHandler.Value) : 0,
                                                report.TailHandler.Handled ? Int32.Parse(report.TailHandler.Value) : 0);
                }

                // display_filter_posts adds virtual posts to the list to account
                // for changes in value of commodities, which otherwise would affect
                // the running total unpredictably.
                handler = displayFilter = new DisplayFilterPosts(handler, report, report.RevaluedHandler.Handled && !report.NoRoundingHandler.Handled);

                // filter_posts will only pass through posts matching the
                // `display_predicate'.
                if (report.DisplayHandler.Handled)
                {
                    displayPredicate = new Predicate(report.DisplayHandler.Str(), report.WhatToKeep());
                    handler          = new FilterPosts(handler, displayPredicate, report);
                }
            }

            // changed_value_posts adds virtual posts to the list to account for changes
            // in market value of commodities, which otherwise would affect the running
            // total unpredictably.
            if (report.RevaluedHandler.Handled && (!forAccountsReport || report.UnrealizedHandler.Handled))
            {
                handler = new ChangedValuePost(handler, report, forAccountsReport, report.UnrealizedHandler.Handled, displayFilter);
            }

            // calc_posts computes the running total.  When this appears will determine,
            // for example, whether filtered posts are included or excluded from the
            // running total.
            handler = new CalcPosts(handler, expr, !forAccountsReport || (report.RevaluedHandler.Handled && report.UnrealizedHandler.Handled));

            // filter_posts will only pass through posts matching the
            // `secondary_predicate'.
            if (report.OnlyHandler.Handled)
            {
                onlyPredicate = new Predicate(report.OnlyHandler.Str(), report.WhatToKeep());
                handler       = new FilterPosts(handler, onlyPredicate, report);
            }

            if (!forAccountsReport)
            {
                // sort_posts will sort all the posts it sees, based on the `sort_order'
                // value expression.
                if (report.SortHandler.Handled)
                {
                    if (report.SortXactsHandler.Handled)
                    {
                        handler = new SortXacts(handler, new Expr(report.SortHandler.Str()), report);
                    }
                    else
                    {
                        handler = new SortPosts(handler, report.SortHandler.Str(), report);
                    }
                }

                // collapse_posts causes xacts with multiple posts to appear as xacts
                // with a subtotaled post for each commodity used.
                if (report.CollapseHandler.Handled)
                {
                    handler = new CollapsePosts(handler, report, expr, displayPredicate, onlyPredicate, report.CollapseIfZeroHandler.Handled);
                }

                // subtotal_posts combines all the posts it receives into one subtotal
                // xact, which has one post for each commodity in each account.
                //
                // period_posts is like subtotal_posts, but it subtotals according to time
                // periods rather than totalling everything.
                //
                // day_of_week_posts is like period_posts, except that it reports
                // all the posts that fall on each subsequent day of the week.
                if (report.EquityHandler.Handled)
                {
                    handler = new PostsAsEquity(handler, report, expr);
                }
                else if (report.SubTotalHandler.Handled)
                {
                    handler = new SubtotalPosts(handler, expr);
                }
            }

            if (report.DowHandler.Handled)
            {
                handler = new DayOfWeekPosts(handler, expr);
            }
            else if (report.ByPayeeHandler.Handled)
            {
                handler = new ByPayeePosts(handler, expr);
            }

            // interval_posts groups posts together based on a time period, such as
            // weekly or monthly.
            if (report.PeriodHandler.Handled)
            {
                handler = new IntervalPosts(handler, expr, new DateInterval(report.PeriodHandler.Str()), report.ExactHandler.Handled, report.EmptyHandler.Handled);
            }

            if (report.DateHandler.Handled)
            {
                handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_DATE, report.Session.Journal.Master, new Expr(report.DateHandler.Str()), report);
            }

            if (report.AccountHandler.Handled)
            {
                handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_ACCOUNT, report.Session.Journal.Master, new Expr(report.AccountHandler.Str()), report);
            }
            else if (report.PivotHandler.Handled)
            {
                string pivot = string.Format("\"{0}:\" + tag(\"{0}\")", report.PivotHandler.Str());
                handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_ACCOUNT, report.Session.Journal.Master, new Expr(pivot), report);
            }

            if (report.PayeeHandler.Handled)
            {
                handler = new TransferDetails(handler, TransferDetailsElementEnum.SET_PAYEE, report.Session.Journal.Master, new Expr(report.PayeeHandler.Str()), report);
            }

            // related_posts will pass along all posts related to the post received.  If
            // the `related_all' handler is on, then all the xact's posts are passed;
            // meaning that if one post of an xact is to be printed, all the post for
            // that xact will be printed.
            if (report.RelatedHandler.Handled)
            {
                handler = new RelatedPosts(handler, report.RelatedAllHandler.Handled);
            }

            if (report.InjectHandler.Handled)
            {
                handler = new InjectPosts(handler, report.InjectHandler.Str(), report.Session.Journal.Master);
            }

            return(handler);
        }