home

Browse documentation

ezyVet Knowledge Center

Get access to documentation, training, and other high-quality resources.

Primary invoice template

The primary invoice template is a document template that new ezyVet sites automatically use for printed invoices and PDF invoices.

Examples of information shown in invoices that use the primary invoice template include:
  • Invoice number
  • Invoice date
  • Your organization logo at the upper-right
  • Client and patient information
  • Account reference number for online payments
  • Composite tax and VAT as necessary
Figure 1. Primary invoice template: Example PDF output

Primary invoice template: Example PDF output
Note: The name of the primary invoice template as shown in the ezyVet user interface is Invoice 2026 ^% or Invoice 2026 ^%(Document).

Primary invoice template: Make changes to invoice information

The primary invoice template makes it easy for you to make changes to the information shown in printed and PDF invoices. The tables that follow give:
  • An example of what you want invoices to show
  • The related change to make in the template source code to get the result
Note: Usually the only change to make in the template source code is to change True to False or change False to True. IDEXX customer support recommends that you do not make other changes to the template source code.

This table gives the changes that you can make for invoice line items:

For each line item, I want to:Template change to make
Show line item dates.Change {% set showLineDate = 'False' %} to {% set showLineDate = 'True' %}
Show product codes.Change {% set showProductCode = 'False' %} to {% set showProductCode = 'True' %}
Show product names.Change {% set showProductName = 'False' %} to {% set showProductName = 'True' %}
Show batch expiration dates.Change {% set showBatchAndExpiry = 'False' %} to {% set showBatchAndExpiry = 'True' %}
Show staff members.Change {% set showStaffMember = 'False' %} to {% set showStaffMember = 'True' %}
Show the unit price with tax.Change {% set showUnitPriceExcludingTax = 'False' %} to {% set showUnitPriceExcludingTax = 'True' %}
Show the unit price without tax.Change {% set showUnitPriceIncludingTax = 'False' %} to {% set showUnitPriceIncludingTax = 'True' %}
Show the quantity value.Change {% set showQuantity = 'False' %} to {% set showQuantity = 'True' %}
Show the total value without tax and before discounts.Change {% set showTotalBeforeDiscountExcludingTax = 'False' %} to {% set showTotalBeforeDiscountExcludingTax = 'True' %}
Show the total value with tax and before discounts.Change {% set showTotalBeforeDiscountIncludingTax = 'False' %} to {% set showTotalBeforeDiscountIncludingTax = 'True' %}
Show the discount without tax.Change {% set showDiscountExcludingTax = 'False' %} to {% set showDiscountExcludingTax = 'True' %}
Show the discount with tax.Change {% set showDiscountIncludingTax = 'False' %} to {% set showDiscountIncludingTax = 'True' %}
Show the discount without tax.Change {% set showDiscountPercentage = 'False' %} to {% set showDiscountPercentage = 'True' %}
Show tax.Change {% set showTax = 'False' %} to {% set showTax = 'True' %}
Show tax as a percentage.Change {% set showTaxPercentage = 'False' %} to {% set showTaxPercentage = 'True' %}
Show the total value without tax.Change {% set showTotalExcludingTax = 'False' %} to {% set showTotalExcludingTax = 'True' %}
Show the total value with tax.Change {% set showTotalIncludingTax = 'False' %} to {% set showTotalIncludingTax = 'True' %}
Show a batch number.Change {% set showBatchBelowInvoiceLine = 'False' %} to {% set showBatchBelowInvoiceLine = 'True' %}
Show comments.Change {% set showCommentBelowInvoiceLine = 'False' %} to {% set showCommentBelowInvoiceLine = 'True' %}

The table that follows gives the changes that you can make for the summary area of the invoice.

Figure 2. Invoice summary area

Invoice summary area
For the summary area, I want to:Template change to make
Show the total to pay without discount.Change {% set showSummaryTotalBeforeDiscount = 'False' %} to {% set showSummaryTotalBeforeDiscount = 'True' %}
Show the total discount.Change {% set showSummaryTotalDiscount = 'False' %} to {% set showSummaryTotalDiscount = 'True' %}
Show the total discount with tax.Change {% set showSummaryTotalDiscountWithTax = 'False' %} to {% set showSummaryTotalDiscountWithTax = 'True' %}
Show the total to pay with discount.Change {% set showSummaryTotalAfterDiscount = 'False' %} to {% set showSummaryTotalAfterDiscount = 'True' %}
Show the total to pay with discount and tax.Change {% set showSummaryTotalAfterDiscountWithTax = 'False' %} to {% set showSummaryTotalAfterDiscountWithTax = 'True' %}
Show the total quantity of tax.Change {% set showSummaryTaxTotal = 'False' %} to {% set showSummaryTaxTotal = 'True' %}
Show the total quantity of composite tax.Change {% set showSummaryCompositeTaxTotal = 'False' %} to {% set showSummaryCompositeTaxTotal = 'True' %}
Show the full total to pay.Change {% set showSummaryFinalTotal = 'False' %} to {% set showSummaryFinalTotal = 'True' %}
Show the quantity paid.Change {% set showSummaryPaidAmount = 'False' %} to {% set showSummaryPaidAmount = 'True' %}
Show the remaining quantity to pay.Change {% set showSummaryInvoiceBalance = 'False' %} to {% set showSummaryInvoiceBalance = 'True' %}
Show the client account balance.Change {% set showSummaryClientBalance = 'False' %} to {% set showSummaryClientBalance = 'True' %}

This table gives other changes that you can make to the information shown in invoices:

I want invoices to:Template change to make
Show the case owner.Change {% set showCaseOwner = 'False' %} to {% set showCaseOwner = 'True' %}
Show invoice comments.Change {% set showInvoiceComment = 'False' %} to {% set showInvoiceComment = 'True' %}
Show payment methods.Change {% set showPaymentMethods = 'False' %} to {% set showPaymentMethods = 'True' %}
Show the next scheduled appointment.Change {% set showNextAppointment = 'False' %} to {% set showNextAppointment = 'True' %}
Show VAT.Change {% set showVATRateTotalTable = 'False' %} to {% set showVATRateTotalTable = 'True' %}
Show due care services.Change {% set showSOCTable = 'False' %} to {% set showSOCTable = 'True' %}
Figure 3. Care services example


Note: Care services show in a dedicated page in printed and PDF output.

Primary invoice template: Source code

The source code of the primary invoice template and its related header template and footer template is available as follows.
If your ezyVet site does not have the primary invoice template or you want a new copy of it:
  1. Make a copy of the source code for the primary content of the template
  2. Make a document template for the primary content and put the source code (1) in it
  3. Make one document template for the header template and one for the footer template, then enter the applicable source code in them
  4. Configure the document template (2) to use the header template and footer template (3)

  5. Use the procedure given in Set the document templates that ezyVet automatically uses for new invoices and select the document template (2) in the Invoice and Invoice Summarized boxes
Figure 4. The Invoice and Invoice Summarized boxes


This is the source for for the primary content of the primary invoice template:

