mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
Minimally invasive change to set cached starting balance
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3543 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
+58
-12
@@ -83,6 +83,14 @@ xaccInitAccount (Account * acc)
|
||||
acc->share_cleared_balance = gnc_numeric_zero();
|
||||
acc->share_reconciled_balance = gnc_numeric_zero();
|
||||
|
||||
acc->starting_balance = gnc_numeric_zero();
|
||||
acc->starting_cleared_balance = gnc_numeric_zero();
|
||||
acc->starting_reconciled_balance = gnc_numeric_zero();
|
||||
|
||||
acc->starting_share_balance = gnc_numeric_zero();
|
||||
acc->starting_share_cleared_balance = gnc_numeric_zero();
|
||||
acc->starting_share_reconciled_balance = gnc_numeric_zero();
|
||||
|
||||
acc->type = NO_TYPE;
|
||||
|
||||
acc->accountName = g_strdup("");
|
||||
@@ -656,12 +664,12 @@ xaccAccountRecomputeBalance (Account * acc)
|
||||
if(acc->editlevel > 0) return;
|
||||
if(!acc->balance_dirty) return;
|
||||
|
||||
dbalance = gnc_numeric_zero();
|
||||
dcleared_balance = gnc_numeric_zero();
|
||||
dreconciled_balance = gnc_numeric_zero();
|
||||
share_balance = gnc_numeric_zero();
|
||||
share_cleared_balance = gnc_numeric_zero();
|
||||
share_reconciled_balance = gnc_numeric_zero();
|
||||
dbalance = acc->starting_balance;
|
||||
dcleared_balance = acc->starting_cleared_balance;
|
||||
dreconciled_balance = acc->starting_reconciled_balance;
|
||||
share_balance = acc->starting_share_balance;
|
||||
share_cleared_balance = acc->starting_share_cleared_balance;
|
||||
share_reconciled_balance = acc->starting_share_reconciled_balance;
|
||||
|
||||
for(lp = acc->splits; lp; lp = lp->next) {
|
||||
Split *split = (Split *) lp->data;
|
||||
@@ -712,19 +720,16 @@ xaccAccountRecomputeBalance (Account * acc)
|
||||
if ( (STOCK == acc->type) ||
|
||||
(MUTUAL == acc->type) ||
|
||||
(CURRENCY == acc->type) ) {
|
||||
acc -> share_balance = share_balance;
|
||||
acc -> share_cleared_balance = share_cleared_balance;
|
||||
acc -> share_reconciled_balance = share_reconciled_balance;
|
||||
if (last_split) {
|
||||
acc -> share_balance = share_balance;
|
||||
acc -> share_cleared_balance = share_cleared_balance;
|
||||
acc -> share_reconciled_balance = share_reconciled_balance;
|
||||
acc -> balance = price_xfer(last_split, share_balance);
|
||||
acc -> cleared_balance = price_xfer(last_split, share_cleared_balance);
|
||||
acc -> reconciled_balance =
|
||||
price_xfer(last_split, share_reconciled_balance);
|
||||
}
|
||||
else {
|
||||
acc -> share_balance = gnc_numeric_zero();
|
||||
acc -> share_cleared_balance = gnc_numeric_zero();
|
||||
acc -> share_reconciled_balance = gnc_numeric_zero();
|
||||
acc -> balance = gnc_numeric_zero();
|
||||
acc -> cleared_balance = gnc_numeric_zero();
|
||||
acc -> reconciled_balance = gnc_numeric_zero();
|
||||
@@ -742,6 +747,47 @@ xaccAccountRecomputeBalance (Account * acc)
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccAccountSetStartingBalance(Account *acc,
|
||||
const gnc_numeric start_baln,
|
||||
const gnc_numeric start_cleared_baln,
|
||||
const gnc_numeric start_reconciled_baln)
|
||||
{
|
||||
if (!acc) return;
|
||||
|
||||
/* hack alert -- this routine is meant to set the one and only
|
||||
* account commodity starting balance. However, until we remove
|
||||
* the 'reporting currency' from accounts, we will have to guess
|
||||
* which to set based on the account type.
|
||||
*/
|
||||
switch (acc->type)
|
||||
{
|
||||
case BANK:
|
||||
case CASH:
|
||||
case CREDIT:
|
||||
case ASSET:
|
||||
case LIABILITY:
|
||||
case INCOME:
|
||||
case EXPENSE:
|
||||
case EQUITY:
|
||||
acc->starting_balance = start_baln;
|
||||
acc->starting_cleared_balance = start_cleared_baln;
|
||||
acc->starting_reconciled_balance = start_reconciled_baln;
|
||||
break;
|
||||
case STOCK:
|
||||
case MUTUAL:
|
||||
case CURRENCY:
|
||||
acc->starting_share_balance = start_baln;
|
||||
acc->starting_share_cleared_balance = start_cleared_baln;
|
||||
acc->starting_share_reconciled_balance = start_reconciled_baln;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
acc->balance_dirty = TRUE;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* xaccAccountFixSplitDateOrder *
|
||||
|
||||
@@ -108,6 +108,14 @@ struct _account {
|
||||
AccountGroup *children; /* pointer to sub-accounts */
|
||||
|
||||
/* protected data, cached parameters */
|
||||
gnc_numeric starting_balance;
|
||||
gnc_numeric starting_cleared_balance;
|
||||
gnc_numeric starting_reconciled_balance;
|
||||
|
||||
gnc_numeric starting_share_balance;
|
||||
gnc_numeric starting_share_cleared_balance;
|
||||
gnc_numeric starting_share_reconciled_balance;
|
||||
|
||||
gnc_numeric balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
@@ -168,4 +176,25 @@ void xaccAccountRecomputeBalance (Account *);
|
||||
* call this on an existing account! */
|
||||
void xaccAccountSetGUID (Account *account, GUID *guid);
|
||||
|
||||
/* The xaccAccountSetStartingBalance() routine will set the starting
|
||||
* commodity balance for this account. This routine is intended for
|
||||
* use with backends that do not return the complete list of splits
|
||||
* for an account, but rather return a partial list. In such a case,
|
||||
* the backend will typically return all of the splits after some
|
||||
* certain date, and the 'starting balance' will represent the summation
|
||||
* of the splits up to that date.
|
||||
*
|
||||
* Design Note: this routine assumes that there is only one commodity
|
||||
* associated with this account, and that the reporting currency will
|
||||
* no longer be stored with the account.
|
||||
*
|
||||
* This routine is in the private .h file because only backends are
|
||||
* allowed to set the starting balance. This is *not* a user interface
|
||||
* function.
|
||||
*/
|
||||
void xaccAccountSetStartingBalance(Account *account,
|
||||
const gnc_numeric start_baln,
|
||||
const gnc_numeric start_cleared_baln,
|
||||
const gnc_numeric start_reconciled_baln);
|
||||
|
||||
#endif /* __XACC_ACCOUNT_P_H__ */
|
||||
|
||||
Reference in New Issue
Block a user