GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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))
 

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

QofBookgnc_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 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)
 
const char * xaccAccountGetNotes (const Account *account)
 
const char * xaccAccountGetLastNum (const Account *account)
 
GNCPolicygnc_account_get_policy (Account *account)
 
void xaccAccountRecomputeBalance (Account *)
 
void xaccAccountSortSplits (Account *acc, gboolean force)
 
gchar * gnc_account_get_full_name (const Account *account)
 
AccountxaccAccountGainsAccount (Account *acc, gnc_commodity *curr)
 
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_commodityxaccAccountGetCommodity (const Account *account)
 
gnc_commoditygnc_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

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

Definition at line 239 of file Account.h.

Enumeration Type Documentation

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

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

4591 {
4592  if (!acc) return NULL;
4593 
4594  if (xaccAccountIsPriced(acc))
4595  {
4596  KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data,
4597  "old-price-source");
4598  if (value) return (kvp_value_get_string(value));
4599  }
4600  return NULL;
4601 }
gboolean xaccAccountIsPriced(const Account *acc)
Definition: Account.c:4249
char * kvp_value_get_string(const KvpValue *value)
struct KvpValueImpl KvpValue
Definition: kvp_frame.h:80
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 4569 of file Account.c.

4570 {
4571  if (!acc) return;
4572 
4573  xaccAccountBeginEdit(acc);
4574  if (xaccAccountIsPriced(acc))
4575  {
4576  kvp_frame_set_slot_nc(acc->inst.kvp_data,
4577  "old-price-source",
4578  src ? kvp_value_new_string(src) : NULL);
4579  mark_account (acc);
4580  }
4581 
4582  qof_instance_set_dirty(&acc->inst);
4583  xaccAccountCommitEdit(acc);
4584 }
gboolean xaccAccountIsPriced(const Account *acc)
Definition: Account.c:4249
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
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 2525 of file Account.c.

2526 {
2527  AccountPrivate *ppriv, *cpriv;
2528  Account *old_parent;
2529  QofCollection *col;
2530 
2531  /* errors */
2532  g_assert(GNC_IS_ACCOUNT(new_parent));
2533  g_assert(GNC_IS_ACCOUNT(child));
2534 
2535  /* optimizations */
2536  ppriv = GET_PRIVATE(new_parent);
2537  cpriv = GET_PRIVATE(child);
2538  old_parent = cpriv->parent;
2539  if (old_parent == new_parent)
2540  return;
2541 
2542  // xaccAccountBeginEdit(new_parent);
2543  xaccAccountBeginEdit(child);
2544  if (old_parent)
2545  {
2546  gnc_account_remove_child(old_parent, child);
2547 
2548  if (!qof_instance_books_equal(old_parent, new_parent))
2549  {
2550  /* hack alert -- this implementation is not exactly correct.
2551  * If the entity tables are not identical, then the 'from' book
2552  * may have a different backend than the 'to' book. This means
2553  * that we should get the 'from' backend to destroy this account,
2554  * and the 'to' backend to save it. Right now, this is broken.
2555  *
2556  * A 'correct' implementation similar to this is in Period.c
2557  * except its for transactions ...
2558  *
2559  * Note also, we need to reparent the children to the new book as well.
2560  */
2561  PWARN ("reparenting accounts across books is not correctly supported\n");
2562 
2563  qof_event_gen (&child->inst, QOF_EVENT_DESTROY, NULL);
2565  GNC_ID_ACCOUNT);
2566  qof_collection_insert_entity (col, &child->inst);
2567  qof_event_gen (&child->inst, QOF_EVENT_CREATE, NULL);
2568  }
2569  }
2570  cpriv->parent = new_parent;
2571  ppriv->children = g_list_append(ppriv->children, child);
2572  qof_instance_set_dirty(&new_parent->inst);
2573  qof_instance_set_dirty(&child->inst);
2574 
2575  /* Send events data. Warning: The call to commit_edit is also going
2576  * to send a MODIFY event. If the gtktreemodelfilter code gets the
2577  * MODIFY before it gets the ADD, it gets very confused and thinks
2578  * that two nodes have been added. */
2579  qof_event_gen (&child->inst, QOF_EVENT_ADD, NULL);
2580  // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, NULL);
2581 
2582  xaccAccountCommitEdit (child);
2583  // xaccAccountCommitEdit(new_parent);
2584 }
QofBook * qof_instance_get_book(gconstpointer)
#define PWARN(format, args...)
Definition: qoflog.h:243
void gnc_account_remove_child(Account *parent, Account *child)
Definition: Account.c:2587
void qof_collection_insert_entity(QofCollection *, QofInstance *)
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
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 2683 of file Account.c.

2684 {
2685  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), -1);
2686  g_return_val_if_fail(GNC_IS_ACCOUNT(child), -1);
2687  return g_list_index(GET_PRIVATE(parent)->children, child);
2688 }
Account* gnc_account_create_root ( QofBook book)

Create a new root level account.

Definition at line 1097 of file Account.c.

