GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Macros | Functions

A good overview of transactions, splits and accounts can be found in the texinfo documentation, together with an overview of how to use this API. More...

Files

file  Split.h
 API for Transactions and Splits (journal entries)
 

Macros

#define GNC_TYPE_SPLIT   (gnc_split_get_type ())
 
#define GNC_SPLIT(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SPLIT, Split))
 
#define GNC_SPLIT_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SPLIT, SplitClass))
 
#define GNC_IS_SPLIT(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SPLIT))
 
#define GNC_IS_SPLIT_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SPLIT))
 
#define GNC_SPLIT_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SPLIT, SplitClass))
 
#define xaccSplitGetGUID(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 

Functions

GType gnc_split_get_type (void)
 
gnc_numeric xaccSplitConvertAmount (const Split *split, const Account *account)
 

Split general getters/setters

Split * xaccMallocSplit (QofBook *book)
 Constructor.
 
void xaccSplitReinit (Split *split)
 
gboolean xaccSplitDestroy (Split *split)
 Destructor.
 
void xaccSplitCopyOnto (const Split *from_split, Split *to_split)
 This is really a helper for xaccTransCopyOnto.
 
QofBookxaccSplitGetBook (const Split *split)
 Returns the book of this split, i.e.
 
AccountxaccSplitGetAccount (const Split *split)
 Returns the account of this split, which was set through xaccAccountInsertSplit().
 
void xaccSplitSetAccount (Split *s, Account *acc)
 
Transaction * xaccSplitGetParent (const Split *split)
 Returns the parent transaction of the split.
 
void xaccSplitSetParent (Split *split, Transaction *trans)
 
GNCLot * xaccSplitGetLot (const Split *split)
 Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't belong to any.
 
void xaccSplitSetLot (Split *split, GNCLot *lot)
 Assigns the split to a specific Lot.
 
void xaccSplitSetMemo (Split *split, const char *memo)
 The memo is an arbitrary string associated with a split.
 
const char * xaccSplitGetMemo (const Split *split)
 Returns the memo string.
 
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 * xaccSplitGetOnlineID (const Split *split)
 Returns the split's online_id.
 
gboolean xaccSplitHasOnlineID (const Split *split)
 Returns TRUE if the split has a non-empty online_id.
 
void xaccSplitSetAction (Split *split, const char *action)
 The Action is an arbitrary user-assigned string.
 
const char * xaccSplitGetAction (const Split *split)
 Returns the action string.
 

Split Date getters/setters

void xaccSplitSetReconcile (Split *split, char reconciled_flag)
 Set the reconcile flag.
 
char xaccSplitGetReconcile (const Split *split)
 Returns the value of the reconcile flag.
 
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.
 

Split amount getters/setters

'value' vs.

'amount' of a Split: The 'value' is the amount of the transaction balancing commodity (i.e. currency) involved, 'amount' is the amount of the account's commodity involved.

void xaccSplitSetAmount (Split *split, gnc_numeric amount)
 The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have.
 
gnc_numeric xaccSplitGetAmount (const Split *split)
 Returns the amount of the split in the account's commodity.
 
void xaccSplitSetValue (Split *split, gnc_numeric value)
 The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
 
gnc_numeric xaccSplitGetValue (const Split *split)
 Returns the value of this split in the transaction's commodity.
 
void xaccSplitSetSharePriceAndAmount (Split *split, gnc_numeric price, gnc_numeric amount)
 The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the number of shares.
 
gnc_numeric xaccSplitGetSharePrice (const Split *split)
 Returns the price of the split, that is, the value divided by the amount.
 
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_currency is the transaction's commodity, set the value.
 
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_curreny is the transaction's commodity, return the value.
 
gnc_numeric xaccSplitGetBalance (const Split *split)
 Returns the running balance up to and including the indicated split.
 
gnc_numeric xaccSplitGetNoclosingBalance (const Split *split)
 The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transactions.
 
gnc_numeric xaccSplitGetClearedBalance (const Split *split)
 The cleared-balance is the currency-denominated balance of all transactions that have been marked as cleared or reconciled.
 
gnc_numeric xaccSplitGetReconciledBalance (const Split *split)
 Returns the reconciled-balance of this split.
 
void xaccSplitSetAdjustedAmount (Split *split, gnc_numeric amount)
 Sets the stock split adjusted amount of a split.
 
gnc_numeric xaccSplitGetAdjustedAmount (const Split *split)
 Returns the stock-split adjusted amount of the split in the account's commodity.
 

Split utility functions

gboolean xaccSplitEqual (const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
 Equality.
 
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.
 
void xaccSplitAddPeerSplit (Split *split, const Split *other_split, const time64 timestamp)
 Add a peer split to this split's lot-split list.
 
gboolean xaccSplitHasPeers (const Split *split)
 Does this split have peers?
 
gboolean xaccSplitIsPeerSplit (const Split *split, const Split *other_split)
 Report if a split is a peer of this one.
 
void xaccSplitRemovePeerSplit (Split *split, const Split *other_split)
 Remove a peer split from this split's lot-split list.
 
void xaccSplitMergePeerSplits (Split *split, const Split *other_split)
 Merge the other_split's peer splits into split's peers.
 
Split * xaccSplitGetOtherSplit (const Split *split)
 The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits.
 
const char * xaccSplitGetType (Split *s)
 Returns the split type, which is either the string "normal", or "stock-split" for a split from a stock split.
 
void xaccSplitMakeStockSplit (Split *s)
 Mark a split to be of type stock split - after this, you shouldn't modify the value anymore, just the amount.
 
gboolean xaccSplitIsStockSplit (Split *s)
 Returns true if the split is of type stock split.
 
gint xaccSplitOrder (const Split *sa, const Split *sb)
 The xaccSplitOrder(sa,sb) method is useful for sorting.
 
gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
 
int xaccSplitCompareAccountFullNames (const Split *sa, const Split *sb)
 Compare two splits by full name of account.
 
int xaccSplitCompareAccountCodes (const Split *sa, const Split *sb)
 Compare two splits by code of account.
 
int xaccSplitCompareOtherAccountFullNames (const Split *sa, const Split *sb)
 Compare two splits by full name of the other account.
 
int xaccSplitCompareOtherAccountCodes (const Split *sa, const Split *sb)
 Compare two splits by code of the other account.
 
char * xaccSplitGetCorrAccountFullName (const Split *sa)
 These functions take a split, get the corresponding split on the "other side" of the transaction, and extract either the name or code of that split, reverting to returning a constant "Split" if the transaction has more than one split on the "other side".
 
const char * xaccSplitGetCorrAccountName (const Split *sa)
 document me
 
const char * xaccSplitGetCorrAccountCode (const Split *sa)
 document me
 
#define xaccSplitLookupDirect(g, b)   xaccSplitLookup(&(g),b)
 

Split deprecated functions

void xaccSplitSetSharePrice (Split *split, gnc_numeric price)
 

Split voiding

gnc_numeric xaccSplitVoidFormerAmount (const Split *split)
 Returns the original pre-void amount of a split.
 
gnc_numeric xaccSplitVoidFormerValue (const Split *split)
 Returns the original pre-void value of a split.
 

Split Reconciled field values

These define the various reconciliations states a split can be in.

If you change these be sure to change gnc-ui-util.c:gnc_get_reconciled_str() and associated functions

#define CREC   'c'
 The Split has been cleared

 
#define YREC   'y'
 The Split has been reconciled.
 
#define FREC   'f'
 frozen into accounting period
 
#define NREC   'n'
 not reconciled or cleared

 
#define VREC   'v'
 split is void

 

Split Parameter names

Note, if you want to get the equivalent of "ACCT_MATCH_ALL" you need to create a search on the following parameter list: SPLIT->SPLIT_TRANS->TRANS_SPLITLIST->SPLIT_ACCOUNT_GUID.

If you do this, you might want to use the ACCOUNT_MATCH_ALL_TYPE as the override so the gnome-search dialog displays the right type.

#define SPLIT_DATE_RECONCILED   "date-reconciled"
 
#define SPLIT_BALANCE   "balance"
 
#define SPLIT_CLEARED_BALANCE   "cleared-balance"
 
#define SPLIT_RECONCILED_BALANCE   "reconciled-balance"
 
#define SPLIT_MEMO   "memo"
 
#define SPLIT_ACTION   "action"
 
#define SPLIT_RECONCILE   "reconcile-flag"
 
#define SPLIT_AMOUNT   "amount"
 
#define SPLIT_SHARE_PRICE   "share-price"
 
#define SPLIT_VALUE   "value"
 
#define SPLIT_TYPE   "type"
 
#define SPLIT_VOIDED_AMOUNT   "voided-amount"
 
#define SPLIT_VOIDED_VALUE   "voided-value"
 
#define SPLIT_LOT   "lot"
 
#define SPLIT_TRANS   "trans"
 
#define SPLIT_ACCOUNT   "account"
 
#define SPLIT_ACCOUNT_GUID   "account-guid"
 for guid_match_all
 
#define SPLIT_ACCT_FULLNAME   "acct-fullname"
 
#define SPLIT_CORR_ACCT_NAME   "corr-acct-fullname"
 
#define SPLIT_CORR_ACCT_CODE   "corr-acct-code"
 

Detailed Description

A good overview of transactions, splits and accounts can be found in the texinfo documentation, together with an overview of how to use this API.

Splits, or "Ledger Entries" are the fundamental accounting units. Each Split consists of an amount (number of dollar bills, number of shares, etc.), the value of that amount expressed in a (possibly) different currency than the amount, a Memo, a pointer to the parent Transaction, a pointer to the debited Account, a reconciled flag and timestamp, an "Action" field, and a key-value frame which can store arbitrary data.

Transactions embody the notion of "double entry" accounting. A Transaction consists of a date, a description, an ID number, a list of one or more Splits, and a key-value frame. The transaction also specifies the currency with which all of the splits will be valued. When double-entry rules are enforced, the sum total value of the splits are zero. If there are only two splits, then the value of one must be positive, the other negative: this denotes that one account is debited, and another is credited by an equal amount. By forcing the value of the splits to always 'add up' to zero, we can guarantee that the balances of the accounts are always correctly balanced.

The engine does not enforce double-entry accounting, but provides an API to enable user-code to find unbalanced transactions and 'repair' them so that they are in balance.

Note the sum of the values of Splits in a Transaction is always computed with respect to a currency; thus splits can be balanced even when they are in different currencies, as long as they share a common currency. This feature allows currency-trading accounts to be established.

Every Split must point to its parent Transaction, and that Transaction must in turn include that Split in the Transaction's list of Splits. A Split can belong to at most one Transaction. These relationships are enforced by the engine. The engine user cannot accidentally destroy this relationship as long as they stick to using the API and never access internal structures directly.

Splits are grouped into Accounts which are also known as "Ledgers" in accounting practice. Each Account consists of a list of Splits that debit that Account. To ensure consistency, if a Split points to an Account, then the Account must point to the Split, and vice-versa. A Split can belong to at most one Account. Besides merely containing a list of Splits, the Account structure also gives the Account a name, a code number, description and notes fields, a key-value frame, a pointer to the commodity that is used for all splits in this account. The commodity can be the name of anything traded and tradable: a stock (e.g. "IBM", "McDonald's"), a currency (e.g. "USD", "GBP"), or anything added to the commodity table.

Accounts can be arranged in a hierarchical tree. The nodes of the tree are called "Account Groups". By accounting convention, the value of an Account is equal to the value of all of its Splits plus the value of all of its sub-Accounts.

@{ 

Macro Definition Documentation

◆ CREC

#define CREC   'c'

The Split has been cleared

Definition at line 73 of file Split.h.

◆ FREC

#define FREC   'f'

frozen into accounting period

Definition at line 75 of file Split.h.

◆ GNC_IS_SPLIT

#define GNC_IS_SPLIT (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SPLIT))

Definition at line 54 of file Split.h.

◆ GNC_IS_SPLIT_CLASS

#define GNC_IS_SPLIT_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SPLIT))

Definition at line 56 of file Split.h.

◆ GNC_SPLIT

#define GNC_SPLIT (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SPLIT, Split))

Definition at line 50 of file Split.h.

◆ GNC_SPLIT_CLASS

#define GNC_SPLIT_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SPLIT, SplitClass))

Definition at line 52 of file Split.h.

◆ GNC_SPLIT_GET_CLASS

#define GNC_SPLIT_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SPLIT, SplitClass))

Definition at line 58 of file Split.h.

◆ GNC_TYPE_SPLIT

#define GNC_TYPE_SPLIT   (gnc_split_get_type ())

Definition at line 49 of file Split.h.

◆ NREC

#define NREC   'n'

not reconciled or cleared

Definition at line 76 of file Split.h.

◆ SPLIT_ACCOUNT

#define SPLIT_ACCOUNT   "account"

Definition at line 570 of file Split.h.

◆ SPLIT_ACCOUNT_GUID

#define SPLIT_ACCOUNT_GUID   "account-guid"

for guid_match_all

Definition at line 571 of file Split.h.

◆ SPLIT_ACCT_FULLNAME

#define SPLIT_ACCT_FULLNAME   "acct-fullname"

Definition at line 573 of file Split.h.

◆ SPLIT_ACTION

#define SPLIT_ACTION   "action"

Definition at line 560 of file Split.h.

◆ SPLIT_AMOUNT

#define SPLIT_AMOUNT   "amount"

Definition at line 562 of file Split.h.

◆ SPLIT_BALANCE

#define SPLIT_BALANCE   "balance"

Definition at line 556 of file Split.h.

◆ SPLIT_CLEARED_BALANCE

#define SPLIT_CLEARED_BALANCE   "cleared-balance"

Definition at line 557 of file Split.h.

◆ SPLIT_CORR_ACCT_CODE

#define SPLIT_CORR_ACCT_CODE   "corr-acct-code"

Definition at line 575 of file Split.h.

◆ SPLIT_CORR_ACCT_NAME

#define SPLIT_CORR_ACCT_NAME   "corr-acct-fullname"

Definition at line 574 of file Split.h.

◆ SPLIT_DATE_RECONCILED

#define SPLIT_DATE_RECONCILED   "date-reconciled"

Definition at line 555 of file Split.h.

◆ SPLIT_LOT

#define SPLIT_LOT   "lot"

Definition at line 568 of file Split.h.

◆ SPLIT_MEMO

#define SPLIT_MEMO   "memo"

Definition at line 559 of file Split.h.

◆ SPLIT_RECONCILE

#define SPLIT_RECONCILE   "reconcile-flag"

Definition at line 561 of file Split.h.

◆ SPLIT_RECONCILED_BALANCE

#define SPLIT_RECONCILED_BALANCE   "reconciled-balance"

Definition at line 558 of file Split.h.

◆ SPLIT_SHARE_PRICE

#define SPLIT_SHARE_PRICE   "share-price"

Definition at line 563 of file Split.h.

◆ SPLIT_TRANS

#define SPLIT_TRANS   "trans"

Definition at line 569 of file Split.h.

◆ SPLIT_TYPE

#define SPLIT_TYPE   "type"

Definition at line 565 of file Split.h.

◆ SPLIT_VALUE

#define SPLIT_VALUE   "value"

Definition at line 564 of file Split.h.

◆ SPLIT_VOIDED_AMOUNT

#define SPLIT_VOIDED_AMOUNT   "voided-amount"

Definition at line 566 of file Split.h.

◆ SPLIT_VOIDED_VALUE

#define SPLIT_VOIDED_VALUE   "voided-value"

Definition at line 567 of file Split.h.

◆ VREC

#define VREC   'v'

split is void

Definition at line 77 of file Split.h.

◆ xaccSplitGetGUID

#define xaccSplitGetGUID (   X)    qof_entity_get_guid(QOF_INSTANCE(X))
Deprecated:

Definition at line 579 of file Split.h.

◆ xaccSplitLookupDirect

#define xaccSplitLookupDirect (   g,
 
)    xaccSplitLookup(&(g),b)

Definition at line 390 of file Split.h.

◆ YREC

#define YREC   'y'

The Split has been reconciled.

Definition at line 74 of file Split.h.

Function Documentation

◆ gnc_split_get_type()

GType gnc_split_get_type ( void  )

Definition at line 31 of file gmock-Split.cpp.

32{
33 return gnc_mocksplit_get_type();
34}

◆ xaccMallocSplit()

Split * xaccMallocSplit ( QofBook book)

Constructor.

Definition at line 37 of file gmock-Split.cpp.

38{
39 SCOPED_TRACE("");
40 QofMockBook* mockbook = qof_mockbook(book);
41 return mockbook ? mockbook->malloc_split() : nullptr;
42}

◆ xaccSplitAddPeerSplit()

void xaccSplitAddPeerSplit ( Split *  split,
const Split *  other_split,
const time64  timestamp 
)

Add a peer split to this split's lot-split list.

Parameters
other_splitThe split whose guid to add
timestampThe time to be recorded for the split.

Definition at line 2084 of file Split.cpp.

2086{
2087 const GncGUID* guid;
2088
2089 g_return_if_fail (split != nullptr);
2090 g_return_if_fail (other_split != nullptr);
2091
2092 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2093 xaccTransBeginEdit (split->parent);
2094 qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
2095 gnc_time(nullptr), "peer_guid", guid_copy(guid));
2096 mark_split (split);
2097 qof_instance_set_dirty (QOF_INSTANCE (split));
2098 xaccTransCommitEdit (split->parent);
2099}
time64 gnc_time(time64 *tbuf)
get the current time
Definition gnc-date.cpp:262
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
Definition guid.cpp:155
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
The type used to store guids in C.
Definition guid.h:75

