GnuCash fec5643+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

Splits are grouped into Accounts which are also known as "Ledgers" in accounting practice. More...

Files

file  Account.h
 Account handling public routines.
 
file  Account.hpp
 Account public routines (C++ api)
 

Data Structures

struct  AccountClass
 

Macros

#define GNC_TYPE_ACCOUNT   (gnc_account_get_type ())
 
#define GNC_ACCOUNT(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ACCOUNT, Account))
 
#define GNC_ACCOUNT_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ACCOUNT, AccountClass))
 
#define GNC_IS_ACCOUNT(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ACCOUNT))
 
#define GNC_IS_ACCOUNT_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ACCOUNT))
 
#define GNC_ACCOUNT_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ACCOUNT, AccountClass))
 

Typedefs

typedef gnc_numeric(* xaccGetBalanceFn) (const Account *account)
 
typedef gnc_numeric(* xaccGetBalanceInCurrencyFn) (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
typedef gnc_numeric(* xaccGetBalanceAsOfDateFn) (Account *account, time64 date)
 
typedef void(* AccountCb) (Account *a, gpointer data)
 
typedef gpointer(* AccountCb2) (Account *a, gpointer data)
 
using SplitsVec = std::vector< Split * >
 
using AccountVec = std::vector< Account * >
 

Enumerations

enum  GNCAccountType {
  ACCT_TYPE_INVALID = -1 , ACCT_TYPE_NONE = -1 , ACCT_TYPE_BANK = 0 , ACCT_TYPE_CASH = 1 ,
  ACCT_TYPE_CREDIT = 3 , ACCT_TYPE_ASSET = 2 , ACCT_TYPE_LIABILITY = 4 , ACCT_TYPE_STOCK = 5 ,
  ACCT_TYPE_MUTUAL = 6 , ACCT_TYPE_CURRENCY = 7 , ACCT_TYPE_INCOME = 8 , ACCT_TYPE_EXPENSE = 9 ,
  ACCT_TYPE_EQUITY = 10 , ACCT_TYPE_RECEIVABLE = 11 , ACCT_TYPE_PAYABLE = 12 , ACCT_TYPE_ROOT = 13 ,
  ACCT_TYPE_TRADING = 14 , NUM_ACCOUNT_TYPES = 15 , ACCT_TYPE_CHECKING = 15 , ACCT_TYPE_SAVINGS = 16 ,
  ACCT_TYPE_MONEYMRKT = 17 , ACCT_TYPE_CREDITLINE = 18 , ACCT_TYPE_LAST
}
 The account types are used to determine how the transaction data in the account is displayed. More...
 

Functions

GType gnc_account_get_type (void)
 Returns the GType type system description of the Account class.
 
gboolean gnc_account_and_descendants_empty (Account *acc)
 
gchar * gnc_account_name_violations_errmsg (const gchar *separator, GList *invalid_account_names)
 Composes a translatable error message showing which account names clash with the current account separator.
 
GList * gnc_account_list_name_violations (QofBook *book, const gchar *separator)
 Runs through all the accounts and returns a list of account names that contain the provided separator character.
 
void xaccAccountSetReconcileChildrenStatus (Account *account, gboolean status)
 DOCUMENT ME!
 
gboolean xaccAccountGetReconcileChildrenStatus (const Account *account)
 DOCUMENT ME!
 
gboolean xaccAccountHasAncestor (const Account *acc, const Account *ancestor)
 Returns true if the account is 'ancestor' or has 'ancestor' as an ancestor.
 
const SplitsVec & xaccAccountGetSplits (const Account *)
 
void gnc_account_foreach_descendant (const Account *, std::function< void(Account *)> func)
 
template<typename Fn >
void gnc_account_foreach_split_between_dates (const Account *account, std::optional< time64 > start_date, std::optional< time64 > end_date, bool include_descendants, Fn &&fn)
 
void gnc_account_foreach_split (const Account *, std::function< void(Split *)>)
 
void gnc_account_foreach_split_until_date (const Account *acc, time64 end_date, std::function< void(Split *)> f)
 
Split * gnc_account_find_split (const Account *, std::function< bool(const Split *)>, bool)
 scans account split list (in forward or reverse order) until predicate split->bool returns true.
 
std::vector< const Account * > gnc_account_get_all_parents (const Account *account)
 

Account Constructors, Edit/Commit, Comparison

Account * xaccMallocAccount (QofBook *book)
 Constructor.
 
Account * gnc_account_create_root (QofBook *book)
 Create a new root level account.
 
Account * xaccCloneAccount (const Account *source, QofBook *book)
 The xaccCloneAccount() routine makes a simple copy of the indicated account, placing it in the indicated book.
 
void xaccAccountBeginEdit (Account *account)
 The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account updates.
 
void xaccAccountCommitEdit (Account *account)
 ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account updates.
 
void xaccAccountDestroy (Account *account)
 The xaccAccountDestroy() routine can be used to get rid of an account.
 
void xaccAccountDestroyAllTransactions (Account *acc)
 Destroy all of the transactions that parent splits in an account.
 
gboolean xaccAccountEqual (const Account *a, const Account *b, gboolean check_guids)
 Compare two accounts for equality - this is a deep compare.
 
int xaccAccountOrder (const Account *account_1, const Account *account_2)
 The xaccAccountOrder() subroutine defines a sorting order on accounts.
 

Account lookup and GncGUID routines

const gchar * gnc_get_account_separator_string (void)
 Returns the account separation character chosen by the user.
 
gunichar gnc_get_account_separator (void)
 
void gnc_set_account_separator (const gchar *separator)
 
Account * gnc_book_get_root_account (QofBook *book)
 
void gnc_book_set_root_account (QofBook *book, Account *root)
 
Account * xaccAccountLookup (const GncGUID *guid, QofBook *book)
 The xaccAccountLookup() subroutine will return the account associated with the given id, or NULL if there is no such account.
 
#define xaccAccountGetGUID(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 
#define xaccAccountReturnGUID(X)   (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
 
#define xaccAccountLookupDirect(g, b)   xaccAccountLookup(&(g),b)
 

Account general setters/getters

QofBook * gnc_account_get_book (const Account *account)
 
void xaccAccountSetType (Account *account, GNCAccountType)
 Set the account's type.
 
void xaccAccountSetName (Account *account, const char *name)
 Set the account's name.
 
void xaccAccountSetCode (Account *account, const char *code)
 Set the account's accounting code.
 
void xaccAccountSetDescription (Account *account, const char *desc)
 Set the account's description.
 
void xaccAccountSetColor (Account *account, const char *color)
 Set the account's Color.
 
void xaccAccountSetFilter (Account *account, const char *filter)
 Set the account's Filter.
 
void xaccAccountSetSortOrder (Account *account, const char *sortorder)
 Set the account's Sort Order.
 
void xaccAccountSetSortReversed (Account *account, gboolean sortreversed)
 Set the account's Sort Order direction.
 
void xaccAccountSetNotes (Account *account, const char *notes)
 Set the account's notes.
 
void xaccAccountSetOnlineID (Account *account, const char *id)
 Set the account's online_id, the identifier (e.g.
 
void xaccAccountSetAssociatedAccount (Account *acc, const char *tag, const Account *assoc_acct)
 Set the account's associated account e.g.
 
void xaccAccountSetLastNum (Account *account, const char *num)
 Set the last num field of an Account.
 
void gnc_account_set_policy (Account *account, GNCPolicy *policy)
 Set the account's lot order policy.
 
GNCAccountType xaccAccountGetType (const Account *account)
 Returns the account's account type.
 
gboolean xaccAccountIsPriced (const Account *acc)
 Returns true if the account is a stock, mutual fund or currency, otherwise false.
 
void gnc_account_set_start_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting commodity balance for this account.
 
void gnc_account_set_start_cleared_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting cleared commodity balance for this account.
 
void gnc_account_set_start_reconciled_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting reconciled commodity balance for this account.
 
void gnc_account_set_balance_dirty (Account *acc)
 Tell the account that the running balances may be incorrect and need to be recomputed.
 
void gnc_account_set_sort_dirty (Account *acc)
 Tell the account believes that the splits may be incorrectly sorted and need to be resorted.
 
void gnc_account_set_defer_bal_computation (Account *acc, gboolean defer)
 Set the defer balance flag.
 
gboolean gnc_account_insert_split (Account *acc, Split *s)
 Insert the given split from an account.
 
gboolean gnc_account_remove_split (Account *acc, Split *s)
 Remove the given split from an account.
 
const char * xaccAccountGetName (const Account *account)
 Get the account's name.
 
const char * xaccAccountGetCode (const Account *account)
 Get the account's accounting code.
 
const char * xaccAccountGetDescription (const Account *account)
 Get the account's description.
 
const char * xaccAccountGetColor (const Account *account)
 Get the account's color.
 
const char * xaccAccountGetFilter (const Account *account)
 Get the account's filter.
 
const char * xaccAccountGetSortOrder (const Account *account)
 Get the account's Sort Order.
 
gboolean xaccAccountGetSortReversed (const Account *account)
 Get the account's Sort Order direction.
 
const char * xaccAccountGetNotes (const Account *account)
 Get the account's notes.
 
const char * xaccAccountGetOnlineID (const Account *account)
 Get the account's online_id (see xaccAccountSetOnlineID).
 
Account * xaccAccountGetAssociatedAccount (const Account *acc, const char *tag)
 Get the account's associated account e.g.
 
const char * xaccAccountGetLastNum (const Account *account)
 Get the last num field of an Account.
 
GNCPolicy * gnc_account_get_policy (Account *account)
 Get the account's lot order policy.
 
gboolean gnc_account_get_defer_bal_computation (Account *acc)
 Get the account's flag for deferred balance computation.
 
void xaccAccountRecomputeBalance (Account *)
 The following recompute the partial balances (stored with the transaction) and the total balance, for this account.
 
void xaccAccountSortSplits (Account *acc, gboolean force)
 The xaccAccountSortSplits() routine will resort the account's splits if the sort is dirty.
 
gchar * gnc_account_get_full_name (const Account *account)
 The gnc_account_get_full_name routine returns the fully qualified name of the account using the given separator char.
 
Account * xaccAccountGainsAccount (Account *acc, gnc_commodity *curr)
 Retrieve the gains account used by this account for the indicated currency, creating and recording a new one if necessary.
 
void dxaccAccountSetPriceSrc (Account *account, const char *src)
 Set a string that identifies the Finance::Quote backend that should be used to retrieve online prices.
 
const char * dxaccAccountGetPriceSrc (const Account *account)
 Get a string that identifies the Finance::Quote backend that should be used to retrieve online prices.
 

Account Commodity setters/getters

Accounts are used to store an amount of 'something', that 'something' is called the 'commodity'.

An account can only hold one kind of commodity. The following are used to get and set the commodity, and also to set the SCU, the 'Smallest Commodity Unit'.

Note that when we say that a 'split' holds an 'amount', that amount is denominated in the account commodity. Do not confuse 'amount' and 'value'. The 'value' of a split is the value of the amount expressed in the currency of the transaction. Thus, for example, the 'amount' may be 12 apples, where the account commodity is 'apples'. The value of these 12 apples may be 12 dollars, where the transaction currency is 'dollars'.

The SCU is the 'Smallest Commodity Unit', signifying the smallest non-zero amount that can be stored in the account. It is represented as the integer denominator of a fraction. Thus, for example, a SCU of 12 means that 1/12 of something is the smallest amount that can be stored in the account. SCU's can be any value; they do not need to be decimal. This allows the use of accounts with unusual, non-decimal commodities and currencies.

Normally, the SCU is determined by the commodity of the account. However, this default SCU can be over-ridden and set to an account-specific value. This is account-specific value is called the 'non-standard' value in the documentation below.

void xaccAccountSetCommodity (Account *account, gnc_commodity *comm)
 Set the account's commodity.
 
gnc_commodity * xaccAccountGetCommodity (const Account *account)
 Get the account's commodity

 
gnc_commodity * gnc_account_get_currency_or_parent (const Account *account)
 Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
 
int xaccAccountGetCommoditySCU (const Account *account)
 Return the SCU for the account.
 
int xaccAccountGetCommoditySCUi (const Account *account)
 Return the 'internal' SCU setting.
 
void xaccAccountSetCommoditySCU (Account *account, int frac)
 Set the SCU for the account.
 
void xaccAccountSetNonStdSCU (Account *account, gboolean flag)
 Set the flag indicating that this account uses a non-standard SCU.
 
gboolean xaccAccountGetNonStdSCU (const Account *account)
 Return boolean, indicating whether this account uses a non-standard SCU.
 

Account Balance

gnc_numeric xaccAccountGetBalance (const Account *account)
 Get the current balance of the account, which may include future splits.
 
gnc_numeric xaccAccountGetClearedBalance (const Account *account)
 Get the current balance of the account, only including cleared transactions.
 
gnc_numeric xaccAccountGetReconciledBalance (const Account *account)
 Get the current balance of the account, only including reconciled transactions.
 
gnc_numeric xaccAccountGetPresentBalance (const Account *account)
 
gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account)
 
gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account, time64 date)
 Get the balance of the account at the end of the day before the date specified.
 
gnc_numeric xaccAccountGetReconciledBalanceAsOfDate (Account *account, time64 date)
 Get the reconciled balance of the account at the end of the day of the date specified.
 
