|
GnuCash 2.3.0
|
Files | |
| file | Split.h |
API for Transactions and Splits (journal entries) | |
| file | Transaction.h |
API for Transactions and Splits (journal entries) | |
Defines | |
| #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)) |
Typedefs | |
| typedef struct _SplitClass | SplitClass |
| typedef struct _TransactionClass | TransactionClass |
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) |
| QofBook * | xaccSplitGetBook (const Split *split) |
| Account * | xaccSplitGetAccount (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, time_t time) |
| void | xaccSplitSetDateReconciledTS (Split *split, Timespec *ts) |
| void | xaccSplitGetDateReconciledTS (const Split *split, Timespec *ts) |
| Timespec | xaccSplitRetDateReconciledTS (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) |
| 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) |
| 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 | xaccTransSetNotes (Transaction *trans, const char *notes) |
| const char * | xaccTransGetNum (const Transaction *trans) |
| const char * | xaccTransGetDescription (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) |
| SplitList * | xaccTransGetSplitList (const Transaction *trans) |
| gboolean | xaccTransStillHasSplit (const Transaction *trans, const Split *s) |
| void | xaccTransSetReadOnly (Transaction *trans, const char *reason) |
| void | xaccTransClearReadOnly (Transaction *trans) |
| const char * | xaccTransGetReadOnly (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) |
| 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) |
| #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, time_t time) |
| void | xaccTransSetDatePostedTS (Transaction *trans, const Timespec *ts) |
| void | xaccTransSetDateEnteredSecs (Transaction *trans, time_t time) |
| void | xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts) |
| void | xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts) |
| time_t | xaccTransGetDate (const Transaction *trans) |
| void | xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts) |
| Timespec | xaccTransRetDatePostedTS (const Transaction *trans) |
| GDate | xaccTransGetDatePostedGDate (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_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" |
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.
| #define SPLIT_ACCOUNT_GUID "account-guid" |
| #define TXN_TYPE_INVOICE 'I' |
Transaction is an invoice
Definition at line 120 of file Transaction.h.
| #define TXN_TYPE_LINK 'L' |
Transaction is a link between (invoice and payment) lots
Definition at line 122 of file Transaction.h.
| #define TXN_TYPE_NONE '\0' |
No transaction type
Definition at line 119 of file Transaction.h.
| #define TXN_TYPE_PAYMENT 'P' |
Transaction is a payment
Definition at line 121 of file Transaction.h.
| #define xaccSplitGetGUID | ( | X | ) | qof_entity_get_guid(QOF_INSTANCE(X)) |
| #define xaccSplitReturnGUID | ( | X | ) | (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) |
| #define xaccTransAppendSplit | ( | t, | |
| s | |||
| ) | xaccSplitSetParent((s), (t)) |
Add a split to the transaction
The xaccTransAppendSplit() method will append the indicated split to the collection of splits in this transaction.
Definition at line 301 of file Transaction.h.
| #define xaccTransGetBook | ( | X | ) | qof_instance_get_book (QOF_INSTANCE(X)) |
Definition at line 620 of file Transaction.h.
| #define xaccTransGetGUID | ( | X | ) | qof_entity_get_guid(QOF_INSTANCE(X)) |
Definition at line 622 of file Transaction.h.
| #define xaccTransGetSlots | ( | X | ) | qof_instance_get_slots (QOF_INSTANCE(X)) |
Definition at line 626 of file Transaction.h.
| #define xaccTransReturnGUID | ( | X | ) | (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) |
Definition at line 624 of file Transaction.h.
| guint gnc_book_count_transactions | ( | QofBook * | book | ) |
Definition at line 2040 of file Transaction.c.
{
guint count = 0;
xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
counter_thunk, (void*)&count);
return count;
}
| 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 441 of file Transaction.c.
{
Transaction *trans;
g_return_val_if_fail (book, NULL);
trans = g_object_new(GNC_TYPE_TRANSACTION, NULL);
xaccInitTransaction (trans, book);
qof_event_gen (&trans->inst, QOF_EVENT_CREATE, NULL);
return trans;
}
Compare two splits by code of account. Returns similar to strcmp.
Definition at line 1422 of file Split.c.
{
Account *aa, *ab;
if (!sa && !sb) return 0;
if (!sa) return -1;
if (!sb) return 1;
aa = sa->acc;
ab = sb->acc;
return safe_strcmp(xaccAccountGetName(aa), xaccAccountGetName(ab));
}
Compare two splits by full name of account. Returns similar to strcmp.
Definition at line 1401 of file Split.c.
{
Account *aa, *ab;
char *full_a, *full_b;
int retval;
if (!sa && !sb) return 0;
if (!sa) return -1;
if (!sb) return 1;
aa = sa->acc;
ab = sb->acc;
full_a = gnc_account_get_full_name(aa);
full_b = gnc_account_get_full_name(ab);
retval = g_utf8_collate(full_a, full_b);
g_free(full_a);
g_free(full_b);
return retval;
}
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 1457 of file Split.c.
{
const char *ca, *cb;
if (!sa && !sb) return 0;
if (!sa) return -1;
if (!sb) return 1;
ca = xaccSplitGetCorrAccountCode(sa);
cb = xaccSplitGetCorrAccountCode(sb);
return safe_strcmp(ca, cb);
}
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 1436 of file Split.c.
{
char *ca, *cb;
int retval;
if (!sa && !sb) return 0;
if (!sa) return -1;
if (!sb) return 1;
/* doesn't matter what separator we use
* as long as they are the same
*/
ca = xaccSplitGetCorrAccountFullName(sa);
cb = xaccSplitGetCorrAccountFullName(sb);
retval = safe_strcmp(ca, cb);
g_free(ca);
g_free(cb);
return retval;
}
| 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.)
Definition at line 1204 of file Split.c.
{
Account *acc;
Transaction *trans;
GncEventData ed;
if (!split) return TRUE;
acc = split->acc;
trans = split->parent;
if (acc && !qof_instance_get_destroying(acc)
&& xaccTransGetReadOnly(trans))
return FALSE;
xaccTransBeginEdit(trans);
ed.node = split;
ed.idx = xaccTransGetSplitIndex(trans, split);
qof_instance_set_dirty(QOF_INSTANCE(split));
qof_instance_set_destroying(split, TRUE);
qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
xaccTransCommitEdit(trans);
return TRUE;
}
| gboolean xaccSplitEqual | ( | const Split * | sa, |
| const Split * | sb, | ||
| gboolean | check_guids, | ||
| gboolean | check_balances, | ||
| gboolean | check_txn_splits | ||
| ) |
Equality.
| sa | First split to compare |
| sb | Second split to compare |
| check_guids | If TRUE, try a guid_equal() on the GUIDs of both splits if their pointers are not equal in the first place. |
| check_balances | If 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_splits | If 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 538 of file Split.c.
{
gboolean same_book;
if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
if (!sa || !sb)
{
PWARN ("one is NULL");
return FALSE;
}
if (sa == sb) return TRUE;
same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
if (check_guids)
{
if (qof_instance_guid_compare(sa, sb) != 0)
{
PWARN ("GUIDs differ");
return FALSE;
}
}
/* If the same book, since these strings are cached we can just use pointer equality */
if ((same_book && sa->memo != sb->memo) || (!same_book && safe_strcmp(sa->memo, sb->memo) != 0))
{
PWARN ("memos differ: (%p)%s vs (%p)%s",
sa->memo, sa->memo, sb->memo, sb->memo);
return FALSE;
}
if ((same_book && sa->action != sb->action) || (!same_book && safe_strcmp(sa->action, sb->action) != 0))
{
PWARN ("actions differ: %s vs %s", sa->action, sb->action);
return FALSE;
}
if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
{
char *frame_a;
char *frame_b;
frame_a = kvp_frame_to_string (sa->inst.kvp_data);
frame_b = kvp_frame_to_string (sb->inst.kvp_data);
PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
g_free (frame_a);
g_free (frame_b);
return FALSE;
}
if (sa->reconciled != sb->reconciled)
{
PWARN ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
return FALSE;
}
if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
{
PWARN ("reconciled date differs");
return FALSE;
}
if (!gnc_numeric_eq(xaccSplitGetAmount (sa), xaccSplitGetAmount (sb)))
{
char *str_a;
char *str_b;
str_a = gnc_numeric_to_string (xaccSplitGetAmount (sa));
str_b = gnc_numeric_to_string (xaccSplitGetAmount (sb));
PWARN ("amounts differ: %s vs %s", str_a, str_b);
g_free (str_a);
g_free (str_b);
return FALSE;
}
if (!gnc_numeric_eq(xaccSplitGetValue (sa), xaccSplitGetValue (sb)))
{
char *str_a;
char *str_b;
str_a = gnc_numeric_to_string (xaccSplitGetValue (sa));
str_b = gnc_numeric_to_string (xaccSplitGetValue (sb));
PWARN ("values differ: %s vs %s", str_a, str_b);
g_free (str_a);
g_free (str_b);
return FALSE;
}
if (check_balances)
{
if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
return FALSE;
if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
sb->cleared_balance))
return FALSE;
if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
sb->reconciled_balance))
return FALSE;
}
if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
check_balances, FALSE))
{
PWARN ("transactions differ");
return FALSE;
}
return TRUE;
}
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition at line 667 of file Split.c.
{
return s ? s->acc : NULL;
}
| const char* xaccSplitGetAction | ( | const Split * | split | ) |
| gnc_numeric xaccSplitGetAmount | ( | const Split * | split | ) |
| 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 1037 of file Split.c.
{
return s ? s->balance : gnc_numeric_zero();
}
| 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 1110 of file Split.c.
{
if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
/* be more precise -- the value depends on the currency we want it
* expressed in. */
if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
return xaccSplitGetValue(s);
if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
return xaccSplitGetAmount(s);
PERR ("inappropriate base currency %s "
"given split currency=%s and commodity=%s\n",
gnc_commodity_get_printname(base_currency),
gnc_commodity_get_printname(xaccTransGetCurrency (s->parent)),
gnc_commodity_get_printname(xaccAccountGetCommodity(s->acc)));
return gnc_numeric_zero();
}
Returns the book of this split, i.e. the entity where this split is stored.
Definition at line 1737 of file Split.c.
{
return qof_instance_get_book(QOF_INSTANCE(split));
}
| 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 1043 of file Split.c.
{
return s ? s->cleared_balance : gnc_numeric_zero();
}
| const char* xaccSplitGetCorrAccountCode | ( | const Split * | sa | ) |
document me
Definition at line 1383 of file Split.c.
{
static const char *split_const = NULL;
const Split *other_split;
if (!get_corr_account_split(sa, &other_split))
{
if (!split_const)
/* Translators: This string has a disambiguation prefix */
split_const = Q_("Displayed account code of the other account in a multi-split transaction|Split");
return split_const;
}
return xaccAccountGetCode(other_split->acc);
}
| 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.
Definition at line 1367 of file Split.c.
{
static const char *split_const = NULL;
const Split *other_split;
if (!get_corr_account_split(sa, &other_split))
{
if (!split_const)
split_const = _("-- Split Transaction --");
return g_strdup(split_const);
}
return gnc_account_get_full_name(other_split->acc);
}
| const char* xaccSplitGetCorrAccountName | ( | const Split * | sa | ) |
document me
Definition at line 1350 of file Split.c.
{
static const char *split_const = NULL;
const Split *other_split;
if (!get_corr_account_split(sa, &other_split))
{
if (!split_const)
split_const = _("-- Split Transaction --");
return split_const;
}
return xaccAccountGetName(other_split->acc);
}
| const char* xaccSplitGetMemo | ( | 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 1781 of file Split.c.
{
int i;
Transaction *trans;
int count, num_splits;
Split *other = NULL;
KvpValue *sva;
gboolean trading_accts;
if (!split) return NULL;
trans = split->parent;
if (!trans) return NULL;
#ifdef OLD_ALGO_HAS_ONLY_TWO_SPLITS
Split *s1, *s2;
if (g_list_length (trans->splits) != 2) return NULL;
s1 = g_list_nth_data (trans->splits, 0);
s2 = g_list_nth_data (trans->splits, 1);
if (s1 == split) return s2;
return s1;
#endif
trading_accts = xaccTransUseTradingAccounts (trans);
num_splits = xaccTransCountSplits(trans);
count = num_splits;
sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
if (!sva && !trading_accts && (2 != count)) return NULL;
for (i = 0; i < num_splits; i++)
{
Split *s = xaccTransGetSplit(trans, i);
if (s == split)
{
--count;
continue;
}
if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
{
--count;
continue;
}
if (trading_accts &&
xaccAccountGetType(xaccSplitGetAccount(s)) == ACCT_TYPE_TRADING)
{
--count;
continue;
}
other = s;
}
return (1 == count) ? other : NULL;
}
| Transaction* xaccSplitGetParent | ( | const Split * | split | ) |
| char xaccSplitGetReconcile | ( | const Split * | split | ) |
| 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 1049 of file Split.c.
{
return s ? s->reconciled_balance : gnc_numeric_zero();
}
| 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 1694 of file Split.c.
{
gnc_numeric amt, val, price;
if (!split) return gnc_numeric_create(1, 1);
/* if amount == 0 and value == 0, then return 1.
* if amount == 0 and value != 0 then return 0.
* otherwise return value/amount
*/
amt = xaccSplitGetAmount(split);
val = xaccSplitGetValue(split);
if (gnc_numeric_zero_p(amt))
{
if (gnc_numeric_zero_p(val))
return gnc_numeric_create(1, 1);
return gnc_numeric_create(0, 1);
}
price = gnc_numeric_div(val, amt,
GNC_DENOM_AUTO,
GNC_HOW_DENOM_SIGFIGS(PRICE_SIGFIGS) |
GNC_HOW_RND_ROUND_HALF_UP);
/* During random checks we can get some very weird prices. Let's
* handle some overflow and other error conditions by returning
* zero. But still print an error to let us know it happened.
*/
if (gnc_numeric_check(price))
{
PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
return gnc_numeric_create(0, 1);
}
return price;
}
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 896 of file Split.c.
{
return qof_instance_get_slots(QOF_INSTANCE(s));
}
| 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 1743 of file Split.c.
{
const char *split_type;
if (!s) return NULL;
split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
return split_type ? split_type : "normal";
}
| gnc_numeric xaccSplitGetValue | ( | const Split * | split | ) |
The xaccSplitLookup() subroutine will return the split associated with the given id, or NULL if there is no such split.
Definition at line 803 of file Split.c.
{
QofCollection *col;
if (!guid || !book) return NULL;
col = qof_book_get_collection (book, GNC_ID_SPLIT);
return (Split *) qof_collection_lookup_entity (col, guid);
}
| 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 1755 of file Split.c.
{
xaccTransBeginEdit (s->parent);
s->value = gnc_numeric_zero();
kvp_frame_set_str(s->inst.kvp_data, "split-type", "stock-split");
SET_GAINS_VDIRTY(s);
mark_split(s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
}
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 1233 of file Split.c.
{
int retval;
int comp;
char *da, *db;
if (sa == sb) return 0;
/* nothing is always less than something */
if (!sa) return -1;
if (!sb) return +1;
retval = xaccTransOrder (sa->parent, sb->parent);
if (retval) return retval;
/* otherwise, sort on memo strings */
da = sa->memo ? sa->memo : "";
db = sb->memo ? sb->memo : "";
retval = g_utf8_collate (da, db);
if (retval)
return retval;
/* otherwise, sort on action strings */
da = sa->action ? sa->action : "";
db = sb->action ? sb->action : "";
retval = g_utf8_collate (da, db);
if (retval != 0)
return retval;
/* the reconciled flag ... */
if (sa->reconciled < sb->reconciled) return -1;
if (sa->reconciled > sb->reconciled) return +1;
/* compare amounts */
comp = gnc_numeric_compare(xaccSplitGetAmount(sa), xaccSplitGetAmount (sb));
if (comp < 0) return -1;
if (comp > 0) return +1;
comp = gnc_numeric_compare(xaccSplitGetValue(sa), xaccSplitGetValue (sb));
if (comp < 0) return -1;
if (comp > 0) return +1;
/* if dates differ, return */
DATE_CMP(sa, sb, date_reconciled);
/* else, sort on guid - keeps sort stable. */
retval = qof_instance_guid_compare(sa, sb);
if (retval) return retval;
return 0;
}
| 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.
Definition at line 1496 of file Split.c.
{
if (!split || !actn) return;
xaccTransBeginEdit (split->parent);
CACHE_REPLACE(split->action, actn);
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
| 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 ...
Definition at line 977 of file Split.c.
{
if (!s) return;
g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
ENTER ("(split=%p) old amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
" new amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
s->amount.num, s->amount.denom, amt.num, amt.denom);
xaccTransBeginEdit (s->parent);
if (s->acc)
s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
else
s->amount = amt;
SET_GAINS_ADIRTY(s);
mark_split (s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
LEAVE("");
}
| 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.
Definition at line 1055 of file Split.c.
{
const gnc_commodity *currency;
const gnc_commodity *commodity;
if (!s) return;
xaccTransBeginEdit (s->parent);
if (!s->acc)
{
PERR ("split must have a parent account");
return;
}
currency = xaccTransGetCurrency (s->parent);
commodity = xaccAccountGetCommodity (s->acc);
/* If the base_currency is the transaction's commodity ('currency'),
* set the value. If it's the account commodity, set the
* amount. If both, set both. */
if (gnc_commodity_equiv(currency, base_currency))
{
if (gnc_commodity_equiv(commodity, base_currency))
{
s->amount = gnc_numeric_convert(value,
get_commodity_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
}
s->value = gnc_numeric_convert(value,
get_currency_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
}
else if (gnc_commodity_equiv(commodity, base_currency))
{
s->amount = gnc_numeric_convert(value, get_commodity_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
}
else
{
PERR ("inappropriate base currency %s "
"given split currency=%s and commodity=%s\n",
gnc_commodity_get_printname(base_currency),
gnc_commodity_get_printname(currency),
gnc_commodity_get_printname(commodity));
return;
}
SET_GAINS_A_VDIRTY(s);
mark_split (s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
}
| void xaccSplitSetDateReconciledSecs | ( | Split * | split, |
| time_t | time | ||
| ) |
Set the date on which this split was reconciled by specifying the time as time_t.
Definition at line 1555 of file Split.c.
{
if (!split) return;
xaccTransBeginEdit (split->parent);
split->date_reconciled.tv_sec = secs;
split->date_reconciled.tv_nsec = 0;
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
Set the date on which this split was reconciled by specifying the time as Timespec. Caller still owns *ts!
Definition at line 1568 of file Split.c.
{
if (!split || !ts) return;
xaccTransBeginEdit (split->parent);
split->date_reconciled = *ts;
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
Assigns the split to a specific Lot
Definition at line 1654 of file Split.c.
{
xaccTransBeginEdit (split->parent);
split->lot = lot;
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
| 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 1477 of file Split.c.
{
if (!split || !memo) return;
xaccTransBeginEdit (split->parent);
CACHE_REPLACE(split->memo, memo);
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccTransCommitEdit(split->parent);
}
| 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 1529 of file Split.c.
{
if (!split || split->reconciled == recn) return;
xaccTransBeginEdit (split->parent);
switch (recn)
{
case NREC:
case CREC:
case YREC:
case FREC:
case VREC:
split->reconciled = recn;
mark_split (split);
qof_instance_set_dirty(QOF_INSTANCE(split));
xaccAccountRecomputeBalance (split->acc);
break;
default:
PERR("Bad reconciled flag");
break;
}
xaccTransCommitEdit(split->parent);
}
| void xaccSplitSetSharePrice | ( | Split * | split, |
| gnc_numeric | price | ||
| ) |
Definition at line 943 of file Split.c.
{
if (!s) return;
ENTER (" ");
xaccTransBeginEdit (s->parent);
s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
price, get_currency_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
SET_GAINS_VDIRTY(s);
mark_split (s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
LEAVE ("");
}
| 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 915 of file Split.c.
{
if (!s) return;
ENTER (" ");
xaccTransBeginEdit (s->parent);
s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
s->value = gnc_numeric_mul(s->amount, price,
get_currency_denom(s), GNC_HOW_RND_ROUND_HALF_UP);
SET_GAINS_A_VDIRTY(s);
mark_split (s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
LEAVE ("");
}
Set the KvpFrame slots of this split to the given frm by directly using the frm pointer (i.e. non-copying).
Definition at line 902 of file Split.c.
{
if (!s || !frm) return;
xaccTransBeginEdit(s->parent);
qof_instance_set_slots(QOF_INSTANCE(s), frm);
xaccTransCommitEdit(s->parent);
}
| void xaccSplitSetValue | ( | Split * | split, |
| gnc_numeric | value | ||
| ) |
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Definition at line 1009 of file Split.c.
{
gnc_numeric new_val;
if (!s) return;
g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
ENTER ("(split=%p) old val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
" new val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
s->value.num, s->value.denom, amt.num, amt.denom);
xaccTransBeginEdit (s->parent);
new_val = gnc_numeric_convert(amt, get_currency_denom(s),
GNC_HOW_RND_ROUND_HALF_UP);
if (gnc_numeric_check(new_val) == GNC_ERROR_OK)
s->value = new_val;
else PERR("numeric error in converting the split value's denominator");
SET_GAINS_VDIRTY(s);
mark_split (s);
qof_instance_set_dirty(QOF_INSTANCE(s));
xaccTransCommitEdit(s->parent);
LEAVE ("");
}
| gnc_numeric xaccSplitVoidFormerAmount | ( | const Split * | split | ) |
Returns the original pre-void amount of a split.
| split | The split in question. |
Definition at line 1839 of file Split.c.
{
g_return_val_if_fail(split, gnc_numeric_zero());
return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
}
| gnc_numeric xaccSplitVoidFormerValue | ( | const Split * | split | ) |
Returns the original pre-void value of a split.
| split | The split in question. |
Definition at line 1846 of file Split.c.
{
g_return_val_if_fail(split, gnc_numeric_zero());
return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
}
| 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 1087 of file Transaction.c.
{
if (!trans) return;
if (!qof_begin_edit(&trans->inst)) return;
if (qof_book_shutting_down(qof_instance_get_book(trans))) return;
if (!qof_book_is_readonly(qof_instance_get_book(trans)))
{
xaccOpenLog ();
xaccTransWriteLog (trans, 'B');
}
/* Make a clone of the transaction; we will use this
* in case we need to roll-back the edit. */
trans->orig = xaccDupeTransaction (trans);
}
| Transaction* xaccTransClone | ( | const Transaction * | t | ) |
The xaccTransClone() method will create a complete copy of an existing transaction.
Definition at line 534 of file Transaction.c.
{
Transaction *to;
Split *split;
GList *node;
qof_event_suspend();
to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
to->date_entered = from->date_entered;
to->date_posted = from->date_posted;
to->num = CACHE_INSERT (from->num);
to->description = CACHE_INSERT (from->description);
to->common_currency = from->common_currency;
qof_instance_copy_version(to, from);
qof_instance_copy_version_check(to, from);
to->orig = NULL;
qof_instance_init_data (&to->inst, GNC_ID_TRANS, qof_instance_get_book(from));
kvp_frame_delete (to->inst.kvp_data);
to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
xaccTransBeginEdit(to);
for (node = from->splits; node; node = node->next)
{
split = xaccSplitClone(node->data);
split->parent = to;
to->splits = g_list_append (to->splits, split);
}
qof_instance_set_dirty(QOF_INSTANCE(to));
xaccTransCommitEdit(to);
qof_event_resume();
return to;
}
| 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 1286 of file Transaction.c.
{
if (!trans) return;
ENTER ("(trans=%p)", trans);
if (!qof_commit_edit (QOF_INSTANCE(trans)))
{
LEAVE("editlevel non-zero");
return;
}
/* We increment this for the duration of the call
* so other functions don't result in a recursive
* call to xaccTransCommitEdit. */
qof_instance_increase_editlevel(trans);
if (was_trans_emptied(trans))
qof_instance_set_destroying(trans, TRUE);
/* Before committing the transaction, we are going to enforce certain
* constraints. In particular, we want to enforce the cap-gains
* and the balanced lot constraints. These constraints might
* change the number of splits in this transaction, and the
* transaction itself might be deleted. This is also why
* we can't really enforce these constraints elsewhere: they
* can cause pointers to splits and transactions to disappear out
* from under the holder.
*/
if (!qof_instance_get_destroying(trans) && scrub_data &&
!qof_book_shutting_down(xaccTransGetBook(trans)))
{
/* If scrubbing gains recurses through here, don't call it again. */
scrub_data = 0;
/* The total value of the transaction should sum to zero.
* Call the trans scrub routine to fix it. Indirectly, this
* routine also performs a number of other transaction fixes too.
*/
xaccTransScrubImbalance (trans, NULL, NULL);
/* Get the cap gains into a consistent state as well. */
/* Lot Scrubbing is temporarily disabled. */
if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
xaccTransScrubGains (trans, NULL);
/* Allow scrubbing in transaction commit again */
scrub_data = 1;
}
/* Record the time of last modification */
if (0 == trans->date_entered.tv_sec)
{
struct timeval tv;
#ifdef HAVE_GETTIMEOFDAY
gettimeofday (&tv, NULL);
#else
time (&(tv.tv_sec));
tv.tv_usec = 0;
#endif
trans->date_entered.tv_sec = tv.tv_sec;
// trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
qof_instance_set_dirty(QOF_INSTANCE(trans));
}
qof_commit_edit_part2(QOF_INSTANCE(trans),
(void (*) (QofInstance *, QofBackendError))
trans_on_error,
(void (*) (QofInstance *)) trans_cleanup_commit,
(void (*) (QofInstance *)) do_destroy);
LEAVE ("(trans=%p)", trans);
}
| int xaccTransCountSplits | ( | const Transaction * | trans | ) |
Returns the number of splits in this transaction.
Definition at line 1823 of file Transaction.c.
{
gint i = 0;
FOR_EACH_SPLIT(trans, i++);
return i;
}
| 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.
| trans | the transaction to destroy |
Definition at line 1109 of file Transaction.c.
{
if (!trans) return;
if (!xaccTransGetReadOnly (trans) ||
qof_book_shutting_down(qof_instance_get_book(trans)))
{
xaccTransBeginEdit(trans);
qof_instance_set_destroying(trans, TRUE);
xaccTransCommitEdit(trans);
}
}
| gboolean xaccTransEqual | ( | const Transaction * | ta, |
| const Transaction * | tb, | ||
| gboolean | check_guids, | ||
| gboolean | check_splits, | ||
| gboolean | check_balances, | ||
| gboolean | assume_ordered | ||
| ) |
Equality.
| ta | First transaction to compare |
| tb | Second transaction to compare |
| check_guids | If 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_splits | If TRUE, after checking the transaction data structures for equality, also check all splits attached to the transation for equality. |
| check_balances | If 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_ordered | If 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 645 of file Transaction.c.
{
gboolean same_book;
if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */
if (!ta || !tb)
{
PWARN ("one is NULL");
return FALSE;
}
if (ta == tb) return TRUE;
same_book = qof_instance_get_book(QOF_INSTANCE(ta)) == qof_instance_get_book(QOF_INSTANCE(tb));
if (check_guids)
{
if (qof_instance_guid_compare(ta, tb) != 0)
{
PWARN ("GUIDs differ");
return FALSE;
}
}
if (!gnc_commodity_equal(ta->common_currency, tb->common_currency))
{
PWARN ("commodities differ %s vs %s",
gnc_commodity_get_unique_name (ta->common_currency),
gnc_commodity_get_unique_name (tb->common_currency));
return FALSE;
}
if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
{
char buf1[100];
char buf2[100];
(void)gnc_timespec_to_iso8601_buff(ta->date_entered, buf1);
(void)gnc_timespec_to_iso8601_buff(tb->date_entered, buf2);
PWARN ("date entered differs: '%s' vs '%s'", buf1, buf2);
return FALSE;
}
if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
{
char buf1[100];
char buf2[100];
(void)gnc_timespec_to_iso8601_buff(ta->date_posted, buf1);
(void)gnc_timespec_to_iso8601_buff(tb->date_posted, buf2);
PWARN ("date posted differs: '%s' vs '%s'", buf1, buf2);
return FALSE;
}
/* If the same book, since we use cached strings, we can just compare pointer
* equality for num and description
*/
if ((same_book && ta->num != tb->num) || (!same_book && safe_strcmp(ta->num, tb->num) != 0))
{
PWARN ("num differs: %s vs %s", ta->num, tb->num);
return FALSE;
}
if ((same_book && ta->description != tb->description)
|| (!same_book && safe_strcmp(ta->description, tb->description)))
{
PWARN ("descriptions differ: %s vs %s", ta->description, tb->description);
return FALSE;
}
if (kvp_frame_compare(ta->inst.kvp_data, tb->inst.kvp_data) != 0)
{
char *frame_a;
char *frame_b;
frame_a = kvp_frame_to_string (ta->inst.kvp_data);
frame_b = kvp_frame_to_string (tb->inst.kvp_data);
PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
g_free (frame_a);
g_free (frame_b);
return FALSE;
}
if (check_splits)
{
if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
{
PWARN ("only one has splits");
return FALSE;
}
if (ta->splits && tb->splits)
{
GList *node_a, *node_b;
for (node_a = ta->splits, node_b = tb->splits;
node_a;
node_a = node_a->next, node_b = node_b->next)
{
Split *split_a = node_a->data;
Split *split_b;
/* don't presume that the splits are in the same order */
if (!assume_ordered)
node_b = g_list_find_custom (tb->splits, split_a,
compare_split_guids);
if (!node_b)
{
PWARN ("first has split %s and second does not",
guid_to_string (xaccSplitGetGUID (split_a)));
return FALSE;
}
split_b = node_b->data;
if (!xaccSplitEqual (split_a, split_b, check_guids, check_balances,
FALSE))
{
char str_a[GUID_ENCODING_LENGTH + 1];
char str_b[GUID_ENCODING_LENGTH + 1];
guid_to_string_buff (xaccSplitGetGUID (split_a), str_a);
guid_to_string_buff (xaccSplitGetGUID (split_b), str_b);
PWARN ("splits %s and %s differ", str_a, str_b);
return FALSE;
}
}
if (g_list_length (ta->splits) != g_list_length (tb->splits))
{
PWARN ("different number of splits");
return FALSE;
}
}
}
return TRUE;
}
| gnc_numeric xaccTransGetAccountAmount | ( | const Transaction * | trans, |
| const Account * | account | ||
| ) |
Same as xaccTransGetAccountValue, but uses the Account's commodity.
Definition at line 943 of file Transaction.c.
{
gnc_numeric total = gnc_numeric_zero ();
if (!trans || !acc) return total;
total = gnc_numeric_convert (total, xaccAccountGetCommoditySCU (acc),
GNC_HOW_RND_ROUND_HALF_UP);
FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
total = gnc_numeric_add_fixed(
total, xaccSplitGetAmount(s)));
return total;
}
| 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 1017 of file Transaction.c.
{
GList *node;
Split *last_split = NULL;
// Not really the appropriate error value.
g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
for (node = trans->splits; node; node = node->next)
{
Split *split = node->data;
if (!xaccTransStillHasSplit(trans, split))
continue;
if (xaccSplitGetAccount(split) != account)
continue;
if (!last_split)
{
last_split = split;
continue;
}
/* This test needs to correspond to the comparison function used when
sorting the splits for computing the running balance. */
if (xaccSplitOrder (last_split, split) < 0)
last_split = split;
}
return xaccSplitGetBalance (last_split);
}
| 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 927 of file Transaction.c.
{
gnc_numeric total = gnc_numeric_zero ();
if (!trans || !acc) return total;
FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
{
total = gnc_numeric_add (total, xaccSplitGetValue (s),
GNC_DENOM_AUTO,
GNC_HOW_DENOM_EXACT);
});
return total;
}
| 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.
Definition at line 1055 of file Transaction.c.
{
return trans ? trans->common_currency : NULL;
}
| time_t 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 1861 of file Transaction.c.
{
return trans ? trans->date_posted.tv_sec : 0;
}
| void xaccTransGetDateDueTS | ( | const Transaction * | trans, |
| Timespec * | ts | ||
| ) |
Dates and txn-type for A/R and A/P "invoice" postings
Definition at line 1918 of file Transaction.c.
{
KvpValue *value;
if (!trans || !ts) return;
value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP);
if (value)
*ts = kvp_value_get_timespec (value);
else
xaccTransGetDatePostedTS (trans, ts);
}
| 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 1874 of file Transaction.c.
{
if (trans && ts)
*ts = trans->date_entered;
}
| 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 1888 of file Transaction.c.
{
GDate result;
if (trans)
{
/* Can we look up this value in the kvp slot? If yes, use it
* from there because it doesn't suffer from time zone
* shifts. */
const KvpValue* kvp_value =
kvp_frame_get_slot(trans->inst.kvp_data, TRANS_DATE_POSTED);
if (kvp_value)
result = kvp_value_get_gdate(kvp_value);
else
result = timespec_to_gdate(xaccTransRetDatePostedTS(trans));
}
else
{
g_date_clear(&result, 1);
}
return result;
}
| 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 1867 of file Transaction.c.
{
if (trans && ts)
*ts = trans->date_posted;
}
| const char* xaccTransGetDescription | ( | const Transaction * | trans | ) |
Gets the transaction Description
Definition at line 1837 of file Transaction.c.
{
return trans ? trans->description : NULL;
}
| 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 838 of file Transaction.c.
{
/* imbal_value is used if either (1) the transaction has a non currency
split or (2) all the splits are in the same currency. If there are
no non-currency splits and not all splits are in the same currency then
imbal_list is used to compute the imbalance. */
MonetaryList *imbal_list = NULL;
gnc_numeric imbal_value = gnc_numeric_zero();
gboolean trading_accts;
if (!trans) return imbal_list;
ENTER("(trans=%p)", trans);
trading_accts = xaccTransUseTradingAccounts (trans);
/* If using trading accounts and there is at least one split that is not
in the transaction currency or a split that has a price or exchange
rate other than 1, then compute the balance in each commodity in the
transaction. Otherwise (all splits are in the transaction's currency)
then compute the balance using the value fields.
Optimize for the common case of only one currency and a balanced
transaction. */
FOR_EACH_SPLIT(trans,
{
gnc_commodity *commodity;
commodity = xaccAccountGetCommodity(xaccSplitGetAccount(s));
if (trading_accts &&
(imbal_list ||
! gnc_commodity_equiv(commodity, trans->common_currency) ||
! gnc_numeric_equal(xaccSplitGetAmount(s), xaccSplitGetValue(s))))
{
/* Need to use (or already are using) a list of imbalances in each of
the currencies used in the transaction. */
if (! imbal_list)
{
/* All previous splits have been in the transaction's common
currency, so imbal_value is in this currency. */
imbal_list = gnc_monetary_list_add_value(imbal_list,
trans->common_currency,
imbal_value);
}
imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
xaccSplitGetAmount(s));
}
/* Add it to the value accumulator in case we need it. */
imbal_value = gnc_numeric_add(imbal_value, xaccSplitGetValue(s),
GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
} );
if (!imbal_list && !gnc_numeric_zero_p(imbal_value))
{
/* Not balanced and no list, create one. If we found multiple currencies
and no non-currency commodity then imbal_list will already exist and
we won't get here. */
imbal_list = gnc_monetary_list_add_value(imbal_list,
trans->common_currency,
imbal_value);
}
/* Delete all the zero entries from the list, perhaps leaving an
empty list */
imbal_list = gnc_monetary_list_delete_zeros(imbal_list);
LEAVE("(trans=%p), imbal=%p", trans, imbal_list);
return imbal_list;
}
| 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 822 of file Transaction.c.
{
gnc_numeric imbal = gnc_numeric_zero();
if (!trans) return imbal;
ENTER("(trans=%p)", trans);
/* Could use xaccSplitsComputeValue, except that we want to use
GNC_HOW_DENOM_EXACT */
FOR_EACH_SPLIT(trans, imbal =
gnc_numeric_add(imbal, xaccSplitGetValue(s),
GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT));
LEAVE("(trans=%p) imbal=%s", trans, gnc_num_dbg_to_string(imbal));
return imbal;
}
| gboolean xaccTransGetIsClosingTxn | ( | const Transaction * | trans | ) |
Returns whether this transaction is a "closing transaction"
Definition at line 1850 of file Transaction.c.
{
return trans ?
kvp_frame_get_gint64 (trans->inst.kvp_data, trans_is_closing_str)
: FALSE;
}
| 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 1843 of file Transaction.c.
{
return trans ?
kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL;
}
| const char* xaccTransGetNum | ( | const Transaction * | trans | ) |
Gets the transaction Number (or ID) field
Definition at line 1831 of file Transaction.c.
{
return trans ? trans->num : NULL;
}
| const char* xaccTransGetReadOnly | ( | const Transaction * | trans | ) |
FIXME: document me
Definition at line 1951 of file Transaction.c.
{
/* XXX This flag should be cached in the transaction structure
* for performance reasons, since its checked every trans commit.
*/
return trans ? kvp_frame_get_string (
trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
}
| Transaction* xaccTransGetReversedBy | ( | const Transaction * | trans | ) |
Returns the transaction that reversed the given transaction.
| trans | a Transaction that has been reversed |
Definition at line 2163 of file Transaction.c.
{
GncGUID *guid;
g_return_val_if_fail(trans, NULL);
guid = kvp_frame_get_guid(trans->inst.kvp_data, TRANS_REVERSED_BY);
return xaccTransLookup(guid, qof_instance_get_book(trans));
}
| Split* xaccTransGetSplit | ( | const Transaction * | trans, |
| int | i | ||
| ) |
The xaccTransGetSplit() method returns a pointer to each of the splits in this transaction.
| trans | The transaction |
| i | The 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 1797 of file Transaction.c.
{
int j = 0;
if (!trans || i < 0) return NULL;
FOR_EACH_SPLIT(trans, { if (i == j) return s; j++; });
return NULL;
}
| int xaccTransGetSplitIndex | ( | const Transaction * | trans, |
| const Split * | split | ||
| ) |
Inverse of xaccTransGetSplit()
Definition at line 1807 of file Transaction.c.
{
int j = 0;
g_return_val_if_fail(trans && split, -1);
FOR_EACH_SPLIT(trans, { if (s == split) return j; j++; });
return -1;
}
| SplitList* xaccTransGetSplitList | ( | const Transaction * | trans | ) |
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
Definition at line 1817 of file Transaction.c.
{
return trans ? trans->splits : NULL;
}
| char xaccTransGetTxnType | ( | const Transaction * | trans | ) |
Returns the Transaction Type
See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT
Definition at line 1940 of file Transaction.c.
{
const char *s;
if (!trans) return TXN_TYPE_NONE;
s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP);
if (s) return *s;
return TXN_TYPE_NONE;
}
| const char* xaccTransGetVoidReason | ( | const Transaction * | transaction | ) |
Returns the user supplied textual reason why a transaction was voided.
| transaction | The transaction in question. |
Definition at line 2090 of file Transaction.c.
{
g_return_val_if_fail(trans, NULL);
return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str);
}
| gboolean xaccTransGetVoidStatus | ( | const Transaction * | transaction | ) |
Retrieve information on whether or not a transaction has been voided.
| transaction | The transaction in question. |
Definition at line 2083 of file Transaction.c.
{
g_return_val_if_fail(trans, FALSE);
return (kvp_frame_get_slot(trans->inst.kvp_data, void_reason_str) != NULL);
}
| Timespec xaccTransGetVoidTime | ( | const Transaction * | tr | ) |
Returns the time that a transaction was voided.
| tr | The transaction in question. |
Definition at line 2097 of file Transaction.c.
{
const char *val;
Timespec void_time = {0, 0};
g_return_val_if_fail(tr, void_time);
val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str);
return val ? gnc_iso8601_to_timespec_gmt(val) : void_time;
}
| gboolean xaccTransHasReconciledSplits | ( | const Transaction * | trans | ) |
FIXME: document me
Definition at line 1990 of file Transaction.c.
{
return xaccTransHasReconciledSplitsByAccount (trans, NULL);
}
| gboolean xaccTransHasReconciledSplitsByAccount | ( | const Transaction * | trans, |
| const Account * | account | ||
| ) |
FIXME: document me
Definition at line 1961 of file Transaction.c.
{
GList *node;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *split = node->data;
if (!xaccTransStillHasSplit(trans, split))
continue;
if (account && (xaccSplitGetAccount(split) != account))
continue;
switch (xaccSplitGetReconcile (split))
{
case YREC:
case FREC:
return TRUE;
default:
break;
}
}
return FALSE;
}
| gboolean xaccTransHasSplitsInState | ( | const Transaction * | trans, |
| const char | state | ||
| ) |
FIXME: document me
Definition at line 2020 of file Transaction.c.
{
return xaccTransHasSplitsInStateByAccount (trans, state, NULL);
}
| gboolean xaccTransHasSplitsInStateByAccount | ( | const Transaction * | trans, |
| const char | state, | ||
| const Account * | account | ||
| ) |
FIXME: document me
Definition at line 1997 of file Transaction.c.
{
GList *node;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *split = node->data;
if (!xaccTransStillHasSplit(trans, split))
continue;
if (account && (xaccSplitGetAccount(split) != account))
continue;
if (split->reconciled == state)
return TRUE;
}
return FALSE;
}
| gboolean xaccTransIsBalanced | ( | const Transaction * | trans | ) |
Returns true if the transaction is balanced according to the rules currently in effect.
Definition at line 910 of file Transaction.c.
{
MonetaryList *imbal_list;
gboolean result;
if (! gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
return FALSE;
if (!xaccTransUseTradingAccounts (trans))
return TRUE;
imbal_list = xaccTransGetImbalance(trans);
result = imbal_list == NULL;
gnc_monetary_list_free(imbal_list);
return result;
}
| gboolean xaccTransIsOpen | ( | const Transaction * | trans | ) |
The xaccTransIsOpen() method returns TRUE if the transaction is open for editing. Otherwise, it returns false. XXX this routne 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 1508 of file Transaction.c.
{
return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
}
| 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 810 of file Transaction.c.
{
QofCollection *col;
if (!guid || !book) return NULL;
col = qof_book_get_collection (book, GNC_ID_TRANS);
return (Transaction *) qof_collection_lookup_entity (col, guid);
}
| 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.
Definition at line 1516 of file Transaction.c.
{
char *da, *db;
int na, nb, retval;
if ( ta && !tb ) return -1;
if ( !ta && tb ) return +1;
if ( !ta && !tb ) return 0;
/* if dates differ, return */
DATE_CMP(ta, tb, date_posted);
/* otherwise, sort on number string */
na = atoi(ta->num);
nb = atoi(tb->num);
if (na < nb) return -1;
if (na > nb) return +1;
/* if dates differ, return */
DATE_CMP(ta, tb, date_entered);
/* otherwise, sort on description string */
da = ta->description ? ta->description : "";
db = tb->description ? tb->description : "";
retval = g_utf8_collate (da, db);
if (retval)
return retval;
/* else, sort on guid - keeps sort stable. */
return qof_instance_guid_compare(ta, tb);
}
| Timespec xaccTransRetDateDueTS | ( | const Transaction * | trans | ) |
Dates and txn-type for A/R and A/P "invoice" postings
Definition at line 1932 of file Transaction.c.
{
Timespec ts = {0, 0};
if (trans) xaccTransGetDateDueTS (trans, &ts);
return ts;
}
| 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 1911 of file Transaction.c.
{
Timespec ts = {0, 0};
return trans ? trans->date_entered : ts;
}
| 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 1881 of file Transaction.c.
{
Timespec ts = {0, 0};
return trans ? trans->date_posted : ts;
}
| 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).
| transaction | The transaction to create a reverse of. |
Definition at line 2136 of file Transaction.c.
{
Transaction *trans;
kvp_value *kvp_val;
g_return_val_if_fail(orig, NULL);
trans = xaccTransClone(orig);
xaccTransBeginEdit(trans);
/* Reverse the values on each split. Clear per-split info. */
FOR_EACH_SPLIT(trans,
{
xaccSplitSetAmount(s, gnc_numeric_neg(xaccSplitGetAmount(s)));
xaccSplitSetValue(s, gnc_numeric_neg(xaccSplitGetValue(s)));
xaccSplitSetReconcile(s, NREC);
qof_instance_set_dirty(QOF_INSTANCE(trans));
});
/* Now update the original with a pointer to the new one */
kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans));
kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val);
xaccTransCommitEdit(trans);
return trans;
}
| 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.
Definition at line 1368 of file Transaction.c.
{
GList *node, *onode;
QofBackend *be;
Transaction *orig;
GList *slist;
int num_preexist, i;
ENTER ("trans addr=%p\n", trans);
check_open(trans);
/* copy the original values back in. */
orig = trans->orig;
SWAP(trans->num, orig->num);
SWAP(trans->description, orig->description);
trans->date_entered = orig->date_entered;
trans->date_posted = orig->date_posted;
SWAP(trans->common_currency, orig->common_currency);
SWAP(trans->inst.kvp_data, orig->inst.kvp_data);
/* The splits at the front of trans->splits are exactly the same
splits as in the original, but some of them may have changed, so
we restore only those. */
num_preexist = g_list_length(orig->splits);
slist = g_list_copy(trans->splits);
for (i = 0, node = slist, onode = orig->splits; node;
i++, node = node->next, onode = onode ? onode->next : NULL)
{
Split *s = node->data;
if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
continue;
if (i < num_preexist)
{
Split *so = onode->data;
xaccSplitRollbackEdit(s);
SWAP(s->action, so->action);
SWAP(s->memo, so->memo);
SWAP(s->inst.kvp_data, so->inst.kvp_data);
s->reconciled = so->reconciled;
s->amount = so->amount;
s->value = so->value;
s->lot = so->lot;
s->gains_split = so->gains_split;
//SET_GAINS_A_VDIRTY(s);
s->date_reconciled = so->date_reconciled;
qof_instance_mark_clean(QOF_INSTANCE(s));
xaccFreeSplit(so);
}
else
{
/* Potentially added splits */
if (trans != xaccSplitGetParent(s))
{
trans->splits = g_list_remove(trans->splits, s);
/* New split added, but then moved to another
transaction */
continue;
}
xaccSplitRollbackEdit(s);
trans->splits = g_list_remove(trans->splits, s);
g_assert(trans != xaccSplitGetParent(s));
/* NB: our memory management policy here is that a new split
added to the transaction which is then rolled-back still
belongs to the engine. Specifically, it's freed by the
transaction to which it was added. Don't add the Split to
more than one transaction during the begin/commit block! */
if (NULL == xaccSplitGetParent(s))
{
xaccFreeSplit(s); // a newly malloc'd split
}
}
}
g_list_free(slist);
g_list_free(orig->splits);
orig->splits = NULL;
/* Now that the engine copy is back to its original version,
* get the backend to fix it in the database */
be = qof_book_get_backend(qof_instance_get_book(trans));
if (be && be->rollback)
{
QofBackendError errcode;
/* clear errors */
do
{
errcode = qof_backend_get_error (be);
}
while (ERR_BACKEND_NO_ERR != errcode);
(be->rollback) (be, &(trans->inst));
errcode = qof_backend_get_error (be);
if (ERR_BACKEND_MOD_DESTROY == errcode)
{
/* The backend is asking us to delete this transaction.
* This typically happens because another (remote) user
* has deleted this transaction, and we haven't found
* out about it until this user tried to edit it.
*/
xaccTransDestroy (trans);
do_destroy (trans);
/* push error back onto the stack */
qof_backend_set_error (be, errcode);
LEAVE ("deleted trans addr=%p\n", trans);
return;
}
if (ERR_BACKEND_NO_ERR != errcode)
{
PERR ("Rollback Failed. Ouch!");
/* push error back onto the stack */
qof_backend_set_error (be, errcode);
}
}
if (!qof_book_is_readonly(qof_instance_get_book(trans)))
xaccTransWriteLog (trans, 'R');
xaccFreeTransaction (trans->orig);
trans->orig = NULL;
qof_instance_set_destroying(trans, FALSE);
/* Put back to zero. */
qof_instance_decrease_editlevel(trans);
/* FIXME: The register code seems to depend on the engine to
generate an event during rollback, even though the state is just
reverting to what it was. */
gen_event_trans (trans);
LEAVE ("trans addr=%p\n", trans);
}
| 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 2235 of file Transaction.c.
{
SplitList *node;
ENTER("(trans=%p)", trans);
/* Lock down posted date, its to be synced to the posted date
* for the source of the cap gains. */
xaccTransScrubGainsDate(trans);
/* Fix up the split amount */
restart:
for (node = trans->splits; node; node = node->next)
{
Split *s = node->data;
if (!xaccTransStillHasSplit(trans, s)) continue;
xaccSplitDetermineGainStatus(s);
if (s->gains & GAINS_STATUS_ADIRTY)
{
gboolean altered = FALSE;
s->gains &= ~GAINS_STATUS_ADIRTY;
if (s->lot)
altered = xaccScrubLot(s->lot);
else
altered = xaccSplitAssign(s);
if (altered) goto restart;
}
}
/* Fix up gains split value */
FOR_EACH_SPLIT(trans,
if ((s->gains & GAINS_STATUS_VDIRTY) ||
(s->gains_split &&
(s->gains_split->gains & GAINS_STATUS_VDIRTY)))
xaccSplitComputeCapGains(s, gain_acc);
);
LEAVE("(trans=%p)", trans);
}
| void xaccTransSetCurrency | ( | Transaction * | trans, |
| gnc_commodity * | curr | ||
| ) |
Set the commodity of this transaction.
Definition at line 1061 of file Transaction.c.
{
gint fraction, old_fraction;
if (!trans || !curr || trans->common_currency == curr) return;
xaccTransBeginEdit(trans);
old_fraction = gnc_commodity_get_fraction (trans->common_currency);
trans->common_currency = curr;
fraction = gnc_commodity_get_fraction (curr);
/* avoid needless crud if fraction didn't change */
if (fraction != old_fraction)
{
FOR_EACH_SPLIT(trans, xaccSplitSetValue(s, xaccSplitGetValue(s)));
}
qof_instance_set_dirty(QOF_INSTANCE(trans));
mark_trans(trans); /* Dirty balance of every account in trans */
xaccTransCommitEdit(trans);
}
| 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 1659 of file Transaction.c.
{
GDate *date;
if (!trans) return;
date = g_date_new_dmy(day, mon, year);
g_assert(g_date_valid(date));
xaccTransSetDatePostedGDate(trans, *date);
g_date_free(date);
}
| void xaccTransSetDateDueTS | ( | Transaction * | trans, |
| const Timespec * | ts | ||
| ) |
Dates and txn-type for A/R and A/P "invoice" postings
Definition at line 1670 of file Transaction.c.
{
if (!trans || !ts) return;
xaccTransBeginEdit(trans);
kvp_frame_set_timespec (trans->inst.kvp_data, TRANS_DATE_DUE_KVP, *ts);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
| void xaccTransSetDateEnteredSecs | ( | Transaction * | trans, |
| time_t | 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 1615 of file Transaction.c.
{
Timespec ts = {secs, 0};
if (!trans) return;
xaccTransSetDateInternal(trans, &trans->date_entered, ts);
}
| 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 1652 of file Transaction.c.
{
if (!trans || !ts) return;
xaccTransSetDateInternal(trans, &trans->date_entered, *ts);
}
| 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 1593 of file Transaction.c.
{
KvpValue* kvp_value;
KvpFrame* frame;
if (!trans) return;
/* We additionally save this date into a kvp frame to ensure in
* the future a date which was set as *date* (without time) can
* clearly be distinguished from the Timespec. */
kvp_value = kvp_value_new_gdate(date);
frame = kvp_frame_set_value_nc(trans->inst.kvp_data, TRANS_DATE_POSTED, kvp_value);
if (!frame)
{
kvp_value_delete(kvp_value);
}
xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_timespec(date));
set_gains_date_dirty (trans);
}
| void xaccTransSetDatePostedSecs | ( | Transaction * | trans, |
| time_t | time | ||
| ) |
The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time_t (see ctime(3)). The posted date is the date when this transaction was posted at the bank.
Definition at line 1584 of file Transaction.c.
{
Timespec ts = {secs, 0};
if (!trans) return;
xaccTransSetDateInternal(trans, &trans->date_posted, ts);
set_gains_date_dirty (trans);
}
| void xaccTransSetDatePostedTS | ( | Transaction * | trans, |
| const Timespec * | ts | ||
| ) |
The xaccTransSetDatePostedTS() method does the same thing as xaccTransSetDatePostedSecs(), but takes a struct timespec64.
Definition at line 1634 of file Transaction.c.
{
if (!trans || !ts) return;
xaccTransSetDateInternal(trans, &trans->date_posted, *ts);
set_gains_date_dirty (trans);
}
| void xaccTransSetDescription | ( | Transaction * | trans, |
| const char * | desc | ||
| ) |
Sets the transaction Description
Definition at line 1749 of file Transaction.c.
{
if (!trans || !desc) return;
xaccTransBeginEdit(trans);
CACHE_REPLACE(trans->description, desc);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
| void xaccTransSetIsClosingTxn | ( | Transaction * | trans, |
| gboolean | is_closing | ||
| ) |
Sets whether or not this transaction is a "closing transaction"
Definition at line 1779 of file Transaction.c.
{
if (!trans) return;
xaccTransBeginEdit(trans);
if (is_closing)
kvp_frame_set_gint64 (trans->inst.kvp_data, trans_is_closing_str, 1);
else
kvp_frame_replace_value_nc (trans->inst.kvp_data, trans_is_closing_str, NULL);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
| 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 1768 of file Transaction.c.
{
if (!trans || !notes) return;
xaccTransBeginEdit(trans);
kvp_frame_set_str (trans->inst.kvp_data, trans_notes_str, notes);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
| void xaccTransSetNum | ( | Transaction * | trans, |
| const char * | num | ||
| ) |
Sets the transaction Number (or ID) field
Definition at line 1729 of file Transaction.c.
{
if (!trans || !xnum) return;
xaccTransBeginEdit(trans);
CACHE_REPLACE(trans->num, xnum);
qof_instance_set_dirty(QOF_INSTANCE(trans));
mark_trans(trans); /* Dirty balance of every account in trans */
xaccTransCommitEdit(trans);
}
| void xaccTransSetReadOnly | ( | Transaction * | trans, |
| const char * | reason | ||
| ) |
Set the transaction to be ReadOnly
Definition at line 1703 of file Transaction.c.
{
if (trans && reason)
{
xaccTransBeginEdit(trans);
kvp_frame_set_str (trans->inst.kvp_data,
TRANS_READ_ONLY_REASON, reason);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
}
| void xaccTransSetTxnType | ( | Transaction * | trans, |
| char | type | ||
| ) |
Set the Transaction Type
See TXN_TYPE_NONE, TXN_TYPE_INVOICE and TXN_TYPE_PAYMENT
Definition at line 1680 of file Transaction.c.
{
char s[2] = {type, '\0'};
g_return_if_fail(trans);
xaccTransBeginEdit(trans);
kvp_frame_set_str (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP, s);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
}
| void xaccTransSortSplits | ( | Transaction * | trans | ) |
Sorts the splits in a transaction, putting the debits first, followed by the credits.
Definition at line 456 of file Transaction.c.
{
GList *node, *new_list = NULL;
Split *split;
/* first debits */
for (node = trans->splits; node; node = node->next)
{
split = node->data;
if (gnc_numeric_negative_p (xaccSplitGetValue(split)))
continue;
new_list = g_list_append(new_list, split);
}
/* then credits */
for (node = trans->splits; node; node = node->next)
{
split = node->data;
if (!gnc_numeric_negative_p (xaccSplitGetValue(split)))
continue;
new_list = g_list_append(new_list, split);
}
/* install newly sorted list */
g_list_free(trans->splits);
trans->splits = new_list;
}
| 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.
| transaction | The transaction to restore from voided state. |
Definition at line 2109 of file Transaction.c.
{
KvpFrame *frame;
KvpValue *val;
g_return_if_fail(trans);
frame = trans->inst.kvp_data;
val = kvp_frame_get_slot(frame, void_reason_str);
if (!val) return; /* Transaction isn't voided. Bail. */
xaccTransBeginEdit(trans);
val = kvp_frame_get_slot(frame, void_former_notes_str);
kvp_frame_set_slot(frame, trans_notes_str, val);
kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL);
kvp_frame_set_slot_nc(frame, void_reason_str, NULL);
kvp_frame_set_slot_nc(frame, void_time_str, NULL);
FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
/* Dirtying taken care of by ClearReadOnly */
xaccTransClearReadOnly(trans);
xaccTransCommitEdit(trans);
}
| gboolean xaccTransUseTradingAccounts | ( | const Transaction * | trans | ) |
Determine whether this transaction should use commodity trading accounts
Definition at line 801 of file Transaction.c.
{
return qof_book_use_trading_accounts(qof_instance_get_book (trans));
}
| 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.
| transaction | The transaction to void. |
| reason | The textual reason why this transaction is being voided. |
Definition at line 2052 of file Transaction.c.
{
KvpFrame *frame;
KvpValue *val;
Timespec now;
char iso8601_str[ISO_DATELENGTH + 1] = "";
g_return_if_fail(trans && reason);
xaccTransBeginEdit(trans);
frame = trans->inst.kvp_data;
val = kvp_frame_get_slot(frame, trans_notes_str);
kvp_frame_set_slot(frame, void_former_notes_str, val);
kvp_frame_set_string(frame, trans_notes_str, _("Voided transaction"));
kvp_frame_set_string(frame, void_reason_str, reason);
now.tv_sec = time(NULL);
now.tv_nsec = 0;
gnc_timespec_to_iso8601_buff(now, iso8601_str);
kvp_frame_set_string(frame, void_time_str, iso8601_str);
FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
/* Dirtying taken care of by SetReadOnly */
xaccTransSetReadOnly(trans, _("Transaction Voided"));
xaccTransCommitEdit(trans);
}
1.7.4