gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Nov 9 19:58:50 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/6f7c6b9d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/97798f9f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b7205213 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/72c20a07 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9f4677e3 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f0701da8 (commit)



commit 6f7c6b9de3326d27bfaa0857069b8df4a2d22c74
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 10 03:50:55 2019 +0800

    [new-aging] step 3 - only render APAR details if APAR-accounts>1
    
    This commit will hide the APAR account anchor if there's only one
    found. So, for majority of users with single AP/AR accounts, the aging
    report will be very similar to old one. For users with multi APAR
    accounts, each one will be shown with header (and anchor) and
    indenting to highlight grouping.

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 1e451b8f0..6331a147d 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -192,8 +192,7 @@ exist but have no suitable transactions."))
     (gnc:option-value (gnc:lookup-option options section name)))
 
   (define make-heading-list
-    (list ""
-          (_ "Company")
+    (list (_ "Company")
           (_ "Prepayments")
           (_ "Current")
           (_ "0-30 days")
@@ -258,10 +257,12 @@ exist but have no suitable transactions."))
                document (gnc:make-html-text empty-APAR-accounts)))
 
              (else
-              (let ((table (gnc:make-html-table)))
+              (let ((table (gnc:make-html-table))
+                    (accounts>1? (> (length accounts-and-owners) 1)))
 
                 (gnc:html-table-set-col-headers!
-                 table (append make-heading-list
+                 table (append (if accounts>1? '(#f) '())
+                               make-heading-list
                                (options->address options receivable #f)))
 
                 (for-each
@@ -271,13 +272,14 @@ exist but have no suitable transactions."))
                           (acc-totals (caddr account-and-owners))
                           (comm (xaccAccountGetCommodity account)))
 
-                     (gnc:html-table-append-row!
-                      table (list (gnc:make-html-table-cell/size
-                                   1 (+ 2 num-buckets)
-                                   (gnc:make-html-text
-                                    (gnc:html-markup-anchor
-                                     (gnc:account-anchor-text account)
-                                     (xaccAccountGetName account))))))
+                     (when accounts>1?
+                       (gnc:html-table-append-row!
+                        table (list (gnc:make-html-table-cell/size
+                                     1 (+ 2 num-buckets)
+                                     (gnc:make-html-text
+                                      (gnc:html-markup-anchor
+                                       (gnc:account-anchor-text account)
+                                       (xaccAccountGetName account)))))))
 
                      (for-each
                       (lambda (owner-and-aging)
@@ -287,7 +289,7 @@ exist but have no suitable transactions."))
                           (gnc:html-table-append-row!
                            table
                            (append
-                            (list #f)
+                            (if accounts>1? '(#f) '())
                             (cons
                              (gnc:make-html-text
                               (gnc:html-markup-anchor
@@ -309,14 +311,15 @@ exist but have no suitable transactions."))
                       owners-and-aging)
                      (gnc:html-table-append-row!
                       table
-                      (cons* #f
-                             (gnc:make-html-table-cell/markup
-                              "total-label-cell" (_ "Total"))
-                             (map
-                              (lambda (amt)
-                                (gnc:make-html-table-cell/markup
-                                 "total-number-cell" (gnc:make-gnc-monetary comm amt)))
-                              acc-totals)))))
+                      (append
+                       (if accounts>1? '(#f) '())
+                       (list (gnc:make-html-table-cell/markup
+                              "total-label-cell" (_ "Total")))
+                       (map
+                        (lambda (amt)
+                          (gnc:make-html-table-cell/markup
+                           "total-number-cell" (gnc:make-gnc-monetary comm amt)))
+                        acc-totals)))))
                  accounts-and-owners)
                 (for-each gncOwnerFree tofree)
                 (gnc:html-document-add-object! document table)))))

commit 97798f9fd1b5c7864b359e84b9f76f2d8915c2c9
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 10 04:07:08 2019 +0800

    [new-aging] step 2 - reduce indentation level by 1
    
    merge two let* together

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index e4a0a6b07..1e451b8f0 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -325,50 +325,45 @@ exist but have no suitable transactions."))
             (let* ((account (car accounts))
                    (splits-acc-others (list-split splits split-from-acct? account))
                    (acc-splits (car splits-acc-others))
-                   (other-acc-splits (cdr splits-acc-others)))
-
-              (gnc:debug 'account account)
-
-              (let* ((split-owners (map split->owner acc-splits))
-                     (acc-owners (sort (sort-and-delete-duplicates
-                                        split-owners ownerGUID<? gnc-owner-equal?)
-                                       owner<?)))
-
-                (gnc:debug 'owners acc-owners)
-
-                ;; loop into each APAR account split
-                (let lp ((acc-owners acc-owners)
-                         (acc-splits acc-splits)
-                         (acc-totals (make-list (1+ num-buckets) 0))
-                         (owners-and-aging '()))
-                  (cond
-                   ((null? acc-owners)
-                    (loop (cdr accounts)
-                          other-acc-splits
-                          (if (null? owners-and-aging)
-                              accounts-and-owners
-                              (cons (list account owners-and-aging acc-totals)
-                                    accounts-and-owners))
-                          (append-reverse tofree split-owners)))
-
-                   (else
-                    (let* ((owner (car acc-owners))
-                           (splits-own-others (list-split acc-splits split-has-owner?
-                                                          owner))
-                           (owner-splits (car splits-own-others))
-                           (other-owner-splits (cdr splits-own-others))
-                           (aging (gnc:owner-splits->aging-list
-                                   owner-splits num-buckets report-date
-                                   date-type receivable))
-                           (aging-total (apply + aging)))
-                      (lp (cdr acc-owners)
-                          other-owner-splits
-                          (map + acc-totals
-                               (reverse (cons aging-total aging)))
-                          (if (or show-zeros (not (every zero? aging)))
-                              (cons (list owner aging aging-total)
-                                    owners-and-aging)
-                              owners-and-aging))))))))))))))
+                   (other-acc-splits (cdr splits-acc-others))
+                   (split-owners (map split->owner acc-splits))
+                   (acc-owners (sort (sort-and-delete-duplicates
+                                      split-owners ownerGUID<? gnc-owner-equal?)
+                                     owner<?)))
+
+              ;; loop into each APAR account split
+              (let lp ((acc-owners acc-owners)
+                       (acc-splits acc-splits)
+                       (acc-totals (make-list (1+ num-buckets) 0))
+                       (owners-and-aging '()))
+                (cond
+                 ((null? acc-owners)
+                  (loop (cdr accounts)
+                        other-acc-splits
+                        (if (null? owners-and-aging)
+                            accounts-and-owners
+                            (cons (list account owners-and-aging acc-totals)
+                                  accounts-and-owners))
+                        (append-reverse tofree split-owners)))
+
+                 (else
+                  (let* ((owner (car acc-owners))
+                         (splits-own-others (list-split acc-splits split-has-owner?
+                                                        owner))
+                         (owner-splits (car splits-own-others))
+                         (other-owner-splits (cdr splits-own-others))
+                         (aging (gnc:owner-splits->aging-list
+                                 owner-splits num-buckets report-date
+                                 date-type receivable))
+                         (aging-total (apply + aging)))
+                    (lp (cdr acc-owners)
+                        other-owner-splits
+                        (map + acc-totals
+                             (reverse (cons aging-total aging)))
+                        (if (or show-zeros (not (every zero? aging)))
+                            (cons (list owner aging aging-total)
+                                  owners-and-aging)
+                            owners-and-aging)))))))))))))
     (gnc:report-finished)
     document))
 

