GnuCash  5.6-150-g038405b370+
Split.h
Go to the documentation of this file.
1 /********************************************************************\
2  * This program is free software; you can redistribute it and/or *
3  * modify it under the terms of the GNU General Public License as *
4  * published by the Free Software Foundation; either version 2 of *
5  * the License, or (at your option) any later version. *
6  * *
7  * This program is distributed in the hope that it will be useful, *
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10  * GNU General Public License for more details. *
11  * *
12  * You should have received a copy of the GNU General Public License*
13  * along with this program; if not, contact: *
14  * *
15  * Free Software Foundation Voice: +1-617-542-5942 *
16  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
17  * Boston, MA 02110-1301, USA gnu@gnu.org *
18  * *
19 \********************************************************************/
34 #ifndef XACC_SPLIT_H
35 #define XACC_SPLIT_H
36 
37 typedef struct _SplitClass SplitClass;
38 
39 #include <time.h>
40 
41 #include "gnc-commodity.h"
42 #include "gnc-engine.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /* --- type macros --- */
49 #define GNC_TYPE_SPLIT (gnc_split_get_type ())
50 #define GNC_SPLIT(o) \
51  (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SPLIT, Split))
52 #define GNC_SPLIT_CLASS(k) \
53  (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SPLIT, SplitClass))
54 #define GNC_IS_SPLIT(o) \
55  (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SPLIT))
56 #define GNC_IS_SPLIT_CLASS(k) \
57  (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SPLIT))
58 #define GNC_SPLIT_GET_CLASS(o) \
59  (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SPLIT, SplitClass))
60 GType gnc_split_get_type(void);
61 
62 
73 #define CREC 'c'
74 #define YREC 'y'
75 #define FREC 'f'
76 #define NREC 'n'
77 #define VREC 'v'
80 /* Convert the amount/value of the Split for viewing in the account --
81  * in particular we want to convert the Split to be in to_commodity.
82  * Returns the amount.
83  */
84 gnc_numeric xaccSplitConvertAmount (const Split *split, const Account * account);
85 
86 /*-----------------------------------------------------------------------
87  * Splits
88  *-----------------------------------------------------------------------*/
89 
95 Split * xaccMallocSplit (QofBook *book);
96 
97 /* Reinit a previously malloc'd split. Split remains in the book it
98  was already in, and the QofInstance portions also remain unchanged.
99  It's basically the data elements that are reverted to default
100  values. */
101 void xaccSplitReinit(Split * split);
102 
121 gboolean xaccSplitDestroy (Split *split);
122 
123 /*################## Added for Reg2 #################*/
131 void xaccSplitCopyOnto(const Split *from_split, Split *to_split);
132 /*################## Added for Reg2 #################*/
133 
136 QofBook * xaccSplitGetBook (const Split *split);
137 
140 Account * xaccSplitGetAccount (const Split *split);
141 void xaccSplitSetAccount (Split *s, Account *acc);
142 
144 Transaction * xaccSplitGetParent (const Split *split);
145 void xaccSplitSetParent (Split *split, Transaction *trans);
146 
149 GNCLot * xaccSplitGetLot (const Split *split);
150 
152 void xaccSplitSetLot(Split* split, GNCLot* lot);
153 
158 void xaccSplitSetMemo (Split *split, const char *memo);
159 
161 const char * xaccSplitGetMemo (const Split *split);
162 
172 void xaccSplitSetOnlineID (Split *split, const char *id);
173 
177 const char * xaccSplitGetOnlineID (const Split *split);
178 
180 gboolean xaccSplitHasOnlineID (const Split *split);
181 
193 void xaccSplitSetAction (Split *split, const char *action);
194 
200 const char * xaccSplitGetAction (const Split *split);
209 void xaccSplitSetReconcile (Split *split, char reconciled_flag);
211 char xaccSplitGetReconcile (const Split *split);
212 
215 void xaccSplitSetDateReconciledSecs (Split *split, time64 time);
216 
217 /*################## Added for Reg2 #################*/
219 time64 xaccSplitGetDateReconciled (const Split *split);
220 /*################## Added for Reg2 #################*/
221 
251 void xaccSplitSetAmount (Split *split, gnc_numeric amount);
252 
257 gnc_numeric xaccSplitGetAmount (const Split * split);
258 
265 void xaccSplitSetValue (Split *split, gnc_numeric value);
266 
271 gnc_numeric xaccSplitGetValue (const Split * split);
272 
278 void xaccSplitSetSharePriceAndAmount (Split *split,
279  gnc_numeric price,
280  gnc_numeric amount);
281 
285 gnc_numeric xaccSplitGetSharePrice (const Split * split);
286 
300 void xaccSplitSetBaseValue (Split *split, gnc_numeric value,
301  const gnc_commodity * base_currency);
302 
309 gnc_numeric xaccSplitGetBaseValue (const Split *split,
310  const gnc_commodity * base_currency);
311 
319 gnc_numeric xaccSplitGetBalance (const Split *split);
320 
328 gnc_numeric xaccSplitGetNoclosingBalance (const Split *split);
329 
337 gnc_numeric xaccSplitGetClearedBalance (const Split *split);
338 
346 gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
347 
351 void xaccSplitSetAdjustedAmount (Split *split, gnc_numeric amount);
352 
355 gnc_numeric xaccSplitGetAdjustedAmount (const Split *split);
356 
357 
381 gboolean xaccSplitEqual(const Split *sa, const Split *sb,
382  gboolean check_guids,
383  gboolean check_balances,
384  gboolean check_txn_splits);
385 
389 Split * xaccSplitLookup (const GncGUID *guid, QofBook *book);
390 #define xaccSplitLookupDirect(g,b) xaccSplitLookup(&(g),b)
391 
396 void xaccSplitAddPeerSplit (Split *split, const Split *other_split,
397  const time64 timestamp);
400 gboolean xaccSplitHasPeers (const Split *split);
405 gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split);
409 void xaccSplitRemovePeerSplit (Split *split, const Split *other_split);
410 
414 void xaccSplitMergePeerSplits (Split *split, const Split *other_split);
415 
421 Split * xaccSplitGetOtherSplit (const Split *split);
422 
425 const char *xaccSplitGetType(Split *s);
426 
429 void xaccSplitMakeStockSplit(Split *s);
430 
433 gboolean xaccSplitIsStockSplit(Split *s);
434 
447 gint xaccSplitOrder (const Split *sa, const Split *sb);
448 gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb);
449 
450 
451 /*
452  * These functions compare two splits by different criteria.
453  *
454  * These functions were added because converting strings to guile
455  * for comparisons in the transaction report is terribly inefficient.
456  * More may be added here in future if it turns out that other types
457  * of comparisons also induces guile slowdowns.
458  */
459 
462 int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb);
465 int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb);
469 int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb);
473 int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb);
474 
475 
492 char * xaccSplitGetCorrAccountFullName(const Split *sa);
494 const char * xaccSplitGetCorrAccountName(const Split *sa);
496 const char * xaccSplitGetCorrAccountCode(const Split *sa);
497 
498 #ifdef DUMP_FUNCTIONS
499 void xaccSplitDump (const Split *split, const char *tag);
500 #endif
501 
512 void xaccSplitSetSharePrice (Split *split, gnc_numeric price);
513 
517 /********************************************************************\
518  * Miscellaneous utility routines.
519 \********************************************************************/
520 
521 
533 gnc_numeric xaccSplitVoidFormerAmount(const Split *split);
534 
542 gnc_numeric xaccSplitVoidFormerValue(const Split *split);
543 
555 #define SPLIT_DATE_RECONCILED "date-reconciled"
556 #define SPLIT_BALANCE "balance"
557 #define SPLIT_CLEARED_BALANCE "cleared-balance"
558 #define SPLIT_RECONCILED_BALANCE "reconciled-balance"
559 #define SPLIT_MEMO "memo"
560 #define SPLIT_ACTION "action"
561 #define SPLIT_RECONCILE "reconcile-flag"
562 #define SPLIT_AMOUNT "amount"
563 #define SPLIT_SHARE_PRICE "share-price"
564 #define SPLIT_VALUE "value"
565 #define SPLIT_TYPE "type"
566 #define SPLIT_VOIDED_AMOUNT "voided-amount"
567 #define SPLIT_VOIDED_VALUE "voided-value"
568 #define SPLIT_LOT "lot"
569 #define SPLIT_TRANS "trans"
570 #define SPLIT_ACCOUNT "account"
571 #define SPLIT_ACCOUNT_GUID "account-guid"
572 /* used for SORTING ONLY */
573 #define SPLIT_ACCT_FULLNAME "acct-fullname"
574 #define SPLIT_CORR_ACCT_NAME "corr-acct-fullname"
575 #define SPLIT_CORR_ACCT_CODE "corr-acct-code"
576 
579 #define xaccSplitGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
580 
581 #ifdef __cplusplus
582 } /* extern "C" */
583 #endif
584 
585 #endif /* XACC_SPLIT_H */
586 
void xaccSplitSetValue(Split *split, gnc_numeric value)
The xaccSplitSetValue() method sets the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:92
gnc_numeric xaccSplitGetClearedBalance(const Split *split)
The cleared-balance is the currency-denominated balance of all transactions that have been marked as ...
Definition: Split.cpp:1328
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
Definition: Split.cpp:1536
void xaccSplitSetAdjustedAmount(Split *split, gnc_numeric amount)
Sets the stock split adjusted amount of a split.
Definition: Split.cpp:1346
void xaccSplitAddPeerSplit(Split *split, const Split *other_split, const time64 timestamp)
Add a peer split to this split&#39;s lot-split list.
Definition: Split.cpp:2084
void xaccSplitSetBaseValue(Split *split, gnc_numeric value, const gnc_commodity *base_currency)
Depending on the base_currency, set either the value or the amount of this split or both: If the base...
Definition: Split.cpp:1355
void xaccSplitSetAction(Split *split, const char *action)
The Action is an arbitrary user-assigned string.
Definition: Split.cpp:1786
void xaccSplitMakeStockSplit(Split *s)
Mark a split to be of type stock split - after this, you shouldn&#39;t modify the value anymore...
Definition: Split.cpp:2063
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
Definition: Split.cpp:1712
gnc_numeric xaccSplitGetReconciledBalance(const Split *split)
Returns the reconciled-balance of this split.
Definition: Split.cpp:1334
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition: Split.cpp:1506
gboolean xaccSplitHasOnlineID(const Split *split)
Returns TRUE if the split has a non-empty online_id.
Definition: Split.cpp:1963
STRUCTS.
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition: Split.cpp:648
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
void xaccSplitSetReconcile(Split *split, char reconciled_flag)
Set the reconcile flag.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
void xaccSplitRemovePeerSplit(Split *split, const Split *other_split)
Remove a peer split from this split&#39;s lot-split list.
Definition: Split.cpp:2121
const char * xaccSplitGetType(Split *s)
Returns the split type, which is either the string "normal", or "stock-split" for a split from a stoc...
Definition: Split.cpp:2039
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
Definition: Split.cpp:1726
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
Definition: gmock-Split.cpp:45
const char * xaccSplitGetOnlineID(const Split *split)
Returns the split&#39;s online_id.
gnc_numeric xaccSplitGetBalance(const Split *split)
Returns the running balance up to and including the indicated split.
Definition: Split.cpp:1316
int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of account.
Definition: Split.cpp:1688
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition: Split.cpp:819
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
Definition: Split.cpp:2102
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split&#39;s peer splits into split&#39;s peers.
Definition: Split.cpp:2138
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Definition: Split.cpp:2191
Split * xaccSplitLookup(const GncGUID *guid, QofBook *book)
The xaccSplitLookup() subroutine will return the split associated with the given id, or NULL if there is no such split.
Definition: Split.cpp:1091
void xaccSplitSetAmount(Split *split, gnc_numeric amount)
The xaccSplitSetAmount() method sets the amount in the account&#39;s commodity that the split should have...
Definition: gmock-Split.cpp:77
gnc_numeric xaccSplitVoidFormerValue(const Split *split)
Returns the original pre-void value of a split.
Definition: Split.cpp:2199
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of the other account.
Definition: Split.cpp:1747
void xaccSplitSetSharePriceAndAmount(Split *split, gnc_numeric price, gnc_numeric amount)
The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the numbe...
Definition: Split.cpp:1177
gnc_numeric xaccSplitGetNoclosingBalance(const Split *split)
The noclosing-balance is the currency-denominated balance of all transactions except &#39;closing&#39; transa...
Definition: Split.cpp:1322
gboolean xaccSplitIsPeerSplit(const Split *split, const Split *other_split)
Report if a split is a peer of this one.
Definition: Split.cpp:2108
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction...
Definition: Split.cpp:1655
gboolean xaccSplitIsStockSplit(Split *s)
Returns true if the split is of type stock split.
Definition: Split.cpp:2078
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
Definition: Split.cpp:1995
All type declarations for the whole Gnucash engine.
gnc_numeric xaccSplitGetBaseValue(const Split *split, const gnc_commodity *base_currency)
Depending on the base_currency, return either the value or the amount of this split: If the base_curr...
Definition: Split.cpp:1410
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
const char * xaccSplitGetCorrAccountName(const Split *sa)
document me
Definition: Split.cpp:1638
void xaccSplitSetLot(Split *split, GNCLot *lot)
Assigns the split to a specific Lot.
Definition: Split.cpp:1926
QofBook reference.
Definition: qofbook-p.hpp:46
void xaccSplitSetDateReconciledSecs(Split *split, time64 time)
Set the date on which this split was reconciled by specifying the time as time64. ...
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
Definition: Split.cpp:1859
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
void xaccSplitSetOnlineID(Split *split, const char *id)
The online_id is the OFX/HBCI "FITID" recorded on a split when it is imported.
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Definition: Split.cpp:1671
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits...
void xaccSplitSetSharePrice(Split *split, gnc_numeric price)
Definition: Split.cpp:1205
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition: gmock-Split.cpp:99
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
gnc_numeric xaccSplitGetAdjustedAmount(const Split *split)
Returns the stock-split adjusted amount of the split in the account&#39;s commodity.
Definition: Split.cpp:1340
The type used to store guids in C.
Definition: guid.h:75
Commodity handling public routines.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn&#39;t be...
Definition: Split.cpp:1920
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69