From 8d3d711a0e7ffdbc09a1f0cefab42244a19de9a2 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 9 Dec 2023 23:16:51 +0800 Subject: [PATCH 1/3] [trep-engine] use record for subtotal-table-cell data instead of vector... to be more expressive (and less bug-prone) --- gnucash/report/trep-engine.scm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index d2da97cc78..0cc85742e1 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -2015,12 +2015,19 @@ be excluded from periodic reporting.") calculated-cells total-collectors))))) (values table grid csvlist)))) +(define-record-type :subtotal-table-cell + (make-subtotal-table-cell row col data) + subtotal-table-cell? + (row get-subtotal-table-cell-row) + (col get-subtotal-table-cell-col) + (data get-subtotal-table-cell-data)) + ;; grid data structure (define (make-grid) '()) (define (cell-match? cell row col) - (and (or (not row) (equal? row (vector-ref cell 0))) - (or (not col) (equal? col (vector-ref cell 1))))) + (and (or (not row) (equal? row (get-subtotal-table-cell-row cell))) + (or (not col) (equal? col (get-subtotal-table-cell-col cell))))) (define (grid-get grid row col) ;; grid filter - get all row/col - if #f then retrieve whole row/col (filter @@ -2028,13 +2035,13 @@ be excluded from periodic reporting.") (cell-match? cell row col)) grid)) (define (grid-rows grid) - (delete-duplicates (map (lambda (cell) (vector-ref cell 0)) grid))) + (delete-duplicates (map get-subtotal-table-cell-row grid))) (define (grid-cols grid) - (delete-duplicates (map (lambda (cell) (vector-ref cell 1)) grid))) + (delete-duplicates (map get-subtotal-table-cell-col grid))) (define (grid-add grid row col data) ;; we don't need to check for duplicate cells in a row/col because ;; in the trep it should never happen. - (cons (vector row col data) grid)) + (cons (make-subtotal-table-cell row col data) grid)) (define (grid->html-table grid) (define ( Date: Sun, 10 Dec 2023 00:15:59 +0800 Subject: [PATCH 2/3] [trep-engine] subtotal table: for non-average columns divisor is #f cleaner than using divisor of 1 --- gnucash/report/trep-engine.scm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index 0cc85742e1..0113372bb5 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -2071,18 +2071,20 @@ be excluded from periodic reporting.") (if (null? cell) "" (gnc:make-html-table-cell/markup "number-cell" - (monetary-div - (list-ref-safe (get-subtotal-table-cell-data (car cell)) commodity-idx) - divisor))))) + (gnc:make-html-text + (let ((subtotal (list-ref-safe (get-subtotal-table-cell-data (car cell)) commodity-idx))) + (if divisor + (monetary-div subtotal divisor) + subtotal))))))) (define (make-row row commodity-idx) (append (list (cond ((positive? commodity-idx) "") ((eq? row 'row-total) (G_ "Grand Total")) (else (cdr row)))) - (map (lambda (col) (make-table-cell row col commodity-idx 1)) + (map (lambda (col) (make-table-cell row col commodity-idx #f)) list-of-cols) - (list (make-table-cell row 'col-total commodity-idx 1)) + (list (make-table-cell row 'col-total commodity-idx #f)) (if row-average-enabled? (list (make-table-cell row 'col-total commodity-idx (length list-of-cols))) From d81636bb6ca6350aa1e7d6c65239914faf31f63e Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 9 Dec 2023 23:57:07 +0800 Subject: [PATCH 3/3] [trep-engine] add anchor from subtotal-table to relevant subtotal --- gnucash/report/trep-engine.scm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index 0113372bb5..ba5148e799 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -1652,14 +1652,22 @@ be excluded from periodic reporting.") (gnc-commodity-equal commodity (gnc:gnc-monetary-commodity mon))) list-of-monetary)) + (define anchor + (gensym "subtotals")) + + (define (cell-add-id cell) + (gnc:html-table-cell-set-style! cell "total-label-cell" 'attribute (list "id" anchor)) + cell) + (define (first-column string) (if (report-uses? 'export-table) (cons - (gnc:make-html-table-cell/markup "total-label-cell" string) + (cell-add-id (gnc:make-html-table-cell/markup "total-label-cell" string)) (gnc:html-make-empty-cells (+ right-indent width-left-columns -1))) (list - (gnc:make-html-table-cell/size/markup - 1 (+ right-indent width-left-columns) "total-label-cell" string)))) + (cell-add-id + (gnc:make-html-table-cell/size/markup + 1 (+ right-indent width-left-columns) "total-label-cell" string))))) (define (data-columns commodity) (let loop ((merging? #f) @@ -1718,7 +1726,7 @@ be excluded from periodic reporting.") zero)))) (set! grid - (grid-add grid row col (map get-commodity-grid-amount list-of-commodities))) + (grid-add grid row col (map get-commodity-grid-amount list-of-commodities) anchor)) ;; each commodity subtotal gets a separate line in the html-table ;; each line comprises: indenting, first-column, data-columns @@ -2016,11 +2024,12 @@ be excluded from periodic reporting.") (values table grid csvlist)))) (define-record-type :subtotal-table-cell - (make-subtotal-table-cell row col data) + (make-subtotal-table-cell row col data anchor) subtotal-table-cell? (row get-subtotal-table-cell-row) (col get-subtotal-table-cell-col) - (data get-subtotal-table-cell-data)) + (data get-subtotal-table-cell-data) + (anchor get-subtotal-table-cell-anchor)) ;; grid data structure (define (make-grid) @@ -2038,10 +2047,10 @@ be excluded from periodic reporting.") (delete-duplicates (map get-subtotal-table-cell-row grid))) (define (grid-cols grid) (delete-duplicates (map get-subtotal-table-cell-col grid))) -(define (grid-add grid row col data) +(define (grid-add grid row col data anchor) ;; we don't need to check for duplicate cells in a row/col because ;; in the trep it should never happen. - (cons (make-subtotal-table-cell row col data) grid)) + (cons (make-subtotal-table-cell row col data anchor) grid)) (define (grid->html-table grid) (define (