Creating Your Own Invoice Templates

Version 4 (Jeremy Bush, 12/14/2009 09:38 pm)

1 1
h1. Creating Your Own Invoice Templates
2 1
3 1
Custom invoice templates live in application/views/invoice/templates. You need the following files:
4 1
5 4 Jeremy Bush
* views/invoice/templates/*your_template_name*
6 4 Jeremy Bush
* views/invoice/templates/*your_template_name*/view.php
7 4 Jeremy Bush
* views/invoice/templates/*your_template_name*/pdf.php
8 4 Jeremy Bush
9 4 Jeremy Bush
It is recommended that you create your own [[Module Development|Argentum Module]] for your invoice templates.
10 1
11 1
view.php is the main invoice template. It is a basic Kohana view file. You should put any custom styles inside a <style> block at the top of the file. This is required for the DomPDF PDF generator to work properly. This file just needs to be the main body HTML, not with the entire HTML headers.
12 1
13 1
pdf.php is the PDF version of the invoice file. This should be a complete HTML file. It is recommended to include your view.php file for consistency. You can do this by running the following line in your pdf.php file:
14 1
15 1
<?php include Kohana::find_file('views', 'invoice/templates/*your_template_name*/view')?>
16 1
17 3 Jeremy Bush
Please note that if you include your own images in the invoice file, DomPDF does not support PNG24 with an alpha channel.
18 3 Jeremy Bush
19 1
h2. View Variables
20 1
21 1
There is only one main view variable in the invoice template: $invoice. However, this object has many properties you can access to display your information. They are:
22 1
23 1
  * $invoice->id - The invoice number
24 1
  * $invoice->title - The invoice title
25 1
  * $invoice->comments - The comments on the invoice, if any
26 2 Jeremy Bush
  * $invoice->client - The "client object model":http://trac.argentuminvoice.com/browser/trunk/application/models/client.php that the invoice is assigned to.
27 1
  * $invoice->find_operation_types - Returns an array of all operation types assigned to this invoice. Each array member is also an array with the following key/value pairs: name, rate, time.
28 1
  * $invoice->find_related('tickets') - Returns a database result object of all tickets assigned to this invoice.
29 1
  * $invoice->find_related('non_hourly') - Returns a database result object of all non-hourly items assigned to this invoice.
30 1
  * $invoice->find_sales_tax() - Returns the sales tax for this invoice.