GnuCash fec5643+
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.
 
QofBook * xaccSplitGetBook (const Split *split)
 Returns the book of this split, i.e.
 
Account * xaccSplitGetAccount (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,
  b 
)    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 2095 of file Split.cpp.

2097{
2098 const GncGUID* guid;
2099
2100 g_return_if_fail (split != nullptr);
2101 g_return_if_fail (other_split != nullptr);
2102
2103 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2104 xaccTransBeginEdit (split->parent);
2105 qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
2106 gnc_time(nullptr), "peer_guid", guid_copy(guid));
2107 mark_split (split);
2108 qof_instance_set_dirty (QOF_INSTANCE (split));
2109 xaccTransCommitEdit (split->parent);
2110}
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 1723 of file Split.cpp.

1724{
1725 Account *aa, *ab;
1726 if (!sa && !sb) return 0;
1727 if (!sa) return -1;
1728 if (!sb) return 1;
1729
1730 aa = sa->acc;
1731 ab = sb->acc;
1732
1733 return g_strcmp0(xaccAccountGetCode(aa), xaccAccountGetCode(ab));
1734}
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Definition Account.cpp:3324
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 1699 of file Split.cpp.

1700{
1701 Account *aa, *ab;
1702 if (sa == sb) return 0;
1703 if (!sa) return -1;
1704 if (!sb) return 1;
1705
1706 aa = sa->acc;
1707 ab = sb->acc;
1708 if (aa == ab) return 0;
1709
1710 auto path_a = gnc_account_get_all_parents (aa);
1711 auto path_b = gnc_account_get_all_parents (ab);
1712 auto mismatch_pair = std::mismatch (path_a.rbegin(), path_a.rend(),
1713 path_b.rbegin(), path_b.rend());
1714
1715 return mismatch_pair.first == path_a.rend() ? -1
1716 : mismatch_pair.second == path_b.rend() ? 1
1717 : g_utf8_collate (xaccAccountGetName (*mismatch_pair.first),
1718 xaccAccountGetName (*mismatch_pair.second));
1719}
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3277

◆ 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 1758 of file Split.cpp.

1759{
1760 const char *ca, *cb;
1761 if (!sa && !sb) return 0;
1762 if (!sa) return -1;
1763 if (!sb) return 1;
1764
1767 return g_strcmp0(ca, cb);
1768}
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Definition Split.cpp:1682

◆ 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 1737 of file Split.cpp.

1738{
1739 char *ca, *cb;
1740 int retval;
1741 if (!sa && !sb) return 0;
1742 if (!sa) return -1;
1743 if (!sb) return 1;
1744
1745 /* doesn't matter what separator we use
1746 * as long as they are the same
1747 */
1748
1751 retval = g_strcmp0(ca, cb);
1752 g_free(ca);
1753 g_free(cb);
1754 return retval;
1755}
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction,...
Definition Split.cpp:1666

◆ xaccSplitConvertAmount()

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

Definition at line 1444 of file Split.cpp.

