more helper functions for data hiding in transactions

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@673 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-03-20 05:08:09 +00:00
parent 2903edb8f9
commit ae0ac46d64
5 changed files with 195 additions and 24 deletions

View File

@ -137,6 +137,8 @@ void xaccConsolidateTransactions (Account *);
void xaccMoveFarEnd (Split *, Account *);
void xaccMoveFarEndByName (Split *, const char *);
Account * xaccSplitGetAccount (Split *);
/** GLOBALS *********************************************************/
extern int next_free_unique_account_id;

View File

@ -521,6 +521,24 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year)
}
}
void
xaccTransSetDateToday (Transaction *trans)
{
Date d;
todaysDate (&d);
xaccTransSetDate (trans, d.day, d.month, d.year);
}
void
xaccTransSetDateStr (Transaction *trans, char *str)
{
Date d;
sscandate (str, &d, DATE_FULL);
xaccTransSetDate (trans, d.day, d.month, d.year);
}
/********************************************************************\
\********************************************************************/
@ -586,12 +604,6 @@ xaccTransSetReconcile (Transaction *trans, char recn)
MARK_SPLIT (&(trans->source_split));
}
void
xaccTransSetDateToday (Transaction *trans)
{
todaysDate( &(trans->date) );
}
/********************************************************************\
\********************************************************************/
Split *
@ -600,6 +612,47 @@ xaccTransGetSourceSplit (Transaction *trans)
return (&(trans->source_split));
}
Split *
xaccTransGetDestSplit (Transaction *trans, int i)
{
return (trans->dest_splits[i]);
}
char *
xaccTransGetNum (Transaction *trans)
{
return (trans->num);
}
char *
xaccTransGetDescription (Transaction *trans)
{
return (trans->description);
}
char *
xaccTransGetDateStr (Transaction *trans)
{
char buf [100];
sprintf( buf, "%2d/%2d/%02d",
trans->date.month,
trans->date.day,
(trans->date.year%100) );
return strdup (buf);
}
int
xaccTransCountSplits (Transaction *trans)
{
return (xaccCountSplits (trans->dest_splits));
}
int
xaccTransIsSource (Transaction *trans, Split *split)
{
return (split == &(trans->source_split));
}
/********************************************************************\
\********************************************************************/
@ -627,5 +680,45 @@ xaccSplitSetReconcile (Split *split, char recn)
MARK_SPLIT (split);
}
/********************************************************************\
\********************************************************************/
/* return the parent transaction of the split */
Transaction *
xaccSplitGetParent (Split *split)
{
return (split->parent);
}
Account *
xaccSplitGetAccount (Split *split)
{
return (split->acc);
}
char
xaccSplitGetReconcile (Split *split)
{
return (split->reconciled);
}
double
xaccSplitGetAmount (Split * split)
{
return (split->damount);
}
double
xaccSplitGetValue (Split * split)
{
return ((split->damount) * (split->share_price));
}
double
xaccSplitGetSharePrice (Split * split)
{
return (split->share_price);
}
/************************ END OF ************************************\
\************************* FILE *************************************/

View File

