GnuCash  2.6.17
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

Files

file  Account.h
 Account handling public routines.
 

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))
 
#define xaccAccountGetSlots(X)   qof_instance_get_slots(QOF_INSTANCE(X))
 

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)
 

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
}
 

Functions

GType gnc_account_get_type (void)
 
gchar * gnc_account_name_violations_errmsg (const gchar *separator, GList *invalid_account_names)
 
GList * gnc_account_list_name_violations (QofBook *book, const gchar *separator)
 
void xaccAccountSetReconcileChildrenStatus (Account *account, gboolean status)
 
gboolean xaccAccountGetReconcileChildrenStatus (const Account *account)
 
gboolean xaccAccountHasAncestor (const Account *acc, const Account *ancestor)
 

Account Constructors, Edit/Commit, Comparison

AccountxaccMallocAccount (QofBook *book)
 
Accountgnc_account_create_root (QofBook *book)
 
AccountxaccCloneAccount (const Account *source, QofBook *book)
 
void xaccAccountBeginEdit (Account *account)
 
void xaccAccountCommitEdit (Account *account)
 
void xaccAccountDestroy (Account *account)
 
gboolean xaccAccountEqual (const Account *a, const Account *b, gboolean check_guids)
 
int xaccAccountOrder (const Account *account_1, const Account *account_2)
 

Account lookup and GncGUID routines

const gchar * gnc_get_account_separator_string (void)
 
gunichar gnc_get_account_separator (void)
 
void gnc_set_account_separator (const gchar *separator)
 
Accountgnc_book_get_root_account (QofBook *book)
 
void gnc_book_set_root_account (QofBook *book, Account *root)
 
AccountxaccAccountLookup (const GncGUID *guid, QofBook *book)
 
#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)
 
void xaccAccountSetName (Account *account, const char *name)
 
void xaccAccountSetCode (Account *account, const char *code)
 
void xaccAccountSetDescription (Account *account, const char *desc)
 
void xaccAccountSetColor (Account *account, const char *color)
 
void xaccAccountSetFilter (Account *account, const char *filter)
 
void xaccAccountSetSortOrder (Account *account, const char *sortorder)
 
void xaccAccountSetSortReversed (Account *account, gboolean sortreversed)
 
void xaccAccountSetNotes (Account *account, const char *notes)
 
void xaccAccountSetLastNum (Account *account, const char *num)
 
void gnc_account_set_policy (Account *account, GNCPolicy *policy)
 
GNCAccountType xaccAccountGetType (const Account *account)
 
gboolean xaccAccountIsPriced (const Account *acc)
 
void gnc_account_set_start_balance (Account *acc, const gnc_numeric start_baln)
 
void gnc_account_set_start_cleared_balance (Account *acc, const gnc_numeric start_baln)
 
void gnc_account_set_start_reconciled_balance (Account *acc, const gnc_numeric start_baln)
 
void gnc_account_set_balance_dirty (Account *acc)
 
void gnc_account_set_sort_dirty (Account *acc)
 
gboolean gnc_account_insert_split (Account *acc, Split *s)
 
gboolean gnc_account_remove_split (Account *acc, Split *s)
 
const char * xaccAccountGetName (const Account *account)
 
const char * xaccAccountGetCode (const Account *account)
 
const char * xaccAccountGetDescription (const Account *account)
 
const char * xaccAccountGetColor (const Account *account)
 
const char * xaccAccountGetFilter (const Account *account)
 
const char * xaccAccountGetSortOrder (const Account *account)
 
gboolean xaccAccountGetSortReversed (const Account *account)
 
const char * xaccAccountGetNotes (const Account *account)
 
const char * xaccAccountGetLastNum (const Account *account)
 
GNCPolicy * gnc_account_get_policy (Account *account)
 
void xaccAccountRecomputeBalance (Account *)
 
void xaccAccountSortSplits (Account *acc, gboolean force)
 
gchar * gnc_account_get_full_name (const Account *account)
 
void dxaccAccountSetPriceSrc (Account *account, const char *src)
 
const char * dxaccAccountGetPriceSrc (const Account *account)
 
gboolean xaccAccountGetAutoInterestXfer (const Account *account, gboolean default_value)
 
void xaccAccountSetAutoInterestXfer (Account *account, gboolean value)
 

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)
 
gnc_commodity * xaccAccountGetCommodity (const Account *account)
 
gnc_commodity * gnc_account_get_currency_or_parent (const Account *account)
 
int xaccAccountGetCommoditySCU (const Account *account)
 
int xaccAccountGetCommoditySCUi (const Account *account)
 
void xaccAccountSetCommoditySCU (Account *account, int frac)
 
void xaccAccountSetNonStdSCU (Account *account, gboolean flag)
 
gboolean xaccAccountGetNonStdSCU (const Account *account)
 

Account Balance

gnc_numeric xaccAccountGetBalance (const Account *account)
 
gnc_numeric xaccAccountGetClearedBalance (const Account *account)
 
gnc_numeric xaccAccountGetReconciledBalance (const Account *account)
 
gnc_numeric xaccAccountGetPresentBalance (const Account *account)
 
gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account)
 
gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account, time64 date)
 
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, gnc_commodity *balance_currency, 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 xaccAccountGetBalanceAsOfDateInCurrency (Account *account, time64 date, gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetBalanceChangeForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 

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)
 
void gnc_account_remove_child (Account *parent, Account *child)
 
Accountgnc_account_get_parent (const Account *account)
 
Accountgnc_account_get_root (Account *account)
 
gboolean gnc_account_is_root (const Account *account)
 
GList * gnc_account_get_children (const Account *account)
 
GList * gnc_account_get_children_sorted (const Account *account)
 
gint gnc_account_n_children (const Account *account)
 
gint gnc_account_child_index (const Account *parent, const Account *child)
 
Accountgnc_account_nth_child (const Account *parent, gint num)
 
GList * gnc_account_get_descendants (const Account *account)
 
GList * gnc_account_get_descendants_sorted (const Account *account)
 
gint gnc_account_n_descendants (const Account *account)
 
gint gnc_account_get_current_depth (const Account *account)
 
gint gnc_account_get_tree_depth (const Account *account)
 

ForEach

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

Concatenation, Merging

void gnc_account_join_children (Account *to_parent, Account *from_parent)
 
void gnc_account_merge_children (Account *parent)
 

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

◆ xaccAccountGetGUID

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

Definition at line 239 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 96 of file Account.h.

97 {
98  ACCT_TYPE_INVALID = -1,
99  ACCT_TYPE_NONE = -1,
101  ACCT_TYPE_BANK = 0,
104  ACCT_TYPE_CASH = 1,
107  ACCT_TYPE_CREDIT = 3,
110  ACCT_TYPE_ASSET = 2,
116  ACCT_TYPE_STOCK = 5,
119  ACCT_TYPE_MUTUAL = 6,
123  ACCT_TYPE_CURRENCY = 7,
134  ACCT_TYPE_INCOME = 8,
137  ACCT_TYPE_EXPENSE = 9,
140  ACCT_TYPE_EQUITY = 10,
145  ACCT_TYPE_PAYABLE = 12,
147  ACCT_TYPE_ROOT = 13,
149  ACCT_TYPE_TRADING = 14,
155  NUM_ACCOUNT_TYPES = 15,
158  /* bank account types */
159  ACCT_TYPE_CHECKING = 15,
161  ACCT_TYPE_SAVINGS = 16,
163  ACCT_TYPE_MONEYMRKT = 17,
165  ACCT_TYPE_CREDITLINE = 18,
167  ACCT_TYPE_LAST
GNCAccountType
Definition: Account.h:96

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.

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

Definition at line 4442 of file Account.c.

4443 {
4444  if (!acc) return NULL;
4445 
4446  if (xaccAccountIsPriced(acc))
4447  {
4448  KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data,
4449  "old-price-source");
4450  if (value) return (kvp_value_get_string(value));
4451  }
4452  return NULL;
4453 }
gboolean xaccAccountIsPriced(const Account *acc)
Definition: Account.c:4175
char * kvp_value_get_string(const KvpValue *value)
Definition: kvp_frame.c:1146

◆ 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 4421 of file Account.c.

4422 {
4423  if (!acc) return;
4424 
4425  xaccAccountBeginEdit(acc);
4426  if (xaccAccountIsPriced(acc))
4427  {
4428  kvp_frame_set_slot_nc(acc->inst.kvp_data,
4429  "old-price-source",
4430  src ? kvp_value_new_string(src) : NULL);
4431  mark_account (acc);
4432  }
4433 
4434  qof_instance_set_dirty(&acc->inst);
4435  xaccAccountCommitEdit(acc);
4436 }
gboolean xaccAccountIsPriced(const Account *acc)
Definition: Account.c:4175
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ 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 2400 of file Account.c.

