Home
30 May 2020

Pretty invoices with GnuCash, LaTeX and gcinvoice using Linux

[ #technology  #bookkeeping  #latex  #gnucash  #invoice  #opensource  #linux  ]

Perhaps not the first subject you’d expect on the blog of a classical singer, but we all have our quirks.

If you want to do your own bookkeeping for your company, GnuCash is an excellent piece of free open source software to do it with.

The invoices GnuCash produces work fine, but leave something to be desired in terms of customization. Using the typesetting software LaTeX and the script gcinvoice you can make a LaTeX template, into which you pour the information from your GnuCash database to make a professional-looking invoice.

Installation

What software you need:

  1. GnuCash
  2. LaTeX
  3. LaTeX-extra
  4. gcinvoice
  5. (The Roboto font if you want to use it in your invoice, like I do)

I use Arch Linux, where you install the first three with the following command:

# pacman -S gnucash texlive-core texlive-latexextra

Gcinvoice is a Python script and easiest to download using Pip, a package manager specifically for Python. On Arch Linux:

# pacman -S python-pip
$ pip install gcinvoice

Roboto is also easy to install, if desired:

# pacman -S ttf-roboto

You’ll need to find out what these packages are called on Ubuntu or other distributions. They are pretty standard, though, so they’re likely to be present in your distribution’s repository.

A program to help with manipulating LaTeX files can also come in handy. I use texstudio for that.

Usage

The working order is like this:

  1. Make an invoice in GnuCash
  2. Save your database(!)
  3. Point gcinvoice to your database, enter the invoice number and point it to your LaTeX template
  4. Compile the resulting LaTeX file to get a pretty pdf file

You need to place pieces of Python code in the invoice template, which get replaced by the corresponding numbers or text from your GnuCash database when you run gcinvoice. If, for example, you write @{owner['full_name']} in your template, gcinvoice will replace this with the name of the customer you addressed your invoice to. A list of the possible pieces of Python code can be found on the web page of gcinvoice under the header “Templates”.

Template

My template can be downloaded from my Github repository. Also included is a bash script you can use to automate running gcinvoice. In both the bash script and the template you will need to edit some global variables to your situation. These are indicated with comments.

My template uses my self-made background image and logo. Feel free to use these, though you’ll probably want to change the logo, considering. For the prettiest results I recommend using vector images for these. If you already have svg files of your images, you can easily export them to pdf using Inkscape.

The background image was made with Scribus. The Scribus file can also be found on my Github repository.

Using GnuCash for the body text

By using billing terms to your invoice, you can automatically change the body text of your letter for different situations. In GnuCash, go to Business → Billing Terms Editor in the menu. You can add different options here. I myself use three different ones:

  • Payment within thirty days
  • Payment before the first lesson
  • Payment already received

By using LaTeX markup in these billing terms, you can make text bold or underlined or similar. By referencing to the variables used in the LaTeX document, you only need to make changes there when something changes.

Payment within thirty days:

For my services I kindly request the following payment,
to be transferred within 30 days to \usekomavar{frombank}
under the name of \textbf{\usekomavar{fromname}}.
Please mention your \underline{name} and the
\underline{invoice number}.

Payment before the first lesson:

For my services I kindly request the following payment,
to be transferred before the first lesson to
\usekomavar{frombank} under the name of
\textbf{\usekomavar{fromname}}. Please mention your
\underline{name} and the \underline{invoice number}.

Payment already received:

This invoice has already been paid and is merely for
your own administration.

In the future, I hope to expand on this with a script to add a SEPA Credit Transfer QR code to the invoice, to make payment easier for customers, using the API from the Online SEPA Credit Transfer QR-code generator. UPDATE: I have done this, see my next blog post.

Did this blog post help you or do you still have questions or tips? Let me know in the comments!

Until next time,
Sebastiaan Ammerlaan

Comments