From c811d5a371d73ffafed21f9214d803a010ffad29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 19 Oct 2018 18:20:06 +0200 Subject: [PATCH 1/6] fix new pdf --- .../core/class/commondocgenerator.class.php | 85 +++-- .../commande/doc/pdf_eratosthene.modules.php | 162 +++++---- .../facture/doc/pdf_sponge.modules.php | 317 +++++++++--------- .../modules/propale/doc/pdf_cyan.modules.php | 202 ++++++----- 4 files changed, 379 insertions(+), 387 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index c24059ecc05..e25b1525f1a 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1,10 +1,11 @@ - * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015 Marcos García - * Copyright (C) 2016 Charlie Benke +/* Copyright (C) 2003-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2015 Marcos García + * Copyright (C) 2016 Charlie Benke + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -823,8 +824,8 @@ abstract class CommonDocGenerator if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h); $pdf->line($x, $y+$h, $x, $y); } - - + + /** * uasort callback function to Sort colums fields * @@ -832,17 +833,16 @@ abstract class CommonDocGenerator * @param array $b PDF lines array fields configs * @return int Return compare result */ - function columnSort($a, $b) { - + 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 * @@ -853,34 +853,34 @@ abstract class CommonDocGenerator * @param int $hideref Do not show ref * @return null */ - function prepareArrayColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0){ - + 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 witdh $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 desable - + 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++; } @@ -888,7 +888,7 @@ abstract class CommonDocGenerator $totalDefinedColWidth += $colDef['width']; } } - + foreach ($this->cols as $colKey =>& $colDef) { // setting empty conf with default @@ -898,7 +898,7 @@ abstract class CommonDocGenerator else{ $colDef['title'] = $this->defaultTitlesFieldsStyle; } - + // setting empty conf with default if(!empty($colDef['content'])){ $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']); @@ -906,14 +906,14 @@ abstract class CommonDocGenerator 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']; @@ -922,7 +922,7 @@ abstract class CommonDocGenerator } } } - + /** * get column content width from column key * @@ -934,8 +934,8 @@ abstract class CommonDocGenerator $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 * @@ -947,7 +947,7 @@ abstract class CommonDocGenerator $colDef = $this->cols[$colKey]; return $colDef['xStartPos'] + $colDef['content']['padding'][3]; } - + /** * get column position rank from column key * @@ -959,7 +959,7 @@ abstract class CommonDocGenerator if(!isset($this->cols[$colKey]['rank'])) return -1; return $this->cols[$colKey]['rank']; } - + /** * get column position rank from column key * @@ -973,21 +973,21 @@ abstract class CommonDocGenerator { // 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']) @@ -995,14 +995,14 @@ abstract class CommonDocGenerator $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 * @@ -1015,7 +1015,7 @@ abstract class CommonDocGenerator function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '') { global $hookmanager; - + $parameters=array( 'object' => $object, 'curY' =>& $curY, @@ -1031,10 +1031,9 @@ abstract class CommonDocGenerator $colDef = $this->cols[$colKey]; $pdf->MultiCell( $this->getColumnContentWidth($colKey),2, $columnText,'',$colDef['content']['align']); } - } - - + + /** * get column status from column key * diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 039f29fa379..1bd98f846cf 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -7,6 +7,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +68,7 @@ class pdf_eratosthene extends ModelePDFCommandes public $type; /** - * @var array() Minimum version of PHP required by module. + * @var array Minimum version of PHP required by module. * e.g.: PHP ≥ 5.3 = array(5, 3) */ public $phpmin = array(5, 2); @@ -136,7 +137,7 @@ class pdf_eratosthene extends ModelePDFCommandes // Define position of columns $this->posxdesc=$this->marge_gauche+1; - + $this->tva=array(); $this->localtax1=array(); @@ -145,7 +146,8 @@ class pdf_eratosthene extends ModelePDFCommandes $this->atleastonediscount=0; } - /** + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + /** * Function to build pdf onto disk * * @param Object $object Object to generate @@ -156,8 +158,9 @@ class pdf_eratosthene extends ModelePDFCommandes * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0) + public function write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0) { + // phpcs:enable global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; @@ -252,7 +255,7 @@ class pdf_eratosthene extends ModelePDFCommandes break; } } - + if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) { $this->posxpicture+=($this->postotalht - $this->posxdiscount); @@ -316,25 +319,25 @@ class pdf_eratosthene extends ModelePDFCommandes { $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite; $pageposbeforenote = $pagenb; - + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object); $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); - + $tab_top -= 2; - + $pdf->startTransaction(); - + $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); // Description $pageposafternote=$pdf->getPage(); $posyafter = $pdf->GetY(); - + if($pageposafternote>$pageposbeforenote ) { $pdf->rollbackTransaction(true); - + // prepar pages to receive notes while ($pagenb < $pageposafternote) { $pdf->AddPage(); @@ -346,16 +349,16 @@ class pdf_eratosthene extends ModelePDFCommandes // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); } - + // back to start $pdf->setPage($pageposbeforenote); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); $pageposafternote=$pdf->getPage(); - + $posyafter = $pdf->GetY(); - + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20))) // There is no space left for total+free text { $pdf->AddPage('','',true); @@ -367,14 +370,14 @@ class pdf_eratosthene extends ModelePDFCommandes $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); //$posyafter = $tab_top_newpage; } - - + + // apply note frame to previus pages $i = $pageposbeforenote; while ($i < $pageposafternote) { $pdf->setPage($i); - - + + $pdf->SetDrawColor(128,128,128); // Draw note frame if($i>$pageposbeforenote){ @@ -385,21 +388,21 @@ class pdf_eratosthene extends ModelePDFCommandes $height_note = $this->page_hauteur - ($tab_top + $heightforfooter); $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1); } - + // Add footer $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $this->_pagefoot($pdf,$object,$outputlangs,1); - + $i++; } - + // apply note frame to last page $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $height_note=$posyafter-$tab_top_newpage; $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1); - + } else // No pagebreak { @@ -407,8 +410,8 @@ class pdf_eratosthene extends ModelePDFCommandes $posyafter = $pdf->GetY(); $height_note=$posyafter-$tab_top; $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1); - - + + if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) ) { // not enough space, need to add page @@ -418,12 +421,12 @@ class pdf_eratosthene extends ModelePDFCommandes $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - + $posyafter = $tab_top_newpage; } - + } - + $tab_height = $tab_height - $height_note; $tab_top = $posyafter +6; } @@ -435,10 +438,10 @@ class pdf_eratosthene extends ModelePDFCommandes $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; - + // Use new auto collum system $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref); - + // Loop on each lines $pageposbeforeprintlines=$pdf->getPage(); $pagenb = $pageposbeforeprintlines; @@ -456,7 +459,7 @@ class pdf_eratosthene extends ModelePDFCommandes $curX = $this->posxdesc-1; $showpricebeforepagebreak=1; - + if($this->getColumnStatus('desc')) { $pdf->startTransaction(); @@ -493,7 +496,7 @@ class pdf_eratosthene extends ModelePDFCommandes } $posYAfterDescription=$pdf->GetY(); } - + $nexY = $pdf->GetY(); $pageposafter=$pdf->getPage(); @@ -515,7 +518,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate); $nexY = max($pdf->GetY(),$nexY); } - + // Unit price before discount if ($this->getColumnStatus('subprice')) { @@ -523,7 +526,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - + // Quantity // Enough for 6 chars if ($this->getColumnStatus('qty')) @@ -532,8 +535,8 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'qty', $qty); $nexY = max($pdf->GetY(),$nexY); } - - + + // Unit if ($this->getColumnStatus('unit')) { @@ -541,7 +544,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'unit', $unit); $nexY = max($pdf->GetY(),$nexY); } - + // Discount on line if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) { @@ -549,7 +552,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent); $nexY = max($pdf->GetY(),$nexY); } - + // Total HT line if ($this->getColumnStatus('totalexcltax')) { @@ -557,8 +560,8 @@ class pdf_eratosthene extends ModelePDFCommandes $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - - + + $parameters=array( 'object' => $object, 'i' => $i, @@ -569,7 +572,7 @@ class pdf_eratosthene extends ModelePDFCommandes 'hidedetails' => $hidedetails ); $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this); // Note that $object may have been modified by hook - + // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva; @@ -664,16 +667,16 @@ class pdf_eratosthene extends ModelePDFCommandes $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; // Affiche zone infos - $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); + $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs); // Affiche zone totaux - $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); + $posy=$this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); // Affiche zone versements /* if ($deja_regle) { - $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); + $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs); } */ @@ -720,9 +723,8 @@ class pdf_eratosthene extends ModelePDFCommandes * @param Translate $outputlangs Object langs for output * @return int <0 if KO, >0 if OK */ - function _tableau_versements(&$pdf, $object, $posy, $outputlangs) + private function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs) { - } @@ -735,7 +737,7 @@ class pdf_eratosthene extends ModelePDFCommandes * @param Translate $outputlangs Langs object * @return void */ - function _tableau_info(&$pdf, $object, $posy, $outputlangs) + private function drawInfoTable(&$pdf, $object, $posy, $outputlangs) { global $conf; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -922,7 +924,7 @@ class pdf_eratosthene extends ModelePDFCommandes * @param Translate $outputlangs Objet langs * @return int Position pour suite */ - function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) + private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs) { global $conf,$mysoc; @@ -1185,7 +1187,7 @@ class pdf_eratosthene extends ModelePDFCommandes * @param string $currency Currency code * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='') + private function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='') { global $conf; @@ -1220,29 +1222,27 @@ class pdf_eratosthene extends ModelePDFCommandes foreach ($this->cols as $colKey => $colDef) { if(!$this->getColumnStatus($colKey)) continue; - + // get title label $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']); - + // Add column separator if(!empty($colDef['border-left'])){ $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height); } - + if (empty($hidetop)) { $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] ); - + $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1]; $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']); } } - + if (empty($hidetop)){ $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param } - - } /** @@ -1255,7 +1255,7 @@ class pdf_eratosthene extends ModelePDFCommandes * @param string $titlekey Translation key to show as title of document * @return void */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="PdfOrderTitle") + private function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="PdfOrderTitle") { global $conf,$langs,$hookmanager; @@ -1463,15 +1463,15 @@ class pdf_eratosthene extends ModelePDFCommandes * @param int $hidefreetext 1=Hide free text * @return int Return height of bottom margin including footer text */ - function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) + private function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) { global $conf; $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; return pdf_pagefoot($pdf,$outputlangs,'ORDER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } - - + + /** * Define Array Column Field * @@ -1482,22 +1482,22 @@ class pdf_eratosthene extends ModelePDFCommandes * @param int $hideref Do not show ref * @return null */ - function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0){ - + public function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0) + { global $conf, $hookmanager; - + // Default field style for content $this->defaultContentsFieldsStyle = array( 'align' => 'R', // R,C,L 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + // Default field style for content $this->defaultTitlesFieldsStyle = array( 'align' => 'C', // R,C,L 'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + /* * For exemple $this->cols['theColKey'] = array( @@ -1515,7 +1515,7 @@ class pdf_eratosthene extends ModelePDFCommandes ), ); */ - + $rank=0; // do not use negative rank $this->cols['desc'] = array( 'rank' => $rank, @@ -1532,7 +1532,7 @@ class pdf_eratosthene extends ModelePDFCommandes 'align' => 'L', ), ); - + $rank = $rank + 10; $this->cols['photo'] = array( 'rank' => $rank, @@ -1547,13 +1547,13 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => false, // remove left line separator ); - + if (! empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) { $this->cols['photo']['status'] = true; } - - + + $rank = $rank + 10; $this->cols['vat'] = array( 'rank' => $rank, @@ -1564,12 +1564,12 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => true, // add left line separator ); - + if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $this->cols['vat']['status'] = true; } - + $rank = $rank + 10; $this->cols['subprice'] = array( 'rank' => $rank, @@ -1580,7 +1580,7 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['qty'] = array( 'rank' => $rank, @@ -1591,7 +1591,7 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['progress'] = array( 'rank' => $rank, @@ -1602,12 +1602,12 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => false, // add left line separator ); - + if($this->situationinvoice) { $this->cols['progress']['status'] = true; } - + $rank = $rank + 10; $this->cols['unit'] = array( 'rank' => $rank, @@ -1621,7 +1621,7 @@ class pdf_eratosthene extends ModelePDFCommandes if($conf->global->PRODUCT_USE_UNITS){ $this->cols['unit']['status'] = true; } - + $rank = $rank + 10; $this->cols['discount'] = array( 'rank' => $rank, @@ -1635,7 +1635,7 @@ class pdf_eratosthene extends ModelePDFCommandes if ($this->atleastonediscount){ $this->cols['discount']['status'] = true; } - + $rank = $rank + 10; $this->cols['totalexcltax'] = array( 'rank' => $rank, @@ -1646,8 +1646,8 @@ class pdf_eratosthene extends ModelePDFCommandes ), 'border-left' => true, // add left line separator ); - - + + $parameters=array( 'object' => $object, 'outputlangs' => $outputlangs, @@ -1655,7 +1655,7 @@ class pdf_eratosthene extends ModelePDFCommandes 'hidedesc' => $hidedesc, 'hideref' => $hideref ); - + $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this); // Note that $object may have been modified by hook if ($reshook < 0) { @@ -1669,7 +1669,5 @@ class pdf_eratosthene extends ModelePDFCommandes { $this->cols = $hookmanager->resArray; } - } - } diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 74f4bf34acf..dc5fbc315cd 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -8,6 +8,7 @@ * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,7 +69,7 @@ class pdf_sponge extends ModelePDFFactures public $type; /** - * @var array() Minimum version of PHP required by module. + * @var array Minimum version of PHP required by module. * e.g.: PHP ≥ 5.3 = array(5, 3) */ public $phpmin = array(5, 2); @@ -108,7 +109,7 @@ class pdf_sponge extends ModelePDFFactures function __construct($db) { global $conf,$langs,$mysoc; - + // Translations $langs->loadLangs(array("main", "bills")); @@ -147,8 +148,8 @@ class pdf_sponge extends ModelePDFFactures // Define position of columns $this->posxdesc=$this->marge_gauche+1; // used for notes ans other stuff - - // Use new system for position of columns, view $this->defineColumnField() + + // Use new system for position of columns, view $this->defineColumnField() $this->tva=array(); $this->localtax1=array(); @@ -159,7 +160,8 @@ class pdf_sponge extends ModelePDFFactures } - /** + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + /** * Function to build pdf onto disk * * @param Object $object Object to generate @@ -170,30 +172,31 @@ class pdf_sponge extends ModelePDFFactures * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { + // phpcs:enable global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; - + if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - + // Translations $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies")); - + $nblignes = count($object->lines); - + // Loop on each lines to detect if there is at least one image to show $realpatharray=array(); $this->atleastonephoto = false; if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) { $objphoto = new Product($this->db); - + for ($i = 0 ; $i < $nblignes ; $i++) { if (empty($object->lines[$i]->fk_product)) continue; - + $objphoto->fetch($object->lines[$i]->fk_product); //var_dump($objphoto->ref);exit; if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) @@ -206,14 +209,14 @@ class pdf_sponge extends ModelePDFFactures $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/'; // default $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/"; // alternative } - + $arephoto = false; foreach ($pdir as $midir) { if (! $arephoto) { $dir = $conf->product->dir_output.'/'.$midir; - + foreach ($objphoto->liste_photos($dir,1) as $key => $obj) { if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo @@ -231,28 +234,28 @@ class pdf_sponge extends ModelePDFFactures { $filename=$obj['photo']; } - + $realpath = $dir.$filename; $arephoto = true; $this->atleastonephoto = true; } } } - + if ($realpath && $arephoto) $realpatharray[$i]=$realpath; } } - + //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva; - + if ($conf->facture->dir_output) { $object->fetch_thirdparty(); - + $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); - + // Definition of $dir and $file if ($object->specimen) { @@ -273,7 +276,7 @@ class pdf_sponge extends ModelePDFFactures return 0; } } - + if (file_exists($dir)) { // Add pdfgeneration hook @@ -286,47 +289,47 @@ class pdf_sponge extends ModelePDFFactures $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - + // Set nblignes with the new facture lines content after hook $nblignes = count($object->lines); $nbpayments = count($object->getListOfPayments()); - + // Create pdf instance $pdf=pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $pdf->SetAutoPageBreak(1,0); - + $heightforinfotot = 50+(4*$nbpayments); // Height reserved to output the info and total part and payment part $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22); // Height reserved to output the footer (value include bottom margin) - + if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); - + // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } - + $pdf->Open(); $pagenb=0; $pdf->SetDrawColor(128,128,128); - + $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); - + $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - + // Does we have at least one line with discount $this->atleastonediscount foreach ($object->lines as $line) { if ($line->remise_percent){ @@ -334,30 +337,30 @@ class pdf_sponge extends ModelePDFFactures break; } } - - + + // Situation invoice handling if ($object->situation_cycle_ref) { $this->situationinvoice = true; } - + // New page $pdf->AddPage(); if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - + $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); - + $tab_top = 90+$top_shift; $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10); $tab_height = 130-$top_shift; $tab_height_newpage = 150; if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift; - + // Incoterm $height_incoterms = 0; if ($conf->incoterm->enabled) @@ -366,21 +369,21 @@ class pdf_sponge extends ModelePDFFactures if ($desc_incoterms) { $tab_top -= 2; - + $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); $nexY = max($pdf->GetY(),$nexY); $height_incoterms=$nexY-$tab_top; - + // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192,192,192); $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); - + $tab_top = $nexY+6; $height_incoterms += 4; } } - + // Affiche notes $notetoshow=empty($object->note_public)?'':$object->note_public; if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) @@ -394,7 +397,7 @@ class pdf_sponge extends ModelePDFFactures if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); } } - + $pagenb = $pdf->getPage(); if ($notetoshow) { @@ -402,24 +405,24 @@ class pdf_sponge extends ModelePDFFactures $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite; $pageposbeforenote = $pagenb; - + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object); $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); - - + + $pdf->startTransaction(); - + $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); // Description $pageposafternote=$pdf->getPage(); $posyafter = $pdf->GetY(); - + if($pageposafternote>$pageposbeforenote ) { $pdf->rollbackTransaction(true); - + // prepar pages to receive notes while ($pagenb < $pageposafternote) { $pdf->AddPage(); @@ -431,16 +434,16 @@ class pdf_sponge extends ModelePDFFactures // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); } - + // back to start $pdf->setPage($pageposbeforenote); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); $pageposafternote=$pdf->getPage(); - + $posyafter = $pdf->GetY(); - + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20))) // There is no space left for total+free text { $pdf->AddPage('','',true); @@ -452,14 +455,14 @@ class pdf_sponge extends ModelePDFFactures $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); //$posyafter = $tab_top_newpage; } - - + + // apply note frame to previus pages $i = $pageposbeforenote; while ($i < $pageposafternote) { $pdf->setPage($i); - - + + $pdf->SetDrawColor(128,128,128); // Draw note frame if($i>$pageposbeforenote){ @@ -470,21 +473,21 @@ class pdf_sponge extends ModelePDFFactures $height_note = $this->page_hauteur - ($tab_top + $heightforfooter); $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1); } - + // Add footer $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $this->_pagefoot($pdf,$object,$outputlangs,1); - + $i++; } - + // apply note frame to last page $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $height_note=$posyafter-$tab_top_newpage; $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1); - + } else // No pagebreak { @@ -492,8 +495,8 @@ class pdf_sponge extends ModelePDFFactures $posyafter = $pdf->GetY(); $height_note=$posyafter-$tab_top; $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1); - - + + if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) ) { // not enough space, need to add page @@ -503,12 +506,12 @@ class pdf_sponge extends ModelePDFFactures $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - + $posyafter = $tab_top_newpage; } - + } - + $tab_height = $tab_height - $height_note; $tab_top = $posyafter +6; } @@ -516,36 +519,36 @@ class pdf_sponge extends ModelePDFFactures { $height_note=0; } - + $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; - + // Use new auto collum system $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref); - + // Loop on each lines $pageposbeforeprintlines=$pdf->getPage(); $pagenb = $pageposbeforeprintlines; for ($i = 0; $i < $nblignes; $i++) { - + $curY = $nexY; $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0,0,0); - + // Define size of image if we need it $imglinesize=array(); if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); - + $pdf->setTopMargin($tab_top_newpage); $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); - + $showpricebeforepagebreak=1; $posYAfterImage=0; $posYAfterDescription=0; - + if($this->getColumnStatus('photo')) { // We start with Photo of product line @@ -554,11 +557,11 @@ class pdf_sponge extends ModelePDFFactures $pdf->AddPage('','',true); if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pdf->setPage($pageposbefore+1); - + $curY = $tab_top_newpage; $showpricebeforepagebreak=0; } - + if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) { $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi @@ -566,7 +569,7 @@ class pdf_sponge extends ModelePDFFactures $posYAfterImage=$curY+$imglinesize['height']; } } - + // Description of product line if ($this->getColumnStatus('desc')) { @@ -604,20 +607,20 @@ class pdf_sponge extends ModelePDFFactures } $posYAfterDescription=$pdf->GetY(); } - + $nexY = $pdf->GetY(); $pageposafter=$pdf->getPage(); $pdf->setPage($pageposbefore); $pdf->setTopMargin($this->marge_haute); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. - + // We suppose that a too long description or photo were moved completely on next page if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { - $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; } - + $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut - + // VAT Rate if ($this->getColumnStatus('vat')) { @@ -625,7 +628,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate); $nexY = max($pdf->GetY(),$nexY); } - + // Unit price before discount if ($this->getColumnStatus('subprice')) { @@ -633,7 +636,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - + // Quantity // Enough for 6 chars if ($this->getColumnStatus('qty')) @@ -642,7 +645,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'qty', $qty); $nexY = max($pdf->GetY(),$nexY); } - + // Situation progress if ($this->getColumnStatus('progress')) { @@ -650,7 +653,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'progress', $progress); $nexY = max($pdf->GetY(),$nexY); } - + // Unit if ($this->getColumnStatus('unit')) { @@ -658,7 +661,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'unit', $unit); $nexY = max($pdf->GetY(),$nexY); } - + // Discount on line if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) { @@ -666,7 +669,7 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent); $nexY = max($pdf->GetY(),$nexY); } - + // Total HT line if ($this->getColumnStatus('totalexcltax')) { @@ -674,8 +677,8 @@ class pdf_sponge extends ModelePDFFactures $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - - + + $parameters=array( 'object' => $object, 'i' => $i, @@ -686,9 +689,9 @@ class pdf_sponge extends ModelePDFFactures 'hidedetails' => $hidedetails ); $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this); // Note that $object may have been modified by hook - - - + + + $sign=1; if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva @@ -701,20 +704,20 @@ class pdf_sponge extends ModelePDFFactures if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva; else $tvaligne= $sign * $object->lines[$i]->total_tva; } - + $localtax1ligne=$object->lines[$i]->total_localtax1; $localtax2ligne=$object->lines[$i]->total_localtax2; $localtax1_rate=$object->lines[$i]->localtax1_tx; $localtax2_rate=$object->lines[$i]->localtax2_tx; $localtax1_type=$object->lines[$i]->localtax1_type; $localtax2_type=$object->lines[$i]->localtax2_type; - + if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100; if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100; if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; - + $vatrate=(string) $object->lines[$i]->tva_tx; - + // Retrieve type from database for backward compatibility with old records if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax @@ -723,19 +726,19 @@ class pdf_sponge extends ModelePDFFactures $localtax1_type = $localtaxtmp_array[0]; $localtax2_type = $localtaxtmp_array[2]; } - + // retrieve global local tax if ($localtax1_type && $localtax1ligne != 0) $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne; if ($localtax2_type && $localtax2ligne != 0) $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne; - + if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0; $this->tva[$vatrate] += $tvaligne; - + $nexY = max($nexY,$posYAfterImage); - + // Add line if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) { @@ -745,9 +748,9 @@ class pdf_sponge extends ModelePDFFactures $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); $pdf->SetLineStyle(array('dash'=>0)); } - + $nexY+=2; // Passe espace entre les lignes - + // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) { @@ -766,7 +769,7 @@ class pdf_sponge extends ModelePDFFactures $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); } - + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) { if ($pagenb == $pageposafter) @@ -784,9 +787,9 @@ class pdf_sponge extends ModelePDFFactures $pagenb++; if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); } - + } - + // Show square if ($pagenb == $pageposbeforeprintlines) { @@ -798,38 +801,38 @@ class pdf_sponge extends ModelePDFFactures $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code); $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } - + // Affiche zone infos - $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); - + $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs); + // Affiche zone totaux - $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); - + $posy=$this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); + // Affiche zone versements if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) { - $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); + $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs); } - + // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); - + $pdf->Close(); - + $pdf->Output($file,'F'); - + // Add pdfgeneration hook $hookmanager->initHooks(array('pdfgeneration')); $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - + $this->result = array('fullpath'=>$file); - + return 1; // No error } else @@ -855,7 +858,7 @@ class pdf_sponge extends ModelePDFFactures * @param Translate $outputlangs Object langs for output * @return int <0 if KO, >0 if OK */ - function _tableau_versements(&$pdf, $object, $posy, $outputlangs) + function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs) { global $conf; @@ -982,7 +985,6 @@ class pdf_sponge extends ModelePDFFactures $this->error=$this->db->lasterror(); return -1; } - } @@ -995,7 +997,7 @@ class pdf_sponge extends ModelePDFFactures * @param Translate $outputlangs Langs object * @return void */ - function _tableau_info(&$pdf, $object, $posy, $outputlangs) + private function drawInfoTable(&$pdf, $object, $posy, $outputlangs) { global $conf; @@ -1153,7 +1155,7 @@ class pdf_sponge extends ModelePDFFactures * @param Translate $outputlangs Objet langs * @return int Position pour suite */ - function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) + private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs) { global $conf,$mysoc; @@ -1511,29 +1513,27 @@ class pdf_sponge extends ModelePDFFactures foreach ($this->cols as $colKey => $colDef) { if(!$this->getColumnStatus($colKey)) continue; - + // get title label $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']); - + // Add column separator if(!empty($colDef['border-left'])){ $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height); } - + if (empty($hidetop)) { $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] ); - + $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1]; $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']); } } - + if (empty($hidetop)){ $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param } - - } /** @@ -1548,7 +1548,7 @@ class pdf_sponge extends ModelePDFFactures function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { global $conf, $langs; - + // Translations $outputlangs->loadLangs(array("main", "bills", "propal", "companies")); @@ -1822,9 +1822,9 @@ class pdf_sponge extends ModelePDFFactures return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } - - - + + + /** * Define Array Column Field * @@ -1835,22 +1835,22 @@ class pdf_sponge extends ModelePDFFactures * @param int $hideref Do not show ref * @return null */ - function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0){ - + function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0) + { global $conf, $hookmanager; - + // Default field style for content $this->defaultContentsFieldsStyle = array( 'align' => 'R', // R,C,L 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + // Default field style for content $this->defaultTitlesFieldsStyle = array( - 'align' => 'C', // R,C,L + 'align' => 'C', // R,C,L 'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + /* * For exemple $this->cols['theColKey'] = array( @@ -1859,19 +1859,19 @@ class pdf_sponge extends ModelePDFFactures 'title' => array( 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label 'label' => ' ', // the final label : used fore final generated text - 'align' => 'L', // text alignement : R,C,L + 'align' => 'L', // text alignement : R,C,L 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ), 'content' => array( - 'align' => 'L', // text alignement : R,C,L + 'align' => 'L', // text alignement : R,C,L 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ), ); */ - + $rank=0; // do not use negative rank $this->cols['desc'] = array( - 'rank' => $rank, + 'rank' => $rank, 'width' => false, // only for desc 'status' => true, 'title' => array( @@ -1885,7 +1885,7 @@ class pdf_sponge extends ModelePDFFactures 'align' => 'L', ), ); - + // PHOTO $rank = $rank + 10; $this->cols['photo'] = array( @@ -1894,20 +1894,20 @@ class pdf_sponge extends ModelePDFFactures 'status' => false, 'title' => array( 'textkey' => 'Photo', - 'label' => ' ' + 'label' => ' ' ), 'content' => array( 'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ), 'border-left' => false, // remove left line separator ); - + if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) { $this->cols['photo']['status'] = true; } - - + + $rank = $rank + 10; $this->cols['vat'] = array( 'rank' => $rank, @@ -1918,12 +1918,12 @@ class pdf_sponge extends ModelePDFFactures ), 'border-left' => true, // add left line separator ); - + if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $this->cols['vat']['status'] = true; } - + $rank = $rank + 10; $this->cols['subprice'] = array( 'rank' => $rank, @@ -1934,7 +1934,7 @@ class pdf_sponge extends ModelePDFFactures ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['qty'] = array( 'rank' => $rank, @@ -1945,7 +1945,7 @@ class pdf_sponge extends ModelePDFFactures ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['progress'] = array( 'rank' => $rank, @@ -1956,12 +1956,12 @@ class pdf_sponge extends ModelePDFFactures ), 'border-left' => true, // add left line separator ); - + if($this->situationinvoice) { $this->cols['progress']['status'] = true; } - + $rank = $rank + 10; $this->cols['unit'] = array( 'rank' => $rank, @@ -1975,7 +1975,7 @@ class pdf_sponge extends ModelePDFFactures if($conf->global->PRODUCT_USE_UNITS){ $this->cols['unit']['status'] = true; } - + $rank = $rank + 10; $this->cols['discount'] = array( 'rank' => $rank, @@ -1989,7 +1989,7 @@ class pdf_sponge extends ModelePDFFactures if ($this->atleastonediscount){ $this->cols['discount']['status'] = true; } - + $rank = $rank + 10; $this->cols['totalexcltax'] = array( 'rank' => $rank, @@ -2000,8 +2000,8 @@ class pdf_sponge extends ModelePDFFactures ), 'border-left' => true, // add left line separator ); - - + + $parameters=array( 'object' => $object, 'outputlangs' => $outputlangs, @@ -2009,7 +2009,7 @@ class pdf_sponge extends ModelePDFFactures 'hidedesc' => $hidedesc, 'hideref' => $hideref ); - + $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this); // Note that $object may have been modified by hook if ($reshook < 0) { @@ -2023,8 +2023,5 @@ class pdf_sponge extends ModelePDFFactures { $this->cols = $hookmanager->resArray; } - } - - } diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index c9bce8b07a4..be7aea54464 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -7,6 +7,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,24 +41,24 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; */ class pdf_cyan extends ModelePDFPropales { - var $db; - var $name; - var $description; - var $update_main_doc_field; // Save the name of generated file as the main doc when generating a doc with this template - var $type; + public $db; + public $name; + public $description; + public $update_main_doc_field; // Save the name of generated file as the main doc when generating a doc with this template + public $type; - var $phpmin = array(4,3,0); // Minimum version of PHP required by module - var $version = 'development'; + public $phpmin = array(4,3,0); // Minimum version of PHP required by module + public $version = 'development'; - var $page_largeur; - var $page_hauteur; - var $format; - var $marge_gauche; - var $marge_droite; - var $marge_haute; - var $marge_basse; + public $page_largeur; + public $page_hauteur; + public $format; + public $marge_gauche; + public $marge_droite; + public $marge_haute; + public $marge_basse; - var $emetteur; // Objet societe qui emet + public $emetteur; // Objet societe qui emet /** @@ -65,10 +66,10 @@ class pdf_cyan extends ModelePDFPropales * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { global $conf,$langs,$mysoc; - + // Translations $langs->loadLangs(array("main", "bills")); @@ -107,8 +108,8 @@ class pdf_cyan extends ModelePDFPropales // Define position of columns $this->posxdesc=$this->marge_gauche+1; - - + + $this->tva=array(); $this->localtax1=array(); @@ -117,6 +118,7 @@ class pdf_cyan extends ModelePDFPropales $this->atleastonediscount=0; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** * Function to build pdf onto disk * @@ -128,8 +130,9 @@ class pdf_cyan extends ModelePDFPropales * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { + // phpcs:enable global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; @@ -286,8 +289,8 @@ class pdf_cyan extends ModelePDFPropales break; } } - - + + // New page $pdf->AddPage(); @@ -308,7 +311,7 @@ class pdf_cyan extends ModelePDFPropales $tab_top = 90+$top_shift; $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10); - + // Incoterm $height_incoterms = 0; @@ -353,7 +356,7 @@ class pdf_cyan extends ModelePDFPropales if ($tmpuser->email) $notetoshow.=', Mail: '.$tmpuser->email; if ($tmpuser->office_phone) $notetoshow.=', Tel: '.$tmpuser->office_phone; } - + $pagenb = $pdf->getPage(); if ($notetoshow) { @@ -361,24 +364,24 @@ class pdf_cyan extends ModelePDFPropales $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite; $pageposbeforenote = $pagenb; - + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object); $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); $pdf->startTransaction(); - + $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); // Description $pageposafternote=$pdf->getPage(); $posyafter = $pdf->GetY(); - + if($pageposafternote>$pageposbeforenote ) { $pdf->rollbackTransaction(true); - + // prepar pages to receive notes while ($pagenb < $pageposafternote) { $pdf->AddPage(); @@ -390,16 +393,16 @@ class pdf_cyan extends ModelePDFPropales // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); } - + // back to start $pdf->setPage($pageposbeforenote); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); $pdf->SetFont('','', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); $pageposafternote=$pdf->getPage(); - + $posyafter = $pdf->GetY(); - + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20))) // There is no space left for total+free text { $pdf->AddPage('','',true); @@ -411,14 +414,14 @@ class pdf_cyan extends ModelePDFPropales $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); //$posyafter = $tab_top_newpage; } - - + + // apply note frame to previus pages $i = $pageposbeforenote; while ($i < $pageposafternote) { $pdf->setPage($i); - - + + $pdf->SetDrawColor(128,128,128); // Draw note frame if($i>$pageposbeforenote){ @@ -429,21 +432,21 @@ class pdf_cyan extends ModelePDFPropales $height_note = $this->page_hauteur - ($tab_top + $heightforfooter); $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1); } - + // Add footer $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $this->_pagefoot($pdf,$object,$outputlangs,1); - + $i++; } - + // apply note frame to last page $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $height_note=$posyafter-$tab_top_newpage; $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1); - + } else // No pagebreak { @@ -451,8 +454,8 @@ class pdf_cyan extends ModelePDFPropales $posyafter = $pdf->GetY(); $height_note=$posyafter-$tab_top; $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1); - - + + if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) ) { // not enough space, need to add page @@ -462,12 +465,12 @@ class pdf_cyan extends ModelePDFPropales $pdf->setPage($pageposafternote); if (! empty($tplidx)) $pdf->useTemplate($tplidx); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - + $posyafter = $tab_top_newpage; } - + } - + $tab_height = $tab_height - $height_note; $tab_top = $posyafter +6; } @@ -479,10 +482,10 @@ class pdf_cyan extends ModelePDFPropales $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; - + // Use new auto collum system $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref); - + // Loop on each lines $pageposbeforeprintlines=$pdf->getPage(); $pagenb = $pageposbeforeprintlines; @@ -513,12 +516,12 @@ class pdf_cyan extends ModelePDFPropales if (! empty($tplidx)) $pdf->useTemplate($tplidx); //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->setPage($pageposbefore+1); - + $curY = $tab_top_newpage; $showpricebeforepagebreak=0; } - - + + if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) { $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi @@ -526,7 +529,7 @@ class pdf_cyan extends ModelePDFPropales $posYAfterImage=$curY+$imglinesize['height']; } } - + // Description of product line if($this->getColumnStatus('desc')) { @@ -540,7 +543,7 @@ class pdf_cyan extends ModelePDFPropales //print $pageposafter.'-'.$pageposbefore;exit; $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); - + $pageposafter=$pdf->getPage(); $posyafter=$pdf->GetY(); //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; @@ -596,7 +599,7 @@ class pdf_cyan extends ModelePDFPropales $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - + // Quantity // Enough for 6 chars if ($this->getColumnStatus('qty')) @@ -605,8 +608,8 @@ class pdf_cyan extends ModelePDFPropales $this->printStdColumnContent($pdf, $curY, 'qty', $qty); $nexY = max($pdf->GetY(),$nexY); } - - + + // Unit if ($this->getColumnStatus('unit')) { @@ -614,7 +617,7 @@ class pdf_cyan extends ModelePDFPropales $this->printStdColumnContent($pdf, $curY, 'unit', $unit); $nexY = max($pdf->GetY(),$nexY); } - + // Discount on line if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) { @@ -622,7 +625,7 @@ class pdf_cyan extends ModelePDFPropales $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent); $nexY = max($pdf->GetY(),$nexY); } - + // Total HT line if ($this->getColumnStatus('totalexcltax')) { @@ -630,8 +633,8 @@ class pdf_cyan extends ModelePDFPropales $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax); $nexY = max($pdf->GetY(),$nexY); } - - + + $parameters=array( 'object' => $object, 'i' => $i, @@ -642,8 +645,8 @@ class pdf_cyan extends ModelePDFPropales 'hidedetails' => $hidedetails ); $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this); // Note that $object may have been modified by hook - - + + // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva; @@ -745,23 +748,23 @@ class pdf_cyan extends ModelePDFPropales } // Affiche zone infos - $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); + $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs); // Affiche zone totaux - $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs); + $posy=$this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs); // Affiche zone versements /* if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) { - $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); + $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs); } */ // Customer signature area if (empty($conf->global->PROPAL_DISABLE_SIGNATURE)) { - $posy=$this->_signature_area($pdf, $object, $posy, $outputlangs); + $posy=$this->drawSignatureArea($pdf, $object, $posy, $outputlangs); } // Pied de page @@ -872,7 +875,7 @@ class pdf_cyan extends ModelePDFPropales } } - /** + /** * Show payments table * * @param TCPDF $pdf Object PDF @@ -881,9 +884,8 @@ class pdf_cyan extends ModelePDFPropales * @param Translate $outputlangs Object langs for output * @return int <0 if KO, >0 if OK */ - function _tableau_versements(&$pdf, $object, $posy, $outputlangs) + private function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs) { - } @@ -896,7 +898,7 @@ class pdf_cyan extends ModelePDFPropales * @param Translate $outputlangs Langs object * @return void */ - function _tableau_info(&$pdf, $object, $posy, $outputlangs) + function drawInfoTable(&$pdf, $object, $posy, $outputlangs) { global $conf; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -1076,7 +1078,7 @@ class pdf_cyan extends ModelePDFPropales * @param Translate $outputlangs Objet langs * @return int Position pour suite */ - function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) + private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs) { global $conf,$mysoc; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -1389,29 +1391,27 @@ class pdf_cyan extends ModelePDFPropales foreach ($this->cols as $colKey => $colDef) { if(!$this->getColumnStatus($colKey)) continue; - + // get title label $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']); - + // Add column separator if(!empty($colDef['border-left'])){ $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height); } - + if (empty($hidetop)) { $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] ); - + $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1]; $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']); } } - + if (empty($hidetop)){ $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param } - - } /** @@ -1661,7 +1661,7 @@ class pdf_cyan extends ModelePDFPropales * @param Translate $outputlangs Objet langs * @return int Position pour suite */ - function _signature_area(&$pdf, $object, $posy, $outputlangs) + private function drawSignatureArea(&$pdf, $object, $posy, $outputlangs) { global $conf; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -1686,8 +1686,8 @@ class pdf_cyan extends ModelePDFPropales return ($tab_hl*7); } - - + + /** * Define Array Column Field * @@ -1698,22 +1698,22 @@ class pdf_cyan extends ModelePDFPropales * @param int $hideref Do not show ref * @return null */ - function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0){ - + function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0) + { global $conf, $hookmanager; - + // Default field style for content $this->defaultContentsFieldsStyle = array( 'align' => 'R', // R,C,L 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + // Default field style for content $this->defaultTitlesFieldsStyle = array( 'align' => 'C', // R,C,L 'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left ); - + /* * For exemple $this->cols['theColKey'] = array( @@ -1731,7 +1731,7 @@ class pdf_cyan extends ModelePDFPropales ), ); */ - + $rank=0; // do not use negative rank $this->cols['desc'] = array( 'rank' => $rank, @@ -1748,7 +1748,7 @@ class pdf_cyan extends ModelePDFPropales 'align' => 'L', ), ); - + $rank = $rank + 10; $this->cols['photo'] = array( 'rank' => $rank, @@ -1763,13 +1763,13 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => false, // remove left line separator ); - + if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto)) { $this->cols['photo']['status'] = true; } - - + + $rank = $rank + 10; $this->cols['vat'] = array( 'rank' => $rank, @@ -1780,12 +1780,12 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => true, // add left line separator ); - + if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) { $this->cols['vat']['status'] = true; } - + $rank = $rank + 10; $this->cols['subprice'] = array( 'rank' => $rank, @@ -1796,7 +1796,7 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['qty'] = array( 'rank' => $rank, @@ -1807,7 +1807,7 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => true, // add left line separator ); - + $rank = $rank + 10; $this->cols['progress'] = array( 'rank' => $rank, @@ -1818,12 +1818,12 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => false, // add left line separator ); - + if($this->situationinvoice) { $this->cols['progress']['status'] = true; } - + $rank = $rank + 10; $this->cols['unit'] = array( 'rank' => $rank, @@ -1837,7 +1837,7 @@ class pdf_cyan extends ModelePDFPropales if($conf->global->PRODUCT_USE_UNITS){ $this->cols['unit']['status'] = true; } - + $rank = $rank + 10; $this->cols['discount'] = array( 'rank' => $rank, @@ -1851,7 +1851,7 @@ class pdf_cyan extends ModelePDFPropales if ($this->atleastonediscount){ $this->cols['discount']['status'] = true; } - + $rank = $rank + 10; $this->cols['totalexcltax'] = array( 'rank' => $rank, @@ -1862,8 +1862,8 @@ class pdf_cyan extends ModelePDFPropales ), 'border-left' => true, // add left line separator ); - - + + $parameters=array( 'object' => $object, 'outputlangs' => $outputlangs, @@ -1871,7 +1871,7 @@ class pdf_cyan extends ModelePDFPropales 'hidedesc' => $hidedesc, 'hideref' => $hideref ); - + $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this); // Note that $object may have been modified by hook if ($reshook < 0) { @@ -1885,7 +1885,5 @@ class pdf_cyan extends ModelePDFPropales { $this->cols = $hookmanager->resArray; } - } - } From 042118fe38f76f7eb624488249d907c1e9542dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 19 Oct 2018 18:35:16 +0200 Subject: [PATCH 2/6] fix it --- htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_sponge.modules.php | 2 +- htdocs/core/modules/propale/doc/pdf_cyan.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 1bd98f846cf..adcdda6f209 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -146,7 +146,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->atleastonediscount=0; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build pdf onto disk * diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index dc5fbc315cd..a910c7e0984 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -160,7 +160,7 @@ class pdf_sponge extends ModelePDFFactures } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build pdf onto disk * diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index be7aea54464..f6b4c43b3e8 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -118,7 +118,7 @@ class pdf_cyan extends ModelePDFPropales $this->atleastonediscount=0; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build pdf onto disk * From fbc5ce623e02868e677d5c19804bcaa92183dec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Oct 2018 17:17:21 +0200 Subject: [PATCH 3/6] payments --- .../compta/paiement/class/paiement.class.php | 88 +++++++++++++++---- htdocs/public/payment/paymentok.php | 14 +-- 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index fd64155f3d9..18dabbcf980 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -1,13 +1,14 @@ - * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo +/* Copyright (C) 2002-2004 Rodolphe Quiedeville + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2014 Raphaël Doursenaud * Copyright (C) 2014 Marcos García * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Thibault FOUCART + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -73,16 +74,69 @@ class Paiement extends CommonObject public $author; public $paiementid; // Type de paiement. Stocke dans fk_paiement // de llx_paiement qui est lie aux types de - //paiement de llx_c_paiement - public $num_paiement; // Numero du CHQ, VIR, etc... - public $num_payment; // Numero du CHQ, VIR, etc... - public $payment_id; // Id of external modepayment - public $payment_site; // name of external modepayment - public $bank_account; // Id compte bancaire du paiement - public $bank_line; // Id de la ligne d'ecriture bancaire + //paiement de llx_c_paiement + + /** + * @var string type libelle + */ + public $type_libelle; + + /** + * @var string type code + */ + public $type_code; + + /** + * @var string Numero du CHQ, VIR, etc... + * @deprecated + * @see num_payment + */ + public $numero; + + /** + * @var string Numero du CHQ, VIR, etc... + * @deprecated + * @see num_payment + */ + public $num_paiement; + + /** + * @var string Numero du CHQ, VIR, etc... + */ + public $num_payment; + + /** + * @var string Id of external payment mode + */ + public $ext_payment_id; + + /** + * @var string Name of external payment mode + */ + public $ext_payment_site; + + /** + * @var int bank account id of payment + * @deprecated + */ + public $bank_account; + + /** + * @var int bank account id of payment + */ + public $fk_account; + + /** + * @var int id of payment line in bank account + */ + public $bank_line; + // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...) - // fk_paiement dans llx_paiement_facture est le rowid du paiement - public $fk_paiement; // Type of paiment + // fk_paiement dans llx_paiement_facture est le rowid du paiement + /** + * @var int payment id + */ + public $fk_paiement; // Type of payment /** @@ -90,7 +144,7 @@ class Paiement extends CommonObject * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db = $db; } @@ -103,7 +157,7 @@ class Paiement extends CommonObject * @param int $fk_bank Id of bank line associated to payment * @return int <0 if KO, 0 if not found, >0 if OK */ - function fetch($id, $ref='', $fk_bank='') + public function fetch($id, $ref='', $fk_bank='') { $sql = 'SELECT p.rowid, p.ref, p.datep as dp, p.amount, p.statut, p.ext_payment_id, p.ext_payment_site, p.fk_bank,'; $sql.= ' c.code as type_code, c.libelle as type_libelle,'; @@ -138,8 +192,8 @@ class Paiement extends CommonObject $this->type_libelle = $obj->type_libelle; $this->type_code = $obj->type_code; $this->statut = $obj->statut; - $this->payment_id = $obj->ext_payment_id; - $this->payment_site = $obj->ext_payment_site; + $this->ext_payment_id = $obj->ext_payment_id; + $this->ext_payment_site = $obj->ext_payment_site; $this->bank_account = $obj->fk_account; // deprecated $this->fk_account = $obj->fk_account; @@ -235,7 +289,7 @@ class Paiement extends CommonObject $note = ($this->note_public?$this->note_public:$this->note); $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat)"; - $sql.= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($note)."', ".($this->payment_id?"'".$this->db->escape($this->payment_id)."'":"null").", ".($this->payment_site?"'".$this->db->escape($this->payment_site)."'":"null").", ".$user->id.")"; + $sql.= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($note)."', ".($this->ext_payment_id?"'".$this->db->escape($this->ext_payment_id)."'":"null").", ".($this->ext_payment_site?"'".$this->db->escape($this->ext_payment_site)."'":"null").", ".$user->id.")"; dol_syslog(get_class($this)."::Create insert paiement", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 15e77502625..36723658946 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -630,9 +630,9 @@ if ($ispaymentok) $paiement->paiementid = $paymentTypeId; $paiement->num_paiement = ''; $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress; - $paiement->payment_id = $TRANSACTIONID; - $paiement->payment_site = $paymentmethod; - + $paiement->ext_payment_id = $TRANSACTIONID; + $paiement->ext_payment_site = $paymentmethod; + if (! $error) { $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents @@ -653,8 +653,8 @@ if ($ispaymentok) { $bankaccountid = 0; if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; - if ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; - if ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; if ($bankaccountid > 0) { @@ -873,8 +873,8 @@ else if (! empty($conf->global->PAYMENTONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYMENTONLINE_SENDEMAIL; // TODO Remove local option to keep only the generic one ? if ($paymentmethod == 'paypal' && ! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL; - if ($paymentmethod == 'paybox' && ! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL; - if ($paymentmethod == 'stripe' && ! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL; + elseif ($paymentmethod == 'paybox' && ! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL; + elseif ($paymentmethod == 'stripe' && ! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL; // Send an email if ($sendemail) From d10dfd51cb68bd4f16bd750d06d37409ce9f501b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Oct 2018 23:14:04 +0200 Subject: [PATCH 4/6] fix --- test/phpunit/FactureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index d04844783c5..09ea42dd2b6 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -228,7 +228,7 @@ class FactureTest extends PHPUnit_Framework_TestCase $newlocalobject, true, array( - 'newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem', + 'newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem','date_modification', 'ref','statut','paye','specimen','facnumber','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement', 'cond_reglement_doc','situation_cycle_ref','situation_counter','situation_final','multicurrency_total_ht','multicurrency_total_tva', 'multicurrency_total_ttc','fk_multicurrency','multicurrency_code','multicurrency_tx' From cce2e2414f00b6c912c116e8bdafeaae5b198c8d Mon Sep 17 00:00:00 2001 From: ias-ceo Date: Sun, 21 Oct 2018 07:41:40 +0300 Subject: [PATCH 5/6] missing simicolon --- htdocs/theme/eldy/style.css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index bb43aa0af55..d9ad2a590ac 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -3271,7 +3271,7 @@ ul.noborder li:nth-child(even):not(.liste_titre) { .boxstats130 { width: 158px; height: 48px; - padding: 3px + padding: 3px; } .boxstats { padding: 3px; From 263b53bf63347a4a99956c361672145462f1cc7c Mon Sep 17 00:00:00 2001 From: aplose Date: Sun, 21 Oct 2018 18:28:05 +0200 Subject: [PATCH 6/6] Paybox Update : include Paybox HMAC key in process in order to keep the module working with Paybox. --- htdocs/paybox/admin/paybox.php | 9 ++++++ htdocs/paybox/lib/paybox.lib.php | 47 ++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/htdocs/paybox/admin/paybox.php b/htdocs/paybox/admin/paybox.php index 79a6a62ad2a..e4ae5a9eb66 100644 --- a/htdocs/paybox/admin/paybox.php +++ b/htdocs/paybox/admin/paybox.php @@ -71,6 +71,9 @@ if ($action == 'setvalue' && $user->admin) if (! $result > 0) $error++; $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; + $result=dolibarr_set_const($db, "PAYBOX_HMAC_KEY", dol_encode(GETPOST('PAYBOX_HMAC_KEY','alpha')),'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; + if (! $error) { @@ -145,6 +148,12 @@ print 'trans("Test").')'; print ''; +print ''; +print ''.$langs->trans("PAYBOX_HMAC_KEY").''; +print ''; +print '
'.$langs->trans("Example").': 2 ('.$langs->trans("Test").')'; +print ''; + print ''; print ''.$langs->trans("UsageParameter").''; print ''.$langs->trans("Value").''; diff --git a/htdocs/paybox/lib/paybox.lib.php b/htdocs/paybox/lib/paybox.lib.php index a4106488f53..a904c372099 100644 --- a/htdocs/paybox/lib/paybox.lib.php +++ b/htdocs/paybox/lib/paybox.lib.php @@ -92,16 +92,41 @@ function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) $IBS_REFUSE=$urlko; $IBS_BKGD="#FFFFFF"; $IBS_WAIT="2000"; - $IBS_LANG="GBR"; // By default GBR=english (FRA, GBR, ESP, ITA et DEU...) - if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA"; - if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP"; - if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA"; - if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU"; - if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD"; - if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE"; - $IBS_OUTPUT='E'; - $PBX_SOURCE='HTML'; - $PBX_TYPEPAIEMENT='CARTE'; + $IBS_LANG="GBR"; // By default GBR=english (FRA, GBR, ESP, ITA et DEU...) + if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA"; + if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP"; + if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA"; + if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU"; + if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD"; + if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE"; + $IBS_OUTPUT='E'; + $PBX_SOURCE='HTML'; + $PBX_TYPEPAIEMENT='CARTE'; + + $msg = "PBX_IDENTIFIANT=".$PBX_IDENTIFIANT. + "&PBX_MODE=".$IBS_MODE. + "&PBX_SITE=".$IBS_SITE. + "&PBX_RANG=".$IBS_RANG. + "&PBX_TOTAL=".$IBS_TOTAL. + "&PBX_DEVISE=".$IBS_DEVISE. + "&PBX_CMD=".$IBS_CMD. + "&PBX_PORTEUR=".$IBS_PORTEUR. + "&PBX_RETOUR=".$IBS_RETOUR. + "&PBX_EFFECTUE=".$IBS_EFFECTUE. + "&PBX_ANNULE=".$IBS_ANNULE. + "&PBX_REFUSE=".$IBS_REFUSE. + "&PBX_TXT=".$IBS_TXT. + "&PBX_BKGD=".$IBS_BKGD. + "&PBX_WAIT=".$IBS_WAIT. + "&PBX_LANGUE=".$IBS_LANG. + "&PBX_OUTPUT=".$IBS_OUTPUT. + "&PBX_SOURCE=".$PBX_SOURCE. + "&PBX_TYPEPAIEMENT=".$PBX_TYPEPAIEMENT; + + $binKey = pack("H*", dol_decode($conf->global->PAYBOX_HMAC_KEY)); + + $hmac = strtoupper(hash_hmac('sha512', $msg, $binKey)); + dol_syslog("Soumission Paybox", LOG_DEBUG); dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG); @@ -157,7 +182,7 @@ function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) print ''."\n"; print ''."\n"; print ''."\n"; - + print ''."\n"; print ''."\n";