double-entry bug fixes & misc bug fixes

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1997-11-01 02:15:42 +00:00
parent f5db2d0fff
commit 2dad05d314
9 changed files with 77 additions and 16 deletions

View File

@ -64,7 +64,7 @@ typedef struct _editaccwindow {
Widget name; /* The account name text field */
Widget desc; /* Account description text field */
Account *account; /* The text from the "Notes" window */
Account *account; /* The account to edit */
} EditAccWindow;
/** GLOBALS *********************************************************/

View File

@ -115,18 +115,34 @@ getTransaction( Account *acc, int num )
return NULL;
}
/********************************************************************\
\********************************************************************/
int
getNumOfTransaction( Account *acc, Transaction *trans )
{
int i;
for (i=0; i<acc->numTrans; i++) {
if (trans == acc->transaction[i]) return i;
}
return -1;
}
/********************************************************************\
\********************************************************************/
Transaction *
removeTransaction( Account *acc, int num )
{
Transaction *trans = NULL;
if( acc != NULL )
{
int i,j;
struct _account * _acc = (struct _account *) acc;
Transaction **oldTrans = acc->transaction;
/* check for valid number */
if( (0 > num) || (num >= acc->numTrans) ) return NULL;
/* Set this flag, so we know we need to save the data file: */
if( data != NULL )
data->saved = False;

View File

@ -611,7 +611,7 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
DEBUG("AMB_OPEN");
{
Account *acc = getAccount(data,row);
if( acc->regData == NULL )
if( NULL == acc->regData ) /* avoid having two registers updating one account */
acc->regData = regWindow( toplevel, acc );
}
break;

View File

@ -26,10 +26,10 @@
######################################################################
# DO NOT EDIT THE STUFF BELOW THIS LINE! #
OBJS = main.o util.o date.o MainWindow.o RegWindow.o BuildMenu.o \
AccWindow.o FileIO.o Account.o Data.o XferWindow.o FileBox.o \
QuickFill.o Reports.o RecnWindow.o HelpWindow.o AdjBWindow.o \
QIFIO.o Transaction.o
OBJS = Account.o AccWindow.o AdjBWindow.o BuildMenu.o Data.o date.o \
FileBox.o FileIO.o HelpWindow.o main.o MainWindow.o \
QIFIO.o QuickFill.o RecnWindow.o RegWindow.o Reports.o \
Transaction.o util.o XferWindow.o
SRCS = ${OBJS:.o=.c}

View File

@ -494,21 +494,23 @@ regSaveTransaction( RegWindow *regData, int position )
tmp = XbaeMatrixGetCell(regData->reg,row+1,MEMO_CELL_C);
/* if its a transfer, indicate where its from ... */
/* hack alert -- this algorithm is fundamentally broken if
* memo field is repeatedly edited ... */
if ((NULL != trans->debit) && (NULL != trans->credit)) {
Account *fromAccount = NULL;
if (((struct _account *) acc) == trans->debit) {
if (acc == ((Account *) trans->debit) ) {
fromAccount = (Account *) trans->credit;
} else {
fromAccount = (Account *) trans->debit;
}
/* Get the memo, and add the "from" account name to it */
memo = (String)malloc (strlen(tmp)+
strlen(fromAccount->accountName)+
strlen("[From: ] ") );
sprintf( memo, "[From: %s] %s\0", fromAccount->accountName, tmp);
XbaeMatrixSetCell( regData->reg, row+1, MEMO_CELL_C, memo );
trans->memo = memo;
} else {
trans->memo = XtNewString( tmp );
@ -702,6 +704,7 @@ regWindow( Widget parent, Account *acc )
}
regData = (RegWindow *)_malloc(sizeof(RegWindow));
acc -> regData = regData; /* avoid having two open registers for one account */
regData->acc = acc;
regData->changed = 0; /* Nothing has changed yet! */
regData->lastTrans = 0;
@ -771,6 +774,10 @@ regWindow( Widget parent, Account *acc )
NULL, NULL, (MenuItem *)NULL },
{ "Delete Transaction", &xmPushButtonWidgetClass, 'D', NULL, NULL,
deleteCB, (XtPointer)regData, (MenuItem *)NULL },
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL,
NULL, NULL, (MenuItem *)NULL },
{ "Close Window", &xmPushButtonWidgetClass, 'Q', NULL, NULL,
destroyShellCB,(XtPointer)(regData->dialog),(MenuItem *)NULL },
NULL,
};
@ -1036,6 +1043,22 @@ regWindow( Widget parent, Account *acc )
XtAddCallback( widget, XmNactivateCallback,
cancelCB, (XtPointer)regData );
/* the "close" button */
position++;
widget = XtVaCreateManagedWidget( "Close",
xmPushButtonWidgetClass, buttonform,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, position,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, position+1,
XmNshowAsDefault, True,
NULL );
XtAddCallback( widget, XmNactivateCallback,
destroyShellCB, (XtPointer)(regData->dialog) );
position+=2;
/* Fix button area of the pane to its current size, and not let
@ -1188,6 +1211,7 @@ deleteCB( Widget mw, XtPointer cd, XtPointer cb )
{
RegWindow *regData = (RegWindow *)cd;
Account *acc = regData->acc;
Account *otherAcc = 0x0;
if( getTransaction(acc,regData->lastTrans) != NULL )
{
@ -1204,11 +1228,27 @@ deleteCB( Widget mw, XtPointer cd, XtPointer cb )
XbaeMatrixDeleteRows( regData->reg, row, 2 );
XbaeMatrixRefresh(regData->reg);
/* if this is a double entry transaction,
* remove it from the other account too ...... */
if (trans->credit) otherAcc = (Account *) trans->credit;
if (trans->debit) otherAcc = (Account *) trans->debit;
if (otherAcc) {
RegWindow *otherRegData = otherAcc -> regData;
int otherrow;
int n = getNumOfTransaction (otherAcc, trans);
trans = removeTransaction( otherAcc, n );
/* remove the rows from the matrix */
if (otherRegData) {
otherrow = 2*n + 1;
XbaeMatrixDeleteRows( otherRegData->reg, otherrow, 2 );
XbaeMatrixRefresh( otherRegData->reg);
regRecalculateBalance (otherRegData);
}
}
/* Delete the transaction */
XtFree(trans->num);
XtFree(trans->description);
XtFree(trans->memo);
_free(trans);
freeTransaction (trans);
regRecalculateBalance(regData);
}

