mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
*** empty log message ***
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2112 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2a3802851a
commit
86214cc428
@ -12,7 +12,7 @@
|
||||
*
|
||||
* HISTORY:
|
||||
* created by Linas Vepstas January 1999
|
||||
* Copyright (c) 1999 Linas Vepstas
|
||||
* Copyright (c) 1999, 2000 Linas Vepstas
|
||||
*/
|
||||
/********************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
|
@ -40,7 +40,7 @@
|
||||
*
|
||||
* HISTORY:
|
||||
* created by Linas Vepstas January 1999
|
||||
* Copyright (c) 1999 Linas Vepstas
|
||||
* Copyright (c) 1999, 2000 Linas Vepstas
|
||||
*/
|
||||
/********************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* Transaction.c -- the transaction data structure *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998 Linas Vepstas *
|
||||
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -319,7 +319,7 @@ double xaccSplitGetCostBasis (Split *s)
|
||||
|
||||
void
|
||||
xaccInitTransaction( Transaction * trans )
|
||||
{
|
||||
{
|
||||
Split *split;
|
||||
|
||||
/* fill in some sane defaults */
|
||||
@ -346,18 +346,18 @@ xaccInitTransaction( Transaction * trans )
|
||||
trans->marker = 0;
|
||||
trans->open = 0;
|
||||
trans->orig = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
Transaction *
|
||||
xaccMallocTransaction( void )
|
||||
{
|
||||
{
|
||||
Transaction *trans = (Transaction *)_malloc(sizeof(Transaction));
|
||||
xaccInitTransaction (trans);
|
||||
return trans;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
@ -407,7 +407,7 @@ xaccCloneTransaction (Transaction *t)
|
||||
|
||||
void
|
||||
xaccFreeTransaction( Transaction *trans )
|
||||
{
|
||||
{
|
||||
int i;
|
||||
Split *s;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* Transaction.h -- defines transaction for xacc (X-Accountant) *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998 Linas Vepstas *
|
||||
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -1,26 +1,7 @@
|
||||
/*
|
||||
* FILE:
|
||||
* TransactionP.h
|
||||
*
|
||||
* FUNCTION:
|
||||
* The is the *private* transaction header file. Code outside of
|
||||
* engine should *not* include this file. This is because code
|
||||
* outside of the engine should *never* access any of the structure
|
||||
* members directly.
|
||||
*
|
||||
* Note that this header file also defines prototypes for various
|
||||
* routines that perform sub-atomic updates of the accounting
|
||||
* structures. If these routines are not used properly, they
|
||||
* can result in inconsistent, unbalanced accounting structures.
|
||||
* In other words, thier use is dangerous, and thier use outside
|
||||
* of the scope of the engine is forbidden.
|
||||
*
|
||||
*/
|
||||
|
||||
/********************************************************************\
|
||||
* TransactionP.h -- defines transaction for xacc (X-Accountant) *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998 Linas Vepstas *
|
||||
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -42,6 +23,25 @@
|
||||
* Huntington Beach, CA 92648-4632 *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* FILE:
|
||||
* TransactionP.h
|
||||
*
|
||||
* FUNCTION:
|
||||
* The is the *private* transaction header file. Code outside of
|
||||
* engine should *not* include this file. This is because code
|
||||
* outside of the engine should *never* access any of the structure
|
||||
* members directly.
|
||||
*
|
||||
* Note that this header file also defines prototypes for various
|
||||
* routines that perform sub-atomic updates of the accounting
|
||||
* structures. If these routines are not used properly, they
|
||||
* can result in inconsistent, unbalanced accounting structures.
|
||||
* In other words, thier use is dangerous, and thier use outside
|
||||
* of the scope of the engine is forbidden.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XACC_TRANSACTION_P_H__
|
||||
#define __XACC_TRANSACTION_P_H__
|
||||
|
||||
|
@ -216,3 +216,57 @@
|
||||
(+ (gnc:split-list-total splits)
|
||||
(gnc:split-get-balance first-split)
|
||||
(- (gnc:split-get-value first-split))))))
|
||||
|
||||
;; get transaction date from split - needs to be done indirectly
|
||||
;; as it's stored in the parent transaction
|
||||
(define (gnc:split-get-transaction-date split)
|
||||
(gnc:transaction-get-date-posted (gnc:split-get-parent split)))
|
||||
|
||||
;; ditto descriptions
|
||||
(define (gnc:split-get-description-from-parent split)
|
||||
(gnc:transaction-get-description (gnc:split-get-parent split)))
|
||||
|
||||
;; get the account name of a split
|
||||
(define (gnc:split-get-account-name split)
|
||||
(gnc:account-get-name (gnc:split-get-account split)))
|
||||
|
||||
;; get the account balance at the specified date. if include-children?
|
||||
;; is true, the balances of all children (not just direct children)
|
||||
;; are included in the calculation.
|
||||
(define (gnc:account-get-balance-at-date account date include-children?)
|
||||
(let ((children-balance
|
||||
(if include-children?
|
||||
(gnc:group-get-balance-at-date
|
||||
(gnc:account-get-children account) date)
|
||||
0)))
|
||||
(let loop ((index 0)
|
||||
(balance 0)
|
||||
(split (gnc:account-get-split account 0)))
|
||||
(if (pointer-token-null? split)
|
||||
(+ children-balance balance)
|
||||
(if (gnc:timepair-lt date (gnc:split-get-transaction-date split))
|
||||
(+ children-balance balance)
|
||||
(loop (+ index 1)
|
||||
(gnc:split-get-balance split)
|
||||
(gnc:account-get-split account (+ index 1))))))))
|
||||
|
||||
;; get the balance of a group of accounts at the specified date.
|
||||
;; all children are included in the calculation
|
||||
(define (gnc:group-get-balance-at-date group date)
|
||||
(apply +
|
||||
(gnc:group-map-accounts
|
||||
(lambda (account)
|
||||
(gnc:account-get-balance-at-date account date #t)) group)))
|
||||
|
||||
;; get the change in balance from the 'from' date to the 'to' date.
|
||||
;; this isn't quite as efficient as it could be, but it's a whole lot
|
||||
;; simpler :)
|
||||
(define (gnc:account-get-balance-interval account from to include-children?)
|
||||
(- (gnc:account-get-balance-at-date account to include-children?)
|
||||
(gnc:account-get-balance-at-date account from include-children?)))
|
||||
|
||||
(define (gnc:group-get-balance-interval group from to)
|
||||
(apply +
|
||||
(gnc:group-map-accounts
|
||||
(lambda (account)
|
||||
(gnc:account-get-balance-interval account from to #t)) group)))
|
||||
|
@ -115,21 +115,6 @@
|
||||
#(GLPlot "Gain/Loss" "Gain And Loss"))))
|
||||
gnc:*runavg-track-options*))
|
||||
|
||||
;; get transactions date from split - needs to be done indirectly
|
||||
;; as it's stored in the parent transaction
|
||||
|
||||
(define (gnc:split-get-transaction-date split)
|
||||
(gnc:transaction-get-date-posted (gnc:split-get-parent split)))
|
||||
|
||||
;; ditto descriptions
|
||||
(define (gnc:split-get-description-from-parent split)
|
||||
(gnc:transaction-get-description (gnc:split-get-parent split)))
|
||||
|
||||
;; get the account name of a split
|
||||
(define (gnc:split-get-account-name split)
|
||||
(gnc:account-get-name (gnc:split-get-account split)))
|
||||
|
||||
|
||||
;; Text table
|
||||
|
||||
; Create an text table row from a list of entries
|
||||
|
@ -7,43 +7,6 @@
|
||||
(gnc:depend "report-utilities.scm")
|
||||
(gnc:depend "options.scm")
|
||||
|
||||
(define (gnc:account-get-balance-until account to-tp include-children?)
|
||||
(let ((query (gnc:malloc-query))
|
||||
(balance (if include-children?
|
||||
(gnc:group-get-balance-until
|
||||
(gnc:account-get-children account) to-tp)
|
||||
0)))
|
||||
(gnc:query-add-account query account)
|
||||
(gnc:query-show-earliest query)
|
||||
(gnc:query-set-latest query to-tp)
|
||||
(set! balance
|
||||
(+ balance (gnc:split-list-balance (gnc:query-get-splits query))))
|
||||
(gnc:free-query query)
|
||||
balance))
|
||||
|
||||
(define (gnc:account-get-balance-interval account from-tp to-tp
|
||||
include-children?)
|
||||
(let ((query (gnc:malloc-query))
|
||||
(balance (if include-children?
|
||||
(gnc:group-get-balance-interval
|
||||
(gnc:account-get-children account) from-tp to-tp)
|
||||
0)))
|
||||
(gnc:query-add-account query account)
|
||||
(gnc:query-set-earliest query from-tp)
|
||||
(gnc:query-set-latest query to-tp)
|
||||
(set! balance
|
||||
(+ balance (gnc:split-list-total (gnc:query-get-splits query))))
|
||||
(gnc:free-query query)
|
||||
balance))
|
||||
|
||||
(define (gnc:group-get-balance-until group to-tp)
|
||||
(apply + (gnc:group-map-accounts
|
||||
(lambda (x) (gnc:account-get-balance-until x to-tp #t)) group)))
|
||||
|
||||
(define (gnc:group-get-balance-interval group from-tp to-tp)
|
||||
(apply + (gnc:group-map-accounts
|
||||
(lambda (x) (gnc:account-get-balance-interval x from-tp to-tp #t))
|
||||
group)))
|
||||
|
||||
;; Just a private scope.
|
||||
(let
|
||||
@ -156,7 +119,7 @@
|
||||
(gnc:account-get-children account)))
|
||||
|
||||
(account-balance (if balance-sheet?
|
||||
(gnc:account-get-balance-until
|
||||
(gnc:account-get-balance-at-date
|
||||
account
|
||||
to-value #f)
|
||||
(gnc:account-get-balance-interval
|
||||
@ -183,7 +146,7 @@
|
||||
(balance (make-stats-collector))
|
||||
(rawbal
|
||||
(if balance-sheet?
|
||||
(gnc:account-get-balance-until account to-value #f)
|
||||
(gnc:account-get-balance-at-date account to-value #f)
|
||||
(gnc:account-get-balance-interval
|
||||
account
|
||||
from-value
|
||||
@ -202,8 +165,8 @@
|
||||
((if balance-sheet? + -)
|
||||
0
|
||||
(if balance-sheet?
|
||||
(gnc:group-get-balance-until grandchildren
|
||||
to-value)
|
||||
(gnc:group-get-balance-at-date grandchildren
|
||||
to-value)
|
||||
(gnc:group-get-balance-interval grandchildren
|
||||
from-value
|
||||
to-value)))))
|
||||
|
Loading…
Reference in New Issue
Block a user