Still missing: the invoice number, that requires more tables and possibly a PL/pgSQL function to do it properly.