View File

@ -74,6 +74,11 @@ void
freeTransaction( Transaction *trans )
{
if( trans != NULL ) {
XtFree(trans->num);
XtFree(trans->description);
XtFree(trans->memo);
initTransaction (trans); /* just in case someone looks up freed memory ... */
_free(trans);
}

View File

@ -446,7 +446,6 @@ xferCB( Widget mw, XtPointer cd, XtPointer cb )
trans->debit = (struct _account *) getAccount(data,xferData->from);
trans->credit = (struct _account *) getAccount(data,xferData->to);
/* insert transaction into from acount */
acc = getAccount(data,xferData->from);
insertTransaction( acc, trans );

View File

@ -135,8 +135,8 @@ main( int argc, char *argv[] )
datafile = fileBox( toplevel, OPEN );
if( datafile != NULL )
/* data = readData(datafile); /* load the accounts data from datafile*/
data = xaccReadQIFData(datafile); /* load the accounts data from datafile*/
data = readData(datafile); /* load the accounts data from datafile*/
/* data = xaccReadQIFData(datafile); /* load the accounts data from datafile*/
if( data == NULL )
{

View File

@ -276,6 +276,7 @@ textBox( Widget parent, char *title, char *text, Boolean editable )
XmNdeleteResponse, XmDESTROY,
XmNminWidth, 150,
XmNminHeight, 200,
XmNtransient, FALSE, /* allow window to be repositioned */
NULL );
/* Create a PanedWindow Manager for the dialog box... the child