colinramsay.co.uk

Freshbooks Invoice Widget

27 Nov 2008

At Plastiscenic, I organise all the boring stuff using Freshbooks. In fact, Freshbooks make sorting invoices, estimates and time tracking a bit of a breeze. I was mulling over the past month of work when it struck me that I was thinking about things in completely the wrong way: I was trying to ensure that I was busy all the time, when in fact all that matters - from a business perspective - was that I was earning enough.

Freshbooks has a record of all of the Plastiscenic invoices, and therefore the amount we've brought in during a given month. It also has an API. I decided to quickly flex my PHP muscles and come up with a cash-orientated way of viewing my performance via my invoice data.

I created a web invoice widget for Freshbooks which uses the Sparkline PHP Graphing Library to generate a graph of the past 12 months. Ones in which invoice totals exceed the specified upper threshold are marked in green, and ones which are lower than the lower threshold are red. Everything else is black. To the side of the graph, there's a numerical readout of the invoice totals from this month and the previous month, again coloured accordingly.

In terms of the actual scripts involved, you need to edit FbInvoicePerformance.php and enter your Freshbooks API token and API URL which can be obtained in your Freshbooks account. Then just tweak index.php from the archive according to your needs. The good and bad variables are the high and low thresholds for colouration, and the HTML in that file it just boilerplate for demonstration purposes and can be hacked as you like. Notice the readout function for displaying the numerical invoice totals. The FbInvoicePerformance class powers the whole thing but it's pretty small and usage should be clear from the index.php file.

This Freshbooks invoice widget is completely unsupported by me. Sparkline requires PHP 4.0.6 or newer (including PHP 5) and GD 2.0 built as a PHP module, so bear that in mind if you try and use the widget. There's no demo, but you can download the widget here.

Feedback or questions on this post? Create an issue on GitHub.