Browse Source

Add extrafields on PDF object lines for compatible pdf

ATM john 5 years ago
parent
commit
60b3d9d4db

+ 17 - 1
htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php

@@ -702,6 +702,17 @@ class pdf_eratosthene extends ModelePDFCommandes
 					    $nexY = max($pdf->GetY(), $nexY);
 					}
 
+                    // Extrafields
+                    if(!empty($object->lines[$i]->array_options)){
+                        foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue){
+                            if ($this->getColumnStatus($extrafieldColKey))
+                            {
+                                $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
+                                $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
+                                $nexY = max($pdf->GetY(), $nexY);
+                            }
+                        }
+                    }
 
 					$parameters = array(
 					    'object' => $object,
@@ -1804,7 +1815,7 @@ class pdf_eratosthene extends ModelePDFCommandes
 	        $this->cols['discount']['status'] = true;
 	    }
 
-	    $rank = $rank + 10;
+	    $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
 	    $this->cols['totalexcltax'] = array(
 	        'rank' => $rank,
 	        'width' => 26, // in mm
@@ -1815,6 +1826,11 @@ class pdf_eratosthene extends ModelePDFCommandes
 	        'border-left' => true, // add left line separator
 	    );
 
+        // Add extrafields cols
+        if(!empty($object->lines)) {
+            $line = reset($object->lines);
+            $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
+        }
 
 	    $parameters = array(
 	        'object' => $object,

+ 16 - 1
htdocs/core/modules/expedition/doc/pdf_espadon.modules.php

@@ -558,7 +558,17 @@ class pdf_espadon extends ModelePdfExpedition
 					    $nexY = max($pdf->GetY(), $nexY);
 					}
 
-
+                    // Extrafields
+                    if(!empty($object->lines[$i]->array_options)){
+                        foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue){
+                            if ($this->getColumnStatus($extrafieldColKey))
+                            {
+                                $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
+                                $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
+                                $nexY = max($pdf->GetY(), $nexY);
+                            }
+                        }
+                    }
 
 					$nexY += 3;
 					if ($weighttxt && $voltxt) $nexY += 2;
@@ -1225,6 +1235,11 @@ class pdf_espadon extends ModelePdfExpedition
 	        ),
 	    );
 
+        // Add extrafields cols
+        if(!empty($object->lines)) {
+            $line = reset($object->lines);
+            $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
+        }
 
 	    $parameters = array(
 	        'object' => $object,

+ 17 - 1
htdocs/core/modules/propale/doc/pdf_cyan.modules.php

@@ -717,6 +717,17 @@ class pdf_cyan extends ModelePDFPropales
 					    $nexY = max($pdf->GetY(), $nexY);
 					}
 
+                    // Extrafields
+                    if(!empty($object->lines[$i]->array_options)){
+                        foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue){
+                            if ($this->getColumnStatus($extrafieldColKey))
+                            {
+                                $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
+                                $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
+                                $nexY = max($pdf->GetY(), $nexY);
+                            }
+                        }
+                    }
 
 					$parameters = array(
 					    'object' => $object,
@@ -1952,7 +1963,7 @@ class pdf_cyan extends ModelePDFPropales
 	        $this->cols['discount']['status'] = true;
 	    }
 
-	    $rank = $rank + 10;
+	    $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
 	    $this->cols['totalexcltax'] = array(
 	        'rank' => $rank,
 	        'width' => 26, // in mm
@@ -1963,6 +1974,11 @@ class pdf_cyan extends ModelePDFPropales
 	        'border-left' => true, // add left line separator
 	    );
 
+        // Add extrafields cols
+        if(!empty($object->lines)) {
+            $line = reset($object->lines);
+            $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
+        }
 
 	    $parameters = array(
 	        'object' => $object,

+ 17 - 227
htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php

@@ -649,6 +649,17 @@ class pdf_cornas extends ModelePDFSuppliersOrders
 					    $nexY = max($pdf->GetY(), $nexY);
 					}
 
+                    // Extrafields
+                    if(!empty($object->lines[$i]->array_options)){
+                        foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue){
+                            if ($this->getColumnStatus($extrafieldColKey))
+                            {
+                                $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
+                                $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
+                                $nexY = max($pdf->GetY(), $nexY);
+                            }
+                        }
+                    }
 
 					$parameters = array(
 					    'object' => $object,
@@ -1596,7 +1607,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders
 	        $this->cols['discount']['status'] = true;
 	    }
 
-	    $rank = $rank + 10;
+	    $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
 	    $this->cols['totalexcltax'] = array(
 	        'rank' => $rank,
 	        'width' => 26, // in mm
@@ -1607,6 +1618,11 @@ class pdf_cornas extends ModelePDFSuppliersOrders
 	        'border-left' => true, // add left line separator
 	    );
 
+        // Add extrafields cols
+        if(!empty($object->lines)) {
+            $line = reset($object->lines);
+            $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
+        }
 
 	    $parameters = array(
 	        'object' => $object,
@@ -1630,230 +1646,4 @@ class pdf_cornas extends ModelePDFSuppliersOrders
 	        $this->cols = $hookmanager->resArray;
 	    }
 	}
-
-	/*
-	 *
-	 * DEBUT PARTIE NORMALEMENT DANS LA CLASSE CommonDocGenerator
-	 *
-	 *
-	 */
-
-	/**
-	 *   	uasort callback function to Sort columns fields
-	 *
-	 *   	@param	array			$a    			PDF lines array fields configs
-	 *   	@param	array			$b    			PDF lines array fields configs
-	 *      @return	int								Return compare result
-	 */
-	public function columnSort($a, $b)
-	{
-	    if (empty($a['rank'])) { $a['rank'] = 0; }
-	    if (empty($b['rank'])) { $b['rank'] = 0; }
-	    if ($a['rank'] == $b['rank']) {
-	        return 0;
-	    }
-	    return ($a['rank'] > $b['rank']) ? -1 : 1;
-	}
-
-	/**
-	 *   	Prepare Array Column Field
-	 *
-	 *   	@param	object		  $object    		common object
-	 *   	@param	Translate	  $outputlangs      langs
-	 *      @param	int			  $hidedetails		Do not show line details
-	 *      @param	int			  $hidedesc			Do not show desc
-	 *      @param	int			  $hideref			Do not show ref
-	 *      @return	null
-	 */
-	public function prepareArrayColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
-	{
-	    global $conf;
-
-	    $this->defineColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
-
-	    // Sorting
-	    uasort($this->cols, array($this, 'columnSort'));
-
-	    // Positionning
-	    $curX = $this->page_largeur - $this->marge_droite; // start from right
-
-	    // Array width
-	    $arrayWidth = $this->page_largeur - $this->marge_droite - $this->marge_gauche;
-
-	    // Count flexible column
-	    $totalDefinedColWidth = 0;
-	    $countFlexCol = 0;
-	    foreach ($this->cols as $colKey => &$colDef)
-	    {
-	        if (!$this->getColumnStatus($colKey)) continue; // continue if disabled
-
-	        if (!empty($colDef['scale'])) {
-	            // In case of column widht is defined by percentage
-	            $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100);
-	        }
-
-	        if (empty($colDef['width'])) {
-	            $countFlexCol++;
-	        }
-	        else {
-	            $totalDefinedColWidth += $colDef['width'];
-	        }
-	    }
-
-	    foreach ($this->cols as $colKey => &$colDef)
-	    {
-	        // setting empty conf with default
-	        if (!empty($colDef['title'])) {
-	            $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
-	        }
-	        else {
-	            $colDef['title'] = $this->defaultTitlesFieldsStyle;
-	        }
-
-	        // setting empty conf with default
-	        if (!empty($colDef['content'])) {
-	            $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
-	        }
-	        else {
-	            $colDef['content'] = $this->defaultContentsFieldsStyle;
-	        }
-
-	        if ($this->getColumnStatus($colKey))
-	        {
-	            // In case of flexible column
-	            if (empty($colDef['width'])) {
-	                $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
-	            }
-
-	            // Set positions
-	            $lastX = $curX;
-	            $curX = $lastX - $colDef['width'];
-	            $colDef['xStartPos'] = $curX;
-	            $colDef['xEndPos']   = $lastX;
-	        }
-	    }
-	}
-
-	/**
-	 *   	get column content width from column key
-	 *
-	 *   	@param	string			$colKey    		the column key
-	 *      @return	float      width in mm
-	 */
-	public function getColumnContentWidth($colKey)
-	{
-	    $colDef = $this->cols[$colKey];
-	    return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
-	}
-
-
-	/**
-	 *   	get column content X (abscissa) left position from column key
-	 *
-	 *   	@param	string    $colKey    		the column key
-	 *      @return	float      X position in mm
-	 */
-	public function getColumnContentXStart($colKey)
-	{
-	    $colDef = $this->cols[$colKey];
-	    return  $colDef['xStartPos'] + $colDef['content']['padding'][3];
-	}
-
-	/**
-	 *   	get column position rank from column key
-	 *
-	 *   	@param	string		$colKey    		the column key
-	 *      @return	int         rank on success and -1 on error
-	 */
-	public function getColumnRank($colKey)
-	{
-	    if (!isset($this->cols[$colKey]['rank'])) return -1;
-	    return  $this->cols[$colKey]['rank'];
-	}
-
-	/**
-	 *   	get column position rank from column key
-	 *
-	 *   	@param	string		$newColKey    	the new column key
-	 *   	@param	array		$defArray    	a single column definition array
-	 *   	@param	string		$targetCol    	target column used to place the new column beside
-	 *   	@param	bool		$insertAfterTarget    	insert before or after target column ?
-	 *      @return	int         new rank on success and -1 on error
-	 */
-	public function insertNewColumnDef($newColKey, $defArray, $targetCol = false, $insertAfterTarget = false)
-	{
-	    // prepare wanted rank
-	    $rank = -1;
-
-	    // try to get rank from target column
-	    if (!empty($targetCol)) {
-	        $rank = $this->getColumnRank($targetCol);
-	        if ($rank >= 0 && $insertAfterTarget) { $rank++; }
-	    }
-
-	    // get rank from new column definition
-	    if ($rank < 0 && !empty($defArray['rank'])) {
-	        $rank = $defArray['rank'];
-	    }
-
-	    // error: no rank
-	    if ($rank < 0) { return -1; }
-
-	    foreach ($this->cols as $colKey =>& $colDef)
-	    {
-	        if ($rank <= $colDef['rank'])
-	        {
-	            $colDef['rank'] = $colDef['rank'] + 1;
-	        }
-	    }
-
-	    $defArray['rank'] = $rank;
-	    $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
-
-	    return $rank;
-	}
-
-
-	/**
-	 *   	print standard column content
-	 *
-	 *   	@param	PDF		    $pdf    	pdf object
-	 *   	@param	float		$curY    	curent Y position
-	 *   	@param	string		$colKey    	the column key
-	 *   	@param	string		$columnText   column text
-	 *      @return	int         new rank on success and -1 on error
-	 */
-	public function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
-	{
-	    global $hookmanager;
-
-	    $parameters = array(
-	        'curY' =>& $curY,
-	        'columnText' => $columnText,
-	        'colKey' => $colKey
-	    );
-	    $reshook = $hookmanager->executeHooks('printStdColumnContent', $parameters, $this); // Note that $action and $object may have been modified by hook
-	    if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-	    if (!$reshook)
-	    {
-	        if (empty($columnText)) return;
-	        $pdf->SetXY($this->getColumnContentXStart($colKey), $curY); // Set curent position
-	        $colDef = $this->cols[$colKey];
-	        $pdf->MultiCell($this->getColumnContentWidth($colKey), 2, $columnText, '', $colDef['content']['align']);
-	    }
-	}
-
-	/**
-	 *   	get column status from column key
-	 *
-	 *   	@param	string			$colKey    		the column key
-	 *      @return	float      width in mm
-	 */
-	public function getColumnStatus($colKey)
-	{
-	    if (!empty($this->cols[$colKey]['status'])) {
-	        return true;
-	    }
-	    else return false;
-	}
 }