[transaction] convert add-split-row to functional style

This commit removes need for row-contents, building a list of
table-cells directly.
This commit is contained in:
Christopher Lam 2018-08-20 10:30:35 +08:00
parent f3100ddc0a
commit 83ad9e4b89

View File

@ -1509,65 +1509,46 @@ be excluded from periodic reporting.")
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (add-split-row split cell-calculators row-style transaction-row?) (define (add-split-row split cell-calculators row-style transaction-row?)
(let* ((row-contents '()) (let* ((account (xaccSplitGetAccount split))
(trans (xaccSplitGetParent split)) (reversible-account? (if account-types-to-reverse
(account (xaccSplitGetAccount split))) (member (xaccAccountGetType account)
account-types-to-reverse)
(gnc-reverse-balance account)))
(cells (map (lambda (cell)
(let* ((split->monetary (vector-ref cell 1)))
(vector (split->monetary split)
(vector-ref cell 2) ;reverse?
(vector-ref cell 3) ;subtotal?
)))
cell-calculators)))
(define left-cols (unless (column-uses? 'subtotals-only)
(gnc:html-table-append-row/markup!
table row-style
(append
(gnc:html-make-empty-cells indent-level)
(map (lambda (left-col) (map (lambda (left-col)
(let* ((col-fn (vector-ref left-col 1)) ((vector-ref left-col 1)
(col-data (col-fn split transaction-row?))) split transaction-row?))
col-data)) left-columns)
left-columns))
(define cells
(map (lambda (cell) (map (lambda (cell)
(let* ((calculator (vector-ref cell 1)) (let ((cell-monetary (vector-ref cell 0))
(reverse? (vector-ref cell 2))
(subtotal? (vector-ref cell 3))
(calculated (calculator split)))
(vector calculated
reverse?
subtotal?)))
cell-calculators))
(for-each (lambda (cell) (addto! row-contents cell))
(gnc:html-make-empty-cells indent-level))
(for-each (lambda (col)
(addto! row-contents col))
left-cols)
(for-each (lambda (cell)
(let ((cell-content (vector-ref cell 0))
;; reverse? returns a bool - will check if the cell type has reversible sign,
;; whether the account is also reversible according to Report Option, or
;; if Report Option follows Global Settings, will retrieve bool from it.
(reverse? (and (vector-ref cell 1) (reverse? (and (vector-ref cell 1)
(if account-types-to-reverse reversible-account?)))
(member (xaccAccountGetType account) account-types-to-reverse) (and cell-monetary
(gnc-reverse-balance account)))))
(if cell-content
(addto! row-contents
(gnc:make-html-table-cell/markup (gnc:make-html-table-cell/markup
"number-cell" "number-cell"
(gnc:html-transaction-anchor (gnc:html-transaction-anchor
trans (xaccSplitGetParent split)
;; if conditions for reverse are satisfied, apply sign reverse to
;; monetary amount
(if reverse? (if reverse?
(gnc:monetary-neg cell-content) (gnc:monetary-neg cell-monetary)
cell-content)))) cell-monetary))))))
(addto! row-contents (gnc:html-make-empty-cell))))) cells))))
cells)
(if (not (column-uses? 'subtotals-only))
(gnc:html-table-append-row/markup! table row-style (reverse row-contents)))
(map (lambda (cell) (map (lambda (cell)
(let ((cell-content (vector-ref cell 0)) (let ((cell-monetary (vector-ref cell 0))
(subtotal? (vector-ref cell 2))) (subtotal? (vector-ref cell 2)))
(and subtotal? cell-content))) (and subtotal? cell-monetary)))
cells))) cells)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;