1098 {
1099  Account *root;
1100  AccountPrivate *rpriv;
1101 
1102  root = xaccMallocAccount(book);
1103  rpriv = GET_PRIVATE(root);
1104  xaccAccountBeginEdit(root);
1105  rpriv->type = ACCT_TYPE_ROOT;
1106  CACHE_REPLACE(rpriv->accountName, "Root Account");
1107  mark_account (root);
1108  xaccAccountCommitEdit(root);
1109  gnc_book_set_root_account(book, root);
1110  return root;
1111 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
Account * xaccMallocAccount(QofBook *book)
Definition: Account.c:1083
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
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 2940 of file Account.c.

2943 {
2944  const AccountPrivate *priv;
2945  GList *node;
2946 
2947  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2948  g_return_if_fail(thunk);
2949 
2950  priv = GET_PRIVATE(acc);
2951  for (node = priv->children; node; node = node->next)
2952  {
2953  thunk (node->data, user_data);
2954  }
2955 }
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 2958 of file Account.c.

2961 {
2962  const AccountPrivate *priv;
2963  GList *node;
2964  Account *child;
2965 
2966  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2967  g_return_if_fail(thunk);
2968 
2969  priv = GET_PRIVATE(acc);
2970  for (node = priv->children; node; node = node->next)
2971  {
2972  child = node->data;
2973  thunk(child, user_data);
2974  gnc_account_foreach_descendant(child, thunk, user_data);
2975  }
2976 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
Definition: Account.c:2958
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 2979 of file Account.c.

2982 {
2983  const AccountPrivate *priv;
2984  GList *node;
2985  Account *child;
2986  gpointer result;
2987 
2988  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2989  g_return_val_if_fail(thunk, NULL);
2990 
2991  priv = GET_PRIVATE(acc);
2992  for (node = priv->children; node; node = node->next)
2993  {
2994  child = node->data;
2995  result = thunk(child, user_data);
2996  if (result)
2997  return(result);
2998 
2999  result = gnc_account_foreach_descendant_until(child, thunk, user_data);
3000  if (result)
3001  return(result);
3002  }
3003 
3004  return NULL;
3005 }
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
Definition: Account.c:2979
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 2654 of file Account.c.

2655 {
2656  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2657  return g_list_copy(GET_PRIVATE(account)->children);
2658 }
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 2661 of file Account.c.

2662 {
2663  AccountPrivate *priv;
2664 
2665  /* errors */
2666  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2667 
2668  /* optimizations */
2669  priv = GET_PRIVATE(account);
2670  if (!priv->children)
2671  return NULL;
2672  return g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
2673 }
int xaccAccountOrder(const Account *aa, const Account *ab)
Definition: Account.c:2132
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 3155 of file Account.c.

3156 {
3157  gnc_commodity * commodity;
3158  g_assert(account);
3159 
3160  commodity = xaccAccountGetCommodity (account);
3161  if (gnc_commodity_is_currency(commodity))
3162  return commodity;
3163  else
3164  {
3165  const Account *parent_account = account;
3166  /* Account commodity is not a currency, walk up the tree until
3167  * we find a parent account that is a currency account and use
3168  * it's currency.
3169  */
3170  do
3171  {
3172  parent_account = gnc_account_get_parent (parent_account);
3173  if (parent_account)
3174  {
3175  commodity = xaccAccountGetCommodity (parent_account);
3176  if (gnc_commodity_is_currency(commodity))
3177  {
3178  return commodity;
3179  //break;
3180  }
3181  }
3182  }
3183  while (parent_account);
3184  }
3185  return NULL; // no suitable commodity found.
3186 }
Account * gnc_account_get_parent(const Account *acc)
Definition: Account.c:2623
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Definition: Account.c:3148
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 2715 of file Account.c.

2716 {
2717  AccountPrivate *priv;
2718  int depth = 0;
2719 
2720  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2721 
2722  priv = GET_PRIVATE(account);
2723  while (priv->parent && (priv->type != ACCT_TYPE_ROOT))
2724  {
2725  account = priv->parent;
2726  priv = GET_PRIVATE(account);
2727  depth++;
2728  }
2729 
2730  return depth;
2731 }
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 2755 of file Account.c.

2756 {
2757  AccountPrivate *priv;
2758  GList *child, *descendants;
2759 
2760  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2761 
2762  priv = GET_PRIVATE(account);
2763  if (!priv->children)
2764  return NULL;
2765 
2766  descendants = NULL;
2767  for (child = priv->children; child; child = g_list_next(child))
2768  {
2769  descendants = g_list_append(descendants, child->data);
2770  descendants = g_list_concat(descendants,
2771  gnc_account_get_descendants(child->data));
2772  }
2773  return descendants;
2774 }
GList * gnc_account_get_descendants(const Account *account)
Definition: Account.c:2755
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 2777 of file Account.c.

2778 {
2779  AccountPrivate *priv;
2780  GList *child, *children, *descendants;
2781 
2782  /* errors */
2783  g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
2784 
2785  /* optimizations */
2786  priv = GET_PRIVATE(account);
2787  if (!priv->children)
2788  return NULL;
2789 
2790  descendants = NULL;
2791  children = g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
2792  for (child = children; child; child = g_list_next(child))
2793  {
2794  descendants = g_list_append(descendants, child->data);
2795  descendants = g_list_concat(descendants,
2796  gnc_account_get_descendants_sorted(child->data));
2797  }
2798  g_list_free(children);
2799  return descendants;
2800 }
GList * gnc_account_get_descendants_sorted(const Account *account)
Definition: Account.c:2777
int xaccAccountOrder(const Account *aa, const Account *ab)
Definition: Account.c:2132
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 3038 of file Account.c.

3039 {
3040  AccountPrivate *priv;
3041  const Account *a;
3042  char *fullname;
3043  gchar **names;
3044  int level;
3045 
3046  /* So much for hardening the API. Too many callers to this function don't
3047  * bother to check if they have a non-NULL pointer before calling. */
3048  if (NULL == account)
3049  return g_strdup("");
3050 
3051  /* errors */
3052  g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
3053 
3054  /* optimizations */
3055  priv = GET_PRIVATE(account);
3056  if (!priv->parent)
3057  return g_strdup("");
3058 
3059  /* Figure out how much space is needed by counting the nodes up to
3060  * the root. */
3061  level = 0;
3062  for (a = account; a; a = priv->parent)
3063  {
3064  priv = GET_PRIVATE(a);
3065  level++;
3066  }
3067 
3068  /* Get all the pointers in the right order. The root node "entry"
3069  * becomes the terminating NULL pointer for the array of strings. */
3070  names = g_malloc(level * sizeof(gchar *));
3071  names[--level] = NULL;
3072  for (a = account; level > 0; a = priv->parent)
3073  {
3074  priv = GET_PRIVATE(a);
3075  names[--level] = priv->accountName;
3076  }
3077 
3078  /* Build the full name */
3079  fullname = g_strjoinv(account_separator, names);
3080  g_free(names);
3081 
3082  return fullname;
3083 }
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 2623 of file Account.c.

2624 {
2625  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2626  return GET_PRIVATE(acc)->parent;
2627 }
GNCPolicy* gnc_account_get_policy ( Account account)

Get the account's lot order policy

Definition at line 1880 of file Account.c.

1881 {
1882  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
1883 
1884  return GET_PRIVATE(acc)->policy;
1885 }
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 2630 of file Account.c.

2631 {
2632  AccountPrivate *priv;
2633 
2634  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
2635 
2636  priv = GET_PRIVATE(acc);
2637  while (priv->parent)
2638  {
2639  acc = priv->parent;
2640  priv = GET_PRIVATE(acc);
2641  }
2642 
2643  return acc;
2644 }
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 specifed account itself.

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

Definition at line 2734 of file Account.c.

2735 {
2736  AccountPrivate *priv;
2737  GList *node;
2738  gint depth = 0, child_depth;
2739 
2740  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2741 
2742  priv = GET_PRIVATE(account);
2743  if (!priv->children)
2744  return 1;
2745 
2746  for (node = priv->children; node; node = g_list_next(node))
2747  {
2748  child_depth = gnc_account_get_tree_depth(node->data);
2749  depth = MAX(depth, child_depth);
2750  }
2751  return depth + 1;
2752 }
gint gnc_account_get_tree_depth(const Account *account)
Definition: Account.c:2734
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().

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

1721 {
1722  AccountPrivate *priv;
1723  GList *node;
1724 
1725  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1726  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1727 
1728  priv = GET_PRIVATE(acc);
1729  node = g_list_find(priv->splits, s);
1730  if (node)
1731  return FALSE;
1732 
1733  if (qof_instance_get_editlevel(acc) == 0)
1734  {
1735  priv->splits = g_list_insert_sorted(priv->splits, s,
1736  (GCompareFunc)xaccSplitOrder);
1737  }
1738  else
1739  {
1740  priv->splits = g_list_prepend(priv->splits, s);
1741  priv->sort_dirty = TRUE;
1742  }
1743 
1744  //FIXME: find better event
1745  qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
1746  /* Also send an event based on the account */
1747  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_ADDED, s);
1748 
1749  priv->balance_dirty = TRUE;
1750 // DRH: Should the below be added? It is present in the delete path.
1751 // xaccAccountRecomputeBalance(acc);
1752  return TRUE;
1753 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
Definition: Split.c:1521
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
#define GNC_EVENT_ITEM_ADDED
Definition: gnc-event.h:45
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 2647 of file Account.c.

2648 {
2649  g_return_val_if_fail(GNC_IS_ACCOUNT(account), FALSE);
2650  return (GET_PRIVATE(account)->parent == NULL);
2651 }
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 4739 of file Account.c.

4740 {
4741  AccountPrivate *from_priv;
4742  GList *children, *node;
4743 
4744  /* errors */
4745  g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
4746  g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
4747 
4748  /* optimizations */
4749  from_priv = GET_PRIVATE(from_parent);
4750  if (!from_priv->children)
4751  return;
4752 
4753  ENTER (" ");
4754  children = g_list_copy(from_priv->children);
4755  for (node = children; node; node = g_list_next(node))
4756  gnc_account_append_child(to_parent, node->data);
4757  g_list_free(children);
4758  LEAVE (" ");
4759 }
void gnc_account_append_child(Account *new_parent, Account *child)
Definition: Account.c:2525
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 196 of file Account.c.

197 {
198  Account *root_account = gnc_book_get_root_account(book);
199  GList *accounts, *node;
200  GList *invalid_list = NULL;
201 
202  g_return_val_if_fail (separator != NULL, NULL);
203 
204  if (root_account == NULL)
205  return NULL;
206 
207  accounts = gnc_account_get_descendants (root_account);
208  for (node = accounts; node; node = g_list_next(node))
209  {
210  Account *acct = (Account*)node->data;
211  gchar *acct_name = g_strdup ( xaccAccountGetName ( acct ) );
212 
213  if ( g_strstr_len ( acct_name, -1, separator ) )
214  invalid_list = g_list_prepend ( invalid_list, (gpointer) acct_name );
215  else
216  g_free ( acct_name );
217  }
218  if (accounts != NULL)
219  {
220  g_list_free(accounts);
221  }
222 
223  return invalid_list;
224 }
GList * gnc_account_get_descendants(const Account *account)
Definition: Account.c:2755
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:3031
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 4764 of file Account.c.

4765 {
4766  AccountPrivate *ppriv, *priv_a, *priv_b;
4767  GList *node_a, *node_b, *work, *worker;
4768 
4769  g_return_if_fail(GNC_IS_ACCOUNT(parent));
4770 
4771  ppriv = GET_PRIVATE(parent);
4772  for (node_a = ppriv->children; node_a; node_a = node_a->next)
4773  {
4774  Account *acc_a = node_a->data;
4775 
4776  priv_a = GET_PRIVATE(acc_a);
4777  for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
4778  {
4779  Account *acc_b = node_b->data;
4780 
4781  priv_b = GET_PRIVATE(acc_b);
4782  if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
4783  continue;
4784  if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
4785  continue;
4786  if (0 != null_strcmp(priv_a->description, priv_b->description))
4787  continue;
4788  if (0 != null_strcmp(xaccAccountGetColor(acc_a),
4789  xaccAccountGetColor(acc_b)))
4790  continue;
4791  if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
4792  continue;
4793  if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
4794  xaccAccountGetNotes(acc_b)))
4795  continue;
4796  if (priv_a->type != priv_b->type)
4797  continue;
4798 
4799  /* consolidate children */
4800  if (priv_b->children)
4801  {
4802  work = g_list_copy(priv_b->children);
4803  for (worker = work; worker; worker = g_list_next(worker))
4804  gnc_account_append_child (acc_a, (Account *)worker->data);
4805  g_list_free(work);
4806 
4807  qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, NULL);
4808  qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, NULL);
4809  }
4810 
4811  /* recurse to do the children's children */
4813 
4814  /* consolidate transactions */
4815  while (priv_b->splits)
4816  xaccSplitSetAccount (priv_b->splits->data, acc_a);
4817 
4818  /* move back one before removal. next iteration around the loop
4819  * will get the node after node_b */
4820  node_b = g_list_previous(node_b);
4821 
4822  /* The destroy function will remove from list -- node_a is ok,
4823  * it's before node_b */
4824  xaccAccountBeginEdit (acc_b);
4825  xaccAccountDestroy (acc_b);
4826  }
4827  }
4828 }
void gnc_account_append_child(Account *new_parent, Account *child)
Definition: Account.c:2525
void xaccAccountDestroy(Account *acc)
Definition: Account.c:1400
const char * xaccAccountGetColor(const Account *acc)
Definition: Account.c:3100
gint null_strcmp(const gchar *da, const gchar *db)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
void gnc_account_merge_children(Account *parent)
Definition: Account.c:4764
const char * xaccAccountGetNotes(const Account *acc)
Definition: Account.c:3121
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 2676 of file Account.c.