2401 {
2402  AccountPrivate *ppriv, *cpriv;
2403  Account *old_parent;
2404  QofCollection *col;
2405 
2406  /* errors */
2407  g_assert(GNC_IS_ACCOUNT(new_parent));
2408  g_assert(GNC_IS_ACCOUNT(child));
2409 
2410  /* optimizations */
2411  ppriv = GET_PRIVATE(new_parent);
2412  cpriv = GET_PRIVATE(child);
2413  old_parent = cpriv->parent;
2414  if (old_parent == new_parent)
2415  return;
2416 
2417  // xaccAccountBeginEdit(new_parent);
2418  xaccAccountBeginEdit(child);
2419  if (old_parent)
2420  {
2421  gnc_account_remove_child(old_parent, child);
2422 
2423  if (!qof_instance_books_equal(old_parent, new_parent))
2424  {
2425  /* hack alert -- this implementation is not exactly correct.
2426  * If the entity tables are not identical, then the 'from' book
2427  * may have a different backend than the 'to' book. This means
2428  * that we should get the 'from' backend to destroy this account,
2429  * and the 'to' backend to save it. Right now, this is broken.
2430  *
2431  * A 'correct' implementation similar to this is in Period.c
2432  * except its for transactions ...
2433  *
2434  * Note also, we need to reparent the children to the new book as well.
2435  */
2436  PWARN ("reparenting accounts across books is not correctly supported\n");
2437 
2438  qof_event_gen (&child->inst, QOF_EVENT_DESTROY, NULL);
2440  GNC_ID_ACCOUNT);
2441  qof_collection_insert_entity (col, &child->inst);
2442  qof_event_gen (&child->inst, QOF_EVENT_CREATE, NULL);
2443  }
2444  }
2445  cpriv->parent = new_parent;
2446  ppriv->children = g_list_append(ppriv->children, child);
2447  qof_instance_set_dirty(&new_parent->inst);
2448  qof_instance_set_dirty(&child->inst);
2449 
2450  /* Send events data. Warning: The call to commit_edit is also going
2451  * to send a MODIFY event. If the gtktreemodelfilter code gets the
2452  * MODIFY before it gets the ADD, it gets very confused and thinks
2453  * that two nodes have been added. */
2454  qof_event_gen (&child->inst, QOF_EVENT_ADD, NULL);
2455  // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, NULL);
2456 
2457  xaccAccountCommitEdit (child);
2458  // xaccAccountCommitEdit(new_parent);
2459 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define PWARN(format, args...)
Definition: qoflog.h:238
void gnc_account_remove_child(Account *parent, Account *child)
Definition: Account.c:2462
void qof_collection_insert_entity(QofCollection *, QofInstance *)
Definition: qofid.c:94
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:572
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ 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 2558 of file Account.c.

2559 {
2560  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), -1);
2561  g_return_val_if_fail(GNC_IS_ACCOUNT(child), -1);
2562  return g_list_index(GET_PRIVATE(parent)->children, child);
2563 }

◆ gnc_account_create_root()

Account* gnc_account_create_root ( QofBook *  book)

Create a new root level account.

Definition at line 960 of file Account.c.

