From 3866d9bb7c31c80279dbd96dd811a67a9480dee6 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 23 Jan 2020 21:31:04 +0800 Subject: [PATCH] [new-owner-report] refactor. separate LHS inv/pmt processing. 1. handle accumulation of totals and printing of balance-b/f row earlier 2. separate LHS processing into invoice and payment. --- .../business-reports/new-owner-report.scm | 111 ++++++++++-------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm index 57aea2856f..460b4f57be 100644 --- a/gnucash/report/business-reports/new-owner-report.scm +++ b/gnucash/report/business-reports/new-owner-report.scm @@ -710,8 +710,22 @@ (gnc:warn "sanity check fail" txn) (lp printed? odd-row? (cdr splits) total debit credit tax sale)) + ;; txn-date < start-date. skip display, accumulate amounts + ((< (xaccTransGetDate (xaccSplitGetParent (car splits))) start-date) + (let* ((txn (xaccSplitGetParent (car splits))) + (value (AP-negate (xaccTransGetAccountAmount txn acc)))) + (lp printed? odd-row? (cdr splits) (+ total value) + debit credit tax sale))) + + ;; if balance row hasn't been rendered, consider + ;; adding here. skip if value=0. + ((not printed?) + (let ((print? (and (bal-col used-columns) (not (zero? total))))) + (if print? (add-balance-row odd-row? total)) + (lp #t (not print?) splits total debit credit tax sale))) + ;; start printing txns. - (else + ((txn-is-invoice? (xaccSplitGetParent (car splits))) (let* ((split (car splits)) (txn (xaccSplitGetParent split)) (date (xaccTransGetDate txn)) @@ -719,52 +733,57 @@ (value (AP-negate orig-value)) (invoice (gncInvoiceGetInvoiceFromTxn txn))) - (cond - ;; txn-date < start-date. skip display, accumulate amounts - ((< date start-date) - (lp printed? odd-row? (cdr splits) (+ total value) - debit credit tax sale)) - - ;; if balance row hasn't been rendered, consider - ;; adding here. skip if value=0. - ((not printed?) - (let ((print? (and (bal-col used-columns) (not (zero? total))))) - (if print? (add-balance-row odd-row? total)) - (lp #t (not print?) splits total debit credit tax sale))) + (add-row + table odd-row? used-columns date (invoice->due-date invoice) + (split->reference split) + (split->type-str split) + (splits->desc (list split)) + currency (+ total value) + (and (< orig-value 0) orig-value) + (and (>= orig-value 0) orig-value) + (invoice->sale invoice) (invoice->tax invoice) + split + link-option + (case link-option + ((simple) (list (list (and (gncInvoiceIsPaid invoice) (_ "Paid"))))) + ((detailed) (make-invoice->payments-table invoice)) + (else '(())))) + + (lp printed? (not odd-row?) (cdr splits) (+ total value) + (if (< 0 orig-value) (+ debit orig-value) debit) + (if (< 0 orig-value) credit (- credit orig-value)) + (+ tax (or (invoice->tax invoice) 0)) + (+ sale (or (invoice->sale invoice) 0))))) + + ((txn-is-payment? (xaccSplitGetParent (car splits))) + (let* ((split (car splits)) + (txn (xaccSplitGetParent split)) + (date (xaccTransGetDate txn)) + (orig-value (xaccTransGetAccountAmount txn acc)) + (value (AP-negate orig-value)) + (invoice (gncInvoiceGetInvoiceFromTxn txn))) - (else - (add-row - table odd-row? used-columns date (invoice->due-date invoice) - (split->reference split) - (split->type-str split) - (splits->desc - (cond - ((txn-is-invoice? txn) (list split)) - ((txn-is-payment? txn) (txn->assetliab-splits txn)))) - currency (+ total value) - (and (< orig-value 0) orig-value) - (and (>= orig-value 0) orig-value) - (invoice->sale invoice) (invoice->tax invoice) - split - link-option - (cond - ((and (txn-is-invoice? txn) (eq? link-option 'simple)) - (if (gncInvoiceIsPaid invoice) - (list (list (_ "Paid"))) - (list (list #f)))) - ((and (txn-is-invoice? txn) (eq? link-option 'detailed)) - (make-invoice->payments-table invoice)) - ((and (txn-is-payment? txn) (eq? link-option 'simple)) - (make-payment->invoices-list txn)) - ((and (txn-is-payment? txn) (eq? link-option 'detailed)) - (make-payment->invoices-table txn)) - (else '(())))) - - (lp printed? (not odd-row?) (cdr splits) (+ total value) - (if (< 0 orig-value) (+ debit orig-value) debit) - (if (< 0 orig-value) credit (- credit orig-value)) - (+ tax (or (invoice->tax invoice) 0)) - (+ sale (or (invoice->sale invoice) 0)))))))))) + (add-row + table odd-row? used-columns date (invoice->due-date invoice) + (split->reference split) + (split->type-str split) + (splits->desc (txn->assetliab-splits txn)) + currency (+ total value) + (and (< orig-value 0) orig-value) + (and (>= orig-value 0) orig-value) + (invoice->sale invoice) (invoice->tax invoice) + split + link-option + (case link-option + ((simple) (make-payment->invoices-list txn)) + ((detailed) (make-payment->invoices-table txn)) + (else '(())))) + + (lp printed? (not odd-row?) (cdr splits) (+ total value) + (if (< 0 orig-value) (+ debit orig-value) debit) + (if (< 0 orig-value) credit (- credit orig-value)) + (+ tax (or (invoice->tax invoice) 0)) + (+ sale (or (invoice->sale invoice) 0)))))))) (define (options-generator owner-type)