/
Document Templates
Document Templates
Overview
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 domestic legislation
- A template for module "Contracts" which holds information about the standard contract you sign with your customers
Template Processing Engine
OBS ERP is equipped with a template processing engine called OB1, developed by OBS ERP. It can convert template variables to text. For example:
- In the "Contracts" module, you can use a variable like
~~date_of_issue~~
- OBS ERP will convert this variable to the actual date of issue of the contract
Note: The template processing engine is called OB1 and it is developed by OBS ERP
Accessing Templates
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.).
Note: Do not forget to make a backup of the original template before making any changes
Editing Templates
Let's open one of the most complex default templates - Invoices (navigate to Administration → Templates → Docs → Edit row 1).
Fig. 1: Template editing interface
In the template editor, you can:
- Set the font type and size
- Add header and footer to the template
- Control the paging
- Select the modules where the template will be applied (click on the 'Modules' button in the top left corner)
Editing Template Contents
Click the "Text" input field to open the template contents:
Fig. 2: Template contents editing
To change the contents of a template:
- Make your changes
- Click the "Save" button (highlighted in red in Fig. 2)
- Click the "Reload Templates" button (highlighted in blue in Fig. 2)
To see the end result:
- Open the target module (e.g., "Income")
- Create a record
- Click on the PDF button above the record
Template Processor Features
The template processor supports the following features:
- Variables
- Functions
- Text replacement
- Loops
- Conditional evaluation
Showing Available Variables
To check which variables are available for a specific module:
- Write the following function anywhere in the template:
~.show_vars.~
- Click save and reload
- The result will be visible in the target module, for example:
VAR | VALUE |
---|---|
amount | 8700.00 |
contract_id | 2015-09-23 №28 Test Customer |
Using Variables
To display the value of a variable, use the following enclosing sequence:
~~variable~~
Creating Tables with Values
Enclosing sequence for an auto-layout table:
~#table_name^table #~
Custom Header Tables
Create tables with a custom header layout:
~#table_name^table_with_custom_header:thead_template;~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~#~
Conditional Evaluation
To display a value conditionally, you can use the following syntax:
~?variable; ?~
Or, to display a specific message if the variable is set and an alternative message if it is not set:
~?variable; displayed if set ^ displayed if not set ?~
Example:
~?description; This is a description: ~~description~~ ?~
If the description is not set, you can also use:
~?description; This is a description: ^ Text displayed in case description is not set ~~description~~ ?~
Displaying HTML Code
To display a variable containing HTML code, use:
{{ open_template (index $.MainRecord "comment") }}
Importing Templates
Import a template using:
~.import^template_name.~
Date Formatting
Example of date formatting syntax:
~.format_date^~created_at~,2006-01-02.~
Printing Statuses
Print a table with audit trail if status_id
is enabled in the module:
<div class="grid" style="display: grid; width: 100%; grid-template-columns: 33% 33% 33%; column-gap: 0.5rem; row-gap: 0.5rem;"> <div style="font-weight: bold;">~_time_~</div> <div style="font-weight: bold;">~_employee_~</div> <div style="font-weight: bold;">~_status_~</div> {{ range $a, $b := $.Statuses }} <div style="border: solid 1px #ececec;">{{ format_time_to_minute $b.Time }}:</div> <div>{{ $b.Employee }} -></div> <div>{{ $b.Status }}</div> {{ end }} </div>