961 {
962  Account *root;
963  AccountPrivate *rpriv;
964 
965  root = xaccMallocAccount(book);
966  rpriv = GET_PRIVATE(root);
967  xaccAccountBeginEdit(root);
968  rpriv->type = ACCT_TYPE_ROOT;
969  CACHE_REPLACE(rpriv->accountName, "Root Account");
970  mark_account (root);
971  xaccAccountCommitEdit(root);
972  gnc_book_set_root_account(book, root);
973  return root;
974 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
Account * xaccMallocAccount(QofBook *book)
Definition: Account.c:946
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ 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 2815 of file Account.c.

2818 {
2819  const AccountPrivate *priv;
2820  GList *node;
2821 
2822  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2823  g_return_if_fail(thunk);
2824 
2825  priv = GET_PRIVATE(acc);
2826  for (node = priv->children; node; node = node->next)
2827  {
2828  thunk (node->data, user_data);
2829  }
2830 }

◆ gnc_account_foreach_descendant()

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 2833 of file Account.c.

2836 {
2837  const AccountPrivate *priv;
2838  GList *node;
2839  Account *child;
2840 
2841  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2842  g_return_if_fail(thunk);
2843 
2844  priv = GET_PRIVATE(acc);
2845  for (node = priv->children; node; node = node->next)
2846  {
2847  child = node->data;
2848  thunk(child, user_data);
2849  gnc_account_foreach_descendant(child, thunk, user_data);
2850  }
2851 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
Definition: Account.c:2833

◆ 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 2854 of file Account.c.

2857 {
2858  const AccountPrivate *priv;
2859  GList *node;
2860  Account *child;
2861  gpointer result;
2862 
2863  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2864  g_return_val_if_fail(thunk, NULL);
2865 
2866  priv = GET_PRIVATE(acc);
2867  for (node = priv->children; node; node = node->next)
2868  {
2869  child = node->data;
2870  result = thunk(child, user_data);
2871  if (result)
2872  return(result);
2873 
2874  result = gnc_account_foreach_descendant_until(child, thunk, user_data);
2875  if (result)
2876  return(result);
2877  }
2878 
2879  return NULL;
2880 }
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
Definition: Account.c:2854

◆ 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 2529 of file Account.c.

2530 {
2531  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2532  return g_list_copy(GET_PRIVATE(account)->children);
2533 }

◆ 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 2536 of file Account.c.

2537 {
2538  AccountPrivate *priv;
2539 
2540  /* errors */
2541  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2542 
2543  /* optimizations */
2544  priv = GET_PRIVATE(account);
2545  if (!priv->children)
2546  return NULL;
2547  return g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
2548 }
int xaccAccountOrder(const Account *aa, const Account *ab)
Definition: Account.c:1995

◆ 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 3041 of file Account.c.

3042 {
3043  gnc_commodity * commodity;
3044  g_assert(account);
3045 
3046  commodity = xaccAccountGetCommodity (account);
3047  if (gnc_commodity_is_currency(commodity))
3048  return commodity;
3049  else
3050  {
3051  const Account *parent_account = account;
3052  /* Account commodity is not a currency, walk up the tree until
3053  * we find a parent account that is a currency account and use
3054  * it's currency.
3055  */
3056  do
3057  {
3058  parent_account = gnc_account_get_parent (parent_account);
3059  if (parent_account)
3060  {
3061  commodity = xaccAccountGetCommodity (parent_account);
3062  if (gnc_commodity_is_currency(commodity))
3063  {
3064  return commodity;
3065  //break;
3066  }
3067  }
3068  }
3069  while (parent_account);
3070  }
3071  return NULL; // no suitable commodity found.
3072 }
Account * gnc_account_get_parent(const Account *acc)
Definition: Account.c:2498
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3034

◆ 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 2590 of file Account.c.

2591 {
2592  AccountPrivate *priv;
2593  int depth = 0;
2594 
2595  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2596 
2597  priv = GET_PRIVATE(account);
2598  while (priv->parent && (priv->type != ACCT_TYPE_ROOT))
2599  {
2600  account = priv->parent;
2601  priv = GET_PRIVATE(account);
2602  depth++;
2603  }
2604 
2605  return depth;
2606 }

◆ 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 2630 of file Account.c.

2631 {
2632  AccountPrivate *priv;
2633  GList *child, *descendants;
2634 
2635  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2636 
2637  priv = GET_PRIVATE(account);
2638  if (!priv->children)
2639  return NULL;
2640 
2641  descendants = NULL;
2642  for (child = priv->children; child; child = g_list_next(child))
2643  {
2644  descendants = g_list_append(descendants, child->data);
2645  descendants = g_list_concat(descendants,
2646  gnc_account_get_descendants(child->data));
2647  }
2648  return descendants;
2649 }
GList * gnc_account_get_descendants(const Account *account)
Definition: Account.c:2630

◆ 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 som 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 2652 of file Account.c.

2653 {
2654  AccountPrivate *priv;
2655  GList *child, *children, *descendants;
2656 
2657  /* errors */
2658  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2659 
2660  /* optimizations */
2661  priv = GET_PRIVATE(account);
2662  if (!priv->children)
2663  return NULL;
2664 
2665  descendants = NULL;
2666  children = g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
2667  for (child = children; child; child = g_list_next(child))
2668  {
2669  descendants = g_list_append(descendants, child->data);
2670  descendants = g_list_concat(descendants,
2671  gnc_account_get_descendants_sorted(child->data));
2672  }
2673  g_list_free(children);
2674  return descendants;
2675 }
GList * gnc_account_get_descendants_sorted(const Account *account)
Definition: Account.c:2652
int xaccAccountOrder(const Account *aa, const Account *ab)
Definition: Account.c:1995

◆ 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 2913 of file Account.c.

2914 {
2915  AccountPrivate *priv;
2916  const Account *a;
2917  char *fullname;
2918  gchar **names;
2919  int level;
2920 
2921  /* So much for hardening the API. Too many callers to this function don't
2922  * bother to check if they have a non-NULL pointer before calling. */
2923  if (NULL == account)
2924  return g_strdup("");
2925 
2926  /* errors */
2927  g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
2928 
2929  /* optimizations */
2930  priv = GET_PRIVATE(account);
2931  if (!priv->parent)
2932  return g_strdup("");
2933 
2934  /* Figure out how much space is needed by counting the nodes up to
2935  * the root. */
2936  level = 0;
2937  for (a = account; a; a = priv->parent)
2938  {
2939  priv = GET_PRIVATE(a);
2940  level++;
2941  }
2942 
2943  /* Get all the pointers in the right order. The root node "entry"
2944  * becomes the terminating NULL pointer for the array of strings. */
2945  names = g_malloc(level * sizeof(gchar *));
2946  names[--level] = NULL;
2947  for (a = account; level > 0; a = priv->parent)
2948  {
2949  priv = GET_PRIVATE(a);
2950  names[--level] = priv->accountName;
2951  }
2952 
2953  /* Build the full name */
2954  fullname = g_strjoinv(account_separator, names);
2955  g_free(names);
2956 
2957  return fullname;
2958 }

◆ 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 2498 of file Account.c.

2499 {
2500  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2501  return GET_PRIVATE(acc)->parent;
2502 }

◆ gnc_account_get_policy()

GNCPolicy* gnc_account_get_policy ( Account account)

Get the account's lot order policy

Definition at line 1743 of file Account.c.

1744 {
1745  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
1746 
1747  return GET_PRIVATE(acc)->policy;
1748 }

◆ 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 2505 of file Account.c.

2506 {
2507  AccountPrivate *priv;
2508 
2509  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2510 
2511  priv = GET_PRIVATE(acc);
2512  while (priv->parent)
2513  {
2514  acc = priv->parent;
2515  priv = GET_PRIVATE(acc);
2516  }
2517 
2518  return acc;
2519 }

◆ 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 2609 of file Account.c.

2610 {
2611  AccountPrivate *priv;
2612  GList *node;
2613  gint depth = 0, child_depth;
2614 
2615  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2616 
2617  priv = GET_PRIVATE(account);
2618  if (!priv->children)
2619  return 1;
2620 
2621  for (node = priv->children; node; node = g_list_next(node))
2622  {
2623  child_depth = gnc_account_get_tree_depth(node->data);
2624  depth = MAX(depth, child_depth);
2625  }
2626  return depth + 1;
2627 }
gint gnc_account_get_tree_depth(const Account *account)
Definition: Account.c:2609

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

◆ 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 1583 of file Account.c.

1584 {
1585  AccountPrivate *priv;
1586  GList *node;
1587 
1588  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1589  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1590 
1591  priv = GET_PRIVATE(acc);
1592  node = g_list_find(priv->splits, s);
1593  if (node)
1594  return FALSE;
1595 
1596  if (qof_instance_get_editlevel(acc) == 0)
1597  {
1598  priv->splits = g_list_insert_sorted(priv->splits, s,
1599  (GCompareFunc)xaccSplitOrder);
1600  }
1601  else
1602  {
1603  priv->splits = g_list_prepend(priv->splits, s);
1604  priv->sort_dirty = TRUE;
1605  }
1606 
1607  //FIXME: find better event
1608  qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
1609  /* Also send an event based on the account */
1610  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_ADDED, s);
1611 
1612  priv->balance_dirty = TRUE;
1613 // DRH: Should the below be added? It is present in the delete path.
1614 // xaccAccountRecomputeBalance(acc);
1615  return TRUE;
1616 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
Definition: Split.c:1298
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230
#define GNC_EVENT_ITEM_ADDED
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 2522 of file Account.c.

2523 {
2524  g_return_val_if_fail(GNC_IS_ACCOUNT(account), FALSE);
2525  return (GET_PRIVATE(account)->parent == NULL);
2526 }

◆ 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 4591 of file Account.c.

4592 {
4593  AccountPrivate *from_priv;
4594  GList *children, *node;
4595 
4596  /* errors */
4597  g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
4598  g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
4599 
4600  /* optimizations */
4601  from_priv = GET_PRIVATE(from_parent);
4602  if (!from_priv->children)
4603  return;
4604 
4605  ENTER (" ");
4606  children = g_list_copy(from_priv->children);
4607  for (node = children; node; node = g_list_next(node))
4608  gnc_account_append_child(to_parent, node->data);
4609  g_list_free(children);
4610  LEAVE (" ");
4611 }
void gnc_account_append_child(Account *new_parent, Account *child)
Definition: Account.c:2400
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ 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 if no longer needed.

Definition at line 178 of file Account.c.

179 {
180  Account *root_account = gnc_book_get_root_account(book);
181  GList *accounts, *node;
182  GList *invalid_list = NULL;
183 
184  g_return_val_if_fail (separator != NULL, NULL);
185 
186  if (root_account == NULL)
187  return NULL;
188 
189  accounts = gnc_account_get_descendants (root_account);
190  for (node = accounts; node; node = g_list_next(node))
191  {
192  Account *acct = (Account*)node->data;
193  gchar *acct_name = g_strdup ( xaccAccountGetName ( acct ) );
194 
195  if ( g_strstr_len ( acct_name, -1, separator ) )
196  invalid_list = g_list_prepend ( invalid_list, (gpointer) acct_name );
197  else
198  g_free ( acct_name );
199  }
200  if (accounts != NULL)
201  {
202  g_list_free(accounts);
203  }
204 
205  return invalid_list;
206 }
GList * gnc_account_get_descendants(const Account *account)
Definition: Account.c:2630
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:2906

◆ 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 4616 of file Account.c.

4617 {
4618  AccountPrivate *ppriv, *priv_a, *priv_b;
4619  GList *node_a, *node_b, *work, *worker;
4620 
4621  g_return_if_fail(GNC_IS_ACCOUNT(parent));
4622 
4623  ppriv = GET_PRIVATE(parent);
4624  for (node_a = ppriv->children; node_a; node_a = node_a->next)
4625  {
4626  Account *acc_a = node_a->data;
4627 
4628  priv_a = GET_PRIVATE(acc_a);
4629  for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
4630  {
4631  Account *acc_b = node_b->data;
4632 
4633  priv_b = GET_PRIVATE(acc_b);
4634  if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
4635  continue;
4636  if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
4637  continue;
4638  if (0 != null_strcmp(priv_a->description, priv_b->description))
4639  continue;
4640  if (0 != null_strcmp(xaccAccountGetColor(acc_a),
4641  xaccAccountGetColor(acc_b)))
4642  continue;
4643  if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
4644  continue;
4645  if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
4646  xaccAccountGetNotes(acc_b)))
4647  continue;
4648  if (priv_a->type != priv_b->type)
4649  continue;
4650 
4651  /* consolidate children */
4652  if (priv_b->children)
4653  {
4654  work = g_list_copy(priv_b->children);
4655  for (worker = work; worker; worker = g_list_next(worker))
4656  gnc_account_append_child (acc_a, (Account *)worker->data);
4657  g_list_free(work);
4658 
4659  qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, NULL);
4660  qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, NULL);
4661  }
4662 
4663  /* recurse to do the children's children */
4665 
4666  /* consolidate transactions */
4667  while (priv_b->splits)
4668  xaccSplitSetAccount (priv_b->splits->data, acc_a);
4669 
4670  /* move back one before removal. next iteration around the loop
4671  * will get the node after node_b */
4672  node_b = g_list_previous(node_b);
4673 
4674  /* The destroy function will remove from list -- node_a is ok,
4675  * it's before node_b */
4676  xaccAccountBeginEdit (acc_b);
4677  xaccAccountDestroy (acc_b);
4678  }
4679  }
4680 }
void gnc_account_append_child(Account *new_parent, Account *child)
Definition: Account.c:2400
void xaccAccountDestroy(Account *acc)
Definition: Account.c:1263
const char * xaccAccountGetColor(const Account *acc)
Definition: Account.c:2975
gint null_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:123
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
void gnc_account_merge_children(Account *parent)
Definition: Account.c:4616
const char * xaccAccountGetNotes(const Account *acc)
Definition: Account.c:3007

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

