Archive for November, 2008

Coping with the VAT Change

Tuesday, November 25th, 2008

There seems to be a lot of wailing and gnashing of teeth about the upcoming VAT change. Especially as it is only a 13 month change and the rate will revert to 17.5% in 2010.

However, it ought to be really simple (although I realise that this may be a bit late for some computer systems).

Never hard-code the VAT rate

Have a Tax class that the rest of the system can ask when it needs the tax rate. That way, you’ve only got one place to make the change.

Store the rate against your invoice lines

Add a field to your invoice lines that stores the rate applicable for that line. Populate this when the line is created. That way, an invoice at tax point 30th November 2008 will have lines with a 17.5% stored against them, those created on the 1st December 2008 will have a 15% stored against them. This keeps your most vital financial documents accurate over time.

Calculate the VAT as late as possible

When calculating the VAT on an invoice do not do this:



value_excluding_vat = 0

vat = 0

value_including_vat = 0

for each line in my invoice

  value_excluding_vat += line.value

  vat += line.value * line.tax_rate

  value_including_vat += line.value + (line.value * line.tax_rate)

The problem here is that you are calculating the VAT on a per line basis and then summing the values. This will lead to rounding errors – where your line values are a penny out from your totals.

Instead you need to place each line into a “bucket” for its tax rate, sum all values for a given rate and then calculate the tax on that. That way you are working on the largest numbers possible, reducing the risk of small decimal place discrepancies throwing your totals out.



value_excluding_vat = 0

for each line in my invoice

  bucket = the_bucket_for line.vat

  bucket.value += line.value

  value_excluding_vat += line.value

vat = 0

for each bucket in my collection of buckets

  vat += bucket.value * bucket.rate

value_including_vat = value_excluding_vat + vat

Have a Tax Band and Tax Rate model that deals with changes over time

If you really want to have a “minimal administration” system for dealing with tax rate changes then you should switch your data model to have multiple Tax Band objects (as remember, there are multiple VAT bands – “standard” is 17.5/15%, “low” is 5%, “zero-rated” is 0% and “exempt” is also 0% but needs to be accounted for separately to “zero-rated”).

A Data Model for dealing with variable tax bands and variable tax ratesEach Tax Band object should have a set of Tax Rate objects hanging off it – where each Tax Rate has a percentage rate and a start and end date. That way you can ask your “Standard Rate” tax object “what is the percentage on the 30th November 2008?” and it can give you the correct answer.

That makes dealing with a change like this simple – you simply go to the “Standard Rate” object, find it’s current rate object and set its end date to 30th November 2008. Then you add a new rate object to the “standard rate” of 15%, setting its start date to 1st December 2008, with an end date of 31st December 2009. Lastly, add another 17.5% rate object, with a start date of 1st January 2010 and no end date.

Update the rest of your systems to always ask the relevant tax object for the correct rate and tax rate changes will never be a headache again.

Acceptance Testing in Ruby, Rails, RSpec and Cucumber

Friday, November 21st, 2008

I’ve written up a new post at the Brightbox blog detailing how we are using RSpec and Cucumber to build acceptance tests for the next generation Brightbox systems.

Rails 2.1 and 2.2: CSRF vulnerability and work-around

Wednesday, November 19th, 2008

I’ve done a quick write-up on the recent CSRF vulnerability on the Brightbox blog.

Rails vs Merb (updated)

Tuesday, November 18th, 2008
Ruby Programmers having a fight

Ruby Programmers having a fight

What the fuck is this?

Merb is launched and DHH suddenly has a load of “Rails Myths” posts up on his blog. Like this sly little dig:

it shows the great power of being an full-stack framework

Wycats responds with a slightly less sly dig:

For the moment, these differences are the reason that Rails will continue to dominate amongst developers seeking to build apps similar in scope to apps built by 37Signals. I suspect that Merb will pick up steam amongst developers looking to build innovative apps leveraging the latest and greatest Ruby techniques and libraries.

Zed responds angrily to a mistake by DHH (which DHH subsequently corrects).

