[income-statement] compact functions

This commit is contained in:
Christopher Lam 2019-10-01 00:06:48 +08:00
parent bf202d1461
commit 34bb47e23f

View File

@ -387,9 +387,8 @@
;; Wrapper to call gnc:html-table-add-labeled-amount-line! ;; Wrapper to call gnc:html-table-add-labeled-amount-line!
;; with the proper arguments. ;; with the proper arguments.
(define (add-subtotal-line table pos-label neg-label signed-balance) (define (add-subtotal-line table pos-label neg-label signed-balance)
(let* ((neg? (and signed-balance (let* ((neg? (and signed-balance neg-label
neg-label (negative?
(gnc-numeric-negative-p
(gnc:gnc-monetary-amount (gnc:gnc-monetary-amount
(gnc:sum-collector-commodity (gnc:sum-collector-commodity
signed-balance report-commodity exchange-fn))))) signed-balance report-commodity exchange-fn)))))
@ -405,22 +404,18 @@
(gnc:html-table-append-ruler! table (* 2 tree-depth))) (gnc:html-table-append-ruler! table (* 2 tree-depth)))
(gnc:html-document-set-title! (gnc:html-document-set-title!
doc (format #f doc (format #f (string-append "~a ~a " (_ "For Period Covering ~a to ~a"))
(string-append "~a ~a "
(_ "For Period Covering ~a to ~a"))
company-name report-title company-name report-title
(qof-print-date start-date-printable) (qof-print-date start-date-printable)
(qof-print-date end-date))) (qof-print-date end-date)))
(if (null? accounts) (if (null? accounts)
;; error condition: no accounts specified ;; error condition: no accounts specified is this *really*
;; is this *really* necessary?? ;; necessary?? i'd be fine with an all-zero P&L that would,
;; i'd be fine with an all-zero P&L ;; technically, be correct....
;; that would, technically, be correct....
(gnc:html-document-add-object! (gnc:html-document-add-object!
doc doc (gnc:html-make-no-account-warning
(gnc:html-make-no-account-warning
reportname (gnc:report-id report-obj))) reportname (gnc:report-id report-obj)))
;; Get all the balances for each of the account types. ;; Get all the balances for each of the account types.
@ -531,78 +526,44 @@
(string-append (_ "Net loss") period-for) (string-append (_ "Net loss") period-for)
net-income (* 2 (1- tree-depth)) exchange-fn #f #f) net-income (* 2 (1- tree-depth)) exchange-fn #f #f)
(gnc:html-document-add-object! ;; add the sections in the desired order to document
doc (let ((build-table (gnc:make-html-table))
(let* ((build-table (gnc:make-html-table))) (inc-cell (gnc:make-html-table-cell inc-table))
(if two-column? (tra-cell (if (null? trading-accounts)
(gnc:html-table-append-row!
build-table
(if standard-order?
(list
(gnc:make-html-table-cell inc-table)
(if (null? trading-accounts)
(gnc:html-make-empty-cell) (gnc:html-make-empty-cell)
(gnc:make-html-table-cell tra-table)) (gnc:make-html-table-cell tra-table)))
(gnc:make-html-table-cell exp-table) (exp-cell (gnc:make-html-table-cell exp-table)))
) (define (add-cells . lst) (gnc:html-table-append-row! build-table lst))
(list (cond
(gnc:make-html-table-cell exp-table) ((and two-column? standard-order?)
(gnc:make-html-table-cell inc-table) (add-cells inc-cell tra-cell exp-cell))
(if (null? trading-accounts)
(gnc:html-make-empty-cell) (two-column?
(gnc:make-html-table-cell tra-table)) (add-cells exp-cell inc-cell tra-cell))
)
) (standard-order?
) (add-cells inc-cell)
(if standard-order? (unless (null? trading-accounts) (add-cells tra-cell))
(begin (add-cells exp-cell))
(gnc:html-table-append-row!
build-table (else
(list (gnc:make-html-table-cell inc-table))) (add-cells exp-cell)
(if (not (null? trading-accounts)) (add-cells inc-cell)
(gnc:html-table-append-row! (unless (null? trading-accounts) (add-cells tra-cell))))
build-table
(list (gnc:make-html-table-cell tra-table))))
(gnc:html-table-append-row!
build-table
(list (gnc:make-html-table-cell exp-table)))
)
(begin
(gnc:html-table-append-row!
build-table
(list (gnc:make-html-table-cell exp-table)))
(gnc:html-table-append-row!
build-table
(list (gnc:make-html-table-cell inc-table)))
(if (not (null? trading-accounts))
(gnc:html-table-append-row!
build-table
(list (gnc:make-html-table-cell tra-table))))
)
)
)
(gnc:html-table-set-style! (gnc:html-table-set-style!
build-table "td" build-table "td"
'attribute '("align" "left") 'attribute '("align" "left")
'attribute '("valign" "top")) 'attribute '("valign" "top"))
build-table (gnc:html-document-add-object! doc build-table))
)
)
;; add currency information if requested ;; add currency information if requested
(gnc:report-percent-done 90) (gnc:report-percent-done 90)
(if show-rates? (when show-rates?
(gnc:html-document-add-object! (gnc:html-document-add-object!
doc ;;(gnc:html-markup-p) doc (gnc:html-make-exchangerates
(gnc:html-make-exchangerates
report-commodity exchange-fn accounts))) report-commodity exchange-fn accounts)))
(gnc:report-percent-done 100) (gnc:report-percent-done 100)))
)
)
(gnc:report-finished) (gnc:report-finished)