[new-owner-report] if Payment amount is negative, label "Refund"

and add logic to properly handle AP/AR negation rules
This commit is contained in:
Christopher Lam 2020-02-09 09:54:25 +08:00
parent 6e64a37839
commit 09d3e95379
2 changed files with 19 additions and 17 deletions

View File

@ -274,12 +274,14 @@
(let ((inv (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot split)))) (let ((inv (gncInvoiceGetInvoiceFromLot (xaccSplitGetLot split))))
(gnc:make-html-text (invoice->anchor inv))))))) (gnc:make-html-text (invoice->anchor inv)))))))
(define (split->type-str split) (define (split->type-str split payable?)
(let* ((txn (xaccSplitGetParent split)) (let* ((txn (xaccSplitGetParent split))
(amt (xaccSplitGetAmount split))
(refund? (if payable? (< amt 0) (> amt 0)))
(invoice (gncInvoiceGetInvoiceFromTxn txn))) (invoice (gncInvoiceGetInvoiceFromTxn txn)))
(cond (cond
((txn-is-invoice? txn) (gncInvoiceGetTypeString invoice)) ((txn-is-invoice? txn) (gncInvoiceGetTypeString invoice))
((txn-is-payment? txn) (_ "Payment")) ((txn-is-payment? txn) (if refund? (_ "Refund") (_ "Payment")))
((txn-is-link? txn) (_ "Link")) ((txn-is-link? txn) (_ "Link"))
(else (_ "Unknown"))))) (else (_ "Unknown")))))
@ -573,7 +575,7 @@
(cons (make-link-data (cons (make-link-data
(qof-print-date (xaccTransGetDate lot-txn)) (qof-print-date (xaccTransGetDate lot-txn))
(split->reference lot-split) (split->reference lot-split)
(split->type-str lot-split) (split->type-str lot-split payable?)
(splits->desc non-document) (splits->desc non-document)
(gnc:make-html-text (split->anchor lot-split #t)) (gnc:make-html-text (split->anchor lot-split #t))
(list->cell (list->cell
@ -600,7 +602,7 @@
(cons (make-link-data (cons (make-link-data
(qof-print-date (xaccTransGetDate posting-txn)) (qof-print-date (xaccTransGetDate posting-txn))
(split->reference posting-split) (split->reference posting-split)
(split->type-str posting-split) (split->type-str posting-split payable?)
(splits->desc (list posting-split)) (splits->desc (list posting-split))
(gnc:make-html-text (split->anchor lot-split neg)) (gnc:make-html-text (split->anchor lot-split neg))
(gnc:make-html-text (split->anchor posting-split neg)) (gnc:make-html-text (split->anchor posting-split neg))
@ -689,7 +691,7 @@
(make-link-data (make-link-data
(qof-print-date (xaccTransGetDate (xaccSplitGetParent s))) (qof-print-date (xaccTransGetDate (xaccSplitGetParent s)))
(split->reference s) (split->reference s)
(split->type-str s) (split->type-str s payable?)
(splits->desc (list s)) (splits->desc (list s))
(gnc:make-html-text (split->anchor s #f)) (gnc:make-html-text (split->anchor s #f))
(gnc:make-html-text (split->anchor s #f)) (gnc:make-html-text (split->anchor s #f))
@ -771,7 +773,7 @@
(add-row (add-row
table odd-row? used-columns date (gncInvoiceGetDateDue invoice) table odd-row? used-columns date (gncInvoiceGetDateDue invoice)
(split->reference split) (split->reference split)
(split->type-str split) (split->type-str split payable?)
(splits->desc (list split)) (splits->desc (list split))
currency (+ total value) currency (+ total value)
(and (>= orig-value 0) (amount->anchor split orig-value)) (and (>= orig-value 0) (amount->anchor split orig-value))
@ -800,7 +802,7 @@
(add-row (add-row
table odd-row? used-columns date #f table odd-row? used-columns date #f
(split->reference split) (split->reference split)
(split->type-str split) (split->type-str split payable?)
(splits->desc (xaccTransGetAPARAcctSplitList txn #t)) (splits->desc (xaccTransGetAPARAcctSplitList txn #t))
currency (+ total value) currency (+ total value)
(and (>= orig-value 0) (amount->anchor split orig-value)) (and (>= orig-value 0) (amount->anchor split orig-value))

View File

@ -274,25 +274,25 @@
((sxpath `(// (table 3) // (tr 11) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 11) // *text*)) sxml))
;; tests for refund $120 to partially repay ;; tests for refund $120 to partially repay
(test-equal "line 12" (test-equal "line 12 refund $120 to partially repay"
'("1980-06-28" "Payment" "-$148.25" "1980-06-30" "Payment" '("1980-06-28" "Payment" "-$148.25" "1980-06-30" "Refund"
"$160.00" "$50.00" "$50.00") "$160.00" "$50.00" "$50.00")
((sxpath `(// (table 3) // (tr 12) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 12) // *text*)) sxml))
(test-equal "line 13" (test-equal "line 13 refund $120 to partially repay"
'("1980-06-29" "Payment" "$120.00" "$120.00") '("1980-06-29" "Refund" "$120.00" "$120.00")
((sxpath `(// (table 3) // (tr 13) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 13) // *text*)) sxml))
(test-equal "line 14" (test-equal "line 14 refund $120 to partially repay"
'("Pre-Payment" "-$10.00") '("Pre-Payment" "-$10.00")
((sxpath `(// (table 3) // (tr 14) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 14) // *text*)) sxml))
(test-equal "line 15" (test-equal "line 15 refund $120 to partially repay"
'("1980-06-29" "Payment" "-$28.25" "1980-06-28" "Payment" '("1980-06-29" "Refund" "-$28.25" "1980-06-28" "Payment"
"$120.00" "-$120.00" "-$120.00") "$120.00" "-$120.00" "-$120.00")
((sxpath `(// (table 3) // (tr 15) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 15) // *text*)) sxml))
(test-equal "line 16" (test-equal "line 16 refund $120 to partially repay"
'("1980-06-30" "Payment" "$21.75" "1980-06-28" "Payment" '("1980-06-30" "Refund" "$21.75" "1980-06-28" "Payment"
"$50.00" "-$40.00" "-$40.00") "$50.00" "-$40.00" "-$40.00")
((sxpath `(// (table 3) // (tr 16) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 16) // *text*)) sxml))
(test-equal "line 17" (test-equal "line 17 refund $120 to partially repay"
'("Pre-Payment" "-$10.00") '("Pre-Payment" "-$10.00")
((sxpath `(// (table 3) // (tr 17) // *text*)) sxml)) ((sxpath `(// (table 3) // (tr 17) // *text*)) sxml))