Skip to content

Commit

Permalink
[trep-engine] accumulate subtotals within add-split-row
Browse files Browse the repository at this point in the history
it's cleaner; add-split-row won't need to return a monetary to be
processed later.
  • Loading branch information
christopherlam committed Dec 30, 2023
1 parent 56e2425 commit 4380f1b
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions gnucash/report/trep-engine.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,15 @@ be excluded from periodic reporting.")
(define (render-grand-total)
(G_ "Grand Total"))

(define primary-subtotal-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

(define secondary-subtotal-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

(define total-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; add-split-row
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1841,26 +1850,28 @@ be excluded from periodic reporting.")
cell-content)))))
cell-calculators))))

(map (lambda (cell)
(and (assq-ref cell 'subtotal?)
((assq-ref cell 'calc-fn) split transaction-row?)))
cell-calculators)))
(when transaction-row?
(for-each
(lambda (prime-collector sec-collector tot-collector cell)
(when (assq-ref cell 'subtotal?)
(let ((value ((assq-ref cell 'calc-fn) split transaction-row?)))
(when value
(let ((comm (gnc:gnc-monetary-commodity value))
(amt (gnc:gnc-monetary-amount value)))
(prime-collector 'add comm amt)
(sec-collector 'add comm amt)
(tot-collector 'add comm amt))))))
primary-subtotal-collectors
secondary-subtotal-collectors
total-collectors
cell-calculators))))

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

;; do-rows-with-subtotals

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

(define primary-subtotal-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

(define secondary-subtotal-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

(define total-collectors
(map (lambda (x) (gnc:make-commodity-collector)) calculated-cells))

(define grid (make-grid))
(define primary-subtotal-comparator (report-uses? 'primary-key/split-sortvalue))
(define secondary-subtotal-comparator (report-uses? 'secondary-key/split-sortvalue))
Expand Down Expand Up @@ -1901,14 +1912,13 @@ be excluded from periodic reporting.")

(let* ((current (car splits))
(rest (cdr splits))
(next (and (pair? rest) (car rest)))
(split-values (add-split-row
current
calculated-cells
(if (or odd-row? (report-uses? 'multiline))
def:normal-row-style
def:alternate-row-style)
#t)))
(next (and (pair? rest) (car rest))))

(add-split-row current calculated-cells
(if (or odd-row? (report-uses? 'multiline))
def:normal-row-style
def:alternate-row-style)
#t)

(when (report-uses? 'multiline)
(for-each
Expand All @@ -1918,19 +1928,6 @@ be excluded from periodic reporting.")
(delete current (xaccTransGetSplitList
(xaccSplitGetParent current)))))

(for-each
(lambda (prime-collector sec-collector tot-collector value)
(when (gnc:gnc-monetary? value)
(let ((comm (gnc:gnc-monetary-commodity value))
(val (gnc:gnc-monetary-amount value)))
(prime-collector 'add comm val)
(sec-collector 'add comm val)
(tot-collector 'add comm val))))
primary-subtotal-collectors
secondary-subtotal-collectors
total-collectors
split-values)

(cond
((and primary-subtotal-comparator
(or (not next)
Expand Down

0 comments on commit 4380f1b

Please sign in to comment.