GnuCash de0bfde+
Loading...
Searching...
No Matches

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)
#define GNC_SPLIT_CLASS(k)
#define GNC_IS_SPLIT(o)
#define GNC_IS_SPLIT_CLASS(k)
#define GNC_SPLIT_GET_CLASS(o)
#define xaccSplitGetGUID(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)

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.

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)
Value:
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SPLIT))

Definition at line 54 of file Split.h.

54#define GNC_IS_SPLIT(o) \
55 (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_SPLIT))

◆ GNC_IS_SPLIT_CLASS

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

Definition at line 56 of file Split.h.

56#define GNC_IS_SPLIT_CLASS(k) \
57 (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_SPLIT))

◆ GNC_SPLIT

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

Definition at line 50 of file Split.h.

50#define GNC_SPLIT(o) \
51 (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_SPLIT, Split))

◆ GNC_SPLIT_CLASS

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

Definition at line 52 of file Split.h.

52#define GNC_SPLIT_CLASS(k) \
53 (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_SPLIT, SplitClass))

◆ GNC_SPLIT_GET_CLASS

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

Definition at line 58 of file Split.h.

58#define GNC_SPLIT_GET_CLASS(o) \
59 (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_SPLIT, SplitClass))

◆ 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)
Value:
qof_entity_get_guid(QOF_INSTANCE(X))
const GncGUID * qof_entity_get_guid(gconstpointer ent)
Deprecated

Definition at line 579 of file Split.h.

◆ xaccSplitLookupDirect

#define xaccSplitLookupDirect ( g,
b )
Value:
Split * xaccSplitLookup(const GncGUID *guid, QofBook *book)
The xaccSplitLookup() subroutine will return the split associated with the given id,...
Definition Split.cpp:1095

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

2099{
2100 const GncGUID* guid;
2101
2102 g_return_if_fail (split != nullptr);
2103 g_return_if_fail (other_split != nullptr);
2104
2105 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2106 xaccTransBeginEdit (split->parent);
2107 qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
2108 gnc_time(nullptr), "peer_guid", guid_copy(guid));
2109 mark_split (split);
2110 qof_instance_set_dirty (QOF_INSTANCE (split));
2111 xaccTransCommitEdit (split->parent);
2112}
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:3317
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:3270

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

1453{
1454 gnc_commodity *acc_com, *to_commodity;
1455 Transaction *txn;
1456 gnc_numeric amount, value, convrate;
1457 Account * split_acc;
1458
1459 amount = xaccSplitGetAmount (split);
1460
1461 /* If this split is attached to this account, OR */
1462 split_acc = xaccSplitGetAccount (split);
1463 if (split_acc == account)
1464 return amount;
1465
1466 /* If split->account->commodity == to_commodity, return the amount */
1467 acc_com = xaccAccountGetCommodity (split_acc);
1468 to_commodity = xaccAccountGetCommodity (account);
1469 if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
1470 return amount;
1471
1472 /* Ok, this split is not for the viewed account, and the commodity
1473 * does not match. So we need to do some conversion.
1474 *
1475 * First, we can cheat. If this transaction is balanced and has
1476 * exactly two splits, then we can implicitly determine the exchange
1477 * rate and just return the 'other' split amount.
1478 */
1479 txn = xaccSplitGetParent (split);
1480 if (txn && xaccTransIsBalanced (txn))
1481 {
1482 const Split *osplit = xaccSplitGetOtherSplit (split);
1483
1484 if (osplit)
1485 {
1486 gnc_commodity* split_comm =
1488 if (!gnc_commodity_equal(to_commodity, split_comm))
1489 {
1490 gchar guidstr[GUID_ENCODING_LENGTH+1];
1491 guid_to_string_buff(xaccSplitGetGUID(osplit),guidstr);
1492 PERR("The split's (%s) amount can't be converted from %s into %s.",
1493 guidstr,
1494 gnc_commodity_get_mnemonic(split_comm),
1495 gnc_commodity_get_mnemonic(to_commodity)
1496 );
1497 return gnc_numeric_zero();
1498 }
1499 return gnc_numeric_neg (xaccSplitGetAmount (osplit));
1500 }
1501 }
1502
1503 /* ... otherwise, we need to compute the amount from the conversion
1504 * rate into _this account_. So, find the split into this account,
1505 * compute the conversion rate (based on amount/value), and then multiply
1506 * this times the split value.
1507 */
1508 value = xaccSplitGetValue (split);
1509
1510 if (gnc_numeric_zero_p (value))
1511 {
1512 return value;
1513 }
1514
1515 convrate = xaccTransGetAccountConvRate(txn, account);
1516 return gnc_numeric_mul (value, convrate,
1517 gnc_commodity_get_fraction (to_commodity),
1519}
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
Definition Account.cpp:3389
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.
@ GNC_HOW_RND_ROUND_HALF_UP
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
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:2001
Account * xaccSplitGetAccount(const Split *s)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition Split.cpp:959
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits.
Definition Split.cpp:2174
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition Split.cpp:1995

◆ 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:1295
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:1258
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
Definition Split.cpp:1982
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition Split.cpp:1947
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 1525 of file Split.cpp.

1526{
1527 Account *acc;
1528 Transaction *trans;
1529 GncEventData ed;
1530
1531 if (!split) return TRUE;
1532
1533 acc = split->acc;
1534 trans = split->parent;
1535 if (acc && !qof_instance_get_destroying(acc)
1537 && xaccTransGetReadOnly(trans))
1538 return FALSE;
1539
1540 xaccTransBeginEdit(trans);
1541 ed.node = split;
1542 ed.idx = xaccTransGetSplitIndex(trans, split);
1543 qof_instance_set_dirty(QOF_INSTANCE(split));
1544 qof_instance_set_destroying(split, TRUE);
1545 qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1546 xaccTransCommitEdit(trans);
1547
1548 return TRUE;
1549}
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 822 of file Split.cpp.

826{
827 gboolean same_book;
828
829 if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
830
831 if (!sa || !sb)
832 {
833 PINFO ("one is nullptr");
834 return FALSE;
835 }
836
837 if (sa == sb) return TRUE;
838
839 same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
840
841 if (check_guids)
842 {
843 if (qof_instance_guid_compare(sa, sb) != 0)
844 {
845 PINFO ("GUIDs differ");
846 return FALSE;
847 }
848 }
849
850 /* If the same book, since these strings are cached we can just use pointer equality */
851 if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
852 {
853 PINFO ("memos differ: (%p)%s vs (%p)%s",
854 sa->memo, sa->memo, sb->memo, sb->memo);
855 return FALSE;
856 }
857
858 if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
859 {
860 PINFO ("actions differ: %s vs %s", sa->action, sb->action);
861 return FALSE;
862 }
863
864 if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
865 {
866 char *frame_a;
867 char *frame_b;
868
869 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
870 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
871
872 PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
873
874 g_free (frame_a);
875 g_free (frame_b);
876
877 return FALSE;
878 }
879
880 if (sa->reconciled != sb->reconciled)
881 {
882 PINFO ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
883 return FALSE;
884 }
885
886 if (sa->date_reconciled != sb->date_reconciled)
887 {
888 PINFO ("reconciled date differs");
889 return FALSE;
890 }
891
893 {
894 char *str_a;
895 char *str_b;
896
899
900 PINFO ("amounts differ: %s vs %s", str_a, str_b);
901
902 g_free (str_a);
903 g_free (str_b);
904
905 return FALSE;
906 }
907
909 {
910 char *str_a;
911 char *str_b;
912
915
916 PINFO ("values differ: %s vs %s", str_a, str_b);
917
918 g_free (str_a);
919 g_free (str_b);
920
921 return FALSE;
922 }
923
924 if (check_balances)
925 {
926 if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
927 return FALSE;
928 if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
929 sb->cleared_balance))
930 return FALSE;
931 if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
932 sb->reconciled_balance))
933 return FALSE;
934 if (!xaccSplitEqualCheckBal ("noclosing ", sa->noclosing_balance,
935 sb->noclosing_balance))
936 return FALSE;
937 if (!xaccSplitEqualCheckBal ("adjusted ", sa->adjusted_amount,
938 sb->adjusted_amount))
939 return FALSE;
940 }
941
942 if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
943 check_balances, FALSE))
944 {
945 PINFO ("transactions differ");
946 return FALSE;
947 }
948
949 return TRUE;
950}
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 1355 of file Split.cpp.

