GnuCash  2.6.17
Files | Macros | Functions

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 xaccSplitReturnGUID(X)   (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
 
#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))
 
#define xaccTransReturnGUID(X)   (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
 
#define xaccTransGetSlots(X)   qof_instance_get_slots (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)
 

Split Reconciled field values

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

#define CREC   'c'
 
#define YREC   'y'
 
#define FREC   'f'
 
#define NREC   'n'
 
#define VREC   'v'
 

Split general getters/setters

Split * xaccMallocSplit (QofBook *book)
 
void xaccSplitReinit (Split *split)
 
gboolean xaccSplitDestroy (Split *split)
 
void xaccSplitCopyOnto (const Split *from_split, Split *to_split)
 
QofBook * xaccSplitGetBook (const Split *split)
 
AccountxaccSplitGetAccount (const Split *split)
 
void xaccSplitSetAccount (Split *s, Account *acc)
 
Transaction * xaccSplitGetParent (const Split *split)
 
void xaccSplitSetParent (Split *split, Transaction *trans)
 
GNCLot * xaccSplitGetLot (const Split *split)
 
void xaccSplitSetLot (Split *split, GNCLot *lot)
 
KvpFrame * xaccSplitGetSlots (const Split *split)
 
void xaccSplitSetSlots_nc (Split *s, KvpFrame *frm)
 
void xaccSplitSetMemo (Split *split, const char *memo)
 
const char * xaccSplitGetMemo (const Split *split)
 
void xaccSplitSetAction (Split *split, const char *action)
 
const char * xaccSplitGetAction (const Split *split)
 

Split Date getters/setters

void xaccSplitSetReconcile (Split *split, char reconciled_flag)
 
char xaccSplitGetReconcile (const Split *split)
 
void xaccSplitSetDateReconciledSecs (Split *split, time64 time)
 
void xaccSplitSetDateReconciledTS (Split *split, Timespec *ts)
 
void xaccSplitGetDateReconciledTS (const Split *split, Timespec *ts)
 
Timespec xaccSplitRetDateReconciledTS (const Split *split)
 
time64 xaccSplitGetDateReconciled (const Split *split)
 

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)
 
gnc_numeric xaccSplitGetAmount (const Split *split)
 
void xaccSplitSetValue (Split *split, gnc_numeric value)
 
gnc_numeric xaccSplitGetValue (const Split *split)
 
void xaccSplitSetSharePriceAndAmount (Split *split, gnc_numeric price, gnc_numeric amount)
 
gnc_numeric xaccSplitGetSharePrice (const Split *split)
 
void xaccSplitSetBaseValue (Split *split, gnc_numeric value, const gnc_commodity *base_currency)
 
gnc_numeric xaccSplitGetBaseValue (const Split *split, const gnc_commodity *base_currency)
 
gnc_numeric xaccSplitGetBalance (const Split *split)
 
gnc_numeric xaccSplitGetClearedBalance (const Split *split)
 
gnc_numeric xaccSplitGetReconciledBalance (const Split *split)
 

Split utility functions

gboolean xaccSplitEqual (const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
 
Split * xaccSplitLookup (const GncGUID *guid, QofBook *book)
 
GList * xaccSplitListGetUniqueTransactions (const GList *splits)
 
Split * xaccSplitGetOtherSplit (const Split *split)
 
const char * xaccSplitGetType (const Split *s)
 
void xaccSplitMakeStockSplit (Split *s)
 
gint xaccSplitOrder (const Split *sa, const Split *sb)
 
gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
 
int xaccSplitCompareAccountFullNames (const Split *sa, const Split *sb)
 
int xaccSplitCompareAccountCodes (const Split *sa, const Split *sb)
 
int xaccSplitCompareOtherAccountFullNames (const Split *sa, const Split *sb)
 
int xaccSplitCompareOtherAccountCodes (const Split *sa, const Split *sb)
 
char * xaccSplitGetCorrAccountFullName (const Split *sa)
 
const char * xaccSplitGetCorrAccountName (const Split *sa)
 
const char * xaccSplitGetCorrAccountCode (const Split *sa)
 
#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)
 
gnc_numeric xaccSplitVoidFormerValue (const Split *split)
 

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_KVP   "kvp"
 
#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"
 
#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_NONE   '\0'
 
#define TXN_TYPE_INVOICE   'I'
 
#define TXN_TYPE_PAYMENT   'P'
 
#define TXN_TYPE_LINK   'L'
 

Transaction creation and editing

Transaction * xaccMallocTransaction (QofBook *book)
 
void xaccTransDestroy (Transaction *trans)
 
Transaction * xaccTransClone (const Transaction *t)
 
gboolean xaccTransEqual (const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
 
void xaccTransBeginEdit (Transaction *trans)
 
void xaccTransCommitEdit (Transaction *trans)
 
void xaccTransRollbackEdit (Transaction *trans)
 
gboolean xaccTransIsOpen (const Transaction *trans)
 
Transaction * xaccTransLookup (const GncGUID *guid, QofBook *book)
 
Transaction * xaccTransCopyToClipBoard (const Transaction *from_trans)
 
void xaccTransCopyOnto (const Transaction *from_trans, Transaction *to_trans)
 
void xaccTransCopyFromClipBoard (const Transaction *from_trans, Transaction *to_trans, const Account *from_acc, Account *to_acc, gboolean no_date)
 
Split * xaccTransFindSplitByAccount (const Transaction *trans, const Account *acc)
 
void xaccTransScrubGains (Transaction *trans, Account *gain_acc)
 
guint gnc_book_count_transactions (QofBook *book)
 
#define xaccTransLookupDirect(g, b)   xaccTransLookup(&(g),b)
 

Transaction general getters/setters

gboolean xaccTransUseTradingAccounts (const Transaction *trans)
 
void xaccTransSortSplits (Transaction *trans)
 
void xaccTransSetTxnType (Transaction *trans, char type)
 
char xaccTransGetTxnType (const Transaction *trans)
 
void xaccTransSetNum (Transaction *trans, const char *num)
 
void xaccTransSetDescription (Transaction *trans, const char *desc)
 
void xaccTransSetAssociation (Transaction *trans, const char *assoc)
 
void xaccTransSetNotes (Transaction *trans, const char *notes)
 
const char * xaccTransGetNum (const Transaction *trans)
 
const char * xaccTransGetDescription (const Transaction *trans)
 
const char * xaccTransGetAssociation (const Transaction *trans)
 
const char * xaccTransGetNotes (const Transaction *trans)
 
void xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing)
 
gboolean xaccTransGetIsClosingTxn (const Transaction *trans)
 
Split * xaccTransGetSplit (const Transaction *trans, int i)
 
int xaccTransGetSplitIndex (const Transaction *trans, const Split *split)
 
SplitListxaccTransGetSplitList (const Transaction *trans)
 
gboolean xaccTransStillHasSplit (const Transaction *trans, const Split *s)
 
Split * xaccTransGetFirstPaymentAcctSplit (const Transaction *trans)
 
Split * xaccTransGetFirstAPARAcctSplit (const Transaction *trans)
 
void xaccTransSetReadOnly (Transaction *trans, const char *reason)
 
void xaccTransClearReadOnly (Transaction *trans)
 
const char * xaccTransGetReadOnly (const Transaction *trans)
 
gboolean xaccTransIsReadonlyByPostedDate (const Transaction *trans)
 
gboolean xaccTransInFutureByPostedDate (const Transaction *trans)
 
int xaccTransCountSplits (const Transaction *trans)
 
gboolean xaccTransHasReconciledSplits (const Transaction *trans)
 
gboolean xaccTransHasReconciledSplitsByAccount (const Transaction *trans, const Account *account)
 
gboolean xaccTransHasSplitsInState (const Transaction *trans, const char state)
 
gboolean xaccTransHasSplitsInStateByAccount (const Transaction *trans, const char state, const Account *account)
 
gnc_commodity * xaccTransGetCurrency (const Transaction *trans)
 
void xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr)
 
gnc_numeric xaccTransGetImbalanceValue (const Transaction *trans)
 
MonetaryList * xaccTransGetImbalance (const Transaction *trans)
 
gboolean xaccTransIsBalanced (const Transaction *trans)
 
gnc_numeric xaccTransGetAccountValue (const Transaction *trans, const Account *account)
 
gnc_numeric xaccTransGetAccountAmount (const Transaction *trans, const Account *account)
 
gboolean xaccTransGetRateForCommodity (const Transaction *trans, const gnc_commodity *split_com, const Split *split_to_exclude, gnc_numeric *rate)
 
gnc_numeric xaccTransGetAccountConvRate (const Transaction *txn, const Account *acc)
 
gnc_numeric xaccTransGetAccountBalance (const Transaction *trans, const Account *account)
 
int xaccTransOrder (const Transaction *ta, const Transaction *tb)
 
int xaccTransOrder_num_action (const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
 
#define xaccTransAppendSplit(t, s)   xaccSplitSetParent((s), (t))
 

Transaction date setters/getters

void xaccTransSetDate (Transaction *trans, int day, int mon, int year)
 
void xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
 
void xaccTransSetDatePostedSecs (Transaction *trans, time64 time)
 
void xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
 
void xaccTransSetDatePostedTS (Transaction *trans, const Timespec *ts)
 
void xaccTransSetDateEnteredSecs (Transaction *trans, time64 time)
 
void xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts)
 
void xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts)
 
time64 xaccTransGetDate (const Transaction *trans)
 
void xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts)
 
Timespec xaccTransRetDatePostedTS (const Transaction *trans)
 
GDate xaccTransGetDatePostedGDate (const Transaction *trans)
 
time64 xaccTransGetDateEntered (const Transaction *trans)
 
void xaccTransGetDateEnteredTS (const Transaction *trans, Timespec *ts)
 
Timespec xaccTransRetDateEnteredTS (const Transaction *trans)
 
Timespec xaccTransRetDateDueTS (const Transaction *trans)
 
void xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts)
 

Transaction voiding

void xaccTransVoid (Transaction *transaction, const char *reason)
 
void xaccTransUnvoid (Transaction *transaction)
 
Transaction * xaccTransReverse (Transaction *transaction)
 
Transaction * xaccTransGetReversedBy (const Transaction *trans)
 
gboolean xaccTransGetVoidStatus (const Transaction *transaction)
 
const char * xaccTransGetVoidReason (const Transaction *transaction)
 
Timespec xaccTransGetVoidTime (const Transaction *tr)
 

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_ASSOCIATION   "assoc"
 
#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.

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 cannnot accidentally destroy this relationship as long as they stick to using the API and never access internal structures directly.

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

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

Macro Definition Documentation

◆ CREC

#define CREC   'c'

The Split has been cleared

Definition at line 67 of file Split.h.

◆ FREC

#define FREC   'f'

frozen into accounting period

Definition at line 69 of file Split.h.

◆ NREC

#define NREC   'n'

not reconciled or cleared

Definition at line 70 of file Split.h.

◆ SPLIT_ACCOUNT_GUID

#define SPLIT_ACCOUNT_GUID   "account-guid"

for guid_match_all

Definition at line 534 of file Split.h.

◆ TXN_TYPE_INVOICE

#define TXN_TYPE_INVOICE   'I'

Transaction is an invoice

Definition at line 120 of file Transaction.h.

◆ TXN_TYPE_LINK

#define TXN_TYPE_LINK   'L'

Transaction is a link between (invoice and payment) lots

Definition at line 122 of file Transaction.h.

◆ TXN_TYPE_NONE

#define TXN_TYPE_NONE   '\0'

No transaction type

Definition at line 119 of file Transaction.h.

◆ TXN_TYPE_PAYMENT

#define TXN_TYPE_PAYMENT   'P'

Transaction is a payment

Definition at line 121 of file Transaction.h.

◆ VREC

#define VREC   'v'

split is void

Definition at line 71 of file Split.h.

◆ xaccSplitGetGUID

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

Definition at line 542 of file Split.h.

◆ xaccSplitReturnGUID

#define xaccSplitReturnGUID (   X)    (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
Deprecated:

Definition at line 544 of file Split.h.

◆ xaccTransAppendSplit

#define xaccTransAppendSplit (   t,
 
)    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 351 of file Transaction.h.

◆ xaccTransGetBook

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

Definition at line 762 of file Transaction.h.

◆ xaccTransGetGUID

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

Definition at line 764 of file Transaction.h.

◆ xaccTransGetSlots

#define xaccTransGetSlots (   X)    qof_instance_get_slots (QOF_INSTANCE(X))
Deprecated:

Definition at line 768 of file Transaction.h.

◆ xaccTransReturnGUID

#define xaccTransReturnGUID (   X)    (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
Deprecated:

Definition at line 766 of file Transaction.h.

◆ YREC

#define YREC   'y'

The Split has been reconciled

Definition at line 68 of file Split.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 2474 of file Transaction.c.

2475 {
2476  guint count = 0;
2477  xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
2478  counter_thunk, (void*)&count);
2479  return count;
2480 }
int xaccAccountTreeForEachTransaction(Account *acc, TransactionCallback proc, void *data)

◆ xaccMallocSplit()

Split* xaccMallocSplit ( QofBook *  book)

Constructor.

Definition at line 349 of file Split.c.

350 {
351  Split *split;
352  g_return_val_if_fail (book, NULL);
353 
354  split = g_object_new (GNC_TYPE_SPLIT, NULL);
355  xaccInitSplit (split, book);
356 
357  return split;
358 }

