[report-utilities] compact functions. no refactoring.

This commit is contained in:
Christopher Lam 2018-08-30 23:08:43 +08:00
parent 512dd7c73c
commit 0144055c43

View File

@ -699,21 +699,15 @@
;; If type is #f, sums all splits in the interval (even closing splits)
(define (gnc:account-get-trans-type-balance-interval-with-closing
account-list type start-date end-date)
(let* ((total (gnc:make-commodity-collector)))
(let ((total (gnc:make-commodity-collector)))
(map (lambda (split)
(let* ((shares (xaccSplitGetAmount split))
(acct-comm (xaccAccountGetCommodity
(xaccSplitGetAccount split)))
)
(gnc-commodity-collector-add total acct-comm shares)
)
)
(xaccSplitGetAccount split))))
(gnc-commodity-collector-add total acct-comm shares)))
(gnc:account-get-trans-type-splits-interval
account-list type start-date end-date)
)
total
)
)
account-list type start-date end-date))
total))
;; Filters the splits from the source to the target accounts
;; returns a commodity collector
@ -904,14 +898,10 @@
(define (gnc:budget-accountlist-helper accountlist get-fn)
(let
(
(net (gnc:make-commodity-collector)))
(let ((net (gnc:make-commodity-collector)))
(for-each
(lambda (account)
(net 'merge
(get-fn account)
#f))
(net 'merge (get-fn account) #f))
accountlist)
net))
@ -923,17 +913,14 @@
;;
;; Returns a commodity-collector.
(define (gnc:budget-account-get-net budget account start-period end-period)
(if (not start-period) (set! start-period 0))
(if (not end-period) (set! end-period (gnc-budget-get-num-periods budget)))
(let*
(
(period start-period)
(let* ((period (or start-period 0))
(net (gnc:make-commodity-collector))
(acct-comm (xaccAccountGetCommodity account)))
(while (< period end-period)
(net 'add acct-comm
(gnc-budget-get-account-period-value budget account period))
(set! period (+ period 1)))
(set! period (1+ period)))
net))
;; Sums budget values for accounts in accountlist from start-period (inclusive)
@ -1016,11 +1003,8 @@
;;
;; Returns a gnc-numeric value
(define (gnc:budget-account-get-rolledup-net budget account start-period end-period)
(if (not start-period) (set! start-period 0))
(if (not end-period) (set! end-period (gnc-budget-get-num-periods budget)))
(let*
(
(period start-period)
(let* ((period (or start-period 0))
(net (gnc-numeric-zero))
(acct-comm (xaccAccountGetCommodity account)))
(while (< period end-period)
@ -1043,28 +1027,19 @@
initial-balances))
(define (gnc:select-assoc-account-balance account-balances account)
(let*
(
(account-balance (car account-balances))
(result
(if
(equal? account-balance '())
#f
(if
(equal? (car account-balance) account)
(car (cdr account-balance))
(let ((account-balance (car account-balances)))
(and (pair? account-balance)
(if (equal? (car account-balance) account)
(cadr account-balance)
(gnc:select-assoc-account-balance
(cdr account-balances)
account)))))
result))
(define (gnc:get-assoc-account-balances-total account-balances)
(let
(
(total (gnc:make-commodity-collector)))
(let ((total (gnc:make-commodity-collector)))
(for-each
(lambda (account-balance)
(total 'merge (car (cdr account-balance)) #f))
(total 'merge (cadr account-balance) #f))
account-balances)
total))