1
edit
Gschratzer (talk | contribs) No edit summary Tag: 2017 source edit |
(As mentionned in issue (https://github.com/Dolibarr/dolibarr/issues/22364) I put the warning in red and bold) |
||
| Line 1: | Line 1: | ||
{{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 document template to build documents using ODT generation. | ||
| Line 25: | Line 16: | ||
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 makes detection/replacement impossible. With LibreOffice you can also use the Ctrl+M to remove direct formatting from Tags'''</span> | ||
==Tags== | ==Tags== | ||
| Line 54: | Line 45: | ||
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"> | ||
[!-- IF {object_total_..._x} --] | [!-- IF {object_total_..._x} --] | ||
0 | 0 | ||
| Line 60: | Line 51: | ||
{object_total_..._x} | {object_total_..._x} | ||
[!-- ENDIF {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). | [[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 119: | Line 110: | ||
*Inside this file, just write one function like this: | *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 136: | Line 127: | ||
$substitutionarray['myowntag']=$myvalue; | $substitutionarray['myowntag']=$myvalue; | ||
} | } | ||
</ | </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 148: | Line 139: | ||
*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"> | ||
$this->module_parts = array('substitutions' => 1) | $this->module_parts = array('substitutions' => 1) | ||
</ | </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 165: | Line 156: | ||
*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 183: | Line 174: | ||
$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. | ||
edit