2552 {
2553  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2554  return g_list_length(GET_PRIVATE(account)->children);
2555 }

◆ 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 2573 of file Account.c.

2574 {
2575  AccountPrivate *priv;
2576  GList *node;
2577  gint count = 0;
2578 
2579  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2580 
2581  priv = GET_PRIVATE(account);
2582  for (node = priv->children; node; node = g_list_next(node))
2583  {
2584  count += gnc_account_n_descendants(node->data) + 1;
2585  }
2586  return count;
2587 }
gint gnc_account_n_descendants(const Account *account)
Definition: Account.c:2573

◆ 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 141 of file Account.c.

142 {
143  GList *node;
144  gchar *message = NULL;
145  gchar *account_list = NULL;
146 
147  if ( !invalid_account_names )
148  return NULL;
149 
150  for ( node = invalid_account_names; node; node = g_list_next(node))
151  {
152  if ( !account_list )
153  account_list = node->data;
154  else
155  {
156  gchar *tmp_list = NULL;
157 
158  tmp_list = g_strconcat (account_list, "\n", node->data, NULL );
159  g_free ( account_list );
160  account_list = tmp_list;
161  }
162  }
163 
164  /* Translators: The first %s will be the account separator character,
165  the second %s is a list of account names.
166  The resulting string will be displayed to the user if there are
167  account names containing the separator character. */
168  message = g_strdup_printf(
169  _("The separator character \"%s\" is used in one or more account names.\n\n"
170  "This will result in unexpected behaviour. "
171  "Either change the account names or choose another separator character.\n\n"
172  "Below you will find the list of invalid account names:\n"
173  "%s"), separator, account_list );
174  g_free ( account_list );
175  return message;
176 }

◆ 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 2566 of file Account.c.

2567 {
2568  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
2569  return g_list_nth_data(GET_PRIVATE(parent)->children, num);
2570 }

◆ 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 2462 of file Account.c.

2463 {
2464  AccountPrivate *ppriv, *cpriv;
2465  GncEventData ed;
2466 
2467  if (!child) return;
2468 
2469  /* Note this routine might be called on accounts which
2470  * are not yet parented. */
2471  if (!parent) return;
2472 
2473  ppriv = GET_PRIVATE(parent);
2474  cpriv = GET_PRIVATE(child);
2475 
2476  if (cpriv->parent != parent)
2477  {
2478  PERR ("account not a child of parent");
2479  return;
2480  }
2481 
2482  /* Gather event data */
2483  ed.node = parent;
2484  ed.idx = g_list_index(ppriv->children, child);
2485 
2486  ppriv->children = g_list_remove(ppriv->children, child);
2487 
2488  /* Now send the event. */
2489  qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
2490 
2491  /* clear the account's parent pointer after REMOVE event generation. */
2492  cpriv->parent = NULL;
2493 
2494  qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, NULL);
2495 }
#define PERR(format, args...)
Definition: qoflog.h:232
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ 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 1619 of file Account.c.

1620 {
1621  AccountPrivate *priv;
1622  GList *node;
1623 
1624  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1625  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1626 
1627  priv = GET_PRIVATE(acc);
1628  node = g_list_find(priv->splits, s);
1629  if (NULL == node)
1630  return FALSE;
1631 
1632  priv->splits = g_list_delete_link(priv->splits, node);
1633  //FIXME: find better event type
1634  qof_event_gen(&acc->inst, QOF_EVENT_MODIFY, NULL);
1635  // And send the account-based event, too
1636  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_REMOVED, s);
1637 
1638  priv->balance_dirty = TRUE;
1640  return TRUE;
1641 }
void xaccAccountRecomputeBalance(Account *acc)
Definition: Account.c:1921
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ 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 1566 of file Account.c.

