Add Extrafields on PDF Models: Difference between revisions
No edit summary Tag: 2017 source edit |
No edit summary Tag: 2017 source edit |
||
| Line 59: | Line 59: | ||
# Rename '''class pdf_crabe''' to '''class pdf_my_template''' | # Rename '''class pdf_crabe''' to '''class pdf_my_template''' | ||
# Rename constant '''$this->name = "crabe";''' to '''$this->name = "my_template";''' | # Rename constant '''$this->name = "crabe";''' to '''$this->name = "my_template";''' | ||
# Save file. Now the template will be available in the list of models in Dolibarr. | # Update the '''$this->description''' with your description | ||
# Test this model before going further ... | # Save file. Now the template will be available in the list of models in Dolibarr[[File:Invoices module setup template.png|none|thumb]] | ||
# Test this model (by generating a pdf) before going further ... | |||
=Modify the new invoice template= | =Modify the new invoice template= | ||
Revision as of 11:41, 4 October 2019
This page give you some advises how to integrate complementary attributes (extrafields) into PDF models of Dolibarr.
This is a exemple and needs to be adapted to your needs. It is based on billing document but it will be the same for the others modules
Prerequisite
You can read the following links before, some paragraph will come from these pages :
Create a Complementary Attributes on Invoices Module
First you need to create your complementary attribute. This complementary attributes can be of two types :
- Module complementary attribute
- Line complementary attribute
Access to the configuration
Go on the Dolibarr application > Setup > Modules/Applications
Click on the parameter icon
of the Invoices module
Then you can create Module or Line complementary attribute
Module complementary attribute
Go on the Complementary attributes (invoices) tab
Put the all the mandatory fields, especially the Attribute code that will be used in the next chapters
You should end up with something like that :
Line complementary attribute
Go on the Complementary attributes (lines) tab
Put the all the mandatory fields, especially the Attribute code that will be used in the next chapters
You should end up with something like that :
Verification on the Invoices Module
Clic on Billing|Payement and select New invoice
If you have created a Module complementary attribute, you should have that :
If you have created a Line complementary attribute, you should have that :
Create a new invoice template
All the steps are describes there Create a PDF document template
- Open the core\modules\facture\doc\ directory
- Copy the pdf_crabe.modules.php
- Rename the copy as pdf_my_template.modules.php
- Edit and make the following changes in the code:
- Rename class pdf_crabe to class pdf_my_template
- Rename constant $this->name = "crabe"; to $this->name = "my_template";
- Update the $this->description with your description
- Save file. Now the template will be available in the list of models in Dolibarr
- Test this model (by generating a pdf) before going further ...
Modify the new invoice template
- Open the new template pdf_my_template.modules.php
- Look for the last require_one lines ate the beginning of the template
- Add the line
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'
Module complementary attribute
- Find the
function write_file
- Just before the
// Affiche notes - Add the code to load extrafield array in object
$extrafields = new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- Add the code to load extrafield into object
$object->fetch($rowid); $object->fetch_optionals($rowid,$extralabels);
- Add the code to display the extrafiled
$pdf->MultiCell (190,3, $outputlangs->convToOutputCharset($object->array_options['options_my_extra']),0,'L'); );