implement transfers

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@489 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/multiline
Linas Vepstas 29 years ago
parent dabf234517
commit 1137fddc16

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

Loading…
Cancel
Save