Reports - getting numeric value from commodity collector

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Reports - getting numeric value from commodity collector

Darryl Cousins
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
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Darryl Cousins
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
> [hidden email]
> 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
[hidden email]
http://www.treefernwebservices.co.nz/

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Derek Atkins
Try using gnc-numeric math functions:

(set! mytaxes (gnc:gnc-numeric-mul myprofit (gnc:gnc-numeric-create 33 100)))

You need to use gnc-numeric mathematics -- you cannot convert from
a gnc-numeric to a scheme number and then back again like you're trying.

-derek

Quoting Darryl Cousins <[hidden email]>:

> 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 #
> "&euro;" #) 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
>> [hidden email]
>> 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
> [hidden email]
> http://www.treefernwebservices.co.nz/
>
> _______________________________________________
> gnucash-user mailing list
> [hidden email]
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>



--
       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
       [hidden email]                        PGP key available

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Darryl Cousins
Hi Derek,

That's very nice. Thank you for the advice. Now it works as I'd like:

Problem though that I used options make-number-range which returns a
figure like 33.0 which gnc:numeric-create doesn't like. After some
struggle I gave up.

<error>
 306: 27*  [gnc:numeric-create 32.0 100]
/usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: In procedure gnc:numeric-create in expression (gnc:numeric-create tax-rate 100):
/usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: Wrong type argument in position 1: 32.0
</error>

    (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 100 GNC-DENOM-REDUCE)
                              ;; always getting a figure 100 times the actual. Tried different denom but to no avail
                              (gnc:numeric-create 33 100)
                              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)


On Fri, 2005-11-25 at 09:24 -0500, Derek Atkins wrote:

> Try using gnc-numeric math functions:
>
> (set! mytaxes (gnc:gnc-numeric-mul myprofit (gnc:gnc-numeric-create 33 100)))
>
> You need to use gnc-numeric mathematics -- you cannot convert from
> a gnc-numeric to a scheme number and then back again like you're trying.
>
> -derek
>
> Quoting Darryl Cousins <[hidden email]>:
>
> > 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 #
> > "&euro;" #) 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
> >> [hidden email]
> >> 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
> > [hidden email]
> > http://www.treefernwebservices.co.nz/
> >
> > _______________________________________________
> > gnucash-user mailing list
> > [hidden email]
> > 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
[hidden email]
http://www.treefernwebservices.co.nz/

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Derek Atkins
Try:

(gnc:double-to-gnc-numeric tax-rate)

-derek

Quoting Darryl Cousins <[hidden email]>:

> Hi Derek,
>
> That's very nice. Thank you for the advice. Now it works as I'd like:
>
> Problem though that I used options make-number-range which returns a
> figure like 33.0 which gnc:numeric-create doesn't like. After some
> struggle I gave up.
>
> <error>
> 306: 27*  [gnc:numeric-create 32.0 100]
> /usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: In procedure gnc:numeric-create in expression (gnc:numeric-create tax-rate
> 100):
> /usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: Wrong type argument in position 1:
> 32.0
> </error>
>
>    (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 100
> GNC-DENOM-REDUCE)
>                              ;; always getting a figure 100 times the
> actual. Tried different denom but to no avail
>                              (gnc:numeric-create 33 100)
>                              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)
>
>
> On Fri, 2005-11-25 at 09:24 -0500, Derek Atkins wrote:
>> Try using gnc-numeric math functions:
>>
>> (set! mytaxes (gnc:gnc-numeric-mul myprofit (gnc:gnc-numeric-create
>> 33 100)))
>>
>> You need to use gnc-numeric mathematics -- you cannot convert from
>> a gnc-numeric to a scheme number and then back again like you're trying.
>>
>> -derek
>>
>> Quoting Darryl Cousins <[hidden email]>:
>>
>> > 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 #
>> > "&euro;" #) 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
>> >> [hidden email]
>> >> 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
>> > [hidden email]
>> > http://www.treefernwebservices.co.nz/
>> >
>> > _______________________________________________
>> > gnucash-user mailing list
>> > [hidden email]
>> > 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
> [hidden email]
> http://www.treefernwebservices.co.nz/
>
>



--
       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
       [hidden email]                        PGP key available

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Darryl Cousins
Hi Derek,

Thanks. Yes I was trying that but am having problems with using denom

Using this:

 (set! mytaxes (gnc:numeric-mul num
                   (gnc:double-to-gnc-numeric tax-rate 100 GNC-DENOM-REDUCE)
                   ;(gnc:numeric-create 33 100)
                   100 GNC-DENOM-REDUCE))

Gave me a figure 100 times to large. I tried different figures for
'denom' argument but to no avail.

Best regards.
Darryl

On Fri, 2005-11-25 at 23:20 -0500, Derek Atkins wrote:

> Try:
>
> (gnc:double-to-gnc-numeric tax-rate)
>
> -derek
>
> Quoting Darryl Cousins <[hidden email]>:
>
> > Hi Derek,
> >
> > That's very nice. Thank you for the advice. Now it works as I'd like:
> >
> > Problem though that I used options make-number-range which returns a
> > figure like 33.0 which gnc:numeric-create doesn't like. After some
> > struggle I gave up.
> >
> > <error>
> > 306: 27*  [gnc:numeric-create 32.0 100]
> > /usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: In procedure gnc:numeric-create in expression (gnc:numeric-create tax-rate
> > 100):
> > /usr/share/gnucash/guile-modules/gnucash/report/statement-performance.scm:306:31: Wrong type argument in position 1:
> > 32.0
> > </error>
> >
> >    (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 100
> > GNC-DENOM-REDUCE)
> >                              ;; always getting a figure 100 times the
> > actual. Tried different denom but to no avail
> >                              (gnc:numeric-create 33 100)
> >                              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)
> >
> >
> > On Fri, 2005-11-25 at 09:24 -0500, Derek Atkins wrote:
> >> Try using gnc-numeric math functions:
> >>
> >> (set! mytaxes (gnc:gnc-numeric-mul myprofit (gnc:gnc-numeric-create
> >> 33 100)))
> >>
> >> You need to use gnc-numeric mathematics -- you cannot convert from
> >> a gnc-numeric to a scheme number and then back again like you're trying.
> >>
> >> -derek
> >>
> >> Quoting Darryl Cousins <[hidden email]>:
> >>
> >> > 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 #
> >> > "&euro;" #) 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
> >> >> [hidden email]
> >> >> 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
> >> > [hidden email]
> >> > http://www.treefernwebservices.co.nz/
> >> >
> >> > _______________________________________________
> >> > gnucash-user mailing list
> >> > [hidden email]
> >> > 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
> > [hidden email]
> > http://www.treefernwebservices.co.nz/
> >
> >
>
>
>
--
Darryl Cousins
Tree Fern Web Services (NZ) Ltd
106 Sandes St
Thames 2801
New Zealand
+64 7 868 3139
[hidden email]
http://www.treefernwebservices.co.nz/

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Darryl Cousins
In reply to this post by Derek Atkins
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)




_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user
Reply | Threaded
Open this post in threaded view
|

Re: Reports - getting numeric value from commodity collector

Derek Atkins
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 <[hidden email]>:

> 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
       [hidden email]                        PGP key available

_______________________________________________
gnucash-user mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-user