GnuCash c935c2f+
Loading...
Searching...
No Matches
SplitP.hpp
1/********************************************************************\
2 * SplitP.hpp -- 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.hpp
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
71struct 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 const 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 const char *action; /* Buy, Sell, Div, etc. */
95
96 time64 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 const char *split_type;
119
120 /* -------------------------------------------------------------- */
121 /* Below follow some 'temporary' fields */
122
123 /* The various "balances" are the sum of all of the values of
124 * all the splits in the account, up to and including this split.
125 * These balances apply to a sorting order by date posted
126 * (not by date entered). */
127 gnc_numeric balance;
128 gnc_numeric noclosing_balance;
129 gnc_numeric cleared_balance;
130 gnc_numeric reconciled_balance;
131
132 /* The stock-split adjusted amount */
133 gnc_numeric adjusted_amount;
134};
135
137{
138 QofInstanceClass parent_class;
139};
140
141
142/* Set the split's GncGUID. This should only be done when reading
143 * a split from a datafile, or some other external source. Never
144 * call this on an existing split! */
145#define xaccSplitSetGUID(s,g) qof_instance_set_guid(QOF_INSTANCE(s),g)
146
147/* The xaccFreeSplit() method simply frees all memory associated
148 * with the split. It does not verify that the split isn't
149 * referenced in some account. If the split is referenced by an
150 * account, then calling this method will leave the system in an
151 * inconsistent state. This *will* lead to crashes and hangs.
152 */
153void xaccFreeSplit (Split *split); /* frees memory */
154
155Split *xaccSplitCloneNoKvp (const Split *s);
156void xaccSplitCopyKvp (const Split *from, Split *to);
157
158Split *xaccDupeSplit (const Split *s);
159void mark_split (Split *s);
160
161void xaccSplitVoid(Split *split);
162void xaccSplitUnvoid(Split *split);
163void xaccSplitCommitEdit(Split *s);
164void xaccSplitRollbackEdit(Split *s);
165
166/* Compute the value of a list of splits in the given currency,
167 * excluding the skip_me split. */
168gnc_numeric xaccSplitsComputeValue (GList *splits, const Split * skip_me,
169 const gnc_commodity * base_currency);
170
171/* Code to register Split type with the engine */
172gboolean xaccSplitRegister (void);
173
174/* The xaccSplitDetermineGainStatus() routine will analyze the
175 * the split, and try to set the internal status flags
176 * appropriately for the split. These flags indicate if the split
177 * represents cap gains, and if the gains value/amount needs to be
178 * recomputed.
179 */
180void xaccSplitDetermineGainStatus (Split *split);
181
182/* ---------------------------------------------------------------- */
183/* Deprecated routines */
184void DxaccSplitSetSharePriceAndAmount (Split *split,
185 double price,
186 double amount);
187void DxaccSplitSetShareAmount (Split *split, double amount);
188
189/********************************************************************\
190 * sorting comparison function
191 *
192 * returns a negative value if transaction a is dated earlier than b,
193 * returns a positive value if transaction a is dated later than b,
194 *
195 * This function tries very hard to uniquely order all transactions.
196 * If two transactions occur on the same date, then their "num" fields
197 * are compared. If the num fields are identical, then the description
198 * fields are compared. If these are identical, then the memo fields
199 * are compared. Hopefully, there will not be any transactions that
200 * occur on the same day that have all three of these values identical.
201 *
202 * Note that being able to establish this kind of absolute order is
203 * important for some of the ledger display functions.
204 *
205 * Yes, this kind of code dependency is ugly, but the alternatives seem
206 * ugly too.
207 *
208\********************************************************************/
209
210
211#define CHECK_GAINS_STATUS(s) \
212 if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
213
214#define SET_GAINS_DIRTY(s,flg) do { \
215 if (FALSE == (GAINS_STATUS_GAINS & s->gains)) { \
216 s->gains |= flg; \
217 } else { \
218 if (s->gains_split) s->gains_split->gains |= flg; \
219 } \
220} while (0)
221
222#define SET_GAINS_ADIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_ADIRTY);
223#define SET_GAINS_A_VDIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_A_VDIRTY);
224#define SET_GAINS_VDIRTY(s) SET_GAINS_DIRTY(s,GAINS_STATUS_VDIRTY);
225
226/* Structure for accessing static functions for testing */
227typedef struct
228{
229 gboolean (*xaccSplitEqualCheckBal) (const char *tag, gnc_numeric a,
230 gnc_numeric b);
231 int (*get_currency_denom) (const Split *s);
232 int (*get_commodity_denom) (const Split *s);
233 gboolean (*get_corr_account_split) (const Split *sa, const Split **retval);
235
236SplitTestFunctions* _utest_split_fill_functions (void);
237
238
242#endif /* XACC_SPLIT_P_H */
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
STRUCTS.
Split in Gnucash.
Definition SplitP.hpp:72