I admit I’ve not had much time to look at Merb in detail; the times when I have played with it my impression has been “it’s much the same as Rails but done in a different (probably cleaner) way”. I love the fact in Rails that everything comes in one bundle (apart from RSpec :-), I love the fact that Merb gives you choices (even though I don’t have the time to research those choices), I like the fact that the two frameworks are now feeding off each other.

But the thing that impressed me most when I came to Rails was how nice and friendly the Ruby community was. But, it would appear that that was an illusion and massive egos are in charge. Discussion is good. Adapting your ideas in the face of competition and change is good. Having a massive pissing match because my framework is better than your framework is stupid. I wish you would all just shut the fuck up.

UPDATE:

And the fighting continues – this time it’s _why versus Zed.

Loading the MySQL drivers into GNU Smalltalk

Friday, November 14th, 2008

It’s an unfortunate fact that many Open Source projects have documentation that is sadly lacking. A case in point is GNU Smalltalk.

Smalltalk is one of my favourite languages but a decent Smalltalk implementation that fits with your native window manager is hard to find. The point of GNU Smalltalk is that it works “headlessly” (Smalltalk invented the graphical user-interface and the integrated development environment so this is quite a departure), so I can still use my favourite text editor and run stuff from the command line. Just like Ruby!

However, it’s taken me a couple of hours to figure out how to simply connect to a database. But now I have, here it is:

  • Install GNU Smalltalk (in my case using MacPorts):
    sudo port install gst
  • Start GNU Smalltalk and create a working image:
    cd /Users/rahoulb/source/st
    gst
    st> ObjectMemory snapshot: 'work.im'.
  • Ctrl-D to exit Smalltalk and then restart using your new image:
    gst -I work.im
  • Load the DBI database driver:
    st> PackageLoader fileInPackage: 'DBI'.
    Load the MySQL driver:
    st> PackageLoader fileInPackage: 'DBD-MySQL'.
    Save your image so you don’t need to reload these packages again:
    st> ObjectMemory snapshot.
  • Open a connection to your database:
    st>con:= DBI.Connection connect: 'dbi:MySQL:dbname=mydatabase' user: 'myuser' password: 'mypassword'.
    Grab some data:
    st>results:= con select: 'select name from customers limit 10;'
  • Bask in the glory of your data

TechieTubbies: podcasting about startups and techie stuff in Britain and around the world

Monday, November 10th, 2008

The second episode of my new joint-venture, Techietubbies, performed with the irrepressible Dominic Hodgson, is now available. It’s semi-regular half hour podcast where we discuss startups and technology news whilst giggling like children – probably not very professional but that’s the way we like it!

iPhone prevents irate customer

Monday, November 3rd, 2008

I spent this weekend in the Lake District in the wet north-west of England. A beautiful part of the world, but one lacking in 3G connectivity. Not great for browsing (although Mobile Twitter and email were fine) but fantastic for battery life.

On Sunday morning, I awoke to find an email from a web-site monitoring service that I use, stating that a client site was down. The email was sent at 5am. It was now 10am and I had no computer, a mere GPRS connection and a hangover. Not good.

However, I fired up TouchTerm (an SSH client) on my iPhone and connected to the server in question. Connect OK. Good. Then I type sudo monit status to find out what state the server is in. All services running OK. Then cat /etc/apache2/sites-enabled/rails-mysite. This lets me examine the web-server configuration file; and I can prove to myself that I had set up aliases for the site (so that the same site is also available on an alternative web address). I then used Mobile Safari to connect on the alternative addresses and everything works fine. Lastly, I write an email to the client stating that the site is down but nothing at my end is wrong – could it be a DNS problem?

iPhone with TouchTerm

iPhone with TouchTerm

Of course, there are many phones that can do this. In fact I have had so-called “smartphones” for years – all of which are capable of connecting over SSH, over the web and over email. But the iPhone is the first where I have actually used that capability, where it’s not so painful to use that I want to try it out.

Later that day I got an email from the monitoring service stating that the site had returned. And on Monday, the client tells me that their registrar had had a failure and all of their domain names had gone down for the day.

Still, I think that’s pretty good; Sunday, with a hangover, pro-actively investigating a fault on a customer’s server, on a telephone and an antique net connection.