User's guide /

Document Templates

The OBS ERP document templates module allows you to present information stored in the OBS ERP modules as PDF documents. For example, you can create a custom template for module Finance -> Income that contains a branded invoice aligned with the domestic legislation, or a template for module "Contracts" which holds information about the standard contract you sign with your customers. 

OBS ERP is equipped with a template processing engine. It can convert the template variables to text. Let's take module "Contracts" as an example. You can call a variable inside the template called ~~date_of_issue~~. OBS ERP will convert the variable to the actual date of issue of the contract. This process is described in details below.

Note: The template processing engine is called OB1 and it is developed by OBS ERP

The document templates can be found in module Administration -> Templates -> Docs. OBS ERP comes with a default set of templates for some of the main modules ( Invoices, Quotations, Vacations, etc ). You might want to edit the default templates to suit your needs.

Note: Do not forget to make backup of the original template before making any changes

Let's open one of the most complex default templates - Invoices ( navigate to Administration -> Templates -> Docs -> Edit row 1). The template is shown on Fig. 1

Fig. 1

As you can see, you can set the font type and size, add header and footer to the template and control the paging. The long blue button "Modules" is used to specify which modules will use this template. 

Click the "Content" input field to open the template contents (Fig. 2)

Fig. 2
To change the contents of a template, you must first save your changes and then reload the template. The "Save" and "Reload Templates" buttons are shown on Fig. 2 highlighted in red and blue respectively. To see the end result, you need to open the target module (in this case "Income"), create a record and click on the PDF button above the record. OBS ERP will produce a PDF document using your template. 

Fig. 3

The template processor supports the following features:
  • variables
  • functions
  • text replacement
  • loops
  • conditional evaluation
Show all available variables
Depending on the module you prepare a template for, you will get different set of variables you can use. To check which variables are available you need to write the following function anywhere in the template, click save and reload. 
The result will be visible in the target module as described above. For example:

amount 8700.00
contract_id 2015-09-23 №28 Test Customer
... ....

Now we know the names of the variables. We can display the value of a variable using the following enclosing sequence:
Result (invoice number):
Translate keyword as per the definitions in the "Translations" module:

Enclosing sequence

Create a table with values
  • Table with automatic layout:
    Enclosing sequence:
    ~#table_name^table #~​

    # name qty price
    1 Test 1 100

    You can skip a column by adding the skip keyword as shown below:
    ~#invoice_items^table; skip:photo; #~ ( this will skip the photo column )
    *photo is the Translation key value of the DB column photo 
  • Table with custom columns
    Enclosing tag:
    ~#table_name^table; ~column_one~ ~column_two~ ~column_three~ #~​
    ~#invoice_items^table; ~SEQ~ ~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~#~​

    ~SEQ~ will create a column with sequential numbers, starting from 1.

    # name Quantity Price per unit Discount Total
    1 Test 1 100 1 99
  • Functions
    The data in a column can be passed to a function. For example:

    To show an image inside the table use showImageInTD function:

    ~#quotation_items^table; ~SEQ~ ~.showImageInTD^~product_image~,products,3.5.~ ~price_per_unit~ #~

    Alternatively, you can use any data processing function in the table.
  • Table with custom header.
    This section describes how to create tables with custom header like the one below:

    *    Create a new template holding the custom table header. The name of the template will be used later. For example:
    # Date Principle Monthly installments Taxes and commissions Remaining
    Interest Principle Amount

    *    Generate the table using the following syntax: 
    ~#invoice_items^table_with_custom_header:thead_template;~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~#~​
    * table_with_custom_header - the name of the layout
    * thead_template - the name of the template created as described in point 1
    * ~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~ - the names of the columns. Can be omitted.
Display value in case it exists
Enclosing sequence:
~?variable; ?~​
~?variable; displayed if set ^ displayed if not set ?~​
~?description; This is a description: ~~description~~ ?~​
In case it does not exist:
~?description; This is a description: ^ Text displayed in case description is not set ~~description~~ ?~​

Display variable containing HTML code:
Function: open_template
{{ open_template (index $.MainRecord "comment") }}​

Other example:

~.utranslate^ ~category_id~ .~
~.sum^ ~num1~ 0 .~

Variables are enclosed with ~

Import template
You can import a template into another template using the following syntax:

Where "template_name" is the name of the template you would like to import
Custom logic: You can use the HUGO templating language to implement custom logic in your templates

Data formatting

* Date & time formatting