gnc_numeric xaccAccountConvertBalanceToCurrency (const Account *account, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
 
gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate (const Account *account, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 date)
 
gnc_numeric xaccAccountGetBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetClearedBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetReconciledBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetPresentBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetProjectedMinimumBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetNoclosingBalanceAsOfDateInCurrency (Account *acc, time64 date, gnc_commodity *report_commodity, gboolean include_children)
 This function gets the balance at the end of the given date, ignoring closing entries, in the desired commodity.
 
gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency (Account *account, time64 date, gnc_commodity *report_commodity, gboolean include_children)
 This function gets the balance at the end of the given date in the desired commodity.
 
gnc_numeric xaccAccountGetNoclosingBalanceChangeForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gnc_numeric xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gnc_numeric xaccAccountGetBalanceChangeForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gboolean xaccAccountHasStockSplit (const Account *acc)
 Returns true if the account has a stock split, otherwise false.
 

Account Children and Parents.

The set of accounts is represented as a doubly-linked tree, so that given any account, both its parent and its children can be easily found.

At the top of the tree hierarchy lies a single root node, the root account.

The account tree hierarchy is unique, in that a given account can have only one parent account.

void gnc_account_append_child (Account *new_parent, Account *child)
 This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
 
void gnc_account_remove_child (Account *parent, Account *child)
 This function will remove the specified child account from the specified parent account.
 
Account * gnc_account_get_parent (const Account *account)
 This routine returns a pointer to the parent of the specified account.
 
Account * gnc_account_get_root (Account *account)
 This routine returns the root account of the account tree that the specified account belongs to.
 
gboolean gnc_account_is_root (const Account *account)
 This routine indicates whether the specified account is the root node of an account tree.
 
GList * gnc_account_get_children (const Account *account)
 This routine returns a GList of all children accounts of the specified account.
 
GList * gnc_account_get_children_sorted (const Account *account)
 This routine returns a GList of all children accounts of the specified account, ordered by xaccAccountOrder().
 
gint gnc_account_n_children (const Account *account)
 Return the number of children of the specified account.
 
gint gnc_account_child_index (const Account *parent, const Account *child)
 Return the index of the specified child within the list of the parent's children.
 
Account * gnc_account_nth_child (const Account *parent, gint num)
 Return the n'th child account of the specified parent account.
 
GList * gnc_account_get_descendants (const Account *account)
 This routine returns a flat list of all of the accounts that are descendants of the specified account.
 
GList * gnc_account_get_descendants_sorted (const Account *account)
 This function returns a GList containing all the descendants of the specified account, sorted at each level.
 
gint gnc_account_n_descendants (const Account *account)
 Return the number of descendants of the specified account.
 
gint gnc_account_get_current_depth (const Account *account)
 Return the number of levels of this account below the root account.
 
gint gnc_account_get_tree_depth (const Account *account)
 Return the number of levels of descendants accounts below the specified account.
 

ForEach

void gnc_account_foreach_child (const Account *account, AccountCb func, gpointer user_data)
 This method will traverse the immediate children of this accounts, calling 'func' on each account.
 
void gnc_account_foreach_descendant (const Account *account, AccountCb func, gpointer user_data)
 This method will traverse all children of this accounts and their descendants, calling 'func' on each account.
 
gpointer gnc_account_foreach_descendant_until (const Account *account, AccountCb2 func, gpointer user_data)
 This method will traverse all children of this accounts and their descendants, calling 'func' on each account.
 

Concatenation, Merging

void gnc_account_join_children (Account *to_parent, Account *from_parent)
 The gnc_account_join_children() subroutine will move (reparent) all child accounts from the from_parent account to the to_parent account, preserving the account hierarchy.
 
void gnc_account_merge_children (Account *parent)
 The gnc_account_merge_children() subroutine will go through an account, merging all child accounts that have the same name and description.
 

Detailed Description

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 tradeable: 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. 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

◆ GNC_ACCOUNT

#define GNC_ACCOUNT (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ACCOUNT, Account))

Definition at line 73 of file Account.h.

◆ GNC_ACCOUNT_CLASS

#define GNC_ACCOUNT_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ACCOUNT, AccountClass))

Definition at line 75 of file Account.h.

◆ GNC_ACCOUNT_GET_CLASS

#define GNC_ACCOUNT_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ACCOUNT, AccountClass))

Definition at line 81 of file Account.h.

◆ GNC_IS_ACCOUNT

#define GNC_IS_ACCOUNT (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ACCOUNT))

Definition at line 77 of file Account.h.

◆ GNC_IS_ACCOUNT_CLASS

#define GNC_IS_ACCOUNT_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ACCOUNT))

Definition at line 79 of file Account.h.

◆ GNC_TYPE_ACCOUNT

#define GNC_TYPE_ACCOUNT   (gnc_account_get_type ())

Definition at line 72 of file Account.h.

◆ xaccAccountGetGUID

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

Definition at line 252 of file Account.h.

◆ xaccAccountLookupDirect

#define xaccAccountLookupDirect (   g,
  b 
)    xaccAccountLookup(&(g),b)

Definition at line 259 of file Account.h.

◆ xaccAccountReturnGUID

#define xaccAccountReturnGUID (   X)    (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))

Definition at line 253 of file Account.h.

Typedef Documentation

◆ AccountCb

typedef void(* AccountCb) (Account *a, gpointer data)

Definition at line 63 of file Account.h.

◆ AccountCb2

typedef gpointer(* AccountCb2) (Account *a, gpointer data)

Definition at line 64 of file Account.h.

◆ AccountVec

using AccountVec = std::vector<Account*>

Definition at line 45 of file Account.hpp.

◆ SplitsVec

using SplitsVec = std::vector<Split*>

Definition at line 44 of file Account.hpp.

◆ xaccGetBalanceAsOfDateFn

typedef gnc_numeric(* xaccGetBalanceAsOfDateFn) (Account *account, time64 date)

Definition at line 60 of file Account.h.

◆ xaccGetBalanceFn

typedef gnc_numeric(* xaccGetBalanceFn) (const Account *account)

Definition at line 54 of file Account.h.

◆ xaccGetBalanceInCurrencyFn

typedef gnc_numeric(* xaccGetBalanceInCurrencyFn) (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)

Definition at line 56 of file Account.h.

Enumeration Type Documentation

◆ GNCAccountType

The account types are used to determine how the transaction data in the account is displayed.

These values can be safely changed from one release to the next. Note that if values are added, the file IO translation routines need to be updated. Note also that GUI code depends on these numbers.

Note
IMPORTANT: If you do change the enumeration names (not the numbers), you need to update xaccAccountTypeEnumAsString — used for text file exports
Enumerator
ACCT_TYPE_INVALID 

Not a type.

ACCT_TYPE_NONE 

Not a type.

ACCT_TYPE_BANK 

The bank account type denotes a savings or checking account held at a bank.

Often interest bearing.

ACCT_TYPE_CASH 

The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.

ACCT_TYPE_CREDIT 

The Credit card account is used to denote credit (e.g.

amex) and debit (e.g. visa, mastercard) card accounts

ACCT_TYPE_ASSET 

asset (and liability) accounts indicate generic, generalized accounts that are none of the above.

ACCT_TYPE_LIABILITY 

liability (and asset) accounts indicate generic, generalized accounts that are none of the above.

ACCT_TYPE_STOCK 

Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.

ACCT_TYPE_MUTUAL 

Mutual Fund accounts will typically be shown in registers which show three columns: price, number of shares, and value.

ACCT_TYPE_CURRENCY 

The currency account type indicates that the account is a currency trading account.

In many ways, a currency trading account is like a stock * trading account. It is shown in the register with three columns: price, number of shares, and value. Note: Since version 1.7.0, this account is * no longer needed to exchange currencies between accounts, so this type is DEPRECATED.

ACCT_TYPE_INCOME 

Income accounts are used to denote income.

ACCT_TYPE_EXPENSE 

Expense accounts are used to denote expenses.

ACCT_TYPE_EQUITY 

Equity account is used to balance the balance sheet.

ACCT_TYPE_RECEIVABLE 

A/R account type.

ACCT_TYPE_PAYABLE 

A/P account type.

ACCT_TYPE_ROOT 

The hidden root account of an account tree.

ACCT_TYPE_TRADING 

Account used to record multiple commodity transactions.

This is not the same as ACCT_TYPE_CURRENCY above. Multiple commodity transactions have splits in these accounts to make the transaction balance in each commodity as well as in total value.

NUM_ACCOUNT_TYPES 

stop here; the following types just aren't ready for prime time

ACCT_TYPE_CHECKING 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_SAVINGS 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_MONEYMRKT 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_CREDITLINE 

line of credit – don't use this for now, see NUM_ACCOUNT_TYPES

Definition at line 101 of file Account.h.