◆ xaccSplitCompareAccountCodes()

int xaccSplitCompareAccountCodes ( const Split *  sa,
const Split *  sb 
)

Compare two splits by code of account.

Returns similar to strcmp.

Definition at line 1712 of file Split.cpp.

1713{
1714 Account *aa, *ab;
1715 if (!sa && !sb) return 0;
1716 if (!sa) return -1;
1717 if (!sb) return 1;
1718
1719 aa = sa->acc;
1720 ab = sb->acc;
1721
1722 return g_strcmp0(xaccAccountGetCode(aa), xaccAccountGetCode(ab));
1723}
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Definition Account.cpp:3336
STRUCTS.

◆ xaccSplitCompareAccountFullNames()

int xaccSplitCompareAccountFullNames ( const Split *  sa,
const Split *  sb 
)

Compare two splits by full name of account.

Returns similar to strcmp.

Definition at line 1688 of file Split.cpp.

1689{
1690 Account *aa, *ab;
1691 if (sa == sb) return 0;
1692 if (!sa) return -1;
1693 if (!sb) return 1;
1694
1695 aa = sa->acc;
1696 ab = sb->acc;
1697 if (aa == ab) return 0;
1698
1699 auto path_a = gnc_account_get_all_parents (aa);
1700 auto path_b = gnc_account_get_all_parents (ab);
1701 auto mismatch_pair = std::mismatch (path_a.rbegin(), path_a.rend(),
1702 path_b.rbegin(), path_b.rend());
1703
1704 return mismatch_pair.first == path_a.rend() ? -1
1705 : mismatch_pair.second == path_b.rend() ? 1
1706 : g_utf8_collate (xaccAccountGetName (*mismatch_pair.first),
1707 xaccAccountGetName (*mismatch_pair.second));
1708}
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3289

◆ xaccSplitCompareOtherAccountCodes()

int xaccSplitCompareOtherAccountCodes ( const Split *  sa,
const Split *  sb 
)

Compare two splits by code of the other account.

Returns similar to strcmp. This function attempts to find the split on the other side of a transaction and compare on it.

Definition at line 1747 of file Split.cpp.

1748{
1749 const char *ca, *cb;
1750 if (!sa && !sb) return 0;
1751 if (!sa) return -1;
1752 if (!sb) return 1;
1753
1756 return g_strcmp0(ca, cb);
1757}
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Definition Split.cpp:1671

◆ xaccSplitCompareOtherAccountFullNames()

int xaccSplitCompareOtherAccountFullNames ( const Split *  sa,
const Split *  sb 
)

Compare two splits by full name of the other account.

Returns similar to strcmp. This function attempts to find the split on the other side of a transaction and compare on it.

Definition at line 1726 of file Split.cpp.

1727{
1728 char *ca, *cb;
1729 int retval;
1730 if (!sa && !sb) return 0;
1731 if (!sa) return -1;
1732 if (!sb) return 1;
1733
1734 /* doesn't matter what separator we use
1735 * as long as they are the same
1736 */
1737
1740 retval = g_strcmp0(ca, cb);
1741 g_free(ca);
1742 g_free(cb);
1743 return retval;
1744}
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

◆ xaccSplitConvertAmount()

gnc_numeric xaccSplitConvertAmount ( const Split *  split,
const Account account 
)

Definition at line 1433 of file Split.cpp.

1434{
1435 gnc_commodity *acc_com, *to_commodity;
1436 Transaction *txn;
1437 gnc_numeric amount, value, convrate;
1438 Account * split_acc;
1439
1440 amount = xaccSplitGetAmount (split);
1441
1442 /* If this split is attached to this account, OR */
1443 split_acc = xaccSplitGetAccount (split);
1444 if (split_acc == account)
1445 return amount;
1446
1447 /* If split->account->commodity == to_commodity, return the amount */
1448 acc_com = xaccAccountGetCommodity (split_acc);
1449 to_commodity = xaccAccountGetCommodity (account);
1450 if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
1451 return amount;
1452
1453 /* Ok, this split is not for the viewed account, and the commodity
1454 * does not match. So we need to do some conversion.
1455 *
1456 * First, we can cheat. If this transaction is balanced and has
1457 * exactly two splits, then we can implicitly determine the exchange
1458 * rate and just return the 'other' split amount.
1459 */
1460 txn = xaccSplitGetParent (split);
1461 if (txn && xaccTransIsBalanced (txn))
1462 {
1463 const Split *osplit = xaccSplitGetOtherSplit (split);
1464
1465 if (osplit)
1466 {
1467 gnc_commodity* split_comm =
1469 if (!gnc_commodity_equal(to_commodity, split_comm))
1470 {
1471 gchar guidstr[GUID_ENCODING_LENGTH+1];
1472 guid_to_string_buff(xaccSplitGetGUID(osplit),guidstr);
1473 PERR("The split's (%s) amount can't be converted from %s into %s.",
1474 guidstr,
1475 gnc_commodity_get_mnemonic(split_comm),
1476 gnc_commodity_get_mnemonic(to_commodity)
1477 );
1478 return gnc_numeric_zero();
1479 }
1480 return gnc_numeric_neg (xaccSplitGetAmount (osplit));
1481 }
1482 }
1483
1484 /* ... otherwise, we need to compute the amount from the conversion
1485 * rate into _this account_. So, find the split into this account,
1486 * compute the conversion rate (based on amount/value), and then multiply
1487 * this times the split value.
1488 */
1489 value = xaccSplitGetValue (split);
1490
1491 if (gnc_numeric_zero_p (value))
1492 {
1493 return value;
1494 }
1495
1496 convrate = xaccTransGetAccountConvRate(txn, account);
1497 return gnc_numeric_mul (value, convrate,
1498 gnc_commodity_get_fraction (to_commodity),
1499 GNC_HOW_RND_ROUND_HALF_UP);
1500}
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Definition Account.cpp:3408
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gboolean xaccTransIsBalanced(const Transaction *trans)
Returns true if the transaction is balanced according to the rules currently in effect.
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition guid.h:84
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Definition guid.cpp:208
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
Definition Split.cpp:1870
#define xaccSplitGetGUID(X)
Definition Split.h:579
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition Split.cpp:1989
Account * xaccSplitGetAccount(const Split *s)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition Split.cpp:956
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits.
Definition Split.cpp:2161
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition Split.cpp:1983

