Add Extrafields on PDF Models: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
Tag: 2017 source edit
mNo edit summary
Tag: 2017 source edit
Line 106: Line 106:
*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 <syntaxhighlight lang="PHP">require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';</syntaxhighlight>[[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 <syntaxhighlight lang="PHP">function write_file</syntaxhighlight>
*Just before the <source lang="php">// Affiche notes</source>
*Just before the <syntaxhighlight lang="PHP">// Affiche notes</syntaxhighlight>
*Add the code to load extrafield array in object <source lang="php">
*Add the code to load extrafield array in object <syntaxhighlight lang="PHP">
$extrafields = new ExtraFields($this->db);
$extrafields = new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
</source>
</syntaxhighlight>
*Add the code to load extrafield into object <source lang="php">
*Add the code to load extrafield into object <syntaxhighlight lang="PHP">
$object->fetch($rowid);
$object->fetch($rowid);
$object->fetch_optionals($rowid,$extralabels);
$object->fetch_optionals($rowid,$extralabels);
</source>
</syntaxhighlight>
*Add the code to print the extrafield <source lang="php">
*Add the code to print the extrafield <syntaxhighlight 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>[[File:Invoices module template Modification.png]]
</syntaxhighlight>[[File:Invoices module template Modification.png]]
*Result : [[File:Invoices module template Modification Result.png|none|thumb]]
*Result : [[File:Invoices module template Modification Result.png|none|thumb]]


==Line complementary attribute==
==Line complementary attribute==


*Find <source lang="php">$object->fetch_thirdparty();</source>
*Find <syntaxhighlight lang="PHP">$object->fetch_thirdparty();</syntaxhighlight>
*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 <syntaxhighlight lang="PHP">
$extrafieldsline = new ExtraFields($this->db);
$extrafieldsline = new ExtraFields($this->db);
$extralabelsline=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$extralabelsline=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
</source>[[File:Add extrafields line in pdf 1.png]]
</syntaxhighlight>[[File:Add extrafields line in pdf 1.png]]
*Find <source lang="php">// Loop on each lines
*Find <syntaxhighlight lang="PHP">// Loop on each lines
for ($i = 0; $i < $nblignes; $i++)
for ($i = 0; $i < $nblignes; $i++)
{</source>
{</syntaxhighlight>
*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 <syntaxhighlight 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]]
</syntaxhighlight>[[File:Add extrafields line in pdf 2.png]]
*Find <source lang="php">$posYAfterDescription=$pdf->GetY();</source>
*Find <syntaxhighlight lang="PHP">$posYAfterDescription=$pdf->GetY();</syntaxhighlight>
*Add, just before, the code to display the line extrafield <source lang="php">
*Add, just before, the code to display the line extrafield <syntaxhighlight lang="PHP">
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_my_line_extra']), 0, 'L', 0);
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_my_line_extra']), 0, 'L', 0);
</source>[[File:Add extrafields line in pdf 3.png]]
</syntaxhighlight>[[File:Add extrafields line in pdf 3.png]]
*Result : [[File:Invoices module template Modification Result 2.png|none|thumb]]
*Result : [[File:Invoices module template Modification Result 2.png|none|thumb]]


Line 158: Line 158:


To display the label instead of the code, you should replace the :
To display the label instead of the code, you should replace the :
<source lang="php">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</source>
<syntaxhighlight lang="PHP">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</syntaxhighlight>
by :
by :
<source lang="php">$extrafields->showOutputField('my_extra', $object->array_options['options_my_extra'])</source>
<syntaxhighlight lang="PHP">$extrafields->showOutputField('my_extra', $object->array_options['options_my_extra'])</syntaxhighlight>


=Special Case for Extrafields type "Date"=
=Special Case for Extrafields type "Date"=
Line 176: Line 176:


To display the date in human readable format, you should replace the :
To display the date in human readable format, you should replace the :
<source lang="php">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</source>
<syntaxhighlight lang="PHP">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</syntaxhighlight>
by :
by :
<source lang="php">dol_print_date($object->array_options['options_my_extra'],"dayhour",false,$outputlangs,true)</source>
<syntaxhighlight lang="PHP">dol_print_date($object->array_options['options_my_extra'],"dayhour",false,$outputlangs,true)</syntaxhighlight>


=Special Case for Product extrafields on Invoice Line=
=Special Case for Product extrafields on Invoice Line=
Line 188: Line 188:
===Include Product Extrafield===
===Include Product Extrafield===


*Find <source lang="php">// Loop on each lines
*Find <syntaxhighlight lang="PHP">// Loop on each lines
for ($i = 0; $i < $nblignes; $i++)
for ($i = 0; $i < $nblignes; $i++)
{</source>
{</syntaxhighlight>
*Just after add :
*Just after add :


<source lang="php"> if ($object->lines[$i]->fk_product)
<syntaxhighlight lang="PHP"> if ($object->lines[$i]->fk_product)
{
{
require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
Line 203: Line 203:


$product->fetch_optionals($product->rowid, $extralabels_product);
$product->fetch_optionals($product->rowid, $extralabels_product);
}</source>
}</syntaxhighlight>


===Display Product Extrafield===
===Display Product Extrafield===
Instead of using that :
Instead of using that :
<source lang="php">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</source>
<syntaxhighlight lang="PHP">$outputlangs->convToOutputCharset($object->array_options['options_my_extra'])</syntaxhighlight>
Should be replace by :
Should be replace by :
<source lang="php">$outputlangs->convToOutputCharset($product->array_options['options_my_product_extra'])</source>
<syntaxhighlight lang="PHP">$outputlangs->convToOutputCharset($product->array_options['options_my_product_extra'])</syntaxhighlight>


=Special Case for Third party extrafields=
=Special Case for Third party extrafields=
Line 216: Line 216:


===Display Third party Extrafield===
===Display Third party Extrafield===
<source lang="php">
<syntaxhighlight lang="PHP">
$pdf->writeHTMLCell (190,3, $this->posxdesc-1, $tab_top-5, $outputlangs->convToOutputCharset($object->thirdparty->array_options['options_my_third_party_extra']),0,1);
$pdf->writeHTMLCell (190,3, $this->posxdesc-1, $tab_top-5, $outputlangs->convToOutputCharset($object->thirdparty->array_options['options_my_third_party_extra']),0,1);
</source>
</syntaxhighlight>




Navigation menu