gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sun Jan 12 09:12:52 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/ead5c947 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/fd24b016 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6aff6e15 (commit)
	from  https://github.com/Gnucash/gnucash/commit/e3b926bd (commit)



commit ead5c94787d846005dccf6836ca406a475c78cd1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jan 12 21:33:13 2020 +0800

    Bug 797548 - multicolumn income statement: some closing entries are not ignored when within reporting period
    
    Remove closing-entries substring/regex filter.
    
    We will rely on the closing flag created with the Tools>Close Book
    tool. This means very *old* closing entries will need to be re-done
    via Tools>Close Book using the same date as the old closing entries.

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index c7d40b6fa..faa2c0927 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -96,15 +96,6 @@ below parent and children groups."))
 (define optname-amount-links (N_ "Display amounts as hyperlinks"))
 (define opthelp-amount-links (N_ "Shows each amounts in the table as a hyperlink to a register or report."))
 
-;; closing entries filter - for P&L report
-(define pagename-entries "Closing Entries")
-(define optname-closing-pattern (N_ "Closing Entries pattern"))
-(define opthelp-closing-pattern (N_ "Any text in the Description column which identifies closing entries."))
-(define optname-closing-casing (N_ "Closing Entries pattern is case-sensitive"))
-(define opthelp-closing-casing (N_ "Causes the Closing Entries Pattern match to be case-sensitive."))
-(define optname-closing-regexp (N_ "Closing Entries Pattern is regular expression"))
-(define opthelp-closing-regexp (N_ "Causes the Closing Entries Pattern to be treated as a regular expression."))
-
 ;; section labels
 (define optname-label-sections (N_ "Label sections"))
 (define opthelp-label-sections (N_ "Whether or not to include a label for sections."))
@@ -347,23 +338,7 @@ also show overall period profit & loss."))
       (add-option
        (gnc:make-simple-boolean-option
         gnc:pagename-general optname-include-overall-period
-        "c6" opthelp-include-overall-period #f))
-
-      ;; closing entry match criteria
-      (add-option
-       (gnc:make-string-option
-        pagename-entries optname-closing-pattern
-        "a" opthelp-closing-pattern (_ "Closing Entries")))
-
-      (add-option
-       (gnc:make-simple-boolean-option
-        pagename-entries optname-closing-casing
-        "b" opthelp-closing-casing #f))
-
-      (add-option
-       (gnc:make-simple-boolean-option
-        pagename-entries optname-closing-regexp
-        "c" opthelp-closing-regexp #f)))
+        "c6" opthelp-include-overall-period #f)))
 
     (gnc:options-set-default-section options gnc:pagename-general)
 
@@ -795,10 +770,11 @@ also show overall period profit & loss."))
                                                  (gnc:make-commodity-collector))
                       #:split->elt
                       (lambda (s)
-                        (val-coll 'add
-                                  (xaccTransGetCurrency (xaccSplitGetParent s))
-                                  (xaccSplitGetValue s))
-                        (make-datum s (amt->monetary (xaccSplitGetBalance s))
+                        (unless (xaccTransGetIsClosingTxn (xaccSplitGetParent s))
+                          (val-coll 'add
+                                    (xaccTransGetCurrency (xaccSplitGetParent s))
+                                    (xaccSplitGetValue s)))
+                        (make-datum s (amt->monetary (xaccSplitGetNoclosingBalance s))
                                     (gnc:collector+ val-coll)))))))
            accounts))
 
