2009-01-28 16:09:37 +01:00
< ? php
2017-08-30 14:36:00 +02:00
/* Copyright ( C ) 2006 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-08-04 10:11:56 +02:00
* Copyright ( C ) 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2017-08-30 14:36:00 +02:00
* Copyright ( C ) 2010 - 2017 Juanjo Menent < jmenent @ 2 byte . es >
2014-08-04 10:11:56 +02:00
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
2014-11-14 16:43:49 +01:00
* Copyright ( C ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2012 - 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2014-08-04 10:11:56 +02:00
* Copyright ( C ) 2014 Cedric GROSS < c . gross @ kreiz - it . fr >
* Copyright ( C ) 2014 Teddy Andreotti < 125155 @ supinfo . com >
2016-03-19 23:00:33 +01:00
* Copyright ( C ) 2015 - 2016 Marcos García < marcosgdf @ gmail . com >
2013-08-22 16:49:23 +02:00
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
*/
2009-01-28 16:09:37 +01:00
/**
2011-10-24 12:59:44 +02:00
* \file htdocs / core / lib / pdf . lib . php
2013-08-22 16:49:23 +02:00
* \brief Set of functions used for PDF generation
* \ingroup core
*/
2009-01-28 16:09:37 +01:00
2009-06-15 20:57:34 +02:00
2010-12-21 00:43:45 +01:00
/**
2013-04-29 09:25:42 +02:00
* Return array with format properties of default PDF format
*
* @ param Translate $outputlangs Output lang to use to autodetect output format if setup not done
* @ return array Array ( 'width' => w , 'height' => h , 'unit' => u );
*/
2016-08-11 15:23:00 +02:00
function pdf_getFormat ( Translate $outputlangs = null )
2011-08-11 14:13:59 +02:00
{
2011-09-17 03:05:44 +02:00
global $conf , $db ;
2011-08-11 14:13:59 +02:00
2011-09-17 03:05:44 +02:00
// Default value if setup was not done and/or entry into c_paper_format not defined
$width = 210 ; $height = 297 ; $unit = 'mm' ;
2011-08-11 14:13:59 +02:00
2011-09-17 03:05:44 +02:00
if ( empty ( $conf -> global -> MAIN_PDF_FORMAT ))
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2013-04-29 09:25:42 +02:00
$pdfformat = dol_getDefaultFormat ( $outputlangs );
2011-09-17 03:05:44 +02:00
}
else $pdfformat = $conf -> global -> MAIN_PDF_FORMAT ;
2011-08-11 14:13:59 +02:00
$sql = " SELECT code, label, width, height, unit FROM " . MAIN_DB_PREFIX . " c_paper_format " ;
2011-09-17 03:05:44 +02:00
$sql .= " WHERE code = ' " . $pdfformat . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
$width = ( int ) $obj -> width ;
$height = ( int ) $obj -> height ;
$unit = $obj -> unit ;
}
}
//print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
return array ( 'width' => $width , 'height' => $height , 'unit' => $unit );
2011-08-11 14:13:59 +02:00
}
/**
2013-08-16 10:16:06 +02:00
* Return a PDF instance object . We create a FPDI instance that instantiate TCPDF .
2011-09-17 03:05:44 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param string $format Array ( width , height ) . Keep empty to use default setup .
* @ param string $metric Unit of format ( 'mm' )
* @ param string $pagetype 'P' or 'l'
2016-08-11 15:23:00 +02:00
* @ return TCPDF PDF object
2010-12-21 00:43:45 +01:00
*/
2011-08-11 14:13:59 +02:00
function pdf_getInstance ( $format = '' , $metric = 'mm' , $pagetype = 'P' )
2010-12-21 00:43:45 +01:00
{
2011-09-17 03:05:44 +02:00
global $conf ;
2013-06-08 16:29:59 +02:00
// Define constant for TCPDF
2014-05-01 19:17:45 +02:00
if ( ! defined ( 'K_TCPDF_EXTERNAL_CONFIG' ))
{
define ( 'K_TCPDF_EXTERNAL_CONFIG' , 1 ); // this avoid using tcpdf_config file
define ( 'K_PATH_CACHE' , DOL_DATA_ROOT . '/admin/temp/' );
define ( 'K_PATH_URL_CACHE' , DOL_DATA_ROOT . '/admin/temp/' );
dol_mkdir ( K_PATH_CACHE );
define ( 'K_BLANK_IMAGE' , '_blank.png' );
define ( 'PDF_PAGE_FORMAT' , 'A4' );
define ( 'PDF_PAGE_ORIENTATION' , 'P' );
define ( 'PDF_CREATOR' , 'TCPDF' );
define ( 'PDF_AUTHOR' , 'TCPDF' );
define ( 'PDF_HEADER_TITLE' , 'TCPDF Example' );
define ( 'PDF_HEADER_STRING' , " by Dolibarr ERP CRM " );
define ( 'PDF_UNIT' , 'mm' );
define ( 'PDF_MARGIN_HEADER' , 5 );
define ( 'PDF_MARGIN_FOOTER' , 10 );
define ( 'PDF_MARGIN_TOP' , 27 );
define ( 'PDF_MARGIN_BOTTOM' , 25 );
define ( 'PDF_MARGIN_LEFT' , 15 );
define ( 'PDF_MARGIN_RIGHT' , 15 );
define ( 'PDF_FONT_NAME_MAIN' , 'helvetica' );
define ( 'PDF_FONT_SIZE_MAIN' , 10 );
define ( 'PDF_FONT_NAME_DATA' , 'helvetica' );
define ( 'PDF_FONT_SIZE_DATA' , 8 );
define ( 'PDF_FONT_MONOSPACED' , 'courier' );
define ( 'PDF_IMAGE_SCALE_RATIO' , 1.25 );
define ( 'HEAD_MAGNIFICATION' , 1.1 );
define ( 'K_CELL_HEIGHT_RATIO' , 1.25 );
define ( 'K_TITLE_MAGNIFICATION' , 1.3 );
define ( 'K_SMALL_RATIO' , 2 / 3 );
define ( 'K_THAI_TOPCHARS' , true );
define ( 'K_TCPDF_CALLS_IN_HTML' , true );
define ( 'K_TCPDF_THROW_EXCEPTION_ERROR' , false );
}
2013-06-08 16:29:59 +02:00
2012-03-20 01:42:18 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_FPDF ) && ! empty ( $conf -> global -> MAIN_DISABLE_FPDI ))
2013-04-04 13:58:33 +02:00
return " Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together " ;
2012-03-20 01:42:18 +01:00
2012-12-04 20:51:45 +01:00
// We use by default TCPDF else FPDF
2012-08-22 23:11:24 +02:00
if ( empty ( $conf -> global -> MAIN_USE_FPDF )) require_once TCPDF_PATH . 'tcpdf.php' ;
2012-12-04 20:51:45 +01:00
else require_once FPDF_PATH . 'fpdf.php' ;
2015-03-02 01:38:40 +01:00
// We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
if ( empty ( $conf -> global -> MAIN_DISABLE_TCPDI )) require_once TCPDI_PATH . 'tcpdi.php' ;
else if ( empty ( $conf -> global -> MAIN_DISABLE_FPDI )) require_once FPDI_PATH . 'fpdi.php' ;
2011-09-17 03:05:44 +02:00
//$arrayformat=pdf_getFormat();
//$format=array($arrayformat['width'],$arrayformat['height']);
//$metric=$arrayformat['unit'];
2012-12-19 13:06:45 +01:00
// Protection and encryption of pdf
2012-12-04 20:51:45 +01:00
if ( empty ( $conf -> global -> MAIN_USE_FPDF ) && ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION ))
2014-05-01 19:17:45 +02:00
{
2011-09-17 03:05:44 +02:00
/* Permission supported by TCPDF
2014-04-07 09:54:24 +02:00
- print : Print the document ;
2013-04-04 13:58:33 +02:00
- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms' , 'extract' and 'assemble' ;
- copy : Copy or otherwise extract text and graphics from the document ;
- annot - forms : Add or modify text annotations , fill in interactive form fields , and , if 'modify' is also set , create or modify interactive form fields ( including signature fields );
- fill - forms : Fill in existing interactive form fields ( including signature fields ), even if 'annot-forms' is not specified ;
- extract : Extract text and graphics ( in support of accessibility to users with disabilities or for other purposes );
- assemble : Assemble the document ( insert , rotate , or delete pages and create bookmarks or thumbnail images ), even if 'modify' is not set ;
- print - high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated . When this is not set , printing is limited to a low - level representation of the appearance , possibly of degraded quality .
- owner : ( inverted logic - only for public - key ) when set permits change of encryption and enables all other permissions .
*/
2015-03-02 01:38:40 +01:00
if ( class_exists ( 'TCPDI' )) $pdf = new TCPDI ( $pagetype , $metric , $format );
else if ( class_exists ( 'FPDI' )) $pdf = new FPDI ( $pagetype , $metric , $format );
2012-12-04 20:51:45 +01:00
else $pdf = new TCPDF ( $pagetype , $metric , $format );
// For TCPDF, we specify permission we want to block
$pdfrights = array ( 'modify' , 'copy' );
2014-04-07 09:54:24 +02:00
$pdfuserpass = '' ; // Password for the end user
$pdfownerpass = NULL ; // Password of the owner, created randomly if not defined
2011-09-17 03:05:44 +02:00
$pdf -> SetProtection ( $pdfrights , $pdfuserpass , $pdfownerpass );
}
else
{
2015-03-02 01:38:40 +01:00
if ( class_exists ( 'TCPDI' )) $pdf = new TCPDI ( $pagetype , $metric , $format );
else if ( class_exists ( 'FPDI' )) $pdf = new FPDI ( $pagetype , $metric , $format );
2011-09-17 03:05:44 +02:00
else $pdf = new TCPDF ( $pagetype , $metric , $format );
}
2012-12-04 20:51:45 +01:00
// If we use FPDF class, we may need to add method writeHTMLCell
if ( ! empty ( $conf -> global -> MAIN_USE_FPDF ) && ! method_exists ( $pdf , 'writeHTMLCell' ))
{
2012-12-19 13:06:45 +01:00
// Declare here a class to overwrite FPDI to add method writeHTMLCell
2012-12-04 20:51:45 +01:00
/**
2014-05-01 19:17:45 +02:00
* This class is an enhanced FPDI class that support method writeHTMLCell
2014-04-07 09:54:24 +02:00
*/
2012-12-04 20:51:45 +01:00
class FPDI_DolExtended extends FPDI
2015-11-13 12:48:17 +01:00
{
2012-12-19 20:59:08 +01:00
/**
* __call
*
* @ param string $method Method
* @ param mixed $args Arguments
* @ return void
*/
2012-12-04 20:51:45 +01:00
public function __call ( $method , $args )
{
if ( isset ( $this -> $method )) {
$func = $this -> $method ;
$func ( $args );
}
}
2012-12-19 20:59:08 +01:00
/**
* writeHTMLCell
*
2013-08-22 16:49:23 +02:00
* @ param int $w Width
* @ param int $h Height
* @ param int $x X
* @ param int $y Y
* @ param string $html Html
* @ param int $border Border
* @ param int $ln Ln
* @ param boolean $fill Fill
* @ param boolean $reseth Reseth
* @ param string $align Align
* @ param boolean $autopadding Autopadding
* @ return void
2012-12-19 20:59:08 +01:00
*/
2012-12-04 20:51:45 +01:00
public function writeHTMLCell ( $w , $h , $x , $y , $html = '' , $border = 0 , $ln = 0 , $fill = false , $reseth = true , $align = '' , $autopadding = true )
{
$this -> SetXY ( $x , $y );
$val = str_replace ( '<br>' , " \n " , $html );
2013-07-14 16:35:02 +02:00
//$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
$val = dol_string_nohtmltag ( $val , false , 'UTF-8' );
2012-12-04 20:51:45 +01:00
$this -> MultiCell ( $w , $h , $val , $border , $align , $fill );
}
}
$pdf2 = new FPDI_DolExtended ( $pagetype , $metric , $format );
unset ( $pdf );
$pdf = $pdf2 ;
}
2011-09-17 03:05:44 +02:00
return $pdf ;
2010-12-21 00:43:45 +01:00
}
2012-12-04 20:51:45 +01:00
2010-11-13 03:58:29 +01:00
/**
* Return font name to use for PDF generation
2011-09-17 03:05:44 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Output langs object
* @ return string Name of font to use
2010-11-13 03:58:29 +01:00
*/
function pdf_getPDFFont ( $outputlangs )
{
2012-10-31 19:38:16 +01:00
global $conf ;
if ( ! empty ( $conf -> global -> MAIN_PDF_FORCE_FONT )) return $conf -> global -> MAIN_PDF_FORCE_FONT ;
$font = 'Helvetica' ; // By default, for FPDI, or ISO language on TCPDF
2011-09-17 03:05:44 +02:00
if ( class_exists ( 'TCPDF' )) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
{
if ( $outputlangs -> trans ( 'FONTFORPDF' ) != 'FONTFORPDF' )
{
$font = $outputlangs -> trans ( 'FONTFORPDF' );
}
}
return $font ;
2010-11-13 03:58:29 +01:00
}
2010-12-01 22:16:28 +01:00
/**
* Return font size to use for PDF generation
2011-09-17 03:05:44 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Output langs object
* @ return int Size of font to use
2010-12-01 22:16:28 +01:00
*/
function pdf_getPDFFontSize ( $outputlangs )
{
2011-09-17 03:05:44 +02:00
$size = 10 ; // By default, for FPDI or ISO language on TCPDF
if ( class_exists ( 'TCPDF' )) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
{
if ( $outputlangs -> trans ( 'FONTSIZEFORPDF' ) != 'FONTSIZEFORPDF' )
{
$size = ( int ) $outputlangs -> trans ( 'FONTSIZEFORPDF' );
}
}
return $size ;
2010-12-01 22:16:28 +01:00
}
2010-09-19 18:25:24 +02:00
2012-04-01 23:57:15 +02:00
/**
2014-04-07 09:54:24 +02:00
* Return height to use for Logo onto PDF
2012-04-01 23:57:15 +02:00
*
* @ param string $logo Full path to logo file to use
2013-07-03 16:06:42 +02:00
* @ param bool $url Image with url ( true or false )
2012-04-01 23:57:15 +02:00
* @ return number
*/
2013-07-03 16:06:42 +02:00
function pdf_getHeightForLogo ( $logo , $url = false )
2012-04-01 23:57:15 +02:00
{
2014-08-30 22:57:37 +02:00
global $conf ;
2014-09-14 12:06:38 +02:00
$height = ( empty ( $conf -> global -> MAIN_DOCUMENTS_LOGO_HEIGHT ) ? 22 : $conf -> global -> MAIN_DOCUMENTS_LOGO_HEIGHT );
2014-08-30 22:57:37 +02:00
$maxwidth = 130 ;
2013-04-04 13:58:33 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
2013-07-03 16:06:42 +02:00
$tmp = dol_getImageSize ( $logo , $url );
2013-04-04 13:58:33 +02:00
if ( $tmp [ 'height' ])
{
$width = round ( $height * $tmp [ 'width' ] / $tmp [ 'height' ]);
if ( $width > $maxwidth ) $height = $height * $maxwidth / $width ;
}
//print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
return $height ;
2012-04-01 23:57:15 +02:00
}
2015-09-18 12:10:47 +02:00
/**
* Function to try to calculate height of a HTML Content
2016-06-30 15:49:57 +02:00
*
2015-09-18 12:10:47 +02:00
* @ param TCPDF $pdf PDF initialized object
* @ param string $htmlcontent HTML Contect
* @ see getStringHeight
*/
function pdfGetHeightForHtmlContent ( & $pdf , $htmlcontent )
{
// store current object
$pdf -> startTransaction ();
// store starting values
$start_y = $pdf -> GetY ();
2015-10-19 14:55:01 +02:00
//var_dump($start_y);
2015-09-18 12:10:47 +02:00
$start_page = $pdf -> getPage ();
2015-10-19 14:55:01 +02:00
// call printing functions with content
2015-09-18 12:10:47 +02:00
$pdf -> writeHTMLCell ( 0 , 0 , 0 , $start_y , $htmlcontent , 0 , 1 , false , true , 'J' , true );
// get the new Y
$end_y = $pdf -> GetY ();
$end_page = $pdf -> getPage ();
// calculate height
$height = 0 ;
if ( $end_page == $start_page ) {
$height = $end_y - $start_y ;
}
2016-06-30 15:49:57 +02:00
else
2015-09-18 12:10:47 +02:00
{
for ( $page = $start_page ; $page <= $end_page ; ++ $page ) {
2016-06-23 10:48:52 +02:00
$pdf -> setPage ( $page );
2016-07-28 23:51:09 +02:00
$tmpm = $pdf -> getMargins ();
$tMargin = $tmpm [ 'top' ];
2015-09-18 12:10:47 +02:00
if ( $page == $start_page ) {
// first page
2016-07-28 23:51:09 +02:00
$height = $pdf -> getPageHeight () - $start_y - $pdf -> getBreakMargin ();
2015-09-18 12:10:47 +02:00
} elseif ( $page == $end_page ) {
// last page
2016-07-28 23:51:09 +02:00
$height = $end_y - $tMargin ;
2015-09-18 12:10:47 +02:00
} else {
2016-07-28 23:51:09 +02:00
$height = $pdf -> getPageHeight () - $tMargin - $pdf -> getBreakMargin ();
2015-09-18 12:10:47 +02:00
}
}
}
// restore previous object
2016-06-30 15:49:57 +02:00
$pdf = $pdf -> rollbackTransaction ();
2015-09-18 12:10:47 +02:00
return $height ;
}
2015-02-27 15:08:08 +01:00
/**
* Returns the name of the thirdparty
*
2016-02-24 13:29:37 +01:00
* @ param Societe | Contact $thirdparty Contact or thirdparty
* @ param Translate $outputlangs Output language
* @ param int $includealias 1 = Include alias name after name
2017-07-09 15:15:23 +02:00
* @ return string String with name of thirdparty ( + alias if requested )
2015-02-27 15:08:08 +01:00
*/
2016-02-24 13:29:37 +01:00
function pdfBuildThirdpartyName ( $thirdparty , Translate $outputlangs , $includealias = 0 )
2015-02-27 15:08:08 +01:00
{
2017-07-09 15:15:23 +02:00
global $conf ;
2016-02-24 13:29:37 +01:00
// Recipient name
2015-02-27 15:08:08 +01:00
$socname = '' ;
if ( $thirdparty instanceof Societe ) {
$socname .= $thirdparty -> name ;
2017-07-09 15:15:23 +02:00
if (( $includealias || ! empty ( $conf -> global -> PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME )) && ! empty ( $thirdparty -> name_alias )) {
2016-02-24 13:29:37 +01:00
$socname .= " \n " . $thirdparty -> name_alias ;
}
2015-02-27 15:08:08 +01:00
} elseif ( $thirdparty instanceof Contact ) {
$socname = $thirdparty -> socname ;
} else {
2016-04-22 19:07:32 +02:00
throw new InvalidArgumentException ( 'Parameter 1=$thirdparty is not a Societe nor Contact' );
2015-02-27 15:08:08 +01:00
}
return $outputlangs -> convToOutputCharset ( $socname );
}
2012-04-01 23:57:15 +02:00
2016-02-25 02:44:34 +01:00
2010-09-19 18:25:24 +02:00
/**
2016-02-25 20:54:37 +01:00
* Return a string with full address formated for output on documents
2011-09-12 19:43:31 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Output langs object
* @ param Societe $sourcecompany Source company object
* @ param Societe $targetcompany Target company object
* @ param Contact $targetcontact Target contact object
* @ param int $usecontact Use contact instead of company
2016-05-19 17:36:25 +02:00
* @ param int $mode Address type ( 'source' , 'target' , 'targetwithdetails' , 'targetwithdetails_xxx' : target but include also phone / fax / email / url )
2016-02-25 18:30:31 +01:00
* @ param Object $object Object we want to build document for
2011-12-06 00:39:24 +01:00
* @ return string String with full address
2010-03-30 20:03:01 +02:00
*/
2016-02-25 18:30:31 +01:00
function pdf_build_address ( $outputlangs , $sourcecompany , $targetcompany = '' , $targetcontact = '' , $usecontact = 0 , $mode = 'source' , $object = null )
2010-03-30 20:03:01 +02:00
{
2016-02-25 20:54:37 +01:00
global $conf , $hookmanager ;
2011-09-17 03:05:44 +02:00
if ( $mode == 'source' && ! is_object ( $sourcecompany )) return - 1 ;
if ( $mode == 'target' && ! is_object ( $targetcompany )) return - 1 ;
2016-02-25 20:54:37 +01:00
if ( ! empty ( $sourcecompany -> state_id ) && empty ( $sourcecompany -> departement )) $sourcecompany -> departement = getState ( $sourcecompany -> state_id ); //TODO deprecated
if ( ! empty ( $sourcecompany -> state_id ) && empty ( $sourcecompany -> state )) $sourcecompany -> state = getState ( $sourcecompany -> state_id );
2017-11-08 11:42:02 +01:00
if ( ! empty ( $sourcecompany -> state_id ) && ! isset ( $sourcecompany -> departement_id )) $sourcecompany -> departement_id = getState ( $sourcecompany -> state_id , '2' );
2016-02-25 20:54:37 +01:00
if ( ! empty ( $targetcompany -> state_id ) && empty ( $targetcompany -> departement )) $targetcompany -> departement = getState ( $targetcompany -> state_id ); //TODO deprecated
if ( ! empty ( $targetcompany -> state_id ) && empty ( $targetcompany -> state )) $targetcompany -> state = getState ( $targetcompany -> state_id );
2017-11-08 11:42:02 +01:00
if ( ! empty ( $targetcompany -> state_id ) && ! isset ( $targetcompany -> departement_id )) $targetcompany -> departement_id = getState ( $targetcompany -> state_id , '2' );
2011-09-17 03:05:44 +02:00
2016-02-25 20:54:37 +01:00
$reshook = 0 ;
$stringaddress = '' ;
if ( is_object ( $hookmanager ))
2011-09-17 03:05:44 +02:00
{
2016-02-25 20:54:37 +01:00
$parameters = array ( 'sourcecompany' =>& $sourcecompany , 'targetcompany' =>& $targetcompany , 'targetcontact' => $targetcontact , 'outputlangs' => $outputlangs , 'mode' => $mode , 'usecontact' => $usecontact );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_build_address' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
$stringaddress .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2016-02-25 20:54:37 +01:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2016-02-25 20:54:37 +01:00
if ( $mode == 'source' )
{
$withCountry = 0 ;
if ( ! empty ( $sourcecompany -> country_code ) && ( $targetcompany -> country_code != $sourcecompany -> country_code )) $withCountry = 1 ;
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $sourcecompany , $withCountry , " \n " , $outputlangs )) . " \n " ;
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
if ( empty ( $conf -> global -> MAIN_PDF_DISABLESOURCEDETAILS ))
{
// Phone
2017-10-09 09:26:25 +02:00
if ( $sourcecompany -> phone ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " PhoneShort " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> phone );
2016-02-25 20:54:37 +01:00
// Fax
if ( $sourcecompany -> fax ) $stringaddress .= ( $stringaddress ? ( $sourcecompany -> phone ? " - " : " \n " ) : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> fax );
// EMail
2017-10-09 09:26:25 +02:00
if ( $sourcecompany -> email ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> email );
2016-02-25 20:54:37 +01:00
// Web
2017-10-09 09:26:25 +02:00
if ( $sourcecompany -> url ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> url );
2016-02-25 20:54:37 +01:00
}
}
2016-06-30 15:49:57 +02:00
2016-05-19 17:36:25 +02:00
if ( $mode == 'target' || preg_match ( '/targetwithdetails/' , $mode ))
2016-02-25 20:54:37 +01:00
{
if ( $usecontact )
{
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $targetcontact -> getFullName ( $outputlangs , 1 ));
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
if ( ! empty ( $targetcontact -> address )) {
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcontact ));
2016-02-25 20:54:37 +01:00
} else {
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcompany ));
2016-02-25 20:54:37 +01:00
}
// Country
if ( ! empty ( $targetcontact -> country_code ) && $targetcontact -> country_code != $sourcecompany -> country_code ) {
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcontact -> country_code ));
2016-02-25 20:54:37 +01:00
}
else if ( empty ( $targetcontact -> country_code ) && ! empty ( $targetcompany -> country_code ) && ( $targetcompany -> country_code != $sourcecompany -> country_code )) {
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> country_code ));
2016-02-25 20:54:37 +01:00
}
2016-06-30 15:49:57 +02:00
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || preg_match ( '/targetwithdetails/' , $mode ))
2016-02-25 20:54:37 +01:00
{
// Phone
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_phone/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( ! empty ( $targetcontact -> phone_pro ) || ! empty ( $targetcontact -> phone_mobile )) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " ;
2016-05-19 17:36:25 +02:00
if ( ! empty ( $targetcontact -> phone_pro )) $stringaddress .= $outputlangs -> convToOutputCharset ( $targetcontact -> phone_pro );
if ( ! empty ( $targetcontact -> phone_pro ) && ! empty ( $targetcontact -> phone_mobile )) $stringaddress .= " / " ;
if ( ! empty ( $targetcontact -> phone_mobile )) $stringaddress .= $outputlangs -> convToOutputCharset ( $targetcontact -> phone_mobile );
}
2016-02-25 20:54:37 +01:00
// Fax
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcontact -> fax ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> fax );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
// EMail
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcontact -> email ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> email );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
// Web
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcontact -> url ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> url );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
}
}
else
{
2017-10-06 15:06:59 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcompany ));
2016-02-25 20:54:37 +01:00
// Country
2017-10-09 09:26:25 +02:00
if ( ! empty ( $targetcompany -> country_code ) && $targetcompany -> country_code != $sourcecompany -> country_code ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> country_code ));
2016-06-30 15:49:57 +02:00
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || preg_match ( '/targetwithdetails/' , $mode ))
2016-02-25 20:54:37 +01:00
{
// Phone
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_phone/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( ! empty ( $targetcompany -> phone ) || ! empty ( $targetcompany -> phone_mobile )) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " ;
2016-05-19 17:36:25 +02:00
if ( ! empty ( $targetcompany -> phone )) $stringaddress .= $outputlangs -> convToOutputCharset ( $targetcompany -> phone );
if ( ! empty ( $targetcompany -> phone ) && ! empty ( $targetcompany -> phone_mobile )) $stringaddress .= " / " ;
if ( ! empty ( $targetcompany -> phone_mobile )) $stringaddress .= $outputlangs -> convToOutputCharset ( $targetcompany -> phone_mobile );
}
2016-02-25 20:54:37 +01:00
// Fax
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcompany -> fax ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> fax );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
// EMail
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcompany -> email ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> email );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
// Web
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcompany -> url ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> url );
2016-05-19 17:36:25 +02:00
}
2016-02-25 20:54:37 +01:00
}
}
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
// Intra VAT
if ( empty ( $conf -> global -> MAIN_TVAINTRA_NOT_IN_ADDRESS ))
{
2017-10-09 09:26:25 +02:00
if ( $targetcompany -> tva_intra ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> tva_intra );
2016-02-25 20:54:37 +01:00
}
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
// Professionnal Ids
if ( ! empty ( $conf -> global -> MAIN_PROFID1_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof1 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId1 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof1 );
2016-02-25 20:54:37 +01:00
}
if ( ! empty ( $conf -> global -> MAIN_PROFID2_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof2 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId2 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof2 );
2016-02-25 20:54:37 +01:00
}
if ( ! empty ( $conf -> global -> MAIN_PROFID3_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof3 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId3 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof3 );
2016-02-25 20:54:37 +01:00
}
if ( ! empty ( $conf -> global -> MAIN_PROFID4_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof4 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId4 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof4 );
2016-02-25 20:54:37 +01:00
}
2016-05-19 17:36:25 +02:00
if ( ! empty ( $conf -> global -> MAIN_PROFID5_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof5 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId5 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof5 );
2016-05-19 17:36:25 +02:00
}
if ( ! empty ( $conf -> global -> MAIN_PROFID6_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof6 ))
{
$tmp = $outputlangs -> transcountrynoentities ( " ProfId6 " , $targetcompany -> country_code );
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) $tmp = $reg [ 1 ];
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof6 );
2016-05-19 17:36:25 +02:00
}
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
// Public note
if ( ! empty ( $conf -> global -> MAIN_PUBLIC_NOTE_IN_ADDRESS ))
{
if ( $mode == 'source' && ! empty ( $sourcecompany -> note_public ))
{
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . dol_string_nohtmltag ( $sourcecompany -> note_public );
2016-02-25 20:54:37 +01:00
}
2016-05-19 17:36:25 +02:00
if (( $mode == 'target' || preg_match ( '/targetwithdetails/' , $mode )) && ! empty ( $targetcompany -> note_public ))
2016-02-25 20:54:37 +01:00
{
2017-10-09 09:26:25 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . dol_string_nohtmltag ( $targetcompany -> note_public );
2016-02-25 20:54:37 +01:00
}
}
}
2011-09-17 03:05:44 +02:00
}
2016-06-30 15:49:57 +02:00
2011-09-17 03:05:44 +02:00
return $stringaddress ;
2010-03-30 20:03:01 +02:00
}
2009-06-15 20:57:34 +02:00
/**
2010-08-31 23:02:29 +02:00
* Show header of page for PDF generation
2011-09-12 19:43:31 +02:00
*
2016-08-11 15:23:00 +02:00
* @ param TCPDF $pdf Object PDF
2011-09-12 20:15:11 +02:00
* @ param Translate $outputlangs Object lang for output
2011-09-12 19:43:31 +02:00
* @ param int $page_height Height of page
2011-12-06 00:39:24 +01:00
* @ return void
2009-06-15 20:57:34 +02:00
*/
function pdf_pagehead ( & $pdf , $outputlangs , $page_height )
{
2011-09-17 03:05:44 +02:00
global $conf ;
2009-06-15 20:57:34 +02:00
2011-09-17 03:05:44 +02:00
// Add a background image on document
2015-11-05 14:16:13 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF )) // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
2011-09-17 03:05:44 +02:00
{
2014-08-04 10:11:56 +02:00
$pdf -> SetAutoPageBreak ( 0 , 0 ); // Disable auto pagebreak before adding image
2014-06-06 12:57:12 +02:00
$pdf -> Image ( $conf -> mycompany -> dir_output . '/logos/' . $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF , ( isset ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF_X ) ? $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF_X : 0 ), ( isset ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF_Y ) ? $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF_Y : 0 ), 0 , $page_height );
2014-08-04 10:11:56 +02:00
$pdf -> SetAutoPageBreak ( 1 , 0 ); // Restore pagebreak
2011-09-17 03:05:44 +02:00
}
2009-06-15 20:57:34 +02:00
}
2017-04-17 13:02:40 +02:00
/**
2017-10-31 11:17:44 +01:00
* Return array of possible substitutions for PDF content ( without external module substitutions ) .
2017-04-17 13:02:40 +02:00
*
2017-10-31 11:17:44 +01:00
* @ param Translate $outputlangs Output language
* @ param array $exclude Array of family keys we want to exclude . For example array ( 'mycompany' , 'object' , 'date' , 'user' , ... )
* @ param Object $object Object
2017-11-03 11:44:31 +01:00
* @ param int $onlykey 1 = Do not calculate some heavy values of keys ( performance enhancement when we need only the keys ), 2 = Values are truncated and html sanitized ( to use for help tooltip )
2017-10-31 11:17:44 +01:00
* @ return array Array of substitutions
2017-04-17 13:02:40 +02:00
*/
2017-11-03 11:44:31 +01:00
function pdf_getSubstitutionArray ( $outputlangs , $exclude = null , $object = null , $onlykey = 0 )
2017-04-17 13:02:40 +02:00
{
2017-11-03 11:44:31 +01:00
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , $onlykey , $exclude , $object );
2017-06-01 01:53:55 +02:00
$substitutionarray [ '__FROM_NAME__' ] = '__FROM_NAME__' ;
$substitutionarray [ '__FROM_EMAIL__' ] = '__FROM_EMAIL__' ;
return $substitutionarray ;
2017-04-17 13:02:40 +02:00
}
2010-09-01 16:13:51 +02:00
/**
* Add a draft watermark on PDF files
2011-09-12 19:43:31 +02:00
*
2017-06-01 01:53:55 +02:00
* @ param TCPDF $pdf Object PDF
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Object lang
* @ param int $h Height of PDF
* @ param int $w Width of PDF
2014-04-07 09:54:24 +02:00
* @ param string $unit Unit of height ( mm , pt , ... )
2011-12-06 00:39:24 +01:00
* @ param string $text Text to show
* @ return void
2010-09-01 16:13:51 +02:00
*/
function pdf_watermark ( & $pdf , $outputlangs , $h , $w , $unit , $text )
{
2017-04-17 13:02:40 +02:00
global $langs , $mysoc , $user ;
2017-06-01 01:53:55 +02:00
2011-09-17 03:05:44 +02:00
// Print Draft Watermark
if ( $unit == 'pt' ) $k = 1 ;
elseif ( $unit == 'mm' ) $k = 72 / 25.4 ;
elseif ( $unit == 'cm' ) $k = 72 / 2.54 ;
elseif ( $unit == 'in' ) $k = 72 ;
2017-04-17 13:02:40 +02:00
// Make substitution
2017-06-01 13:32:20 +02:00
$substitutionarray = pdf_getSubstitutionArray ( $outputlangs , null , null );
complete_substitutions_array ( $substitutionarray , $outputlangs , null );
$text = make_substitutions ( $text , $substitutionarray , $outputlangs );
2017-04-17 13:02:40 +02:00
$text = $outputlangs -> convToOutputCharset ( $text );
2017-06-01 01:53:55 +02:00
2013-07-25 18:56:09 +02:00
$savx = $pdf -> getX (); $savy = $pdf -> getY ();
2013-09-25 19:58:22 +02:00
2013-07-25 18:56:09 +02:00
$watermark_angle = atan ( $h / $w ) / 2 ;
$watermark_x_pos = 0 ;
$watermark_y_pos = $h / 3 ;
$watermark_x = $w / 2 ;
$watermark_y = $h / 3 ;
$pdf -> SetFont ( '' , 'B' , 40 );
2011-09-17 03:05:44 +02:00
$pdf -> SetTextColor ( 255 , 192 , 203 );
//rotate
$pdf -> _out ( sprintf ( 'q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm' , cos ( $watermark_angle ), sin ( $watermark_angle ), - sin ( $watermark_angle ), cos ( $watermark_angle ), $watermark_x * $k ,( $h - $watermark_y ) * $k , - $watermark_x * $k , - ( $h - $watermark_y ) * $k ));
//print watermark
2013-07-25 18:56:09 +02:00
$pdf -> SetXY ( $watermark_x_pos , $watermark_y_pos );
$pdf -> Cell ( $w - 20 , 25 , $outputlangs -> convToOutputCharset ( $text ), " " , 2 , " C " , 0 );
2011-09-17 03:05:44 +02:00
//antirotate
$pdf -> _out ( 'Q' );
2013-07-25 18:56:09 +02:00
$pdf -> SetXY ( $savx , $savy );
2010-09-01 16:13:51 +02:00
}
2009-01-28 16:09:37 +01:00
/**
2012-04-02 20:08:08 +02:00
* Show bank informations for PDF generation
2011-09-17 03:05:44 +02:00
*
2016-08-11 15:23:00 +02:00
* @ param TCPDF $pdf Object PDF
2012-04-02 20:08:08 +02:00
* @ param Translate $outputlangs Object lang
* @ param int $curx X
* @ param int $cury Y
* @ param Account $account Bank account object
2014-12-11 10:13:44 +01:00
* @ param int $onlynumber Output only number ( bank + desk + key + number according to country , but without name of bank and domiciliation )
2012-04-02 20:08:08 +02:00
* @ param int $default_font_size Default font size
2014-04-23 16:53:02 +02:00
* @ return float The Y PDF position
2009-01-28 16:09:37 +01:00
*/
2012-04-02 20:08:08 +02:00
function pdf_bank ( & $pdf , $outputlangs , $curx , $cury , $account , $onlynumber = 0 , $default_font_size = 10 )
2009-01-28 16:09:37 +01:00
{
2011-09-17 03:05:44 +02:00
global $mysoc , $conf ;
2016-05-19 17:36:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formbank.class.php' ;
2016-06-30 15:49:57 +02:00
2013-03-24 14:01:33 +01:00
$diffsizetitle = ( empty ( $conf -> global -> PDF_DIFFSIZE_TITLE ) ? 3 : $conf -> global -> PDF_DIFFSIZE_TITLE );
$diffsizecontent = ( empty ( $conf -> global -> PDF_DIFFSIZE_CONTENT ) ? 4 : $conf -> global -> PDF_DIFFSIZE_CONTENT );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2011-09-17 03:05:44 +02:00
if ( empty ( $onlynumber ))
{
2013-03-24 14:01:33 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizetitle );
2011-09-17 03:05:44 +02:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( 'PaymentByTransferOnThisBankAccount' ) . ':' , 0 , 'L' , 0 );
$cury += 4 ;
}
$outputlangs -> load ( " banks " );
2014-12-11 10:13:44 +01:00
// Use correct name of bank id according to country
$bickey = " BICNumber " ;
if ( $account -> getCountryCode () == 'IN' ) $bickey = " SWIFT " ;
2011-09-17 03:05:44 +02:00
// Get format of bank account according to its country
$usedetailedbban = $account -> useDetailedBBAN ();
2015-01-31 13:00:51 +01:00
//$onlynumber=0; $usedetailedbban=1; // For tests
2011-09-17 03:05:44 +02:00
if ( $usedetailedbban )
{
$savcurx = $curx ;
if ( empty ( $onlynumber ))
{
2013-03-24 14:01:33 +01:00
$pdf -> SetFont ( '' , '' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2012-04-02 20:08:08 +02:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
2011-09-17 03:05:44 +02:00
$cury += 3 ;
}
2015-11-14 14:55:14 +01:00
if ( empty ( $conf -> global -> PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN )) // Note that some countries still need bank number, BIC/IBAN not enought for them
2011-09-17 03:05:44 +02:00
{
2015-11-14 14:55:14 +01:00
// Note:
// bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
// desk = code guichet (FR), used only when $usedetailedbban = 1
// number = account number
// key = check control key used only when $usedetailedbban = 1
if ( empty ( $onlynumber )) $pdf -> line ( $curx + 1 , $cury + 1 , $curx + 1 , $cury + 6 );
2016-06-30 15:49:57 +02:00
2016-03-19 23:00:33 +01:00
foreach ( $account -> getFieldsToShow () as $val )
{
$pdf -> SetXY ( $curx , $cury + 4 );
$pdf -> SetFont ( '' , '' , $default_font_size - 3 );
if ( $val == 'BankCode' ) {
// Bank code
$tmplength = 18 ;
$content = $account -> code_banque ;
} elseif ( $val == 'DeskCode' ) {
// Desk
$tmplength = 18 ;
$content = $account -> code_guichet ;
} elseif ( $val == 'BankAccountNumber' ) {
// Number
$tmplength = 24 ;
$content = $account -> number ;
} elseif ( $val == 'BankAccountNumberKey' ) {
// Key
$tmplength = 13 ;
$content = $account -> cle_rib ;
2016-06-30 15:49:57 +02:00
} elseif ( $val == 'IBAN' || $val == 'BIC' ) {
// Key
$tmplength = 0 ;
$content = '' ;
2016-03-19 23:00:33 +01:00
} else {
2016-06-30 15:49:57 +02:00
dol_print_error ( $account -> db , 'Unexpected value for getFieldsToShow: ' . $val );
2016-03-19 23:00:33 +01:00
break ;
}
$pdf -> MultiCell ( $tmplength , 3 , $outputlangs -> convToOutputCharset ( $content ), 0 , 'C' , 0 );
$pdf -> SetXY ( $curx , $cury + 1 );
$curx += $tmplength ;
2017-08-07 15:43:42 +02:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2016-03-19 23:00:33 +01:00
$pdf -> MultiCell ( $tmplength , 3 , $outputlangs -> transnoentities ( $val ), 0 , 'C' , 0 );
if ( empty ( $onlynumber )) {
$pdf -> line ( $curx , $cury + 1 , $curx , $cury + 7 );
}
2016-05-19 17:36:25 +02:00
}
2016-06-30 15:49:57 +02:00
2015-11-14 14:55:14 +01:00
$curx = $savcurx ;
$cury += 8 ;
2011-09-17 03:05:44 +02:00
}
}
else
{
2013-03-24 14:01:33 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2012-04-02 20:08:08 +02:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
2011-09-17 03:05:44 +02:00
$cury += 3 ;
2013-03-24 14:01:33 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2012-04-02 20:08:08 +02:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " BankAccountNumber " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> number ), 0 , 'L' , 0 );
2011-09-17 03:05:44 +02:00
$cury += 3 ;
2015-07-12 16:22:06 +02:00
2013-03-24 16:17:36 +01:00
if ( $diffsizecontent <= 2 ) $cury += 1 ;
2011-09-17 03:05:44 +02:00
}
2013-03-24 14:01:33 +01:00
$pdf -> SetFont ( '' , '' , $default_font_size - $diffsizecontent );
2015-07-12 16:22:06 +02:00
2011-09-17 03:05:44 +02:00
if ( empty ( $onlynumber ) && ! empty ( $account -> domiciliation ))
{
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2011-09-17 03:05:44 +02:00
$val = $outputlangs -> transnoentities ( " Residence " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> domiciliation );
2012-04-02 20:08:08 +02:00
$pdf -> MultiCell ( 100 , 3 , $val , 0 , 'L' , 0 );
2013-03-24 16:17:36 +01:00
//$nboflines=dol_nboflines_bis($val,120);
//$cury+=($nboflines*3)+2;
2013-04-04 13:58:33 +02:00
$tmpy = $pdf -> getStringHeight ( 100 , $val );
2013-03-24 16:17:36 +01:00
$cury += $tmpy ;
2011-09-17 03:05:44 +02:00
}
2015-07-12 16:22:06 +02:00
2015-03-01 21:31:03 +01:00
if ( ! empty ( $account -> proprio ))
{
$pdf -> SetXY ( $curx , $cury );
$val = $outputlangs -> transnoentities ( " BankAccountOwner " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> proprio );
$pdf -> MultiCell ( 100 , 3 , $val , 0 , 'L' , 0 );
$tmpy = $pdf -> getStringHeight ( 100 , $val );
$cury += $tmpy ;
2017-08-07 15:43:42 +02:00
$cur += 1 ;
2015-03-01 21:31:03 +01:00
}
2015-07-12 16:22:06 +02:00
2011-09-17 03:05:44 +02:00
else if ( ! $usedetailedbban ) $cury += 1 ;
2015-07-12 16:22:06 +02:00
2014-12-11 10:13:44 +01:00
// Use correct name of bank id according to country
2016-03-19 19:39:18 +01:00
$ibankey = FormBank :: getIBANLabel ( $account );
2016-05-19 17:36:25 +02:00
2014-12-11 10:13:44 +01:00
if ( ! empty ( $account -> iban ))
{
2015-09-01 10:56:55 +02:00
//Remove whitespaces to ensure we are dealing with the format we expect
$ibanDisplay_temp = str_replace ( ' ' , '' , $outputlangs -> convToOutputCharset ( $account -> iban ));
2014-12-11 10:13:44 +01:00
$ibanDisplay = " " ;
2015-11-13 12:48:17 +01:00
$nbIbanDisplay_temp = dol_strlen ( $ibanDisplay_temp );
for ( $i = 0 ; $i < $nbIbanDisplay_temp ; $i ++ )
2014-12-11 10:13:44 +01:00
{
$ibanDisplay .= $ibanDisplay_temp [ $i ];
if ( $i % 4 == 3 && $i > 0 ) $ibanDisplay .= " " ;
}
$pdf -> SetFont ( '' , 'B' , $default_font_size - 3 );
$pdf -> SetXY ( $curx , $cury );
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $ibankey ) . ': ' . $ibanDisplay , 0 , 'L' , 0 );
$cury += 3 ;
}
2013-03-24 16:17:36 +01:00
if ( ! empty ( $account -> bic ))
{
2014-12-11 10:13:44 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - 3 );
2013-03-24 16:17:36 +01:00
$pdf -> SetXY ( $curx , $cury );
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $bickey ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bic ), 0 , 'L' , 0 );
}
2011-09-17 03:05:44 +02:00
return $pdf -> getY ();
2009-01-28 16:09:37 +01:00
}
/**
2011-12-06 00:39:24 +01:00
* Show footer of page for PDF generation
2011-09-12 19:43:31 +02:00
*
2016-08-11 15:23:00 +02:00
* @ param TCPDF $pdf The PDF factory
2012-02-04 14:39:47 +01:00
* @ param Translate $outputlangs Object lang for output
2011-12-06 00:39:24 +01:00
* @ param string $paramfreetext Constant name of free text
2012-02-04 14:39:47 +01:00
* @ param Societe $fromcompany Object company
2012-08-08 04:12:20 +02:00
* @ param int $marge_basse Margin bottom we use for the autobreak
* @ param int $marge_gauche Margin left ( no more used )
* @ param int $page_hauteur Page height ( no more used )
2011-12-06 00:39:24 +01:00
* @ param Object $object Object shown in PDF
2016-05-21 12:21:17 +02:00
* @ param int $showdetails Show company adress details into footer ( 0 = Nothing , 1 = Show address , 2 = Show managers , 3 = Both )
2012-10-30 13:11:17 +01:00
* @ param int $hidefreetext 1 = Hide free text , 0 = Show free text
2012-08-08 04:12:20 +02:00
* @ return int Return height of bottom margin including footer text
2009-01-28 16:09:37 +01:00
*/
2012-10-30 13:11:17 +01:00
function pdf_pagefoot ( & $pdf , $outputlangs , $paramfreetext , $fromcompany , $marge_basse , $marge_gauche , $page_hauteur , $object , $showdetails = 0 , $hidefreetext = 0 )
2009-01-28 16:09:37 +01:00
{
2017-04-17 13:02:40 +02:00
global $conf , $user , $mysoc ;
2009-01-28 16:09:37 +01:00
2011-09-17 03:05:44 +02:00
$outputlangs -> load ( " dict " );
$line = '' ;
2009-01-28 16:09:37 +01:00
2012-08-08 04:12:20 +02:00
$dims = $pdf -> getPageDimensions ();
2011-09-17 03:05:44 +02:00
// Line of free text
2012-10-30 13:11:17 +01:00
if ( empty ( $hidefreetext ) && ! empty ( $conf -> global -> $paramfreetext ))
2011-09-17 03:05:44 +02:00
{
2017-06-01 13:32:20 +02:00
$substitutionarray = pdf_getSubstitutionArray ( $outputlangs , null , $object );
2017-04-17 13:02:40 +02:00
// More substitution keys
$substitutionarray [ '__FROM_NAME__' ] = $fromcompany -> name ;
$substitutionarray [ '__FROM_EMAIL__' ] = $fromcompany -> email ;
2017-06-01 13:32:20 +02:00
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
$newfreetext = make_substitutions ( $conf -> global -> $paramfreetext , $substitutionarray , $outputlangs );
2017-06-17 00:13:09 +02:00
// Make a change into HTML code to allow to include images from medias directory.
// <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
// become
2017-07-03 02:09:14 +02:00
// <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
2017-06-17 00:13:09 +02:00
$newfreetext = preg_replace ( '/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/' , '\1' . DOL_DATA_ROOT . '/medias/\2\3' , $newfreetext );
2011-09-17 03:05:44 +02:00
$line .= $outputlangs -> convToOutputCharset ( $newfreetext );
}
// First line of company infos
2014-08-25 19:16:37 +02:00
$line1 = " " ; $line2 = " " ; $line3 = " " ; $line4 = " " ;
2011-09-17 03:05:44 +02:00
2016-05-19 17:36:25 +02:00
if ( $showdetails == 1 || $showdetails == 3 )
2011-09-17 03:05:44 +02:00
{
// Company name
if ( $fromcompany -> name )
{
$line1 .= ( $line1 ? " - " : " " ) . $outputlangs -> transnoentities ( " RegisteredOffice " ) . " : " . $fromcompany -> name ;
}
// Address
if ( $fromcompany -> address )
{
2016-04-23 17:10:56 +02:00
$line1 .= ( $line1 ? " - " : " " ) . str_replace ( " \n " , " , " , $fromcompany -> address );
2011-09-17 03:05:44 +02:00
}
// Zip code
if ( $fromcompany -> zip )
{
$line1 .= ( $line1 ? " - " : " " ) . $fromcompany -> zip ;
}
// Town
if ( $fromcompany -> town )
{
$line1 .= ( $line1 ? " " : " " ) . $fromcompany -> town ;
}
// Phone
if ( $fromcompany -> phone )
{
2016-04-23 17:10:56 +02:00
$line2 .= ( $line2 ? " - " : " " ) . $outputlangs -> transnoentities ( " Phone " ) . " : " . $fromcompany -> phone ;
2011-09-17 03:05:44 +02:00
}
// Fax
if ( $fromcompany -> fax )
{
2016-04-23 17:10:56 +02:00
$line2 .= ( $line2 ? " - " : " " ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $fromcompany -> fax ;
2011-09-17 03:05:44 +02:00
}
// URL
if ( $fromcompany -> url )
{
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> url ;
}
// Email
if ( $fromcompany -> email )
{
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> email ;
}
}
2016-04-23 17:10:56 +02:00
if ( $showdetails == 2 || $showdetails == 3 || ( $fromcompany -> country_code == 'DE' ))
2014-08-25 19:16:37 +02:00
{
// Managers
if ( $fromcompany -> managers )
{
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> managers ;
}
}
2011-09-17 03:05:44 +02:00
// Line 3 of company infos
// Juridical status
if ( $fromcompany -> forme_juridique_code )
{
$line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> convToOutputCharset ( getFormeJuridiqueLabel ( $fromcompany -> forme_juridique_code ));
}
// Capital
if ( $fromcompany -> capital )
{
2014-11-12 10:37:39 +01:00
$tmpamounttoshow = price2num ( $fromcompany -> capital ); // This field is a free string
if ( is_numeric ( $tmpamounttoshow ) && $tmpamounttoshow > 0 ) $line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> transnoentities ( " CapitalOf " , price ( $tmpamounttoshow , 0 , $outputlangs , 0 , 0 , 0 , $conf -> currency ));
else $line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> transnoentities ( " CapitalOf " , $tmpamounttoshow , $outputlangs );
2011-09-17 03:05:44 +02:00
}
// Prof Id 1
2011-12-29 18:07:41 +01:00
if ( $fromcompany -> idprof1 && ( $fromcompany -> country_code != 'FR' || ! $fromcompany -> idprof2 ))
2011-09-17 03:05:44 +02:00
{
2011-12-29 18:07:41 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId1 " , $fromcompany -> country_code );
2011-09-17 03:05:44 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line3 .= ( $line3 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof1 );
}
// Prof Id 2
if ( $fromcompany -> idprof2 )
{
2011-12-29 18:07:41 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId2 " , $fromcompany -> country_code );
2011-09-17 03:05:44 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line3 .= ( $line3 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof2 );
}
// Line 4 of company infos
// Prof Id 3
if ( $fromcompany -> idprof3 )
{
2011-12-29 18:07:41 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId3 " , $fromcompany -> country_code );
2011-09-17 03:05:44 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof3 );
}
// Prof Id 4
if ( $fromcompany -> idprof4 )
{
2011-12-29 18:07:41 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId4 " , $fromcompany -> country_code );
2011-09-17 03:05:44 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof4 );
}
2016-12-05 09:04:34 +01:00
// Prof Id 5
if ( $fromcompany -> idprof5 )
{
$field = $outputlangs -> transcountrynoentities ( " ProfId5 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof5 );
}
// Prof Id 6
if ( $fromcompany -> idprof6 )
{
$field = $outputlangs -> transcountrynoentities ( " ProfId6 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof6 );
}
2011-09-17 03:05:44 +02:00
// IntraCommunautary VAT
if ( $fromcompany -> tva_intra != '' )
{
$line4 .= ( $line4 ? " - " : " " ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> tva_intra );
}
$pdf -> SetFont ( '' , '' , 7 );
$pdf -> SetDrawColor ( 224 , 224 , 224 );
2014-04-07 09:54:24 +02:00
// The start of the bottom of this page footer is positioned according to # of lines
2012-10-30 13:11:17 +01:00
$freetextheight = 0 ;
2012-10-30 11:17:49 +01:00
if ( $line ) // Free text
{
2015-09-18 12:10:47 +02:00
//$line="eee<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
2016-07-28 23:51:09 +02:00
if ( empty ( $conf -> global -> PDF_ALLOW_HTML_FOR_FREE_TEXT ))
2015-09-18 12:10:47 +02:00
{
$width = 20000 ; $align = 'L' ; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
if ( ! empty ( $conf -> global -> MAIN_USE_AUTOWRAP_ON_FREETEXT )) {
$width = 200 ; $align = 'C' ;
}
$freetextheight = $pdf -> getStringHeight ( $width , $line );
}
else
{
2015-09-18 12:32:50 +02:00
$freetextheight = pdfGetHeightForHtmlContent ( $pdf , dol_htmlentitiesbr ( $line , 1 , 'UTF-8' , 0 )); // New method (works for HTML content)
2015-09-18 12:10:47 +02:00
//print '<br>'.$freetextheight;exit;
2012-10-30 11:17:49 +01:00
}
}
$marginwithfooter = $marge_basse + $freetextheight + ( ! empty ( $line1 ) ? 3 : 0 ) + ( ! empty ( $line2 ) ? 3 : 0 ) + ( ! empty ( $line3 ) ? 3 : 0 ) + ( ! empty ( $line4 ) ? 3 : 0 );
2012-08-08 04:12:20 +02:00
$posy = $marginwithfooter + 0 ;
2011-09-17 03:05:44 +02:00
if ( $line ) // Free text
{
2012-08-08 04:12:20 +02:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2015-09-18 12:10:47 +02:00
if ( empty ( $conf -> global -> PDF_ALLOW_HTML_FOR_FREE_TEXT )) // by default
{
$pdf -> MultiCell ( 0 , 3 , $line , 0 , $align , 0 );
}
else
{
2015-09-18 12:32:50 +02:00
$pdf -> writeHTMLCell ( $pdf -> page_largeur - $pdf -> margin_left - $pdf -> margin_right , $freetextheight , $dims [ 'lm' ], $dims [ 'hk' ] - $marginwithfooter , dol_htmlentitiesbr ( $line , 1 , 'UTF-8' , 0 ));
2015-09-18 12:10:47 +02:00
}
2012-10-30 11:17:49 +01:00
$posy -= $freetextheight ;
2011-09-17 03:05:44 +02:00
}
2012-10-31 13:48:59 +01:00
2011-09-17 03:05:44 +02:00
$pdf -> SetY ( - $posy );
2012-08-08 04:12:20 +02:00
$pdf -> line ( $dims [ 'lm' ], $dims [ 'hk' ] - $posy , $dims [ 'wk' ] - $dims [ 'rm' ], $dims [ 'hk' ] - $posy );
2011-09-17 03:05:44 +02:00
$posy -- ;
2011-01-16 03:26:20 +01:00
2012-07-10 20:45:07 +02:00
if ( ! empty ( $line1 ))
2011-09-17 03:05:44 +02:00
{
$pdf -> SetFont ( '' , 'B' , 7 );
2012-08-08 04:12:20 +02:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2017-03-03 14:19:46 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line1 , 0 , 'C' , 0 );
2011-09-17 03:05:44 +02:00
$posy -= 3 ;
$pdf -> SetFont ( '' , '' , 7 );
}
2011-01-16 03:26:20 +01:00
2012-07-10 20:45:07 +02:00
if ( ! empty ( $line2 ))
2011-09-17 03:05:44 +02:00
{
$pdf -> SetFont ( '' , 'B' , 7 );
2012-08-08 04:12:20 +02:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2017-03-03 14:19:46 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line2 , 0 , 'C' , 0 );
2011-09-17 03:05:44 +02:00
$posy -= 3 ;
$pdf -> SetFont ( '' , '' , 7 );
}
2012-07-10 20:45:07 +02:00
if ( ! empty ( $line3 ))
2011-09-17 03:05:44 +02:00
{
2012-08-08 04:12:20 +02:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2017-03-03 14:19:46 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line3 , 0 , 'C' , 0 );
2011-09-17 03:05:44 +02:00
}
2012-07-10 20:45:07 +02:00
if ( ! empty ( $line4 ))
2011-09-17 03:05:44 +02:00
{
$posy -= 3 ;
2012-08-08 04:12:20 +02:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2017-03-03 14:19:46 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line4 , 0 , 'C' , 0 );
2011-09-17 03:05:44 +02:00
}
// Show page nb only on iso languages (so default Helvetica font)
2014-08-05 21:18:36 +02:00
if ( strtolower ( pdf_getPDFFont ( $outputlangs )) == 'helvetica' )
2011-09-17 03:05:44 +02:00
{
2017-06-26 09:28:02 +02:00
$pdf -> SetXY ( $dims [ 'wk' ] - $dims [ 'rm' ] - 15 , - $posy );
2012-12-04 20:51:45 +01:00
//print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
2017-06-26 09:28:02 +02:00
if ( empty ( $conf -> global -> MAIN_USE_FPDF )) $pdf -> MultiCell ( 15 , 2 , $pdf -> PageNo () . '/' . $pdf -> getAliasNbPages (), 0 , 'R' , 0 );
else $pdf -> MultiCell ( 15 , 2 , $pdf -> PageNo () . '/{nb}' , 0 , 'R' , 0 );
2011-09-17 03:05:44 +02:00
}
2012-08-08 04:12:20 +02:00
return $marginwithfooter ;
2009-01-28 16:09:37 +01:00
}
2012-07-02 19:30:37 +02:00
/**
2012-03-02 14:46:18 +01:00
* Show linked objects for PDF generation
*
2016-08-11 15:23:00 +02:00
* @ param TCPDF $pdf Object PDF
2012-03-18 19:23:01 +01:00
* @ param object $object Object
* @ param Translate $outputlangs Object lang
2012-03-19 17:18:11 +01:00
* @ param int $posx X
* @ param int $posy Y
2012-04-03 17:56:54 +02:00
* @ param float $w Width of cells . If 0 , they extend up to the right margin of the page .
* @ param float $h Cell minimum height . The cell extends automatically if needed .
2012-03-18 19:23:01 +01:00
* @ param int $align Align
* @ param string $default_font_size Font size
2014-04-23 16:53:02 +02:00
* @ return float The Y PDF position
2012-07-02 19:30:37 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_writeLinkedObjects ( & $pdf , $object , $outputlangs , $posx , $posy , $w , $h , $align , $default_font_size )
2012-03-02 14:46:18 +01:00
{
2013-01-26 10:35:30 +01:00
$linkedobjects = pdf_getLinkedObjects ( $object , $outputlangs );
2012-03-02 14:46:18 +01:00
if ( ! empty ( $linkedobjects ))
{
foreach ( $linkedobjects as $linkedobject )
{
2015-12-21 12:52:10 +01:00
$reftoshow = $linkedobject [ " ref_title " ] . ' : ' . $linkedobject [ " ref_value " ];
if ( ! empty ( $linkedobject [ " date_value " ]))
{
$reftoshow .= ' / ' . $linkedobject [ " date_value " ];
}
2016-06-30 15:49:57 +02:00
2012-03-02 14:46:18 +01:00
$posy += 3 ;
$pdf -> SetXY ( $posx , $posy );
$pdf -> SetFont ( '' , '' , $default_font_size - 2 );
2015-12-21 12:52:10 +01:00
$pdf -> MultiCell ( $w , $h , $reftoshow , '' , $align );
2012-03-02 14:46:18 +01:00
}
}
2012-07-02 19:30:37 +02:00
return $pdf -> getY ();
2012-03-02 14:46:18 +01:00
}
2009-01-28 16:09:37 +01:00
/**
2010-10-27 19:25:46 +02:00
* Output line description into PDF
2011-09-12 19:43:31 +02:00
*
2016-08-11 15:23:00 +02:00
* @ param TCPDF $pdf PDF object
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object lang for output
* @ param int $w Width
* @ param int $h Height
* @ param int $posx Pos x
* @ param int $posy Pos y
* @ param int $hideref Hide reference
2014-04-07 09:54:24 +02:00
* @ param int $hidedesc Hide description
2011-12-06 00:39:24 +01:00
* @ param int $issupplierline Is it a line for a supplier object ?
2015-10-22 17:51:05 +02:00
* @ return string
2009-01-28 16:09:37 +01:00
*/
2013-01-26 10:35:30 +01:00
function pdf_writelinedesc ( & $pdf , $object , $i , $outputlangs , $w , $h , $posx , $posy , $hideref = 0 , $hidedesc = 0 , $issupplierline = 0 )
2009-01-28 16:09:37 +01:00
{
2013-01-26 10:35:30 +01:00
global $db , $conf , $langs , $hookmanager ;
2010-09-19 18:25:24 +02:00
2013-03-09 15:05:09 +01:00
$reshook = 0 ;
2016-02-25 20:54:37 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'pdf' => $pdf , 'i' => $i , 'outputlangs' => $outputlangs , 'w' => $w , 'h' => $h , 'posx' => $posx , 'posy' => $posy , 'hideref' => $hideref , 'hidedesc' => $hidedesc , 'issupplierline' => $issupplierline , 'special_code' => $special_code );
2011-11-22 14:00:03 +01:00
$action = '' ;
2011-08-11 00:47:33 +02:00
$reshook = $hookmanager -> executeHooks ( 'pdf_writelinedesc' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2016-02-25 20:54:37 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2013-03-09 15:05:09 +01:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
$labelproductservice = pdf_getlinedesc ( $object , $i , $outputlangs , $hideref , $hidedesc , $issupplierline );
// Description
2013-02-26 17:41:08 +01:00
$pdf -> writeHTMLCell ( $w , $h , $posx , $posy , $outputlangs -> convToOutputCharset ( $labelproductservice ), 0 , 1 , false , true , 'J' , true );
2016-02-25 20:54:37 +01:00
$result .= $labelproductservice ;
2011-09-17 03:05:44 +02:00
}
2016-02-25 20:54:37 +01:00
return $result ;
2010-10-27 19:25:46 +02:00
}
/**
2012-02-19 21:08:17 +01:00
* Return line description translated in outputlangs and encoded into htmlentities and with < br >
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
2012-02-19 20:31:59 +01:00
* @ param int $i Current line number ( 0 = first line , 1 = second line , ... )
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Object langs for output
* @ param int $hideref Hide reference
* @ param int $hidedesc Hide description
* @ param int $issupplierline Is it a line for a supplier object ?
* @ return string String with line
2010-10-27 19:25:46 +02:00
*/
function pdf_getlinedesc ( $object , $i , $outputlangs , $hideref = 0 , $hidedesc = 0 , $issupplierline = 0 )
{
2011-09-17 03:05:44 +02:00
global $db , $conf , $langs ;
2012-07-10 20:45:07 +02:00
$idprod = ( ! empty ( $object -> lines [ $i ] -> fk_product ) ? $object -> lines [ $i ] -> fk_product : false );
2012-08-25 12:07:18 +02:00
$label = ( ! empty ( $object -> lines [ $i ] -> label ) ? $object -> lines [ $i ] -> label : ( ! empty ( $object -> lines [ $i ] -> product_label ) ? $object -> lines [ $i ] -> product_label : '' ));
2012-07-10 20:45:07 +02:00
$desc = ( ! empty ( $object -> lines [ $i ] -> desc ) ? $object -> lines [ $i ] -> desc : ( ! empty ( $object -> lines [ $i ] -> description ) ? $object -> lines [ $i ] -> description : '' ));
$ref_supplier = ( ! empty ( $object -> lines [ $i ] -> ref_supplier ) ? $object -> lines [ $i ] -> ref_supplier : ( ! empty ( $object -> lines [ $i ] -> ref_fourn ) ? $object -> lines [ $i ] -> ref_fourn : '' )); // TODO Not yet saved for supplier invoices, only supplier orders
$note = ( ! empty ( $object -> lines [ $i ] -> note ) ? $object -> lines [ $i ] -> note : '' );
2014-03-07 11:35:16 +01:00
$dbatch = ( ! empty ( $object -> lines [ $i ] -> detail_batch ) ? $object -> lines [ $i ] -> detail_batch : false );
2011-09-17 03:05:44 +02:00
if ( $issupplierline ) $prodser = new ProductFournisseur ( $db );
else $prodser = new Product ( $db );
if ( $idprod )
{
$prodser -> fetch ( $idprod );
// If a predefined product and multilang and on other lang, we renamed label with label translated
2012-08-25 12:07:18 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ( $outputlangs -> defaultlang != $langs -> defaultlang ))
2011-09-17 03:05:44 +02:00
{
2014-06-20 16:01:08 +02:00
$translatealsoifmodified = ( ! empty ( $conf -> global -> MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED )); // By default if value was modified manually, we keep it (no translation because we don't have it)
2014-05-01 19:17:45 +02:00
2014-06-20 16:01:08 +02:00
// TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation
// ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
// Set label
// If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation.
//var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
$textwasmodified = ( $label == $prodser -> label );
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " label " ]) && ( $textwasmodified || $translatealsoifmodified )) $label = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " label " ];
// Set desc
// Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
$textwasmodified = false ;
2013-12-03 17:06:19 +01:00
if ( ! empty ( $desc ) && dol_textishtml ( $desc ) && ! empty ( $prodser -> description ) && dol_textishtml ( $prodser -> description )) {
2014-06-20 16:01:08 +02:00
$textwasmodified = ( strpos ( dol_html_entity_decode ( $desc , ENT_QUOTES | ENT_HTML401 ), dol_html_entity_decode ( $prodser -> description , ENT_QUOTES | ENT_HTML401 )) !== false );
2013-12-02 00:20:50 +01:00
} else {
2014-06-20 16:01:08 +02:00
$textwasmodified = ( $desc == $prodser -> description );
2013-12-02 00:20:50 +01:00
}
2014-06-20 16:01:08 +02:00
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ]) && ( $textwasmodified || $translatealsoifmodified )) $desc = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ];
2013-12-02 11:11:08 +01:00
2014-06-20 16:01:08 +02:00
// Set note
$textwasmodified = ( $note == $prodser -> note );
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " note " ]) && ( $textwasmodified || $translatealsoifmodified )) $note = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " note " ];
2011-09-17 03:05:44 +02:00
}
}
// Description short of product line
$libelleproduitservice = $label ;
// Description long of product line
2012-08-25 12:07:18 +02:00
if ( ! empty ( $desc ) && ( $desc != $label ))
2011-09-17 03:05:44 +02:00
{
2012-04-26 10:29:46 +02:00
if ( $libelleproduitservice && empty ( $hidedesc ))
{
2012-04-28 15:44:04 +02:00
$libelleproduitservice .= '__N__' ;
2012-04-26 10:29:46 +02:00
}
2011-09-17 03:05:44 +02:00
if ( $desc == '(CREDIT_NOTE)' && $object -> lines [ $i ] -> fk_remise_except )
{
$discount = new DiscountAbsolute ( $db );
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromCreditNote " , $discount -> ref_facture_source );
}
2011-11-16 18:58:11 +01:00
elseif ( $desc == '(DEPOSIT)' && $object -> lines [ $i ] -> fk_remise_except )
{
2013-04-04 13:58:33 +02:00
$discount = new DiscountAbsolute ( $db );
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromDeposit " , $discount -> ref_facture_source );
// Add date of deposit
if ( ! empty ( $conf -> global -> INVOICE_ADD_DEPOSIT_DATE )) echo ' (' . dol_print_date ( $discount -> datec , 'day' , '' , $outputlangs ) . ')' ;
2011-11-16 18:58:11 +01:00
}
2016-11-25 11:04:42 +01:00
if ( $desc == '(EXCESS RECEIVED)' && $object -> lines [ $i ] -> fk_remise_except )
{
$discount = new DiscountAbsolute ( $db );
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromExcessReceived " , $discount -> ref_facture_source );
}
2011-09-17 03:05:44 +02:00
else
{
if ( $idprod )
{
2012-04-26 10:29:46 +02:00
if ( empty ( $hidedesc )) $libelleproduitservice .= $desc ;
2011-09-17 03:05:44 +02:00
}
else
{
2011-12-08 20:20:16 +01:00
$libelleproduitservice .= $desc ;
2011-09-17 03:05:44 +02:00
}
}
}
2017-11-13 11:30:41 +01:00
// We add ref of product (and supplier ref if defined)
$prefix_prodserv = " " ;
$ref_prodserv = " " ;
if ( ! empty ( $conf -> global -> PRODUCT_ADD_TYPE_IN_DOCUMENTS )) // In standard mode, we do not show this
2011-09-17 03:05:44 +02:00
{
2017-11-13 11:30:41 +01:00
if ( $prodser -> isService ())
2011-09-17 03:05:44 +02:00
{
2017-11-13 11:30:41 +01:00
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Service " ) . " " ;
}
else
{
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Product " ) . " " ;
}
}
2011-09-17 03:05:44 +02:00
2017-11-13 11:30:41 +01:00
if ( empty ( $hideref ))
{
if ( $issupplierline )
{
if ( $conf -> global -> PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1 )
$ref_prodserv = $ref_supplier ;
elseif ( $conf -> global -> PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2 )
$ref_prodserv = $ref_supplier . ' (' . $outputlangs -> transnoentitiesnoconv ( " InternalRef " ) . ' ' . $prodser -> ref . ')' ;
else // Common case
2011-09-17 03:05:44 +02:00
{
2017-11-13 11:30:41 +01:00
$ref_prodserv = $prodser -> ref ; // Show local ref
if ( $ref_supplier ) $ref_prodserv .= ( $prodser -> ref ? ' (' : '' ) . $outputlangs -> transnoentitiesnoconv ( " SupplierRef " ) . ' ' . $ref_supplier . ( $prodser -> ref ? ')' : '' );
2011-09-17 03:05:44 +02:00
}
}
2017-11-13 11:30:41 +01:00
else
{
$ref_prodserv = $prodser -> ref ; // Show local ref only
}
if ( ! empty ( $libelleproduitservice ) && ! empty ( $ref_prodserv )) $ref_prodserv .= " - " ;
2011-09-17 03:05:44 +02:00
}
2013-09-25 19:58:22 +02:00
2017-11-13 11:30:41 +01:00
$libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice ;
2013-09-03 11:15:19 +02:00
// Add an additional description for the category products
2013-09-06 10:40:44 +02:00
if ( ! empty ( $conf -> global -> CATEGORY_ADD_DESC_INTO_DOC ) && $idprod && ! empty ( $conf -> categorie -> enabled ))
2013-09-03 11:15:19 +02:00
{
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$categstatic = new Categorie ( $db );
// recovering the list of all the categories linked to product
2015-05-23 18:52:31 +02:00
$tblcateg = $categstatic -> containing ( $idprod , Categorie :: TYPE_PRODUCT );
2013-09-03 11:15:19 +02:00
foreach ( $tblcateg as $cate )
{
// Adding the descriptions if they are filled
$desccateg = $cate -> add_description ;
if ( $desccateg )
$libelleproduitservice .= '__N__' . $desccateg ;
}
}
2013-09-25 19:58:22 +02:00
2012-07-10 20:45:07 +02:00
if ( ! empty ( $object -> lines [ $i ] -> date_start ) || ! empty ( $object -> lines [ $i ] -> date_end ))
2011-09-17 03:05:44 +02:00
{
2011-12-05 17:13:48 +01:00
$format = 'day' ;
2011-09-17 03:05:44 +02:00
// Show duration if exists
if ( $object -> lines [ $i ] -> date_start && $object -> lines [ $i ] -> date_end )
{
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateFromTo' , dol_print_date ( $object -> lines [ $i ] -> date_start , $format , false , $outputlangs ), dol_print_date ( $object -> lines [ $i ] -> date_end , $format , false , $outputlangs )) . ')' ;
}
if ( $object -> lines [ $i ] -> date_start && ! $object -> lines [ $i ] -> date_end )
{
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateFrom' , dol_print_date ( $object -> lines [ $i ] -> date_start , $format , false , $outputlangs )) . ')' ;
}
if ( ! $object -> lines [ $i ] -> date_start && $object -> lines [ $i ] -> date_end )
{
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateUntil' , dol_print_date ( $object -> lines [ $i ] -> date_end , $format , false , $outputlangs )) . ')' ;
}
//print '>'.$outputlangs->charset_output.','.$period;
2012-04-28 15:44:04 +02:00
$libelleproduitservice .= " __N__ " . $period ;
2011-09-17 03:05:44 +02:00
//print $libelleproduitservice;
}
2014-05-01 19:17:45 +02:00
if ( $dbatch )
2014-03-07 11:35:16 +01:00
{
$format = 'day' ;
foreach ( $dbatch as $detail )
{
$dte = array ();
if ( $detail -> eatby ) $dte [] = $outputlangs -> transnoentitiesnoconv ( 'printEatby' , dol_print_date ( $detail -> eatby , $format , false , $outputlangs ));
if ( $detail -> sellby ) $dte [] = $outputlangs -> transnoentitiesnoconv ( 'printSellby' , dol_print_date ( $detail -> sellby , $format , false , $outputlangs ));
if ( $detail -> batch ) $dte [] = $outputlangs -> transnoentitiesnoconv ( 'printBatch' , $detail -> batch );
$dte [] = $outputlangs -> transnoentitiesnoconv ( 'printQty' , $detail -> dluo_qty );
2017-01-31 12:54:00 +01:00
$libelleproduitservice .= " __N__ " . implode ( " - " , $dte );
2014-03-07 11:35:16 +01:00
}
}
2011-12-08 20:20:16 +01:00
// Now we convert \n into br
2012-04-28 15:44:04 +02:00
if ( dol_textishtml ( $libelleproduitservice )) $libelleproduitservice = preg_replace ( '/__N__/' , '<br>' , $libelleproduitservice );
else $libelleproduitservice = preg_replace ( '/__N__/' , " \n " , $libelleproduitservice );
2011-12-08 20:20:16 +01:00
$libelleproduitservice = dol_htmlentitiesbr ( $libelleproduitservice , 1 );
2011-09-17 03:05:44 +02:00
return $libelleproduitservice ;
2009-01-28 16:09:37 +01:00
}
2010-09-09 09:26:17 +02:00
2011-03-30 22:51:25 +02:00
/**
* Return line num
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2015-10-22 17:51:05 +02:00
* @ return string
2011-03-30 22:51:25 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlinenum ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-03-30 22:51:25 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-10-29 11:50:16 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
2015-10-29 13:14:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getlinenum' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2015-11-02 19:49:00 +01:00
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2015-11-02 19:49:00 +01:00
$result .= dol_htmlentitiesbr ( $object -> lines [ $i ] -> num );
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-03-30 22:51:25 +02:00
}
2010-10-27 19:25:46 +02:00
2010-09-13 08:33:42 +02:00
/**
2011-05-26 15:22:26 +02:00
* Return line product ref
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2015-10-22 17:51:05 +02:00
* @ return string
2010-09-13 08:33:42 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineref ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-13 08:33:42 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-10-29 11:50:16 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
2015-10-29 13:14:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineref' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2015-11-02 19:49:00 +01:00
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2015-11-02 19:49:00 +01:00
$result .= dol_htmlentitiesbr ( $object -> lines [ $i ] -> product_ref );
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-13 08:33:42 +02:00
}
2011-05-20 17:38:26 +02:00
/**
* Return line ref_supplier
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2015-10-22 17:51:05 +02:00
* @ return string
2011-05-20 17:38:26 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineref_supplier ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-05-20 17:38:26 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-10-29 11:50:16 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
2015-10-29 13:14:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineref_supplier' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2015-11-02 19:49:00 +01:00
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2015-11-02 19:49:00 +01:00
$result .= dol_htmlentitiesbr ( $object -> lines [ $i ] -> ref_supplier );
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-05-20 17:38:26 +02:00
}
2010-09-09 09:26:17 +02:00
/**
* Return line vat rate
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2010-09-09 09:26:17 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlinevatrate ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-09 09:26:17 +02:00
{
2017-08-29 17:22:03 +02:00
global $conf , $hookmanager , $mysoc ;
2013-01-26 10:35:30 +01:00
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
2015-11-02 19:31:42 +01:00
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2011-11-22 14:00:03 +01:00
$action = '' ;
2015-09-24 16:57:13 +02:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getlinevatrate' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2017-08-29 17:22:03 +02:00
if ( empty ( $hidedetails ) || $hidedetails > 1 )
{
$tmpresult = '' ;
2017-09-27 21:58:42 +02:00
$tmpresult .= vatrate ( $object -> lines [ $i ] -> tva_tx , 0 , $object -> lines [ $i ] -> info_bits , - 1 );
2017-08-30 14:36:00 +02:00
if ( empty ( $conf -> global -> MAIN_PDF_MAIN_HIDE_SECOND_TAX ))
2017-08-29 17:22:03 +02:00
{
2017-08-30 14:36:00 +02:00
if ( $object -> lines [ $i ] -> total_localtax1 != 0 )
2017-08-29 17:22:03 +02:00
{
2017-08-29 17:24:49 +02:00
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) $tmpresult .= '/' ;
2017-08-29 17:22:03 +02:00
else $tmpresult = '' ;
2017-09-27 21:58:42 +02:00
$tmpresult .= vatrate ( abs ( $object -> lines [ $i ] -> localtax1_tx ), 0 );
2017-08-29 17:22:03 +02:00
}
}
2017-08-30 14:36:00 +02:00
if ( empty ( $conf -> global -> MAIN_PDF_MAIN_HIDE_THIRD_TAX ))
2017-08-29 17:22:03 +02:00
{
2017-08-30 14:36:00 +02:00
if ( $object -> lines [ $i ] -> total_localtax2 != 0 )
2017-08-29 17:22:03 +02:00
{
2017-08-29 17:24:49 +02:00
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) $tmpresult .= '/' ;
2017-08-29 17:22:03 +02:00
else $tmpresult = '' ;
2017-09-27 21:58:42 +02:00
$tmpresult .= vatrate ( abs ( $object -> lines [ $i ] -> localtax2_tx ), 0 );
2017-08-29 17:22:03 +02:00
}
}
2017-09-27 21:58:42 +02:00
$tmpresult .= '%' ;
2017-08-29 17:22:03 +02:00
$result .= $tmpresult ;
}
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-09 09:26:17 +02:00
}
2010-09-09 10:33:30 +02:00
/**
* Return line unit price excluding tax
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2010-09-09 10:33:30 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineupexcltax ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-09 10:33:30 +02:00
{
2013-04-04 13:58:33 +02:00
global $conf , $hookmanager ;
2011-11-11 00:36:01 +01:00
2013-04-04 13:58:33 +02:00
$sign = 1 ;
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) $sign =- 1 ;
2011-11-11 00:36:01 +01:00
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2011-11-22 14:00:03 +01:00
$action = '' ;
2015-09-24 16:57:13 +02:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineupexcltax' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2011-09-17 03:05:44 +02:00
{
2016-06-30 15:49:57 +02:00
if ( empty ( $hidedetails ) || $hidedetails > 1 )
2016-01-21 22:26:51 +01:00
{
$subprice = ( $conf -> multicurrency -> enabled && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_subprice : $object -> lines [ $i ] -> subprice );
$result .= price ( $sign * $subprice , 0 , $outputlangs );
}
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-09 10:33:30 +02:00
}
2011-12-03 23:37:16 +01:00
/**
* Return line unit price including tax
2011-12-06 00:39:24 +01:00
*
* @ param Object $object Object
* @ param int $i Current line number
2014-12-20 15:42:03 +01:00
* @ param Translate $outputlangs Object langs for output
2011-12-06 00:39:24 +01:00
* @ param int $hidedetails Hide value ( 0 = no , 1 = yes , 2 = just special lines )
2015-10-22 17:51:05 +02:00
* @ return string
2011-12-03 23:37:16 +01:00
*/
function pdf_getlineupwithtax ( $object , $i , $outputlangs , $hidedetails = 0 )
{
2016-06-30 14:27:58 +02:00
global $hookmanager , $conf ;
$sign = 1 ;
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) $sign =- 1 ;
2013-01-26 10:35:30 +01:00
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2013-04-04 13:58:33 +02:00
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-10-22 17:51:05 +02:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineupwithtax' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2013-04-04 13:58:33 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2013-04-04 13:58:33 +02:00
{
2016-07-01 03:17:20 +02:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= price ( $sign * (( $object -> lines [ $i ] -> subprice ) + ( $object -> lines [ $i ] -> subprice ) * ( $object -> lines [ $i ] -> tva_tx ) / 100 ), 0 , $outputlangs );
2013-04-04 13:58:33 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-12-03 23:37:16 +01:00
}
2010-09-09 10:33:30 +02:00
/**
* Return line quantity
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2010-09-09 10:33:30 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineqty ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-09 10:33:30 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineqty' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result = $hookmanager -> resPrint ;
2015-10-22 17:51:05 +02:00
}
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= $object -> lines [ $i ] -> qty ;
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-09 10:33:30 +02:00
}
2011-05-27 10:44:52 +02:00
/**
* Return line quantity asked
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2011-05-27 10:44:52 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineqty_asked ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-05-27 10:44:52 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineqty_asked' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2015-10-22 17:51:05 +02:00
}
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= $object -> lines [ $i ] -> qty_asked ;
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-05-27 10:44:52 +02:00
}
/**
* Return line quantity shipped
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2011-05-27 10:44:52 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineqty_shipped ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-05-27 10:44:52 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineqty_shipped' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2015-10-22 17:51:05 +02:00
}
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= $object -> lines [ $i ] -> qty_shipped ;
2011-09-17 03:05:44 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-05-27 10:44:52 +02:00
}
2011-05-29 14:30:44 +02:00
/**
* Return line keep to ship quantity
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2015-10-22 17:51:05 +02:00
* @ return string
2011-05-29 14:30:44 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineqty_keeptoship ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-05-29 14:30:44 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
2015-10-22 17:51:05 +02:00
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineqty_keeptoship' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= ( $object -> lines [ $i ] -> qty_asked - $object -> lines [ $i ] -> qty_shipped );
2015-10-22 17:51:05 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-05-29 14:30:44 +02:00
}
2015-02-26 14:15:33 +01:00
/**
* Return line unit
*
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
* @ param HookManager $hookmanager Hook manager instance
2016-05-19 17:36:25 +02:00
* @ return string Value for unit cell
2015-02-26 14:15:33 +01:00
*/
function pdf_getlineunit ( $object , $i , $outputlangs , $hidedetails = 0 , $hookmanager = false )
{
global $langs ;
2016-06-30 15:49:57 +02:00
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
2015-10-22 17:51:05 +02:00
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-02-26 14:15:33 +01:00
}
2015-10-22 17:51:05 +02:00
$parameters = array (
'i' => $i ,
'outputlangs' => $outputlangs ,
'hidedetails' => $hidedetails ,
'special_code' => $special_code
);
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineunit' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2015-02-26 14:15:33 +01:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= $langs -> transnoentitiesnoconv ( $object -> lines [ $i ] -> getLabelOfUnit ( 'short' ));
2015-10-22 17:51:05 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2015-02-26 14:15:33 +01:00
}
2010-09-09 10:33:30 +02:00
/**
* Return line remise percent
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2014-04-23 16:53:02 +02:00
* @ return string
2010-09-09 10:33:30 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlineremisepercent ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-09 10:33:30 +02:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2011-09-17 03:05:44 +02:00
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineremisepercent' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
{
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
2015-11-02 19:49:00 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= dol_print_reduction ( $object -> lines [ $i ] -> remise_percent , $outputlangs );
2015-10-22 17:51:05 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-09 10:33:30 +02:00
}
2014-11-14 16:43:49 +01:00
/**
* Return line percent
*
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
* @ param HookManager $hookmanager Hook manager instance
2015-10-22 17:51:05 +02:00
* @ return string
2014-11-14 16:43:49 +01:00
*/
function pdf_getlineprogress ( $object , $i , $outputlangs , $hidedetails = 0 , $hookmanager = null )
{
2017-09-28 15:25:51 +02:00
if ( empty ( $hookmanager )) global $hookmanager ;
2017-10-31 11:17:44 +01:00
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
2015-10-22 17:51:05 +02:00
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
{
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineprogress' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-10-22 17:51:05 +02:00
if ( ! empty ( $hookmanager -> resPrint )) return $hookmanager -> resPrint ;
}
if ( empty ( $reshook ))
{
2017-04-20 10:27:44 +02:00
if ( $object -> lines [ $i ] -> special_code == 3 ) return '' ;
if ( empty ( $hidedetails ) || $hidedetails > 1 )
{
2017-11-12 20:12:56 +01:00
if ( $conf -> global -> SITUATION_DISPLAY_DIFF_ON_PDF )
2017-04-20 10:27:44 +02:00
{
2017-11-12 20:12:56 +01:00
$prev_progress = 0 ;
if ( method_exists ( $object , 'get_prev_progress' ))
{
$prev_progress = $object -> lines [ $i ] -> get_prev_progress ( $object -> id );
}
$result = ( $object -> lines [ $i ] -> situation_percent - $prev_progress ) . '%' ;
2017-04-20 10:27:44 +02:00
}
else
$result = $object -> lines [ $i ] -> situation_percent . '%' ;
}
2014-11-14 16:43:49 +01:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2014-11-14 16:43:49 +01:00
}
2010-09-09 10:33:30 +02:00
/**
* Return line total excluding tax
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2013-06-09 16:49:47 +02:00
* @ return string Return total of line excl tax
2010-09-09 10:33:30 +02:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getlinetotalexcltax ( $object , $i , $outputlangs , $hidedetails = 0 )
2010-09-09 10:33:30 +02:00
{
2013-04-04 13:58:33 +02:00
global $conf , $hookmanager ;
2011-11-11 00:36:01 +01:00
2013-04-04 13:58:33 +02:00
$sign = 1 ;
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) $sign =- 1 ;
2011-11-11 00:36:01 +01:00
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2015-11-02 19:49:00 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2011-09-17 03:05:44 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code , 'sign' => $sign );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlinetotalexcltax' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2017-04-28 16:50:30 +02:00
{
2015-10-22 17:51:05 +02:00
if ( $object -> lines [ $i ] -> special_code == 3 )
{
return $outputlangs -> transnoentities ( " Option " );
}
2016-01-21 22:26:51 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 )
{
$total_ht = ( $conf -> multicurrency -> enabled && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_total_ht : $object -> lines [ $i ] -> total_ht );
2017-11-12 20:12:56 +01:00
if ( $object -> lines [ $i ] -> situation_percent > 0 )
2017-04-28 16:50:30 +02:00
{
2017-11-12 20:12:56 +01:00
$prev_progress = 0 ;
$progress = 1 ;
if ( method_exists ( $object , 'get_prev_progress' ))
{
$prev_progress = $object -> lines [ $i ] -> get_prev_progress ( $object -> id );
$progress = ( $object -> lines [ $i ] -> situation_percent - $prev_progress ) / 100 ;
}
$result .= price ( $sign * ( $total_ht / ( $object -> lines [ $i ] -> situation_percent / 100 )) * $progress , 0 , $outputlangs );
}
2017-04-28 16:50:30 +02:00
else
2016-01-21 22:26:51 +01:00
$result .= price ( $sign * $total_ht , 0 , $outputlangs );
2011-09-17 03:05:44 +02:00
}
2017-04-28 16:50:30 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2010-09-09 10:33:30 +02:00
}
2011-12-03 23:37:16 +01:00
/**
* Return line total including tax
2011-12-06 00:39:24 +01:00
*
* @ param Object $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int $hidedetails Hide value ( 0 = no , 1 = yes , 2 = just special lines )
2013-06-09 16:49:47 +02:00
* @ return string Return total of line incl tax
2011-12-03 23:37:16 +01:00
*/
function pdf_getlinetotalwithtax ( $object , $i , $outputlangs , $hidedetails = 0 )
{
2016-06-30 14:27:58 +02:00
global $hookmanager , $conf ;
$sign = 1 ;
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) $sign =- 1 ;
2013-01-26 10:35:30 +01:00
2015-10-22 17:51:05 +02:00
$reshook = 0 ;
2016-02-25 20:54:37 +01:00
$result = '' ;
2015-10-22 17:51:05 +02:00
//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
if ( is_object ( $hookmanager )) // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2013-04-04 13:58:33 +02:00
{
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlinetotalwithtax' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2016-06-30 15:49:57 +02:00
2015-11-02 19:49:00 +01:00
if ( ! empty ( $hookmanager -> resPrint )) $result .= $hookmanager -> resPrint ;
2013-04-04 13:58:33 +02:00
}
2015-10-22 17:51:05 +02:00
if ( empty ( $reshook ))
2013-04-04 13:58:33 +02:00
{
2015-10-22 17:51:05 +02:00
if ( $object -> lines [ $i ] -> special_code == 3 )
{
2016-02-25 20:54:37 +01:00
$result .= $outputlangs -> transnoentities ( " Option " );
2015-10-22 17:51:05 +02:00
}
2016-07-01 03:22:16 +02:00
elseif ( empty ( $hidedetails ) || $hidedetails > 1 ) $result .= price ( $sign * ( $object -> lines [ $i ] -> total_ht ) + ( $object -> lines [ $i ] -> total_ht ) * ( $object -> lines [ $i ] -> tva_tx ) / 100 , 0 , $outputlangs );
2013-04-04 13:58:33 +02:00
}
2015-11-02 19:49:00 +01:00
return $result ;
2011-12-03 23:37:16 +01:00
}
2011-02-23 15:38:39 +01:00
/**
* Return total quantity of products and / or services
2011-09-12 19:08:02 +02:00
*
2011-12-06 00:39:24 +01:00
* @ param Object $object Object
* @ param string $type Type
* @ param Translate $outputlangs Object langs for output
2015-03-17 00:21:17 +01:00
* @ return integer
2016-09-02 22:13:47 +02:00
* @ deprecated Not used by Dolibarr core , so will be removed .
2011-02-23 15:38:39 +01:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getTotalQty ( $object , $type , $outputlangs )
2011-02-23 15:38:39 +01:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2011-02-23 15:38:39 +01:00
$total = 0 ;
2011-09-17 21:49:50 +02:00
$nblignes = count ( $object -> lines );
2011-03-31 18:26:57 +02:00
2011-02-23 15:38:39 +01:00
// Loop on each lines
for ( $i = 0 ; $i < $nblignes ; $i ++ )
{
if ( $object -> lines [ $i ] -> special_code != 3 )
{
if ( $type == 'all' )
{
$total += $object -> lines [ $i ] -> qty ;
}
2013-01-26 10:35:30 +01:00
else if ( $type == 9 && is_object ( $hookmanager ) && (( $object -> lines [ $i ] -> product_type == 9 && ! empty ( $object -> lines [ $i ] -> special_code )) || ! empty ( $object -> lines [ $i ] -> fk_parent_line )))
2011-02-23 15:38:39 +01:00
{
2011-04-13 09:09:59 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) $special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
2015-10-29 11:50:16 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
2015-10-29 13:14:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getTotalQty' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
return $hookmanager -> resPrint ;
2011-02-23 15:38:39 +01:00
}
else if ( $type == 0 && $object -> lines [ $i ] -> product_type == 0 )
{
$total += $object -> lines [ $i ] -> qty ;
}
else if ( $type == 1 && $object -> lines [ $i ] -> product_type == 1 )
{
$total += $object -> lines [ $i ] -> qty ;
}
}
}
2011-03-31 18:26:57 +02:00
2011-02-23 15:38:39 +01:00
return $total ;
}
2012-03-02 08:11:40 +01:00
/**
2016-02-25 20:54:37 +01:00
* Return linked objects to use for document generation .
* Warning : To save space , this function returns only one link per link type ( all links are concated on same record string ) . This function is used by pdf_writeLinkedObjects
2012-03-18 19:23:01 +01:00
*
2012-03-02 08:11:40 +01:00
* @ param object $object Object
* @ param Translate $outputlangs Object lang for output
2015-12-21 12:52:10 +01:00
* @ return array Linked objects
2012-03-02 08:11:40 +01:00
*/
2013-01-26 10:35:30 +01:00
function pdf_getLinkedObjects ( $object , $outputlangs )
2012-03-02 08:11:40 +01:00
{
2013-01-26 10:35:30 +01:00
global $hookmanager ;
2012-03-02 08:11:40 +01:00
$linkedobjects = array ();
2012-03-18 19:23:01 +01:00
2012-03-02 08:11:40 +01:00
$object -> fetchObjectLinked ();
2016-06-30 15:49:57 +02:00
2012-03-02 08:11:40 +01:00
foreach ( $object -> linkedObjects as $objecttype => $objects )
{
2016-02-25 20:54:37 +01:00
if ( $objecttype == 'facture' )
{
// For invoice, we don't want to have a reference line on document. Image we are using recuring invoice, we will have a line longer than document width.
}
elseif ( $objecttype == 'propal' || $objecttype == 'supplier_proposal' )
2012-03-02 08:11:40 +01:00
{
$outputlangs -> load ( 'propal' );
2015-10-29 11:50:16 +01:00
2015-08-19 16:36:44 +02:00
foreach ( $objects as $elementobject )
2012-03-02 08:11:40 +01:00
{
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefProposal " );
2015-08-19 16:36:44 +02:00
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> transnoentities ( $elementobject -> ref );
2012-03-02 08:11:40 +01:00
$linkedobjects [ $objecttype ][ 'date_title' ] = $outputlangs -> transnoentities ( " DatePropal " );
2015-08-19 16:36:44 +02:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date , 'day' , '' , $outputlangs );
2012-03-02 08:11:40 +01:00
}
}
2016-02-25 20:54:37 +01:00
else if ( $objecttype == 'commande' || $objecttype == 'supplier_order' )
2012-03-02 08:11:40 +01:00
{
$outputlangs -> load ( 'orders' );
2015-08-19 16:36:44 +02:00
foreach ( $objects as $elementobject )
2012-03-02 08:11:40 +01:00
{
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " );
2016-02-25 20:54:37 +01:00
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> transnoentities ( $elementobject -> ref ) . ( $elementobject -> ref_client ? ' (' . $elementobject -> ref_client . ')' : '' ) . ( $elementobject -> ref_supplier ? ' (' . $elementobject -> ref_supplier . ')' : '' );
2012-03-02 08:11:40 +01:00
$linkedobjects [ $objecttype ][ 'date_title' ] = $outputlangs -> transnoentities ( " OrderDate " );
2015-08-19 16:36:44 +02:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date , 'day' , '' , $outputlangs );
2012-03-02 08:11:40 +01:00
}
}
2012-07-02 19:30:37 +02:00
else if ( $objecttype == 'contrat' )
{
$outputlangs -> load ( 'contracts' );
2015-08-19 16:36:44 +02:00
foreach ( $objects as $elementobject )
2012-07-02 10:37:39 +02:00
{
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefContract " );
2015-08-19 16:36:44 +02:00
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> transnoentities ( $elementobject -> ref );
2012-07-02 10:37:39 +02:00
$linkedobjects [ $objecttype ][ 'date_title' ] = $outputlangs -> transnoentities ( " DateContract " );
2015-08-19 16:36:44 +02:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date_contrat , 'day' , '' , $outputlangs );
2012-07-02 19:30:37 +02:00
}
2012-07-02 10:37:39 +02:00
}
2014-09-14 12:06:38 +02:00
else if ( $objecttype == 'shipping' )
{
$outputlangs -> load ( 'orders' );
$outputlangs -> load ( 'sendings' );
2016-02-26 15:42:07 +01:00
foreach ( $objects as $x => $elementobject )
2014-09-14 12:06:38 +02:00
{
2016-02-26 15:42:07 +01:00
$order = null ;
// We concat this record info into fields xxx_value. title is overwrote.
if ( empty ( $object -> linkedObjects [ 'commande' ]) && $object -> element != 'commande' ) // There is not already a link to order and object is not the order, so we show also info with order
{
$elementobject -> fetchObjectLinked ();
if ( ! empty ( $elementobject -> linkedObjects [ 'commande' ])) $order = reset ( $elementobject -> linkedObjects [ 'commande' ]);
}
if ( ! is_object ( $order ))
{
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefSending " );
if ( ! empty ( $linkedobjects [ $objecttype ][ 'ref_value' ])) $linkedobjects [ $objecttype ][ 'ref_value' ] .= ' / ' ;
$linkedobjects [ $objecttype ][ 'ref_value' ] .= $outputlangs -> transnoentities ( $elementobject -> ref );
2016-06-18 10:34:42 +02:00
//$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
2016-06-30 15:49:57 +02:00
//if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
2016-02-26 15:42:07 +01:00
//$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
}
else
{
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " ) . ' / ' . $outputlangs -> transnoentities ( " RefSending " );
if ( empty ( $linkedobjects [ $objecttype ][ 'ref_value' ])) $linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> convToOutputCharset ( $order -> ref ) . ( $order -> ref_client ? ' (' . $order -> ref_client . ')' : '' );
$linkedobjects [ $objecttype ][ 'ref_value' ] .= ' / ' . $outputlangs -> transnoentities ( $elementobject -> ref );
2016-06-18 10:34:42 +02:00
//$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
2016-02-26 15:42:07 +01:00
//if (empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs);
//$linkedobjects[$objecttype]['date_value'].= ($elementobject->date_delivery ? ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs) : '');
}
2014-09-14 12:06:38 +02:00
}
}
2012-03-02 08:11:40 +01:00
}
2012-03-18 19:23:01 +01:00
2012-03-02 10:51:59 +01:00
// For add external linked objects
2012-03-02 08:31:38 +01:00
if ( is_object ( $hookmanager ))
{
2012-07-02 19:30:37 +02:00
$parameters = array ( 'linkedobjects' => $linkedobjects , 'outputlangs' => $outputlangs );
$action = '' ;
2012-03-02 10:29:11 +01:00
$hookmanager -> executeHooks ( 'pdf_getLinkedObjects' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2012-03-02 10:51:59 +01:00
if ( ! empty ( $hookmanager -> resArray )) $linkedobjects = $hookmanager -> resArray ;
2012-03-02 08:31:38 +01:00
}
2012-03-02 10:29:11 +01:00
2012-03-02 08:11:40 +01:00
return $linkedobjects ;
}
2013-07-13 21:14:05 +02:00
/**
2013-07-14 16:35:02 +02:00
* Return dimensions to use for images onto PDF checking that width and height are not higher than
* maximum ( 16 x32 by default ) .
2013-07-13 21:14:05 +02:00
*
* @ param string $realpath Full path to photo file to use
2013-07-14 16:35:02 +02:00
* @ return array Height and width to use to output image ( in pdf user unit , so mm )
2013-07-13 21:14:05 +02:00
*/
2013-07-14 16:35:02 +02:00
function pdf_getSizeForImage ( $realpath )
2013-07-13 21:14:05 +02:00
{
2013-07-14 16:35:02 +02:00
global $conf ;
2014-05-07 12:21:14 +02:00
$maxwidth = ( empty ( $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_WIDTH ) ? 20 : $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_WIDTH );
2013-07-14 16:35:02 +02:00
$maxheight = ( empty ( $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT ) ? 32 : $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT );
2013-07-13 21:14:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
$tmp = dol_getImageSize ( $realpath );
if ( $tmp [ 'height' ])
{
2013-07-14 16:35:02 +02:00
$width = ( int ) round ( $maxheight * $tmp [ 'width' ] / $tmp [ 'height' ]); // I try to use maxheight
if ( $width > $maxwidth ) // Pb with maxheight, so i use maxwidth
2013-07-13 21:14:05 +02:00
{
$width = $maxwidth ;
2013-07-15 18:51:56 +02:00
$height = ( int ) round ( $maxwidth * $tmp [ 'height' ] / $tmp [ 'width' ]);
2013-07-13 21:14:05 +02:00
}
2013-07-14 16:35:02 +02:00
else // No pb with maxheight
2013-07-13 21:14:05 +02:00
{
$height = $maxheight ;
}
}
return array ( 'width' => $width , 'height' => $height );
}