Invoicr – Open Source PHP Invoice Generator (HTML, PDF, DOCX)

 

 

 

SECTION A

INTRODUCTION

WHAT IS INVOICR?

Invoicr is a free and open-source PHP invoice generator that is capable of churning out HTML, PDF, and DOCX invoices. It may not be the best in the world, but it is simple, fuss-free, and should give the developers a quick boost with all the essentials already built-in.

 

THE TEMPLATES

Invoicr currently comes with 5 free themes available for DOCX, HTML and PDF output:

  • Simple
  • Strawberry
  • Apple
  • Lime
  • Blueberry

 

LICENSE

Invoicr is released under the MIT License – You are free to use it for your own personal and commercial projects, modify it as you see fit. On the condition that there the software is provided “as-is”. There are no warranties provided and “no strings attached” – Code Boxx and the authors are not liable for any claims, damages, or any liabilities.

 

CREDITS

Invoicr is made possible with the following open source projects:

  • MPDF for adding the PDF capabilities.
  • PHPWord for the DOCX capability.

 

 

SECTION B

DOWNLOAD & INSTALLATION

DOWNLOAD & REQUIREMENTS

You can download Invoicr from Sourceforge, Github or Bitbucket. Invoicr has not been extensively tested, but it should work well with most modern XAMPP installations –

  • PHP 5.6 and above.
  • Apache web server.
  • Should work on IIS as well.

 

HOW TO INSTALL

Invoicr does not require a database or anything “special”. Just download the file, unzip it into your project folder, and it is pretty much ready for action.

 

 

SECTION C

HOW TO USE – IN 3 STEPS

STEP 1) CREATE INVOICR OBJECT

/* [STEP 1 - CREATE NEW INVOICR OBJECT] */
require dirname(__DIR__) . DIRECTORY_SEPARATOR . "invoicr.php";
$invoice = new Invoicr();

Start by including the Invoicr library and creating a new Invoicr object.

 

STEP 2) FEED THE INFORMATION

/* [STEP 2 - FEED ALL THE INFORMATION] */
// 2A - COMPANY INFORMATION
// OR YOU CAN PERMANENTLY CODE THIS INTO THE LIBRARY ITSELF
$invoice->set("company", [
  (isset($_SERVER['HTTPS']) ? "https://" : "http://") . 
  $_SERVER['HTTP_HOST'] . 
  parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . 
  "cb-logo.png",
  __DIR__ . DIRECTORY_SEPARATOR . "cb-logo.png", 
  "Code Boxx", 
  "Street Address, City, State, Zip",
  "Phone: xxx-xxx-xxx | Fax: xxx-xxx-xxx",
  "https://code-boxx.com",
  "doge@code-boxx.com"
]);

// 2B - INVOICE INFO
$invoice->set("invoice", [
  ["Invoice #", "CB-123-456"],
  ["DOP", "2011-11-11"],
  ["P.O. #", "CB-789-123"],
  ["Due Date", "2011-12-12"]
]);

// 2C - BILL TO
$invoice->set("billto", [
  "Customer Name",
  "Street Address", 
  "City, State, Zip"
]);

// 2D - SHIP TO
$invoice->set("shipto", [
  "Customer Name",
  "Street Address", 
  "City, State, Zip"
]);

// 2E - ITEMS
// YOU CAN JUST DUMP THE ENTIRE ARRAY IN USING SET, BUT HERE IS HOW TO ADD ONE AT A TIME... 
$items = [
  ["Rubber Hose", "5m long rubber hose", 3, "$5.50", "$16.50"],
  ["Rubber Duck", "Good bathtub companion", 8, "$4.20", "$33.60"],
  ["Rubber Band", "", 10, "$0.10", "$1.00"],
  ["Rubber Stamp", "", 3, "$12.30", "$36.90"],
  ["Rubber Shoe", "For slipping, not for running", 1, "$20.00", "$20.00"]
];
foreach ($items as $i) { $invoice->add("items", $i); }

// 2F - TOTALS
$invoice->set("totals", [
  ["SUB-TOTAL", "$108.00"],
  ["DISCOUNT 10%", "-$10.80"],
  ["GRAND TOTAL", "$97.20"]
]);

// 2G - NOTES, IF ANY
$invoice->set("notes", [
  "Cheques should be made payable to Code Boxx",
  "Get a 10% off with the next purchase with discount code DOGE1234!"
]);

This is probably the most “complicated” step, you need to feed Invoicr with information:

  • Company logo, name, address, contact.
  • Invoice information.
  • Bill to.
  • Ship to.
  • The items.
  • Totals.
  • Notes, if any.

 

STEP 3) CHOOSE TEMPLATE & OUTPUT THE INVOICE

/* [STEP 3 - OUTPUT] */
// 3A - CHOOSE TEMPLATE, DEFAULTS TO SIMPLE IF NOT SPECIFIED
$invoice->template("apple");

// 3B - OUTPUT IN HTML
// DEFAULT DISPLAY IN BROWSER | 1 DISPLAY IN BROWSER | 2 FORCE DOWNLOAD | 3 SAVE ON SERVER
$invoice->outputHTML();
$invoice->outputHTML(1);
$invoice->outputHTML(2, "invoice.html");
$invoice->outputHTML(3, __DIR__ . DIRECTORY_SEPARATOR . "invoice.html");

// 3C - PDF OUTPUT
// DEFAULT DISPLAY IN BROWSER | 1 DISPLAY IN BROWSER | 2 FORCE DOWNLOAD | 3 SAVE ON SERVER
$invoice->outputPDF();
$invoice->outputPDF(1);
$invoice->outputPDF(2, "invoice.pdf");
$invoice->outputPDF(3, __DIR__ . DIRECTORY_SEPARATOR . "invoice.pdf");

// 3D - DOCX OUTPUT
// DEFAULT FORCE DOWNLOAD| 1 FORCE DOWNLOAD | 2 SAVE ON SERVER
$invoice->outputDOCX();
$invoice->outputDOCX(1, "invoice.docx");
$invoice->outputDOCX(2, __DIR__ . DIRECTORY_SEPARATOR . "invoice.docx");

Finally, choose a template to use and output the invoice.

 

 

SECTION D

FOR THE DEVELOPERS

BUILDING YOUR OWN TEMPLATE

Want to build your own customized theme? It is very easy to do so… If you are unsure at any point, feel free to use the “default” simple.php template file as a reference.

 

STEP 1) CREATE EMPTY PHP FILE

  • Create a new PHP file in the respective templates folder – DOCX, HTML, or PDF.
  • You can now use your template by calling $invoice->template().
  • For example, if you have created a durian.php in the HTML template folder, you can now use it –
$invoice->template("durian");
$invoice->outputHTML();

 

STEP 2) ACCESSING INVOICE INFORMATION

In your template file, you can get the various invoice information by accessing the respective $this-> variable. If you are not sure, check back with the above “how to use” example:

  • company – Company logo, name, address, contact.
  • invoice – Invoice information.
  • billto – Bill to.
  • shipto – Ship to.
  • items – The items.
  • totals – Totals.
  • notes – Notes, if any.

 

STEP 3A) HTML TEMPLATES

Simply put all your HTML code into the $this->data variable.

 

STEP 3B) PDF TEMPLATES

The PDF generation is handled by MPDF, and there is already a $mpdf object initiated. You can check out the official MPDF documentation on how to use it.

 

STEP 3C) DOCX TEMPLATES

PHPWord handles the DOCX generation, and a $pw object is initiated. Check out the official PHPWord documentation on how to use it.

 

Leave a Comment

Your email address will not be published. Required fields are marked *