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 >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ inodbox . 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 >
2019-08-12 22:21:41 +02:00
* Copyright ( C ) 2019 Lenin Rivas < lenin . rivas @ servcom - it . com >
2020-10-02 09:27:01 +02:00
* Copyright ( C ) 2020 Nicolas ZABOURI < info @ inovea - conseil . com >
2021-04-27 00:22:39 +02:00
* Copyright ( C ) 2021 Anthony Berton < bertonanthony @ 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2013-08-22 16:49:23 +02:00
*/
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
2021-04-27 00:22:39 +02:00
/**
* Return array head with list of tabs to view object informations .
*
* @ return array head array with tabs
*/
function pdf_admin_prepare_head ()
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/pdf.php' ;
2021-05-04 00:15:06 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " Common " );
2021-04-27 00:22:39 +02:00
$head [ $h ][ 2 ] = 'general' ;
$h ++ ;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'pdf_admin' );
2021-04-28 23:25:03 +02:00
if ( ! empty ( $conf -> propal -> enabled )) {
2021-05-04 00:15:06 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/pdf_other.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " Other " );
$head [ $h ][ 2 ] = 'other' ;
2021-04-28 23:25:03 +02:00
$h ++ ;
}
2021-04-27 00:22:39 +02:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'pdf_admin' , 'remove' );
return $head ;
}
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
*
2019-06-24 13:39:32 +02:00
* @ param Translate $outputlangs Output lang to use to autodetect output format if we need 'auto' detection
* @ param string $mode 'setup' = Use setup , 'auto' = Force autodetection whatever is setup
2013-04-29 09:25:42 +02:00
* @ return array Array ( 'width' => w , 'height' => h , 'unit' => u );
*/
2019-06-24 13:39:32 +02:00
function pdf_getFormat ( Translate $outputlangs = null , $mode = 'setup' )
2011-08-11 14:13:59 +02:00
{
2019-06-24 12:59:16 +02:00
global $conf , $db , $langs ;
2019-11-13 19:35:02 +01:00
dol_syslog ( " pdf_getFormat Get paper format with mode= " . $mode . " MAIN_PDF_FORMAT= " . ( empty ( $conf -> global -> MAIN_PDF_FORMAT ) ? 'null' : $conf -> global -> MAIN_PDF_FORMAT ) . " outputlangs->defaultlang= " . ( is_object ( $outputlangs ) ? $outputlangs -> defaultlang : 'null' ) . " and langs->defaultlang= " . ( is_object ( $langs ) ? $langs -> defaultlang : 'null' ));
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
2021-03-01 20:37:16 +01:00
$width = 210 ;
$height = 297 ;
$unit = 'mm' ;
2011-08-11 14:13:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $mode == 'auto' || empty ( $conf -> global -> MAIN_PDF_FORMAT ) || $conf -> global -> MAIN_PDF_FORMAT == 'auto' ) {
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2019-11-13 19:35:02 +01:00
$pdfformat = dol_getDefaultFormat ( $outputlangs );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:02 +01:00
$pdfformat = $conf -> global -> MAIN_PDF_FORMAT ;
2019-06-24 13:39:32 +02:00
}
2011-08-11 14:13:59 +02:00
2019-11-13 19:35:02 +01:00
$sql = " SELECT code, label, width, height, unit FROM " . MAIN_DB_PREFIX . " c_paper_format " ;
$sql .= " WHERE code = ' " . $db -> escape ( $pdfformat ) . " ' " ;
$resql = $db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2019-11-13 19:35:02 +01:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 22:03:23 +01:00
if ( $obj ) {
2019-11-13 19:35:02 +01:00
$width = ( int ) $obj -> width ;
$height = ( int ) $obj -> height ;
$unit = $obj -> unit ;
2011-09-17 03:05:44 +02:00
}
}
//print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
2019-11-13 19:35:02 +01:00
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
*/
2019-01-27 15:20:16 +01: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
2021-02-23 22:03:23 +01:00
if ( ! defined ( 'K_TCPDF_EXTERNAL_CONFIG' )) {
2019-11-13 19:35:02 +01:00
define ( 'K_TCPDF_EXTERNAL_CONFIG' , 1 ); // this avoid using tcpdf_config file
2014-05-01 19:17:45 +02:00
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 );
2019-11-13 19:35:02 +01:00
define ( 'K_SMALL_RATIO' , 2 / 3 );
2014-05-01 19:17:45 +02:00
define ( 'K_THAI_TOPCHARS' , true );
define ( 'K_TCPDF_CALLS_IN_HTML' , true );
2020-10-07 15:01:28 +02:00
if ( ! empty ( $conf -> global -> TCPDF_THROW_ERRORS_INSTEAD_OF_DIE )) {
2020-10-05 14:51:28 +02:00
define ( 'K_TCPDF_THROW_EXCEPTION_ERROR' , true );
} else {
define ( 'K_TCPDF_THROW_EXCEPTION_ERROR' , false );
}
2014-05-01 19:17:45 +02:00
}
2013-06-08 16:29:59 +02:00
2018-04-13 23:18:39 +02:00
// Load TCPDF
require_once TCPDF_PATH . 'tcpdf.php' ;
2012-03-20 01:42:18 +01:00
2018-04-13 23:18:39 +02:00
// We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_TCPDI )) {
require_once TCPDI_PATH . 'tcpdi.php' ;
}
2011-09-17 03:05:44 +02:00
//$arrayformat=pdf_getFormat();
//$format=array($arrayformat['width'],$arrayformat['height']);
//$metric=$arrayformat['unit'];
2019-11-13 19:35:02 +01:00
$pdfa = false ; // PDF-1.3
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PDF_USE_1A )) {
$pdfa = true ; // PDF1/A
}
2018-06-07 21:12:30 +02:00
2021-02-23 22:03:23 +01:00
if ( class_exists ( 'TCPDI' )) {
$pdf = new TCPDI ( $pagetype , $metric , $format , true , 'UTF-8' , false , $pdfa );
} else {
$pdf = new TCPDF ( $pagetype , $metric , $format , true , 'UTF-8' , false , $pdfa );
}
2018-04-14 10:41:38 +02:00
2012-12-19 13:06:45 +01:00
// Protection and encryption of pdf
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION )) {
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 .
*/
2018-04-14 10:41:38 +02:00
2012-12-04 20:51:45 +01:00
// For TCPDF, we specify permission we want to block
2019-11-13 19:35:02 +01:00
$pdfrights = ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION_RIGHTS ) ? json_decode ( $conf -> global -> PDF_SECURITY_ENCRYPTION_RIGHTS , true ) : array ( 'modify' , 'copy' )); // Json format in llx_const
2018-04-14 15:12:51 +02:00
2018-04-14 15:24:52 +02:00
// Password for the end user
2019-11-13 19:35:02 +01:00
$pdfuserpass = ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION_USERPASS ) ? $conf -> global -> PDF_SECURITY_ENCRYPTION_USERPASS : '' );
2018-04-14 15:24:52 +02:00
// Password of the owner, created randomly if not defined
2019-11-13 19:35:02 +01:00
$pdfownerpass = ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION_OWNERPASS ) ? $conf -> global -> PDF_SECURITY_ENCRYPTION_OWNERPASS : null );
2018-04-14 15:24:52 +02:00
2018-04-14 15:12:51 +02:00
// For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
2019-11-13 19:35:02 +01:00
$encstrength = ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION_STRENGTH ) ? $conf -> global -> PDF_SECURITY_ENCRYPTION_STRENGTH : 0 );
2018-04-14 15:12:51 +02:00
// Array of recipients containing public-key certificates ('c') and permissions ('p').
// For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
2019-11-13 19:35:02 +01:00
$pubkeys = ( ! empty ( $conf -> global -> PDF_SECURITY_ENCRYPTION_PUBKEYS ) ? json_decode ( $conf -> global -> PDF_SECURITY_ENCRYPTION_PUBKEYS , true ) : null ); // Json format in llx_const
2012-12-04 20:51:45 +01:00
2019-01-27 11:55:16 +01:00
$pdf -> SetProtection ( $pdfrights , $pdfuserpass , $pdfownerpass , $encstrength , $pubkeys );
2011-09-17 03:05:44 +02:00
}
2012-12-04 20:51:45 +01:00
2011-09-17 03:05:44 +02:00
return $pdf ;
2010-12-21 00:43:45 +01:00
}
2018-05-08 09:45:10 +02:00
/**
* Return if pdf file is protected / encrypted
*
* @ param string $pathoffile Path of file
* @ return boolean True or false
*/
2019-06-03 09:36:00 +02:00
function pdf_getEncryption ( $pathoffile )
2018-05-08 09:45:10 +02:00
{
2019-06-03 09:36:00 +02:00
require_once TCPDF_PATH . 'tcpdf_parser.php' ;
2018-05-08 09:45:10 +02:00
$isencrypted = false ;
2019-06-03 09:36:00 +02:00
$content = file_get_contents ( $pathoffile );
2019-06-17 07:09:19 +02:00
//ob_start();
2019-06-03 09:36:00 +02:00
@ ( $parser = new \TCPDF_PARSER ( ltrim ( $content )));
list ( $xref , $data ) = $parser -> getParsedData ();
unset ( $parser );
2019-06-17 07:09:19 +02:00
//ob_end_clean();
2019-06-03 09:36:00 +02:00
if ( isset ( $xref [ 'trailer' ][ 'encrypt' ])) {
2019-11-13 19:35:02 +01:00
$isencrypted = true ; // Secured pdf file are currently not supported
2019-06-03 09:36:00 +02:00
}
if ( empty ( $data )) {
2019-11-13 19:35:02 +01:00
$isencrypted = true ; // Object list not found. Possible secured file
2018-05-08 09:45:10 +02:00
}
return $isencrypted ;
}
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 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_FORCE_FONT )) {
return $conf -> global -> MAIN_PDF_FORCE_FONT ;
}
2012-10-31 19:38:16 +01:00
2019-11-13 19:35:02 +01:00
$font = 'Helvetica' ; // By default, for FPDI, or ISO language on TCPDF
2021-02-23 22:03:23 +01:00
if ( class_exists ( 'TCPDF' )) { // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
if ( $outputlangs -> trans ( 'FONTFORPDF' ) != 'FONTFORPDF' ) {
2019-11-13 19:35:02 +01:00
$font = $outputlangs -> trans ( 'FONTFORPDF' );
2011-09-17 03:05:44 +02:00
}
}
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 )
{
2019-10-15 11:13:14 +02:00
global $conf ;
2019-11-13 19:35:02 +01:00
$size = 10 ; // By default, for FPDI or ISO language on TCPDF
2021-02-23 22:03:23 +01:00
if ( class_exists ( 'TCPDF' )) { // If TCPDF on, we can use an UTF8 font like DejaVuSans if required (slower)
if ( $outputlangs -> trans ( 'FONTSIZEFORPDF' ) != 'FONTSIZEFORPDF' ) {
2011-09-17 03:05:44 +02:00
$size = ( int ) $outputlangs -> trans ( 'FONTSIZEFORPDF' );
}
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_FORCE_FONT_SIZE )) {
$size = $conf -> global -> MAIN_PDF_FORCE_FONT_SIZE ;
}
2019-10-15 11:13:14 +02:00
2011-09-17 03:05:44 +02:00
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 ;
2020-07-24 03:36:44 +02:00
$height = ( empty ( $conf -> global -> MAIN_DOCUMENTS_LOGO_HEIGHT ) ? 20 : $conf -> global -> MAIN_DOCUMENTS_LOGO_HEIGHT );
2019-11-13 19:35:02 +01:00
$maxwidth = 130 ;
2013-04-04 13:58:33 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
2019-11-13 19:35:02 +01:00
$tmp = dol_getImageSize ( $logo , $url );
2021-02-23 22:03:23 +01:00
if ( $tmp [ 'height' ]) {
2019-11-13 19:35:02 +01:00
$width = round ( $height * $tmp [ 'width' ] / $tmp [ 'height' ]);
2021-02-23 22:03:23 +01:00
if ( $width > $maxwidth ) {
$height = $height * $maxwidth / $width ;
}
2013-04-04 13:58:33 +02:00
}
//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
*
2018-10-04 17:56:56 +02:00
* @ param TCPDF $pdf PDF initialized object
* @ param string $htmlcontent HTML Contect
* @ return int Height
2019-03-11 01:01:15 +01:00
* @ see getStringHeight ()
2015-09-18 12:10:47 +02:00
*/
function pdfGetHeightForHtmlContent ( & $pdf , $htmlcontent )
{
2020-10-31 14:32:18 +01:00
// store current object
$pdf -> startTransaction ();
// store starting values
$start_y = $pdf -> GetY ();
//var_dump($start_y);
$start_page = $pdf -> getPage ();
// call printing functions with content
$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 ;
} else {
for ( $page = $start_page ; $page <= $end_page ; ++ $page ) {
$pdf -> setPage ( $page );
$tmpm = $pdf -> getMargins ();
$tMargin = $tmpm [ 'top' ];
if ( $page == $start_page ) {
// first page
$height = $pdf -> getPageHeight () - $start_y - $pdf -> getBreakMargin ();
} elseif ( $page == $end_page ) {
// last page
$height = $end_y - $tMargin ;
} else {
$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
2020-10-31 14:32:18 +01:00
return $height ;
2015-09-18 12:10:47 +02:00
}
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
*/
2019-01-27 15:20:16 +01:00
function pdfBuildThirdpartyName ( $thirdparty , Translate $outputlangs , $includealias = 0 )
2015-02-27 15:08:08 +01:00
{
2020-10-31 14:32:18 +01:00
global $conf ;
2017-07-09 15:15:23 +02:00
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 ;
2019-11-13 19:35:02 +01:00
if (( $includealias || ! empty ( $conf -> global -> PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME )) && ! empty ( $thirdparty -> name_alias )) {
2020-10-31 14:32:18 +01:00
$socname .= " - " . $thirdparty -> name_alias ;
2016-02-24 13:29:37 +01:00
}
2015-02-27 15:08:08 +01:00
} elseif ( $thirdparty instanceof Contact ) {
$socname = $thirdparty -> socname ;
} else {
2018-04-13 23:18:39 +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
*
2019-04-23 10:38:20 +02:00
* @ param Translate $outputlangs Output langs object
* @ param Societe $sourcecompany Source company object
* @ param Societe | string | null $targetcompany Target company object
* @ param Contact | string | null $targetcontact Target contact object
* @ param int $usecontact Use contact instead of company
* @ param string $mode Address type ( 'source' , 'target' , 'targetwithdetails' , 'targetwithdetails_xxx' : target but include also phone / fax / email / url )
* @ param Object $object Object we want to build document for
* @ return string String with full address
2010-03-30 20:03:01 +02:00
*/
2019-01-27 15:20:16 +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
2021-02-23 22:03:23 +01:00
if ( $mode == 'source' && ! is_object ( $sourcecompany )) {
return - 1 ;
}
if ( $mode == 'target' && ! is_object ( $targetcompany )) {
return - 1 ;
}
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $sourcecompany -> state_id ) && empty ( $sourcecompany -> state )) {
$sourcecompany -> state = getState ( $sourcecompany -> state_id );
}
if ( ! empty ( $targetcompany -> state_id ) && empty ( $targetcompany -> state )) {
$targetcompany -> state = getState ( $targetcompany -> state_id );
}
2011-09-17 03:05:44 +02:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
2016-02-25 20:54:37 +01:00
$stringaddress = '' ;
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2020-03-14 14:47:01 +01:00
$parameters = array ( 'sourcecompany' => & $sourcecompany , 'targetcompany' => & $targetcompany , 'targetcontact' => & $targetcontact , 'outputlangs' => $outputlangs , 'mode' => $mode , 'usecontact' => $usecontact );
2019-11-13 19:35:02 +01:00
$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
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $mode == 'source' ) {
2020-10-31 14:32:18 +01:00
$withCountry = 0 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $sourcecompany -> country_code ) && ( $targetcompany -> country_code != $sourcecompany -> country_code )) {
$withCountry = 1 ;
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $sourcecompany , $withCountry , " \n " , $outputlangs )) . " \n " ;
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_PDF_DISABLESOURCEDETAILS )) {
2020-10-31 14:32:18 +01:00
// Phone
2021-02-23 22:03:23 +01:00
if ( $sourcecompany -> phone ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " PhoneShort " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> phone );
}
2020-10-31 14:32:18 +01:00
// Fax
2021-02-23 22:03:23 +01:00
if ( $sourcecompany -> fax ) {
$stringaddress .= ( $stringaddress ? ( $sourcecompany -> phone ? " - " : " \n " ) : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> fax );
}
2020-10-31 14:32:18 +01:00
// EMail
2021-02-23 22:03:23 +01:00
if ( $sourcecompany -> email ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> email );
}
2020-10-31 14:32:18 +01:00
// Web
2021-02-23 22:03:23 +01:00
if ( $sourcecompany -> url ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> url );
}
2020-10-31 14:32:18 +01:00
}
// Intra VAT
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_TVAINTRA_IN_SOURCE_ADDRESS )) {
if ( $sourcecompany -> tva_intra ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> tva_intra );
}
2020-10-31 14:32:18 +01:00
}
// Professionnal Ids
$reg = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID1_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof1 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId1 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof1 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID2_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof2 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId2 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof2 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID3_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof3 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId3 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof3 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID4_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof4 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId4 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof4 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID5_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof5 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId5 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof5 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID6_IN_SOURCE_ADDRESS ) && ! empty ( $sourcecompany -> idprof6 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId6 " , $sourcecompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> idprof6 );
}
if ( ! empty ( $conf -> global -> PDF_ADD_MORE_AFTER_SOURCE_ADDRESS )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $conf -> global -> PDF_ADD_MORE_AFTER_SOURCE_ADDRESS ;
}
}
2021-02-23 22:03:23 +01:00
if ( $mode == 'target' || preg_match ( '/targetwithdetails/' , $mode )) {
if ( $usecontact ) {
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $targetcontact -> getFullName ( $outputlangs , 1 ));
if ( ! empty ( $targetcontact -> address )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcontact ));
} else {
$companytouseforaddress = $targetcompany ;
2018-09-03 17:55:24 +02:00
2018-10-04 17:50:19 +02:00
// Contact on a thirdparty that is a different thirdparty than the thirdparty of object
2021-02-23 22:03:23 +01:00
if ( $targetcontact -> socid > 0 && $targetcontact -> socid != $targetcompany -> id ) {
2018-09-08 18:28:21 +02:00
$targetcontact -> fetch_thirdparty ();
2018-09-05 20:39:38 +02:00
$companytouseforaddress = $targetcontact -> thirdparty ;
}
2018-09-03 17:55:24 +02:00
2019-11-13 19:35:02 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $companytouseforaddress ));
2018-10-04 17:47:22 +02:00
}
2020-10-31 14:32:18 +01:00
// Country
if ( ! empty ( $targetcontact -> country_code ) && $targetcontact -> country_code != $sourcecompany -> country_code ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcontact -> country_code ));
} elseif ( empty ( $targetcontact -> country_code ) && ! empty ( $targetcompany -> country_code ) && ( $targetcompany -> country_code != $sourcecompany -> country_code )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> country_code ));
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || preg_match ( '/targetwithdetails/' , $mode )) {
2020-10-31 14:32:18 +01:00
// Phone
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_phone/' , $mode )) {
if ( ! empty ( $targetcontact -> phone_pro ) || ! empty ( $targetcontact -> phone_mobile )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " ;
}
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 );
}
2020-10-31 14:32:18 +01:00
}
// Fax
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode )) {
if ( $targetcontact -> fax ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> fax );
}
2020-10-31 14:32:18 +01:00
}
// EMail
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode )) {
if ( $targetcontact -> email ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> email );
}
2020-10-31 14:32:18 +01:00
}
// Web
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode )) {
if ( $targetcontact -> url ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> url );
}
2020-10-31 14:32:18 +01:00
}
}
} else {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcompany ));
// Country
2021-02-23 22:03:23 +01:00
if ( ! empty ( $targetcompany -> country_code ) && $targetcompany -> country_code != $sourcecompany -> country_code ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> country_code ));
}
2020-10-31 14:32:18 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || preg_match ( '/targetwithdetails/' , $mode )) {
2020-10-31 14:32:18 +01:00
// Phone
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_phone/' , $mode )) {
if ( ! empty ( $targetcompany -> phone ) || ! empty ( $targetcompany -> phone_mobile )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " ;
}
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 );
}
2020-10-31 14:32:18 +01:00
}
// Fax
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode )) {
if ( $targetcompany -> fax ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> fax );
}
2020-10-31 14:32:18 +01:00
}
// EMail
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode )) {
if ( $targetcompany -> email ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> email );
}
2020-10-31 14:32:18 +01:00
}
// Web
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PDF_ADDALSOTARGETDETAILS ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode )) {
if ( $targetcompany -> url ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> url );
}
2020-10-31 14:32:18 +01:00
}
}
}
// Intra VAT
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_TVAINTRA_NOT_IN_ADDRESS )) {
if ( $targetcompany -> tva_intra ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> tva_intra );
}
2020-10-31 14:32:18 +01:00
}
// Professionnal Ids
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID1_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof1 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId1 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof1 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID2_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof2 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId2 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof2 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID3_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof3 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId3 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof3 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID4_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof4 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId4 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof4 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID5_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof5 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId5 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof5 );
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PROFID6_IN_ADDRESS ) && ! empty ( $targetcompany -> idprof6 )) {
2020-10-31 14:32:18 +01:00
$tmp = $outputlangs -> transcountrynoentities ( " ProfId6 " , $targetcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.+)\)/' , $tmp , $reg )) {
$tmp = $reg [ 1 ];
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof6 );
}
// Public note
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_PUBLIC_NOTE_IN_ADDRESS )) {
if ( $mode == 'source' && ! empty ( $sourcecompany -> note_public )) {
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . dol_string_nohtmltag ( $sourcecompany -> note_public );
}
2021-02-23 22:03:23 +01:00
if (( $mode == 'target' || preg_match ( '/targetwithdetails/' , $mode )) && ! empty ( $targetcompany -> note_public )) {
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . dol_string_nohtmltag ( $targetcompany -> note_public );
}
}
}
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
*/
2019-01-27 15:20:16 +01:00
function pdf_pagehead ( & $pdf , $outputlangs , $page_height )
2009-06-15 20:57:34 +02:00
{
2011-09-17 03:05:44 +02:00
global $conf ;
2009-06-15 20:57:34 +02:00
2021-05-27 00:02:01 +02:00
// Add a background image on document only if good setup of const
2021-06-11 19:05:05 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF ) && ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF != '-1' )) { // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
2019-11-13 19:35:02 +01:00
$pdf -> SetAutoPageBreak ( 0 , 0 ); // Disable auto pagebreak before adding image
$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 );
$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
*/
2019-01-27 15:20:16 +01:00
function pdf_getSubstitutionArray ( $outputlangs , $exclude = null , $object = null , $onlykey = 0 )
2017-04-17 13:02:40 +02:00
{
2020-10-31 14:32:18 +01:00
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , $onlykey , $exclude , $object );
$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
2021-02-23 22:03:23 +01:00
if ( $unit == 'pt' ) {
$k = 1 ;
} elseif ( $unit == 'mm' ) {
$k = 72 / 25.4 ;
} elseif ( $unit == 'cm' ) {
$k = 72 / 2.54 ;
} elseif ( $unit == 'in' ) {
$k = 72 ;
}
2011-09-17 03:05:44 +02:00
2017-04-17 13:02:40 +02:00
// Make substitution
2019-11-13 19:35:02 +01:00
$substitutionarray = pdf_getSubstitutionArray ( $outputlangs , null , null );
2017-06-01 13:32:20 +02:00
complete_substitutions_array ( $substitutionarray , $outputlangs , null );
2019-11-13 19:35:02 +01:00
$text = make_substitutions ( $text , $substitutionarray , $outputlangs );
$text = $outputlangs -> convToOutputCharset ( $text );
2017-06-01 01:53:55 +02:00
2021-03-01 20:37:16 +01:00
$savx = $pdf -> getX ();
$savy = $pdf -> getY ();
2013-09-25 19:58:22 +02:00
2019-11-13 19:35:02 +01:00
$watermark_angle = atan ( $h / $w ) / 2 ;
$watermark_x_pos = 0 ;
$watermark_y_pos = $h / 3 ;
$watermark_x = $w / 2 ;
$watermark_y = $h / 3 ;
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , 40 );
$pdf -> SetTextColor ( 255 , 192 , 203 );
2011-09-17 03:05:44 +02:00
//rotate
2019-11-13 19:35:02 +01:00
$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 ));
2011-09-17 03:05:44 +02:00
//print watermark
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $watermark_x_pos , $watermark_y_pos );
2019-11-13 19:35:02 +01:00
$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
2019-01-27 11:55:16 +01: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
*/
2019-01-27 15:20:16 +01: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
2019-11-13 19:35:02 +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
2021-02-23 22:03:23 +01:00
if ( empty ( $onlynumber )) {
2019-01-27 11:55:16 +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 );
2019-11-13 19:35:02 +01:00
$cury += 4 ;
2011-09-17 03:05:44 +02:00
}
$outputlangs -> load ( " banks " );
2014-12-11 10:13:44 +01:00
// Use correct name of bank id according to country
2019-11-13 19:35:02 +01:00
$bickey = " BICNumber " ;
2021-02-23 22:03:23 +01:00
if ( $account -> getCountryCode () == 'IN' ) {
$bickey = " SWIFT " ;
}
2014-12-11 10:13:44 +01:00
2011-09-17 03:05:44 +02:00
// Get format of bank account according to its country
2019-11-13 19:35:02 +01:00
$usedetailedbban = $account -> useDetailedBBAN ();
2011-09-17 03:05:44 +02:00
2015-01-31 13:00:51 +01:00
//$onlynumber=0; $usedetailedbban=1; // For tests
2021-02-23 22:03:23 +01:00
if ( $usedetailedbban ) {
2019-11-13 19:35:02 +01:00
$savcurx = $curx ;
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $onlynumber )) {
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
$cury += 3 ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN )) { // Note that some countries still need bank number, BIC/IBAN not enougth for them
2020-10-31 14:32:18 +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
2021-02-23 22:03:23 +01:00
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
2021-02-23 22:03:23 +01:00
foreach ( $account -> getFieldsToShow () as $val ) {
2019-11-13 19:35:02 +01:00
$pdf -> SetXY ( $curx , $cury + 4 );
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , $default_font_size - 3 );
2016-03-19 23:00:33 +01:00
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
2018-11-22 13:08:18 +01:00
$tmplength = 15 ;
2016-03-19 23:00:33 +01:00
$content = $account -> cle_rib ;
2020-05-21 15:05:19 +02:00
} elseif ( $val == 'IBAN' || $val == 'BIC' ) {
2016-06-30 15:49:57 +02:00
// 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 );
}
2020-10-31 14:32:18 +01:00
}
2016-06-30 15:49:57 +02:00
2020-10-31 14:32:18 +01:00
$curx = $savcurx ;
$cury += 8 ;
2011-09-17 03:05:44 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
$cury += 3 ;
2011-09-17 03:05:44 +02:00
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " BankAccountNumber " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> number ), 0 , 'L' , 0 );
$cury += 3 ;
2015-07-12 16:22:06 +02:00
2021-02-23 22:03:23 +01:00
if ( $diffsizecontent <= 2 ) {
$cury += 1 ;
}
2011-09-17 03:05:44 +02:00
}
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , $default_font_size - $diffsizecontent );
2015-07-12 16:22:06 +02:00
2020-11-22 14:49:30 +01:00
if ( empty ( $onlynumber ) && ! empty ( $account -> domiciliation )) {
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01: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;
2019-11-13 19:35:02 +01:00
$tmpy = $pdf -> getStringHeight ( 100 , $val );
$cury += $tmpy ;
2011-09-17 03:05:44 +02:00
}
2015-07-12 16:22:06 +02:00
2020-11-22 14:49:30 +01:00
if ( ! empty ( $account -> proprio )) {
2015-03-01 21:31:03 +01:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$val = $outputlangs -> transnoentities ( " BankAccountOwner " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> proprio );
2015-03-01 21:31:03 +01:00
$pdf -> MultiCell ( 100 , 3 , $val , 0 , 'L' , 0 );
2019-11-13 19:35:02 +01:00
$tmpy = $pdf -> getStringHeight ( 100 , $val );
$cury += $tmpy ;
2020-11-22 14:49:30 +01:00
} elseif ( ! $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
2021-02-23 22:03:23 +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 );
2021-02-23 22:03:23 +01:00
for ( $i = 0 ; $i < $nbIbanDisplay_temp ; $i ++ ) {
2014-12-11 10:13:44 +01:00
$ibanDisplay .= $ibanDisplay_temp [ $i ];
2021-02-23 22:03:23 +01:00
if ( $i % 4 == 3 && $i > 0 ) {
$ibanDisplay .= " " ;
}
2014-12-11 10:13:44 +01:00
}
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - 3 );
2014-12-11 10:13:44 +01:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $ibankey ) . ': ' . $ibanDisplay , 0 , 'L' , 0 );
$cury += 3 ;
2014-12-11 10:13:44 +01:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $account -> bic )) {
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - 3 );
2013-03-24 16:17:36 +01:00
$pdf -> SetXY ( $curx , $cury );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $bickey ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bic ), 0 , 'L' , 0 );
2013-03-24 16:17:36 +01:00
}
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
*/
2019-01-27 15:20:16 +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
{
2019-11-13 19:35:02 +01:00
global $conf , $user , $mysoc ;
2009-01-28 16:09:37 +01:00
2011-09-17 03:05:44 +02:00
$outputlangs -> load ( " dict " );
2019-11-13 19:35:02 +01:00
$line = '' ;
2009-01-28 16:09:37 +01:00
2019-11-13 19:35:02 +01:00
$dims = $pdf -> getPageDimensions ();
2012-08-08 04:12:20 +02:00
2011-09-17 03:05:44 +02:00
// Line of free text
2021-02-23 22:03:23 +01:00
if ( empty ( $hidefreetext ) && ! empty ( $conf -> global -> $paramfreetext )) {
2019-11-13 19:35:02 +01:00
$substitutionarray = pdf_getSubstitutionArray ( $outputlangs , null , $object );
2017-04-17 13:02:40 +02:00
// More substitution keys
2019-11-13 19:35:02 +01:00
$substitutionarray [ '__FROM_NAME__' ] = $fromcompany -> name ;
$substitutionarray [ '__FROM_EMAIL__' ] = $fromcompany -> email ;
2017-06-01 13:32:20 +02:00
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
2019-11-13 19:35:02 +01:00
$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" />
2020-04-26 23:52:23 +02:00
$newfreetext = preg_replace ( '/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/' , '\1file:/' . DOL_DATA_ROOT . '/medias/\2\3' , $newfreetext );
2017-06-17 00:13:09 +02:00
2019-11-13 19:35:02 +01:00
$line .= $outputlangs -> convToOutputCharset ( $newfreetext );
2011-09-17 03:05:44 +02:00
}
// First line of company infos
2021-03-01 20:37:16 +01:00
$line1 = " " ;
$line2 = " " ;
$line3 = " " ;
$line4 = " " ;
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( $showdetails == 1 || $showdetails == 3 ) {
2011-09-17 03:05:44 +02:00
// Company name
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> name ) {
2019-11-13 19:35:02 +01:00
$line1 .= ( $line1 ? " - " : " " ) . $outputlangs -> transnoentities ( " RegisteredOffice " ) . " : " . $fromcompany -> name ;
2011-09-17 03:05:44 +02:00
}
// Address
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> address ) {
2019-11-13 19:35:02 +01:00
$line1 .= ( $line1 ? " - " : " " ) . str_replace ( " \n " , " , " , $fromcompany -> address );
2011-09-17 03:05:44 +02:00
}
// Zip code
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> zip ) {
2019-11-13 19:35:02 +01:00
$line1 .= ( $line1 ? " - " : " " ) . $fromcompany -> zip ;
2011-09-17 03:05:44 +02:00
}
// Town
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> town ) {
2019-11-13 19:35:02 +01:00
$line1 .= ( $line1 ? " " : " " ) . $fromcompany -> town ;
2011-09-17 03:05:44 +02:00
}
2019-10-01 21:03:58 +02:00
// Country
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> country ) {
2019-11-13 19:35:02 +01:00
$line1 .= ( $line1 ? " , " : " " ) . $fromcompany -> country ;
2019-10-01 21:03:58 +02:00
}
2011-09-17 03:05:44 +02:00
// Phone
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> phone ) {
2019-11-13 19:35:02 +01:00
$line2 .= ( $line2 ? " - " : " " ) . $outputlangs -> transnoentities ( " Phone " ) . " : " . $fromcompany -> phone ;
2011-09-17 03:05:44 +02:00
}
// Fax
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> fax ) {
2019-11-13 19:35:02 +01:00
$line2 .= ( $line2 ? " - " : " " ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $fromcompany -> fax ;
2011-09-17 03:05:44 +02:00
}
// URL
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> url ) {
2019-11-13 19:35:02 +01:00
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> url ;
2011-09-17 03:05:44 +02:00
}
// Email
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> email ) {
2019-11-13 19:35:02 +01:00
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> email ;
2011-09-17 03:05:44 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $showdetails == 2 || $showdetails == 3 || ( $fromcompany -> country_code == 'DE' )) {
2014-08-25 19:16:37 +02:00
// Managers
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> managers ) {
2019-11-13 19:35:02 +01:00
$line2 .= ( $line2 ? " - " : " " ) . $fromcompany -> managers ;
2014-08-25 19:16:37 +02:00
}
}
2011-09-17 03:05:44 +02:00
// Line 3 of company infos
// Juridical status
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> forme_juridique_code ) {
2019-11-13 19:35:02 +01:00
$line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> convToOutputCharset ( getFormeJuridiqueLabel ( $fromcompany -> forme_juridique_code ));
2011-09-17 03:05:44 +02:00
}
// Capital
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> capital ) {
2014-11-12 10:37:39 +01:00
$tmpamounttoshow = price2num ( $fromcompany -> capital ); // This field is a free string
2021-02-23 22:03:23 +01:00
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
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof1 && ( $fromcompany -> country_code != 'FR' || ! $fromcompany -> idprof2 )) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId1 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line3 .= ( $line3 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof1 );
2011-09-17 03:05:44 +02:00
}
// Prof Id 2
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof2 ) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId2 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line3 .= ( $line3 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof2 );
2011-09-17 03:05:44 +02:00
}
// Line 4 of company infos
// Prof Id 3
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof3 ) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId3 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof3 );
2011-09-17 03:05:44 +02:00
}
// Prof Id 4
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof4 ) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId4 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof4 );
2011-09-17 03:05:44 +02:00
}
2016-12-05 09:04:34 +01:00
// Prof Id 5
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof5 ) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId5 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof5 );
2016-12-05 09:04:34 +01:00
}
// Prof Id 6
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> idprof6 ) {
2019-11-13 19:35:02 +01:00
$field = $outputlangs -> transcountrynoentities ( " ProfId6 " , $fromcompany -> country_code );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
2019-11-13 19:35:02 +01:00
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof6 );
2016-12-05 09:04:34 +01:00
}
2011-09-17 03:05:44 +02:00
// IntraCommunautary VAT
2021-02-23 22:03:23 +01:00
if ( $fromcompany -> tva_intra != '' ) {
2019-11-13 19:35:02 +01:00
$line4 .= ( $line4 ? " - " : " " ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> tva_intra );
2011-09-17 03:05:44 +02:00
}
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , 7 );
$pdf -> SetDrawColor ( 224 , 224 , 224 );
2011-09-17 03:05:44 +02:00
2014-04-07 09:54:24 +02:00
// The start of the bottom of this page footer is positioned according to # of lines
2019-11-13 19:35:02 +01:00
$freetextheight = 0 ;
2021-02-23 22:03:23 +01:00
if ( $line ) { // Free text
2018-02-26 15:03:09 +01:00
//$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> PDF_ALLOW_HTML_FOR_FREE_TEXT )) {
2021-03-01 20:37:16 +01: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.
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_AUTOWRAP_ON_FREETEXT )) {
2021-03-01 20:37:16 +01:00
$width = 200 ;
$align = 'C' ;
2020-10-31 14:32:18 +01:00
}
$freetextheight = $pdf -> getStringHeight ( $width , $line );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$freetextheight = pdfGetHeightForHtmlContent ( $pdf , dol_htmlentitiesbr ( $line , 1 , 'UTF-8' , 0 )); // New method (works for HTML content)
//print '<br>'.$freetextheight;exit;
2012-10-30 11:17:49 +01:00
}
}
2019-11-13 19:35:02 +01:00
$marginwithfooter = $marge_basse + $freetextheight + ( ! empty ( $line1 ) ? 3 : 0 ) + ( ! empty ( $line2 ) ? 3 : 0 ) + ( ! empty ( $line3 ) ? 3 : 0 ) + ( ! empty ( $line4 ) ? 3 : 0 );
$posy = $marginwithfooter + 0 ;
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( $line ) { // Free text
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> PDF_ALLOW_HTML_FOR_FREE_TEXT )) { // by default
2020-10-31 14:32:18 +01:00
$pdf -> MultiCell ( 0 , 3 , $line , 0 , $align , 0 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01: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
}
2019-11-13 19:35:02 +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 );
2019-11-13 19:35:02 +01: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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $line1 )) {
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , 7 );
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line1 , 0 , 'C' , 0 );
$posy -= 3 ;
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , 7 );
2011-09-17 03:05:44 +02:00
}
2011-01-16 03:26:20 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $line2 )) {
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , 'B' , 7 );
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line2 , 0 , 'C' , 0 );
$posy -= 3 ;
2019-01-27 11:55:16 +01:00
$pdf -> SetFont ( '' , '' , 7 );
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $line3 )) {
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2019-11-13 19:35:02 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line3 , 0 , 'C' , 0 );
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $line4 )) {
2019-11-13 19:35:02 +01:00
$posy -= 3 ;
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2019-11-13 19:35:02 +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)
2021-02-23 22:03:23 +01:00
if ( strtolower ( pdf_getPDFFont ( $outputlangs )) == 'helvetica' ) {
2019-11-13 19:35:02 +01: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;
2018-04-13 23:18:39 +02:00
$pdf -> MultiCell ( 15 , 2 , $pdf -> PageNo () . '/' . $pdf -> getAliasNbPages (), 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
*/
2019-01-27 15:20:16 +01:00
function pdf_writeLinkedObjects ( & $pdf , $object , $outputlangs , $posx , $posy , $w , $h , $align , $default_font_size )
2012-03-02 14:46:18 +01:00
{
2019-01-27 11:55:16 +01:00
$linkedobjects = pdf_getLinkedObjects ( $object , $outputlangs );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $linkedobjects )) {
foreach ( $linkedobjects as $linkedobject ) {
2020-10-31 14:32:18 +01:00
$reftoshow = $linkedobject [ " ref_title " ] . ' : ' . $linkedobject [ " ref_value " ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $linkedobject [ " date_value " ])) {
2020-10-31 14:32:18 +01:00
$reftoshow .= ' / ' . $linkedobject [ " date_value " ];
}
2016-06-30 15:49:57 +02:00
2019-11-13 19:35:02 +01:00
$posy += 3 ;
2019-01-27 11:55:16 +01:00
$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
*
2021-05-10 11:53:19 +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
*/
2019-01-27 15:20:16 +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
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2020-11-28 12:12:31 +01:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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 );
$action = '' ;
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
2019-11-13 19:35:02 +01:00
$labelproductservice = pdf_getlinedesc ( $object , $i , $outputlangs , $hideref , $hidedesc , $issupplierline );
2019-01-31 18:12:34 +01:00
//var_dump($labelproductservice);exit;
// Fix bug of some HTML editors that replace links <img src="http://localhostgit/viewimage.php?modulepart=medias&file=image/efd.png" into <img src="http://localhostgit/viewimage.php?modulepart=medias&file=image/efd.png"
// We make the reverse, so PDF generation has the real URL.
$labelproductservice = preg_replace ( '/(<img[^>]*src=")([^"]*)(&)([^"]*")/' , '\1\2&\4' , $labelproductservice , - 1 , $nbrep );
//var_dump($labelproductservice);exit;
2011-09-17 03:05:44 +02:00
// Description
2019-01-27 11:55:16 +01:00
$pdf -> writeHTMLCell ( $w , $h , $posx , $posy , $outputlangs -> convToOutputCharset ( $labelproductservice ), 0 , 1 , false , true , 'J' , true );
2019-11-13 19:35:02 +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
*/
2019-01-27 15:20:16 +01:00
function pdf_getlinedesc ( $object , $i , $outputlangs , $hideref = 0 , $hidedesc = 0 , $issupplierline = 0 )
2010-10-27 19:25:46 +02:00
{
2011-09-17 03:05:44 +02:00
global $db , $conf , $langs ;
2019-12-03 19:42:29 +01:00
2019-11-13 19:35:02 +01:00
$idprod = ( ! empty ( $object -> lines [ $i ] -> fk_product ) ? $object -> lines [ $i ] -> fk_product : false );
$label = ( ! empty ( $object -> lines [ $i ] -> label ) ? $object -> lines [ $i ] -> label : ( ! empty ( $object -> lines [ $i ] -> product_label ) ? $object -> lines [ $i ] -> product_label : '' ));
$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 : '' );
$dbatch = ( ! empty ( $object -> lines [ $i ] -> detail_batch ) ? $object -> lines [ $i ] -> detail_batch : false );
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( $issupplierline ) {
2018-09-02 16:09:40 +02:00
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php' ;
$prodser = new ProductFournisseur ( $db );
2020-05-21 15:05:19 +02:00
} else {
2018-09-02 16:09:40 +02:00
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$prodser = new Product ( $db );
2020-10-26 13:05:07 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2021-02-23 22:03:23 +01:00
include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php' ;
2020-10-26 13:05:07 +01:00
}
2018-09-02 16:09:40 +02:00
}
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( $idprod ) {
2011-09-17 03:05:44 +02:00
$prodser -> fetch ( $idprod );
// If a predefined product and multilang and on other lang, we renamed label with label translated
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ( $outputlangs -> defaultlang != $langs -> defaultlang )) {
2019-11-13 19:35:02 +01: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
2021-06-05 11:07:38 +02:00
// ($textwasnotmodified is replaced with $textwasmodifiedorcompleted and we add completion).
2014-06-20 16:01:08 +02:00
// Set label
2021-06-05 15:28:41 +02:00
// If we want another language, and if label is same than default language (we did not force it to a specific value), we can use translation.
2014-06-20 16:01:08 +02:00
//var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
2021-06-05 11:07:38 +02:00
$textwasnotmodified = ( $label == $prodser -> label );
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " label " ]) && ( $textwasnotmodified || $translatealsoifmodified )) {
2020-12-08 21:56:12 +01:00
$label = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " label " ];
}
2014-06-20 16:01:08 +02:00
// Set desc
// Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
2021-06-05 11:07:38 +02:00
$textwasnotmodified = false ;
2013-12-03 17:06:19 +01:00
if ( ! empty ( $desc ) && dol_textishtml ( $desc ) && ! empty ( $prodser -> description ) && dol_textishtml ( $prodser -> description )) {
2021-06-05 11:07:38 +02:00
$textwasnotmodified = ( strpos ( dol_html_entity_decode ( $desc , ENT_QUOTES | ENT_HTML5 ), dol_html_entity_decode ( $prodser -> description , ENT_QUOTES | ENT_HTML5 )) !== false );
2013-12-02 00:20:50 +01:00
} else {
2021-06-05 11:07:38 +02:00
$textwasnotmodified = ( $desc == $prodser -> description );
2013-12-02 00:20:50 +01:00
}
2021-06-05 11:07:38 +02:00
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ]) && ( $textwasnotmodified || $translatealsoifmodified )) {
2021-02-23 22:03:23 +01:00
$desc = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ];
}
2013-12-02 11:11:08 +01:00
2014-06-20 16:01:08 +02:00
// Set note
2021-06-05 11:07:38 +02:00
$textwasnotmodified = ( $note == $prodser -> note_public );
2021-06-05 11:14:06 +02:00
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " other " ]) && ( $textwasnotmodified || $translatealsoifmodified )) {
$note = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " other " ];
2021-02-23 22:03:23 +01:00
}
2011-09-17 03:05:44 +02:00
}
2020-05-21 15:05:19 +02:00
} elseif ( $object -> element == 'facture' || $object -> element == 'facturefourn' ) {
2021-06-10 18:00:49 +02:00
$desc = str_replace ( '(DEPOSIT)' , $outputlangs -> trans ( 'Deposit' ), $desc );
2019-11-30 16:14:16 +01:00
}
2011-09-17 03:05:44 +02:00
// Description short of product line
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $label ;
2020-10-20 14:34:17 +02:00
if ( ! empty ( $libelleproduitservice ) && ! empty ( $conf -> global -> PDF_BOLD_PRODUCT_LABEL )) {
2020-10-31 14:32:18 +01:00
$libelleproduitservice = '<b>' . $libelleproduitservice . '</b>' ;
2020-10-20 14:34:17 +02:00
}
2011-09-17 03:05:44 +02:00
2020-12-08 21:56:12 +01:00
// Add ref of subproducts
if ( ! empty ( $conf -> global -> SHOW_SUBPRODUCT_REF_IN_PDF )) {
$prodser -> get_sousproduits_arbo ();
if ( ! empty ( $prodser -> sousprods ) && is_array ( $prodser -> sousprods ) && count ( $prodser -> sousprods )) {
$tmparrayofsubproducts = reset ( $prodser -> sousprods );
2020-12-09 18:03:02 +01:00
foreach ( $tmparrayofsubproducts as $subprodval ) {
2020-12-08 21:56:12 +01:00
$libelleproduitservice .= " \n * " . $subprodval [ 5 ] . (( $subprodval [ 5 ] && $subprodval [ 3 ]) ? ' - ' : '' ) . $subprodval [ 3 ] . ' (' . $subprodval [ 1 ] . ')' ;
}
}
2020-10-20 14:34:17 +02:00
}
2011-09-17 03:05:44 +02:00
2020-10-20 14:34:17 +02:00
// Description long of product line
2021-02-23 22:03:23 +01:00
if ( ! empty ( $desc ) && ( $desc != $label )) {
if ( $libelleproduitservice && empty ( $hidedesc )) {
2019-11-13 19:35:02 +01:00
$libelleproduitservice .= '__N__' ;
2012-04-26 10:29:46 +02:00
}
2011-09-17 03:05:44 +02:00
2021-02-23 22:03:23 +01:00
if ( $desc == '(CREDIT_NOTE)' && $object -> lines [ $i ] -> fk_remise_except ) {
2019-11-13 19:35:02 +01:00
$discount = new DiscountAbsolute ( $db );
2011-09-17 03:05:44 +02:00
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
2019-11-13 19:35:02 +01:00
$sourceref = ! empty ( $discount -> discount_type ) ? $discount -> ref_invoive_supplier_source : $discount -> ref_facture_source ;
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromCreditNote " , $sourceref );
2021-02-23 22:03:23 +01:00
} elseif ( $desc == '(DEPOSIT)' && $object -> lines [ $i ] -> fk_remise_except ) {
2019-11-13 19:35:02 +01:00
$discount = new DiscountAbsolute ( $db );
2013-04-04 13:58:33 +02:00
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
2019-11-13 19:35:02 +01:00
$sourceref = ! empty ( $discount -> discount_type ) ? $discount -> ref_invoive_supplier_source : $discount -> ref_facture_source ;
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromDeposit " , $sourceref );
2013-04-04 13:58:33 +02:00
// Add date of deposit
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> INVOICE_ADD_DEPOSIT_DATE )) {
$libelleproduitservice .= ' (' . dol_print_date ( $discount -> datec , 'day' , '' , $outputlangs ) . ')' ;
}
} elseif ( $desc == '(EXCESS RECEIVED)' && $object -> lines [ $i ] -> fk_remise_except ) {
2019-11-13 19:35:02 +01:00
$discount = new DiscountAbsolute ( $db );
2016-11-25 11:04:42 +01:00
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromExcessReceived " , $discount -> ref_facture_source );
2021-02-23 22:03:23 +01:00
} elseif ( $desc == '(EXCESS PAID)' && $object -> lines [ $i ] -> fk_remise_except ) {
2019-11-13 19:35:02 +01:00
$discount = new DiscountAbsolute ( $db );
2018-02-19 15:52:07 +01:00
$discount -> fetch ( $object -> lines [ $i ] -> fk_remise_except );
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromExcessPaid " , $discount -> ref_invoice_supplier_source );
2020-05-21 15:05:19 +02:00
} else {
2020-12-08 21:56:12 +01:00
if ( $idprod ) {
// Check if description must be output
if ( ! empty ( $object -> element )) {
$tmpkey = 'MAIN_DOCUMENTS_HIDE_DESCRIPTION_FOR_' . strtoupper ( $object -> element );
if ( ! empty ( $conf -> global -> $tmpkey )) {
$hidedesc = 1 ;
}
}
if ( empty ( $hidedesc )) {
if ( ! empty ( $conf -> global -> MAIN_DOCUMENTS_DESCRIPTION_FIRST )) {
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $desc . " \n " . $libelleproduitservice ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-02 09:39:42 +02:00
if ( ! empty ( $conf -> global -> HIDE_LABEL_VARIANT_PDF ) && $prodser -> isVariant ()) {
2020-10-02 09:21:44 +02:00
$libelleproduitservice = $desc ;
} else {
$libelleproduitservice .= $desc ;
}
2018-06-07 17:24:45 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:02 +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 = " " ;
2020-11-26 10:12:24 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_ADD_TYPE_IN_DOCUMENTS )) { // In standard mode, we do not show this
if ( $prodser -> isService ()) {
2017-11-13 11:30:41 +01:00
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Service " ) . " " ;
2020-05-21 15:05:19 +02:00
} else {
2017-11-13 11:30:41 +01:00
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Product " ) . " " ;
}
}
2011-09-17 03:05:44 +02:00
2020-11-26 10:12:24 +01:00
if ( empty ( $hideref )) {
if ( $issupplierline ) {
if ( empty ( $conf -> global -> PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES )) { // Common case
2017-11-13 11:30:41 +01:00
$ref_prodserv = $prodser -> ref ; // Show local ref
2021-02-23 22:03:23 +01:00
if ( $ref_supplier ) {
$ref_prodserv .= ( $prodser -> ref ? ' (' : '' ) . $outputlangs -> transnoentitiesnoconv ( " SupplierRef " ) . ' ' . $ref_supplier . ( $prodser -> ref ? ')' : '' );
}
2020-11-26 10:12:24 +01:00
} elseif ( $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 . ')' ;
2011-09-17 03:05:44 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-13 11:30:41 +01:00
$ref_prodserv = $prodser -> ref ; // Show local ref only
2020-10-26 13:05:07 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES )) {
2021-02-23 22:03:23 +01:00
$productCustomerPriceStatic = new Productcustomerprice ( $db );
$filter = array ( 'fk_product' => $idprod , 'fk_soc' => $object -> socid );
2020-10-26 13:05:07 +01:00
2021-02-23 22:03:23 +01:00
$nbCustomerPrices = $productCustomerPriceStatic -> fetch_all ( '' , '' , 1 , 0 , $filter );
2020-10-26 13:05:07 +01:00
2021-02-23 22:03:23 +01:00
if ( $nbCustomerPrices > 0 ) {
$productCustomerPrice = $productCustomerPriceStatic -> lines [ 0 ];
2020-10-26 13:05:07 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $productCustomerPrice -> ref_customer )) {
switch ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_PDF_REF_MODE ) {
case 1 :
$ref_prodserv = $productCustomerPrice -> ref_customer ;
break ;
2020-10-26 13:05:07 +01:00
2021-02-23 22:03:23 +01:00
case 2 :
$ref_prodserv = $productCustomerPrice -> ref_customer . ' (' . $outputlangs -> transnoentitiesnoconv ( 'InternalRef' ) . ' ' . $ref_prodserv . ')' ;
break ;
2020-10-26 13:05:07 +01:00
2021-02-23 22:03:23 +01:00
default :
$ref_prodserv = $ref_prodserv . ' (' . $outputlangs -> transnoentitiesnoconv ( 'RefCustomer' ) . ' ' . $productCustomerPrice -> ref_customer . ')' ;
}
}
}
2020-10-26 13:05:07 +01:00
}
2017-11-13 11:30:41 +01:00
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $libelleproduitservice ) && ! empty ( $ref_prodserv )) {
$ref_prodserv .= " - " ;
}
2011-09-17 03:05:44 +02:00
}
2013-09-25 19:58:22 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $ref_prodserv ) && ! empty ( $conf -> global -> PDF_BOLD_PRODUCT_REF_AND_PERIOD )) {
$ref_prodserv = '<b>' . $ref_prodserv . '</b>' ;
}
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice ;
2017-11-13 11:30:41 +01:00
2013-09-03 11:15:19 +02:00
// Add an additional description for the category products
2021-02-23 22:03:23 +01: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' ;
2019-11-13 19:35:02 +01:00
$categstatic = new Categorie ( $db );
2013-09-03 11:15:19 +02:00
// recovering the list of all the categories linked to product
2019-11-13 19:35:02 +01:00
$tblcateg = $categstatic -> containing ( $idprod , Categorie :: TYPE_PRODUCT );
2021-02-23 22:03:23 +01:00
foreach ( $tblcateg as $cate ) {
2013-09-03 11:15:19 +02:00
// Adding the descriptions if they are filled
2020-02-20 09:45:17 +01:00
$desccateg = $cate -> description ;
2021-02-23 22:03:23 +01:00
if ( $desccateg ) {
2019-11-13 19:35:02 +01:00
$libelleproduitservice .= '__N__' . $desccateg ;
2021-02-23 22:03:23 +01:00
}
2013-09-03 11:15:19 +02:00
}
}
2013-09-25 19:58:22 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> date_start ) || ! empty ( $object -> lines [ $i ] -> date_end )) {
2019-11-13 19:35:02 +01:00
$format = 'day' ;
2020-10-31 14:32:18 +01:00
$period = '' ;
2011-09-17 03:05:44 +02:00
// Show duration if exists
2021-02-23 22:03:23 +01:00
if ( $object -> lines [ $i ] -> date_start && $object -> lines [ $i ] -> date_end ) {
2019-11-13 19:35:02 +01:00
$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 )) . ')' ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $object -> lines [ $i ] -> date_start && ! $object -> lines [ $i ] -> date_end ) {
2019-11-13 19:35:02 +01:00
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateFrom' , dol_print_date ( $object -> lines [ $i ] -> date_start , $format , false , $outputlangs )) . ')' ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! $object -> lines [ $i ] -> date_start && $object -> lines [ $i ] -> date_end ) {
2019-11-13 19:35:02 +01:00
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateUntil' , dol_print_date ( $object -> lines [ $i ] -> date_end , $format , false , $outputlangs )) . ')' ;
2011-09-17 03:05:44 +02:00
}
//print '>'.$outputlangs->charset_output.','.$period;
2020-01-30 17:06:26 +01:00
if ( ! empty ( $conf -> global -> PDF_BOLD_PRODUCT_REF_AND_PERIOD )) {
2020-10-31 14:32:18 +01:00
$libelleproduitservice .= '<b style="color:#333666;" ><em>' . " __N__</b> " . $period . '</em>' ;
2019-10-27 11:53:20 +01:00
} else {
2020-10-31 14:32:18 +01:00
$libelleproduitservice .= " __N__ " . $period ;
2018-12-08 17:56:03 +01:00
}
2011-09-17 03:05:44 +02:00
//print $libelleproduitservice;
}
2021-02-23 22:03:23 +01:00
if ( $dbatch ) {
2019-11-13 19:35:02 +01:00
$format = 'day' ;
2021-02-23 22:03:23 +01:00
foreach ( $dbatch as $detail ) {
2019-11-13 19:35:02 +01:00
$dte = array ();
2021-02-23 22:03:23 +01:00
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 );
}
2019-11-13 19:35:02 +01:00
$dte [] = $outputlangs -> transnoentitiesnoconv ( 'printQty' , $detail -> qty );
$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
2021-02-23 22:03:23 +01:00
if ( dol_textishtml ( $libelleproduitservice )) {
$libelleproduitservice = preg_replace ( '/__N__/' , '<br>' , $libelleproduitservice );
} else {
$libelleproduitservice = preg_replace ( '/__N__/' , " \n " , $libelleproduitservice );
}
2019-11-13 19:35:02 +01:00
$libelleproduitservice = dol_htmlentitiesbr ( $libelleproduitservice , 1 );
2011-12-08 20:20:16 +01:00
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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlinenum' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
2019-11-13 19:35:02 +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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineref' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
2019-11-13 19:35:02 +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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getlineref_supplier' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
$result .= $hookmanager -> resPrint ;
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
2019-11-13 19:35:02 +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
*/
2019-01-27 15:20:16 +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
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
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) ) )
2021-02-23 22:03:23 +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 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( empty ( $hidedetails ) || $hidedetails > 1 ) {
2019-11-13 19:35:02 +01:00
$tmpresult = '' ;
2017-08-29 17:22:03 +02:00
2019-11-13 19:35:02 +01:00
$tmpresult .= vatrate ( $object -> lines [ $i ] -> tva_tx , 0 , $object -> lines [ $i ] -> info_bits , - 1 );
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_PDF_MAIN_HIDE_SECOND_TAX )) {
if ( $object -> lines [ $i ] -> total_localtax1 != 0 ) {
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) {
$tmpresult .= '/' ;
} else {
$tmpresult = '' ;
}
2019-11-13 19:35:02 +01:00
$tmpresult .= vatrate ( abs ( $object -> lines [ $i ] -> localtax1_tx ), 0 );
2017-08-29 17:22:03 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> global -> MAIN_PDF_MAIN_HIDE_THIRD_TAX )) {
if ( $object -> lines [ $i ] -> total_localtax2 != 0 ) {
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) {
$tmpresult .= '/' ;
} else {
$tmpresult = '' ;
}
2019-11-13 19:35:02 +01:00
$tmpresult .= vatrate ( abs ( $object -> lines [ $i ] -> localtax2_tx ), 0 );
2017-08-29 17:22:03 +02:00
}
}
2019-11-13 19:35:02 +01:00
$tmpresult .= '%' ;
2017-08-29 17:22:03 +02:00
2019-11-13 19:35:02 +01:00
$result .= $tmpresult ;
2017-08-29 17:22:03 +02:00
}
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
*/
2019-01-27 15:20:16 +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
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) {
$sign = - 1 ;
}
2011-11-11 00:36:01 +01:00
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
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) ) )
2021-02-23 22:03:23 +01: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
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( empty ( $hidedetails ) || $hidedetails > 1 ) {
2020-11-21 16:27:50 +01:00
$subprice = ( ! empty ( $conf -> multicurrency -> enabled ) && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_subprice : $object -> lines [ $i ] -> subprice );
2019-11-13 19:35:02 +01:00
$result .= price ( $sign * $subprice , 0 , $outputlangs );
2016-01-21 22:26:51 +01:00
}
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
*/
2019-01-27 15:20:16 +01:00
function pdf_getlineupwithtax ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-12-03 23:37:16 +01:00
{
2019-11-13 19:35:02 +01:00
global $hookmanager , $conf ;
2016-06-30 14:27:58 +02:00
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) {
$sign = - 1 ;
}
2013-01-26 10:35:30 +01:00
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
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) ) )
2021-02-23 22:03:23 +01: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
2013-04-04 13:58:33 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01: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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2013-04-04 13:58:33 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result = $hookmanager -> resPrint ;
}
2015-10-22 17:51:05 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2015-10-22 17:51:05 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2015-10-22 17:51:05 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
2020-10-31 14:32:18 +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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
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
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
2020-10-31 14:32:18 +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) ) )
2021-02-23 22:03:23 +01: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
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 );
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 = '' ;
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2015-02-26 14:15:33 +01:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
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
*/
2019-01-27 15:20:16 +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
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
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 )
{
2021-02-23 22:03:23 +01:00
if ( empty ( $hookmanager )) {
global $hookmanager ;
}
2018-12-01 11:37:50 +01:00
global $conf ;
2017-10-31 11:17:44 +01:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
2020-10-31 14:32:18 +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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
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 = '' ;
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
return $hookmanager -> resPrint ;
}
2015-10-22 17:51:05 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
return '' ;
}
if ( empty ( $hidedetails ) || $hidedetails > 1 ) {
if ( $conf -> global -> SITUATION_DISPLAY_DIFF_ON_PDF ) {
2017-11-12 20:12:56 +01:00
$prev_progress = 0 ;
2021-02-23 22:03:23 +01:00
if ( method_exists ( $object , 'get_prev_progress' )) {
$prev_progress = $object -> lines [ $i ] -> get_prev_progress ( $object -> id );
2017-11-12 20:12:56 +01:00
}
2021-03-16 10:39:10 +01:00
$result = round ( $object -> lines [ $i ] -> situation_percent - $prev_progress , 1 ) . '%' ;
2021-02-23 22:03:23 +01:00
} else {
2021-03-16 10:39:10 +01:00
$result = round ( $object -> lines [ $i ] -> situation_percent , 1 ) . '%' ;
2021-02-23 22:03:23 +01:00
}
}
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
*/
2019-01-27 15:20:16 +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
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) {
$sign = - 1 ;
}
2011-11-11 00:36:01 +01:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2011-09-17 03:05:44 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
2020-10-31 14:32:18 +01:00
$result .= $outputlangs -> transnoentities ( " Option " );
2021-02-23 22:03:23 +01:00
} elseif ( empty ( $hidedetails ) || $hidedetails > 1 ) {
2020-11-21 23:37:42 +01:00
$total_ht = ( ! empty ( $conf -> multicurrency -> enabled ) && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_total_ht : $object -> lines [ $i ] -> total_ht );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> situation_percent ) && $object -> lines [ $i ] -> situation_percent > 0 ) {
2020-10-31 14:32:18 +01:00
// TODO Remove this. The total should be saved correctly in database instead of being modified here.
$prev_progress = 0 ;
$progress = 1 ;
2021-02-23 22:03:23 +01:00
if ( method_exists ( $object -> lines [ $i ], 'get_prev_progress' )) {
2017-11-12 20:12:56 +01:00
$prev_progress = $object -> lines [ $i ] -> get_prev_progress ( $object -> id );
$progress = ( $object -> lines [ $i ] -> situation_percent - $prev_progress ) / 100 ;
2020-10-31 14:32:18 +01:00
}
2019-11-13 19:35:02 +01:00
$result .= price ( $sign * ( $total_ht / ( $object -> lines [ $i ] -> situation_percent / 100 )) * $progress , 0 , $outputlangs );
2020-10-31 14:32:18 +01:00
} else {
$result .= price ( $sign * $total_ht , 0 , $outputlangs );
}
}
}
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
*/
2019-01-27 15:20:16 +01:00
function pdf_getlinetotalwithtax ( $object , $i , $outputlangs , $hidedetails = 0 )
2011-12-03 23:37:16 +01:00
{
2019-11-13 19:35:02 +01:00
global $hookmanager , $conf ;
2016-06-30 14:27:58 +02:00
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) {
$sign = - 1 ;
}
2013-01-26 10:35:30 +01:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$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) ) )
2021-02-23 22:03:23 +01: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
2015-10-22 17:51:05 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$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
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> resPrint )) {
$result .= $hookmanager -> resPrint ;
}
2013-04-04 13:58:33 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $reshook )) {
if ( $object -> lines [ $i ] -> special_code == 3 ) {
2020-10-31 14:32:18 +01:00
$result .= $outputlangs -> transnoentities ( " Option " );
2021-02-23 22:03:23 +01:00
} elseif ( empty ( $hidedetails ) || $hidedetails > 1 ) {
2020-11-21 23:37:42 +01:00
$total_ttc = ( ! empty ( $conf -> multicurrency -> enabled ) && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_total_ttc : $object -> lines [ $i ] -> total_ttc );
2021-02-23 22:03:23 +01:00
if ( $object -> lines [ $i ] -> situation_percent > 0 ) {
2020-10-31 14:32:18 +01:00
// TODO Remove this. The total should be saved correctly in database instead of being modified here.
$prev_progress = 0 ;
$progress = 1 ;
2021-02-23 22:03:23 +01:00
if ( method_exists ( $object -> lines [ $i ], 'get_prev_progress' )) {
2020-10-31 14:32:18 +01:00
$prev_progress = $object -> lines [ $i ] -> get_prev_progress ( $object -> id );
$progress = ( $object -> lines [ $i ] -> situation_percent - $prev_progress ) / 100 ;
}
$result .= price ( $sign * ( $total_ttc / ( $object -> lines [ $i ] -> situation_percent / 100 )) * $progress , 0 , $outputlangs );
} else {
$result .= price ( $sign * $total_ttc , 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
*/
2019-01-27 15:20:16 +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 ;
2019-11-13 19:35:02 +01:00
$total = 0 ;
$nblines = count ( $object -> lines );
2011-03-31 18:26:57 +02:00
2011-02-23 15:38:39 +01:00
// Loop on each lines
2021-02-23 22:03:23 +01:00
for ( $i = 0 ; $i < $nblines ; $i ++ ) {
if ( $object -> lines [ $i ] -> special_code != 3 ) {
if ( $type == 'all' ) {
2011-02-23 15:38:39 +01:00
$total += $object -> lines [ $i ] -> qty ;
2021-02-23 22:03:23 +01:00
} elseif ( $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-04-13 09:09:59 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-11-13 19:35:02 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'pdf_getTotalQty' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2015-10-29 13:14:38 +01:00
return $hookmanager -> resPrint ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 0 && $object -> lines [ $i ] -> product_type == 0 ) {
2011-02-23 15:38:39 +01:00
$total += $object -> lines [ $i ] -> qty ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 1 && $object -> lines [ $i ] -> product_type == 1 ) {
2011-02-23 15:38:39 +01:00
$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
*/
2019-01-27 15:20:16 +01:00
function pdf_getLinkedObjects ( $object , $outputlangs )
2012-03-02 08:11:40 +01:00
{
2020-08-23 19:13:30 +02:00
global $db , $hookmanager ;
2013-01-26 10:35:30 +01:00
2019-11-13 19:35:02 +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
2021-02-23 22:03:23 +01:00
foreach ( $object -> linkedObjects as $objecttype => $objects ) {
if ( $objecttype == 'facture' ) {
2020-10-31 14:32:18 +01:00
// 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.
2021-02-23 22:03:23 +01:00
} 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
2021-02-23 22:03:23 +01: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 " );
2019-01-27 11:55:16 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date , 'day' , '' , $outputlangs );
2012-03-02 08:11:40 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $objecttype == 'commande' || $objecttype == 'supplier_order' ) {
2012-03-02 08:11:40 +01:00
$outputlangs -> load ( 'orders' );
2021-02-23 22:03:23 +01:00
foreach ( $objects as $elementobject ) {
2012-03-02 08:11:40 +01:00
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " );
2019-11-13 19:35:02 +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 " );
2019-01-27 11:55:16 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date , 'day' , '' , $outputlangs );
2012-03-02 08:11:40 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $objecttype == 'contrat' ) {
2012-07-02 19:30:37 +02:00
$outputlangs -> load ( 'contracts' );
2021-02-23 22:03:23 +01: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 " );
2019-01-27 11:55:16 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> date_contrat , 'day' , '' , $outputlangs );
2012-07-02 19:30:37 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $objecttype == 'fichinter' ) {
2019-08-12 22:21:41 +02:00
$outputlangs -> load ( 'interventions' );
2021-02-23 22:03:23 +01:00
foreach ( $objects as $elementobject ) {
2019-08-12 22:21:41 +02:00
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " InterRef " );
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> transnoentities ( $elementobject -> ref );
$linkedobjects [ $objecttype ][ 'date_title' ] = $outputlangs -> transnoentities ( " InterDate " );
2020-01-22 14:56:19 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( $elementobject -> datec , 'day' , '' , $outputlangs );
2019-08-12 22:21:41 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $objecttype == 'shipping' ) {
2018-09-18 11:02:18 +02:00
$outputlangs -> loadLangs ( array ( " orders " , " sendings " ));
2021-02-23 22:03:23 +01:00
foreach ( $objects as $x => $elementobject ) {
2020-10-31 14:32:18 +01:00
$order = null ;
// We concat this record info into fields xxx_value. title is overwrote.
2021-02-23 22:03:23 +01:00
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
2020-10-31 14:32:18 +01:00
$elementobject -> fetchObjectLinked ( null , '' , null , '' , 'OR' , 1 , 'sourcetype' , 0 );
if ( ! empty ( $elementobject -> linkedObjectsIds [ 'commande' ])) {
2020-08-23 19:20:50 +02:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2020-08-23 19:13:30 +02:00
$order = new Commande ( $db );
2020-08-17 15:00:31 +02:00
$ret = $order -> fetch ( reset ( $elementobject -> linkedObjectsIds [ 'commande' ]));
2021-02-23 22:03:23 +01:00
if ( $ret < 1 ) {
$order = null ;
}
2020-08-17 15:00:31 +02:00
}
2020-10-31 14:32:18 +01:00
}
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $order )) {
2020-10-31 14:32:18 +01:00
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefSending " );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $linkedobjects [ $objecttype ][ 'ref_value' ])) {
$linkedobjects [ $objecttype ][ 'ref_value' ] .= ' / ' ;
}
2020-10-31 14:32:18 +01:00
$linkedobjects [ $objecttype ][ 'ref_value' ] .= $outputlangs -> transnoentities ( $elementobject -> ref );
//$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
//if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
//$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
} else {
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " ) . ' / ' . $outputlangs -> transnoentities ( " RefSending " );
2021-02-23 22:03:23 +01:00
if ( empty ( $linkedobjects [ $objecttype ][ 'ref_value' ])) {
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> convToOutputCharset ( $order -> ref ) . ( $order -> ref_client ? ' (' . $order -> ref_client . ')' : '' );
}
2020-10-31 14:32:18 +01:00
$linkedobjects [ $objecttype ][ 'ref_value' ] .= ' / ' . $outputlangs -> transnoentities ( $elementobject -> ref );
//$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
//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
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2012-07-02 19:30:37 +02:00
$parameters = array ( 'linkedobjects' => $linkedobjects , 'outputlangs' => $outputlangs );
2019-11-13 19:35:02 +01:00
$action = '' ;
$hookmanager -> executeHooks ( 'pdf_getLinkedObjects' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 22:03:23 +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 ;
2019-11-13 19:35:02 +01:00
$maxwidth = ( empty ( $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_WIDTH ) ? 20 : $conf -> global -> MAIN_DOCUMENTS_WITH_PICTURE_WIDTH );
$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' ;
2019-11-13 19:35:02 +01:00
$tmp = dol_getImageSize ( $realpath );
2021-02-23 22:03:23 +01:00
if ( $tmp [ 'height' ]) {
2019-11-13 19:35:02 +01:00
$width = ( int ) round ( $maxheight * $tmp [ 'width' ] / $tmp [ 'height' ]); // I try to use maxheight
2021-02-23 22:03:23 +01:00
if ( $width > $maxwidth ) { // Pb with maxheight, so i use maxwidth
2019-11-13 19:35:02 +01:00
$width = $maxwidth ;
$height = ( int ) round ( $maxwidth * $tmp [ 'height' ] / $tmp [ 'width' ]);
2020-05-21 15:05:19 +02:00
} else // No pb with maxheight
2013-07-13 21:14:05 +02:00
{
2019-11-13 19:35:02 +01:00
$height = $maxheight ;
2013-07-13 21:14:05 +02:00
}
}
2019-11-13 19:35:02 +01:00
return array ( 'width' => $width , 'height' => $height );
2013-07-13 21:14:05 +02:00
}
2019-06-24 12:00:55 +02:00
/**
* Return line total amount discount
*
* @ 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 )
* @ return string Return total of line excl tax
*/
2019-06-24 14:36:06 +02:00
function pdfGetLineTotalDiscountAmount ( $object , $i , $outputlangs , $hidedetails = 0 )
2019-06-24 12:00:55 +02:00
{
global $conf , $hookmanager ;
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && ! empty ( $conf -> global -> INVOICE_POSITIVE_CREDIT_NOTE )) {
$sign = - 1 ;
}
if ( $object -> lines [ $i ] -> special_code == 3 ) {
2019-06-24 12:00:55 +02:00
return $outputlangs -> transnoentities ( " Option " );
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2019-06-24 12:00:55 +02:00
$special_code = $object -> lines [ $i ] -> special_code ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line )) {
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2019-06-24 12:00:55 +02:00
$parameters = array (
'i' => $i ,
'outputlangs' => $outputlangs ,
'hidedetails' => $hidedetails ,
'special_code' => $special_code
);
2019-11-13 19:35:02 +01:00
$action = '' ;
2019-06-24 12:00:55 +02:00
2021-02-23 22:03:23 +01:00
if ( $hookmanager -> executeHooks ( 'getlinetotalremise' , $parameters , $object , $action ) > 0 ) {
2019-11-13 19:35:02 +01:00
return $hookmanager -> resPrint ; // Note that $action and $object may have been modified by some hooks
2019-06-24 12:00:55 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) {
return $sign * (( $object -> lines [ $i ] -> subprice * $object -> lines [ $i ] -> qty ) - $object -> lines [ $i ] -> total_ht );
}
2019-06-24 12:00:55 +02:00
}
return '' ;
2019-06-24 14:36:06 +02:00
}