mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
add auto-numbering for account codes
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1321 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
047f4c1213
commit
a20bc2b30b
@ -624,6 +624,65 @@ xaccAccountOrder (Account **aa, Account **ab)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
/* account codes will be assigned base-36, with three digits */
|
||||
|
||||
#define BASE 36
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -87,6 +87,16 @@ void xaccZeroRunningBalances (Account **list);
|
||||
*/
|
||||
int xaccAccountOrder (Account**, Account **);
|
||||
|
||||
/* The xaccAccountAutoCode() method will assign an automatically
|
||||
* generated account code to the account, if one does not already
|
||||
* exist. Account codes will have the indicated number of digits
|
||||
* in them. The numbering scheme roughly follows generally
|
||||
* accepted accounting practice, in that top-level accounts
|
||||
* will be number 100, 200, etc., second level accounts 110, 120,
|
||||
* .. 210, 220, ...etc. and third level accounts 111, 112, .. etc.
|
||||
*/
|
||||
void xaccAccountAutoCode (Account *, int digits);
|
||||
|
||||
/* The xaccConsolidateTransactions() subroutine scans through
|
||||
* all of the transactions in an account, and compares them.
|
||||
* If any of them are exact duplicates, the duplicates are removed.
|
||||
@ -95,7 +105,7 @@ int xaccAccountOrder (Account**, Account **);
|
||||
* as it may remove transactions that were not true duplicatees ...
|
||||
*/
|
||||
|
||||
void xaccConsolidateTransactions (Account *);
|
||||
void xaccConsolidateTransactions (Account *);
|
||||
|
||||
/* The xaccMoveFarEnd() method changes the account to which the
|
||||
* "far end" of the split belongs. The "far end" is as follows:
|
||||
|
Loading…
Reference in New Issue
Block a user