[equity-statement] compact unrealized gain calculator

This commit is contained in:
Christopher Lam 2019-09-29 18:28:37 +08:00
parent 1acbc0c1ec
commit 607fd6ff9b

View File

@ -406,29 +406,11 @@
;; that though.... ;; that though....
;; ;;
(define (unrealized-gains-at-date book-balance exchange-fn date) (define (unrealized-gains-at-date book-balance exchange-fn date)
(let* ((unrealized-gain-collector (gnc:make-commodity-collector)) (define weighted-fn
(weighted-fn (gnc:case-exchange-fn 'weighted-average report-commodity date))
(gnc:case-exchange-fn 'weighted-average (gnc:collector-
report-commodity date)) (gnc:sum-collector-commodity book-balance report-commodity exchange-fn)
(gnc:sum-collector-commodity book-balance report-commodity weighted-fn)))
(value
(gnc:gnc-monetary-amount
(gnc:sum-collector-commodity book-balance
report-commodity
exchange-fn)))
(cost
(gnc:gnc-monetary-amount
(gnc:sum-collector-commodity book-balance
report-commodity
weighted-fn)))
(unrealized-gain (gnc-numeric-sub-fixed value cost)))
(unrealized-gain-collector 'add report-commodity unrealized-gain)
unrealized-gain-collector
)
)
;; If you ask me, any outstanding(TM) retained earnings and ;; If you ask me, any outstanding(TM) retained earnings and
;; unrealized gains should be added directly into equity, ;; unrealized gains should be added directly into equity,
@ -553,7 +535,8 @@
(net-investment 'minusmerge neg-pre-closing-equity #f);; > 0 (net-investment 'minusmerge neg-pre-closing-equity #f);; > 0
(net-investment 'merge neg-start-equity-balance #f) ;; net increase (net-investment 'merge neg-start-equity-balance #f) ;; net increase
(set! withdrawals (account-get-total-flow 'in equity-accounts start-date end-date)) (set! withdrawals
(account-get-total-flow 'in equity-accounts start-date end-date))
(set! investments (gnc:make-commodity-collector)) (set! investments (gnc:make-commodity-collector))
(investments 'merge net-investment #f) (investments 'merge net-investment #f)