1356{
1357 return s ? s->adjusted_amount : gnc_numeric_zero();
1358}

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

1332{
1333 return s ? s->balance : gnc_numeric_zero();
1334}

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

1430{
1431 if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
1432
1433 /* be more precise -- the value depends on the currency we want it
1434 * expressed in. */
1435 if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
1436 return xaccSplitGetValue(s);
1437 if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
1438 return xaccSplitGetAmount(s);
1439
1440 PERR ("inappropriate base currency %s "
1441 "given split currency=%s and commodity=%s\n",
1442 gnc_commodity_get_printname(base_currency),
1445 return gnc_numeric_zero();
1446}
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 1343 of file Split.cpp.

1344{
1345 return s ? s->cleared_balance : gnc_numeric_zero();
1346}

◆ 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:3286

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

1338{
1339 return s ? s->noclosing_balance : gnc_numeric_zero();
1340}

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

1350{
1351 return s ? s->reconciled_balance : gnc_numeric_zero();
1352}

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

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

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

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

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

◆ xaccSplitHasPeers()

gboolean xaccSplitHasPeers ( const Split * split)

Does this split have peers?

Definition at line 2115 of file Split.cpp.

2116{
2117 return qof_instance_has_slot (QOF_INSTANCE (split), "lot-split");
2118}

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

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

◆ xaccSplitIsStockSplit()

gboolean xaccSplitIsStockSplit ( Split * s)

Returns true if the split is of type stock split.

Definition at line 2091 of file Split.cpp.

2092{
2093 return g_strcmp0(split_type_stock_split, xaccSplitGetType(s)) == 0;
2094}
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:2051

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

1096{
1097 QofCollection *col;
1098 if (!guid || !book) return nullptr;
1099 col = qof_book_get_collection (book, GNC_ID_SPLIT);
1100 return (Split *) qof_collection_lookup_entity (col, guid);
1101}
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 2075 of file Split.cpp.

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

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

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

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

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

◆ xaccSplitOrderDateOnly()

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

Definition at line 1619 of file Split.cpp.

1620{
1621 if (sa == sb) return 0;
1622 /* nothing is always less than something */
1623 if (!sa) return -1;
1624 if (!sb) return +1;
1625
1626 const auto da = sa->parent ? sa->parent->date_posted : INT64_MAX;
1627 const auto db = sb->parent ? sb->parent->date_posted : INT64_MAX;
1628 return da > db ? 1 : da < db ? -1 : 0;
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 2134 of file Split.cpp.

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

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

1362{
1363 if (!s) return;
1364 if (gnc_numeric_check (amt)) return;
1365
1366 s->adjusted_amount = amt;
1367}

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

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

◆ 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 g_return_if_fail (split);
1940 xaccTransBeginEdit (split->parent);
1941 split->lot = lot;
1942 qof_instance_set_dirty(QOF_INSTANCE(split));
1943 xaccTransCommitEdit(split->parent);
1944}

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

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

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

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

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

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

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