Пример #1
0
        /// <summary>
        /// Ported from void transfer_details::operator()(post_t& post)
        /// </summary>
        public override void Handle(Post post)
        {
            Xact xact = Temps.CopyXact(post.Xact);

            xact.Date = post.GetDate();

            Post temp = Temps.CopyPost(post, xact);

            temp.State = post.State;

            BindScope boundScope = new BindScope(Scope, temp);
            Value     substitute = Expr.Calc(boundScope);

            if (!Value.IsNullOrEmpty(substitute))
            {
                switch (WhichElement)
                {
                case TransferDetailsElementEnum.SET_DATE:
                    temp.Date = substitute.AsDate;
                    break;

                case TransferDetailsElementEnum.SET_ACCOUNT:
                {
                    string accountName = substitute.AsString;
                    if (!String.IsNullOrEmpty(accountName) && !accountName.EndsWith(":"))
                    {
                        Account prevAccount = temp.Account;
                        temp.Account.RemovePost(temp);

                        accountName += ":" + prevAccount.FullName;

                        string[] accountNames = accountName.Split(':');
                        temp.Account = FiltersCommon.CreateTempAccountFromPath(accountNames, Temps, xact.Journal.Master);
                        temp.Account.AddPost(temp);

                        temp.Account.SetFlags(prevAccount);
                        if (prevAccount.HasXData)
                        {
                            temp.Account.XData.SetFlags(prevAccount.XData);
                        }
                    }
                    break;
                }

                case TransferDetailsElementEnum.SET_PAYEE:
                    xact.Payee = substitute.AsString;
                    break;
                }
            }

            base.Handle(temp);
        }
Пример #2
0
        public InjectPosts(PostHandler handler, string tagList, Account master)
            : base(handler)
        {
            TagsList = new List <Tuple <string, Account, ISet <Xact> > >();
            Temps    = new Temporaries();

            foreach (string q in tagList.Split(',').Select(s => s.Trim()))
            {
                string[] accountNames = q.Split(':');
                Account  account      = FiltersCommon.CreateTempAccountFromPath(accountNames, Temps, master);
                account.IsGeneratedAccount = true;

                TagsList.Add(new Tuple <string, Account, ISet <Xact> >(q, account, new HashSet <Xact>()));
            }
        }
Пример #3
0
        public override void Handle(Post post)
        {
            bool copyXactDetails = false;

            if (LastXact != post.Xact)
            {
                Temps.CopyXact(post.Xact);
                LastXact        = post.Xact;
                copyXactDetails = true;
            }
            Xact xact = Temps.LastXact;

            xact.Code = null;

            if (copyXactDetails)
            {
                xact.CopyDetails(post.Xact);

                string buf = String.Format("{0}{1}{0}", post.Xact.Payee, IntegerGen.Value());

                xact.Payee = SHA1.GetHash(buf);
                xact.Note  = null;
            }
            else
            {
                xact.Journal = post.Xact.Journal;
            }

            IList <string> accountNames = new List <string>();

            for (Account acct = post.Account; acct != null; acct = acct.Parent)
            {
                string buf = String.Format("{0}{1}{2}", IntegerGen.Value(), acct, acct.FullName);

                accountNames.Add(SHA1.GetHash(buf));
            }

            Account newAccount = FiltersCommon.CreateTempAccountFromPath(accountNames, Temps, xact.Journal.Master);
            Post    temp       = Temps.CopyPost(post, xact, newAccount);

            temp.Note   = null;
            temp.Flags |= SupportsFlagsEnum.POST_ANONYMIZED;

            RenderCommodity(temp.Amount);
            if (temp.Amount.HasAnnotation)
            {
                temp.Amount.Annotation.Tag = null;
                if (temp.Amount.Annotation.Price != null)
                {
                    RenderCommodity(temp.Amount.Annotation.Price);
                }
            }

            if (temp.Cost != null)
            {
                RenderCommodity(temp.Cost);
            }
            if (temp.AssignedAmount != null)
            {
                RenderCommodity(temp.AssignedAmount);
            }

            base.Handle(temp);
        }