GnuCash  5.6-107-ga53ed8f501+
TransactionP.h
1 /********************************************************************\
2  * TransactionP.h -- private header for transaction & splits *
3  * Copyright (C) 1997 Robin D. Clark *
4  * Copyright (C) 1997-2000 Linas Vepstas <linas@linas.org> *
5  * Copyright (C) 2000 Bill Gribble *
6  * *
7  * This program is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License as *
9  * published by the Free Software Foundation; either version 2 of *
10  * the License, or (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License*
18  * along with this program; if not, contact: *
19  * *
20  * Free Software Foundation Voice: +1-617-542-5942 *
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
22  * Boston, MA 02110-1301, USA gnu@gnu.org *
23  * *
24 \********************************************************************/
25 
26 /*
27  * FILE:
28  * TransactionP.h
29  *
30  * FUNCTION:
31  * The is the *private* transaction header file. Code outside of
32  * engine should *not* include this file. This is because code
33  * outside of the engine should *never* access any of the structure
34  * members directly.
35  *
36  * Note that this header file also defines prototypes for various
37  * routines that perform sub-atomic updates of the accounting
38  * structures. If these routines are not used properly, they
39  * can result in inconsistent, unbalanced accounting structures.
40  * In other words, their use is dangerous, and their use outside
41  * of the scope of the engine is forbidden.
42  *
43  */
44 
45 #ifndef XACC_TRANSACTION_P_H
46 #define XACC_TRANSACTION_P_H
47 
48 #include <time.h>
49 #include <glib.h>
50 
51 #include "gnc-engine.h" /* for typedefs */
52 #include "SplitP.h"
53 #include "qof.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 
61 /*
62  * Double-entry is forced by having at least two splits in every
63  * transaction. By convention, (and only by convention, not by
64  * any innate requirement), the first split is considered to be
65  * the source split or the crediting split, and the others are
66  * the destination, or debiting splits. The grand total of all
67  * of the splits must always be kept zero.
68  */
69 
70 /* A split transaction is one which shows up as a credit (or debit) in
71  * one account, and pieces of it show up as debits (or credits) in other
72  * accounts. Thus, a single credit-card transaction might be split
73  * between "dining", "tips" and "taxes" categories.
74  *
75  * A "split" is more commonly referred to as an "entry" in a "transaction".
76  */
77 
79 {
80  QofInstance inst; /* glbally unique id */
81 
82  time64 date_entered; /* date register entry was made */
83  time64 date_posted; /* date transaction was posted at bank */
84 
85  /* The num field is a arbitrary user-assigned field.
86  * It is intended to store a short id number, typically the check number,
87  * deposit number, invoice number or other tracking number.
88  */
89  const char *num;
90 
91  /* The description field is an arbitrary user-assigned value.
92  * It is meant to be a short descriptive phrase.
93  */
94  const char *description;
95 
96  /* The common_currency field is the balancing common currency for
97  * all the splits in the transaction. Alternate, better(?) name:
98  * "valuation currency": it is the currency in which all of the
99  * splits can be valued. */
100  gnc_commodity *common_currency;
101 
102  GList * splits; /* list of splits */
103 
104  /* marker is used to track the progress of transaction traversals.
105  * 0 is never a legitimate marker value, so we can tell is we hit
106  * a new transaction in the middle of a traversal. All each new
107  * traversal cares about is whether or not the marker stored in
108  * a transaction is the same as or different than the one
109  * corresponding to the current traversal. */
110  unsigned char marker;
111 
112  /* The orig pointer points at a copy of the original transaction,
113  * before editing was started. This orig copy is used to rollback
114  * any changes made if/when the edit is abandoned.
115  */
116  Transaction *orig;
117 
118  /* A flag to indicate when a transaction represents an invoice, a payment,
119  * or a link between the two.
120  */
121  char txn_type;
122 
123 };
124 
126 {
127  QofInstanceClass parent_class;
128 };
129 
130 /* Set the transaction's GncGUID. This should only be done when reading
131  * a transaction from a datafile, or some other external source. Never
132  * call this on an existing transaction! */
133 #define xaccTransSetGUID(t,g) qof_instance_set_guid(QOF_INSTANCE(t),g)
134 
135 /* This routine makes a 'duplicate' of the indicated transaction.
136  * This routine cannot be exposed publicly since the duplicate
137  * is wrong in many ways: it is not issued a unique guid, and thus
138  * not a properly registered Entity. The splits are copied, but
139  * these are also funny: they aren't inserted into the accounts
140  * they claim to be in. The splits also have bogus GncGUID's.
141  * Another 'feature': the splits point at the old transaction
142  * as the parent, not the new transaction.
143  */
144 Transaction * xaccDupeTransaction (const Transaction *t);
145 
146 /* The xaccTransSet/GetVersion() routines set & get the version
147  * numbers on this transaction. The version number is used to manage
148  * multi-user updates. These routines are private because we don't
149  * want anyone except the backend to mess with them.
150  */
151 void xaccTransSetVersion (Transaction*, gint32);
152 gint32 xaccTransGetVersion (const Transaction*);
153 
154 /* Code to register Transaction type with the engine */
155 gboolean xaccTransRegister (void);
156 
157 /* The xaccTransactionGetBackend() subroutine will find the
158  * persistent-data storage backend associated with this
159  * transaction.
160  */
161 QofBackend * xaccTransactionGetBackend (Transaction *trans);
162 
163 /* The xaccEnable/DisableDataScrubbing() routines affect what
164  * happens during transaction commit. When scrubbing is enabled,
165  * then transactions are fixed up during transaction commit,
166  * so that only consistent transactions are committed to the engine.
167  * However, when data is being loaded from a backend (in particular,
168  * from the file backend), the data might not be consistent until
169  * its completely loaded. In particular, gains transactions might
170  * be loaded at a different time than the transactions that caused
171  * the gains. Thus, scrubbing needs do be disabled during file
172  * load. These routines enable that.
173  */
174 void xaccEnableDataScrubbing(void);
175 void xaccDisableDataScrubbing(void);
176 
177 void xaccTransRemoveSplit (Transaction *trans, const Split *split);
178 void check_open (const Transaction *trans);
179 
180 /* Structure for accessing static functions for testing */
181 typedef struct
182 {
183  void (*mark_trans)(Transaction*);
184  void (*gen_event_trans)(Transaction*);
185  void (*xaccFreeTransaction)(Transaction*);
186  void (*destroy_gains)(Transaction*);
187  void (*do_destroy)(QofInstance*);
188  gboolean (*was_trans_emptied)(Transaction*);
189  void (*trans_on_error)(QofInstance*, QofBackendError);
190  void (*trans_cleanup_commit)(QofInstance*);
191  void (*xaccTransScrubGainsDate)(Transaction*);
192  Transaction *(*dupe_trans)(const Transaction*);
193 
195 
196 TransTestFunctions* _utest_trans_fill_functions (void);
197 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 
205 #endif /* XACC_TRANSACTION_P_H */
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:57
STRUCTS.
Definition: TransactionP.h:78
All type declarations for the whole Gnucash engine.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87