Reports - getting numeric value from commodity collector

Darryl Cousins darryl at darrylcousins.net.nz
Fri Nov 25 06:17:49 EST 2005


Hi Everyone,

I appear to have made some progress with my problem, I have been able to
extract the number from the profit total (returned as a
commodity-collector). Now I want to reconstruct that number for printing
in the report as follows. Any suggestions? I'll back to it tomorrow. 

    (if show-taxes?
        (begin

     ;; collect total profit - procedure taken from html-utilities.scm
     (set! myprofit (gnc:accounts-get-comm-total-profit (filter use-acct? accounts) my-get-balance))
     (set! myprofit (gnc:sum-collector-commodity myprofit report-currency exchange-fn))

     ;; collect the bits
     (set! num (gnc:gnc-monetary-amount myprofit))
     (set! denom (gnc:gnc-numeric-denom num))

     ;; make a number I can compute with
     (set! myprofit (gnc:gnc-numeric-num num))

     ;; calculate taxes - TODO check for zero or negative profit
     ;; TODO add tax percentage to options
     ;; this will print no problem but lacks the currency prefix
     ;; and hasn't been reconfigured with numeric-denom
     (set! mytaxes (* myprofit 33 0.01))

     ;; now try to reconstruct with denominator and currency

     ;; reconstruct numeric
     ;; this won't print (error #1 below)
     ;(set! mytaxes (gnc:make-gnc-numeric mytaxes denom))

     ;; reconstruct monetary for printing
     ;; this won't print (error #2 below)
     ;(set! mytaxes (gnc:make-gnc-monetary report-currency mytaxes))


     (gnc:html-acct-table-row-helper!
       table tree-depth
       1 (_ "Taxes Payable")
       mytaxes
       #f "primary-subheading" #t #f)
      ))

          ;; add the table
          (gnc:html-document-add-object! doc table)


Error #1 tail

In /usr/share/gnucash/scm/html-style-info.scm:
      ...
 284: 97    [gnc:amount->string # #]
/usr/share/gnucash/scm/html-style-info.scm:284:3: In procedure gnc_scm_to_gint64 in expression (gnc:amount->string datum (gnc:default-print-info #f)):
/usr/share/gnucash/scm/html-style-info.scm:284:3: Wrong type (inexact) argument in position 1: 107.72

Error #2 tail

In unknown file:
      ...
   ?: 97    [gnc:default-html-gnc-monetary-renderer # #f]
In /usr/share/gnucash/scm/html-style-info.scm:
 287: 98    (let* ((result #) (ind #)) (if ind (string-append # "€" #) result))
 287: 99*   [gnc:amount->string # #]
/usr/share/gnucash/scm/html-style-info.scm:287:18: In procedure gnc_scm_to_gint64 in expression (gnc:amount->string (gnc:gnc-monetary-amount datum) (gnc:commodity-print-info # #t)):
/usr/share/gnucash/scm/html-style-info.scm:287:18: Wrong type (inexact) argument in position 1: 107.72

On Fri, 2005-11-25 at 15:53 +1300, Darryl Cousins wrote:
> Hi Everyone,
> 
> I'm rather new to GnuCash and guile/schema however I've made some
> progress in creating my own 'Statement of Financial Performance using
> reports/pnl.scm as a starting point. All well and good.
> 
> My problem is in adding a final row to the report after Profit which
> calculates the income tax owing on the profit (company tax at 33% here
> in NZ).
> 
> I've managed thus:
> 
>     (if show-taxes?
>         (begin
>      (set! myprofit (gnc:accounts-get-comm-total-profit (filter use-acct? accounts) my-get-balance))
>      (set! myprofit (gnc:sum-collector-commodity myprofit report-currency exchange-fn))
>      (set! myprofit (gnc:gnc-monetary-amount myprofit))
>      (gnc:html-acct-table-row-helper!
>        table tree-depth
>        1 (_ "Taxes Payable")
>        myprofit
>        #f "primary-subheading" #t #f)
>       ))
> 
> Which so far just gives the total profit figure. My dilemma is to
> extract the number alone from the commodity collector (as returned from
> gncsum-collector-commodity OR extract the number from the gnc-numeric
> construct. Once I have the number itself then I can (* myprofit 0.33).
> Probably then I'll be in trouble turning that back into a commodity
> object.
> 
> Any help would be appreciated.
> 
> Best regards,
> Darryl Cousins
> 
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
-- 
Darryl Cousins
Tree Fern Web Services (NZ) Ltd
106 Sandes St
Thames 2801
New Zealand
+64 7 868 3139
darryl.cousins at treefernwebservices.co.nz
http://www.treefernwebservices.co.nz/



More information about the gnucash-user mailing list