TransactionP.h

00001 /********************************************************************\
00002  * TransactionP.h -- private header for transaction & splits        *
00003  * Copyright (C) 1997 Robin D. Clark                                *
00004  * Copyright (C) 1997-2000 Linas Vepstas <linas@linas.org>          *
00005  * Copyright (C) 2000 Bill Gribble                                  *
00006  *                                                                  *
00007  * This program is free software; you can redistribute it and/or    *
00008  * modify it under the terms of the GNU General Public License as   *
00009  * published by the Free Software Foundation; either version 2 of   *
00010  * the License, or (at your option) any later version.              *
00011  *                                                                  *
00012  * This program is distributed in the hope that it will be useful,  *
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00015  * GNU General Public License for more details.                     *
00016  *                                                                  *
00017  * You should have received a copy of the GNU General Public License*
00018  * along with this program; if not, contact:                        *
00019  *                                                                  *
00020  * Free Software Foundation           Voice:  +1-617-542-5942       *
00021  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00022  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00023  *                                                                  *
00024 \********************************************************************/
00025 
00026 /*
00027  * FILE:
00028  * TransactionP.h
00029  *
00030  * FUNCTION:
00031  * The is the *private* transaction header file.  Code outside of 
00032  * engine should *not* include this file.  This is because code
00033  * outside of the engine should *never* access any of the structure
00034  * members directly.
00035  *
00036  * Note that this header file also defines prototypes for various
00037  * routines that perform sub-atomic updates of the accounting
00038  * structures.  If these routines are not used properly, they
00039  * can result in inconsistent, unbalanced accounting structures.
00040  * In other words, their use is dangerous, and their use outside
00041  * of the scope of the engine is forbidden.
00042  *
00043  */
00044 
00045 #ifndef XACC_TRANSACTION_P_H
00046 #define XACC_TRANSACTION_P_H
00047 
00048 #include <time.h>
00049 #include <glib.h>
00050 
00051 #include "gnc-engine.h"   /* for typedefs */
00052 #include "SplitP.h"
00053 #include "qof.h"
00054 
00055 
00057 /* 
00058  * Double-entry is forced by having at least two splits in every
00059  * transaction.  By convention, (and only by convention, not by
00060  * any innate requirement), the first split is considered to be
00061  * the source split or the crediting split, and the others are
00062  * the destination, or debiting splits.  The grand total of all
00063  * of the splits must always be kept zero.
00064  */
00065 
00066 /* A split transaction is one which shows up as a credit (or debit) in
00067  * one account, and pieces of it show up as debits (or credits) in other
00068  * accounts.  Thus, a single credit-card transaction might be split
00069  * between "dining", "tips" and "taxes" categories.
00070  *
00071  * A "split" is more commonly referred to as an "entry" in a "transaction".
00072  */
00073 
00074 struct transaction_s
00075 {
00076   QofInstance inst;     /* glbally unique id */
00077 
00078   Timespec date_entered;     /* date register entry was made              */
00079   Timespec date_posted;      /* date transaction was posted at bank       */
00080 
00081   /* The num field is a arbitrary user-assigned field.  
00082    * It is intended to store a short id number, typically the check number,
00083    * deposit number, invoice number or other tracking number.
00084    */
00085   char * num;  
00086 
00087   /* The description field is an arbitrary user-assigned value. 
00088    * It is meant to be a short descriptive phrase.
00089    */
00090   char * description;        
00091 
00092   /* The common_currency field is the balancing common currency for
00093    * all the splits in the transaction.  Alternate, better(?) name: 
00094    * "valuation currency": it is the currency in which all of the 
00095    * splits can be valued.  */
00096   gnc_commodity *common_currency;
00097 
00098   GList * splits; /* list of splits */
00099 
00100   /* marker is used to track the progress of transaction traversals. 
00101    * 0 is never a legitimate marker value, so we can tell is we hit
00102    * a new transaction in the middle of a traversal. All each new
00103    * traversal cares about is whether or not the marker stored in
00104    * a transaction is the same as or different than the one
00105    * corresponding to the current traversal. */
00106   unsigned char  marker;      
00107 
00108   /* The orig pointer points at a copy of the original transaction,
00109    * before editing was started.  This orig copy is used to rollback 
00110    * any changes made if/when the edit is abandoned.
00111    */
00112   Transaction *orig;
00113 };
00114 
00115 struct _TransactionClass
00116 {
00117   QofInstanceClass parent_class;
00118 };
00119 
00120 /* Set the transaction's GUID. This should only be done when reading
00121  * a transaction from a datafile, or some other external source. Never
00122  * call this on an existing transaction! */
00123 #define xaccTransSetGUID(t,g) qof_instance_set_guid(QOF_INSTANCE(t),g)
00124 
00125 /* This routine makes a 'duplicate' of the indicated transaction.
00126  * This routine cannot be exposed publically since the duplicate
00127  * is wrong in many ways: it is not issued a unique guid, and thus
00128  * not a properly registered Entity.  The splits are copied, but
00129  * these are also funny: they aren't inserted into the accounts 
00130  * they claim to be in.  The splits also have bogus GUID's.
00131  * Another 'feature': the splits point at the old transaction
00132  * as the parent, not the new transaction.  
00133  */
00134 Transaction * xaccDupeTransaction (const Transaction *t);
00135 
00136 /* The xaccTransSet/GetVersion() routines set & get the version
00137  *    numbers on this transaction.  The version number is used to manage
00138  *    multi-user updates.  These routines are private because we don't
00139  *    want anyone except the backend to mess with them.
00140  */
00141 void xaccTransSetVersion (Transaction*, gint32);
00142 gint32 xaccTransGetVersion (const Transaction*);
00143 
00144 /* Code to register Transaction type with the engine */
00145 gboolean xaccTransRegister (void);
00146 
00147 /* The xaccTransactionGetBackend() subroutine will find the
00148  *    persistent-data storage backend associated with this 
00149  *    transaction.
00150  */
00151 QofBackend * xaccTransactionGetBackend (Transaction *trans);
00152 
00153 /* The xaccEnable/DisableDataScrubbing() routines affect what
00154  *   happens during transaction commit.  When scrubbing is enabled,
00155  *   then transactions are fixed up during transaction commit, 
00156  *   so that only consistent transactions are commited to the engine.
00157  *   However, when data is being loaded from a backend (in particular,
00158  *   from the file backend), the data might not be consistent until
00159  *   its completely loaded.   In particular, gains transactions might
00160  *   be loaded at a different time than the transactions that casued
00161  *   the gains.  Thus, scrubbing needs do be disabled during file
00162  *   load.  These routines enable that.
00163  */
00164 void xaccEnableDataScrubbing(void);
00165 void xaccDisableDataScrubbing(void);
00166 
00172 #define xaccTransSetSlots_nc(T,F) qof_instance_set_slots(QOF_INSTANCE(T),F)
00173 
00174 void xaccTransRemoveSplit (Transaction *trans, const Split *split);
00175 G_INLINE_FUNC void check_open (const Transaction *trans);
00176 
00180 #endif /* XACC_TRANSACTION_P_H */

Generated on Sun Oct 12 05:07:47 2008 for GnuCash by  doxygen 1.5.2