major revision to add general ledger capabilities

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@145 57a11ea4-9604-0410-9ed3-97b8803252fd
archive
Linas Vepstas 29 years ago
parent 621c1de0d3
commit e1b02b2280

@ -641,7 +641,7 @@ createCB( Widget mw, XtPointer cd, XtPointer cb )
/* The account has to have a name! */
if( strcmp( name, "" ) == 0 ) {
errorBox (toplevel, "The account must be given a name! \n");
errorBox (toplevel, ACC_NO_NAME_MSG);
return;
}
@ -683,7 +683,7 @@ createCB( Widget mw, XtPointer cd, XtPointer cb )
refreshMainWindow();
/* open up the account window for the user */
regWindow( toplevel, acc );
regWindowSimple ( toplevel, acc );
/* if we got to here, tear down the dialog window */
XtDestroyWidget (accData->dialog);
@ -754,12 +754,12 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
case BANK:
case CASH:
case ASSET:
case PORTFOLIO:
case STOCK:
case MUTUAL:
XtSetSensitive (menu->type_widgets[BANK], True);
XtSetSensitive (menu->type_widgets[CASH], True);
XtSetSensitive (menu->type_widgets[ASSET], True);
XtSetSensitive (menu->type_widgets[PORTFOLIO], True);
XtSetSensitive (menu->type_widgets[STOCK], True);
XtSetSensitive (menu->type_widgets[MUTUAL], True);
XtSetSensitive (menu->type_widgets[LIABILITY], False);
XtSetSensitive (menu->type_widgets[CREDIT], False);
@ -776,7 +776,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
/* set a default, if an inapporpriate button is pushed */
if ((BANK != but) && (CASH != but) &&
(ASSET != but) && (PORTFOLIO != but) &&
(ASSET != but) && (STOCK != but) &&
(MUTUAL != but) ) {
XtVaSetValues (menu->type_widgets[acc->type], XmNset, True, NULL);
}
@ -787,7 +787,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtSetSensitive (menu->type_widgets[BANK], False);
XtSetSensitive (menu->type_widgets[CASH], False);
XtSetSensitive (menu->type_widgets[ASSET], False);
XtSetSensitive (menu->type_widgets[PORTFOLIO], False);
XtSetSensitive (menu->type_widgets[STOCK], False);
XtSetSensitive (menu->type_widgets[MUTUAL], False);
XtSetSensitive (menu->type_widgets[LIABILITY], True);
XtSetSensitive (menu->type_widgets[CREDIT], True);
@ -799,7 +799,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtVaSetValues (menu->type_widgets[BANK], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[CASH], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[ASSET], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[PORTFOLIO], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[STOCK], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[MUTUAL], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[INCOME], XmNset, False, NULL);
XtVaSetValues (menu->type_widgets[EXPENSE], XmNset, False, NULL);
@ -815,7 +815,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtSetSensitive (menu->type_widgets[BANK], False);
XtSetSensitive (menu->type_widgets[CASH], False);
XtSetSensitive (menu->type_widgets[ASSET], False);
XtSetSensitive (menu->type_widgets[PORTFOLIO], False);
XtSetSensitive (menu->type_widgets[STOCK], False);
XtSetSensitive (menu->type_widgets[MUTUAL], False);
XtSetSensitive (menu->type_widgets[LIABILITY], False);
XtSetSensitive (menu->type_widgets[CREDIT], False);
@ -836,7 +836,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtSetSensitive (menu->type_widgets[BANK], False);
XtSetSensitive (menu->type_widgets[CASH], False);
XtSetSensitive (menu->type_widgets[ASSET], False);
XtSetSensitive (menu->type_widgets[PORTFOLIO], False);
XtSetSensitive (menu->type_widgets[STOCK], False);
XtSetSensitive (menu->type_widgets[MUTUAL], False);
XtSetSensitive (menu->type_widgets[LIABILITY], False);
XtSetSensitive (menu->type_widgets[CREDIT], False);
@ -857,7 +857,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtSetSensitive (menu->type_widgets[BANK], False);
XtSetSensitive (menu->type_widgets[CASH], False);
XtSetSensitive (menu->type_widgets[ASSET], False);
XtSetSensitive (menu->type_widgets[PORTFOLIO], False);
XtSetSensitive (menu->type_widgets[STOCK], False);
XtSetSensitive (menu->type_widgets[MUTUAL], False);
XtSetSensitive (menu->type_widgets[LIABILITY], False);
XtSetSensitive (menu->type_widgets[CREDIT], False);
@ -881,7 +881,7 @@ selectAccountCB( Widget mw, XtPointer cd, XtPointer cb )
XtSetSensitive (menu->type_widgets[ASSET], True);
XtSetSensitive (menu->type_widgets[CREDIT], True);
XtSetSensitive (menu->type_widgets[LIABILITY], True);
XtSetSensitive (menu->type_widgets[PORTFOLIO], True);
XtSetSensitive (menu->type_widgets[STOCK], True);
XtSetSensitive (menu->type_widgets[MUTUAL], True);
XtSetSensitive (menu->type_widgets[INCOME], True);
XtSetSensitive (menu->type_widgets[EXPENSE], True);