@@ -1139,10 +1115,7 @@ also show overall period profit & loss."))
               (gnc:html-markup-anchor chart (_ "Barchart")))))))
 
      ((eq? report-type 'pnl)
-      (let* ((closing-str (get-option pagename-entries optname-closing-pattern))
-             (closing-cased (get-option pagename-entries optname-closing-casing))
-             (closing-regexp (get-option pagename-entries optname-closing-regexp))
-             (include-overall-period? (get-option gnc:pagename-general
+      (let* ((include-overall-period? (get-option gnc:pagename-general
                                                   optname-include-overall-period))
              (col-idx->datepair
               (lambda (idx)
@@ -1161,44 +1134,13 @@ also show overall period profit & loss."))
                                           (cons (list-ref balancelist idx)
                                                 (list-ref balancelist (1+ idx))))))
 
-             (closing-entries (let ((query (qof-query-create-for-splits)))
-                                (qof-query-set-book query (gnc-get-current-book))
-                                (xaccQueryAddAccountMatch
-                                 query income-expense
-                                 QOF-GUID-MATCH-ANY QOF-QUERY-AND)
-                                (if (and closing-str (not (string-null? closing-str)))
-                                    (xaccQueryAddDescriptionMatch
-                                     query closing-str closing-cased closing-regexp
-                                     QOF-COMPARE-CONTAINS QOF-QUERY-AND))
-                                (xaccQueryAddClosingTransMatch query #t QOF-QUERY-OR)
-                                (let ((splits (qof-query-run query)))
-                                  (qof-query-destroy query)
-                                  splits)))
-
-             ;; this function will query the above closing-entries for
-             ;; splits within the date range, and produce the total
-             ;; amount for these closing entries
-             (closing-adjustment
-              (lambda (account col-idx)
-                (define datepair (col-idx->datepair col-idx))
-                (define (include-split? split)
-                  (and (equal? (xaccSplitGetAccount split) account)
-                       (<= (car datepair)
-                           (xaccTransGetDate (xaccSplitGetParent split))
-                           (cdr datepair))))
-                (let ((account-closing-splits (filter include-split? closing-entries)))
-                  (gnc:make-gnc-monetary
-                   (xaccAccountGetCommodity account)
-                   (apply + (map xaccSplitGetAmount account-closing-splits))))))
-
              (get-cell-monetary-fn
               (lambda (account col-idx)
                 (let* ((balances (assoc-ref accounts-balances account))
                        (monetarypair (col-idx->monetarypair balances col-idx)))
                   (monetary-less
                    (cdr monetarypair)
-                   (car monetarypair)
-                   (closing-adjustment account col-idx)))))
+                   (car monetarypair)))))
 
              (get-cell-anchor-fn
               (lambda (account col-idx)

commit fd24b016896af96e322324b03097906fb51eae83
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jan 12 20:31:05 2020 +0800

    [new-aging] reuse string

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 9d467a055..754c742fb 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -212,7 +212,7 @@ exist but have no suitable transactions."))
 
   (define make-heading-list
     (list (_ "Company")
-          (_ "Prepayments")
+          (_ "Pre-Payment")
           (_ "Current")
           (_ "0-30 days")
           (_ "31-60 days")

commit 6aff6e15f0a617be39c9545e4cce011ba0f1e67e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jan 12 20:31:01 2020 +0800

    [new-aging] reinstate sort-by choices
    
    - offer choices for sorting owners in each APAR list
    - may be useful for ordering customer aging debts
    - this means we remove the default owner->name sorting

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 444fcde90..9d467a055 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -29,6 +29,7 @@
 
 (use-modules (srfi srfi-1))
 (use-modules (srfi srfi-11))            ;let-values
+(use-modules (ice-9 match))
 (use-modules (gnucash utilities))
 (use-modules (gnucash gnc-module))
 (use-modules (gnucash gettext))
@@ -39,6 +40,7 @@
 (use-modules (gnucash report business-reports))
 
 (define optname-to-date (N_ "To"))
+(define optname-sort-by (N_ "Sort By"))
 (define optname-sort-order (N_ "Sort Order"))
 (define optname-report-currency (N_ "Report's currency"))
 (define optname-price-source (N_ "Price Source"))
@@ -90,6 +92,20 @@ exist but have no suitable transactions."))
      (gnc:lookup-option options gnc:pagename-general optname-to-date)
      (cons 'relative 'today))
 
+    (add-option
+     (gnc:make-multichoice-option
+      gnc:pagename-general optname-sort-by "i" (N_ "Sort companies by.") 'name
+      (list
+       (vector 'name
+               (N_ "Name")
+               (N_ "Name of the company."))
+       (vector 'total
+               (N_ "Total Owed")
+               (N_ "Total amount owed to/from Company."))
+       (vector 'oldest-bracket
+               (N_ "Bracket Total Owed")
+               (N_ "Amount owed in oldest bracket - if same go to next oldest.")))))
+
     (add-option
      (gnc:make-multichoice-option
       gnc:pagename-general optname-sort-order "ia" (N_ "Sort order.") 'increasing
@@ -213,6 +229,7 @@ exist but have no suitable transactions."))
                        (gnc:date-option-absolute-time
                         (op-value gnc:pagename-general optname-to-date))))
          (sort-order (op-value gnc:pagename-general optname-sort-order))
+         (sort-by (op-value gnc:pagename-general optname-sort-by))
          (show-zeros (op-value gnc:pagename-general optname-show-zeros))
          (date-type (op-value gnc:pagename-general optname-date-driver))
          (query (qof-query-create-for-splits))
@@ -223,10 +240,21 @@ exist but have no suitable transactions."))
     (define (ownerGUID<? a b)
       (string<? (gncOwnerGetGUID a) (gncOwnerGetGUID b)))
 
-    ;; for presentation. compare names.
-    (define (owner<? a b)
-      ((if (eq? sort-order 'increasing) string<? string>?)
-       (gncOwnerGetName a) (gncOwnerGetName b)))
+    (define (sort-aging<? a b)
+      (match-let* (((own1 aging1 aging-total1) a)
+                   ((own2 aging2 aging-total2) b)
+                   (increasing? (eq? sort-order 'increasing))
+                   (op-str (if increasing? string<? string>?))
+                   (op-num (if increasing? < >)))
+        (case sort-by
+          ((name)  (op-str (gncOwnerGetName own1) (gncOwnerGetName own2)))
+          ((total) (op-num aging-total1 aging-total2))
+          (else
+           (let lp ((aging1 aging1) (aging2 aging2))
+             (cond
+              ((null? aging1) (op-str (gncOwnerGetName own1) (gncOwnerGetName own2)))
+              ((= (car aging1) (car aging2)) (lp (cdr aging1) (cdr aging2)))
+              (else (op-num (car aging1) (car aging2)))))))))
 
     ;; set default title
     (gnc:html-document-set-title! document report-title)
@@ -313,7 +341,7 @@ exist but have no suitable transactions."))
                                 (gnc:owner-report-text owner account)
                                 (gnc:make-gnc-monetary comm aging-total)))))
                             (options->address options receivable owner)))))
-                      (reverse owners-and-aging))
+                      (sort owners-and-aging sort-aging<?))
 
                      (gnc:html-table-append-row!
                       table
@@ -368,9 +396,8 @@ exist but have no suitable transactions."))
                            (gncOwnerFree owner)
                            b))))
                      '() acc-splits))
-                   (acc-owners (sort (sort-and-delete-duplicates
-                                      split-owners ownerGUID<? gnc-owner-equal?)
-                                     owner<?)))
+                   (acc-owners (sort-and-delete-duplicates
+                                split-owners ownerGUID<? gnc-owner-equal?)))
 
               ;; loop into each APAR account split
               (let lp ((acc-owners acc-owners)



Summary of changes:
 gnucash/report/business-reports/new-aging.scm    | 45 +++++++++++---
 gnucash/report/standard-reports/balsheet-pnl.scm | 74 +++---------------------
 2 files changed, 44 insertions(+), 75 deletions(-)



More information about the gnucash-changes mailing list