@ -59,15 +59,15 @@ typedef struct _transaction Transaction;
* is stored in proper date order in the accounts.
*/
Split * xaccMallocSplit (void);
void xaccInitSplit (Split *); /* clears a split struct */
void xaccFreeSplit (Split *); /* frees memory */
int xaccCountSplits (Split **sarray);
Transaction * xaccMallocTransaction (void); /* mallocs and inits */
void xaccInitTransaction (Transaction *);/* clears a trans struct */
/* freeTransaction only does so if the transaction is not part of an
* account. (i.e. if none of the member splits are in an account). */
void xaccFreeTransaction (Transaction *);
void xaccTransSetDate (Transaction *, int day, int mon, int year);
void xaccTransSetDateStr (Transaction *, char *);
/* set the transaction date to the current system time. */
void xaccTransSetDateToday (Transaction *);
@ -78,25 +78,39 @@ void xaccTransSetMemo (Transaction *, const char *);
void xaccTransSetAction (Transaction *, const char *);
void xaccTransSetReconcile (Transaction *, char);
/* return pointer to the source split */
Split * xaccTransGetSourceSplit (Transaction *);
void xaccSplitSetMemo (Split *, const char *);
void xaccSplitSetAction (Split *, const char *);
void xaccSplitSetReconcile (Split *, char);
/* freeTransaction only does so if the transaction is not part of an
* account. (i.e. if none of the member splits are in an account). */
void xaccFreeTransaction (Transaction *);
void xaccTransAppendSplit (Transaction *, Split *);
void xaccTransRemoveSplit (Transaction *, Split *);
void xaccTransAppendSplit (Transaction *, Split *);
void xaccTransRemoveSplit (Transaction *, Split *);
/* recompute the total transaction value, based
* on the sum of the debit splits that belong to this
* transaction. */
void xaccTransRecomputeAmount (Transaction *);
/* ------------- gets --------------- */
/* return pointer to the source split */
Split * xaccTransGetSourceSplit (Transaction *);
Split * xaccTransGetDestSplit (Transaction *trans, int i);
char * xaccTransGetNum (Transaction *);
char * xaccTransGetDescription (Transaction *trans);
char * xaccTransGetDateStr (Transaction *);
/* return the number of destination splits */
int xaccTransCountSplits (Transaction *trans);
/* returns non-zero value if split is source split */
int xaccTransIsSource (Transaction *, Split *);
Split * xaccMallocSplit (void);
void xaccInitSplit (Split *); /* clears a split struct */
void xaccFreeSplit (Split *); /* frees memory */
int xaccCountSplits (Split **sarray);
void xaccSplitSetMemo (Split *, const char *);
void xaccSplitSetAction (Split *, const char *);
void xaccSplitSetReconcile (Split *, char);
/* The following two functions set the amount on the split */
void xaccSetAmount (Split *, double);
void xaccSetShareAmount (Split *, double);
@ -125,6 +139,15 @@ double xaccGetClearedBalance (Split *);
double xaccGetReconciledBalance (Split *);
double xaccGetShareBalance (Split *);
/* return teh parent transaction of the split */
Transaction * xaccSplitGetParent (Split *);
/* return the value of the reconcile flag */
char xaccSplitGetReconcile (Split *split);
double xaccSplitGetAmount (Split * split);
double xaccSplitGetValue (Split * split);
double xaccSplitGetSharePrice (Split * split);
/********************************************************************\
* sorting comparison function
*

View File

@ -240,5 +240,41 @@ datecmp( Date *date1, Date *date2 )
}
}
/********************************************************************\
* sscandate *
* parses a date from a given string *
* *
* Args: in_string -- the string to parse *
* date -- the date into which the parsed date is placed *
* flag -- indicates whether to parse the whole of the *
* or a portion. Valid values are: *
DATE_SHORT, DATE_YEAR and DATE_FULL *
* Return: number of characters read from string *
\********************************************************************/
int
sscandate( const char *in_string, Date *date, int flags )
{
int *a,*b,*c; /* pointers to address of day, month and year vars */
int ret;
#ifdef UK_DATES
a=&date->day; b=&date->month; c=&date->year;
#else
a=&date->month; b=&date->day; c=&date->year;
#endif
switch (flags)
{
case DATE_SHORT:
ret=sscanf( in_string, "%d/%d", a, b ); break;
case DATE_YEAR:
ret=sscanf( in_string, "%d", c ); break;
case DATE_FULL:
ret=sscanf( in_string, "%d/%d/%d", a, b, c); break;
}
return ret;
}
/********************** END OF FILE *********************************\
\********************************************************************/

View File

@ -1,3 +1,13 @@
/*
* Major Hack Alert ---
* this whole file & design needs to be replaced with
* something that can handle seconds (actually, milliseconds
* to keep the banks happy).
*
* There a lot of lint here and it needs major overhaul in general.
*/
/********************************************************************\
* date.h -- utility functions to handle the date (adjusting, get *
* current date, etc.) for xacc (X-Accountant) *
@ -99,6 +109,13 @@ Date* todaysDate( Date *date );
int daysInMonth( int month , int year );
int datecmp( Date *date1, Date *date2 );
#define DATE_SHORT 0
#define DATE_YEAR 1
#define DATE_FULL 2
int sscandate( const char *in_string, Date *date, int flags);
/** GLOBALS *********************************************************/
#endif /* __XACC_DATE_H__ */