@ -53,6 +53,8 @@ mallocAccount( void )
acc->balance = 0.0;
acc->cleared_balance = 0.0;
acc->running_balance = 0.0;
acc->running_cleared_balance = 0.0;
acc->flags = 0;
acc->type = -1;
@ -61,15 +63,17 @@ mallocAccount( void )
acc->description = NULL;
acc->notes = NULL;
/* transction array should be null-terminated */
acc->numTrans = 0;
acc->transaction = NULL; /* Initially there are no transactions
* in this account's transaction
* array */
acc->transaction = (Transaction **) _malloc (sizeof (Transaction *));
acc->transaction[0] = NULL;
/* private data */
acc->arrowb = NULL;
acc->expand = 0;
acc->regData = NULL;
acc->regLedger = NULL;
acc->ledgerList = NULL;
acc->recnData = NULL;
acc->adjBData = NULL;
acc->editAccData = NULL;
@ -136,9 +140,13 @@ freeAccount( Account *acc )
acc->arrowb = NULL;
acc->expand = 0;
acc->regData = NULL;
acc->regLedger = NULL;
acc->recnData = NULL;
acc->adjBData = NULL;
if (acc->ledgerList) _free (acc->ledgerList);
acc->ledgerList = NULL;
_free(acc);
}
@ -154,6 +162,7 @@ xaccGetAccountID (Account *acc)
/********************************************************************\
\********************************************************************/
Transaction *
getTransaction( Account *acc, int num )
{
@ -167,6 +176,7 @@ getTransaction( Account *acc, int num )
/********************************************************************\
\********************************************************************/
int
getNumOfTransaction( Account *acc, Transaction *trans )
{
@ -179,6 +189,7 @@ getNumOfTransaction( Account *acc, Transaction *trans )
/********************************************************************\
\********************************************************************/
Transaction *
removeTransaction( Account *acc, int num )
{
@ -198,27 +209,22 @@ removeTransaction( Account *acc, int num )
acc->numTrans--;
if (0 < acc->numTrans) {
acc->transaction = (Transaction **)_malloc((acc->numTrans)*
acc->transaction = (Transaction **)_malloc(((acc->numTrans)+1)*
sizeof(Transaction *));
trans = oldTrans[acc->numTrans];/* In case we are deleting last in
trans = oldTrans[acc->numTrans];/* In case we are deleting last in
* old array */
for( i=0,j=0; i<acc->numTrans; i++,j++ ) {
if( j != num ) {
acc->transaction[i] = oldTrans[j];
} else {
trans = oldTrans[j];
i--;
}
}
} else {
if (0 != num) {
PERR ("removeTransaction(): num should be zero !");
for( i=0,j=0; i<acc->numTrans; i++,j++ ) {
if( j != num ) {
acc->transaction[i] = oldTrans[j];
} else {
trans = oldTrans[j];
i--;
}
trans = oldTrans[0];
acc->transaction = NULL;
}
}
/* make sure the array is NULL terminated */
acc->transaction[acc->numTrans] = NULL;
_free (oldTrans);
@ -244,6 +250,7 @@ xaccRemoveTransaction( Account *acc, Transaction *trans)
/********************************************************************\
\********************************************************************/
int
insertTransaction( Account *acc, Transaction *trans )
{
@ -290,47 +297,45 @@ insertTransaction( Account *acc, Transaction *trans )
acc->numTrans++;
oldTrans = acc->transaction;
acc->transaction = (Transaction **)_malloc((acc->numTrans)*
acc->transaction = (Transaction **)_malloc(((acc->numTrans) + 1) *
sizeof(Transaction *));
if (oldTrans) {
/* dt is the date of the transaction we are inserting, and dj
* is the date of the "cursor" transaction... we want to insert
* the new transaction before the first transaction of the same
* or later date. The !inserted bit is a bit of a kludge to
* make sure we only insert the new transaction once! */
dt = &(trans->date);
for( i=0,j=0; i<acc->numTrans; i++,j++ )
/* dt is the date of the transaction we are inserting, and dj
* is the date of the "cursor" transaction... we want to insert
* the new transaction before the first transaction of the same
* or later date. The !inserted bit is a bit of a kludge to
* make sure we only insert the new transaction once! */
dt = &(trans->date);
for( i=0,j=0; i<acc->numTrans; i++,j++ )
{
/* if we didn't do this, and we needed to insert into the
* last spot in the array, we would walk off the end of the
* old array, which is no good! */
if( j>=(acc->numTrans-1) )
{
/* if we didn't do this, and we needed to insert into the
* last spot in the array, we would walk off the end of the
* old array, which is no good! */
if( j>=(acc->numTrans-1) )
position = i;
acc->transaction[i] = trans;
break;
}
else
{
dj = &(oldTrans[j]->date);
if( (datecmp(dj,dt) > 0) & !inserted )
{
position = i;
acc->transaction[i] = trans;
break;
j--;
inserted = True;
}
else
{
dj = &(oldTrans[j]->date);
if( (datecmp(dj,dt) > 0) & !inserted )
{
position = i;
acc->transaction[i] = trans;
j--;
inserted = True;
}
else
acc->transaction[i] = oldTrans[j];
}
acc->transaction[i] = oldTrans[j];
}
_free(oldTrans);
} else {
acc->transaction[0] = trans;
position = 0;
}
}
/* make sure the array is NULL terminated */
acc->transaction[acc->numTrans] = NULL;
_free(oldTrans);
if( position != -1 )
qfInsertTransaction( acc->qfRoot, trans );
@ -340,6 +345,7 @@ insertTransaction( Account *acc, Transaction *trans )
/********************************************************************\
\********************************************************************/
Account *
xaccGetOtherAccount( Account *acc, Transaction *trans )
{
@ -513,6 +519,7 @@ double xaccGetShareBalance (Account *acc, Transaction *trans)
* Args: account -- the account for which to recompute balances *
* Return: void *
\********************************************************************/
void
xaccRecomputeBalance( Account * acc )
{
@ -534,7 +541,7 @@ xaccRecomputeBalance( Account * acc )
share_balance += amt;
dbalance += amt * (trans->share_price);
if( trans->reconciled != NREC ) {
if( NREC != trans->reconciled ) {
share_cleared_balance += amt;
dcleared_balance += amt * (trans->share_price);
}
@ -543,7 +550,7 @@ xaccRecomputeBalance( Account * acc )
if (tracc == acc) {
/* For bank accounts, the invarient subtotal is the dollar
* amount. For stock accoounts, the invarient is the share amount */
if ( (PORTFOLIO == tracc->type) || ( MUTUAL == tracc->type) ) {
if ( (STOCK == tracc->type) || ( MUTUAL == tracc->type) ) {
trans -> credit_share_balance = share_balance;
trans -> credit_share_cleared_balance = share_cleared_balance;
trans -> credit_balance = trans->share_price * share_balance;
@ -557,7 +564,7 @@ xaccRecomputeBalance( Account * acc )
}
tracc = (Account *) trans->debit;
if (tracc == acc) {
if ( (PORTFOLIO == tracc->type) || ( MUTUAL == tracc->type) ) {
if ( (STOCK == tracc->type) || ( MUTUAL == tracc->type) ) {
trans -> debit_share_balance = share_balance;
trans -> debit_share_cleared_balance = share_cleared_balance;
trans -> debit_balance = trans->share_price * share_balance;
@ -573,7 +580,7 @@ xaccRecomputeBalance( Account * acc )
last_trans = trans;
}
if ( (PORTFOLIO == acc->type) || ( MUTUAL == acc->type) ) {
if ( (STOCK == acc->type) || ( MUTUAL == acc->type) ) {
acc -> balance = share_balance * (last_trans->share_price);
acc -> cleared_balance = share_cleared_balance * (last_trans->share_price);
} else {
@ -594,6 +601,7 @@ xaccRecomputeBalance( Account * acc )
*
* Return: int -- non-zero if out of order *
\********************************************************************/
int
xaccCheckDateOrder (Account * acc, Transaction *trans )
{
@ -641,6 +649,7 @@ xaccCheckDateOrder (Account * acc, Transaction *trans )
* Args: trans -- the transaction to check *
* Return: int -- non-zero if out of order *
\********************************************************************/
int
xaccCheckDateOrderDE (Transaction *trans )
{
@ -658,4 +667,62 @@ xaccCheckDateOrderDE (Transaction *trans )
return 0;
}
/*************************** end of file **************************** */
/********************************************************************\
\********************************************************************/
int
xaccIsAccountInList (Account * acc, Account **list)
{
Account * chk;
int nacc = 0;
int nappearances = 0;
if (!acc) return 0;
if (!list) return 0;
chk = list[0];
while (chk) {
if (acc == chk) nappearances ++;
nacc++;
chk = list[nacc];
}
return nappearances;
}
/********************************************************************\
\********************************************************************/
void
xaccRecomputeBalances( Account **list )
{
Account * acc;
int nacc = 0;
if (!list) return;
acc = list[0];
while (acc) {
xaccRecomputeBalance (acc);
nacc++;
acc = list[nacc];
}
}
/********************************************************************\
\********************************************************************/
void
xaccZeroRunningBalances( Account **list )
{
Account * acc;
int nacc = 0;
if (!list) return;
acc = list[0];
while (acc) {
acc -> running_balance = 0.0;
acc -> running_cleared_balance = 0.0;
nacc++;
acc = list[nacc];
}
}
/*************************** END OF FILE **************************** */

@ -150,6 +150,7 @@ xaccBuildAccountSubMenu (AccountGroup *grp,
menuList[i].label = tmp;
menuList[i].wclass = &xmPushButtonWidgetClass;
menuList[i].mnemonic = 0;
menuList[i].sensitive = True;
menuList[i].accelerator = NULL;
menuList[i].accel_text = NULL;
menuList[i].callback = xaccAccountMenuCB;
@ -172,6 +173,7 @@ xaccBuildAccountSubMenu (AccountGroup *grp,
menuList[i+pad].label = tmp;
menuList[i+pad].wclass = &xmPushButtonWidgetClass;
menuList[i+pad].mnemonic = 0;
menuList[i+pad].sensitive = True;
menuList[i+pad].accelerator = NULL;
menuList[i+pad].accel_text = NULL;
menuList[i+pad].callback = xaccAccountMenuCB;
@ -194,6 +196,7 @@ xaccBuildAccountSubMenu (AccountGroup *grp,
menuList[i+pad].label = tmp;
menuList[i+pad].wclass = &xmPushButtonWidgetClass;
menuList[i+pad].mnemonic = 0;
menuList[i+pad].sensitive = True;
menuList[i+pad].accelerator = NULL;
menuList[i+pad].accel_text = NULL;
menuList[i+pad].callback = xaccAccountMenuCB;

@ -43,6 +43,7 @@ actionBox (Widget parent)
AddPopBoxMenuItem (popGUI, "Buy");
AddPopBoxMenuItem (popGUI, "Sell");
AddPopBoxMenuItem (popGUI, "Price");
AddPopBoxMenuItem (popGUI, "Int");
AddPopBoxMenuItem (popGUI, "Div");
AddPopBoxMenuItem (popGUI, "LTCG");
AddPopBoxMenuItem (popGUI, "STCG");

@ -125,6 +125,9 @@ Widget BuildMenu( Widget parent, int menu_type, char *menu_title,
NULL );
}
/* possible grey out menu entries */
XtSetSensitive (widget, items[i].sensitive);
/* If the current widget (menu item) being created corresponds to the
* int that the user specified as initial choice, then set initial_choice
* = widget. The (int)initial specified by caller of function is the

@ -0,0 +1,56 @@
/*******************************************************************\
* Destroy.c -- utilities for the window destruction (X-Accountant) *
* Copyright (C) 1997 Linas Vepstas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#include "Account.h"
#include "AccWindow.h"
#include "AdjBWindow.h"
#include "Data.h"
#include "LedgerUtils.h"
#include "RegWindow.h"
#include "RecnWindow.h"
#include "util.h"
/* ------------------------------------------------------ */
void
xaccAccountWindowDestroy (Account *acc)
{
int nacc;
int i, n;
if (!acc) return;
/* recursively destroy windows associated with children */
if (acc->children) {
for (i=0; i<acc->children->numAcc; i++) {
xaccAccountWindowDestroy (acc->children->account[i]);
}
}
xaccDestroyRegWindow (acc->regData);
xaccDestroyRegWindow (acc->regLedger);
xaccDestroyRecnWindow (acc->recnData);
xaccDestroyAdjBWindow (acc->adjBData);
xaccDestroyEditAccWindow (acc->editAccData);
xaccDestroyEditNotesWindow (acc->editNotesData);
}
/************************** END OF FILE *************************/

@ -0,0 +1,323 @@
/*******************************************************************\
* LedgerUtils.c -- utilities for the ledger window (X-Accountant) *
* Copyright (C) 1997 Linas Vepstas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#include "Account.h"
#include "Data.h"
#include "Transaction.h"
#include "util.h"
/* ------------------------------------------------------ */
int accListCount (Account **list)
{
Account *acc;
int nacc = 0;
if (!list) return 0;
acc = list[0];
while (acc) {
nacc++;
acc = list[nacc];
}
return nacc;
}
/* ------------------------------------------------------ */
Account ** accListCopy (Account **list)
{
Account **newlist;
int i;
int nacc = 0;
if (!list) return NULL;
nacc = accListCount (list);
if (0 == nacc) return NULL;
newlist = (Account **) _malloc ((nacc+1) * sizeof (Account *));
for (i=0; i<nacc; i++) {
newlist[i] = list[i];
}
newlist [nacc] = NULL;
return newlist;
}
/* ------------------------------------------------------ */
/* sort the transactions in date order */
Transaction ** accListGetSortedTrans (Account **list)
{
Account *acc;
Transaction *trans;
Transaction **tarray;
int nacc = 0;
int ntrans = 0;
int i, j;
if (!list) return 0;
/* count the total number of transactions */
nacc = 0;
acc = list[0];
while (acc) {
ntrans += acc->numTrans;
nacc++;
acc = list[nacc];
}
ntrans ++;
/* malloc the array of transactions */
tarray = (Transaction **) _malloc (ntrans * sizeof (Transaction *));
/* put all of the transactions in the flat array */
nacc = 0;
ntrans = 0;
acc = list[0];
while (acc) {
for (i=0; i<acc->numTrans; i++) {
tarray[ntrans] = getTransaction (acc, i);
ntrans ++;
}
nacc++;
acc = list[nacc];
}
tarray [ntrans] = NULL;
/* search and destroy duplicates. */
/* duplicates are possible due to double-entry */
/* one transaction can appear at most twice in the list */
for (i=0; i<ntrans; i++) {
for (j=i+1; j<ntrans; j++) {
if (tarray[i] == tarray[j]) {
tarray[j] = tarray [ntrans-1];
tarray[ntrans-1] = NULL;
ntrans --;
}
}
}
/* run the sort routine on the array */
qsort (tarray, ntrans, sizeof (Transaction *), xaccTransOrder);
return tarray;
}
/* ------------------------------------------------------ */
Account **
xaccGroupToList (Account *acc)
{
Account **list;
int nacc;
int i, n;
if (!acc) return;
nacc = xaccGetNumAccounts (acc->children);
nacc ++; /* add one for this account */
list = (Account **) _malloc ((nacc+1) * sizeof (Account *));
list[0] = acc; /* must be first -- other code depends on this */
n = 1;
if (acc->children) {
for (i=0; i<acc->children->numAcc; i++) {
list[n] = acc->children->account[i];
/* recursively add children too */
if (acc->children->account[i]->children) {
Account **childlist;
Account *childacc;
int ic = 0;
/* get the children */
childlist = xaccGroupToList (acc->children->account[i]);
/* copy them over */
childacc = childlist[0];
while (childacc) {
n++;
list[n] = childacc;
childacc = childlist[ic];
ic ++;
}
_free(childlist);
}
n++;
}
}
list[n] = NULL;
return list;
}
/* ------------------------------------------------------ */
int
ledgerListCount (struct _RegWindow **list)
{
struct _RegWindow *reg;
int n;
if (!list) return 0;
n = 0;
reg = list[0];
while (reg) {
n++;
reg = list[n];
}
return n;
}
/* ------------------------------------------------------ */
void
ledgerListAdd (Account * acc, struct _RegWindow *addreg)
{
struct _RegWindow **oldlist;
struct _RegWindow **newlist;
struct _RegWindow *reg;
int n;
if (!acc) return;
if (!addreg) return;
oldlist = acc->ledgerList;
n = ledgerListCount (oldlist);
newlist = (struct _RegWindow **)
_malloc ((n+2) * sizeof (struct _RegWindow *));
n = 0;
if (oldlist) {
reg = oldlist[0];
while (reg) {
newlist[n] = reg;
n++;
reg = oldlist[n];
}
_free (oldlist);
}
newlist[n] = addreg;
newlist[n+1] = NULL;
acc->ledgerList = newlist;
}
/* ------------------------------------------------------ */
void
ledgerListRemove (Account * acc, struct _RegWindow *delreg)
{
struct _RegWindow **oldlist;
struct _RegWindow **newlist;
struct _RegWindow *reg;
int n, i;
if (!acc) return;
if (!delreg) return;
oldlist = acc->ledgerList;
n = ledgerListCount (oldlist);
newlist = (struct _RegWindow **)
_malloc ((n+1) * sizeof (struct _RegWindow *));
n = 0;
i = 0;
if (oldlist) {
reg = oldlist[0];
while (reg) {
newlist[i] = reg;
if (delreg == reg) i--;
i++;
n++;
reg = oldlist[n];
}
_free (oldlist);
}
newlist[i] = NULL;
acc->ledgerList = newlist;
}
/* ------------------------------------------------------ */
int
ledgerListIsMember (Account * acc, struct _RegWindow *memreg)
{
struct _RegWindow **list;
struct _RegWindow *reg;
int n;
if (!acc) return 0;
if (!memreg) return 0;
list = acc->ledgerList;
if (!list) return 0;
n = 0;
reg = list[0];
while (reg) {
if (memreg == reg) return 1;
n++;
reg = list[n];
}
return 0;
}
/* ------------------------------------------------------ */
void
ledgerListAddList (Account ** list, struct _RegWindow *reg)
{
Account *acc;
int n = 0;
if (!list) return;
if (!reg) return;
acc = list[0];
while (acc) {
ledgerListAdd (acc, reg);
n++;
acc = list[n];
}
}
/* ------------------------------------------------------ */
void
ledgerListRemoveList (Account ** list, struct _RegWindow *reg)
{
Account *acc;
int n = 0;
if (!list) return;
if (!reg) return;
acc = list[0];
while (acc) {
ledgerListRemove (acc, reg);
n++;
acc = list[n];
}
}
/************************** END OF FILE *************************/

@ -40,9 +40,11 @@
#include "AccWindow.h"
#include "BuildMenu.h"
#include "Data.h"
#include "Destroy.h"
#include "FileBox.h"
#include "FileIO.h"
#include "HelpWindow.h"
#include "LedgerUtils.h"
#include "main.h"
#include "MainWindow.h"
#include "RecnWindow.h"
@ -155,7 +157,7 @@ xaccMainWindowAddAcct (Widget acctrix, AccountGroup *grp, int depth )
#endif
/* associate a pointer to the actual account with the row */
XbaeMatrixSetRowUserData ( acctrix, currow, (XtPointer *) acc);
XbaeMatrixSetRowUserData ( acctrix, currow, (XtPointer) acc);
/* If the account has sub-accounts, then add an arrow button
* next to the account name. Clicking on the arrow button will
@ -354,55 +356,57 @@ mainWindow( Widget parent )
* Set up the menubar *
\******************************************************************/
MenuItem fileMenu[] = {
{ "New File...", &xmPushButtonWidgetClass, 'N', NULL, NULL,
{ "New File...", &xmPushButtonWidgetClass, 'N', NULL, NULL, True,
fileMenubarCB, (XtPointer)FMB_NEW, (MenuItem *)NULL },
{ "Open File... ",&xmPushButtonWidgetClass, 'O', NULL, NULL,
{ "Open File... ",&xmPushButtonWidgetClass, 'O', NULL, NULL, True,
fileMenubarCB, (XtPointer)FMB_OPEN, (MenuItem *)NULL },
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL,
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL, True,
NULL, NULL, (MenuItem *)NULL },
{ "Save", &xmPushButtonWidgetClass, 'S', NULL, NULL,
{ "Save", &xmPushButtonWidgetClass, 'S', NULL, NULL, True,
fileMenubarCB, (XtPointer)FMB_SAVE, (MenuItem *)NULL },
{ "Save As...", &xmPushButtonWidgetClass, 'A', NULL, NULL,
{ "Save As...", &xmPushButtonWidgetClass, 'A', NULL, NULL, True,
fileMenubarCB, (XtPointer)FMB_SAVEAS,(MenuItem *)NULL },
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL,
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL, True,
NULL, NULL, (MenuItem *)NULL },
{ "Quit", &xmPushButtonWidgetClass, 'Q', NULL, NULL,
{ "Quit", &xmPushButtonWidgetClass, 'Q', NULL, NULL, True,
fileMenubarCB, (XtPointer)FMB_QUIT, (MenuItem *)NULL },
NULL,
};
MenuItem accountMenu[] = {
{ "New Account...", &xmPushButtonWidgetClass, 'N', NULL, NULL,
{ "New Account...", &xmPushButtonWidgetClass, 'N', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_NEW, (MenuItem *)NULL },
{ "Open Account", &xmPushButtonWidgetClass, 'O', NULL, NULL,
{ "Open Account", &xmPushButtonWidgetClass, 'O', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_OPEN, (MenuItem *)NULL },
{ "Edit Account...", &xmPushButtonWidgetClass, 'E', NULL, NULL,
{ "Open Subaccounts", &xmPushButtonWidgetClass, 'O', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_LEDGER, (MenuItem *)NULL },
{ "Edit Account...", &xmPushButtonWidgetClass, 'E', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_EDIT, (MenuItem *)NULL },
{ "Delete Account...", &xmPushButtonWidgetClass, 'D', NULL, NULL,
{ "Delete Account...", &xmPushButtonWidgetClass, 'D', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_DEL, (MenuItem *)NULL },
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL,
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL, True,
NULL, NULL, (MenuItem *)NULL },
{ "Transfer", &xmPushButtonWidgetClass, 'C', NULL, NULL,
{ "Transfer", &xmPushButtonWidgetClass, 'C', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_TRNS, (MenuItem *)NULL },
{ "Report", &xmPushButtonWidgetClass, 'R', NULL, NULL,
{ "Report", &xmPushButtonWidgetClass, 'R', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_RPRT, (MenuItem *)NULL },
#if 0
{ "Edit Categories...", &xmPushButtonWidgetClass, 'C', NULL, NULL,
{ "Edit Categories...", &xmPushButtonWidgetClass, 'C', NULL, NULL, True,
accountMenubarCB, (XtPointer)AMB_CAT, (MenuItem *)NULL },
#endif
NULL,
};
MenuItem helpMenu[] = {
{ "About...", &xmPushButtonWidgetClass, 'A', NULL, NULL,
{ "About...", &xmPushButtonWidgetClass, 'A', NULL, NULL, True,
helpMenubarCB, (XtPointer)HMB_ABOUT, (MenuItem *)NULL },
{ "Help...", &xmPushButtonWidgetClass, 'H', NULL, NULL,
{ "Help...", &xmPushButtonWidgetClass, 'H', NULL, NULL, True,
helpMenubarCB, (XtPointer)HMB_MAIN, (MenuItem *)NULL },
{ "Accounts...", &xmPushButtonWidgetClass, 'H', NULL, NULL,
{ "Accounts...", &xmPushButtonWidgetClass, 'H', NULL, NULL, True,
helpMenubarCB, (XtPointer)HMB_ACC, (MenuItem *)NULL },
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL,
{ "", &xmSeparatorWidgetClass, 0, NULL, NULL, True,
NULL, NULL, (MenuItem *)NULL },
{ "License...", &xmPushButtonWidgetClass, 'L', NULL, NULL,
{ "License...", &xmPushButtonWidgetClass, 'L', NULL, NULL, True,
helpMenubarCB, (XtPointer)HMB_LIC, (MenuItem *)NULL },
NULL,
};
@ -519,7 +523,7 @@ mainWindow( Widget parent )
listCB, (XtPointer)NULL );
/* If the user double-clicks on an account in the list, open
* up the detail view (ie the regWindow, or whatever) for
* up the detail view (ie the register window, or whatever) for
* that type of account */
XtAddCallback( accountlist, XmNdefaultActionCallback,
accountMenubarCB, (XtPointer)AMB_OPEN );
@ -715,7 +719,7 @@ xaccMainWindowRedisplayBalance (void)
case BANK:
case CASH:
case ASSET:
case PORTFOLIO:
case STOCK:
case MUTUAL:
case CREDIT:
case LIABILITY:
@ -919,6 +923,7 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
* which of the file menubar options was chosen
* AMB_NEW - New account
* AMB_OPEN - Open account
* AMB_LEDGER - Open account and subaccounts in one register
* AMB_EDIT - Edit account
* AMB_DEL - Delete account
* AMB_CAT - Edit catagories
@ -930,9 +935,10 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
DEBUG("AMB_NEW\n");
accWindow(toplevel);
break;
case AMB_OPEN:
DEBUG("AMB_OPEN\n");
{
{
Account *acc = selected_acc;
if( NULL == acc ) {
int make_new = verifyBox (toplevel, ACC_NEW_MSG);
@ -940,13 +946,26 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
accWindow(toplevel);
}
} else {
if( NULL == acc->regData ) {
/* avoid having two registers updating one account */
acc->regData = regWindow( toplevel, acc );
regWindowSimple ( toplevel, acc );
}
}
break;
case AMB_LEDGER:
DEBUG("AMB_LEDGER\n");
{
Account *acc = selected_acc;
if( NULL == acc ) {
int make_new = verifyBox (toplevel, ACC_NEW_MSG);
if (make_new) {
accWindow(toplevel);
}
} else {
regWindowAccGroup ( toplevel, acc );
}
}
break;
case AMB_EDIT:
DEBUG("AMB_EDIT\n");
{
@ -958,9 +977,10 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
}
}
break;
case AMB_DEL:
DEBUG("AMB_DEL\n");
{
{
Account *acc = selected_acc;
if( NULL == acc ) {
errorBox (toplevel, ACC_DEL_MSG);
@ -972,14 +992,7 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
/* before deleting the account, make
* sure that we close any misc register
* windows, if they are open */
/* hack alert -- this should be done for
* any child accounts this account might have .. */
xaccDestroyRegWindow (selected_acc->regData);
xaccDestroyRecnWindow (selected_acc->recnData);
xaccDestroyAdjBWindow (selected_acc->adjBData);
xaccDestroyEditAccWindow (selected_acc->editAccData);
xaccDestroyEditNotesWindow (selected_acc->editNotesData);
xaccAccountWindowDestroy (selected_acc);
xaccRemoveAccount (selected_acc);
freeAccount (selected_acc);
selected_acc = NULL;
@ -988,17 +1001,21 @@ accountMenubarCB( Widget mw, XtPointer cd, XtPointer cb )
}
}
break;
case AMB_TRNS:
DEBUG("AMB_TRNS\n");
xferWindow(toplevel);
break;
case AMB_RPRT:
DEBUG("AMB_RPRT\n");
simpleReportWindow(toplevel);
break;
case AMB_CAT:
DEBUG("AMB_CAT\n");
break;
default:
PERR ("AccountMenuBarCB(): We shouldn't be here!\n");
}

@ -27,8 +27,8 @@
# DO NOT EDIT THE STUFF BELOW THIS LINE! #
OBJS = Account.o AccountMenu.o AccWindow.o Action.o AdjBWindow.o \
BuildMenu.o Data.o date.o \
FileBox.o FileIO.o HelpWindow.o main.o MainWindow.o PopBox.o \
BuildMenu.o Data.o date.o Destroy.o \
FileBox.o FileIO.o HelpWindow.o LedgerUtils.o main.o MainWindow.o PopBox.o \
QIFIO.o QuickFill.o RecnWindow.o RegWindow.o Reports.o \
TextBox.o Transaction.o util.o XferBox.o XferWindow.o

@ -33,7 +33,7 @@ typedef struct _PopBox {
/** PROTOTYPES ******************************************************/
void selectCB (Widget w, XtPointer cd, XtPointer cb );
static void selectCB (Widget w, XtPointer cd, XtPointer cb );
/********************************************************************\
* popBox *
@ -68,8 +68,10 @@ popBox (Widget parent)
XmNvalue, "",
/* hack alert -- the width of the combobox should be relative to the font, should
be relative to the size of the cell in which it will fit. */
* be relative to the size of the cell in which it will fit. Basically, these
* values should not be hard-coded, but should be conmputed somehow */
XmNwidth, 53,
XmNdropDownWidth, 103,
NULL);
popData -> combobox = combobox;
@ -133,11 +135,15 @@ void SetPopBox (PopBox *ab, int row, int col)
choice = XbaeMatrixGetCell (ab->reg, ab->currow, ab->curcol);
/* do a menu selection only if the cell ain't empty. */
if (0x0 != choice[0]) {
/* convert String to XmString ... arghhh */
choosen = XmCvtCTToXmString (choice);
XmComboBoxSelectItem (ab->combobox, choosen, False);
XmStringFree (choosen);
if (choice) {
if (0x0 != choice[0]) {
/* convert String to XmString ... arghhh */
choosen = XmCvtCTToXmString (choice);
XmComboBoxSelectItem (ab->combobox, choosen, False);
XmStringFree (choosen);
} else {
XmComboBoxClearItemSelection (ab->combobox);
}
} else {
XmComboBoxClearItemSelection (ab->combobox);
}
@ -156,6 +162,17 @@ void SetPopBox (PopBox *ab, int row, int col)
}
}
/********************************************************************\
\********************************************************************/
void freePopBox (PopBox *ab)
{
if (!ab) return;
SetPopBox (ab, -1, -1);
XtDestroyWidget (ab->combobox);
_free (ab);
}
/********************************************************************\
* selectCB -- get the user's selection, put the string into the *
* cell. *
@ -166,7 +183,7 @@ void SetPopBox (PopBox *ab, int row, int col)
* Return: none *
\********************************************************************/
void selectCB (Widget w, XtPointer cd, XtPointer cb )
static void selectCB (Widget w, XtPointer cd, XtPointer cb )
{
PopBox *ab = (PopBox *) cd;
@ -182,4 +199,5 @@ void selectCB (Widget w, XtPointer cd, XtPointer cb )
/* a diffeent way of getting the user's selection ... */
/* text = XmComboBoxGetString (ab->combobox); */
}
/************************* END OF FILE ******************************/

@ -156,7 +156,7 @@ char * xaccReadQIFAccount (int fd, Account * acc)
acc -> type = BANK;
} else
if (!strcmp (&qifline[1], "Invst\r\n")) {
acc -> type = PORTFOLIO;
acc -> type = STOCK;
} else {
DEBUG ("Unsupported account type\n");
DEBUG (&qifline[1]);

File diff suppressed because it is too large Load Diff

@ -23,6 +23,7 @@
* Huntington Beach, CA 92648-4632 *
\********************************************************************/
#include "date.h"
#include "Transaction.h"
#include "util.h"
@ -118,6 +119,53 @@ freeTransaction( Transaction *trans )
_free(trans);
}
/********************************************************************\
* sorting comparison function
*
* returns a negative value if transaction a is dated earlier than b,
* returns a positive value if transaction a is dated later than b,
* returns zero if both transactions are on the same date.
*
\********************************************************************/
int
xaccTransOrder (Transaction **ta, Transaction **tb)
{
int retval;
char *da, *db;
retval = datecmp (&((*ta)->date), &((*tb)->date));
/* if dates differ, return */
if (retval) return retval;
/* otherwise, sort on transaction strings */
da = (*ta)->description;
db = (*tb)->description;
if (!da) return -1;
if (!db) return +1;
retval = strcmp (da, db);
return retval;
}
/********************************************************************\
\********************************************************************/
int
xaccCountTransactions (Transaction **tarray)
{
Transaction *trans;
int ntrans = 0;
trans = tarray[0];
while (trans) {
ntrans ++;
trans = tarray[ntrans];
}
return ntrans;
}
/************************ END OF ************************************\
\************************* FILE *************************************/

@ -251,6 +251,7 @@ xferWindow( Widget parent )
accountMenu[i].mnemonic = 0;
accountMenu[i].accelerator = NULL;
accountMenu[i].accel_text = NULL;
accountMenu[i].sensitive = True;
accountMenu[i].callback = menuCB;
accountMenu[i].callback_data = xferData->menuData[2*i];
accountMenu[i].subitems = (MenuItem *)NULL;
@ -284,6 +285,7 @@ xferWindow( Widget parent )
accountMenu[i].mnemonic = 0;
accountMenu[i].accelerator = NULL;
accountMenu[i].accel_text = NULL;
accountMenu[i].sensitive = True;
accountMenu[i].callback = menuCB;
accountMenu[i].callback_data = xferData->menuData[2*i+1];
accountMenu[i].subitems = (MenuItem *)NULL;
@ -487,4 +489,4 @@ xferCB( Widget mw, XtPointer cd, XtPointer cb )
XtDestroyWidget(xferData->dialog);
}
/* ********************** END OF FILE *************************/
/*********************** END OF FILE *************************/

@ -1,7 +1,7 @@
Begin3
Title: xacc -- simple single-user accounting program
Version: 0.9p
Entered-date: 21NOV97
Version: 0.9t
Entered-date: 24NOV97
Description: xacc is a program to keep track of your finances. It
offers a simple check-book register style interface.
Currently, the features are quite simple:
@ -19,15 +19,24 @@ Description: xacc is a program to keep track of your finances. It
the previous transaction. Handy if you have
similar transactions on a regular basis.
(such as depositing your paycheck every week :)
- General Ledger. Well, not yet, but double-entry
is supported (transfers between accounts),
sub-accounts are supported (so that master accounts
can contain detail accounts), as well as
income/expense accounts that handle double-entry
properly.
- Stock/Mutual Fund Portfolios. Tracks stock
investments.
- General Ledger. This is an advanced feature
for more serious work. Supported are:
o Double Entry: Transactions can appear in two
accounts, one debited, one credited.
o Sub-accounts: A master account can have
a heriarchy of detail accounts.
o Income/Expense account types.
o General Ledger for displaying multiple
accounts at once.
This is a beta development version with known
minor user interface bugs and no known major bugs.
Under rare circumstances, it will core dump (due to
Motif problems) so save often! It has been tested
only lightly but seems to work. It is not beleived to
corrupt data.
Keywords: X11 Accounting double entry
Author: rclark@cs.hmc.edu (Robin Clark)
@ -35,7 +44,7 @@ Maintained-by: linas@linas.org (Linas Vepstas)
Primary-site: http://www3.hmc.edu/~rclark/xacc/
Alternate-site: http://linas.org/linux/xacc
Alternate-site: sunsite.unc.edu /pub/Linux/apps/financial/accounting/
521kB xacc-0.9m.tar.gz
527kB xacc-0.9s.tar.gz
Platforms: Linux/Unix/X Windows/Lesstif/Motif/Sparc/Intel
Copying-policy: GPL
End

Loading…
Cancel
Save