public override void Handle(Post post) { foreach (Tuple <string, Account, ISet <Xact> > pair in TagsList) { Value tagValue = post.GetTag(pair.Item1, false); // When checking if the transaction has the tag, only inject once // per transaction. if (Value.IsNullOrEmptyOrFalse(tagValue) && !pair.Item3.Contains(post.Xact)) { tagValue = post.Xact.GetTag(pair.Item1); if (!Value.IsNullOrEmptyOrFalse(tagValue)) { pair.Item3.Add(post.Xact); } } if (!Value.IsNullOrEmptyOrFalse(tagValue)) { Xact xact = Temps.CopyXact(post.Xact); xact.Date = post.GetDate(); xact.Flags |= SupportsFlagsEnum.ITEM_GENERATED; Post temp = Temps.CopyPost(post, xact); temp.Account = pair.Item2; temp.Amount = tagValue.AsAmount; temp.Flags |= SupportsFlagsEnum.ITEM_GENERATED; base.Handle(temp); } } base.Handle(post); }
/// <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); }
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); }