[register] simplify make-split-table main loop

Previous was using nested ifs. use cond instead which is more
appropriate.

Also handle dangling-split separately.
This commit is contained in:
Christopher Lam 2019-02-22 23:09:35 +08:00
parent bae74fed0a
commit b1763ed13d

View File

@ -605,16 +605,14 @@
(let loop ((splits splits) (let loop ((splits splits)
(odd-row? #t)) (odd-row? #t))
(if (null? splits) (cond
;; ---------------------------------- ;; ----------------------------------
;; exit condition reached ;; exit condition reached
;; ----------------------------------
(begin
;; ------------------------------------
;; add debit/credit totals to the table ;; add debit/credit totals to the table
;; ------------------------------------ ;; ----------------------------------
(if (reg-report-show-totals?) ((null? splits)
(begin (when reg-report-show-totals?
(add-subtotal-row (_ "Total Debits") leader table used-columns (add-subtotal-row (_ "Total Debits") leader table used-columns
debit-collector "grand-total" #f) debit-collector "grand-total" #f)
(add-subtotal-row (_ "Total Credits") leader table used-columns (add-subtotal-row (_ "Total Credits") leader table used-columns
@ -622,31 +620,36 @@
(add-subtotal-row (_ "Total Value Debits") leader table used-columns (add-subtotal-row (_ "Total Value Debits") leader table used-columns
debit-value "grand-total" #t) debit-value "grand-total" #t)
(add-subtotal-row (_ "Total Value Credits") leader table used-columns (add-subtotal-row (_ "Total Value Credits") leader table used-columns
credit-value "grand-total" #t))) credit-value "grand-total" #t))
(if ledger-type? (when ledger-type?
(add-subtotal-row (_ "Net Change") leader table used-columns (add-subtotal-row (_ "Net Change") leader table used-columns
total-collector "grand-total" #f)) total-collector "grand-total" #f))
(add-subtotal-row (_ "Value Change") leader table used-columns (add-subtotal-row (_ "Value Change") leader table used-columns
total-value "grand-total" #t)) total-value "grand-total" #t))
;; The general journal has a split that doesn't have an account
;; set yet (the new entry transaction).
;; This split should be skipped or the report errors out. See
;; bug #639082
((null? (xaccSplitGetAccount (car splits)))
(loop (cdr splits) (not odd-row?)))
;; ---------------------------------- ;; ----------------------------------
;; process the splits list ;; process the splits list
;; ---------------------------------- ;; ----------------------------------
(else
(let* ((current (car splits)) (let* ((current (car splits))
(current-row-style (if multi-rows? "normal-row" (current-row-style (if (or multi-rows? odd-row?)
(if odd-row? "normal-row" "normal-row"
"alternate-row"))) "alternate-row")))
(rest (cdr splits))
(valid-split? (not (null? (xaccSplitGetAccount current)))))
;; ---------------------------------------------- ;; ----------------------------------------------
;; update totals, but don't add them to the table ;; update totals, but don't add them to the table
;; ---------------------------------------------- ;; ----------------------------------------------
(if (and multi-rows? valid-split?) (if multi-rows?
(for-each (lambda (split) (for-each
(if (string=? (gncAccountGetGUID (lambda (split)
(xaccSplitGetAccount current)) (if (equal? (xaccSplitGetAccount current)
(gncAccountGetGUID (xaccSplitGetAccount split))
(xaccSplitGetAccount split)))
(accumulate-totals split (accumulate-totals split
total-collector total-value total-collector total-value
debit-collector debit-value debit-collector debit-value
@ -659,24 +662,18 @@
;; ---------------------------------- ;; ----------------------------------
;; add the splits to the table ;; add the splits to the table
;; ---------------------------------- ;; ----------------------------------
;; The general journal has a split that doesn't have an account
;; set yet (the new entry transaction).
;; This split should be skipped or the report errors out.
;; See bug #639082
(if valid-split?
(add-split-row table current used-columns (add-split-row table current used-columns
current-row-style #t (not multi-rows?) current-row-style #t (not multi-rows?)
action-for-num? ledger-type? action-for-num? ledger-type?
double? (opt-val "Display" "Memo") double? (opt-val "Display" "Memo")
(opt-val "Display" "Description") (opt-val "Display" "Description")
total-collector)) total-collector)
(if (and multi-rows? valid-split?) (if multi-rows?
(add-other-split-rows current table used-columns (add-other-split-rows current table used-columns
"alternate-row" action-for-num? "alternate-row" action-for-num?
ledger-type? total-collector)) ledger-type? total-collector))
(loop (cdr splits)
(loop rest (not odd-row?))))) (not odd-row?))))))
table)) table))
(define (reg-renderer report-obj) (define (reg-renderer report-obj)