/// <summary> /// Get acc hierarchy starting from any give nod in th eorginal chain /// </summary> /// <param name="accGUID"></param> /// <returns></returns> public Account GetAccountHierarchy(string accGUID) { var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; var rootAcc = gnuCashRecordRoot.Book.Account.Where(x => x.id.Value == accGUID).FirstOrDefault(); accListExceptRoot = gnuCashRecordRoot.Book.Account.Where(x => x.parent != null).ToList(); AddChildren(GetEquivalentAccout(rootAcc), true); return(this.rootAccWithHierarchy); }
public static GNUCashMgr GetInstance() { if (instance == null) { instance = new GNUCashMgr(); } return(instance); }
/// <summary> /// Get the full Acc Hierarchy from the root. /// </summary> /// <returns></returns> public Account GetAccountHierarchy() { var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; var rootAcc = gnuCashRecordRoot.Book.Account.Where(x => x.parent.Value == "-1").FirstOrDefault(); if (this.accListExceptRoot == null) { accListExceptRoot = gnuCashRecordRoot.Book.Account.Where(x => x.parent.Value != "-1").ToList(); } AddChildren(GetEquivalentAccout(rootAcc), true); return(this.rootAccWithHierarchy); }
public void BasicParentPrint() { var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; foreach (var acc in gnuCashRecordRoot.Book.Account) { Console.WriteLine(acc.name); var parentAcc = gnuCashRecordRoot.Book.Account.Where(x => x.id.Value.Equals(acc.parent.Value)).FirstOrDefault(); var parentAccName = ""; if (parentAcc != null) { parentAccName = parentAcc.name; } Console.WriteLine("parent=" + parentAccName); } }
public static bool ISTHISCANDIDATEX(this IEnumerable <XMLSplitsSplit> XMLSplits, string accountGUID) { bool found = false; var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; foreach (var xmlSplit in XMLSplits) { var acc = GNUCashMgr.GetInstance().GetXMLAccount(xmlSplit.account.Value); found = acc.IsAncestor(accountGUID); if (found) { break; } else { Console.WriteLine(); } } //GNUCashAccMgr accMgr = new GNUCashAccMgr(); ////var hierarchyForChosenParent = accMgr.GetAccountHierarchy(accountGUID); ////var accList = GNUCashAccMgr.FlattenAccountHierarchy(hierarchyForChosenParent); //accMgr.i //foreach (var acc in accList) //{ // if( XMLSplits.Any(x => x.account.Value == acc.GUID)) // { // var qualifiedSplite= XMLSplits.Where(x => x.account.Value == acc.GUID).FirstOrDefault(); // qualifiedSplite.Mark = "YES THIS IS THE ONE CHOSEN"; // var couterpartSplit = XMLSplits.Where(x => x.account.Value != acc.GUID).FirstOrDefault(); // couterpartSplit.Mark = "THE COUNTERPART";//This will help avoid cleaning for the next run where both could be marked as chosen. // found = true; // break; // } //} return(found); }
public List <XMLBookTransaction> GetXMLTramsactions(string accGUID, bool isRecursive) { List <XMLBookTransaction> transactions = null; if (isRecursive) { var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; transactions = gnuCashRecordRoot.Book.Transaction.Where(transaction => transaction.splits.ISTHISCANDIDATEX(accGUID)).ToList(); } else { //TODO --Test this non recursive version-its untested yet. var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; transactions = gnuCashRecordRoot.Book.Transaction.Where(transaction => transaction.splits.Any(split => split.account.Value == accGUID)).ToList(); } return(transactions); }
public static string GetAccNameByGUID(string accGUID) { var gnuCashRecordRoot = GNUCashMgr.GetInstance().GnuCashRecordRoot; return(gnuCashRecordRoot.Book.Account.Where(x => x.id.Value == accGUID).FirstOrDefault().name); }