Instead of writing your own invoice system, check out Cashboard
http://www.getcashboard.com
</shameless plug>