GnuCash  5.6-150-g038405b370+
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)
 
file  Transaction.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))
 
#define GNC_TYPE_TRANSACTION   (gnc_transaction_get_type ())
 
#define GNC_TRANSACTION(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TRANSACTION, Transaction))
 
#define GNC_TRANSACTION_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TRANSACTION, TransactionClass))
 
#define GNC_IS_TRANSACTION(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TRANSACTION))
 
#define GNC_IS_TRANSACTION_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TRANSACTION))
 
#define GNC_TRANSACTION_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TRANSACTION, TransactionClass))
 
#define GNC_IS_TRANS(obj)   GNC_IS_TRANSACTION(obj)
 
#define GNC_TRANS(obj)   GNC_TRANSACTION(obj)
 
#define RECONCILED_MATCH_TYPE   "reconciled-match"
 
#define xaccTransGetBook(X)   qof_instance_get_book (QOF_INSTANCE(X))
 
#define xaccTransGetGUID(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 

Functions

GType gnc_split_get_type (void)
 
gnc_numeric xaccSplitConvertAmount (const Split *split, const Account *account)
 
GType gnc_transaction_get_type (void)
 
void xaccTransRecordPrice (Transaction *trans, PriceSource source)
 The xaccTransRecordPrice() method iterates through the splits and and record the non-currency equivalent prices in the price database. More...
 

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 general getters/setters

Split * xaccMallocSplit (QofBook *book)
 Constructor. More...
 
void xaccSplitReinit (Split *split)
 
gboolean xaccSplitDestroy (Split *split)
 Destructor. More...
 
void xaccSplitCopyOnto (const Split *from_split, Split *to_split)
 This is really a helper for xaccTransCopyOnto. More...
 
QofBook * xaccSplitGetBook (const Split *split)
 Returns the book of this split, i.e. More...
 
Account * xaccSplitGetAccount (const Split *split)
 Returns the account of this split, which was set through xaccAccountInsertSplit(). More...
 
void xaccSplitSetAccount (Split *s, Account *acc)
 
Transaction * xaccSplitGetParent (const Split *split)
 Returns the parent transaction of the split. More...
 
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. More...
 
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. More...
 
const char * xaccSplitGetMemo (const Split *split)
 Returns the memo string. More...
 
void xaccSplitSetOnlineID (Split *split, const char *id)
 The online_id is the OFX/HBCI "FITID" recorded on a split when it is imported. More...
 
const char * xaccSplitGetOnlineID (const Split *split)
 Returns the split's online_id. More...
 
gboolean xaccSplitHasOnlineID (const Split *split)
 Returns TRUE if the split has a non-empty online_id. More...
 
void xaccSplitSetAction (Split *split, const char *action)
 The Action is an arbitrary user-assigned string. More...
 
const char * xaccSplitGetAction (const Split *split)
 Returns the action string. More...
 

Split Date getters/setters

void xaccSplitSetReconcile (Split *split, char reconciled_flag)
 Set the reconcile flag. More...
 
char xaccSplitGetReconcile (const Split *split)
 Returns the value of the reconcile flag. More...
 
void xaccSplitSetDateReconciledSecs (Split *split, time64 time)
 Set the date on which this split was reconciled by specifying the time as time64. More...
 
time64 xaccSplitGetDateReconciled (const Split *split)
 Retrieve the date when the Split was reconciled. More...
 

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. More...
 
gnc_numeric xaccSplitGetAmount (const Split *split)
 Returns the amount of the split in the account's commodity. More...
 
void xaccSplitSetValue (Split *split, gnc_numeric value)
 The xaccSplitSetValue() method sets the value of this split in the transaction's commodity. More...
 
gnc_numeric xaccSplitGetValue (const Split *split)
 Returns the value of this split in the transaction's commodity. More...
 
void xaccSplitSetSharePriceAndAmount (Split *split, gnc_numeric price, gnc_numeric amount)
 The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the number of shares. More...
 
gnc_numeric xaccSplitGetSharePrice (const Split *split)
 Returns the price of the split, that is, the value divided by the amount. More...
 
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. More...
 
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. More...
 
gnc_numeric xaccSplitGetBalance (const Split *split)
 Returns the running balance up to and including the indicated split. More...
 
gnc_numeric xaccSplitGetNoclosingBalance (const Split *split)
 The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transactions. More...
 
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. More...
 
gnc_numeric xaccSplitGetReconciledBalance (const Split *split)
 Returns the reconciled-balance of this split. More...
 
void xaccSplitSetAdjustedAmount (Split *split, gnc_numeric amount)
 Sets the stock split adjusted amount of a split. More...
 
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. More...
 
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. More...
 
void xaccSplitAddPeerSplit (Split *split, const Split *other_split, const time64 timestamp)
 Add a peer split to this split's lot-split list. More...
 
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. More...
 
void xaccSplitRemovePeerSplit (Split *split, const Split *other_split)
 Remove a peer split from this split's lot-split list. More...
 
void xaccSplitMergePeerSplits (Split *split, const Split *other_split)
 Merge the other_split's peer splits into split's peers. More...
 
Split * xaccSplitGetOtherSplit (const Split *split)
 The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits. More...
 
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. More...
 
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. More...
 
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. More...
 
gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
 
int xaccSplitCompareAccountFullNames (const Split *sa, const Split *sb)
 Compare two splits by full name of account. More...
 
int xaccSplitCompareAccountCodes (const Split *sa, const Split *sb)
 Compare two splits by code of account. More...
 
int xaccSplitCompareOtherAccountFullNames (const Split *sa, const Split *sb)
 Compare two splits by full name of the other account. More...
 
int xaccSplitCompareOtherAccountCodes (const Split *sa, const Split *sb)
 Compare two splits by code of the other account. More...
 
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". More...
 
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. More...
 
gnc_numeric xaccSplitVoidFormerValue (const Split *split)
 Returns the original pre-void value of a split. More...
 

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"
 

Transaction Type field values

#define TXN_TYPE_UNCACHED   '?' /** Transaction type not yet cached */
 
#define TXN_TYPE_NONE   '\0'
 No transaction type.
 
#define TXN_TYPE_INVOICE   'I'
 Transaction is an invoice.
 
#define TXN_TYPE_PAYMENT   'P'
 Transaction is a payment.
 
#define TXN_TYPE_LINK   'L'
 Transaction is a link between (invoice and payment) lots.
 

Transaction creation and editing

Transaction * xaccMallocTransaction (QofBook *book)
 
The xaccMallocTransaction() will malloc memory and initialize it. More...
 
void xaccTransDestroy (Transaction *trans)
 Destroys a transaction. More...
 
Transaction * xaccTransClone (const Transaction *t)
 
The xaccTransClone() method will create a complete copy of an existing transaction.
 
Transaction * xaccTransCloneNoKvp (const Transaction *t)
 
The xaccTransCloneNoKvp() method will create a complete copy of an existing transaction except that the KVP slots will be empty.
 
gboolean xaccTransEqual (const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
 Equality. More...
 
void xaccTransBeginEdit (Transaction *trans)
 The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of its component splits. More...
 
void xaccTransCommitEdit (Transaction *trans)
 The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are complete and should be made permanent. More...
 
void xaccTransRollbackEdit (Transaction *trans)
 The xaccTransRollbackEdit() routine rejects all edits made, and sets the transaction back to where it was before the editing started. More...
 
gboolean xaccTransIsOpen (const Transaction *trans)
 The xaccTransIsOpen() method returns TRUE if the transaction is open for editing. More...
 
Transaction * xaccTransLookup (const GncGUID *guid, QofBook *book)
 The xaccTransLookup() subroutine will return the transaction associated with the given id, or NULL if there is no such transaction. More...
 
Transaction * xaccTransCopyToClipBoard (const Transaction *from_trans)
 Copy a transaction to the 'clipboard' transaction using dupe_transaction. More...
 
void xaccTransCopyOnto (const Transaction *from_trans, Transaction *to_trans)
 Copy a transaction to another using the function below without changing any account information.
 
void xaccTransCopyFromClipBoard (const Transaction *from_trans, Transaction *to_trans, const Account *from_acc, Account *to_acc, gboolean no_date)
 This function explicitly must robustly handle some unusual input. More...
 
Split * xaccTransFindSplitByAccount (const Transaction *trans, const Account *acc)
 
void xaccTransScrubGains (Transaction *trans, Account *gain_acc)
 The xaccTransScrubGains() routine performs a number of cleanup functions on the indicated transaction, with the end-goal of setting up a consistent set of gains/losses for all the splits in the transaction. More...
 
guint gnc_book_count_transactions (QofBook *book)
 
#define xaccTransLookupDirect(g, b)   xaccTransLookup(&(g),b)
 

Transaction general getters/setters

gboolean xaccTransUseTradingAccounts (const Transaction *trans)
 Determine whether this transaction should use commodity trading accounts.
 
void xaccTransSortSplits (Transaction *trans)
 Sorts the splits in a transaction, putting the debits first, followed by the credits.
 
void xaccTransSetTxnType (Transaction *trans, char type)
 Set the Transaction Type: note the type will be saved into the Transaction kvp property as a backward compatibility measure, for previous GnuCash versions whose xaccTransGetTxnType reads from the kvp slots. More...
 
char xaccTransGetTxnType (Transaction *trans)
 Returns the Transaction Type: note this type will be derived from the transaction splits, returning TXN_TYPE_NONE, TXN_TYPE_INVOICE, TXN_TYPE_LINK, or TXN_TYPE_PAYMENT according to heuristics. More...
 
void xaccTransSetNum (Transaction *trans, const char *num)
 Sets the transaction Number (or ID) field; 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.
 
void xaccTransSetDescription (Transaction *trans, const char *desc)
 Sets the transaction Description.
 
void xaccTransSetDocLink (Transaction *trans, const char *doclink)
 Sets the transaction Document Link.
 
void xaccTransSetNotes (Transaction *trans, const char *notes)
 Sets the transaction Notes. More...
 
const char * xaccTransGetNum (const Transaction *trans)
 Gets the transaction Number (or ID) field; 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.
 
const char * xaccTransGetDescription (const Transaction *trans)
 Gets the transaction Description.
 
const char * xaccTransGetDocLink (const Transaction *trans)
 Gets the transaction Document Link.
 
const char * xaccTransGetNotes (const Transaction *trans)
 Gets the transaction Notes. More...
 
void xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
 Sets whether or not this transaction is a "closing transaction".
 
gboolean xaccTransGetIsClosingTxn (const Transaction *trans)
 Returns whether this transaction is a "closing transaction".
 
void xaccTransClearSplits (Transaction *trans)
 Remove all splits from the transaction. More...
 
Split * xaccTransGetSplit (const Transaction *trans, int i)
 Return a pointer to the indexed split in this transaction's split list. More...
 
int xaccTransGetSplitIndex (const Transaction *trans, const Split *split)
 Inverse of xaccTransGetSplit()
 
SplitList * xaccTransGetSplitList (const Transaction *trans)
 The xaccTransGetSplitList() method returns a GList of the splits in a transaction. More...
 
SplitList * xaccTransGetPaymentAcctSplitList (const Transaction *trans)
 The xaccTransGetPaymentAcctSplitList() method returns a GList of the splits in a transaction that belong to an account which is considered a valid account for business payments. More...
 
SplitList * xaccTransGetAPARAcctSplitList (const Transaction *trans, gboolean strict)
 The xaccTransGetAPARSplitList() method returns a GList of the splits in a transaction that belong to an AR or AP account. More...
 
gboolean xaccTransStillHasSplit (const Transaction *trans, const Split *s)
 
Split * xaccTransGetFirstPaymentAcctSplit (const Transaction *trans)
 The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transaction that belongs to an account which is considered a valid account for business payments. More...
 
Split * xaccTransGetFirstAPARAcctSplit (const Transaction *trans, gboolean strict)
 The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transaction that belongs to an AR or AP account. More...
 
void xaccTransSetReadOnly (Transaction *trans, const char *reason)
 Set the transaction to be ReadOnly by setting a non-NULL value as "reason". More...
 
void xaccTransClearReadOnly (Transaction *trans)
 
const char * xaccTransGetReadOnly (Transaction *trans)
 Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text. More...
 
gboolean xaccTransIsReadonlyByPostedDate (const Transaction *trans)
 Returns TRUE if this Transaction is read-only because its posted-date is older than the "auto-readonly" threshold of this book. More...
 
int xaccTransCountSplits (const Transaction *trans)
 Returns the number of splits in this transaction. More...
 
gboolean xaccTransHasReconciledSplits (const Transaction *trans)
 FIXME: document me.
 
gboolean xaccTransHasReconciledSplitsByAccount (const Transaction *trans, const Account *account)
 FIXME: document me.
 
gboolean xaccTransHasSplitsInState (const Transaction *trans, const char state)
 FIXME: document me.
 
gboolean xaccTransHasSplitsInStateByAccount (const Transaction *trans, const char state, const Account *account)
 FIXME: document me.
 
gnc_commodity * xaccTransGetCurrency (const Transaction *trans)
 Returns the valuation commodity of this transaction. More...
 
void xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr)
 Set the commodity of this transaction. More...
 