103{
104 ACCT_TYPE_INVALID = -1,
105 ACCT_TYPE_NONE = -1,
107 ACCT_TYPE_BANK = 0,
110 ACCT_TYPE_CASH = 1,
113 ACCT_TYPE_CREDIT = 3,
116 ACCT_TYPE_ASSET = 2,
122 ACCT_TYPE_STOCK = 5,
125 ACCT_TYPE_MUTUAL = 6,
140 ACCT_TYPE_INCOME = 8,
146 ACCT_TYPE_EQUITY = 10,
151 ACCT_TYPE_PAYABLE = 12,
153 ACCT_TYPE_ROOT = 13,
155 ACCT_TYPE_TRADING = 14,
161 NUM_ACCOUNT_TYPES = 15,
164 /* bank account types */
165 ACCT_TYPE_CHECKING = 15,
167 ACCT_TYPE_SAVINGS = 16,
173 ACCT_TYPE_LAST
174#ifdef __cplusplus
175};
176#else
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed.
Definition Account.h:103
@ ACCT_TYPE_INCOME
Income accounts are used to denote income.
Definition Account.h:140
@ ACCT_TYPE_MUTUAL
Mutual Fund accounts will typically be shown in registers which show three columns: price,...
Definition Account.h:125
@ ACCT_TYPE_ROOT
The hidden root account of an account tree.
Definition Account.h:153
@ ACCT_TYPE_CREDITLINE
line of credit – don't use this for now, see NUM_ACCOUNT_TYPES
Definition Account.h:171
@ ACCT_TYPE_TRADING
Account used to record multiple commodity transactions.
Definition Account.h:155
@ ACCT_TYPE_EXPENSE
Expense accounts are used to denote expenses.
Definition Account.h:143
@ ACCT_TYPE_BANK
The bank account type denotes a savings or checking account held at a bank.
Definition Account.h:107
@ ACCT_TYPE_PAYABLE
A/P account type.
Definition Account.h:151
@ ACCT_TYPE_ASSET
asset (and liability) accounts indicate generic, generalized accounts that are none of the above.
Definition Account.h:116
@ ACCT_TYPE_CURRENCY
The currency account type indicates that the account is a currency trading account.
Definition Account.h:129
@ ACCT_TYPE_MONEYMRKT
bank account type – don't use this for now, see NUM_ACCOUNT_TYPES
Definition Account.h:169
@ ACCT_TYPE_RECEIVABLE
A/R account type.
Definition Account.h:149
@ ACCT_TYPE_CASH
The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.
Definition Account.h:110
@ ACCT_TYPE_LIABILITY
liability (and asset) accounts indicate generic, generalized accounts that are none of the above.
Definition Account.h:119
@ ACCT_TYPE_CHECKING
bank account type – don't use this for now, see NUM_ACCOUNT_TYPES
Definition Account.h:165
@ ACCT_TYPE_EQUITY
Equity account is used to balance the balance sheet.
Definition Account.h:146
@ ACCT_TYPE_CREDIT
The Credit card account is used to denote credit (e.g.
Definition Account.h:113
@ NUM_ACCOUNT_TYPES
stop here; the following types just aren't ready for prime time
Definition Account.h:161
@ ACCT_TYPE_STOCK
Stock accounts will typically be shown in registers which show three columns: price,...
Definition Account.h:122
@ ACCT_TYPE_SAVINGS
bank account type – don't use this for now, see NUM_ACCOUNT_TYPES
Definition Account.h:167
@ ACCT_TYPE_INVALID
Not a type.
Definition Account.h:104
@ ACCT_TYPE_NONE
Not a type.
Definition Account.h:105

Function Documentation

◆ dxaccAccountGetPriceSrc()

const char * dxaccAccountGetPriceSrc ( const Account *  account)

Get a string that identifies the Finance::Quote backend that should be used to retrieve online prices.

See price-quotes.scm for more information. This function uses a static char*.

Deprecated:
Price quote information is now stored on the commodity, not the account.

Definition at line 4835 of file Account.cpp.

4836{
4837 if (!acc) return nullptr;
4838
4839 if (!xaccAccountIsPriced(acc)) return nullptr;
4840
4841 return get_kvp_string_path (acc, {"old-price-source"});
4842}
gboolean xaccAccountIsPriced(const Account *acc)
Returns true if the account is a stock, mutual fund or currency, otherwise false.
Definition Account.cpp:4539

◆ dxaccAccountSetPriceSrc()

void dxaccAccountSetPriceSrc ( Account *  account,
const char *  src 
)

Set a string that identifies the Finance::Quote backend that should be used to retrieve online prices.

See price-quotes.scm for more information

Deprecated:
Price quote information is now stored on the commodity, not the account.

Definition at line 4823 of file Account.cpp.

4824{
4825 if (!acc) return;
4826
4827 if (xaccAccountIsPriced(acc))
4828 set_kvp_string_path (acc, {"old-price-source"}, src);
4829}

◆ gnc_account_and_descendants_empty()

gboolean gnc_account_and_descendants_empty ( Account *  acc)

Definition at line 3953 of file Account.cpp.

3954{
3955 g_return_val_if_fail (GNC_IS_ACCOUNT (acc), FALSE);
3956 auto priv = GET_PRIVATE (acc);
3957 if (!priv->splits.empty()) return FALSE;
3958 return std::all_of (priv->children.begin(), priv->children.end(),
3959 gnc_account_and_descendants_empty);
3960}

◆ gnc_account_append_child()

void gnc_account_append_child ( Account *  new_parent,
Account *  child 
)

This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.

The exception to this is when the old and new parent accounts are the same, in which case this function does nothing.

If the child account belongs to a different book than the specified new parent account, the child will be removed from the other book (and thus, the other book's entity tables, generating a destroy event), and will be added to the new book (generating a create event).

Parameters
new_parentThe new parent account to which the child should be attached.
childThe account to attach.

Definition at line 2824 of file Account.cpp.

2825{
2826 AccountPrivate *ppriv, *cpriv;
2827 Account *old_parent;
2828 QofCollection *col;
2829
2830 /* errors */
2831 g_assert(GNC_IS_ACCOUNT(new_parent));
2832 g_assert(GNC_IS_ACCOUNT(child));
2833
2834 /* optimizations */
2835 ppriv = GET_PRIVATE(new_parent);
2836 cpriv = GET_PRIVATE(child);
2837 old_parent = cpriv->parent;
2838 if (old_parent == new_parent)
2839 return;
2840
2841 // xaccAccountBeginEdit(new_parent);
2842 xaccAccountBeginEdit(child);
2843 if (old_parent)
2844 {
2845 gnc_account_remove_child(old_parent, child);
2846
2847 if (!qof_instance_books_equal(old_parent, new_parent))
2848 {
2849 /* hack alert -- this implementation is not exactly correct.
2850 * If the entity tables are not identical, then the 'from' book
2851 * may have a different backend than the 'to' book. This means
2852 * that we should get the 'from' backend to destroy this account,
2853 * and the 'to' backend to save it. Right now, this is broken.
2854 *
2855 * A 'correct' implementation similar to this is in Period.c
2856 * except its for transactions ...
2857 *
2858 * Note also, we need to reparent the children to the new book as well.
2859 */
2860 PWARN ("reparenting accounts across books is not correctly supported\n");
2861
2862 qof_event_gen (&child->inst, QOF_EVENT_DESTROY, nullptr);
2864 GNC_ID_ACCOUNT);
2865 qof_collection_insert_entity (col, &child->inst);
2866 qof_event_gen (&child->inst, QOF_EVENT_CREATE, nullptr);
2867 }
2868 }
2869 cpriv->parent = new_parent;
2870 ppriv->children.push_back (child);
2871 qof_instance_set_dirty(&new_parent->inst);
2872 qof_instance_set_dirty(&child->inst);
2873
2874 /* Send events data. Warning: The call to commit_edit is also going
2875 * to send a MODIFY event. If the gtktreemodelfilter code gets the
2876 * MODIFY before it gets the ADD, it gets very confused and thinks
2877 * that two nodes have been added. */
2878 qof_event_gen (&child->inst, QOF_EVENT_ADD, nullptr);
2879 // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, nullptr);
2880
2881 xaccAccountCommitEdit (child);
2882 // xaccAccountCommitEdit(new_parent);
2883}
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition Account.cpp:1504
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition Account.cpp:1463
void gnc_account_remove_child(Account *parent, Account *child)
This function will remove the specified child account from the specified parent account.
Definition Account.cpp:2886
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
See if two QofInstances share the same book.
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
void qof_collection_insert_entity(QofCollection *, QofInstance *)
Take entity, remove it from whatever collection its currently in, and place it in a new collection.
Definition qofid.cpp:95
STRUCTS.

◆ gnc_account_child_index()

gint gnc_account_child_index ( const Account *  parent,
const Account *  child 
)

Return the index of the specified child within the list of the parent's children.

The first child index is 0. This function returns -1 if the parent account is NULL of if the specified child does not belong to the parent account.

Parameters
parentThe parent account to check.
childThe child account to find.
Returns
The index of the child account within the specified parent, or -1.

Definition at line 2971 of file Account.cpp.

2972{
2973 g_return_val_if_fail(GNC_IS_ACCOUNT(parent), -1);
2974 g_return_val_if_fail(GNC_IS_ACCOUNT(child), -1);
2975 auto& children = GET_PRIVATE(parent)->children;
2976 auto find_it = std::find (children.begin(), children.end(), child);
2977 return find_it == children.end() ? -1 : std::distance (children.begin(), find_it);
2978}

◆ gnc_account_create_root()

Account * gnc_account_create_root ( QofBook *  book)

Create a new root level account.


Definition at line 1272 of file Account.cpp.

1273{
1274 Account *root;
1275 AccountPrivate *rpriv;
1276
1277 root = xaccMallocAccount(book);
1278 rpriv = GET_PRIVATE(root);
1280 rpriv->type = ACCT_TYPE_ROOT;
1281 rpriv->accountName = qof_string_cache_replace(rpriv->accountName, "Root Account");
1282 mark_account (root);
1284 gnc_book_set_root_account(book, root);
1285 return root;
1286}
Account * xaccMallocAccount(QofBook *book)
Constructor.
Definition Account.cpp:1258
const char * qof_string_cache_replace(char const *dst, char const *src)
Same as CACHE_REPLACE below, but safe to call from C++.

◆ gnc_account_find_split()

Split * gnc_account_find_split ( const Account *  acc,
std::function< bool(const Split *)>  predicate,
bool  reverse 
)

scans account split list (in forward or reverse order) until predicate split->bool returns true.

Maybe return the split.

Parameters
accThe account to which the split should be added.
predicateA split->bool predicate.
reverseTo scan in reverse order
Returns
Split* or nullptr if not found

Definition at line 1155 of file Account.cpp.

1157{
1158 if (!GNC_IS_ACCOUNT (acc))
1159 return nullptr;
1160
1161 const auto& splits{GET_PRIVATE(acc)->splits};
1162 if (reverse)
1163 {
1164 auto latest = std::find_if(splits.rbegin(), splits.rend(), predicate);
1165 return (latest == splits.rend()) ? nullptr : *latest;
1166 }
1167 else
1168 {
1169 auto earliest = std::find_if(splits.begin(), splits.end(), predicate);
1170 return (earliest == splits.end()) ? nullptr : *earliest;
1171 }
1172}

◆ gnc_account_foreach_child()

void gnc_account_foreach_child ( const Account *  account,
AccountCb  func,
gpointer  user_data 
)

This method will traverse the immediate children of this accounts, calling 'func' on each account.

This function traverses all children nodes. To traverse only a subset of the child nodes use the gnc_account_foreach_child_until() function.

Parameters
accountA pointer to the account on whose children the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3213 of file Account.cpp.

3216{
3217 g_return_if_fail(GNC_IS_ACCOUNT(acc));
3218 g_return_if_fail(thunk);
3219 std::for_each (GET_PRIVATE(acc)->children.begin(), GET_PRIVATE(acc)->children.end(),
3220 [user_data, thunk](auto a){ thunk (a, user_data); });
3221}

◆ gnc_account_foreach_descendant() [1/2]

void gnc_account_foreach_descendant ( const Account *  acc,
std::function< void(Account *)>  func 
)

Definition at line 2792 of file Account.cpp.

2793{
2794 g_return_if_fail (GNC_IS_ACCOUNT(acc));
2795
2796 // children must be a vector copy instead of reference because
2797 // some callers e.g. xaccAccountTreeScrubLots will modify the
2798 // children
2799 auto children = GET_PRIVATE(acc)->children;
2800 for (auto child : children)
2801 {
2802 account_cb (child);
2803 gnc_account_foreach_descendant (child, account_cb);
2804 }
2805}

◆ gnc_account_foreach_descendant() [2/2]

void gnc_account_foreach_descendant ( const Account *  account,
AccountCb  func,
gpointer  user_data 
)

This method will traverse all children of this accounts and their descendants, calling 'func' on each account.

This function traverses all descendant nodes. To traverse only a subset of the descendant nodes use the gnc_account_foreach_descendant_until() function.

Parameters
accountA pointer to the account on whose descendants the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3224 of file Account.cpp.

3227{
3228 gnc_account_foreach_descendant (acc, [&](auto acc){ thunk (acc, user_data); });
3229}

◆ gnc_account_foreach_descendant_until()

gpointer gnc_account_foreach_descendant_until ( const Account *  account,
AccountCb2  func,
gpointer  user_data 
)

This method will traverse all children of this accounts and their descendants, calling 'func' on each account.

Traversal will stop when func returns a non-null value, and the routine will return with that value. Therefore, this function will return null if func returns null for every account. For a simpler function that always traverses all children nodes, use the gnc_account_foreach_descendant() function.

Parameters
accountA pointer to the account on whose descendants the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3232 of file Account.cpp.

3235{
3236 gpointer result {nullptr};
3237
3238 g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr);
3239 g_return_val_if_fail (thunk, nullptr);
3240
3241 for (auto child : GET_PRIVATE(acc)->children)
3242 {
3243 result = thunk (child, user_data);
3244 if (result) break;
3245
3246 result = gnc_account_foreach_descendant_until (child, thunk, user_data);
3247 if (result) break;
3248 }
3249
3250 return result;
3251}
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
Definition Account.cpp:3232

◆ gnc_account_foreach_split()

void gnc_account_foreach_split ( const Account *  acc,
std::function< void(Split *)>  func 
)

Definition at line 1141 of file Account.cpp.

1142{
1143 gnc_account_foreach_split_between_dates (acc, {}, {}, false, func);
1144}

◆ gnc_account_foreach_split_between_dates()

template<typename Fn >
void gnc_account_foreach_split_between_dates ( const Account *  account,
std::optional< time64 >  start_date,
std::optional< time64 >  end_date,
bool  include_descendants,
Fn &&  fn 
)

Definition at line 69 of file Account.hpp.

73{
74 g_return_if_fail (GNC_IS_ACCOUNT (account));
75 auto scan_account = [&](const Account* acc)
76 {
77 const auto& splits = xaccAccountGetSplits (acc);
78 std::for_each (splits_start (splits, start_date), splits_end (splits, end_date),
79 fn);
80 };
81
82 scan_account (account);
83 if (include_descendants)
84 gnc_account_foreach_descendant (account, scan_account);
85}

◆ gnc_account_foreach_split_until_date()

void gnc_account_foreach_split_until_date ( const Account *  acc,
time64  end_date,
std::function< void(Split *)>  f 
)

Definition at line 1147 of file Account.cpp.

1149{
1150 gnc_account_foreach_split_between_dates (acc, {}, end_date, false, f);
1151}

◆ gnc_account_get_all_parents()

std::vector< const Account * > gnc_account_get_all_parents ( const Account *  account)

Definition at line 3284 of file Account.cpp.

3285{
3286 std::vector<const Account*> rv;
3287 for (auto a = account; !gnc_account_is_root (a); a = gnc_account_get_parent (a))
3288 rv.push_back (a);
3289 return rv;
3290}
gboolean gnc_account_is_root(const Account *account)
This routine indicates whether the specified account is the root node of an account tree.
Definition Account.cpp:2941
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
Definition Account.cpp:2923

◆ gnc_account_get_book()

QofBook * gnc_account_get_book ( const Account *  account)

Definition at line 1178 of file Account.cpp.

1179{
1180 if (!account) return nullptr;
1181 return qof_instance_get_book(QOF_INSTANCE(account));
1182}

◆ gnc_account_get_children()

GList * gnc_account_get_children ( const Account *  account)

This routine returns a GList of all children accounts of the specified account.

This function only returns the immediate children of the specified account. For a list of all descendant accounts, use the gnc_account_get_descendants() function.

If you are looking for the splits of this account, use xaccAccountGetSplitList() instead. This function here deals with children accounts inside the account tree.

Parameters
accountThe account whose children should be returned.
Returns
A GList of account pointers, or NULL if there are no children accounts. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 2948 of file Account.cpp.

2949{
2950 g_return_val_if_fail(GNC_IS_ACCOUNT(account), nullptr);
2951 auto& children = GET_PRIVATE(account)->children;
2952 return std::accumulate (children.rbegin(), children.rend(), static_cast<GList*>(nullptr),
2953 g_list_prepend);
2954}

◆ gnc_account_get_children_sorted()

GList * gnc_account_get_children_sorted ( const Account *  account)

This routine returns a GList of all children accounts of the specified account, ordered by xaccAccountOrder().

See also
gnc_account_get_children()

Definition at line 2957 of file Account.cpp.

2958{
2959 g_return_val_if_fail(GNC_IS_ACCOUNT(account), nullptr);
2960 return g_list_sort(gnc_account_get_children (account), (GCompareFunc)xaccAccountOrder);
2961}
GList * gnc_account_get_children(const Account *account)
This routine returns a GList of all children accounts of the specified account.
Definition Account.cpp:2948
int xaccAccountOrder(const Account *aa, const Account *ab)
The xaccAccountOrder() subroutine defines a sorting order on accounts.
Definition Account.cpp:2363

◆ gnc_account_get_currency_or_parent()

gnc_commodity * gnc_account_get_currency_or_parent ( const Account *  account)

Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.

The gnc_commodity is taken either from the current account, or from the next parent account that has a gnc_commodity that is a currency. If neither this account nor any of its parent has such a commodity that is a currency, NULL is returned. In that case, you can use gnc_default_currency() but you might want to show a warning dialog first.

Definition at line 3403 of file Account.cpp.

3404{
3405 g_return_val_if_fail (GNC_IS_ACCOUNT (account), nullptr);
3406
3407 for (auto acc = account; acc; acc = gnc_account_get_parent (acc))
3408 if (auto comm = xaccAccountGetCommodity (acc); gnc_commodity_is_currency (comm))
3409 return comm;
3410
3411 return nullptr; // no suitable commodity found.
3412}
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Definition Account.cpp:3396
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency.

◆ gnc_account_get_current_depth()

gint gnc_account_get_current_depth ( const Account *  account)

Return the number of levels of this account below the root account.

Parameters
accountThe account to query.
Returns
The number of levels below the root.

Definition at line 2998 of file Account.cpp.

2999{
3000 AccountPrivate *priv;
3001 int depth = 0;
3002
3003 g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
3004
3005 priv = GET_PRIVATE(account);
3006 while (priv->parent && (priv->type != ACCT_TYPE_ROOT))
3007 {
3008 account = priv->parent;
3009 priv = GET_PRIVATE(account);
3010 depth++;
3011 }
3012
3013 return depth;
3014}

◆ gnc_account_get_defer_bal_computation()

gboolean gnc_account_get_defer_bal_computation ( Account *  acc)

Get the account's flag for deferred balance computation.

Definition at line 1912 of file Account.cpp.

1913{
1914 AccountPrivate *priv;
1915 if (!acc)
1916 return false;
1917 priv = GET_PRIVATE (acc);
1918 return priv->defer_bal_computation;
1919}

◆ gnc_account_get_descendants()

GList * gnc_account_get_descendants ( const Account *  account)

This routine returns a flat list of all of the accounts that are descendants of the specified account.

This includes not only the the children, but the children of the children, etc. For a list of only the immediate child accounts, use the gnc_account_get_children() function. Within each set of child accounts, the accounts returned by this function are unordered. For a list of descendants where each set of children is sorted via the standard account sort function, use the gnc_account_get_descendants_sorted() function.

Parameters
accountThe account whose descendants should be returned.
Returns
A GList of account pointers, or NULL if there are no descendants. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 3032 of file Account.cpp.

3033{
3034 GList* list = nullptr;
3035 gnc_account_foreach_descendant (account, [&list](auto a){ list = g_list_prepend (list, a); });
3036 return g_list_reverse (list);
3037}

