gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Mar 14 18:58:27 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/f182d9f9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/50674ef6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a8f03cf1 (commit)
	from  https://github.com/Gnucash/gnucash/commit/cfa16258 (commit)



commit f182d9f9121130b49320e82810a924b73d69a6b9
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Mar 5 19:57:22 2020 +0800

    Bug 797640 - The Reconciliation Window starting balance calculator needs to ignore splits after statement date

diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index 22e2cbb53..76a1ac0bd 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -281,7 +281,8 @@ recnRecalculateBalance (RecnWindow *recnData)
 
     /* update the starting balance */
     include_children = xaccAccountGetReconcileChildrenStatus(account);
-    starting = gnc_ui_account_get_reconciled_balance(account, include_children);
+    starting = gnc_ui_account_get_reconciled_balance_as_of_date
+        (account, recnData->statement_date, include_children);
     print_info = gnc_account_print_info (account, TRUE);
 
     /*

commit 50674ef6325e18776b330215b163eed3136fe35c
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Mar 5 19:56:56 2020 +0800

    [gnc-ui-balances] add and expose gnc_ui_account_get_reconciled_balance_as_of_date

diff --git a/libgnucash/app-utils/gnc-ui-balances.c b/libgnucash/app-utils/gnc-ui-balances.c
index 8529f7dba..b02fe76cb 100644
--- a/libgnucash/app-utils/gnc-ui-balances.c
+++ b/libgnucash/app-utils/gnc-ui-balances.c
@@ -179,11 +179,11 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
     return g_strdup(xaccPrintAmount(balance, print_info));
 }
 
-
-gnc_numeric
-gnc_ui_account_get_balance_as_of_date (Account *account,
-                                       time64 date,
-                                       gboolean include_children)
+static gnc_numeric
+account_get_balance_as_of_date (Account *account,
+                                time64 date,
+                                gboolean include_children,
+                                xaccGetBalanceAsOfDateFn fn)
 {
     QofBook *book = gnc_account_get_book (account);
     GNCPriceDB *pdb = gnc_pricedb_get_db (book);
@@ -194,7 +194,7 @@ gnc_ui_account_get_balance_as_of_date (Account *account,
         return gnc_numeric_zero ();
 
     currency = xaccAccountGetCommodity (account);
-    balance = xaccAccountGetBalanceAsOfDate (account, date);
+    balance = fn (account, date);
 
     if (include_children)
     {
@@ -210,7 +210,7 @@ gnc_ui_account_get_balance_as_of_date (Account *account,
 
             child = node->data;
             child_currency = xaccAccountGetCommodity (child);
-            child_balance = xaccAccountGetBalanceAsOfDate (child, date);
+            child_balance = fn (child, date);
             child_balance =
                 gnc_pricedb_convert_balance_latest_price (pdb, child_balance,
                                                           child_currency,
@@ -228,6 +228,24 @@ gnc_ui_account_get_balance_as_of_date (Account *account,
     return balance;
 }
 
+gnc_numeric
+gnc_ui_account_get_balance_as_of_date (Account *account,
+                                       time64 date,
+                                       gboolean include_children)
+{
+    return account_get_balance_as_of_date (account, date, include_children,
+                                           xaccAccountGetBalanceAsOfDate);
+}
+
+gnc_numeric
+gnc_ui_account_get_reconciled_balance_as_of_date (Account *account,
+                                                  time64 date,
+                                                  gboolean include_children)
+{
+    return account_get_balance_as_of_date (account, date, include_children,
+                                           xaccAccountGetReconciledBalanceAsOfDate);
+}
+
 
 /********************************************************************
  * Balance calculations related to owners
diff --git a/libgnucash/app-utils/gnc-ui-balances.h b/libgnucash/app-utils/gnc-ui-balances.h
index 8c8289ee8..3479f7477 100644
--- a/libgnucash/app-utils/gnc-ui-balances.h
+++ b/libgnucash/app-utils/gnc-ui-balances.h
@@ -110,6 +110,10 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
 gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
 						   time64 date,
 						   gboolean include_children);
+gnc_numeric
+gnc_ui_account_get_reconciled_balance_as_of_date (Account *account,
+                                                  time64 date,
+                                                  gboolean include_children);
 
 /********************************************************************
  * Balance calculations related to owners

commit a8f03cf1c8649227200296e7d5785459ebf4ee17
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Mar 5 19:56:33 2020 +0800

    [account] add and expose xaccAccountGetReconciledBalanceAsOfDate

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index ea976be49..ebe8f3851 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3428,6 +3428,24 @@ xaccAccountGetNoclosingBalanceAsOfDate (Account *acc, time64 date)
     return GetBalanceAsOfDate (acc, date, TRUE);
 }
 
+gnc_numeric
+xaccAccountGetReconciledBalanceAsOfDate (Account *acc, time64 date)
+{
+    gnc_numeric balance = gnc_numeric_zero();
+
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+
+    for (GList *node = GET_PRIVATE(acc)->splits; node; node = node->next)
+    {
+        Split *split = (Split*) node->data;
+        if ((xaccSplitGetReconcile (split) == YREC) &&
+            (xaccSplitGetDateReconciled (split) <= date))
+            balance = gnc_numeric_add_fixed (balance, xaccSplitGetAmount (split));
+    };
+
+    return balance;
+}
+
 /*
  * Originally gsr_account_present_balance in gnc-split-reg.c
  *
diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h
index 92ee17ab5..e778bc86f 100644
--- a/libgnucash/engine/Account.h
+++ b/libgnucash/engine/Account.h
@@ -558,6 +558,9 @@ gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account);
 gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account,
         time64 date);
 
+/** Get the reconciled balance of the account as of the date specified */
+gnc_numeric xaccAccountGetReconciledBalanceAsOfDate (Account *account, time64 date);
+
 /* These two functions convert a given balance from one commodity to
    another.  The account argument is only used to get the Book, and
    may have nothing to do with the supplied balance.  Likewise, the



Summary of changes:
 gnucash/gnome/window-reconcile.c       |  3 ++-
 libgnucash/app-utils/gnc-ui-balances.c | 32 +++++++++++++++++++++++++-------
 libgnucash/app-utils/gnc-ui-balances.h |  4 ++++
 libgnucash/engine/Account.cpp          | 18 ++++++++++++++++++
 libgnucash/engine/Account.h            |  3 +++
 5 files changed, 52 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list