diff --git a/gnucash/report/standard-reports/income-gst-statement.scm b/gnucash/report/standard-reports/income-gst-statement.scm index 2cd7b7e27a..82d6bb7423 100644 --- a/gnucash/report/standard-reports/income-gst-statement.scm +++ b/gnucash/report/standard-reports/income-gst-statement.scm @@ -37,6 +37,7 @@ ;; Define the strings here to avoid typos and make changes easier. (define reportname (N_ "Income & GST Statement")) (define pagename-sorting (N_ "Sorting")) +(define pagename-filter (N_ "Filter")) (define TAX-SETUP-DESC (string-append (_ "This report is useful to calculate periodic business tax payable/receivable from @@ -63,10 +64,9 @@ accounts must be of type ASSET for taxes paid on expenses, and type LIABILITY fo ;; split -> bool ;; ;; additional split filter - returns #t if split must be included - ;; we need to exclude Closing, Link and Payment transactions - (let ((trans (xaccSplitGetParent split))) - (and (member (xaccTransGetTxnType trans) (list TXN-TYPE-NONE TXN-TYPE-INVOICE)) - (not (xaccTransGetIsClosingTxn trans))))) + ;; we need to exclude Link and Payment transactions + (memv (xaccTransGetTxnType (xaccSplitGetParent split)) + (list TXN-TYPE-NONE TXN-TYPE-INVOICE))) (define (gst-statement-options-generator) @@ -115,6 +115,9 @@ for taxes paid on expenses, and type LIABILITY for taxes collected on sales.") (gnc:option-make-internal! options gnc:pagename-accounts "Filter Type") (gnc:option-make-internal! options gnc:pagename-accounts "Filter By...") (gnc:option-make-internal! options gnc:pagename-general "Show original currency amount") + ;; Disallow closing transactions + (gnc:option-set-value (gnc:lookup-option options pagename-filter "Closing transactions") 'exclude-closing) + (gnc:option-make-internal! options pagename-filter "Closing transactions") ;; Disable display options not being used anymore (gnc:option-make-internal! options gnc:pagename-display "Shares") (gnc:option-make-internal! options gnc:pagename-display "Price") diff --git a/gnucash/report/standard-reports/test/test-transaction.scm b/gnucash/report/standard-reports/test/test-transaction.scm index 35800f47b1..6b27989ea3 100644 --- a/gnucash/report/standard-reports/test/test-transaction.scm +++ b/gnucash/report/standard-reports/test/test-transaction.scm @@ -184,6 +184,7 @@ (list "Income" (list (cons 'type ACCT-TYPE-INCOME))) (list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE))) (list "Liabilities" (list (cons 'type ACCT-TYPE-LIABILITY))) + (list "Equity" (list (cons 'type ACCT-TYPE-EQUITY))) )) (define (null-test) @@ -202,6 +203,7 @@ (income (cdr (assoc "Income" account-alist))) (expense (cdr (assoc "Expenses" account-alist))) (liability (cdr (assoc "Liabilities" account-alist))) + (equity (cdr (assoc "Equity" account-alist))) (YEAR (gnc:time64-get-year (gnc:get-today))) (foreign1 (gnc-commodity-table-lookup (gnc-commodity-table-get-table (gnc-account-get-book bank)) @@ -288,6 +290,10 @@ (xaccTransSetNotes txn "multisplit") (xaccTransCommitEdit txn)) + ;; A single closing transaction + (let ((closing-txn (env-transfer env 31 12 1999 expense equity 111 #:description "Closing"))) + (xaccTransSetIsClosingTxn closing-txn #t)) + ;; A couple of transactions which involve foreign currency ;; conversions. We'll set the currencies to GBP and USD. (env-transfer-foreign env 15 01 2000 gbp-bank usd-bank 10 14 #:description "GBP 10 to USD 14") @@ -464,7 +470,31 @@ (let ((sxml (options->sxml options "both void and non-void"))) (test-equal "filter void-transactions only, sum = $11.00" '("$11.00") - (get-row-col sxml -1 -1)))) + (get-row-col sxml -1 -1))) + + ;; Test Closing-Txn Filters + (set! options (default-testing-options)) + (set-option! options "Accounts" "Accounts" (list expense)) + (set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 01 01 1911))) + (set-option! options "General" "End Date" (cons 'absolute (gnc-dmy2time64 31 12 2012))) + (set-option! options "Filter" "Closing transactions" 'exclude-closing) + (let ((sxml (options->sxml options "filter closing - exclude closing txns "))) + (test-equal "filter exclude closing. bal = $111" + '("$111.00") + (get-row-col sxml -1 -1))) + + (set-option! options "Filter" "Closing transactions" 'closing-only) + (let ((sxml (options->sxml options "filter closing - include closing only"))) + (test-equal "filter closing only. bal = -$111" + '("-$111.00") + (get-row-col sxml -1 -1))) + + (set-option! options "Filter" "Closing transactions" 'include-both) + (let ((sxml (options->sxml options "filter closing - include both"))) + (test-equal "filter include both. bal = $0" + '("$0.00") + (get-row-col sxml -1 -1))) + ) (test-end "accounts selectors and filtering") diff --git a/gnucash/report/standard-reports/transaction.scm b/gnucash/report/standard-reports/transaction.scm index 7178ddfc82..00bcf6db50 100644 --- a/gnucash/report/standard-reports/transaction.scm +++ b/gnucash/report/standard-reports/transaction.scm @@ -17,6 +17,7 @@ ;; - add support for indenting for better grouping ;; - add defaults suitable for a reconciliation report ;; - add subtotal summary grid +;; - by default, exclude closing transactions from the report ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -98,6 +99,7 @@ (define optname-transaction-matcher-regex (N_ "Use regular expressions for transaction filter")) (define optname-reconcile-status (N_ "Reconcile Status")) (define optname-void-transactions (N_ "Void Transactions")) +(define optname-closing-transactions (N_ "Closing transactions")) ;;Styles (define def:grand-total-style "grand-total") @@ -325,6 +327,23 @@ in the Options panel.")) (cons 'text (_ "Both")) (cons 'tip (_ "Show both (and include void transactions in totals).")))))) +(define show-closing-list + (list + (cons 'exclude-closing (list + (cons 'text (_ "Exclude closing transactions")) + (cons 'tip (_ "Exclude closing transactions from report.")) + (cons 'closing-match #f))) + + (cons 'include-both (list + (cons 'text (_ "Show both closing and regular transactions")) + (cons 'tip (_ "Show both (and include closing transactions in totals).")) + (cons 'closing-match 'both))) + + (cons 'closing-only (list + (cons 'text (_ "Show closing transactions only")) + (cons 'tip (_ "Show only closing transactions.")) + (cons 'closing-match #t))))) + (define reconcile-status-list ;; 'filter-types must be either #f (i.e. disable reconcile filter) ;; or a value defined as defined in Query.c @@ -555,6 +574,16 @@ tags within description, notes or memo. ") 'non-void-only (keylist->vectorlist show-void-list))) + (gnc:register-trep-option + (gnc:make-multichoice-option + pagename-filter optname-closing-transactions + "l" (_ "By default most users should not include closing \ +transactions in a transaction report. Closing transactions are \ +transfers from INCOME and EXPENSE accounts to equity, and must usually \ +be excluded from periodic reporting.") + 'exclude-closing + (keylist->vectorlist show-closing-list))) + ;; Accounts options ;; account to do report on @@ -1787,6 +1816,9 @@ tags within description, notes or memo. ") (secondary-order (opt-val pagename-sorting optname-sec-sortorder)) (secondary-date-subtotal (opt-val pagename-sorting optname-sec-date-subtotal)) (void-status (opt-val pagename-filter optname-void-transactions)) + (closing-match (keylist-get-info show-closing-list + (opt-val pagename-filter optname-closing-transactions) + 'closing-match)) (splits '()) (custom-sort? (or (and (member primary-key DATE-SORTING-TYPES) ; this will remain (not (eq? primary-date-subtotal 'none))) ; until qof-query @@ -1866,6 +1898,8 @@ tags within description, notes or memo. ") (else #f)) (if reconcile-status-filter (xaccQueryAddClearedMatch query reconcile-status-filter QOF-QUERY-AND)) + (if (boolean? closing-match) + (xaccQueryAddClosingTransMatch query closing-match QOF-QUERY-AND)) (if (not custom-sort?) (begin (qof-query-set-sort-order query