◆ gnc_account_get_descendants_sorted()

GList * gnc_account_get_descendants_sorted ( const Account *  account)

This function returns a GList containing all the descendants of the specified account, sorted at each level.

This includes not only the the children, but the children of the children, etc. Within each set of child accounts, the accounts returned by this function are ordered via the standard account sort function. For a list of descendants where each set of children is unordered, use the gnc_account_get_descendants() function.

Note: Use this function where the results are intended for display to the user. If the results are internal to GnuCash or will be resorted at some later point in time you should use the gnc_account_get_descendants() function.

Parameters
accountThe account whose descendants should be returned.
Returns
A GList of account pointers, or NULL if there are no descendants. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 3040 of file Account.cpp.

3041{
3042 GList* list = nullptr;
3043 account_foreach_descendant_sorted (account, [&list](auto a){ list = g_list_prepend (list, a); });
3044 return g_list_reverse (list);
3045}

◆ gnc_account_get_full_name()

gchar * gnc_account_get_full_name ( const Account *  account)

The gnc_account_get_full_name routine returns the fully qualified name of the account using the given separator char.

The name must be g_free'd after use. The fully qualified name of an account is the concatenation of the names of the account and all its ancestor accounts starting with the topmost account and ending with the given account. Each name is separated by the given character.

Note
: WAKE UP! Unlike all other gets, the string returned by gnc_account_get_full_name() must be freed by you the user !!! hack alert – since it breaks the rule of string allocation, maybe this routine should not be in this library, but some utility library?

Definition at line 3293 of file Account.cpp.

3294{
3295 /* So much for hardening the API. Too many callers to this function don't
3296 * bother to check if they have a non-nullptr pointer before calling. */
3297 if (nullptr == account)
3298 return g_strdup("");
3299
3300 /* errors */
3301 g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
3302
3303 auto path{gnc_account_get_all_parents (account)};
3304 auto seps_size{path.empty() ? 0 : strlen (account_separator) * (path.size() - 1)};
3305 auto alloc_size{std::accumulate (path.begin(), path.end(), seps_size,
3306 [](auto sum, auto acc)
3307 { return sum + strlen (xaccAccountGetName (acc)); })};
3308 auto rv = g_new (char, alloc_size + 1);
3309 auto p = rv;
3310
3311 std::for_each (path.rbegin(), path.rend(),
3312 [&p, rv](auto a)
3313 {
3314 if (p != rv)
3315 p = stpcpy (p, account_separator);
3316 p = stpcpy (p, xaccAccountGetName (a));
3317 });
3318 *p = '\0';
3319
3320 return rv;
3321}

◆ gnc_account_get_parent()

Account * gnc_account_get_parent ( const Account *  account)

This routine returns a pointer to the parent of the specified account.

If the account has no parent, i.e it is either the root node or is a disconnected account, then its parent will be NULL.

Parameters
accountA pointer to any exiting account.
Returns
A pointer to the parent account node, or NULL if there is no parent account.

Definition at line 2923 of file Account.cpp.

2924{
2925 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
2926 return GET_PRIVATE(acc)->parent;
2927}

◆ gnc_account_get_policy()

GNCPolicy * gnc_account_get_policy ( Account *  account)

Get the account's lot order policy.

Definition at line 2088 of file Account.cpp.

2089{
2090 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
2091
2092 return GET_PRIVATE(acc)->policy;
2093}

◆ gnc_account_get_root()

Account * gnc_account_get_root ( Account *  account)

This routine returns the root account of the account tree that the specified account belongs to.

It is the equivalent of repeatedly calling the gnc_account_get_parent() routine until that routine returns NULL.

Parameters
accountA pointer to any existing account.
Returns
The root node of the account tree to which this account belongs. NULL if the account is not part of any account tree.

Definition at line 2930 of file Account.cpp.

2931{
2932 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
2933
2934 while (auto parent = gnc_account_get_parent (acc))
2935 acc = parent;
2936
2937 return acc;
2938}

◆ gnc_account_get_tree_depth()

gint gnc_account_get_tree_depth ( const Account *  account)

Return the number of levels of descendants accounts below the specified account.

The returned number does not include the specified account itself.

Parameters
accountThe account to query.
Returns
The number of levels of descendants.

Definition at line 3017 of file Account.cpp.

3018{
3019 AccountPrivate *priv;
3020 g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
3021
3022 priv = GET_PRIVATE(account);
3023 if (!priv->children.size())
3024 return 1;
3025
3026 return 1 + std::accumulate (priv->children.begin(), priv->children.end(),
3027 0, [](auto a, auto b)
3028 { return std::max (a, gnc_account_get_tree_depth (b)); });
3029}

◆ gnc_account_get_type()

GType gnc_account_get_type ( void  )

Returns the GType type system description of the Account class.

This must not be confused with the GNCAccountType as returned by xaccAccountGetType().

Definition at line 27 of file gmock-Account.cpp.

28{
29 return gnc_mockaccount_get_type();
30}

◆ gnc_account_insert_split()

gboolean gnc_account_insert_split ( Account *  acc,
Split *  s 
)

Insert the given split from an account.

Parameters
accThe account to which the split should be added.
sThe split to be added.
Returns
TRUE is the split is successfully added to the set of splits in the account. FALSE if the addition fails for any reason (including that the split is already in the account).

Definition at line 1931 of file Account.cpp.

1932{
1933 AccountPrivate *priv;
1934
1935 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1936 g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1937
1938 priv = GET_PRIVATE(acc);
1939 if (!g_hash_table_add (priv->splits_hash, s))
1940 return false;
1941
1942 priv->splits.push_back (s);
1943
1944 if (qof_instance_get_editlevel(acc) == 0)
1945 std::sort (priv->splits.begin(), priv->splits.end(), split_cmp_less);
1946 else
1947 priv->sort_dirty = true;
1948
1949 //FIXME: find better event
1950 qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, nullptr);
1951 /* Also send an event based on the account */
1952 qof_event_gen(&acc->inst, GNC_EVENT_ITEM_ADDED, s);
1953
1954 priv->balance_dirty = TRUE;
1955// DRH: Should the below be added? It is present in the delete path.
1956// xaccAccountRecomputeBalance(acc);
1957 return TRUE;
1958}
#define GNC_EVENT_ITEM_ADDED
These events are used when a split is added to an account.
Definition gnc-event.h:45

◆ gnc_account_is_root()

gboolean gnc_account_is_root ( const Account *  account)

This routine indicates whether the specified account is the root node of an account tree.

Parameters
accountA pointer to any account.
Returns
TRUE if this account is of type ROOT. FALSE otherwise.

Definition at line 2941 of file Account.cpp.

2942{
2943 g_return_val_if_fail(GNC_IS_ACCOUNT(account), FALSE);
2944 return (GET_PRIVATE(account)->parent == nullptr);
2945}

◆ gnc_account_join_children()

void gnc_account_join_children ( Account *  to_parent,
Account *  from_parent 
)

The gnc_account_join_children() subroutine will move (reparent) all child accounts from the from_parent account to the to_parent account, preserving the account hierarchy.

It will also take care that the moved accounts will have the to_parent's book parent as well.

Definition at line 4919 of file Account.cpp.

4920{
4921
4922 /* errors */
4923 g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
4924 g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
4925
4926 /* optimizations */
4927 auto from_priv = GET_PRIVATE(from_parent);
4928 if (from_priv->children.empty())
4929 return;
4930
4931 ENTER (" ");
4932 auto children = from_priv->children;
4933 for (auto child : children)
4934 gnc_account_append_child(to_parent, child);
4935 LEAVE (" ");
4936}
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship,...
Definition Account.cpp:2824
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

◆ gnc_account_list_name_violations()

GList * gnc_account_list_name_violations ( QofBook *  book,
const gchar *  separator 
)

Runs through all the accounts and returns a list of account names that contain the provided separator character.

This can be used to check if certain account names are invalid.

Parameters
bookPointer to the book with accounts to verify
separatorThe separator character to verify against
Returns
A GList of invalid account names. Should be freed with g_list_free_full (value, g_free) when no longer needed.

Definition at line 273 of file Account.cpp.

274{
275 g_return_val_if_fail (separator != nullptr, nullptr);
276 if (!book) return nullptr;
277 ViolationData cb = { nullptr, separator };
278 gnc_account_foreach_descendant (gnc_book_get_root_account (book),
279 (AccountCb)check_acct_name, &cb);
280 return cb.list;
281}

◆ gnc_account_merge_children()

void gnc_account_merge_children ( Account *  parent)

The gnc_account_merge_children() subroutine will go through an account, merging all child accounts that have the same name and description.

This function is useful when importing Quicken(TM) files.

Definition at line 4941 of file Account.cpp.

4942{
4943 g_return_if_fail(GNC_IS_ACCOUNT(parent));
4944
4945 auto ppriv = GET_PRIVATE(parent);
4946 for (auto it_a = ppriv->children.begin(); it_a != ppriv->children.end(); it_a++)
4947 {
4948 auto acc_a = *it_a;
4949 auto priv_a = GET_PRIVATE(acc_a);
4950 for (auto it_b = std::next(it_a); it_b != ppriv->children.end(); it_b++)
4951 {
4952 auto acc_b = *it_b;
4953 auto priv_b = GET_PRIVATE(acc_b);
4954 if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
4955 continue;
4956 if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
4957 continue;
4958 if (0 != null_strcmp(priv_a->description, priv_b->description))
4959 continue;
4960 if (0 != null_strcmp(xaccAccountGetColor(acc_a),
4961 xaccAccountGetColor(acc_b)))
4962 continue;
4963 if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
4964 continue;
4965 if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
4966 xaccAccountGetNotes(acc_b)))
4967 continue;
4968 if (priv_a->type != priv_b->type)
4969 continue;
4970
4971 /* consolidate children */
4972 if (!priv_b->children.empty())
4973 {
4974 auto work = priv_b->children;
4975 for (auto w : work)
4976 gnc_account_append_child (acc_a, w);
4977
4978 qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, nullptr);
4979 qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, nullptr);
4980 }
4981
4982 /* recurse to do the children's children */
4984
4985 /* consolidate transactions */
4986 while (!priv_b->splits.empty())
4987 xaccSplitSetAccount (priv_b->splits.front(), acc_a);
4988
4989 /* move back one before removal. next iteration around the loop
4990 * will get the node after node_b */
4991 it_b--;
4992
4993 /* The destroy function will remove from list -- node_a is ok,
4994 * it's before node_b */
4995 xaccAccountBeginEdit (acc_b);
4996 xaccAccountDestroy (acc_b);
4997 }
4998 }
4999}
const char * xaccAccountGetColor(const Account *acc)
Get the account's color.
Definition Account.cpp:3338
void xaccAccountDestroy(Account *acc)
The xaccAccountDestroy() routine can be used to get rid of an account.
Definition Account.cpp:1578
void gnc_account_merge_children(Account *parent)
The gnc_account_merge_children() subroutine will go through an account, merging all child accounts th...
Definition Account.cpp:4941
const char * xaccAccountGetNotes(const Account *acc)
Get the account's notes.
Definition Account.cpp:3362
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gint null_strcmp(const gchar *da, const gchar *db)
The null_strcmp compares strings a and b the same way that strcmp() does, except that either may be n...
Definition qofutil.cpp:123

◆ gnc_account_n_children()

gint gnc_account_n_children ( const Account *  account)

Return the number of children of the specified account.

The returned number does not include the account itself.

Parameters
accountThe account to query.
Returns
The number of children of the specified account.

Definition at line 2964 of file Account.cpp.

2965{
2966 g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2967 return GET_PRIVATE(account)->children.size();
2968}

◆ gnc_account_n_descendants()

gint gnc_account_n_descendants ( const Account *  account)

Return the number of descendants of the specified account.

The returned number does not include the account itself.

Parameters
accountThe account to query.
Returns
The number of descendants of the specified account.

Definition at line 2990 of file Account.cpp.

2991{
2992 int count {0};
2993 gnc_account_foreach_descendant (account, [&count](auto acc){ count++; });
2994 return count;
2995}

◆ gnc_account_name_violations_errmsg()

gchar * gnc_account_name_violations_errmsg ( const gchar *  separator,
GList *  invalid_account_names 
)

Composes a translatable error message showing which account names clash with the current account separator.

Can be called after gnc_account_list_name_violations to have a consistent error message in different parts of GnuCash

Parameters
separatorThe separator character that was verified against
invalid_account_namesA GList of invalid account names.
Returns
An error message that can be displayed to the user or logged. This message string should be freed with g_free when no longer needed.

Definition at line 235 of file Account.cpp.

236{
237 gchar *message = nullptr;
238
239 if ( !invalid_account_names )
240 return nullptr;
241
242 auto account_list {gnc_g_list_stringjoin (invalid_account_names, "\n")};
243
244 /* Translators: The first %s will be the account separator character,
245 the second %s is a list of account names.
246 The resulting string will be displayed to the user if there are
247 account names containing the separator character. */
248 message = g_strdup_printf(
249 _("The separator character \"%s\" is used in one or more account names.\n\n"
250 "This will result in unexpected behaviour. "
251 "Either change the account names or choose another separator character.\n\n"
252 "Below you will find the list of invalid account names:\n"
253 "%s"), separator, account_list );
254 g_free ( account_list );
255 return message;
256}
gchar * gnc_g_list_stringjoin(GList *list_of_strings, const gchar *sep)
Return a string joining a GList whose elements are gchar* strings.

◆ gnc_account_nth_child()

Account * gnc_account_nth_child ( const Account *  parent,
gint  num 
)

Return the n'th child account of the specified parent account.

If the parent account is not specified or the child index number is invalid, this function returns NULL.

Parameters
parentThe parent account to check.
numThe index number of the child account that should be returned.
Returns
A pointer to the specified child account, or NULL

Definition at line 2981 of file Account.cpp.

2982{
2983 g_return_val_if_fail(GNC_IS_ACCOUNT(parent), nullptr);
2984 if ((size_t)num >= GET_PRIVATE(parent)->children.size())
2985 return nullptr;
2986 return static_cast<Account*>(GET_PRIVATE(parent)->children.at (num));
2987}

◆ gnc_account_remove_child()

void gnc_account_remove_child ( Account *  parent,
Account *  child 
)

This function will remove the specified child account from the specified parent account.

