mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
implement destroy-split, other cleanup
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@778 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
9d592247c3
commit
7c9818f75e
@ -133,6 +133,53 @@ MarkChanged (Transaction *trans)
|
|||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccSplitDestroy (Split *split)
|
||||||
|
{
|
||||||
|
Transaction *trans;
|
||||||
|
int numsplits = 0;
|
||||||
|
int ismember = 0;
|
||||||
|
Split *s;
|
||||||
|
|
||||||
|
trans = split->parent;
|
||||||
|
assert (trans);
|
||||||
|
assert (trans->splits);
|
||||||
|
|
||||||
|
numsplits = 0;
|
||||||
|
s = trans->splits[0];
|
||||||
|
while (s) {
|
||||||
|
if (s == split) ismember = 1;
|
||||||
|
numsplits ++;
|
||||||
|
s = trans->splits[numsplits];
|
||||||
|
}
|
||||||
|
assert (ismember);
|
||||||
|
|
||||||
|
/* if the accoount has three or more splits,
|
||||||
|
* merely unlink & free the split.
|
||||||
|
*/
|
||||||
|
if (2 < numsplits) {
|
||||||
|
xaccTransRemoveSplit (trans, split);
|
||||||
|
xaccAccountRemoveSplit (split->acc, split);
|
||||||
|
xaccFreeSplit (split);
|
||||||
|
xaccSplitRebalance (trans->splits[1]);
|
||||||
|
} else {
|
||||||
|
/* if the transaction has only two splits,
|
||||||
|
* remove both of them, and them destroy the
|
||||||
|
* transaction.
|
||||||
|
*/
|
||||||
|
s = trans->splits[0];
|
||||||
|
xaccAccountRemoveSplit (split->acc, s);
|
||||||
|
xaccFreeSplit (s);
|
||||||
|
s = trans->splits[1];
|
||||||
|
xaccAccountRemoveSplit (split->acc, s);
|
||||||
|
xaccFreeSplit (s);
|
||||||
|
xaccFreeTransaction (trans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************\
|
||||||
|
\********************************************************************/
|
||||||
|
|
||||||
int
|
int
|
||||||
xaccCountSplits (Split **tarray)
|
xaccCountSplits (Split **tarray)
|
||||||
{
|
{
|
||||||
@ -491,12 +538,6 @@ xaccTransRemoveSplit (Transaction *trans, Split *split)
|
|||||||
s = trans->splits[n];
|
s = trans->splits[n];
|
||||||
}
|
}
|
||||||
trans->splits[i] = NULL;
|
trans->splits[i] = NULL;
|
||||||
|
|
||||||
/* force double entry to always be consistent */
|
|
||||||
xaccTransRebalance (trans);
|
|
||||||
|
|
||||||
/* hack alert -- this leaves open the possibility of a danglig split!
|
|
||||||
* */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
|
@ -75,6 +75,14 @@ void xaccTransSetDateToday (Transaction *);
|
|||||||
|
|
||||||
void xaccTransSetNum (Transaction *, const char *);
|
void xaccTransSetNum (Transaction *, const char *);
|
||||||
void xaccTransSetDescription (Transaction *, const char *);
|
void xaccTransSetDescription (Transaction *, const char *);
|
||||||
|
|
||||||
|
/* The xaccTransSetMemo() and xaccTransSetAction() methods are
|
||||||
|
* convenience routines to keep the memo and action fields
|
||||||
|
* of two-split trasnactions in sync. If the transaction has
|
||||||
|
* precisely two splits, then these routines will set the memo
|
||||||
|
* and action of both splits. Otherwise, they will set the
|
||||||
|
* memo and action of the first split (source split) only.
|
||||||
|
*/
|
||||||
void xaccTransSetMemo (Transaction *, const char *);
|
void xaccTransSetMemo (Transaction *, const char *);
|
||||||
void xaccTransSetAction (Transaction *, const char *);
|
void xaccTransSetAction (Transaction *, const char *);
|
||||||
|
|
||||||
|
@ -107,9 +107,15 @@ struct _transaction
|
|||||||
|
|
||||||
/* freeTransaction only does so if the transaction is not part of an
|
/* freeTransaction only does so if the transaction is not part of an
|
||||||
* account. (i.e. if none of the member splits are in an account). */
|
* account. (i.e. if none of the member splits are in an account). */
|
||||||
void xaccFreeTransaction (Transaction *);
|
void xaccFreeTransaction (Transaction *);
|
||||||
|
|
||||||
void xaccFreeSplit (Split *); /* frees memory */
|
void xaccFreeSplit (Split *); /* frees memory */
|
||||||
|
|
||||||
|
/* The xaccTransRemoveSplit() routine will remove the indicated
|
||||||
|
* split from the transaction. It will *NOT* otherwise
|
||||||
|
* readjust balances, modify accounts, etc.
|
||||||
|
*/
|
||||||
|
void xaccTransRemoveSplit (Transaction*, Split *);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user