add group function to auto-insert an account code

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1322 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-10-19 00:49:35 +00:00
parent a20bc2b30b
commit 2b174a1f1a
2 changed files with 89 additions and 26 deletions

View File

@ -351,6 +351,7 @@ xaccRemoveAccount (Account *acc)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
void void
xaccInsertSubAccount( Account *adult, Account *child ) xaccInsertSubAccount( Account *adult, Account *child )
{ {
@ -467,6 +468,33 @@ xaccRecomputeGroupBalance (AccountGroup *grp)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
void
xaccGroupDepthAutoCode (AccountGroup *grp)
{
int depth;
/* get the depth */
depth = xaccGroupGetDepth (grp);
if (3>depth) depth = 3;
xaccGroupAutoCode (grp, depth);
}
void
xaccGroupAutoCode (AccountGroup *grp, int depth)
{
int i;
for (i=0; i<grp->numAcc; i++) {
Account *acc = grp->account[i];
xaccAccountAutoCode (acc, depth);
xaccGroupAutoCode (acc->children, depth);
}
}
/********************************************************************\
\********************************************************************/
void void
xaccConcatGroups (AccountGroup *togrp, AccountGroup *fromgrp) xaccConcatGroups (AccountGroup *togrp, AccountGroup *fromgrp)
{ {
@ -595,4 +623,22 @@ xaccGroupGetBalance (AccountGroup * grp)
return (grp->balance); return (grp->balance);
} }
/********************************************************************\
\********************************************************************/
int
xaccGroupGetDepth (AccountGroup *grp)
{
int i, depth=0, maxdepth=0;
if (!grp) return 0;
for (i=0; i<grp->numAcc; i++) {
depth = xaccGroupGetDepth (grp->account[i]->children);
if (depth > maxdepth) maxdepth = depth;
}
maxdepth++;
return maxdepth;
}
/****************** END OF FILE *************************************/ /****************** END OF FILE *************************************/

View File

@ -80,14 +80,17 @@ void xaccInsertSubAccount( Account *parent, Account *child );
/* /*
* The xaccGetNumAccounts() subroutine returns the number * The xaccGetNumAccounts() subroutine returns the number
* of accounts, including subaccounts, in the account group * of accounts, including subaccounts, in the account group
*/ *
int xaccGetNumAccounts (AccountGroup *grp);
/*
* The xaccGroupGetNumAccounts() subroutine returns the number * The xaccGroupGetNumAccounts() subroutine returns the number
* of accounts in the indicated group only (children not counted). * of accounts in the indicated group only (children not counted).
*
* The xaccGroupGetDepth() subroutine returns the length of the
* longest tree branch. Each link between an account and its
* (non-null) children counts as one unit of length.
*/ */
int xaccGetNumAccounts (AccountGroup *grp);
int xaccGroupGetNumAccounts (AccountGroup *grp); int xaccGroupGetNumAccounts (AccountGroup *grp);
int xaccGroupGetDepth (AccountGroup *grp);
/* /*
* The xaccGetAccountFromID() subroutine fetches the account * The xaccGetAccountFromID() subroutine fetches the account
@ -143,4 +146,18 @@ void xaccConsolidateGrpTransactions (AccountGroup *);
Account * xaccGroupGetAccount (AccountGroup *, int); Account * xaccGroupGetAccount (AccountGroup *, int);
double xaccGroupGetBalance (AccountGroup *); double xaccGroupGetBalance (AccountGroup *);
/*
* The xaccGroupAutoCode() method will traverse the group, automatically
* inserting account codes into those accounts whose account codes
* are blank. It uses the algorithm used in xaccAccountAutoCode()
* to pick an account code.
*
* The xaccGroupDepthAutoCode() first measures teh depth of the account
* tree, and uses that depth to pck the number of digits in the account
* code.
*/
void xaccGroupAutoCode (AccountGroup *grp, int num_digits);
void xaccGroupDepthAutoCode (AccountGroup *grp);
#endif /* __XACC_ACCOUNT_GROUP_H__ */ #endif /* __XACC_ACCOUNT_GROUP_H__ */