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 
174 void xaccSplitSetAction (Split *split, const char *action);
175 
181 const char * xaccSplitGetAction (const Split *split);
190 void xaccSplitSetReconcile (Split *split, char reconciled_flag);
192 char xaccSplitGetReconcile (const Split *split);
193 
196 void xaccSplitSetDateReconciledSecs (Split *split, time64 time);
197 
198 /*################## Added for Reg2 #################*/
200 time64 xaccSplitGetDateReconciled (const Split *split);
201 /*################## Added for Reg2 #################*/
202 
232 void xaccSplitSetAmount (Split *split, gnc_numeric amount);
233 
238 gnc_numeric xaccSplitGetAmount (const Split * split);
239 
246 void xaccSplitSetValue (Split *split, gnc_numeric value);
247 
252 gnc_numeric xaccSplitGetValue (const Split * split);
253 
259 void xaccSplitSetSharePriceAndAmount (Split *split,
260  gnc_numeric price,
261  gnc_numeric amount);
262 
266 gnc_numeric xaccSplitGetSharePrice (const Split * split);
267 
281 void xaccSplitSetBaseValue (Split *split, gnc_numeric value,
282  const gnc_commodity * base_currency);
283 
290 gnc_numeric xaccSplitGetBaseValue (const Split *split,
291  const gnc_commodity * base_currency);
292 
300 gnc_numeric xaccSplitGetBalance (const Split *split);
301 
309 gnc_numeric xaccSplitGetNoclosingBalance (const Split *split);
310 
318 gnc_numeric xaccSplitGetClearedBalance (const Split *split);
319 
327 gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
328 
352 gboolean xaccSplitEqual(const Split *sa, const Split *sb,
353  gboolean check_guids,
354  gboolean check_balances,
355  gboolean check_txn_splits);
356 
360 Split * xaccSplitLookup (const GncGUID *guid, QofBook *book);
361 #define xaccSplitLookupDirect(g,b) xaccSplitLookup(&(g),b)
362 
367 void xaccSplitAddPeerSplit (Split *split, const Split *other_split,
368  const time64 timestamp);
371 gboolean xaccSplitHasPeers (const Split *split);
376 gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split);
380 void xaccSplitRemovePeerSplit (Split *split, const Split *other_split);
381 
385 void xaccSplitMergePeerSplits (Split *split, const Split *other_split);
386 
392 Split * xaccSplitGetOtherSplit (const Split *split);
393 
402 const char *xaccSplitGetType(const Split *s);
403 
406 void xaccSplitMakeStockSplit(Split *s);
407 
420 gint xaccSplitOrder (const Split *sa, const Split *sb);
421 gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb);
422 
423 
424 /*
425  * These functions compare two splits by different criteria.
426  *
427  * These functions were added because converting strings to guile
428  * for comparisons in the transaction report is terribly inefficient.
429  * More may be added here in future if it turns out that other types
430  * of comparisons also induces guile slowdowns.
431  */
432 
435 int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb);
438 int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb);
442 int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb);
446 int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb);
447 
448 
465 char * xaccSplitGetCorrAccountFullName(const Split *sa);
467 const char * xaccSplitGetCorrAccountName(const Split *sa);
469 const char * xaccSplitGetCorrAccountCode(const Split *sa);
470 
471 #ifdef DUMP_FUNCTIONS
472 void xaccSplitDump (const Split *split, const char *tag);
473 #endif
474 
485 void xaccSplitSetSharePrice (Split *split, gnc_numeric price);
486 
490 /********************************************************************\
491  * Miscellaneous utility routines.
492 \********************************************************************/
493 
494 
506 gnc_numeric xaccSplitVoidFormerAmount(const Split *split);
507 
515 gnc_numeric xaccSplitVoidFormerValue(const Split *split);
516 
528 #define SPLIT_DATE_RECONCILED "date-reconciled"
529 #define SPLIT_BALANCE "balance"
530 #define SPLIT_CLEARED_BALANCE "cleared-balance"
531 #define SPLIT_RECONCILED_BALANCE "reconciled-balance"
532 #define SPLIT_MEMO "memo"
533 #define SPLIT_ACTION "action"
534 #define SPLIT_RECONCILE "reconcile-flag"
535 #define SPLIT_AMOUNT "amount"
536 #define SPLIT_SHARE_PRICE "share-price"
537 #define SPLIT_VALUE "value"
538 #define SPLIT_TYPE "type"
539 #define SPLIT_VOIDED_AMOUNT "voided-amount"
540 #define SPLIT_VOIDED_VALUE "voided-value"
541 #define SPLIT_LOT "lot"
542 #define SPLIT_TRANS "trans"
543 #define SPLIT_ACCOUNT "account"
544 #define SPLIT_ACCOUNT_GUID "account-guid"
545 /* used for SORTING ONLY */
546 #define SPLIT_ACCT_FULLNAME "acct-fullname"
547 #define SPLIT_CORR_ACCT_NAME "corr-acct-fullname"
548 #define SPLIT_CORR_ACCT_CODE "corr-acct-code"
549 
552 #define xaccSplitGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
553 
554 #ifdef __cplusplus
555 } /* extern "C" */
556 #endif
557 
558 #endif /* XACC_SPLIT_H */
559 
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:1308
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
Definition: Split.cpp:1501
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:2014
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:1320
void xaccSplitSetAction(Split *split, const char *action)
The Action is an arbitrary user-assigned string.
Definition: Split.cpp:1748
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:1997
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
Definition: Split.cpp:1674
gnc_numeric xaccSplitGetReconciledBalance(const Split *split)
Returns the reconciled-balance of this split.
Definition: Split.cpp:1314
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition: Split.cpp:1471
STRUCTS.
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition: Split.cpp:638
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:2051
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
Definition: Split.cpp:1688
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
Definition: gmock-Split.cpp:45
gnc_numeric xaccSplitGetBalance(const Split *split)
Returns the running balance up to and including the indicated split.
Definition: Split.cpp:1296
int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of account.
Definition: Split.cpp:1653
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition: Split.cpp:801
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
Definition: Split.cpp:2032
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split&#39;s peer splits into split&#39;s peers.
Definition: Split.cpp:2068
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Definition: Split.cpp:2121
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:1070
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:2136
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:1709
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:1158
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:1302
gboolean xaccSplitIsPeerSplit(const Split *split, const Split *other_split)
Report if a split is a peer of this one.
Definition: Split.cpp:2038
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction...
Definition: Split.cpp:1620
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
Definition: Split.cpp:1928
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:1375
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
const char * xaccSplitGetCorrAccountName(const Split *sa)
document me
Definition: Split.cpp:1603
void xaccSplitSetLot(Split *split, GNCLot *lot)
Assigns the split to a specific Lot.
Definition: Split.cpp:1888
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:1821
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
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Definition: Split.cpp:1636
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:1186
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
const char * xaccSplitGetType(const Split *s)
The xaccIsPeerSplit() is a convenience routine that returns TRUE (a non-zero value) if the two splits...
Definition: Split.cpp:1972
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:1882
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69