From ddcdc1fd0e817eef6f68b8aa65afcc0562425a38 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 29 Nov 1997 07:51:33 +0000 Subject: [PATCH] implemnt elimination of dup transactions git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@180 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Account.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Data.c | 20 +++++++++++++++++ src/MainWindow.c | 1 + 3 files changed, 77 insertions(+) diff --git a/src/Account.c b/src/Account.c index 3588185f00..64e3180637 100644 --- a/src/Account.c +++ b/src/Account.c @@ -737,4 +737,60 @@ xaccZeroRunningBalances( Account **list ) } } +/********************************************************************\ +\********************************************************************/ + +void +xaccConsolidateTransactions (Account * acc) +{ + Transaction *ta, *tb; + int i,j,k; + + if (!acc) return; + + for (i=0; inumTrans; i++) { + ta = acc->transaction[i]; + for (j=i+1; jnumTrans; 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; knumTrans; k++) { + acc->transaction[k-1] = acc->transaction[k]; + } + acc->transaction[acc->numTrans -1] = NULL; + acc->numTrans --; + } + } +} + /*************************** END OF FILE **************************** */ diff --git a/src/Data.c b/src/Data.c index ff7b03beff..9df049417e 100644 --- a/src/Data.c +++ b/src/Data.c @@ -578,4 +578,24 @@ xaccMergeAccounts (AccountGroup *grp) } } +/********************************************************************\ +\********************************************************************/ + +void +xaccConsolidateGrpTransactions (AccountGroup *grp) +{ + Account * acc; + int i; + + if (!grp) return; + + for (i=0; inumAcc; i++) { + acc = grp->account[i]; + xaccConsolidateTransactions (acc); + + /* recursively do the children */ + xaccConsolidateGrpTransactions (acc->children); + } +} + /****************** END OF FILE *************************************/ diff --git a/src/MainWindow.c b/src/MainWindow.c index 23f1e1b3b0..cecdcf985f 100644 --- a/src/MainWindow.c +++ b/src/MainWindow.c @@ -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; }