oops, we need another routine to do the right thing ...

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1328 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-10-19 06:17:23 +00:00
parent 079754e1c8
commit b81b256508
2 changed files with 65 additions and 1 deletions

View File

@ -513,6 +513,66 @@ xaccGroupGetNextFreeCode (AccountGroup *grp, int digits)
return retval; return retval;
} }
/********************************************************************\
\********************************************************************/
/* almost identical code to above, but altered to deal with
* specified account */
char *
xaccAccountGetNextChildCode (Account *parent_acc, int digits)
{
Account *acc;
int i, maxcode = 0;
char * retval;
AccountGroup *grp;
if (!parent_acc) return NULL;
/* count levels to top */
acc = parent_acc;
while (acc) {
digits --;
assert (acc->parent); /* all acounts must be in a group */
acc = acc->parent->parent;
}
/* if (0>digits) we could insert a decimal place, but I am too lazy
* to write this code. It doesn't seem important at the moment ... */
/* find the largest used code */
acc = parent_acc;
if (acc) {
if (acc->accountCode) {
maxcode = strtol (acc->accountCode, NULL, BASE);
}
}
grp = parent_acc->children;
if (grp) {
for (i=0; i<grp->numAcc; i++) {
Account *acnt = grp->account[i];
if (acnt->accountCode) {
int code = strtol (acnt->accountCode, NULL, BASE);
if (code > maxcode) maxcode = code;
}
}
}
/* right-shift */
for (i=1; i<digits; i++) {
maxcode /= BASE;
}
maxcode ++;
/* left-shift */
for (i=1; i<digits; i++) {
maxcode *= BASE;
}
/* print */
retval = ultostr ((unsigned long) maxcode, BASE);
return retval;
}
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/

View File

@ -147,9 +147,12 @@ Account * xaccGroupGetAccount (AccountGroup *, int);
double xaccGroupGetBalance (AccountGroup *); double xaccGroupGetBalance (AccountGroup *);
/* /*
* The xaccGroupNextFreeCode() method will try to guess a reasonable * The xaccGroupGetNextFreeCode() method will try to guess a reasonable
* candidate for the next unused account code in this group. * candidate for the next unused account code in this group.
* *
* The xaccAccountGetNextChildCode() method does same as above,
* except that it returns a value appropriate for a child account.
*
* The xaccGroupAutoCode() method will traverse the group, automatically * The xaccGroupAutoCode() method will traverse the group, automatically
* inserting account codes into those accounts whose account codes * inserting account codes into those accounts whose account codes
* are blank. It uses the algorithm used in xaccAccountAutoCode() * are blank. It uses the algorithm used in xaccAccountAutoCode()
@ -161,6 +164,7 @@ double xaccGroupGetBalance (AccountGroup *);
*/ */
char * xaccGroupGetNextFreeCode (AccountGroup *grp, int num_digits); char * xaccGroupGetNextFreeCode (AccountGroup *grp, int num_digits);
char * xaccAccountGetNextChildCode (Account *acc, int num_digits);
void xaccGroupAutoCode (AccountGroup *grp, int num_digits); void xaccGroupAutoCode (AccountGroup *grp, int num_digits);
void xaccGroupDepthAutoCode (AccountGroup *grp); void xaccGroupDepthAutoCode (AccountGroup *grp);