Changes

Line 15: Line 15:  
An ODT template does not require PHP knowledge. To build an ODT template, see this page [[Create an ODT document template]].  
 
An ODT template does not require PHP knowledge. To build an ODT template, see this page [[Create an ODT document template]].  
   −
=Prerequisite=
+
=Prerequisites=
    
*Dolibarr: 3.0+
 
*Dolibarr: 3.0+
Line 29: Line 29:  
propale for commercial proposals
 
propale for commercial proposals
 
facture for invoices
 
facture for invoices
commandes for orders, etc...  
+
commande for orders, etc...  
 
and finally '''doc''' or '''pdf'''.
 
and finally '''doc''' or '''pdf'''.
 
For instance, proposal templates will be located in '''...core/modules/propale/doc/'''
 
For instance, proposal templates will be located in '''...core/modules/propale/doc/'''
 +
 +
The list of recommended PDF Models :
 +
{| class="wikitable"
 +
!Module
 +
!PDF Model name
 +
!Dolibarr min version
 +
|-
 +
|Shipping
 +
|espadon
 +
|V12
 +
|-
 +
|Order
 +
|eratosthene
 +
|V12
 +
|-
 +
|Invoice
 +
|sponge
 +
|V12
 +
|-
 +
|Proposal/Quotation
 +
|cyan
 +
|V12
 +
|-
 +
|Supplier order
 +
|cornas
 +
|V12
 +
|-
 +
|Delivery
 +
|storm
 +
|V13
 +
|}
    
=Create a new template=
 
=Create a new template=
==For an existing module==
+
==For an existing core module==
Do not modify an existing template. Copy the file of the template used as example into a new name in same directory than your example and edit it to change content.
+
Do not directly modify an existing template.  
For this example, we will call our new template 'mycompanyblue', based on the existing template 'azur':
+
 
 +
Although it is possible to copy the file of the template used as example into a new name in same directory and edit it to change content it is strongly recommended not to modify any core file or structure(If you want to fix something use the project Github page to propose your changes).
 +
 
 +
Instead use the [[https://wiki.dolibarr.org/index.php?title=Module_development#Module_creation_with_the_module_builder |Module Builder]] available from v12.0 to create your own module even for just a new template.
 +
 
 +
For this example, we will call our new module 'mymodule' and our template 'mycompanyblue', based on the existing template 'cyan':
 +
 
 +
 
 +
*Copy and paste file pdf_cyan.modules.php into custom/mymodule/core/modules/propale/doc
 +
*Rename the copy as pdf_mycompanyblue.modules.php
 +
*Edit the file and make the following changes in the code:
   −
*Copy and paste file pdf_propale_azur.modules.php
+
#'class pdf_cyan extends ModelePDFPropales' to 'class pdf_mycompanyblue extends ModelePDFPropales'
*Rename the copy as pdf_propale_mycompanyblue.modules.php
+
#'$this->name = "cyan";' to '$this->name = "mycompanyblue";'.
*Edit and make the following changes in the code:
+
#'$this->description = $langs->trans('DocModelCyanDescription');' to '$this->description = $langs->trans('DocModelMycompanyblueDescription');'.
 +
#Save file.
   −
#Rename 'Class pdf_propale_azur { ' to 'Class pdf_propale_mycompanyblue { '
+
*Edit the file custom/mymodule/core/modules/modMymodule.class.php and make the following changes in the code:
#Rename constant $this->name to match your new template name. For example for 'azur' template, change line '$this->name = "azur";' to '$this->name = "mycompanyblue";'.
+
 
#Save file. Now the template will be available in the list of models in Dolibarr.
+
#'models' => 0 to 'models' => 1
 +
#Save file.
 +
 
 +
*Activate your new module
 +
 
 +
Now the template will be available in the list of models in the admin settings of proposal.
    
Test this model (see previous section) before going further.
 
Test this model (see previous section) before going further.
  −
Add into table '''llx_document_model''' the new document template that you have created.
      
==For a new module==
 
==For a new module==
Just use the [[Module Builder]] from v12.0 to create your module. When entering the name of a new object to create, you can also check a checkbox to say that you want to manage documents for such new object. In such a case, two templates will be automatically generated (one ODT template and one PDF template).
+
Just use the [[https://wiki.dolibarr.org/index.php?title=Module_development#Module_creation_with_the_module_builder |Module Builder]] AGAIN to create your module. When entering the name of a new object to create, you can also check a checkbox to say that you want to manage documents for such new object. In such a case, two templates will be automatically generated (one ODT template and one PDF template).
    
The templates will be generated with path:
 
The templates will be generated with path:
Line 61: Line 106:  
Customize the new template:
 
Customize the new template:
   −
In file pdf_propale_mycompanyblue.modules.php, look for the function '_pagehead()' function. It is the function that manages the display of the header.
+
In file pdf_mycompanyblue.modules.php, look for the function '_pagehead()' function. It is the function that manages the display of the header.
    
Look for the '_pagefooter()' function. It is the function that manages the display of the footer.
 
Look for the '_pagefooter()' function. It is the function that manages the display of the footer.
Line 69: Line 114:     
==Library for PDF manipulation==
 
==Library for PDF manipulation==
The library used to create PDF documents in PHP is called FPDF and can be found in htdocs/includes/tcpdf/tcpdf.class.php (or htdocs/includes/tecnickcom/tcpdf/tcpdf.class.php). This class contains the methods used to generate different parts of documents.
+
The library used to create PDF documents in PHP is called TCPDF and can be found in htdocs/includes/tecnickcom/tcpdf/tcpdf.class.php. This class contains the methods used to generate different parts of documents.
   −
Templates instantiate the FPDF class and use its methods combined with the specific data of the invoice, order etc.
+
Templates instantiate the TCPDF class and use its methods combined with the specific data of the invoice, order etc.
    
We can generally find the following calls into templates that generate PDF documents:
 
We can generally find the following calls into templates that generate PDF documents:
61

edits