Пример #1
0
        public override void Clear()
        {
            AmountExpr.MarkUncomplited();
            DisplayPredicate.MarkUncomplited();
            OnlyPredicate.MarkUncomplited();

            Subtotal = new Value();
            Count    = 0;
            LastXact = null;
            LastPost = null;

            Temps.Clear();
            CreateAccounts();
            ComponentPosts.Clear();

            base.Clear();
        }
Пример #2
0
        public override void Handle(Post post)
        {
            // If we've reached a new xact, report on the subtotal
            // accumulated thus far.
            if (LastXact != post.Xact && Count > 0)
            {
                ReportSubtotal();
            }

            Subtotal = post.AddToValue(Subtotal, AmountExpr);

            ComponentPosts.Add(post);

            LastXact = post.Xact;
            LastPost = post;
            Count++;
        }
Пример #3
0
        /// <summary>
        /// Ported from collapse_posts::report_subtotal
        /// </summary>
        public void ReportSubtotal()
        {
            if (Count == 0)
            {
                return;
            }

            int displayedCount = 0;

            foreach (Post post in ComponentPosts)
            {
                BindScope boundScope = new BindScope(Report, post);
                if (OnlyPredicate.Calc(boundScope).Bool&& DisplayPredicate.Calc(boundScope).Bool)
                {
                    displayedCount++;
                }
            }

            if (displayedCount == 1)
            {
                base.Handle(LastPost);
            }
            else if (OnlyCollapseIfZero && !Subtotal.IsZero)
            {
                foreach (Post post in ComponentPosts)
                {
                    base.Handle(post);
                }
            }
            else
            {
                Date earliestDate = default(Date);
                Date latestDate   = default(Date);

                foreach (Post post in ComponentPosts)
                {
                    Date date      = post.GetDate();
                    Date valueDate = post.ValueDate;
                    if (!earliestDate.IsValid() || date < earliestDate)
                    {
                        earliestDate = date;
                    }
                    if (!latestDate.IsValid() || valueDate > latestDate)
                    {
                        latestDate = valueDate;
                    }
                }

                Xact xact = Temps.CreateXact();
                xact.Payee = LastXact.Payee;
                xact.Date  = earliestDate.IsValid() ? earliestDate : LastXact.Date;

                Logger.Debug("filters.collapse", () => String.Format("Pseudo-xact date = {0}", xact.Date));
                Logger.Debug("filters.collapse", () => String.Format("earliest date    = {0}", earliestDate));
                Logger.Debug("filters.collapse", () => String.Format("latest date      = {0}", latestDate));

                FiltersCommon.HandleValue(
                    /* value=      */ Subtotal,
                    /* account=    */ TotalsAccount,
                    /* xact=       */ xact,
                    /* temps=      */ Temps,
                    /* handler=    */ (PostHandler)Handler,
                    /* date=       */ latestDate,
                    /* act_date_p= */ false);
            }

            ComponentPosts.Clear();

            LastXact = null;
            LastPost = null;
            Subtotal = Value.Get(0);
            Count    = 0;
        }