00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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 GType gnc_account_get_type(void);
00081
00092 typedef enum
00093 {
00094 ACCT_TYPE_INVALID = -1,
00095 ACCT_TYPE_NONE = -1,
00097 ACCT_TYPE_BANK = 0,
00100 ACCT_TYPE_CASH = 1,
00103 ACCT_TYPE_CREDIT = 3,
00106 ACCT_TYPE_ASSET = 2,
00109 ACCT_TYPE_LIABILITY = 4,
00112 ACCT_TYPE_STOCK = 5,
00115 ACCT_TYPE_MUTUAL = 6,
00119 ACCT_TYPE_CURRENCY = 7,
00130 ACCT_TYPE_INCOME = 8,
00133 ACCT_TYPE_EXPENSE = 9,
00136 ACCT_TYPE_EQUITY = 10,
00139 ACCT_TYPE_RECEIVABLE = 11,
00141 ACCT_TYPE_PAYABLE = 12,
00143 ACCT_TYPE_ROOT = 13,
00145 ACCT_TYPE_TRADING = 14,
00151 NUM_ACCOUNT_TYPES = 15,
00154
00155 ACCT_TYPE_CHECKING = 15,
00157 ACCT_TYPE_SAVINGS = 16,
00159 ACCT_TYPE_MONEYMRKT = 17,
00161 ACCT_TYPE_CREDITLINE = 18,
00163 } GNCAccountType;
00164
00165
00166
00171 Account * xaccMallocAccount (QofBook *book);
00172
00174 Account * gnc_account_create_root (QofBook *book);
00175
00182 Account * xaccCloneAccount (const Account *source, QofBook *book);
00183
00194 Account * xaccCloneAccountSimple (const Account *source, QofBook *book);
00195
00198 void xaccAccountBeginEdit (Account *account);
00199
00202 void xaccAccountCommitEdit (Account *account);
00203
00207 void xaccAccountDestroy (Account *account);
00208
00210 gboolean xaccAccountEqual(const Account *a, const Account* b,
00211 gboolean check_guids);
00212
00221 int xaccAccountOrder (const Account *account_1, const Account *account_2);
00222
00225
00226
00234 const gchar *gnc_get_account_separator_string (void);
00235 gunichar gnc_get_account_separator (void);
00236 void gnc_set_account_separator (const gchar *separator);
00237
00238
00239 Account *gnc_book_get_root_account(QofBook *book);
00240 void gnc_book_set_root_account(QofBook *book, Account *root);
00241
00243 #define xaccAccountGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X))
00244 #define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
00245
00249 Account * xaccAccountLookup (const GncGUID *guid, QofBook *book);
00250 #define xaccAccountLookupDirect(g,b) xaccAccountLookup(&(g),b)
00251
00266 gchar *gnc_account_name_violations_errmsg (const gchar *separator, GList* invalid_account_names);
00267
00278 GList *gnc_account_list_name_violations (QofBook *book, const gchar *separator);
00279
00280
00281
00285 QofBook *gnc_account_get_book(const Account *account);
00287 void xaccAccountSetType (Account *account, GNCAccountType);
00289 void xaccAccountSetName (Account *account, const char *name);
00291 void xaccAccountSetCode (Account *account, const char *code);
00293 void xaccAccountSetDescription (Account *account, const char *desc);
00295 void xaccAccountSetColor (Account *account, const char *color);
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);
00303 GNCAccountType xaccAccountGetType (const Account *account);
00305 gboolean xaccAccountIsPriced(const Account *acc);
00306
00314 void gnc_account_set_start_balance (Account *acc,
00315 const gnc_numeric start_baln);
00316
00324 void gnc_account_set_start_cleared_balance (Account *acc,
00325 const gnc_numeric start_baln);
00326
00334 void gnc_account_set_start_reconciled_balance (Account *acc,
00335 const gnc_numeric start_baln);
00336
00341 void gnc_account_set_balance_dirty (Account *acc);
00342
00347 void gnc_account_set_sort_dirty (Account *acc);
00348
00357 gboolean gnc_account_find_split (Account *acc, Split *s);
00358
00368 gboolean gnc_account_insert_split (Account *acc, Split *s);
00369
00379 gboolean gnc_account_remove_split (Account *acc, Split *s);
00380
00382 const char * xaccAccountGetName (const Account *account);
00384 const char * xaccAccountGetCode (const Account *account);
00386 const char * xaccAccountGetDescription (const Account *account);
00388 const char * xaccAccountGetColor (const Account *account);
00390 const char * xaccAccountGetNotes (const Account *account);
00392 const char * xaccAccountGetLastNum (const Account *account);
00394 GNCPolicy *gnc_account_get_policy (Account *account);
00396 gnc_numeric gnc_account_get_start_balance (Account *acc);
00397
00400 gnc_numeric gnc_account_get_start_cleared_balance (Account *acc);
00401
00404 gnc_numeric gnc_account_get_start_reconciled_balance (Account *acc);
00405
00413 gboolean gnc_account_get_balance_dirty (Account *acc);
00414
00422 gboolean gnc_account_get_sort_dirty (Account *acc);
00423
00427 void xaccAccountRecomputeBalance (Account *);
00428
00433 void xaccAccountSortSplits (Account *acc, gboolean force);
00434
00448 gchar * gnc_account_get_full_name (const Account *account);
00449
00456 void dxaccAccountSetPriceSrc (Account *account, const char *src);
00463 const char * dxaccAccountGetPriceSrc (const Account *account);
00464
00469 gboolean xaccAccountGetAutoInterestXfer (const Account *account,
00470 gboolean default_value);
00475 void xaccAccountSetAutoInterestXfer (Account *account, gboolean value);
00510 void xaccAccountSetCommodity (Account *account, gnc_commodity *comm);
00511
00513 gnc_commodity * xaccAccountGetCommodity (const Account *account);
00514
00519 int xaccAccountGetCommoditySCU (const Account *account);
00520
00523 int xaccAccountGetCommoditySCUi (const Account *account);
00524
00529 void xaccAccountSetCommoditySCU (Account *account, int frac);
00530
00532 void xaccAccountSetNonStdSCU (Account *account, gboolean flag);
00533
00536 gboolean xaccAccountGetNonStdSCU (const Account *account);
00545 gnc_numeric xaccAccountGetBalance (const Account *account);
00548 gnc_numeric xaccAccountGetClearedBalance (const Account *account);
00551 gnc_numeric xaccAccountGetReconciledBalance (const Account *account);
00552 gnc_numeric xaccAccountGetPresentBalance (const Account *account);
00553 gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account);
00555 gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account,
00556 time_t date);
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 gnc_numeric xaccAccountConvertBalanceToCurrency(
00568 const Account *account,
00569 gnc_numeric balance,
00570 const gnc_commodity *balance_currency,
00571 const gnc_commodity *new_currency);
00572 gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate(
00573 const Account *account,
00574 gnc_numeric balance, gnc_commodity *balance_currency,
00575 gnc_commodity *new_currency, time_t date);
00576
00577
00578
00579 gnc_numeric xaccAccountGetBalanceInCurrency (
00580 const Account *account, const gnc_commodity *report_commodity,
00581 gboolean include_children);
00582 gnc_numeric xaccAccountGetClearedBalanceInCurrency (
00583 const Account *account, const gnc_commodity *report_commodity,
00584 gboolean include_children);
00585 gnc_numeric xaccAccountGetReconciledBalanceInCurrency (
00586 const Account *account, const gnc_commodity *report_commodity,
00587 gboolean include_children);
00588 gnc_numeric xaccAccountGetPresentBalanceInCurrency (
00589 const Account *account, const gnc_commodity *report_commodity,
00590 gboolean include_children);
00591 gnc_numeric xaccAccountGetProjectedMinimumBalanceInCurrency (
00592 const Account *account, const gnc_commodity *report_commodity,
00593 gboolean include_children);
00594
00595
00596
00597 gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency(
00598 Account *account, time_t date, gnc_commodity *report_commodity,
00599 gboolean include_children);
00600
00601 gnc_numeric xaccAccountGetBalanceChangeForPeriod (
00602 Account *acc, time_t date1, time_t date2, gboolean recurse);
00603
00637 void gnc_account_append_child (Account *new_parent, Account *child);
00638
00649 void gnc_account_remove_child (Account *parent, Account *child);
00650
00659
00660 Account * gnc_account_get_parent (const Account *account);
00661
00671 Account * gnc_account_get_root (Account *account);
00672
00679 gboolean gnc_account_is_root (const Account *account);
00680
00691 GList *gnc_account_get_children (const Account *account);
00692 GList *gnc_account_get_children_sorted (const Account *account);
00693
00700 gint gnc_account_n_children (const Account *account);
00701
00713 gint gnc_account_child_index (const Account *parent, const Account *child);
00714
00725 Account *gnc_account_nth_child (const Account *parent, gint num);
00726
00742 GList * gnc_account_get_descendants (const Account *account);
00743
00762 GList *gnc_account_get_descendants_sorted (const Account *account);
00763
00770 gint gnc_account_n_descendants (const Account *account);
00771
00778 gint gnc_account_get_current_depth (const Account *account);
00779
00787 gint gnc_account_get_tree_depth (const Account *account);
00788
00805 void gnc_account_foreach_child (const Account *account,
00806 AccountCb func, gpointer user_data);
00807
00823 gpointer gnc_account_foreach_child_until (const Account *account,
00824 AccountCb2 func, gpointer user_data);
00825
00826
00840 void gnc_account_foreach_descendant (const Account *account,
00841 AccountCb func, gpointer user_data);
00842
00858 gpointer gnc_account_foreach_descendant_until (const Account *account,
00859 AccountCb2 func, gpointer user_data);
00860
00861
00874 void gnc_account_join_children (Account *to_parent, Account *from_parent);
00875
00883 void gnc_account_copy_children (Account *dest, Account *src);
00884
00890 void gnc_account_merge_children (Account *parent);
00891
00895 void xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status);
00896
00898 gboolean xaccAccountGetReconcileChildrenStatus(const Account *account);
00899
00905 gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor);
00906
00907 #define xaccAccountGetSlots(X) qof_instance_get_slots(QOF_INSTANCE(X))
00908
00923 Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
00924
00929 Account *gnc_account_lookup_by_full_name (const Account *any_account,
00930 const gchar *name);
00931
00935 Account *gnc_account_lookup_by_code (const Account *parent,
00936 const char *code);
00937
00940
00941
00950 const char * xaccAccountTypeEnumAsString (GNCAccountType type);
00956 gboolean xaccAccountStringToType (const char* str, GNCAccountType *type);
00962 GNCAccountType xaccAccountStringToEnum (const char* str);
00963
00967 const char * xaccAccountGetTypeStr (GNCAccountType type);
00971 GNCAccountType xaccAccountGetTypeFromStr (const gchar *str);
00972
00974 guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type);
00975
00978 gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,
00979 GNCAccountType child_type);
00980
00983 guint32 xaccAccountTypesValid(void);
00984
00985
00988
00989
00997 #define xaccAccountInsertSplit(acc, s) xaccSplitSetAccount((s), (acc))
00998
01010 SplitList* xaccAccountGetSplitList (const Account *account);
01011
01014 void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);
01015
01044 gint xaccAccountForEachTransaction(const Account *account,
01045 TransactionCallback proc,
01046 void *data);
01047
01049 Transaction * xaccAccountFindTransByDesc(const Account *account,
01050 const char *description);
01051
01053 Split * xaccAccountFindSplitByDesc(const Account *account,
01054 const char *description);
01055
01058
01059
01068 void xaccAccountInsertLot (Account *, GNCLot *);
01069 void xaccAccountRemoveLot (Account *, GNCLot *);
01070
01079 LotList* xaccAccountGetLotList (const Account *account);
01080
01087 gpointer xaccAccountForEachLot(
01088 const Account *acc,
01089 gpointer (*proc)(GNCLot *lot, gpointer user_data), gpointer user_data);
01090
01091
01097 LotList * xaccAccountFindOpenLots (const Account *acc,
01098 gboolean (*match_func)(GNCLot *lot,
01099 gpointer user_data),
01100 gpointer user_data, GCompareFunc sort_func);
01101
01103
01104
01109 gboolean xaccAccountGetReconcileLastDate (const Account *account,
01110 time_t *last_date);
01112 void xaccAccountSetReconcileLastDate (Account *account, time_t last_date);
01113
01115 gboolean xaccAccountGetReconcileLastInterval (const Account *account,
01116 int *months, int *days);
01118 void xaccAccountSetReconcileLastInterval (Account *account,
01119 int months, int days);
01121 gboolean xaccAccountGetReconcilePostponeDate (const Account *account,
01122 time_t *postpone_date);
01124 void xaccAccountSetReconcilePostponeDate (Account *account,
01125 time_t postpone_date);
01126
01128 gboolean xaccAccountGetReconcilePostponeBalance (const Account *account,
01129 gnc_numeric *balance);
01131 void xaccAccountSetReconcilePostponeBalance (Account *account,
01132 gnc_numeric balance);
01133
01135 void xaccAccountClearReconcilePostpone (Account *account);
01140 typedef enum
01141 {
01142 PLACEHOLDER_NONE,
01143 PLACEHOLDER_THIS,
01144 PLACEHOLDER_CHILD,
01145 } GNCPlaceholderType;
01146
01157 gboolean xaccAccountGetPlaceholder (const Account *account);
01158
01165 void xaccAccountSetPlaceholder (Account *account, gboolean val);
01166
01172 GNCPlaceholderType xaccAccountGetDescendantPlaceholder(const Account *account);
01186 gboolean xaccAccountGetHidden (const Account *acc);
01187
01195 void xaccAccountSetHidden (Account *acc, gboolean val);
01196
01206 gboolean xaccAccountIsHidden (const Account *acc);
01214 gboolean xaccAccountGetTaxRelated (const Account *account);
01216 void xaccAccountSetTaxRelated (Account *account, gboolean tax_related);
01218 const char * xaccAccountGetTaxUSCode (const Account *account);
01220 void xaccAccountSetTaxUSCode (Account *account, const char *code);
01222 const char * xaccAccountGetTaxUSPayerNameSource (const Account *account);
01224 void xaccAccountSetTaxUSPayerNameSource (Account *account, const char *source);
01226 gint64 xaccAccountGetTaxUSCopyNumber (const Account *account);
01228 void xaccAccountSetTaxUSCopyNumber (Account *account, gint64 copy_number);
01241 void xaccAccountSetMark (Account *account, short mark);
01242
01244 short xaccAccountGetMark (const Account *account);
01245
01248 void xaccClearMark (Account *account, short val);
01249
01252 void xaccClearMarkDown (Account *account, short val);
01299 void gnc_account_tree_begin_staged_transaction_traversals(Account *acc);
01300
01305 void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
01306
01311 void xaccAccountBeginStagedTransactionTraversals(const Account *account);
01312
01318 gboolean xaccTransactionTraverse(Transaction *trans, int stage);
01319
01323 gboolean xaccSplitTransactionTraverse(Split *split, int stage);
01324
01338 int xaccAccountStagedTransactionTraversal(const Account *a,
01339 unsigned int stage,
01340 TransactionCallback thunk,
01341 void *data);
01342
01356 int gnc_account_tree_staged_transaction_traversal(const Account *account,
01357 unsigned int stage,
01358 TransactionCallback thunk,
01359 void *data);
01360
01392 int xaccAccountTreeForEachTransaction(Account *acc,
01393 TransactionCallback proc, void *data);
01394
01407 void DxaccAccountSetCurrency (Account *account, gnc_commodity *currency);
01408
01412 gnc_commodity * DxaccAccountGetCurrency (const Account *account);
01413
01421 void dxaccAccountSetQuoteTZ (Account *account, const char *tz);
01428 const char * dxaccAccountGetQuoteTZ (const Account *account);
01435 #define ACCOUNT_KVP "kvp"
01436 #define ACCOUNT_NAME_ "name"
01437 #define ACCOUNT_CODE_ "code"
01438 #define ACCOUNT_DESCRIPTION_ "desc"
01439 #define ACCOUNT_COLOR_ "color"
01440 #define ACCOUNT_NOTES_ "notes"
01441 #define ACCOUNT_BALANCE_ "balance"
01442 #define ACCOUNT_CLEARED_ "cleared"
01443 #define ACCOUNT_RECONCILED_ "reconciled"
01444 #define ACCOUNT_PRESENT_ "present"
01445 #define ACCOUNT_FUTURE_MINIMUM_ "future-minimum"
01446 #define ACCOUNT_TAX_RELATED "tax-related-p"
01447 #define ACCOUNT_TYPE_ "account-type"
01448 #define ACCOUNT_SCU "smallest-commodity-unit"
01449 #define ACCOUNT_NSCU "non-standard-scu"
01450 #define ACCOUNT_PARENT "parent-account"
01451
01456 #define ACCOUNT_MATCH_ALL_TYPE "account-match-all"
01457
01458 #endif
01459