It will NOT free the associated memory or otherwise alter the account: the account can now be reparented to a new location. Note, however, that it will mark the old parents as having been modified.

Parameters
parentThe parent account from which the child should be removed.
childThe child account to remove.

Definition at line 2886 of file Account.cpp.

2887{
2888 AccountPrivate *ppriv, *cpriv;
2889 GncEventData ed;
2890
2891 if (!child) return;
2892
2893 /* Note this routine might be called on accounts which
2894 * are not yet parented. */
2895 if (!parent) return;
2896
2897 ppriv = GET_PRIVATE(parent);
2898 cpriv = GET_PRIVATE(child);
2899
2900 if (cpriv->parent != parent)
2901 {
2902 PERR ("account not a child of parent");
2903 return;
2904 }
2905
2906 /* Gather event data */
2907 ed.node = parent;
2908 ed.idx = gnc_account_child_index (parent, child);
2909
2910 ppriv->children.erase (std::remove (ppriv->children.begin(), ppriv->children.end(), child),
2911 ppriv->children.end());
2912
2913 /* Now send the event. */
2914 qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
2915
2916 /* clear the account's parent pointer after REMOVE event generation. */
2917 cpriv->parent = nullptr;
2918
2919 qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, nullptr);
2920}
gint gnc_account_child_index(const Account *parent, const Account *child)
Return the index of the specified child within the list of the parent's children.
Definition Account.cpp:2971
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ gnc_account_remove_split()

gboolean gnc_account_remove_split ( Account *  acc,
Split *  s 
)

Remove the given split from an account.

Parameters
accThe account from which the split should be removed.
sThe split to be removed.
Returns
TRUE is the split is successfully removed from the set of splits in the account. FALSE if the removal fails for any reason.

Definition at line 1961 of file Account.cpp.

1962{
1963 AccountPrivate *priv;
1964
1965 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1966 g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1967
1968 priv = GET_PRIVATE(acc);
1969
1970 if (!g_hash_table_remove (priv->splits_hash, s))
1971 return false;
1972
1973 // shortcut pruning the last element. this is the most common
1974 // remove_split operation during UI or book shutdown.
1975 if (s == priv->splits.back())
1976 priv->splits.pop_back();
1977 else
1978 priv->splits.erase (std::remove (priv->splits.begin(), priv->splits.end(), s),
1979 priv->splits.end());
1980
1981 //FIXME: find better event type
1982 qof_event_gen(&acc->inst, QOF_EVENT_MODIFY, nullptr);
1983 // And send the account-based event, too
1984 qof_event_gen(&acc->inst, GNC_EVENT_ITEM_REMOVED, s);
1985
1986 priv->balance_dirty = TRUE;
1988 return TRUE;
1989}
void xaccAccountRecomputeBalance(Account *acc)
The following recompute the partial balances (stored with the transaction) and the total balance,...
Definition Account.cpp:2263

◆ gnc_account_set_balance_dirty()

void gnc_account_set_balance_dirty ( Account *  acc)

Tell the account that the running balances may be incorrect and need to be recomputed.

Parameters
accSet the flag on this account.

Definition at line 1886 of file Account.cpp.

1887{
1888 AccountPrivate *priv;
1889
1890 g_return_if_fail(GNC_IS_ACCOUNT(acc));
1891
1893 return;
1894
1895 priv = GET_PRIVATE(acc);
1896 priv->balance_dirty = TRUE;
1897}
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.

◆ gnc_account_set_defer_bal_computation()

void gnc_account_set_defer_bal_computation ( Account *  acc,
gboolean  defer 
)

Set the defer balance flag.

If defer is true, the account balance is not automatically computed, which can save a lot of time if multiple operations have to be done on the same account. If defer is false, further operations on account will cause the balance to be recomputed as normal.

Parameters
accSet the flag on this account.
deferNew value for the flag.

Definition at line 1899 of file Account.cpp.

1900{
1901 AccountPrivate *priv;
1902
1903 g_return_if_fail (GNC_IS_ACCOUNT (acc));
1904
1906 return;
1907
1908 priv = GET_PRIVATE (acc);
1909 priv->defer_bal_computation = defer;
1910}

◆ gnc_account_set_policy()

void gnc_account_set_policy ( Account *  account,
GNCPolicy *  policy 
)

Set the account's lot order policy.

Definition at line 2096 of file Account.cpp.

2097{
2098 AccountPrivate *priv;
2099
2100 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2101
2102 priv = GET_PRIVATE(acc);
2103 priv->policy = policy ? policy : xaccGetFIFOPolicy();
2104}
GNCPolicy * xaccGetFIFOPolicy(void)
First-in, First-out Policy This policy will create FIFO Lots.
Definition policy.cpp:155

◆ gnc_account_set_sort_dirty()

void gnc_account_set_sort_dirty ( Account *  acc)

Tell the account believes that the splits may be incorrectly sorted and need to be resorted.

Parameters
accSet the flag on this account.

Definition at line 1872 of file Account.cpp.

1873{
1874 AccountPrivate *priv;
1875
1876 g_return_if_fail(GNC_IS_ACCOUNT(acc));
1877
1879 return;
1880
1881 priv = GET_PRIVATE(acc);
1882 priv->sort_dirty = TRUE;
1883}

◆ gnc_account_set_start_balance()

void gnc_account_set_start_balance ( Account *  acc,
const gnc_numeric  start_baln 
)

This function will set the starting commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3417 of file Account.cpp.

3418{
3419 AccountPrivate *priv;
3420
3421 g_return_if_fail(GNC_IS_ACCOUNT(acc));
3422
3423 priv = GET_PRIVATE(acc);
3424 priv->starting_balance = start_baln;
3425 priv->balance_dirty = TRUE;
3426}

◆ gnc_account_set_start_cleared_balance()

void gnc_account_set_start_cleared_balance ( Account *  acc,
const gnc_numeric  start_baln 
)

This function will set the starting cleared commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3429 of file Account.cpp.

3431{
3432 AccountPrivate *priv;
3433
3434 g_return_if_fail(GNC_IS_ACCOUNT(acc));
3435
3436 priv = GET_PRIVATE(acc);
3437 priv->starting_cleared_balance = start_baln;
3438 priv->balance_dirty = TRUE;
3439}

◆ gnc_account_set_start_reconciled_balance()

void gnc_account_set_start_reconciled_balance ( Account *  acc,
const gnc_numeric  start_baln 
)

This function will set the starting reconciled commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3442 of file Account.cpp.

3444{
3445 AccountPrivate *priv;
3446
3447 g_return_if_fail(GNC_IS_ACCOUNT(acc));
3448
3449 priv = GET_PRIVATE(acc);
3450 priv->starting_reconciled_balance = start_baln;
3451 priv->balance_dirty = TRUE;
3452}

◆ gnc_book_get_root_account()

Account * gnc_book_get_root_account ( QofBook *  book)

Definition at line 1225 of file Account.cpp.

1226{
1227 QofCollection *col;
1228 Account *root;
1229
1230 if (!book) return nullptr;
1231 col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
1232 root = gnc_coll_get_root_account (col);
1233 if (root == nullptr && !qof_book_shutting_down(book))
1234 root = gnc_account_create_root(book);
1235 return root;
1236}
Account * gnc_account_create_root(QofBook *book)
Create a new root level account.
Definition Account.cpp:1272
gboolean qof_book_shutting_down(const QofBook *book)
Is the book shutting down?
Definition qofbook.cpp:447

◆ gnc_book_set_root_account()

void gnc_book_set_root_account ( QofBook *  book,
Account *  root 
)

Definition at line 1239 of file Account.cpp.

1240{
1241 QofCollection *col;
1242 if (!book) return;
1243
1244 if (root && gnc_account_get_book(root) != book)
1245 {
1246 PERR ("cannot mix and match books freely!");
1247 return;
1248 }
1249
1250 col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
1251 gnc_coll_set_root_account (col, root);
1252}

◆ gnc_get_account_separator()

gunichar gnc_get_account_separator ( void  )

Definition at line 211 of file Account.cpp.

212{
213 return account_uc_separator;
214}

◆ gnc_get_account_separator_string()

const gchar * gnc_get_account_separator_string ( void  )

Returns the account separation character chosen by the user.

Returns
The character to use.

Definition at line 205 of file Account.cpp.

206{
207 return account_separator;
208}

◆ gnc_set_account_separator()

void gnc_set_account_separator ( const gchar *  separator)

Definition at line 217 of file Account.cpp.

218{
219 gunichar uc;
220 gint count;
221
222 uc = g_utf8_get_char_validated(separator, -1);
223 if ((uc == (gunichar) - 2) || (uc == (gunichar) - 1) || g_unichar_isalnum(uc))
224 {
225 account_uc_separator = ':';
226 strcpy(account_separator, ":");
227 return;
228 }
229
230 account_uc_separator = uc;
231 count = g_unichar_to_utf8(uc, account_separator);
232 account_separator[count] = '\0';
233}

◆ xaccAccountBeginEdit()

void xaccAccountBeginEdit ( Account *  account)

The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account updates.

Definition at line 1463 of file Account.cpp.

1464{
1465 g_return_if_fail(acc);
1466 qof_begin_edit(&acc->inst);
1467}
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ xaccAccountCommitEdit()

void xaccAccountCommitEdit ( Account *  account)

ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account updates.

Definition at line 1504 of file Account.cpp.

1505{
1506 AccountPrivate *priv;
1507 QofBook *book;
1508
1509 g_return_if_fail(acc);
1510 if (!qof_commit_edit(&acc->inst)) return;
1511
1512 /* If marked for deletion, get rid of subaccounts first,
1513 * and then the splits ... */
1514 priv = GET_PRIVATE(acc);
1516 {
1517 QofCollection *col;
1518
1519 qof_instance_increase_editlevel(acc);
1520
1521 /* First, recursively free children */
1522 xaccFreeAccountChildren(acc);
1523
1524 PINFO ("freeing splits for account %p (%s)",
1525 acc, priv->accountName ? priv->accountName : "(null)");
1526
1527 book = qof_instance_get_book(acc);
1528
1529 /* If book is shutting down, just clear the split list. The splits
1530 themselves will be destroyed by the transaction code */
1531 if (!qof_book_shutting_down(book))
1532 {
1533 // We need to delete in reverse order so that the vector's iterators aren't invalidated.
1534 for_each(priv->splits.rbegin(), priv->splits.rend(), [](Split *s) {
1535 xaccSplitDestroy (s); });
1536 }
1537 else
1538 {
1539 priv->splits.clear();
1540 g_hash_table_remove_all (priv->splits_hash);
1541 }
1542
1543 /* It turns out there's a case where this assertion does not hold:
1544 When the user tries to delete an Imbalance account, while also
1545 deleting all the splits in it. The splits will just get
1546 recreated and put right back into the same account!
1547
1548 g_assert(priv->splits == nullptr || qof_book_shutting_down(acc->inst.book));
1549 */
1550
1551 if (!qof_book_shutting_down(book))
1552 {
1553 col = qof_book_get_collection(book, GNC_ID_TRANS);
1554 qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
1555
1556 /* the lots should be empty by now */
1557 for (auto lp = priv->lots; lp; lp = lp->next)
1558 {
1559 GNCLot *lot = static_cast<GNCLot*>(lp->data);
1560 gnc_lot_destroy (lot);
1561 }
1562 }
1563 g_list_free(priv->lots);
1564 priv->lots = nullptr;
1565
1566 qof_instance_set_dirty(&acc->inst);
1567 qof_instance_decrease_editlevel(acc);
1568 }
1569 else
1570 {
1571 xaccAccountBringUpToDate(acc);
1572 }
1573
1574 qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
1575}
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
QofBook reference.
Definition qofbook-p.hpp:47

◆ xaccAccountConvertBalanceToCurrency()

gnc_numeric xaccAccountConvertBalanceToCurrency ( const Account *  account,
gnc_numeric  balance,
const gnc_commodity *  balance_currency,
const gnc_commodity *  new_currency 
)

Definition at line 3561 of file Account.cpp.

3565{
3566 QofBook *book;
3567 GNCPriceDB *pdb;
3568
3569 if (gnc_numeric_zero_p (balance) ||
3570 gnc_commodity_equiv (balance_currency, new_currency))
3571 return balance;
3572
3573 book = gnc_account_get_book (acc);
3574 pdb = gnc_pricedb_get_db (book);
3575
3577 pdb, balance, balance_currency, new_currency);
3578
3579 return balance;
3580}
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
Convert a balance from one currency to another using the most recent price between the two.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.

◆ xaccAccountConvertBalanceToCurrencyAsOfDate()

gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate ( const Account *  account,
gnc_numeric  balance,
const gnc_commodity *  balance_currency,
const gnc_commodity *  new_currency,
time64  date 
)

Definition at line 3587 of file Account.cpp.

