Add Extrafields on PDF Models: Difference between revisions

Jump to navigation Jump to search
No edit summary
Tag: 2017 source edit
Tag: 2017 source edit
Line 53: Line 53:
=Create a new invoice template=
=Create a new invoice template=
All the steps are describes there [[Create a PDF document 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'''  
*Open the '''core\modules\facture\doc\''' directory
* Rename the copy as '''pdf_my_template.modules.php'''
*Copy the '''pdf_crabe.modules.php'''
* Edit and make the following changes in the code:  
*Rename the copy as '''pdf_my_template.modules.php'''
# Rename '''class pdf_crabe''' to '''class pdf_my_template'''
*Edit and make the following changes in the code:
# Rename constant '''$this->name = "crabe";''' to '''$this->name = "my_template";'''
 
# Update the '''$this->description''' with your description
#Rename '''class pdf_crabe''' to '''class pdf_my_template'''
# Save file. Now the template will be available in the list of models in Dolibarr[[File:Invoices module setup template.png|none|thumb]]
#Rename constant '''$this->name = "crabe";''' to '''$this->name = "my_template";'''
# Test this model (by generating a pdf) before going further ...
#Update the '''$this->description''' with your description
#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=
*Open the new template '''pdf_my_template.modules.php'''
*Open the new template '''pdf_my_template.modules.php'''
*Look for the last '''require_one''' lines ate the beginning of the template
*Look for the last '''require_one''' lines ate the beginning of the template
*Add the line <source lang="php">require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';</source>[[File:Add_extrafields_in_pdf_1.png|none|thumb]]
*Add the line <source lang="php">require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';</source>[[File:Add_extrafields_in_pdf_1.png|none|thumb]]


== Module complementary attribute ==
==Module complementary attribute==
 
*Find the <source lang="php">function write_file</source>
*Find the <source lang="php">function write_file</source>
*Just before the <source lang="php">// Affiche notes</source>
*Just before the <source lang="php">// Affiche notes</source>
Line 81: Line 85:
*Add the code to print the extrafiled <source lang="php">
*Add the code to print the extrafiled <source lang="php">
$pdf->writeHTMLCell (190,3, $this->posxdesc-1, $tab_top-5, $outputlangs->convToOutputCharset($object->array_options['options_my_extra']),0,1);
$pdf->writeHTMLCell (190,3, $this->posxdesc-1, $tab_top-5, $outputlangs->convToOutputCharset($object->array_options['options_my_extra']),0,1);
</source>
</source>[[File:Invoices module template Modification.png]]
[[File:Invoices module template Modification.png|none|thumb]]
 


==Line complementary attribute==


== Line complementary attribute ==
*Find <source lang="php">$object->fetch_thirdparty();</source>
*Find <source lang="php">$object->fetch_thirdparty();</source>
*Add, just after, the code to load extrafield array in object <source lang="php">
*Add, just after, the code to load extrafield array in object <source lang="php">
$extrafields = new ExtraFields($db);
$extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
</source>[[File:Add extrafields line in pdf 1.png|thumb]]
</source>[[File:Add extrafields line in pdf 1.png]]
*Find <source lang="php">// Loop on each lines
*Find <source lang="php">// Loop on each lines
for ($i = 0; $i < $nblignes; $i++)
for ($i = 0; $i < $nblignes; $i++)
Line 96: Line 100:
*Add, just after, the code to load line extrafield into object <source lang="php">
*Add, just after, the code to load line extrafield into object <source lang="php">
$object->lines[$i]->fetch_optionals($object->lines[$i]->rowid,$extralabelsline);
$object->lines[$i]->fetch_optionals($object->lines[$i]->rowid,$extralabelsline);
</source>[[File:Add extrafields line in pdf 2.png|none|thumb]]
</source>[[File:Add extrafields line in pdf 2.png]]
*Find <source lang="php">$posYAfterDescription=$pdf->GetY();</source>
*Find <source lang="php">$posYAfterDescription=$pdf->GetY();</source>
*Add, just before, the code to display the line extrafiled <source lang="php">
*Add, just before, the code to display the line extrafiled <source lang="php">
$pdf->MultiCell(0, 3, $object->lines[$i]->array_options['options_my_line_extra'], 0, 'L', 0);
$pdf->MultiCell(0, 3, $object->lines[$i]->array_options['options_my_line_extra'], 0, 'L', 0);
</source>[[File:Add extrafields line in pdf 3.png|thumb]]
</source>[[File:Add extrafields line in pdf 3.png]]
676

edits

Navigation menu