gnc_numeric xaccTransGetImbalanceValue (const Transaction *trans)
 The xaccTransGetImbalanceValue() method returns the total value of the transaction. More...
 
MonetaryList * xaccTransGetImbalance (const Transaction *trans)
 The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency for which the balance is not zero. More...
 
gboolean xaccTransIsBalanced (const Transaction *trans)
 Returns true if the transaction is balanced according to the rules currently in effect. More...
 
gnc_numeric xaccTransGetAccountValue (const Transaction *trans, const Account *account)
 The xaccTransGetAccountValue() method returns the total value applied to a particular account. More...
 
gnc_numeric xaccTransGetAccountAmount (const Transaction *trans, const Account *account)
 Same as xaccTransGetAccountValue, but uses the Account's commodity. More...
 
gnc_numeric xaccTransGetAccountConvRate (const Transaction *txn, const Account *acc)
 
gnc_numeric xaccTransGetAccountBalance (const Transaction *trans, const Account *account)
 Get the account balance for the specified account after the last split in the specified transaction. More...
 
int xaccTransOrder (const Transaction *ta, const Transaction *tb)
 The xaccTransOrder(ta,tb) method is useful for sorting. More...
 
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. More...
 
#define xaccTransAppendSplit(t, s)   xaccSplitSetParent((s), (t))
 Add a split to the transaction. More...
 

Transaction date setters/getters

void xaccTransSetDate (Transaction *trans, int day, int mon, int year)
 The xaccTransSetDate() method does the same thing as xaccTransSetDate[Posted]Secs(), but takes a convenient day-month-year format. More...
 
void xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
 This method modifies posted date of the transaction, specified by a GDate. More...
 
void xaccTransSetDatePostedSecs (Transaction *trans, time64 time)
 The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)). More...
 
void xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
 This function sets the posted date of the transaction, specified by a time64 (see ctime(3)). More...
 
void xaccTransSetDateEnteredSecs (Transaction *trans, time64 time)
 Modify the date of when the transaction was entered. More...
 
void xaccTransSetDateDue (Transaction *trans, time64 time)
 Dates and txn-type for A/R and A/P "invoice" postings.
 
time64 xaccTransGetDate (const Transaction *trans)
 Retrieve the posted date of the transaction. More...
 
time64 xaccTransRetDatePosted (const Transaction *trans)
 Retrieve the posted date of the transaction. More...
 
GDate xaccTransGetDatePostedGDate (const Transaction *trans)
 Retrieve the posted date of the transaction. More...
 
time64 xaccTransGetDateEntered (const Transaction *trans)
 Retrieve the date of when the transaction was entered. More...
 
time64 xaccTransRetDateEntered (const Transaction *trans)
 Retrieve the date of when the transaction was entered. More...
 
time64 xaccTransRetDateDue (const Transaction *trans)
 Dates and txn-type for A/R and A/P "invoice" postings.
 

Transaction voiding

void xaccTransVoid (Transaction *transaction, const char *reason)
 xaccTransVoid voids a transaction. More...
 
void xaccTransUnvoid (Transaction *transaction)
 xaccTransUnvoid restores a voided transaction to its original state. More...
 
Transaction * xaccTransReverse (Transaction *transaction)
 xaccTransReverse creates a Transaction that reverses the given transaction by inverting all the numerical values in the given transaction. More...
 
Transaction * xaccTransGetReversedBy (const Transaction *trans)
 Returns the transaction that reversed the given transaction. More...
 
gboolean xaccTransGetVoidStatus (const Transaction *transaction)
 Retrieve information on whether or not a transaction has been voided. More...
 
const char * xaccTransGetVoidReason (const Transaction *transaction)
 Returns the user supplied textual reason why a transaction was voided. More...
 
time64 xaccTransGetVoidTime (const Transaction *tr)
 Returns the time that a transaction was voided. More...
 

Transaction Parameter names

#define TRANS_KVP   "kvp"
 
#define TRANS_NUM   "num"
 
#define TRANS_DESCRIPTION   "desc"
 
#define TRANS_DATE_ENTERED   "date-entered"
 
#define TRANS_DATE_POSTED   "date-posted"
 
#define TRANS_DATE_DUE   "date-due"
 
#define TRANS_IMBALANCE   "trans-imbalance"
 
#define TRANS_IS_BALANCED   "trans-balanced?"
 
#define TRANS_IS_CLOSING   "trans-is-closing?"
 
#define TRANS_NOTES   "notes"
 
#define TRANS_DOCLINK   "doclink"
 
#define TRANS_TYPE   "type"
 
#define TRANS_VOID_STATUS   "void-p"
 
#define TRANS_VOID_REASON   "void-reason"
 
#define TRANS_VOID_TIME   "void-time"
 
#define TRANS_SPLITLIST   "split-list" /* for guid_match_all */
 

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

◆ xaccSplitGetGUID

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

Definition at line 579 of file Split.h.

◆ xaccTransAppendSplit

#define xaccTransAppendSplit (   t,
  s 
)    xaccSplitSetParent((s), (t))

Add a split to the transaction.

The xaccTransAppendSplit() method will append the indicated split to the collection of splits in this transaction.

Note
If the split is already a part of another transaction, it will be removed from that transaction first.

Definition at line 380 of file Transaction.h.

◆ xaccTransGetBook

#define xaccTransGetBook (   X)    qof_instance_get_book (QOF_INSTANCE(X))
Deprecated:

Definition at line 785 of file Transaction.h.

◆ xaccTransGetGUID

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

Definition at line 787 of file Transaction.h.

Function Documentation

◆ gnc_book_count_transactions()

guint gnc_book_count_transactions ( QofBook *  book)
Warning
XXX FIXME gnc_book_count_transactions is a utility function, probably needs to be moved to a utility file somewhere.

Definition at line 2494 of file Transaction.cpp.

2495 {
2496  guint count = 0;
2497  xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
2498  counter_thunk, (void*)&count);
2499  return count;
2500 }
int xaccAccountTreeForEachTransaction(Account *acc, TransactionCallback proc, void *data)
Traverse all of the transactions in the given account group.

◆ 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 }

◆ xaccMallocTransaction()

Transaction* xaccMallocTransaction ( QofBook *  book)


The xaccMallocTransaction() will malloc memory and initialize it.

Once created, it is usually unsafe to merely "free" this memory; the xaccTransDestroy() method should be called.

Definition at line 485 of file Transaction.cpp.

486 {
487  Transaction *trans;
488 
489  g_return_val_if_fail (book, nullptr);
490 
491  trans = GNC_TRANSACTION(g_object_new(GNC_TYPE_TRANSACTION, nullptr));
492  xaccInitTransaction (trans, book);
493  qof_event_gen (&trans->inst, QOF_EVENT_CREATE, nullptr);
494 
495  return trans;
496 }
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

◆ 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 }
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
Definition: guid.cpp:155
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...
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:262
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 }
STRUCTS.
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 
1765  ca = xaccSplitGetCorrAccountCode(sa);
1766  cb = xaccSplitGetCorrAccountCode(sb);
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

◆ 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 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 xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
Definition: Split.cpp:1797
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
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
Definition: Split.cpp:1778
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...
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
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition: Split.cpp:1947
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
Definition: Split.cpp:1982
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition: Split.cpp:1995

◆ 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)
1536  && !qof_instance_get_destroying(trans)
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 }
STRUCTS.
const char * xaccTransGetReadOnly(Transaction *trans)
Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text...
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
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...
int xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Inverse of xaccTransGetSplit()
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

◆ 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 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
Equality.
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 ...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition: Split.cpp:2001
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition: Split.cpp:1995

◆ 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 }

◆ 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 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition: Split.cpp:2001
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
Definition: Account.cpp:3389
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition: Split.cpp:1995

◆ 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 }

◆ 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

◆ 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 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
gnc_numeric gnc_numeric_div(gnc_numeric x, gnc_numeric y, gint64 denom, gint how)
Division.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition: Split.cpp:2001
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:165
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
Check for error signal in value.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
Definition: gnc-numeric.h:245
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition: Split.cpp:1995

◆ 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 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ 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&#39;s online_id.
Definition: Split.cpp:1967

◆ 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 }
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

◆ 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 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition: qofid.cpp:209
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

◆ 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 }
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...

◆ 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 }
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...

◆ 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 &#39;Num&#39; field, FALSE if it uses transaction nu...
gint 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:2045
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.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: Split.cpp:2001
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
The xaccTransOrder(ta,tb) method is useful for sorting.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: Split.cpp:1995

◆ 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 }
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
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...
The type used to store guids in C.
Definition: guid.h:75

◆ 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 }
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...

◆ 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 }
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
Check for error signal in value.

◆ 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),
1414  gnc_commodity_get_printname(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 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments &#39;...
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...
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the &#39;print&#39; name for the specified commodity.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account&#39;s commodity.
Definition: Account.cpp:3389
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:165
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.

◆ 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 }

◆ 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 }

◆ 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 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
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...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:165
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: Split.cpp:1995

◆ 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 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments &#39;...
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
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...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:165

◆ 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 }

