more account utilities from ledger to engine

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@519 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-02-06 23:34:27 +00:00
parent 83415d1588
commit aaa9c0f3f6
2 changed files with 58 additions and 68 deletions

View File

@ -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)
{

View File

@ -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 */