◆ xaccSplitCopyOnto()

void xaccSplitCopyOnto ( const Split *  from_split,
Split *  to_split 
)

This is really a helper for xaccTransCopyOnto.

It doesn't reparent the 'to' split to from's transaction, because xaccTransCopyOnto is responsible for parenting the split to the correct transaction. Also, from's parent transaction may not even be a valid transaction, so this function may not modify anything about 'from' or from's transaction.

Definition at line 648 of file Split.cpp.

649{
650 if (!from_split || !to_split) return;
651 xaccTransBeginEdit (to_split->parent);
652
653 xaccSplitSetMemo(to_split, xaccSplitGetMemo(from_split));
654 xaccSplitSetAction(to_split, xaccSplitGetAction(from_split));
655 xaccSplitSetAmount(to_split, xaccSplitGetAmount(from_split));
656 xaccSplitSetValue(to_split, xaccSplitGetValue(from_split));
657 /* Setting the account is okay here because, even though the from
658 split might not really belong to the account it claims to,
659 setting the account won't cause any event involving from. */
660 xaccSplitSetAccount(to_split, xaccSplitGetAccount(from_split));
661 /* N.B. Don't set parent. */
662
663 qof_instance_set_dirty(QOF_INSTANCE(to_split));
664 xaccTransCommitEdit(to_split->parent);
665}
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
Definition Split.cpp:1767
void xaccSplitSetValue(Split *s, gnc_numeric amt)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Definition Split.cpp:1280
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
Definition Split.cpp:1243
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
Definition Split.cpp:1970
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition Split.cpp:1935
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
Definition Split.cpp:1786

◆ xaccSplitDestroy()

gboolean xaccSplitDestroy ( Split *  split)

Destructor.

The xaccSplitDestroy() method will update its parent account and transaction in a consistent manner, resulting in the complete unlinking of the split, and the freeing of its associated memory. The goal of this routine is to perform the removal and destruction of the split in an atomic fashion, with no chance of accidentally leaving the accounting structure out-of-balance or otherwise inconsistent.

It begins and commits an edit on the transaction, so if after the split is removed the transaction has no more splits and if is not open it too will be destroyed, as it will if the outer edits are committed without adding transactions.

Returns
TRUE upon successful deletion of the split. FALSE when the parenting Transaction is a read-only one.

Definition at line 1506 of file Split.cpp.

1507{
1508 Account *acc;
1509 Transaction *trans;
1510 GncEventData ed;
1511
1512 if (!split) return TRUE;
1513
1514 acc = split->acc;
1515 trans = split->parent;
1516 if (acc && !qof_instance_get_destroying(acc)
1518 && xaccTransGetReadOnly(trans))
1519 return FALSE;
1520
1521 xaccTransBeginEdit(trans);
1522 ed.node = split;
1523 ed.idx = xaccTransGetSplitIndex(trans, split);
1524 qof_instance_set_dirty(QOF_INSTANCE(split));
1525 qof_instance_set_destroying(split, TRUE);
1526 qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1527 xaccTransCommitEdit(trans);
1528
1529 return TRUE;
1530}
int xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Inverse of xaccTransGetSplit()
const char * xaccTransGetReadOnly(Transaction *trans)
Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text...
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.

◆ xaccSplitEqual()

gboolean xaccSplitEqual ( const Split *  sa,
const Split *  sb,
gboolean  check_guids,
gboolean  check_balances,
gboolean  check_txn_splits 
)

Equality.

Parameters
saFirst split to compare
sbSecond split to compare
check_guidsIf TRUE, try a guid_equal() on the GUIDs of both splits if their pointers are not equal in the first place.
check_balancesIf TRUE, compare balances between the two splits. Balances are recalculated whenever a split is added or removed from an account, so YMMV on whether this should be set.
check_txn_splitsIf the pointers are not equal, but everything else so far is equal (including memo, amount, value, kvp), then, when comparing the parenting transactions with xaccTransEqual(), set its argument check_splits to be TRUE.

Definition at line 819 of file Split.cpp.

823{
824 gboolean same_book;
825
826 if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
827
828 if (!sa || !sb)
829 {
830 PINFO ("one is nullptr");
831 return FALSE;
832 }
833
834 if (sa == sb) return TRUE;
835
836 same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
837
838 if (check_guids)
839 {
840 if (qof_instance_guid_compare(sa, sb) != 0)
841 {
842 PINFO ("GUIDs differ");
843 return FALSE;
844 }
845 }
846
847 /* If the same book, since these strings are cached we can just use pointer equality */
848 if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
849 {
850 PINFO ("memos differ: (%p)%s vs (%p)%s",
851 sa->memo, sa->memo, sb->memo, sb->memo);
852 return FALSE;
853 }
854
855 if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
856 {
857 PINFO ("actions differ: %s vs %s", sa->action, sb->action);
858 return FALSE;
859 }
860
861 if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
862 {
863 char *frame_a;
864 char *frame_b;
865
866 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
867 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
868
869 PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
870
871 g_free (frame_a);
872 g_free (frame_b);
873
874 return FALSE;
875 }
876
877 if (sa->reconciled != sb->reconciled)
878 {
879 PINFO ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
880 return FALSE;
881 }
882
883 if (sa->date_reconciled != sb->date_reconciled)
884 {
885 PINFO ("reconciled date differs");
886 return FALSE;
887 }
888
890 {
891 char *str_a;
892 char *str_b;
893
896
897 PINFO ("amounts differ: %s vs %s", str_a, str_b);
898
899 g_free (str_a);
900 g_free (str_b);
901
902 return FALSE;
903 }
904
906 {
907 char *str_a;
908 char *str_b;
909
912
913 PINFO ("values differ: %s vs %s", str_a, str_b);
914
915 g_free (str_a);
916 g_free (str_b);
917
918 return FALSE;
919 }
920
921 if (check_balances)
922 {
923 if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
924 return FALSE;
925 if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
926 sb->cleared_balance))
927 return FALSE;
928 if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
929 sb->reconciled_balance))
930 return FALSE;
931 if (!xaccSplitEqualCheckBal ("noclosing ", sa->noclosing_balance,
932 sb->noclosing_balance))
933 return FALSE;
934 if (!xaccSplitEqualCheckBal ("adjusted ", sa->adjusted_amount,
935 sb->adjusted_amount))
936 return FALSE;
937 }
938
939 if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
940 check_balances, FALSE))
941 {
942 PINFO ("transactions differ");
943 return FALSE;
944 }
945
946 return TRUE;
947}
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
Equality.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.

◆ xaccSplitGetAccount()

Account * xaccSplitGetAccount ( const Split *  split)

Returns the account of this split, which was set through xaccAccountInsertSplit().

Definition at line 53 of file gmock-Split.cpp.

54{
55 SCOPED_TRACE("");
56 auto mocksplit = gnc_mocksplit(split);
57 return mocksplit ? mocksplit->get_account() : nullptr;
58}

