How to retrieve the account balance in scm?

casi casi at maanreri.de
Mon Dec 26 11:16:07 EST 2011


Hi Derek,

thanks for the quick reply. That helped!

What I learn from this
1. that gnc-numeric is not a trace info but a type info 
2. that "engine" also is a relevant directory in this matter (not only
"report")

My little test routine looks now like this

(gnc:debug 
  (let ((num (gnc:gnc-numeric-num (gnc:account-get-balance-at-date acct
date-val #f)))
        (denom (gnc:gnc-numeric-denom (gnc:account-get-balance-at-date
acct date-val #f))))
       (/ num denom 1.0)))

and returns exactly what I want, for now.

Primarily, I try to get something like a "personal cashflow report",
which can use 1:1 for my tax declaration.
Specifically, the current cashflow report shows all accounts that
contribute to the cashflow in one selected account, but I would like to
be able to "hide" some of these.

Secondarily, I just want to know how it works to be able to build some
"only useful for me reports".

Merry Christmas,
Carsten



On Mon, 2011-12-26 at 09:04 -0500, Derek Atkins wrote:
> Hi,
> 
> On Mon, December 26, 2011 8:02 am, casi wrote:
> > Hi,
> >
> > GnuCash 2.4.7, on Ubuntu 11.10
> >
> > trying to get familiar with customizing reports directly in Scheme, I
> > managed to get into the language deep enough to get the clou out of
> > hello-world.scm (working and playing around with my private copy).
> >
> > hello-world.scm tells you a lot about how to set and retreive options
> > and values for a report, but it does not tell you much about how to make
> > use of them.
> >
> > Starting with the very basic (as I thought) I tried to read from the
> > standard reports how to do this - but this is not really obvious to me
> > (I am looking at account-summary.scm and cash-flow.scm, maybe not
> > clever?).
> >
> > Finally, I got down to calling
> > "(gnc:account-get-balance-at-date acct date-val #f)"
> > and the debug print out shows the return value as
> > "#<<gnc-numeric> num: -53065 denom: 100>"
> > and here I get stuck as I don't find any syntax explanation for
> > "#<...>".
> >
> > (Well, I do understand that the account balance is -53065/100 ->
> > -530.65, which is correct.)
> >
> > I tried to interpret "#<<gnc-numeric> num: -53065 denom: 100>" as
> > - string
> > - list
> > - vector
> > (- even tried "numerator ...")
> > neither of which seems to work (and unfortunately gnucash.trace only
> > shows what input type is expected, but not what it actually got).
> 
> You should interpret it as a gnc-numeric (which is exactly what it's
> telling you it is).  You can use the gnc-numeric operations or, as shown
> in other reports, a commodity-collector, to sum up your values.  Then you
> can put them into number-column tables to output them.
> 
> > So here comes my question:
> > How can I get the numerical account balance value from "#<<gnc-numeric>
> > num: -53065 denom: 100>" ?
> 
> You HAVE the account balance, in the form of a gnc-numeric.
> 
> > If there is even a smarter way to get to the same result, feel welcome
> > to give me that hint :-)
> 
> You don't say what you are trying to do with the balance, so I don't know
> if there is a "smarter way to get the same result".  The function you
> called is generally the correct one to get the balance-as-of-date.
> 
> > Thx and advance,
> > Carsten
> 
> > Please remember to CC this list on all your replies.
> > You can do this by using Reply-To-List or Reply-All.
> 
> -derek
> 




More information about the gnucash-user mailing list