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     QofInstanceClass parent_class;
00065 } AccountClass;
00066 
00067 /* --- type macros --- */
00068 #define GNC_TYPE_ACCOUNT            (gnc_account_get_type ())
00069 #define GNC_ACCOUNT(o)              \
00070      (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ACCOUNT, Account))
00071 #define GNC_ACCOUNT_CLASS(k)        \
00072      (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ACCOUNT, AccountClass))
00073 #define GNC_IS_ACCOUNT(o)           \
00074      (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ACCOUNT))
00075 #define GNC_IS_ACCOUNT_CLASS(k)     \
00076      (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ACCOUNT))
00077 #define GNC_ACCOUNT_GET_CLASS(o)    \
00078      (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ACCOUNT, AccountClass))
00079 GType gnc_account_get_type(void);
00080 
00091 typedef enum 
00092 {
00093   ACCT_TYPE_INVALID = -1, 
00094   ACCT_TYPE_NONE = -1,
00096   ACCT_TYPE_BANK = 0,   
00099   ACCT_TYPE_CASH = 1,   
00102   ACCT_TYPE_CREDIT = 3, 
00105   ACCT_TYPE_ASSET = 2,  
00108   ACCT_TYPE_LIABILITY = 4,
00111   ACCT_TYPE_STOCK = 5,  
00114   ACCT_TYPE_MUTUAL= 6,  
00118   ACCT_TYPE_CURRENCY = 7,
00129   ACCT_TYPE_INCOME = 8, 
00132   ACCT_TYPE_EXPENSE = 9,
00135   ACCT_TYPE_EQUITY = 10,
00138   ACCT_TYPE_RECEIVABLE = 11,
00140   ACCT_TYPE_PAYABLE = 12,  
00142   ACCT_TYPE_ROOT = 13, 
00144   NUM_ACCOUNT_TYPES = 14,  
00147   /* bank account types */
00148   ACCT_TYPE_CHECKING = 14, 
00150   ACCT_TYPE_SAVINGS = 15, 
00152   ACCT_TYPE_MONEYMRKT = 16, 
00154   ACCT_TYPE_CREDITLINE = 17, 
00156 } GNCAccountType;
00157 
00158 
00159 
00164 Account * xaccMallocAccount (QofBook *book);
00165 
00167 Account * gnc_account_create_root (QofBook *book);
00168 
00175 Account * xaccCloneAccount (const Account *from, QofBook *book);
00176 
00187 Account * xaccCloneAccountSimple (const Account *from, QofBook *book);
00188 
00191 void xaccAccountBeginEdit (Account *account);
00192 
00195 void xaccAccountCommitEdit (Account *account);
00196 
00200 void xaccAccountDestroy (Account *account);
00201 
00203 gboolean xaccAccountEqual(const Account *a, const Account* b, 
00204                           gboolean check_guids);
00205 
00214 int xaccAccountOrder (const Account *account_1, const Account *account_2);
00215 
00218 /* ------------------ */
00219 
00227 const gchar *gnc_get_account_separator_string (void);
00228 gunichar gnc_get_account_separator (void);
00229 void gnc_set_account_separator (const gchar *separator);
00230 
00231 Account *gnc_book_get_root_account(QofBook *book);
00232 void gnc_book_set_root_account(QofBook *book, Account *root);
00233 
00235 #define xaccAccountGetGUID(X)     qof_entity_get_guid(QOF_INSTANCE(X))
00236 #define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
00237 
00241 Account * xaccAccountLookup (const GUID *guid, QofBook *book);
00242 #define xaccAccountLookupDirect(g,b) xaccAccountLookup(&(g),b)
00243 
00246 /* ------------------ */
00247 
00251 QofBook *gnc_account_get_book(const Account *account);
00253 void xaccAccountSetType (Account *account, GNCAccountType);
00255 void xaccAccountSetName (Account *account, const char *name);
00257 void xaccAccountSetCode (Account *account, const char *code);
00259 void xaccAccountSetDescription (Account *account, const char *desc);
00261 void xaccAccountSetNotes (Account *account, const char *notes);
00263 void xaccAccountSetLastNum (Account *account, const char *num);
00265 void gnc_account_set_policy (Account *account, GNCPolicy *policy);
00267 GNCAccountType xaccAccountGetType (const Account *account);
00269 gboolean xaccAccountIsPriced(const Account *acc);
00270 
00278 void gnc_account_set_start_balance (Account *acc,
00279                                     const gnc_numeric start_baln);
00280 
00288 void gnc_account_set_start_cleared_balance (Account *acc,
00289                                             const gnc_numeric start_baln);
00290 
00298 void gnc_account_set_start_reconciled_balance (Account *acc,
00299                                                const gnc_numeric start_baln);
00300 
00305 void gnc_account_set_balance_dirty (Account *acc);
00306 
00311 void gnc_account_set_sort_dirty (Account *acc);
00312 
00321 gboolean gnc_account_find_split (Account *acc, Split *s);
00322 
00332 gboolean gnc_account_insert_split (Account *acc, Split *s);
00333 
00343 gboolean gnc_account_remove_split (Account *acc, Split *s);
00344 
00346 const char * xaccAccountGetName (const Account *account);
00348 const char * xaccAccountGetCode (const Account *account);
00350 const char * xaccAccountGetDescription (const Account *account);
00352 const char * xaccAccountGetNotes (const Account *account);
00354 const char * xaccAccountGetLastNum (const Account *account);
00356 GNCPolicy *gnc_account_get_policy (Account *account);
00358 gnc_numeric gnc_account_get_start_balance (Account *acc);
00359 
00362 gnc_numeric gnc_account_get_start_cleared_balance (Account *acc);
00363 
00366 gnc_numeric gnc_account_get_start_reconciled_balance (Account *acc);
00367 
00375 gboolean gnc_account_get_balance_dirty (Account *acc);
00376 
00384 gboolean gnc_account_get_sort_dirty (Account *acc);
00385 
00389 void xaccAccountRecomputeBalance (Account *);
00390 
00395 void xaccAccountSortSplits (Account *acc, gboolean force);
00396 
00410 char * xaccAccountGetFullName (const Account *account);
00411 
00418 void dxaccAccountSetPriceSrc (Account *account, const char *src);
00425 const char * dxaccAccountGetPriceSrc (const Account *account);
00426 
00431 gboolean xaccAccountGetAutoInterestXfer (const Account *account, 
00432                                          gboolean default_value);
00437 void xaccAccountSetAutoInterestXfer (Account *account, gboolean value);
00472 void xaccAccountSetCommodity (Account *account, gnc_commodity *comm);
00473 
00475 #define DxaccAccountSetSecurity xaccAccountSetCommodity
00476 
00478 gnc_commodity * xaccAccountGetCommodity (const Account *account);
00479 
00481 #define DxaccAccountGetSecurity xaccAccountGetCommodity
00482 
00487 int xaccAccountGetCommoditySCU (const Account *account);
00488 
00491 int xaccAccountGetCommoditySCUi (const Account *account);
00492 
00497 void xaccAccountSetCommoditySCU (Account *account, int frac);
00498 
00500 #define xaccAccountSetCommoditySCUandFlag xaccAccountSetCommoditySCU 
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 Account * gnc_account_get_parent (const Account *account);
00631 
00641 Account * gnc_account_get_root (Account *account);
00642 
00649 gboolean gnc_account_is_root (const Account *account);
00650 
00661 GList *gnc_account_get_children (const Account *account);
00662 GList *gnc_account_get_children_sorted (const Account *account);
00663 
00670 gint gnc_account_n_children (const Account *account);
00671 
00683 gint gnc_account_child_index (const Account *parent, const Account *child);
00684 
00695 Account *gnc_account_nth_child (const Account *parent, gint num);
00696 
00712 GList * gnc_account_get_descendants (const Account *account);
00713 
00732 GList *gnc_account_get_descendants_sorted (const Account *account);
00733 
00740 gint gnc_account_n_descendants (const Account *account);
00741 
00748 gint gnc_account_get_current_depth (const Account *account);
00749 
00757 gint gnc_account_get_tree_depth (const Account *account);
00758 
00775 void gnc_account_foreach_child (const Account *account,
00776                                 AccountCb func, gpointer user_data);
00777 
00793 gpointer gnc_account_foreach_child_until (const Account *account,
00794                                           AccountCb2 func, gpointer user_data);
00795 
00796 
00810 void gnc_account_foreach_descendant (const Account *account,
00811                                      AccountCb func, gpointer user_data);
00812 
00828 gpointer gnc_account_foreach_descendant_until (const Account *account,
00829                                                AccountCb2 func, gpointer user_data);
00830 
00831 
00844 void gnc_account_join_children (Account *to_parent, Account *from_parent);
00845 
00853 void gnc_account_copy_children (Account *dest, Account *src);
00854 
00860 void gnc_account_merge_children (Account *parent);
00861 
00865 void xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status);
00866 
00868 gboolean xaccAccountGetReconcileChildrenStatus(const Account *account);
00869 
00875 gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor);
00876 
00877 #define xaccAccountGetSlots(X) qof_instance_get_slots(QOF_INSTANCE(X))
00878 
00893 Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
00894 
00899 Account *gnc_account_lookup_by_full_name (const Account *any_account,
00900                                           const gchar *name);
00901 
00905 Account *gnc_account_lookup_by_code (const Account *parent,
00906                                      const char *code);
00907 
00910 /* ------------------ */
00911 
00920 const char * xaccAccountTypeEnumAsString (GNCAccountType type); 
00926 gboolean xaccAccountStringToType (const char* str, GNCAccountType *type);
00932 GNCAccountType xaccAccountStringToEnum (const char* str);
00933 
00937 const char * xaccAccountGetTypeStr (GNCAccountType type); 
00941 GNCAccountType xaccAccountGetTypeFromStr (const gchar *str);
00942 
00944 guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type);
00945 
00948 gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,
00949                                      GNCAccountType child_type);
00950 
00953 guint32 xaccAccountTypesValid(void);
00954 
00955 
00958 /* ------------------ */
00959 
00967 #define xaccAccountInsertSplit(acc, s)  xaccSplitSetAccount((s), (acc))
00968 
00980 SplitList* xaccAccountGetSplitList (const Account *account);
00981 
00984 void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);
00985 
01014 gint xaccAccountForEachTransaction(const Account *account,
01015                                    TransactionCallback proc,
01016                                    void *data);
01017 
01019 Transaction * xaccAccountFindTransByDesc(const Account *account, 
01020                                          const char *description);
01021 
01023 Split * xaccAccountFindSplitByDesc(const Account *account, 
01024                                    const char *description);
01025 
01028 /* ------------------ */
01029 
01038 void xaccAccountInsertLot (Account *, GNCLot *);
01039 void xaccAccountRemoveLot (Account *, GNCLot *);
01040 
01049 LotList* xaccAccountGetLotList (const Account *account);
01050 
01057 gpointer xaccAccountForEachLot(
01058     const Account *acc,
01059     gpointer (*proc)(GNCLot *lot, gpointer user_data), gpointer user_data);
01060 
01061 
01067 LotList * xaccAccountFindOpenLots (const Account *acc,
01068                                    gboolean (*match_func)(GNCLot *lot,
01069                                                           gpointer user_data),
01070                                    gpointer user_data, GCompareFunc sort_func);
01071 
01073 /* ------------------ */
01074 
01079 gboolean xaccAccountGetReconcileLastDate (const Account *account,
01080                                           time_t *last_date);
01082 void xaccAccountSetReconcileLastDate (Account *account, time_t last_date);
01083 
01085 gboolean xaccAccountGetReconcileLastInterval (const Account *account,
01086                                               int *months, int *days);
01088 void xaccAccountSetReconcileLastInterval (Account *account,
01089                                           int months, int days);
01091 gboolean xaccAccountGetReconcilePostponeDate (const Account *account,
01092                                               time_t *postpone_date);
01094 void xaccAccountSetReconcilePostponeDate (Account *account, 
01095                                           time_t postpone_date);
01096 
01098 gboolean xaccAccountGetReconcilePostponeBalance (const Account *account,
01099                                                  gnc_numeric *balance);
01101 void xaccAccountSetReconcilePostponeBalance (Account *account,
01102                                              gnc_numeric balance);
01103 
01105 void xaccAccountClearReconcilePostpone (Account *account);
01110 typedef enum 
01111   {
01112   PLACEHOLDER_NONE,
01113   PLACEHOLDER_THIS,
01114   PLACEHOLDER_CHILD,
01115   } GNCPlaceholderType;
01116 
01127 gboolean xaccAccountGetPlaceholder (const Account *account);
01128 
01135 void xaccAccountSetPlaceholder (Account *account, gboolean val);
01136 
01142 GNCPlaceholderType xaccAccountGetDescendantPlaceholder(const Account *account);
01156 gboolean xaccAccountGetHidden (const Account *acc);
01157 
01165 void xaccAccountSetHidden (Account *acc, gboolean val);
01166 
01176 gboolean xaccAccountIsHidden (const Account *acc);
01184 gboolean xaccAccountGetTaxRelated (const Account *account);
01186 void xaccAccountSetTaxRelated (Account *account, gboolean tax_related);
01188 const char * xaccAccountGetTaxUSCode (const Account *account);
01190 void xaccAccountSetTaxUSCode (Account *account, const char *code);
01192 const char * xaccAccountGetTaxUSPayerNameSource (const Account *account);
01194 void xaccAccountSetTaxUSPayerNameSource (Account *account, const char *source);
01207 void xaccAccountSetMark (Account *account, short mark); 
01208 
01210 short xaccAccountGetMark (const Account *account);
01211 
01214 void xaccClearMark (Account *account, short val);
01215 
01218 void xaccClearMarkDown (Account *account, short val);
01265 void gnc_account_tree_begin_staged_transaction_traversals(Account *acc);
01266 
01271 void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
01272 
01277 void xaccAccountBeginStagedTransactionTraversals(const Account *account);
01278 
01284 gboolean xaccTransactionTraverse(Transaction *trans, int stage);
01285 
01289 gboolean xaccSplitTransactionTraverse(Split *split, int stage);
01290 
01304 int xaccAccountStagedTransactionTraversal(const Account *a,
01305                                           unsigned int stage,
01306                                           TransactionCallback thunk,
01307                                           void *data);
01308 
01322 int gnc_account_tree_staged_transaction_traversal(const Account *account,
01323                                                   unsigned int stage,
01324                                                   TransactionCallback thunk,
01325                                                   void *data);
01326 
01358 int xaccAccountTreeForEachTransaction(Account *acc, 
01359                                       TransactionCallback proc, void *data);
01360 
01373 void DxaccAccountSetCurrency (Account *account, gnc_commodity *currency);
01374 
01378 gnc_commodity * DxaccAccountGetCurrency (const Account *account);
01379 
01387 void dxaccAccountSetQuoteTZ (Account *account, const char *tz);
01394 const char * dxaccAccountGetQuoteTZ (const Account *account);
01401 #define ACCOUNT_KVP                     "kvp"
01402 #define ACCOUNT_NAME_           "name"
01403 #define ACCOUNT_CODE_           "code"
01404 #define ACCOUNT_DESCRIPTION_    "desc"
01405 #define ACCOUNT_NOTES_          "notes"
01406 #define ACCOUNT_BALANCE_        "balance"
01407 #define ACCOUNT_CLEARED_        "cleared"
01408 #define ACCOUNT_RECONCILED_     "reconciled"
01409 #define ACCOUNT_PRESENT_        "present"
01410 #define ACCOUNT_FUTURE_MINIMUM_ "future-minimum"
01411 #define ACCOUNT_TAX_RELATED     "tax-related-p"
01412 #define ACCOUNT_TYPE_           "account-type"
01413 #define ACCOUNT_SCU                     "smallest-commodity-unit"
01414 #define ACCOUNT_NSCU            "non-standard-scu"
01415 #define ACCOUNT_PARENT          "parent-account"
01416 
01421 #define ACCOUNT_MATCH_ALL_TYPE  "account-match-all"
01422 
01423 #endif /* XACC_ACCOUNT_H */
01424 

Generated on Sun Sep 7 05:06:59 2008 for GnuCash by  doxygen 1.5.2