public override void Handle(Post post) { if (Completed) { return; } if (LastXact != post.Xact) { if (LastXact != null) { XactsSeen++; } LastXact = post.Xact; } if (TailCount == 0 && HeadCount > 0 && XactsSeen >= HeadCount) { Flush(); Completed = true; return; } Posts.Add(post); }
public override void Clear() { Sorter.Clear(); LastXact = null; base.Clear(); }
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); }
public Post CreatePost(Xact xact, Account account, bool bidirLink = true) { if (PostTemps == null) { PostTemps = new List <Post>(); } Post temp = new Post(account); temp.Flags |= SupportsFlagsEnum.ITEM_TEMP; temp.Account = account; temp.Account.AddPost(temp); PostTemps.Add(temp); if (bidirLink) { xact.AddPost(temp); } else { temp.Xact = xact; } return(temp); }
public void Journal_AddXact_DoesNotAllowToAddTwoXactsWithTheSameUUIDButDifferentPostAmounts() { Account account1 = new Account(); Account account2 = new Account(); Journal journal = new Journal(); Xact xact1 = new Xact(); xact1.SetTag("UUID", Value.StringValue("val1")); xact1.AddPost(new Post() { Account = account1, Amount = new Amount(10) }); xact1.AddPost(new Post() { Account = account2, Amount = new Amount(-10) }); Xact xact2 = new Xact(); xact2.SetTag("UUID", Value.StringValue("val1")); xact2.AddPost(new Post() { Account = account1, Amount = new Amount(5) }); xact2.AddPost(new Post() { Account = account2, Amount = new Amount(-5) }); journal.AddXact(xact1); Assert.Throws <RuntimeError>(() => journal.AddXact(xact2)); }
public void TextualParser_ParseXact_CheckingBalanceIntegrationTest() { string line = @"2003/12/01 * Checking balance Assets:Checking $1,000.00 Equity:Opening Balances"; ITextualReader reader = CreateReaderForString(line); TextualParser parser = CreateTextualParser(); Account account = new Account(); string current = reader.ReadLine(); Xact xact = parser.ParseXact(current, reader, account); Assert.IsNotNull(xact); Assert.AreEqual(new Date(2003, 12, 01), xact.Date); Assert.IsNull(xact.DateAux); Assert.AreEqual(ItemStateEnum.Cleared, xact.State); Assert.AreEqual("Checking balance", xact.Payee); Assert.AreEqual(2, xact.Posts.Count); Post post1 = xact.Posts.First(); Assert.AreEqual("Assets:Checking", post1.Account.FullName); Assert.AreEqual("$", post1.Amount.Commodity.Symbol); Assert.AreEqual(BigInt.Parse("1000", 2), post1.Amount.Quantity); Post post2 = xact.Posts.Last(); Assert.AreEqual("Equity:Opening Balances", post2.Account.FullName); Assert.IsNull(post2.Amount); }
/// <summary> /// Ported from changed_value_posts::output_revaluation /// </summary> public void OutputRevaluation(Post post, Date date) { if (date.IsValid()) { post.XData.Date = date; } try { BindScope boundScope = new BindScope(Report, post); RepricedTotal = TotalExpr.Calc(boundScope); } finally { post.XData.Date = default(Date); } if (!Value.IsNullOrEmpty(LastTotal)) { Value diff = RepricedTotal - LastTotal; if (!Value.IsNullOrEmptyOrFalse(diff)) { Xact xact = Temps.CreateXact(); xact.Payee = "Commodities revalued"; xact.Date = date.IsValid() ? date : post.ValueDate; if (!ForAccountsReports) { FiltersCommon.HandleValue( /* value= */ diff, /* account= */ RevaluedAccount, /* xact= */ xact, /* temps= */ Temps, /* handler= */ (PostHandler)Handler, /* date= */ xact.Date.Value, /* act_date_p= */ true, /* total= */ RepricedTotal); } else if (ShowUnrealized) { FiltersCommon.HandleValue( /* value= */ diff.Negated(), /* account= */ (diff.IsLessThan(Value.Zero) ? LossesEquityAccount : GainsEquityAccount), /* xact= */ xact, /* temps= */ Temps, /* handler= */ (PostHandler)Handler, /* date= */ xact.Date.Value, /* act_date_p= */ true, /* total= */ new Value(), /* direct_amount= */ false, /* mark_visited= */ true); } } } }
public override void Clear() { Completed = false; Posts.Clear(); XactsSeen = 0; LastXact = null; base.Clear(); }
public void Xact_AddPost_PopulatesXactInPost() { Xact xact = new Xact(); Post post = new Post(); xact.AddPost(post); Assert.AreEqual(xact, post.Xact); }
public void Xact_Valid_FailsIfNoDateValue() { Xact xact = new Xact(); Assert.False(xact.Valid()); xact.Date = (Date)DateTime.Today; Assert.True(xact.Valid()); }
/// <summary> /// Ported from post_t::aux_date() /// </summary> public override Date?GetAuxDate() { Date?date = base.GetAuxDate(); if (!date.HasValue && Xact != null) { return(Xact.GetAuxDate()); } return(date); }
/// <summary> /// Ported from void truncate_xacts::flush() /// </summary> public override void Flush() { if (!Posts.Any()) { return; } int l = Posts.Select(p => p.Xact).Distinct().Count(); Xact xact = Posts.First().Xact; int i = 0; foreach (Post post in Posts) { if (xact != post.Xact) { xact = post.Xact; i++; } bool print = false; if (HeadCount != 0) { if (HeadCount > 0 && i < HeadCount) { print = true; } else if (HeadCount < 0 && i >= -HeadCount) { print = true; } } if (!print && TailCount != 0) { if (TailCount > 0 && l - i <= TailCount) { print = true; } else if (TailCount < 0 && l - i > -TailCount) { print = true; } } if (print) { base.Handle(post); } } Posts.Clear(); base.Flush(); }
public void Xact_Detach_FailsIfThereIsTempPost() { Account account = new Account(); Xact xact = new Xact(); Post post = new Post(account); post.Flags = SupportsFlagsEnum.ITEM_TEMP; xact.AddPost(post); Assert.Throws <InvalidOperationException>(() => xact.Detach()); }
public void Post_Valid_CheckWhetherXactIsPopulated() { Post post = new Post(new Account(), new Amount(10)); Xact xact = new Xact(); xact.Posts.Add(post); Assert.False(post.Valid()); post.Xact = xact; Assert.True(post.Valid()); }
public void Post_Valid_CheckWhetherXactRefersToPost() { Post post = new Post(new Account(), new Amount(10)); Xact xact = new Xact(); post.Xact = xact; Assert.IsFalse(post.Valid()); xact.Posts.Add(post); Assert.IsTrue(post.Valid()); }
public override void Handle(Post post) { if (LastXact != null && post.Xact != LastXact) { Sorter.PostAccumulatedPosts(); } Sorter.Handle(post); LastXact = post.Xact; }
public void Xact_Detach_FailsIfThereIsTempPost() { Account account = new Account(); Xact xact = new Xact(); Post post = new Post(account); post.Flags = SupportsFlagsEnum.ITEM_TEMP; xact.AddPost(post); xact.Detach(); }
public void AddBalancingPost_Constructor_PopulatesXactAndPost() { Xact xact = new Xact(); Post post = new Post(); AddBalancingPost addBalancingPost = new AddBalancingPost(xact, post); Assert.True(addBalancingPost.First); Assert.Equal(xact, addBalancingPost.Xact); Assert.Equal(post, addBalancingPost.NullPost); }
public void AddBalancingPost_Constructor_CopiesFromAnotherItem() { Xact xact = new Xact(); Post post = new Post(); AddBalancingPost addBalancingPost1 = new AddBalancingPost(xact, post); AddBalancingPost addBalancingPost2 = new AddBalancingPost(addBalancingPost1); Assert.True(addBalancingPost2.First); Assert.Equal(xact, addBalancingPost2.Xact); Assert.Equal(post, addBalancingPost2.NullPost); }
/// <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 void Xact_Detach_RemovesPostsFromAccounts() { Account account = new Account(); Xact xact = new Xact(); Post post = new Post(account); xact.AddPost(post); account.Posts.Add(post); xact.Detach(); Assert.AreEqual(0, account.Posts.Count); // Post has been removed }
public override bool HasTag(string tag, bool inherit = true) { if (base.HasTag(tag)) { return(true); } if (inherit && Xact != null) { return(Xact.HasTag(tag)); } return(false); }
public override bool HasTag(Mask tagMask, Mask valueMask = null, bool inherit = true) { if (base.HasTag(tagMask, valueMask)) { return(true); } if (inherit && Xact != null) { return(Xact.HasTag(tagMask, valueMask)); } return(false); }
public void Post_Valid_CheckWhetherAmountIsValid() { Post post = new Post(new Account(), new Amount(10)); Xact xact = new Xact(); post.Xact = xact; xact.Posts.Add(post); Assert.True(post.Valid()); var quantity = new Amount(10).Quantity.SetPrecision(2048); post.Amount = new Amount(quantity, null); Assert.False(post.Amount.Valid()); Assert.False(post.Valid()); }
public void TextualParser_ParsePost_ExpensesFoodGroceriesIntegrationTest() { string line = " Expenses:Food:Groceries $ 37.50 ; [=2011/03/01]"; TextualParser parser = CreateTextualParser(); Account account = new Account(); Xact xact = new Xact(); Post post = parser.ParsePost(line, xact, account); Assert.IsNotNull(post); Assert.AreEqual("Expenses:Food:Groceries", post.Account.FullName); Assert.AreEqual("$", post.Amount.Commodity.Symbol); Assert.AreEqual(BigInt.Parse("37.50", 2), post.Amount.Quantity); Assert.AreEqual(new Date(2011, 03, 01), post.DateAux); }
public Xact CreateXact() { if (XactTemps == null) { XactTemps = new List <Xact>(); } Xact temp = new Xact(); temp.Flags |= SupportsFlagsEnum.ITEM_TEMP; XactTemps.Add(temp); return(temp); }
public Xact CopyXact(Xact origin) { if (XactTemps == null) { XactTemps = new List <Xact>(); } XactTemps.Add(origin); Xact temp = new Xact(origin); temp.Flags |= SupportsFlagsEnum.ITEM_TEMP; return(temp); }
public void TextualParser_ParsePost_AssetsWyshonaItemsIntegrationTest() { string line = " Assets:Wyshona:Items \"Plans: Wildthorn Mail\" 1 {1.25G}"; TextualParser parser = CreateTextualParser(); Account account = new Account(); Xact xact = new Xact(); Post post = parser.ParsePost(line, xact, account); Assert.IsNotNull(post); Assert.AreEqual("Assets:Wyshona:Items", post.Account.FullName); Assert.AreEqual("\"Plans: Wildthorn Mail\"", post.Amount.Commodity.Symbol); Assert.AreEqual(BigInt.Parse("1"), post.Amount.Quantity); Assert.AreEqual("G", ((AnnotatedCommodity)post.Amount.Commodity).Details.Price.Commodity.Symbol); Assert.AreEqual(BigInt.Parse("1.25", 2), ((AnnotatedCommodity)post.Amount.Commodity).Details.Price.Quantity); }
public void Journal_Valid_ReturnsFalseIfXactNotValid() { Journal journal = new Journal(); journal.Master = new Account(); Assert.True(journal.Valid()); Xact xact = new Xact(); xact.AddPost(new Post(journal.Master, new Amount(10))); xact.AddPost(new Post(journal.Master, new Amount(-10))); journal.AddXact(xact); Assert.False(xact.Valid()); // [DM] - Xact is not valid (but finalizable to add to the journal) because of no date. Assert.False(journal.Valid()); }
public override Value GetTag(string tag, bool inherit = true) { Value value = base.GetTag(tag, inherit); if (!Value.IsNullOrEmpty(value)) { return(value); } if (inherit && Xact != null) { return(Xact.GetTag(tag)); } return(Value.Empty); }