Developer Guide

For Version 5.x documentation, please go to invoiceninja.github.io

This guide will provide an overview of Invoice Ninja. If anything’s unclear please send us an email, we’re always working to improve it.

The application is written in PHP using the Laravel framework, the full list of libraries can be found on our GitHub page.

If you’re running the app for your own use you can white label the client portal and emails by purchasing an annual white label license from within the application. If you’d like to white label the admin pages to re-sell the application please send us an email to learn about our affiliate program.

We try to follow the PSR-2 style guidelines and are using the Git-Flow model of branching and releasing, please create pull requests against the develop branch.

Code

When setting up the app you can choose to either use the self hosted zip or checkout the code from GitHub. The zip includes all third party libraries, whereas checking out the code from GitHub requires using Composer.

We use Gulp to concatenate the JavasScript and CSS files. You can download the source files with Bower. After making any changes you need to run gulp to re-generate the built files.

Most of the system tables are cached (ie, currencies, languages, etc). If you make any changes you need to run php artisan db:seed --class=UpdateSeeder and then load any page with ?clear_cache=true added at the end of the URL.

Database

The following are the main entities, you can browse the app/Models folder for the complete list.

  • Accounts +users
  • Clients +contacts
  • Invoices +invoice_items
  • Payments
  • Credits

The best places to start when reviewing the code are app/Http/routes.php and app/Providers/EventServiceProvider.php.

To enable each account to have it’s own incrementing Ids (ie, /clients/1) all account entity classes extend the custom EntityModel.php class. This gives each entity a public_id field. You can read more about it in this post.

All actions are tracked in the activities table. Example of actions are creating a client, viewing an invoice or entering a payment. This is implemented using Laravel model events. An example can be seen at the bottom of app/Models/Invoice.php.

Laravel supplies soft delete functionality, however in order to ensure referential integrity records are only deleted when a user cancels their account. To support this we’ve added an is_deleted field. When the deleted_at field is set the entity has been archived, when is_deleted is true the entity has been deleted.

Automated Tests

To run the Codeception tests you’ll need to install PhantomJS.

  • Create config file: cp tests/_bootstrap.php.default tests/_bootstrap.php
  • Create test user: php artisan db:seed --class=UserTableSeeder
  • edit the following files, replacing www.ninja.test:8000 with your local test domain: - /.travis.ylm - /app/Libraries/Utils.php - /tests/acceptance.suite.yml - /tests/functional.suite.yml
  • Start the PhantomJS web server: phantomjs --webdriver=4444
  • Run the tests: sudo ./vendor/codeception/codeception/codecept run --debug