3592{
3593 QofBook *book;
3594 GNCPriceDB *pdb;
3595
3596 if (gnc_numeric_zero_p (balance) ||
3597 gnc_commodity_equiv (balance_currency, new_currency))
3598 return balance;
3599
3600 book = gnc_account_get_book (acc);
3601 pdb = gnc_pricedb_get_db (book);
3602
3604 pdb, balance, balance_currency, new_currency, date);
3605
3606 return balance;
3607}
gnc_numeric gnc_pricedb_convert_balance_nearest_before_price_t64(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
Convert a balance from one currency to another using the price nearest to before the given time.

◆ xaccAccountDestroy()

void xaccAccountDestroy ( Account *  account)

The xaccAccountDestroy() routine can be used to get rid of an account.

The account should have been opened for editing (by calling xaccAccountBeginEdit()) before calling this routine.

Definition at line 1578 of file Account.cpp.

1579{
1580 g_return_if_fail(GNC_IS_ACCOUNT(acc));
1581
1582 qof_instance_set_destroying(acc, TRUE);
1583
1585}

◆ xaccAccountDestroyAllTransactions()

void xaccAccountDestroyAllTransactions ( Account *  acc)

Destroy all of the transactions that parent splits in an account.

Definition at line 1588 of file Account.cpp.

1589{
1590 auto priv = GET_PRIVATE(acc);
1591 std::vector<Transaction*> transactions;
1592 transactions.reserve(priv->splits.size());
1593 std::transform(priv->splits.begin(), priv->splits.end(),
1594 back_inserter(transactions),
1595 [](auto split) { return split->parent; });
1596 std::stable_sort(transactions.begin(), transactions.end());
1597 transactions.erase(std::unique(transactions.begin(), transactions.end()),
1598 transactions.end());
1600 std::for_each(transactions.rbegin(), transactions.rend(),
1601 [](auto trans) { xaccTransDestroy (trans); });
1603}
void qof_event_resume(void)
Resume engine event generation.
Definition qofevent.cpp:156
void qof_event_suspend(void)
Suspend all engine events.
Definition qofevent.cpp:145

◆ xaccAccountEqual()

gboolean xaccAccountEqual ( const Account *  a,
const Account *  b,
gboolean  check_guids 
)

Compare two accounts for equality - this is a deep compare.

Definition at line 1654 of file Account.cpp.

1655{
1656 AccountPrivate *priv_aa, *priv_ab;
1657
1658 if (!aa && !ab) return TRUE;
1659
1660 g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
1661 g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
1662
1663 priv_aa = GET_PRIVATE(aa);
1664 priv_ab = GET_PRIVATE(ab);
1665 if (priv_aa->type != priv_ab->type)
1666 {
1667 PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
1668 return FALSE;
1669 }
1670
1671 if (g_strcmp0(priv_aa->accountName, priv_ab->accountName) != 0)
1672 {
1673 PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
1674 return FALSE;
1675 }
1676
1677 if (g_strcmp0(priv_aa->accountCode, priv_ab->accountCode) != 0)
1678 {
1679 PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
1680 return FALSE;
1681 }
1682
1683 if (g_strcmp0(priv_aa->description, priv_ab->description) != 0)
1684 {
1685 PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
1686 return FALSE;
1687 }
1688
1689 if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
1690 {
1691 PWARN ("commodities differ");
1692 return FALSE;
1693 }
1694
1695 if (check_guids)
1696 {
1697 if (qof_instance_guid_compare(aa, ab) != 0)
1698 {
1699 PWARN ("GUIDs differ");
1700 return FALSE;
1701 }
1702 }
1703
1704 if (qof_instance_compare_kvp (QOF_INSTANCE (aa), QOF_INSTANCE (ab)) != 0)
1705 {
1706 char *frame_a;
1707 char *frame_b;
1708
1709 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (aa));
1710 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (ab));
1711
1712 PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
1713
1714 g_free (frame_a);
1715 g_free (frame_b);
1716
1717 return FALSE;
1718 }
1719
1720 if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
1721 {
1722 char *str_a;
1723 char *str_b;
1724
1725 str_a = gnc_numeric_to_string(priv_aa->starting_balance);
1726 str_b = gnc_numeric_to_string(priv_ab->starting_balance);
1727
1728 PWARN ("starting balances differ: %s vs %s", str_a, str_b);
1729
1730 g_free (str_a);
1731 g_free (str_b);
1732
1733 return FALSE;
1734 }
1735
1736 if (!gnc_numeric_equal(priv_aa->starting_noclosing_balance,
1737 priv_ab->starting_noclosing_balance))
1738 {
1739 char *str_a;
1740 char *str_b;
1741
1742 str_a = gnc_numeric_to_string(priv_aa->starting_noclosing_balance);
1743 str_b = gnc_numeric_to_string(priv_ab->starting_noclosing_balance);
1744
1745 PWARN ("starting noclosing balances differ: %s vs %s", str_a, str_b);
1746
1747 g_free (str_a);
1748 g_free (str_b);
1749
1750 return FALSE;
1751 }
1752 if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
1753 priv_ab->starting_cleared_balance))
1754 {
1755 char *str_a;
1756 char *str_b;
1757
1758 str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
1759 str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
1760
1761 PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
1762
1763 g_free (str_a);
1764 g_free (str_b);
1765
1766 return FALSE;
1767 }
1768
1769 if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
1770 priv_ab->starting_reconciled_balance))
1771 {
1772 char *str_a;
1773 char *str_b;
1774
1775 str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
1776 str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
1777
1778 PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
1779
1780 g_free (str_a);
1781 g_free (str_b);
1782
1783 return FALSE;
1784 }
1785
1786 if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
1787 {
1788 char *str_a;
1789 char *str_b;
1790
1791 str_a = gnc_numeric_to_string(priv_aa->balance);
1792 str_b = gnc_numeric_to_string(priv_ab->balance);
1793
1794 PWARN ("balances differ: %s vs %s", str_a, str_b);
1795
1796 g_free (str_a);
1797 g_free (str_b);
1798
1799 return FALSE;
1800 }
1801
1802 if (!gnc_numeric_equal(priv_aa->noclosing_balance, priv_ab->noclosing_balance))
1803 {
1804 char *str_a;
1805 char *str_b;
1806
1807 str_a = gnc_numeric_to_string(priv_aa->noclosing_balance);
1808 str_b = gnc_numeric_to_string(priv_ab->noclosing_balance);
1809
1810 PWARN ("noclosing balances differ: %s vs %s", str_a, str_b);
1811
1812 g_free (str_a);
1813 g_free (str_b);
1814
1815 return FALSE;
1816 }
1817 if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
1818 {
1819 char *str_a;
1820 char *str_b;
1821
1822 str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
1823 str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
1824
1825 PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
1826
1827 g_free (str_a);
1828 g_free (str_b);
1829
1830 return FALSE;
1831 }
1832
1833 if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
1834 {
1835 char *str_a;
1836 char *str_b;
1837
1838 str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
1839 str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
1840
1841 PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
1842
1843 g_free (str_a);
1844 g_free (str_b);
1845
1846 return FALSE;
1847 }
1848
1849 /* no parent; always compare downwards. */
1850
1851 if (!std::equal (priv_aa->splits.begin(), priv_aa->splits.end(),
1852 priv_ab->splits.begin(), priv_ab->splits.end(),
1853 [check_guids](auto sa, auto sb)
1854 { return xaccSplitEqual(sa, sb, check_guids, true, false); }))
1855 {
1856 PWARN ("splits differ");
1857 return false;
1858 }
1859
1860 if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
1861 {
1862 PWARN ("children differ");
1863 return FALSE;
1864 }
1865
1866 return(TRUE);
1867}
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.

◆ xaccAccountGainsAccount()

Account * xaccAccountGainsAccount ( Account *  acc,
gnc_commodity *  curr 
)

Retrieve the gains account used by this account for the indicated currency, creating and recording a new one if necessary.

FIXME: There is at present no interface to designate an existing account, and the new account name is hard coded to "Orphaned Gains -- CUR"

FIXME: There is no provision for creating separate accounts for anything other than currency, e.g. holding period of a security.

Definition at line 4805 of file Account.cpp.

4806{
4807 Path path {KEY_LOT_MGMT, "gains-acct", gnc_commodity_get_unique_name (curr)};
4808 auto gains_account = get_kvp_account_path (acc, path);
4809
4810 if (gains_account == nullptr) /* No gains account for this currency */
4811 {
4812 gains_account = GetOrMakeOrphanAccount (gnc_account_get_root (acc), curr);
4813 set_kvp_account_path (acc, path, gains_account);
4814 }
4815
4816 return gains_account;
4817}
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to.
Definition Account.cpp:2930
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.

◆ xaccAccountGetAssociatedAccount()

Account * xaccAccountGetAssociatedAccount ( const Account *  acc,
const char *  tag 
)

Get the account's associated account e.g.

stock account -> dividend account

Definition at line 3375 of file Account.cpp.

3376{
3377 g_return_val_if_fail (tag && *tag, nullptr);
3378
3379 return get_kvp_account_path (acc, {"associated-account", tag});
3380}

◆ xaccAccountGetBalance()

gnc_numeric xaccAccountGetBalance ( const Account *  account)

Get the current balance of the account, which may include future splits.

Definition at line 3455 of file Account.cpp.

3456{
3457 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3458 return GET_PRIVATE(acc)->balance;
3459}

◆ xaccAccountGetBalanceAsOfDate()

gnc_numeric xaccAccountGetBalanceAsOfDate ( Account *  account,
time64  date 
)

Get the balance of the account at the end of the day before the date specified.

Definition at line 3521 of file Account.cpp.

3522{
3523 return GetBalanceAsOfDate (acc, date, xaccSplitGetBalance);
3524}
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
Definition Split.cpp:1327

◆ xaccAccountGetBalanceAsOfDateInCurrency()

gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency ( Account *  account,
time64  date,
gnc_commodity *  report_commodity,
gboolean  include_children 
)

This function gets the balance at the end of the given date in the desired commodity.

Definition at line 3839 of file Account.cpp.

3842{
3843 return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive (
3844 acc, date, xaccAccountGetBalanceAsOfDate, report_commodity,
3845 include_children);
3846}
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
Definition Account.cpp:3521

◆ xaccAccountGetBalanceChangeForPeriod()

gnc_numeric xaccAccountGetBalanceChangeForPeriod ( Account *  acc,
time64  date1,
time64  date2,
gboolean  recurse 
)

Definition at line 3859 of file Account.cpp.

3861{
3862 gnc_numeric b1, b2;
3863
3864 b1 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t1, nullptr, recurse);
3865 b2 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t2, nullptr, recurse);
3866 return gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
3867}
gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency(Account *acc, time64 date, gnc_commodity *report_commodity, gboolean include_children)
This function gets the balance at the end of the given date in the desired commodity.
Definition Account.cpp:3839
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a-b.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.

◆ xaccAccountGetBalanceInCurrency()

gnc_numeric xaccAccountGetBalanceInCurrency ( const Account *  account,
const gnc_commodity *  report_commodity,
gboolean  include_children 
)

Definition at line 3784 of file Account.cpp.

3787{
3788 gnc_numeric rc;
3789 rc = xaccAccountGetXxxBalanceInCurrencyRecursive (
3790 acc, xaccAccountGetBalance, report_commodity, include_children);
3791 PINFO(" baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, rc.num, rc.denom);
3792 return rc;
3793}
gnc_numeric xaccAccountGetBalance(const Account *acc)
Get the current balance of the account, which may include future splits.
Definition Account.cpp:3455

◆ xaccAccountGetClearedBalance()

gnc_numeric xaccAccountGetClearedBalance ( const Account *  account)

Get the current balance of the account, only including cleared transactions.

Definition at line 3462 of file Account.cpp.

3463{
3464 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3465 return GET_PRIVATE(acc)->cleared_balance;
3466}

◆ xaccAccountGetClearedBalanceInCurrency()

gnc_numeric xaccAccountGetClearedBalanceInCurrency ( const Account *  account,
const gnc_commodity *  report_commodity,
gboolean  include_children 
)

Definition at line 3797 of file Account.cpp.

3800{
3801 return xaccAccountGetXxxBalanceInCurrencyRecursive (
3802 acc, xaccAccountGetClearedBalance, report_commodity,
3803 include_children);
3804}
gnc_numeric xaccAccountGetClearedBalance(const Account *acc)
Get the current balance of the account, only including cleared transactions.
Definition Account.cpp:3462

◆ xaccAccountGetCode()

const char * xaccAccountGetCode ( const Account *  account)

Get the account's accounting code.

Definition at line 3324 of file Account.cpp.

3325{
3326 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
3327 return GET_PRIVATE(acc)->accountCode;
3328}

◆ xaccAccountGetColor()

const char * xaccAccountGetColor ( const Account *  account)

Get the account's color.

Definition at line 3338 of file Account.cpp.

3339{
3340 return get_kvp_string_path (acc, {"color"});
3341}

◆ xaccAccountGetCommodity()

gnc_commodity * xaccAccountGetCommodity ( const Account *  account)

Get the account's commodity

Definition at line 3396 of file Account.cpp.

3397{
3398 if (!GNC_IS_ACCOUNT(acc))
3399 return nullptr;
3400 return GET_PRIVATE(acc)->commodity;
3401}

◆ xaccAccountGetCommoditySCU()

int xaccAccountGetCommoditySCU ( const Account *  account)

Return the SCU for the account.

If a non-standard SCU has been set for the account, that is returned; else the default SCU for the account commodity is returned.

Definition at line 2733 of file Account.cpp.

2734{
2735 AccountPrivate *priv;
2736
2737 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2738
2739 priv = GET_PRIVATE(acc);
2740 if (priv->non_standard_scu || !priv->commodity)
2741 return priv->commodity_scu;
2742 return gnc_commodity_get_fraction(priv->commodity);
2743}
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.

◆ xaccAccountGetCommoditySCUi()

int xaccAccountGetCommoditySCUi ( const Account *  account)

Return the 'internal' SCU setting.

This returns the over-ride SCU for the account (which might not be set, and might be zero).

Definition at line 2726 of file Account.cpp.

2727{
2728 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2729 return GET_PRIVATE(acc)->commodity_scu;
2730}

◆ xaccAccountGetDescription()

const char * xaccAccountGetDescription ( const Account *  account)

Get the account's description.

Definition at line 3331 of file Account.cpp.

3332{
3333 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
3334 return GET_PRIVATE(acc)->description;
3335}

◆ xaccAccountGetFilter()

const char * xaccAccountGetFilter ( const Account *  account)

Get the account's filter.

Definition at line 3344 of file Account.cpp.

3345{
3346 return get_kvp_string_path (acc, {"filter"});
3347}

◆ xaccAccountGetLastNum()

const char * xaccAccountGetLastNum ( const Account *  account)

Get the last num field of an Account.

Definition at line 4671 of file Account.cpp.

4672{
4673 return get_kvp_string_path (acc, {"last-num"});
4674}

◆ xaccAccountGetName()

const char * xaccAccountGetName ( const Account *  account)

Get the account's name.

Definition at line 3277 of file Account.cpp.

3278{
3279 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
3280 return GET_PRIVATE(acc)->accountName;
3281}

◆ xaccAccountGetNoclosingBalanceAsOfDateInCurrency()

gnc_numeric xaccAccountGetNoclosingBalanceAsOfDateInCurrency ( Account *  acc,
time64  date,
gnc_commodity *  report_commodity,
gboolean  include_children 
)

This function gets the balance at the end of the given date, ignoring closing entries, in the desired commodity.

Definition at line 3849 of file Account.cpp.

3852{
3853 return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive
3854 (acc, date, xaccAccountGetNoclosingBalanceAsOfDate,
3855 report_commodity, include_children);
3856}

◆ xaccAccountGetNoclosingBalanceChangeForPeriod()

gnc_numeric xaccAccountGetNoclosingBalanceChangeForPeriod ( Account *  acc,
time64  date1,
time64  date2,
gboolean  recurse 
)

Definition at line 3870 of file Account.cpp.

3872{
3873 gnc_numeric b1, b2;
3874
3875 b1 = xaccAccountGetNoclosingBalanceAsOfDateInCurrency(acc, t1, nullptr, recurse);
3876 b2 = xaccAccountGetNoclosingBalanceAsOfDateInCurrency(acc, t2, nullptr, recurse);
3877 return gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
3878}
gnc_numeric xaccAccountGetNoclosingBalanceAsOfDateInCurrency(Account *acc, time64 date, gnc_commodity *report_commodity, gboolean include_children)
This function gets the balance at the end of the given date, ignoring closing entries,...
Definition Account.cpp:3849

◆ xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod()

gnc_numeric xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod ( Account *  acc,
time64  date1,
time64  date2,
gboolean  recurse 
)

Definition at line 3904 of file Account.cpp.

3906{
3907
3908
3909 gnc_numeric b1, b2;
3910 b1 = GetBalanceAsOfDate(acc, t1, xaccSplitGetNoclosingBalance);
3911 b2 = GetBalanceAsOfDate(acc, t2, xaccSplitGetNoclosingBalance);
3912 gnc_numeric balanceChange = gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
3913
3914 gnc_commodity *report_commodity = xaccAccountGetCommodity(acc);
3915 CurrencyBalanceChange cbdiff = { report_commodity, balanceChange, t1, t2 };
3916
3917 if(recurse)
3918 {
3919 gnc_account_foreach_descendant (acc, xaccAccountBalanceChangeHelper, &cbdiff);
3920 balanceChange = cbdiff.balanceChange;
3921 }
3922 return balanceChange;
3923}
gnc_numeric xaccSplitGetNoclosingBalance(const Split *s)
The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transa...
Definition Split.cpp:1333

◆ xaccAccountGetNonStdSCU()

gboolean xaccAccountGetNonStdSCU ( const Account *  account)

Return boolean, indicating whether this account uses a non-standard SCU.

Definition at line 2762 of file Account.cpp.

2763{
2764 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2765 return GET_PRIVATE(acc)->non_standard_scu;
2766}

◆ xaccAccountGetNotes()

const char * xaccAccountGetNotes ( const Account *  account)

Get the account's notes.

Definition at line 3362 of file Account.cpp.

3363{
3364 return get_kvp_string_path (acc, {"notes"});
3365}

◆ xaccAccountGetOnlineID()

const char * xaccAccountGetOnlineID ( const Account *  account)

Get the account's online_id (see xaccAccountSetOnlineID).

The returned string is owned by the account and must NOT be freed; returns NULL if no online_id is set.

Definition at line 3368 of file Account.cpp.

3369{
3370 g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr);
3371 return get_kvp_string_path (acc, {KEY_ONLINE_ID});
3372}