1567 {
1568  AccountPrivate *priv;
1569 
1570  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1571 
1572  if (qof_instance_get_destroying(acc))
1573  return;
1574 
1575  priv = GET_PRIVATE(acc);
1576  priv->balance_dirty = TRUE;
1577 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660

◆ gnc_account_set_policy()

void gnc_account_set_policy ( Account account,
GNCPolicy *  policy 
)

Set the account's lot order policy

Definition at line 1751 of file Account.c.

1752 {
1753  AccountPrivate *priv;
1754 
1755  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1756 
1757  priv = GET_PRIVATE(acc);
1758  priv->policy = policy ? policy : xaccGetFIFOPolicy();
1759 }
GNCPolicy * xaccGetFIFOPolicy(void)
Definition: policy.c:178

◆ 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 1552 of file Account.c.

1553 {
1554  AccountPrivate *priv;
1555 
1556  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1557 
1558  if (qof_instance_get_destroying(acc))
1559  return;
1560 
1561  priv = GET_PRIVATE(acc);
1562  priv->sort_dirty = TRUE;
1563 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660

◆ 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 3077 of file Account.c.

3078 {
3079  AccountPrivate *priv;
3080 
3081  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3082 
3083  priv = GET_PRIVATE(acc);
3084  priv->starting_balance = start_baln;
3085  priv->balance_dirty = TRUE;
3086 }

◆ 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 3089 of file Account.c.

3091 {
3092  AccountPrivate *priv;
3093 
3094  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3095 
3096  priv = GET_PRIVATE(acc);
3097  priv->starting_cleared_balance = start_baln;
3098  priv->balance_dirty = TRUE;
3099 }

◆ 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 3102 of file Account.c.

3104 {
3105  AccountPrivate *priv;
3106 
3107  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3108 
3109  priv = GET_PRIVATE(acc);
3110  priv->starting_reconciled_balance = start_baln;
3111  priv->balance_dirty = TRUE;
3112 }

◆ 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 111 of file Account.c.

112 {
113  return account_separator;
114 }

◆ xaccAccountBeginEdit()

void xaccAccountBeginEdit ( Account account)

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

Definition at line 1143 of file Account.c.

1144 {
1145  g_return_if_fail(acc);
1146  qof_begin_edit(&acc->inst);
1147 }
gboolean qof_begin_edit(QofInstance *inst)
Definition: qofinstance.c:941

◆ xaccAccountCommitEdit()

void xaccAccountCommitEdit ( Account account)

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

Definition at line 1184 of file Account.c.

1185 {
1186  AccountPrivate *priv;
1187  QofBook *book;
1188 
1189  g_return_if_fail(acc);
1190  if (!qof_commit_edit(&acc->inst)) return;
1191 
1192  /* If marked for deletion, get rid of subaccounts first,
1193  * and then the splits ... */
1194  priv = GET_PRIVATE(acc);
1195  if (qof_instance_get_destroying(acc))
1196  {
1197  GList *lp, *slist;
1198  QofCollection *col;
1199 
1200  qof_instance_increase_editlevel(acc);
1201 
1202  /* First, recursively free children */
1203  xaccFreeAccountChildren(acc);
1204 
1205  PINFO ("freeing splits for account %p (%s)",
1206  acc, priv->accountName ? priv->accountName : "(null)");
1207 
1208  book = qof_instance_get_book(acc);
1209 
1210  /* If book is shutting down, just clear the split list. The splits
1211  themselves will be destroyed by the transaction code */
1212  if (!qof_book_shutting_down(book))
1213  {
1214  slist = g_list_copy(priv->splits);
1215  for (lp = slist; lp; lp = lp->next)
1216  {
1217  Split *s = lp->data;
1218  xaccSplitDestroy (s);
1219  }
1220  g_list_free(slist);
1221  }
1222  else
1223  {
1224  g_list_free(priv->splits);
1225  priv->splits = NULL;
1226  }
1227 
1228  /* It turns out there's a case where this assertion does not hold:
1229  When the user tries to delete an Imbalance account, while also
1230  deleting all the splits in it. The splits will just get
1231  recreated and put right back into the same account!
1232 
1233  g_assert(priv->splits == NULL || qof_book_shutting_down(acc->inst.book));
1234  */
1235 
1236  if (!qof_book_shutting_down(book))
1237  {
1238  col = qof_book_get_collection(book, GNC_ID_TRANS);
1239  qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
1240 
1241  /* the lots should be empty by now */
1242  for (lp = priv->lots; lp; lp = lp->next)
1243  {
1244  GNCLot *lot = lp->data;
1245  gnc_lot_destroy (lot);
1246  }
1247  }
1248  g_list_free(priv->lots);
1249  priv->lots = NULL;
1250 
1251  qof_instance_set_dirty(&acc->inst);
1252  qof_instance_decrease_editlevel(acc);
1253  }
1254  else
1255  {
1256  xaccAccountBringUpToDate(acc);
1257  }
1258 
1259  qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
1260 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
#define PINFO(format, args...)
Definition: qoflog.h:244
gboolean xaccSplitDestroy(Split *split)
Definition: Split.c:1269
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660
gboolean qof_commit_edit(QofInstance *inst)
Definition: qofinstance.c:963
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
void qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Definition: qofid.c:317
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
Definition: qofinstance.c:982
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306
gboolean qof_book_shutting_down(const QofBook *book)
Definition: qofbook.c:230

◆ 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 1263 of file Account.c.

1264 {
1265  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1266 
1267  qof_instance_set_destroying(acc, TRUE);
1268 
1269  xaccAccountCommitEdit (acc);
1270 }
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ 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 1338 of file Account.c.

1339 {
1340  AccountPrivate *priv_aa, *priv_ab;
1341 
1342  if (!aa && !ab) return TRUE;
1343 
1344  g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
1345  g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
1346 
1347  priv_aa = GET_PRIVATE(aa);
1348  priv_ab = GET_PRIVATE(ab);
1349  if (priv_aa->type != priv_ab->type)
1350  {
1351  PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
1352  return FALSE;
1353  }
1354 
1355  if (g_strcmp0(priv_aa->accountName, priv_ab->accountName) != 0)
1356  {
1357  PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
1358  return FALSE;
1359  }
1360 
1361  if (g_strcmp0(priv_aa->accountCode, priv_ab->accountCode) != 0)
1362  {
1363  PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
1364  return FALSE;
1365  }
1366 
1367  if (g_strcmp0(priv_aa->description, priv_ab->description) != 0)
1368  {
1369  PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
1370  return FALSE;
1371  }
1372 
1373  if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
1374  {
1375  PWARN ("commodities differ");
1376  return FALSE;
1377  }
1378 
1379  if (check_guids)
1380  {
1381  if (qof_instance_guid_compare(aa, ab) != 0)
1382  {
1383  PWARN ("GUIDs differ");
1384  return FALSE;
1385  }
1386  }
1387 
1388  if (kvp_frame_compare(aa->inst.kvp_data, ab->inst.kvp_data) != 0)
1389  {
1390  char *frame_a;
1391  char *frame_b;
1392 
1393  frame_a = kvp_frame_to_string (aa->inst.kvp_data);
1394  frame_b = kvp_frame_to_string (ab->inst.kvp_data);
1395 
1396  PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
1397 
1398  g_free (frame_a);
1399  g_free (frame_b);
1400 
1401  return FALSE;
1402  }
1403 
1404  if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
1405  {
1406  char *str_a;
1407  char *str_b;
1408 
1409  str_a = gnc_numeric_to_string(priv_aa->starting_balance);
1410  str_b = gnc_numeric_to_string(priv_ab->starting_balance);
1411 
1412  PWARN ("starting balances differ: %s vs %s", str_a, str_b);
1413 
1414  g_free (str_a);
1415  g_free (str_b);
1416 
1417  return FALSE;
1418  }
1419 
1420  if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
1421  priv_ab->starting_cleared_balance))
1422  {
1423  char *str_a;
1424  char *str_b;
1425 
1426  str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
1427  str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
1428 
1429  PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
1430 
1431  g_free (str_a);
1432  g_free (str_b);
1433 
1434  return FALSE;
1435  }
1436 
1437  if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
1438  priv_ab->starting_reconciled_balance))
1439  {
1440  char *str_a;
1441  char *str_b;
1442 
1443  str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
1444  str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
1445 
1446  PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
1447 
1448  g_free (str_a);
1449  g_free (str_b);
1450 
1451  return FALSE;
1452  }
1453 
1454  if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
1455  {
1456  char *str_a;
1457  char *str_b;
1458 
1459  str_a = gnc_numeric_to_string(priv_aa->balance);
1460  str_b = gnc_numeric_to_string(priv_ab->balance);
1461 
1462  PWARN ("balances differ: %s vs %s", str_a, str_b);
1463 
1464  g_free (str_a);
1465  g_free (str_b);
1466 
1467  return FALSE;
1468  }
1469 
1470  if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
1471  {
1472  char *str_a;
1473  char *str_b;
1474 
1475  str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
1476  str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
1477 
1478  PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
1479 
1480  g_free (str_a);
1481  g_free (str_b);
1482 
1483  return FALSE;
1484  }
1485 
1486  if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
1487  {
1488  char *str_a;
1489  char *str_b;
1490 
1491  str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
1492  str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
1493 
1494  PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
1495 
1496  g_free (str_a);
1497  g_free (str_b);
1498 
1499  return FALSE;
1500  }
1501 
1502  /* no parent; always compare downwards. */
1503 
1504  {
1505  GList *la = priv_aa->splits;
1506  GList *lb = priv_ab->splits;
1507 
1508  if ((la && !lb) || (!la && lb))
1509  {
1510  PWARN ("only one has splits");
1511  return FALSE;
1512  }
1513 
1514  if (la && lb)
1515  {
1516  /* presume that the splits are in the same order */
1517  while (la && lb)
1518  {
1519  Split *sa = (Split *) la->data;
1520  Split *sb = (Split *) lb->data;
1521 
1522  if (!xaccSplitEqual(sa, sb, check_guids, TRUE, FALSE))
1523  {
1524  PWARN ("splits differ");
1525  return(FALSE);
1526  }
1527 
1528  la = la->next;
1529  lb = lb->next;
1530  }
1531 
1532  if ((la != NULL) || (lb != NULL))
1533  {
1534  PWARN ("number of splits differs");
1535  return(FALSE);
1536  }
1537  }
1538  }
1539 
1540  if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
1541  {
1542  PWARN ("children differ");
1543  return FALSE;
1544  }
1545 
1546  return(TRUE);
1547 }
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Definition: gnc-numeric.c:304
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
Definition: kvp_frame.c:1427
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
gchar * gnc_numeric_to_string(gnc_numeric n)
Definition: gnc-numeric.c:1371
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Definition: Split.c:579
#define PWARN(format, args...)
Definition: qoflog.h:238
gchar * kvp_frame_to_string(const KvpFrame *frame)
Definition: kvp_frame.c:1620
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519

◆ xaccAccountGetAutoInterestXfer()

gboolean xaccAccountGetAutoInterestXfer ( const Account account,
gboolean  default_value 
)

Returns a per-account flag: Prior to reconciling an account which charges or pays interest, this flag tells whether to prompt the user to enter a transaction for the interest charge or payment. This per-account flag overrides the global preference.

Definition at line 4367 of file Account.c.

4368 {
4369  const char *str = NULL;
4370  if (!acc) return default_value;
4371 
4372  str = kvp_frame_get_string(acc->inst.kvp_data,
4373  "reconcile-info/auto-interest-transfer");
4374  return str ? !strcmp(str, "true") : default_value;
4375 }

◆ xaccAccountGetBalance()

gnc_numeric xaccAccountGetBalance ( const Account account)

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

Definition at line 3115 of file Account.c.

3116 {
3117  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3118  return GET_PRIVATE(acc)->balance;
3119 }

◆ xaccAccountGetBalanceAsOfDate()

gnc_numeric xaccAccountGetBalanceAsOfDate ( Account account,
time64  date 
)

Get the balance of the account as of the date specified

Definition at line 3174 of file Account.c.

