mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
implement account merge
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@179 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
ba1e24a487
commit
d7c0ade60a
@ -105,6 +105,7 @@ freeAccount( Account *acc )
|
||||
Transaction *trans = acc->transaction[i];
|
||||
struct _account * _acc = (struct _account *) acc;
|
||||
|
||||
if (!trans) continue;
|
||||
/* free the transaction only if its not
|
||||
* a part of a double entry */
|
||||
if (_acc == trans->credit) trans->credit = NULL;
|
||||
|
63
src/Data.c
63
src/Data.c
@ -499,7 +499,7 @@ xaccGetRootGroupOfAcct (Account *acc)
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccMergeGroup (AccountGroup *togrp, AccountGroup *fromgrp)
|
||||
xaccConcatGroups (AccountGroup *togrp, AccountGroup *fromgrp)
|
||||
{
|
||||
Account * acc;
|
||||
int i;
|
||||
@ -517,4 +517,65 @@ xaccMergeGroup (AccountGroup *togrp, AccountGroup *fromgrp)
|
||||
fromgrp->numAcc = 0;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccMergeAccounts (AccountGroup *grp)
|
||||
{
|
||||
Account *acc_a, *acc_b;
|
||||
int i,j, k;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
for (i=0; i<grp->numAcc; i++) {
|
||||
acc_a = grp->account[i];
|
||||
for (j=i+1; j<grp->numAcc; j++) {
|
||||
acc_b = grp->account[j];
|
||||
if ((0 == strcmp(acc_a->accountName, acc_b->accountName)) &&
|
||||
(0 == strcmp(acc_a->description, acc_b->description)) &&
|
||||
(0 == strcmp(acc_a->notes, acc_b->notes)) &&
|
||||
(acc_a->type == acc_b->type)) {
|
||||
|
||||
AccountGroup *ga, *gb;
|
||||
|
||||
/* consolidate children */
|
||||
ga = (AccountGroup *) acc_a->children;
|
||||
gb = (AccountGroup *) acc_b->children;
|
||||
if (gb) {
|
||||
if (!ga) {
|
||||
acc_a->children = (struct _account_group *) gb;
|
||||
gb->parent = acc_a;
|
||||
acc_b->children = NULL;
|
||||
} else {
|
||||
xaccConcatGroups (ga, gb);
|
||||
freeAccountGroup (gb);
|
||||
acc_b->children = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* recurse to do the children's children */
|
||||
xaccMergeAccounts (ga);
|
||||
|
||||
/* consolidate transactions */
|
||||
for (k=0; k<acc_b->numTrans; k++) {
|
||||
Transaction *trans;
|
||||
trans = acc_b->transaction[k];
|
||||
acc_b->transaction[k] = NULL;
|
||||
if (acc_b == (Account *) trans->debit) trans->debit = (struct _account *) acc_a;
|
||||
if (acc_b == (Account *) trans->credit) trans->credit = (struct _account *) acc_a;
|
||||
insertTransaction (acc_a, trans);
|
||||
}
|
||||
|
||||
/* free the account structure itself */
|
||||
acc_b->numTrans = 0;
|
||||
freeAccount (acc_b);
|
||||
grp->account[j] = grp->account[grp->numAcc -1];
|
||||
grp->account[grp->numAcc -1] = NULL;
|
||||
grp->numAcc --;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************** END OF FILE *************************************/
|
||||
|
@ -886,7 +886,8 @@ fileMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
|
||||
|
||||
/* since quicken will not export all accounts
|
||||
* into one file, we must merge them in one by one */
|
||||
xaccMergeGroup (topgroup, grp);
|
||||
xaccConcatGroups (topgroup, grp);
|
||||
xaccMergeAccounts (topgroup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
18
src/QIFIO.c
18
src/QIFIO.c
@ -140,6 +140,7 @@ char * xaccReadQIFCategory (int fd, Account * acc)
|
||||
acc -> type = -1; /* type is byte */
|
||||
acc -> accountName = 0x0; /* string */
|
||||
acc -> description = 0x0; /* string */
|
||||
acc -> notes = 0x0; /* string */
|
||||
|
||||
qifline = xaccReadQIFLine (fd);
|
||||
if (!qifline) return NULL;
|
||||
@ -187,6 +188,7 @@ char * xaccReadQIFCategory (int fd, Account * acc)
|
||||
|
||||
XACC_PREP_NULL_STRING (acc->accountName);
|
||||
XACC_PREP_NULL_STRING (acc->description);
|
||||
XACC_PREP_NULL_STRING (acc->notes);
|
||||
|
||||
return qifline;
|
||||
}
|
||||
@ -210,6 +212,7 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
||||
acc -> type = -1; /* type is byte */
|
||||
acc -> accountName = 0x0; /* string */
|
||||
acc -> description = 0x0; /* string */
|
||||
acc -> notes = 0x0; /* string */
|
||||
|
||||
qifline = xaccReadQIFLine (fd);
|
||||
if (!qifline) return NULL;
|
||||
@ -259,6 +262,7 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
||||
|
||||
XACC_PREP_NULL_STRING (acc->accountName);
|
||||
XACC_PREP_NULL_STRING (acc->description);
|
||||
XACC_PREP_NULL_STRING (acc->notes);
|
||||
|
||||
return qifline;
|
||||
}
|
||||
@ -483,6 +487,8 @@ xaccGetXferQIFAccount (Account *acc, char *qifline)
|
||||
if (!xfer_acc) {
|
||||
xfer_acc = mallocAccount ();
|
||||
xfer_acc->accountName = XtNewString (qifline);
|
||||
xfer_acc->description = XtNewString ("");
|
||||
xfer_acc->notes = XtNewString ("");
|
||||
xfer_acc->type = BANK;
|
||||
insertAccount (rootgrp, xfer_acc);
|
||||
}
|
||||
@ -520,6 +526,8 @@ xaccGetSecurityQIFAccount (Account *acc, char *qifline)
|
||||
if (!xfer_acc) {
|
||||
xfer_acc = mallocAccount ();
|
||||
xfer_acc->accountName = XtNewString (qifline);
|
||||
xfer_acc->description = XtNewString ("");
|
||||
xfer_acc->notes = XtNewString ("");
|
||||
xfer_acc->type = STOCK;
|
||||
xaccInsertSubAccount (acc, xfer_acc);
|
||||
}
|
||||
@ -723,8 +731,12 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
|
||||
} else
|
||||
if ('!' == qifline [0]) break;
|
||||
qifline = xaccReadQIFLine (fd);
|
||||
|
||||
}
|
||||
|
||||
/* at this point, we should see an end-of-transaction marker
|
||||
* if we see something else, assume the worst, free the last
|
||||
* transaction, and return */
|
||||
if ('!' == qifline[0]) {
|
||||
xaccRemoveTransaction ((Account *) trans->debit, trans);
|
||||
xaccRemoveTransaction ((Account *) trans->credit, trans);
|
||||
@ -808,6 +820,8 @@ char * xaccReadQIFTransList (int fd, Account *acc)
|
||||
if (!acc) return 0x0;
|
||||
do {
|
||||
qifline = xaccReadQIFTransaction (fd, acc);
|
||||
|
||||
if ('!' == qifline[0]) break;
|
||||
} while (qifline);
|
||||
return qifline;
|
||||
}
|
||||
@ -856,6 +870,8 @@ xaccReadQIFData( char *datafile )
|
||||
|
||||
acc->type = BANK;
|
||||
acc->accountName = XtNewString ("Quicken Bank Account");
|
||||
acc->description = XtNewString ("");
|
||||
acc->notes = XtNewString ("");
|
||||
|
||||
insertAccount( grp, acc );
|
||||
qifline = xaccReadQIFTransList (fd, acc);
|
||||
@ -880,6 +896,8 @@ xaccReadQIFData( char *datafile )
|
||||
|
||||
acc->type = BANK;
|
||||
acc->accountName = XtNewString ("Quicken Investment Account");
|
||||
acc->description = XtNewString ("");
|
||||
acc->notes = XtNewString ("");
|
||||
|
||||
insertAccount( grp, acc );
|
||||
qifline = xaccReadQIFTransList (fd, acc);
|
||||
|
Loading…
Reference in New Issue
Block a user