◆ xaccTransBeginEdit()

void xaccTransBeginEdit ( Transaction *  trans)

The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of its component splits.

If this is not done, errors will result.

Definition at line 35 of file gmock-Transaction.cpp.

36 {
37  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
38  gnc_mocktransaction(trans)->begin_edit();
39 }

◆ xaccTransClearSplits()

void xaccTransClearSplits ( Transaction *  trans)

Remove all splits from the transaction.

Clears the split list of the transaction. All splits that the transaction still owns will be destroyed, and others will be unlinked.

Opens and commits an edit on the transaction, so this will destroy the transaction if it isn't already open, as will committing the outer edits if new splits are not added before hand.

Definition at line 2064 of file Transaction.cpp.

2065 {
2066  xaccTransBeginEdit(trans);
2067  /* We only own the splits that still think they belong to us. This is done
2068  in 2 steps. In the first, the splits are marked as being destroyed, but they
2069  are not destroyed yet. In the second, the destruction is committed which will
2070  do the actual destruction. If both steps are done for a split before they are
2071  done for the next split, then a split will still be on the split list after it
2072  has been freed. This can cause other parts of the code (e.g. in xaccSplitDestroy())
2073  to reference the split after it has been freed. */
2074  for (auto node = trans->splits; node; node = node->next)
2075  {
2076  auto s = GNC_SPLIT(node->data);
2077  if (s && s->parent == trans)
2078  {
2079  xaccSplitDestroy(s);
2080  }
2081  }
2082  for (auto node = trans->splits; node; node = node->next)
2083  {
2084  auto s = GNC_SPLIT(node->data);
2085  if (s && s->parent == trans)
2086  {
2087  xaccSplitCommitEdit(s);
2088  }
2089  }
2090  g_list_free (trans->splits);
2091  trans->splits = nullptr;
2092 
2093  xaccTransCommitEdit(trans);
2094 }
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition: Split.cpp:1525
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...

◆ xaccTransCommitEdit()

void xaccTransCommitEdit ( Transaction *  trans)

The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are complete and should be made permanent.

Note this routine may result in the deletion of the transaction, if the transaction is "empty" (has no splits), or of xaccTransDestroy() was called on the transaction.

Definition at line 42 of file gmock-Transaction.cpp.

43 {
44  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
45  gnc_mocktransaction(trans)->commit_edit();
46 }

◆ xaccTransCopyFromClipBoard()

void xaccTransCopyFromClipBoard ( const Transaction *  from_trans,
Transaction *  to_trans,
const Account *  from_acc,
Account *  to_acc,
gboolean  no_date 
)

This function explicitly must robustly handle some unusual input.

'from_trans' may be a duped trans (see xaccDupeTransaction), so its splits may not really belong to the accounts that they say they do.

'from_acc' need not be a valid account. It may be an already freed Account. Therefore, it must not be dereferenced at all.

Neither 'from_trans', nor 'from_acc', nor any of 'from's splits may be modified in any way.

'no_date' if TRUE will not copy the date posted.

The 'to_trans' transaction will end up with valid copies of from's splits. In addition, the copies of any of from's splits that were in from_acc (or at least claimed to be) will end up in to_acc.

Definition at line 705 of file Transaction.cpp.

707 {
708  gboolean change_accounts = FALSE;
709  GList *node;
710 
711  if (!from_trans || !to_trans)
712  return;
713 
714  change_accounts = from_acc && GNC_IS_ACCOUNT(to_acc) && from_acc != to_acc;
715  xaccTransBeginEdit(to_trans);
716 
717  xaccTransClearSplits(to_trans);
718  xaccTransSetCurrency(to_trans, xaccTransGetCurrency(from_trans));
719  xaccTransSetDescription(to_trans, xaccTransGetDescription(from_trans));
720 
721  if ((xaccTransGetNum(to_trans) == nullptr) || (g_strcmp0 (xaccTransGetNum(to_trans), "") == 0))
722  xaccTransSetNum(to_trans, xaccTransGetNum(from_trans));
723 
724  xaccTransSetNotes(to_trans, xaccTransGetNotes(from_trans));
725  xaccTransSetDocLink(to_trans, xaccTransGetDocLink (from_trans));
726  if(!no_date)
727  {
728  xaccTransSetDatePostedSecs(to_trans, xaccTransRetDatePosted (from_trans));
729  }
730 
731  /* Each new split will be parented to 'to' */
732  for (node = from_trans->splits; node; node = node->next)
733  {
734  Split *new_split = xaccMallocSplit( qof_instance_get_book(QOF_INSTANCE(from_trans)));
735  xaccSplitCopyOnto(GNC_SPLIT(node->data), new_split);
736  if (change_accounts && xaccSplitGetAccount(GNC_SPLIT(node->data)) == from_acc)
737  xaccSplitSetAccount(new_split, to_acc);
738  xaccSplitSetParent(new_split, to_trans);
739  }
740  xaccTransCommitEdit(to_trans);
741 }
void xaccTransClearSplits(Transaction *trans)
Remove all splits from the transaction.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
void xaccTransSetNotes(Transaction *trans, const char *notes)
Sets the transaction Notes.
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition: Split.cpp:648
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
void xaccTransSetNum(Transaction *trans, const char *xnum)
Sets the transaction Number (or ID) field; rather than use this function directly, see &#39;gnc_set_num_action&#39; 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.
const char * xaccTransGetNum(const Transaction *trans)
Gets the transaction Number (or ID) field; rather than use this function directly, see &#39;gnc_get_num_action&#39; and &#39;gnc_get_action_num&#39; 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.
const char * xaccTransGetDocLink(const Transaction *trans)
Gets the transaction Document Link.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
const char * xaccTransGetNotes(const Transaction *trans)
Gets the transaction Notes.
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
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...
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
void xaccTransSetDatePostedSecs(Transaction *trans, time64 secs)
The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)).
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
void xaccTransSetDocLink(Transaction *trans, const char *doclink)
Sets the transaction Document Link.

◆ xaccTransCopyToClipBoard()

Transaction* xaccTransCopyToClipBoard ( const Transaction *  from_trans)

Copy a transaction to the 'clipboard' transaction using dupe_transaction.

The 'clipboard' transaction must never be dereferenced.

Definition at line 665 of file Transaction.cpp.

666 {
667  Transaction *to_trans;
668 
669  if (!from_trans)
670  return nullptr;
671 
672  to_trans = dupe_trans(from_trans);
673  return to_trans;
674 }

◆ xaccTransCountSplits()

int xaccTransCountSplits ( const Transaction *  trans)

Returns the number of splits in this transaction.

Definition at line 2200 of file Transaction.cpp.

2201 {
2202  gint i = 0;
2203  g_return_val_if_fail (trans != nullptr, 0);
2204  FOR_EACH_SPLIT(trans, i++);
2205  return i;
2206 }

◆ xaccTransDestroy()

void xaccTransDestroy ( Transaction *  trans)

Destroys a transaction.

Each split in transaction trans is removed from its account and destroyed as well.

If the transaction has not already been opened for editing with xaccTransBeginEdit() then the changes are committed immediately. Otherwise, the caller must follow up with either xaccTransCommitEdit(), in which case the transaction and split memory will be freed, or xaccTransRollbackEdit(), in which case nothing at all is freed, and everything is put back into original order.

Parameters
transthe transaction to destroy

Definition at line 150 of file gmock-Transaction.cpp.

151 {
152  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
153  gnc_mocktransaction(trans)->destroy();
154 }

◆ xaccTransEqual()

gboolean xaccTransEqual ( const Transaction *  ta,
const Transaction *  tb,
gboolean  check_guids,
gboolean  check_splits,
gboolean  check_balances,
gboolean  assume_ordered 
)

Equality.

Parameters
taFirst transaction to compare
tbSecond transaction to compare
check_guidsIf TRUE, try a guid_equal() on the GUIDs of both transactions if their pointers are not equal in the first place. Also passed to subsidiary calls to xaccSplitEqual.
check_splitsIf TRUE, after checking the transaction data structures for equality, also check all splits attached to the transaction for equality.
check_balancesIf TRUE, when checking splits also 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.
assume_orderedIf TRUE, assume that the splits in each transaction appear in the same order. This saves some time looking up splits by GncGUID, and is required for checking duplicated transactions because all the splits have new GUIDs.

Definition at line 810 of file Transaction.cpp.

