Line 2:
Line 2:
<!-- You can edit this section but do NOT remove these comments
<!-- You can edit this section but do NOT remove these comments
Links below will be automatically replicated on translated pages by PolyglotBot -->
Links below will be automatically replicated on translated pages by PolyglotBot -->
−
[[fr:Créer_un_modèle_de_document_ODT]]
+
[[fr:Créer_un_modèle_de_document_ODT_ou_ODS]]
−
[[es:Crear_un_modelo_de_documento_ODT]]
+
[[es:Crear_un_modelo_de_documento_ODT_o_ODS]]
+
[[de:Erstellen einer ODT-Dokumentvorlage]]
<!-- END interlang links -->
<!-- END interlang links -->
−
[[Category:Admin]]
{{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 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 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...
==Prerequisite==
==Prerequisite==
*Dolibarr: 3.1+
*Dolibarr: 3.1+
−
*OpenOffice: 3.2+, LibreOffice, ...
+
*LibreOffice or any ODT or ODS editor (OpenOffice, ...)
==Create your document==
==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'''
+
*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.
*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. With LibreOffice you can also use the Ctrl+M to remove direct formatting from Tags
+
[[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 36:
Line 40:
===Contacts===
===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 not tags for delivery contact.
+
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}}
{{TagsOdtContact}}
Line 53:
Line 61:
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:
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">
+
<syntaxhighlight lang="bash">
[!-- IF {object_total_..._x} --]
[!-- IF {object_total_..._x} --]
0
0
Line 59:
Line 67:
{object_total_..._x}
{object_total_..._x}
[!-- ENDIF {object_total_..._x} --]
[!-- ENDIF {object_total_..._x} --]
−
</syntaxHighlight>
+
</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).
[[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).
Line 118:
Line 126:
*Inside this file, just write one function like this:
*Inside this file, just write one function like this:
−
<syntaxHighlight lang="php">
+
<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 135:
Line 143:
$substitutionarray['myowntag']=$myvalue;
$substitutionarray['myowntag']=$myvalue;
}
}
−
</syntaxHighlight>
+
</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)...
Line 147:
Line 155:
*Check your module descriptor file contains an entry to declare this module has a substitutions file
*Check your module descriptor file contains an entry to declare this module has a substitutions file
−
<syntaxHighlight lang="php">
+
<syntaxhighlight lang="php">
$this->module_parts = array('substitutions' => 1)
$this->module_parts = array('substitutions' => 1)
−
</syntaxHighlight>
+
</syntaxhighlight>
*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).
Line 164:
Line 172:
*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">
+
<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 182:
Line 190:
$substitutionarray['myowntag']=$myvalue;
$substitutionarray['myowntag']=$myvalue;
}
}
−
</syntaxHighlight>
+
</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'''