mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
fix transfers from account to account
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@515 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
cbfd145555
commit
3288c2fe2b
115
src/Ledger.c
115
src/Ledger.c
@ -38,9 +38,10 @@ Split * xaccGetCurrentSplit (BasicRegister *reg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================== */
|
/* ======================================================== */
|
||||||
|
/* a split always has a partner */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
GetPeerAccName (Split *split)
|
GetOtherAccName (Split *split)
|
||||||
{
|
{
|
||||||
Account *acc = NULL;
|
Account *acc = NULL;
|
||||||
Transaction *trans;
|
Transaction *trans;
|
||||||
@ -50,12 +51,14 @@ GetPeerAccName (Split *split)
|
|||||||
acc = (Account *) trans->credit_split.acc;
|
acc = (Account *) trans->credit_split.acc;
|
||||||
} else {
|
} else {
|
||||||
if (trans->debit_splits) {
|
if (trans->debit_splits) {
|
||||||
/* if only one split, then use that */
|
if (NULL != trans->debit_splits[0]) {
|
||||||
if (NULL == trans->debit_splits[1]) {
|
/* if only one split, then use that */
|
||||||
acc = (Account *) trans->debit_splits[0]->acc;
|
if (NULL == trans->debit_splits[1]) {
|
||||||
} else {
|
acc = (Account *) trans->debit_splits[0]->acc;
|
||||||
return SPLIT_STR;
|
} else {
|
||||||
}
|
return SPLIT_STR;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (acc) return acc->accountName;
|
if (acc) return acc->accountName;
|
||||||
@ -64,22 +67,74 @@ GetPeerAccName (Split *split)
|
|||||||
|
|
||||||
/* ======================================================== */
|
/* ======================================================== */
|
||||||
|
|
||||||
static Split *
|
static void
|
||||||
GetPeerSplit (Split *split)
|
ModifyXfer (Split * split, const char * new_acc_name)
|
||||||
{
|
{
|
||||||
|
char * xfr;
|
||||||
|
Split *partner_split;
|
||||||
Transaction *trans = (Transaction *) (split->parent);
|
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)) {
|
if (split != &(trans->credit_split)) {
|
||||||
return &(trans->credit_split);
|
partner_split = &(trans->credit_split);
|
||||||
} else {
|
|
||||||
|
/* remove the partner split from the old account */
|
||||||
|
acc = (Account *) (partner_split->acc);
|
||||||
|
xaccRemoveSplit (acc, partner_split);
|
||||||
|
accRefresh (acc);
|
||||||
|
|
||||||
|
/* insert the partner split into the new account */
|
||||||
|
acc = (Account *) split->acc;
|
||||||
|
acc = xaccGetPeerAccountFromName (acc, new_acc_name);
|
||||||
|
xaccInsertSplit (acc, partner_split);
|
||||||
|
accRefresh (acc);
|
||||||
|
|
||||||
|
/* loop over all of the debit splits, and refresh,
|
||||||
|
* since they were all affected. */
|
||||||
if (trans->debit_splits) {
|
if (trans->debit_splits) {
|
||||||
/* if only one split, then use that */
|
int i = 0;
|
||||||
if (NULL == trans->debit_splits[1]) {
|
partner_split = trans->debit_splits[i];
|
||||||
return (trans->debit_splits[0]);
|
while (partner_split) {
|
||||||
}
|
acc = (Account *) (partner_split->acc);
|
||||||
}
|
accRefresh (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);
|
||||||
|
accRefresh (acc);
|
||||||
|
|
||||||
|
/* insert the partner split into the new account */
|
||||||
|
acc = (Account *) split->acc;
|
||||||
|
acc = xaccGetPeerAccountFromName (acc, new_acc_name);
|
||||||
|
xaccInsertSplit (acc, partner_split);
|
||||||
|
accRefresh (acc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================== */
|
/* ======================================================== */
|
||||||
@ -90,7 +145,6 @@ xaccSaveRegEntry (BasicRegister *reg)
|
|||||||
Split *split;
|
Split *split;
|
||||||
Transaction *trans;
|
Transaction *trans;
|
||||||
Account * acc;
|
Account * acc;
|
||||||
char * xfr;
|
|
||||||
|
|
||||||
/* get the handle to the current split and transaction */
|
/* get the handle to the current split and transaction */
|
||||||
split = xaccGetCurrentSplit (reg);
|
split = xaccGetCurrentSplit (reg);
|
||||||
@ -109,26 +163,7 @@ printf ("saving %s \n", trans->description);
|
|||||||
xaccSplitSetAction (split, reg->actionCell->cell.value);
|
xaccSplitSetAction (split, reg->actionCell->cell.value);
|
||||||
xaccSplitSetReconcile (split, reg->recnCell->value[0]);
|
xaccSplitSetReconcile (split, reg->recnCell->value[0]);
|
||||||
|
|
||||||
/* if the user changed thw value of the xfrm cell,
|
ModifyXfer (split, reg->xfrmCell->cell.value);
|
||||||
* then move the far end oof the split to the new location.
|
|
||||||
*/
|
|
||||||
xfr = GetPeerAccName (split);
|
|
||||||
if (strcmp (xfr, reg->xfrmCell->cell.value) &&
|
|
||||||
strcmp (SPLIT_STR, reg->xfrmCell->cell.value)) {
|
|
||||||
Split *peer_split;
|
|
||||||
|
|
||||||
printf ("xfr from %s to %s \n", xfr, reg->xfrmCell->cell.value);
|
|
||||||
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
|
/* lets assume that the amount changed, and
|
||||||
* refresh all related accounts & account windows */
|
* refresh all related accounts & account windows */
|
||||||
@ -169,7 +204,7 @@ trans->date.day, trans->date.month, trans->date.year);
|
|||||||
xaccSetBasicCellValue (reg->recnCell, buff);
|
xaccSetBasicCellValue (reg->recnCell, buff);
|
||||||
|
|
||||||
/* the transfer account */
|
/* the transfer account */
|
||||||
accname = GetPeerAccName (split);
|
accname = GetOtherAccName (split);
|
||||||
xaccSetComboCellValue (reg->xfrmCell, accname);
|
xaccSetComboCellValue (reg->xfrmCell, accname);
|
||||||
|
|
||||||
xaccSetDebCredCellValue (reg->debitCell,
|
xaccSetDebCredCellValue (reg->debitCell,
|
||||||
@ -249,7 +284,7 @@ LoadXferCell (ComboCell *cell, AccountGroup *grp)
|
|||||||
if (!grp) return;
|
if (!grp) return;
|
||||||
|
|
||||||
/* build the xfer menu out of account names */
|
/* build the xfer menu out of account names */
|
||||||
/* traverse sub-accounts ecursively */
|
/* traverse sub-accounts recursively */
|
||||||
n = 0;
|
n = 0;
|
||||||
acc = getAccount (grp, n);
|
acc = getAccount (grp, n);
|
||||||
while (acc) {
|
while (acc) {
|
||||||
|
Loading…
Reference in New Issue
Block a user