ODT Template erstellen: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
(copy from english article)
 
mNo edit summary
Tag: 2017 source edit
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
Return to user
{{TemplateDocUser}}
documentation index
Auf dieser Seite wird beschrieben, wie Sie eine ODT-Dokumentenvorlage erstellen, um eigene Dokumente mithilfe der ODT Generierung zu erstellen.
File Doc user.png


This page describe how to build an ODT document template to build documents using ODT 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 template.''


Inhaltsverzeichnis [Verbergen]
== Prerequisite ==
1 Prerequisite
* Dolibarr: 3.1+
2 Create your document
* OpenOffice: 3.2+, LibreOffice, ...
3 Tags
 
3.1 Company/foundation information
== Create your document ==
3.2 Customers, prospects or suppliers information
* Create from scratch an empty OpenOffice document and take a provided example. You may find them installed into a subdirectory of directory '''documents/doctemplates'''
3.3 User information
* Edit your document using all your Office suite features.
3.4 Other information
3.5 Object information (invoice, commercial proposal, order, ...)
3.6 Lines of object
3.7 For project documents
3.8 Conditional substitution
3.9 Other personalized tags
3.10 Other personalized tags for lines
4 Store your document
[Bearbeiten] Prerequisite
Dolibarr: 3.1+
OpenOffice: 3.2+, LibreOffice, ...
[Bearbeiten] 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.


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.


[Bearbeiten] 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:


[Bearbeiten]Company/foundation information
===Company/foundation information===
{mycompany_logo} : Your company logo
{{TagsOdtMyCompany}}
{mycompany_name} : Your company name
{mycompany_address} : Your company address
{mycompany_zip} : Your company zip
{mycompany_town} : Your company town
{mycompany_country} : Your company country (label)
{mycompany_country_code} : Your company country (code: FR, US, IT...)
{mycompany_state} : Your company state (label)
{mycompany_state_code} : Your company state (code)
{mycompany_phone}
{mycompany_fax}
{mycompany_email}
{mycompany_web}
{mycompany_barcode}
{mycompany_capital}
{mycompany_juridicalstatus}
{mycompany_idprof1}
{mycompany_idprof2}
{mycompany_idprof3}
{mycompany_idprof4}
{mycompany_idprof5}
{mycompany_idprof6}
{mycompany_vatnumber} : Your company VAT number
{mycompany_note} : Your company note
[Bearbeiten]Customers, prospects or suppliers information
{company_name} : Customer or Supplier company name
{company_address}
{company_zip}
{company_town}
{company_country} : Customer or Supplier company country (label)
{company_country_code} : Customer or Supplier company country (code: FR, US, IT...)
{company_state}
{company_state_code}
{company_phone}
{company_fax}
{company_email}
{company_web}
{company_barcode}
{company_customercode} : Company customer code
{company_suppliercode} : Company supplier code
{company_customeraccountancycode} : Company customer accountancy code
{company_supplieraccountancycode} : Company supplier accountancy code
{company_capital}
{company_juridicalstatus}
{company_idprof1}
{company_idprof2}
{company_idprof3}
{company_idprof4}
{company_idprof5}
{company_idprof6}
{company_vatnumber} : Customer or Supplier company VAT number
{company_note_public} : Customer or Supplier company public note
[Bearbeiten]User information
{myuser_lastname}
{myuser_firstname}
{myuser_login}
{myuser_email}
{myuser_zip}
{myuser_town}
{myuser_country}
{myuser_country_code}
{myuser_state}
{myuser_state_code}
...
[Bearbeiten] Other information
{current_date}
{current_datehour}
{current_server_date}
{current_server_datehour}
{current_date_locale}
{current_datehour_locale}
{current_server_date_locale}
{current_server_datehour_locale}


{__(XXX)__} = Translated value of a translation key XXX - Note: Translation must be inside a language file that was previously loaded with $langs->load("languagefile")
===Customers, prospects or suppliers information===
{__[XXX]__} = Value of constant XXX
{{TagsOdtThirdParty}}
[Bearbeiten]Object information (invoice, commercial proposal, order, ...)
{object_id}
{object_ref}
{object_ref_customer}
{object_ref_supplier}
{object_date}
{object_date_creation}
{object_date_modification}
{object_date_validation}
{object_note_private}
{object_note_public}
or
{object_note}


Amounts (numeric data):
===User information===
{object_total_ht}
{{TagsOdtUser}}
{object_total_vat}
{object_total_localtax1} (Dolibarr >= 3.5.0)
{object_total_localtax2} (Dolibarr >= 3.5.0)
{object_total_ttc}
{object_total_discount_ht}
{object_total_vat_x} (Dolibarr >= 3.5.0, is vat total for rate x. x can be for example 20, 8.5, 5.99 ...}


Amounts (in output language format):
=== Other information ===
{object_total_ht_locale} (Dolibarr >= 3.5.0)
{{TagsOdtOther}}
{object_total_vat_locale} (Dolibarr >= 3.5.0)
{object_total_localtax1_locale} (Dolibarr >= 3.5.0)
{object_total_localtax2_locale} (Dolibarr >= 3.5.0)
{object_total_ttc_locale} (Dolibarr >= 3.5.0)
{object_total_discount_ht_locale} (Dolibarr >= 3.5.0)
{object_total_vat_locale_x.x} (Dolibarr >= 3.6.0, is vat total for rate x. x can be for example 20.000, 8.500, 5.990 ...}


Specific to proposals:
===Object information (invoice, commercial proposal, order, ...) ===
{object_date_end} : End date of validity of proposal
{{TagsOdtObjects}}


Specific to order:
===Lines of object===
{object_date_delivery_planed}  (Dolibarr >= 3.4.0)
 
Specific to invoices:
{object_date_limit}
{object_payment_mode}
{object_payment_term}
{object_source_invoice_ref}
{object_already_payed} : Amount already payed (numeric)
{object_remain_to_pay} : Remaining to pay amount (numeric)
{object_already_payed_locale} : Amount already payed (output language format)
{object_remain_to_pay_locale} : Remaining to pay amount (output language format)
 
Extra fields:
{object_options_xxx} : Value of extra field (where xxx is code of extra field)
[Bearbeiten]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}}


{line_fulldesc}
This an example of what you may have in your office suite:
{line_product_ref}
[[File:Line for document generation.png|500px]]
{line_product_label}
{line_desc}
{line_vatrate}
{line_up}
{line_up_locale}
{line_qty}
{line_discount_percent}
{line_price_ht}
{line_price_ht_locale}
{line_price_vat}
{line_price_vat_locale}
{line_price_ttc}
{line_price_ttc_locale}
{line_date_start}
{line_date_start_rfc}
{line_date_end}
{line_date_end_rfc}


Extra fields:
=== For project documents ===
{line_options_xxx} : Value of extra field (where xxx is code of extra field)
For document about projects and task, you also have
This an example of what you may have in your office suite: Line for document generation.png
{{TagsOdtProject}}


[Bearbeiten] For project documents
=== Conditional substitution ===
For document about projects and task, you also have


{tasktime_rowid}
{tasktime_task_date}
{tasktime_task_duration}
{tasktime_task_duration_sec}
{tasktime_note}
{tasktime_fk_user}
{tasktime_user_name}
{tasktime_user_first}
{tasktime_fullcivname}
[Bearbeiten] 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.
[Bearbeiten] 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:
 
<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).


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
$this->module_parts = array('substitutions' => 1)
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).


[Bearbeiten] 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).


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.


[Bearbeiten] Store your document
== 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'''

Navigation menu