Skip to main content

How to Create a Basic Invoicing System

Submitted by jessica on Mon, 03/05/2018 - 17:57

Let's dive in and create a simple invoicing system, because hey, why not. It's useful if you're a freelancer, or work for one. It's also a good way to familiarize yourself with drupal concepts, such as content types and entities.

Here's a link to a super basic invoice database. You can make any of the columns sortable. In this case, all of the columns can be sorted by clicking on their headers. Here is that same database, sorted by payment status. When you click on a client, in any of these views, or from this rolodex, you can see their description, web site, contact email(s) and invoices. You can add new clients, and those clients will automatically appear in a drop-down menu as a client option when creating a new invoice. Pretty neat, right?

Here are the steps I followed. The type of the field chosen is in parenthesis.

  1. Create a content type for clients. Give it these fields: name (by changing the title label to name), website (link), email (email), and description (long text and format). 
  2. Create a content type for invoices. Give it these fields: title, client (entity reference), invoice number (integer), description (long text and format), amount (decimal), and status (select list with only 1 value allowed). The client field, references the client content type, because every time the user adds a client, we want that client to be a new option when creating an invoice. 
    When adding a field, make it an entity reference by choosing Reference > Content
    When adding a field, make it an entity reference by choosing Reference > Content
    Once you add the field, make sure you select which content type you want it to reference.
    Once you add the field, make sure you select which content type you want it to reference.
  3. Check to see the entity reference is working by creating a few clients, and making sure they show up as options when creating invoices. 
    The clients you add as content types show up as options when you create invoices, thanks to Entity Reference!
    The clients you add as content types show up as options when you create invoices,
    thanks to Entity Reference!

     

  4. Create a few invoices; at least one for each client.
  5. Create a view by going to Structure > View > + Add view. 
    I added all of the fields for invoices, and used a table format with sortable headers.
    Add the fields for invoices you would like displayed. I used a table format with sortable headers, but you can format it however you like. Then, filter for the invoice content type.
    If you want to create a summary view, try contextual filters.
    If you want to create a summary view, try contextual filters.
    This created a summary view that sorted by payment status.
    This created a summary view that sorted by payment status.
  6. Take a look at your page view. Mine is here. By appending /all to the URL of your view, you will be able to see all of the results, unsummarized. Here is my view, with all of the results.
  7. In this case, I wanted to make the invoices for each client appear on their own content type pages. If you want to do this also, create another view, this time, filtering for invoices, adding a contextual filter that draws from URL values, and placing it in a block. Then, place the block on the client content types only.

    Contextual filter that only shows invoices for this particular client.
    Contextual filter that only shows invoices for a particular client,
    when on its content type page.
  8. View a client content type to see that it is working. An example is here.
  9. Lastly, to create a rolodex of clients, create a page view and filter for the content type of client. Here's a simple example.

So, that's one way to create a basic invoicing system using drupal. It requires some configuration and a basic understanding of drupal, but no coding wizardry.