mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-23 01:16:43 -06:00
move account code tools to different file
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1327 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a9e8460f68
commit
079754e1c8
@ -630,55 +630,12 @@ xaccAccountOrder (Account **aa, Account **ab)
|
||||
void
|
||||
xaccAccountAutoCode (Account *acc, int digits)
|
||||
{
|
||||
Account *rent;
|
||||
int maxcode = 0;
|
||||
AccountGroup *top = acc->parent;
|
||||
int i;
|
||||
|
||||
if (!acc) return;
|
||||
if (acc->accountCode) return; /* no-op if code already assinged */
|
||||
if (!(acc->parent)) return;
|
||||
|
||||
/* count levels to top */
|
||||
rent = acc->parent->parent;
|
||||
while (rent) {
|
||||
digits --;
|
||||
assert (rent->parent);
|
||||
rent = rent->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 */
|
||||
rent = acc->parent->parent;
|
||||
if (rent) {
|
||||
if (rent->accountCode) {
|
||||
maxcode = strtol (rent->accountCode, NULL, BASE);
|
||||
}
|
||||
}
|
||||
for (i=0; i<top->numAcc; i++) {
|
||||
Account *acnt = top->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 */
|
||||
acc->accountCode = ultostr ((unsigned long) maxcode, BASE);
|
||||
top->saved = FALSE;
|
||||
acc->accountCode = xaccGroupGetNextFreeCode (acc->parent, digits);
|
||||
acc->parent->saved = FALSE;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -456,6 +456,63 @@ xaccRecomputeGroupBalance (AccountGroup *grp)
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
/* account codes will be assigned base-36, with three digits */
|
||||
|
||||
#define BASE 36
|
||||
|
||||
char *
|
||||
xaccGroupGetNextFreeCode (AccountGroup *grp, int digits)
|
||||
{
|
||||
Account *acc;
|
||||
int i, maxcode = 0;
|
||||
char * retval;
|
||||
|
||||
if (!grp) return NULL;
|
||||
|
||||
/* count levels to top */
|
||||
acc = grp->parent;
|
||||
while (acc) {
|
||||
digits --;
|
||||
assert (acc->parent);
|
||||
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 = grp->parent;
|
||||
if (acc) {
|
||||
if (acc->accountCode) {
|
||||
maxcode = strtol (acc->accountCode, NULL, BASE);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -147,6 +147,9 @@ Account * xaccGroupGetAccount (AccountGroup *, int);
|
||||
double xaccGroupGetBalance (AccountGroup *);
|
||||
|
||||
/*
|
||||
* The xaccGroupNextFreeCode() method will try to guess a reasonable
|
||||
* candidate for the next unused account code in this group.
|
||||
*
|
||||
* 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()
|
||||
@ -157,7 +160,8 @@ double xaccGroupGetBalance (AccountGroup *);
|
||||
* code.
|
||||
*/
|
||||
|
||||
void xaccGroupAutoCode (AccountGroup *grp, int num_digits);
|
||||
void xaccGroupDepthAutoCode (AccountGroup *grp);
|
||||
char * xaccGroupGetNextFreeCode (AccountGroup *grp, int num_digits);
|
||||
void xaccGroupAutoCode (AccountGroup *grp, int num_digits);
|
||||
void xaccGroupDepthAutoCode (AccountGroup *grp);
|
||||
|
||||
#endif /* __XACC_ACCOUNT_GROUP_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user