Merge pull request #9821 from frederic34/fixpdf

fix new pdf
This commit is contained in:
Laurent Destailleur 2018-10-24 03:02:28 +02:00 committed by GitHub
commit 094625f27c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 114 deletions

View File

@ -1,10 +1,11 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
*
* 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
*

View File

@ -7,6 +7,7 @@
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
*
* 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);
@ -145,7 +146,8 @@ 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
*
* @param Object $object Object to generate
@ -156,7 +158,7 @@ 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;
@ -665,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);
}
*/
@ -721,7 +723,7 @@ 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)
{
// phpcs:enable
@ -737,7 +739,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)
{
// phpcs:enable
global $conf;
@ -925,7 +927,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)
{
// phpcs:enable
global $conf,$mysoc;
@ -1189,7 +1191,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;
@ -1245,8 +1247,6 @@ class pdf_eratosthene extends ModelePDFCommandes
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
}
}
/**
@ -1259,7 +1259,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;
@ -1470,7 +1470,7 @@ 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;
@ -1489,9 +1489,8 @@ 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
@ -1677,7 +1676,5 @@ class pdf_eratosthene extends ModelePDFCommandes
{
$this->cols = $hookmanager->resArray;
}
}
}

View File

@ -8,6 +8,7 @@
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
*
* 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);
@ -159,7 +160,8 @@ class pdf_sponge extends ModelePDFFactures
}
/** phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build pdf onto disk
*
* @param Object $object Object to generate
@ -170,7 +172,7 @@ 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;
@ -801,15 +803,15 @@ class pdf_sponge extends ModelePDFFactures
}
// 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
@ -856,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)
{
// phpcs:enable
global $conf;
@ -984,7 +986,6 @@ class pdf_sponge extends ModelePDFFactures
$this->error=$this->db->lasterror();
return -1;
}
}
@ -997,7 +998,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)
{
// phpcs:enable
global $conf;
@ -1156,7 +1157,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)
{
// phpcs:enable
global $conf,$mysoc;
@ -1536,8 +1537,6 @@ class pdf_sponge extends ModelePDFFactures
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
}
}
/**
@ -1842,9 +1841,8 @@ 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
@ -2031,8 +2029,5 @@ class pdf_sponge extends ModelePDFFactures
{
$this->cols = $hookmanager->resArray;
}
}
}

View File

@ -7,6 +7,7 @@
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
*
* 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,7 +66,7 @@ class pdf_cyan extends ModelePDFPropales
*
* @param DoliDB $db Database handler
*/
function __construct($db)
public function __construct($db)
{
global $conf,$langs,$mysoc;
@ -117,7 +118,8 @@ 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
*
* @param Object $object Object to generate
@ -128,9 +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
// phpcs:enable
global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
if (! is_object($outputlangs)) $outputlangs=$langs;
@ -746,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
@ -882,7 +884,7 @@ 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)
{
// phpcs:enable
}
@ -897,7 +899,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)
{
// phpcs:enable
global $conf;
@ -1078,7 +1080,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);
@ -1412,8 +1414,6 @@ class pdf_cyan extends ModelePDFPropales
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
}
}
/**
@ -1666,7 +1666,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);
@ -1703,9 +1703,8 @@ 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
@ -1891,7 +1890,5 @@ class pdf_cyan extends ModelePDFPropales
{
$this->cols = $hookmanager->resArray;
}
}
}