2677 {
2678  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2679  return g_list_length(GET_PRIVATE(account)->children);
2680 }
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 2698 of file Account.c.

2699 {
2700  AccountPrivate *priv;
2701  GList *node;
2702  gint count = 0;
2703 
2704  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2705 
2706  priv = GET_PRIVATE(account);
2707  for (node = priv->children; node; node = g_list_next(node))
2708  {
2709  count += gnc_account_n_descendants(node->data) + 1;
2710  }
2711  return count;
2712 }
gint gnc_account_n_descendants(const Account *account)
Definition: Account.c:2698
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 159 of file Account.c.

160 {
161  GList *node;
162  gchar *message = NULL;
163  gchar *account_list = NULL;
164 
165  if ( !invalid_account_names )
166  return NULL;
167 
168  for ( node = invalid_account_names; node; node = g_list_next(node))
169  {
170  if ( !account_list )
171  account_list = node->data;
172  else
173  {
174  gchar *tmp_list = NULL;
175 
176  tmp_list = g_strconcat (account_list, "\n", node->data, NULL );
177  g_free ( account_list );
178  account_list = tmp_list;
179  }
180  }
181 
182  /* Translators: The first %s will be the account separator character,
183  the second %s is a list of account names.
184  The resulting string will be displayed to the user if there are
185  account names containing the separator character. */
186  message = g_strdup_printf(
187  _("The separator character \"%s\" is used in one or more account names.\n\n"
188  "This will result in unexpected behaviour. "
189  "Either change the account names or choose another separator character.\n\n"
190  "Below you will find the list of invalid account names:\n"
191  "%s"), separator, account_list );
192  g_free ( account_list );
193  return message;
194 }
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 2691 of file Account.c.

2692 {
2693  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
2694  return g_list_nth_data(GET_PRIVATE(parent)->children, num);
2695 }
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 2587 of file Account.c.

2588 {
2589  AccountPrivate *ppriv, *cpriv;
2590  GncEventData ed;
2591 
2592  if (!child) return;
2593 
2594  /* Note this routine might be called on accounts which
2595  * are not yet parented. */
2596  if (!parent) return;
2597 
2598  ppriv = GET_PRIVATE(parent);
2599  cpriv = GET_PRIVATE(child);
2600 
2601  if (cpriv->parent != parent)
2602  {
2603  PERR ("account not a child of parent");
2604  return;
2605  }
2606 
2607  /* Gather event data */
2608  ed.node = parent;
2609  ed.idx = g_list_index(ppriv->children, child);
2610 
2611  ppriv->children = g_list_remove(ppriv->children, child);
2612 
2613  /* Now send the event. */
2614  qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
2615 
2616  /* clear the account's parent pointer after REMOVE event generation. */
2617  cpriv->parent = NULL;
2618 
2619  qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, NULL);
2620 }
#define PERR(format, args...)
Definition: qoflog.h:237
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
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 1756 of file Account.c.

1757 {
1758  AccountPrivate *priv;
1759  GList *node;
1760 
1761  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1762  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1763 
1764  priv = GET_PRIVATE(acc);
1765  node = g_list_find(priv->splits, s);
1766  if (NULL == node)
1767  return FALSE;
1768 
1769  priv->splits = g_list_delete_link(priv->splits, node);
1770  //FIXME: find better event type
1771  qof_event_gen(&acc->inst, QOF_EVENT_MODIFY, NULL);
1772  // And send the account-based event, too
1773  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_REMOVED, s);
1774 
1775  priv->balance_dirty = TRUE;
1777  return TRUE;
1778 }
void xaccAccountRecomputeBalance(Account *acc)
Definition: Account.c:2058
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
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 1703 of file Account.c.

