API questions

John Ralls jralls at ceridwen.us
Fri Jun 10 12:24:58 EDT 2016


> On Jun 10, 2016, at 8:43 AM, David Goodenough <david.goodenough at linkchoose.co.uk> wrote:
> 
> On Friday 10 June 2016 08:29:01 John Ralls wrote:
>>> On Jun 10, 2016, at 7:06 AM, David Goodenough
>>> <david.goodenough at linkchoose.co.uk> wrote:> 
>>> On Friday 10 June 2016 06:59:38 John Ralls wrote:
>>>>> On Jun 10, 2016, at 2:05 AM, David Goodenough
>>>>> <david.goodenough at linkchoose.co.uk> wrote:
>>>>> 
>>>>> I notice when looking at the API pages that a method is defined as
>>>>> starting
>>>>> at a given line, and then the code below always starts on the next line,
>>>>> i.e. missing out the prototype.  For example:-
>>>>> 
>>>>> Definition at line 116 of file print-session.c.
>>>>> 
>>>>> 117 {
>>>>> 118     return print_settings;
>>>>> 119 }
>>>>> 
>>>>> Would it not be possible to show line 116 as well?  This seems to be a
>>>>> consistent problem throughout the docs.
>>>> 
>>>> The prototype is in very large print above the description. Repeating it
>>>> in
>>>> the listing would be redundant.
>>> 
>>> OK, missed that.  It just looked odd at first glance that the line number
>>> immedately before the code was not in the code that was shown.
>>> 
>>>>> The reason I was looking was to generate customer reports via the API.
>>>>> I would like to be able to generate a report for each customer who
>>>>> either
>>>>> has a non-zero balance or where some transaction (invoice or receipt of
>>>>> payment) happened last month (or since rather since I last ran the
>>>>> program). I then want to export the report as a PDF.  I have looked my
>>>>> way through the API docs but could not see how to generate reports, or
>>>>> to
>>>>> check for the balance or the presence of transactions since a date.
>>>>> 
>>>>> I found docs on how to create invoices, but also need to be able to
>>>>> export them as PDFs and could not locate the API for that either.  I
>>>>> notice
>>>>> in the gnucash XML files that the last direcorty to which invoices ( and
>>>>> I
>>>>> guess customer reports ) were exported is stored, is this available from
>>>>> the API.
>>> 
>>> I think having read a bit further that this is in the customer dictionary?
>>> 
>>>>> What I want to be able to write is a program that will generate reports
>>>>> for all relevant customers, and then send an email to each customer who
>>>>> has either an invoice and/or a report containing both.
>>>>> 
>>>>> Any pointers gratefully received.
>>>> 
>>>> PDF generation is provided by (IIRC) libgtk as part of printing support.
>>>> You won't find the code for that in GnuCash itself.
>>> 
>>> OK, but I still need to tell it to generate the customer report, and to
>>> check whether I need to do so?
>> 
>> Sorry, neither of those questions make sense.
> I will try to restate them:-
> 
> 1) From the UI I can request a customer report and tell the UI to export it as
> a PDF.  How do I achieve the same from the API?

The reports module is written in Scheme, so anything having to do with reports must use Scheme. That API isn't documented via Doxygen (Doxygen doesn't know how to parse Scheme), so you'll have to study the code in src/reports. You may find http://wiki.gnucash.org/wiki/Custom_Reports helpful.

I already told you that GnuCash's API doesn't know how to export PDFs. It knows how to write HTML. You'll have to find an external library or utility to convert the HTML to PDF.

>  
> 
> 2) Looking at the customer report I can see if the report shows a non-zero
> balance or has transactions in the last month.  How can I check the balance
> and see if there are invoices or receipts for a given customer in the last 
> month though the API?

You will have to extract the logic of the report to replicate its query and calculations and test the results.

> 
> Obviously I would like to have dataset format independance rather than going 
> direct to the data, so I want to do as much as possible through the API.
> 
> David
>> 
>> Regards,
>> John Ralls




More information about the gnucash-user mailing list