示例#1
0
        public override void Clear()
        {
            DisplayAmountExpr.MarkUncomplited();
            DisplayTotalExpr.MarkUncomplited();

            LastDisplayTotal = new Value();

            Temps.Clear();
            base.Clear();

            CreateAccounts();
        }
示例#2
0
        public bool OutputRounding(Post post)
        {
            BindScope boundScope      = new BindScope(Report, post);
            Value     newDisplayTotal = new Value();

            if (ShowRounding)
            {
                newDisplayTotal = DisplayTotalExpr.Calc(boundScope).StripAnnotations(Report.WhatToKeep());
                Logger.Current.Debug("filters.changed_value.rounding", () => String.Format("rounding.new_display_total     = {0}", newDisplayTotal));
            }

            // Allow the posting to be displayed if:
            //  1. Its display_amount would display as non-zero, or
            //  2. The --empty option was specified, or
            //  3. a) The account of the posting is <Revalued>, and
            //     b) the revalued option is specified, and
            //     c) the --no-rounding option is not specified.

            if (post.Account == RevaluedAccount)
            {
                if (ShowRounding)
                {
                    LastDisplayTotal = newDisplayTotal;
                }
                return(true);
            }

            Value repricedAmount = DisplayAmountExpr.Calc(boundScope).StripAnnotations(Report.WhatToKeep());

            if (!Value.IsNullOrEmptyOrFalse(repricedAmount))
            {
                if (!Value.IsNullOrEmpty(LastDisplayTotal))
                {
                    Logger.Current.Debug("filters.changed_value.rounding", () => String.Format("rounding.repriced_amount       = {0}", repricedAmount));

                    Value preciseDisplayTotal = newDisplayTotal.Truncated() - repricedAmount.Truncated();

                    Logger.Current.Debug("filters.changed_value.rounding", () => String.Format("rounding.precise_display_total = {0}", preciseDisplayTotal));
                    Logger.Current.Debug("filters.changed_value.rounding", () => String.Format("rounding.last_display_total    = {0}", LastDisplayTotal));

                    Value diff = preciseDisplayTotal - LastDisplayTotal;
                    if (!Value.IsNullOrEmptyOrFalse(diff))
                    {
                        Logger.Current.Debug("filters.changed_value.rounding", () => String.Format("rounding.diff                  = {0}", diff));

                        FiltersCommon.HandleValue(
                            /* value=         */ diff,
                            /* account=       */ RoundingAccount,
                            /* xact=          */ post.Xact,
                            /* temps=         */ Temps,
                            /* handler=       */ (PostHandler)Handler,
                            /* date=          */ default(Date),
                            /* act_date_p=    */ true,
                            /* total=         */ preciseDisplayTotal,
                            /* direct_amount= */ true,
                            /* mark_visited=  */ false,
                            /* bidir_link=    */ false);
                    }
                }
                if (ShowRounding)
                {
                    LastDisplayTotal = newDisplayTotal;
                }
                return(true);
            }
            else
            {
                return(Report.EmptyHandler.Handled);
            }
        }