1704 {
1705  AccountPrivate *priv;
1706 
1707  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1708 
1709  if (qof_instance_get_destroying(acc))
1710  return;
1711 
1712  priv = GET_PRIVATE(acc);
1713  priv->balance_dirty = TRUE;
1714 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
void gnc_account_set_policy ( Account account,
GNCPolicy policy 
)

Set the account's lot order policy

Definition at line 1888 of file Account.c.

1889 {
1890  AccountPrivate *priv;
1891 
1892  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1893 
1894  priv = GET_PRIVATE(acc);
1895  priv->policy = policy ? policy : xaccGetFIFOPolicy();
1896 }
GNCPolicy * xaccGetFIFOPolicy(void)
Definition: policy.c:178
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 1689 of file Account.c.

1690 {
1691  AccountPrivate *priv;
1692 
1693  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1694 
1695  if (qof_instance_get_destroying(acc))
1696  return;
1697 
1698  priv = GET_PRIVATE(acc);
1699  priv->sort_dirty = TRUE;
1700 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
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 3191 of file Account.c.

3192 {
3193  AccountPrivate *priv;
3194 
3195  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3196 
3197  priv = GET_PRIVATE(acc);
3198  priv->starting_balance = start_baln;
3199  priv->balance_dirty = TRUE;
3200 }
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 3203 of file Account.c.

3205 {
3206  AccountPrivate *priv;
3207 
3208  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3209 
3210  priv = GET_PRIVATE(acc);
3211  priv->starting_cleared_balance = start_baln;
3212  priv->balance_dirty = TRUE;
3213 }
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 3216 of file Account.c.

3218 {
3219  AccountPrivate *priv;
3220 
3221  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3222 
3223  priv = GET_PRIVATE(acc);
3224  priv->starting_reconciled_balance = start_baln;
3225  priv->balance_dirty = TRUE;
3226 }
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 129 of file Account.c.

130 {
131  return account_separator;
132 }
void xaccAccountBeginEdit ( Account account)

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

Definition at line 1280 of file Account.c.

1281 {
1282  g_return_if_fail(acc);
1283  qof_begin_edit(&acc->inst);
1284 }
gboolean qof_begin_edit(QofInstance *inst)
void xaccAccountCommitEdit ( Account account)

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

Definition at line 1321 of file Account.c.

1322 {
1323  AccountPrivate *priv;
1324  QofBook *book;
1325 
1326  g_return_if_fail(acc);
1327  if (!qof_commit_edit(&acc->inst)) return;
1328 
1329  /* If marked for deletion, get rid of subaccounts first,
1330  * and then the splits ... */
1331  priv = GET_PRIVATE(acc);
1332  if (qof_instance_get_destroying(acc))
1333  {
1334  GList *lp, *slist;
1335  QofCollection *col;
1336 
1337  qof_instance_increase_editlevel(acc);
1338 
1339  /* First, recursively free children */
1340  xaccFreeAccountChildren(acc);
1341 
1342  PINFO ("freeing splits for account %p (%s)",
1343  acc, priv->accountName ? priv->accountName : "(null)");
1344 
1345  book = qof_instance_get_book(acc);
1346 
1347  /* If book is shutting down, just clear the split list. The splits
1348  themselves will be destroyed by the transaction code */
1349  if (!qof_book_shutting_down(book))
1350  {
1351  slist = g_list_copy(priv->splits);
1352  for (lp = slist; lp; lp = lp->next)
1353  {
1354  Split *s = lp->data;
1355  xaccSplitDestroy (s);
1356  }
1357  g_list_free(slist);
1358  }
1359  else
1360  {
1361  g_list_free(priv->splits);
1362  priv->splits = NULL;
1363  }
1364 
1365  /* It turns out there's a case where this assertion does not hold:
1366  When the user tries to delete an Imbalance account, while also
1367  deleting all the splits in it. The splits will just get
1368  recreated and put right back into the same account!
1369 
1370  g_assert(priv->splits == NULL || qof_book_shutting_down(acc->inst.book));
1371  */
1372 
1373  if (!qof_book_shutting_down(book))
1374  {
1375  col = qof_book_get_collection(book, GNC_ID_TRANS);
1376  qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
1377 
1378  /* the lots should be empty by now */
1379  for (lp = priv->lots; lp; lp = lp->next)
1380  {
1381  GNCLot *lot = lp->data;
1382  gnc_lot_destroy (lot);
1383  }
1384  }
1385  g_list_free(priv->lots);
1386  priv->lots = NULL;
1387 
1388  qof_instance_set_dirty(&acc->inst);
1389  qof_instance_decrease_editlevel(acc);
1390  }
1391  else
1392  {
1393  xaccAccountBringUpToDate(acc);
1394  }
1395 
1396  qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
1397 }
QofBook * qof_instance_get_book(gconstpointer)
#define PINFO(format, args...)
Definition: qoflog.h:249
gboolean xaccSplitDestroy(Split *split)
Definition: Split.c:1492
gboolean qof_instance_get_destroying(gconstpointer ptr)
gboolean qof_commit_edit(QofInstance *inst)
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
Definition: SplitP.h:71
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
gboolean qof_book_shutting_down(const QofBook *book)
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 1400 of file Account.c.

1401 {
1402  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1403 
1404  qof_instance_set_destroying(acc, TRUE);
1405 
1406  xaccAccountCommitEdit (acc);
1407 }
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
gboolean xaccAccountEqual ( const Account a,
const Account b,
gboolean  check_guids 
)

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

Definition at line 1475 of file Account.c.

1476 {
1477  AccountPrivate *priv_aa, *priv_ab;
1478 
1479  if (!aa && !ab) return TRUE;
1480 
1481  g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
1482  g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
1483 
1484  priv_aa = GET_PRIVATE(aa);
1485  priv_ab = GET_PRIVATE(ab);
1486  if (priv_aa->type != priv_ab->type)
1487  {
1488  PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
1489  return FALSE;
1490  }
1491 
1492  if (g_strcmp0(priv_aa->accountName, priv_ab->accountName) != 0)
1493  {
1494  PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
1495  return FALSE;
1496  }
1497 
1498  if (g_strcmp0(priv_aa->accountCode, priv_ab->accountCode) != 0)
1499  {
1500  PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
1501  return FALSE;
1502  }
1503 
1504  if (g_strcmp0(priv_aa->description, priv_ab->description) != 0)
1505  {
1506  PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
1507  return FALSE;
1508  }
1509 
1510  if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
1511  {
1512  PWARN ("commodities differ");
1513  return FALSE;
1514  }
1515 
1516  if (check_guids)
1517  {
1518  if (qof_instance_guid_compare(aa, ab) != 0)
1519  {
1520  PWARN ("GUIDs differ");
1521  return FALSE;
1522  }
1523  }
1524 
1525  if (kvp_frame_compare(aa->inst.kvp_data, ab->inst.kvp_data) != 0)
1526  {
1527  char *frame_a;
1528  char *frame_b;
1529 
1530  frame_a = kvp_frame_to_string (aa->inst.kvp_data);
1531  frame_b = kvp_frame_to_string (ab->inst.kvp_data);
1532 
1533  PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
1534 
1535  g_free (frame_a);
1536  g_free (frame_b);
1537 
1538  return FALSE;
1539  }
1540 
1541  if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
1542  {
1543  char *str_a;
1544  char *str_b;
1545 
1546  str_a = gnc_numeric_to_string(priv_aa->starting_balance);
1547  str_b = gnc_numeric_to_string(priv_ab->starting_balance);
1548 
1549  PWARN ("starting balances differ: %s vs %s", str_a, str_b);
1550 
1551  g_free (str_a);
1552  g_free (str_b);
1553 
1554  return FALSE;
1555  }
1556 
1557  if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
1558  priv_ab->starting_cleared_balance))
1559  {
1560  char *str_a;
1561  char *str_b;
1562 
1563  str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
1564  str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
1565 
1566  PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
1567 
1568  g_free (str_a);
1569  g_free (str_b);
1570 
1571  return FALSE;
1572  }
1573 
1574  if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
1575  priv_ab->starting_reconciled_balance))
1576  {
1577  char *str_a;
1578  char *str_b;
1579 
1580  str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
1581  str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
1582 
1583  PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
1584 
1585  g_free (str_a);
1586  g_free (str_b);
1587 
1588  return FALSE;
1589  }
1590 
1591  if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
1592  {
1593  char *str_a;
1594  char *str_b;
1595 
1596  str_a = gnc_numeric_to_string(priv_aa->balance);
1597  str_b = gnc_numeric_to_string(priv_ab->balance);
1598 
1599  PWARN ("balances differ: %s vs %s", str_a, str_b);
1600 
1601  g_free (str_a);
1602  g_free (str_b);
1603 
1604  return FALSE;
1605  }
1606 
1607  if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
1608  {
1609  char *str_a;
1610  char *str_b;
1611 
1612  str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
1613  str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
1614 
1615  PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
1616 
1617  g_free (str_a);
1618  g_free (str_b);
1619 
1620  return FALSE;
1621  }
1622 
1623  if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
1624  {
1625  char *str_a;
1626  char *str_b;
1627 
1628  str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
1629  str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
1630 
1631  PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
1632 
1633  g_free (str_a);
1634  g_free (str_b);
1635 
1636  return FALSE;
1637  }
1638 
1639  /* no parent; always compare downwards. */
1640 
1641  {
1642  GList *la = priv_aa->splits;
1643  GList *lb = priv_ab->splits;
1644 
1645  if ((la && !lb) || (!la && lb))
1646  {
1647  PWARN ("only one has splits");
1648  return FALSE;
1649  }
1650 
1651  if (la && lb)
1652  {
1653  /* presume that the splits are in the same order */
1654  while (la && lb)
1655  {
1656  Split *sa = (Split *) la->data;
1657  Split *sb = (Split *) lb->data;
1658 
1659  if (!xaccSplitEqual(sa, sb, check_guids, TRUE, FALSE))
1660  {
1661  PWARN ("splits differ");
1662  return(FALSE);
1663  }
1664 
1665  la = la->next;
1666  lb = lb->next;
1667  }
1668 
1669  if ((la != NULL) || (lb != NULL))
1670  {
1671  PWARN ("number of splits differs");
1672  return(FALSE);
1673  }
1674  }
1675  }
1676 
1677  if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
1678  {
1679  PWARN ("children differ");
1680  return FALSE;
1681  }
1682 
1683  return(TRUE);
1684 }
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
gchar * gnc_numeric_to_string(gnc_numeric n)
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Definition: Split.c:815
#define PWARN(format, args...)
Definition: qoflog.h:243
gchar * kvp_frame_to_string(const KvpFrame *frame)
Definition: SplitP.h:71
gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr2)
Account* xaccAccountGainsAccount ( Account acc,
gnc_commodity curr 
)

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

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

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

