31,034
edits
(copy from english article) |
mNo edit summary Tag: 2017 source edit |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{TemplateDocUser}} | |||
Auf dieser Seite wird beschrieben, wie Sie eine ODT-Dokumentenvorlage erstellen, um eigene Dokumente mithilfe der ODT Generierung zu erstellen. | |||
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 == | |||
* 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. | |||
Dolibarr: 3.1+ | |||
OpenOffice: 3.2+, LibreOffice, ... | |||
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. | ||
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 == | |||
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: | ||
===Company/foundation information=== | |||
{ | {{TagsOdtMyCompany}} | ||
{ | |||
===Customers, prospects or suppliers information=== | |||
{{TagsOdtThirdParty}} | |||
{ | |||
{ | |||
===User information=== | |||
{{TagsOdtUser}} | |||
{ | |||
{ | |||
=== Other information === | |||
{{TagsOdtOther}} | |||
{ | |||
{ | |||
===Object information (invoice, commercial proposal, order, ...) === | |||
{ | {{TagsOdtObjects}} | ||
===Lines of object=== | |||
This is how to use arrays for lines of objects (invoices, commercial proposal, orders, etc...). You must create your array in the document and use a begin and end tag to define a line of the array. The line will then be repeated as much as required during generation. | This is how to use arrays for lines of objects (invoices, commercial proposal, orders, etc...). You must create your array in the document and use a begin and end tag to define a line of the array. The line will then be repeated as much as required during generation. | ||
<pre> | |||
[!-- BEGIN row.lines --] | [!-- BEGIN row.lines --] | ||
... | ... | ||
[!-- END row.lines --] | [!-- END row.lines --] | ||
</pre> | |||
If you want to display it not in tables row but in block lines : | If you want to display it not in tables row but in block lines : | ||
<pre> | |||
[!-- BEGIN lines --] | [!-- BEGIN lines --] | ||
... | ... | ||
[!-- END lines --] | [!-- END lines --] | ||
</pre> | |||
Then, you can use following tags into your line: | Then, you can use following tags into your line: | ||
{{TagsOdtLines}} | |||
This an example of what you may have in your office suite: | |||
[[File:Line for document generation.png|500px]] | |||
=== For project documents === | |||
{ | For document about projects and task, you also have | ||
{{TagsOdtProject}} | |||
=== 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. | ||
Example: | Example: | ||
<pre> | |||
[!-- IF {my_var} --] | [!-- IF {my_var} --] | ||
Print this text if {my_var} is true (can be any value but null/0/empty string) | Print this text if {my_var} is true (can be any value but null/0/empty string) | ||
| Line 221: | Line 70: | ||
Or print this if it's false (null/0/empty string) | Or print this if it's false (null/0/empty string) | ||
[!-- ENDIF {my_var} --] | [!-- ENDIF {my_var} --] | ||
</pre> | |||
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. | ||
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} | ||
--] | ** --] | ||
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 === | |||
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: | ||
<syntaxhighlight lang="PHP"> | |||
Inside this file, just write one function like this: | |||
/** 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) | ||
* functions xxx_completesubstitutionarray are called by make_substitutions() if file | * functions xxx_completesubstitutionarray are called by make_substitutions() if file | ||
| Line 248: | Line 99: | ||
{ | { | ||
global $conf,$db; | global $conf,$db; | ||
$myvalue='Put here calculated value to insert'; | $myvalue='Put here calculated value to insert'; | ||
$substitutionarray['myowntag']=$myvalue; | $substitutionarray['myowntag']=$myvalue; | ||
} | } | ||
Function will be called before generating document to complete the array used for substitution and to replace tag myowntag with value $myvalue. You can add as many tags as you need and put all personalized code you want to define values (search into database, into files, calculation, from received parameters or from global variables)... | </syntaxhighlight> | ||
Function will be called before generating document to complete the array used for substitution and to replace tag myowntag with value $myvalue. You can add as many tags as you need and put all personalized code you want to define values (search into database, into files, calculation, from received parameters or from global variables)... | |||
Warning: First parameter in function parameter declaration must start with & as value is modified by your code and must be returned modified. | Warning: First parameter in function parameter declaration must start with & as value is modified by your code and must be returned modified. | ||
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 module descriptor file contains an entry to declare this module has a substitutions file | |||
<syntaxhighlight lang="PHP"> | |||
$this->module_parts = array('substitutions' => 1) | |||
</syntaxhighlight> | |||
* 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 === | |||
This function is available since Dolibarr v3.3 (future development version). | This function is available since Dolibarr v3.3 (future development version). | ||
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: | ||
<syntaxhighlight 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) | ||
* functions xxx_completesubstitutionarray_lines are called by make_substitutions() if file | * functions xxx_completesubstitutionarray_lines are called by make_substitutions() if file | ||
| Line 285: | Line 142: | ||
{ | { | ||
global $conf,$db; | global $conf,$db; | ||
$myvalue='Put here calculated value to insert'; | $myvalue='Put here calculated value to insert'; | ||
$substitutionarray['myowntag']=$myvalue; | $substitutionarray['myowntag']=$myvalue; | ||
} | } | ||
</syntaxhighlight> | |||
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 == | |||
To have your document to appear in list of available documents, put it into correct subdirectory found into directory documents/doctemplates | To have your document to appear in list of available documents, put it into correct subdirectory found into | ||
directory '''documents/doctemplates''' | |||