Reports - getting numeric value from commodity collector
Derek Atkins
warlord at MIT.EDU
Sat Nov 26 00:24:45 EST 2005
Hi,
Again, you probably want more than '100' in the denominator of the
taxrate.
-derek
PS: It's "scheme", not "schema". ;)
PPS: Glad I could help.
Quoting Darryl Cousins <darryl at darrylcousins.net.nz>:
> Hi,
>
> Aah! This works for me:
>
> ;; calculate taxes
> (set! mytaxes (gnc:numeric-mul num
> (gnc:double-to-gnc-numeric (* tax-rate 0.01) 100
> GNC-RND-NEVER)
> 100 GNC-DENOM-REDUCE))
> ))
>
> Full code below.
>
> Thanks Derek for your help. Another schema-newbie makes his first steps.
>
> Best regards,
> Darryl Cousins
>
> (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 numeric bit
> (set! num (gnc:gnc-monetary-amount myprofit))
>
> ;; check for zero or negative profit
> (cond ((gnc:numeric-zero-p num)
> (set! mytaxes (gnc:numeric-create 0 100)))
> ((gnc:numeric-negative-p num)
> (set! mytaxes (gnc:numeric-create 0 100)))
> (else
> ;; calculate taxes
> (set! mytaxes (gnc:numeric-mul num
> (gnc:double-to-gnc-numeric (* tax-rate
> 0.01) 100 GNC-RND-NEVER)
> 100 GNC-DENOM-REDUCE))
> ))
>
> ;; reconstruct monetary for printing
> (set! mytaxes (gnc:make-gnc-monetary report-currency mytaxes))
>
> ;; tab it to the table
> (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)
>
>
>
>
>
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-user
mailing list