Definition at line 4537 of file Account.c.

4538 {
4539  KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (acc));
4540  const gchar *curr_name = gnc_commodity_get_unique_name (curr);
4541  GncGUID *guid;
4542  Account *gains_account;
4543 
4544  frame = kvp_frame_get_frame_slash (frame, "/lot-mgmt/gains-act/");
4545  guid = kvp_frame_get_guid (frame, curr_name);
4546  if (guid == NULL) /* No gains account for this currency */
4547  {
4548  gains_account = GetOrMakeOrphanAccount (gnc_account_get_root (acc),
4549  curr);
4550  guid = (GncGUID*)qof_instance_get_guid (QOF_INSTANCE (gains_account));
4551  xaccAccountBeginEdit (acc);
4552  {
4553  kvp_frame_set_guid (frame, curr_name, guid);
4554  qof_instance_set_dirty (QOF_INSTANCE (acc));
4555  }
4556  xaccAccountCommitEdit (acc);
4557  }
4558  else
4559  gains_account = xaccAccountLookup (guid,
4560  qof_instance_get_book(acc));
4561 
4562  return gains_account;
4563 }
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
Definition: guid.h:65
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
struct KvpFrameImpl KvpFrame
Definition: kvp_frame.h:76
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Account * gnc_account_get_root(Account *acc)
Definition: Account.c:2630
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
Definition: Account.c:1827
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 4441 of file Account.c.

4442 {
4443  const char *str = NULL;
4444  if (!acc) return default_value;
4445 
4446  str = kvp_frame_get_string(acc->inst.kvp_data,
4447  "reconcile-info/auto-interest-transfer");
4448  return str ? !strcmp(str, "true") : default_value;
4449 }
gnc_numeric xaccAccountGetBalance ( const Account account)

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

Definition at line 3229 of file Account.c.

3230 {
3231  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3232  return GET_PRIVATE(acc)->balance;
3233 }
gnc_numeric xaccAccountGetBalanceAsOfDate ( Account account,
time64  date 
)

Get the balance of the account as of the date specified

Definition at line 3288 of file Account.c.

3289 {
3290  /* Ideally this could use xaccAccountForEachSplit, but
3291  * it doesn't exist yet and I'm uncertain of exactly how
3292  * it would work at this time, since it differs from
3293  * xaccAccountForEachTransaction by using gpointer return
3294  * values rather than gints.
3295  */
3296  AccountPrivate *priv;
3297  GList *lp;
3298  Timespec ts, trans_ts;
3299  gboolean found = FALSE;
3300  gnc_numeric balance;
3301 
3302  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3303 
3304  xaccAccountSortSplits (acc, TRUE); /* just in case, normally a noop */
3305  xaccAccountRecomputeBalance (acc); /* just in case, normally a noop */
3306 
3307  priv = GET_PRIVATE(acc);
3308  balance = priv->balance;
3309 
3310  /* Since transaction post times are stored as a Timespec,
3311  * convert date into a Timespec as well rather than converting
3312  * each transaction's Timespec into a time64.
3313  *
3314  * FIXME: CAS: I think this comment is a bogus justification for
3315  * using xaccTransGetDatePostedTS. There's no benefit to using
3316  * Timespec when the input argument is time64, and it's hard to
3317  * imagine that casting long long to long and comparing two longs is
3318  * worse than comparing two long longs every time. IMO,
3319  * xaccAccountGetPresentBalance gets this right, and its algorithm
3320  * should be used here.
3321  */
3322  ts.tv_sec = date;
3323  ts.tv_nsec = 0;
3324 
3325  lp = priv->splits;
3326  while ( lp && !found )
3327  {
3329  &trans_ts );
3330  if ( timespec_cmp( &trans_ts, &ts ) >= 0 )
3331  found = TRUE;
3332  else
3333  lp = lp->next;
3334  }
3335 
3336  if ( lp )
3337  {
3338  if ( lp->prev )
3339  {
3340  /* Since lp is now pointing to a split which was past the reconcile
3341  * date, get the running balance of the previous split.
3342  */
3343  balance = xaccSplitGetBalance( (Split *)lp->prev->data );
3344  }
3345  else
3346  {
3347  /* AsOf date must be before any entries, return zero. */
3348  balance = gnc_numeric_zero();
3349  }
3350  }
3351 
3352  /* Otherwise there were no splits posted after the given date,
3353  * so the latest account balance should be good enough.
3354  */
3355 
3356  return( balance );
3357 }
void xaccAccountSortSplits(Account *acc, gboolean force)
Definition: Account.c:1781
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
Transaction * xaccSplitGetParent(const Split *split)
Definition: Split.c:1903
gnc_numeric xaccSplitGetBalance(const Split *s)
Definition: Split.c:1323
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
void xaccAccountRecomputeBalance(Account *acc)
Definition: Account.c:2058
Definition: SplitP.h:71
void xaccTransGetDatePostedTS(const Transaction *trans, Timespec *ts)
Definition: Transaction.c:2229
gnc_numeric xaccAccountGetClearedBalance ( const Account account)

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

