GnuCash 2.4.99
Transaction.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 \********************************************************************/
00086 #ifndef XACC_TRANSACTION_H
00087 #define XACC_TRANSACTION_H
00088 
00089 typedef struct _TransactionClass TransactionClass;
00090 
00091 #include <time.h>
00092 
00093 #include "gnc-commodity.h"
00094 #include "gnc-engine.h"
00095 #include "Split.h"
00096 
00097 /* --- type macros --- */
00098 #define GNC_TYPE_TRANSACTION            (gnc_transaction_get_type ())
00099 #define GNC_TRANSACTION(o)              \
00100      (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TRANSACTION, Transaction))
00101 #define GNC_TRANSACTION_CLASS(k)        \
00102      (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TRANSACTION, TransactionClass))
00103 #define GNC_IS_TRANSACTION(o)           \
00104      (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TRANSACTION))
00105 #define GNC_IS_TRANSACTION_CLASS(k)     \
00106      (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TRANSACTION))
00107 #define GNC_TRANSACTION_GET_CLASS(o)    \
00108      (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TRANSACTION, TransactionClass))
00109 GType gnc_transaction_get_type(void);
00110 
00111 
00112 /* FIXME: These macros are not consistent with the type name */
00113 #define GNC_IS_TRANS(obj)  GNC_IS_TRANSACTION(obj)
00114 #define GNC_TRANS(obj)     GNC_TRANSACTION(obj)
00115 
00119 #define TXN_TYPE_NONE    '\0' 
00120 #define TXN_TYPE_INVOICE 'I'  
00121 #define TXN_TYPE_PAYMENT 'P'  
00122 #define TXN_TYPE_LINK    'L'  
00125 /* --------------------------------------------------------------- */
00126 /* Transactions */
00127 
00135 Transaction * xaccMallocTransaction (QofBook *book);
00136 
00151 void          xaccTransDestroy (Transaction *trans);
00152 
00157 Transaction * xaccTransClone (const Transaction *t);
00158 
00182 gboolean xaccTransEqual(const Transaction *ta,
00183                         const Transaction *tb,
00184                         gboolean check_guids,
00185                         gboolean check_splits,
00186                         gboolean check_balances,
00187                         gboolean assume_ordered);
00188 
00192 void          xaccTransBeginEdit (Transaction *trans);
00193 
00199 void          xaccTransCommitEdit (Transaction *trans);
00200 
00206 void          xaccTransRollbackEdit (Transaction *trans);
00207 
00214 gboolean      xaccTransIsOpen (const Transaction *trans);
00215 
00219 /*@ dependent @*//*@ null @*/
00220 Transaction * xaccTransLookup (const GncGUID *guid, QofBook *book);
00221 #define xaccTransLookupDirect(g,b) xaccTransLookup(&(g),b)
00222 
00223 Split * xaccTransFindSplitByAccount(const Transaction *trans,
00224                                     const Account *acc);
00225 
00233 void xaccTransScrubGains (Transaction *trans, Account *gain_acc);
00234 
00235 
00240 guint gnc_book_count_transactions(QofBook *book);
00241 
00251 gboolean xaccTransUseTradingAccounts(const Transaction *trans);
00252 
00256 void          xaccTransSortSplits (Transaction *trans);
00257 
00261 void          xaccTransSetTxnType (Transaction *trans, char type);
00265 char          xaccTransGetTxnType (const Transaction *trans);
00266 
00267 
00269 void          xaccTransSetNum (Transaction *trans, const char *num);
00271 void          xaccTransSetDescription (Transaction *trans, const char *desc);
00275 void          xaccTransSetNotes (Transaction *trans, const char *notes);
00276 
00278 const char *  xaccTransGetNum (const Transaction *trans);
00280 const char *  xaccTransGetDescription (const Transaction *trans);
00284 const char *  xaccTransGetNotes (const Transaction *trans);
00285 
00286 
00288 void          xaccTransSetIsClosingTxn (Transaction *trans, gboolean is_closing);
00289 
00291 gboolean      xaccTransGetIsClosingTxn (const Transaction *trans);
00292 
00293 
00301 #define xaccTransAppendSplit(t, s) xaccSplitSetParent((s), (t))
00302 
00310 Split *       xaccTransGetSplit (const Transaction *trans, int i);
00311 
00313 int xaccTransGetSplitIndex(const Transaction *trans, const Split *split);
00314 
00319 /*@ dependent @*/
00320 SplitList *   xaccTransGetSplitList (const Transaction *trans);
00321 gboolean xaccTransStillHasSplit(const Transaction *trans, const Split *s);
00322 
00323 
00329 void          xaccTransSetReadOnly (Transaction *trans, const char *reason);
00330 void          xaccTransClearReadOnly (Transaction *trans);
00331 
00334 const char *  xaccTransGetReadOnly (const Transaction *trans);
00335 
00339 gboolean xaccTransIsReadonlyByPostedDate(const Transaction *trans);
00340 
00342 int           xaccTransCountSplits (const Transaction *trans);
00343 
00345 gboolean      xaccTransHasReconciledSplits (const Transaction *trans);
00347 gboolean      xaccTransHasReconciledSplitsByAccount (const Transaction *trans,
00348         const Account *account);
00349 
00351 gboolean      xaccTransHasSplitsInState (const Transaction *trans, const char state);
00353 gboolean      xaccTransHasSplitsInStateByAccount (const Transaction *trans,
00354         const char state,
00355         const Account *account);
00356 
00357 
00365 /*@ dependent @*/
00366 gnc_commodity * xaccTransGetCurrency (const Transaction *trans);
00367 
00369 void xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr);
00370 
00386 gnc_numeric xaccTransGetImbalanceValue (const Transaction * trans);
00387 
00394 MonetaryList *xaccTransGetImbalance (const Transaction * trans);
00395 
00398 gboolean xaccTransIsBalanced(const Transaction * trans);
00399 
00406 gnc_numeric xaccTransGetAccountValue (const Transaction *trans,
00407                                       const Account *account);
00408 
00410 gnc_numeric xaccTransGetAccountAmount (const Transaction *trans,
00411                                        const Account *account);
00412 
00413 /* Compute the conversion rate for the transaction to this account.
00414  * Any "split value" (which is in the transaction currency),
00415  * multiplied by this conversion rate, will give you the value you
00416  * should display for this account.
00417  *
00418  * If 'acc' is NULL, return unity.
00419  */
00420 gnc_numeric xaccTransGetAccountConvRate(const Transaction *txn, const Account *acc);
00421 
00424 gnc_numeric xaccTransGetAccountBalance (const Transaction *trans,
00425                                         const Account *account);
00426 
00443 int  xaccTransOrder     (const Transaction *ta, const Transaction *tb);
00444 
00461 void          xaccTransSetDate (Transaction *trans,
00462                                 int day, int mon, int year);
00463 
00471 void xaccTransSetDatePostedGDate (Transaction *trans, GDate date);
00472 
00477 void          xaccTransSetDatePostedSecs (Transaction *trans, time_t time);
00478 
00481 void          xaccTransSetDatePostedTS (Transaction *trans,
00482                                         const Timespec *ts);
00483 
00486 void          xaccTransSetDateEnteredSecs (Transaction *trans, time_t time);
00489 void          xaccTransSetDateEnteredTS (Transaction *trans,
00490         const Timespec *ts);
00491 
00493 void          xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts);
00494 
00499 time_t        xaccTransGetDate (const Transaction *trans);
00504 void          xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts);
00509 Timespec      xaccTransRetDatePostedTS (const Transaction *trans);
00512 GDate      xaccTransGetDatePostedGDate (const Transaction *trans);
00513 
00516 void          xaccTransGetDateEnteredTS (const Transaction *trans, Timespec *ts);
00519 Timespec      xaccTransRetDateEnteredTS (const Transaction *trans);
00520 
00522 Timespec      xaccTransRetDateDueTS (const Transaction *trans);
00524 void          xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts);
00529 /********************************************************************\
00530  * Miscellaneous utility routines.
00531 \********************************************************************/
00532 
00533 
00546 void xaccTransVoid(Transaction *transaction,
00547                    const char *reason);
00548 
00556 void xaccTransUnvoid(Transaction *transaction);
00557 
00569 Transaction * xaccTransReverse(Transaction *transaction);
00570 
00578 Transaction * xaccTransGetReversedBy(const Transaction *trans);
00579 
00587 gboolean xaccTransGetVoidStatus(const Transaction *transaction);
00588 
00596 const char *xaccTransGetVoidReason(const Transaction *transaction);
00597 
00605 Timespec xaccTransGetVoidTime(const Transaction *tr);
00611 #define TRANS_KVP               "kvp"
00612 #define TRANS_NUM               "num"
00613 #define TRANS_DESCRIPTION       "desc"
00614 #define TRANS_DATE_ENTERED      "date-entered"
00615 #define TRANS_DATE_POSTED       "date-posted"
00616 #define TRANS_DATE_DUE          "date-due"
00617 #define TRANS_IMBALANCE         "trans-imbalance"
00618 #define TRANS_IS_BALANCED       "trans-balanced?"
00619 #define TRANS_IS_CLOSING        "trans-is-closing?"
00620 #define TRANS_NOTES             "notes"
00621 #define TRANS_TYPE              "type"
00622 #define TRANS_VOID_STATUS       "void-p"
00623 #define TRANS_VOID_REASON       "void-reason"
00624 #define TRANS_VOID_TIME         "void-time"
00625 #define TRANS_SPLITLIST         "split-list" /* for guid_match_all */
00626 
00628 #define RECONCILED_MATCH_TYPE   "reconciled-match"
00629 
00631 #define xaccTransGetBook(X)      qof_instance_get_book (QOF_INSTANCE(X))
00632 
00633 #define xaccTransGetGUID(X)      qof_entity_get_guid(QOF_INSTANCE(X))
00634 
00635 #define xaccTransReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
00636 
00637 #define xaccTransGetSlots(X)     qof_instance_get_slots (QOF_INSTANCE(X))
00638 
00639 #endif /* XACC_TRANSACTION_H */
00640 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines