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