Definition at line 3236 of file Account.c.

3237 {
3238  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3239  return GET_PRIVATE(acc)->cleared_balance;
3240 }
const char* xaccAccountGetCode ( const Account account)

Get the account's accounting code

Definition at line 3086 of file Account.c.

3087 {
3088  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3089  return GET_PRIVATE(acc)->accountCode;
3090 }
const char* xaccAccountGetColor ( const Account account)

Get the account's color

Definition at line 3100 of file Account.c.

3101 {
3102  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3103  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "color") : NULL;
3104 }
gnc_commodity* xaccAccountGetCommodity ( const Account account)

Get the account's commodity

Definition at line 3148 of file Account.c.

3149 {
3150  if (!GNC_IS_ACCOUNT(acc))
3151  return NULL;
3152  return GET_PRIVATE(acc)->commodity;
3153 }
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 2458 of file Account.c.

2459 {
2460  AccountPrivate *priv;
2461 
2462  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2463 
2464  priv = GET_PRIVATE(acc);
2465  if (priv->non_standard_scu || !priv->commodity)
2466  return priv->commodity_scu;
2467  return gnc_commodity_get_fraction(priv->commodity);
2468 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
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 2451 of file Account.c.

2452 {
2453  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2454  return GET_PRIVATE(acc)->commodity_scu;
2455 }
const char* xaccAccountGetDescription ( const Account account)

Get the account's description

Definition at line 3093 of file Account.c.

3094 {
3095  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3096  return GET_PRIVATE(acc)->description;
3097 }
const char* xaccAccountGetFilter ( const Account account)

Get the account's filter

Definition at line 3107 of file Account.c.

3108 {
3109  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
3110  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "filter") : NULL;
3111 }
const char* xaccAccountGetLastNum ( const Account account)

Get the last num field of an Account

Definition at line 4472 of file Account.c.

4473 {
4474  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "last-num") : NULL;
4475 }
const char* xaccAccountGetName ( const Account account)

Get the account's name

Definition at line 3031 of file Account.c.

3032 {
3033  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3034  return GET_PRIVATE(acc)->accountName;
3035 }
gboolean xaccAccountGetNonStdSCU ( const Account account)

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

Definition at line 2487 of file Account.c.

2488 {
2489  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2490  return GET_PRIVATE(acc)->non_standard_scu;
2491 }
const char* xaccAccountGetNotes ( const Account account)

Get the account's notes

Definition at line 3121 of file Account.c.

3122 {
3123  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
3124  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "notes") : NULL;
3125 }
gboolean xaccAccountGetReconcileChildrenStatus ( const Account account)

DOCUMENT ME!

Definition at line 4660 of file Account.c.

4661 {
4662  /* access the account's kvp-data for status and return that, if no value
4663  * is found then we can assume not to include the children, that being
4664  * the default behaviour
4665  */
4666  return acc ? kvp_frame_get_gint64(acc->inst.kvp_data,
4667  "reconcile-info/include-children") : FALSE;
4668 }
gnc_numeric xaccAccountGetReconciledBalance ( const Account account)

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

Definition at line 3243 of file Account.c.

3244 {
3245  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
3246  return GET_PRIVATE(acc)->reconciled_balance;
3247 }
const char* xaccAccountGetSortOrder ( const Account account)

Get the account's Sort Order

Definition at line 3114 of file Account.c.

3115 {
3116  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
3117  return acc ? kvp_frame_get_string(acc->inst.kvp_data, "sort-order") : NULL;
3118 }
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 3009 of file Account.c.

3010 {
3011  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), ACCT_TYPE_NONE);
3012  return GET_PRIVATE(acc)->type;
3013 }
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 4004 of file Account.c.

4005 {
4006  const Account *parent;
4007 
4008  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4009  g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
4010 
4011  parent = acc;
4012  while (parent && parent != ancestor)
4013  parent = GET_PRIVATE(parent)->parent;
4014 
4015  return (parent == ancestor);
4016 }
gboolean xaccAccountIsPriced ( const Account acc)

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

Definition at line 4249 of file Account.c.

4250 {
4251  AccountPrivate *priv;
4252 
4253  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4254 
4255  priv = GET_PRIVATE(acc);
4256  return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
4257  priv->type == ACCT_TYPE_CURRENCY);
4258 }
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 1827 of file Account.c.

1828 {
1829  QofCollection *col;
1830  if (!guid || !book) return NULL;
1831  col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
1832  return (Account *) qof_collection_lookup_entity (col, guid);
1833 }
QofInstance * qof_collection_lookup_entity(const QofCollection *, const GncGUID *)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
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 2132 of file Account.c.

2133 {
2134  AccountPrivate *priv_aa, *priv_ab;
2135  char *da, *db;
2136  char *endptr = NULL;
2137  int ta, tb, result;
2138  long la, lb;
2139 
2140  if ( aa && !ab ) return -1;
2141  if ( !aa && ab ) return +1;
2142  if ( !aa && !ab ) return 0;
2143 
2144  priv_aa = GET_PRIVATE(aa);
2145  priv_ab = GET_PRIVATE(ab);
2146 
2147  /* sort on accountCode strings */
2148  da = priv_aa->accountCode;
2149  db = priv_ab->accountCode;
2150 
2151  /* If accountCodes are both base 36 integers do an integer sort */
2152  la = strtoul (da, &endptr, 36);
2153  if ((*da != '\0') && (*endptr == '\0'))
2154  {
2155  lb = strtoul (db, &endptr, 36);
2156  if ((*db != '\0') && (*endptr == '\0'))
2157  {
2158  if (la < lb) return -1;
2159  if (la > lb) return +1;
2160  }
2161  }
2162 
2163  /* Otherwise do a string sort */
2164  result = g_strcmp0 (da, db);
2165  if (result)
2166  return result;
2167 
2168  /* if account-type-order array not initialized, initialize it */
2169  /* this will happen at most once during program invocation */
2170  if (-1 == revorder[0])
2171  {
2172  int i;
2173  for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
2174  {
2175  revorder [typeorder[i]] = i;
2176  }
2177  }
2178 
2179  /* otherwise, sort on account type */
2180  ta = priv_aa->type;
2181  tb = priv_ab->type;
2182  ta = revorder[ta];
2183  tb = revorder[tb];
2184  if (ta < tb) return -1;
2185  if (ta > tb) return +1;
2186 
2187  /* otherwise, sort on accountName strings */
2188  da = priv_aa->accountName;
2189  db = priv_ab->accountName;
2190  result = safe_utf8_collate(da, db);
2191  if (result)
2192  return result;
2193 
2194  /* guarantee a stable sort */
2195  return qof_instance_guid_compare(aa, ab);
2196 }
int safe_utf8_collate(const char *da, const char *db)
gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr2)
void xaccAccountRecomputeBalance ( Account )

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

