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