Navigation:  Printed Document Templates >

Logic and Syntax of Templates

Previous pageReturn to chapter overviewNext page

Variables

All variables and commands can be identified by \ (backslash) symbol in the beginning and in the end. Variables display data, extracted from Projetex database, and relevant to each particular saved document.

Example:

In example below you can see \CLIENT_NAME\, \CLIENT_STREET1\ and \CLIENT_PHONE1\ variables, along with some static text:

To: \CLIENT_NAME\

Address: \CLIENT_STREET1\

Phone: \CLIENT_PHONE1\

When you use this template by clicking on Save or Print in some dialog box, \CLIENT_NAME\ variable will be replaced by name of currently client, valid to this particular document, \CLIENT_STREET1\ — by client’s street address and \CLIENT_PHONE1\ — by client’s phone number. The final output will look like this:

To: XYZ Company

Address: Elm Street, 1

Phone: +1 212 898 11 31

Variables like \INVOICE_CODE\ will display code of currently saved invoice, variables like \INVOICE_DATE\ will display issue date of current invoice, and so on.

 

_bm3 Note: Numerical values sometimes are surrounded by fnum command. This command simply tells the parser to round up the value to specified number of digits after decimal point (2 digits in the example below).

Example:

Job Total: \fnum(dtLinkJobs:TOTAL, 2)\

 

Data Scan commands

Another of RTF templates is Data Scan commands. These are used to create tables in which number of rows is determined by the number of records in database.

1. Begin by entering \scan(dtLinkJobs)\ command. This must not necessarily be dtLinkJobs, depending on the template, this can be:

\scan(dtLinkJobs)\ — in invoices, job assignment and PO templates, to display jobs included in invoice, JA or PO.
\scan(dtLinkInvoices)\ — in payment templates to display invoices linked to the payment.
\scan(dtLinkPayments)\ — in invoice and PO templates to indicate linked sums.

2. Insert table header between \scan(dtLinkJobs)\ and \scanentry\.

3. Insert one row of data-columns after \scanentry\. Every variable in table must be preceded with dtlink command. For instance if the table begins with \scan(dtLinkJobs)\, each variable must have this link included: \dtLinkJobs:JOB_NAME\, \dtLinkJobs:COMPLETED\, and so on.

4. Insert \endscan\ after data-columns.

_bm3 Note: Use noeof to hide table's header and footer if the table body appears to be empty. For instance, if your invoice includes only jobs and no expenses, the header and footer for expenses will not be saved/printed.

Example:

\scan:dtlinkJOBS\

PO No.           Job Name

\scanentry\

\dtlinkJobs:PO\  \dtlinkJobs:JOB_NAME\

\scanfooter\

Jobss Total: \JOBS_TOTAL\

\endscan\

Command \scan(dtLinkJobs)\ will make the parser scan (go from first record to the last one) all selected data in Jobs table (in this particular case all jobs included in the invoice) and output them to file or printer.

Text between \scan(dtLinkJobs)\ command and \scanentry\ command is table header.

Text between \scanfooter\ and \endscan\ commands will be considered table footer and will only be displayed once at the end of this table.

Text between \scanentry\ and \scanfooter\ commands is table "body". It includes variables from columns which must be listed in the table. In example above these are:

\dtLinkJobs:PO\ – PO Number.
\dtLinkJobs:COMPLETED\ – Date of job delivery.
\dtLinkJobs:JOB_NAME\ – Name of the job.
\dtLinkJobs:SERVICE\ – Service provided.

 

Condition checking

This allows the template to react to certain varying conditions and produce output suitable to each of possible conditions. The logic is the following \IF(condition)\ Reaction \ENDIF\.

Example:

If Discount 1 is applied, display discount name, discount value and subtotal. The code is as follows:

\IF(DISCOUNT1)\

\DISCOUNT1NAME\: \DISCOUNT1VALUE\

Subtotal: \AFTERDISCOUNT1\\endif\

This will make the template check if discount 1 is applied, and if so — display data between \IF(...)\ and \ENDIF\ commands.

DISCOUNT1 is a logical variable, i.e. it can have one of two values: either true or false. In this particular case, Projetex sets DISCOUNT1 into true if first discount is present and into false, if there is no first discount.
When \IF(DISCOUNT1)\ is encountered in template, parser checks DISCOUNT1 logical value, and if it is true, runs the code below this command, until \endif\ is encountered, which instructs parser to stop. If DISCOUNT1 is false, everything until \endif\ command is skipped.
In this particular case, without \IF(DISCOUNT1)\ command, the parser would output empty string with: and empty Subtotal: in cases when there would not be discount. But with \IF(DISCOUNT1)\ command, in such cases above block is skipped in its entirety.

 

Arithmetic calculations syntax

Arithmetic can be performed in templates with the following syntax:

\((JOBS_TOTAL+100-10)*10)/2\

The whole expression must be included in backslashes;
All arithmetic operations must be defined by the following symbols + - / *;
The brackets inside backlashes must be positioned by the rules of arithmetic.

 

Logical operations syntax

 

Logical operations: && (and), || (or), ! (not),  can be performed in templates with the following syntax:

 

\IF( (table1:field1>b+1) || (table1:field1=0) )\

............

\ENDIF\