commit b72052137b562888421fdc9d4e7c7d05867c0186
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Nov 9 17:19:50 2019 +0800

    [new-aging] step 1 - split loops into processing vs building table
    
    Instead of rendering html-table all incrementally, build
    account-and-owners and owners-and-aging lists first, leaving building
    the html-table for the end. tofree is a list of owners which are
    generated and must be freed after use.

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 36d99c986..e4a0a6b07 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -237,8 +237,7 @@ exist but have no suitable transactions."))
       (setup-query query accounts report-date)
       (let* ((splits (qof-query-run query))
              (accounts (sort-and-delete-duplicates (map xaccSplitGetAccount splits)
-                                                   gnc:account-path-less-p equal?))
-             (table (gnc:make-html-table)))
+                                                   gnc:account-path-less-p equal?)))
         (qof-query-destroy query)
 
         ;; loop into each APAR account
@@ -247,32 +246,88 @@ exist but have no suitable transactions."))
                             (lambda (split)
                               (or (txn-is-invoice? (xaccSplitGetParent split))
                                   (txn-is-payment? (xaccSplitGetParent split))))
-                            splits)))
+                            splits))
+                   (accounts-and-owners '())
+                   (tofree '()))
           (cond
            ((null? accounts)
-            (gnc:html-table-set-col-headers!
-             table (append make-heading-list
-                           (options->address options receivable #f)))
-            (gnc:html-document-add-object!
-             document (if (null? (gnc:html-table-data table))
-                          (gnc:make-html-text empty-APAR-accounts)
-                          table)))
+
+            (cond
+             ((null? accounts-and-owners)
+              (gnc:html-document-add-object!
+               document (gnc:make-html-text empty-APAR-accounts)))
+
+             (else
+              (let ((table (gnc:make-html-table)))
+
+                (gnc:html-table-set-col-headers!
+                 table (append make-heading-list
+                               (options->address options receivable #f)))
+
+                (for-each
+                 (lambda (account-and-owners)
+                   (let* ((account (car account-and-owners))
+                          (owners-and-aging (cadr account-and-owners))
+                          (acc-totals (caddr account-and-owners))
+                          (comm (xaccAccountGetCommodity account)))
+
+                     (gnc:html-table-append-row!
+                      table (list (gnc:make-html-table-cell/size
+                                   1 (+ 2 num-buckets)
+                                   (gnc:make-html-text
+                                    (gnc:html-markup-anchor
+                                     (gnc:account-anchor-text account)
+                                     (xaccAccountGetName account))))))
+
+                     (for-each
+                      (lambda (owner-and-aging)
+                        (let ((owner (car owner-and-aging))
+                              (aging (cadr owner-and-aging))
+                              (aging-total (caddr owner-and-aging)))
+                          (gnc:html-table-append-row!
+                           table
+                           (append
+                            (list #f)
+                            (cons
+                             (gnc:make-html-text
+                              (gnc:html-markup-anchor
+                               (gnc:owner-anchor-text owner)
+                               (gncOwnerGetName owner)))
+                             (map
+                              (lambda (amt)
+                                (gnc:make-html-table-cell/markup
+                                 "number-cell" (gnc:make-gnc-monetary comm amt)))
+                              (reverse aging)))
+                            (list
+                             (gnc:make-html-table-cell/markup
+                              "number-cell"
+                              (gnc:make-html-text
+                               (gnc:html-markup-anchor
+                                (gnc:owner-report-text owner account)
+                                (gnc:make-gnc-monetary comm aging-total)))))
+                            (options->address options receivable owner)))))
+                      owners-and-aging)
+                     (gnc:html-table-append-row!
+                      table
+                      (cons* #f
+                             (gnc:make-html-table-cell/markup
+                              "total-label-cell" (_ "Total"))
+                             (map
+                              (lambda (amt)
+                                (gnc:make-html-table-cell/markup
+                                 "total-number-cell" (gnc:make-gnc-monetary comm amt)))
+                              acc-totals)))))
+                 accounts-and-owners)
+                (for-each gncOwnerFree tofree)
+                (gnc:html-document-add-object! document table)))))
 
            (else
             (let* ((account (car accounts))
-                   (comm (xaccAccountGetCommodity account))
                    (splits-acc-others (list-split splits split-from-acct? account))
                    (acc-splits (car splits-acc-others))
                    (other-acc-splits (cdr splits-acc-others)))
 
               (gnc:debug 'account account)
-              (gnc:html-table-append-row!
-               table (list (gnc:make-html-table-cell/size
-                            1 (+ 2 num-buckets)
-                            (gnc:make-html-text
-                             (gnc:html-markup-anchor
-                              (gnc:account-anchor-text account)
-                              (xaccAccountGetName account))))))
 
               (let* ((split-owners (map split->owner acc-splits))
                      (acc-owners (sort (sort-and-delete-duplicates
@@ -284,22 +339,17 @@ exist but have no suitable transactions."))
                 ;; loop into each APAR account split
                 (let lp ((acc-owners acc-owners)
                          (acc-splits acc-splits)
-                         (acc-totals (make-list (1+ num-buckets) 0)))
+                         (acc-totals (make-list (1+ num-buckets) 0))
+                         (owners-and-aging '()))
                   (cond
                    ((null? acc-owners)
-                    (for-each gncOwnerFree split-owners)
-                    (gnc:html-table-append-row!
-                     table
-                     (cons* #f
-                            (gnc:make-html-table-cell/markup
-                             "total-label-cell" (_ "Total"))
-                            (map
-                             (lambda (amt)
-                               (gnc:make-html-table-cell/markup
-                                "total-number-cell" (gnc:make-gnc-monetary comm amt)))
-                             acc-totals)))
                     (loop (cdr accounts)
-                          other-acc-splits))
+                          other-acc-splits
+                          (if (null? owners-and-aging)
+                              accounts-and-owners
+                              (cons (list account owners-and-aging acc-totals)
+                                    accounts-and-owners))
+                          (append-reverse tofree split-owners)))
 
                    (else
                     (let* ((owner (car acc-owners))
@@ -311,33 +361,14 @@ exist but have no suitable transactions."))
                                    owner-splits num-buckets report-date
                                    date-type receivable))
                            (aging-total (apply + aging)))
-                      (when (or show-zeros (not (every zero? aging)))
-                        (gnc:html-table-append-row!
-                         table
-                         (append
-                          (list #f)
-                          (cons
-                           (gnc:make-html-text
-                            (gnc:html-markup-anchor
-                             (gnc:owner-anchor-text owner)
-                             (gncOwnerGetName owner)))
-                           (map
-                            (lambda (amt)
-                              (gnc:make-html-table-cell/markup
-                               "number-cell" (gnc:make-gnc-monetary comm amt)))
-                            (reverse aging)))
-                          (list
-                           (gnc:make-html-table-cell/markup
-                            "number-cell"
-                            (gnc:make-html-text
-                             (gnc:html-markup-anchor
-                              (gnc:owner-report-text owner account)
-                              (gnc:make-gnc-monetary comm aging-total)))))
-                          (options->address options receivable owner))))
                       (lp (cdr acc-owners)
                           other-owner-splits
                           (map + acc-totals
-                               (reverse (cons aging-total aging))))))))))))))))
+                               (reverse (cons aging-total aging)))
+                          (if (or show-zeros (not (every zero? aging)))
+                              (cons (list owner aging aging-total)
+                                    owners-and-aging)
+                              owners-and-aging))))))))))))))
     (gnc:report-finished)
     document))
 

