コード例 #1
0
        public static PostHandler ChainPrePostHandlers(PostHandler baseHandler, Report report)
        {
            PostHandler handler = baseHandler;

            // anonymize_posts removes all meaningful information from xact payee's and
            // account names, for the sake of creating useful bug reports.
            if (report.AnonHandler.Handled)
            {
                handler = new AnonymizePosts(handler);
            }

            // This filter_posts will only pass through posts matching the `predicate'.
            if (report.LimitHandler.Handled)
            {
                Logger.Current.Debug("report.predicate", () => String.Format("Report predicate expression = {0}", report.LimitHandler.Str()));
                handler = new FilterPosts(handler, new Predicate(report.LimitHandler.Str(), report.WhatToKeep()), report);
            }

            // budget_posts takes a set of posts from a data file and uses them to
            // generate "budget posts" which balance against the reported posts.
            //
            // forecast_posts is a lot like budget_posts, except that it adds xacts
            // only for the future, and does not balance them against anything but the
            // future balance.

            if (report.BudgetFlags != ReportBudgetFlags.BUDGET_NO_BUDGET)
            {
                BudgetPosts budgetHandler = new BudgetPosts(handler, (Date)report.Terminus.Date, report.BudgetFlags);
                budgetHandler.AddPeriodXacts(report.Session.Journal.PeriodXacts);
                handler = budgetHandler;

                // Apply this before the budget handler, so that only matching posts are
                // calculated toward the budget.  The use of filter_posts above will
                // further clean the results so that no automated posts that don't match
                // the filter get reported.
                if (report.LimitHandler.Handled)
                {
                    handler = new FilterPosts(handler, new Predicate(report.LimitHandler.Str(), report.WhatToKeep()), report);
                }
            }
            else if (report.ForecastWhileHandler.Handled)
            {
                ForecastPosts forecastPosts = new ForecastPosts(handler, new Predicate(report.ForecastWhileHandler.Str(), report.WhatToKeep()),
                                                                report, report.ForecastYearsHandler.Handled ? int.Parse(report.ForecastYearsHandler.Value) : 5);
                forecastPosts.AddPeriodXacts(report.Session.Journal.PeriodXacts);
                handler = forecastPosts;

                // See above, under budget_posts.
                if (report.LimitHandler.Handled)
                {
                    handler = new FilterPosts(handler, new Predicate(report.LimitHandler.Str(), report.WhatToKeep()), report);
                }
            }

            return(handler);
        }
コード例 #2
0
ファイル: ForecastPostsTests.cs プロジェクト: taiab/nledger
        public void ForecastPosts_AddPost_DoesNotModifyInputPeriod()
        {
            ForecastPosts forecastPosts = new ForecastPosts(null, null, null, 1);
            DateInterval  dateInterval  = new DateInterval("from 2010/04/01 to 2010/06/10");

            dateInterval.Duration = new DateDuration(SkipQuantumEnum.DAYS, 5);
            Post post = new Post();

            Assert.IsNull(dateInterval.Start);

            forecastPosts.AddPost(dateInterval, post);

            Assert.IsNull(dateInterval.Start);
            Assert.IsNotNull(forecastPosts.PendingPosts.First().DateInterval.Start);
        }