GnuCash  4.8a-176-g88ecf8dd1
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 
71 #define CREC 'c'
72 #define YREC 'y'
73 #define FREC 'f'
74 #define NREC 'n'
75 #define VREC 'v'
78 /* Convert the amount/value of the Split for viewing in the account --
79  * in particular we want to convert the Split to be in to_commodity.
80  * Returns the amount.
81  */
82 gnc_numeric xaccSplitConvertAmount (const Split *split, const Account * account);
83 
84 /*-----------------------------------------------------------------------
85  * Splits
86  *-----------------------------------------------------------------------*/
87 
93 Split * xaccMallocSplit (QofBook *book);
94 
95 /* Reinit a previously malloc'd split. Split remains in the book it
96  was already in, and the QofInstance portions also remain unchanged.
97  It's basically the data elements that are reverted to default
98  values. */
99 void xaccSplitReinit(Split * split);
100 
118 gboolean xaccSplitDestroy (Split *split);
119 
120 /*################## Added for Reg2 #################*/
128 void xaccSplitCopyOnto(const Split *from_split, Split *to_split);
129 /*################## Added for Reg2 #################*/
130 
133 QofBook * xaccSplitGetBook (const Split *split);
134 
137 Account * xaccSplitGetAccount (const Split *split);
138 void xaccSplitSetAccount (Split *s, Account *acc);
139 
141 Transaction * xaccSplitGetParent (const Split *split);
142 void xaccSplitSetParent (Split *split, Transaction *trans);
143 
146 GNCLot * xaccSplitGetLot (const Split *split);
147 
149 void xaccSplitSetLot(Split* split, GNCLot* lot);
150 
155 void xaccSplitSetMemo (Split *split, const char *memo);
156 
158 const char * xaccSplitGetMemo (const Split *split);
159 
171 void xaccSplitSetAction (Split *split, const char *action);
172 
178 const char * xaccSplitGetAction (const Split *split);
187 void xaccSplitSetReconcile (Split *split, char reconciled_flag);
189 char xaccSplitGetReconcile (const Split *split);
190 
193 void xaccSplitSetDateReconciledSecs (Split *split, time64 time);
194 
195 /*################## Added for Reg2 #################*/
197 time64 xaccSplitGetDateReconciled (const Split *split);
198 /*################## Added for Reg2 #################*/
199 
229 void xaccSplitSetAmount (Split *split, gnc_numeric amount);
230 
235 gnc_numeric xaccSplitGetAmount (const Split * split);
236 
243 void xaccSplitSetValue (Split *split, gnc_numeric value);
244 
249 gnc_numeric xaccSplitGetValue (const Split * split);
250 
256 void xaccSplitSetSharePriceAndAmount (Split *split,
257  gnc_numeric price,
258  gnc_numeric amount);
259 
263 gnc_numeric xaccSplitGetSharePrice (const Split * split);
264 
278 void xaccSplitSetBaseValue (Split *split, gnc_numeric value,
279  const gnc_commodity * base_currency);
280 
287 gnc_numeric xaccSplitGetBaseValue (const Split *split,
288  const gnc_commodity * base_currency);
289 
297 gnc_numeric xaccSplitGetBalance (const Split *split);
298 
306 gnc_numeric xaccSplitGetNoclosingBalance (const Split *split);
307 
315 gnc_numeric xaccSplitGetClearedBalance (const Split *split);
316 
324 gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
325 
349 gboolean xaccSplitEqual(const Split *sa, const Split *sb,
350  gboolean check_guids,
351  gboolean check_balances,
352  gboolean check_txn_splits);
353 
357 Split * xaccSplitLookup (const GncGUID *guid, QofBook *book);
358 #define xaccSplitLookupDirect(g,b) xaccSplitLookup(&(g),b)
359 
360 /*################## Added for Reg2 #################*/
361 /* Get a GList of unique transactions containing the given list of Splits. */
362 GList *xaccSplitListGetUniqueTransactionsReversed (const GList *splits);
363 GList *xaccSplitListGetUniqueTransactions(const GList *splits);
364 /*################## Added for Reg2 #################*/
369 void xaccSplitAddPeerSplit (Split *split, const Split *other_split,
370  const time64 timestamp);
373 gboolean xaccSplitHasPeers (const Split *split);
378 gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split);
382 void xaccSplitRemovePeerSplit (Split *split, const Split *other_split);
383 
387 void xaccSplitMergePeerSplits (Split *split, const Split *other_split);
388 
394 Split * xaccSplitGetOtherSplit (const Split *split);
395 
404 const char *xaccSplitGetType(const Split *s);
405 
408 void xaccSplitMakeStockSplit(Split *s);
409 
422 gint xaccSplitOrder (const Split *sa, const Split *sb);
423 gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb);
424 
425 
426 /*
427  * These functions compare two splits by different criteria.
428  *
429  * These functions were added because converting strings to guile
430  * for comparisons in the transaction report is terribly inefficient.
431  * More may be added here in future if it turns out that other types
432  * of comparisons also induces guile slowdowns.
433  */
434 
437 int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb);
440 int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb);
444 int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb);
448 int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb);
449 
450 
467 char * xaccSplitGetCorrAccountFullName(const Split *sa);
469 const char * xaccSplitGetCorrAccountName(const Split *sa);
471 const char * xaccSplitGetCorrAccountCode(const Split *sa);
472 
473 #ifdef DUMP_FUNCTIONS
474 void xaccSplitDump (const Split *split, const char *tag);
475 #endif
476 
487 void xaccSplitSetSharePrice (Split *split, gnc_numeric price);
488 
492 /********************************************************************\
493  * Miscellaneous utility routines.
494 \********************************************************************/
495 
496 
508 gnc_numeric xaccSplitVoidFormerAmount(const Split *split);
509 
517 gnc_numeric xaccSplitVoidFormerValue(const Split *split);
518 
530 #define SPLIT_DATE_RECONCILED "date-reconciled"
531 #define SPLIT_BALANCE "balance"
532 #define SPLIT_CLEARED_BALANCE "cleared-balance"
533 #define SPLIT_RECONCILED_BALANCE "reconciled-balance"
534 #define SPLIT_MEMO "memo"
535 #define SPLIT_ACTION "action"
536 #define SPLIT_RECONCILE "reconcile-flag"
537 #define SPLIT_AMOUNT "amount"
538 #define SPLIT_SHARE_PRICE "share-price"
539 #define SPLIT_VALUE "value"
540 #define SPLIT_TYPE "type"
541 #define SPLIT_VOIDED_AMOUNT "voided-amount"
542 #define SPLIT_VOIDED_VALUE "voided-value"
543 #define SPLIT_LOT "lot"
544 #define SPLIT_TRANS "trans"
545 #define SPLIT_ACCOUNT "account"
546 #define SPLIT_ACCOUNT_GUID "account-guid"
547 /* used for SORTING ONLY */
548 #define SPLIT_ACCT_FULLNAME "acct-fullname"
549 #define SPLIT_CORR_ACCT_NAME "corr-acct-fullname"
550 #define SPLIT_CORR_ACCT_CODE "corr-acct-code"
551 
554 #define xaccSplitGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
555 
556 #define xaccSplitReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
557 
558 #ifdef __cplusplus
559 } /* extern "C" */
560 #endif
561 
562 #endif /* XACC_SPLIT_H */
563 
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.c:1307
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
Definition: Split.c:1500
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.c:2020
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.c:1319
void xaccSplitSetAction(Split *split, const char *action)
The Action is an arbitrary user-assigned string.
Definition: Split.c:1747
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.c:2002
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
Definition: Split.c:1673
gnc_numeric xaccSplitGetReconciledBalance(const Split *split)
Returns the reconciled-balance of this split.
Definition: Split.c:1313
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition: Split.c:1470
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition: Split.c:639
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.c:2057
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
Definition: Split.c:1687
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.c:1295
int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of account.
Definition: Split.c:1652
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition: Split.c:769
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
Definition: Split.c:2038
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split&#39;s peer splits into split&#39;s peers.
Definition: Split.c:2074
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Definition: Split.c:2127
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.c: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.c:2142
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
Definition: Split.c:1728
int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of the other account.
Definition: Split.c:1708
void xaccSplitSetSharePriceAndAmount(Split *split, gnc_numeric price, gnc_numeric amount)
The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the numbe...
Definition: Split.c:1168
gnc_numeric xaccSplitGetNoclosingBalance(const Split *split)
The noclosing-balance is the currency-denominated balance of all transactions except &#39;closing&#39; transa...
Definition: Split.c:1301
gboolean xaccSplitIsPeerSplit(const Split *split, const Split *other_split)
Report if a split is a peer of this one.
Definition: Split.c:2044
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction...
Definition: Split.c:1619
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
Definition: Split.c:1927
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.c:1374
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
const char * xaccSplitGetCorrAccountName(const Split *sa)
document me
Definition: Split.c:1602
void xaccSplitSetLot(Split *split, GNCLot *lot)
Assigns the split to a specific Lot.
Definition: Split.c:1887
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.c:1820
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.c:1635
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.c:1196
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
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
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.c:1975
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.c:1881
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69