GnuCash 2.4.99
Account.h
Go to the documentation of this file.
00001 /********************************************************************\
00002  * This program is free software; you can redistribute it and/or    *
00003  * modify it under the terms of the GNU General Public License as   *
00004  * published by the Free Software Foundation; either version 2 of   *
00005  * the License, or (at your option) any later version.              *
00006  *                                                                  *
00007  * This program is distributed in the hope that it will be useful,  *
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00010  * GNU General Public License for more details.                     *
00011  *                                                                  *
00012  * You should have received a copy of the GNU General Public License*
00013  * along with this program; if not, contact:                        *
00014  *                                                                  *
00015  * Free Software Foundation           Voice:  +1-617-542-5942       *
00016  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00017  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00018  *                                                                  *
00019 \********************************************************************/
00045 #ifndef XACC_ACCOUNT_H
00046 #define XACC_ACCOUNT_H
00047 #include "qof.h"
00048 #include "gnc-engine.h"
00049 #include "policy.h"
00050 
00051 typedef gnc_numeric (*xaccGetBalanceFn)( const Account *account );
00052 
00053 typedef gnc_numeric (*xaccGetBalanceInCurrencyFn) (
00054     const Account *account, const gnc_commodity *report_commodity,
00055     gboolean include_children);
00056 
00057 typedef gnc_numeric (*xaccGetBalanceAsOfDateFn) (
00058     Account *account, time_t date);
00059 
00060 typedef void (*AccountCb)(Account *a, gpointer data);
00061 typedef gpointer (*AccountCb2)(Account *a, gpointer data);
00062 
00063 typedef struct
00064 {
00065     QofInstanceClass parent_class;
00066 } AccountClass;
00067 
00068 /* --- type macros --- */
00069 #define GNC_TYPE_ACCOUNT            (gnc_account_get_type ())
00070 #define GNC_ACCOUNT(o)              \
00071      (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ACCOUNT, Account))
00072 #define GNC_ACCOUNT_CLASS(k)        \
00073      (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ACCOUNT, AccountClass))
00074 #define GNC_IS_ACCOUNT(o)           \
00075      (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ACCOUNT))
00076 #define GNC_IS_ACCOUNT_CLASS(k)     \
00077      (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ACCOUNT))
00078 #define GNC_ACCOUNT_GET_CLASS(o)    \
00079      (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ACCOUNT, AccountClass))
00080 
00084 GType gnc_account_get_type(void);
00085 
00096 typedef enum
00097 {
00098     ACCT_TYPE_INVALID = -1, 
00099     ACCT_TYPE_NONE = -1,
00101     ACCT_TYPE_BANK = 0, 
00104     ACCT_TYPE_CASH = 1, 
00107     ACCT_TYPE_CREDIT = 3,       
00110     ACCT_TYPE_ASSET = 2,        
00113     ACCT_TYPE_LIABILITY = 4,
00116     ACCT_TYPE_STOCK = 5,        
00119     ACCT_TYPE_MUTUAL = 6,       
00123     ACCT_TYPE_CURRENCY = 7,
00134     ACCT_TYPE_INCOME = 8,       
00137     ACCT_TYPE_EXPENSE = 9,
00140     ACCT_TYPE_EQUITY = 10,
00143     ACCT_TYPE_RECEIVABLE = 11,
00145     ACCT_TYPE_PAYABLE = 12,  
00147     ACCT_TYPE_ROOT = 13, 
00149     ACCT_TYPE_TRADING = 14, 
00155     NUM_ACCOUNT_TYPES = 15,  
00158     /* bank account types */
00159     ACCT_TYPE_CHECKING = 15, 
00161     ACCT_TYPE_SAVINGS = 16, 
00163     ACCT_TYPE_MONEYMRKT = 17, 
00165     ACCT_TYPE_CREDITLINE = 18, 
00167     ACCT_TYPE_LAST
00168 } GNCAccountType;
00169 
00170 
00171 
00176 Account * xaccMallocAccount (QofBook *book);
00177 
00179 Account * gnc_account_create_root (QofBook *book);
00180 
00189 Account * xaccCloneAccount (const Account *source, QofBook *book);
00190 
00193 void xaccAccountBeginEdit (Account *account);
00194 
00197 void xaccAccountCommitEdit (Account *account);
00198 
00202 void xaccAccountDestroy (Account *account);
00203 
00205 gboolean xaccAccountEqual(const Account *a, const Account* b,
00206                           gboolean check_guids);
00207 
00217 int xaccAccountOrder (const Account *account_1, const Account *account_2);
00218 
00221 /* ------------------ */
00222 
00230 const gchar *gnc_get_account_separator_string (void);
00231 gunichar gnc_get_account_separator (void);
00232 void gnc_set_account_separator (const gchar *separator);
00233 
00234 /*@ dependent @*/
00235 Account *gnc_book_get_root_account(QofBook *book);
00236 void gnc_book_set_root_account(QofBook *book, Account *root);
00237 
00239 #define xaccAccountGetGUID(X)     qof_entity_get_guid(QOF_INSTANCE(X))
00240 #define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
00241 
00245 /*@ dependent @*/ Account * xaccAccountLookup (const GncGUID *guid, QofBook *book);
00246 #define xaccAccountLookupDirect(g,b) xaccAccountLookup(&(g),b)
00247 
00262 gchar *gnc_account_name_violations_errmsg (const gchar *separator, GList* invalid_account_names);
00263 
00274 GList *gnc_account_list_name_violations (QofBook *book, const gchar *separator);
00275 
00276 /* ------------------ */
00277 
00281 QofBook *gnc_account_get_book(const Account *account);
00283 void xaccAccountSetType (Account *account, GNCAccountType);
00285 void xaccAccountSetName (Account *account, const char *name);
00287 void xaccAccountSetCode (Account *account, const char *code);
00289 void xaccAccountSetDescription (Account *account, const char *desc);
00291 void xaccAccountSetColor (Account *account, const char *color);
00293 void xaccAccountSetFilter (Account *account, const char *filter);
00295 void xaccAccountSetSortOrder (Account *account, const char *sortorder);
00297 void xaccAccountSetNotes (Account *account, const char *notes);
00299 void xaccAccountSetLastNum (Account *account, const char *num);
00301 void gnc_account_set_policy (Account *account, GNCPolicy *policy);
00306 GNCAccountType xaccAccountGetType (const Account *account);
00309 gboolean xaccAccountIsPriced(const Account *acc);
00310 
00318 void gnc_account_set_start_balance (Account *acc,
00319                                     const gnc_numeric start_baln);
00320 
00328 void gnc_account_set_start_cleared_balance (Account *acc,
00329         const gnc_numeric start_baln);
00330 
00338 void gnc_account_set_start_reconciled_balance (Account *acc,
00339         const gnc_numeric start_baln);
00340 
00345 void gnc_account_set_balance_dirty (Account *acc);
00346 
00351 void gnc_account_set_sort_dirty (Account *acc);
00352 
00362 gboolean gnc_account_insert_split (Account *acc, Split *s);
00363 
00373 gboolean gnc_account_remove_split (Account *acc, Split *s);
00374 
00376 const char * xaccAccountGetName (const Account *account);
00378 const char * xaccAccountGetCode (const Account *account);
00380 const char * xaccAccountGetDescription (const Account *account);
00382 const char * xaccAccountGetColor (const Account *account);
00384 const char * xaccAccountGetFilter (const Account *account);
00386 const char * xaccAccountGetSortOrder (const Account *account);
00388 const char * xaccAccountGetNotes (const Account *account);
00390 const char * xaccAccountGetLastNum (const Account *account);
00392 GNCPolicy *gnc_account_get_policy (Account *account);
00393 
00397 void xaccAccountRecomputeBalance (Account *);
00398 
00403 void xaccAccountSortSplits (Account *acc, gboolean force);
00404 
00418 gchar * gnc_account_get_full_name (const Account *account);
00419 
00426 void dxaccAccountSetPriceSrc (Account *account, const char *src);
00433 const char * dxaccAccountGetPriceSrc (const Account *account);
00434 
00439 gboolean xaccAccountGetAutoInterestXfer (const Account *account,
00440         gboolean default_value);
00445 void xaccAccountSetAutoInterestXfer (Account *account, gboolean value);
00480 void xaccAccountSetCommodity (Account *account, gnc_commodity *comm);
00481 
00483 /*@ dependent @*/
00484 gnc_commodity * xaccAccountGetCommodity (const Account *account);
00485 
00490 int xaccAccountGetCommoditySCU (const Account *account);
00491 
00494 int xaccAccountGetCommoditySCUi (const Account *account);
00495 
00500 void xaccAccountSetCommoditySCU (Account *account, int frac);
00501 
00503 void xaccAccountSetNonStdSCU (Account *account, gboolean flag);
00504 
00507 gboolean  xaccAccountGetNonStdSCU (const Account *account);
00516 gnc_numeric xaccAccountGetBalance (const Account *account);
00519 gnc_numeric xaccAccountGetClearedBalance (const Account *account);
00522 gnc_numeric xaccAccountGetReconciledBalance (const Account *account);
00523 gnc_numeric xaccAccountGetPresentBalance (const Account *account);
00524 gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account);
00526 gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account,
00527         time_t date);
00528 
00529 /* These two functions convert a given balance from one commodity to
00530    another.  The account argument is only used to get the Book, and
00531    may have nothing to do with the supplied balance.  Likewise, the
00532    date argument is only used for commodity conversion and may have
00533    nothing to do with supplied balance.
00534 
00535    Since they really have nothing to do with Accounts, there's
00536    probably some better place for them, but where?  gnc-commodity.h?
00537 */
00538 gnc_numeric xaccAccountConvertBalanceToCurrency(
00539     const Account *account, /* for book */
00540     gnc_numeric balance,
00541     const gnc_commodity *balance_currency,
00542     const gnc_commodity *new_currency);
00543 gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate(
00544     const Account *account, /* for book */
00545     gnc_numeric balance, gnc_commodity *balance_currency,
00546     gnc_commodity *new_currency, time_t date);
00547 
00548 /* These functions get some type of balance in the desired commodity.
00549    'report_commodity' may be NULL to use the account's commodity. */
00550 gnc_numeric xaccAccountGetBalanceInCurrency (
00551     const Account *account, const gnc_commodity *report_commodity,
00552     gboolean include_children);
00553 gnc_numeric xaccAccountGetClearedBalanceInCurrency (
00554     const Account *account, const gnc_commodity *report_commodity,
00555     gboolean include_children);
00556 gnc_numeric xaccAccountGetReconciledBalanceInCurrency (
00557     const Account *account, const gnc_commodity *report_commodity,
00558     gboolean include_children);
00559 gnc_numeric xaccAccountGetPresentBalanceInCurrency (
00560     const Account *account, const gnc_commodity *report_commodity,
00561     gboolean include_children);
00562 gnc_numeric xaccAccountGetProjectedMinimumBalanceInCurrency (
00563     const Account *account, const gnc_commodity *report_commodity,
00564     gboolean include_children);
00565 
00566 /* This function gets the balance as of the given date in the desired
00567    commodity. */
00568 gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency(
00569     Account *account, time_t date, gnc_commodity *report_commodity,
00570     gboolean include_children);
00571 
00572 gnc_numeric xaccAccountGetBalanceChangeForPeriod (
00573     Account *acc, time_t date1, time_t date2, gboolean recurse);
00574 
00608 void gnc_account_append_child (Account *new_parent, Account *child);
00609 
00620 void gnc_account_remove_child (Account *parent, Account *child);
00621 
00630 /*@ dependent @*/
00631 Account * gnc_account_get_parent (const Account *account);
00632 
00642 Account * gnc_account_get_root (Account *account);
00643 
00650 gboolean gnc_account_is_root (const Account *account);
00651 
00666 GList *gnc_account_get_children (const Account *account);
00667 
00671 GList *gnc_account_get_children_sorted (const Account *account);
00672 
00679 gint gnc_account_n_children (const Account *account);
00680 
00692 gint gnc_account_child_index (const Account *parent, const Account *child);
00693 
00704 Account *gnc_account_nth_child (const Account *parent, gint num);
00705 
00721 GList * gnc_account_get_descendants (const Account *account);
00722 
00741 GList *gnc_account_get_descendants_sorted (const Account *account);
00742 
00749 gint gnc_account_n_descendants (const Account *account);
00750 
00757 gint gnc_account_get_current_depth (const Account *account);
00758 
00766 gint gnc_account_get_tree_depth (const Account *account);
00767 
00784 void gnc_account_foreach_child (const Account *account,
00785                                 AccountCb func, /*@ null @*/ gpointer user_data);
00786 
00800 void gnc_account_foreach_descendant (const Account *account,
00801                                      AccountCb func, /*@ null @*/ gpointer user_data);
00802 
00818 gpointer gnc_account_foreach_descendant_until (const Account *account,
00819         AccountCb2 func, /*@ null @*/ gpointer user_data);
00820 
00821 
00834 void gnc_account_join_children (Account *to_parent, Account *from_parent);
00835 
00841 void gnc_account_merge_children (Account *parent);
00842 
00846 void xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status);
00847 
00849 gboolean xaccAccountGetReconcileChildrenStatus(const Account *account);
00850 
00856 gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor);
00857 
00858 #define xaccAccountGetSlots(X) qof_instance_get_slots(QOF_INSTANCE(X))
00859 
00874 Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
00875 
00880 Account *gnc_account_lookup_by_full_name (const Account *any_account,
00881         const gchar *name);
00882 
00886 Account *gnc_account_lookup_by_code (const Account *parent,
00887                                      const char *code);
00888 
00891 /* ------------------ */
00892 
00901 const char * xaccAccountTypeEnumAsString (GNCAccountType type);
00907 gboolean xaccAccountStringToType (const char* str, GNCAccountType *type);
00913 GNCAccountType xaccAccountStringToEnum (const char* str);
00914 
00918 const char * xaccAccountGetTypeStr (GNCAccountType type);
00919 
00921 guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type);
00922 
00925 gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,
00926                                      GNCAccountType child_type);
00927 
00930 guint32 xaccAccountTypesValid(void);
00931 
00932 
00935 /* ------------------ */
00936 
00944 #define xaccAccountInsertSplit(acc, s)  xaccSplitSetAccount((s), (acc))
00945 
00957 SplitList* xaccAccountGetSplitList (const Account *account);
00958 
00961 void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);
00962 
00991 gint xaccAccountForEachTransaction(const Account *account,
00992                                    TransactionCallback proc,
00993                                    void *data);
00994 
00996 Transaction * xaccAccountFindTransByDesc(const Account *account,
00997         const char *description);
00998 
01000 Split * xaccAccountFindSplitByDesc(const Account *account,
01001                                    const char *description);
01002 
01005 /* ------------------ */
01006 
01015 void xaccAccountInsertLot (Account *, GNCLot *);
01016 void xaccAccountRemoveLot (Account *, GNCLot *);
01017 
01026 LotList* xaccAccountGetLotList (const Account *account);
01027 
01034 gpointer xaccAccountForEachLot(
01035     const Account *acc,
01036     gpointer (*proc)(GNCLot *lot, gpointer user_data), /*@ null @*/ gpointer user_data);
01037 
01038 
01044 LotList * xaccAccountFindOpenLots (const Account *acc,
01045                                    gboolean (*match_func)(GNCLot *lot,
01046                                            gpointer user_data),
01047                                    /*@ null @*/ gpointer user_data, GCompareFunc sort_func);
01048 
01050 /* ------------------ */
01051 
01056 gboolean xaccAccountGetReconcileLastDate (const Account *account,
01057         time_t *last_date);
01059 void xaccAccountSetReconcileLastDate (Account *account, time_t last_date);
01060 
01062 gboolean xaccAccountGetReconcileLastInterval (const Account *account,
01063         int *months, int *days);
01065 void xaccAccountSetReconcileLastInterval (Account *account,
01066         int months, int days);
01068 gboolean xaccAccountGetReconcilePostponeDate (const Account *account,
01069         time_t *postpone_date);
01071 void xaccAccountSetReconcilePostponeDate (Account *account,
01072         time_t postpone_date);
01073 
01075 gboolean xaccAccountGetReconcilePostponeBalance (const Account *account,
01076         gnc_numeric *balance);
01078 void xaccAccountSetReconcilePostponeBalance (Account *account,
01079         gnc_numeric balance);
01080 
01082 void xaccAccountClearReconcilePostpone (Account *account);
01087 typedef enum
01088 {
01089     PLACEHOLDER_NONE,
01090     PLACEHOLDER_THIS,
01091     PLACEHOLDER_CHILD,
01092 } GNCPlaceholderType;
01093 
01104 gboolean xaccAccountGetPlaceholder (const Account *account);
01105 
01112 void xaccAccountSetPlaceholder (Account *account, gboolean val);
01113 
01119 GNCPlaceholderType xaccAccountGetDescendantPlaceholder(const Account *account);
01133 gboolean xaccAccountGetHidden (const Account *acc);
01134 
01142 void xaccAccountSetHidden (Account *acc, gboolean val);
01143 
01153 gboolean xaccAccountIsHidden (const Account *acc);
01161 gboolean xaccAccountGetTaxRelated (const Account *account);
01163 void xaccAccountSetTaxRelated (Account *account, gboolean tax_related);
01165 const char * xaccAccountGetTaxUSCode (const Account *account);
01167 void xaccAccountSetTaxUSCode (Account *account, const char *code);
01169 const char * xaccAccountGetTaxUSPayerNameSource (const Account *account);
01171 void xaccAccountSetTaxUSPayerNameSource (Account *account, const char *source);
01173 gint64 xaccAccountGetTaxUSCopyNumber (const Account *account);
01175 void xaccAccountSetTaxUSCopyNumber (Account *account, gint64 copy_number);
01188 void xaccAccountSetMark (Account *account, short mark);
01189 
01195 void xaccClearMark (Account *account, short val);
01196 
01199 void xaccClearMarkDown (Account *account, short val);
01246 void gnc_account_tree_begin_staged_transaction_traversals(Account *acc);
01247 
01252 void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
01253 
01258 void xaccAccountBeginStagedTransactionTraversals(const Account *account);
01259 
01265 gboolean xaccTransactionTraverse(Transaction *trans, int stage);
01266 
01280 int xaccAccountStagedTransactionTraversal(const Account *a,
01281         unsigned int stage,
01282         TransactionCallback thunk,
01283         void *data);
01284 
01298 int gnc_account_tree_staged_transaction_traversal(const Account *account,
01299         unsigned int stage,
01300         TransactionCallback thunk,
01301         void *data);
01302 
01334 int xaccAccountTreeForEachTransaction(Account *acc,
01335                                       TransactionCallback proc, void *data);
01336 
01349 void DxaccAccountSetCurrency (Account *account, gnc_commodity *currency);
01350 
01354 gnc_commodity * DxaccAccountGetCurrency (const Account *account);
01355 
01363 void dxaccAccountSetQuoteTZ (Account *account, const char *tz);
01370 const char * dxaccAccountGetQuoteTZ (const Account *account);
01377 #define ACCOUNT_KVP             "kvp"
01378 #define ACCOUNT_NAME_           "name"
01379 #define ACCOUNT_CODE_           "code"
01380 #define ACCOUNT_DESCRIPTION_    "desc"
01381 #define ACCOUNT_COLOR_          "color"
01382 #define ACCOUNT_FILTER_         "filter"
01383 #define ACCOUNT_SORT_ORDER_     "sort-order"
01384 #define ACCOUNT_NOTES_          "notes"
01385 #define ACCOUNT_BALANCE_        "balance"
01386 #define ACCOUNT_CLEARED_        "cleared"
01387 #define ACCOUNT_RECONCILED_     "reconciled"
01388 #define ACCOUNT_PRESENT_        "present"
01389 #define ACCOUNT_FUTURE_MINIMUM_ "future-minimum"
01390 #define ACCOUNT_TAX_RELATED     "tax-related-p"
01391 #define ACCOUNT_TYPE_           "account-type"
01392 #define ACCOUNT_SCU             "smallest-commodity-unit"
01393 #define ACCOUNT_NSCU            "non-standard-scu"
01394 #define ACCOUNT_PARENT          "parent-account"
01395 
01400 #define ACCOUNT_MATCH_ALL_TYPE  "account-match-all"
01401 
01402 #endif /* XACC_ACCOUNT_H */
01403 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines