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 
371 gboolean xaccSplitEqual(const Split *sa, const Split *sb,
372  gboolean check_guids,
373  gboolean check_balances,
374  gboolean check_txn_splits);
375 
379 Split * xaccSplitLookup (const GncGUID *guid, QofBook *book);
380 #define xaccSplitLookupDirect(g,b) xaccSplitLookup(&(g),b)
381 
386 void xaccSplitAddPeerSplit (Split *split, const Split *other_split,
387  const time64 timestamp);
390 gboolean xaccSplitHasPeers (const Split *split);
395 gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split);
399 void xaccSplitRemovePeerSplit (Split *split, const Split *other_split);
400 
404 void xaccSplitMergePeerSplits (Split *split, const Split *other_split);
405 
411 Split * xaccSplitGetOtherSplit (const Split *split);
412 
421 const char *xaccSplitGetType(const Split *s);
422 
425 void xaccSplitMakeStockSplit(Split *s);
426 
439 gint xaccSplitOrder (const Split *sa, const Split *sb);
440 gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb);
441 
442 
443 /*
444  * These functions compare two splits by different criteria.
445  *
446  * These functions were added because converting strings to guile
447  * for comparisons in the transaction report is terribly inefficient.
448  * More may be added here in future if it turns out that other types
449  * of comparisons also induces guile slowdowns.
450  */
451 
454 int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb);
457 int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb);
461 int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb);
465 int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb);
466 
467 
484 char * xaccSplitGetCorrAccountFullName(const Split *sa);
486 const char * xaccSplitGetCorrAccountName(const Split *sa);
488 const char * xaccSplitGetCorrAccountCode(const Split *sa);
489 
490 #ifdef DUMP_FUNCTIONS
491 void xaccSplitDump (const Split *split, const char *tag);
492 #endif
493 
504 void xaccSplitSetSharePrice (Split *split, gnc_numeric price);
505 
509 /********************************************************************\
510  * Miscellaneous utility routines.
511 \********************************************************************/
512 
513 
525 gnc_numeric xaccSplitVoidFormerAmount(const Split *split);
526 
534 gnc_numeric xaccSplitVoidFormerValue(const Split *split);
535 
547 #define SPLIT_DATE_RECONCILED "date-reconciled"
548 #define SPLIT_BALANCE "balance"
549 #define SPLIT_CLEARED_BALANCE "cleared-balance"
550 #define SPLIT_RECONCILED_BALANCE "reconciled-balance"
551 #define SPLIT_MEMO "memo"
552 #define SPLIT_ACTION "action"
553 #define SPLIT_RECONCILE "reconcile-flag"
554 #define SPLIT_AMOUNT "amount"
555 #define SPLIT_SHARE_PRICE "share-price"
556 #define SPLIT_VALUE "value"
557 #define SPLIT_TYPE "type"
558 #define SPLIT_VOIDED_AMOUNT "voided-amount"
559 #define SPLIT_VOIDED_VALUE "voided-value"
560 #define SPLIT_LOT "lot"
561 #define SPLIT_TRANS "trans"
562 #define SPLIT_ACCOUNT "account"
563 #define SPLIT_ACCOUNT_GUID "account-guid"
564 /* used for SORTING ONLY */
565 #define SPLIT_ACCT_FULLNAME "acct-fullname"
566 #define SPLIT_CORR_ACCT_NAME "corr-acct-fullname"
567 #define SPLIT_CORR_ACCT_CODE "corr-acct-code"
568 
571 #define xaccSplitGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
572 
573 #ifdef __cplusplus
574 } /* extern "C" */
575 #endif
576 
577 #endif /* XACC_SPLIT_H */
578 
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:2037
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:1751
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:2023
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
Definition: Split.cpp:1677
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
gboolean xaccSplitHasOnlineID(const Split *split)
Returns TRUE if the split has a non-empty online_id.
Definition: Split.cpp:1928
STRUCTS.
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition: Split.cpp:640
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:2074
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
Definition: Split.cpp:1691
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: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:803
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
Definition: Split.cpp:2055
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split&#39;s peer splits into split&#39;s peers.
Definition: Split.cpp:2091
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Definition: Split.cpp:2144
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:1072
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:2152
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:1712
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:2061
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:1960
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:1891
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:1824
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: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:2004
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:1885
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69