{# --- START OF TEMPLATE SETTINGS --- #}
<div class="settings"><br />
{# --- LINE TABLE COLUMN CONFIGURATION (set to 'True' to show) --- #}<br />
{% set showLineDate = 'True' %}<br />
{##}<br />
{% set showProductCode = 'False' %}<br />
{##}<br />
{% set showProductName = 'True' %}<br />
{##}<br />
{% set showBatchAndExpiry = 'False' %}<br />
{##}<br />
{% set showStaffMember = 'False' %}<br />
{##}<br />
{% set showUnitPriceExcludingTax = 'True' %}<br />
{##}<br />
{% set showUnitPriceIncludingTax = 'False' %}<br />
{##}<br />
{% set showQuantity = 'True' %}<br />
{##}<br />
{% set showTotalBeforeDiscountExcludingTax = 'False' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showTotalBeforeDiscountIncludingTax = 'False' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showDiscountExcludingTax = 'True' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showDiscountIncludingTax = 'False' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showDiscountPercentage = 'False' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showTax = 'False' %}<br />
{##}<br />
{% set showTaxPercentage = 'True' %}<br />
{##}<br />
{% set showTotalExcludingTax = 'True' %}<br />
{##}<br />
{% set showTotalIncludingTax = 'False' %}<br />
{##}<br />
{# --- LINE TABLE HEADER NAME CONFIGURATION (Set what will print on invoice table headers) --- #}<br />
{% set LineDateHeader = 'Date' %}<br />
{##}<br />
{% set ProductCodeHeader = 'Code' %}<br />
{##}<br />
{% set ProductNameHeader = 'Description' %}<br />
{##}<br />
{% set BatchAndExpiryHeader = 'Batch Expiry' %}<br />
{##}<br />
{% set StaffMemberHeader = 'Staff Member' %}<br />
{##}<br />
{% set UnitPriceExcludingTaxHeader = 'Unit Price' %}<br />
{##}<br />
{% set UnitPriceIncludingTaxHeader = 'Unit Price' %}<br />
{##}<br />
{% set QuantityHeader = 'Qty' %}<br />
{##}<br />
{% set TotalBeforeDiscountExcludingTaxHeader = 'Gross' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set TotalBeforeDiscountIncludingTaxHeader = 'Gross' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set DiscountExcludingTaxHeader = 'Discount' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set DiscountIncludingTaxHeader = 'Discount' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set DiscountPercentageHeader = 'Disc. %' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set TaxHeader = 'TAX' %}<br />
{##}<br />
{% set TaxPercentageHeader = 'TAX %' %}<br />
{##}<br />
{% set TotalExcludingTaxHeader = 'Net Total' %}<br />
{##}<br />
{% set TotalIncludingTaxHeader = 'Net Total' %}<br />
{##}<br />
{# --- SUMMARY TABLE ROWS (set to 'True' to show) --- #}<br />
<br />
{% set showSummaryTotalBeforeDiscount = 'False' %}{# NB: If discounts are present and PRE-TAX #}<br />
{##}<br />
{% set showSummaryTotalDiscount = 'True' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showSummaryTotalDiscountWithTax = 'False' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set showSummaryTotalAfterDiscount = 'True' %}{# NB: PRE-TAX #}<br />
{##}<br />
{% set showSummaryTotalAfterDiscountWithTax = 'False' %}<br />
{##}<br />
{% set showSummaryTaxTotal = 'True' %}<br />
{##}<br />
{% set showSummaryCompositeTaxTotal = 'False' %}<br />
{##}<br />
{% set showSummaryFinalTotal = 'True' %}<br />
{##}<br />
{% set showSummaryPaidAmount = 'True' %}<br />
{##}<br />
{% set showSummaryInvoiceBalance = 'True' %}<br />
{##}<br />
{% set showSummaryClientBalance = 'True' %}<br />
{##}<br />
{# --- SUMMARY TABLE LABELS (Set what will print on the invoice summary table) --- #}<br />
<br />
{% set SummaryTotalBeforeDiscountLabel = 'Gross Total' %}{# NB: If discounts are present and PRE-TAX #}<br />
{##}<br />
{% set SummaryTotalDiscountLabel = 'Discount Total' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set SummaryTotalDiscountWithTaxLabel = 'Discount Total' %}{# NB: If discounts are present #}<br />
{##}<br />
{% set SummaryTotalAfterDiscountLabel = 'Net Total' %}{# NB: PRE-TAX #}<br />
{##}<br />
{% set SummaryTotalAfterDiscountWithTaxLabel = 'Subtotal' %}<br />
{##}<br />
{% set SummaryTaxTotalLabel = 'TAX' %}<br />
{##}<br />
{% set SummaryFinalTotalLabel = 'Final Total' %}<br />
{##}<br />
{% set SummaryPaidAmountLabel = 'Amount Paid' %}<br />
{##}<br />
{% set SummaryInvoiceBalanceLabel = 'Outstanding Amount' %}<br />
{##}<br />
{% set SummaryClientBalanceLabel = 'Account Balance' %}<br />
{##}<br />
{# --- ADDITIONAL CONFIGURATION --- #}<br />
{##}<br />
{% set showCaseOwner = 'True' %}<br />
{##}<br />
{% set showTreatmentDateRange = 'True' %}<br />
{##}<br />
{% set showInvoiceComment = 'True' %}<br />
{##}<br />
{% set showPaymentMethods = 'True' %}<br />
{##}<br />
{% set showNextAppointment = 'True' %}<br />
{##}<br />
{% set showVATRateTotalTable = 'False' %}<br />
{##}<br />
{% set showBatchBelowInvoiceLine = 'True' %}<br />
{##}<br />
{% set showCommentBelowInvoiceLine = 'False' %}<br />
{##}<br />
{% set showSOCTable = 'True' %}<br />
{##}<br />
{% set hiddenProductGroup = 'Does Not Print - Internal Use Only' %}<br />
{##}<br />
{% set printInvoiceNoteProductGroup  = 'Invoice Notes' %}<br />
{##}</div>
{# --- END OF TEMPLATE SETTINGS --- #}{# --- START OF CASCADING STYLE SHEETS (CCS) --- #}
<style type="text/css">th,
td {
	text-align: left;
	padding: 6px;
	font-size: 12px
}
td.fitwidth {
    width: 1px;
    white-space: nowrap;
    color:#000000;
    float:left;
    font-size:12px;
    height:30px;
    text-align:left;
    border-bottom: 2px solid #ccc;
}
td.line {
	font-size:12px;
    height:30px;
    float:left;
    text-align:left;
} 
td.subline {
	color:#555555;
    float:left;
    font-style: italic;
    font-size: 12px;
    height:30px;
    text-align:left;
}
.summary tr:nth-child(1) td {
	padding-top: 20px;
}
.summary tr:last-child td {
	padding-bottom: 20px;
}
.settings {
	display: none;
}
</style>
{# --- END OF CASCADING STYLE SHEETS (CCS) --- #}{# --- START OF INVOICE LINE ARRAY CLUSTER --- #}{# This grouping creates an invoice line array so that they can be ordered by date in the invoice table: 
    
            0. Creates an unordered array to store lines initially for ordering
            1. Adds invoice lines to the empty array.
            2. Merges the unordered array and adjusts the variable to reflect ordering
            3. Sets the starting date and end date for the treatments   

#}{# 0 #}{% set unarrangedinvoicelines = [] %}{# 1 #}{% for invoiceline in invoice.lineItems %}{% set unarrangedinvoicelines = unarrangedinvoicelines|merge([{
                        'rawDate': invoiceline.date,
                        'formattedDate': invoiceline.date|dateformat,
                        'id': invoiceline.id
                    }]) %}{% endfor %}{# 2 - sort by raw date #}{% set arrangedinvoicelines = unarrangedinvoicelines|sort((a, b) => a.rawDate <=> b.rawDate) %}{# 3 #}{% set lowestValue = arrangedinvoicelines|first.formattedDate %}{% set highestValue = arrangedinvoicelines|last.formattedDate %}{# --- END OF INVOICE LINE ARRAY CLUSTER --- #}{# --- START OF NON BUNDLE DISCOUNT TOTAL EXCLUDING TAX CLUSTER --- #}{# This grouping calculates nonBundle discount total so that can be referenced in an if condition for discount column of invoice table:
    
            0. Sets totalDiscount to 0 as an initial starting point.
            1. Checks if the line is a header line.
            2. Sets the discount to be equal to the invoiceline nonbundleTotalDiscount value if not the 'reverse balance charge' item .
            3. Overrides totalDiscount's value, then adds to it. So, totalDiscount = totalDiscount + discount.
            4. Checks if the invoice line is not a header line.
    
#}{# 0 #}{% set totalDiscount = 0 %}{# 1 #}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set discount = invoiceline.nonBundleTotalDiscount(false) %}{# 3 #}{% set totalDiscount = totalDiscount + discount %}{% endif %}{# 4 #}{% elseif not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set discount = invoiceline.nonBundleTotalDiscount(false) %}{# 3 #}{% set totalDiscount = totalDiscount + discount %}{% endif %}{% endif %}{% endfor %}{# --- END OF NON BUNDLE DISCOUNT TOTAL EXCLUDING TAX CLUSTER --- #}{# --- START OF NON BUNDLE DISCOUNT TOTAL INCLUDING TAX CLUSTER --- #}{# This grouping calculates nonBundle discount total so that can be referenced in an if condition for discount column of invoice table:
    
            0. Sets totalDiscountWithTax to 0 as an initial starting point.
            1. Checks if the line is a header line.
            2. Sets the discountWithTax to be equal to the invoiceline nonbundleTotalDiscount value if not the 'reverse balance charge' item .
            3. Overrides totalDiscountWithTax's value, then adds to it. So, totalDiscountWithTax = totalDiscountWithTax + discountWithTax.
            4. Checks if the invoice line is not a header line.
    
#}{# 0 #}{% set totalDiscountWithTax = 0 %}{# 1 #}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set discountWithTax = invoiceline.nonBundleTotalDiscount(true) %}{# 3 #}{% set totalDiscountWithTax = totalDiscountWithTax + discountWithTax %}{% endif %}{# 4 #}{% elseif not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set discountWithTax = invoiceline.nonBundleTotalDiscount(true) %}{# 3 #}{% set totalDiscountWithTax = totalDiscountWithTax + discountWithTax %}{% endif %}{% endif %}{% endfor %}{# --- END OF NON BUNDLE DISCOUNT TOTAL INCLUDING TAX CLUSTER --- #}{# --- START OF TOTAL EXCLUDING REVERSE BALANCE CHARGE CLUSTER --- #}{# This grouping calculates invoice total to exclude reverse balance charge:
    
            0. Sets the nonReversalTotal to 0.
            1. Checks if the invoice line is a header line.
            2. Sets nonReversalLineTotal to be invoiceline total if not the 'reverse balance charge' item 
            3. Overrides the nonReversalTotal's value, then adds to it. So, nonReversalTotal = nonReversalTotal + nonReversalLineTotal
            4. Checks if the invoice line is not a header line.
    
#}{# 0 #}{% set nonReversalTotal = 0 %}{# 1 #}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set nonReversalLineTotal = invoiceline.total(false) %}{# 3 #}{% set nonReversalTotal = nonReversalTotal + nonReversalLineTotal %}{% endif %}{# 4 #}{% elseif not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set nonReversalLineTotal = invoiceline.total(false) %}{# 3 #}{% set nonReversalTotal = nonReversalTotal + nonReversalLineTotal %}{% endif %}{% endif %}{% endfor %}{# --- END OF TOTAL EXCLUDING REVERSE BALANCE CHARGE CLUSTER --- #}{# --- START OF TAX EXCLUDING REVERSE BALANCE CHARGE CLUSTER #}{# This grouping calculates the invoice tax total to exclude reverse balance charge:
            
            0. Set the taxTotal variable to 0 as a starting point. 
            1. Checks if the invoice line is a header line.
            2. Sets nonReversalLineTotal to be invoiceline total if not the 'reverse balance charge' item.
            3. Overrides taxTotal's value, then adds to it. So, taxTotal = taxTotal + taxLineTotal
			4. Checks if the invoice line is not a header line.
            
#}{# 0 #}{% set taxTotal = 0 %}{# 1 #}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set taxLineTotal = invoiceline.totalgst %}{# 3 #}{% set taxTotal = taxTotal + taxLineTotal %}{% endif %}{# 4 #}{% elseif not invoiceline.hasHeaderLine %}{# 2 #}{% if invoiceline.product.getCode != 'REVERSE' %}{% set taxLineTotal = invoiceline.totalgst %}{# 3 #}{% set taxTotal = taxTotal + taxLineTotal %}{% endif %}{% endif %}{% endfor %}{# --- END OF TAX EXCLUDING REVERSE BALANCE CHARGE CLUSTER --- #}{# showVATRateTotalTable must be set to true to print in the template settings above #}{% if showVATRateTotalTable|lower == 'true' %}{# --- START OF TAX RATE TOTAL COUNT CLUSTER  --- #}{# This grouping calculates the invoice tax totals per tax rate:   

        {# A0 - Creates and sets variables for Net, Tax and Gross Totals at Standard Rate (S) (20%) to 0 #}{% set nonReversalNetTotalSRate = 0 %}{% set nonReversalTaxTotalSRate = 0 %}{% set nonReversalGrossTotalSRate = 0 %}{# A1 - Traverses all invoice lines and nested lines and adds to the variables set for Net, Tax, Gross Totals if not a header line (i.e. bundle or item with a service fee) #}{% for invoiceline in invoice.lineItems %}{% if not invoiceline.isHeaderline and invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + invoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + invoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% for subinvoiceline in invoiceline.nestedLines %}{% if not subinvoiceline.isHeaderline and subinvoiceline.hasHeaderLine %}{% if subinvoiceline.product.getCode != 'REVERSE' and subinvoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + subinvoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + subinvoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if not subsubinvoiceline.isHeaderline and subsubinvoiceline.hasHeaderLine %}{% if subsubinvoiceline.product.getCode != 'REVERSE' and subsubinvoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + subsubinvoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + subsubinvoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if not subsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubinvoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + subsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + subsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %}{% if not subsubsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubsubinvoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + subsubsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + subsubsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elseif not invoiceline.isHeaderline and not invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'S' %}{% set nonReversalNetTotalSRate = nonReversalNetTotalSRate + invoiceline.total(false) %}{% set nonReversalTaxTotalSRate = nonReversalTaxTotalSRate + invoiceline.totalgst %}{% set nonReversalGrossTotalSRate = nonReversalGrossTotalSRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{# A2 - End of S Rate (20%) Net, Tax and Gross Total Count #}{# B0 - Creates and sets variables for Net, Tax and Gross Totals at Reduced Rate (R) (5%) to 0 #}{% set nonReversalNetTotalRRate = 0 %}{% set nonReversalTaxTotalRRate = 0 %}{% set nonReversalGrossTotalRRate = 0 %}{# B1 - Traverses all invoice lines and nested lines and adds to the variables set for Net, Tax, Gross Totals if not a header line (i.e. bundle or item with a service fee) #}{% for invoiceline in invoice.lineItems %}{% if not invoiceline.isHeaderline and invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + invoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + invoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% for subinvoiceline in invoiceline.nestedLines %}{% if not subinvoiceline.isHeaderline and subinvoiceline.hasHeaderLine %}{% if subinvoiceline.product.getCode != 'REVERSE' and subinvoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + subinvoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + subinvoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if not subsubinvoiceline.isHeaderline and subsubinvoiceline.hasHeaderLine %}{% if subsubinvoiceline.product.getCode != 'REVERSE' and subsubinvoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + subsubinvoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + subsubinvoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if not subsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubinvoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + subsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + subsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %}{% if not subsubsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubsubinvoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + subsubsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + subsubsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elseif not invoiceline.isHeaderline and not invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'R' %}{% set nonReversalNetTotalRRate = nonReversalNetTotalRRate + invoiceline.total(false) %}{% set nonReversalTaxTotalRRate = nonReversalTaxTotalRRate + invoiceline.totalgst %}{% set nonReversalGrossTotalRRate = nonReversalGrossTotalRRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{# B2 - End of R Rate (5%) Net, Tax and Gross Total Count #}{# C0 - Creates and sets variables for Net, Tax and Gross Totals at Zero Rate (Z) (0%) to 0 #}{% set nonReversalNetTotalZRate = 0 %}{% set nonReversalTaxTotalZRate = 0 %}{% set nonReversalGrossTotalZRate = 0 %}{# C1 - Traverses all invoice lines and nested lines and adds to the variables set for Net, Tax, Gross Totals if not a header line (i.e. bundle or item with a service fee) #}{% for invoiceline in invoice.lineItems %}{% if not invoiceline.isHeaderline and invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + invoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + invoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% for subinvoiceline in invoiceline.nestedLines %}{% if not subinvoiceline.isHeaderline and subinvoiceline.hasHeaderLine %}{% if subinvoiceline.product.getCode != 'REVERSE' and subinvoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + subinvoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + subinvoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if not subsubinvoiceline.isHeaderline and subsubinvoiceline.hasHeaderLine %}{% if subsubinvoiceline.product.getCode != 'REVERSE' and subsubinvoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + subsubinvoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + subsubinvoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if not subsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubinvoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + subsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + subsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %}{% if not subsubsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubsubinvoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + subsubsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + subsubsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elseif not invoiceline.isHeaderline and not invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'Z' %}{% set nonReversalNetTotalZRate = nonReversalNetTotalZRate + invoiceline.total(false) %}{% set nonReversalTaxTotalZRate = nonReversalTaxTotalZRate + invoiceline.totalgst %}{% set nonReversalGrossTotalZRate = nonReversalGrossTotalZRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{# C2 - End of Z Rate (0%) Net, Tax and Gross Total Count #}{# D0 - Creates and sets variables for Net, Tax and Gross Totals at Exempt Rate (X) (0%) to 0 #}{% set nonReversalNetTotalXRate = 0 %}{% set nonReversalTaxTotalXRate = 0 %}{% set nonReversalGrossTotalXRate = 0 %}{# D1 - Traverses all invoice lines and nested lines and adds to the variables set for Net, Tax, Gross Totals if not a header line (i.e. bundle or item with a service fee) #}{% for invoiceline in invoice.lineItems %}{% if not invoiceline.isHeaderline and invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + invoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + invoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% for subinvoiceline in invoiceline.nestedLines %}{% if not subinvoiceline.isHeaderline and subinvoiceline.hasHeaderLine %}{% if subinvoiceline.product.getCode != 'REVERSE' and subinvoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + subinvoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + subinvoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if not subsubinvoiceline.isHeaderline and subsubinvoiceline.hasHeaderLine %}{% if subsubinvoiceline.product.getCode != 'REVERSE' and subsubinvoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + subsubinvoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + subsubinvoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if not subsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubinvoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + subsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + subsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% endif %}{% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %}{% if not subsubsubsubinvoiceline.isHeaderline and subsubsubinvoiceline.hasHeaderLine %}{% if subsubsubsubinvoiceline.product.getCode != 'REVERSE' and subsubsubsubinvoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + subsubsubsubinvoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + subsubsubsubinvoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elseif not invoiceline.isHeaderline and not invoiceline.hasHeaderLine %}{% if invoiceline.product.getCode != 'REVERSE' and invoiceline.getTaxCode == 'X' %}{% set nonReversalNetTotalXRate = nonReversalNetTotalXRate + invoiceline.total(false) %}{% set nonReversalTaxTotalXRate = nonReversalTaxTotalXRate + invoiceline.totalgst %}{% set nonReversalGrossTotalXRate = nonReversalGrossTotalXRate + invoiceline.total(true) %}{% endif %}{% endif %}{% endfor %}{# D2 - End of X Rate (0%) Net, Tax and Gross Total Count #}{# --- END OF TAX RATE TOTAL COUNT CLUSTER ---#}{% endif %}
<div style="margin: 0px">{# showTreatmentDateRange must be set to true to print in the template settings above #}{% if showTreatmentDateRange|lower == 'true' %}{# --- START OF TREATMENT DATE RANGE TABLE --- #}{# This table generates above the main invoice table to highlight treatment dates of the invoice if its across multiple days #}{% if highestValue != lowestValue %}
<table style="width:100%">
	<tbody>
		<tr>
			<td style="color:#000000; float:center; font-size:12px; text-align:center"><strong>Treatment Dates: {{ lowestValue }} &mdash; {{ highestValue }}</strong></td>
		</tr>
	</tbody>
</table>
<br />
{% endif %}{# --- END OF TREATMENT DATE RANGE TABLE --- #}{% endif %}{# showCaseOwner must be set to true to print in the template settings above #}{% if showCaseOwner|lower == 'true' %}{# --- START OF CASE OWNER TABLE --- #}{# This generates if the consult associated with the invoice has a case owner #}{% if invoice.consult.getCaseOwner.getName != "" %}
<table style="width:100%">
	<tbody>
		<tr style="background-color:#f0f0f0">
			<td style="font-size:12px; height:30px; text-align:left"><strong>Overview of visit with {{ invoice.consult.getCaseOwner.getName }}</strong></td>
		</tr>
	</tbody>
</table>
{% endif %}{# --- END OF CASE OWNER TABLE --- #}{% endif %}{# --- START OF MAIN INVOICE TABLE --- #}

<table style="border-bottom:2px solid #cccccc; width:100%">{# --- START OF INVOICE HEADER --- #}
	<thead>{# This applies a grey background colour to column headers below if there is no associated case owner and showcasOwner is not true - meaning that the case owner table will not generate #}{% if (invoice.consult?.getCaseOwner?.getName ?? '') != '' and showCaseOwner|lower == 'true' %}
		<tr>{% else %}
		</tr>
		<tr style="background-color:#f0f0f0">{% endif %}{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td class="fitwidth">{# LineDateHeader is set in the template settings above #}<strong>{{ LineDateHeader }}</strong></td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td class="fitwidth">{# ProductCodeHeader is set in the template settings above #}<strong>{{ ProductCodeHeader }}</strong></td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td class="fitwidth">{# ProductNameHeader is set in the template settings above #}<strong>{{ ProductNameHeader }}</strong></td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="fitwidth">{# BatchAndExpiryHeader is set in the template settings above #}<strong>{{ BatchAndExpiryHeader }}</strong></td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td class="fitwidth">{# StaffMemberHeader is set in the template settings above #}<strong>{{ StaffMemberHeader }}</strong></td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="fitwidth">{# UnitPriceExcludingTaxHeader is set in the template settings above #}<strong>{{ UnitPriceExcludingTaxHeader }}</strong></td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="fitwidth">{# UnitPriceIncludingTaxHeader is set in the template settings above #}<strong>{{ UnitPriceIncludingTaxHeader }}</strong></td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="fitwidth">{# QuantityHeader is set in the template settings above #}<strong>{{ QuantityHeader }}</strong></td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discount exists #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="fitwidth">{# TotalBeforeDiscountExcludingTaxHeader is set in the template settings above #}<strong>{{ TotalBeforeDiscountExcludingTaxHeader }}</strong></td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="fitwidth">{# TotalBeforeDiscountIncludingTaxHeader is set in the template settings above #}<strong>{{ TotalBeforeDiscountIncludingTaxHeader }}</strong></td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td class="fitwidth">{# DiscountExcludingTaxHeader is set in the template settings above #}<strong>{{ DiscountExcludingTaxHeader }}</strong></td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td class="fitwidth">{# DiscountIncludingTaxHeader is set in the template settings above #}<strong>{{ DiscountIncludingTaxHeader }}</strong></td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="fitwidth">{# DiscountPercentageHeader is set in the template settings above #}<strong>{{ DiscountPercentageHeader }}</strong></td>
			{% endif %}{% endif %}{# showTax must be set to true to print in the template settings above #}{% if showTax|lower == 'true' %}
			<td class="fitwidth">{# TaxHeader is set in the template settings above #}<strong>{{ TaxHeader }}</strong></td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="fitwidth">{# TaxPercentageHeader is set in the template settings above #}<strong>{{ TaxPercentageHeader }}</strong></td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="fitwidth" style="text-align:right">{# TotalExcludingTaxHeader is set in the template settings above #}<strong>{{ TotalExcludingTaxHeader }}</strong></td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="fitwidth" style="text-align:right">{# TotalIncludingTaxHeader is set in the template settings above #}<strong>{{ TotalIncludingTaxHeader }}</strong></td>
			{% endif %}
		</tr>
	</thead>
	{# -- END OF INVOICE HEADER --- #}{# --- START OF INVOICE BODY ---- #}
	<tbody>{% for invoiceline in invoice.lineItems %}{# Start of invoice line generation if a header line (i.e. bundle or item with a service fee) #}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{# Excludes invoice line if reverse balance charge - this is in case a service fee is added to the product erroneously #}{% if invoiceline.product.getCode != 'REVERSE' %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}{# --- START OF COST PRICE EXCLUDING TAX CLUSTER --- #}{# This cluster sets the unit price to be calculated using total AFTER discount if it is a fixed bundle - works if fixed to £0 #}{% if invoiceline.lineType == 'header-bundle-fixed' %}{# if the quantity is positive #}{% if invoiceline.quantity > 0 %}{% set costpriceexcludingtax = invoiceline.total(false) / invoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = invoiceline.total(false) / (invoiceline.quantity*-1) %}{% endif %}{# Else if it is a Variable bundle then it it adds all components together then divides by quantity #}{% elseif invoiceline.lineType == 'header-bundle' %}{# if the quantity is positive #}{% if invoiceline.quantity > 0 %}{% set costpriceexcludingtax = (invoiceline.total(false) + invoiceline.nonBundleTotalDiscount(false)) / invoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = (invoiceline.total(false) + invoiceline.nonBundleTotalDiscount(false)) / (invoiceline.quantity*-1) %}{% endif %}{# Else if it is not a bundle AKA normal line or med with service fee ('header-serviced') #}{% else %}{# if positive value for quantity #}{% if invoiceline.quantity > 0 %}{% set costpriceexcludingtax = invoiceline.totalBeforeDiscount(false) / invoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif invoiceline.quantity == 0 %}{% set costpriceexcludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = invoiceline.totalBeforeDiscount(false) / (invoiceline.quantity*-1) %}{% endif %}{% endif %}{# --- END OF COST PRICE EXCLUDING TAX CLUSTER --- #}{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}{# --- START OF COST PRICE INCLUDING TAX CLUSTER --- #}{# This cluster sets the unit price to be calculated using total AFTER discount if it is a fixed bundle - works if fixed to £0 #}{% if invoiceline.lineType == 'header-bundle-fixed' %}{# if the quantity is positive #}{% if invoiceline.quantity > 0 %}{% set costpriceincludingtax = invoiceline.total(true) / invoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = invoiceline.total(true) / (invoiceline.quantity*-1) %}{% endif %}{# Else if it is a Variable bundle then it it adds all components together then divides by quantity #}{% elseif invoiceline.lineType == 'header-bundle' %}{# if the quantity is positive #}{% if invoiceline.quantity > 0 %}{% set costpriceincludingtax = (invoiceline.total(true) + invoiceline.nonBundleTotalDiscount(true)) / invoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = (invoiceline.total(true) + invoiceline.nonBundleTotalDiscount(true)) / (invoiceline.quantity*-1) %}{% endif %}{# Else if it is not a bundle AKA normal line or med with service fee ('header-serviced') #}{% else %}{# if positive value for quantity #}{% if invoiceline.quantity > 0 %}{% set costpriceincludingtax = invoiceline.totalBeforeDiscount(true) / invoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif invoiceline.quantity == 0 %}{% set costpriceincludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = invoiceline.totalBeforeDiscount(true) / (invoiceline.quantity*-1) %}{% endif %}{% endif %}{# --- END OF COST PRICE INCLUDING TAX CLUSTER --- #}{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}{# --- START OF DISCOUNT PERCENTAGE CLUSTER --- #}{# Calculates discount percentage based on nonBundleTotalDiscount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# if the cost price is not 0 #}{% if invoiceline.totalBeforeDiscount(false) != 0 %}{# set the discount percentage  = (discount amount / total before discount) * 100 #}{% set net = invoiceline.nonBundleTotalDiscount(false) + invoiceline.total(false) %}{% set discountPercent = (( invoiceline.nonBundleTotalDiscount(false) / net ) * 100) %}{# else in the cases where the cost is 0 but the total is not 0 then it sets the discount to 100% #}{% else %}{% set discountPercent = 100.00 %}{% endif %}{# else is there is no discount or a surcharge then set it to 0 #}{% else %}{% set discountPercent = 0.00 %}{% endif %}{# --- END OF DISCOUNT PERCENTAGE CLUSTER --- #}{% endif %}{# hiddenProductGroup must be set to match product group name in the template settings above #}{% if invoiceline.product.financialProductGroup.name|lower != hiddenProductGroup %}
		<tr>{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td class="line">{{ invoiceline.date|dateformat }}</td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td class="line">{{ invoiceline.productCode }}</td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td class="line">{# Uses invoice line description if it does not match product printable name #}{% if ( invoiceline.product.printablename != invoiceline.name ) and ( invoiceline.name != "" ) %}{{ invoiceline.name }} {% else %} {{ invoiceline.product.printablename }} {% endif %} {# showBatchBelowInvoiceLine must be set to true to print in the template settings above #} {% if showBatchBelowInvoiceLine|lower == 'true' %} {% if invoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ invoiceline.serialAndExpiry }} {% elseif invoiceline.lineType == 'header-serviced' %} {% for subinvoiceline in invoiceline.nestedLines %} {% if subinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %} {% endif %} {# showCommentBelowInvoiceLine must be set to true to print in the template settings above #} {% if showCommentBelowInvoiceLine|lower == 'true' %} {% if invoiceline.reference %}<br />
			<em>Comment: {{ invoiceline.reference }}</em> {% endif %} {% endif %}</td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="line">{% if invoiceline.hasSerialNumbers %}{{ invoiceline.serialAndExpiry }} {% elseif invoiceline.lineType == 'header-serviced' %} {% for subinvoiceline in invoiceline.nestedLines %} {% if subinvoiceline.hasSerialNumbers %} {{ subinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %}</td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td class="line">{# --- START OF CHECK FOR SALES PERSON --- #}{% set primary_name = invoiceline.salesperson.name %}{% if primary_name %}{{ primary_name }} {% else %} {% set names = '' %} {# Step 1: Subline salesperson names if line salesperson blank #} {% for subinvoiceline in invoiceline.nestedLines %} {% if subinvoiceline.salesperson is defined and subinvoiceline.salesperson.name is defined %} {% set name = subinvoiceline.salesperson.name %} {% if name != '' %} {% if names == '' %} {% set names = name %} {% else %} {% set check = ', ' ~ name ~ ',' %} {% set full_list = ', ' ~ names ~ ',' %} {% if check not in full_list %} {% set names = names ~ ', ' ~ name %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {# Step 2: If no names found, look in sub-sublines #} {% if names == '' %} {% for subinvoiceline in invoiceline.nestedLines %} {% if subinvoiceline.nestedLines is defined %} {% for subsubinvoiceline in subinvoiceline.nestedLines %} {% if subsubinvoiceline.salesperson is defined and subsubinvoiceline.salesperson.name is defined %} {% set name = subsubinvoiceline.salesperson.name %} {% if name != '' %} {% if names == '' %} {% set names = name %} {% else %} {% set check = ', ' ~ name ~ ',' %} {% set full_list = ', ' ~ names ~ ',' %} {% if check not in full_list %} {% set names = names ~ ', ' ~ name %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {{ names }} {% endif %} {# --- START OF CHECK FOR SALES PERSON --- #}</td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{{ costpriceexcludingtax|moneyformat }} {% endif %}</td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{{ costpriceincludingtax|moneyformat }} {% endif %}</td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="line">{{ invoiceline.quantity }}</td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discounts are present #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (invoiceline.nonBundleTotalDiscount(false) + invoiceline.total(false))|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (invoiceline.nonBundleTotalDiscount(true) + invoiceline.total(true))|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{{ invoiceline.nonBundleTotalDiscount(false)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{{ invoiceline.nonBundleTotalDiscount(true)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if discountPercent > 0 %}{# Discount percent set to round to 1 decimal to avoid discrepencies with UI when using more than 1 decimal point #}{{ discountPercent|round(1)}}% {% endif %} {% endif %}</td>
			{% endif %}{% endif %}{# showTax must be set to true to print in the template settings above #}{% if showTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{{ invoiceline.totalGst|moneyformat }} {% endif %}</td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{# --- Start of tax rate check across sublines and consolidation --- #}{% if not invoiceline.printContainedPrices %}{% set primary_tax = invoiceline.getTaxRate %}{% if primary_tax %}{{ primary_tax }}% {% else %} {% set taxes = "" %} {# ----------------- Level 1: subinvoiceline check ----------------- #} {% for subinvoiceline in invoiceline.nestedLines %} {# Add tax rate from subinvoiceline if defined #} {% if subinvoiceline.getTaxRate is defined %} {% set rate = subinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 2: subsubinvoiceline check ----------------- #} {% if subinvoiceline.nestedLines is defined %} {% for subsubinvoiceline in subinvoiceline.nestedLines %} {% if subsubinvoiceline.getTaxRate is defined %} {% set rate = subsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 3: subsubsubinvoiceline check ----------------- #} {% if subsubinvoiceline.nestedLines is defined %} {% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %} {% if subsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 4: subsubsubsubinvoiceline check ----------------- #} {% if subsubsubinvoiceline.nestedLines is defined %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% if taxes != "" %} {{ taxes }}% {% else %} 0% {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="line" style="text-align:right">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{{ invoiceline.total(false)|moneyformat }} {% endif %}</td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="line" style="text-align:right">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not invoiceline.printContainedPrices %}{{ invoiceline.total(true)|moneyformat }} {% endif %}</td>
			{% endif %}
		</tr>
		{% endif %}{% endif %}{# End of invoice line generation if a header line (i.e. bundle or item with a service fee) #}{# Start of subinvoice line generation #}{% if invoiceline.printContained %}{% for subinvoiceline in invoiceline.nestedLines %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}{# --- START OF COST PRICE EXCLUDING TAX CLUSTER --- #}{# This cluster sets the unit price to be calculated using total AFTER discount if it is a fixed bundle - works if fixed to £0 #}{% if subinvoiceline.lineType == 'header-bundle-fixed' %}{# if the quantity is positive #}{% if subinvoiceline.quantity > 0 %}{% set costpriceexcludingtax = subinvoiceline.total(false) / subinvoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = subinvoiceline.total(false) / (subinvoiceline.quantity*-1) %}{% endif %}{# Else if it is a Variable bundle then it it adds all components together then divides by quantity #}{% elseif subinvoiceline.lineType == 'header-bundle' %}{# if the quantity is positive #}{% if subinvoiceline.quantity > 0 %}{% set costpriceexcludingtax = (subinvoiceline.total(false) + subinvoiceline.nonBundleTotalDiscount(false)) / subinvoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = (subinvoiceline.total(false) + subinvoiceline.nonBundleTotalDiscount(false)) / (subinvoiceline.quantity*-1) %}{% endif %}{# Else if it is not a bundle AKA normal line or med with service fee ('header-serviced') #}{% else %}{# if positive value for quantity #}{% if subinvoiceline.quantity > 0 %}{% set costpriceexcludingtax = subinvoiceline.totalBeforeDiscount(false) / subinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subinvoiceline.quantity == 0 %}{% set costpriceexcludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = subinvoiceline.totalBeforeDiscount(false) / (subinvoiceline.quantity*-1) %}{% endif %}{% endif %}{# --- END OF COST PRICE EXCLUDING TAX CLUSTER --- #}{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}{# --- START OF COST PRICE INCLUDING TAX CLUSTER --- #}{# This cluster sets the unit price to be calculated using total AFTER discount if it is a fixed bundle - works if fixed to £0 #}{% if subinvoiceline.lineType == 'header-bundle-fixed' %}{# if the quantity is positive #}{% if subinvoiceline.quantity > 0 %}{% set costpriceincludingtax = subinvoiceline.total(true) / subinvoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = subinvoiceline.total(true) / (subinvoiceline.quantity*-1) %}{% endif %}{# Else if it is a Variable bundle then it it adds all components together then divides by quantity #}{% elseif subinvoiceline.lineType == 'header-bundle' %}{# if the quantity is positive #}{% if subinvoiceline.quantity > 0 %}{% set costpriceincludingtax = (subinvoiceline.total(true) + subinvoiceline.nonBundleTotalDiscount(true)) / subinvoiceline.quantity %}{# if the quanitity is negative #}{% else %}{% set costpriceeincludingtax = (subinvoiceline.total(true) + subinvoiceline.nonBundleTotalDiscount(true)) / (subinvoiceline.quantity*-1) %}{% endif %}{# Else if it is not a bundle AKA normal line or med with service fee ('header-serviced') #}{% else %}{# if positive value for quantity #}{% if subinvoiceline.quantity > 0 %}{% set costpriceincludingtax = subinvoiceline.totalBeforeDiscount(true) / subinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subinvoiceline.quantity == 0 %}{% set costpriceincludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = subinvoiceline.totalBeforeDiscount(true) / (subinvoiceline.quantity*-1) %}{% endif %}{% endif %}{# --- END OF COST PRICE INCLUDING TAX CLUSTER --- #}{% endif %}{# START OF DISCOUNT CLUSTER #}{# Calculates discount percentage based on nonBundleTotalDiscount #}{% if subinvoiceline.nonBundleTotalDiscount > 0 %}{# if the cost price is not 0 #}{% if subinvoiceline.totalBeforeDiscount(false) != 0 %}{# set the discount percentage  = (discount amount / total before discount) * 100 #}{% set net = subinvoiceline.nonBundleTotalDiscount(false) + subinvoiceline.total(false) %}{% set discountPercent = (( subinvoiceline.nonBundleTotalDiscount(false) / net ) * 100) %}{# else in the cases where the cost is 0 but the total is not 0 then it sets the discount to 100% #}{% else %}{% set discountPercent = 100.00 %}{% endif %}{# else is there is no discount or a surcharge then set it to 0 #}{% else %}{% set discountPercent = 0.00 %}{% endif %}{# END OF DISCOUNT CLUSTER #}{# hiddenProductGroup must be set to match product group name in the template settings above #}{% if subinvoiceline.product.financialProductGroup.name|lower != hiddenProductGroup %}
		<tr>{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td class="subline">{#  Date column is empty for sublines #}</td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td class="subline">{{ subinvoiceline.productCode }}</td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td class="subline" style="padding-left:20px">{# Uses invoice line description if it does not match product printable name #}{% if ( subinvoiceline.product.printablename != subinvoiceline.name ) and ( subinvoiceline.name != "" ) %}{{ subinvoiceline.name }} {% else %} {{ subinvoiceline.product.printablename }} {% endif %} {# showBatchBelowInvoiceLine must be set to true to print in the template settings above #} {% if showBatchBelowInvoiceLine|lower == 'true' %} {% if subinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subinvoiceline.serialAndExpiry }} {% elseif subinvoiceline.lineType == 'header-serviced' %} {% for subsubinvoiceline in subinvoiceline.nestedLines %} {% if subsubinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %} {% endif %} {# showCommentBelowInvoiceLine must be set to true to print in the template settings above #} {% if showCommentBelowInvoiceLine|lower == 'true' %} {% if subinvoiceline.reference %}<br />
			<em>Comment: {{ subinvoiceline.reference }}</em> {% endif %} {% endif %}</td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.hasSerialNumbers %}{{ subinvoiceline.serialAndExpiry }} {% elseif subinvoiceline.lineType == 'header-serviced' %} {% for subsubinvoiceline in subinvoiceline.nestedLines %} {% if subsubinvoiceline.hasSerialNumbers %} {{ subsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %}</td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td class="subline">{#  Staff member is empty for sublines #}</td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{{ costpriceexcludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{{ costpriceincludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="subline">{{ subinvoiceline.quantity }}</td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discounts are present #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subinvoiceline.nonBundleTotalDiscount(false) + subinvoiceline.total(false))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subinvoiceline.nonBundleTotalDiscount(true) + subinvoiceline.total(true))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td>{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subinvoiceline.nonBundleTotalDiscount > 0 %}{{ subinvoiceline.nonBundleTotalDiscount(false)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td>{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subinvoiceline.nonBundleTotalDiscount > 0 %}{{ subinvoiceline.nonBundleTotalDiscount(true)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if discountPercent > 0 %}{# Discount percent set to round to 1 decimal to avoid discrepencies with UI when using more than 1 decimal point #}{{ discountPercent|round(1)}}% {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{% endif %}{# showTax must be set to true to print in the template settings above #}{% if showTax|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{{ subinvoiceline.totalGst|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="subline">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{% set primary_tax = subinvoiceline.getTaxRate %}{% if primary_tax %}{{ primary_tax }}% {% else %} {% set taxes = "" %} {# ----------------- Level 1: subsubinvoiceline check ----------------- #} {% if subinvoiceline.nestedLines is defined %} {% for subsubinvoiceline in subinvoiceline.nestedLines %} {% if subsubinvoiceline.getTaxRate is defined %} {% set rate = subsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 2: subsubsubinvoiceline check ----------------- #} {% if subsubinvoiceline.nestedLines is defined %} {% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %} {% if subsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 3: subsubsubsubinvoiceline check ----------------- #} {% if subsubsubinvoiceline.nestedLines is defined %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% if taxes != "" %} {{ taxes }}% {% else %} 0% {% endif %} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{{ subinvoiceline.total(false)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if invoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subinvoiceline.printContainedPrices %}{{ subinvoiceline.total(true)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}
		</tr>
		{% endif %}{# End of subinvoice line generation #}{# Start of subsubinvoice line generation #}{% if subinvoiceline.isHeaderline %}{% if subinvoiceline.printContained %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}{# --- START OF COST PRICE CLUSTER EXCLUDING TAX --- #}{# if positive value for quantity #}{% if subsubinvoiceline.quantity > 0 %}{% set costpriceexcludingtax = subsubinvoiceline.totalBeforeDiscount(false) / subsubinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subsubinvoiceline.quantity == 0 %}{% set costpriceexcludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = subsubinvoiceline.totalBeforeDiscount(false) / (subsubinvoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE CLUSTER EXCLUDING TAX --- #}{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}{# --- START OF COST PRICE CLUSTER INCLUDING TAX --- #}{# if positive value for quantity #}{% if subsubinvoiceline.quantity > 0 %}{% set costpriceincludingtax = subsubinvoiceline.totalBeforeDiscount(true) / subsubinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subsubinvoiceline.quantity == 0 %}{% set costpriceincludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = subsubinvoiceline.totalBeforeDiscount(true) / (subsubinvoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE CLUSTER INCLUDING TAX --- #}{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}{# --- START OF DISCOUNT PERCENTAGE CLUSTER --- #}{# Calculates discount percentage based on nonBundleTotalDiscount #}{% if subsubinvoiceline.nonBundleTotalDiscount > 0 %}{# if the cost price is not 0 #}{% if subsubinvoiceline.totalBeforeDiscount(false) != 0 %}{# set the discount percentage  = (discount amount / total before discount) * 100 #}{% set net = subsubinvoiceline.nonBundleTotalDiscount(false) + subsubinvoiceline.total(false) %}{% set discountPercent = (( subsubinvoiceline.nonBundleTotalDiscount(false) / net ) * 100) %}{# else in the cases where the cost is 0 but the total is not 0 then it sets the discount to 100% #}{% else %}{% set discountPercent = 100.00 %}{% endif %}{# else is there is no discount or a surcharge then set it to 0 #}{% else %}{% set discountPercent = 0.00 %}{% endif %}{# --- END OF DISCOUNT PERCENTAGE CLUSTER --- #}{% endif %}{# hiddenProductGroup must be set to match product group name in the template settings above #}{% if subsubinvoiceline.product.financialProductGroup.name|lower != hiddenProductGroup %}
		<tr>{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td class="subline">{#  Date column is empty for sublines #}</td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td class="subline">{{ subsubinvoiceline.productCode }}</td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td class="subline" style="padding-left:40px">{# Uses line description if it does not match product printable name #}{% if ( subsubinvoiceline.product.printablename != subsubinvoiceline.name ) and ( subsubinvoiceline.name != "" ) %}{{ subsubinvoiceline.name }} {% else %} {{ subsubinvoiceline.product.printablename }} {% endif %} {# showBatchBelowInvoiceLine must be set to true to print in the template settings above #} {% if showBatchBelowInvoiceLine|lower == 'true' %} {% if subsubinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subsubinvoiceline.serialAndExpiry }} {% elseif subsubinvoiceline.lineType == 'header-serviced' %} {% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %} {% if subsubsubinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subsubsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %} {% endif %} {# showCommentBelowInvoiceLine must be set to true to print in the template settings above #} {% if showCommentBelowInvoiceLine|lower == 'true' %} {% if subsubinvoiceline.reference %}<br />
			<em>Comment: {{ subsubinvoiceline.reference }}</em> {% endif %} {% endif %}</td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.hasSerialNumbers %}{{ subsubinvoiceline.serialAndExpiry }} {% elseif subsubinvoiceline.lineType == 'header-serviced' %} {% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %} {% if subsubsubinvoiceline.hasSerialNumbers %} {{ subsubsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %}</td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td class="subline">{#  Staff member is empty for sublines #}</td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if header is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{{ costpriceexcludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if header is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{{ costpriceincludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="subline">{{ subsubinvoiceline.quantity }}</td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discounts are present #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{# Shows if subinvoice line has a discount #}{% if subsubinvoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subsubinvoiceline.nonBundleTotalDiscount(false) + subsubinvoiceline.total(false))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{# Shows if subinvoice line has a discount #}{% if subsubinvoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subsubinvoiceline.nonBundleTotalDiscount(true) + subsubinvoiceline.total(true))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if header is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subsubinvoiceline.nonBundleTotalDiscount > 0 %}{{ subsubinvoiceline.nonBundleTotalDiscount(false)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if header is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subsubinvoiceline.nonBundleTotalDiscount > 0 %}{{ subsubinvoiceline.nonBundleTotalDiscount(true)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if discountPercent > 0 %}{# Discount percent set to round to 1 decimal to avoid discrepencies with UI when using more than 1 decimal point #}{{ discountPercent|round(1)}}% {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{% endif %}{# showTax must be set to true to print in the template settings above #}{% if showTax|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{{ subsubinvoiceline.totalGst|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="subline">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{% set primary_tax = subsubinvoiceline.getTaxRate %}{% if primary_tax %}{{ primary_tax }}% {% else %} {% set taxes = "" %} {# ----------------- Level 1: subsubsubinvoiceline check ----------------- #} {% if subsubinvoiceline.nestedLines is defined %} {% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %} {% if subsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {# ----------------- Level 2: subsubsubsubinvoiceline check ----------------- #} {% if subsubsubinvoiceline.nestedLines is defined %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% if taxes != "" %} {{ taxes }}% {% else %} 0% {% endif %} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{{ subsubinvoiceline.total(false)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if subinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubinvoiceline.printContainedPrices %}{{ subsubinvoiceline.total(true)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}
		</tr>
		{% endif %}{# --- End of subsubinvoice line generation --- #}{# --- Start of subsubsubinvoice line generation --- #}{% if subinvoiceline.isHeaderline %}{% if subsubinvoiceline.printContained %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}{# --- START OF COST PRICE CLUSTER EXCLUDING TAX --- #}{# if positive value for quantity #}{% if subsubsubinvoiceline.quantity > 0 %}{% set costpriceexcludingtax = subsubsubinvoiceline.totalBeforeDiscount(false) / subsubsubinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subsubsubinvoiceline.quantity == 0 %}{% set costpriceexcludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = subsubsubinvoiceline.totalBeforeDiscount(false) / (subsubsubinvoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE CLUSTER EXCLUDING TAX --- #}{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}{# --- START OF COST PRICE CLUSTER INCLUDING TAX --- #}{# if positive value for quantity #}{% if subsubsubinvoiceline.quantity > 0 %}{% set costpriceeincludingtax = subsubsubinvoiceline.totalBeforeDiscount(true) / subsubsubinvoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif subsubsubinvoiceline.quantity == 0 %}{% set costpriceincludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = subsubsubinvoiceline.totalBeforeDiscount(true) / (subsubsubinvoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE CLUSTER INCLUDING TAX --- #}{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}{# --- START OF DISCOUNT PERCENTAGE CLUSTER --- #}{# Calculates discount percentage based on nonBundleTotalDiscount #}{% if subsubsubinvoiceline.nonBundleTotalDiscount > 0 %}{# if the cost price is not 0 #}{% if subsubsubinvoiceline.totalBeforeDiscount(false) != 0 %}{# set the discount percentage  = (discount amount / total before discount) * 100 #}{% set net = subsubsubinvoiceline.nonBundleTotalDiscount(false) + subsubsubinvoiceline.total(false) %}{% set discountPercent = (( subsubsubinvoiceline.nonBundleTotalDiscount(false) / net ) * 100) %}{# else in the cases where the cost is 0 but the total is not 0 then it sets the discount to 100% #}{% else %}{% set discountPercent = 100.00 %}{% endif %}{# else is there is no discount or a surcharge then set it to 0 #}{% else %}{% set discountPercent = 0.00 %}{% endif %}{# --- END OF DISCOUNT PERCENTAGE CLUSTER --- #}{% endif %}{# hiddenProductGroup must be set to match product group name in the template settings above #}{% if subsubsubinvoiceline.product.financialProductGroup.name|lower != hiddenProductGroup %}
		<tr>{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td class="subline">{#  Date column is empty for sublines #}</td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td class="subline">{{ subsubsubinvoiceline.productCode }}</td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td class="subline" style="padding-left:60px">{# Uses line description if it does not match product printable name #}{% if ( subsubsubinvoiceline.product.printablename != subsubsubinvoiceline.name ) and ( subsubsubinvoiceline.name != "" ) %}{{ subsubsubinvoiceline.name }} {% else %} {{ subsubsubinvoiceline.product.printablename }} {% endif %} {# showBatchBelowInvoiceLine must be set to true to print in the template settings above #} {% if showBatchBelowInvoiceLine|lower == 'true' %} {% if subsubsubinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subsubsubinvoiceline.serialAndExpiry }} {% elseif subsubsubinvoiceline.lineType == 'header-serviced' %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ subsubsubsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %} {% endif %} {# showCommentBelowInvoiceLine must be set to true to print in the template settings above #} {% if showCommentBelowInvoiceLine|lower == 'true' %} {% if subsubsubinvoiceline.reference %}<br />
			<em>Comment: {{ subsubsubinvoiceline.reference }}</em> {% endif %} {% endif %}</td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="subline">{% if subsubsubinvoiceline.hasSerialNumbers %}{{ subsubsubinvoiceline.serialAndExpiry }} {% elseif subsubsubinvoiceline.lineType == 'header-serviced' %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.hasSerialNumbers %} {{ subsubsubsubinvoiceline.serialAndExpiry }} {% endif %} {% endfor %} {% endif %}</td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td class="subline">{#  Staff member is empty for sublines #}</td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if header is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{{ costpriceexcludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with sub-header line will not show if header is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{{ costpriceincludingtax|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="subline">{{ subsubsubinvoiceline.quantity }}</td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discounts are present #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{# Shows if subinvoice line has a discount #}{% if subsubsubinvoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subsubsubinvoiceline.nonBundleTotalDiscount(false) + subsubsubinvoiceline.total(false))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{# Shows if subinvoice line has a discount #}{% if subsubsubinvoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (subsubsubinvoiceline.nonBundleTotalDiscount(true) + subsubsubinvoiceline.total(true))|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if header is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subsubsubinvoiceline.nonBundleTotalDiscount > 0 %}{{ subsubsubinvoiceline.nonBundleTotalDiscount(false)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if header is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if subsubsubinvoiceline.nonBundleTotalDiscount > 0 %}{{ subsubsubinvoiceline.nonBundleTotalDiscount(true)|moneyformat }} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{# Shows if invoice line has a discount #}{% if discountPercent > 0 %}{# Discount percent set to round to 1 decimal to avoid discrepencies with UI when using more than 1 decimal point #}{{ discountPercent|round(1)}}% {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{% endif %}{% if showTax|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{{ subsubsubinvoiceline.totalGst|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="subline">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{% set primary_tax = subsubsubinvoiceline.getTaxRate %}{% if primary_tax %}{{ primary_tax }}% {% else %} {% set taxes = "" %} {# ----------------- Level 1: subsubsubsubinvoiceline check ----------------- #} {% if subsubsubinvoiceline.nestedLines is defined %} {% for subsubsubsubinvoiceline in subsubsubinvoiceline.nestedLines %} {% if subsubsubsubinvoiceline.getTaxRate is defined %} {% set rate = subsubsubsubinvoiceline.getTaxRate %} {% if rate != "" %} {% set check = ", " ~ rate ~ "," %} {% set full_list = ", " ~ taxes ~ "," %} {% if check not in full_list %} {% if taxes == "" %} {% set taxes = rate %} {% else %} {% set taxes = taxes ~ ", " ~ rate %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% if taxes != "" %} {{ taxes }}% {% else %} 0% {% endif %} {% endif %} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{{ subsubsubinvoiceline.total(false)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="subline" style="text-align:right">{% if subsubinvoiceline.printContainedPrices %}{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{% if not subsubsubinvoiceline.printContainedPrices %}{{ subsubsubinvoiceline.total(true)|moneyformat }} {% endif %} {% endif %}</td>
			{% endif %}
		</tr>
		{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{# --- End of subsubsubinvoice line generation --- #}{# --- Start of invoice line generation if NOT a header line (i.e. NOT bundle or item with a service fee) --- #}{% elseif not invoiceline.hasHeaderLine %}{# Excludes invoice line if reverse balance charge #}{% if invoiceline.product.getCode != 'REVERSE' %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}{# --- START OF COST PRICE EXCLUDING TAX CLUSTER --- #}{# if positive value for quantity #}{% if invoiceline.quantity > 0 %}{% set costpriceexcludingtax = invoiceline.totalBeforeDiscount(false) / invoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif invoiceline.quantity == 0 %}{% set costpriceexcludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceexcludingtax = invoiceline.totalBeforeDiscount(false) / (invoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE EXCLUDING TAX CLUSTER --- #}{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}{# --- START OF COST PRICE INCLUDING TAX CLUSTER --- #}{# if positive value for quantity #}{% if invoiceline.quantity > 0 %}{% set costpriceincludingtax = invoiceline.totalBeforeDiscount(true) / invoiceline.quantity %}{# if conversions mess up and set qty to 0 then this is a failsafe #}{% elseif invoiceline.quantity == 0 %}{% set costpriceincludingtax = 0 %}{# if the quanitity is negative #}{% else %}{% set costpriceincludingtax = invoiceline.totalBeforeDiscount(true) / (invoiceline.quantity*-1) %}{% endif %}{# --- END OF COST PRICE INCLUDING CLUSTER --- #}{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}{# --- START OF DISCOUNT PERCENTAGE CLUSTER --- #}{# Calculates discount percentage based on nonBundleTotalDiscount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# if the cost price is not 0 #}{% if invoiceline.totalBeforeDiscount(false) != 0 %}{# set the discount percentage  = (discount amount / total before discount) * 100 #}{% set net = invoiceline.nonBundleTotalDiscount(false) + invoiceline.total(false) %}{% set discountPercent = (( invoiceline.nonBundleTotalDiscount(false) / net ) * 100) %}{# else in the cases where the cost is 0 but the total is not 0 then it sets the discount to 100% #}{% else %}{% set discountPercent = 100.00 %}{% endif %}{# else is there is no discount or a surcharge then set it to 0 #}{% else %}{% set discountPercent = 0.00 %}{% endif %}{# --- END OF DISCOUNT PERCENTAGE CLUSTER --- #}{% endif %}{# hiddenProductGroup must be set to match product group name in the template settings above #}{% if subsubsubinvoiceline.product.financialProductGroup.name|lower != hiddenProductGroup %}
		<tr>{# showLineDate must be set to true to print in the template settings above #}{% if showLineDate|lower == 'true' %}
			<td>{{ invoiceline.date|dateformat }}</td>
			{% endif %}{# showProductCode must be set to true to print in the template settings above #}{% if showProductCode|lower == 'true' %}
			<td>{{ invoiceline.productCode }}</td>
			{% endif %}{# showProductName must be set to true to print in the template settings above #}{% if showProductName|lower == 'true' %}
			<td>{# Uses invoice line description if it does not match product printable name #}{% if ( invoiceline.product.printablename != invoiceline.name ) and ( invoiceline.name != "" ) %}{{ invoiceline.name }} {% else %} {{ invoiceline.product.printablename }} {% endif %} {# showBatchBelowInvoiceLine must be set to true to print in the template settings above #} {% if showBatchBelowInvoiceLine|lower == 'true' %} {% if invoiceline.hasSerialNumbers %}<br />
			<strong>Batch:</strong> {{ invoiceline.serialAndExpiry }} {% endif %} {% endif %} {# showCommentBelowInvoiceLine must be set to true to print in the template settings above #} {% if showCommentBelowInvoiceLine|lower == 'true' %} {% if invoiceline.reference %}<br />
			<em>Comment: {{ invoiceline.reference }}</em> {% endif %} {% endif %}</td>
			{% endif %}{# showBatchAndExpiry must be set to true to print in the template settings above #}{% if showBatchAndExpiry|lower == 'true' %}
			<td class="line">{% if invoiceline.hasSerialNumbers %}{{ invoiceline.serialAndExpiry }} {% endif %}</td>
			{% endif %}{# showStaffMember must be set to true to print in the template settings above #}{% if showStaffMember|lower == 'true' %}
			<td>{{ invoiceline.salesPerson.name }}</td>
			{% endif %}{# showUnitPriceExcludingTax must be set to true to print in the template settings above #}{% if showUnitPriceExcludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{{ costpriceexcludingtax|moneyformat }}</td>
			{% endif %}{# showUnitPriceIncludingTax must be set to true to print in the template settings above #}{% if showUnitPriceIncludingTax|lower == 'true' %}
			<td class="line">{# Prices associated with header line will not show if bundle is set to print contained prices instead #}{{ costpriceincludingtax|moneyformat }}</td>
			{% endif %}{# showQuantity must be set to true to print in the template settings above #}{% if showQuantity|lower == 'true' %}
			<td class="line">{{ invoiceline.quantity }}</td>
			{% endif %}{# Will only print total before discount, discount amount and discount percentage if non-bundle discounts are present #}{% if totalDiscount > 0 %}{# showTotalBeforeDiscountExcludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountExcludingTax|lower == 'true' %}
			<td class="line">{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (invoiceline.nonBundleTotalDiscount(false) + invoiceline.total(false))|moneyformat }} {% endif %}</td>
			{% endif %}{# showTotalBeforeDiscountIncludingTax must be set to true to print in the template settings above #}{% if showTotalBeforeDiscountIncludingTax|lower == 'true' %}
			<td class="line">{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{# Shows correct net total even when it is a fixed price bundle #}{{ (invoiceline.nonBundleTotalDiscount(true) + invoiceline.total(true))|moneyformat }} {% endif %}</td>
			{% endif %}{# showDiscountExcludingTax must be set to true to print in the template settings above #}{% if showDiscountExcludingTax|lower == 'true' %}
			<td class="line">{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{{ invoiceline.nonBundleTotalDiscount(false)|moneyformat }} {% endif %}</td>
			{% endif %}{# showDiscountIncludingTax must be set to true to print in the template settings above #}{% if showDiscountIncludingTax|lower == 'true' %}
			<td class="line">{# Shows if invoice line has a discount #}{% if invoiceline.nonBundleTotalDiscount > 0 %}{{ invoiceline.nonBundleTotalDiscount(true)|moneyformat }} {% endif %}</td>
			{% endif %}{# showDiscountPercentage must be set to true to print in the template settings above #}{% if showDiscountPercentage|lower == 'true' %}
			<td class="line">{# Shows if invoice line has a discount #}{% if discountPercent > 0 %}{# Discount percent set to round to 1 decimal to avoid discrepencies with UI when using more than 1 decimal point #}{{ discountPercent|round(1)}}% {% endif %}</td>
			{% endif %}{% endif %}{% if showTax|lower == 'true' %}
			<td class="line">{{ invoiceline.totalGst|moneyformat }}</td>
			{% endif %}{# showTaxPercentage must be set to true to print in the template settings above #}{% if showTaxPercentage|lower == 'true' %}
			<td class="line">{{ invoiceline.getTaxRate }}%</td>
			{% endif %}{# showTotalExcludingTax must be set to true to print in the template settings above #}{% if showTotalExcludingTax|lower == 'true' %}
			<td class="line" style="text-align:right">{{ invoiceline.total(false)|moneyformat }}</td>
			{% endif %}{# showTotalIncludingTax must be set to true to print in the template settings above #}{% if showTotalIncludingTax|lower == 'true' %}
			<td class="line" style="text-align:right">{{ invoiceline.total(true)|moneyformat }}</td>
			{% endif %}
		</tr>
		{% endif %}{% endif %}{% endif %}{% endfor %}{# --- End of invoice line generation if NOT a header line (i.e. NOT bundle or item with a service fee) --- #}
	</tbody>
</table>
{# --- END OF INVOICE BODY TABLE --- #}{# --- START OF TABLE THAT HOUSES ALL INVOICE TOTAL TABLES --- #}

<table style="width:100%">
	<tbody>
		<tr>{# showVATRateTotalTable must be set to true to print in the template settings above #}{% if showVATRateTotalTable|lower == 'true' %}
			<td style="vertical-align:top">{# --- START OF TAX RATE TOTAL BREAKDOWN TABLE --- #}
			<table border="0" cellpadding="0" cellspacing="5" style="margin-right:auto; width:300px">
				<tbody class="summary">
					<tr>
						<td style="width:150px"><strong>TAX Code Breakdown</strong></td>
						<td style="text-align:right; width:50px"><strong>Net</strong></td>
						<td style="text-align:right; width:50px"><strong>TAX</strong></td>
						<td style="text-align:right; width:50px"><strong>Gross</strong></td>
					</tr>
					{% if nonReversalNetTotalSRate != 0 %}
					<tr>
						<td>Standard Rate 20%</td>
						<td style="text-align:right">{{ nonReversalNetTotalSRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalTaxTotalSRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalGrossTotalSRate|moneyformat }}</td>
					</tr>
					{% endif %}{% if nonReversalNetTotalRRate != 0 %}
					<tr>
						<td>Reduced Rate 5%</td>
						<td style="text-align:right">{{ nonReversalNetTotalRRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalTaxTotalRRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalGrossTotalRRate|moneyformat }}</td>
					</tr>
					{% endif %}{% if nonReversalNetTotalZRate != 0 %}
					<tr>
						<td>Zero Rate 0%</td>
						<td style="text-align:right">{{ nonReversalNetTotalZRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalTaxTotalZRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalGrossTotalZRate|moneyformat }}</td>
					</tr>
					{% endif %}{% if nonReversalNetTotalXRate != 0 %}
					<tr>
						<td>Exempt Rate 0%</td>
						<td style="text-align:right">{{ nonReversalNetTotalXRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalTaxTotalXRate|moneyformat }}</td>
						<td style="text-align:right">{{ nonReversalGrossTotalXRate|moneyformat }}</td>
					</tr>
					{% endif %}
				</tbody>
			</table>
			</td>
			{% endif %}
			<td style="text-align:right">{# START OF INVOICE TOTALS TABLE #}
			<table border="0" cellpadding="0" cellspacing="5" style="margin-left:auto; width:350px">
				<tbody class="summary">{# Total discount and total before discount rows will only generate if non-bundle discounts are present on invoice #}{% if totalDiscount > 0 %}{# showSummaryTotalBeforeDiscount must be set to true to print in the template settings above #}{% if showSummaryTotalBeforeDiscount|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTotalBeforeDiscountLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ ( ( nonReversalTotal - taxTotal ) + totalDiscount )|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryTotalDiscount must be set to true to print in the template settings above #}{% if showSummaryTotalDiscount|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTotalDiscountLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px">{# Total discount sign is reversed to show deduction #}<strong>{{ (totalDiscount*-1)|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryTotalDiscountWithTax must be set to true to print in the template settings above #}{% if showSummaryTotalDiscountWithTax|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTotalDiscountWithTaxLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px">{# Total discount sign is reversed to show deduction #}<strong>{{ (totalDiscountWithTax*-1)|moneyformat }}</strong></td>
					</tr>
					{% endif %}{% endif %}{# showSummaryTotalAfterDiscount must be set to true to print in the template settings above #}{% if showSummaryTotalAfterDiscount|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTotalAfterDiscountLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ ( nonReversalTotal - taxTotal )|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryTotalAfterDiscountWithTax must be set to true to print in the template settings above #}{% if showSummaryTotalAfterDiscountWithTax|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTotalAfterDiscountWithTaxLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ ( nonReversalTotal - totalDiscountWithTax )|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryTaxTotal must be set to true to print in the template settings above #}{% if showSummaryTaxTotal|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryTaxTotalLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ taxTotal|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryCompositeTaxTotal must be set to true to print in the template settings above #}{% if showSummaryCompositeTaxTotal|lower == 'true' %}{# START OF BREAKDOWN INTO INDIVIDUAL TAX CODES CLUSTER #}{# Checks if tax breakdown exists #}{% if invoice.taxBreakDownString != "" %}{# Creates an adjustable variable to continue storing the string after edits #}{% set taxBreakDownString = invoice.taxBreakDownString %}{# Creates an output array to store keys of tax rates vs amounts #}{% set outputTaxArray = [] %}{# Creates an array to iterate through #}{% set taxArray = taxBreakDownString|split('\n') %}{% for taxType in taxArray %}{# Split from key vs value using : as the delimiter #}{% set splitTaxNameType = taxType|split(':') %}{# Creates a key for the outputArray #}{% set taxName = splitTaxNameType[0] %}{# Creates a value for the output array #}{% set taxAmount = splitTaxNameType[1] %}{# Imports into the output tax array #}{% set outputTaxArray = outputTaxArray|merge({(taxName):taxAmount}) %}{% endfor %}{% endif %}{# END OF BREAKDOWN INTO INDIVIDUAL TAX CODES CLUSTER #}{% if taxTotal > 0 %}{% for tax, value in outputTaxArray %}{# Excludes tax rates if composite (as individual tax rates will be printed) and if Exempt or Zero-rated #}{% if "Composite" not in tax %}{% if "Exempt Supplies" not in tax %}{% if "Zero-rated Supplies" not in tax %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{tax}}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{value|moneyformat}}</strong></td>
					</tr>
					{% endif %}{% endif %}{% endif %}{% endfor %}{% endif %}{% endif %}{# showSummaryFinalTotal must be set to true to print in the template settings above #}{% if showSummaryFinalTotal|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryFinalTotalLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ nonReversalTotal|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryPaidAmount must be set to true to print in the template settings above #}{% if showSummaryPaidAmount|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryPaidAmountLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ invoice.paid|moneyformat }}</strong></td>
					</tr>
					{% endif %}{% set balance = nonReversalTotal - invoice.paid %}{# showSummaryInvoiceBalance must be set to true to print in the template settings above #}{% if showSummaryInvoiceBalance|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryInvoiceBalanceLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ invoice.paid|moneyformat }}</strong></td>
					</tr>
					{% endif %}{# showSummaryClientBalance must be set to true to print in the template settings above #}{% if showSummaryClientBalance|lower == 'true' %}
					<tr>
						<td style="text-align:right; width:250px"><strong>{{ SummaryClientBalanceLabel }}:</strong></td>
						<td style="padding-right:15px; text-align:right; width:100px"><strong>{{ invoice.contact.balanceAt|moneyformat }}</strong></td>
					</tr>
					{% endif %}
				</tbody>
			</table>
			{#  --- END OF INVOICE TOTAL SUMMARY TABLES ---  #}{# showshowPaymentMethods must be set to true to print in the template settings above #}{% if showPaymentMethods|lower == 'true' %}{# --- START OF PAYMENT METHOD FILTER AND TABLE --- #}{% if invoice.paymentMethods %}{# 0.   - 'invoice.paymentMethods' is a single string that contains all payment methods and their amounts in one line.
        - Example: "Cheque : 100.00 Eftpos/Visa/Mastercard : 50.00 Direct Credit : 25.00"
        - Currency symbols are missing.
        #}{# 1.   - replaces " : " with " : £".
        #}{% set paymentMethodsWithCurrency = invoice.paymentMethods
        |replace({' : ': ' : £'}) %}{# 2.   - removes any leading/trailing whitespace so we don't get odd empty pieces.
                - split('.'): cuts the string on every dot character ".".
                - Example: "Cheque : £100.00 Eftpos ..."  becomes  ["Cheque : £100", "00 Eftpos ..."]
                - IMPORTANT: This is to rebuild the text and decide when to insert breaks.
        #}{% set s = paymentMethodsWithCurrency|trim %}{% set parts = s|split('.') %}{# 3.   - Initialises the output with everything BEFORE the first dot.
                - parts[0] is the text up to (but not including) the first dot.
        #}{% set out = parts[0] %}{# 4.   - parts|slice(1) skips the first element and gives us only the segments that come AFTER a dot.
                - Each of these segments begins with whatever came right after the dot.
                - For amounts like "100.00", a segment will start with "00" (the decimals), then a space, then the next label (e.g., " Eftpos/Visa/Mastercard : £50.00 ...").
        #}{% for seg in parts|slice(1) %}{# 5.   - Takes the first two characters of the segment (potentially the decimals), and the rest of the segment after those two characters.
                - Example:
                    seg = "00 Eftpos/Visa/Mastercard : £50.00 ..."
                    first2 = "00"
                    rest   = " Eftpos/Visa/Mastercard : £50.00 ..."
        #}{% set first2 = seg|slice(0, 2) %}{% set rest   = seg|slice(2) %}{# 6.   - Inserts a newline (line break) right after the two decimal digits IF
                    A) There is a third character after the dot (i.e., 'rest' is NOT empty.)
                    B) The two characters after the dot are digits (0-9)
                - Reason:
                    A) Ensures a trailing break is not added at the very end (e.g., "... £100.00" with nothing following it.)
                    B) Ensures breaks are only inserted after decimal places, not after arbitrary dots.
        #}{% if rest is not empty and first2 matches '/^\\d{2}$/' %}{# 7.   - When hitting ".<two digits><there is more>", a newline is inserted AFTER the two digits.
                - This puta back the dot, then the two digits, then '\n', then the remainder.
                - Example:
                    Before: "... £100" + "." + "00 Eftpos..."
                    After:  "... £100.00\n Eftpos..."
        #}{% set out = out ~ '.' ~ first2 ~ '\n' ~ rest %}{% else %}{# 8.   - When NOT at a decimal + a following label, it will just put the dot and the whole segment back unchanged.
        #}{% set out = out ~ '.' ~ seg %}{% endif %}{% endfor %}{# 9.   - 'out' now contains newline characters ('\n') where we want line breaks.
                - Variable is then set for rendering.
        #}{% set paymentMethodsWithBreaks = out %}{# 10.  - {{ paymentMethodsWithBreaks|nl2br }}
                - '|nl2br' converts newline characters ('\n') into <br> so they render as line breaks in the template output.
                - This also escapes the text by default, so this is safe for HTML output.
        #}

			<table border="0" cellpadding="0" cellspacing="5" style="margin-left:auto; width:350px">
				<tbody class="summary">{% if 'Invoice' in invoice.paymentMethods %}
					<tr>
						<td style="text-align:right; width:150px"><strong>Payment Method(s):</strong></td>
						<td style="padding-right:15px; text-align:right; width:200px">{{ paymentMethodsWithBreaks|nl2br }}</td>
					</tr>
					{% else %}
					<tr>
						<td style="text-align:right; width:200px"><strong>Payment Method(s):</strong></td>
						<td style="padding-right:15px; text-align:right; width:150px">{{ paymentMethodsWithBreaks|nl2br }}</td>
					</tr>
					{% endif %}{% endif %}
				</tbody>
			</table>
			{% endif %}{# --- END OF PAYMENT METHOD FILTER AND TABLE --- #}</td>
		</tr>
	</tbody>
</table>
{#  --- END OF TABLE THAT HOUSES ALL INVOICE TOTAL TABLE ---  #}{# showNextAppointment must be set to true to print in the template settings above #}{% if showNextAppointment|lower == 'true' %}{# --- START OF NEXT APPOINTMENT CHECK --- #}{% if invoice.animal and not invoice.animal.isDead %}{% if invoice.animal.NextAppointmentStartTime %}

<p style="font-size:12px; text-align:center;">{{ invoice.animal.name }}&#39;s next visit with us is on <strong>{{ invoice.animal.NextAppointmentStartTime|date("l M d Y") }} at {{ invoice.animal.NextAppointmentStartTime|date("h:i a") }}</strong></p>
{% endif %}{% endif %}{# --- END OF NEXT APPOINTMENT CHECK --- #}{% endif %}{# showInvoiceComment must be set to true to print in the template settings above #}{% if showInvoiceComment|lower == 'true' %}{# --- START OF INVOICE COMMENT CHECK --- #}{% if invoice.getComments %}

<p style="font-size:12px"><strong>Comments</strong><br />
{{ invoice.getComments|nl2br }}</p>
{% endif %}{# --- END OF INVOICE COMMENT CHECK --- #}{% endif %}{# --- START OF PRODUCT NOTE ITEMS SET AGAINST printInvoiceNoteProductGroup --- #}{# --- Sets NOTEQTY to 0 to start count for any invoice products in the group set against printInvoiceNoteProductGroup in settings --- #}{% if printInvoiceNoteProductGroup %}{% set NOTEQTY = 0 %}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{% if invoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides NOTEQTY's value, then 1 adds to it. So, NOTEQTY = NOTEQTY + 1 #}{% set NOTEQTY = NOTEQTY + 1 %}{% endif %}{% if invoiceline.printContained %}{% for subinvoiceline in invoiceline.nestedLines %}{% if subinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides NOTEQTY's value, then 1 adds to it. So, NOTEQTY = NOTEQTY + 1 #}{% set NOTEQTY = NOTEQTY + 1 %}{% endif %}{% if subinvoiceline.isHeaderline %}{% if subinvoiceline.printContained %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if subsubinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides NOTEQTY's value, then 1 adds to it. So, NOTEQTY = NOTEQTY + 1 #}{% set NOTEQTY = NOTEQTY + 1 %}{% endif %}{% if subsubinvoiceline.isHeaderline %}{% if subsubinvoiceline.printContained %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if subsubsubinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides NOTEQTY's value, then 1 adds to it. So, NOTEQTY = NOTEQTY + 1 #}{% set NOTEQTY = NOTEQTY + 1 %}{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{% elseif not invoiceline.hasHeaderLine %}{% if invoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides NOTEQTY's value, then 1 adds to it. So, NOTEQTY = NOTEQTY + 1 #}{% set NOTEQTY = NOTEQTY + 1 %}{% endif %}{% endif %}{% endfor %}{% if NOTEQTY > 0 %}

<table style="width:100%">
	<thead>
		<tr>
			<td style="float:left; height:40px; padding-left:5px; text-align:left"><span style="font-size:14px"><strong>Notes</strong> </span></td>
		</tr>
	</thead>
	<tbody>{# --- Sets ROWNUM to 0 to start count for rows in produced table of invoice comment and product note items --- #}{% set ROWNUM = 0 %}{% for invoiceline in invoice.lineItems %}{% if invoiceline.isHeaderLine and not invoiceline.hasHeaderLine %}{% if invoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides ROWNUM's value, then 1 adds to it. So, ROWNUM = ROWNUM + 1 #}{% set ROWNUM = ROWNUM + 1 %}
		<tr>
			<td>{{ ROWNUM }}. {{ invoiceline.product.getDescription }}</td>
		</tr>
		{% endif %}{% if invoiceline.printContained %}{% for subinvoiceline in invoiceline.nestedLines %}{% if subinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides ROWNUM's value, then 1 adds to it. So, ROWNUM = ROWNUM + 1 #}{% set ROWNUM = ROWNUM + 1 %}
		<tr>
			<td>{{ ROWNUM }}. {{ subinvoiceline.product.getDescription }}</td>
		</tr>
		{% endif %}{% if subinvoiceline.isHeaderline %}{% if subinvoiceline.printContained %}{% for subsubinvoiceline in subinvoiceline.nestedLines %}{% if subsubinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides ROWNUM's value, then 1 adds to it. So, ROWNUM = ROWNUM + 1 #}{% set ROWNUM = ROWNUM + 1 %}
		<tr>
			<td>{{ ROWNUM }}. {{ subsubinvoiceline.product.getDescription }}</td>
		</tr>
		{% endif %}{% if subsubinvoiceline.isHeaderline %}{% if subsubinvoiceline.printContained %}{% for subsubsubinvoiceline in subsubinvoiceline.nestedLines %}{% if subsubsubinvoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides ROWNUM's value, then 1 adds to it. So, ROWNUM = ROWNUM + 1 #}{% set ROWNUM = ROWNUM + 1 %}
		<tr>
			<td>{{ ROWNUM }}. {{ subsubsubinvoiceline.product.getDescription }}</td>
		</tr>
		{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{% endif %}{% endfor %}{% endif %}{% elseif not invoiceline.hasHeaderLine %}{% if invoiceline.product.financialProductGroup.name == printInvoiceNoteProductGroup %}{# Overrides ROWNUM's value, then 1 adds to it. So, ROWNUM = ROWNUM + 1 #}{% set ROWNUM = ROWNUM + 1 %}
		<tr>
			<td>{{ ROWNUM }}. {{ invoiceline.product.getDescription }}</td>
		</tr>
		{% endif %}{% endif %}{% endfor %}
	</tbody>
</table>
{% endif %}{% endif %}{# --- END OF PRODUCT NOTE ITEMS SET AGAINST printInvoiceNoteProductGroup --- #}{# showSOCTable must be set to true to print in the template settings above #}{% if showSOCTable|lower == 'true' %}{# --- STANDARD OF CARE TABLE --- #}{% if invoice.animal and not invoice.animal.isDead %}

<div style="page-break-after: always"><span style="display:none">&nbsp;</span></div>

<div style="margin: 0 40px">
<p style="font-size:16px; text-align:center;"><strong>{{ invoice.animal.name }} is next due for the following services:</strong></p>
{{ invoice.animal.getNextVaccinationsAndTreatmentsTable|raw }}</div>
{% endif %}{% endif %}</div>

This is the source code for the header template for the primary invoice template:

<div style="padding-bottom:50px">
<table align="left" border="0" style="width:100%">
	<tbody>
		<tr>
			<td align="left" style="vertical-align:top">
			<p style="font-size:26px"><strong>{{ invoice.InvoiceTypeName|replace({'TAX INVOICE': 'INVOICE'}) }}</strong></p>
			{#}{#}<br />
			{#}{#}
			<p style="font-size:12px"><strong>{{ invoice.ownershipSeparation.inheritedcontact.name }}</strong></p>

			<p style="font-size:12px">{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getStreet1 %}{{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getStreet1 }}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getStreet2 %}, {{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getStreet2 }}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getSuburb %}, {{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getSuburb}}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getCity %}, {{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getCity }}{% endif %}{#{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getRegion %}, {{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getRegion }}{% endif %}#}{% if invoice.ownershipSeparation.inheritedcontact.physicalAddress.getPostCode %}, {{ invoice.ownershipSeparation.inheritedcontact.physicalAddress.getPostCode}}{% endif %}</p>

			<p style="font-size:12px"><strong>Tel:</strong> {{ invoice.ownershipSeparation.inheritedcontact.phoneNumber }}</p>

			<p style="font-size:12px"><strong>Email:</strong> {{ invoice.ownershipSeparation.inheritedcontact.businessEmail }}</p>

			<p style="font-size:12px"><span style="color:#ffffff"><strong>VAT Registration #:</strong>&nbsp;{{ invoice.ownershipSeparation.inheritedcontact.getTaxNumber }}</span></p>
			{#}{#}<br />
			{#}{#}{#}{#}<br />
			{#}{#}</td>
			<td align="right" style="vertical-align:top"><img alt="LogoWillPrintHere" src="{{ templatesettings.logoLocation }}" style="width:150px" /></td>
		</tr>
	</tbody>
</table>

<table style="width:100%">
	<tbody>
		<tr>
			<td colspan="3" style="font-size:12px; height:30px; text-align:left; vertical-align:top">{{ invoice.InvoiceTypeName|title|replace({'Tax Invoice': 'Invoice'}) }}&nbsp;Number: {{ invoice.getNumber }}<br />
			{{ invoice.InvoiceTypeName|title|replace({'Tax Invoice': 'Invoice'}) }}&nbsp;Date: {{ invoice.Date|dateformat }}{% if invoice.InvoiceTypeName != "CREDIT NOTE" %} <span style="color:#ffffff">| Tax Point: {{ invoice.Date|dateformat }}</span>{% endif %}</td>
			<td colspan="2" style="font-size:12px; height:30px; text-align:right; vertical-align:top"><strong>Account Reference: {{ invoice.contact.getCode }}</strong>{% if invoice.Outstanding > 0 %}<br />
			<strong>Payment Due By: {{ invoice.DueDate|dateformat }}{% endif %}</strong></td>
		</tr>
		{% if invoice.animal %}
		<tr>
			<td colspan="2" style="background-color:#f0f0f0; float:left; height:20px; text-align:left; width:40%"><span style="font-size:12px"><strong>Client</strong> </span></td>
			<td style="float:left; height:20px; text-align:left; width:10%"></td>
			<td colspan="2" style="background-color:#f0f0f0; float:left; height:20px; text-align:left; width:40%"><span style="font-size:12px"><strong>Patient</strong> </span></td>
		</tr>
		{% endif %}
		<tr>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>Name</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{% if contact.TitleName %}{{ invoice.contact.TitleName }} {% endif %}{{ invoice.contact.NameInformal }}</span></td>
			<td style="float:left; height:20px; text-align:left; width:10%"></td>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>{% if invoice.animal %}Name{% endif %}</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.animal.name }}</span></td>
		</tr>
		<tr>
			<td style="float:left; height:20px; text-align:left; vertical-align:top; width:10%"><span style="font-size:12px"><strong>Address</strong></span></td>
			<td style="float:left; height:20px; text-align:left; vertical-align:top; width:30%"><span style="font-size:12px">{% if invoice.contact.postalAddress.getStreet1 %}{{ invoice.contact.postalAddress.getStreet1 }}{% endif %}{% if invoice.contact.postalAddress.getStreet2 %}, {{ invoice.contact.postalAddress.getStreet2 }}{% endif %}{% if invoice.contact.postalAddress.getSuburb %}, {{ invoice.contact.postalAddress.getSuburb}}{% endif %}{% if invoice.contact.postalAddress.getCity %}, {{ invoice.contact.postalAddress.getCity }}{% endif %}{#{% if invoice.contact.postalAddress.getRegion %}, {{ invoice.contact.postalAddress.getRegion }}{% endif %}#}{% if invoice.contact.postalAddress.getPostCode %}, {{ invoice.contact.postalAddress.getPostCode}}{% endif %}</span></td>
			<td style="float:left; height:20px; text-align:left; width:10%"></td>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>{% if invoice.animal.getSpecies.getName %}Species{% endif %}</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.animal.getSpecies.getName }}</span></td>
		</tr>
		<tr>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>Tel.</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.contact.TemplateVarGeneralLandlines }}</span></td>
			<td style="float:left; height:20px; text-align:left; width:10%"></td>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>{% if invoice.animal.getBreed %}Breed{% endif %}</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.animal.getBreed }}</span></td>
		</tr>
		<tr>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>Email</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.contact.TemplateVarGeneralEmails }}</span></td>
			<td style="float:left; height:20px; text-align:left; width:10%"></td>
			<td style="float:left; height:20px; text-align:left; width:10%"><span style="font-size:12px"><strong>{% if invoice.animal.sex %}Sex{% endif %}</strong></span></td>
			<td style="float:left; height:20px; text-align:left; width:30%"><span style="font-size:12px">{{ invoice.animal.sex|sexformat }}</span></td>
		</tr>
	</tbody>
</table>
</div>

This is the source code for the footer for the primary invoice template:

<table border="0" cellpadding="1" cellspacing="1" style="background-color:#f5f5f5; width:100%">
	<tbody>
		<tr>
			<td colspan="2" style="text-align:center; width:100%"><span style="font-size:13px"><strong>Thank you for choosing {{ invoice.ownershipSeparation.inheritedcontact.name }}</strong></span></td>
		</tr>
		{% if invoice.InvoiceTypeName != "CREDIT NOTE" %}
		<tr>
			<td colspan="2" style="text-align:center; width:100%"><span style="font-size:11px">{{ invoice.ownershipSeparation.inheritedcontact.getBankAccountNumber }}{% if invoice.ownershipSeparation.inheritedcontact.getPaymentReference %}<br />
			{{ invoice.ownershipSeparation.inheritedcontact.getPaymentReference }}{% endif %}</span></td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:center; width:100%"><span style="font-size:11px"><strong>When processing your payment please quote your Account Reference which is located at the top of this invoice.</strong></span></td>
		</tr>
		{% endif %}
		<tr>
			<td colspan="2" style="text-align:center; width:100%"><span style="font-size:11px"><em>Registered Office: {% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getStreet1 %}{{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getStreet1 }}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getStreet2 %}, {{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getStreet2 }}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getSuburb %}, {{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getSuburb}}{% endif %}{% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getCity %}, {{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getCity }}{% endif %}{#{% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getRegion %}, {{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getRegion }}{% endif %}#}{% if invoice.ownershipSeparation.inheritedcontact.postalAddress.getPostCode %}, {{ invoice.ownershipSeparation.inheritedcontact.postalAddress.getPostCode}}{% endif %}&nbsp;&bull; {{ invoice.ownershipSeparation.inheritedcontact.phoneNumber }}&nbsp;&bull; {{ invoice.ownershipSeparation.inheritedcontact.businessEmail }}</em></span></td>
		</tr>
		<tr>
			<td style="text-align:center; width:50%"></td>
			<td style="text-align:center; width:50%"></td>
		</tr>
	</tbody>
</table>