src/engine/Transaction.[ch]: add xaccTransGetAccountValue() method to compute

the sum of all Splits in a Transaction that touch a specific Account.  This
  is most useful with lots.

src/engine/gw-engine-spec.scm: wrap some of the Lot API and the new function
  xaccTransGetAccountValue(), and xaccTransGetTxnType()


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7032 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2002-06-27 02:11:17 +00:00
parent 094f790dd0
commit 2ce7831f7d
3 changed files with 80 additions and 0 deletions

View File

@@ -1358,6 +1358,26 @@ xaccTransGetImbalance (Transaction * trans)
return xaccSplitsComputeValue (trans->splits, NULL, currency);
}
gnc_numeric
xaccTransGetAccountValue (Transaction *trans, Account *account)
{
gnc_numeric total = gnc_numeric_zero ();
GList *splits;
if (!trans || !account)
return total;
for (splits = xaccTransGetSplitList (trans); splits; splits = splits->next)
{
Split *s = splits->data;
Account *a = xaccSplitGetAccount (s);
if (a == account)
total = gnc_numeric_add (total, xaccSplitGetValue (s),
GNC_DENOM_AUTO, GNC_DENOM_LCD);
}
return total;
}
/********************************************************************\
\********************************************************************/

View File

@@ -255,6 +255,14 @@ void xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr);
*/
gnc_numeric xaccTransGetImbalance (Transaction * trans);
/* The xaccTransGetAccountValue() method returns the total value applied
* to a paricular account. In some cases there may be multiple Splits
* in a single Transaction applied to one account (in particular when
* trying to balance Lots) -- this function is just a convienience to
* view everything at once.
*/
gnc_numeric xaccTransGetAccountValue (Transaction *trans, Account *account);
/* ------------- splits --------------- */
Split * xaccMallocSplit (GNCBook *book);

View File

@@ -30,6 +30,7 @@
"#include <gnc-session.h>\n"
"#include <gnc-engine-util.h>\n"
"#include <gnc-event.h>\n"
"#include <gnc-lot.h>\n"
"#include <date.h>\n"
"#include <engine-helpers.h>\n"
"#include <gnc-engine.h>\n"
@@ -97,6 +98,7 @@
(gw:wrap-as-wct ws '<gnc:AccInfo*> "AccInfo*" "const AccInfo*")
(gw:wrap-as-wct ws '<gnc:AccountGroup*> "AccountGroup*" "const AccountGroup*")
(gw:wrap-as-wct ws '<gnc:Book*> "GNCBook*" "const GNCBook*")
(gw:wrap-as-wct ws '<gnc:Lot*> "GNCLot*" "const GNCLot*")
(gw:wrap-as-wct ws '<gnc:Session*> "GNCSession*" "const GNCSession**")
(gw:wrap-as-wct ws '<gnc:Split*> "Split*" "const Split*")
(gw:wrap-as-wct ws '<gnc:Transaction*> "Transaction*" "const Transaction*")
@@ -284,6 +286,13 @@
(gw:wrap-value ws 'gnc:split-corr-account-code '<gnc:id-type>
"SPLIT_CORR_ACCT_CODE")
;
; Transaction Types
;
(gw:wrap-value ws 'gnc:transaction-type-none '<gw:char> "TXN_TYPE_NONE")
(gw:wrap-value ws 'gnc:transaction-type-invoice '<gw:char> "TXN_TYPE_INVOICE")
(gw:wrap-value ws 'gnc:transaction-type-payment '<gw:char> "TXN_TYPE_PAYMENT")
(gw:wrap-function
ws
@@ -640,6 +649,22 @@ number of nanoseconds.")
'((<gnc:Transaction*> trans) (<gnc:commodity*> comm))
"Sets the commodity common for this transaction.")
(gw:wrap-function
ws
'gnc:transaction-get-account-value
'<gnc:numeric>
"xaccTransGetAccountValue"
'((<gnc:Transaction*> trans) (<gnc:Account*> acc))
"Compute the sum of all Splits in trans that are applied to Account acc.")
(gw:wrap-function
ws
'gnc:transaction-get-txn-type
'<gw:char>
"xaccTransGetTxnType"
'((<gnc:Transaction*> trans))
"Return the transaction type.")
(gw:wrap-function
ws
'gnc:malloc-account
@@ -1113,6 +1138,14 @@ when no longer needed.")
(<gw:scm> thunk))
"FIXME: For now, see Group.h for info...")
(gw:wrap-function
ws
'gnc:account-get-lot-list
'(gw:glist-of <gnc:Lot*> callee-owned)
"xaccAccountGetLotList"
'((<gnc:Account*> account))
"Return the list of Lots for this account.")
;;============
;; GNCPriceDB
@@ -2277,3 +2310,22 @@ of having a parent transaction with which one is working...")
"Convert a timepair on a certain day (localtime) to\
the timepair representing midday on that day")
;;
;; gnc-lot.h
;;
(gw:wrap-function
ws
'gnc:lot-get-balance
'<gnc:numeric>
"gnc_lot_get_balance"
'((<gnc:Lot*> lot))
"Return the balance of the lot")
(gw:wrap-function
ws
'gnc:lot-closed?
'<gw:bool>
"gnc_lot_is_closed"
'((<gnc:Lot*> lot))
"Is this Lot closed (is the balance zero)?")