Invoice Template Sample Code

Summary

This article provides sample code which can be used based on the scenarios listed below. These are meant to be examples only and should be customized to reflect the format and data that you wish to show in the invoice. These may be used in conjunction with other XSL code in order to create a complete invoice template. Please refer to the basic invoice template and customize that as needed. Related Link:

For details on customizing templates and advanced configuration help beyond what is provided in this article, please look at these good sites which will provide ways to manipulate data in XSL:

Further references are available by simply 'googling' the question you have or to solve formatting problems.

Package Group

Display Packages without services broken out. Packages will also display the period as shown below in the image.

HTML SECTION

<xsl:apply-templates select="PackageGroup"/>

XSL SECTION

<xsl:template match="PackageGroup"> <xsl:apply-templates select="ItemGroup"/> </xsl:template><xsl:template match="ItemGroup"> <tr> <td colspan="5"></td> </tr> <tr> <td colspan="5"> <span> <h2> Monthly Charges for <xsl:apply-templates select="UserTopParent"/> </h2> </span> </td> </tr> <xsl:if test="count(Item)>0"> <tr> <td colspan="5"> <span> <h3> <xsl:apply-templates select="User"/> </h3> </span> </td> </tr> <tr> <td width="2%"></td> <td width="48%">Package</td> <td width="40%">Period Billed</td> <td width="10%" align="center">Amount</td> </tr> <xsl:apply-templates select="Item"/> </xsl:if> </xsl:template> <xsl:template match="Item"> <xsl:if test="not(Amount = '0.00')"> <tr> <td></td> <td> <b> <xsl:apply-templates select="Detail"/> </b> </td> <xsl:if test="count(CurrentBilldate)>0"> <td> <b> <xsl:apply-templates select="CurrentBilldate"/> - <xsl:apply-templates select="NextBilldate"/> </b> </td> </xsl:if> <xsl:if test="count(CurrentBilldate)=0"> <td> <b> <xsl:apply-templates select="TransactionDate"/> - <xsl:apply-templates select="TransactionDate"/> </b> </td> </xsl:if><td align="center"> <b> <xsl:apply-templates select="Amount"/> </b> </td> </tr> </xsl:if> </xsl:template>

Monthly Recurring Package Grouping Summary

This will provide a breakdown of monthly recurring packages, their quantity on the account and the total charge by package.

HTML SECTION

<xsl:apply-templates select="PackageGroupRecurring"/>

XSL SECTION


Profile Answers for Services

Displays profile answers attached to services that are show on the customer invoice As shown above, we have created the profile question ‘What is your favourite colour?’ on the Dialup Service. Once the XML is in place, we can then show that profile question answer on the invoice, in this case, the answer is ‘RED’ Complete Invoice Template Sample: 



HTML SECTION

XSL SECTION

Show Profile Answers on Roles

Displays answers based on profile questions on roles if the question is answered on the customer account Note: Currently at least one transaction is required to be on the account before this will appear - this will be changed in a future release.

HTML SECTION

XSL SECTION

Invoice Detail

Token in the invoice is 'Extra Detail' - The 'invoice detail' component on packages allows you to insert additional information or notes about a particular package on an invoice. Remember that this is a global setting for anyone who signs up for this package and is not configurable per account. The 'extra detail' token as referred to here displays the 'invoice detail' component data.

HTML SECTION

XSL SECTION

Invoice Identifier

The invoice identifier option allows you to tag packages and/or services with a specific identifier for the purpose of applying formatting to the item on the invoice. For example, if you would like to hide specific services on invoices so that they are not seen by your customers you could create an invoice identifier named HIDE. In your invoice template you would look for any services which have an identifier value of HIDE and then react by not showing them on the invoice. The same could be done to hide services which do not have an amount ($0.00) on invoices, to highlight a particular discount or promotional service with different font formatting than the others listed.

  1. Click Setup tab

  2. Click Invoice Identifiers

  3. Add your invoice identifiers

  4. Click the service you want to identify

  5. Select the identifier from the invoice identifier dropdown menu

  6. Click Save

  7. Once an invoice is generated with that package and service, the tag will appear in the xsl: <ServiceInvoiceIdentifier>HIDE</ServiceInvoiceIdentifier>


HTML SECTION

IF Statements and Logic Within XML

Adding logic within XML for flexibility of data display.
The below code can be used as an example for using IF statements to output the data needed.

Equals Check

Manual Transaction Listing

If you want to display only a list of manual transactions, in the case where you might be using package grouping as well, you can use this code below to show only those manual transactions

HTML SECTION

XSL SECTION


How to Omit Account Detail Rows Where All Transactions are Zero

In the invoice detail, if you have accounts with zero dollar transactions, you can make sure they don’t show up in the detail with this piece of code

Note: the below code as inserted into the 'ItemGroup' element

 

HTML SECTION


Adding XSL Tokens

This allows you to create new tokens if one does not exist, for example when you want to add taxes token with the invoice charges token and display the sum of the two.

Note: When adding variables / tokens, if your format includes commas  (i.e. $1,234.00 as opposed to $1234.00) to delineate thousands for example, you need to first strip the comma out of the token, perform the calculation, then add it back in using the XML formatting of numbers.

HTML SECTION

XSL SECTION

Formatting Token Values

To format the value from tokens to 2 decimal places (ie: $278.00), insert the extra code here within your select tags.
<xsl:copy-of select=”format-number(TokenNamehere,’#,###.00′)”/>

Defining the Sort Order of Your Data

This code provides a way to sort your returned data, ascending, descending, based on a particular column of data

The below is an example and an article link for how you might sort your data. The below example can be found and its detailed here: http://msdn.microsoft.com/en-us/library/ms950734.aspx

Breakout Prorated Charges and Full Period Charges

This allows you to separate out prorated charges and full period charges on the invoice

HTML SECTION

XSL SECTION


Convert Duration to Minutes

This allows you to convert the duration on invoices to minutes

PAID Invoice Stamp

This code allows you to add an image showing that the invoice is PAID already when sending to customers.

Enter the following XLT code your template wherever you would like the PAID stamp to show. Make sure the URL or directory location is accessible to your end user (e.g. a customer portal webserver is a good place to put the image).

Tax Breakout (not per user)

This is a breakout of taxes at the bottom of your invoice. This is not displayed per user.

HTML HEADER

HTML BODY

Tax Breakout PER User

Install before  <xsl:template match="Invoice"> <xsl:key name="keyAccountType" match="Invoice/UserTaxesByDisplayName/UserTax" use="User" />   Install in line of the page structure.

Date Formatting

If you need to format your date, you can use a substring method for example to trim a 4 digit year to a 2 digit year. Because the date is not in a UTC format, you cannot currently use the standard XSL date formatting methods.

Related pages