Definition at line 2058 of file Account.c.

2059 {
2060  AccountPrivate *priv;
2061  gnc_numeric balance;
2062  gnc_numeric cleared_balance;
2063  gnc_numeric reconciled_balance;
2064  GList *lp;
2065 
2066  if (NULL == acc) return;
2067 
2068  priv = GET_PRIVATE(acc);
2069  if (qof_instance_get_editlevel(acc) > 0) return;
2070  if (!priv->balance_dirty) return;
2071  if (qof_instance_get_destroying(acc)) return;
2073 
2074  balance = priv->starting_balance;
2075  cleared_balance = priv->starting_cleared_balance;
2076  reconciled_balance = priv->starting_reconciled_balance;
2077 
2078  PINFO ("acct=%s starting baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
2079  priv->accountName, balance.num, balance.denom);
2080  for (lp = priv->splits; lp; lp = lp->next)
2081  {
2082  Split *split = (Split *) lp->data;
2083  gnc_numeric amt = xaccSplitGetAmount (split);
2084 
2085  balance = gnc_numeric_add_fixed(balance, amt);
2086 
2087  if (NREC != split->reconciled)
2088  {
2089  cleared_balance = gnc_numeric_add_fixed(cleared_balance, amt);
2090  }
2091 
2092  if (YREC == split->reconciled ||
2093  FREC == split->reconciled)
2094  {
2095  reconciled_balance =
2096  gnc_numeric_add_fixed(reconciled_balance, amt);
2097  }
2098 
2099  split->balance = balance;
2100  split->cleared_balance = cleared_balance;
2101  split->reconciled_balance = reconciled_balance;
2102 
2103  }
2104 
2105  priv->balance = balance;
2106  priv->cleared_balance = cleared_balance;
2107  priv->reconciled_balance = reconciled_balance;
2108  priv->balance_dirty = FALSE;
2109 }
QofBook * qof_instance_get_book(gconstpointer)
#define PINFO(format, args...)
Definition: qoflog.h:249
gboolean qof_instance_get_destroying(gconstpointer ptr)
#define YREC
Definition: Split.h:68
#define FREC
Definition: Split.h:69
Definition: SplitP.h:71
gboolean qof_book_shutting_down(const QofBook *book)
#define NREC
Definition: Split.h:70
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1987
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 4455 of file Account.c.