◆ xaccSplitGetAction()

const char * xaccSplitGetAction ( const Split *  split)

Returns the action string.

Rather than use this function directly, see 'gnc_get_num_action' and 'gnc_get_action_num'in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically

Definition at line 151 of file gmock-Split.cpp.

152{
153 SCOPED_TRACE("");
154 auto mocksplit = gnc_mocksplit(split);
155 return mocksplit ? mocksplit->get_action() : "";
156}

◆ xaccSplitGetAdjustedAmount()

gnc_numeric xaccSplitGetAdjustedAmount ( const Split *  split)

Returns the stock-split adjusted amount of the split in the account's commodity.

Definition at line 1340 of file Split.cpp.

1341{
1342 return s ? s->adjusted_amount : gnc_numeric_zero();
1343}

◆ xaccSplitGetAmount()

gnc_numeric xaccSplitGetAmount ( const Split *  split)

Returns the amount of the split in the account's commodity.

Note that for cap-gains splits, this is slaved to the transaction that is causing the gains to occur.

Definition at line 69 of file gmock-Split.cpp.

70{
71 SCOPED_TRACE("");
72 auto mocksplit = gnc_mocksplit(split);
73 return mocksplit ? mocksplit->get_amount() : gnc_numeric_zero();
74}

◆ xaccSplitGetBalance()

gnc_numeric xaccSplitGetBalance ( const Split *  split)

Returns the running balance up to and including the indicated split.

The balance is the currency-denominated balance. For accounts with non-unit share prices, it is correctly adjusted for share prices.

Returns the running balance up to & including the indicated split.

Definition at line 1316 of file Split.cpp.

1317{
1318 return s ? s->balance : gnc_numeric_zero();
1319}

◆ xaccSplitGetBaseValue()

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_curreny is the transaction's commodity, return the value.

If it is the account's commodity, return the amount. If it is neither print a warning message and return gnc_numeric_zero().

Definition at line 1410 of file Split.cpp.

1411{
1412 if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
1413
1414 /* be more precise -- the value depends on the currency we want it
1415 * expressed in. */
1416 if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
1417 return xaccSplitGetValue(s);
1418 if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
1419 return xaccSplitGetAmount(s);
1420
1421 PERR ("inappropriate base currency %s "
1422 "given split currency=%s and commodity=%s\n",
1423 gnc_commodity_get_printname(base_currency),
1426 return gnc_numeric_zero();
1427}
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.

◆ xaccSplitGetBook()

QofBook * xaccSplitGetBook ( const Split *  split)

Returns the book of this split, i.e.

the entity where this split is stored.

Definition at line 45 of file gmock-Split.cpp.

46{
47 SCOPED_TRACE("");
48 auto mocksplit = gnc_mocksplit(split);
49 return mocksplit ? mocksplit->get_book() : nullptr;
50}

◆ xaccSplitGetClearedBalance()

gnc_numeric xaccSplitGetClearedBalance ( const Split *  split)

The cleared-balance is the currency-denominated balance of all transactions that have been marked as cleared or reconciled.

It is correctly adjusted for price fluctuations.

Returns the running balance up to & including the indicated split.

Definition at line 1328 of file Split.cpp.

1329{
1330 return s ? s->cleared_balance : gnc_numeric_zero();
1331}

◆ xaccSplitGetCorrAccountCode()

const char * xaccSplitGetCorrAccountCode ( const Split *  sa)

document me

Definition at line 1671 of file Split.cpp.

1672{
1673 static const char *split_const = nullptr;
1674 const Split *other_split;
1675
1676 if (!get_corr_account_split(sa, &other_split))
1677 {
1678 if (!split_const)
1679 split_const = C_("Displayed account code of the other account in a multi-split transaction", "Split");
1680
1681 return split_const;
1682 }
1683 return xaccAccountGetCode(other_split->acc);
1684}

◆ xaccSplitGetCorrAccountFullName()

char * xaccSplitGetCorrAccountFullName ( const Split *  sa)

These functions take a split, get the corresponding split on the "other side" of the transaction, and extract either the name or code of that split, reverting to returning a constant "Split" if the transaction has more than one split on the "other side".

These were added for the transaction report, and is in C because the code was already written in C for the above functions and duplication is silly.

Note that this will only return a real value in case of a two-split transaction as that is the only situation in which a reliable value can be returned. In other situations "-- Split Transaction --" will be returned as Account Name or "Split" for Account Code.

Definition at line 1655 of file Split.cpp.

1656{
1657 static const char *split_const = nullptr;
1658 const Split *other_split;
1659
1660 if (!get_corr_account_split(sa, &other_split))
1661 {
1662 if (!split_const)
1663 split_const = _("-- Split Transaction --");
1664
1665 return g_strdup(split_const);
1666 }
1667 return gnc_account_get_full_name(other_split->acc);
1668}
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
Definition Account.cpp:3305

◆ xaccSplitGetCorrAccountName()

const char * xaccSplitGetCorrAccountName ( const Split *  sa)

document me

Definition at line 1638 of file Split.cpp.

1639{
1640 static const char *split_const = nullptr;
1641 const Split *other_split;
1642
1643 if (!get_corr_account_split(sa, &other_split))
1644 {
1645 if (!split_const)
1646 split_const = _("-- Split Transaction --");
1647
1648 return split_const;
1649 }
1650
1651 return xaccAccountGetName(other_split->acc);
1652}

◆ xaccSplitGetDateReconciled()

time64 xaccSplitGetDateReconciled ( const Split *  split)

Retrieve the date when the Split was reconciled.

Definition at line 1859 of file Split.cpp.

1860{
1861 return split ? split->date_reconciled : 0;
1862}

◆ xaccSplitGetLot()

GNCLot * xaccSplitGetLot ( const Split *  split)

Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't belong to any.

Definition at line 1920 of file Split.cpp.

1921{
1922 return split ? split->lot : nullptr;
1923}

◆ xaccSplitGetMemo()

const char * xaccSplitGetMemo ( const Split *  split)

Returns the memo string.

Definition at line 99 of file gmock-Split.cpp.

100{
101 SCOPED_TRACE("");
102 auto mocksplit = gnc_mocksplit(split);
103 return mocksplit ? mocksplit->get_memo() : "";
104}

◆ xaccSplitGetNoclosingBalance()

gnc_numeric xaccSplitGetNoclosingBalance ( const Split *  split)

The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transactions.

It is correctly adjusted for price fluctuations.

Returns the running balance up to & including the indicated split.

Definition at line 1322 of file Split.cpp.

1323{
1324 return s ? s->noclosing_balance : gnc_numeric_zero();
1325}

◆ xaccSplitGetOnlineID()

const char * xaccSplitGetOnlineID ( const Split *  split)

Returns the split's online_id.

The returned string is owned by the split and must NOT be freed; it is valid until the online_id is changed or the split is destroyed. Returns NULL if no online_id is set.

Definition at line 114 of file gmock-Split.cpp.

115{
116 SCOPED_TRACE("");
117 auto mocksplit = gnc_mocksplit(split);
118 return mocksplit ? mocksplit->get_online_id() : nullptr;
119}

◆ xaccSplitGetOtherSplit()

Split * xaccSplitGetOtherSplit ( const Split *  split)

The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits.

If there are more than two splits, it returns NULL.

Definition at line 159 of file gmock-Split.cpp.

160{
161 SCOPED_TRACE("");
162 auto mocksplit = gnc_mocksplit(split);
163 return mocksplit ? mocksplit->get_other_split() : nullptr;
164}

◆ xaccSplitGetParent()

Transaction * xaccSplitGetParent ( const Split *  split)

Returns the parent transaction of the split.

Definition at line 167 of file gmock-Split.cpp.

168{
169 SCOPED_TRACE("");
170 auto mocksplit = gnc_mocksplit(split);
171 return mocksplit ? mocksplit->get_parent() : nullptr;
172}

◆ xaccSplitGetReconcile()

char xaccSplitGetReconcile ( const Split *  split)

Returns the value of the reconcile flag.

Definition at line 129 of file gmock-Split.cpp.

130{
131 SCOPED_TRACE("");
132 auto mocksplit = gnc_mocksplit(split);
133 return mocksplit ? mocksplit->get_reconcile() : VREC;
134}
#define VREC
split is void
Definition Split.h:77

◆ xaccSplitGetReconciledBalance()

gnc_numeric xaccSplitGetReconciledBalance ( const Split *  split)

Returns the reconciled-balance of this split.

The reconciled-balance is the currency-denominated balance of all transactions that have been marked as reconciled.

Returns the running balance up to & including the indicated split.

Definition at line 1334 of file Split.cpp.

1335{
1336 return s ? s->reconciled_balance : gnc_numeric_zero();
1337}

◆ xaccSplitGetSharePrice()

gnc_numeric xaccSplitGetSharePrice ( const Split *  split)

Returns the price of the split, that is, the value divided by the amount.

If the amount is zero, returns a gnc_numeric of value one.

Definition at line 1995 of file Split.cpp.

1996{
1997 gnc_numeric amt, val, price;
1998 if (!split) return gnc_numeric_create(0, 1);
1999
2000
2001 /* if amount == 0, return 0
2002 * otherwise return value/amount
2003 */
2004
2005 amt = xaccSplitGetAmount(split);
2006 val = xaccSplitGetValue(split);
2007 if (gnc_numeric_zero_p(amt))
2008 return gnc_numeric_create(0, 1);
2009
2010 price = gnc_numeric_div(val, amt,
2012 GNC_HOW_RND_ROUND_HALF_UP);
2013
2014 /* During random checks we can get some very weird prices. Let's
2015 * handle some overflow and other error conditions by returning
2016 * zero. But still print an error to let us know it happened.
2017 */
2018 if (gnc_numeric_check(price))
2019 {
2020 PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
2021 G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
2022 gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
2023 return gnc_numeric_create(0, 1);
2024 }
2025
2026 return price;
2027}
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ xaccSplitGetType()

const char * xaccSplitGetType ( Split *  s)

Returns the split type, which is either the string "normal", or "stock-split" for a split from a stock split.


Definition at line 2039 of file Split.cpp.

2040{
2041 if (!s) return nullptr;
2042
2043 if (!s->split_type)
2044 {
2045 auto type{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(s), {"split-type"})};
2046
2047 if (!type || !g_strcmp0 (*type, split_type_normal))
2048 s->split_type = split_type_normal;
2049 else if (!g_strcmp0 (*type, split_type_stock_split))
2050 s->split_type = split_type_stock_split;
2051 else
2052 {
2053 PERR ("unexpected split-type %s, reset to normal.", *type);
2054 s->split_type = split_type_normal;
2055 }
2056 }
2057 return s->split_type;
2058}

