Skip to content

Commit

Permalink
Christian Stimming's report patch.
Browse files Browse the repository at this point in the history
	* src/scm/html-utilities.scm: Added different printing of stock
	accounts. Started a new layout/ordering for sub-totals.

	* src/scm/commodity-utilities.scm (gnc:sum-collector-stocks):
	added such that stock prices are no longer shown but foreign
	currencies are. Rounding precision increased. Added sanity checks
	for arguments of various funtions.

	* src/scm/report-utilities.scm (gnc:account-is-stock?): added
	function


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3744 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
jdavisp3 committed Mar 4, 2001
1 parent 240fa15 commit 9e22005
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 60 deletions.
1 change: 1 addition & 0 deletions .cvsignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ltmain.sh
make-gnucash-patch
stamp-h
stamp-h.in
tags
*.tar.gz
*.log
*.patch
Expand Down
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2001-03-04 Christian Stimming <stimming@tuhh.de>

* src/scm/html-utilities.scm: Added different printing of stock
accounts. Started a new layout/ordering for sub-totals.

* src/scm/commodity-utilities.scm (gnc:sum-collector-stocks):
added such that stock prices are no longer shown but foreign
currencies are. Rounding precision increased. Added sanity checks
for arguments of various funtions.

* src/scm/report-utilities.scm (gnc:account-is-stock?): added
function

2001-03-04 Dave Peticolas <dave@krondo.com>

* src/gnome/window-help.c: save & restore window size
Expand Down
89 changes: 60 additions & 29 deletions src/scm/commodity-utilities.scm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
(gnc:support "commodity-utilities.scm")
(gnc:depend "report-utilities.scm")

;; Returns true if the commodity comm represents a currency, false if
;; it represents a stock or mutual-fund.
(define (gnc:commodity-is-currency? comm)
(equal? GNC_COMMODITY_NS_ISO
(gnc:commodity-get-namespace comm)))

;; All the functions below up to gnc:make-exchange-fn are calculating
;; the exchange rate for different commodities by determining the
;; weighted average of all currency transactions.
Expand Down Expand Up @@ -80,16 +86,16 @@
(b (gnc:make-numeric-collector)))
(a 'add (unknown-coll 'total #f))
(b 'add
;; round to (at least) 6 significant digits
;; round to (at least) 8 significant digits
(gnc:numeric-div
(gnc:numeric-mul
(un->known-coll 'total #f)
((cdadr known-pair) 'total #f)
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 7) GNC-RND-ROUND))
(logior (GNC-DENOM-SIGFIGS 9) GNC-RND-ROUND))
((caadr known-pair) 'total #f)
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 6) GNC-RND-ROUND)))
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))
;; in other words: (/ (* (caadr un->known-coll) (cdadr
;; known-pair)) (caadr known-pair) ))
(cons a b)))
Expand Down Expand Up @@ -263,7 +269,7 @@
(gnc:numeric-div ((cdadr e) 'total #f)
((caadr e) 'total #f)
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 6) GNC-RND-ROUND)))))
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))
(gnc:get-exchange-totals report-commodity end-date)))

