[budget] eradicate gnc-numeric methods

This commit is contained in:
Christopher Lam 2019-03-02 21:03:43 +08:00
parent 9d38d7fa8e
commit 86cbebd0ac

View File

@ -289,7 +289,7 @@
html-table acct-table budget params) html-table acct-table budget params)
(let* ((get-val (lambda (alist key) (let* ((get-val (lambda (alist key)
(let ((lst (assoc-ref alist key))) (let ((lst (assoc-ref alist key)))
(if lst (car lst) lst)))) (and lst (car lst)))))
(show-actual? (get-val params 'show-actual)) (show-actual? (get-val params 'show-actual))
(show-budget? (get-val params 'show-budget)) (show-budget? (get-val params 'show-budget))
(show-diff? (get-val params 'show-difference)) (show-diff? (get-val params 'show-difference))
@ -306,12 +306,10 @@
;; assumption. ;; assumption.
(colnum (quotient numcolumns 2))) (colnum (quotient numcolumns 2)))
(define (negative-numeric-p x)
(if (gnc-numeric-p x) (gnc-numeric-negative-p x) #f))
(define (number-cell-tag x) (define (number-cell-tag x)
(if (negative-numeric-p x) "number-cell-neg" "number-cell")) (if (negative? x) "number-cell-neg" "number-cell"))
(define (total-number-cell-tag x) (define (total-number-cell-tag x)
(if (negative-numeric-p x) "total-number-cell-neg" "total-number-cell")) (if (negative? x) "total-number-cell-neg" "total-number-cell"))
;; Calculate the value to use for the budget of an account for a ;; Calculate the value to use for the budget of an account for a
;; specific set of periods. If there is 1 period, use that ;; specific set of periods. If there is 1 period, use that
@ -330,10 +328,9 @@
((= (length periodlist) 1) ((= (length periodlist) 1)
(gnc:get-account-period-rolledup-budget-value budget acct (car periodlist))) (gnc:get-account-period-rolledup-budget-value budget acct (car periodlist)))
(else (else
(gnc-numeric-add (+
(gnc:get-account-period-rolledup-budget-value budget acct (car periodlist)) (gnc:get-account-period-rolledup-budget-value budget acct (car periodlist))
(gnc:get-account-periodlist-budget-value budget acct (cdr periodlist)) (gnc:get-account-periodlist-budget-value budget acct (cdr periodlist))))))
GNC-DENOM-AUTO GNC-RND-ROUND))))
;; Calculate the value to use for the actual of an account for a ;; Calculate the value to use for the actual of an account for a
;; specific set of periods. This is the sum of the actuals for ;; specific set of periods. This is the sum of the actuals for
@ -351,10 +348,9 @@
((= (length periodlist) 1) ((= (length periodlist) 1)
(gnc-budget-get-account-period-actual-value budget acct (car periodlist))) (gnc-budget-get-account-period-actual-value budget acct (car periodlist)))
(else (else
(gnc-numeric-add (+
(gnc-budget-get-account-period-actual-value budget acct (car periodlist)) (gnc-budget-get-account-period-actual-value budget acct (car periodlist))
(gnc:get-account-periodlist-actual-value budget acct (cdr periodlist)) (gnc:get-account-periodlist-actual-value budget acct (cdr periodlist))))))
GNC-DENOM-AUTO GNC-RND-ROUND))))
;; Adds a line to tbe budget report. ;; Adds a line to tbe budget report.
;; ;;
@ -371,9 +367,9 @@
html-table rownum colnum budget acct rollup-budget? html-table rownum colnum budget acct rollup-budget?
column-list exchange-fn) column-list exchange-fn)
(let* ((current-col (+ colnum 1)) (let* ((current-col (+ colnum 1))
(bgt-total (gnc-numeric-zero)) (bgt-total 0)
(bgt-total-unset? #t) (bgt-total-unset? #t)
(act-total (gnc-numeric-zero)) (act-total 0)
(comm (xaccAccountGetCommodity acct)) (comm (xaccAccountGetCommodity acct))
(reverse-balance? (gnc-reverse-balance acct)) (reverse-balance? (gnc-reverse-balance acct))
(income-acct? (eq? (xaccAccountGetType acct) ACCT-TYPE-INCOME))) (income-acct? (eq? (xaccAccountGetType acct) ACCT-TYPE-INCOME)))
@ -397,7 +393,7 @@
(style-tag-neg (string-append style-tag "-neg"))) (style-tag-neg (string-append style-tag "-neg")))
(if show-budget? (if show-budget?
(begin (begin
(set! bgt-val (if (gnc-numeric-zero-p bgt-numeric-val) "." (set! bgt-val (if (zero? bgt-numeric-val) "."
(gnc:make-gnc-monetary comm bgt-numeric-val))) (gnc:make-gnc-monetary comm bgt-numeric-val)))
(gnc:html-table-set-cell/tag! (gnc:html-table-set-cell/tag!
html-table rownum current-col style-tag bgt-val) html-table rownum current-col style-tag bgt-val)
@ -407,7 +403,7 @@
(set! act-val (gnc:make-gnc-monetary comm act-numeric-val)) (set! act-val (gnc:make-gnc-monetary comm act-numeric-val))
(gnc:html-table-set-cell/tag! (gnc:html-table-set-cell/tag!
html-table rownum current-col html-table rownum current-col
(if (gnc-numeric-negative-p act-numeric-val) (if (negative? act-numeric-val)
style-tag-neg style-tag-neg
style-tag) style-tag)
act-val) act-val)
@ -415,13 +411,13 @@
(if show-diff? (if show-diff?
(begin (begin
(set! dif-val (set! dif-val
(if (and (gnc-numeric-zero-p bgt-numeric-val) (if (and (zero? bgt-numeric-val)
(gnc-numeric-zero-p act-numeric-val)) (zero? act-numeric-val))
"." "."
(gnc:make-gnc-monetary comm dif-numeric-val))) (gnc:make-gnc-monetary comm dif-numeric-val)))
(gnc:html-table-set-cell/tag! (gnc:html-table-set-cell/tag!
html-table rownum current-col html-table rownum current-col
(if (gnc-numeric-negative-p dif-numeric-val) (if (negative? dif-numeric-val)
style-tag-neg style-tag-neg
style-tag) style-tag)
dif-val) dif-val)
@ -446,27 +442,21 @@
budget acct period-list)) budget acct period-list))
(act-numeric-val (act-numeric-val
(if reverse-balance? (if reverse-balance?
(gnc-numeric-neg act-numeric-abs) (- act-numeric-abs)
act-numeric-abs)) act-numeric-abs))
;; difference (budget to actual) ;; difference (budget to actual)
(dif-numeric-val (dif-numeric-val
(gnc-numeric-sub (- bgt-numeric-val act-numeric-val)))
bgt-numeric-val act-numeric-val
GNC-DENOM-AUTO (+ GNC-DENOM-LCD GNC-RND-NEVER))))
(if (not (gnc-numeric-zero-p bgt-numeric-val)) (if (not (zero? bgt-numeric-val))
(begin (begin
(set! bgt-total (gnc-numeric-add bgt-total bgt-numeric-val (set! bgt-total (+ bgt-total bgt-numeric-val))
GNC-DENOM-AUTO GNC-RND-ROUND))
(set! bgt-total-unset? #f))) (set! bgt-total-unset? #f)))
(set! act-total (gnc-numeric-add act-total act-numeric-val (set! act-total (+ act-total act-numeric-val))
GNC-DENOM-AUTO GNC-RND-ROUND))
(if income-acct? (if income-acct?
(set! dif-numeric-val (set! dif-numeric-val
(gnc-numeric-sub (- act-numeric-val bgt-numeric-val)))
act-numeric-val bgt-numeric-val
GNC-DENOM-AUTO (+ GNC-DENOM-LCD GNC-RND-NEVER))))
(gnc:html-table-display-budget-columns! (gnc:html-table-display-budget-columns!
html-table rownum #f html-table rownum #f
bgt-numeric-val act-numeric-val dif-numeric-val))) bgt-numeric-val act-numeric-val dif-numeric-val)))
@ -478,12 +468,8 @@
(gnc:html-table-display-budget-columns! (gnc:html-table-display-budget-columns!
html-table rownum #t bgt-total act-total html-table rownum #t bgt-total act-total
(if income-acct? (if income-acct?
(gnc-numeric-sub (- act-total bgt-total)
act-total bgt-total (- bgt-total act-total))))
GNC-DENOM-AUTO (+ GNC-DENOM-LCD GNC-RND-NEVER))
(gnc-numeric-sub
bgt-total act-total
GNC-DENOM-AUTO (+ GNC-DENOM-LCD GNC-RND-NEVER)))))
((list? col-info) ((list? col-info)
(gnc:html-table-add-budget-line-columns! (gnc:html-table-add-budget-line-columns!
html-table rownum budget acct col-info)) html-table rownum budget acct col-info))