1445{
1446 gnc_commodity *acc_com, *to_commodity;
1447 Transaction *txn;
1448 gnc_numeric amount, value, convrate;
1449 Account * split_acc;
1450
1451 amount = xaccSplitGetAmount (split);
1452
1453 /* If this split is attached to this account, OR */
1454 split_acc = xaccSplitGetAccount (split);
1455 if (split_acc == account)
1456 return amount;
1457
1458 /* If split->account->commodity == to_commodity, return the amount */
1459 acc_com = xaccAccountGetCommodity (split_acc);
1460 to_commodity = xaccAccountGetCommodity (account);
1461 if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
1462 return amount;
1463
1464 /* Ok, this split is not for the viewed account, and the commodity
1465 * does not match. So we need to do some conversion.
1466 *
1467 * First, we can cheat. If this transaction is balanced and has
1468 * exactly two splits, then we can implicitly determine the exchange
1469 * rate and just return the 'other' split amount.
1470 */
1471 txn = xaccSplitGetParent (split);
1472 if (txn && xaccTransIsBalanced (txn))
1473 {
1474 const Split *osplit = xaccSplitGetOtherSplit (split);
1475
1476 if (osplit)
1477 {
1478 gnc_commodity* split_comm =
1480 if (!gnc_commodity_equal(to_commodity, split_comm))
1481 {
1482 gchar guidstr[GUID_ENCODING_LENGTH+1];
1483 guid_to_string_buff(xaccSplitGetGUID(osplit),guidstr);
1484 PERR("The split's (%s) amount can't be converted from %s into %s.",
1485 guidstr,
1486 gnc_commodity_get_mnemonic(split_comm),
1487 gnc_commodity_get_mnemonic(to_commodity)
1488 );
1489 return gnc_numeric_zero();
1490 }
1491 return gnc_numeric_neg (xaccSplitGetAmount (osplit));
1492 }
1493 }
1494
1495 /* ... otherwise, we need to compute the amount from the conversion
1496 * rate into _this account_. So, find the split into this account,
1497 * compute the conversion rate (based on amount/value), and then multiply
1498 * this times the split value.
1499 */
1500 value = xaccSplitGetValue (split);
1501
1502 if (gnc_numeric_zero_p (value))
1503 {
1504 return value;
1505 }
1506
1507 convrate = xaccTransGetAccountConvRate(txn, account);
1508 return gnc_numeric_mul (value, convrate,
1509 gnc_commodity_get_fraction (to_commodity),
1510 GNC_HOW_RND_ROUND_HALF_UP);
1511}
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Definition Account.cpp:3396
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:1881
#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:2000
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:2172
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition Split.cpp:1994

◆ 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:1778
void xaccSplitSetValue(Split *s, gnc_numeric amt)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Definition Split.cpp:1291
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:1254
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
Definition Split.cpp:1981
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition Split.cpp:1946
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
Definition Split.cpp:1797

◆ 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 1517 of file Split.cpp.

1518{
1519 Account *acc;
1520 Transaction *trans;
1521 GncEventData ed;
1522
1523 if (!split) return TRUE;
1524
1525 acc = split->acc;
1526 trans = split->parent;
1527 if (acc && !qof_instance_get_destroying(acc)
1529 && xaccTransGetReadOnly(trans))
1530 return FALSE;
1531
1532 xaccTransBeginEdit(trans);
1533 ed.node = split;
1534 ed.idx = xaccTransGetSplitIndex(trans, split);
1535 qof_instance_set_dirty(QOF_INSTANCE(split));
1536 qof_instance_set_destroying(split, TRUE);
1537 qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1538 xaccTransCommitEdit(trans);
1539
1540 return TRUE;
1541}
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 1351 of file Split.cpp.

1352{
1353 return s ? s->adjusted_amount : gnc_numeric_zero();
1354}

◆ 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 1327 of file Split.cpp.

1328{
1329 return s ? s->balance : gnc_numeric_zero();
1330}

◆ 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 1421 of file Split.cpp.

