Changes

Line 51: Line 51:  
|V12
 
|V12
 
|-
 
|-
|Quotation
+
|Proposal/Quotation
 
|cyan
 
|cyan
 
|V12
 
|V12
Line 65: Line 65:     
=Create a new template=
 
=Create a new template=
==For an existing module==
+
==For an existing core module==
Do not directly modify an existing template. Copy the file of the template used as example into a new name in same directory 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':
     −
*Copy and paste file pdf_propale_azur.modules.php
+
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).
*Rename the copy as pdf_propale_mycompanyblue.modules.php
  −
*Edit and make the following changes in the code:
     −
#Rename 'Class pdf_propale_azur { ' to 'Class pdf_propale_mycompanyblue { '
+
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.
#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.
+
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:
 +
 
 +
#'class pdf_cyan extends ModelePDFPropales' to 'class pdf_mycompanyblue extends ModelePDFPropales'
 +
#'$this->name = "cyan";' to '$this->name = "mycompanyblue";'.
 +
#'$this->description = $langs->trans('DocModelCyanDescription');' to '$this->description = $langs->trans('DocModelMycompanyblueDescription');'.
 +
#Save file.
 +
 
 +
*Edit the file custom/mymodule/core/modules/modMymodule.class.php and make the following changes in the code:
 +
 
 +
#'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.
  −
<br />
      
==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 92: 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 100: Line 114:     
==Library for PDF manipulation==
 
==Library for PDF manipulation==
The library used to create PDF documents in PHP is called TCPDF 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