diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index 486764b167e..b61c9209aa8 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -184,7 +184,7 @@ if ($action == 'add') GETPOST('langfile', 'alpha'), 1, (GETPOST('totalizable', 'alpha')?1:0), - (GETPOST('documentpdf', 'alpha')?1:0) + GETPOST('documentpdf', 'alpha') ); if ($result > 0) { @@ -354,7 +354,7 @@ if ($action == 'update') GETPOST('langfile'), 1, (GETPOST('totalizable', 'alpha')?1:0), - (GETPOST('documentpdf', 'alpha')?1:0) + GETPOST('documentpdf', 'alpha') ); if ($result > 0) { diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index eb214516a6f..753002a39ee 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1074,7 +1074,7 @@ abstract class CommonDocGenerator /** * print standard column content * - * @param PDF $pdf pdf object + * @param TCPDF $pdf pdf object * @param float $curY curent Y position * @param string $colKey the column key * @param string $columnText column text @@ -1179,6 +1179,8 @@ abstract class CommonDocGenerator $defaultParams = array( 'style' => '', 'display' => 'auto', // auto, table, list + 'documentpdfEnable' => array(1), + 'documentpdfEnableNotEmpty' => array(2), 'table' => array( 'maxItemsInRow' => 2, @@ -1213,7 +1215,18 @@ abstract class CommonDocGenerator foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { // Enable extrafield ? - $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + $enabled = 0; + $disableOnEmpty = 0; + if(!empty($extrafields->attributes[$object->table_element]['documentpdf'][$key])) { + $documentpdf = intval($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + if(in_array($documentpdf,$params['documentpdfEnable']) || in_array($documentpdf,$params['documentpdfEnableNotEmpty']) ) { + $enabled = 1; + } + + if (in_array($documentpdf,$params['documentpdfEnableNotEmpty'])) { + $disableOnEmpty = 1; + } + } if(empty($enabled)){ continue; @@ -1225,6 +1238,11 @@ abstract class CommonDocGenerator $field->label = $outputlangs->transnoentities($label); $field->type = $extrafields->attributes[$object->table_element]['type'][$key]; + // dont display if empty + if($disableOnEmpty && empty($field->content)) { + continue; + } + $fields[] = $field; } } @@ -1234,10 +1252,7 @@ abstract class CommonDocGenerator // Sort extrafields by rank uasort($fields, function ($a, $b) { return ($a->rank > $b->rank) ? -1 : 1; - } - ); - - + }); // define some HTML content with style $html.= ''; @@ -1425,8 +1440,16 @@ abstract class CommonDocGenerator } // Enable extrafield ? - $enabled = !empty($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + $enabled = 0; + if(!empty($extrafields->attributes[$object->table_element]['documentpdf'][$key])) { + $documentpdf = intval($extrafields->attributes[$object->table_element]['documentpdf'][$key]); + if($documentpdf === 1 || $documentpdf === 2) { + $enabled = 1; + } + // Note : if $documentpdf === 3 or 4 so, it's displayed after line description not in cols + } + if (!$enabled){ continue; } // don't wast resourses if we don't need them... // Load language if required if (!empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $outputlangs->load($extrafields->attributes[$object->table_element]['langfile'][$key]); diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index cd9327e25b9..90290caaf61 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -638,12 +638,34 @@ class pdf_sponge extends ModelePDFFactures { $pdf->startTransaction(); pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc); + $posYAfterDescription = $pdf->GetY(); + $params = array( + 'display' => 'list', + 'documentpdfEnable' => array(3), + 'documentpdfEnableNotEmpty' => array(4) + ); + $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params); + if(!empty($extrafieldDesc)){ + $this->printStdColumnContent($pdf, $posYAfterDescription, 'desc', $extrafieldDesc); + } + $pageposafter = $pdf->getPage(); if ($pageposafter > $pageposbefore) // There is a pagebreak { $pdf->rollbackTransaction(true); $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc); + $posYAfterDescription = $pdf->GetY(); + $params = array( + 'display' => 'list', + 'documentpdfEnable' => array(3), + 'documentpdfEnableNotEmpty' => array(4) + ); + $extrafieldDesc = $this->getExtrafieldsInHtml($object->lines[$i], $outputlangs, $params); + if(!empty($extrafieldDesc)){ + $this->printStdColumnContent($pdf, $posYAfterDescription, 'desc', $extrafieldDesc); + } + $pageposafter = $pdf->getPage(); $posyafter = $pdf->GetY(); //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; @@ -673,7 +695,7 @@ class pdf_sponge extends ModelePDFFactures $posYAfterDescription = $pdf->GetY(); } - $nexY = $pdf->GetY(); + $nexY = $pdf->GetY(); $pageposafter = $pdf->getPage(); $pdf->setPage($pageposbefore); $pdf->setTopMargin($this->marge_haute); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 37872f2a5c0..a31b83309af 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -198,7 +198,7 @@ $langs->load("modulebuilder"); textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> -> + trans("Totalizable"); ?>> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 8e14ad978ca..f92bdd1ada6 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -267,7 +267,7 @@ else textwithpicto($langs->trans("DisplayOnPdf"), $langs->trans("DisplayOnPdfDesc")); ?> -> + textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?>> textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?> diff --git a/htdocs/core/tpl/admin_extrafields_view.tpl.php b/htdocs/core/tpl/admin_extrafields_view.tpl.php index 3bec8cb8d6f..6ed1480a0ea 100644 --- a/htdocs/core/tpl/admin_extrafields_view.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_view.tpl.php @@ -93,7 +93,7 @@ if (is_array($extrafields->attributes[$elementtype]['type']) && count($extrafiel print ''.yn($extrafields->attributes[$elementtype]['required'][$key])."\n"; print ''.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."\n"; print ''.$extrafields->attributes[$elementtype]['list'][$key]."\n"; - print ''.yn($extrafields->attributes[$elementtype]['documentpdf'][$key])."\n"; + print ''.$extrafields->attributes[$elementtype]['documentpdf'][$key]."\n"; print ''.yn($extrafields->attributes[$elementtype]['totalizable'][$key])."\n"; if (! empty($conf->multicompany->enabled)) { print '';