◆ xaccSplitGetValue()

gnc_numeric xaccSplitGetValue ( const Split *  split)

Returns the value of this split in the transaction's commodity.

Note that for cap-gains splits, this is slaved to the transaction that is causing the gains to occur.

Definition at line 84 of file gmock-Split.cpp.

85{
86 SCOPED_TRACE("");
87 auto mocksplit = gnc_mocksplit(split);
88 return mocksplit ? mocksplit->get_value() : gnc_numeric_zero();
89}

◆ xaccSplitHasOnlineID()

gboolean xaccSplitHasOnlineID ( const Split *  split)

Returns TRUE if the split has a non-empty online_id.

Definition at line 1963 of file Split.cpp.

1964{
1965 auto id = xaccSplitGetOnlineID (split);
1966 return (id && *id);
1967}
const char * xaccSplitGetOnlineID(const Split *split)
Returns the split's online_id.
Definition Split.cpp:1955

◆ xaccSplitHasPeers()

gboolean xaccSplitHasPeers ( const Split *  split)

Does this split have peers?

Definition at line 2102 of file Split.cpp.

2103{
2104 return qof_instance_has_slot (QOF_INSTANCE (split), "lot-split");
2105}

◆ xaccSplitIsPeerSplit()

gboolean xaccSplitIsPeerSplit ( const Split *  split,
const Split *  other_split 
)

Report if a split is a peer of this one.

Parameters
other_splitThe split to test for being a peer of this one.
Returns
: True if other_split is registered as a peer of this one.

Definition at line 2108 of file Split.cpp.

2109{
2110 const GncGUID* guid;
2111
2112 g_return_val_if_fail (split != nullptr, FALSE);
2113 g_return_val_if_fail (other_split != nullptr, FALSE);
2114
2115 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2116 return qof_instance_kvp_has_guid (QOF_INSTANCE (split), "lot-split",
2117 "peer_guid", guid);
2118}

◆ xaccSplitIsStockSplit()

gboolean xaccSplitIsStockSplit ( Split *  s)

Returns true if the split is of type stock split.

Definition at line 2078 of file Split.cpp.

2079{
2080 return g_strcmp0(split_type_stock_split, xaccSplitGetType(s)) == 0;
2081}
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

◆ xaccSplitLookup()

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 at line 1091 of file Split.cpp.

1092{
1093 QofCollection *col;
1094 if (!guid || !book) return nullptr;
1095 col = qof_book_get_collection (book, GNC_ID_SPLIT);
1096 return (Split *) qof_collection_lookup_entity (col, guid);
1097}
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition qofid.cpp:209

◆ xaccSplitMakeStockSplit()

void xaccSplitMakeStockSplit ( Split *  s)

Mark a split to be of type stock split - after this, you shouldn't modify the value anymore, just the amount.

Definition at line 2063 of file Split.cpp.

2064{
2065 xaccTransBeginEdit (s->parent);
2066
2067 s->value = gnc_numeric_zero();
2068 s->split_type = split_type_stock_split;
2069 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(s), g_strdup(split_type_stock_split),
2070 {"split-type"});
2071 SET_GAINS_VDIRTY(s);
2072 mark_split(s);
2073 qof_instance_set_dirty(QOF_INSTANCE(s));
2074 xaccTransCommitEdit(s->parent);
2075}

◆ xaccSplitMergePeerSplits()

void xaccSplitMergePeerSplits ( Split *  split,
const Split *  other_split 
)

Merge the other_split's peer splits into split's peers.

Parameters
other_splitThe split donating the peer splits.

Definition at line 2138 of file Split.cpp.

2139{
2140 xaccTransBeginEdit (split->parent);
2141 qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
2142 QOF_INSTANCE (other_split), "lot-split");
2143 mark_split (split);
2144 qof_instance_set_dirty (QOF_INSTANCE (split));
2145 xaccTransCommitEdit (split->parent);
2146}

◆ xaccSplitOrder()

gint xaccSplitOrder ( const Split *  sa,
const Split *  sb 
)

The xaccSplitOrder(sa,sb) method is useful for sorting.

if sa and sb have different transactions, return their xaccTransOrder return a negative value if split sa has a smaller currency-value than sb, return a positive value if split sa has a larger currency-value than sb, return a negative value if split sa has a smaller share-price than sb, return a positive value if split sa has a larger share-price than sb, then compares memo and action using the strcmp() c-library routine, returning what strcmp would return. Then it compares the reconciled flags, then the reconciled dates, Finally, it returns zero if all of the above match.

Definition at line 1536 of file Split.cpp.

