Creating invoices is certainly one of the most typical applications for TX Text Control. MS Word compatibility, flow type layouts and WYSIWYG template creation are just a few of the wide-ranging advantages over pure reporting tools.
This tutorial shows how to create professional invoices using TX Text Control. You will learn how to create the template using TX Text Control Words and how to use the MailMerge component to create the final invoice.
First, let's take a look at the data structure for invoices. Typically, invoice data come from different database tables. The sender is coming from a different table than the addressee. Invoice items are typically loaded from an article database. The following tables are usually required to create an invoice.
Creating the template
For this tutorial, we prepared a ready-to-use invoice template you can use, modify or redesign for your purposes. Refer to the documentation to learn how to use TX Text Control Words to create a template from scratch.
The template consists of different parts with dynamic fields, repeating blocks and special fields such as a field to display the current date.
All merge fields from the listed data tables are used and have been added to the above template. The green areas are repeating blocks that will be merged with a list of invoice items and taxes.
Preparing the Data
In invoicing modules of ERP systems, the complete invoice is stored in database tables. The resulting PDF or the printout is a specific view of this invoice. The pure invoice data is used for further processing inside the ERP system. This data gathering process is always different and depends on the used databases and the .NET data layer (e.g. ADO.NET).
In our sample, we are using an already merged DataSet in form of an XML file that could have been generated as a database view for real-live scenarios as well.
Merging the Document As Easy As 1-2-3
All you need to do is to connect a TextControl with the MailMerge component in order to load the template:
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings(); ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord; mailMerge1.TextComponent = textControl1; textControl1.Load("invoice.docx", TXTextControl.StreamType.WordprocessingML, ls);
The following code lines are required to merge the document:
DataSet ds = new DataSet(); ds.ReadXml("invoice.xml"); mailMerge1.MergeBlocks(ds); mailMerge1.Merge(ds.Tables["invoice"], false);
TX Text Control is looking for the appropriate merge fields in the data automatically in order to merge the fields. The repeating blocks are recognized and merged with the associated DataTables.
How to Use the Sample?
Download the Visual Studio 2010 project
Download and open the project in Visual Studio 2010. At least, a TX Text Control .NET for Windows Forms trial version is required.
Start the application
The template is loaded automatically. You can see different text fields that are not merged yet.
Choose Create from the Invoice menu to start the merge process
The data is merged into the text fields. Pay attention to the invoice items that are part of a repeating block. These item lines are repeated based on the number of invoice items passed in the data.
As you can see, creating invoices using TX Text Control is a very easy task and has advantages over pure reporting tools. You can easily change your templates in a true WYSIWYG editor or reuse MS Word documents to create your templates.