From 8c36dd0ad8f6108a7e7fc7daf658a6616cfadb3c Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 23 Feb 2020 02:26:21 +0100 Subject: [PATCH] add extrafields in notes --- .../core/class/commondocgenerator.class.php | 81 +++++++++++++------ .../commande/doc/pdf_eratosthene.modules.php | 7 ++ .../expedition/doc/pdf_espadon.modules.php | 16 +++- .../facture/doc/pdf_sponge.modules.php | 7 ++ .../modules/propale/doc/pdf_cyan.modules.php | 8 ++ .../supplier_order/doc/pdf_cornas.modules.php | 7 ++ 6 files changed, 99 insertions(+), 27 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 0b77ee2a61a..2517e5f4709 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1102,7 +1102,7 @@ abstract class CommonDocGenerator * * @param object $object common object * @param string $extrafieldKey the extrafield key - * @return null + * @return string */ public function getExtrafieldContent($object, $extrafieldKey) { @@ -1157,48 +1157,80 @@ abstract class CommonDocGenerator /** - * print extrafields columns content + * display extrafields columns content * - * @param Tcpdf $pdf pdf object - * @param float $curY curent Y position * @param object $object line of common object + * @param Translate $outputlangs Output language * @return double max y value */ - public function printLineExtrafieldsColumnsContent($pdf, &$curY, $object) + public function getExtrafieldsInHtml($object, $outputlangs) { global $hookmanager; - if(empty($object->table_element) || !isset($this->extrafieldsCache[$object->table_element])){ + if(empty($object->table_element)){ return; } - $nextY = $curY; + // Load extrafiels if not allready does + if(!isset($this->extrafieldsCache)){ $this->extrafieldsCache = array(); } + if(!isset($this->extrafieldsCache[$object->table_element])){ + $extrafields = new ExtraFields($this->db); + $extrafields->fetch_name_optionals_label($object->table_element); + } + else{ + $extrafields = $this->extrafieldsCache[$object->table_element]; + } - // get extrafield config from cache - $extrafields =& $this->extrafieldsCache[$object->table_element]; /** * @var $extrafields ExtraFields */ + $html = ''; + $fields = array(); + if (is_array($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { - $extrafieldColKey = "options_".$key; - - if ($this->getColumnStatus($extrafieldColKey) && isset($object->array_options[$extrafieldColKey])) - { - // TODO : allow showOutputField to be pdf public friendly, ex: in a link to object, clean getNomUrl to remove link and images... - $columnText = $extrafields->showOutputField($key, $object->array_options[$extrafieldColKey], '', $object->table_element); - - - $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $columnText); - $nextY = max($pdf->GetY(), $nextY); + // Enable extrafield ? + $enabled = 1; + if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){ + $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1); } + + if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){ + $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1); + } + + // TODO : add extrafields enabled for display from extrafield config panel + + if(empty($enabled)){ + continue; + } + + $field = new stdClass(); + $field->rank = intval($extrafields->attributes[$object->table_element]['pos'][$key]); + $field->content = $this->getExtrafieldContent($object, $key); + $field->label = $outputlangs->transnoentities($label); + + $fields[] = $field; } } - return $nextY; + if(!empty($fields)) + { + uasort($fields, function($a, $b){ + return ($a->rank > $b->rank) ? -1 : 1; + } + ); + + foreach ($fields as $field){ + $html.= !empty($html)?'
':''; + $html.= $field->label.' : '.$field->content; + } + } + + return $html; } @@ -1314,15 +1346,16 @@ abstract class CommonDocGenerator // Enable extrafield ? $enabled = 1; - if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])) - { + if ($enabled && isset($extrafields->attributes[$object->table_element]['enabled'][$key])){ $enabled = dol_eval($extrafields->attributes[$object->table_element]['enabled'][$key], 1); } - if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])) - { + + if ($enabled && isset($extrafields->attributes[$object->table_element]['list'][$key])){ $enabled = dol_eval($extrafields->attributes[$object->table_element]['list'][$key], 1); } + // TODO : add extrafields $enabled from extrafield config panel + // 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/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index a797d97e59c..fc1d737a7d5 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -410,6 +410,13 @@ class pdf_eratosthene extends ModelePDFCommandes } } + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) + { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + $pagenb = $pdf->getPage(); if ($notetoshow) { diff --git a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php index 49a3307188a..5d211c2cbae 100644 --- a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php @@ -336,7 +336,17 @@ class pdf_espadon extends ModelePdfExpedition } } - if (!empty($object->note_public) || !empty($object->tracking_number)) + // display note + $notetoshow = empty($object->note_public) ? '' : $object->note_public; + + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) + { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + + if (!empty($notetoshow) || !empty($object->tracking_number)) { $tab_top = 88 + $height_incoterms; $tab_top_alt = $tab_top; @@ -375,10 +385,10 @@ class pdf_espadon extends ModelePdfExpedition } // Notes - if (!empty($object->note_public)) + if (!empty($notetoshow)) { $pdf->SetFont('', '', $default_font_size - 1); // In loop to manage multi-page - $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); + $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($notetoshow), 0, 1); } $nexY = $pdf->GetY(); diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 43b1fa4dbac..cd9327e25b9 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -447,6 +447,13 @@ class pdf_sponge extends ModelePDFFactures } } + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) + { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + $pagenb = $pdf->getPage(); if ($notetoshow) { diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index c7b1b1d715d..702202be988 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -418,6 +418,14 @@ class pdf_cyan extends ModelePDFPropales if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature); } } + + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) + { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0) { $tmpuser = new User($this->db); diff --git a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php index b7a5f49f06d..92bc5219688 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php @@ -369,6 +369,13 @@ class pdf_cornas extends ModelePDFSuppliersOrders // Affiche notes $notetoshow = empty($object->note_public) ? '' : $object->note_public; + // Extrafields in note + $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); + if (!empty($extranote)) + { + $notetoshow = dol_concatdesc($notetoshow, $extranote); + } + $pagenb = $pdf->getPage(); if ($notetoshow) {