gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Mon Nov 11 09:09:43 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/346d2e24 (commit)
via https://github.com/Gnucash/gnucash/commit/3d5d8191 (commit)
via https://github.com/Gnucash/gnucash/commit/980776f4 (commit)
from https://github.com/Gnucash/gnucash/commit/9189bcbe (commit)
commit 346d2e24da17e30b93b011324e76c196cf2c9974
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Nov 11 21:09:25 2019 +0800
[new-owner-report] use total-number-cell for monetaries
Previous would tag all cells as total-label-cell. Tag monetaries with
total-number-cell which leads to right-aligned period totals.
diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index 8764cbb0e..2987db118 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-label-cell" cell))
+ (gnc:make-html-table-cell/markup "total-number-cell" cell))
(define (make-cell amt)
(total-cell (gnc:make-gnc-monetary currency amt)))
(define span
@@ -264,7 +264,8 @@
(gnc:html-table-append-row/markup!
table "grand-total"
(append
- (list (total-cell (_ "Period Totals")))
+ (list (gnc:make-html-table-cell/markup
+ "total-label-cell" (_ "Period Totals")))
(addif (>= span 2) (gnc:make-html-table-cell/size 1 (1- span) ""))
(addif (sale-col used-columns) (make-cell sale))
(addif (tax-col used-columns) (make-cell tax))
@@ -278,7 +279,8 @@
(gnc:html-table-append-row/markup!
table "grand-total"
(append
- (list (total-cell
+ (list (gnc:make-html-table-cell/markup
+ "total-label-cell"
(if (negative? total)
(_ "Total Credit")
(_ "Total Due")))
commit 3d5d8191dd1aca478269fc4046e3ce180c6f223e
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Nov 10 23:42:26 2019 +0800
[report-utilities] fix: overpayments in gnc:owner-splits->aging-list
Previous algorithm had assumed all payments would match attached
invoices. This updated algorithm does not assume.
Invoice: add into appropriate bucket and save invoice+splits into
list.
Payment: scan payments from invoice+splits to find appropriate
invoice, and deduct from the transfer account. The remainder is an
pre/overpayment and added into prepayment bucket.
It will always assume that the splitlist being processed will *all*
belong to one owner.
diff --git a/gnucash/report/report-system/report-utilities.scm b/gnucash/report/report-system/report-utilities.scm
index 825928834..1cc84bad0 100644
--- a/gnucash/report/report-system/report-utilities.scm
+++ b/gnucash/report/report-system/report-utilities.scm
@@ -1114,18 +1114,19 @@ flawed. see report-utilities.scm. please update reports.")
(buckets (make-vector num-buckets 0)))
(define (addbucket! idx amt)
(vector-set! buckets idx (+ amt (vector-ref buckets idx))))
- (let lp ((splits splits))
+ (let lp ((splits splits)
+ (invoices-and-splits '()))
(cond
((null? splits)
(vector->list buckets))
- ;; next split is an invoice posting split. note we don't need
- ;; to handle invoice payments because these payments will
- ;; reduce the lot balance automatically.
+ ;; next split is an invoice posting split. add its balance to
+ ;; bucket, and add splits to invoices-and-splits for payments.
((eqv? (xaccTransGetTxnType (xaccSplitGetParent (car splits)))
TXN-TYPE-INVOICE)
(let* ((invoice (gncInvoiceGetInvoiceFromTxn
(xaccSplitGetParent (car splits))))
+ (inv-splits (gnc-lot-get-split-list (gncInvoiceGetPostedLot invoice)))
(lot (gncInvoiceGetPostedLot invoice))
(bal (gnc-lot-get-balance lot))
(bal (if receivable? bal (- bal)))
@@ -1136,23 +1137,33 @@ flawed. see report-utilities.scm. please update reports.")
(let loop ((idx 0) (bucket-dates bucket-dates))
(if (< date (car bucket-dates))
(addbucket! idx bal)
- (loop (1+ idx) (cdr bucket-dates)))))
- (lp (cdr splits)))
-
- ;; next split is a prepayment
- ((and (eqv? (xaccTransGetTxnType (xaccSplitGetParent (car splits)))
- TXN-TYPE-PAYMENT)
- (null? (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot (car splits)))))
- (let* ((prepay (xaccSplitGetAmount (car splits)))
- (prepay (if receivable? prepay (- prepay))))
- (gnc:pk 'next=prepay (car splits) prepay)
- (addbucket! (1- num-buckets) prepay))
- (lp (cdr splits)))
+ (loop (1+ idx) (cdr bucket-dates))))
+ (lp (cdr splits)
+ (cons (cons invoice inv-splits) invoices-and-splits))))
+
+ ;; next split is a payment. find the associated invoices,
+ ;; deduct their totals. the remaining is an overpayment.
+ ((eqv? (xaccTransGetTxnType (xaccSplitGetParent (car splits)))
+ TXN-TYPE-PAYMENT)
+ (let* ((txn (xaccSplitGetParent (car splits)))
+ (payment (apply + (map xaccSplitGetAmount
+ (xaccTransGetPaymentAcctSplitList txn))))
+ (overpayment
+ (fold
+ (lambda (inv-and-splits payment-left)
+ (if (member txn (map xaccSplitGetParent (cdr inv-and-splits)))
+ (- payment-left (gncInvoiceGetTotal (car inv-and-splits)))
+ payment-left))
+ (if receivable? payment (- payment)) invoices-and-splits)))
+ (gnc:pk 'payment (car splits) payment "->" overpayment)
+ (when (positive? overpayment)
+ (addbucket! (1- num-buckets) (- overpayment)))
+ (lp (cdr splits) invoices-and-splits)))
;; not invoice/prepayment. regular or payment split.
(else
(gnc:pk 'next=skipped (car splits))
- (lp (cdr splits)))))))
+ (lp (cdr splits) invoices-and-splits))))))
;; ***************************************************************************
commit 980776f46f9fc84f9aedbb566ff4fa33beaa7273
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Nov 10 22:17:29 2019 +0800
[new-owner-report] fix: overpayments must show prepayment row
If a payment exceeds the amounts from associated invoices, the amount
remaining must be considered a prepayment.
diff --git a/gnucash/report/business-reports/new-owner-report.scm b/gnucash/report/business-reports/new-owner-report.scm
index ee8263f70..8764cbb0e 100644
--- a/gnucash/report/business-reports/new-owner-report.scm
+++ b/gnucash/report/business-reports/new-owner-report.scm
@@ -348,29 +348,33 @@
#f)))
payment-splits)))))
- (define (make-payment->invoices-table split payment-splits currency)
- (if (null? payment-splits)
- (list (list (gnc:make-html-table-cell/size 1 2 (_ "Prepayments"))
- (make-cell
- (gnc:make-gnc-monetary
- currency (- (xaccSplitGetAmount split))))))
- (map
- (lambda (inv-splits)
- (let ((inv (car inv-splits))
- (inv-split (cadr inv-splits)))
- (list
- (qof-print-date
- (gncInvoiceGetDatePosted inv))
- (gnc:make-html-text
- (gnc:html-markup-anchor
- (gnc:invoice-anchor-text inv)
- (gnc-get-num-action
- (gncInvoiceGetPostedTxn inv) #f)))
- (make-cell
- (gnc:make-gnc-monetary
- currency
- (- (xaccSplitGetAmount inv-split)))))))
- payment-splits)))
+ (define (make-payment->invoices-table amount payment-splits currency)
+ (let lp ((payment-splits payment-splits)
+ (amount (- amount))
+ (result '()))
+ (cond
+ ((null? payment-splits)
+ (reverse
+ (if (positive? amount)
+ (cons (list (gnc:make-html-table-cell/size 1 2 (_ "Prepayments"))
+ (make-cell (gnc:make-gnc-monetary currency amount)))
+ result)
+ result)))
+ (else
+ (let* ((payment-split (car payment-splits))
+ (inv (car payment-split))
+ (inv-split (cadr payment-split))
+ (inv-amount (xaccSplitGetAmount inv-split)))
+ (lp (cdr payment-splits)
+ (- amount inv-amount)
+ (cons (list
+ (qof-print-date (gncInvoiceGetDatePosted inv))
+ (gnc:make-html-text
+ (gnc:html-markup-anchor
+ (gnc:invoice-anchor-text inv)
+ (gnc-get-num-action (gncInvoiceGetPostedTxn inv) #f)))
+ (make-cell (gnc:make-gnc-monetary currency inv-amount)))
+ result)))))))
(define (split->type-str split)
(let* ((txn (xaccSplitGetParent split))
@@ -494,7 +498,7 @@
((and payment-splits (eq? link-option 'simple))
(make-payment->invoices-list invoice payment-splits))
((and payment-splits (eq? link-option 'detailed))
- (make-payment->invoices-table split payment-splits currency))
+ (make-payment->invoices-table value payment-splits currency))
;; some error occurred, show 1 line containing empty-list
(else '(()))))
Summary of changes:
.../report/business-reports/new-owner-report.scm | 60 ++++++++++++----------
gnucash/report/report-system/report-utilities.scm | 45 ++++++++++------
2 files changed, 61 insertions(+), 44 deletions(-)
More information about the gnucash-changes
mailing list