TR: omit display of $0 in subtotals in other currencies.

Previously in dual-subtotal columns, the dual-subtotal would
attempt to print all commodities in the row. This meant
if user chose common-currency thereby triggering additional
commodities, the dual-subtotal would attempt to add amounts
in other commodities which would be 0, and display the 0
amount. This commit will modify the the dual-subtotal strategy
to only add column where a value actually exists.

This commit is a continuation of previous TR enhancement
(multiple data columns) where I have now understood how
to disable these $0 amounts in subtotals.

From: http://i.imgur.com/sqAHsPQ.png
To:   http://i.imgur.com/n0R7xeV.png
This commit is contained in:
Christopher Lam 2018-01-28 07:29:44 +08:00
parent 12f3099f59
commit 3749ca528b

View File

@ -1113,50 +1113,43 @@ tags within description, notes or memo. ")
;; calculator-function ;; (calculator-function split) to obtain amount ;; calculator-function ;; (calculator-function split) to obtain amount
;; reverse-column? ;; to optionally reverse signs ;; reverse-column? ;; to optionally reverse signs
;; subtotal? ;; subtotal? to allow subtotals (ie irrelevant for running balance) ;; subtotal? ;; subtotal? to allow subtotals (ie irrelevant for running balance)
;; (vector start-dual-column? ;; #t for the left side of a dual column (i.e. debit/credit) ;; start-dual-column? ;; #t for the left side of a dual column (i.e. debit/credit)
;; merging-function)) ;; function to apply to dual-subtotal (+ / -) ;; ;; which means the next column will be the right side
;; friendly-heading-fn ;; retrieve friendly heading name for account debit/credit ;; friendly-heading-fn ;; retrieve friendly heading name for account debit/credit
(if (column-uses? 'amount-single) (if (column-uses? 'amount-single)
(list (vector (header-commodity (_ "Amount")) (list (vector (header-commodity (_ "Amount"))
amount #t #t amount #t #t #f
(vector #f #f)
(lambda (a) ""))) (lambda (a) "")))
'()) '())
(if (column-uses? 'amount-double) (if (column-uses? 'amount-double)
(list (vector (header-commodity (_ "Debit")) (list (vector (header-commodity (_ "Debit"))
debit-amount #f #t debit-amount #f #t #t
(vector #t +)
friendly-debit) friendly-debit)
(vector (header-commodity (_ "Credit")) (vector (header-commodity (_ "Credit"))
credit-amount #f #t credit-amount #f #t #f
(vector #f -)
friendly-credit)) friendly-credit))
'()) '())
(if (and (column-uses? 'amount-original-currency) (if (and (column-uses? 'amount-original-currency)
(column-uses? 'amount-single)) (column-uses? 'amount-single))
(list (vector (_ "Amount") (list (vector (_ "Amount")
original-amount #t #t original-amount #t #t #f
(vector #f #f)
(lambda (a) ""))) (lambda (a) "")))
'()) '())
(if (and (column-uses? 'amount-original-currency) (if (and (column-uses? 'amount-original-currency)
(column-uses? 'amount-double)) (column-uses? 'amount-double))
(list (vector (_ "Debit") (list (vector (_ "Debit")
original-debit-amount #f #t original-debit-amount #f #t #t
(vector #t +)
friendly-debit) friendly-debit)
(vector (_ "Credit") (vector (_ "Credit")
original-credit-amount #f #t original-credit-amount #f #t #f
(vector #f -)
friendly-credit)) friendly-credit))
'()) '())
(if (column-uses? 'running-balance) (if (column-uses? 'running-balance)
(list (vector (_ "Running Balance") (list (vector (_ "Running Balance")
running-balance #t #f running-balance #t #f #f
(vector #f #f)
(lambda (a) ""))) (lambda (a) "")))
'())))) '()))))
@ -1252,35 +1245,36 @@ tags within description, notes or memo. ")
(define (add-columns commodity) (define (add-columns commodity)
(let ((start-dual-column? #f) (let ((start-dual-column? #f)
(dual-subtotal 0)) (dual-subtotal #f))
(for-each (lambda (column merge-entry) (for-each (lambda (column merge-entry)
(let* ((mon (retrieve-commodity column commodity)) (let* ((mon (retrieve-commodity column commodity))
(column-amount (and mon (gnc:gnc-monetary-amount mon))) (column-amount (and mon (gnc:gnc-monetary-amount mon)))
(merge? (vector-ref merge-entry 0)) (merge? merge-entry))
(merge-fn (vector-ref merge-entry 1)))
(if merge? (if merge?
;; We're merging. Run merge-fn (usu + or -) ;; We're merging. If a subtotal exists, store
;; and store total in dual-subtotal. Do NOT add column. ;; it in dual-subtotal. Do NOT add column to row.
(begin (begin
(if column-amount (set! dual-subtotal column-amount)
(set! dual-subtotal
(merge-fn dual-subtotal column-amount)))
(set! start-dual-column? #t)) (set! start-dual-column? #t))
(if start-dual-column? (if start-dual-column?
(begin (begin
;; We've completed merging. Add this column amount ;; We've completed merging. Add the negated
;; and add the columns. ;; column amount and add the columns to row.
(if column-amount (if column-amount
(set! dual-subtotal (set! dual-subtotal
(merge-fn dual-subtotal column-amount))) (- (or dual-subtotal 0) column-amount)))
(if (positive? dual-subtotal) (cond ((not dual-subtotal)
(begin (addto! row-contents "")
(addto! row-contents ""))
((positive? dual-subtotal)
(addto! row-contents (addto! row-contents
(gnc:make-html-table-cell/markup (gnc:make-html-table-cell/markup
"total-number-cell" "total-number-cell"
(gnc:make-gnc-monetary commodity dual-subtotal))) (gnc:make-gnc-monetary
commodity
dual-subtotal)))
(addto! row-contents "")) (addto! row-contents ""))
(begin (else
(addto! row-contents "") (addto! row-contents "")
(addto! row-contents (addto! row-contents
(gnc:make-html-table-cell/markup (gnc:make-html-table-cell/markup
@ -1289,7 +1283,7 @@ tags within description, notes or memo. ")
commodity commodity
(- dual-subtotal)))))) (- dual-subtotal))))))
(set! start-dual-column? #f) (set! start-dual-column? #f)
(set! dual-subtotal 0)) (set! dual-subtotal #f))
;; Default; not merging/completed merge. Just ;; Default; not merging/completed merge. Just
;; display monetary amount ;; display monetary amount
(addto! row-contents (addto! row-contents