From aaa9c0f3f6e057398cc888ab1f332bc99f28a21d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 6 Feb 1998 23:34:27 +0000 Subject: [PATCH] more account utilities from ledger to engine git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@519 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Account.c | 57 ++++++++++++++++++++++++++++++++++++++++++ src/Ledger.c | 69 +-------------------------------------------------- 2 files changed, 58 insertions(+), 68 deletions(-) diff --git a/src/Account.c b/src/Account.c index 69d316bbf7..b5db966c5b 100644 --- a/src/Account.c +++ b/src/Account.c @@ -28,6 +28,7 @@ #include "Account.h" #include "Data.h" #include "date.h" +#include "messages.h" #include "Transaction.h" #include "util.h" @@ -525,6 +526,62 @@ xaccZeroRunningBalances( Account **list ) /********************************************************************\ \********************************************************************/ +void +xaccMoveFarEnd (Split *split, Account *new_acc) +{ + Split *partner_split = 0x0; + Transaction *trans; + Account * acc; + + if (!split) return; + + /* if the new desitnation does not match the current dest, + * then move the far end of the split to the new location. + */ + trans = (Transaction *) (split->parent); + if (split != &(trans->credit_split)) { + partner_split = &(trans->credit_split); + } else { + /* perform that transfer *only* if there is one split */ + if (trans->debit_splits) { + if (0x0 != trans->debit_splits[0]) { + if (0x0 == trans->debit_splits[1]) { + partner_split = trans->debit_splits[0]; + } + } + } + } + + if (partner_split) { + /* remove the partner split from the old account */ + acc = (Account *) (partner_split->acc); + if (acc != new_acc) { + xaccRemoveSplit (acc, partner_split); + xaccInsertSplit (new_acc, partner_split); + } + } +} + +/********************************************************************\ +\********************************************************************/ + +void +xaccMoveFarEndByName (Split *split, const char *new_acc_name) +{ + Account *acc; + + if (!split) return; + if (0 == strcmp (SPLIT_STR, new_acc_name)) return; + + acc = (Account *) split->acc; + acc = xaccGetPeerAccountFromName (acc, new_acc_name); + + xaccMoveFarEnd (split, acc); +} + +/********************************************************************\ +\********************************************************************/ + void xaccConsolidateTransactions (Account * acc) { diff --git a/src/Ledger.c b/src/Ledger.c index 72f3816930..fb78d62d1c 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -67,73 +67,6 @@ GetOtherAccName (Split *split) /* ======================================================== */ -static void -ModifyXfer (Split * split, const char * new_acc_name) -{ - char * xfr; - Split *partner_split; - Transaction *trans = (Transaction *) (split->parent); - Account * acc; - - if (0 == strcmp (SPLIT_STR, new_acc_name)) return; - - /* check to see whether old an new destination are - * the same. If they are, then its a no-op */ - xfr = GetOtherAccName (split); - if (0 == strcmp (xfr, new_acc_name)) return; - - /* if the new desitnation does not match the current dest, - * then move the far end of the split to the new location. - */ -printf ("xfr from %s to %s \n", xfr, new_acc_name); - - if (split != &(trans->credit_split)) { - partner_split = &(trans->credit_split); - - /* remove the partner split from the old account */ - acc = (Account *) (partner_split->acc); - xaccRemoveSplit (acc, partner_split); - - /* insert the partner split into the new account */ - acc = (Account *) split->acc; - acc = xaccGetPeerAccountFromName (acc, new_acc_name); - xaccInsertSplit (acc, partner_split); - - /* loop over all of the debit splits, and refresh, - * since they were all affected. */ - if (trans->debit_splits) { - int i = 0; - partner_split = trans->debit_splits[i]; - while (partner_split) { - acc = (Account *) (partner_split->acc); - i++; - partner_split = trans->debit_splits[i]; - } - } - } else { - /* perform that transfer *only* if there is - * one split */ - if (trans->debit_splits) { - if (0x0 != trans->debit_splits[0]) { - if (0x0 == trans->debit_splits[1]) { - partner_split = trans->debit_splits[0]; - - /* remove the partner split from the old account */ - acc = (Account *) (partner_split->acc); - xaccRemoveSplit (acc, partner_split); - - /* insert the partner split into the new account */ - acc = (Account *) split->acc; - acc = xaccGetPeerAccountFromName (acc, new_acc_name); - xaccInsertSplit (acc, partner_split); - } - } - } - } -} - -/* ======================================================== */ - void xaccSaveRegEntry (BasicRegister *reg) { @@ -189,7 +122,7 @@ printf ("saving %s \n", trans->description); xaccSplitSetAction (split, reg->actionCell->cell.value); if (MOD_XFRM & changed) - ModifyXfer (split, reg->xfrmCell->cell.value); + xaccMoveFarEndByName (split, reg->xfrmCell->cell.value); if (MOD_XTO & changed) { /* hack alert -- implement this */