GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SplitP.h
1 /********************************************************************\
2  * SplitP.h -- private header for splits *
3  * Copyright (C) 1997 Robin D. Clark *
4  * Copyright (C) 1997-2000 Linas Vepstas <[email protected]> *
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 [email protected] *
23  * *
24 \********************************************************************/
25 
26 /*
27  * FILE:
28  * SplitP.h
29  *
30  * FUNCTION:
31  * The is the *private* split 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_SPLIT_P_H
46 #define XACC_SPLIT_P_H
47 
48 #include <time.h>
49 #include <glib.h>
50 
51 #include "gnc-engine.h" /* for typedefs */
52 #include "qof.h"
53 
54 
56 /* A "split" is more commonly referred to as an "entry" in a "transaction".
57  */
58 
59 /* Flags for handling cap-gains status */
60 #define GAINS_STATUS_UNKNOWN 0xff
61 #define GAINS_STATUS_CLEAN 0x0
62 #define GAINS_STATUS_GAINS 0x3
63 #define GAINS_STATUS_DATE_DIRTY 0x10
64 #define GAINS_STATUS_AMNT_DIRTY 0x20
65 #define GAINS_STATUS_VALU_DIRTY 0x40
66 #define GAINS_STATUS_LOT_DIRTY 0x80
67 #define GAINS_STATUS_ADIRTY (GAINS_STATUS_AMNT_DIRTY|GAINS_STATUS_LOT_DIRTY)
68 #define GAINS_STATUS_VDIRTY (GAINS_STATUS_VALU_DIRTY)
69 #define GAINS_STATUS_A_VDIRTY (GAINS_STATUS_AMNT_DIRTY|GAINS_STATUS_VALU_DIRTY|GAINS_STATUS_LOT_DIRTY)
70 
71 struct split_s
72 {
73  QofInstance inst;
74 
75  Account *acc; /* back-pointer to debited/credited account */
76  Account *orig_acc;
77  GNCLot *lot; /* back-pointer to debited/credited lot */
78 
79  Transaction *parent; /* parent of split */
80  Transaction *orig_parent;
81 
82  /* The memo field is an arbitrary user-assiged value.
83  * It is intended to hold a short (zero to forty character) string
84  * that is displayed by the GUI along with this split.
85  */
86  char * memo;
87 
88  /* The action field is an arbitrary user-assigned value.
89  * It is meant to be a very short (one to ten character) string that
90  * signifies the "type" of this split, such as e.g. Buy, Sell, Div,
91  * Withdraw, Deposit, ATM, Check, etc. The idea is that this field
92  * can be used to create custom reports or graphs of data.
93  */
94  char * action; /* Buy, Sell, Div, etc. */
95 
96  Timespec date_reconciled; /* date split was reconciled */
97  char reconciled; /* The reconciled field */
98 
99  /* gains is a flag used to track the relationship between
100  * capital-gains splits. Depending on its value, this flag indicates
101  * if this split is the source of gains, if this split is a record
102  * of the gains, and if values are 'dirty' and need to be recomputed.
103  */
104  unsigned char gains;
105 
106  /* 'gains_split' is a convenience pointer used to track down the
107  * other end of a cap-gains transaction pair. NULL if this split
108  * doesn't involve cap gains.
109  */
110  Split *gains_split;
111 
112  /* 'value' is the quantity of the transaction balancing commodity
113  * (i.e. currency) involved, 'amount' is the amount of the account's
114  * commodity involved. */
115  gnc_numeric value;
116  gnc_numeric amount;
117 
118  /* -------------------------------------------------------------- */
119  /* Below follow some 'temporary' fields */
120 
121  /* The various "balances" are the sum of all of the values of
122  * all the splits in the account, up to and including this split.
123  * These balances apply to a sorting order by date posted
124  * (not by date entered). */
125  gnc_numeric balance;
126  gnc_numeric cleared_balance;
127  gnc_numeric reconciled_balance;
128 };
129 
131 {
132  QofInstanceClass parent_class;
133 };
134 
135 
136 /* Set the split's GncGUID. This should only be done when reading
137  * a split from a datafile, or some other external source. Never
138  * call this on an existing split! */
139 #define xaccSplitSetGUID(s,g) qof_instance_set_guid(QOF_INSTANCE(s),g)
140 
141 /* The xaccFreeSplit() method simply frees all memory associated
142  * with the split. It does not verify that the split isn't
143  * referenced in some account. If the split is referenced by an
144  * account, then calling this method will leave the system in an
145  * inconsistent state. This *will* lead to crashes and hangs.
146  */
147 void xaccFreeSplit (Split *split); /* frees memory */
148 
149 Split *xaccSplitCloneNoKvp (const Split *s);
150 void xaccSplitCopyKvp (const Split *from, Split *to);
151 
152 Split *xaccDupeSplit (const Split *s);
153 void mark_split (Split *s);
154 
155 void xaccSplitVoid(Split *split);
156 void xaccSplitUnvoid(Split *split);
157 void xaccSplitCommitEdit(Split *s);
158 void xaccSplitRollbackEdit(Split *s);
159 
160 /* Compute the value of a list of splits in the given currency,
161  * excluding the skip_me split. */
162 gnc_numeric xaccSplitsComputeValue (GList *splits, const Split * skip_me,
163  const gnc_commodity * base_currency);
164 
165 /* Code to register Split type with the engine */
166 gboolean xaccSplitRegister (void);
167 
168 /* The xaccSplitDetermineGainStatus() routine will analyze the
169  * the split, and try to set the internal status flags
170  * appropriately for the split. These flags indicate if the split
171  * represents cap gains, and if the gains value/amount needs to be
172  * recomputed.
173  */
174 void xaccSplitDetermineGainStatus (Split *split);
175 
176 /* ---------------------------------------------------------------- */
177 /* Deprecated routines */
178 void DxaccSplitSetSharePriceAndAmount (Split *split,
179  double price,
180  double amount);
181 void DxaccSplitSetShareAmount (Split *split, double amount);
182 
183 /********************************************************************\
184  * sorting comparison function
185  *
186  * returns a negative value if transaction a is dated earlier than b,
187  * returns a positive value if transaction a is dated later than b,
188  *
189  * This function tries very hard to uniquely order all transactions.
190  * If two transactions occur on the same date, then their "num" fields
191  * are compared. If the num fields are identical, then the description
192  * fields are compared. If these are identical, then the memo fields
193  * are compared. Hopefully, there will not be any transactions that
194  * occur on the same day that have all three of these values identical.
195  *
196  * Note that being able to establish this kind of absolute order is
197  * important for some of the ledger display functions.
198  *
199  * Yes, this kind of code dependency is ugly, but the alternatives seem
200  * ugly too.
201  *
202 \********************************************************************/
203 
204 
205 #define DATE_CMP(aaa,bbb,field) { \
206  /* if dates differ, return */ \
207  if ( (aaa->field.tv_sec) < \
208  (bbb->field.tv_sec)) { \
209  return -1; \
210  } else \
211  if ( (aaa->field.tv_sec) > \
212  (bbb->field.tv_sec)) { \
213  return +1; \
214  } \
215  \
216  /* else, seconds match. check nanoseconds */ \
217  if ( (aaa->field.tv_nsec) < \
218  (bbb->field.tv_nsec)) { \
219  return -1; \
220  } else \
221  if ( (aaa->field.tv_nsec) > \
222  (bbb->field.tv_nsec)) { \
223  return +1; \
224  } \
225 }
226 
227 #define CHECK_GAINS_STATUS(s) \
228  if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
229 
230 #define SET_GAINS_DIRTY(s,flg) do { \
231  if (FALSE == (GAINS_STATUS_GAINS & s->gains)) { \
232  s->gains |= flg; \
233  } else { \
234  if (s->gains_split) s->gains_split->gains |= flg; \
235  } \
236 } while (0)
237 
238 #define SET_GAINS_ADIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_ADIRTY);
239 #define SET_GAINS_A_VDIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_A_VDIRTY);
240 #define SET_GAINS_VDIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_VDIRTY);
241 
242 /* Structure for accessing static functions for testing */
243 typedef struct
244 {
245  gboolean (*xaccSplitEqualCheckBal) (const char *tag, gnc_numeric a,
246  gnc_numeric b);
247  int (*get_currency_denom) (const Split *s);
248  int (*get_commodity_denom) (const Split *s);
249  gboolean (*get_corr_account_split) (const Split *sa, const Split **retval);
251 
252 SplitTestFunctions* _utest_split_fill_functions (void);
253 
254 
258 #endif /* XACC_SPLIT_P_H */
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
All type declarations for the whole Gnucash engine.
Definition: SplitP.h:71