3175 {
3176  /* Ideally this could use xaccAccountForEachSplit, but
3177  * it doesn't exist yet and I'm uncertain of exactly how
3178  * it would work at this time, since it differs from
3179  * xaccAccountForEachTransaction by using gpointer return
3180  * values rather than gints.
3181  */
3182  AccountPrivate *priv;
3183  GList *lp;
3184  Timespec ts, trans_ts;
3185  gboolean found = FALSE;
3186  gnc_numeric balance;
3187 
3188  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3189 
3190  xaccAccountSortSplits (acc, TRUE); /* just in case, normally a noop */
3191  xaccAccountRecomputeBalance (acc); /* just in case, normally a noop */
3192 
3193  priv = GET_PRIVATE(acc);
3194  balance = priv->balance;
3195 
3196  /* Since transaction post times are stored as a Timespec,
3197  * convert date into a Timespec as well rather than converting
3198  * each transaction's Timespec into a time64.
3199  *
3200  * FIXME: CAS: I think this comment is a bogus justification for
3201  * using xaccTransGetDatePostedTS. There's no benefit to using
3202  * Timespec when the input argument is time64, and it's hard to
3203  * imagine that casting long long to long and comparing two longs is
3204  * worse than comparing two long longs every time. IMO,
3205  * xaccAccountGetPresentBalance gets this right, and its algorithm
3206  * should be used here.
3207  */
3208  ts.tv_sec = date;
3209  ts.tv_nsec = 0;
3210 
3211  lp = priv->splits;
3212  while ( lp && !found )
3213  {
3214  xaccTransGetDatePostedTS( xaccSplitGetParent( (Split *)lp->data ),
3215  &trans_ts );
3216  if ( timespec_cmp( &trans_ts, &ts ) >= 0 )
3217  found = TRUE;
3218  else
3219  lp = lp->next;
3220  }
3221 
3222  if ( lp )
3223  {
3224  if ( lp->prev )
3225  {
3226  /* Since lp is now pointing to a split which was past the reconcile
3227  * date, get the running balance of the previous split.
3228  */
3229  balance = xaccSplitGetBalance( (Split *)lp->prev->data );
3230  }
3231  else
3232  {
3233  /* AsOf date must be before any entries, return zero. */
3234  balance = gnc_numeric_zero();
3235  }
3236  }
3237 
3238  /* Otherwise there were no splits posted after the given date,
3239  * so the latest account balance should be good enough.
3240  */
3241 
3242  return( balance );
3243 }
void xaccAccountSortSplits(Account *acc, gboolean force)
Definition: Account.c:1644
Transaction * xaccSplitGetParent(const Split *split)
Definition: Split.c:1658
gnc_numeric xaccSplitGetBalance(const Split *s)
Definition: Split.c:1102
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
Definition: gnc-date.c:593
void xaccAccountRecomputeBalance(Account *acc)
Definition: Account.c:1921
void xaccTransGetDatePostedTS(const Transaction *trans, Timespec *ts)
Definition: Transaction.c:2233

◆ xaccAccountGetClearedBalance()

gnc_numeric xaccAccountGetClearedBalance ( const Account account)

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

Definition at line 3122 of file Account.c.

3123 {
3124  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3125  return GET_PRIVATE(acc)->cleared_balance;
3126 }

◆ xaccAccountGetCode()

const char* xaccAccountGetCode ( const Account account)

Get the account's accounting code

Definition at line 2961 of file Account.c.

2962 {
2963  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2964  return GET_PRIVATE(acc)->accountCode;
2965 }

◆ xaccAccountGetColor()

const char* xaccAccountGetColor ( const Account account)

Get the account's color

Definition at line 2975 of file Account.c.

2976 {
2977  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2978  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "color") : NULL;
2979 }

◆ xaccAccountGetCommodity()

gnc_commodity* xaccAccountGetCommodity ( const Account account)

Get the account's commodity

Definition at line 3034 of file Account.c.

3035 {
3036  if (!GNC_IS_ACCOUNT(acc))
3037  return NULL;
3038  return GET_PRIVATE(acc)->commodity;
3039 }

◆ 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 2333 of file Account.c.

2334 {
2335  AccountPrivate *priv;
2336 
2337  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2338 
2339  priv = GET_PRIVATE(acc);
2340  if (priv->non_standard_scu || !priv->commodity)
2341  return priv->commodity_scu;
2342  return gnc_commodity_get_fraction(priv->commodity);
2343 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)

◆ 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 2326 of file Account.c.

2327 {
2328  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2329  return GET_PRIVATE(acc)->commodity_scu;
2330 }

◆ xaccAccountGetDescription()

const char* xaccAccountGetDescription ( const Account account)

Get the account's description

Definition at line 2968 of file Account.c.

2969 {
2970  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2971  return GET_PRIVATE(acc)->description;
2972 }

◆ xaccAccountGetFilter()

const char* xaccAccountGetFilter ( const Account account)

Get the account's filter

Definition at line 2982 of file Account.c.

2983 {
2984  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2985  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "filter") : NULL;
2986 }

◆ xaccAccountGetLastNum()

const char* xaccAccountGetLastNum ( const Account account)

Get the last num field of an Account

Definition at line 4398 of file Account.c.

4399 {
4400  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "last-num") : NULL;
4401 }

◆ xaccAccountGetName()

const char* xaccAccountGetName ( const Account account)

Get the account's name

Definition at line 2906 of file Account.c.

2907 {
2908  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2909  return GET_PRIVATE(acc)->accountName;
2910 }

◆ xaccAccountGetNonStdSCU()

gboolean xaccAccountGetNonStdSCU ( const Account account)

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

Definition at line 2362 of file Account.c.

2363 {
2364  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2365  return GET_PRIVATE(acc)->non_standard_scu;
2366 }

◆ xaccAccountGetNotes()

const char* xaccAccountGetNotes ( const Account account)

Get the account's notes

Definition at line 3007 of file Account.c.

3008 {
3009  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3010  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "notes") : NULL;
3011 }

◆ xaccAccountGetReconcileChildrenStatus()

gboolean xaccAccountGetReconcileChildrenStatus ( const Account account)

DOCUMENT ME!

Definition at line 4512 of file Account.c.

4513 {
4514  /* access the account's kvp-data for status and return that, if no value
4515  * is found then we can assume not to include the children, that being
4516  * the default behaviour
4517  */
4518  return acc ? kvp_frame_get_gint64(acc->inst.kvp_data,
4519  "reconcile-info/include-children") : FALSE;
4520 }

◆ xaccAccountGetReconciledBalance()

gnc_numeric xaccAccountGetReconciledBalance ( const Account account)

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

Definition at line 3129 of file Account.c.

3130 {
3131  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3132  return GET_PRIVATE(acc)->reconciled_balance;
3133 }

◆ xaccAccountGetSortOrder()

const char* xaccAccountGetSortOrder ( const Account account)

Get the account's Sort Order

Definition at line 2989 of file Account.c.

2990 {
2991  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2992  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "sort-order") : NULL;
2993 }

◆ xaccAccountGetSortReversed()

gboolean xaccAccountGetSortReversed ( const Account account)

Get the account's Sort Order direction

Definition at line 2996 of file Account.c.

2997 {
2998  const char *str;
2999 
3000  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
3001 
3002  str = kvp_frame_get_string(acc->inst.kvp_data, "sort-reversed");
3003  return (str && !strcmp(str, "true"));
3004 }

◆ 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 2884 of file Account.c.

2885 {
2886  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), ACCT_TYPE_NONE);
2887  return GET_PRIVATE(acc)->type;
2888 }

◆ 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 3890 of file Account.c.

3891 {
3892  const Account *parent;
3893 
3894  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
3895  g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
3896 
3897  parent = acc;
3898  while (parent && parent != ancestor)
3899  parent = GET_PRIVATE(parent)->parent;
3900 
3901  return (parent == ancestor);
3902 }

◆ xaccAccountIsPriced()

gboolean xaccAccountIsPriced ( const Account acc)

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

Definition at line 4175 of file Account.c.

4176 {
4177  AccountPrivate *priv;
4178 
4179  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4180 
4181  priv = GET_PRIVATE(acc);
4182  return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
4183  priv->type == ACCT_TYPE_CURRENCY);
4184 }

◆ 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 1690 of file Account.c.