4456 {
4457  if (!acc) return;
4458 
4459  xaccAccountBeginEdit (acc);
4460  /* FIXME: need KVP_TYPE_BOOLEAN for this someday */
4461  kvp_frame_set_string (acc->inst.kvp_data,
4462  "/reconcile-info/auto-interest-transfer",
4463  (option ? "true" : "false"));
4464  mark_account (acc);
4465  xaccAccountCommitEdit (acc);
4466 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
void xaccAccountSetCode ( Account account,
const char *  code 
)

Set the account's accounting code

Definition at line 2249 of file Account.c.

2250 {
2251  AccountPrivate *priv;
2252 
2253  /* errors */
2254  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2255 
2256  /* optimizations */
2257  priv = GET_PRIVATE(acc);
2258  if (g_strcmp0(str, priv->accountCode) == 0)
2259  return;
2260 
2261  xaccAccountBeginEdit(acc);
2262  CACHE_REPLACE(priv->accountCode, str ? str : "");
2263  mark_account (acc);
2264  xaccAccountCommitEdit(acc);
2265 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetColor ( Account account,
const char *  color 
)

Set the account's Color

Definition at line 2287 of file Account.c.

2288 {
2289  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2290 
2291  xaccAccountBeginEdit(acc);
2292  if (str)
2293  {
2294  gchar *tmp = g_strstrip(g_strdup(str));
2295  kvp_frame_set_slot_nc(acc->inst.kvp_data, "color",
2296  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2297  g_free(tmp);
2298  }
2299  else
2300  {
2301  kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", NULL);
2302  }
2303  mark_account (acc);
2304  xaccAccountCommitEdit(acc);
2305 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetCommodity ( Account account,
gnc_commodity comm 
)

Set the account's commodity

Definition at line 2389 of file Account.c.

2390 {
2391  AccountPrivate *priv;
2392  GList *lp;
2393 
2394  /* errors */
2395  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2396  g_return_if_fail(GNC_IS_COMMODITY(com));
2397 
2398  /* optimizations */
2399  priv = GET_PRIVATE(acc);
2400  if (com == priv->commodity)
2401  return;
2402 
2403  xaccAccountBeginEdit(acc);
2404  gnc_commodity_decrement_usage_count(priv->commodity);
2405  priv->commodity = com;
2407  priv->commodity_scu = gnc_commodity_get_fraction(com);
2408  priv->non_standard_scu = FALSE;
2409 
2410  /* iterate over splits */
2411  for (lp = priv->splits; lp; lp = lp->next)
2412  {
2413  Split *s = (Split *) lp->data;
2414  Transaction *trans = xaccSplitGetParent (s);
2415 
2416  xaccTransBeginEdit (trans);
2418  xaccTransCommitEdit (trans);
2419  }
2420 
2421  priv->sort_dirty = TRUE; /* Not needed. */
2422  priv->balance_dirty = TRUE;
2423  mark_account (acc);
2424 
2425  xaccAccountCommitEdit(acc);
2426 }
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:1903
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
Definition: Split.c:1258
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
void xaccTransCommitEdit(Transaction *trans)
Definition: Transaction.c:1579
void xaccTransBeginEdit(Transaction *trans)
Definition: Transaction.c:1380
Definition: SplitP.h:71
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1987
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 2435 of file Account.c.

2436 {
2437  AccountPrivate *priv;
2438 
2439  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2440 
2441  priv = GET_PRIVATE(acc);
2442  xaccAccountBeginEdit(acc);
2443  priv->commodity_scu = scu;
2444  if (scu != gnc_commodity_get_fraction(priv->commodity))
2445  priv->non_standard_scu = TRUE;
2446  mark_account(acc);
2447  xaccAccountCommitEdit(acc);
2448 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetDescription ( Account account,
const char *  desc 
)

Set the account's description

Definition at line 2268 of file Account.c.

2269 {
2270  AccountPrivate *priv;
2271 
2272  /* errors */
2273  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2274 
2275  /* optimizations */
2276  priv = GET_PRIVATE(acc);
2277  if (g_strcmp0(str, priv->description) == 0)
2278  return;
2279 
2280  xaccAccountBeginEdit(acc);
2281  CACHE_REPLACE(priv->description, str ? str : "");
2282  mark_account (acc);
2283  xaccAccountCommitEdit(acc);
2284 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetFilter ( Account account,
const char *  filter 
)

Set the account's Filter

Definition at line 2308 of file Account.c.

2309 {
2310  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2311 
2312  xaccAccountBeginEdit(acc);
2313  if (str)
2314  {
2315  gchar *tmp = g_strstrip(g_strdup(str));
2316  kvp_frame_set_slot_nc(acc->inst.kvp_data, "filter",
2317  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2318  g_free(tmp);
2319  }
2320  else
2321  {
2322  kvp_frame_set_slot_nc(acc->inst.kvp_data, "filter", NULL);
2323  }
2324  mark_account (acc);
2325  xaccAccountCommitEdit(acc);
2326 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetLastNum ( Account account,
const char *  num 
)

Set the last num field of an Account

Definition at line 4481 of file Account.c.

4482 {
4483  if (!acc) return;
4484 
4485  xaccAccountBeginEdit (acc);
4486  kvp_frame_set_string(acc->inst.kvp_data, "last-num", num);
4487  mark_account (acc);
4488  xaccAccountCommitEdit (acc);
4489 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
void xaccAccountSetName ( Account account,
const char *  name 
)

Set the account's name

Definition at line 2229 of file Account.c.

2230 {
2231  AccountPrivate *priv;
2232 
2233  /* errors */
2234  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2235  g_return_if_fail(str);
2236 
2237  /* optimizations */
2238  priv = GET_PRIVATE(acc);
2239  if (g_strcmp0(str, priv->accountName) == 0)
2240  return;
2241 
2242  xaccAccountBeginEdit(acc);
2243  CACHE_REPLACE(priv->accountName, str);
2244  mark_account (acc);
2245  xaccAccountCommitEdit(acc);
2246 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetNonStdSCU ( Account account,
gboolean  flag 
)

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

Definition at line 2471 of file Account.c.

2472 {
2473  AccountPrivate *priv;
2474 
2475  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2476 
2477  priv = GET_PRIVATE(acc);
2478  if (priv->non_standard_scu == flag)
2479  return;
2480  xaccAccountBeginEdit(acc);
2481  priv->non_standard_scu = flag;
2482  mark_account (acc);
2483  xaccAccountCommitEdit(acc);
2484 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetNotes ( Account account,
const char *  notes 
)

Set the account's notes

Definition at line 2368 of file Account.c.

2369 {
2370  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2371 
2372  xaccAccountBeginEdit(acc);
2373  if (str)
2374  {
2375  gchar *tmp = g_strstrip(g_strdup(str));
2376  kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes",
2377  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2378  g_free(tmp);
2379  }
2380  else
2381  {
2382  kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes", NULL);
2383  }
2384  mark_account(acc);
2385  xaccAccountCommitEdit(acc);
2386 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetReconcileChildrenStatus ( Account account,
gboolean  status 
)

DOCUMENT ME!

Definition at line 4643 of file Account.c.

4644 {
4645  if (!acc) return;
4646 
4647  xaccAccountBeginEdit (acc);
4648 
4649  /* XXX FIXME: someday this should use KVP_TYPE_BOOLEAN */
4650  kvp_frame_set_gint64 (acc->inst.kvp_data,
4651  "/reconcile-info/include-children", status);
4652  mark_account(acc);
4653  xaccAccountCommitEdit (acc);
4654 }
void kvp_frame_set_gint64(KvpFrame *frame, const gchar *path, gint64 ival)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetSortOrder ( Account account,
const char *  sortorder 
)

Set the account's Sort Order

Definition at line 2329 of file Account.c.

2330 {
2331  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2332 
2333  xaccAccountBeginEdit(acc);
2334  if (str)
2335  {
2336  gchar *tmp = g_strstrip(g_strdup(str));
2337  kvp_frame_set_slot_nc(acc->inst.kvp_data, "sort-order",
2338  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
2339  g_free(tmp);
2340  }
2341  else
2342  {
2343  kvp_frame_set_slot_nc(acc->inst.kvp_data, "sort-order", NULL);
2344  }
2345  mark_account (acc);
2346  xaccAccountCommitEdit(acc);
2347 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
void xaccAccountSetType ( Account account,
GNCAccountType   
)

Set the account's type

Definition at line 2208 of file Account.c.

2209 {
2210  AccountPrivate *priv;
2211 
2212  /* errors */
2213  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2214  g_return_if_fail(tip < NUM_ACCOUNT_TYPES);
2215 
2216  /* optimizations */
2217  priv = GET_PRIVATE(acc);
2218  if (priv->type == tip)
2219  return;
2220 
2221  xaccAccountBeginEdit(acc);
2222  priv->type = tip;
2223  priv->balance_dirty = TRUE; /* new type may affect balance computation */
2224  mark_account(acc);
2225  xaccAccountCommitEdit(acc);
2226 }
void xaccAccountBeginEdit(Account *acc)
Definition: Account.c:1280
void xaccAccountCommitEdit(Account *acc)
Definition: Account.c:1321
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 1781 of file Account.c.

1782 {
1783  AccountPrivate *priv;
1784 
1785  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1786 
1787  priv = GET_PRIVATE(acc);
1788  if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
1789  return;
1790  priv->splits = g_list_sort(priv->splits, (GCompareFunc)xaccSplitOrder);
1791  priv->sort_dirty = FALSE;
1792  priv->balance_dirty = TRUE;
1793 }
gint xaccSplitOrder(const Split *sa, const Split *sb)
Definition: Split.c:1521
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 1114 of file Account.c.

1115 {
1116  Account *ret;
1117  AccountPrivate *from_priv, *priv;
1118 
1119  g_return_val_if_fail(GNC_IS_ACCOUNT(from), NULL);
1120  g_return_val_if_fail(QOF_IS_BOOK(book), NULL);
1121 
1122  ENTER (" ");
1123  ret = g_object_new (GNC_TYPE_ACCOUNT, NULL);
1124  g_return_val_if_fail (ret, NULL);
1125 
1126  from_priv = GET_PRIVATE(from);
1127  priv = GET_PRIVATE(ret);
1128  xaccInitAccount (ret, book);
1129 
1130  /* Do not Begin/CommitEdit() here; give the caller
1131  * a chance to fix things up, and let them do it.
1132  * Also let caller issue the generate_event (EVENT_CREATE) */
1133  priv->type = from_priv->type;
1134 
1135  priv->accountName = CACHE_INSERT(from_priv->accountName);
1136  priv->accountCode = CACHE_INSERT(from_priv->accountCode);
1137  priv->description = CACHE_INSERT(from_priv->description);
1138 
1139  kvp_frame_delete(ret->inst.kvp_data);
1140  ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
1141 
1142  /* The new book should contain a commodity that matches
1143  * the one in the old book. Find it, use it. */
1144  priv->commodity = gnc_commodity_obtain_twin(from_priv->commodity, book);
1145  gnc_commodity_increment_usage_count(priv->commodity);
1146 
1147  priv->commodity_scu = from_priv->commodity_scu;
1148  priv->non_standard_scu = from_priv->non_standard_scu;
1149 
1150  qof_instance_set_dirty(&ret->inst);
1151  LEAVE (" ");
1152  return ret;
1153 }
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
#define ENTER(format, args...)
Definition: qoflog.h:261
void kvp_frame_delete(KvpFrame *frame)
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
#define LEAVE(format, args...)
Definition: qoflog.h:271
gnc_commodity * gnc_commodity_obtain_twin(const gnc_commodity *from, QofBook *book)
Account* xaccMallocAccount ( QofBook book)

Constructor

Definition at line 1083 of file Account.c.

1084 {
1085  Account *acc;
1086 
1087  g_return_val_if_fail (book, NULL);
1088 
1089  acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
1090  xaccInitAccount (acc, book);
1091  qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL);
1092 
1093  return acc;
1094 }
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.