mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
implemnt elimination of dup transactions
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@180 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d7c0ade60a
commit
ddcdc1fd0e
@ -737,4 +737,60 @@ xaccZeroRunningBalances( Account **list )
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccConsolidateTransactions (Account * acc)
|
||||
{
|
||||
Transaction *ta, *tb;
|
||||
int i,j,k;
|
||||
|
||||
if (!acc) return;
|
||||
|
||||
for (i=0; i<acc->numTrans; i++) {
|
||||
ta = acc->transaction[i];
|
||||
for (j=i+1; j<acc->numTrans; j++) {
|
||||
tb = acc->transaction[j];
|
||||
|
||||
/* if no match, then continue on in the loop.
|
||||
* we really must match everything to get a duplicate */
|
||||
if (ta->credit != tb->credit) continue;
|
||||
if (ta->debit != tb->debit) continue;
|
||||
if (ta->reconciled != tb->reconciled) continue;
|
||||
if (ta->date.year != tb->date.year) continue;
|
||||
if (ta->date.month != tb->date.month) continue;
|
||||
if (ta->date.day != tb->date.day) continue;
|
||||
if (strcmp (ta->num, tb->num)) continue;
|
||||
if (strcmp (ta->description, tb->description)) continue;
|
||||
if (strcmp (ta->memo, tb->memo)) continue;
|
||||
if (strcmp (ta->action, tb->action)) continue;
|
||||
if (0 == DEQ(ta->damount, tb->damount)) continue;
|
||||
if (0 == DEQ(ta->share_price, tb->share_price)) continue;
|
||||
|
||||
/* if we got to here, then there must be a duplicate. */
|
||||
/* before deleting it, remove it from the other
|
||||
* double-entry account */
|
||||
if (acc == (Account *) tb->credit) {
|
||||
xaccRemoveTransaction ((Account *) tb->debit, tb);
|
||||
}
|
||||
if (acc == (Account *) tb->debit) {
|
||||
xaccRemoveTransaction ((Account *) tb->credit, tb);
|
||||
}
|
||||
tb->credit = NULL;
|
||||
tb->debit = NULL;
|
||||
|
||||
/* Free the transaction, and shuffle down by one.
|
||||
* Need to shuffle in order to preserve date ordering. */
|
||||
freeTransaction (tb);
|
||||
|
||||
for (k=j+1; k<acc->numTrans; k++) {
|
||||
acc->transaction[k-1] = acc->transaction[k];
|
||||
}
|
||||
acc->transaction[acc->numTrans -1] = NULL;
|
||||
acc->numTrans --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** END OF FILE **************************** */
|
||||
|
20
src/Data.c
20
src/Data.c
@ -578,4 +578,24 @@ xaccMergeAccounts (AccountGroup *grp)
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccConsolidateGrpTransactions (AccountGroup *grp)
|
||||
{
|
||||
Account * acc;
|
||||
int i;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
for (i=0; i<grp->numAcc; i++) {
|
||||
acc = grp->account[i];
|
||||
xaccConsolidateTransactions (acc);
|
||||
|
||||
/* recursively do the children */
|
||||
xaccConsolidateGrpTransactions (acc->children);
|
||||
}
|
||||
}
|
||||
|
||||
/****************** END OF FILE *************************************/
|
||||
|
@ -888,6 +888,7 @@ fileMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
|
||||
* into one file, we must merge them in one by one */
|
||||
xaccConcatGroups (topgroup, grp);
|
||||
xaccMergeAccounts (topgroup);
|
||||
xaccConsolidateGrpTransactions (topgroup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user