From 1137fddc1666e5de68517bf749df7f5847767bbd Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 2 Feb 1998 05:17:49 +0000 Subject: [PATCH] implement transfers git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@489 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Ledger.c | 90 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/src/Ledger.c b/src/Ledger.c index 291baea0ab..5947fb4666 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -39,12 +39,58 @@ Split * xaccGetCurrentSplit (BasicRegister *reg) /* ======================================================== */ +static char * +GetPeerAccName (Split *split) +{ + Account *acc = NULL; + Transaction *trans; + trans = (Transaction *) (split->parent); + + if (split != &(trans->credit_split)) { + acc = (Account *) trans->credit_split.acc; + } else { + if (trans->debit_splits) { + /* if only one split, then use that */ + if (NULL == trans->debit_splits[1]) { + acc = (Account *) trans->debit_splits[0]->acc; + } else { + return SPLIT_STR; + } + } + } + if (acc) return acc->accountName; + return ""; +} + +/* ======================================================== */ + +static Split * +GetPeerSplit (Split *split) +{ + Transaction *trans = (Transaction *) (split->parent); + + if (split != &(trans->credit_split)) { + return &(trans->credit_split); + } else { + if (trans->debit_splits) { + /* if only one split, then use that */ + if (NULL == trans->debit_splits[1]) { + return (trans->debit_splits[0]); + } + } + } + return NULL; +} + +/* ======================================================== */ + void xaccSaveRegEntry (BasicRegister *reg) { Split *split; Transaction *trans; Account * acc; + char * xfr; /* get the handle to the current split and transaction */ split = xaccGetCurrentSplit (reg); @@ -64,9 +110,26 @@ xaccSaveRegEntry (BasicRegister *reg) /* hack alert -- do transfers */ + xfr = GetPeerAccName (split); + if (strcmp (xfr, reg->xfrmCell->cell.value) && + strcmp (SPLIT_STR, reg->xfrmCell->cell.value)) { + Split *peer_split; + + peer_split = GetPeerSplit (split); + if (peer_split) { + acc = (Account *) (peer_split->acc); + xaccRemoveSplit (acc, peer_split); + accRefresh (acc); + + acc = xaccGetPeerAccountFromName (acc, reg->xfrmCell->cell.value); + xaccInsertSplit (acc, peer_split); + accRefresh (acc); + } + } + /* lets assume that the amount changed, and * refresh all related accounts & account windows */ - xaccTransRecomputeBalance (trans); + xaccTransRecomputeAmount (trans); acc = (Account *) split->acc; accRefresh (acc); acc = (Account *) trans->credit_split.acc; @@ -75,31 +138,6 @@ xaccSaveRegEntry (BasicRegister *reg) /* ======================================================== */ -static char * -GetPeerAccName (Split *split) -{ - Account *acc = NULL; - Transaction *trans; - trans = (Transaction *) (split->parent); - - if (split != &(trans->credit_split)) { - acc = (Account *) trans->credit_split.acc; - } else { - if (trans->debit_splits) { - /* if only one split, then use that */ - if (NULL == trans->debit_splits[1]) { - acc = (Account *) trans->debit_splits[0]->acc; - } else { - return SPLIT_STR; - } - } - } - if (acc) return acc->accountName; - return ""; -} - -/* ======================================================== */ - void xaccLoadRegEntry (BasicRegister *reg, Split *split) {