Changes

m
Line 1: Line 1:  +
<!-- BEGIN origin interlang links -->
 +
<!-- You can edit this section but do NOT remove these comments
 +
    Links below will be automatically replicated on translated pages by PolyglotBot -->
 +
[[fr:Créer_un_modèle_de_document_ODT_ou_ODS]]
 +
[[es:Crear_un_modelo_de_documento_ODT_o_ODS]]
 +
[[de:Erstellen einer ODT-Dokumentvorlage]]
 +
<!-- END interlang links -->
 +
 
{{TemplateDocUser}}
 
{{TemplateDocUser}}
This page describe how to build an ODT document template to build documents using ODT generation.
+
This page describe how to build an ODT or ODS document (Format for OpenOffice, LibreOffice, ...) template to build documents, using ODT/ODS generation.
 +
 
 +
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 or ODS template.
 +
 
 +
* ODT is the format of documents generated by LibreOffice Writer for example (the mostly used case for document generation).
 +
* ODS is the format of documents generated by LibreOffice Calc for example.
 +
You can you both of them to generated a templatethat can be used by Dolubarr...
   −
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+
* Dolibarr: 3.1+
+
*LibreOffice or any ODT or ODS editor (OpenOffice, ...)
* 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 sub-directory 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 backward and no copy-paste). If not doing that, Office suite add some invisible informations making replacement not possible.
+
[[File:Warning.png]] <span style="color:#FE0000">'''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 that makes detection and replacement impossible. With LibreOffice you can also use the Ctrl+M to remove direct formatting from Tags'''</span>
   −
== Tags ==
+
==Tags for substitution variables==
 
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 23: Line 38:  
===Customers, prospects or suppliers information===
 
===Customers, prospects or suppliers information===
 
{{TagsOdtThirdParty}}
 
{{TagsOdtThirdParty}}
 +
 +
===Contacts===
 +
It is the tags for contact of:
 +
* invoice for invoices (type BILLING),
 +
* contact of proposal for proposals (type CUSTOMER),
 +
* contact of order for sale orders (type CUSTOMER).
 +
There is no tags for the delivery contact. Also other type of documents are not supported.
 +
{{TagsOdtContact}}
    
===User information===
 
===User information===
<pre>
+
{{TagsOdtUser}}
myuser_lastname = {myuser_lastname}
+
 
myuser_firstname = {myuser_firstname}
+
===Other information===
myuser_login = {myuser_login}
+
{{TagsOdtOther}}
myuser_email = {myuser_email}
  −
...
  −
</pre>
     −
=== Other information ===
+
===Object information (invoice, commercial proposal, order, ...)===
<pre>
+
Note: When you find _locale at end of the name of a tag, it means the output value will be in the locale and language of the targetted language for generation instead of the default format or language.
current_user_date = {current_user_date}
  −
current_user_datehour = {current_user_datehour}
  −
current_server_date = {current_server_date}
  −
current_server_datehour = {current_server_datehour}
  −
</pre>
     −
===Object information (invoice, commercial proposal, order, ...) ===
   
{{TagsOdtObjects}}
 
{{TagsOdtObjects}}
 +
 +
[[File:Info.png]]
 +
 +
For the tag {object_total_..._x}, if there is no amount for the vat rate x, the key is not replaced. So you can use the condition syntax to show 0 instead of the key when value is not defined:
 +
<syntaxhighlight lang="bash">
 +
[!-- IF {object_total_..._x} --]
 +
0
 +
[!-- ELSE {object_total_..._x} --]
 +
{object_total_..._x}
 +
[!-- ENDIF {object_total_..._x} --]
 +
</syntaxhighlight>
 +
[[File:Warning.png]] To be sure this part of code does not contains hidden text (added silently by LibreOffice for versioning/tracking change purpose), you must select all the code section, make a right click an  select the feature "Remove direct formatting" (not doing this may make the code section not working).
    
===Lines of object===
 
===Lines of object===
Line 52: Line 78:  
</pre>
 
</pre>
   −
Then, you can use following tags into your line:
+
If you want to display it not in tables row but in block lines :
 +
<pre>
 +
[!-- BEGIN lines --]
 +
...
 +
[!-- END lines --]
 +
</pre>
 +
 
 +
Then, you can use the following tags into your line (in addition to any other tags of the document):
 
{{TagsOdtLines}}
 
{{TagsOdtLines}}
   Line 58: Line 91:  
[[File:Line for document generation.png|500px]]
 
[[File:Line for document generation.png|500px]]
   −
=== Conditional substitution ===
+
===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.
Line 73: Line 110:  
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: 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.
   −
=== 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 one of those locations:
+
 
'''htdocs/core/substitutions/functions_mymodule.lib.php''' or
+
*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:
+
 
<source lang="php">
+
*Inside this file, just write one function like this:
 +
 
 +
<syntaxhighlight 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)
 
  * functions xxx_completesubstitutionarray are called by make_substitutions() if file
 
  * functions xxx_completesubstitutionarray are called by make_substitutions() if file
Line 102: Line 143:  
   $substitutionarray['myowntag']=$myvalue;
 
   $substitutionarray['myowntag']=$myvalue;
 
}
 
}
</source>
+
</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)...  
 
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 valu 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 :
 +
 
 +
*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
   −
Note: With 3.2 and higher, if you have build your own module (See page [[Module development]]), you can put the substitution file inside a subdirectory of this module called htdocs/mymodule/core/substitutions.
+
<syntaxhighlight lang="php">
Moreover, function will be called only if module '''mymodule''' contains an entry
  −
<source lang="php">
   
$this->module_parts = array('substitutions' => 1)  
 
$this->module_parts = array('substitutions' => 1)  
</source>
+
</syntaxhighlight>
and module has been activated.
+
 
 +
*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 123: Line 169:  
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">
+
 
 +
<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 143: Line 190:  
   $substitutionarray['myowntag']=$myvalue;
 
   $substitutionarray['myowntag']=$myvalue;
 
}
 
}
</source>
+
</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 ==
+
==Store your document==
To have your document to appear in list of available documents, put it into correct subdirectory found into
+
To see your document template appear in the list of available templates by going to the module configuration. In the ODT/ODS Template section, there is a small form to upload the template. It is also possible to place the file manually in the appropriate subdirectory located in the '''documents/doctemplates''' directory
directory '''documents/doctemplates'''