1691 {
1692  QofCollection *col;
1693  if (!guid || !book) return NULL;
1694  col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
1695  return (Account *) qof_collection_lookup_entity (col, guid);
1696 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Definition: qofid.c:211
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306

◆ 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 1995 of file Account.c.

1996 {
1997  AccountPrivate *priv_aa, *priv_ab;
1998  char *da, *db;
1999  char *endptr = NULL;
2000  int ta, tb, result;
2001  long la, lb;
2002 
2003  if ( aa && !ab ) return -1;
2004  if ( !aa && ab ) return +1;
2005  if ( !aa && !ab ) return 0;
2006 
2007  priv_aa = GET_PRIVATE(aa);
2008  priv_ab = GET_PRIVATE(ab);
2009 
2010  /* sort on accountCode strings */
2011  da = priv_aa->accountCode;
2012  db = priv_ab->accountCode;
2013 
2014  /* If accountCodes are both base 36 integers do an integer sort */
2015  la = strtoul (da, &endptr, 36);
2016  if ((*da != '\0') && (*endptr == '\0'))
2017  {
2018  lb = strtoul (db, &endptr, 36);
2019  if ((*db != '\0') && (*endptr == '\0'))
2020  {
2021  if (la < lb) return -1;
2022  if (la > lb) return +1;
2023  }
2024  }
2025 
2026  /* Otherwise do a string sort */
2027  result = g_strcmp0 (da, db);
2028  if (result)
2029  return result;
2030 
2031  /* if account-type-order array not initialized, initialize it */
2032  /* this will happen at most once during program invocation */
2033  if (-1 == revorder[0])
2034  {
2035  int i;
2036  for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
2037  {
2038  revorder [typeorder[i]] = i;
2039  }
2040  }
2041 
2042  /* otherwise, sort on account type */
2043  ta = priv_aa->type;
2044  tb = priv_ab->type;
2045  ta = revorder[ta];
2046  tb = revorder[tb];
2047  if (ta < tb) return -1;
2048  if (ta > tb) return +1;
2049 
2050  /* otherwise, sort on accountName strings */
2051  da = priv_aa->accountName;
2052  db = priv_ab->accountName;
2053  result = safe_utf8_collate(da, db);
2054  if (result)
2055  return result;
2056 
2057  /* guarantee a stable sort */
2058  return qof_instance_guid_compare(aa, ab);
2059 }
int safe_utf8_collate(const char *da, const char *db)
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Definition: qofinstance.c:519

◆ xaccAccountRecomputeBalance()

void xaccAccountRecomputeBalance ( Account )

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

Definition at line 1921 of file Account.c.

1922 {
1923  AccountPrivate *priv;
1924  gnc_numeric balance;
1925  gnc_numeric cleared_balance;
1926  gnc_numeric reconciled_balance;
1927  GList *lp;
1928 
1929  if (NULL == acc) return;
1930 
1931  priv = GET_PRIVATE(acc);
1932  if (qof_instance_get_editlevel(acc) > 0) return;
1933  if (!priv->balance_dirty) return;
1934  if (qof_instance_get_destroying(acc)) return;
1936 
1937  balance = priv->starting_balance;
1938  cleared_balance = priv->starting_cleared_balance;
1939  reconciled_balance = priv->starting_reconciled_balance;
1940 
1941  PINFO ("acct=%s starting baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
1942  priv->accountName, balance.num, balance.denom);
1943  for (lp = priv->splits; lp; lp = lp->next)
1944  {
1945  Split *split = (Split *) lp->data;
1946  gnc_numeric amt = xaccSplitGetAmount (split);
1947 
1948  balance = gnc_numeric_add_fixed(balance, amt);
1949 
1950  if (NREC != split->reconciled)
1951  {
1952  cleared_balance = gnc_numeric_add_fixed(cleared_balance, amt);
1953  }
1954 
1955  if (YREC == split->reconciled ||
1956  FREC == split->reconciled)
1957  {
1958  reconciled_balance =
1959  gnc_numeric_add_fixed(reconciled_balance, amt);
1960  }
1961 
1962  split->balance = balance;
1963  split->cleared_balance = cleared_balance;
1964  split->reconciled_balance = reconciled_balance;
1965 
1966  }
1967 
1968  priv->balance = balance;
1969  priv->cleared_balance = cleared_balance;
1970  priv->reconciled_balance = reconciled_balance;
1971  priv->balance_dirty = FALSE;
1972 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
#define PINFO(format, args...)
Definition: qoflog.h:244
gboolean qof_instance_get_destroying(gconstpointer ptr)
Definition: qofinstance.c:660
#define YREC
Definition: Split.h:68
#define FREC
Definition: Split.h:69
gboolean qof_book_shutting_down(const QofBook *book)
Definition: qofbook.c:230
#define NREC
Definition: Split.h:70
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ xaccAccountSetAutoInterestXfer()

void xaccAccountSetAutoInterestXfer ( Account account,
gboolean  value 
)

Sets a per-account flag: Prior to reconciling an account which charges or pays interest, this flag tells whether to prompt the user to enter a transaction for the interest charge or payment. This per-account flag overrides the global preference.

Definition at line 4381 of file Account.c.

4382 {
4383  if (!acc) return;
4384 
4385  xaccAccountBeginEdit (acc);
4386  /* FIXME: need KVP_TYPE_BOOLEAN for this someday */
4387  kvp_frame_set_string (acc->inst.kvp_data,
4388  "/reconcile-info/auto-interest-transfer",
4389  (option ? "true" : "false"));
4390  mark_account (acc);
4391  xaccAccountCommitEdit (acc);
4392 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.

◆ xaccAccountSetCode()

void xaccAccountSetCode ( Account account,
const char *  code 
)

Set the account's accounting code

Definition at line 2112 of file Account.c.

2113 {
2114  AccountPrivate *priv;
2115 
2116  /* errors */
2117  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2118 
2119  /* optimizations */
2120  priv = GET_PRIVATE(acc);
2121  if (g_strcmp0(str, priv->accountCode) == 0)
2122  return;
2123 
2124  xaccAccountBeginEdit(acc);
2125  CACHE_REPLACE(priv->accountCode, str ? str : "");
2126  mark_account (acc);
2127  xaccAccountCommitEdit(acc);
2128 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetColor()

void xaccAccountSetColor ( Account account,
const char *  color 
)

Set the account's Color

Definition at line 2150 of file Account.c.

2151 {
2152  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2153 
2154  xaccAccountBeginEdit(acc);
2155  if (str)
2156  {
2157  gchar *tmp = g_strstrip(g_strdup(str));
2158  kvp_frame_set_slot_nc(acc->inst.kvp_data, "color",
2159  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2160  g_free(tmp);
2161  }
2162  else
2163  {
2164  kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", NULL);
2165  }
2166  mark_account (acc);
2167  xaccAccountCommitEdit(acc);
2168 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetCommodity()

void xaccAccountSetCommodity ( Account account,
gnc_commodity *  comm 
)

Set the account's commodity

Definition at line 2264 of file Account.c.

2265 {
2266  AccountPrivate *priv;
2267  GList *lp;
2268 
2269  /* errors */
2270  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2271  g_return_if_fail(GNC_IS_COMMODITY(com));
2272 
2273  /* optimizations */
2274  priv = GET_PRIVATE(acc);
2275  if (com == priv->commodity)
2276  return;
2277 
2278  xaccAccountBeginEdit(acc);
2279  gnc_commodity_decrement_usage_count(priv->commodity);
2280  priv->commodity = com;
2282  priv->commodity_scu = gnc_commodity_get_fraction(com);
2283  priv->non_standard_scu = FALSE;
2284 
2285  /* iterate over splits */
2286  for (lp = priv->splits; lp; lp = lp->next)
2287  {
2288  Split *s = (Split *) lp->data;
2289  Transaction *trans = xaccSplitGetParent (s);
2290 
2291  xaccTransBeginEdit (trans);
2293  xaccTransCommitEdit (trans);
2294  }
2295 
2296  priv->sort_dirty = TRUE; /* Not needed. */
2297  priv->balance_dirty = TRUE;
2298  mark_account (acc);
2299 
2300  xaccAccountCommitEdit(acc);
2301 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
void gnc_commodity_decrement_usage_count(gnc_commodity *cm)
Transaction * xaccSplitGetParent(const Split *split)
Definition: Split.c:1658
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
Definition: Split.c:1042
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1555
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1356
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1742

◆ 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 2310 of file Account.c.

2311 {
2312  AccountPrivate *priv;
2313 
2314  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2315 
2316  priv = GET_PRIVATE(acc);
2317  xaccAccountBeginEdit(acc);
2318  priv->commodity_scu = scu;
2319  if (scu != gnc_commodity_get_fraction(priv->commodity))
2320  priv->non_standard_scu = TRUE;
2321  mark_account(acc);
2322  xaccAccountCommitEdit(acc);
2323 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetDescription()

void xaccAccountSetDescription ( Account account,
const char *  desc 
)

Set the account's description

Definition at line 2131 of file Account.c.

2132 {
2133  AccountPrivate *priv;
2134 
2135  /* errors */
2136  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2137 
2138  /* optimizations */
2139  priv = GET_PRIVATE(acc);
2140  if (g_strcmp0(str, priv->description) == 0)
2141  return;
2142 
2143  xaccAccountBeginEdit(acc);
2144  CACHE_REPLACE(priv->description, str ? str : "");
2145  mark_account (acc);
2146  xaccAccountCommitEdit(acc);
2147 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetFilter()

void xaccAccountSetFilter ( Account account,
const char *  filter 
)

Set the account's Filter

Definition at line 2171 of file Account.c.

2172 {
2173  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2174 
2175  xaccAccountBeginEdit(acc);
2176  if (str)
2177  {
2178  gchar *tmp = g_strstrip(g_strdup(str));
2179  kvp_frame_set_slot_nc(acc->inst.kvp_data, "filter",
2180  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2181  g_free(tmp);
2182  }
2183  else
2184  {
2185  kvp_frame_set_slot_nc(acc->inst.kvp_data, "filter", NULL);
2186  }
2187  mark_account (acc);
2188  xaccAccountCommitEdit(acc);
2189 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetLastNum()

void xaccAccountSetLastNum ( Account account,
const char *  num 
)

Set the last num field of an Account

Definition at line 4407 of file Account.c.

4408 {
4409  if (!acc) return;
4410 
4411  xaccAccountBeginEdit (acc);
4412  kvp_frame_set_string(acc->inst.kvp_data, "last-num", num);
4413  mark_account (acc);
4414  xaccAccountCommitEdit (acc);
4415 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.

◆ xaccAccountSetName()

void xaccAccountSetName ( Account account,
const char *  name 
)

Set the account's name

Definition at line 2092 of file Account.c.

2093 {
2094  AccountPrivate *priv;
2095 
2096  /* errors */
2097  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2098  g_return_if_fail(str);
2099 
2100  /* optimizations */
2101  priv = GET_PRIVATE(acc);
2102  if (g_strcmp0(str, priv->accountName) == 0)
2103  return;
2104 
2105  xaccAccountBeginEdit(acc);
2106  CACHE_REPLACE(priv->accountName, str);
2107  mark_account (acc);
2108  xaccAccountCommitEdit(acc);
2109 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetNonStdSCU()

void xaccAccountSetNonStdSCU ( Account account,
gboolean  flag 
)

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

Definition at line 2346 of file Account.c.

2347 {
2348  AccountPrivate *priv;
2349 
2350  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2351 
2352  priv = GET_PRIVATE(acc);
2353  if (priv->non_standard_scu == flag)
2354  return;
2355  xaccAccountBeginEdit(acc);
2356  priv->non_standard_scu = flag;
2357  mark_account (acc);
2358  xaccAccountCommitEdit(acc);
2359 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetNotes()

void xaccAccountSetNotes ( Account account,
const char *  notes 
)

Set the account's notes

Definition at line 2243 of file Account.c.

2244 {
2245  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2246 
2247  xaccAccountBeginEdit(acc);
2248  if (str)
2249  {
2250  gchar *tmp = g_strstrip(g_strdup(str));
2251  kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes",
2252  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2253  g_free(tmp);
2254  }
2255  else
2256  {
2257  kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes", NULL);
2258  }
2259  mark_account(acc);
2260  xaccAccountCommitEdit(acc);
2261 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetReconcileChildrenStatus()

void xaccAccountSetReconcileChildrenStatus ( Account account,
gboolean  status 
)

DOCUMENT ME!

Definition at line 4495 of file Account.c.

4496 {
4497  if (!acc) return;
4498 
4499  xaccAccountBeginEdit (acc);
4500 
4501  /* XXX FIXME: someday this should use KVP_TYPE_BOOLEAN */
4502  kvp_frame_set_gint64 (acc->inst.kvp_data,
4503  "/reconcile-info/include-children", status);
4504  mark_account(acc);
4505  xaccAccountCommitEdit (acc);
4506 }
void kvp_frame_set_gint64(KvpFrame *frame, const gchar *path, gint64 ival)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetSortOrder()

void xaccAccountSetSortOrder ( Account account,
const char *  sortorder 
)

Set the account's Sort Order

Definition at line 2192 of file Account.c.

2193 {
2194  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2195 
2196  xaccAccountBeginEdit(acc);
2197  if (str)
2198  {
2199  gchar *tmp = g_strstrip(g_strdup(str));
2200  kvp_frame_set_slot_nc(acc->inst.kvp_data, "sort-order",
2201  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2202  g_free(tmp);
2203  }
2204  else
2205  {
2206  kvp_frame_set_slot_nc(acc->inst.kvp_data, "sort-order", NULL);
2207  }
2208  mark_account (acc);
2209  xaccAccountCommitEdit(acc);
2210 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ xaccAccountSetSortReversed()

void xaccAccountSetSortReversed ( Account account,
gboolean  sortreversed 
)

Set the account's Sort Order direction

Definition at line 2213 of file Account.c.

2214 {
2215  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2216 
2217  xaccAccountBeginEdit (acc);
2218  kvp_frame_set_string (acc->inst.kvp_data, "sort-reversed",
2219  sortreversed ? "true" : NULL);
2220  mark_account (acc);
2221  xaccAccountCommitEdit (acc);
2222 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.

◆ xaccAccountSetType()

void xaccAccountSetType ( Account account,
GNCAccountType   
)

Set the account's type

Definition at line 2071 of file Account.c.

2072 {
2073  AccountPrivate *priv;
2074 
2075  /* errors */
2076  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2077  g_return_if_fail(tip < NUM_ACCOUNT_TYPES);
2078 
2079  /* optimizations */
2080  priv = GET_PRIVATE(acc);
2081  if (priv->type == tip)
2082  return;
2083 
2084  xaccAccountBeginEdit(acc);
2085  priv->type = tip;
2086  priv->balance_dirty = TRUE; /* new type may affect balance computation */
2087  mark_account(acc);
2088  xaccAccountCommitEdit(acc);
2089 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1143
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1184

◆ 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 1644 of file Account.c.

1645 {
1646  AccountPrivate *priv;
1647 
1648  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1649 
1650  priv = GET_PRIVATE(acc);
1651  if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
1652  return;
1653  priv->splits = g_list_sort(priv->splits, (GCompareFunc)xaccSplitOrder);
1654  priv->sort_dirty = FALSE;
1655  priv->balance_dirty = TRUE;
1656 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
Definition: Split.c:1298

◆ 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 977 of file Account.c.

978 {
979  Account *ret;
980  AccountPrivate *from_priv, *priv;
981 
982  g_return_val_if_fail(GNC_IS_ACCOUNT(from), NULL);
983  g_return_val_if_fail(QOF_IS_BOOK(book), NULL);
984 
985  ENTER (" ");
986  ret = g_object_new (GNC_TYPE_ACCOUNT, NULL);
987  g_return_val_if_fail (ret, NULL);
988 
989  from_priv = GET_PRIVATE(from);
990  priv = GET_PRIVATE(ret);
991  xaccInitAccount (ret, book);
992 
993  /* Do not Begin/CommitEdit() here; give the caller
994  * a chance to fix things up, and let them do it.
995  * Also let caller issue the generate_event (EVENT_CREATE) */
996  priv->type = from_priv->type;
997 
998  priv->accountName = CACHE_INSERT(from_priv->accountName);
999  priv->accountCode = CACHE_INSERT(from_priv->accountCode);
1000  priv->description = CACHE_INSERT(from_priv->description);
1001 
1002  kvp_frame_delete(ret->inst.kvp_data);
1003  ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
1004 
1005  /* The new book should contain a commodity that matches
1006  * the one in the old book. Find it, use it. */
1007  priv->commodity = gnc_commodity_obtain_twin(from_priv->commodity, book);
1008  gnc_commodity_increment_usage_count(priv->commodity);
1009 
1010  priv->commodity_scu = from_priv->commodity_scu;
1011  priv->non_standard_scu = from_priv->non_standard_scu;
1012 
1013  qof_instance_set_dirty(&ret->inst);
1014  LEAVE (" ");
1015  return ret;
1016 }
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
Definition: kvp_frame.c:151
void qof_instance_set_dirty(QofInstance *inst)
Set the dirty flag.
Definition: qofinstance.c:723
#define ENTER(format, args...)
Definition: qoflog.h:256
void kvp_frame_delete(KvpFrame *frame)
Definition: kvp_frame.c:116
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
#define LEAVE(format, args...)
Definition: qoflog.h:266
gnc_commodity * gnc_commodity_obtain_twin(const gnc_commodity *from, QofBook *book)

◆ xaccMallocAccount()

Account* xaccMallocAccount ( QofBook *  book)

Constructor

Definition at line 946 of file Account.c.

947 {
948  Account *acc;
949 
950  g_return_val_if_fail (book, NULL);
951 
952  acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
953  xaccInitAccount (acc, book);
954  qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL);
955 
956  return acc;
957 }
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230