From 2f4e33a86f58b8630bc0bc49f69a4f6f15176c85 Mon Sep 17 00:00:00 2001 From: Mike Alexander Date: Wed, 19 Jan 2011 04:17:06 +0000 Subject: [PATCH] Make it possible to include trading accounts in the Income Statement and Profit and Loss reports. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20124 57a11ea4-9604-0410-9ed3-97b8803252fd --- .../standard-reports/income-statement.scm | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/src/report/standard-reports/income-statement.scm b/src/report/standard-reports/income-statement.scm index f850c43a90..9adeb1a6fb 100644 --- a/src/report/standard-reports/income-statement.scm +++ b/src/report/standard-reports/income-statement.scm @@ -93,6 +93,12 @@ (define optname-total-revenue (N_ "Include revenue total")) (define opthelp-total-revenue (N_ "Whether or not to include a line indicating total revenue")) +(define optname-label-trading (N_ "Label the trading accounts section")) +(define opthelp-label-trading + (N_ "Whether or not to include a label for the trading accounts section")) +(define optname-total-trading (N_ "Include trading accounts total")) +(define opthelp-total-trading + (N_ "Whether or not to include a line indicating total trading accounts balance")) (define optname-label-expense (N_ "Label the expense section")) (define opthelp-label-expense (N_ "Whether or not to include a label for the expense section")) @@ -227,6 +233,15 @@ gnc:pagename-display optname-total-revenue "h" opthelp-total-revenue #t)) + (add-option + (gnc:make-simple-boolean-option + gnc:pagename-display optname-label-trading + "h1" opthelp-label-trading #t)) + (add-option + (gnc:make-simple-boolean-option + gnc:pagename-display optname-total-trading + "h2" opthelp-total-trading #t)) + (add-option (gnc:make-simple-boolean-option gnc:pagename-display optname-label-expense @@ -325,6 +340,10 @@ optname-label-revenue)) (total-revenue? (get-option gnc:pagename-display optname-total-revenue)) + (label-trading? (get-option gnc:pagename-display + optname-label-trading)) + (total-trading? (get-option gnc:pagename-display + optname-total-trading)) (label-expense? (get-option gnc:pagename-display optname-label-expense)) (total-expense? (get-option gnc:pagename-display @@ -355,10 +374,8 @@ ;; decompose the account list (split-up-accounts (gnc:decompose-accountlist accounts)) (revenue-accounts (assoc-ref split-up-accounts ACCT-TYPE-INCOME)) + (trading-accounts (assoc-ref split-up-accounts ACCT-TYPE-TRADING)) (expense-accounts (assoc-ref split-up-accounts ACCT-TYPE-EXPENSE)) - (income-expense-accounts - (append (assoc-ref split-up-accounts ACCT-TYPE-INCOME) - (assoc-ref split-up-accounts ACCT-TYPE-EXPENSE))) (doc (gnc:make-html-document)) ;; this can occasionally put extra (blank) columns in our @@ -437,17 +454,20 @@ (neg-revenue-total #f) (revenue-total #f) (expense-total #f) + (trading-total #f) (net-income #f) ;; Create the account tables below where their ;; percentage time can be tracked. (inc-table (gnc:make-html-table)) ;; gnc:html-table (exp-table (gnc:make-html-table)) + (tra-table (gnc:make-html-table)) (table-env #f) ;; parameters for :make- (params #f) ;; and -add-account- (revenue-table #f) ;; gnc:html-acct-table (expense-table #f) ;; gnc:html-acct-table + (trading-table #f) (terse-period? #t) (period-for (if terse-period? @@ -517,9 +537,14 @@ (neg-revenue-total 'minusmerge revenue-closing #f) (set! revenue-total (gnc:make-commodity-collector)) (revenue-total 'minusmerge neg-revenue-total #f) + (set! trading-total + (gnc:accountlist-get-comm-balance-interval + trading-accounts + start-date-tp end-date-tp)) ;; calculate net income (set! net-income (gnc:make-commodity-collector)) (net-income 'merge revenue-total #f) + (net-income 'merge trading-total #f) (net-income 'minusmerge expense-total #f) (set! table-env @@ -564,7 +589,8 @@      ") )) (gnc:html-table-append-row! inc-table space) - (gnc:html-table-append-row! exp-table space)) + (gnc:html-table-append-row! exp-table space) + (gnc:html-table-append-row! tra-table space)) (gnc:report-percent-done 80) @@ -591,6 +617,17 @@ (if total-expense? (add-subtotal-line exp-table (_ "Total Expenses") #f expense-total)) + + (if label-trading? + (add-subtotal-line tra-table (_ "Trading") #f #f)) + (set! trading-table + (gnc:make-html-acct-table/env/accts + table-env trading-accounts)) + (gnc:html-table-add-account-balances + tra-table trading-table params) + (if total-trading? + (add-subtotal-line + tra-table (_ "Total Trading") #f trading-total)) (report-line (if standard-order? @@ -611,11 +648,15 @@ (if standard-order? (list (gnc:make-html-table-cell inc-table) + (if (not (null? trading-accounts)) + (gnc:make-html-table-cell tra-table)) (gnc:make-html-table-cell exp-table) ) (list (gnc:make-html-table-cell exp-table) (gnc:make-html-table-cell inc-table) + (if (not (null? trading-accounts)) + (gnc:make-html-table-cell tra-table)) ) ) ) @@ -624,6 +665,10 @@ (gnc:html-table-append-row! build-table (list (gnc:make-html-table-cell inc-table))) + (if (not (null? trading-accounts)) + (gnc:html-table-append-row! + build-table + (list (gnc:make-html-table-cell tra-table)))) (gnc:html-table-append-row! build-table (list (gnc:make-html-table-cell exp-table))) @@ -635,6 +680,10 @@ (gnc:html-table-append-row! build-table (list (gnc:make-html-table-cell inc-table))) + (if (not (null? trading-accounts)) + (gnc:html-table-append-row! + build-table + (list (gnc:make-html-table-cell tra-table)))) ) ) )