1537{
1538 int retval;
1539 int comp;
1540 const char *da, *db;
1541 gboolean action_for_num;
1542
1543 if (sa == sb) return 0;
1544 /* nothing is always less than something */
1545 if (!sa) return -1;
1546 if (!sb) return +1;
1547
1548 /* sort in transaction order, but use split action rather than trans num
1549 * according to book option */
1551 (xaccSplitGetBook (sa));
1552 if (action_for_num)
1553 retval = xaccTransOrder_num_action (sa->parent, sa->action,
1554 sb->parent, sb->action);
1555 else
1556 retval = xaccTransOrder (sa->parent, sb->parent);
1557 if (retval) return retval;
1558
1559 /* otherwise, sort on memo strings */
1560 da = sa->memo ? sa->memo : "";
1561 db = sb->memo ? sb->memo : "";
1562 retval = g_utf8_collate (da, db);
1563 if (retval)
1564 return retval;
1565
1566 /* otherwise, sort on action strings */
1567 da = sa->action ? sa->action : "";
1568 db = sb->action ? sb->action : "";
1569 retval = g_utf8_collate (da, db);
1570 if (retval != 0)
1571 return retval;
1572
1573 /* the reconciled flag ... */
1574 if (sa->reconciled < sb->reconciled) return -1;
1575 if (sa->reconciled > sb->reconciled) return +1;
1576
1577 /* compare amounts */
1579 if (comp < 0) return -1;
1580 if (comp > 0) return +1;
1581
1583 if (comp < 0) return -1;
1584 if (comp > 0) return +1;
1585
1586 /* if dates differ, return */
1587 if (sa->date_reconciled < sb->date_reconciled)
1588 return -1;
1589 else if (sa->date_reconciled > sb->date_reconciled)
1590 return 1;
1591
1592 /* else, sort on guid - keeps sort stable. */
1593 retval = qof_instance_guid_compare(sa, sb);
1594 if (retval) return retval;
1595
1596 return 0;
1597}
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction nu...
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
The xaccTransOrder(ta,tb) method is useful for sorting.
int xaccTransOrder_num_action(const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
The xaccTransOrder_num_action(ta,actna,tb,actnb) method is useful for sorting.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
Definition Split.cpp:2033

◆ xaccSplitOrderDateOnly()

gint xaccSplitOrderDateOnly ( const Split *  sa,
const Split *  sb 
)

Definition at line 1600 of file Split.cpp.

1601{
1602 Transaction *ta, *tb;
1603
1604 if (sa == sb) return 0;
1605 /* nothing is always less than something */
1606 if (!sa) return -1;
1607 if (!sb) return +1;
1608
1609 ta = sa->parent;
1610 tb = sb->parent;
1611 if ( !ta && !tb ) return 0;
1612 if ( !tb ) return -1;
1613 if ( !ta ) return +1;
1614
1615 if (ta->date_posted == tb->date_posted)
1616 return -1; // Keep the same order
1617 return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1618}

◆ xaccSplitReinit()

void xaccSplitReinit ( Split *  split)

Definition at line 505 of file Split.cpp.

506{
507 /* fill in some sane defaults */
508 split->acc = nullptr;
509 split->orig_acc = nullptr;
510 split->parent = nullptr;
511 split->lot = nullptr;
512
513 CACHE_REPLACE(split->action, "");
514 CACHE_REPLACE(split->memo, "");
515 split->reconciled = NREC;
516 split->amount = gnc_numeric_zero();
517 split->value = gnc_numeric_zero();
518
519 split->date_reconciled = 0;
520
521 split->balance = gnc_numeric_zero();
522 split->cleared_balance = gnc_numeric_zero();
523 split->reconciled_balance = gnc_numeric_zero();
524 split->noclosing_balance = gnc_numeric_zero();
525
526 split->adjusted_amount = gnc_numeric_zero();
527 split->split_type = nullptr;
528
529 qof_instance_set_idata(split, 0);
530
531 split->gains = GAINS_STATUS_UNKNOWN;
532 split->gains_split = nullptr;
533}
#define NREC
not reconciled or cleared
Definition Split.h:76

◆ xaccSplitRemovePeerSplit()

void xaccSplitRemovePeerSplit ( Split *  split,
const Split *  other_split 
)

Remove a peer split from this split's lot-split list.

Parameters
other_splitThe split whose guid to remove

Definition at line 2121 of file Split.cpp.

2122{
2123 const GncGUID* guid;
2124
2125 g_return_if_fail (split != nullptr);
2126 g_return_if_fail (other_split != nullptr);
2127
2128 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2129 xaccTransBeginEdit (split->parent);
2130 qof_instance_kvp_remove_guid (QOF_INSTANCE (split), "lot-split",
2131 "peer_guid", guid);
2132 mark_split (split);
2133 qof_instance_set_dirty (QOF_INSTANCE (split));
2134 xaccTransCommitEdit (split->parent);
2135}

◆ xaccSplitSetAccount()

void xaccSplitSetAccount ( Split *  s,
Account acc 
)

Definition at line 61 of file gmock-Split.cpp.

62{
63 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
64 ASSERT_TRUE(GNC_IS_ACCOUNT(acc));
65 gnc_mocksplit(split)->set_account(acc);
66}

◆ xaccSplitSetAction()

void xaccSplitSetAction ( Split *  split,
const char *  action 
)

The Action is an arbitrary user-assigned string.

The action field is an arbitrary user-assigned value. It is meant to be a very short (one to ten character) string that signifies the "type" of this split, such as e.g. Buy, Sell, Div, Withdraw, Deposit, ATM, Check, etc. The idea is that this field can be used to create custom reports or graphs of data. Note that the business features auto-fill this value, but doesn't depend on it. Rather than use this function directly, see 'gnc_set_num_action' in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically

Definition at line 1786 of file Split.cpp.

1787{
1788 if (!split || !actn) return;
1789 xaccTransBeginEdit (split->parent);
1790
1791 CACHE_REPLACE(split->action, actn);
1792 qof_instance_set_dirty(QOF_INSTANCE(split));
1793 xaccTransCommitEdit(split->parent);
1794
1795}

◆ xaccSplitSetAdjustedAmount()

void xaccSplitSetAdjustedAmount ( Split *  split,
gnc_numeric  amount 
)

Sets the stock split adjusted amount of a split.


Note
The adjusted amount will be reset when the account is rebalanced.

Definition at line 1346 of file Split.cpp.

1347{
1348 if (!s) return;
1349 if (gnc_numeric_check (amt)) return;
1350
1351 s->adjusted_amount = amt;
1352}

◆ xaccSplitSetAmount()

void xaccSplitSetAmount ( Split *  split,
gnc_numeric  amount 
)

The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have.

The following four setter functions set the prices and amounts. All of the routines always maintain balance: that is, invoking any of them will cause other splits in the transaction to be modified so that the net value of the transaction is zero.

IMPORTANT: The split should be parented by an account before any of these routines are invoked! This is because the actual setting of amounts/values requires SCU settings from the account. If these are not available, then amounts/values will be set to -1/0, which is an invalid value. I believe this order dependency is a bug, but I'm too lazy to find, fix & test at the moment ...

Note
If you use this on a newly created transaction, make sure that the 'value' is also set so that it doesn't remain zero.

Definition at line 77 of file gmock-Split.cpp.

78{
79 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
80 gnc_mocksplit(split)->set_amount(amt);
81}

◆ xaccSplitSetBaseValue()

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_currency is the transaction's commodity, set the value.

If it is the account's commodity, set the amount. If both, set both.

Note
WATCH OUT: When using this function and the transaction's and account's commodities are different, the amount or the value will be left as zero. This might screw up the multi-currency handling code in the register. So please think twice whether you need this function – using xaccSplitSetValue() together with xaccSplitSetAmount() is definitely the better and safer solution!

Definition at line 1355 of file Split.cpp.

1357{
1358 const gnc_commodity *currency;
1359 const gnc_commodity *commodity;
1360
1361 if (!s) return;
1362 xaccTransBeginEdit (s->parent);
1363
1364 if (!s->acc)
1365 {
1366 PERR ("split must have a parent account");
1367 return;
1368 }
1369
1370 currency = xaccTransGetCurrency (s->parent);
1371 commodity = xaccAccountGetCommodity (s->acc);
1372
1373 /* If the base_currency is the transaction's commodity ('currency'),
1374 * set the value. If it's the account commodity, set the
1375 * amount. If both, set both. */
1376 if (gnc_commodity_equiv(currency, base_currency))
1377 {
1378 if (gnc_commodity_equiv(commodity, base_currency))
1379 {
1380 s->amount = gnc_numeric_convert(value,
1381 get_commodity_denom(s),
1382 GNC_HOW_RND_ROUND_HALF_UP);
1383 }
1384 s->value = gnc_numeric_convert(value,
1385 get_currency_denom(s),
1386 GNC_HOW_RND_ROUND_HALF_UP);
1387 }
1388 else if (gnc_commodity_equiv(commodity, base_currency))
1389 {
1390 s->amount = gnc_numeric_convert(value, get_commodity_denom(s),
1391 GNC_HOW_RND_ROUND_HALF_UP);
1392 }
1393 else
1394 {
1395 PERR ("inappropriate base currency %s "
1396 "given split currency=%s and commodity=%s\n",
1397 gnc_commodity_get_printname(base_currency),
1399 gnc_commodity_get_printname(commodity));
1400 return;
1401 }
1402
1403 SET_GAINS_A_VDIRTY(s);
1404 mark_split (s);
1405 qof_instance_set_dirty(QOF_INSTANCE(s));
1406 xaccTransCommitEdit(s->parent);
1407}

◆ xaccSplitSetDateReconciledSecs()

void xaccSplitSetDateReconciledSecs ( Split *  split,
time64  time 
)

Set the date on which this split was reconciled by specifying the time as time64.

Definition at line 144 of file gmock-Split.cpp.

145{
146 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
147 gnc_mocksplit(split)->set_date_reconciled_secs(secs);
148}

◆ xaccSplitSetLot()

void xaccSplitSetLot ( Split *  split,
GNCLot *  lot 
)

Assigns the split to a specific Lot.

Definition at line 1926 of file Split.cpp.

1927{
1928 xaccTransBeginEdit (split->parent);
1929 split->lot = lot;
1930 qof_instance_set_dirty(QOF_INSTANCE(split));
1931 xaccTransCommitEdit(split->parent);
1932}

◆ xaccSplitSetMemo()

void xaccSplitSetMemo ( Split *  split,
const char *  memo 
)

The memo is an arbitrary string associated with a split.

It is intended to hold a short (zero to forty character) string that is displayed by the GUI along with this split. Users typically type in free form text from the GUI.

Definition at line 107 of file gmock-Split.cpp.

108{
109 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
110 gnc_mocksplit(split)->set_memo(memo);
111}

◆ xaccSplitSetOnlineID()

void xaccSplitSetOnlineID ( Split *  split,
const char *  id 
)

The online_id is the OFX/HBCI "FITID" recorded on a split when it is imported.

It is used to recognise the split on re-import so that overlapping or re-downloaded statements don't create duplicates. This is the same value (engine KVP slot "online_id") that the desktop OFX/HBCI importer reads and writes.

The setter only changes engine data: call it inside the parent transaction's edit (xaccTransBeginEdit()/xaccTransCommitEdit()), and a session save persists it. Passing NULL or "" clears the online_id.

Definition at line 122 of file gmock-Split.cpp.

123{
124 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
125 gnc_mocksplit(split)->set_online_id(id);
126}

◆ xaccSplitSetParent()

void xaccSplitSetParent ( Split *  split,
Transaction *  trans 
)

Definition at line 175 of file gmock-Split.cpp.

176{
177 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
178 ASSERT_TRUE(GNC_IS_TRANSACTION(trans));
179 gnc_mocksplit(split)->set_parent(trans);
180}

◆ xaccSplitSetReconcile()

void xaccSplitSetReconcile ( Split *  split,
char  reconciled_flag 
)

Set the reconcile flag.

The Reconcile flag is a single char, whose values are typically are 'n', 'y', 'c'. In Transaction.h, macros are defined for typical values (e.g. CREC, YREC).

Definition at line 137 of file gmock-Split.cpp.

138{
139 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
140 gnc_mocksplit(split)->set_reconcile(recn);
141}

◆ xaccSplitSetSharePrice()

void xaccSplitSetSharePrice ( Split *  split,
gnc_numeric  price 
)
Deprecated:
The xaccSplitSetSharePrice() method sets the price of the split. DEPRECATED - set the value and amount instead.

Definition at line 1205 of file Split.cpp.

1206{
1207 if (!s) return;
1208
1209 if (gnc_numeric_zero_p (price))
1210 return;
1211
1212 ENTER (" ");
1213 xaccTransBeginEdit (s->parent);
1214
1215 s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
1216 price, get_currency_denom(s),
1217 GNC_HOW_RND_ROUND_HALF_UP);
1218
1219 SET_GAINS_VDIRTY(s);
1220 mark_split (s);
1221 qof_instance_set_dirty(QOF_INSTANCE(s));
1222 xaccTransCommitEdit(s->parent);
1223 LEAVE ("");
1224}
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

