protected ICollection <TItem> FindItems(IAccountPredicate predicate) { // Performance.MarkStart("ItemCollection.FindItems(predicate)"); var result = new List <TItem>(); if (predicate is QueryAccountPredicate) { FindItemsByQueryParts(_rootNode, ((QueryAccountPredicate)predicate).QueryParts, 0, result); } else if (predicate is OrAccountPredicate) { result = ((OrAccountPredicate)predicate).Predicates.SelectMany(FindItems).Distinct().ToList(); } else if (predicate is AndAccountPredicate) { throw new NotImplementedException(); } else { _rootNode.GetAllItems(result); result = result.Where(item => predicate.Matches(item.Account)).ToList(); } // Performance.MarkEnd("ItemCollection.FindItems(predicate)"); return(result); }
public ICollection <IEntryItem> GetEntryItems(IBook book, IAccountPredicate accountPredicate, IComparable startIndex, bool startInclusive, IComparable endIndex, bool endInclusive) { var result = _entryItems.Where(x => x.Book.Equals(book)); if (startIndex != null) { if (startInclusive) { result = result.Where(x => x.Entry.Index.CompareTo(startIndex) >= 0); } else { result = result.Where(x => x.Entry.Index.CompareTo(startIndex) > 0); } } if (endIndex != null) { if (endInclusive) { result = result.Where(x => x.Entry.Index.CompareTo(endIndex) <= 0); } else { result = result.Where(x => x.Entry.Index.CompareTo(endIndex) < 0); } } return(result.Where(x => accountPredicate.Matches(x.Account)).ToList()); }
public virtual void AddItems(ILedger ledger, IBook book, IAccountPredicate predicate, IAccount debitAccount, IAccount creditAccount, IAsset asset, decimal amount) { if (amount > 0) { AddItems(ledger, book, predicate, debitAccount, creditAccount, asset, amount, 0); } else { AddItems(ledger, book, predicate, debitAccount, creditAccount, asset, 0, -amount); } }
public ICollection <IBalanceItem> GetBalanceItemsCombined(IAccountPredicate predicate) { return(FindItems(predicate).GroupBy(balanceItem => balanceItem.Asset).Select(grp => { return (IBalanceItem) new BalanceItem { Balance = null, // TODO Account = null, // TODO Asset = grp.Key, TotalDebit = grp.Sum(x => x.TotalDebit), TotalCredit = grp.Sum(x => x.TotalCredit) }; }).ToList()); }
public ICollection <IEntryItem> GetEntryItemsCombined(IBook book, IAccountPredicate predicate) { return(FindItems(predicate).Where(entryItem => entryItem.Book.Equals(book)).GroupBy(x => x.Asset).Select(grp => { return (IEntryItem) new EntryItem { Entry = null, // TODO Book = book, Account = null, // TODO Asset = grp.Key, Debit = grp.Sum(x => x.Debit), Credit = grp.Sum(x => x.Credit) }; }).ToList()); }
protected static IEnumerable <string> GetAllAccountIds(IBalance balance, IAccountPredicate accountPredicate) { var accountIds = balance.Items.GetBalanceItems(accountPredicate).Select(balanceItem => ((Account)balanceItem.Account).Id); var accountIdsList = new List <string>(); foreach (var accountId in accountIds) { var accountIdParts = accountId.Split(':'); for (var i = 1; i <= accountIdParts.Length; i++) { accountIdsList.Add(string.Join(":", accountIdParts.Take(i))); } } return(accountIdsList.Distinct()); }
public static IEnumerable <IEntryItem> GetEntryItems(this IEnumerable <IEntry> entries, IBook book, IAccountPredicate predicate) { return(entries.SelectMany(x => x.Items).Where(x => x.Book.Equals(book) && predicate.Matches(x.Account))); }
public IEntryItem GetEntryItemCombined(IBook book, IAccountPredicate predicate, IAsset asset) { return(GetEntryItemsCombined(book, predicate).SingleOrDefault(x => x.Asset.Equals(asset))); }
public IEntryItem GetEntryItemCombined(IBook book, IAccountPredicate predicate) { return(GetEntryItemsCombined(book, predicate).SingleOrDefault()); }
protected static IEnumerable <string> GetAccountIds(IBalance balance, IAccountPredicate accountPredicate) { return(balance.Items.GetBalanceItems(accountPredicate).Select(balanceItem => ((Account)balanceItem.Account).Id).Distinct()); }
public IBalanceItem GetBalanceItemCombined(IAccountPredicate predicate) { return(GetBalanceItemsCombined(predicate).SingleOrDefault()); }
public virtual void AddItems(ILedger ledger, IBook book, IAccountPredicate predicate, IAccount debitAccount, IAccount creditAccount, IAsset asset, decimal debit, decimal credit) { if (debit < 0) { throw new ArgumentException("Debit cannot be negative.", "debit"); } if (credit < 0) { throw new ArgumentException("Credit cannot be negative.", "credit"); } if (debit == 0 && credit == 0) { throw new ArgumentException("Must have either debit or credit specified."); } if (debit != 0 && credit != 0) { throw new ArgumentException("Cannot have both debit and credit specified."); } var balanceDebit = 0M; var balanceCredit = 0M; var balance = ledger.GetLastBalance(book); if (balance != null) { var balanceItem = balance.Items.GetBalanceItemCombined(predicate, asset); if (balanceItem != null) { balanceDebit = balanceItem.BalanceDebit; balanceCredit = balanceItem.BalanceCredit; } } if (debit != 0) { if (balanceCredit != 0) { if (balanceCredit >= debit) { AddItem(book, creditAccount, asset, debit, 0); } else { AddItem(book, creditAccount, asset, balanceCredit, 0); AddItem(book, debitAccount, asset, debit - balanceCredit, 0); } return; } AddItem(book, debitAccount, asset, debit, 0); } if (credit != 0) { if (balanceDebit != 0) { if (balanceDebit >= credit) { AddItem(book, debitAccount, asset, 0, credit); } else { AddItem(book, debitAccount, asset, 0, balanceDebit); AddItem(book, creditAccount, asset, 0, credit - balanceDebit); } return; } AddItem(book, creditAccount, asset, 0, credit); } }
public AccountsBalanceBalanceValidator(IBook book, IAccountPredicate accountPredicate1, IAccountPredicate accountPredicate2) { _book = book; _accountPredicate1 = accountPredicate1; _accountPredicate2 = accountPredicate2; }
public AccountsBalanceEntryValidator(IAccountPredicate accountPredicate1, IAccountPredicate accountPredicate2) { _accountPredicate1 = accountPredicate1; _accountPredicate2 = accountPredicate2; }
public IEnumerable <IEntryItem> GetEntryItemsAtOrBetween(IBook book, IAccountPredicate accountPredicate, IComparable startIndex, IComparable endIndex) { return(_store.GetEntryItems(book, accountPredicate, startIndex, startInclusive: true, endIndex: endIndex, endInclusive: true)); }
public IBalanceItem GetBalanceItem(IAccountPredicate predicate) { return(FindItems(predicate).SingleOrDefault()); }
public ICollection <IBalanceItem> GetBalanceItems(IAccountPredicate predicate) { return(FindItems(predicate)); }
public IEntryItem GetEntryItem(IBook book, IAccountPredicate predicate) { return(FindItems(predicate).SingleOrDefault(entryItem => entryItem.Book.Equals(book))); }
public IBalanceItem GetBalanceItemCombined(IAccountPredicate predicate, IAsset asset) { return(GetBalanceItemsCombined(predicate).SingleOrDefault(balanceItem => balanceItem.Asset.Equals(asset))); }
public ICollection <IEntryItem> GetEntryItems(IAccountPredicate predicate) { return(FindItems(predicate)); }
public ICollection <IEntryItem> GetEntryItems(IBook book, IAccountPredicate predicate) { return(FindItems(predicate).Where(entryItem => entryItem.Book.Equals(book)).ToList()); }
public AccountBalanceCreditZeroBalanceValidator(IBook book, IAccountPredicate accountPredicate) { _book = book; _accountPredicate = accountPredicate; }