mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
fix the stupid splitloading
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@939 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
80e411b5d2
commit
b935443c81
@ -98,36 +98,6 @@ xaccSRGetCurrentSplit (SplitRegister *reg)
|
|||||||
return split;
|
return split;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================== */
|
|
||||||
/* a split always has a partner */
|
|
||||||
|
|
||||||
static char *
|
|
||||||
GetOtherAccName (Split *split)
|
|
||||||
{
|
|
||||||
Account *acc = NULL;
|
|
||||||
Transaction *trans;
|
|
||||||
Split *s, *other_split;
|
|
||||||
int numsplits;
|
|
||||||
|
|
||||||
trans = xaccSplitGetParent (split);
|
|
||||||
|
|
||||||
numsplits = xaccTransCountSplits (trans);
|
|
||||||
/* if (2 < numsplits) return SPLIT_STR; */
|
|
||||||
if (2 < numsplits) return "BOGUS";
|
|
||||||
|
|
||||||
s = xaccTransGetSplit (trans, 0);
|
|
||||||
if (s == split) {
|
|
||||||
other_split = xaccTransGetSplit (trans, 1);
|
|
||||||
} else {
|
|
||||||
other_split = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
acc = xaccSplitGetAccount (other_split);
|
|
||||||
if (acc) return xaccAccountGetName (acc);
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ======================================================== */
|
/* ======================================================== */
|
||||||
/* Copy from the register object to the engine */
|
/* Copy from the register object to the engine */
|
||||||
|
|
||||||
@ -287,7 +257,7 @@ xaccSRLoadRegEntry (SplitRegister *reg, Split *split)
|
|||||||
xaccSetBasicCellValue (reg->recnCell, buff);
|
xaccSetBasicCellValue (reg->recnCell, buff);
|
||||||
|
|
||||||
/* the transfer account */
|
/* the transfer account */
|
||||||
accname = GetOtherAccName (split);
|
accname = xaccAccountGetName (xaccSplitGetAccount (split));
|
||||||
xaccSetComboCellValue (reg->xfrmCell, accname);
|
xaccSetComboCellValue (reg->xfrmCell, accname);
|
||||||
|
|
||||||
xaccSetDebCredCellValue (reg->debitCell,
|
xaccSetDebCredCellValue (reg->debitCell,
|
||||||
@ -324,7 +294,6 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Split *split;
|
Split *split;
|
||||||
Transaction *trans;
|
|
||||||
Table *table;
|
Table *table;
|
||||||
int save_cursor_phys_row;
|
int save_cursor_phys_row;
|
||||||
int num_phys_rows;
|
int num_phys_rows;
|
||||||
@ -353,39 +322,49 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist,
|
|||||||
/* num_phys_rows is the number of rows in all the cursors */
|
/* num_phys_rows is the number of rows in all the cursors */
|
||||||
num_phys_rows = reg->header->numRows;
|
num_phys_rows = reg->header->numRows;
|
||||||
|
|
||||||
/* number of virtual rows is number of splits plus transactions,
|
/* Count the number of rows needed.
|
||||||
* plus one for the header */
|
* the count will be equal to
|
||||||
|
* +1 for the header
|
||||||
|
* +n that is, one (transaction) row for each split passed in,
|
||||||
|
* +n one blank edit row for each transaction
|
||||||
|
* +p where p is the sum total of all the splits in the transaction
|
||||||
|
* +2 an editable transaction and split at the end.
|
||||||
|
*/
|
||||||
num_virt_rows = 1;
|
num_virt_rows = 1;
|
||||||
|
|
||||||
i=0;
|
i=0;
|
||||||
trans = NULL;
|
|
||||||
split = slist[0];
|
split = slist[0];
|
||||||
while (split) {
|
while (split) {
|
||||||
if (trans != xaccSplitGetParent (split)) {
|
Transaction *trans;
|
||||||
if (NULL != trans) {
|
int j;
|
||||||
/* add a line for the blank split at tail
|
|
||||||
* of previous transaction. */
|
trans = xaccSplitGetParent (split);
|
||||||
num_virt_rows ++;
|
if (!trans) {
|
||||||
num_phys_rows += reg->split_cursor->numRows;
|
/* hack assert */
|
||||||
}
|
printf ("Internal Error: xaccSRLoadRegister(): "
|
||||||
trans = xaccSplitGetParent (split);
|
"Split without a parent \n");
|
||||||
/* add a row for each transaction */
|
break;
|
||||||
num_virt_rows ++;
|
}
|
||||||
num_phys_rows += reg->trans_cursor->numRows;
|
|
||||||
}
|
/* add one row for a transaction */
|
||||||
/* add a row for each split */
|
|
||||||
num_virt_rows ++;
|
num_virt_rows ++;
|
||||||
num_phys_rows += reg->split_cursor->numRows;
|
num_phys_rows += reg->trans_cursor->numRows;
|
||||||
|
|
||||||
|
/* add a row for each split, minus one, plus one */
|
||||||
|
j = xaccTransCountSplits (trans);
|
||||||
|
num_virt_rows += j;
|
||||||
|
num_phys_rows += j * reg->split_cursor->numRows;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
split = slist[i];
|
split = slist[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* plus three: for the blank new entry split.
|
/* plus two: one blank transaction, one blank split. */
|
||||||
* (one for last split, one for blank transaction & split) */
|
|
||||||
if (!(reg->user_hook)) {
|
if (!(reg->user_hook)) {
|
||||||
num_virt_rows += 3;
|
i++;
|
||||||
|
num_virt_rows += 2;
|
||||||
num_phys_rows += reg->trans_cursor->numRows;
|
num_phys_rows += reg->trans_cursor->numRows;
|
||||||
num_phys_rows += 2 * (reg->split_cursor->numRows);
|
num_phys_rows += reg->split_cursor->numRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* num_virt_cols is always one. */
|
/* num_virt_cols is always one. */
|
||||||
@ -394,66 +373,58 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist,
|
|||||||
/* make sure that the header is loaded */
|
/* make sure that the header is loaded */
|
||||||
xaccSetCursor (table, reg->header, 0, 0, 0, 0);
|
xaccSetCursor (table, reg->header, 0, 0, 0, 0);
|
||||||
|
|
||||||
printf ("load reg of %d entries --------------------------- \n",i);
|
printf ("load register of %d virtual entries %d phys rows ----------- \n", i, num_phys_rows);
|
||||||
/* populate the table */
|
/* populate the table */
|
||||||
i=0;
|
i=0;
|
||||||
vrow = 1; /* header is vrow zero */
|
vrow = 1; /* header is vrow zero */
|
||||||
phys_row = reg->header->numRows;
|
phys_row = reg->header->numRows;
|
||||||
trans = NULL;
|
|
||||||
split = slist[0];
|
split = slist[0];
|
||||||
while (split) {
|
while (split) {
|
||||||
|
|
||||||
/* don't load the "blank split" inline; instead, we put
|
/* do not load the blank split */
|
||||||
* it at the end. */
|
if (split != ((Split *) reg->user_hook)) {
|
||||||
if (split != ((Split *) (reg->user_hook))) {
|
Transaction *trans;
|
||||||
|
Split * secondary;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
/* first, load the transaction header line */
|
/* hack alert it would be more efficient to have two different
|
||||||
if (trans != xaccSplitGetParent (split)) {
|
loads, one to handle teh transaction side, one to handle the
|
||||||
if (NULL != trans) {
|
split side. But, for now a single load works just fine.
|
||||||
/* add a line for the blank split at tail
|
*/
|
||||||
* of previous transaction. */
|
printf ("load trans %d at phys row %d \n", i, phys_row);
|
||||||
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
xaccSetCursor (table, reg->trans_cursor, phys_row, 0, vrow, 0);
|
||||||
xaccMoveCursor (table, phys_row, 0);
|
|
||||||
xaccSRLoadRegEntry (reg, NULL);
|
|
||||||
printf ("load blank split %d \n", phys_row);
|
|
||||||
vrow ++;
|
|
||||||
phys_row += reg->split_cursor->numRows;
|
|
||||||
}
|
|
||||||
trans = xaccSplitGetParent (split);
|
|
||||||
printf ("load trans %d \n", phys_row);
|
|
||||||
xaccSetCursor (table, reg->trans_cursor, phys_row, 0, vrow, 0);
|
|
||||||
xaccMoveCursor (table, phys_row, 0);
|
|
||||||
xaccSRLoadRegEntry (reg, split);
|
|
||||||
vrow ++;
|
|
||||||
phys_row += reg->trans_cursor->numRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ("load split %d \n", phys_row);
|
|
||||||
/* now load each split that belongs to that transaction */
|
|
||||||
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
|
||||||
xaccMoveCursor (table, phys_row, 0);
|
xaccMoveCursor (table, phys_row, 0);
|
||||||
xaccSRLoadRegEntry (reg, split);
|
xaccSRLoadRegEntry (reg, split);
|
||||||
vrow ++;
|
vrow ++;
|
||||||
phys_row += (reg->split_cursor->numRows);
|
phys_row += reg->trans_cursor->numRows;
|
||||||
|
|
||||||
|
/* loop over all of the splits in the transaction */
|
||||||
|
/* the do..while will automaticaly put a blank (null) split at the end */
|
||||||
|
trans = xaccSplitGetParent (split);
|
||||||
|
j = 0;
|
||||||
|
do {
|
||||||
|
secondary = xaccTransGetSplit (trans, j);
|
||||||
|
if (secondary != split) {
|
||||||
|
printf ("load split %d at phys row %d \n", j, phys_row);
|
||||||
|
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
||||||
|
xaccMoveCursor (table, phys_row, 0);
|
||||||
|
xaccSRLoadRegEntry (reg, secondary);
|
||||||
|
vrow ++;
|
||||||
|
phys_row += reg->split_cursor->numRows;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
} while (secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
split = slist[i];
|
split = slist[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a line for the blank split at tail
|
|
||||||
* of previous transaction. */
|
|
||||||
printf ("load blank split %d \n", phys_row);
|
|
||||||
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
|
||||||
xaccMoveCursor (table, phys_row, 0);
|
|
||||||
xaccSRLoadRegEntry (reg, NULL);
|
|
||||||
vrow ++;
|
|
||||||
phys_row += reg->split_cursor->numRows;
|
|
||||||
|
|
||||||
/* add the "blank split" at the end */
|
/* add the "blank split" at the end */
|
||||||
if (reg->user_hook) {
|
if (reg->user_hook) {
|
||||||
split = (Split *) reg->user_hook;
|
split = (Split *) reg->user_hook;
|
||||||
} else {
|
} else {
|
||||||
|
Transaction *trans;
|
||||||
trans = xaccMallocTransaction ();
|
trans = xaccMallocTransaction ();
|
||||||
xaccTransBeginEdit (trans);
|
xaccTransBeginEdit (trans);
|
||||||
xaccTransSetDateToday (trans);
|
xaccTransSetDateToday (trans);
|
||||||
@ -472,6 +443,8 @@ printf ("load blank split %d \n", phys_row);
|
|||||||
|
|
||||||
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
xaccSetCursor (table, reg->split_cursor, phys_row, 0, vrow, 0);
|
||||||
xaccMoveCursor (table, phys_row, 0);
|
xaccMoveCursor (table, phys_row, 0);
|
||||||
|
// hack alert something busted, this staement cause a core dump. why ??
|
||||||
|
// xaccSRLoadRegEntry (reg, split);
|
||||||
|
|
||||||
/* restore the cursor to its original location */
|
/* restore the cursor to its original location */
|
||||||
if (phys_row <= save_cursor_phys_row) {
|
if (phys_row <= save_cursor_phys_row) {
|
||||||
@ -516,7 +489,6 @@ LoadXferCell (ComboCell *cell, AccountGroup *grp)
|
|||||||
void xaccLoadXferCell (ComboCell *cell, AccountGroup *grp)
|
void xaccLoadXferCell (ComboCell *cell, AccountGroup *grp)
|
||||||
{
|
{
|
||||||
xaccAddComboCellMenuItem (cell, "");
|
xaccAddComboCellMenuItem (cell, "");
|
||||||
xaccAddComboCellMenuItem (cell, SPLIT_STR);
|
|
||||||
LoadXferCell (cell, grp);
|
LoadXferCell (cell, grp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user