From 8def3ba26e54a186bec421c585cf7b655fe90f5c Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 13 Mar 2020 19:37:56 +0800 Subject: [PATCH] [account.cpp] refactor xaccAccountGetPresentBalance instead of starting from account->splits tail then backtrack, reuse existing code. --- libgnucash/engine/Account.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index ebe8f38518..f74aaf4d1b 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -3448,32 +3448,14 @@ xaccAccountGetReconciledBalanceAsOfDate (Account *acc, time64 date) /* * Originally gsr_account_present_balance in gnc-split-reg.c - * - * How does this routine compare to xaccAccountGetBalanceAsOfDate just - * above? These two routines should eventually be collapsed into one. - * Perhaps the startup logic from that one, and the logic from this - * one that walks from the tail of the split list. */ gnc_numeric xaccAccountGetPresentBalance (const Account *acc) { - AccountPrivate *priv; - GList *node; - time64 today; - g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero()); - priv = GET_PRIVATE(acc); - today = gnc_time64_get_today_end(); - for (node = g_list_last(priv->splits); node; node = node->prev) - { - Split *split = static_cast(node->data); - - if (xaccTransGetDate (xaccSplitGetParent (split)) <= today) - return xaccSplitGetBalance (split); - } - - return gnc_numeric_zero (); + return xaccAccountGetBalanceAsOfDate (GNC_ACCOUNT (acc), + gnc_time64_get_today_end ()); }