◆ xaccAccountGetPresentBalance()

gnc_numeric xaccAccountGetPresentBalance ( const Account *  account)

Definition at line 3542 of file Account.cpp.

3543{
3544 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3545
3546 return xaccAccountGetBalanceAsOfDate (GNC_ACCOUNT (acc),
3548}
time64 gnc_time64_get_today_end(void)
The gnc_time64_get_today_end() routine returns a time64 value corresponding to the last second of tod...

◆ xaccAccountGetPresentBalanceInCurrency()

gnc_numeric xaccAccountGetPresentBalanceInCurrency ( const Account *  account,
const gnc_commodity *  report_commodity,
gboolean  include_children 
)

Definition at line 3817 of file Account.cpp.

3820{
3821 return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive (
3823 report_commodity,
3824 include_children);
3825}

◆ xaccAccountGetProjectedMinimumBalance()

gnc_numeric xaccAccountGetProjectedMinimumBalance ( const Account *  account)

Definition at line 3476 of file Account.cpp.

3477{
3478 auto today{gnc_time64_get_today_end()};
3479 std::optional<gnc_numeric> minimum;
3480
3481 auto before_today_end = [&minimum, today](const Split *s) -> bool
3482 {
3483 auto bal{xaccSplitGetBalance(s)};
3484 if (!minimum || gnc_numeric_compare (bal, *minimum) < 0)
3485 minimum = bal;
3486 return (xaccTransGetDate(xaccSplitGetParent(s)) < today);
3487 };
3488 // scan to find today's split, but we're really interested in the
3489 // minimum balance
3490 [[maybe_unused]] auto todays_split = gnc_account_find_split (acc, before_today_end, true);
3491 return minimum ? *minimum : gnc_numeric_zero();
3492}
Split * gnc_account_find_split(const Account *acc, std::function< bool(const Split *)> predicate, bool reverse)
scans account split list (in forward or reverse order) until predicate split->bool returns true.
Definition Account.cpp:1155
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.

◆ xaccAccountGetProjectedMinimumBalanceInCurrency()

gnc_numeric xaccAccountGetProjectedMinimumBalanceInCurrency ( const Account *  account,
const gnc_commodity *  report_commodity,
gboolean  include_children 
)

Definition at line 3828 of file Account.cpp.

3832{
3833 return xaccAccountGetXxxBalanceInCurrencyRecursive (
3834 acc, xaccAccountGetProjectedMinimumBalance, report_commodity,
3835 include_children);
3836}

◆ xaccAccountGetReconcileChildrenStatus()

gboolean xaccAccountGetReconcileChildrenStatus ( const Account *  account)

DOCUMENT ME!

Definition at line 4883 of file Account.cpp.

4884{
4885 /* access the account's kvp-data for status and return that, if no value
4886 * is found then we can assume not to include the children, that being
4887 * the default behaviour
4888 */
4889 return get_kvp_boolean_path (acc, {KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN});
4890}

◆ xaccAccountGetReconciledBalance()

gnc_numeric xaccAccountGetReconciledBalance ( const Account *  account)

Get the current balance of the account, only including reconciled transactions.

Definition at line 3469 of file Account.cpp.

3470{
3471 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3472 return GET_PRIVATE(acc)->reconciled_balance;
3473}

◆ xaccAccountGetReconciledBalanceAsOfDate()

gnc_numeric xaccAccountGetReconciledBalanceAsOfDate ( Account *  account,
time64  date 
)

Get the reconciled balance of the account at the end of the day of the date specified.

Definition at line 3533 of file Account.cpp.

3534{
3535 return GetBalanceAsOfDate (acc, date, xaccSplitGetReconciledBalance);
3536}
gnc_numeric xaccSplitGetReconciledBalance(const Split *s)
Returns the reconciled-balance of this split.
Definition Split.cpp:1345

◆ xaccAccountGetReconciledBalanceInCurrency()

gnc_numeric xaccAccountGetReconciledBalanceInCurrency ( const Account *  account,
const gnc_commodity *  report_commodity,
gboolean  include_children 
)

Definition at line 3807 of file Account.cpp.

3810{
3811 return xaccAccountGetXxxBalanceInCurrencyRecursive (
3812 acc, xaccAccountGetReconciledBalance, report_commodity,
3813 include_children);
3814}
gnc_numeric xaccAccountGetReconciledBalance(const Account *acc)
Get the current balance of the account, only including reconciled transactions.
Definition Account.cpp:3469

◆ xaccAccountGetSortOrder()

const char * xaccAccountGetSortOrder ( const Account *  account)

Get the account's Sort Order.

Definition at line 3350 of file Account.cpp.

3351{
3352 return get_kvp_string_path (acc, {"sort-order"});
3353}

◆ xaccAccountGetSortReversed()

gboolean xaccAccountGetSortReversed ( const Account *  account)

Get the account's Sort Order direction.

Definition at line 3356 of file Account.cpp.

3357{
3358 return get_kvp_boolean_path (acc, {"sort-reversed"});
3359}

◆ xaccAccountGetSplits()

const SplitsVec & xaccAccountGetSplits ( const Account *  account)

Definition at line 3929 of file Account.cpp.

3930{
3931 static const SplitsVec empty;
3932 g_return_val_if_fail (GNC_IS_ACCOUNT(account), empty);
3933 return GET_PRIVATE(account)->splits;
3934}

◆ xaccAccountGetType()

GNCAccountType xaccAccountGetType ( const Account *  account)

Returns the account's account type.

This must not be confused with the GType as returned by gnc_account_get_type(), which is related to glib's type system.

Definition at line 3255 of file Account.cpp.

3256{
3257 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), ACCT_TYPE_NONE);
3258 return GET_PRIVATE(acc)->type;
3259}

◆ xaccAccountHasAncestor()

gboolean xaccAccountHasAncestor ( const Account *  acc,
const Account *  ancestor 
)

Returns true if the account is 'ancestor' or has 'ancestor' as an ancestor.

An ancestor account may be the accounts parent, its parent's parent, its parent's parent's parent, etc. Returns false if either one is NULL.

Definition at line 4212 of file Account.cpp.

4213{
4214 const Account *parent;
4215
4216 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4217 g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
4218
4219 parent = acc;
4220 while (parent && parent != ancestor)
4221 parent = GET_PRIVATE(parent)->parent;
4222
4223 return (parent == ancestor);
4224}

◆ xaccAccountHasStockSplit()

gboolean xaccAccountHasStockSplit ( const Account *  acc)

Returns true if the account has a stock split, otherwise false.

Definition at line 3495 of file Account.cpp.

3496{
3497 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false);
3498 return GET_PRIVATE(acc)->has_stock_split;
3499}

◆ xaccAccountIsPriced()

gboolean xaccAccountIsPriced ( const Account *  acc)

Returns true if the account is a stock, mutual fund or currency, otherwise false.

Definition at line 4539 of file Account.cpp.

4540{
4541 AccountPrivate *priv;
4542
4543 g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4544
4545 priv = GET_PRIVATE(acc);
4546 return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
4547 priv->type == ACCT_TYPE_CURRENCY);
4548}

◆ xaccAccountLookup()

Account * xaccAccountLookup ( const GncGUID *  guid,
QofBook *  book 
)

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

Definition at line 2038 of file Account.cpp.

2039{
2040 QofCollection *col;
2041 if (!guid || !book) return nullptr;
2042 col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
2043 return (Account *) qof_collection_lookup_entity (col, guid);
2044}
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition qofid.cpp:209

◆ xaccAccountOrder()

int xaccAccountOrder ( const Account *  account_1,
const Account *  account_2 
)

The xaccAccountOrder() subroutine defines a sorting order on accounts.

It takes pointers to two accounts, and returns an int < 0 if the first account is "less than" the second, returns an int > 0 if the first is "greater than" the second, and 0 if they are equal. To determine the sort order, first the account codes are compared, and if these are equal, then account types, then account names. If still equal, it compares GUID to ensure that there aren't any ties.

Definition at line 2363 of file Account.cpp.

2364{
2365 AccountPrivate *priv_aa, *priv_ab;
2366 const char *da, *db;
2367 int ta, tb, result;
2368
2369 if (aa == ab) return 0;
2370 if (!ab) return -1;
2371 if (!aa) return +1;
2372
2373 priv_aa = GET_PRIVATE(aa);
2374 priv_ab = GET_PRIVATE(ab);
2375
2376 /* sort on accountCode strings */
2377 da = priv_aa->accountCode;
2378 db = priv_ab->accountCode;
2379
2380 /* Otherwise do a string sort */
2381 result = g_strcmp0 (da, db);
2382 if (result)
2383 return result;
2384
2385 /* if account-type-order array not initialized, initialize it */
2386 /* this will happen at most once during program invocation */
2387 if (-1 == revorder[0])
2388 {
2389 int i;
2390 for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
2391 {
2392 revorder [typeorder[i]] = i;
2393 }
2394 }
2395
2396 /* otherwise, sort on account type */
2397 ta = priv_aa->type;
2398 tb = priv_ab->type;
2399 ta = revorder[ta];
2400 tb = revorder[tb];
2401 if (ta < tb) return -1;
2402 if (ta > tb) return +1;
2403
2404 /* otherwise, sort on accountName strings */
2405 da = priv_aa->accountName;
2406 db = priv_ab->accountName;
2407 result = safe_utf8_collate(da, db);
2408 if (result)
2409 return result;
2410
2411 /* guarantee a stable sort */
2412 return qof_instance_guid_compare(aa, ab);
2413}
int safe_utf8_collate(const char *da, const char *db)
Collate two UTF-8 strings.

◆ xaccAccountRecomputeBalance()

void xaccAccountRecomputeBalance ( Account *  acc)

The following recompute the partial balances (stored with the transaction) and the total balance, for this account.

Definition at line 2263 of file Account.cpp.