1422{
1423 if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
1424
1425 /* be more precise -- the value depends on the currency we want it
1426 * expressed in. */
1427 if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
1428 return xaccSplitGetValue(s);
1429 if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
1430 return xaccSplitGetAmount(s);
1431
1432 PERR ("inappropriate base currency %s "
1433 "given split currency=%s and commodity=%s\n",
1434 gnc_commodity_get_printname(base_currency),
1437 return gnc_numeric_zero();
1438}
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 1339 of file Split.cpp.

1340{
1341 return s ? s->cleared_balance : gnc_numeric_zero();
1342}

◆ xaccSplitGetCorrAccountCode()

const char * xaccSplitGetCorrAccountCode ( const Split *  sa)

document me

Definition at line 1682 of file Split.cpp.

1683{
1684 static const char *split_const = nullptr;
1685 const Split *other_split;
1686
1687 if (!get_corr_account_split(sa, &other_split))
1688 {
1689 if (!split_const)
1690 split_const = C_("Displayed account code of the other account in a multi-split transaction", "Split");
1691
1692 return split_const;
1693 }
1694 return xaccAccountGetCode(other_split->acc);
1695}

◆ 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 1666 of file Split.cpp.

1667{
1668 static const char *split_const = nullptr;
1669 const Split *other_split;
1670
1671 if (!get_corr_account_split(sa, &other_split))
1672 {
1673 if (!split_const)
1674 split_const = _("-- Split Transaction --");
1675
1676 return g_strdup(split_const);
1677 }
1678 return gnc_account_get_full_name(other_split->acc);
1679}
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:3293

◆ xaccSplitGetCorrAccountName()

const char * xaccSplitGetCorrAccountName ( const Split *  sa)

document me

Definition at line 1649 of file Split.cpp.

1650{
1651 static const char *split_const = nullptr;
1652 const Split *other_split;
1653
1654 if (!get_corr_account_split(sa, &other_split))
1655 {
1656 if (!split_const)
1657 split_const = _("-- Split Transaction --");
1658
1659 return split_const;
1660 }
1661
1662 return xaccAccountGetName(other_split->acc);
1663}

◆ xaccSplitGetDateReconciled()

time64 xaccSplitGetDateReconciled ( const Split *  split)

Retrieve the date when the Split was reconciled.

Definition at line 1870 of file Split.cpp.

1871{
1872 return split ? split->date_reconciled : 0;
1873}

◆ 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 1931 of file Split.cpp.

1932{
1933 return split ? split->lot : nullptr;
1934}

◆ 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 1333 of file Split.cpp.

1334{
1335 return s ? s->noclosing_balance : gnc_numeric_zero();
1336}

◆ 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 1345 of file Split.cpp.

1346{
1347 return s ? s->reconciled_balance : gnc_numeric_zero();
1348}

◆ 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 2006 of file Split.cpp.

2007{
2008 gnc_numeric amt, val, price;
2009 if (!split) return gnc_numeric_create(0, 1);
2010
2011
2012 /* if amount == 0, return 0
2013 * otherwise return value/amount
2014 */
2015
2016 amt = xaccSplitGetAmount(split);
2017 val = xaccSplitGetValue(split);
2018 if (gnc_numeric_zero_p(amt))
2019 return gnc_numeric_create(0, 1);
2020
2021 price = gnc_numeric_div(val, amt,
2023 GNC_HOW_RND_ROUND_HALF_UP);
2024
2025 /* During random checks we can get some very weird prices. Let's
2026 * handle some overflow and other error conditions by returning
2027 * zero. But still print an error to let us know it happened.
2028 */
2029 if (gnc_numeric_check(price))
2030 {
2031 PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
2032 G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
2033 gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
2034 return gnc_numeric_create(0, 1);
2035 }
2036
2037 return price;
2038}
#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 2050 of file Split.cpp.

2051{
2052 if (!s) return nullptr;
2053
2054 if (!s->split_type)
2055 {
2056 auto type{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(s), {"split-type"})};
2057
2058 if (!type || !g_strcmp0 (*type, split_type_normal))
2059 s->split_type = split_type_normal;
2060 else if (!g_strcmp0 (*type, split_type_stock_split))
2061 s->split_type = split_type_stock_split;
2062 else
2063 {
2064 PERR ("unexpected split-type %s, reset to normal.", *type);
2065 s->split_type = split_type_normal;
2066 }
2067 }
2068 return s->split_type;
2069}

◆ 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 1974 of file Split.cpp.

1975{
1976 auto id = xaccSplitGetOnlineID (split);
1977 return (id && *id);
1978}
const char * xaccSplitGetOnlineID(const Split *split)
Returns the split's online_id.
Definition Split.cpp:1966

