mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[trial-balance] rewrite to omit account-get-pos-trans-total-interval
Reuse adjusting-splits and filter for positive values. This function was buggy... see total-query is defined as the output of qof-query-merge-in-place, or qof-query-destroy, both returning #unspecified; this fails when passed to qof-query-run.
This commit is contained in:
parent
0ec82872b0
commit
268e9670e2
@ -318,57 +318,6 @@
|
|||||||
|
|
||||||
options))
|
options))
|
||||||
|
|
||||||
(define (account-get-pos-trans-total-interval
|
|
||||||
account-list type start-date end-date)
|
|
||||||
(let* ((str-query (qof-query-create-for-splits))
|
|
||||||
(sign-query (qof-query-create-for-splits))
|
|
||||||
(total-query #f)
|
|
||||||
(get-val (lambda (alist key)
|
|
||||||
(let ((lst (assoc-ref alist key)))
|
|
||||||
(and lst (car lst)))))
|
|
||||||
(matchstr (get-val type 'str))
|
|
||||||
(case-sens (and (get-val type 'cased) #t))
|
|
||||||
(regexp (and (get-val type 'regexp) #t))
|
|
||||||
(pos? (and (get-val type 'positive) #t))
|
|
||||||
(total (gnc:make-commodity-collector)))
|
|
||||||
(qof-query-set-book str-query (gnc-get-current-book))
|
|
||||||
(qof-query-set-book sign-query (gnc-get-current-book))
|
|
||||||
(gnc:query-set-match-non-voids-only! str-query (gnc-get-current-book))
|
|
||||||
(gnc:query-set-match-non-voids-only! sign-query (gnc-get-current-book))
|
|
||||||
(xaccQueryAddAccountMatch str-query account-list QOF-GUID-MATCH-ANY QOF-QUERY-AND)
|
|
||||||
(xaccQueryAddAccountMatch sign-query account-list QOF-GUID-MATCH-ANY QOF-QUERY-AND)
|
|
||||||
(xaccQueryAddDateMatchTT str-query
|
|
||||||
(and start-date #t) (or start-date 0)
|
|
||||||
(and end-date #t) (or end-date 0)
|
|
||||||
QOF-QUERY-AND)
|
|
||||||
(xaccQueryAddDateMatchTT sign-query
|
|
||||||
(and start-date #t) (or start-date 0)
|
|
||||||
(and end-date #t) (or end-date 0)
|
|
||||||
QOF-QUERY-AND)
|
|
||||||
(xaccQueryAddDescriptionMatch
|
|
||||||
str-query matchstr case-sens regexp QOF-COMPARE-CONTAINS QOF-QUERY-AND)
|
|
||||||
(set! total-query
|
|
||||||
;; this is a tad inefficient, but its a simple way to accomplish
|
|
||||||
;; description match inversion...
|
|
||||||
(if pos?
|
|
||||||
(qof-query-merge-in-place sign-query str-query QOF-QUERY-AND)
|
|
||||||
(let ((inv-query (qof-query-invert str-query)))
|
|
||||||
(qof-query-merge-in-place
|
|
||||||
sign-query inv-query QOF-QUERY-AND)
|
|
||||||
(qof-query-destroy inv-query))))
|
|
||||||
(qof-query-destroy str-query)
|
|
||||||
|
|
||||||
(for-each
|
|
||||||
(lambda (split)
|
|
||||||
(let* ((shares (xaccSplitGetAmount split))
|
|
||||||
(acct-comm (xaccAccountGetCommodity
|
|
||||||
(xaccSplitGetAccount split))))
|
|
||||||
(unless (negative? shares)
|
|
||||||
(total 'add acct-comm shares))))
|
|
||||||
(qof-query-run total-query))
|
|
||||||
(qof-query-destroy total-query)
|
|
||||||
total))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; trial-balance-renderer
|
;; trial-balance-renderer
|
||||||
;; set up the document and add the table
|
;; set up the document and add the table
|
||||||
@ -706,35 +655,30 @@
|
|||||||
(list 'regexp adjusting-regexp))
|
(list 'regexp adjusting-regexp))
|
||||||
start-date end-date)))
|
start-date end-date)))
|
||||||
|
|
||||||
(define (sum-account-splits account splits)
|
(define (sum-account-splits account splits pos-filter?)
|
||||||
(let ((total (gnc:make-commodity-collector))
|
(let ((total (gnc:make-commodity-collector))
|
||||||
(comm (xaccAccountGetCommodity account)))
|
(comm (xaccAccountGetCommodity account)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
(when (equal? (xaccSplitGetAccount s) account)
|
(let ((amt (xaccSplitGetAmount s)))
|
||||||
(total 'add comm (xaccSplitGetAmount s))))
|
(when (and (equal? (xaccSplitGetAccount s) account)
|
||||||
|
(or (not pos-filter?) (positive? amt)))
|
||||||
|
(total 'add comm amt))))
|
||||||
splits)
|
splits)
|
||||||
total))
|
total))
|
||||||
|
|
||||||
(while (< row rows)
|
(while (< row rows)
|
||||||
(let* ((env (gnc:html-acct-table-get-row-env acct-table row))
|
(let* ((env (gnc:html-acct-table-get-row-env acct-table row))
|
||||||
(acct (get-val env 'account))
|
(acct (get-val env 'account))
|
||||||
(group (list acct))
|
|
||||||
(curr-bal (get-val env 'account-bal))
|
(curr-bal (get-val env 'account-bal))
|
||||||
(closing (sum-account-splits acct closing-splits))
|
(closing (sum-account-splits acct closing-splits #f))
|
||||||
(adjusting (sum-account-splits acct adjusting-splits))
|
(adjusting (sum-account-splits acct adjusting-splits #f))
|
||||||
(is? (member acct all-is-accounts))
|
(is? (member acct all-is-accounts))
|
||||||
(ga-or-is? (or (member acct all-ga-accounts) is?))
|
(ga-or-is? (or (member acct all-ga-accounts) is?))
|
||||||
(pos-adjusting
|
(pos-adjusting
|
||||||
(and ga-or-is?
|
(and ga-or-is?
|
||||||
adjusting
|
adjusting
|
||||||
(account-get-pos-trans-total-interval
|
(sum-account-splits acct adjusting-splits #t)))
|
||||||
group
|
|
||||||
(list (list 'str adjusting-str)
|
|
||||||
(list 'cased adjusting-cased)
|
|
||||||
(list 'regexp adjusting-regexp)
|
|
||||||
(list 'positive #t))
|
|
||||||
start-date end-date)))
|
|
||||||
(neg-adjusting
|
(neg-adjusting
|
||||||
(and pos-adjusting (gnc:make-commodity-collector)))
|
(and pos-adjusting (gnc:make-commodity-collector)))
|
||||||
(pre-closing-bal (gnc:make-commodity-collector))
|
(pre-closing-bal (gnc:make-commodity-collector))
|
||||||
|
Loading…
Reference in New Issue
Block a user