[Please CC any replies, as I'm not subscribed]

Hi guys,

I switched my business accouting from a clunky home-made script+database
to Gnucash several months ago -- kudos for all your work!  Having now
finished my first tax report based on Gnucash's reports, here are two
things I found lacking in those reports:

* In addition to revenues and expenses, I also needed to know how much
  was spent on assets, for depreciation purposes.  Unfortunately, even
  though I can select asset accounts for an Income Statement report,
  only income and expenses accounts are displayed in the end result.
  Substracting last year's balance sheet from this year's kinda sucks
  (especially when coupled with the second point).

* Being a Canadian citizen, most of my accounting is done is CAD, but I
  do have some expenses (hosting, domain names, etc.) in USD, charged on
  my credit card.  Gnucash will add them all as USD, and try to convert
  the total figure using some average exchange rate; this obviously
  won't match my own records, where I've added up each CAD amount
  charged to my card.


I'm attaching two patches that fixed (at least for me) those issues.
The first one displays selected asset accounts, if any, in an Income
Statement report.  The second one allows for an Income Statement report
to be based on value instead of amount.  Using both, I now have
everything I need for tax purposes.

(These were based on 2.2.6, but seem to apply cleanly to trunk.)

Please note that I'm not much familiar with either Scheme or the Gnucash
codebase, so these patches will probably be a bit ugly.  Sorry 'bout
that.  Do let me know if you disapprove of them, or want them redone in
a different style.


-- 
<SomeLamer> what's the difference between chattr and chmod?
<SomeGuru> SomeLamer: man chattr > 1; man chmod > 2; diff -u 1 2 | less
                -- Seen on #linux on irc
commit defa0143efcf634ef88f2607f27501c8de5ee3ea
Author: Frédéric Brière <fbri...@fbriere.net>
Date:   Wed Jan 21 12:06:17 2009 -0500

    Display asset accounts, if any, in Income Statement report
    
    This displays any selected asset accounts in an Income Statement report,
    below revenues and expenses (unless the two-column option is used).

diff --git a/src/report/standard-reports/income-statement.scm b/src/report/standard-reports/income-statement.scm
index c7ecce6..65d4eab 100644
--- a/src/report/standard-reports/income-statement.scm
+++ b/src/report/standard-reports/income-statement.scm
@@ -101,6 +101,9 @@
 (define optname-total-expense (N_ "Include expense total"))
 (define opthelp-total-expense
   (N_ "Whether or not to include a line indicating total expense"))
+(define optname-label-assets (N_ "Label the assets section"))
+(define opthelp-label-assets
+  (N_ "Whether or not to include a label for the assets section"))
 
 (define pagename-commodities (N_ "Commodities"))
 (define optname-report-commodity (N_ "Report's currency"))
@@ -238,6 +241,11 @@
       gnc:pagename-display optname-total-expense
       "j" opthelp-total-expense #t))
 
+    (add-option 
+     (gnc:make-simple-boolean-option
+      gnc:pagename-display optname-label-assets
+      "jj" opthelp-label-assets #t))
+
     (add-option
      (gnc:make-simple-boolean-option
       gnc:pagename-display optname-two-column
@@ -331,6 +339,8 @@
 				    optname-label-expense))
          (total-expense? (get-option gnc:pagename-display
 				    optname-total-expense))
+         (label-assets? (get-option gnc:pagename-display
+				    optname-label-assets))
          (use-links? (get-option gnc:pagename-display
 				     optname-account-links))
          (use-rules? (get-option gnc:pagename-display
@@ -361,6 +371,7 @@
          (income-expense-accounts
           (append (assoc-ref split-up-accounts ACCT-TYPE-INCOME)
                   (assoc-ref split-up-accounts ACCT-TYPE-EXPENSE)))
+	 (asset-accounts (assoc-ref split-up-accounts ACCT-TYPE-ASSET))
 	 
          (doc (gnc:make-html-document))
 	 ;; this can occasionally put extra (blank) columns in our
@@ -445,11 +456,13 @@
                ;; percentage time can be tracked.
 	       (inc-table (gnc:make-html-table)) ;; gnc:html-table
 	       (exp-table (gnc:make-html-table))
+	       (ass-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
+               (asset-table #f)                    ;; gnc:html-acct-table
 	       
 	       (terse-period? #t)
 	       (period-for (if terse-period?
@@ -566,10 +579,11 @@
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
 		 ))
 	    (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! ass-table space))
 
 	       
-	  (gnc:report-percent-done 80)
+	  (gnc:report-percent-done 75)
 	  (if label-revenue?
 	      (add-subtotal-line inc-table (_ "Revenues") #f #f))
 	  (set! revenue-table
@@ -581,7 +595,7 @@
 	      (add-subtotal-line 
 	       inc-table (_ "Total Revenue") #f revenue-total))
 	  
-	  (gnc:report-percent-done 85)
+	  (gnc:report-percent-done 80)
 	  (if label-expense?
 	      (add-subtotal-line 
 	       exp-table (_ "Expenses") #f #f))
@@ -604,6 +618,15 @@
 	   (* 2 (- tree-depth 1)) exchange-fn #f #f
 	   )
 	  
+	  (gnc:report-percent-done 85)
+	  (if label-assets?
+	      (add-subtotal-line ass-table (_ "Assets") #f #f))
+	  (set! asset-table
+		(gnc:make-html-acct-table/env/accts
+		 table-env asset-accounts))
+	  (gnc:html-table-add-account-balances
+	   ass-table asset-table params)
+
 	  (gnc:html-document-add-object! 
 	   doc 
 	   (let* ((build-table (gnc:make-html-table)))
@@ -621,24 +644,30 @@
 		       )
 		      )
 		  )
-		 (if standard-order?
-		     (begin
-		       (gnc:html-table-append-row!
-			build-table
-			(list (gnc:make-html-table-cell inc-table)))
-		       (gnc:html-table-append-row!
-			build-table
-			(list (gnc:make-html-table-cell exp-table)))
+		 (begin
+		   (if standard-order?
+		       (begin
+		         (gnc:html-table-append-row!
+			  build-table
+			  (list (gnc:make-html-table-cell inc-table)))
+		         (gnc:html-table-append-row!
+			  build-table
+			  (list (gnc:make-html-table-cell exp-table)))
+		         )
+		       (begin
+		         (gnc:html-table-append-row!
+			  build-table
+			  (list (gnc:make-html-table-cell exp-table)))
+		         (gnc:html-table-append-row!
+			  build-table
+			  (list (gnc:make-html-table-cell inc-table)))
+		         )
 		       )
-		     (begin
+		   (if (not (null? asset-accounts))
 		       (gnc:html-table-append-row!
-			build-table
-			(list (gnc:make-html-table-cell exp-table)))
-		       (gnc:html-table-append-row!
-			build-table
-			(list (gnc:make-html-table-cell inc-table)))
-		       )
-		     )
+		        build-table
+		        (list (gnc:make-html-table-cell ass-table))))
+		   )
 		 )
 	     
 	     (gnc:html-table-set-style!
commit e9eb48412f065deb17240eaf918835b282d7caa2
Author: Frédéric Brière <fbri...@fbriere.net>
Date:   Wed Jan 21 12:38:57 2009 -0500

    Allow for Income Statement report based on value instead of amount
    
    This adds the option of generating an Income Statement report based on
    the value (transaction currency) of each transaction, instead of the
    amount (account currency).
    
    Note: This patch does not take care of the "Total" and "Net" lines

diff --git a/src/report/report-system/html-acct-table.scm b/src/report/report-system/html-acct-table.scm
index b1dfa8e..d208963 100644
--- a/src/report/report-system/html-acct-table.scm
+++ b/src/report/report-system/html-acct-table.scm
@@ -172,6 +172,12 @@
 ;; a report-commodity specified), we can use *that* commodity for each
 ;; account's exchange-fn.
 ;;
+;;     which-figure: 'amount 'value
+;; 
+;;         which figure to add up for each transaction.  'amount (the
+;;         default) is the amount of the account's commodity; 'value
+;;         is the amount of the transaction's commodity.
+;;
 ;;     exchange-fn: commodity_exchange_function
 ;; 
 ;;         the commodity exchange function (you know, that weighted
@@ -597,6 +603,7 @@
 		       (cons 'absolute (cons (current-time) 0))))
 	 (report-commodity (or (get-val env 'report-commodity)
 			       (gnc-default-report-currency)))
+	 (which-figure (or (get-val env 'which-figure) 'amount))
          ;; BUG: other code expects a real function here, maybe
          ;; someone was thinking price-source?
 	 (exchange-fn (or (get-val env 'exchange-fn)
@@ -646,9 +653,13 @@
     (define (get-balance-nosub-mode account start-date end-date)
       (let* ((post-closing-bal
 	      (if start-date
-		  (gnc:account-get-comm-balance-interval
+		  ((if (equal? which-figure 'value)
+		       gnc:account-get-comm-value-interval
+		       gnc:account-get-comm-balance-interval)
 		   account start-date end-date #f)
-		  (gnc:account-get-comm-balance-at-date
+		  ((if (equal? which-figure 'value)
+		       gnc:account-get-comm-value-at-date
+		       gnc:account-get-comm-balance-at-date)
 		   account end-date #f)))
 	     (closing (lambda(a)
 			(gnc:account-get-trans-type-balance-interval
diff --git a/src/report/standard-reports/income-statement.scm b/src/report/standard-reports/income-statement.scm
index c7ecce6..af6e02c 100644
--- a/src/report/standard-reports/income-statement.scm
+++ b/src/report/standard-reports/income-statement.scm
@@ -110,6 +110,8 @@
   (N_ "Display any foreign currency amount in an account"))
 (define optname-show-rates (N_ "Show Exchange Rates"))
 (define opthelp-show-rates (N_ "Show the exchange rates used"))
+(define optname-which-figure (N_ "Which figure"))
+(define opthelp-which-figure (N_ "Which figure to use for each transaction"))
 
 (define pagename-entries (N_ "Entries"))
 (define optname-closing-pattern (N_ "Closing Entries pattern"))
@@ -195,6 +197,18 @@
       pagename-commodities optname-show-rates
       "d" opthelp-show-rates #f))
     
+    (add-option 
+     (gnc:make-multichoice-option
+      pagename-commodities optname-which-figure
+      "e" opthelp-which-figure 'amount
+      (list (vector 'amount
+		    (N_ "Amount")
+		    (N_ "Amount expressed in the account's currency"))
+	    (vector 'value
+		    (N_ "Value")
+		    (N_ "Value expressed in the transaction's currency"))
+	    )))
+    
     ;; what to show for zero-balance accounts
     (add-option 
      (gnc:make-simple-boolean-option
@@ -312,6 +326,8 @@
                                  optname-show-foreign))
          (show-rates? (get-option pagename-commodities
                                   optname-show-rates))
+         (which-figure (get-option pagename-commodities
+                                   optname-which-figure))
          (parent-balance-mode (get-option gnc:pagename-display
                                            optname-parent-balance-mode))
          (parent-total-mode
@@ -534,6 +550,7 @@
 						 'summarize))
 		 (list 'report-commodity report-commodity)
 		 (list 'exchange-fn exchange-fn)
+		 (list 'which-figure which-figure)
 		 (list 'parent-account-subtotal-mode parent-total-mode)
 		 (list 'zero-balance-mode (if show-zb-accts?
 					      'show-leaf-acct
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to