◆ 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 449 of file Transaction.c.

450 {
451  Transaction *trans;
452 
453  g_return_val_if_fail (book, NULL);
454 
455  trans = g_object_new(GNC_TYPE_TRANSACTION, NULL);
456  xaccInitTransaction (trans, book);
457  qof_event_gen (&trans->inst, QOF_EVENT_CREATE, NULL);
458 
459  return trans;
460 }
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ xaccSplitCompareAccountCodes()

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

Compare two splits by code of account. Returns similar to strcmp.

Definition at line 1474 of file Split.c.

1475 {
1476  Account *aa, *ab;
1477  if (!sa && !sb) return 0;
1478  if (!sa) return -1;
1479  if (!sb) return 1;
1480 
1481  aa = sa->acc;
1482  ab = sb->acc;
1483 
1484  return g_strcmp0(xaccAccountGetCode(aa), xaccAccountGetCode(ab));
1485 }
const char * xaccAccountGetCode(const Account *acc)
Definition: Account.c:2961

◆ xaccSplitCompareAccountFullNames()

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

Compare two splits by full name of account. Returns similar to strcmp.

Definition at line 1453 of file Split.c.

1454 {
1455  Account *aa, *ab;
1456  char *full_a, *full_b;
1457  int retval;
1458  if (!sa && !sb) return 0;
1459  if (!sa) return -1;
1460  if (!sb) return 1;
1461 
1462  aa = sa->acc;
1463  ab = sb->acc;
1464  full_a = gnc_account_get_full_name(aa);
1465  full_b = gnc_account_get_full_name(ab);
1466  retval = g_utf8_collate(full_a, full_b);
1467  g_free(full_a);
1468  g_free(full_b);
1469  return retval;
1470 }
gchar * gnc_account_get_full_name(const Account *account)
Definition: Account.c:2913

◆ 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 1509 of file Split.c.

1510 {
1511  const char *ca, *cb;
1512  if (!sa && !sb) return 0;
1513  if (!sa) return -1;
1514  if (!sb) return 1;
1515 
1516  ca = xaccSplitGetCorrAccountCode(sa);
1517  cb = xaccSplitGetCorrAccountCode(sb);
1518  return g_strcmp0(ca, cb);
1519 }
const char * xaccSplitGetCorrAccountCode(const Split *sa)
Definition: Split.c:1435

◆ 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 1488 of file Split.c.

1489 {
1490  char *ca, *cb;
1491  int retval;
1492  if (!sa && !sb) return 0;
1493  if (!sa) return -1;
1494  if (!sb) return 1;
1495 
1496  /* doesn't matter what separator we use
1497  * as long as they are the same
1498  */
1499 
1502  retval = g_strcmp0(ca, cb);
1503  g_free(ca);
1504  g_free(cb);
1505  return retval;
1506 }
char * xaccSplitGetCorrAccountFullName(const Split *sa)
Definition: Split.c:1419

◆ 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 450 of file Split.c.

451 {
452  if (!from_split || !to_split) return;
453  xaccTransBeginEdit (to_split->parent);
454 
455  xaccSplitSetMemo(to_split, xaccSplitGetMemo(from_split));
456  xaccSplitSetAction(to_split, xaccSplitGetAction(from_split));
457  xaccSplitSetAmount(to_split, xaccSplitGetAmount(from_split));
458  xaccSplitSetValue(to_split, xaccSplitGetValue(from_split));
459  /* Setting the account is okay here because, even though the from
460  split might not really belong to the account it claims to,
461  setting the account won't cause any event involving from. */
462  xaccSplitSetAccount(to_split, xaccSplitGetAccount(from_split));
463  /* N.B. Don't set parent. */
464 
465  qof_instance_set_dirty(QOF_INSTANCE(to_split));
466  xaccTransCommitEdit(to_split->parent);
467 }
void xaccSplitSetValue(Split *s, gnc_numeric amt)
Definition: Split.c:1074
void xaccSplitSetAction(Split *split, const char *actn)
Definition: Split.c:1548
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
Definition: Split.c:1042
void xaccSplitSetMemo(Split *split, const char *memo)
Definition: Split.c:1529
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
const char * xaccSplitGetMemo(const Split *split)
Definition: Split.c:1723
const char * xaccSplitGetAction(const Split *split)
Definition: Split.c:1729
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

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

If the deletion of the split leaves the transaction with no splits, then the transaction will be marked for deletion. (It will not be deleted until the xaccTransCommitEdit() routine is called.)

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

Definition at line 1269 of file Split.c.

1270 {
1271  Account *acc;
1272  Transaction *trans;
1273  GncEventData ed;
1274 
1275  if (!split) return TRUE;
1276 
1277  acc = split->acc;
1278  trans = split->parent;
1279  if (acc && !qof_instance_get_destroying(acc)
1280  && xaccTransGetReadOnly(trans))
1281  return FALSE;
1282 
1283  xaccTransBeginEdit(trans);
1284  ed.node = split;
1285  ed.idx = xaccTransGetSplitIndex(trans, split);
1286  qof_instance_set_dirty(QOF_INSTANCE(split));
1287  qof_instance_set_destroying(split, TRUE);
1288  qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1289  xaccTransCommitEdit(trans);
1290 
1291  return TRUE;
1292 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
const char * xaccTransGetReadOnly(const Transaction *trans)
Definition: Transaction.c:2314
int xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Definition: Transaction.c:2136
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ 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_frame), then, when comparing the parenting transactions with xaccTransEqual(), set its argument check_splits to be TRUE.

Definition at line 579 of file Split.c.

583 {
584  gboolean same_book;
585 
586  if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
587 
588  if (!sa || !sb)
589  {
590  PINFO ("one is NULL");
591  return FALSE;
592  }
593 
594  if (sa == sb) return TRUE;
595 
596  same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
597 
598  if (check_guids)
599  {
600  if (qof_instance_guid_compare(sa, sb) != 0)
601  {
602  PINFO ("GUIDs differ");
603  return FALSE;
604  }
605  }
606 
607  /* If the same book, since these strings are cached we can just use pointer equality */
608  if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
609  {
610  PINFO ("memos differ: (%p)%s vs (%p)%s",
611  sa->memo, sa->memo, sb->memo, sb->memo);
612  return FALSE;
613  }
614 
615  if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
616  {
617  PINFO ("actions differ: %s vs %s", sa->action, sb->action);
618  return FALSE;
619  }
620 
621  if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
622  {
623  char *frame_a;
624  char *frame_b;
625 
626  frame_a = kvp_frame_to_string (sa->inst.kvp_data);
627  frame_b = kvp_frame_to_string (sb->inst.kvp_data);
628 
629  PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
630 
631  g_free (frame_a);
632  g_free (frame_b);
633 
634  return FALSE;
635  }
636 
637  if (sa->reconciled != sb->reconciled)
638  {
639  PINFO ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
640  return FALSE;
641  }
642 
643  if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
644  {
645  PINFO ("reconciled date differs");
646  return FALSE;
647  }
648 
650  {
651  char *str_a;
652  char *str_b;
653 
656 
657  PINFO ("amounts differ: %s vs %s", str_a, str_b);
658 
659  g_free (str_a);
660  g_free (str_b);
661 
662  return FALSE;
663  }
664 
666  {
667  char *str_a;
668  char *str_b;
669 
672 
673  PINFO ("values differ: %s vs %s", str_a, str_b);
674 
675  g_free (str_a);
676  g_free (str_b);
677 
678  return FALSE;
679  }
680 
681  if (check_balances)
682  {
683  if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
684  return FALSE;
685  if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
686  sb->cleared_balance))
687  return FALSE;
688  if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
689  sb->reconciled_balance))
690  return FALSE;
691  }
692 
693  if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
694  check_balances, FALSE))
695  {
696  PINFO ("transactions differ");
697  return FALSE;
698  }
699 
700  return TRUE;
701 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
#define PINFO(format, args...)
Definition: qoflog.h:244
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
Definition: kvp_frame.c:1427
gchar * gnc_numeric_to_string(gnc_numeric n)
Definition: gnc-numeric.c:1371
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
Definition: gnc-date.c:593
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
Definition: Transaction.c:779
gchar * kvp_frame_to_string(const KvpFrame *frame)
Definition: kvp_frame.c:1620
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Definition: gnc-numeric.c:293
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ xaccSplitGetAccount()

Account* xaccSplitGetAccount ( const Split *  split)

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

Definition at line 732 of file Split.c.

733 {
734  return s ? s->acc : NULL;
735 }

◆ 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 1729 of file Split.c.

1730 {
1731  return split ? split->action : NULL;
1732 }

◆ 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 1742 of file Split.c.

1743 {
1744  return split ? split->amount : gnc_numeric_zero();
1745 }

◆ 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 1102 of file Split.c.

1103 {
1104  return s ? s->balance : gnc_numeric_zero();
1105 }

◆ 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 1175 of file Split.c.

