diff --git a/src/engine/Query.c b/src/engine/Query.c index 06e837c93c..cdf1764206 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -587,6 +587,20 @@ xaccQueryAddKVPMatch(QofQuery *q, GSList *path, const KvpValue *value, qof_query_add_term (q, param_list, pred_data, op); } +/******************************************************************** + * xaccQueryAddClosingTransMatch + * Add a filter that matches book closing entries to an existing query. + ********************************************************************/ + +void +xaccQueryAddClosingTransMatch(QofQuery *q, gboolean value, QofQueryOp op) +{ + GSList *param_list; + + param_list = qof_query_build_param_list(SPLIT_TRANS, TRANS_IS_CLOSING, NULL); + qof_query_add_boolean_match(q, param_list, value, op); +} + /******************************************************************* * xaccQueryGetEarliestDateFound *******************************************************************/ diff --git a/src/engine/Query.h b/src/engine/Query.h index 39425fb787..e994b5ec25 100644 --- a/src/engine/Query.h +++ b/src/engine/Query.h @@ -166,6 +166,8 @@ void xaccQueryGetDateMatchTT (QofQuery * q, time64 * stt, time64 * ett); +void xaccQueryAddClosingTransMatch(QofQuery *q, gboolean value, QofQueryOp op); + typedef enum { CLEARED_NONE = 0x0000, diff --git a/src/report/report-system/report-utilities.scm b/src/report/report-system/report-utilities.scm index eed68b78ba..5ab9ac9a23 100644 --- a/src/report/report-system/report-utilities.scm +++ b/src/report/report-system/report-utilities.scm @@ -890,7 +890,13 @@ ) ;; Return the splits that match an account list, date range, and (optionally) type -;; where type is defined as an alist '((str "match me") (cased #f) (regexp #f)) +;; where type is defined as an alist like: +;; '((str "match me") (cased #f) (regexp #f) (closing #f)) +;; where str, cased, and regexp define a pattern match on transaction deseriptions +;; and "closing" matches transactions created by the book close command. If "closing" +;; is given as #t then only closing transactions will be returned, if it is #f then +;; only non-closing transactions will be returned, and if it is omitted then both +;; kinds of transactions will be returned. (define (gnc:account-get-trans-type-splits-interval account-list type start-date-tp end-date-tp) (if (null? account-list) @@ -898,6 +904,7 @@ '() ;; The normal case: There are accounts given. (let* ((query (qof-query-create-for-splits)) + (query2 #f) (splits #f) (get-val (lambda (alist key) (let ((lst (assoc-ref alist key))) @@ -905,6 +912,7 @@ (matchstr (get-val type 'str)) (case-sens (if (get-val type 'cased) #t #f)) (regexp (if (get-val type 'regexp) #t #f)) + (closing (if (get-val type 'closing) #t #f)) ) (qof-query-set-book query (gnc-get-current-book)) (gnc:query-set-match-non-voids-only! query (gnc-get-current-book)) @@ -913,9 +921,16 @@ query (and start-date-tp #t) start-date-tp (and end-date-tp #t) end-date-tp QOF-QUERY-AND) - (if type (xaccQueryAddDescriptionMatch - query matchstr case-sens regexp QOF-QUERY-AND)) - + (if (or matchstr closing) + (begin + (set! query2 (qof-query-create-for-splits)) + (if matchstr (xaccQueryAddDescriptionMatch + query2 matchstr case-sens regexp QOF-QUERY-OR)) + (if closing (xaccQueryAddClosingTransMatch query2 1 QOF-QUERY-OR)) + (qof-query-merge-in-place query query2 QOF-QUERY-AND) + (qof-query-destroy query2) + )) + (set! splits (qof-query-run query)) (qof-query-destroy query) splits diff --git a/src/report/standard-reports/equity-statement.scm b/src/report/standard-reports/equity-statement.scm index 3732b904c9..841c2ff9a5 100644 --- a/src/report/standard-reports/equity-statement.scm +++ b/src/report/standard-reports/equity-statement.scm @@ -261,6 +261,7 @@ (list 'cased closing-cased) (list 'regexp closing-regexp) (list 'positive #f) + (list 'closing #t) ) ) diff --git a/src/report/standard-reports/income-statement.scm b/src/report/standard-reports/income-statement.scm index 548b0cb600..2ade73fdd2 100644 --- a/src/report/standard-reports/income-statement.scm +++ b/src/report/standard-reports/income-statement.scm @@ -364,6 +364,7 @@ (list (list 'str closing-str) (list 'cased closing-cased) (list 'regexp closing-regexp) + (list 'closing #t) ) ) (indent 0) diff --git a/src/report/standard-reports/trial-balance.scm b/src/report/standard-reports/trial-balance.scm index 2f18c2e22a..f3701c2aac 100644 --- a/src/report/standard-reports/trial-balance.scm +++ b/src/report/standard-reports/trial-balance.scm @@ -702,20 +702,22 @@ (group (list acct)) (curr-bal (get-val env 'account-bal)) (closing - (gnc:account-get-trans-type-balance-interval + (gnc:account-get-trans-type-balance-interval-with-closing group (list (list 'str closing-str) (list 'cased closing-cased) (list 'regexp closing-regexp) + (list 'closing #t) ) start-date-tp end-date-tp )) (adjusting - (gnc:account-get-trans-type-balance-interval + (gnc:account-get-trans-type-balance-interval-with-closing group (list (list 'str adjusting-str) (list 'cased adjusting-cased) (list 'regexp adjusting-regexp) + (list 'closing #t) ) start-date-tp end-date-tp ))