mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
REFACTOR: centralize numerous used-* into column-uses? helper function
This commit is contained in:
parent
02905fe38f
commit
ff0d7cc2c4
@ -154,6 +154,9 @@ options specified in the Options panels."))
|
|||||||
table subheading-style
|
table subheading-style
|
||||||
(list heading-cell))))
|
(list heading-cell))))
|
||||||
|
|
||||||
|
(define (column-uses? param columns-used)
|
||||||
|
(cdr (assq param columns-used)))
|
||||||
|
|
||||||
;; display an account name depending on the options the user has set
|
;; display an account name depending on the options the user has set
|
||||||
(define (account-namestring account show-account-code? show-account-name? show-account-full-name?)
|
(define (account-namestring account show-account-code? show-account-name? show-account-full-name?)
|
||||||
;;# on multi-line splits we can get an empty ('()) account
|
;;# on multi-line splits we can get an empty ('()) account
|
||||||
@ -172,6 +175,8 @@ options specified in the Options panels."))
|
|||||||
(xaccAccountGetName account))
|
(xaccAccountGetName account))
|
||||||
""))))
|
""))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; render an account subheading - column-vector determines what is displayed
|
;; render an account subheading - column-vector determines what is displayed
|
||||||
(define (render-account-subheading
|
(define (render-account-subheading
|
||||||
split table width subheading-style column-vector)
|
split table width subheading-style column-vector)
|
||||||
@ -180,9 +185,9 @@ options specified in the Options panels."))
|
|||||||
(gnc:html-markup-anchor
|
(gnc:html-markup-anchor
|
||||||
(gnc:account-anchor-text account)
|
(gnc:account-anchor-text account)
|
||||||
(account-namestring account
|
(account-namestring account
|
||||||
(used-sort-account-code column-vector)
|
(column-uses? 'sort-account-code column-vector)
|
||||||
#t
|
#t
|
||||||
(used-sort-account-full-name column-vector))))
|
(column-uses? 'sort-account-full-name column-vector))))
|
||||||
table width subheading-style)))
|
table width subheading-style)))
|
||||||
|
|
||||||
(define (render-corresponding-account-subheading
|
(define (render-corresponding-account-subheading
|
||||||
@ -194,9 +199,9 @@ options specified in the Options panels."))
|
|||||||
""
|
""
|
||||||
(gnc:account-anchor-text account))
|
(gnc:account-anchor-text account))
|
||||||
(account-namestring account
|
(account-namestring account
|
||||||
(used-sort-account-code column-vector)
|
(column-uses? 'sort-account-code column-vector)
|
||||||
#t
|
#t
|
||||||
(used-sort-account-full-name column-vector))))
|
(column-uses? 'sort-account-full-name column-vector))))
|
||||||
table width subheading-style)))
|
table width subheading-style)))
|
||||||
|
|
||||||
(define (render-week-subheading split table width subheading-style column-vector)
|
(define (render-week-subheading split table width subheading-style column-vector)
|
||||||
@ -262,9 +267,9 @@ options specified in the Options panels."))
|
|||||||
table width split total-collector subtotal-style column-vector export?)
|
table width split total-collector subtotal-style column-vector export?)
|
||||||
(add-subtotal-row table width
|
(add-subtotal-row table width
|
||||||
(total-string (account-namestring (xaccSplitGetAccount split)
|
(total-string (account-namestring (xaccSplitGetAccount split)
|
||||||
(used-sort-account-code column-vector)
|
(column-uses? 'sort-account-code column-vector)
|
||||||
#t
|
#t
|
||||||
(used-sort-account-full-name column-vector)))
|
(column-uses? 'sort-account-full-name column-vector)))
|
||||||
total-collector subtotal-style export?))
|
total-collector subtotal-style export?))
|
||||||
|
|
||||||
(define (render-corresponding-account-subtotal
|
(define (render-corresponding-account-subtotal
|
||||||
@ -272,9 +277,9 @@ options specified in the Options panels."))
|
|||||||
(add-subtotal-row table width
|
(add-subtotal-row table width
|
||||||
(total-string (account-namestring (xaccSplitGetAccount
|
(total-string (account-namestring (xaccSplitGetAccount
|
||||||
(xaccSplitGetOtherSplit split))
|
(xaccSplitGetOtherSplit split))
|
||||||
(used-sort-account-code column-vector)
|
(column-uses? 'sort-account-code column-vector)
|
||||||
#t
|
#t
|
||||||
(used-sort-account-full-name column-vector)))
|
(column-uses? 'sort-account-full-name column-vector)))
|
||||||
total-collector subtotal-style export?))
|
total-collector subtotal-style export?))
|
||||||
|
|
||||||
(define (render-week-subtotal
|
(define (render-week-subtotal
|
||||||
@ -348,95 +353,99 @@ options specified in the Options panels."))
|
|||||||
;; likely match a price on the previous day
|
;; likely match a price on the previous day
|
||||||
(timespecCanonicalDayTime trans-date))))
|
(timespecCanonicalDayTime trans-date))))
|
||||||
|
|
||||||
(if (used-date column-vector)
|
(if (column-uses? 'date column-vector)
|
||||||
(addto! row-contents
|
(addto! row-contents
|
||||||
(if transaction-row?
|
(if transaction-row?
|
||||||
(gnc:make-html-table-cell/markup "date-cell"
|
(gnc:make-html-table-cell/markup
|
||||||
(gnc-print-date (gnc-transaction-get-date-posted parent)))
|
"date-cell"
|
||||||
" ")))
|
(gnc-print-date trans-date))
|
||||||
|
"")))
|
||||||
|
|
||||||
|
(if (column-uses? 'reconciled-date column-vector)
|
||||||
|
(addto! row-contents
|
||||||
|
(gnc:make-html-table-cell/markup
|
||||||
|
"date-cell"
|
||||||
|
(let ((date (gnc-split-get-date-reconciled split)))
|
||||||
|
(if (equal? date (cons 0 0))
|
||||||
|
""
|
||||||
|
(gnc-print-date date))))))
|
||||||
|
|
||||||
(if (used-reconciled-date column-vector)
|
(if (column-uses? 'num column-vector)
|
||||||
(addto! row-contents
|
|
||||||
(gnc:make-html-table-cell/markup "date-cell"
|
|
||||||
(let ((date (gnc-split-get-date-reconciled split)))
|
|
||||||
(if (equal? date (cons 0 0))
|
|
||||||
" "
|
|
||||||
(gnc-print-date date))))))
|
|
||||||
(if (used-num column-vector)
|
|
||||||
(addto! row-contents
|
(addto! row-contents
|
||||||
(if transaction-row?
|
(if transaction-row?
|
||||||
(if (qof-book-use-split-action-for-num-field
|
(if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
|
||||||
(gnc-get-current-book))
|
|
||||||
(let* ((num (gnc-get-num-action parent split))
|
(let* ((num (gnc-get-num-action parent split))
|
||||||
(t-num (if (if (gnc:lookup-option options gnc:pagename-display
|
(t-num (if (if (gnc:lookup-option options gnc:pagename-display
|
||||||
(N_ "Trans Number"))
|
(N_ "Trans Number"))
|
||||||
(opt-val gnc:pagename-display (N_ "Trans Number"))
|
(opt-val gnc:pagename-display (N_ "Trans Number"))
|
||||||
#f)
|
"")
|
||||||
(gnc-get-num-action parent #f)
|
(gnc-get-num-action parent #f)
|
||||||
""))
|
""))
|
||||||
(num-string (if (string-null? t-num)
|
(num-string (if (string-null? t-num)
|
||||||
num
|
num
|
||||||
(string-append num "/" t-num))))
|
(string-append num "/" t-num))))
|
||||||
(gnc:make-html-table-cell/markup "text-cell"
|
(gnc:make-html-table-cell/markup "text-cell" num-string))
|
||||||
num-string))
|
|
||||||
(gnc:make-html-table-cell/markup "text-cell"
|
(gnc:make-html-table-cell/markup "text-cell"
|
||||||
(gnc-get-num-action parent split)))
|
(gnc-get-num-action parent split)))
|
||||||
" ")))
|
"")))
|
||||||
|
|
||||||
(if (used-description column-vector)
|
(if (column-uses? 'description column-vector)
|
||||||
(addto! row-contents
|
(addto! row-contents
|
||||||
(if transaction-row?
|
(if transaction-row?
|
||||||
(gnc:make-html-table-cell/markup "text-cell"
|
(gnc:make-html-table-cell/markup
|
||||||
(xaccTransGetDescription parent))
|
"text-cell"
|
||||||
" ")))
|
(xaccTransGetDescription parent))
|
||||||
|
"")))
|
||||||
|
|
||||||
(if (used-memo column-vector)
|
(if (column-uses? 'memo column-vector)
|
||||||
(let ((memo (xaccSplitGetMemo split)))
|
(let ((memo (xaccSplitGetMemo split)))
|
||||||
(if (and (equal? memo "") (used-notes column-vector))
|
(if (and (string-null? memo) (column-uses? 'notes column-vector))
|
||||||
(addto! row-contents (xaccTransGetNotes parent))
|
(addto! row-contents (xaccTransGetNotes parent))
|
||||||
(addto! row-contents memo))))
|
(addto! row-contents memo))))
|
||||||
|
|
||||||
(if (or (used-account-name column-vector) (used-account-code column-vector))
|
(if (or (column-uses? 'account-name column-vector) (column-uses? 'account-code column-vector))
|
||||||
(addto! row-contents (account-namestring account
|
(addto! row-contents (account-namestring account
|
||||||
(used-account-code column-vector)
|
(column-uses? 'account-code column-vector)
|
||||||
(used-account-name column-vector)
|
(column-uses? 'account-name column-vector)
|
||||||
(used-account-full-name column-vector))))
|
(column-uses? 'account-full-name column-vector))))
|
||||||
|
|
||||||
(if (or (used-other-account-name column-vector) (used-other-account-code column-vector))
|
(if (or (column-uses? 'other-account-name column-vector) (column-uses? 'other-account-code column-vector))
|
||||||
(addto! row-contents (account-namestring (xaccSplitGetAccount
|
(addto! row-contents (account-namestring (xaccSplitGetAccount (xaccSplitGetOtherSplit split))
|
||||||
(xaccSplitGetOtherSplit split))
|
(column-uses? 'other-account-code column-vector)
|
||||||
(used-other-account-code column-vector)
|
(column-uses? 'other-account-name column-vector)
|
||||||
(used-other-account-name column-vector)
|
(column-uses? 'other-account-full-name column-vector))))
|
||||||
(used-other-account-full-name column-vector))))
|
|
||||||
|
|
||||||
(if (used-shares column-vector)
|
(if (column-uses? 'shares column-vector)
|
||||||
(addto! row-contents (xaccSplitGetAmount split)))
|
(addto! row-contents (xaccSplitGetAmount split)))
|
||||||
|
|
||||||
|
(if (column-uses? 'price column-vector)
|
||||||
|
(addto! row-contents (gnc:make-gnc-monetary (xaccTransGetCurrency parent)
|
||||||
|
(xaccSplitGetSharePrice split))))
|
||||||
|
|
||||||
(if (used-price column-vector)
|
(if (column-uses? 'amount-single column-vector)
|
||||||
(addto! row-contents
|
(addto! row-contents
|
||||||
(gnc:make-gnc-monetary (xaccTransGetCurrency parent)
|
(gnc:make-html-table-cell/markup
|
||||||
(xaccSplitGetSharePrice split))))
|
"number-cell" (gnc:html-transaction-anchor parent split-value))))
|
||||||
|
|
||||||
(if (used-amount-single column-vector)
|
(if (column-uses? 'amount-double column-vector)
|
||||||
(addto! row-contents
|
|
||||||
(gnc:make-html-table-cell/markup "number-cell"
|
|
||||||
(gnc:html-transaction-anchor parent split-value))))
|
|
||||||
|
|
||||||
(if (used-amount-double-positive column-vector)
|
|
||||||
(if (gnc-numeric-positive-p (gnc:gnc-monetary-amount split-value))
|
(if (gnc-numeric-positive-p (gnc:gnc-monetary-amount split-value))
|
||||||
(addto! row-contents
|
|
||||||
(gnc:make-html-table-cell/markup "number-cell"
|
(begin
|
||||||
(gnc:html-transaction-anchor parent split-value)))
|
(addto! row-contents
|
||||||
(addto! row-contents " ")))
|
(gnc:make-html-table-cell/markup
|
||||||
|
"number-cell" (gnc:html-transaction-anchor
|
||||||
|
parent split-value)))
|
||||||
|
(addto! row-contents ""))
|
||||||
|
|
||||||
|
(begin
|
||||||
|
(addto! row-contents "")
|
||||||
|
(addto! row-contents
|
||||||
|
(gnc:make-html-table-cell/markup
|
||||||
|
"number-cell" (gnc:html-transaction-anchor
|
||||||
|
parent (gnc:monetary-neg split-value)))))))
|
||||||
|
|
||||||
(if (used-amount-double-negative column-vector)
|
(if (column-uses? 'running-balance column-vector)
|
||||||
(if (gnc-numeric-negative-p (gnc:gnc-monetary-amount split-value))
|
|
||||||
(addto! row-contents
|
|
||||||
(gnc:make-html-table-cell/markup
|
|
||||||
"number-cell" (gnc:html-transaction-anchor parent (gnc:monetary-neg split-value))))
|
|
||||||
(addto! row-contents " ")))
|
|
||||||
|
|
||||||
(if (used-running-balance column-vector)
|
|
||||||
(begin
|
(begin
|
||||||
;(gnc:debug "split is " split)
|
;(gnc:debug "split is " split)
|
||||||
;(gnc:debug "split get balance:" (xaccSplitGetBalance split))
|
;(gnc:debug "split get balance:" (xaccSplitGetBalance split))
|
||||||
@ -943,92 +952,73 @@ Credit Card, and Income accounts."))))))
|
|||||||
|
|
||||||
(define (opt-val section name) (gnc:option-value (gnc:lookup-option options section name)))
|
(define (opt-val section name) (gnc:option-value (gnc:lookup-option options section name)))
|
||||||
|
|
||||||
(define (used-date columns-used) (vector-ref columns-used 0))
|
|
||||||
(define (used-reconciled-date columns-used) (vector-ref columns-used 1))
|
|
||||||
(define (used-num columns-used) (vector-ref columns-used 2))
|
|
||||||
(define (used-description columns-used) (vector-ref columns-used 3))
|
|
||||||
(define (used-account-name columns-used) (vector-ref columns-used 4))
|
|
||||||
(define (used-other-account-name columns-used) (vector-ref columns-used 5))
|
|
||||||
(define (used-shares columns-used) (vector-ref columns-used 6))
|
|
||||||
(define (used-price columns-used) (vector-ref columns-used 7))
|
|
||||||
(define (used-amount-single columns-used) (vector-ref columns-used 8))
|
|
||||||
(define (used-amount-double-positive columns-used) (vector-ref columns-used 9))
|
|
||||||
(define (used-amount-double-negative columns-used) (vector-ref columns-used 10))
|
|
||||||
(define (used-running-balance columns-used) (vector-ref columns-used 11))
|
|
||||||
(define (used-account-full-name columns-used) (vector-ref columns-used 12))
|
|
||||||
(define (used-memo columns-used) (vector-ref columns-used 13))
|
|
||||||
(define (used-account-code columns-used) (vector-ref columns-used 14))
|
|
||||||
(define (used-other-account-code columns-used) (vector-ref columns-used 15))
|
|
||||||
(define (used-other-account-full-name columns-used) (vector-ref columns-used 16))
|
|
||||||
(define (used-sort-account-code columns-used) (vector-ref columns-used 17))
|
|
||||||
(define (used-sort-account-full-name columns-used) (vector-ref columns-used 18))
|
|
||||||
(define (used-notes columns-used) (vector-ref columns-used 19))
|
|
||||||
|
|
||||||
(define (build-columns-used)
|
(define (build-columns-used)
|
||||||
(define is-single? (eq? (opt-val gnc:pagename-display optname-detail-level) 'single))
|
(define is-single? (eq? (opt-val gnc:pagename-display optname-detail-level) 'single))
|
||||||
(define amount-setting (opt-val gnc:pagename-display (N_ "Amount")))
|
(define amount-setting (opt-val gnc:pagename-display (N_ "Amount")))
|
||||||
(vector
|
(list (cons 'date (opt-val gnc:pagename-display (N_ "Date")))
|
||||||
(opt-val gnc:pagename-display (N_ "Date"))
|
(cons 'reconciled-date (opt-val gnc:pagename-display (N_ "Reconciled Date")))
|
||||||
(opt-val gnc:pagename-display (N_ "Reconciled Date"))
|
(cons 'num (if (gnc:lookup-option options gnc:pagename-display (N_ "Num"))
|
||||||
(if (gnc:lookup-option options gnc:pagename-display (N_ "Num"))
|
(opt-val gnc:pagename-display (N_ "Num"))
|
||||||
(opt-val gnc:pagename-display (N_ "Num"))
|
(opt-val gnc:pagename-display (N_ "Num/Action"))))
|
||||||
(opt-val gnc:pagename-display (N_ "Num/Action")))
|
(cons 'description (opt-val gnc:pagename-display (N_ "Description")))
|
||||||
(opt-val gnc:pagename-display (N_ "Description"))
|
(cons 'account-name (opt-val gnc:pagename-display (N_ "Account Name")))
|
||||||
(opt-val gnc:pagename-display (N_ "Account Name"))
|
(cons 'other-account-name (and is-single?
|
||||||
(and is-single? (opt-val gnc:pagename-display (N_ "Other Account Name")))
|
(opt-val gnc:pagename-display (N_ "Other Account Name"))))
|
||||||
(opt-val gnc:pagename-display (N_ "Shares"))
|
(cons 'shares (opt-val gnc:pagename-display (N_ "Shares")))
|
||||||
(opt-val gnc:pagename-display (N_ "Price"))
|
(cons 'price (opt-val gnc:pagename-display (N_ "Price")))
|
||||||
(eq? amount-setting 'single)
|
(cons 'amount-single (eq? amount-setting 'single))
|
||||||
(eq? amount-setting 'double)
|
(cons 'amount-double (eq? amount-setting 'double))
|
||||||
(eq? amount-setting 'double)
|
(cons 'running-balance (opt-val gnc:pagename-display (N_ "Running Balance")))
|
||||||
(opt-val gnc:pagename-display (N_ "Running Balance"))
|
(cons 'account-full-name (opt-val gnc:pagename-display (N_ "Use Full Account Name")))
|
||||||
(opt-val gnc:pagename-display (N_ "Use Full Account Name"))
|
(cons 'memo (opt-val gnc:pagename-display (N_ "Memo")))
|
||||||
(opt-val gnc:pagename-display (N_ "Memo"))
|
(cons 'account-code (opt-val gnc:pagename-display (N_ "Account Code")))
|
||||||
(opt-val gnc:pagename-display (N_ "Account Code"))
|
(cons 'other-account-code (and is-single?
|
||||||
(and is-single? (opt-val gnc:pagename-display (N_ "Other Account Code")))
|
(opt-val gnc:pagename-display (N_ "Other Account Code"))))
|
||||||
(and is-single? (opt-val gnc:pagename-display (N_ "Use Full Other Account Name")))
|
(cons 'other-account-full-name (and is-single?
|
||||||
(opt-val pagename-sorting (N_ "Show Account Code"))
|
(opt-val gnc:pagename-display (N_ "Use Full Other Account Name"))))
|
||||||
(opt-val pagename-sorting (N_ "Show Full Account Name"))
|
(cons 'sort-account-code (opt-val pagename-sorting (N_ "Show Account Code")))
|
||||||
(opt-val gnc:pagename-display (N_ "Notes"))))
|
(cons 'sort-account-full-name (opt-val pagename-sorting (N_ "Show Full Account Name")))
|
||||||
|
(cons 'notes (opt-val gnc:pagename-display (N_ "Notes")))))
|
||||||
|
|
||||||
(define (make-heading-list columns-used)
|
(define (make-heading-list columns-used)
|
||||||
(define (add-if pred? item) (if pred? (list item) '()))
|
(define (add-if pred? item) (if pred? (list item) '()))
|
||||||
(append
|
(append
|
||||||
(add-if (used-date columns-used)
|
(add-if (column-uses? 'date columns-used)
|
||||||
(_ "Date"))
|
(_ "Date"))
|
||||||
(add-if (used-reconciled-date columns-used)
|
(add-if (column-uses? 'reconciled-date columns-used)
|
||||||
(_ "Reconciled Date"))
|
(_ "Reconciled Date"))
|
||||||
(add-if (used-num columns-used)
|
(add-if (column-uses? 'num columns-used)
|
||||||
(if (and (qof-book-use-split-action-for-num-field (gnc-get-current-book))
|
(if (and (qof-book-use-split-action-for-num-field (gnc-get-current-book))
|
||||||
(if (gnc:lookup-option options gnc:pagename-display (N_ "Trans Number"))
|
(if (gnc:lookup-option options gnc:pagename-display (N_ "Trans Number"))
|
||||||
(opt-val gnc:pagename-display (N_ "Trans Number"))
|
(opt-val gnc:pagename-display (N_ "Trans Number"))
|
||||||
#f))
|
#f))
|
||||||
(_ "Num/T-Num")
|
(_ "Num/T-Num")
|
||||||
(_ "Num")))
|
(_ "Num")))
|
||||||
(add-if (used-description columns-used)
|
(add-if (column-uses? 'description columns-used)
|
||||||
(_ "Description"))
|
(_ "Description"))
|
||||||
(add-if (used-memo columns-used)
|
(add-if (column-uses? 'memo columns-used)
|
||||||
(if (used-notes columns-used)
|
(if (column-uses? 'notes columns-used)
|
||||||
(string-append (_ "Memo") "/" (_ "Notes"))
|
(string-append (_ "Memo") "/" (_ "Notes"))
|
||||||
(_ "Memo")))
|
(_ "Memo")))
|
||||||
(add-if (or (used-account-name columns-used)
|
(add-if (or (column-uses? 'account-name columns-used)
|
||||||
(used-account-code columns-used))
|
(column-uses? 'account-code columns-used))
|
||||||
(_ "Account"))
|
(_ "Account"))
|
||||||
(add-if (or (used-other-account-name columns-used)
|
(add-if (or (column-uses? 'other-account-name columns-used)
|
||||||
(used-other-account-code columns-used))
|
(column-uses? 'other-account-code columns-used))
|
||||||
(_ "Transfer from/to"))
|
(_ "Transfer from/to"))
|
||||||
(add-if (used-shares columns-used)
|
(add-if (column-uses? 'shares columns-used)
|
||||||
(_ "Shares"))
|
(_ "Shares"))
|
||||||
(add-if (used-price columns-used)
|
(add-if (column-uses? 'price columns-used)
|
||||||
(_ "Price"))
|
(_ "Price"))
|
||||||
(add-if (used-amount-single columns-used)
|
(add-if (column-uses? 'amount-single columns-used)
|
||||||
(_ "Amount"))
|
(_ "Amount"))
|
||||||
;; FIXME: Proper labels: what?
|
;; FIXME: Proper labels: what?
|
||||||
(add-if (used-amount-double-positive columns-used)
|
(if (column-uses? 'amount-double columns-used)
|
||||||
(_ "Debit"))
|
(list
|
||||||
(add-if (used-amount-double-negative columns-used)
|
(_ "Debit")
|
||||||
(_ "Credit"))
|
(_ "Credit"))
|
||||||
(add-if (used-running-balance columns-used)
|
'())
|
||||||
|
(add-if (column-uses? 'running-balance columns-used)
|
||||||
(_ "Balance"))))
|
(_ "Balance"))))
|
||||||
|
|
||||||
(let ((work-to-do (length splits))
|
(let ((work-to-do (length splits))
|
||||||
|
Loading…
Reference in New Issue
Block a user