◆ xaccSplitSetSharePriceAndAmount()

void xaccSplitSetSharePriceAndAmount ( Split *  split,
gnc_numeric  price,
gnc_numeric  amount 
)

The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the number of shares.

This is a utility routine that is equivalent to a xaccSplitSetSharePrice() followed by and xaccSplitSetAmount(), except that it incurs the processing overhead of balancing only once, instead of twice.

Definition at line 1177 of file Split.cpp.

1178{
1179 if (!s) return;
1180 ENTER (" ");
1181 xaccTransBeginEdit (s->parent);
1182
1183 s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
1184 GNC_HOW_RND_ROUND_HALF_UP);
1185 s->value = gnc_numeric_mul(s->amount, price,
1186 get_currency_denom(s), GNC_HOW_RND_ROUND_HALF_UP);
1187
1188 SET_GAINS_A_VDIRTY(s);
1189 mark_split (s);
1190 qof_instance_set_dirty(QOF_INSTANCE(s));
1191 xaccTransCommitEdit(s->parent);
1192 LEAVE ("");
1193}

◆ xaccSplitSetValue()

void xaccSplitSetValue ( Split *  split,
gnc_numeric  value 
)

The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.

Note
If you use this on a newly created transaction, make sure that the 'amount' is also set so that it doesn't remain zero.

Definition at line 92 of file gmock-Split.cpp.

93{
94 ASSERT_TRUE(GNC_IS_MOCKSPLIT(split));
95 gnc_mocksplit(split)->set_value(val);
96}

◆ xaccSplitVoidFormerAmount()

gnc_numeric xaccSplitVoidFormerAmount ( const Split *  split)

Returns the original pre-void amount of a split.

Parameters
splitThe split in question.
Returns
A gnc_numeric containing the original value of this split. Returns a gnc_numeric of zero upon error.

Definition at line 2191 of file Split.cpp.

2192{
2193 g_return_val_if_fail(split, gnc_numeric_zero());
2194 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_amt_str})};
2195 return num ? *num : gnc_numeric_zero();
2196}

◆ xaccSplitVoidFormerValue()

gnc_numeric xaccSplitVoidFormerValue ( const Split *  split)

Returns the original pre-void value of a split.

Parameters
splitThe split in question.
Returns
A gnc_numeric containing the original amount of this split. Returns a gnc_numeric of zero upon error.

Definition at line 2199 of file Split.cpp.

2200{
2201 g_return_val_if_fail(split, gnc_numeric_zero());
2202 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_val_str})};
2203 return num ? *num : gnc_numeric_zero();
2204}