mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-27 11:20:27 -06:00
[account.cpp] refactor xaccAccountGetPresentBalance
instead of starting from account->splits tail then backtrack, reuse existing code.
This commit is contained in:
parent
f182d9f912
commit
8def3ba26e
@ -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<Split*>(node->data);
|
||||
|
||||
if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
|
||||
return xaccSplitGetBalance (split);
|
||||
}
|
||||
|
||||
return gnc_numeric_zero ();
|
||||
return xaccAccountGetBalanceAsOfDate (GNC_ACCOUNT (acc),
|
||||
gnc_time64_get_today_end ());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user