Create an ODT or ODS document template: Difference between revisions

Jump to navigation Jump to search
m
retrait d'une accolade en trop
Tag: 2017 source edit
m (retrait d'une accolade en trop)
Line 11: Line 11:
To know how to build a PDF template, see page [[Create a PDF document template]]. Building a PDF template require PHP development knowledge, but not building an ODT template.
To know how to build a PDF template, see page [[Create a PDF document template]]. Building a PDF template require PHP development knowledge, but not building an ODT template.


== Prerequisite ==
==Prerequisite==
* Dolibarr: 3.1+
 
* OpenOffice: 3.2+, LibreOffice, ...
*Dolibarr: 3.1+
*OpenOffice: 3.2+, LibreOffice, ...
 
==Create your document==
 
*Create from scratch an empty OpenOffice document and take a provided example. You may find them installed into a subdirectory of directory '''documents/doctemplates'''
*Edit your document using all your Office suite features.


== Create your document ==
* Create from scratch an empty OpenOffice document and take a provided example. You may find them installed into a subdirectory of directory '''documents/doctemplates'''
* Edit your document using all your Office suite features.
Include in your document the tags you want to see. Tags will be replaced during generation of document automatically by Dolibarr. List of all available tags are provided in next chapter.
Include in your document the tags you want to see. Tags will be replaced during generation of document automatically by Dolibarr. List of all available tags are provided in next chapter.


[[File:Warning.png]] Warning, tags must be rounded with {} or [] for arrays (see later) and must be typed with no stop using Office suite (with no backspace and no copy-paste). If not doing that, Office suite adds some invisible information makes detection/replacement impossible.
[[File:Warning.png]] Warning, tags must be rounded with {} or [] for arrays (see later) and must be typed with no stop using Office suite (with no backspace and no copy-paste). If not doing that, Office suite adds some invisible information makes detection/replacement impossible.


== Tags ==
==Tags==
This is a list of tags that will be replaced with your informations:
This is a list of tags that will be replaced with your informations:


Line 38: Line 41:
{{TagsOdtUser}}
{{TagsOdtUser}}


=== Other information ===
===Other information===
{{TagsOdtOther}}
{{TagsOdtOther}}


===Object information (invoice, commercial proposal, order, ...) ===
===Object information (invoice, commercial proposal, order, ...)===
{{TagsOdtObjects}}
{{TagsOdtObjects}}


Line 65: Line 68:
[[File:Line for document generation.png|500px]]
[[File:Line for document generation.png|500px]]


=== For project documents ===
===For project documents===
For document about projects and task, you also have
For document about projects and task, you also have
{{TagsOdtProject}}
{{TagsOdtProject}}


=== Conditional substitution ===
===Conditional substitution===


Starting from Dolibarr v3.3, you can use conditional substitutions, which in layman terms means that you can decide to print something if a variable is true, or print something else if it's false (or nothing at all) - including text but also any more complex structures like tables and images.
Starting from Dolibarr v3.3, you can use conditional substitutions, which in layman terms means that you can decide to print something if a variable is true, or print something else if it's false (or nothing at all) - including text but also any more complex structures like tables and images.
Line 84: Line 87:
Note: of course, the ELSE tag and block is optional, you can just use IF/ENDIF if you prefer.
Note: of course, the ELSE tag and block is optional, you can just use IF/ENDIF if you prefer.


* [[File:Warning.png]] Warning: the format of this special tag is very precise and picky, be careful to '''put one space''' between:
*[[File:Warning.png]] Warning: the format of this special tag is very precise and picky, be careful to '''put one space''' between:
** [!--
**[!--
** IF/ELSE/ENDIF
**IF/ELSE/ENDIF
** {my var}
**{my var}
** --]
**--]
* [[File:Warning.png]] Warning: String must be typed with no stop using Office suite (with no backward and no copy-paste). If not doing that, Office suite add some invisible information making detection/replacement of text not possible.
*[[File:Warning.png]] Warning: String must be typed with no stop using Office suite (with no backward and no copy-paste). If not doing that, Office suite add some invisible information making detection/replacement of text not possible.


=== Other personalized tags ===
===Other personalized tags===
If you want to add a field that is not predefined, this is the solution:
If you want to add a field that is not predefined, this is the solution:
* Create a file into the location:
 
*Create a file into the location:
 
'''htdocs/mymodule/core/substitutions/functions_mymodule.lib.php'''
'''htdocs/mymodule/core/substitutions/functions_mymodule.lib.php'''
* Inside this file, just write one function like this:
 
*Inside this file, just write one function like this:
 
<source lang="php">
<source lang="php">
/** Function called to complete substitution array (before generating on ODT, or a personalized email)
/** Function called to complete substitution array (before generating on ODT, or a personalized email)
Line 120: Line 127:


To have your substitution function be called,  if you have to :
To have your substitution function be called,  if you have to :
* Check your substitution file is inside subdirectory module called htdocs/mymodule/core/substitutions.
 
* Build your own module (See page [[Module development]]) with its descriptor file.
*Check your substitution file is inside subdirectory module called htdocs/mymodule/core/substitutions.
* Check your module descriptor file contains an entry to declare this module has a substitutions file
*Build your own module (See page [[Module development]]) with its descriptor file.
*Check your module descriptor file contains an entry to declare this module has a substitutions file
 
<source lang="php">
<source lang="php">
$this->module_parts = array('substitutions' => 1)  
$this->module_parts = array('substitutions' => 1)  
</source>
</source>
* Enable your module (module must be enabled and disabled each time you change the descriptor).
 
*Enable your module (module must be enabled and disabled each time you change the descriptor).


Note2: this only allows to define global, static ODT variables (ie: to make dynamic variables that changes for every line of product, please see the next chapter).
Note2: this only allows to define global, static ODT variables (ie: to make dynamic variables that changes for every line of product, please see the next chapter).


=== Other personalized tags for lines ===
===Other personalized tags for lines===


This function is available since Dolibarr v3.3 (future development version).
This function is available since Dolibarr v3.3 (future development version).
Line 136: Line 146:
Similarly to the previous chapter, you have to define a function, and it works about the same, but with a few twists:
Similarly to the previous chapter, you have to define a function, and it works about the same, but with a few twists:


* Create or edit the same file as before (see the previous chapter).
*Create or edit the same file as before (see the previous chapter).
* Here are the twists: in the file, write another function with almost the same name but with '_lines' appended, and also add a new $lines variable:
*Here are the twists: in the file, write another function with almost the same name but with '_lines' appended, and also add a new $lines variable:
 
<source lang="php">
<source lang="php">
/** Function called to complete substitution array for lines (before generating on ODT, or a personalized email)
/** Function called to complete substitution array for lines (before generating on ODT, or a personalized email)
Line 160: Line 171:
Contrary to the previous function which was called only once, this function will be called everytime a line of product will be processed, giving you each time a new $line object that you can process. This allows you to do different substitutions for each product.
Contrary to the previous function which was called only once, this function will be called everytime a line of product will be processed, giving you each time a new $line object that you can process. This allows you to do different substitutions for each product.


== Store your document ==
==Store your document==
To have your document to appear in list of available documents, put it into correct subdirectory found into
To have your document to appear in list of available documents, put it into correct subdirectory found into
directory '''documents/doctemplates'''
directory '''documents/doctemplates'''

Navigation menu