◆ xaccSplitHasPeers()

gboolean xaccSplitHasPeers ( const Split *  split)

Does this split have peers?

Definition at line 2113 of file Split.cpp.

2114{
2115 return qof_instance_has_slot (QOF_INSTANCE (split), "lot-split");
2116}

◆ 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 2119 of file Split.cpp.

2120{
2121 const GncGUID* guid;
2122
2123 g_return_val_if_fail (split != nullptr, FALSE);
2124 g_return_val_if_fail (other_split != nullptr, FALSE);
2125
2126 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2127 return qof_instance_kvp_has_guid (QOF_INSTANCE (split), "lot-split",
2128 "peer_guid", guid);
2129}

◆ xaccSplitIsStockSplit()

gboolean xaccSplitIsStockSplit ( Split *  s)

Returns true if the split is of type stock split.

Definition at line 2089 of file Split.cpp.

2090{
2091 return g_strcmp0(split_type_stock_split, xaccSplitGetType(s)) == 0;
2092}
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:2050

◆ 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 2074 of file Split.cpp.

2075{
2076 xaccTransBeginEdit (s->parent);
2077
2078 s->value = gnc_numeric_zero();
2079 s->split_type = split_type_stock_split;
2080 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(s), g_strdup(split_type_stock_split),
2081 {"split-type"});
2082 SET_GAINS_VDIRTY(s);
2083 mark_split(s);
2084 qof_instance_set_dirty(QOF_INSTANCE(s));
2085 xaccTransCommitEdit(s->parent);
2086}

◆ 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 2149 of file Split.cpp.

2150{
2151 xaccTransBeginEdit (split->parent);
2152 qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
2153 QOF_INSTANCE (other_split), "lot-split");
2154 mark_split (split);
2155 qof_instance_set_dirty (QOF_INSTANCE (split));
2156 xaccTransCommitEdit (split->parent);
2157}

◆ 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 1547 of file Split.cpp.

1548{
1549 int retval;
1550 int comp;
1551 const char *da, *db;
1552 gboolean action_for_num;
1553
1554 if (sa == sb) return 0;
1555 /* nothing is always less than something */
1556 if (!sa) return -1;
1557 if (!sb) return +1;
1558
1559 /* sort in transaction order, but use split action rather than trans num
1560 * according to book option */
1562 (xaccSplitGetBook (sa));
1563 if (action_for_num)
1564 retval = xaccTransOrder_num_action (sa->parent, sa->action,
1565 sb->parent, sb->action);
1566 else
1567 retval = xaccTransOrder (sa->parent, sb->parent);
1568 if (retval) return retval;
1569
1570 /* otherwise, sort on memo strings */
1571 da = sa->memo ? sa->memo : "";
1572 db = sb->memo ? sb->memo : "";
1573 retval = g_utf8_collate (da, db);
1574 if (retval)
1575 return retval;
1576
1577 /* otherwise, sort on action strings */
1578 da = sa->action ? sa->action : "";
1579 db = sb->action ? sb->action : "";
1580 retval = g_utf8_collate (da, db);
1581 if (retval != 0)
1582 return retval;
1583
1584 /* the reconciled flag ... */
1585 if (sa->reconciled < sb->reconciled) return -1;
1586 if (sa->reconciled > sb->reconciled) return +1;
1587
1588 /* compare amounts */
1590 if (comp < 0) return -1;
1591 if (comp > 0) return +1;
1592
1594 if (comp < 0) return -1;
1595 if (comp > 0) return +1;
1596
1597 /* if dates differ, return */
1598 if (sa->date_reconciled < sb->date_reconciled)
1599 return -1;
1600 else if (sa->date_reconciled > sb->date_reconciled)
1601 return 1;
1602
1603 /* else, sort on guid - keeps sort stable. */
1604 retval = qof_instance_guid_compare(sa, sb);
1605 if (retval) return retval;
1606
1607 return 0;
1608}
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:2044