commit 72c20a07c36fbf719691f5cc35e2df4037218d23
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Nov 9 14:45:11 2019 +0800

    [new-owner-report] merge setup-query and setup-job-query
    
    They were very similar.
    
    and remove html-document-set-title! because the document headline will
    override title in the renderer.

diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index f702a9ab4..ee8263f70 100644
--- a/gnucash/report/business-reports/new-owner-report.scm
+++ b/gnucash/report/business-reports/new-owner-report.scm
@@ -622,33 +622,17 @@ invoices and amounts.")))))
         (loop (cdr list-of-substrings)
               (cons* (gnc:html-markup-br) (car list-of-substrings) result)))))
 
-(define (setup-job-query q owner accounts end-date)
-  (let ((guid (gncOwnerReturnGUID owner)))
+(define (setup-query q owner accounts end-date job?)
+  (let ((guid (gncOwnerReturnGUID (if job? owner (gncOwnerGetEndOwner owner))))
+        (last-param (if job? QOF-PARAM-GUID OWNER-PARENTG)))
     (qof-query-add-guid-match
-     q  (list SPLIT-TRANS INVOICE-FROM-TXN INVOICE-OWNER QOF-PARAM-GUID)
+     q (list SPLIT-TRANS INVOICE-FROM-TXN INVOICE-OWNER last-param)
      guid QOF-QUERY-OR)
     (qof-query-add-guid-match
-     q (list SPLIT-LOT OWNER-FROM-LOT QOF-PARAM-GUID)
+     q (list SPLIT-LOT OWNER-FROM-LOT last-param)
      guid QOF-QUERY-OR)
     (qof-query-add-guid-match
-     q (list SPLIT-LOT INVOICE-FROM-LOT INVOICE-OWNER QOF-PARAM-GUID)
-     guid QOF-QUERY-OR)
-    (xaccQueryAddAccountMatch q accounts QOF-GUID-MATCH-ANY QOF-QUERY-AND)
-    (xaccQueryAddDateMatchTT q #f end-date #t end-date QOF-QUERY-AND)
-    (qof-query-set-book q (gnc-get-current-book))
-    (qof-query-set-sort-order q (list SPLIT-TRANS TRANS-DATE-POSTED) '() '())
-    q))
-
-(define (setup-query q owner accounts end-date)
-  (let ((guid (gncOwnerReturnGUID (gncOwnerGetEndOwner owner))))
-    (qof-query-add-guid-match
-     q (list SPLIT-TRANS INVOICE-FROM-TXN INVOICE-OWNER OWNER-PARENTG)
-     guid QOF-QUERY-OR)
-    (qof-query-add-guid-match
-     q (list SPLIT-LOT OWNER-FROM-LOT OWNER-PARENTG)
-     guid QOF-QUERY-OR)
-    (qof-query-add-guid-match
-     q (list SPLIT-LOT INVOICE-FROM-LOT INVOICE-OWNER OWNER-PARENTG)
+     q (list SPLIT-LOT INVOICE-FROM-LOT INVOICE-OWNER last-param)
      guid QOF-QUERY-OR)
     (xaccQueryAddAccountMatch q accounts QOF-GUID-MATCH-ANY QOF-QUERY-AND)
     (xaccQueryAddDateMatchTT q #f end-date #t end-date QOF-QUERY-AND)
@@ -744,16 +728,11 @@ invoices and amounts.")))))
         (_ "This report requires a valid AP/AR account to be available."))))
 
      (else
-      (if (eqv? GNC-OWNER-JOB type)
-          (setup-job-query query owner accounts end-date)
-          (setup-query query owner accounts end-date))
+      (setup-query query owner accounts end-date (eqv? GNC-OWNER-JOB type))
 
       (let ((splits (xaccQueryGetSplitsUniqueTrans query)))
         (qof-query-destroy query)
 
-        (gnc:html-document-set-title!
-         document (string-append report-title ": " (gncOwnerGetName owner)))
-
         (gnc:html-document-set-headline!
          document (gnc:html-markup
                    "span" (owner-string type) " " (_ "Report:") " "

commit 9f4677e34651a35b409a1fcdc967bbbd2b6e5020
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Nov 9 14:31:24 2019 +0800

    [new-owner-report] apply total-label-cell to label
    
    Previous used 'total-number-cell' thereby unnecessarily right-aligning
    total label cells.
    
    Also xaccTransGetAccountAmount is more appropriate than
    xaccTransGetAccountValue because the latter may retrieve numbers in a
    currency other than APAR currency.

diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index c99dee194..f702a9ab4 100644
--- a/gnucash/report/business-reports/new-owner-report.scm
+++ b/gnucash/report/business-reports/new-owner-report.scm
@@ -252,7 +252,7 @@
   (define link-cols (assq-ref '((none . 0) (simple . 1) (detailed . 3)) link-option))
   (define (print-totals total debit credit tax sale)
     (define (total-cell cell)
-      (gnc:make-html-table-cell/markup "total-number-cell" cell))
+      (gnc:make-html-table-cell/markup "total-label-cell" cell))
     (define (make-cell amt)
       (total-cell (gnc:make-gnc-monetary currency amt)))
     (define span
@@ -447,7 +447,7 @@
       (let* ((split (car splits))
              (txn (xaccSplitGetParent split))
              (date (xaccTransGetDate txn))
-             (value (xaccTransGetAccountValue txn acc))
+             (value (xaccTransGetAccountAmount txn acc))
              (value (if payable? (- value) value))
              (invoice (gncInvoiceGetInvoiceFromTxn txn))
              (invoice-splits



Summary of changes:
 gnucash/report/business-reports/new-aging.scm      | 205 ++++++++++++---------
 .../report/business-reports/new-owner-report.scm   |  39 +---
 2 files changed, 126 insertions(+), 118 deletions(-)



More information about the gnucash-changes mailing list