1176 {
1177  if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
1178 
1179  /* be more precise -- the value depends on the currency we want it
1180  * expressed in. */
1181  if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
1182  return xaccSplitGetValue(s);
1183  if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
1184  return xaccSplitGetAmount(s);
1185 
1186  PERR ("inappropriate base currency %s "
1187  "given split currency=%s and commodity=%s\n",
1188  gnc_commodity_get_printname(base_currency),
1191  return gnc_numeric_zero();
1192 }
#define PERR(format, args...)
Definition: qoflog.h:232
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3034
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Definition: Transaction.c:1268
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ xaccSplitGetBook()

QofBook* xaccSplitGetBook ( const Split *  split)

Returns the book of this split, i.e. the entity where this split is stored.

Definition at line 1797 of file Split.c.

1798 {
1799  return qof_instance_get_book(QOF_INSTANCE(split));
1800 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548

◆ 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 1108 of file Split.c.

1109 {
1110  return s ? s->cleared_balance : gnc_numeric_zero();
1111 }

◆ xaccSplitGetCorrAccountCode()

const char* xaccSplitGetCorrAccountCode ( const Split *  sa)

document me

Definition at line 1435 of file Split.c.

1436 {
1437  static const char *split_const = NULL;
1438  const Split *other_split;
1439 
1440  if (!get_corr_account_split(sa, &other_split))
1441  {
1442  if (!split_const)
1443  /* Translators: This string has a disambiguation prefix */
1444  split_const = Q_("Displayed account code of the other account in a multi-split transaction|Split");
1445 
1446  return split_const;
1447  }
1448  return xaccAccountGetCode(other_split->acc);
1449 }
const char * xaccAccountGetCode(const Account *acc)
Definition: Account.c:2961

◆ 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 1419 of file Split.c.

1420 {
1421  static const char *split_const = NULL;
1422  const Split *other_split;
1423 
1424  if (!get_corr_account_split(sa, &other_split))
1425  {
1426  if (!split_const)
1427  split_const = _("-- Split Transaction --");
1428 
1429  return g_strdup(split_const);
1430  }
1431  return gnc_account_get_full_name(other_split->acc);
1432 }
gchar * gnc_account_get_full_name(const Account *account)
Definition: Account.c:2913

◆ xaccSplitGetCorrAccountName()

const char* xaccSplitGetCorrAccountName ( const Split *  sa)

document me

Definition at line 1402 of file Split.c.

1403 {
1404  static const char *split_const = NULL;
1405  const Split *other_split;
1406 
1407  if (!get_corr_account_split(sa, &other_split))
1408  {
1409  if (!split_const)
1410  split_const = _("-- Split Transaction --");
1411 
1412  return split_const;
1413  }
1414 
1415  return xaccAccountGetName(other_split->acc);
1416 }
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:2906

◆ xaccSplitGetDateReconciled()

time64 xaccSplitGetDateReconciled ( const Split *  split)

Retrieve the date when the Split was reconciled.

Definition at line 1647 of file Split.c.

1648 {
1649  return split ? split->date_reconciled.tv_sec : 0;
1650 }

◆ xaccSplitGetDateReconciledTS()

void xaccSplitGetDateReconciledTS ( const Split *  split,
Timespec *  ts 
)

Get the date on which this split was reconciled by having it written into the Timespec that 'ts' is pointing to.

Definition at line 1632 of file Split.c.

1633 {
1634  if (!split || !ts) return;
1635  *ts = (split->date_reconciled);
1636 }

◆ 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 1708 of file Split.c.

1709 {
1710  return split ? split->lot : NULL;
1711 }

◆ xaccSplitGetMemo()

const char* xaccSplitGetMemo ( const Split *  split)

Returns the memo string.

Definition at line 1723 of file Split.c.

1724 {
1725  return split ? split->memo : NULL;
1726 }

◆ 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 1841 of file Split.c.

1842 {
1843  int i;
1844  Transaction *trans;
1845  int count, num_splits;
1846  Split *other = NULL;
1847  KvpValue *sva;
1848  gboolean trading_accts;
1849 
1850  if (!split) return NULL;
1851  trans = split->parent;
1852  if (!trans) return NULL;
1853 
1854 #ifdef OLD_ALGO_HAS_ONLY_TWO_SPLITS
1855  Split *s1, *s2;
1856  if (g_list_length (trans->splits) != 2) return NULL;
1857 
1858  s1 = g_list_nth_data (trans->splits, 0);
1859  s2 = g_list_nth_data (trans->splits, 1);
1860 
1861  if (s1 == split) return s2;
1862  return s1;
1863 #endif
1864 
1865  trading_accts = xaccTransUseTradingAccounts (trans);
1866  num_splits = xaccTransCountSplits(trans);
1867  count = num_splits;
1868  sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
1869  if (!sva && !trading_accts && (2 != count)) return NULL;
1870 
1871  for (i = 0; i < num_splits; i++)
1872  {
1873  Split *s = xaccTransGetSplit(trans, i);
1874  if (s == split)
1875  {
1876  --count;
1877  continue;
1878  }
1879  if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
1880  {
1881  --count;
1882  continue;
1883  }
1884  if (trading_accts &&
1886  {
1887  --count;
1888  continue;
1889  }
1890  other = s;
1891  }
1892  return (1 == count) ? other : NULL;
1893 }
Split * xaccTransGetSplit(const Transaction *trans, int i)
Definition: Transaction.c:2126
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Definition: Transaction.c:935
GNCAccountType xaccAccountGetType(const Account *acc)
Definition: Account.c:2884
int xaccTransCountSplits(const Transaction *trans)
Definition: Transaction.c:2174
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732

◆ xaccSplitGetParent()

Transaction* xaccSplitGetParent ( const Split *  split)

Returns the parent transaction of the split.

Definition at line 1658 of file Split.c.

1659 {
1660  return split ? split->parent : NULL;
1661 }

◆ xaccSplitGetReconcile()

char xaccSplitGetReconcile ( const Split *  split)

Returns the value of the reconcile flag.

Definition at line 1735 of file Split.c.

1736 {
1737  return split ? split->reconciled : ' ';
1738 }

◆ 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 1114 of file Split.c.

1115 {
1116  return s ? s->reconciled_balance : gnc_numeric_zero();
1117 }

◆ 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 1754 of file Split.c.

1755 {
1756  gnc_numeric amt, val, price;
1757  if (!split) return gnc_numeric_create(1, 1);
1758 
1759 
1760  /* if amount == 0 and value == 0, then return 1.
1761  * if amount == 0 and value != 0 then return 0.
1762  * otherwise return value/amount
1763  */
1764 
1765  amt = xaccSplitGetAmount(split);
1766  val = xaccSplitGetValue(split);
1767  if (gnc_numeric_zero_p(amt))
1768  {
1769  if (gnc_numeric_zero_p(val))
1770  return gnc_numeric_create(1, 1);
1771  return gnc_numeric_create(0, 1);
1772  }
1773  price = gnc_numeric_div(val, amt,
1775  GNC_HOW_DENOM_SIGFIGS(PRICE_SIGFIGS) |
1777 
1778  /* During random checks we can get some very weird prices. Let's
1779  * handle some overflow and other error conditions by returning
1780  * zero. But still print an error to let us know it happened.
1781  */
1782  if (gnc_numeric_check(price))
1783  {
1784  PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
1785  G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
1786  gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
1787  return gnc_numeric_create(0, 1);
1788  }
1789 
1790  return price;
1791 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Definition: gnc-numeric.c:173
#define PERR(format, args...)
Definition: qoflog.h:232
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:612
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Definition: gnc-numeric.c:83
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242
#define GNC_HOW_DENOM_SIGFIGS(n)
Definition: gnc-numeric.h:214
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ xaccSplitGetSlots()

KvpFrame* xaccSplitGetSlots ( const Split *  split)

Returns the KvpFrame slots of this split for direct editing.

Split slots are used to store arbitrary strings, numbers, and structures which aren't members of the transaction struct. See kvp_doc.txt for reserved slot names.

Definition at line 961 of file Split.c.

962 {
963  return qof_instance_get_slots(QOF_INSTANCE(s));
964 }
KvpFrame * qof_instance_get_slots(const QofInstance *inst)
Definition: qofinstance.c:586

◆ xaccSplitGetType()

const char* xaccSplitGetType ( const Split *  s)

The xaccIsPeerSplit() is a convenience routine that returns TRUE (a non-zero value) if the two splits share a common parent transaction, else it returns FALSE (zero).

gboolean xaccIsPeerSplit (const Split *split_1, const Split *split_2); Returns the split type, which is either the string "normal", or "stock-split" for a split from a stock split (pun intended? :-).

Definition at line 1803 of file Split.c.

1804 {
1805  const char *split_type;
1806 
1807  if (!s) return NULL;
1808  split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
1809  return split_type ? split_type : "normal";
1810 }

◆ 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 1748 of file Split.c.

1749 {
1750  return split ? split->value : gnc_numeric_zero();
1751 }

◆ 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 868 of file Split.c.

869 {
870  QofCollection *col;
871  if (!guid || !book) return NULL;
872  col = qof_book_get_collection (book, GNC_ID_SPLIT);
873  return (Split *) qof_collection_lookup_entity (col, guid);
874 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Definition: qofid.c:211
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306

◆ 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 1815 of file Split.c.

1816 {
1817  xaccTransBeginEdit (s->parent);
1818 
1819  s->value = gnc_numeric_zero();
1820  kvp_frame_set_str(s->inst.kvp_data, "split-type", "stock-split");
1821  SET_GAINS_VDIRTY(s);
1822  mark_split(s);
1823  qof_instance_set_dirty(QOF_INSTANCE(s));
1824  xaccTransCommitEdit(s->parent);
1825 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define kvp_frame_set_str
Definition: kvp_frame.h:174

◆ 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 1298 of file Split.c.

1299 {
1300  int retval;
1301  int comp;
1302  char *da, *db;
1303  gboolean action_for_num;
1304 
1305  if (sa == sb) return 0;
1306  /* nothing is always less than something */
1307  if (!sa) return -1;
1308  if (!sb) return +1;
1309 
1310  /* sort in transaction order, but use split action rather than trans num
1311  * according to book option */
1313  (xaccSplitGetBook (sa));
1314  if (action_for_num)
1315  retval = xaccTransOrder_num_action (sa->parent, sa->action,
1316  sb->parent, sb->action);
1317  else
1318  retval = xaccTransOrder (sa->parent, sb->parent);
1319  if (retval) return retval;
1320 
1321  /* otherwise, sort on memo strings */
1322  da = sa->memo ? sa->memo : "";
1323  db = sb->memo ? sb->memo : "";
1324  retval = g_utf8_collate (da, db);
1325  if (retval)
1326  return retval;
1327 
1328  /* otherwise, sort on action strings */
1329  da = sa->action ? sa->action : "";
1330  db = sb->action ? sb->action : "";
1331  retval = g_utf8_collate (da, db);
1332  if (retval != 0)
1333  return retval;
1334 
1335  /* the reconciled flag ... */
1336  if (sa->reconciled < sb->reconciled) return -1;
1337  if (sa->reconciled > sb->reconciled) return +1;
1338 
1339  /* compare amounts */
1341  if (comp < 0) return -1;
1342  if (comp > 0) return +1;
1343 
1345  if (comp < 0) return -1;
1346  if (comp > 0) return +1;
1347 
1348  /* if dates differ, return */
1349  DATE_CMP(sa, sb, date_reconciled);
1350 
1351  /* else, sort on guid - keeps sort stable. */
1352  retval = qof_instance_guid_compare(sa, sb);
1353  if (retval) return retval;
1354 
1355  return 0;
1356 }
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Definition: qofbook.c:713
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Definition: gnc-numeric.c:246
QofBook * xaccSplitGetBook(const Split *split)
Definition: Split.c:1797
int xaccTransOrder_num_action(const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
Definition: Transaction.c:1809
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
Definition: Transaction.c:1803
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ xaccSplitRetDateReconciledTS()

Timespec xaccSplitRetDateReconciledTS ( const Split *  split)

Returns the date (as Timespec) on which this split was reconciled.

Definition at line 1639 of file Split.c.

1640 {
1641  Timespec ts = {0, 0};
1642  return split ? split->date_reconciled : ts;
1643 }

◆ 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 1548 of file Split.c.

1549 {
1550  if (!split || !actn) return;
1551  xaccTransBeginEdit (split->parent);
1552 
1553  CACHE_REPLACE(split->action, actn);
1554  qof_instance_set_dirty(QOF_INSTANCE(split));
1555  xaccTransCommitEdit(split->parent);
1556 
1557 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 1042 of file Split.c.

1043 {
1044  if (!s) return;
1045  g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
1046  ENTER ("(split=%p) old amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
1047  " new amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
1048  s->amount.num, s->amount.denom, amt.num, amt.denom);
1049 
1050  xaccTransBeginEdit (s->parent);
1051  if (s->acc)
1052  s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
1054  else
1055  s->amount = amt;
1056 
1057  SET_GAINS_ADIRTY(s);
1058  mark_split (s);
1059  qof_instance_set_dirty(QOF_INSTANCE(s));
1060  xaccTransCommitEdit(s->parent);
1061  LEAVE("");
1062 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
Definition: gnc-numeric.c:774
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define LEAVE(format, args...)
Definition: qoflog.h:266
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Definition: gnc-numeric.c:83

◆ 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 1120 of file Split.c.

1122 {
1123  const gnc_commodity *currency;
1124  const gnc_commodity *commodity;
1125 
1126  if (!s) return;
1127  xaccTransBeginEdit (s->parent);
1128 
1129  if (!s->acc)
1130  {
1131  PERR ("split must have a parent account");
1132  return;
1133  }
1134 
1135  currency = xaccTransGetCurrency (s->parent);
1136  commodity = xaccAccountGetCommodity (s->acc);
1137 
1138  /* If the base_currency is the transaction's commodity ('currency'),
1139  * set the value. If it's the account commodity, set the
1140  * amount. If both, set both. */
1141  if (gnc_commodity_equiv(currency, base_currency))
1142  {
1143  if (gnc_commodity_equiv(commodity, base_currency))
1144  {
1145  s->amount = gnc_numeric_convert(value,
1146  get_commodity_denom(s),
1148  }
1149  s->value = gnc_numeric_convert(value,
1150  get_currency_denom(s),
1152  }
1153  else if (gnc_commodity_equiv(commodity, base_currency))
1154  {
1155  s->amount = gnc_numeric_convert(value, get_commodity_denom(s),
1157  }
1158  else
1159  {
1160  PERR ("inappropriate base currency %s "
1161  "given split currency=%s and commodity=%s\n",
1162  gnc_commodity_get_printname(base_currency),
1163  gnc_commodity_get_printname(currency),
1164  gnc_commodity_get_printname(commodity));
1165  return;
1166  }
1167 
1168  SET_GAINS_A_VDIRTY(s);
1169  mark_split (s);
1170  qof_instance_set_dirty(QOF_INSTANCE(s));
1171  xaccTransCommitEdit(s->parent);
1172 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define PERR(format, args...)
Definition: qoflog.h:232
gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
Definition: gnc-numeric.c:774
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3034
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Definition: Transaction.c:1268
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)

◆ 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 1607 of file Split.c.

1608 {
1609  if (!split) return;
1610  xaccTransBeginEdit (split->parent);
1611 
1612  split->date_reconciled.tv_sec = secs;
1613  split->date_reconciled.tv_nsec = 0;
1614  qof_instance_set_dirty(QOF_INSTANCE(split));
1615  xaccTransCommitEdit(split->parent);
1616 
1617 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ xaccSplitSetDateReconciledTS()

void xaccSplitSetDateReconciledTS ( Split *  split,
Timespec *  ts 
)

Set the date on which this split was reconciled by specifying the time as Timespec. Caller still owns *ts!

Definition at line 1620 of file Split.c.

1621 {
1622  if (!split || !ts) return;
1623  xaccTransBeginEdit (split->parent);
1624 
1625  split->date_reconciled = *ts;
1626  qof_instance_set_dirty(QOF_INSTANCE(split));
1627  xaccTransCommitEdit(split->parent);
1628 
1629 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ xaccSplitSetLot()

void xaccSplitSetLot ( Split *  split,
GNCLot *  lot 
)

Assigns the split to a specific Lot

Definition at line 1714 of file Split.c.

1715 {
1716  xaccTransBeginEdit (split->parent);
1717  split->lot = lot;
1718  qof_instance_set_dirty(QOF_INSTANCE(split));
1719  xaccTransCommitEdit(split->parent);
1720 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 1529 of file Split.c.

1530 {
1531  if (!split || !memo) return;
1532  xaccTransBeginEdit (split->parent);
1533 
1534  CACHE_REPLACE(split->memo, memo);
1535  qof_instance_set_dirty(QOF_INSTANCE(split));
1536  xaccTransCommitEdit(split->parent);
1537 
1538 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 1581 of file Split.c.

1582 {
1583  if (!split || split->reconciled == recn) return;
1584  xaccTransBeginEdit (split->parent);
1585 
1586  switch (recn)
1587  {
1588  case NREC:
1589  case CREC:
1590  case YREC:
1591  case FREC:
1592  case VREC:
1593  split->reconciled = recn;
1594  mark_split (split);
1595  qof_instance_set_dirty(QOF_INSTANCE(split));
1596  xaccAccountRecomputeBalance (split->acc);
1597  break;
1598  default:
1599  PERR("Bad reconciled flag");
1600  break;
1601  }
1602  xaccTransCommitEdit(split->parent);
1603 
1604 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define PERR(format, args...)
Definition: qoflog.h:232
#define VREC
Definition: Split.h:71
#define YREC
Definition: Split.h:68
#define FREC
Definition: Split.h:69
void xaccAccountRecomputeBalance(Account *acc)
Definition: Account.c:1921
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define CREC
Definition: Split.h:67
#define NREC
Definition: Split.h:70

◆ 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 1008 of file Split.c.

1009 {
1010  if (!s) return;
1011  ENTER (" ");
1012  xaccTransBeginEdit (s->parent);
1013 
1014  s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
1015  price, get_currency_denom(s),
1017 
1018  SET_GAINS_VDIRTY(s);
1019  mark_split (s);
1020  qof_instance_set_dirty(QOF_INSTANCE(s));
1021  xaccTransCommitEdit(s->parent);
1022  LEAVE ("");
1023 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:492
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define LEAVE(format, args...)
Definition: qoflog.h:266
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ 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 980 of file Split.c.

981 {
982  if (!s) return;
983  ENTER (" ");
984  xaccTransBeginEdit (s->parent);
985 
986  s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
988  s->value = gnc_numeric_mul(s->amount, price,
989  get_currency_denom(s), GNC_HOW_RND_ROUND_HALF_UP);
990 
991  SET_GAINS_A_VDIRTY(s);
992  mark_split (s);
993  qof_instance_set_dirty(QOF_INSTANCE(s));
994  xaccTransCommitEdit(s->parent);
995  LEAVE ("");
996 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
Definition: gnc-numeric.c:774
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:492
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ xaccSplitSetSlots_nc()

void xaccSplitSetSlots_nc ( Split *  s,
KvpFrame *  frm 
)

Set the KvpFrame slots of this split to the given frm by directly using the frm pointer (i.e. non-copying).

Definition at line 967 of file Split.c.

968 {
969  if (!s || !frm) return;
970  xaccTransBeginEdit(s->parent);
971  qof_instance_set_slots(QOF_INSTANCE(s), frm);
972  xaccTransCommitEdit(s->parent);
973 
974 }
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 1074 of file Split.c.

1075 {
1076  gnc_numeric new_val;
1077  if (!s) return;
1078 
1079  g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
1080  ENTER ("(split=%p) old val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
1081  " new val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
1082  s->value.num, s->value.denom, amt.num, amt.denom);
1083 
1084  xaccTransBeginEdit (s->parent);
1085  new_val = gnc_numeric_convert(amt, get_currency_denom(s),
1087  if (gnc_numeric_check(new_val) == GNC_ERROR_OK)
1088  s->value = new_val;
1089  else PERR("numeric error %s in converting the split value's denominator with amount %s and denom %d", gnc_numeric_errorCode_to_string(gnc_numeric_check(new_val)), gnc_numeric_to_string(amt), get_currency_denom(s));
1090 
1091  SET_GAINS_VDIRTY(s);
1092  mark_split (s);
1093  qof_instance_set_dirty(QOF_INSTANCE(s));
1094  xaccTransCommitEdit(s->parent);
1095  LEAVE ("");
1096 }
gchar * gnc_numeric_to_string(gnc_numeric n)
Definition: gnc-numeric.c:1371
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define PERR(format, args...)
Definition: qoflog.h:232
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
Definition: gnc-numeric.c:774
const char * gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
Definition: gnc-numeric.c:1522
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define LEAVE(format, args...)
Definition: qoflog.h:266
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Definition: gnc-numeric.c:83

◆ 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 1899 of file Split.c.

1900 {
1901  g_return_val_if_fail(split, gnc_numeric_zero());
1902  return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
1903 }

◆ 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 1906 of file Split.c.

1907 {
1908  g_return_val_if_fail(split, gnc_numeric_zero());
1909  return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
1910 }

◆ 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 1356 of file Transaction.c.

1357 {
1358  if (!trans) return;
1359  if (!qof_begin_edit(&trans->inst)) return;
1360 
1361  if (qof_book_shutting_down(qof_instance_get_book(trans))) return;
1362 
1364  {
1365  xaccOpenLog ();
1366  xaccTransWriteLog (trans, 'B');
1367  }
1368 
1369  /* Make a clone of the transaction; we will use this
1370  * in case we need to roll-back the edit. */
1371  trans->orig = xaccDupeTransaction (trans);
1372 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
void xaccTransWriteLog(Transaction *trans, char flag)
Definition: TransLog.c:221
gboolean qof_begin_edit(QofInstance *inst)
Definition: qofinstance.c:941
gboolean qof_book_is_readonly(const QofBook *book)
Definition: qofbook.c:291
gboolean qof_book_shutting_down(const QofBook *book)
Definition: qofbook.c:230

◆ xaccTransClone()

Transaction* xaccTransClone ( const Transaction *  t)

The xaccTransClone() method will create a complete copy of an existing transaction.

Definition at line 578 of file Transaction.c.

579 {
580  Transaction *to;
581  Split *split;
582  GList *node;
583 
585  to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
586 
587  to->date_entered = from->date_entered;
588  to->date_posted = from->date_posted;
589  to->num = CACHE_INSERT (from->num);
590  to->description = CACHE_INSERT (from->description);
591  to->common_currency = from->common_currency;
592  qof_instance_copy_version(to, from);
594 
595  to->orig = NULL;
596 
597  qof_instance_init_data (&to->inst, GNC_ID_TRANS, qof_instance_get_book(from));
598  kvp_frame_delete (to->inst.kvp_data);
599  to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
600 
601  xaccTransBeginEdit(to);
602  for (node = from->splits; node; node = node->next)
603  {
604  split = xaccSplitClone(node->data);
605  split->parent = to;
606  to->splits = g_list_append (to->splits, split);
607  }
608  qof_instance_set_dirty(QOF_INSTANCE(to));
611 
612  return to;
613 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
Definition: kvp_frame.c:151
void qof_instance_copy_version(gpointer to, gconstpointer from)
Definition: qofinstance.c:754
void qof_instance_copy_version_check(gpointer to, gconstpointer from)
Definition: qofinstance.c:776
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void kvp_frame_delete(KvpFrame *frame)
Definition: kvp_frame.c:116
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Definition: qofinstance.c:282
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
void qof_event_suspend(void)
Suspend all engine events.
Definition: qofevent.c:144
void qof_event_resume(void)
Definition: qofevent.c:155

◆ 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 1555 of file Transaction.c.

1556 {
1557  if (!trans) return;
1558  ENTER ("(trans=%p)", trans);
1559 
1560  if (!qof_commit_edit (QOF_INSTANCE(trans)))
1561  {
1562  LEAVE("editlevel non-zero");
1563  return;
1564  }
1565 
1566  /* We increment this for the duration of the call
1567  * so other functions don't result in a recursive
1568  * call to xaccTransCommitEdit. */
1569  qof_instance_increase_editlevel(trans);
1570 
1571  if (was_trans_emptied(trans))
1572  qof_instance_set_destroying(trans, TRUE);
1573 
1574  /* Before committing the transaction, we are going to enforce certain
1575  * constraints. In particular, we want to enforce the cap-gains
1576  * and the balanced lot constraints. These constraints might
1577  * change the number of splits in this transaction, and the
1578  * transaction itself might be deleted. This is also why
1579  * we can't really enforce these constraints elsewhere: they
1580  * can cause pointers to splits and transactions to disappear out
1581  * from under the holder.
1582  */
1583  if (!qof_instance_get_destroying(trans) && scrub_data &&
1585  {
1586  /* If scrubbing gains recurses through here, don't call it again. */
1587  scrub_data = 0;
1588  /* The total value of the transaction should sum to zero.
1589  * Call the trans scrub routine to fix it. Indirectly, this
1590  * routine also performs a number of other transaction fixes too.
1591  */
1592  xaccTransScrubImbalance (trans, NULL, NULL);
1593  /* Get the cap gains into a consistent state as well. */
1594 
1595  /* Lot Scrubbing is temporarily disabled. */
1596  if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
1597  xaccTransScrubGains (trans, NULL);
1598 
1599  /* Allow scrubbing in transaction commit again */
1600  scrub_data = 1;
1601  }
1602 
1603  /* Record the time of last modification */
1604  if (0 == trans->date_entered.tv_sec)
1605  {
1606  struct timeval tv;
1607 #ifdef HAVE_GETTIMEOFDAY
1608  gettimeofday (&tv, NULL);
1609 #else
1610  time (&(tv.tv_sec));
1611  tv.tv_usec = 0;
1612 #endif
1613  trans->date_entered.tv_sec = tv.tv_sec;
1614 // trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
1615  qof_instance_set_dirty(QOF_INSTANCE(trans));
1616  }
1617 
1618  qof_commit_edit_part2(QOF_INSTANCE(trans),
1619  (void (*) (QofInstance *, QofBackendError))
1620  trans_on_error,
1621  (void (*) (QofInstance *)) trans_cleanup_commit,
1622  (void (*) (QofInstance *)) do_destroy);
1623  LEAVE ("(trans=%p)", trans);
1624 }
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:55
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660
gboolean qof_commit_edit(QofInstance *inst)
Definition: qofinstance.c:963
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define ENTER(format, args...)
Definition: qoflog.h:256
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667
void xaccTransScrubImbalance(Transaction *trans, Account *root, Account *account)
Definition: Scrub.c:802
void xaccTransScrubGains(Transaction *trans, Account *gain_acc)
Definition: Transaction.c:2680
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
Definition: qofinstance.c:982
#define xaccTransGetBook(X)
Definition: Transaction.h:762
#define LEAVE(format, args...)
Definition: qoflog.h:266
gboolean qof_book_shutting_down(const QofBook *book)
Definition: qofbook.c:230

◆ 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 662 of file Transaction.c.

664 {
665  Timespec ts = {0,0};
666  gboolean change_accounts = FALSE;
667  GList *node;
668 
669  if (!from_trans || !to_trans)
670  return;
671 
672  change_accounts = from_acc && GNC_IS_ACCOUNT(to_acc) && from_acc != to_acc;
673  xaccTransBeginEdit(to_trans);
674 
675  FOR_EACH_SPLIT(to_trans, xaccSplitDestroy(s));
676  g_list_free(to_trans->splits);
677  to_trans->splits = NULL;
678 
679  xaccTransSetCurrency(to_trans, xaccTransGetCurrency(from_trans));
680  xaccTransSetDescription(to_trans, xaccTransGetDescription(from_trans));
681 
682  if ((xaccTransGetNum(to_trans) == NULL) || (g_strcmp0 (xaccTransGetNum(to_trans), "") == 0))
683  xaccTransSetNum(to_trans, xaccTransGetNum(from_trans));
684 
685  xaccTransSetNotes(to_trans, xaccTransGetNotes(from_trans));
686  if(!no_date)
687  {
688  xaccTransGetDatePostedTS(from_trans, &ts);
689  xaccTransSetDatePostedTS(to_trans, &ts);
690  }
691 
692  /* Each new split will be parented to 'to' */
693  for (node = from_trans->splits; node; node = node->next)
694  {
695  Split *new_split = xaccMallocSplit( qof_instance_get_book(QOF_INSTANCE(from_trans)));
696  xaccSplitCopyOnto(node->data, new_split);
697  if (change_accounts && xaccSplitGetAccount(node->data) == from_acc)
698  xaccSplitSetAccount(new_split, to_acc);
699  xaccSplitSetParent(new_split, to_trans);
700  }
701  xaccTransCommitEdit(to_trans);
702 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
gboolean xaccSplitDestroy(Split *split)
Definition: Split.c:1269
void xaccTransSetNotes(Transaction *trans, const char *notes)
Definition: Transaction.c:2097
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
Definition: Split.c:450
void xaccTransSetDescription(Transaction *trans, const char *desc)
Definition: Transaction.c:2067
void xaccTransSetNum(Transaction *trans, const char *xnum)
Definition: Transaction.c:2047
const char * xaccTransGetNum(const Transaction *trans)
Definition: Transaction.c:2182
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Definition: Transaction.c:1327
const char * xaccTransGetNotes(const Transaction *trans)
Definition: Transaction.c:2201
const char * xaccTransGetDescription(const Transaction *trans)
Definition: Transaction.c:2188
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
Split * xaccMallocSplit(QofBook *book)
Definition: Split.c:349
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Definition: Transaction.c:1268
void xaccTransGetDatePostedTS(const Transaction *trans, Timespec *ts)
Definition: Transaction.c:2233
void xaccTransSetDatePostedTS(Transaction *trans, const Timespec *ts)
Definition: Transaction.c:1946

◆ xaccTransCopyOnto()

void xaccTransCopyOnto ( const Transaction *  from_trans,
Transaction *  to_trans 
)

Copy a transaction to another using the function below without changing any account information.

Definition at line 638 of file Transaction.c.

639 {
640  xaccTransCopyFromClipBoard(from_trans, to_trans, NULL, NULL, TRUE);
641 }
void xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans, const Account *from_acc, Account *to_acc, gboolean no_date)
Definition: Transaction.c:662

◆ xaccTransCopyToClipBoard()

Transaction* xaccTransCopyToClipBoard ( const Transaction *  from_trans)

Copy a transaction to the 'clipboard' transaction using xaccDupeTransaction. The 'clipboard' transaction must never be dereferenced.

Definition at line 622 of file Transaction.c.

623 {
624  Transaction *to_trans;
625 
626  if (!from_trans)
627  return NULL;
628 
629  to_trans = xaccDupeTransaction(from_trans);
630  return to_trans;
631 }

◆ xaccTransCountSplits()

int xaccTransCountSplits ( const Transaction *  trans)

Returns the number of splits in this transaction.

Definition at line 2174 of file Transaction.c.

2175 {
2176  gint i = 0;
2177  FOR_EACH_SPLIT(trans, i++);
2178  return i;
2179 }

◆ 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 1378 of file Transaction.c.

1379 {
1380  if (!trans) return;
1381 
1382  if (!xaccTransGetReadOnly (trans) ||
1384  {
1385  xaccTransBeginEdit(trans);
1386  qof_instance_set_destroying(trans, TRUE);
1387  xaccTransCommitEdit(trans);
1388  }
1389 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
const char * xaccTransGetReadOnly(const Transaction *trans)
Definition: Transaction.c:2314
gboolean qof_book_shutting_down(const QofBook *book)
Definition: qofbook.c:230

◆ 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 transation 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 779 of file Transaction.c.

784 {
785  gboolean same_book;
786 
787  if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */
788 
789  if (!ta || !tb)
790  {
791  PINFO ("one is NULL");
792  return FALSE;
793  }
794 
795  if (ta == tb) return TRUE;
796 
797  same_book = qof_instance_get_book(QOF_INSTANCE(ta)) == qof_instance_get_book(QOF_INSTANCE(tb));
798 
799  if (check_guids)
800  {
801  if (qof_instance_guid_compare(ta, tb) != 0)
802  {
803  PINFO ("GUIDs differ");
804  return FALSE;
805  }
806  }
807 
808  if (!gnc_commodity_equal(ta->common_currency, tb->common_currency))
809  {
810  PINFO ("commodities differ %s vs %s",
811  gnc_commodity_get_unique_name (ta->common_currency),
812  gnc_commodity_get_unique_name (tb->common_currency));
813  return FALSE;
814  }
815 
816  if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
817  {
818  char buf1[100];
819  char buf2[100];
820 
821  (void)gnc_timespec_to_iso8601_buff(ta->date_entered, buf1);
822  (void)gnc_timespec_to_iso8601_buff(tb->date_entered, buf2);
823  PINFO ("date entered differs: '%s' vs '%s'", buf1, buf2);
824  return FALSE;
825  }
826 
827  if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
828  {
829  char buf1[100];
830  char buf2[100];
831 
832  (void)gnc_timespec_to_iso8601_buff(ta->date_posted, buf1);
833  (void)gnc_timespec_to_iso8601_buff(tb->date_posted, buf2);
834  PINFO ("date posted differs: '%s' vs '%s'", buf1, buf2);
835  return FALSE;
836  }
837 
838  /* If the same book, since we use cached strings, we can just compare pointer
839  * equality for num and description
840  */
841  if ((same_book && ta->num != tb->num) || (!same_book && g_strcmp0(ta->num, tb->num) != 0))
842  {
843  PINFO ("num differs: %s vs %s", ta->num, tb->num);
844  return FALSE;
845  }
846 
847  if ((same_book && ta->description != tb->description)
848  || (!same_book && g_strcmp0(ta->description, tb->description)))
849  {
850  PINFO ("descriptions differ: %s vs %s", ta->description, tb->description);
851  return FALSE;
852  }
853 
854  if (kvp_frame_compare(ta->inst.kvp_data, tb->inst.kvp_data) != 0)
855  {
856  char *frame_a;
857  char *frame_b;
858 
859  frame_a = kvp_frame_to_string (ta->inst.kvp_data);
860  frame_b = kvp_frame_to_string (tb->inst.kvp_data);
861 
862  PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
863 
864  g_free (frame_a);
865  g_free (frame_b);
866 
867  return FALSE;
868  }
869 
870  if (check_splits)
871  {
872  if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
873  {
874  PINFO ("only one has splits");
875  return FALSE;
876  }
877 
878  if (ta->splits && tb->splits)
879  {
880  GList *node_a, *node_b;
881 
882  for (node_a = ta->splits, node_b = tb->splits;
883  node_a;
884  node_a = node_a->next, node_b = node_b->next)
885  {
886  Split *split_a = node_a->data;
887  Split *split_b;
888 
889  /* don't presume that the splits are in the same order */
890  if (!assume_ordered)
891  node_b = g_list_find_custom (tb->splits, split_a,
892  compare_split_guids);
893 
894  if (!node_b)
895  {
896  PINFO ("first has split %s and second does not",
897  guid_to_string (xaccSplitGetGUID (split_a)));
898  return FALSE;
899  }
900 
901  split_b = node_b->data;
902 
903  if (!xaccSplitEqual (split_a, split_b, check_guids, check_balances,
904  FALSE))
905  {
906  char str_a[GUID_ENCODING_LENGTH + 1];
907  char str_b[GUID_ENCODING_LENGTH + 1];
908 
909  guid_to_string_buff (xaccSplitGetGUID (split_a), str_a);
910  guid_to_string_buff (xaccSplitGetGUID (split_b), str_b);
911 
912  PINFO ("splits %s and %s differ", str_a, str_b);
913  return FALSE;
914  }
915  }
916 
917  if (g_list_length (ta->splits) != g_list_length (tb->splits))
918  {
919  PINFO ("different number of splits");
920  return FALSE;
921  }
922  }
923  }
924 
925  return TRUE;
926 }
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
#define PINFO(format, args...)
Definition: qoflog.h:244
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
Definition: kvp_frame.c:1427
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Definition: Split.c:579
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
Definition: gnc-date.c:593
#define GUID_ENCODING_LENGTH
Definition: guid.h:71
const char * guid_to_string(const GncGUID *guid)
Definition: guid.c:656
#define xaccSplitGetGUID(X)
Definition: Split.h:542
gchar * kvp_frame_to_string(const KvpFrame *frame)
Definition: kvp_frame.c:1620
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)

◆ xaccTransGetAccountAmount()

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

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

Definition at line 1106 of file Transaction.c.

1107 {
1108  gnc_numeric total = gnc_numeric_zero ();
1109  if (!trans || !acc) return total;
1110 
1111  total = gnc_numeric_convert (total, xaccAccountGetCommoditySCU (acc),
1113  FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
1114  total = gnc_numeric_add_fixed(
1115  total, xaccSplitGetAmount(s)));
1116  return total;
1117 }
int xaccAccountGetCommoditySCU(const Account *acc)
Definition: Account.c:2333
gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
Definition: gnc-numeric.c:774
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ 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 1230 of file Transaction.c.

1232 {
1233  GList *node;
1234  Split *last_split = NULL;
1235 
1236  // Not really the appropriate error value.
1237  g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
1238 
1239  for (node = trans->splits; node; node = node->next)
1240  {
1241  Split *split = node->data;
1242 
1243  if (!xaccTransStillHasSplit(trans, split))
1244  continue;
1245  if (xaccSplitGetAccount(split) != account)
1246  continue;
1247 
1248  if (!last_split)
1249  {
1250  last_split = split;
1251  continue;
1252  }
1253 
1254  /* This test needs to correspond to the comparison function used when
1255  sorting the splits for computing the running balance. */
1256  if (xaccSplitOrder (last_split, split) < 0)
1257  last_split = split;
1258  }
1259 
1260  return xaccSplitGetBalance (last_split);
1261 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
Definition: Split.c:1298
gnc_numeric xaccSplitGetBalance(const Split *s)
Definition: Split.c:1102
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Definition: gnc-numeric.c:1272
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732

◆ 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 convienience to view everything at once.

Definition at line 1090 of file Transaction.c.

1092 {
1093  gnc_numeric total = gnc_numeric_zero ();
1094  if (!trans || !acc) return total;
1095 
1096  FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
1097 {
1098  total = gnc_numeric_add (total, xaccSplitGetValue (s),
1101  });
1102  return total;
1103 }
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:378
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242

◆ xaccTransGetAssociation()

const char* xaccTransGetAssociation ( const Transaction *  trans)

Gets the transaction association

Definition at line 2194 of file Transaction.c.

2195 {
2196  return trans ?
2197  kvp_frame_get_string (trans->inst.kvp_data, assoc_uri_str) : NULL;
2198 }

◆ 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 1268 of file Transaction.c.

1269 {
1270  return trans ? trans->common_currency : NULL;
1271 }

◆ 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 2219 of file Transaction.c.

2220 {
2221  return trans ? trans->date_posted.tv_sec : 0;
2222 }

◆ xaccTransGetDateDueTS()

void xaccTransGetDateDueTS ( const Transaction *  trans,
Timespec *  ts 
)

Dates and txn-type for A/R and A/P "invoice" postings

Definition at line 2281 of file Transaction.c.

2282 {
2283  KvpValue *value;
2284 
2285  if (!trans || !ts) return;
2286 
2287  value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP);
2288  if (value)
2289  *ts = kvp_value_get_timespec (value);
2290  else
2291  xaccTransGetDatePostedTS (trans, ts);
2292 }
void xaccTransGetDatePostedTS(const Transaction *trans, Timespec *ts)
Definition: Transaction.c:2233

◆ 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 2226 of file Transaction.c.

2227 {
2228  return trans ? trans->date_entered.tv_sec : 0;
2229 }

◆ xaccTransGetDateEnteredTS()

void xaccTransGetDateEnteredTS ( const Transaction *  trans,
Timespec *  ts 
)

Retrieve the date of when the transaction was entered. The entered date is the date when the register entry was made.

Definition at line 2240 of file Transaction.c.

2241 {
2242  if (trans && ts)
2243  *ts = trans->date_entered;
2244 }

◆ 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 2254 of file Transaction.c.

2255 {
2256  GDate result;
2257  g_date_clear (&result, 1);
2258  if (trans)
2259  {
2260  /* Can we look up this value in the kvp slot? If yes, use it
2261  * from there because it doesn't suffer from time zone
2262  * shifts. */
2263  const KvpValue* kvp_value =
2264  kvp_frame_get_slot(trans->inst.kvp_data, TRANS_DATE_POSTED);
2265  if (kvp_value)
2266  result = kvp_value_get_gdate(kvp_value);
2267  else
2269  }
2270  return result;
2271 }
#define kvp_value
Definition: kvp_frame.h:108
GDate timespec_to_gdate(Timespec ts)
Definition: gnc-date.c:1672
GDate kvp_value_get_gdate(const KvpValue *value)
Definition: kvp_frame.c:1187
Timespec xaccTransRetDatePostedTS(const Transaction *trans)
Definition: Transaction.c:2247

◆ xaccTransGetDatePostedTS()

void xaccTransGetDatePostedTS ( const Transaction *  trans,
Timespec *  ts 
)

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 2233 of file Transaction.c.

2234 {
2235  if (trans && ts)
2236  *ts = trans->date_posted;
2237 }

◆ xaccTransGetDescription()

const char* xaccTransGetDescription ( const Transaction *  trans)

Gets the transaction Description

Definition at line 2188 of file Transaction.c.

2189 {
2190  return trans ? trans->description : NULL;
2191 }

◆ xaccTransGetFirstAPARAcctSplit()

Split* xaccTransGetFirstAPARAcctSplit ( const Transaction *  trans)

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

Parameters
transThe transaction

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

Definition at line 2162 of file Transaction.c.

2163 {
2164  FOR_EACH_SPLIT (trans,
2165  const Account *account = xaccSplitGetAccount(s);
2167  return s;
2168  );
2169 
2170  return NULL;
2171 }
GNCAccountType xaccAccountGetType(const Account *acc)
Definition: Account.c:2884
gboolean xaccAccountIsAPARType(GNCAccountType t)
Definition: Account.c:4151
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732

◆ 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 2151 of file Transaction.c.

2152 {
2153  FOR_EACH_SPLIT (trans,
2154  const Account *account = xaccSplitGetAccount(s);
2156  return s;
2157  );
2158 
2159  return NULL;
2160 }
GNCAccountType xaccAccountGetType(const Account *acc)
Definition: Account.c:2884
gboolean gncBusinessIsPaymentAcctType(GNCAccountType type)
Definition: gncBusiness.c:92
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732

◆ 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 972 of file Transaction.c.

973 {
974  /* imbal_value is used if either (1) the transaction has a non currency
975  split or (2) all the splits are in the same currency. If there are
976  no non-currency splits and not all splits are in the same currency then
977  imbal_list is used to compute the imbalance. */
978  MonetaryList *imbal_list = NULL;
979  gnc_numeric imbal_value = gnc_numeric_zero();
980  gboolean trading_accts;
981 
982  if (!trans) return imbal_list;
983 
984  ENTER("(trans=%p)", trans);
985 
986  trading_accts = xaccTransUseTradingAccounts (trans);
987 
988  /* If using trading accounts and there is at least one split that is not
989  in the transaction currency or a split that has a price or exchange
990  rate other than 1, then compute the balance in each commodity in the
991  transaction. Otherwise (all splits are in the transaction's currency)
992  then compute the balance using the value fields.
993 
994  Optimize for the common case of only one currency and a balanced
995  transaction. */
996  FOR_EACH_SPLIT(trans,
997  {
998  gnc_commodity *commodity;
1000  if (trading_accts &&
1001  (imbal_list ||
1002  ! gnc_commodity_equiv(commodity, trans->common_currency) ||
1004  {
1005  /* Need to use (or already are using) a list of imbalances in each of
1006  the currencies used in the transaction. */
1007  if (! imbal_list)
1008  {
1009  /* All previous splits have been in the transaction's common
1010  currency, so imbal_value is in this currency. */
1011  imbal_list = gnc_monetary_list_add_value(imbal_list,
1012  trans->common_currency,
1013  imbal_value);
1014  }
1015  imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
1016  xaccSplitGetAmount(s));
1017  }
1018 
1019  /* Add it to the value accumulator in case we need it. */
1020  imbal_value = gnc_numeric_add(imbal_value, xaccSplitGetValue(s),
1022  } );
1023 
1024 
1025  if (!imbal_list && !gnc_numeric_zero_p(imbal_value))
1026  {
1027  /* Not balanced and no list, create one. If we found multiple currencies
1028  and no non-currency commodity then imbal_list will already exist and
1029  we won't get here. */
1030  imbal_list = gnc_monetary_list_add_value(imbal_list,
1031  trans->common_currency,
1032  imbal_value);
1033  }
1034 
1035  /* Delete all the zero entries from the list, perhaps leaving an
1036  empty list */
1037  imbal_list = gnc_monetary_list_delete_zeros(imbal_list);
1038 
1039  LEAVE("(trans=%p), imbal=%p", trans, imbal_list);
1040  return imbal_list;
1041 }
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Definition: gnc-numeric.c:304
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Definition: Transaction.c:935
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:378
gboolean gnc_numeric_zero_p(gnc_numeric a)
Definition: gnc-numeric.c:173
#define ENTER(format, args...)
Definition: qoflog.h:256
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3034
#define LEAVE(format, args...)
Definition: qoflog.h:266
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ 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 956 of file Transaction.c.

957 {
958  gnc_numeric imbal = gnc_numeric_zero();
959  if (!trans) return imbal;
960 
961  ENTER("(trans=%p)", trans);
962  /* Could use xaccSplitsComputeValue, except that we want to use
963  GNC_HOW_DENOM_EXACT */
964  FOR_EACH_SPLIT(trans, imbal =
967  LEAVE("(trans=%p) imbal=%s", trans, gnc_num_dbg_to_string(imbal));
968  return imbal;
969 }
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Definition: gnc-numeric.c:1383
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:378
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
#define LEAVE(format, args...)
Definition: qoflog.h:266
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242

◆ xaccTransGetIsClosingTxn()

gboolean xaccTransGetIsClosingTxn ( const Transaction *  trans)

Returns whether this transaction is a "closing transaction"

Definition at line 2208 of file Transaction.c.

2209 {
2210  return trans ?
2211  kvp_frame_get_gint64 (trans->inst.kvp_data, trans_is_closing_str)
2212  : FALSE;
2213 }

◆ 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 2201 of file Transaction.c.

2202 {
2203  return trans ?
2204  kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL;
2205 }

◆ xaccTransGetNum()

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

Definition at line 2182 of file Transaction.c.

2183 {
2184  return trans ? trans->num : NULL;
2185 }

◆ xaccTransGetReadOnly()

const char* xaccTransGetReadOnly ( const Transaction *  trans)

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

Definition at line 2314 of file Transaction.c.

2315 {
2316  /* XXX This flag should be cached in the transaction structure
2317  * for performance reasons, since its checked every trans commit.
2318  */
2319  return trans ? kvp_frame_get_string (
2320  trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
2321 }

◆ 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 2608 of file Transaction.c.

2609 {
2610  GncGUID *guid;
2611 
2612  g_return_val_if_fail(trans, NULL);
2613  guid = kvp_frame_get_guid(trans->inst.kvp_data, TRANS_REVERSED_BY);
2614  return xaccTransLookup(guid, qof_instance_get_book(trans));
2615 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
Definition: guid.h:54
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
Definition: Transaction.c:944

◆ xaccTransGetSplit()

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

The xaccTransGetSplit() method returns a pointer to each of the splits in this transaction.

Parameters
transThe transaction
iThe split number. Valid values for i are zero to (number_of__splits-1). An invalid value of i will cause NULL to be returned. A convenient way of cycling through all splits is to start at zero, and keep incrementing until a null value is returned.

Definition at line 2126 of file Transaction.c.

2127 {
2128  int j = 0;
2129  if (!trans || i < 0) return NULL;
2130 
2131  FOR_EACH_SPLIT(trans, { if (i == j) return s; j++; });
2132  return NULL;
2133 }

◆ xaccTransGetSplitIndex()

int xaccTransGetSplitIndex ( const Transaction *  trans,
const Split *  split 
)

Inverse of xaccTransGetSplit()

Definition at line 2136 of file Transaction.c.

2137 {
2138  int j = 0;
2139  g_return_val_if_fail(trans && split, -1);
2140 
2141  FOR_EACH_SPLIT(trans, { if (s == split) return j; j++; });
2142  return -1;
2143 }

◆ xaccTransGetSplitList()

SplitList* xaccTransGetSplitList ( const Transaction *  trans)

The xaccTransGetSplitList() method returns a GList of the splits in a 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 2146 of file Transaction.c.

2147 {
2148  return trans ? trans->splits : NULL;
2149 }

◆ xaccTransGetTxnType()

char xaccTransGetTxnType ( const Transaction *  trans)

Returns the Transaction Type

See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT

Definition at line 2303 of file Transaction.c.

2304 {
2305  const char *s;
2306  if (!trans) return TXN_TYPE_NONE;
2307  s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP);
2308  if (s) return *s;
2309 
2310  return TXN_TYPE_NONE;
2311 }
#define TXN_TYPE_NONE
Definition: Transaction.h:119

◆ 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 2532 of file Transaction.c.

2533 {
2534  g_return_val_if_fail(trans, NULL);
2535  return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str);
2536 }

◆ 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 2525 of file Transaction.c.

2526 {
2527  g_return_val_if_fail(trans, FALSE);
2528  return (kvp_frame_get_slot(trans->inst.kvp_data, void_reason_str) != NULL);
2529 }

◆ xaccTransGetVoidTime()

Timespec xaccTransGetVoidTime ( const Transaction *  tr)

Returns the time that a transaction was voided.

Parameters
trThe transaction in question.
Returns
A Timespec containing the time that this transaction was voided. Returns a time of zero upon error.

Definition at line 2539 of file Transaction.c.

2540 {
2541  const char *val;
2542  Timespec void_time = {0, 0};
2543 
2544  g_return_val_if_fail(tr, void_time);
2545 
2546  val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str);
2547  return val ? gnc_iso8601_to_timespec_gmt(val) : void_time;
2548 }
Timespec gnc_iso8601_to_timespec_gmt(const gchar *)

◆ xaccTransHasReconciledSplits()

gboolean xaccTransHasReconciledSplits ( const Transaction *  trans)

FIXME: document me

Definition at line 2424 of file Transaction.c.

2425 {
2426  return xaccTransHasReconciledSplitsByAccount (trans, NULL);
2427 }
gboolean xaccTransHasReconciledSplitsByAccount(const Transaction *trans, const Account *account)
Definition: Transaction.c:2395

◆ xaccTransHasReconciledSplitsByAccount()

gboolean xaccTransHasReconciledSplitsByAccount ( const Transaction *  trans,
const Account account 
)

FIXME: document me

Definition at line 2395 of file Transaction.c.

2397 {
2398  GList *node;
2399 
2400  for (node = xaccTransGetSplitList (trans); node; node = node->next)
2401  {
2402  Split *split = node->data;
2403 
2404  if (!xaccTransStillHasSplit(trans, split))
2405  continue;
2406  if (account && (xaccSplitGetAccount(split) != account))
2407  continue;
2408 
2409  switch (xaccSplitGetReconcile (split))
2410  {
2411  case YREC:
2412  case FREC:
2413  return TRUE;
2414 
2415  default:
2416  break;
2417  }
2418  }
2419 
2420  return FALSE;
2421 }
char xaccSplitGetReconcile(const Split *split)
Definition: Split.c:1735
#define YREC
Definition: Split.h:68
#define FREC
Definition: Split.h:69
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
SplitList * xaccTransGetSplitList(const Transaction *trans)
Definition: Transaction.c:2146

◆ xaccTransHasSplitsInState()

gboolean xaccTransHasSplitsInState ( const Transaction *  trans,
const char  state 
)

FIXME: document me

Definition at line 2454 of file Transaction.c.

2455 {
2456  return xaccTransHasSplitsInStateByAccount (trans, state, NULL);
2457 }
gboolean xaccTransHasSplitsInStateByAccount(const Transaction *trans, const char state, const Account *account)
Definition: Transaction.c:2431

◆ xaccTransHasSplitsInStateByAccount()

gboolean xaccTransHasSplitsInStateByAccount ( const Transaction *  trans,
const char  state,
const Account account 
)

FIXME: document me

Definition at line 2431 of file Transaction.c.

2434 {
2435  GList *node;
2436 
2437  for (node = xaccTransGetSplitList (trans); node; node = node->next)
2438  {
2439  Split *split = node->data;
2440 
2441  if (!xaccTransStillHasSplit(trans, split))
2442  continue;
2443  if (account && (xaccSplitGetAccount(split) != account))
2444  continue;
2445 
2446  if (split->reconciled == state)
2447  return TRUE;
2448  }
2449 
2450  return FALSE;
2451 }
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
SplitList * xaccTransGetSplitList(const Transaction *trans)
Definition: Transaction.c:2146

◆ xaccTransInFutureByPostedDate()

gboolean xaccTransInFutureByPostedDate ( const Transaction *  trans)

Returns TRUE if this Transaction's posted-date is in the future

Definition at line 2376 of file Transaction.c.

2377 {
2378  time64 present;
2379  gboolean result;
2380  g_assert(trans);
2381 
2382  present = gnc_time64_get_today_end ();
2383 
2384  if (trans->date_posted.tv_sec > present)
2385  result = TRUE;
2386  else
2387  result = FALSE;
2388 
2389  return result;
2390 }
time64 gnc_time64_get_today_end(void)
Definition: gnc-date.c:1772
gint64 time64
Definition: gnc-date.h:79

◆ xaccTransIsBalanced()

gboolean xaccTransIsBalanced ( const Transaction *  trans)

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

Definition at line 1044 of file Transaction.c.

1045 {
1046  MonetaryList *imbal_list;
1047  gboolean result;
1048  gnc_numeric imbal = gnc_numeric_zero();
1049  gnc_numeric imbal_trading = gnc_numeric_zero();
1050 
1051  if (trans == NULL) return FALSE;
1052 
1053  if (xaccTransUseTradingAccounts(trans))
1054  {
1055  /* Transaction is imbalanced if the value is imbalanced in either
1056  trading or non-trading splits. One can't be used to balance
1057  the other. */
1058  FOR_EACH_SPLIT(trans,
1059  {
1060  Account *acc = xaccSplitGetAccount(s);
1061  if (!acc || xaccAccountGetType(acc) != ACCT_TYPE_TRADING)
1062  {
1063  imbal = gnc_numeric_add(imbal, xaccSplitGetValue(s),
1065  }
1066  else
1067  {
1068  imbal_trading = gnc_numeric_add(imbal_trading, xaccSplitGetValue(s),
1070  }
1071  }
1072  );
1073  }
1074  else
1075  imbal = xaccTransGetImbalanceValue(trans);
1076 
1077  if (! gnc_numeric_zero_p(imbal) || ! gnc_numeric_zero_p(imbal_trading))
1078  return FALSE;
1079 
1080  if (!xaccTransUseTradingAccounts (trans))
1081  return TRUE;
1082 
1083  imbal_list = xaccTransGetImbalance(trans);
1084  result = imbal_list == NULL;
1085  gnc_monetary_list_free(imbal_list);
1086  return result;
1087 }
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Definition: Transaction.c:935
GNCAccountType xaccAccountGetType(const Account *acc)
Definition: Account.c:2884
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:378
gboolean gnc_numeric_zero_p(gnc_numeric a)
Definition: gnc-numeric.c:173
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
Definition: Transaction.c:956
void gnc_monetary_list_free(MonetaryList *list)
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:732
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
Definition: Transaction.c:972
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242

◆ 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 1795 of file Transaction.c.

1796 {
1797  return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
1798 }

◆ 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 2336 of file Transaction.c.

2337 {
2338  GDate *threshold_date;
2339  GDate trans_date;
2340  const QofBook *book = xaccTransGetBook (trans);
2341  gboolean result;
2342  g_assert(trans);
2343 
2344  if (!qof_book_uses_autoreadonly(book))
2345  {
2346  return FALSE;
2347  }
2348 
2349  if (xaccTransIsSXTemplate (trans))
2350  return FALSE;
2351 
2352  threshold_date = qof_book_get_autoreadonly_gdate(book);
2353  g_assert(threshold_date); // ok because we checked uses_autoreadonly before
2354  trans_date = xaccTransGetDatePostedGDate(trans);
2355 
2356 // g_warning("there is auto-read-only with days=%d, trans_date_day=%d, threshold_date_day=%d",
2357 // qof_book_get_num_days_autofreeze(book),
2358 // g_date_get_day(&trans_date),
2359 // g_date_get_day(threshold_date));
2360 
2361  if (g_date_compare(&trans_date, threshold_date) < 0)
2362  {
2363  //g_warning("we are auto-read-only");
2364  result = TRUE;
2365  }
2366  else
2367  {
2368  result = FALSE;
2369  }
2370  g_date_free(threshold_date);
2371  return result;
2372 }
GDate * qof_book_get_autoreadonly_gdate(const QofBook *book)
Definition: qofbook.c:761
#define xaccTransGetBook(X)
Definition: Transaction.h:762
gboolean qof_book_uses_autoreadonly(const QofBook *book)
Definition: qofbook.c:734
GDate xaccTransGetDatePostedGDate(const Transaction *trans)
Definition: Transaction.c:2254

◆ 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 944 of file Transaction.c.

945 {
946  QofCollection *col;
947  if (!guid || !book) return NULL;
948  col = qof_book_get_collection (book, GNC_ID_TRANS);
949  return (Transaction *) qof_collection_lookup_entity (col, guid);
950 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Definition: qofid.c:211
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306

◆ 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 1803 of file Transaction.c.

1804 {
1805  return xaccTransOrder_num_action (ta, NULL, tb, NULL);
1806 }
int xaccTransOrder_num_action(const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
Definition: Transaction.c:1809

◆ 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 1809 of file Transaction.c.

1811 {
1812  char *da, *db;
1813  int na, nb, retval;
1814 
1815  if ( ta && !tb ) return -1;
1816  if ( !ta && tb ) return +1;
1817  if ( !ta && !tb ) return 0;
1818 
1819  /* if dates differ, return */
1820  DATE_CMP(ta, tb, date_posted);
1821 
1822  /* otherwise, sort on number string */
1823  if (actna && actnb) /* split action string, if not NULL */
1824  {
1825  na = atoi(actna);
1826  nb = atoi(actnb);
1827  }
1828  else /* else transaction num string */
1829  {
1830  na = atoi(ta->num);
1831  nb = atoi(tb->num);
1832  }
1833  if (na < nb) return -1;
1834  if (na > nb) return +1;
1835 
1836  /* if dates differ, return */
1837  DATE_CMP(ta, tb, date_entered);
1838 
1839  /* otherwise, sort on description string */
1840  da = ta->description ? ta->description : "";
1841  db = tb->description ? tb->description : "";
1842  retval = g_utf8_collate (da, db);
1843  if (retval)
1844  return retval;
1845 
1846  /* else, sort on guid - keeps sort stable. */
1847  return qof_instance_guid_compare(ta, tb);
1848 }
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519

◆ xaccTransRetDateDueTS()

Timespec xaccTransRetDateDueTS ( const Transaction *  trans)

Dates and txn-type for A/R and A/P "invoice" postings

Definition at line 2295 of file Transaction.c.

2296 {
2297  Timespec ts = {0, 0};
2298  if (trans) xaccTransGetDateDueTS (trans, &ts);
2299  return ts;
2300 }
void xaccTransGetDateDueTS(const Transaction *trans, Timespec *ts)
Definition: Transaction.c:2281

◆ xaccTransRetDateEnteredTS()

Timespec xaccTransRetDateEnteredTS ( 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 2274 of file Transaction.c.

2275 {
2276  Timespec ts = {0, 0};
2277  return trans ? trans->date_entered : ts;
2278 }

◆ xaccTransRetDatePostedTS()

Timespec xaccTransRetDatePostedTS ( 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 2247 of file Transaction.c.

2248 {
2249  Timespec ts = {0, 0};
2250  return trans ? trans->date_posted : ts;
2251 }

◆ xaccTransReverse()

Transaction* xaccTransReverse ( Transaction *  transaction)

xaccTransReverse creates a Transaction that reverses the given tranaction 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 2578 of file Transaction.c.

2579 {
2580  Transaction *trans;
2581  kvp_value *kvp_val;
2582  g_return_val_if_fail(orig, NULL);
2583 
2584  trans = xaccTransClone(orig);
2585  xaccTransBeginEdit(trans);
2586 
2587  /* Reverse the values on each split. Clear per-split info. */
2588  FOR_EACH_SPLIT(trans,
2589  {
2593  });
2594 
2595  /* Now update the original with a pointer to the new one */
2596  kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans));
2597  kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val);
2598 
2599  /* Make sure the reverse transaction is not read-only */
2600  xaccTransClearReadOnly(trans);
2601 
2602  qof_instance_set_dirty(QOF_INSTANCE(trans));
2603  xaccTransCommitEdit(trans);
2604  return trans;
2605 }
void xaccSplitSetValue(Split *s, gnc_numeric amt)
Definition: Split.c:1074
#define kvp_value
Definition: kvp_frame.h:108
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Definition: gnc-numeric.c:745
void xaccSplitSetReconcile(Split *split, char recn)
Definition: Split.c:1581
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
Definition: Split.c:1042
Transaction * xaccTransClone(const Transaction *from)
Definition: Transaction.c:578
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define xaccTransGetGUID(X)
Definition: Transaction.h:764
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748
#define NREC
Definition: Split.h:70
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ 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 1637 of file Transaction.c.

1638 {
1639  GList *node, *onode;
1640  QofBackend *be;
1641  Transaction *orig;
1642  GList *slist;
1643  int num_preexist, i;
1644 
1645 /* FIXME: This isn't quite the right way to handle nested edits --
1646  * there should be a stack of transaction states that are popped off
1647  * and restored at each level -- but it does prevent restoring to the
1648  * editlevel 0 state until one is returning to editlevel 0, and
1649  * thereby prevents a crash caused by trans->orig getting NULLed too
1650  * soon.
1651  */
1652  if (!qof_instance_get_editlevel (QOF_INSTANCE (trans))) return;
1653  if (qof_instance_get_editlevel (QOF_INSTANCE (trans)) > 1) {
1654  qof_instance_decrease_editlevel (QOF_INSTANCE (trans));
1655  return;
1656  }
1657 
1658  ENTER ("trans addr=%p\n", trans);
1659 
1660  check_open(trans);
1661 
1662  /* copy the original values back in. */
1663 
1664  orig = trans->orig;
1665  SWAP(trans->num, orig->num);
1666  SWAP(trans->description, orig->description);
1667  trans->date_entered = orig->date_entered;
1668  trans->date_posted = orig->date_posted;
1669  SWAP(trans->common_currency, orig->common_currency);
1670  SWAP(trans->inst.kvp_data, orig->inst.kvp_data);
1671 
1672  /* The splits at the front of trans->splits are exactly the same
1673  splits as in the original, but some of them may have changed, so
1674  we restore only those. */
1675 /* FIXME: Runs off the transaction's splits, so deleted splits are not
1676  * restored!
1677  */
1678  num_preexist = g_list_length(orig->splits);
1679  slist = g_list_copy(trans->splits);
1680  for (i = 0, node = slist, onode = orig->splits; node;
1681  i++, node = node->next, onode = onode ? onode->next : NULL)
1682  {
1683  Split *s = node->data;
1684 
1685  if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
1686  continue;
1687 
1688  if (i < num_preexist)
1689  {
1690  Split *so = onode->data;
1691 
1692  xaccSplitRollbackEdit(s);
1693  SWAP(s->action, so->action);
1694  SWAP(s->memo, so->memo);
1695  SWAP(s->inst.kvp_data, so->inst.kvp_data);
1696  s->reconciled = so->reconciled;
1697  s->amount = so->amount;
1698  s->value = so->value;
1699  s->lot = so->lot;
1700  s->gains_split = so->gains_split;
1701  //SET_GAINS_A_VDIRTY(s);
1702  s->date_reconciled = so->date_reconciled;
1703  qof_instance_mark_clean(QOF_INSTANCE(s));
1704  xaccFreeSplit(so);
1705  }
1706  else
1707  {
1708  /* Potentially added splits */
1709  if (trans != xaccSplitGetParent(s))
1710  {
1711  trans->splits = g_list_remove(trans->splits, s);
1712  /* New split added, but then moved to another
1713  transaction */
1714  continue;
1715  }
1716  xaccSplitRollbackEdit(s);
1717  trans->splits = g_list_remove(trans->splits, s);
1718  g_assert(trans != xaccSplitGetParent(s));
1719  /* NB: our memory management policy here is that a new split
1720  added to the transaction which is then rolled-back still
1721  belongs to the engine. Specifically, it's freed by the
1722  transaction to which it was added. Don't add the Split to
1723  more than one transaction during the begin/commit block! */
1724  if (NULL == xaccSplitGetParent(s))
1725  {
1726  xaccFreeSplit(s); // a newly malloc'd split
1727  }
1728  }
1729  }
1730  g_list_free(slist);
1731  g_list_free(orig->splits);
1732  orig->splits = NULL;
1733 
1734  /* Now that the engine copy is back to its original version,
1735  * get the backend to fix it in the database */
1739  if (be && be->rollback)
1740  {
1741  QofBackendError errcode;
1742 
1743  /* clear errors */
1744  do
1745  {
1746  errcode = qof_backend_get_error (be);
1747  }
1748  while (ERR_BACKEND_NO_ERR != errcode);
1749 
1750  (be->rollback) (be, &(trans->inst));
1751 
1752  errcode = qof_backend_get_error (be);
1753  if (ERR_BACKEND_MOD_DESTROY == errcode)
1754  {
1755  /* The backend is asking us to delete this transaction.
1756  * This typically happens because another (remote) user
1757  * has deleted this transaction, and we haven't found
1758  * out about it until this user tried to edit it.
1759  */
1760  xaccTransDestroy (trans);
1761  do_destroy (trans);
1762 
1763  /* push error back onto the stack */
1764  qof_backend_set_error (be, errcode);
1765  LEAVE ("deleted trans addr=%p\n", trans);
1766  return;
1767  }
1768  if (ERR_BACKEND_NO_ERR != errcode)
1769  {
1770  PERR ("Rollback Failed. Ouch!");
1771  /* push error back onto the stack */
1772  qof_backend_set_error (be, errcode);
1773  }
1774  }
1775 
1777  xaccTransWriteLog (trans, 'R');
1778 
1779  xaccFreeTransaction (trans->orig);
1780 
1781  trans->orig = NULL;
1782  qof_instance_set_destroying(trans, FALSE);
1783 
1784  /* Put back to zero. */
1785  qof_instance_decrease_editlevel(trans);
1786  /* FIXME: The register code seems to depend on the engine to
1787  generate an event during rollback, even though the state is just
1788  reverting to what it was. */
1789  gen_event_trans (trans);
1790 
1791  LEAVE ("trans addr=%p\n", trans);
1792 }
void qof_backend_set_error(QofBackend *be, QofBackendError err)
Definition: qofbackend.c:46
#define qof_instance_is_dirty
Definition: qofinstance.h:191
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:55
void xaccTransWriteLog(Transaction *trans, char flag)
Definition: TransLog.c:221
Transaction * xaccSplitGetParent(const Split *split)
Definition: Split.c:1658
#define PERR(format, args...)
Definition: qoflog.h:232
#define ENTER(format, args...)
Definition: qoflog.h:256
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667
void xaccTransDestroy(Transaction *trans)
Definition: Transaction.c:1378
QofBackendError qof_backend_get_error(QofBackend *be)
Definition: qofbackend.c:56
gboolean qof_book_is_readonly(const QofBook *book)
Definition: qofbook.c:291
#define LEAVE(format, args...)
Definition: qoflog.h:266
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
Definition: qofbook.c:223

◆ 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 2680 of file Transaction.c.

2681 {
2682  SplitList *node;
2683 
2684  ENTER("(trans=%p)", trans);
2685  /* Lock down posted date, its to be synced to the posted date
2686  * for the source of the cap gains. */
2687  xaccTransScrubGainsDate(trans);
2688 
2689  /* Fix up the split amount */
2690 restart:
2691  for (node = trans->splits; node; node = node->next)
2692  {
2693  Split *s = node->data;
2694 
2695  if (!xaccTransStillHasSplit(trans, s)) continue;
2696 
2697  xaccSplitDetermineGainStatus(s);
2698  if (s->gains & GAINS_STATUS_ADIRTY)
2699  {
2700  gboolean altered = FALSE;
2701  s->gains &= ~GAINS_STATUS_ADIRTY;
2702  if (s->lot)
2703  altered = xaccScrubLot(s->lot);
2704  else
2705  altered = xaccSplitAssign(s);
2706  if (altered) goto restart;
2707  }
2708  }
2709 
2710  /* Fix up gains split value */
2711  FOR_EACH_SPLIT(trans,
2712  if ((s->gains & GAINS_STATUS_VDIRTY) ||
2713  (s->gains_split &&
2714  (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
2715  xaccSplitComputeCapGains(s, gain_acc);
2716  );
2717 
2718  LEAVE("(trans=%p)", trans);
2719 }
void xaccSplitComputeCapGains(Split *split, Account *gain_acc)
Definition: cap-gains.c:680
#define ENTER(format, args...)
Definition: qoflog.h:256
GList SplitList
Definition: gnc-engine.h:203
gboolean xaccSplitAssign(Split *split)
Definition: cap-gains.c:582
#define LEAVE(format, args...)
Definition: qoflog.h:266
gboolean xaccScrubLot(GNCLot *lot)
Definition: Scrub3.c:85

◆ xaccTransSetAssociation()

void xaccTransSetAssociation ( Transaction *  trans,
const char *  assoc 
)

Sets the transaction Association

Definition at line 2078 of file Transaction.c.

2079 {
2080  if (!trans || !assoc) return;
2081  xaccTransBeginEdit(trans);
2082 
2083  kvp_frame_set_str (trans->inst.kvp_data, assoc_uri_str, assoc);
2084  qof_instance_set_dirty(QOF_INSTANCE(trans));
2085  xaccTransCommitEdit(trans);
2086 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define kvp_frame_set_str
Definition: kvp_frame.h:174

◆ xaccTransSetCurrency()

void xaccTransSetCurrency ( Transaction *  trans,
gnc_commodity *  curr 
)

Set the commodity of this transaction.

Set a new currency on a 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 1327 of file Transaction.c.

1328 {
1329  gnc_commodity *old_curr = trans->common_currency;
1330  if (!trans || !curr || trans->common_currency == curr) return;
1331  xaccTransBeginEdit(trans);
1332 
1333  trans->common_currency = curr;
1334  if (old_curr != NULL && trans->splits != NULL)
1335  {
1336  gnc_numeric rate = find_new_rate(trans, curr);
1337  if (!gnc_numeric_zero_p (rate))
1338  {
1339  FOR_EACH_SPLIT(trans, split_set_new_value(s, curr, old_curr, rate));
1340  }
1341  else
1342  {
1343  FOR_EACH_SPLIT(trans, xaccSplitSetValue(s, xaccSplitGetValue(s)));
1344  }
1345  }
1346 
1347  qof_instance_set_dirty(QOF_INSTANCE(trans));
1348  mark_trans(trans); /* Dirty balance of every account in trans */
1349  xaccTransCommitEdit(trans);
1350 }
void xaccSplitSetValue(Split *s, gnc_numeric amt)
Definition: Split.c:1074
gboolean gnc_numeric_zero_p(gnc_numeric a)
Definition: gnc-numeric.c:173
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748

◆ 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 1971 of file Transaction.c.

1972 {
1973  GDate *date;
1974  if (!trans) return;
1975  date = g_date_new_dmy(day, mon, year);
1976  if (!g_date_valid(date))
1977  {
1978  PWARN("Attempted to set invalid date %d-%d-%d; set today's date instead.",
1979  year, mon, day);
1980  g_free(date);
1981  date = gnc_g_date_new_today();
1982  }
1983  xaccTransSetDatePostedGDate(trans, *date);
1984  g_free(date);
1985 }
void xaccTransSetDatePostedGDate(Transaction *trans, GDate date)
Definition: Transaction.c:1904
#define PWARN(format, args...)
Definition: qoflog.h:238
GDate * gnc_g_date_new_today()
Definition: gnc-date.c:1685

◆ xaccTransSetDateDueTS()

void xaccTransSetDateDueTS ( Transaction *  trans,
const Timespec *  ts 
)

Dates and txn-type for A/R and A/P "invoice" postings

Definition at line 1988 of file Transaction.c.

1989 {
1990  if (!trans || !ts) return;
1991  xaccTransBeginEdit(trans);
1992  kvp_frame_set_timespec (trans->inst.kvp_data, TRANS_DATE_DUE_KVP, *ts);
1993  qof_instance_set_dirty(QOF_INSTANCE(trans));
1994  xaccTransCommitEdit(trans);
1995 }
void kvp_frame_set_timespec(KvpFrame *frame, const gchar *path, Timespec ts)
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 1927 of file Transaction.c.

1928 {
1929  Timespec ts = {secs, 0};
1930  if (!trans) return;
1931  xaccTransSetDateInternal(trans, &trans->date_entered, ts);
1932 }

◆ xaccTransSetDateEnteredTS()

void xaccTransSetDateEnteredTS ( Transaction *  trans,
const Timespec *  ts 
)

Modify the date of when the transaction was entered. The entered date is the date when the register entry was made.

Definition at line 1964 of file Transaction.c.

1965 {
1966  if (!trans || !ts) return;
1967  xaccTransSetDateInternal(trans, &trans->date_entered, *ts);
1968 }

◆ 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 1904 of file Transaction.c.

1905 {
1906  KvpValue* kvp_value;
1907  KvpFrame* frame;
1908  if (!trans) return;
1909 
1910  /* We additionally save this date into a kvp frame to ensure in
1911  * the future a date which was set as *date* (without time) can
1912  * clearly be distinguished from the Timespec. */
1913  kvp_value = kvp_value_new_gdate(date);
1914  frame = kvp_frame_set_value_nc(trans->inst.kvp_data, TRANS_DATE_POSTED, kvp_value);
1915  if (!frame)
1916  {
1917  kvp_value_delete(kvp_value);
1918  }
1919 
1920  /* mark dirty and commit handled by SetDateInternal */
1921  xaccTransSetDateInternal(trans, &trans->date_posted,
1922  gdate_to_timespec(date));
1923  set_gains_date_dirty (trans);
1924 }
#define kvp_value
Definition: kvp_frame.h:108
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *path, KvpValue *value)
Timespec gdate_to_timespec(GDate d)
Definition: gnc-date.c:1699
void kvp_value_delete(KvpValue *value)
Definition: kvp_frame.c:1064

◆ 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 1887 of file Transaction.c.

1888 {
1889  Timespec ts = {secs, 0};
1890  if (!trans) return;
1891  xaccTransSetDateInternal(trans, &trans->date_posted, ts);
1892  set_gains_date_dirty (trans);
1893 }

◆ 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 1896 of file Transaction.c.

1897 {
1898  GDate date;
1899  gnc_gdate_set_time64(&date, time);
1900  xaccTransSetDatePostedGDate(trans, date);
1901 }
void xaccTransSetDatePostedGDate(Transaction *trans, GDate date)
Definition: Transaction.c:1904
void gnc_gdate_set_time64(GDate *gd, time64 time)

◆ xaccTransSetDatePostedTS()

void xaccTransSetDatePostedTS ( Transaction *  trans,
const Timespec *  ts 
)

The xaccTransSetDatePostedTS() method does the same thing as xaccTransSetDatePostedSecs(), but takes a struct timespec64.

Definition at line 1946 of file Transaction.c.

1947 {
1948  if (!trans || !ts) return;
1949  xaccTransSetDateInternal(trans, &trans->date_posted, *ts);
1950  set_gains_date_dirty (trans);
1951 }

◆ xaccTransSetDescription()

void xaccTransSetDescription ( Transaction *  trans,
const char *  desc 
)

Sets the transaction Description

Definition at line 2067 of file Transaction.c.

2068 {
2069  if (!trans || !desc) return;
2070  xaccTransBeginEdit(trans);
2071 
2072  CACHE_REPLACE(trans->description, desc);
2073  qof_instance_set_dirty(QOF_INSTANCE(trans));
2074  xaccTransCommitEdit(trans);
2075 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ xaccTransSetIsClosingTxn()

void xaccTransSetIsClosingTxn ( Transaction *  trans,
gboolean  is_closing 
)

Sets whether or not this transaction is a "closing transaction"

Definition at line 2108 of file Transaction.c.

2109 {
2110  if (!trans) return;
2111  xaccTransBeginEdit(trans);
2112 
2113  if (is_closing)
2114  kvp_frame_set_gint64 (trans->inst.kvp_data, trans_is_closing_str, 1);
2115  else
2116  kvp_frame_replace_value_nc (trans->inst.kvp_data, trans_is_closing_str, NULL);
2117  qof_instance_set_dirty(QOF_INSTANCE(trans));
2118  xaccTransCommitEdit(trans);
2119 }
void kvp_frame_set_gint64(KvpFrame *frame, const gchar *path, gint64 ival)
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
KvpValue * kvp_frame_replace_value_nc(KvpFrame *frame, const gchar *slot, KvpValue *new_value)
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 2097 of file Transaction.c.

2098 {
2099  if (!trans || !notes) return;
2100  xaccTransBeginEdit(trans);
2101 
2102  kvp_frame_set_str (trans->inst.kvp_data, trans_notes_str, notes);
2103  qof_instance_set_dirty(QOF_INSTANCE(trans));
2104  xaccTransCommitEdit(trans);
2105 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define kvp_frame_set_str
Definition: kvp_frame.h:174

◆ xaccTransSetNum()

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

Definition at line 2047 of file Transaction.c.

2048 {
2049  if (!trans || !xnum) return;
2050  xaccTransBeginEdit(trans);
2051 
2052  CACHE_REPLACE(trans->num, xnum);
2053  qof_instance_set_dirty(QOF_INSTANCE(trans));
2054  mark_trans(trans); /* Dirty balance of every account in trans */
2055  xaccTransCommitEdit(trans);
2056 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ 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 2021 of file Transaction.c.

2022 {
2023  if (trans && reason)
2024  {
2025  xaccTransBeginEdit(trans);
2026  kvp_frame_set_str (trans->inst.kvp_data,
2027  TRANS_READ_ONLY_REASON, reason);
2028  qof_instance_set_dirty(QOF_INSTANCE(trans));
2029  xaccTransCommitEdit(trans);
2030  }
2031 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define kvp_frame_set_str
Definition: kvp_frame.h:174

◆ xaccTransSetTxnType()

void xaccTransSetTxnType ( Transaction *  trans,
char  type 
)

Set the Transaction Type

See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT

Definition at line 1998 of file Transaction.c.

1999 {
2000  char s[2] = {type, '\0'};
2001  g_return_if_fail(trans);
2002  xaccTransBeginEdit(trans);
2003  kvp_frame_set_str (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP, s);
2004  qof_instance_set_dirty(QOF_INSTANCE(trans));
2005  xaccTransCommitEdit(trans);
2006 }
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
#define kvp_frame_set_str
Definition: kvp_frame.h:174

◆ xaccTransSortSplits()

void xaccTransSortSplits ( Transaction *  trans)

Sorts the splits in a transaction, putting the debits first, followed by the credits.

Definition at line 500 of file Transaction.c.

501 {
502  GList *node, *new_list = NULL;
503  Split *split;
504 
505  /* first debits */
506  for (node = trans->splits; node; node = node->next)
507  {
508  split = node->data;
510  continue;
511  new_list = g_list_append(new_list, split);
512  }
513 
514  /* then credits */
515  for (node = trans->splits; node; node = node->next)
516  {
517  split = node->data;
519  continue;
520  new_list = g_list_append(new_list, split);
521  }
522 
523  /* install newly sorted list */
524  g_list_free(trans->splits);
525  trans->splits = new_list;
526 }
gboolean gnc_numeric_negative_p(gnc_numeric a)
Definition: gnc-numeric.c:197
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1748

◆ 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 2551 of file Transaction.c.

2552 {
2553  KvpFrame *frame;
2554  KvpValue *val;
2555 
2556  g_return_if_fail(trans);
2557 
2558  frame = trans->inst.kvp_data;
2559  val = kvp_frame_get_slot(frame, void_reason_str);
2560  if (!val) return; /* Transaction isn't voided. Bail. */
2561 
2562  xaccTransBeginEdit(trans);
2563 
2564  val = kvp_frame_get_slot(frame, void_former_notes_str);
2565  kvp_frame_set_slot(frame, trans_notes_str, val);
2566  kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL);
2567  kvp_frame_set_slot_nc(frame, void_reason_str, NULL);
2568  kvp_frame_set_slot_nc(frame, void_time_str, NULL);
2569 
2570  FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
2571 
2572  /* Dirtying taken care of by ClearReadOnly */
2573  xaccTransClearReadOnly(trans);
2574  xaccTransCommitEdit(trans);
2575 }
void kvp_frame_set_slot(KvpFrame *frame, const gchar *key, const KvpValue *value)
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356

◆ xaccTransUseTradingAccounts()

gboolean xaccTransUseTradingAccounts ( const Transaction *  trans)

Determine whether this transaction should use commodity trading accounts

Definition at line 935 of file Transaction.c.

936 {
938 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
gboolean qof_book_use_trading_accounts(const QofBook *book)
Definition: qofbook.c:690

◆ 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 2486 of file Transaction.c.

2487 {
2488  KvpFrame *frame;
2489  KvpValue *val;
2490  Timespec now;
2491  char iso8601_str[ISO_DATELENGTH + 1] = "";
2492 
2493  g_return_if_fail(trans && reason);
2494 
2495  /* Prevent voiding transactions that are already marked
2496  * read only, for example generated by the business features.
2497  */
2498  if (xaccTransGetReadOnly (trans))
2499  {
2500  PWARN ("Refusing to void a read-only transaction!");
2501  return;
2502  }
2503  xaccTransBeginEdit(trans);
2504  frame = trans->inst.kvp_data;
2505 
2506  val = kvp_frame_get_slot(frame, trans_notes_str);
2507  kvp_frame_set_slot(frame, void_former_notes_str, val);
2508 
2509  kvp_frame_set_string(frame, trans_notes_str, _("Voided transaction"));
2510  kvp_frame_set_string(frame, void_reason_str, reason);
2511 
2512  now.tv_sec = gnc_time (NULL);
2513  now.tv_nsec = 0;
2514  gnc_timespec_to_iso8601_buff(now, iso8601_str);
2515  kvp_frame_set_string(frame, void_time_str, iso8601_str);
2516 
2517  FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
2518 
2519  /* Dirtying taken care of by SetReadOnly */
2520  xaccTransSetReadOnly(trans, _("Transaction Voided"));
2521  xaccTransCommitEdit(trans);
2522 }
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
#define PWARN(format, args...)
Definition: qoflog.h:238
void kvp_frame_set_slot(KvpFrame *frame, const gchar *key, const KvpValue *value)
void xaccTransSetReadOnly(Transaction *trans, const char *reason)
Definition: Transaction.c:2021
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
const char * xaccTransGetReadOnly(const Transaction *trans)
Definition: Transaction.c:2314
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.c:410
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.