◆ xaccSplitOrderDateOnly()

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

Definition at line 1611 of file Split.cpp.

1612{
1613 Transaction *ta, *tb;
1614
1615 if (sa == sb) return 0;
1616 /* nothing is always less than something */
1617 if (!sa) return -1;
1618 if (!sb) return +1;
1619
1620 ta = sa->parent;
1621 tb = sb->parent;
1622 if ( !ta && !tb ) return 0;
1623 if ( !tb ) return -1;
1624 if ( !ta ) return +1;
1625
1626 if (ta->date_posted == tb->date_posted)
1627 return -1; // Keep the same order
1628 return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1629}

◆ 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 2132 of file Split.cpp.

2133{
2134 const GncGUID* guid;
2135
2136 g_return_if_fail (split != nullptr);
2137 g_return_if_fail (other_split != nullptr);
2138
2139 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2140 xaccTransBeginEdit (split->parent);
2141 qof_instance_kvp_remove_guid (QOF_INSTANCE (split), "lot-split",
2142 "peer_guid", guid);
2143 mark_split (split);
2144 qof_instance_set_dirty (QOF_INSTANCE (split));
2145 xaccTransCommitEdit (split->parent);
2146}

◆ 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 1797 of file Split.cpp.

1798{
1799 if (!split || !actn) return;
1800 xaccTransBeginEdit (split->parent);
1801
1802 CACHE_REPLACE(split->action, actn);
1803 qof_instance_set_dirty(QOF_INSTANCE(split));
1804 xaccTransCommitEdit(split->parent);
1805
1806}

◆ 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 1357 of file Split.cpp.

1358{
1359 if (!s) return;
1360 if (gnc_numeric_check (amt)) return;
1361
1362 s->adjusted_amount = amt;
1363}

◆ 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 1366 of file Split.cpp.

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

◆ 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 1937 of file Split.cpp.

1938{
1939 xaccTransBeginEdit (split->parent);
1940 split->lot = lot;
1941 qof_instance_set_dirty(QOF_INSTANCE(split));
1942 xaccTransCommitEdit(split->parent);
1943}

◆ 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 1216 of file Split.cpp.

1217{
1218 if (!s) return;
1219
1220 if (gnc_numeric_zero_p (price))
1221 return;
1222
1223 ENTER (" ");
1224 xaccTransBeginEdit (s->parent);
1225
1226 s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
1227 price, get_currency_denom(s),
1228 GNC_HOW_RND_ROUND_HALF_UP);
1229
1230 SET_GAINS_VDIRTY(s);
1231 mark_split (s);
1232 qof_instance_set_dirty(QOF_INSTANCE(s));
1233 xaccTransCommitEdit(s->parent);
1234 LEAVE ("");
1235}
#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 1188 of file Split.cpp.

1189{
1190 if (!s) return;
1191 ENTER (" ");
1192 xaccTransBeginEdit (s->parent);
1193
1194 s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
1195 GNC_HOW_RND_ROUND_HALF_UP);
1196 s->value = gnc_numeric_mul(s->amount, price,
1197 get_currency_denom(s), GNC_HOW_RND_ROUND_HALF_UP);
1198
1199 SET_GAINS_A_VDIRTY(s);
1200 mark_split (s);
1201 qof_instance_set_dirty(QOF_INSTANCE(s));
1202 xaccTransCommitEdit(s->parent);
1203 LEAVE ("");
1204}

◆ 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 2202 of file Split.cpp.

2203{
2204 g_return_val_if_fail(split, gnc_numeric_zero());
2205 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_amt_str})};
2206 return num ? *num : gnc_numeric_zero();
2207}

◆ 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 2210 of file Split.cpp.

2211{
2212 g_return_val_if_fail(split, gnc_numeric_zero());
2213 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_val_str})};
2214 return num ? *num : gnc_numeric_zero();
2215}