From 4380f1b85abbeac4724c6a322fc3252eb6e5d531 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 30 Dec 2023 21:20:13 +0800 Subject: [PATCH] [trep-engine] accumulate subtotals within add-split-row it's cleaner; add-split-row won't need to return a monetary to be processed later. --- gnucash/report/trep-engine.scm | 65 ++++++++++++++++------------------ 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index d2da97cc788..96d9c017f34 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -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 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1841,10 +1850,21 @@ 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)))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1852,15 +1872,6 @@ be excluded from periodic reporting.") ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (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)) @@ -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 @@ -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)