;; This one returns the ready-to-use function for calculation of the
Expand All @@ -273,35 +279,60 @@
(define (gnc:make-exchange-function exchange-alist)
(let ((exchangelist exchange-alist))
(lambda (foreign domestic)
(gnc:make-gnc-monetary
domestic
(let ((pair (assoc (gnc:gnc-monetary-commodity foreign)
exchangelist)))
(if (not pair)
(gnc:numeric-zero)
(gnc:numeric-mul (gnc:gnc-monetary-amount foreign)
(cadr pair)
;; FIXME: the constant 100 here is
;; not a durable solution --
;; anyone has a better idea?
100 GNC-RND-ROUND)))))))
(if foreign
(gnc:make-gnc-monetary
domestic
(let ((pair (assoc (gnc:gnc-monetary-commodity foreign)
exchangelist)))
(if (not pair)
(gnc:numeric-zero)
(gnc:numeric-mul (gnc:gnc-monetary-amount foreign)
(cadr pair)
;; FIXME: the constant 100 here is
;; not a durable solution --
;; anyone has a better idea?
100 GNC-RND-ROUND))))
#f))))

;; Adds all different commodities in the commodity-collector <foreign>
;; by using the exchange rates of <exchange-fn> to calculate the
;; exchange rates to the commodity <domestic>. Returns a
;; <gnc-monetary> with the domestic commodity and its corresponding
;; balance.
;; balance. If the foreign balance is #f, it returns #f.
(define (gnc:sum-collector-commodity foreign domestic exchange-fn)
(let ((balance (gnc:make-commodity-collector)))
(foreign
'format
(lambda (curr val)
(if (gnc:commodity-equiv? domestic curr)
(balance 'add domestic val)
(balance 'add domestic
(gnc:gnc-monetary-amount
(exchange-fn (gnc:make-gnc-monetary curr val)
domestic)))))
#f)
(balance 'getmonetary domestic #f)))
(if foreign
(let ((balance (gnc:make-commodity-collector)))
(foreign
'format
(lambda (curr val)
(if (gnc:commodity-equiv? domestic curr)
(balance 'add domestic val)
(balance 'add domestic
(gnc:gnc-monetary-amount
(exchange-fn (gnc:make-gnc-monetary curr val)
domestic)))))
#f)
(balance 'getmonetary domestic #f))
#f))

;; As above, but adds only the commodities of other stocks and
;; mutual-funds. Returns a commodity-collector which (still) may have
;; several different commodities in it -- if there have been different
;; *currencies*, not only stocks.
(define (gnc:sum-collector-stocks foreign domestic exchange-fn)
(if foreign
(let ((balance (gnc:make-commodity-collector)))
(foreign
'format
(lambda (curr val)
(if (gnc:commodity-equiv? domestic curr)
(balance 'add domestic val)
(if (gnc:commodity-is-currency? curr)
(balance 'add curr val)
(balance 'add domestic
(gnc:gnc-monetary-amount
(exchange-fn (gnc:make-gnc-monetary curr val)
domestic))))))
#f)
balance)
#f))
72 changes: 45 additions & 27 deletions src/scm/html-utilities.scm
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@
;; balance column, and if reverse-balance? is #t the balance will
;; be displayed with the sign reversed.
(define (add-row-helper!
current-depth my-name my-balance reverse-balance?)
current-depth my-name my-balance reverse-balance? boldface?)
(gnc:html-table-append-row!
table
(append
(gnc:html-make-empty-cells (- current-depth 1))
(list (gnc:make-html-table-cell/size
1 (+ 1 (- tree-depth current-depth))
;; FIXME: (if boldface? (gnc:html-markup-b my-name)
;; but this doesn't seen to work
my-name))
(gnc:html-make-empty-cells (- tree-depth current-depth))
;; the account balance
(list (if reverse-balance?
(list (if (and my-balance reverse-balance?)
(gnc:monetary-neg my-balance)
my-balance))
(gnc:html-make-empty-cells (- current-depth 1)))))
Expand All @@ -161,7 +163,8 @@
;; printed. If reverse-balance? == #t then the balance's signs get
;; reversed.
(define (add-commodity-rows!
current-depth my-name my-commodity balance reverse-balance?)
current-depth my-name my-commodity balance
reverse-balance? is-stock-account? boldface?)
;; Adds one row to the table. my-name is the html-object
;; displayed in the name column; foreign-balance is the
;; <gnc-monetary> for the foreign column or #f if to be left
Expand All @@ -177,28 +180,30 @@
1 (+ 1 (- tree-depth current-depth))
my-name))
(gnc:html-make-empty-cells (* 2 (- tree-depth current-depth)))
(list (if (not foreign-balance)
(car (gnc:html-make-empty-cells 1))
foreign-balance)
domestic-balance)
(list foreign-balance domestic-balance)
(gnc:html-make-empty-cells (* 2 (- current-depth 1))))))

;;;;;;;;;;
;; the first row for each account: shows the name and the
;; balance in the report-commodity
(if (or do-subtot?
(gnc:commodity-equiv? my-commodity report-commodity))
(if (and (not is-stock-account?)
(or (gnc:commodity-equiv? my-commodity report-commodity)
do-subtot?))
;; usual case: the account balance in terms of report
;; commodity
(commodity-row-helper!
my-name #f
(balance 'getmonetary report-commodity reverse-balance?))
(if balance
(balance 'getmonetary report-commodity reverse-balance?)
#f))
;; special case if do-subtot? was false and it is in a
;; different commodity than the report: then the
;; foreign commodity gets displayed in this line
;; rather then the following lines (loop below).
(let ((my-balance (balance 'getmonetary
my-commodity reverse-balance?)))
;; different commodity than the report: then the foreign
;; commodity gets displayed in this line rather then the
;; following lines (loop below). Is also used if
;; is-stock-account? is true.
(let ((my-balance
(if balance (balance 'getmonetary
my-commodity reverse-balance?) #f)))
(commodity-row-helper!
my-name
my-balance
Expand All @@ -209,7 +214,7 @@
;; report-currency. One row for each non-report-currency. Is
;; only used when do-subtot? == #f (otherwise this balance has
;; only one commodity).
(if do-subtot?
(if (and do-subtot? (and balance (not is-stock-account?)))
(balance
'format
(lambda (curr val)
Expand Down Expand Up @@ -237,13 +242,16 @@
(gnc:html-account-anchor acct)
(gnc:account-get-commodity acct)
(my-get-balance acct)
(gnc:account-reverse-balance? acct))
(gnc:account-reverse-balance? acct)
(gnc:account-has-shares? acct)
#f)
(add-row-helper!
current-depth
(gnc:html-account-anchor acct)
(gnc:sum-collector-commodity (my-get-balance acct)
report-commodity exchange-fn)
(gnc:account-reverse-balance? acct))))
(gnc:account-reverse-balance? acct)
#f)))

;; Adds rows to the table. Therefore it goes through the list of
;; accounts, runs add-account-rows! on each account. If
Expand All @@ -262,16 +270,19 @@

;; Generalization for a subtotal or the total balance.
(define (add-subtotal-row!
current-depth subtotal-name balance)
current-depth subtotal-name balance boldface?)
(if show-other-curr?
(add-commodity-rows! current-depth subtotal-name
report-commodity balance #f)
report-commodity
(gnc:sum-collector-stocks
balance report-commodity exchange-fn)
#f #f boldface?)
;; Show no other currencies. Therefore just calculate
;; one total via sum-collector-commodity and show it.
(add-row-helper! current-depth subtotal-name
(gnc:sum-collector-commodity
balance report-commodity exchange-fn)
#f)))
#f boldface?)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand All @@ -281,12 +292,18 @@
(for-each
(lambda (accts)
(if (and (not (null? accts)) (not (null? (cdr accts))))
(begin
(let ((groupname (car accts))
(gaccts (cdr accts)))
;; first the group name
(add-subtotal-row! 1 groupname #f #f)
(traverse-accounts! gaccts 2)
(add-subtotal-row!
1 (car accts)
1 (string-append (_ "Total") " " groupname)
(gnc:accounts-get-balance-helper
(cdr accts) my-get-balance gnc:account-reverse-balance?))
(traverse-accounts! (cdr accts) 2))))
gaccts my-get-balance gnc:account-reverse-balance?)
#t)
;; and an empty line
(add-subtotal-row! 1 #f #f #f))))
(gnc:decompose-accountlist (lset-intersection
equal? accounts topl-accounts)))
;; No extra grouping.
Expand All @@ -295,8 +312,9 @@
;; Show the total sum.
(if show-total?
(add-subtotal-row!
1 total-name (get-total-fn (filter show-acct? topl-accounts)
my-get-balance)))
1 total-name
(get-total-fn (filter show-acct? topl-accounts) my-get-balance)
#t))

;; set default alignment to right, and override for the name
;; columns
Expand Down
15 changes: 13 additions & 2 deletions src/scm/report-utilities.scm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
#f)))
(member type '(stock mutual-fund currency))))

;; True if the account is of type stock or mutual-fund
(define (gnc:account-is-stock? account)
(let ((type (gw:enum-<gnc:AccountType>-val->sym
(gnc:account-get-type account)
#f)))
(member type '(stock mutual-fund))))

;; True if the account is of type income or expense
(define (gnc:account-is-inc-exp? account)
(let ((type (gw:enum-<gnc:AccountType>-val->sym
Expand Down Expand Up @@ -408,8 +415,12 @@
;; This works similar as above but returns a commodity-collector,
;; thus takes care of children accounts with different currencies.
;;
;; Note that the commodity-collector contains <gnc:numeric> values
;; rather than double values.
;; Note that this uses the gnc:split-get-share-balance rather than
;; gnc:split-get-balance as above, which means that results for both
;; may differ especially for stock accounts.
;;
;; Also note that the commodity-collector contains <gnc:numeric>
;; values rather than double values.
(define (gnc:account-get-comm-balance-at-date account
date include-children?)
(let ((balance-collector
Expand Down
2 changes: 1 addition & 1 deletion src/scm/report/account-summary.scm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(pagename-accounts (N_ "Accounts"))
(optname-show-subaccounts (N_ "Always show sub-accounts"))
(optname-accounts (N_ "Account"))
(optname-group-accounts (N_ "Group the accouts"))
(optname-group-accounts (N_ "Group the accounts"))
(optname-include-subbalances (N_ "Include Sub-Account balances")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion src/scm/report/pnl.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(optname-display-depth (N_ "Account Display Depth"))
(optname-show-subaccounts (N_ "Always show sub-accounts"))
(optname-accounts (N_ "Account"))
(optname-group-accounts (N_ "Group the accouts"))
(optname-group-accounts (N_ "Group the accounts"))
(optname-include-subbalances (N_ "Include Sub-Account balances"))

;; (pagename-currencies (N_ "Currencies")) too little options :)
Expand Down

0 comments on commit 9e22005

Please sign in to comment.