2264{
2265 if (nullptr == acc) return;
2266
2267 auto priv = GET_PRIVATE(acc);
2268 if (qof_instance_get_editlevel(acc) > 0) return;
2269 if (!priv->balance_dirty || priv->defer_bal_computation) return;
2270 if (qof_instance_get_destroying(acc)) return;
2272
2273 auto balance = priv->starting_balance;
2274 auto noclosing_balance = priv->starting_noclosing_balance;
2275 auto cleared_balance = priv->starting_cleared_balance;
2276 auto reconciled_balance = priv->starting_reconciled_balance;
2277 auto has_stock_split = false;
2278
2279 PINFO ("acct=%s starting baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
2280 priv->accountName, balance.num, balance.denom);
2281 for (auto split : priv->splits)
2282 {
2283 auto amt = xaccSplitGetAmount (split);
2284
2285 if (xaccSplitIsStockSplit(split))
2286 {
2287 if (gnc_numeric_zero_p(balance))
2288 continue;
2289 auto new_balance = gnc_numeric_add_fixed(balance, amt);
2290 if (gnc_numeric_zero_p(new_balance))
2291 continue;
2292 auto ratio = gnc_numeric_div(new_balance, balance, GNC_DENOM_AUTO,
2293 GNC_HOW_DENOM_REDUCE);
2294 auto denom = xaccAccountGetCommoditySCU(acc);
2295 for (auto psplit : priv->splits)
2296 {
2297 if (psplit == split)
2298 break;
2300 gnc_numeric_mul(xaccSplitGetAdjustedAmount(psplit), ratio, denom,
2301 GNC_HOW_RND_ROUND_HALF_UP));
2302 }
2303 balance = new_balance;
2304 has_stock_split = true;
2305 }
2306 else
2307 {
2308 split->adjusted_amount = amt;
2309 balance = gnc_numeric_add_fixed(balance, amt);
2310 }
2311
2312 if (NREC != split->reconciled)
2313 {
2314 cleared_balance = gnc_numeric_add_fixed(cleared_balance, amt);
2315 }
2316
2317 if (YREC == split->reconciled ||
2318 FREC == split->reconciled)
2319 {
2320 reconciled_balance =
2321 gnc_numeric_add_fixed(reconciled_balance, amt);
2322 }
2323
2324 if (!(xaccTransGetIsClosingTxn (split->parent)))
2325 noclosing_balance = gnc_numeric_add_fixed(noclosing_balance, amt);
2326
2327 split->balance = balance;
2328 split->noclosing_balance = noclosing_balance;
2329 split->cleared_balance = cleared_balance;
2330 split->reconciled_balance = reconciled_balance;
2331
2332 }
2333
2334 priv->balance = balance;
2335 priv->noclosing_balance = noclosing_balance;
2336 priv->cleared_balance = cleared_balance;
2337 priv->reconciled_balance = reconciled_balance;
2338 priv->balance_dirty = FALSE;
2339 priv->has_stock_split = has_stock_split;
2340}
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition Account.cpp:2733
gboolean xaccTransGetIsClosingTxn(const Transaction *trans)
Returns whether this transaction is a "closing transaction".
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
void xaccSplitSetAdjustedAmount(Split *s, gnc_numeric amt)
Sets the stock split adjusted amount of a split.
Definition Split.cpp:1357
#define NREC
not reconciled or cleared
Definition Split.h:76
#define FREC
frozen into accounting period
Definition Split.h:75
gnc_numeric xaccSplitGetAdjustedAmount(const Split *s)
Returns the stock-split adjusted amount of the split in the account's commodity.
Definition Split.cpp:1351
#define YREC
The Split has been reconciled.
Definition Split.h:74
gboolean xaccSplitIsStockSplit(Split *s)
Returns true if the split is of type stock split.
Definition Split.cpp:2089
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.

◆ xaccAccountSetAssociatedAccount()

void xaccAccountSetAssociatedAccount ( Account *  acc,
const char *  tag,
const Account *  assoc_acct 
)

Set the account's associated account e.g.

stock account -> dividend account

Definition at line 2657 of file Account.cpp.

2658{
2659 g_return_if_fail (GNC_IS_ACCOUNT(acc));
2660 g_return_if_fail (tag && *tag);
2661
2662 set_kvp_account_path (acc, {"associated-account", tag}, assoc_acct);
2663}

◆ xaccAccountSetCode()

void xaccAccountSetCode ( Account *  account,
const char *  code 
)

Set the account's accounting code.

Definition at line 2466 of file Account.cpp.

2467{
2468 AccountPrivate *priv;
2469
2470 /* errors */
2471 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2472
2473 /* optimizations */
2474 priv = GET_PRIVATE(acc);
2475 if (g_strcmp0(str, priv->accountCode) == 0)
2476 return;
2477
2479 priv->accountCode = qof_string_cache_replace(priv->accountCode, str ? str : "");
2480 mark_account (acc);
2482}

◆ xaccAccountSetColor()

void xaccAccountSetColor ( Account *  account,
const char *  color 
)

Set the account's Color.

Definition at line 2601 of file Account.cpp.

2602{
2603 set_kvp_string_path (acc, {"color"}, str);
2604}

◆ xaccAccountSetCommodity()

void xaccAccountSetCommodity ( Account *  account,
gnc_commodity *  comm 
)

Set the account's commodity.

Definition at line 2666 of file Account.cpp.

2667{
2668 AccountPrivate *priv;
2669
2670 /* errors */
2671 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2672 g_return_if_fail(GNC_IS_COMMODITY(com));
2673
2674 /* optimizations */
2675 priv = GET_PRIVATE(acc);
2676 if (com == priv->commodity)
2677 return;
2678
2680 gnc_commodity_decrement_usage_count(priv->commodity);
2681 priv->commodity = com;
2683 priv->commodity_scu = gnc_commodity_get_fraction(com);
2684 priv->non_standard_scu = FALSE;
2685
2686 /* iterate over splits */
2687 for (auto s : priv->splits)
2688 {
2689 Transaction *trans = xaccSplitGetParent (s);
2690
2691 xaccTransBeginEdit (trans);
2693 xaccTransCommitEdit (trans);
2694 }
2695
2696 priv->sort_dirty = TRUE; /* Not needed. */
2697 priv->balance_dirty = TRUE;
2698 mark_account (acc);
2699
2701}
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
Increment a commodity's internal counter that tracks how many accounts are using that commodity.
void gnc_commodity_decrement_usage_count(gnc_commodity *cm)
Decrement a commodity's internal counter that tracks how many accounts are using that commodity.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...

◆ xaccAccountSetCommoditySCU()

void xaccAccountSetCommoditySCU ( Account *  account,
int  frac 
)

Set the SCU for the account.

Normally, this routine is not required, as the default SCU for an account is given by its commodity.

Definition at line 2710 of file Account.cpp.

2711{
2712 AccountPrivate *priv;
2713
2714 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2715
2716 priv = GET_PRIVATE(acc);
2718 priv->commodity_scu = scu;
2719 if (scu != gnc_commodity_get_fraction(priv->commodity))
2720 priv->non_standard_scu = TRUE;
2721 mark_account(acc);
2723}

◆ xaccAccountSetDescription()

void xaccAccountSetDescription ( Account *  account,
const char *  desc 
)

Set the account's description.

Definition at line 2485 of file Account.cpp.

2486{
2487 AccountPrivate *priv;
2488
2489 /* errors */
2490 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2491
2492 /* optimizations */
2493 priv = GET_PRIVATE(acc);
2494 if (g_strcmp0(str, priv->description) == 0)
2495 return;
2496
2498 priv->description = qof_string_cache_replace(priv->description, str ? str : "");
2499 mark_account (acc);
2501}

◆ xaccAccountSetFilter()

void xaccAccountSetFilter ( Account *  account,
const char *  filter 
)

Set the account's Filter.

Definition at line 2607 of file Account.cpp.

2608{
2609 set_kvp_string_path (acc, {"filter"}, str);
2610}

◆ xaccAccountSetLastNum()

void xaccAccountSetLastNum ( Account *  account,
const char *  num 
)

Set the last num field of an Account.

Definition at line 4680 of file Account.cpp.

4681{
4682 set_kvp_string_path (acc, {"last-num"}, num);
4683}

◆ xaccAccountSetName()

void xaccAccountSetName ( Account *  account,
const char *  name 
)

Set the account's name.

Definition at line 2446 of file Account.cpp.

2447{
2448 AccountPrivate *priv;
2449
2450 /* errors */
2451 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2452 g_return_if_fail(str);
2453
2454 /* optimizations */
2455 priv = GET_PRIVATE(acc);
2456 if (g_strcmp0(str, priv->accountName) == 0)
2457 return;
2458
2460 priv->accountName = qof_string_cache_replace(priv->accountName, str);
2461 mark_account (acc);
2463}

◆ xaccAccountSetNonStdSCU()

void xaccAccountSetNonStdSCU ( Account *  account,
gboolean  flag 
)

Set the flag indicating that this account uses a non-standard SCU.

Definition at line 2746 of file Account.cpp.

2747{
2748 AccountPrivate *priv;
2749
2750 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2751
2752 priv = GET_PRIVATE(acc);
2753 if (priv->non_standard_scu == flag)
2754 return;
2756 priv->non_standard_scu = flag;
2757 mark_account (acc);
2759}

◆ xaccAccountSetNotes()

void xaccAccountSetNotes ( Account *  account,
const char *  notes 
)

Set the account's notes.

Definition at line 2643 of file Account.cpp.

2644{
2645 set_kvp_string_path (acc, {"notes"}, str);
2646}

◆ xaccAccountSetOnlineID()

void xaccAccountSetOnlineID ( Account *  account,
const char *  id 
)

Set the account's online_id, the identifier (e.g.

an OFX/HBCI BANKID+ACCTID composite) of the online account this GnuCash account is mapped to for bank imports. This is the same value (engine KVP slot "online_id") that the desktop OFX/HBCI importer uses to match a downloaded statement to its GnuCash account. Passing NULL or "" clears it. Wraps its own begin/commit edit.

Definition at line 2649 of file Account.cpp.

2650{
2651 g_return_if_fail (GNC_IS_ACCOUNT(acc));
2652 set_kvp_string_path (acc, {KEY_ONLINE_ID}, id);
2653}

◆ xaccAccountSetReconcileChildrenStatus()

void xaccAccountSetReconcileChildrenStatus ( Account *  account,
gboolean  status 
)

DOCUMENT ME!

Definition at line 4870 of file Account.cpp.

4871{
4872 /* Would have been nice to use G_TYPE_BOOLEAN, but the other
4873 * boolean kvps save the value as "true" or "false" and that would
4874 * be file-incompatible with this.
4875 */
4876 set_kvp_int64_path (acc, {KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN}, status);
4877}

◆ xaccAccountSetSortOrder()

void xaccAccountSetSortOrder ( Account *  account,
const char *  sortorder 
)

Set the account's Sort Order.

Definition at line 2613 of file Account.cpp.

2614{
2615 set_kvp_string_path (acc, {"sort-order"}, str);
2616}

◆ xaccAccountSetSortReversed()

void xaccAccountSetSortReversed ( Account *  account,
gboolean  sortreversed 
)

Set the account's Sort Order direction.

Definition at line 2619 of file Account.cpp.

2620{
2621 set_kvp_boolean_path (acc, {"sort-reversed"}, sortreversed);
2622}

◆ xaccAccountSetType()

void xaccAccountSetType ( Account *  account,
GNCAccountType  tip 
)

Set the account's type.

Definition at line 2425 of file Account.cpp.

2426{
2427 AccountPrivate *priv;
2428
2429 /* errors */
2430 g_return_if_fail(GNC_IS_ACCOUNT(acc));
2431 g_return_if_fail(tip < NUM_ACCOUNT_TYPES);
2432
2433 /* optimizations */
2434 priv = GET_PRIVATE(acc);
2435 if (priv->type == tip)
2436 return;
2437
2439 priv->type = tip;
2440 priv->balance_dirty = TRUE; /* new type may affect balance computation */
2441 mark_account(acc);
2443}

◆ xaccAccountSortSplits()

void xaccAccountSortSplits ( Account *  acc,
gboolean  force 
)

The xaccAccountSortSplits() routine will resort the account's splits if the sort is dirty.

If 'force' is true, the account is sorted even if the editlevel is not zero.

Definition at line 1992 of file Account.cpp.

1993{
1994 AccountPrivate *priv;
1995
1996 g_return_if_fail(GNC_IS_ACCOUNT(acc));
1997
1998 priv = GET_PRIVATE(acc);
1999 if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
2000 return;
2001 std::sort (priv->splits.begin(), priv->splits.end(), split_cmp_less);
2002 priv->sort_dirty = FALSE;
2003 priv->balance_dirty = TRUE;
2004}

◆ xaccCloneAccount()

Account * xaccCloneAccount ( const Account *  source,
QofBook *  book 
)

The xaccCloneAccount() routine makes a simple copy of the indicated account, placing it in the indicated book.

It copies the account type, name, description, and the kvp values; it does not copy splits/transactions. The book should have a commodity table in it that has commodities with the same unique name as the ones being copied in the account (the commodities in the clone will be those from the book).

Definition at line 1289 of file Account.cpp.

1290{
1291 Account *ret;
1292 AccountPrivate *from_priv, *priv;
1293
1294 g_return_val_if_fail(GNC_IS_ACCOUNT(from), nullptr);
1295 g_return_val_if_fail(QOF_IS_BOOK(book), nullptr);
1296
1297 ENTER (" ");
1298 ret = static_cast<Account*>(g_object_new (GNC_TYPE_ACCOUNT, nullptr));
1299 g_return_val_if_fail (ret, nullptr);
1300
1301 from_priv = GET_PRIVATE(from);
1302 priv = GET_PRIVATE(ret);
1303 xaccInitAccount (ret, book);
1304
1305 /* Do not Begin/CommitEdit() here; give the caller
1306 * a chance to fix things up, and let them do it.
1307 * Also let caller issue the generate_event (EVENT_CREATE) */
1308 priv->type = from_priv->type;
1309
1310 priv->accountName = qof_string_cache_replace(priv->accountName, from_priv->accountName);
1311 priv->accountCode = qof_string_cache_replace(priv->accountCode, from_priv->accountCode);
1312 priv->description = qof_string_cache_replace(priv->description, from_priv->description);
1313
1314 qof_instance_copy_kvp (QOF_INSTANCE (ret), QOF_INSTANCE (from));
1315
1316 /* The new book should contain a commodity that matches
1317 * the one in the old book. Find it, use it. */
1318 priv->commodity = gnc_commodity_obtain_twin(from_priv->commodity, book);
1319 gnc_commodity_increment_usage_count(priv->commodity);
1320
1321 priv->commodity_scu = from_priv->commodity_scu;
1322 priv->non_standard_scu = from_priv->non_standard_scu;
1323
1324 qof_instance_set_dirty(&ret->inst);
1325 LEAVE (" ");
1326 return ret;
1327}
gnc_commodity * gnc_commodity_obtain_twin(const gnc_commodity *from, QofBook *book)
Given the commodity 'findlike', this routine will find and return the equivalent commodity (commodity...

◆ xaccMallocAccount()

Account * xaccMallocAccount ( QofBook *  book)

Constructor.

Definition at line 1258 of file Account.cpp.

1259{
1260 Account *acc;
1261
1262 g_return_val_if_fail (book, nullptr);
1263
1264 acc = static_cast<Account*>(g_object_new (GNC_TYPE_ACCOUNT, nullptr));
1265 xaccInitAccount (acc, book);
1266 qof_event_gen (&acc->inst, QOF_EVENT_CREATE, nullptr);
1267
1268 return acc;
1269}