815 {
816  gboolean same_book;
817 
818  if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */
819 
820  if (!ta || !tb)
821  {
822  PINFO ("one is nullptr");
823  return FALSE;
824  }
825 
826  if (ta == tb) return TRUE;
827 
828  same_book = qof_instance_get_book(QOF_INSTANCE(ta)) == qof_instance_get_book(QOF_INSTANCE(tb));
829 
830  if (check_guids)
831  {
832  if (qof_instance_guid_compare(ta, tb) != 0)
833  {
834  PINFO ("GUIDs differ");
835  return FALSE;
836  }
837  }
838 
839  if (!gnc_commodity_equal(ta->common_currency, tb->common_currency))
840  {
841  PINFO ("commodities differ %s vs %s",
842  gnc_commodity_get_unique_name (ta->common_currency),
843  gnc_commodity_get_unique_name (tb->common_currency));
844  return FALSE;
845  }
846 
847  if (ta->date_entered != tb->date_entered)
848  {
849  char buf1[100];
850  char buf2[100];
851 
852  (void)gnc_time64_to_iso8601_buff(ta->date_entered, buf1);
853  (void)gnc_time64_to_iso8601_buff(tb->date_entered, buf2);
854  PINFO ("date entered differs: '%s' vs '%s'", buf1, buf2);
855  return FALSE;
856  }
857 
858  if (ta->date_posted != tb->date_posted)
859  {
860  char buf1[100];
861  char buf2[100];
862 
863  (void)gnc_time64_to_iso8601_buff(ta->date_posted, buf1);
864  (void)gnc_time64_to_iso8601_buff(tb->date_posted, buf2);
865  PINFO ("date posted differs: '%s' vs '%s'", buf1, buf2);
866  return FALSE;
867  }
868 
869  /* If the same book, since we use cached strings, we can just compare pointer
870  * equality for num and description
871  */
872  if ((same_book && ta->num != tb->num) || (!same_book && g_strcmp0(ta->num, tb->num) != 0))
873  {
874  PINFO ("num differs: %s vs %s", ta->num, tb->num);
875  return FALSE;
876  }
877 
878  if ((same_book && ta->description != tb->description)
879  || (!same_book && g_strcmp0(ta->description, tb->description)))
880  {
881  PINFO ("descriptions differ: %s vs %s", ta->description, tb->description);
882  return FALSE;
883  }
884 
885  if (qof_instance_compare_kvp (QOF_INSTANCE (ta), QOF_INSTANCE (tb)) != 0)
886  {
887  char *frame_a;
888  char *frame_b;
889 
890  frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (ta));
891  frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (tb));
892 
893 
894  PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
895 
896  g_free (frame_a);
897  g_free (frame_b);
898 
899  return FALSE;
900  }
901 
902  if (check_splits)
903  {
904  if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
905  {
906  PINFO ("only one has splits");
907  return FALSE;
908  }
909 
910  if (ta->splits && tb->splits)
911  {
912  GList *node_a, *node_b;
913 
914  for (node_a = ta->splits, node_b = tb->splits;
915  node_a;
916  node_a = node_a->next, node_b = node_b->next)
917  {
918  Split *split_a = GNC_SPLIT(node_a->data);
919  Split *split_b;
920 
921  /* don't presume that the splits are in the same order */
922  if (!assume_ordered)
923  node_b = g_list_find_custom (tb->splits, split_a,
924  compare_split_guids);
925 
926  if (!node_b)
927  {
928  gchar guidstr[GUID_ENCODING_LENGTH+1];
929  guid_to_string_buff (xaccSplitGetGUID (split_a),guidstr);
930 
931  PINFO ("first has split %s and second does not",guidstr);
932  return FALSE;
933  }
934 
935  split_b = GNC_SPLIT(node_b->data);
936 
937  if (!xaccSplitEqual (split_a, split_b, check_guids, check_balances,
938  FALSE))
939  {
940  char str_a[GUID_ENCODING_LENGTH + 1];
941  char str_b[GUID_ENCODING_LENGTH + 1];
942 
943  guid_to_string_buff (xaccSplitGetGUID (split_a), str_a);
944  guid_to_string_buff (xaccSplitGetGUID (split_b), str_b);
945 
946  PINFO ("splits %s and %s differ", str_a, str_b);
947  return FALSE;
948  }
949  }
950 
951  if (g_list_length (ta->splits) != g_list_length (tb->splits))
952  {
953  PINFO ("different number of splits");
954  return FALSE;
955  }
956  }
957  }
958 
959  return TRUE;
960 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
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
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition: Split.cpp:822
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition: guid.h:84
#define xaccSplitGetGUID(X)
Definition: Split.h:579
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the &#39;unique&#39; name for the specified commodity.
char * gnc_time64_to_iso8601_buff(time64 time, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
Definition: gnc-date.cpp:1213

◆ xaccTransGetAccountAmount()

gnc_numeric xaccTransGetAccountAmount ( const Transaction *  trans,
const Account *  account 
)

Same as xaccTransGetAccountValue, but uses the Account's commodity.

Definition at line 1140 of file Transaction.cpp.

1141 {
1142  gnc_numeric total = gnc_numeric_zero ();
1143  if (!trans || !acc) return total;
1144 
1145  total = gnc_numeric_convert (total, xaccAccountGetCommoditySCU (acc),
1147  FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
1148  total = gnc_numeric_add_fixed(
1149  total, xaccSplitGetAmount(s)));
1150  return total;
1151 }
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition: Account.cpp:2726
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments &#39;...
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:165
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69

◆ xaccTransGetAccountBalance()

gnc_numeric xaccTransGetAccountBalance ( const Transaction *  trans,
const Account *  account 
)

Get the account balance for the specified account after the last split in the specified transaction.

Definition at line 1214 of file Transaction.cpp.

1216 {
1217  GList *node;
1218  Split *last_split = nullptr;
1219 
1220  // Not really the appropriate error value.
1221  g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
1222 
1223  for (node = trans->splits; node; node = node->next)
1224  {
1225  Split *split = GNC_SPLIT(node->data);
1226 
1227  if (!xaccTransStillHasSplit(trans, split))
1228  continue;
1229  if (xaccSplitGetAccount(split) != account)
1230  continue;
1231 
1232  if (!last_split)
1233  {
1234  last_split = split;
1235  continue;
1236  }
1237 
1238  /* This test needs to correspond to the comparison function used when
1239  sorting the splits for computing the running balance. */
1240  if (xaccSplitOrder (last_split, split) < 0)
1241  last_split = split;
1242  }
1243 
1244  return xaccSplitGetBalance (last_split);
1245 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
Definition: Split.cpp:1555
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
Definition: Split.cpp:1331
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Create a gnc_numeric object that signals the error condition noted by error_code, rather than a numbe...
Argument is not a valid number.
Definition: gnc-numeric.h:224
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53

◆ xaccTransGetAccountValue()

gnc_numeric xaccTransGetAccountValue ( const Transaction *  trans,
const Account *  account 
)

The xaccTransGetAccountValue() method returns the total value applied to a particular account.

In some cases there may be multiple Splits in a single Transaction applied to one account (in particular when trying to balance Lots) – this function is just a convenience to view everything at once.

Definition at line 1124 of file Transaction.cpp.

1126 {
1127  gnc_numeric total = gnc_numeric_zero ();
1128  if (!trans || !acc) return total;
1129 
1130  FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
1131 {
1132  total = gnc_numeric_add (total, xaccSplitGetValue (s),
1135  });
1136  return total;
1137 }
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
Definition: gnc-numeric.h:188
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
#define GNC_DENOM_AUTO
Values that can be passed as the &#39;denom&#39; argument.
Definition: gnc-numeric.h:245

◆ xaccTransGetAPARAcctSplitList()

SplitList* xaccTransGetAPARAcctSplitList ( const Transaction *  trans,
gboolean  strict 
)

The xaccTransGetAPARSplitList() method returns a GList of the splits in a transaction that belong to an AR or AP account.

Parameters
transThe transaction
strictThis slightly modifies the test to only consider splits in an AR or AP account and the split is part of a business lot
Returns
The list of splits. This list must be freed when you are done with it.

Definition at line 2137 of file Transaction.cpp.

2138 {
2139  GList *apar_splits = nullptr;
2140  if (!trans) return nullptr;
2141 
2142  FOR_EACH_SPLIT (trans,
2143  const Account *account = xaccSplitGetAccount(s);
2144  if (account && xaccAccountIsAPARType(xaccAccountGetType(account)))
2145  {
2146 
2147  if (!strict)
2148  apar_splits = g_list_prepend (apar_splits, s);
2149  else
2150  {
2151  GncOwner owner;
2152  GNCLot *lot = xaccSplitGetLot(s);
2153  if (lot &&
2154  (gncInvoiceGetInvoiceFromLot (lot) ||
2155  gncOwnerGetOwnerFromLot (lot, &owner)))
2156  apar_splits = g_list_prepend (apar_splits, s);
2157  }
2158  }
2159  );
2160 
2161  apar_splits = g_list_reverse (apar_splits);
2162  return apar_splits;
2163 }
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
Definition: gncOwner.c:636
gboolean xaccAccountIsAPARType(GNCAccountType t)
Convenience function to check if the account is a valid business account type (meaning an Accounts Pa...
Definition: Account.cpp:4508
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Definition: gncInvoice.c:1234
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn&#39;t be...
Definition: Split.cpp:1931

◆ xaccTransGetCurrency()

gnc_commodity* xaccTransGetCurrency ( const Transaction *  trans)

Returns the valuation commodity of this transaction.

Each transaction's valuation commodity, or 'currency' is, by definition, the common currency in which all splits in the transaction can be valued. The total value of the transaction must be zero when all splits are valued in this currency.

Note
What happens if the Currency isn't set? Ans: bad things.

Definition at line 134 of file gmock-Transaction.cpp.

135 {
136  SCOPED_TRACE("");
137  auto mocktrans = gnc_mocktransaction(trans);
138  return mocktrans ? mocktrans->get_currency() : nullptr;
139 }

◆ xaccTransGetDate()

time64 xaccTransGetDate ( const Transaction *  trans)

Retrieve the posted date of the transaction.

The posted date is the date when this transaction was posted at the bank. (Although having different function names, GetDate and GetDatePosted refer to the same single date.)

Definition at line 73 of file gmock-Transaction.cpp.

74 {
75  SCOPED_TRACE("");
76  auto mocktrans = gnc_mocktransaction(trans);
77  return mocktrans ? mocktrans->get_date() : 0;
78 }

◆ xaccTransGetDateEntered()

time64 xaccTransGetDateEntered ( const Transaction *  trans)

Retrieve the date of when the transaction was entered.

The entered date is the date when the register entry was made.

Definition at line 2250 of file Transaction.cpp.

2251 {
2252  return trans ? trans->date_entered : 0;
2253 }

◆ xaccTransGetDatePostedGDate()

GDate xaccTransGetDatePostedGDate ( const Transaction *  trans)

Retrieve the posted date of the transaction.

The posted date is the date when this transaction was posted at the bank.

Definition at line 2263 of file Transaction.cpp.

2264 {
2265  GDate result;
2266  g_date_clear (&result, 1);
2267  if (trans)
2268  {
2269  /* Can we look up this value in the kvp slot? If yes, use it
2270  * from there because it doesn't suffer from time zone
2271  * shifts. */
2272  if (auto res = qof_instance_get_path_kvp<GDate> (QOF_INSTANCE(trans), {TRANS_DATE_POSTED}))
2273  result = *res;
2274  if (! g_date_valid (&result) || gdate_to_time64 (result) == INT64_MAX)
2275  {
2276  /* Well, this txn doesn't have a valid GDate saved in a slot.
2277  * time64_to_gdate() uses local time and we want UTC so we have
2278  * to write it out.
2279  */
2280  time64 time = xaccTransGetDate(trans);
2281  struct tm *stm = gnc_gmtime(&time);
2282  if (stm)
2283  {
2284  g_date_set_dmy(&result, stm->tm_mday,
2285  (GDateMonth)(stm->tm_mon + 1),
2286  stm->tm_year + 1900);
2287  free(stm);
2288  }
2289  }
2290  }
2291  return result;
2292 }
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
Definition: gnc-date.cpp:1323
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
Definition: gnc-date.cpp:178
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87

◆ xaccTransGetFirstAPARAcctSplit()

Split* xaccTransGetFirstAPARAcctSplit ( const Transaction *  trans,
gboolean  strict 
)

The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transaction that belongs to an AR or AP account.

Parameters
transThe transaction
strictThis slightly modifies the test to only consider splits in an AR or AP account and the split is part of a business lot

If there is no such split in the transaction NULL will be returned.

Definition at line 2176 of file Transaction.cpp.

2177 {
2178  FOR_EACH_SPLIT (trans,
2179  const Account *account = xaccSplitGetAccount(s);
2180  if (account && xaccAccountIsAPARType(xaccAccountGetType(account)))
2181  {
2182  GNCLot *lot;
2183  GncOwner owner;
2184 
2185  if (!strict)
2186  return s;
2187 
2188  lot = xaccSplitGetLot(s);
2189  if (lot &&
2190  (gncInvoiceGetInvoiceFromLot (lot) ||
2191  gncOwnerGetOwnerFromLot (lot, &owner)))
2192  return s;
2193  }
2194  );
2195 
2196  return nullptr;
2197 }
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
Definition: gncOwner.c:636
gboolean xaccAccountIsAPARType(GNCAccountType t)
Convenience function to check if the account is a valid business account type (meaning an Accounts Pa...
Definition: Account.cpp:4508
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Definition: gncInvoice.c:1234
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn&#39;t be...
Definition: Split.cpp:1931

◆ xaccTransGetFirstPaymentAcctSplit()

Split* xaccTransGetFirstPaymentAcctSplit ( const Transaction *  trans)

The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transaction that belongs to an account which is considered a valid account for business payments.

Parameters
transThe transaction

If there is no such split in the transaction NULL will be returned.

Definition at line 2165 of file Transaction.cpp.

2166 {
2167  FOR_EACH_SPLIT (trans,
2168  const Account *account = xaccSplitGetAccount(s);
2169  if (account && gncBusinessIsPaymentAcctType(xaccAccountGetType(account)))
2170  return s;
2171  );
2172 
2173  return nullptr;
2174 }
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
gboolean gncBusinessIsPaymentAcctType(GNCAccountType type)
Returns whether the given account type is a valid type to use in business payments.
Definition: gncBusiness.c:92
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53

◆ xaccTransGetImbalance()

MonetaryList* xaccTransGetImbalance ( const Transaction *  trans)

The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency for which the balance is not zero.

If the use of currency accounts is disabled, then this will be only the common currency for the transaction and xaccTransGetImbalance becomes equivalent to xaccTransGetImbalanceValue. Otherwise it will return a list containing the imbalance in each currency.

Definition at line 1006 of file Transaction.cpp.

1007 {
1008  /* imbal_value is used if either (1) the transaction has a non currency
1009  split or (2) all the splits are in the same currency. If there are
1010  no non-currency splits and not all splits are in the same currency then
1011  imbal_list is used to compute the imbalance. */
1012  MonetaryList *imbal_list = nullptr;
1013  gnc_numeric imbal_value = gnc_numeric_zero();
1014  gboolean trading_accts;
1015 
1016  if (!trans) return imbal_list;
1017 
1018  ENTER("(trans=%p)", trans);
1019 
1020  trading_accts = xaccTransUseTradingAccounts (trans);
1021 
1022  /* If using trading accounts and there is at least one split that is not
1023  in the transaction currency or a split that has a price or exchange
1024  rate other than 1, then compute the balance in each commodity in the
1025  transaction. Otherwise (all splits are in the transaction's currency)
1026  then compute the balance using the value fields.
1027 
1028  Optimize for the common case of only one currency and a balanced
1029  transaction. */
1030  FOR_EACH_SPLIT(trans,
1031  {
1032  gnc_commodity *commodity;
1034  if (trading_accts &&
1035  (imbal_list ||
1036  ! gnc_commodity_equiv(commodity, trans->common_currency) ||
1038  {
1039  /* Need to use (or already are using) a list of imbalances in each of
1040  the currencies used in the transaction. */
1041  if (! imbal_list)
1042  {
1043  /* All previous splits have been in the transaction's common
1044  currency, so imbal_value is in this currency. */
1045  imbal_list = gnc_monetary_list_add_value(imbal_list,
1046  trans->common_currency,
1047  imbal_value);
1048  }
1049  imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
1050  xaccSplitGetAmount(s));
1051  }
1052 
1053  /* Add it to the value accumulator in case we need it. */
1054  imbal_value = gnc_numeric_add(imbal_value, xaccSplitGetValue(s),
1056  } );
1057 
1058 
1059  if (!imbal_list && !gnc_numeric_zero_p(imbal_value))
1060  {
1061  /* Not balanced and no list, create one. If we found multiple currencies
1062  and no non-currency commodity then imbal_list will already exist and
1063  we won't get here. */
1064  imbal_list = gnc_monetary_list_add_value(imbal_list,
1065  trans->common_currency,
1066  imbal_value);
1067  }
1068 
1069  /* Delete all the zero entries from the list, perhaps leaving an
1070  empty list */
1071  imbal_list = gnc_monetary_list_delete_zeros(imbal_list);
1072 
1073  LEAVE("(trans=%p), imbal=%p", trans, imbal_list);
1074  return imbal_list;
1075 }
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
Definition: gnc-numeric.h:188
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
Delete all entries in the list that have zero value.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account&#39;s commodity.
Definition: Account.cpp:3389
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
#define GNC_DENOM_AUTO
Values that can be passed as the &#39;denom&#39; argument.
Definition: gnc-numeric.h:245
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69

◆ xaccTransGetImbalanceValue()

gnc_numeric xaccTransGetImbalanceValue ( const Transaction *  trans)

The xaccTransGetImbalanceValue() method returns the total value of the transaction.

In a pure double-entry system, this imbalance should be exactly zero, and if it is not, something is broken. However, when double-entry semantics are not enforced, unbalanced transactions can sneak in, and this routine can be used to find out how much things are off by. The value returned is denominated in the currency that is returned by the xaccTransFindCommonCurrency() method.

If the use of currency exchange accounts is enabled then the a a transaction must be balanced in each currency it uses to be considered to be balanced. The method xaccTransGetImbalance is used by most code to take this into consideration. This method is only used in a few places that want the transaction value even if currency exchange accounts are enabled.

Definition at line 118 of file gmock-Transaction.cpp.

119 {
120  SCOPED_TRACE("");
121  auto mocktrans = gnc_mocktransaction(trans);
122  return mocktrans ? mocktrans->get_imbalance_value() : gnc_numeric_zero();
123 }

◆ xaccTransGetNotes()

const char* xaccTransGetNotes ( const Transaction *  trans)

Gets the transaction Notes.

The Notes field is only visible in the register in double-line mode

Definition at line 103 of file gmock-Transaction.cpp.

104 {
105  SCOPED_TRACE("");
106  auto mocktrans = gnc_mocktransaction(trans);
107  return mocktrans ? mocktrans->get_notes() : "";
108 }

◆ xaccTransGetPaymentAcctSplitList()

SplitList* xaccTransGetPaymentAcctSplitList ( const Transaction *  trans)

The xaccTransGetPaymentAcctSplitList() method returns a GList of the splits in a transaction that belong to an account which is considered a valid account for business payments.

Parameters
transThe transaction
Returns
The list of splits. This list must be freed when you are done with it.

Definition at line 2123 of file Transaction.cpp.

2124 {
2125  GList *pay_splits = nullptr;
2126  FOR_EACH_SPLIT (trans,
2127  const Account *account = xaccSplitGetAccount(s);
2128  if (account && gncBusinessIsPaymentAcctType(xaccAccountGetType(account)))
2129  pay_splits = g_list_prepend (pay_splits, s);
2130  );
2131 
2132  pay_splits = g_list_reverse (pay_splits);
2133  return pay_splits;
2134 }
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
gboolean gncBusinessIsPaymentAcctType(GNCAccountType type)
Returns whether the given account type is a valid type to use in business payments.
Definition: gncBusiness.c:92
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53

◆ xaccTransGetReadOnly()

const char* xaccTransGetReadOnly ( Transaction *  trans)

Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text.

Definition at line 2348 of file Transaction.cpp.

2349 {
2350  return get_kvp_string_path (trans, {TRANS_READ_ONLY_REASON});
2351 }

◆ xaccTransGetReversedBy()

Transaction* xaccTransGetReversedBy ( const Transaction *  trans)

Returns the transaction that reversed the given transaction.

Parameters
transa Transaction that has been reversed
Returns
the transaction that reversed the given transaction, or NULL if the given transaction has not been reversed.

Definition at line 2616 of file Transaction.cpp.

2617 {
2618  g_return_val_if_fail(trans, nullptr);
2619  auto g = qof_instance_get_path_kvp<GncGUID*> (QOF_INSTANCE(trans), {TRANS_REVERSED_BY});
2620  return g ? xaccTransLookup (*g, qof_instance_get_book (trans)) : nullptr;
2621 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
The xaccTransLookup() subroutine will return the transaction associated with the given id...

◆ xaccTransGetSplit()

Split* xaccTransGetSplit ( const Transaction *  trans,
int  i 
)

Return a pointer to the indexed split in this transaction's split list.

Note that the split list is a linked list and that indexed access is O(N). Do not use this method for iteration.

Parameters
transThe transaction
iThe split number. Valid values for i are zero to (number_of__splits-1).
Returns
A Split* or NULL if i is out of range.

Definition at line 49 of file gmock-Transaction.cpp.

50 {
51  SCOPED_TRACE("");
52  auto mocktrans = gnc_mocktransaction(trans);
53  return mocktrans ? mocktrans->get_split(i) : nullptr;
54 }

◆ xaccTransGetSplitList()

SplitList* xaccTransGetSplitList ( const Transaction *  trans)

The xaccTransGetSplitList() method returns a GList of the splits in a transaction.

Parameters
transThe transaction
Returns
The list of splits. This list must NOT be modified. Do NOT free this list when you are done with it.

Definition at line 57 of file gmock-Transaction.cpp.

58 {
59  g_return_val_if_fail(GNC_IS_MOCKTRANSACTION(trans), NULL);
60  return trans ? ((MockTransaction*)trans)->get_split_list() : NULL;
61 }

◆ xaccTransGetTxnType()

char xaccTransGetTxnType ( Transaction *  trans)

Returns the Transaction Type: note this type will be derived from the transaction splits, returning TXN_TYPE_NONE, TXN_TYPE_INVOICE, TXN_TYPE_LINK, or TXN_TYPE_PAYMENT according to heuristics.

It does not query the transaction kvp slots.

See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT

Definition at line 2309 of file Transaction.cpp.

2310 {
2311  gboolean has_nonAPAR_split = FALSE;
2312 
2313  if (!trans) return TXN_TYPE_NONE;
2314 
2315  if (trans->txn_type != TXN_TYPE_UNCACHED)
2316  return trans->txn_type;
2317 
2318  trans->txn_type = TXN_TYPE_NONE;
2319  for (GList *n = xaccTransGetSplitList (trans); n; n = g_list_next (n))
2320  {
2321  Account *acc = xaccSplitGetAccount (GNC_SPLIT(n->data));
2322 
2323  if (!acc)
2324  continue;
2325 
2327  has_nonAPAR_split = TRUE;
2328  else if (trans->txn_type == TXN_TYPE_NONE)
2329  {
2330  GNCLot *lot = xaccSplitGetLot (GNC_SPLIT(n->data));
2331  GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
2332  GncOwner owner;
2333 
2334  if (invoice && trans == gncInvoiceGetPostedTxn (invoice))
2335  trans->txn_type = TXN_TYPE_INVOICE;
2336  else if (invoice || gncOwnerGetOwnerFromLot (lot, &owner))
2337  trans->txn_type = TXN_TYPE_PAYMENT;
2338  }
2339  }
2340 
2341  if (!has_nonAPAR_split && (trans->txn_type == TXN_TYPE_PAYMENT))
2342  trans->txn_type = TXN_TYPE_LINK;
2343 
2344  return trans->txn_type;
2345 }
#define TXN_TYPE_INVOICE
Transaction is an invoice.
Definition: Transaction.h:126
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
#define TXN_TYPE_NONE
No transaction type.
Definition: Transaction.h:125
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
Definition: gncOwner.c:636
gboolean xaccAccountIsAPARType(GNCAccountType t)
Convenience function to check if the account is a valid business account type (meaning an Accounts Pa...
Definition: Account.cpp:4508
#define TXN_TYPE_LINK
Transaction is a link between (invoice and payment) lots.
Definition: Transaction.h:128
#define TXN_TYPE_PAYMENT
Transaction is a payment.
Definition: Transaction.h:127
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Definition: gncInvoice.c:1234
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn&#39;t be...
Definition: Split.cpp:1931

◆ xaccTransGetVoidReason()

const char* xaccTransGetVoidReason ( const Transaction *  transaction)

Returns the user supplied textual reason why a transaction was voided.

Parameters
transactionThe transaction in question.
Returns
A pointer to the user supplied reason for voiding.

Definition at line 2544 of file Transaction.cpp.

2545 {
2546  return get_kvp_string_path (trans, {void_reason_str});
2547 }

◆ xaccTransGetVoidStatus()

gboolean xaccTransGetVoidStatus ( const Transaction *  transaction)

Retrieve information on whether or not a transaction has been voided.

Parameters
transactionThe transaction in question.
Returns
TRUE if the transaction is void, FALSE otherwise. Also returns FALSE upon an error.

Definition at line 2537 of file Transaction.cpp.

2538 {
2539  auto t = xaccTransGetVoidTime (trans);
2540  return t != INT64_MAX;
2541 }
time64 xaccTransGetVoidTime(const Transaction *tr)
Returns the time that a transaction was voided.

◆ xaccTransGetVoidTime()

time64 xaccTransGetVoidTime ( const Transaction *  tr)

Returns the time that a transaction was voided.

Parameters
trThe transaction in question.
Returns
A time64 containing the time that this transaction was voided. Returns INT64_MAX if there is no voided date.

Definition at line 2550 of file Transaction.cpp.

2551 {
2552  auto void_str{get_kvp_string_path (tr, {void_time_str})};
2553  return void_str ? gnc_iso8601_to_time64_gmt (void_str) : INT64_MAX;
2554 }
time64 gnc_iso8601_to_time64_gmt(const gchar *)
The gnc_iso8601_to_time64_gmt() routine converts an ISO-8601 style date/time string to time64...

◆ xaccTransIsBalanced()

gboolean xaccTransIsBalanced ( const Transaction *  trans)

Returns true if the transaction is balanced according to the rules currently in effect.

Definition at line 1078 of file Transaction.cpp.

1079 {
1080  MonetaryList *imbal_list;
1081  gboolean result;
1082  gnc_numeric imbal = gnc_numeric_zero();
1083  gnc_numeric imbal_trading = gnc_numeric_zero();
1084 
1085  if (trans == nullptr) return FALSE;
1086 
1087  if (xaccTransUseTradingAccounts(trans))
1088  {
1089  /* Transaction is imbalanced if the value is imbalanced in either
1090  trading or non-trading splits. One can't be used to balance
1091  the other. */
1092  FOR_EACH_SPLIT(trans,
1093  {
1094  Account *acc = xaccSplitGetAccount(s);
1095  if (!acc || xaccAccountGetType(acc) != ACCT_TYPE_TRADING)
1096  {
1097  imbal = gnc_numeric_add(imbal, xaccSplitGetValue(s),
1099  }
1100  else
1101  {
1102  imbal_trading = gnc_numeric_add(imbal_trading, xaccSplitGetValue(s),
1104  }
1105  }
1106  );
1107  }
1108  else
1109  imbal = xaccTransGetImbalanceValue(trans);
1110 
1111  if (! gnc_numeric_zero_p(imbal) || ! gnc_numeric_zero_p(imbal_trading))
1112  return FALSE;
1113 
1114  if (!xaccTransUseTradingAccounts (trans))
1115  return TRUE;
1116 
1117  imbal_list = xaccTransGetImbalance(trans);
1118  result = imbal_list == nullptr;
1119  gnc_monetary_list_free(imbal_list);
1120  return result;
1121 }
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3248
STRUCTS.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
Definition: gnc-numeric.h:188
Account used to record multiple commodity transactions.
Definition: Account.h:155
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency ...
#define GNC_DENOM_AUTO
Values that can be passed as the &#39;denom&#39; argument.
Definition: gnc-numeric.h:245

◆ xaccTransIsOpen()

gboolean xaccTransIsOpen ( const Transaction *  trans)

The xaccTransIsOpen() method returns TRUE if the transaction is open for editing.

Otherwise, it returns false. XXX this routine should probably be deprecated. its, umm, hard to imagine legitimate uses (but it is used by the import/export code for reasons I can't understand.)

Definition at line 142 of file gmock-Transaction.cpp.

143 {
144  SCOPED_TRACE("");
145  auto mocktrans = gnc_mocktransaction(trans);
146  return mocktrans ? mocktrans->is_open() : FALSE;
147 }

◆ xaccTransIsReadonlyByPostedDate()

gboolean xaccTransIsReadonlyByPostedDate ( const Transaction *  trans)

Returns TRUE if this Transaction is read-only because its posted-date is older than the "auto-readonly" threshold of this book.

See qof_book_uses_autofreeze() and qof_book_get_autofreeze_gdate().

Definition at line 2376 of file Transaction.cpp.

2377 {
2378  GDate *threshold_date;
2379  GDate trans_date;
2380  const QofBook *book = xaccTransGetBook (trans);
2381  gboolean result;
2382  g_assert(trans);
2383 
2384  if (!qof_book_uses_autoreadonly(book))
2385  {
2386  return FALSE;
2387  }
2388 
2389  if (xaccTransIsSXTemplate (trans))
2390  return FALSE;
2391 
2392  threshold_date = qof_book_get_autoreadonly_gdate(book);
2393  g_assert(threshold_date); // ok because we checked uses_autoreadonly before
2394  trans_date = xaccTransGetDatePostedGDate(trans);
2395 
2396 // g_warning("there is auto-read-only with days=%d, trans_date_day=%d, threshold_date_day=%d",
2397 // qof_book_get_num_days_autofreeze(book),
2398 // g_date_get_day(&trans_date),
2399 // g_date_get_day(threshold_date));
2400 
2401  if (g_date_compare(&trans_date, threshold_date) < 0)
2402  {
2403  //g_warning("we are auto-read-only");
2404  result = TRUE;
2405  }
2406  else
2407  {
2408  result = FALSE;
2409  }
2410  g_date_free(threshold_date);
2411  return result;
2412 }
GDate * qof_book_get_autoreadonly_gdate(const QofBook *book)
Returns the GDate that is the threshold for auto-read-only.
Definition: qofbook.cpp:1006
#define xaccTransGetBook(X)
Definition: Transaction.h:785
QofBook reference.
Definition: qofbook-p.hpp:46
gboolean qof_book_uses_autoreadonly(const QofBook *book)
Returns TRUE if the auto-read-only feature should be used, otherwise FALSE.
Definition: qofbook.cpp:974
GDate xaccTransGetDatePostedGDate(const Transaction *trans)
Retrieve the posted date of the transaction.

◆ xaccTransLookup()

Transaction* xaccTransLookup ( const GncGUID *  guid,
QofBook *  book 
)

The xaccTransLookup() subroutine will return the transaction associated with the given id, or NULL if there is no such transaction.

Definition at line 978 of file Transaction.cpp.

979 {
980  QofCollection *col;
981  if (!guid || !book) return nullptr;
982  col = qof_book_get_collection (book, GNC_ID_TRANS);
983  return (Transaction *) qof_collection_lookup_entity (col, guid);
984 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition: qofid.cpp:209
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

◆ xaccTransOrder()

int xaccTransOrder ( const Transaction *  ta,
const Transaction *  tb 
)

The xaccTransOrder(ta,tb) method is useful for sorting.

Orders ta and tb return <0 if ta sorts before tb return >0 if ta sorts after tb return 0 if they are absolutely equal

The comparrison uses the following fields, in order: date posted (compare as a date) num field (compare as an integer) date entered (compare as a date) description field (comcpare as a string using strcmp()) GncGUID (compare as a guid) Finally, it returns zero if all of the above match. Note that it does NOT compare its member splits. Note also that it calls xaccTransOrder_num_action with actna and actnb set as NULL.

Definition at line 1758 of file Transaction.cpp.

1759 {
1760  return xaccTransOrder_num_action (ta, nullptr, tb, nullptr);
1761 }
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.

◆ xaccTransOrder_num_action()

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.

Orders ta and tb return <0 if ta sorts before tb return >0 if ta sorts after tb return 0 if they are absolutely equal

The comparrison uses the following fields, in order: date posted (compare as a date) if actna and actnb are NULL, num field (compare as an integer) else actna and actnb (compare as an integer) date entered (compare as a date) description field (comcpare as a string using strcmp()) GncGUID (compare as a guid) Finally, it returns zero if all of the above match. Note that it does NOT compare its member splits (except action as specified above).

Definition at line 1794 of file Transaction.cpp.

1796 {
1797  const char *da, *db;
1798  int retval;
1799 
1800  if (ta == tb) return 0;
1801  if (!tb) return -1;
1802  if (!ta) return +1;
1803 
1804  if (ta->date_posted != tb->date_posted)
1805  return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1806 
1807  /* Always sort closing transactions after normal transactions */
1808  {
1809  gboolean ta_is_closing = xaccTransGetIsClosingTxn (ta);
1810  gboolean tb_is_closing = xaccTransGetIsClosingTxn (tb);
1811  if (ta_is_closing != tb_is_closing)
1812  return (ta_is_closing - tb_is_closing);
1813  }
1814 
1815  /* otherwise, sort on number string */
1816  if (actna && actnb) /* split action string, if not nullptr */
1817  {
1818  retval = order_by_int64_or_string (actna, actnb);
1819  }
1820  else /* else transaction num string */
1821  {
1822  retval = order_by_int64_or_string (ta->num, tb->num);
1823  }
1824  if (retval)
1825  return retval;
1826 
1827  if (ta->date_entered != tb->date_entered)
1828  return (ta->date_entered > tb->date_entered) - (ta->date_entered < tb->date_entered);
1829 
1830  /* otherwise, sort on description string */
1831  da = ta->description ? ta->description : "";
1832  db = tb->description ? tb->description : "";
1833  retval = g_utf8_collate (da, db);
1834  if (retval)
1835  return retval;
1836 
1837  /* else, sort on guid - keeps sort stable. */
1838  return qof_instance_guid_compare(ta, tb);
1839 }
gboolean xaccTransGetIsClosingTxn(const Transaction *trans)
Returns whether this transaction is a "closing transaction".
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.

◆ xaccTransRecordPrice()

void xaccTransRecordPrice ( Transaction *  trans,
PriceSource  source 
)

The xaccTransRecordPrice() method iterates through the splits and and record the non-currency equivalent prices in the price database.

Parameters
transThe transaction whose price is recorded
sourceThe price priority level

Definition at line 157 of file gmock-Transaction.cpp.

158 {
159  g_return_if_fail(GNC_IS_MOCKTRANSACTION(trans));
160  ((MockTransaction*)trans)->recordPrice();
161 }

◆ xaccTransRetDateEntered()

time64 xaccTransRetDateEntered ( const Transaction *  trans)

Retrieve the date of when the transaction was entered.

The entered date is the date when the register entry was made.

Definition at line 2295 of file Transaction.cpp.

2296 {
2297  return trans ? trans->date_entered : 0;
2298 }

◆ xaccTransRetDatePosted()

time64 xaccTransRetDatePosted ( const Transaction *  trans)

Retrieve the posted date of the transaction.

The posted date is the date when this transaction was posted at the bank. (Although having different function names, GetDate and GetDatePosted refer to the same single date.)

Definition at line 2257 of file Transaction.cpp.

2258 {
2259  return trans ? trans->date_posted : 0;
2260 }

◆ xaccTransReverse()

Transaction* xaccTransReverse ( Transaction *  transaction)

xaccTransReverse creates a Transaction that reverses the given transaction by inverting all the numerical values in the given transaction.

This function cancels out the effect of an earlier transaction. This will be needed by write only accounts as a way to void a previous transaction (since you can't alter the existing transaction).

Parameters
transactionThe transaction to create a reverse of.
Returns
a new transaction which reverses the given transaction

Definition at line 2579 of file Transaction.cpp.

2580 {
2581  Transaction *trans;
2582  g_return_val_if_fail(orig, nullptr);
2583 
2584  /* First edit, dirty, and commit orig to ensure that any trading
2585  * splits are correctly balanced.
2586  */
2587  xaccTransBeginEdit (orig);
2588  qof_instance_set_dirty (QOF_INSTANCE (orig));
2589  xaccTransCommitEdit (orig);
2590 
2591  trans = xaccTransClone(orig);
2592  g_return_val_if_fail (trans, nullptr);
2593  xaccTransBeginEdit(trans);
2594 
2595  /* Reverse the values on each split. Clear per-split info. */
2596  FOR_EACH_SPLIT(trans,
2597  {
2601  });
2602 
2603  /* Now update the original with a pointer to the new one */
2604  qof_instance_set_path_kvp<GncGUID*> (QOF_INSTANCE (orig), guid_copy(xaccTransGetGUID(trans)),
2605  {TRANS_REVERSED_BY});
2606 
2607  /* Make sure the reverse transaction is not read-only */
2608  xaccTransClearReadOnly(trans);
2609 
2610  qof_instance_set_dirty(QOF_INSTANCE(trans));
2611  xaccTransCommitEdit(trans);
2612  return trans;
2613 }
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:92
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
Definition: guid.cpp:155
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account&#39;s commodity that the split should have...
Definition: gmock-Split.cpp:77
Transaction * xaccTransClone(const Transaction *from)
The xaccTransClone() method will create a complete copy of an existing transaction.
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...
#define xaccTransGetGUID(X)
Definition: Transaction.h:787
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
#define NREC
not reconciled or cleared
Definition: Split.h:76
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69

◆ xaccTransRollbackEdit()

void xaccTransRollbackEdit ( Transaction *  trans)

The xaccTransRollbackEdit() routine rejects all edits made, and sets the transaction back to where it was before the editing started.

This includes restoring any deleted splits, removing any added splits, and undoing the effects of xaccTransDestroy, as well as restoring share quantities, memos, descriptions, etc.

Todo:
Fix transrollbackedit in QOF so that rollback is exposed via the API.

Definition at line 1591 of file Transaction.cpp.

1592 {
1593  GList *node, *onode;
1594  QofBackend *be;
1595  Transaction *orig;
1596  GList *slist;
1597  int num_preexist, i;
1598 
1599 /* FIXME: This isn't quite the right way to handle nested edits --
1600  * there should be a stack of transaction states that are popped off
1601  * and restored at each level -- but it does prevent restoring to the
1602  * editlevel 0 state until one is returning to editlevel 0, and
1603  * thereby prevents a crash caused by trans->orig getting nullptred too
1604  * soon.
1605  */
1606  if (!qof_instance_get_editlevel (QOF_INSTANCE (trans))) return;
1607  if (qof_instance_get_editlevel (QOF_INSTANCE (trans)) > 1) {
1608  qof_instance_decrease_editlevel (QOF_INSTANCE (trans));
1609  return;
1610  }
1611 
1612  ENTER ("trans addr=%p\n", trans);
1613 
1614  check_open(trans);
1615 
1616  /* copy the original values back in. */
1617 
1618  orig = trans->orig;
1619  std::swap (trans->num, orig->num);
1620  std::swap (trans->description, orig->description);
1621  trans->date_entered = orig->date_entered;
1622  trans->date_posted = orig->date_posted;
1623  std::swap (trans->common_currency, orig->common_currency);
1624  qof_instance_swap_kvp (QOF_INSTANCE (trans), QOF_INSTANCE (orig));
1625 
1626  /* The splits at the front of trans->splits are exactly the same
1627  splits as in the original, but some of them may have changed, so
1628  we restore only those. */
1629 /* FIXME: Runs off the transaction's splits, so deleted splits are not
1630  * restored!
1631  */
1632  num_preexist = g_list_length(orig->splits);
1633  slist = g_list_copy(trans->splits);
1634  for (i = 0, node = slist, onode = orig->splits; node;
1635  i++, node = node->next, onode = onode ? onode->next : nullptr)
1636  {
1637  Split *s = GNC_SPLIT(node->data);
1638 
1639  if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
1640  continue;
1641 
1642  if (i < num_preexist && onode)
1643  {
1644  Split *so = GNC_SPLIT(onode->data);
1645 
1646  xaccSplitRollbackEdit(s);
1647  std::swap (s->action, so->action);
1648  std::swap (s->memo, so->memo);
1649  qof_instance_copy_kvp (QOF_INSTANCE (s), QOF_INSTANCE (so));
1650  s->reconciled = so->reconciled;
1651  s->amount = so->amount;
1652  s->value = so->value;
1653  s->lot = so->lot;
1654  s->gains_split = so->gains_split;
1655  //SET_GAINS_A_VDIRTY(s);
1656  s->date_reconciled = so->date_reconciled;
1657  qof_instance_mark_clean(QOF_INSTANCE(s));
1658  }
1659  else
1660  {
1661  /* Potentially added splits */
1662  if (trans != xaccSplitGetParent(s))
1663  {
1664  trans->splits = g_list_remove(trans->splits, s);
1665  /* New split added, but then moved to another
1666  transaction */
1667  continue;
1668  }
1669  xaccSplitRollbackEdit(s);
1670  trans->splits = g_list_remove(trans->splits, s);
1671  g_assert(trans != xaccSplitGetParent(s));
1672  /* NB: our memory management policy here is that a new split
1673  added to the transaction which is then rolled-back still
1674  belongs to the engine. Specifically, it's freed by the
1675  transaction to which it was added. Don't add the Split to
1676  more than one transaction during the begin/commit block! */
1677  if (nullptr == xaccSplitGetParent(s))
1678  {
1679  xaccFreeSplit(s); // a newly malloc'd split
1680  }
1681  }
1682  }
1683  g_list_free(slist);
1684 
1685  // orig->splits may still have duped splits so free them
1686  g_list_free_full (orig->splits, (GDestroyNotify)xaccFreeSplit);
1687  orig->splits = nullptr;
1688 
1689  /* Now that the engine copy is back to its original version,
1690  * get the backend to fix it in the database */
1694  if (qof_backend_can_rollback (be))
1695  {
1696  QofBackendError errcode;
1697 
1698  /* clear errors */
1699  do
1700  {
1701  errcode = qof_backend_get_error (be);
1702  }
1703  while (ERR_BACKEND_NO_ERR != errcode);
1704 
1705  qof_backend_rollback_instance (be, &(trans->inst));
1706 
1707  errcode = qof_backend_get_error (be);
1708  if (ERR_BACKEND_MOD_DESTROY == errcode)
1709  {
1710  /* The backend is asking us to delete this transaction.
1711  * This typically happens because another (remote) user
1712  * has deleted this transaction, and we haven't found
1713  * out about it until this user tried to edit it.
1714  */
1715  xaccTransDestroy (trans);
1716  do_destroy (QOF_INSTANCE(trans));
1717 
1718  /* push error back onto the stack */
1719  qof_backend_set_error (be, errcode);
1720  LEAVE ("deleted trans addr=%p\n", trans);
1721  return;
1722  }
1723  if (ERR_BACKEND_NO_ERR != errcode)
1724  {
1725  PERR ("Rollback Failed. Ouch!");
1726  /* push error back onto the stack */
1727  qof_backend_set_error (be, errcode);
1728  }
1729  }
1730 
1732  xaccTransWriteLog (trans, 'R');
1733 
1734  xaccFreeTransaction (trans->orig);
1735 
1736  trans->orig = nullptr;
1737  qof_instance_set_destroying(trans, FALSE);
1738 
1739  /* Put back to zero. */
1740  qof_instance_decrease_editlevel(trans);
1741  /* FIXME: The register code seems to depend on the engine to
1742  generate an event during rollback, even though the state is just
1743  reverting to what it was. */
1744  gen_event_trans (trans);
1745 
1746  LEAVE ("trans addr=%p\n", trans);
1747 }
commit of object update failed because another user has deleted the object
Definition: qofbackend.h:77
#define qof_instance_is_dirty
Return value of is_dirty flag.
Definition: qofinstance.h:166
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:57
void xaccTransWriteLog(Transaction *trans, char flag)
Definition: TransLog.cpp:222
void qof_backend_set_error(QofBackend *qof_be, QofBackendError err)
Set the error on the specified QofBackend.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
QofBackendError qof_backend_get_error(QofBackend *qof_be)
Get the last backend error.
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
Definition: qofbook.cpp:497
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
Definition: qofbook.cpp:440

◆ xaccTransScrubGains()

void xaccTransScrubGains ( Transaction *  trans,
Account *  gain_acc 
)

The xaccTransScrubGains() routine performs a number of cleanup functions on the indicated transaction, with the end-goal of setting up a consistent set of gains/losses for all the splits in the transaction.

This includes making sure that the lot assignments of all the splits are good, and that the lots balance appropriately.

Definition at line 2666 of file Transaction.cpp.

2667 {
2668  SplitList *node;
2669 
2670  ENTER("(trans=%p)", trans);
2671  /* Lock down posted date, its to be synced to the posted date
2672  * for the source of the cap gains. */
2673  xaccTransScrubGainsDate(trans);
2674 
2675  /* Fix up the split amount */
2676 restart:
2677  for (node = trans->splits; node; node = node->next)
2678  {
2679  Split *s = GNC_SPLIT(node->data);
2680 
2681  if (!xaccTransStillHasSplit(trans, s)) continue;
2682 
2683  xaccSplitDetermineGainStatus(s);
2684  if (s->gains & GAINS_STATUS_ADIRTY)
2685  {
2686  gboolean altered = FALSE;
2687  s->gains &= ~GAINS_STATUS_ADIRTY;
2688  if (s->lot)
2689  altered = xaccScrubLot(s->lot);
2690  else
2691  altered = xaccSplitAssign(s);
2692  if (altered) goto restart;
2693  }
2694  }
2695 
2696  /* Fix up gains split value */
2697  FOR_EACH_SPLIT(trans,
2698  if ((s->gains & GAINS_STATUS_VDIRTY) ||
2699  (s->gains_split &&
2700  (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
2701  xaccSplitComputeCapGains(s, gain_acc);
2702  );
2703 
2704  LEAVE("(trans=%p)", trans);
2705 }
void xaccSplitComputeCapGains(Split *split, Account *gain_acc)
The xaccSplitComputeCapGains() routine computes the cap gains or losses for the indicated split...
Definition: cap-gains.cpp:522
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GList SplitList
GList of Split.
Definition: gnc-engine.h:207
gboolean xaccSplitAssign(Split *split)
The`xaccSplitAssign() routine will take the indicated split and, if it doesn&#39;t already belong to a lo...
Definition: cap-gains.cpp:436
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
gboolean xaccScrubLot(GNCLot *lot)
The xaccScrubLot() routine makes sure that the indicated lot is self-consistent and properly balanced...
Definition: Scrub3.cpp:85

◆ xaccTransSetCurrency()

void xaccTransSetCurrency ( Transaction *  trans,
gnc_commodity *  curr 
)

Set the commodity of this transaction.

Set the commodity of this transaction.

When we do that to a transaction with splits we need to re-value all of the splits in the new currency.

Parameters
transThe transaction to change
currThe new currency to set.

Definition at line 1311 of file Transaction.cpp.

1312 {
1313  if (!trans || !curr || trans->common_currency == curr) return;
1314 
1315  gnc_commodity *old_curr = trans->common_currency;
1316  xaccTransBeginEdit(trans);
1317 
1318  trans->common_currency = curr;
1319  if (old_curr != nullptr && trans->splits != nullptr)
1320  {
1321  gnc_numeric rate = find_new_rate(trans, curr);
1322  if (!gnc_numeric_zero_p (rate))
1323  {
1324  FOR_EACH_SPLIT(trans, split_set_new_value(s, curr, old_curr, rate));
1325  }
1326  else
1327  {
1328  FOR_EACH_SPLIT(trans, xaccSplitSetValue(s, xaccSplitGetValue(s)));
1329  }
1330  }
1331 
1332  qof_instance_set_dirty(QOF_INSTANCE(trans));
1333  mark_trans(trans); /* Dirty balance of every account in trans */
1334  xaccTransCommitEdit(trans);
1335 }
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:92
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
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...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84

◆ xaccTransSetDate()

void xaccTransSetDate ( Transaction *  trans,
int  day,
int  mon,
int  year 
)

The xaccTransSetDate() method does the same thing as xaccTransSetDate[Posted]Secs(), but takes a convenient day-month-year format.

(Footnote: this shouldn't matter to a user, but anyone modifying the engine should understand that when xaccTransCommitEdit() is called, the date order of each of the component splits will be checked, and will be restored in ascending date order.)

Definition at line 1937 of file Transaction.cpp.

1938 {
1939  if (!trans) return;
1940  GDate date;
1941  g_date_clear (&date, 1);
1942  if (day >= 0 && day <= G_MAXUINT8 &&
1943  mon >= G_DATE_JANUARY && mon <= G_DATE_DECEMBER &&
1944  year >= 0 && year <= G_MAXUINT16 &&
1945  g_date_valid_dmy (day, static_cast<GDateMonth>(mon), year))
1946  g_date_set_dmy (&date, day, static_cast<GDateMonth>(mon), year);
1947  else
1948  {
1949  PWARN("Attempted to set invalid date %d-%d-%d; set today's date instead.",
1950  year, mon, day);
1951  gnc_gdate_set_today (&date);
1952  }
1953  xaccTransSetDatePostedGDate(trans, date);
1954 }
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
Definition: gnc-date.cpp:1306
void xaccTransSetDatePostedGDate(Transaction *trans, GDate date)
This method modifies posted date of the transaction, specified by a GDate.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250

◆ xaccTransSetDateEnteredSecs()

void xaccTransSetDateEnteredSecs ( Transaction *  trans,
time64  time 
)

Modify the date of when the transaction was entered.

The entered date is the date when the register entry was made.

Definition at line 1930 of file Transaction.cpp.

1931 {
1932  if (!trans) return;
1933  xaccTransSetDateInternal(trans, &trans->date_entered, secs);
1934 }

◆ xaccTransSetDatePostedGDate()

void xaccTransSetDatePostedGDate ( Transaction *  trans,
GDate  date 
)

This method modifies posted date of the transaction, specified by a GDate.

The posted date is the date when this transaction was posted at the bank.

This is identical to xaccTransSetDate(), but different from xaccTransSetDatePostedSecs which artificially introduces the time-of-day part, which needs to be ignored.

Definition at line 1914 of file Transaction.cpp.

1915 {
1916  if (!trans) return;
1917 
1918  /* We additionally save this date into a kvp frame to ensure in
1919  * the future a date which was set as *date* (without time) can
1920  * clearly be distinguished from the time64. */
1921  qof_instance_set_path_kvp<GDate> (QOF_INSTANCE(trans), date, {TRANS_DATE_POSTED});
1922  qof_instance_set_dirty (QOF_INSTANCE(trans));
1923  /* mark dirty and commit handled by SetDateInternal */
1924  xaccTransSetDateInternal(trans, &trans->date_posted,
1925  gdate_to_time64(date));
1926  set_gains_date_dirty (trans);
1927 }
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
Definition: gnc-date.cpp:1323

◆ xaccTransSetDatePostedSecs()

void xaccTransSetDatePostedSecs ( Transaction *  trans,
time64  time 
)

The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)).

The posted date is the date when this transaction was posted at the bank.

Please do not use this function, as the extra time-of-day part messes up a lot of places. Rather, please use xaccTransSetDatePostedGDate() or xaccTransSetDatePostedSecsNormalized().

Definition at line 1898 of file Transaction.cpp.

1899 {
1900  if (!trans) return;
1901  xaccTransSetDateInternal(trans, &trans->date_posted, secs);
1902  set_gains_date_dirty(trans);
1903 }

◆ xaccTransSetDatePostedSecsNormalized()

void xaccTransSetDatePostedSecsNormalized ( Transaction *  trans,
time64  time 
)

This function sets the posted date of the transaction, specified by a time64 (see ctime(3)).

Contrary to xaccTransSetDatePostedSecs(), the time will be normalized to only the date part, and the time-of-day will be ignored. The resulting date is the same as if it had been set as a GDate through xaccTransSetDatePostedGDate().

Please prefer this function over xaccTransSetDatePostedSecs().

The posted date is the date when this transaction was posted at the bank.

Definition at line 81 of file gmock-Transaction.cpp.

82 {
83  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
84  gnc_mocktransaction(trans)->set_date_posted_secs_normalized(time);
85 }

◆ xaccTransSetNotes()

void xaccTransSetNotes ( Transaction *  trans,
const char *  notes 
)

Sets the transaction Notes.

The Notes field is only visible in the register in double-line mode

Definition at line 111 of file gmock-Transaction.cpp.

112 {
113  ASSERT_TRUE(GNC_IS_MOCKTRANSACTION(trans));
114  gnc_mocktransaction(trans)->set_notes(notes);
115 }

◆ xaccTransSetReadOnly()

void xaccTransSetReadOnly ( Transaction *  trans,
const char *  reason 
)

Set the transaction to be ReadOnly by setting a non-NULL value as "reason".

FIXME: If "reason" is NULL, this function does nothing, instead of removing the readonly flag; the actual removal is possible only through xaccTransClearReadOnly().

Definition at line 1979 of file Transaction.cpp.

1980 {
1981  if (trans && reason)
1982  set_kvp_string_path (trans, {TRANS_READ_ONLY_REASON}, reason);
1983 }

◆ xaccTransSetTxnType()

void xaccTransSetTxnType ( Transaction *  trans,
char  type 
)

Set the Transaction Type: note the type will be saved into the Transaction kvp property as a backward compatibility measure, for previous GnuCash versions whose xaccTransGetTxnType reads from the kvp slots.

See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT

Definition at line 1967 of file Transaction.cpp.

1968 {
1969  char s[2] = {type, '\0'};
1970  set_kvp_string_path (trans, {TRANS_TXN_TYPE_KVP}, s);
1971 }

◆ xaccTransUnvoid()

void xaccTransUnvoid ( Transaction *  transaction)

xaccTransUnvoid restores a voided transaction to its original state.

At some point when gnucash is enhanced to support an audit trail (i.e. write only transactions) this command should be automatically disabled when the audit trail feature is enabled.

Parameters
transactionThe transaction to restore from voided state.

Definition at line 2557 of file Transaction.cpp.

2558 {
2559  g_return_if_fail(trans);
2560 
2561  if (!xaccTransGetVoidStatus (trans))
2562  return; /* Transaction isn't voided. Bail. */
2563 
2564  xaccTransBeginEdit(trans);
2565 
2566  set_kvp_string_path (trans, {trans_notes_str}, get_kvp_string_path (trans, {void_former_notes_str}));
2567  set_kvp_string_path (trans, {void_former_notes_str}, nullptr);
2568  set_kvp_string_path (trans, {void_reason_str}, nullptr);
2569  set_kvp_string_path (trans, {void_time_str}, nullptr);
2570 
2571  FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
2572 
2573  /* Dirtying taken care of by ClearReadOnly */
2574  xaccTransClearReadOnly(trans);
2575  xaccTransCommitEdit(trans);
2576 }
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...
gboolean xaccTransGetVoidStatus(const Transaction *trans)
Retrieve information on whether or not a transaction has been voided.

◆ xaccTransVoid()

void xaccTransVoid ( Transaction *  transaction,
const char *  reason 
)

xaccTransVoid voids a transaction.

A void transaction has no values, is unaffected by reconciliation, and, by default is not included in any queries. A voided transaction may not be altered.

Parameters
transactionThe transaction to void.
reasonThe textual reason why this transaction is being voided.

Definition at line 2506 of file Transaction.cpp.

2507 {
2508  g_return_if_fail(trans && reason);
2509 
2510  /* Prevent voiding transactions that are already marked
2511  * read only, for example generated by the business features.
2512  */
2513  if (xaccTransGetReadOnly (trans))
2514  {
2515  PWARN ("Refusing to void a read-only transaction!");
2516  return;
2517  }
2518  xaccTransBeginEdit(trans);
2519 
2520  char iso8601_str[ISO_DATELENGTH + 1] = "";
2521  gnc_time64_to_iso8601_buff (gnc_time(nullptr), iso8601_str);
2522 
2523  if (auto s = get_kvp_string_path (trans, {trans_notes_str}))
2524  set_kvp_string_path (trans, {void_former_notes_str}, s);
2525  set_kvp_string_path (trans, {trans_notes_str}, _("Voided transaction"));
2526  set_kvp_string_path (trans, {void_reason_str}, reason);
2527  set_kvp_string_path (trans, {void_time_str}, iso8601_str);
2528 
2529  FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
2530 
2531  /* Dirtying taken care of by SetReadOnly */
2532  xaccTransSetReadOnly(trans, _("Transaction Voided"));
2533  xaccTransCommitEdit(trans);
2534 }
const char * xaccTransGetReadOnly(Transaction *trans)
Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text...
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
void xaccTransSetReadOnly(Transaction *trans, const char *reason)
Set the transaction to be ReadOnly by setting a non-NULL value as "reason".
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...
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:262
char * gnc_time64_to_iso8601_buff(time64 time, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
Definition: gnc-date.cpp:1213