2009-01-28 16:09:37 +01:00
< ? php
2025-01-13 20:04:35 +01:00
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 >
2022-10-27 22:45:32 +02:00
* Copyright ( C ) 2021 - 2022 Anthony Berton < anthony . berton @ bb2a . fr >
2025-01-05 18:44:12 +01:00
* Copyright ( C ) 2023 - 2025 Frédéric France < frederic . france @ free . fr >
2025-01-13 20:04:35 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . 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
2021-12-15 17:32:15 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php' ;
2009-06-15 20:57:34 +02:00
2021-04-27 00:22:39 +02:00
/**
2024-01-13 19:48:20 +01:00
* Return array head with list of tabs to view object information .
2021-04-27 00:22:39 +02:00
*
2024-09-23 00:37:30 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > head array with tabs
2021-04-27 00:22:39 +02:00
*/
function pdf_admin_prepare_head ()
{
2023-12-18 16:41:40 +01:00
global $langs , $conf ;
2021-04-27 00:22:39 +02:00
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/pdf.php' ;
2021-10-05 06:26:19 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " Parameters " );
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' );
2024-02-27 15:30:37 +01:00
if ( isModEnabled ( " propal " ) || isModEnabled ( 'invoice' ) || isModEnabled ( 'reception' )) {
2021-05-04 00:15:06 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/pdf_other.php' ;
2022-12-16 14:41:45 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Others " );
2021-05-04 00:15:06 +02:00
$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
*
2024-08-29 15:01:42 +02:00
* @ param ? Translate $outputlangs Output lang to use to autodetect output format if we need 'auto' detection
* @ param 'setup' | 'auto' $mode 'setup' = Use setup , 'auto' = Force autodetection whatever is setup
* @ return array { width : float | int , height : float | int , unit : string } Array ( 'width' => w , 'height' => h , 'unit' => u );
2013-04-29 09:25:42 +02:00
*/
2024-09-29 21:52:31 +02:00
function pdf_getFormat ( $outputlangs = null , $mode = 'setup' )
2011-08-11 14:13:59 +02:00
{
2019-06-24 12:59:16 +02:00
global $conf , $db , $langs ;
2023-11-27 11:39:32 +01:00
dol_syslog ( " pdf_getFormat Get paper format with mode= " . $mode . " MAIN_PDF_FORMAT= " . ( ! getDolGlobalString ( '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
2023-11-27 11:39:32 +01:00
if ( $mode == 'auto' || ! getDolGlobalString ( 'MAIN_PDF_FORMAT' ) || getDolGlobalString ( '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 {
2024-01-05 04:18:53 +01:00
$pdfformat = getDolGlobalString ( '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;
2024-03-15 04:22:49 +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
*
2024-08-29 15:01:42 +02:00
* @ param array { float | int , float | int } | array {} | '' $format Array ( width , height ) . Keep empty to use default setup .
2011-12-06 00:39:24 +01:00
* @ param string $metric Unit of format ( 'mm' )
2024-08-29 15:01:42 +02:00
* @ param 'P' | 'l' $pagetype 'P' or 'l'
2024-03-19 19:04:49 +01:00
* @ return TCPDF | TCPDI 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 );
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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).
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_TCPDI' )) {
2021-02-23 22:03:23 +01:00
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'];
2024-09-25 12:48:23 +02:00
//$pdfa = false; // PDF default version
2024-09-26 04:37:44 +02:00
$pdfa = getDolGlobalInt ( 'PDF_USE_A' , 0 ); // PDF/A-1 ou PDF/A-3
2018-06-07 21:12:30 +02:00
2024-01-10 21:51:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_DISABLE_TCPDI' ) && class_exists ( 'TCPDI' )) {
2021-02-23 22:03:23 +01:00
$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
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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
2023-12-04 12:05:28 +01:00
$pdfrights = ( getDolGlobalString ( '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
2024-09-25 12:48:23 +02:00
$pdfuserpass = getDolGlobalString ( 'PDF_SECURITY_ENCRYPTION_USERPASS' );
2018-04-14 15:24:52 +02:00
// Password of the owner, created randomly if not defined
2024-09-25 12:48:23 +02:00
$pdfownerpass = ( getDolGlobalString ( 'PDF_SECURITY_ENCRYPTION_OWNERPASS' ) ? getDolGlobalString ( '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
2024-09-25 12:48:23 +02:00
$encstrength = getDolGlobalInt ( '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')))
2023-12-04 12:05:28 +01:00
$pubkeys = ( getDolGlobalString ( '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();
2023-04-30 03:10:20 +02:00
@ ( $parser = new TCPDF_PARSER ( ltrim ( $content )));
2019-06-03 09:36:00 +02:00
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 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_FORCE_FONT' )) {
2021-02-23 22:03:23 +01:00
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' );
}
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_FORCE_FONT_SIZE' )) {
2024-01-05 04:18:53 +01:00
$size = getDolGlobalString ( 'MAIN_PDF_FORCE_FONT_SIZE' );
2021-02-23 22:03:23 +01:00
}
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 )
2024-03-15 04:22:49 +01:00
* @ return int | float
2012-04-01 23:57:15 +02:00
*/
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 ;
2023-11-27 11:39:32 +01:00
$height = ( ! getDolGlobalString ( '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
2024-01-13 19:48:20 +01:00
* @ param string $htmlcontent HTML Content
2018-10-04 17:56:56 +02:00
* @ 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
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 1 > $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 ) {
2022-06-07 10:58:19 +02:00
$socname = $thirdparty -> name ;
if (( $includealias || getDolGlobalInt ( 'PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME' )) && ! empty ( $thirdparty -> name_alias )) {
if ( getDolGlobalInt ( 'PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME' ) == 2 ) {
2022-01-26 18:46:51 +01:00
$socname = $thirdparty -> name_alias . " - " . $thirdparty -> name ;
2022-06-07 10:58:19 +02:00
} else {
$socname = $thirdparty -> name . " - " . $thirdparty -> name_alias ;
2022-01-26 18:36:04 +01:00
}
2016-02-24 13:29:37 +01:00
}
2015-02-27 15:08:08 +01:00
} elseif ( $thirdparty instanceof Contact ) {
2022-10-27 22:50:30 +02:00
if ( $thirdparty -> socid > 0 ) {
$thirdparty -> fetch_thirdparty ();
$socname = $thirdparty -> thirdparty -> name ;
if (( $includealias || getDolGlobalInt ( 'PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME' )) && ! empty ( $thirdparty -> thirdparty -> name_alias )) {
if ( getDolGlobalInt ( 'PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME' ) == 2 ) {
$socname = $thirdparty -> thirdparty -> name_alias . " - " . $thirdparty -> thirdparty -> name ;
} else {
$socname = $thirdparty -> thirdparty -> name . " - " . $thirdparty -> thirdparty -> name_alias ;
}
2022-10-27 22:45:32 +02:00
}
2022-06-07 10:58:19 +02:00
}
2015-02-27 15:08:08 +01:00
} 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
/**
2024-05-09 14:55:50 +02:00
* Return a string with full address formatted for output on PDF 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 )
2024-09-23 00:37:30 +02:00
* @ param ? CommonObject $object Object we want to build document for
2024-01-18 21:10:58 +01:00
* @ return string | int String with full address or - 1 if KO
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
{
2024-05-09 14:55:50 +02:00
global $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 = '' ;
2025-01-13 20:04:35 +01:00
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
2019-11-13 19:35:02 +01:00
$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 ;
2022-07-28 17:09:56 +02:00
if ( isset ( $targetcompany -> country_code ) && ! empty ( $sourcecompany -> country_code ) && ( $targetcompany -> country_code != $sourcecompany -> country_code )) {
2021-02-23 22:03:23 +01:00
$withCountry = 1 ;
}
2020-10-31 14:32:18 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $sourcecompany , $withCountry , " \n " , $outputlangs )) . " \n " ;
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( '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
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_TVAINTRA_IN_SOURCE_ADDRESS' )) {
2021-02-23 22:03:23 +01:00
if ( $sourcecompany -> tva_intra ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> tva_intra );
}
2020-10-31 14:32:18 +01:00
}
2024-02-09 15:58:49 +01:00
// Professional Ids
2020-10-31 14:32:18 +01:00
$reg = array ();
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PDF_ADD_MORE_AFTER_SOURCE_ADDRESS' )) {
2023-10-15 15:32:35 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . getDolGlobalString ( 'PDF_ADD_MORE_AFTER_SOURCE_ADDRESS' );
2020-10-31 14:32:18 +01:00
}
}
2021-02-23 22:03:23 +01:00
if ( $mode == 'target' || preg_match ( '/targetwithdetails/' , $mode )) {
2024-10-24 03:16:23 +02:00
if ( $usecontact && ( is_object ( $targetcontact ))) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $targetcontact -> getFullName ( $outputlangs , 1 ));
2018-09-03 17:55:24 +02:00
2024-10-24 03:16:23 +02:00
if ( ! empty ( $targetcontact -> address )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcontact )) . " \n " ;
} else {
$companytouseforaddress = $targetcompany ;
// Contact on a thirdparty that is a different thirdparty than the thirdparty of object
if ( $targetcontact -> socid > 0 && $targetcontact -> socid != $targetcompany -> id ) {
$targetcontact -> fetch_thirdparty ();
$companytouseforaddress = $targetcontact -> thirdparty ;
2018-09-05 20:39:38 +02:00
}
2018-09-03 17:55:24 +02:00
2024-10-24 03:16:23 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $companytouseforaddress )) . " \n " ;
}
// 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 ));
}
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || preg_match ( '/targetwithdetails/' , $mode )) {
// Phone
if ( getDolGlobalString ( '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 " ) . " : " ;
2021-02-23 22:03:23 +01:00
}
2024-10-24 03:16:23 +02:00
if ( ! empty ( $targetcontact -> phone_pro )) {
$stringaddress .= $outputlangs -> convToOutputCharset ( $targetcontact -> phone_pro );
2021-02-23 22:03:23 +01:00
}
2024-10-24 03:16:23 +02:00
if ( ! empty ( $targetcontact -> phone_pro ) && ! empty ( $targetcontact -> phone_mobile )) {
$stringaddress .= " / " ;
2021-02-23 22:03:23 +01:00
}
2024-10-24 03:16:23 +02:00
if ( ! empty ( $targetcontact -> phone_mobile )) {
$stringaddress .= $outputlangs -> convToOutputCharset ( $targetcontact -> phone_mobile );
}
}
// Fax
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode )) {
if ( $targetcontact -> fax ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> fax );
2021-02-23 22:03:23 +01:00
}
2024-10-24 03:16:23 +02:00
}
// EMail
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode )) {
if ( $targetcontact -> email ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> email );
}
}
// Web
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode )) {
if ( $targetcontact -> url ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcontact -> url );
2021-02-23 22:03:23 +01:00
}
2020-10-31 14:32:18 +01:00
}
}
} else {
2022-05-19 13:08:00 +02:00
if ( is_object ( $targetcompany )) {
2023-04-10 11:59:24 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( dol_format_address ( $targetcompany ));
2022-05-19 13:08:00 +02:00
// Country
if ( ! empty ( $targetcompany -> country_code ) && $targetcompany -> country_code != $sourcecompany -> country_code ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> country_code ));
2023-04-10 13:26:04 +02:00
} else {
$stringaddress .= ( $stringaddress ? " \n " : '' );
2022-05-19 13:08:00 +02:00
}
2020-10-31 14:32:18 +01:00
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || preg_match ( '/targetwithdetails/' , $mode )) {
2022-05-19 13:08:00 +02:00
// Phone
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_phone/' , $mode )) {
2022-05-19 13:08:00 +02:00
if ( ! empty ( $targetcompany -> phone )) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " ;
}
if ( ! empty ( $targetcompany -> phone )) {
$stringaddress .= $outputlangs -> convToOutputCharset ( $targetcompany -> phone );
}
2021-02-23 22:03:23 +01:00
}
2022-05-19 13:08:00 +02:00
// Fax
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_fax/' , $mode )) {
2022-05-19 13:08:00 +02:00
if ( $targetcompany -> fax ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> fax );
}
2021-02-23 22:03:23 +01:00
}
2022-05-19 13:08:00 +02:00
// EMail
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_email/' , $mode )) {
2022-05-19 13:08:00 +02:00
if ( $targetcompany -> email ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> email );
}
2021-02-23 22:03:23 +01:00
}
2022-05-19 13:08:00 +02:00
// Web
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PDF_ADDALSOTARGETDETAILS' ) || $mode == 'targetwithdetails' || preg_match ( '/targetwithdetails_url/' , $mode )) {
2022-05-19 13:08:00 +02:00
if ( $targetcompany -> url ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $targetcompany -> url );
}
2021-02-23 22:03:23 +01:00
}
2020-10-31 14:32:18 +01:00
}
}
}
// Intra VAT
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_TVAINTRA_NOT_IN_ADDRESS' )) {
2023-10-26 12:28:00 +02:00
if ( $usecontact && is_object ( $targetcontact ) && getDolGlobalInt ( 'MAIN_USE_COMPANY_NAME_OF_CONTACT' )) {
$targetcontact -> fetch_thirdparty ();
if ( ! empty ( $targetcontact -> thirdparty -> id ) && $targetcontact -> thirdparty -> tva_intra ) {
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcontact -> thirdparty -> tva_intra );
}
2024-05-22 17:25:31 +02:00
} elseif ( ! empty ( $targetcompany -> tva_intra )) {
2021-02-23 22:03:23 +01:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> tva_intra );
}
2020-10-31 14:32:18 +01:00
}
2024-05-09 14:55:50 +02:00
// Legal form
if ( getDolGlobalString ( 'MAIN_LEGALFORM_IN_ADDRESS' ) && ! empty ( $targetcompany -> forme_juridique_code )) {
2024-09-05 16:05:37 +02:00
$tmp = getFormeJuridiqueLabel (( string ) $targetcompany -> forme_juridique_code );
2024-05-09 14:55:50 +02:00
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $tmp ;
}
2024-02-09 15:58:49 +01:00
// Professional Ids
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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 );
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_PUBLIC_NOTE_IN_ADDRESS' )) {
2021-02-23 22:03:23 +01:00
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
*
2024-09-23 00:37:30 +02:00
* @ param TCPDF $pdf Object PDF
* @ param Translate $outputlangs Object lang for output
2024-11-07 17:31:40 +01:00
* @ param float $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
2023-12-13 15:20:53 +01:00
if ( getDolGlobalString ( 'MAIN_USE_BACKGROUND_ON_PDF' ) && ( getDolGlobalString ( 'MAIN_USE_BACKGROUND_ON_PDF' ) != '-1' )) { // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
2023-10-15 15:32:35 +02:00
$filepath = $conf -> mycompany -> dir_output . '/logos/' . getDolGlobalString ( 'MAIN_USE_BACKGROUND_ON_PDF' );
2021-12-14 11:19:41 +01:00
if ( file_exists ( $filepath )) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 ); // Disable auto pagebreak before adding image
2023-12-04 12:05:28 +01:00
if ( getDolGlobalString ( 'MAIN_USE_BACKGROUND_ON_PDF_ALPHA' )) {
2024-11-07 17:31:40 +01:00
$pdf -> SetAlpha ( getDolGlobalFloat ( 'MAIN_USE_BACKGROUND_ON_PDF_ALPHA' ));
2023-12-04 12:05:28 +01:00
} // Option for change opacity of background
2024-11-07 17:31:40 +01:00
$pdf -> Image ( $filepath , getDolGlobalFloat ( 'MAIN_USE_BACKGROUND_ON_PDF_X' ), getDolGlobalFloat ( 'MAIN_USE_BACKGROUND_ON_PDF_Y' ), 0 , $page_height );
2023-12-04 12:05:28 +01:00
if ( getDolGlobalString ( 'MAIN_USE_BACKGROUND_ON_PDF_ALPHA' )) {
$pdf -> SetAlpha ( 1 );
}
2023-02-11 14:30:58 +01:00
$pdf -> SetPageMark (); // This option avoid to have the images missing on some pages
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 ); // Restore pagebreak
2021-12-14 11:19:41 +01:00
}
2011-09-17 03:05:44 +02:00
}
2023-03-12 18:38:26 +01:00
if ( getDolGlobalString ( 'MAIN_ADD_PDF_BACKGROUND' ) && getDolGlobalString ( 'MAIN_ADD_PDF_BACKGROUND' ) != '-1' ) {
2023-02-11 18:02:28 +01:00
$pdf -> SetPageMark (); // This option avoid to have the images missing on some pages
}
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
*
2024-03-07 16:41:39 +01:00
* @ param Translate $outputlangs Output language
2024-09-23 00:37:30 +02:00
* @ param null | string [] $exclude Array of family keys we want to exclude . For example array ( 'mycompany' , 'object' , 'date' , 'user' , ... )
* @ param ? Object $object Object
* @ param int < 0 , 2 > $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 )
* @ param null | string [] $include Array of family keys we want to include . For example array ( 'system' , 'mycompany' , 'object' , 'objectamount' , 'date' , 'user' , ... )
* @ return array < string , string > Array of substitutions
2017-04-17 13:02:40 +02:00
*/
2023-03-25 12:40:23 +01:00
function pdf_getSubstitutionArray ( $outputlangs , $exclude = null , $object = null , $onlykey = 0 , $include = null )
2017-04-17 13:02:40 +02:00
{
2023-03-25 12:40:23 +01:00
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , $onlykey , $exclude , $object , $include );
2020-10-31 14:32:18 +01:00
$substitutionarray [ '__FROM_NAME__' ] = '__FROM_NAME__' ;
$substitutionarray [ '__FROM_EMAIL__' ] = '__FROM_EMAIL__' ;
return $substitutionarray ;
2017-04-17 13:02:40 +02:00
}
2010-09-01 16:13:51 +02:00
/**
* Add a draft watermark on PDF files
2011-09-12 19:43:31 +02:00
*
2017-06-01 01:53:55 +02:00
* @ param TCPDF $pdf Object PDF
2011-12-06 00:39:24 +01:00
* @ param Translate $outputlangs Object lang
2024-11-07 17:31:40 +01:00
* @ param float $h Height of PDF
* @ param float $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 )
{
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 ;
2024-09-23 00:37:30 +02:00
} else {
$k = 1 ;
dol_print_error ( null , 'Unexpected unit "' . $unit . '" for pdf_watermark' );
2021-02-23 22:03:23 +01:00
}
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 );
2024-10-24 13:57:57 +02:00
$pdf -> SetTextColor ( 255 , 0 , 0 );
2024-01-10 21:51:32 +01:00
2024-11-07 17:31:40 +01: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 ));
2024-11-07 17:31:40 +01:00
// print watermark
2024-08-07 01:59:37 +02:00
$pdf -> SetAlpha ( 0.5 );
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $watermark_x_pos , $watermark_y_pos );
2024-10-24 13:57:57 +02:00
// set alpha to semi-transparency
$pdf -> SetAlpha ( 0.3 );
2025-02-05 00:52:48 +01:00
$pdf -> Cell ( $w - 20 , 25 , $outputlangs -> convToOutputCharset ( $text ), " " , 2 , " C " , false );
2024-10-24 13:57:57 +02:00
2024-11-07 17:31:40 +01:00
// antirotate
2011-09-17 03:05:44 +02:00
$pdf -> _out ( 'Q' );
2013-07-25 18:56:09 +02:00
2019-01-27 11:55:16 +01:00
$pdf -> SetXY ( $savx , $savy );
2024-10-24 13:57:57 +02:00
// Restore alpha
$pdf -> SetAlpha ( 1 );
2010-09-01 16:13:51 +02:00
}
2009-01-28 16:09:37 +01:00
/**
2024-01-13 19:48:20 +01:00
* Show bank information for PDF generation
2011-09-17 03:05:44 +02:00
*
2024-04-20 22:53:40 +02:00
* @ param TCPDF $pdf Object PDF
2012-04-02 20:08:08 +02:00
* @ param Translate $outputlangs Object lang
2024-11-07 17:31:40 +01:00
* @ param float $curx X
* @ param float $cury Y
2012-04-02 20:08:08 +02:00
* @ param Account $account Bank account object
2024-02-21 16:43:41 +01:00
* @ param int $onlynumber Output only number ( bank + desk + key + number according to country , but without name of bank and address )
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
2024-04-20 22:53:40 +02:00
$diffsizetitle = getDolGlobalInt ( 'PDF_DIFFSIZE_TITLE' , 3 );
$diffsizecontent = getDolGlobalInt ( 'PDF_DIFFSIZE_CONTENT' , 4 );
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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( 'PaymentByTransferOnThisBankAccount' ) . ':' , 0 , 'L' , false );
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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , false );
2019-11-13 19:35:02 +01:00
$cury += 3 ;
2011-09-17 03:05:44 +02:00
}
2024-01-13 19:48:20 +01:00
if ( ! getDolGlobalString ( 'PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN' )) { // Note that some countries still need bank number, BIC/IBAN not enough 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 ;
}
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $tmplength , 3 , $outputlangs -> convToOutputCharset ( $content ), 0 , 'C' , false );
2016-03-19 23:00:33 +01:00
$pdf -> SetXY ( $curx , $cury + 1 );
$curx += $tmplength ;
2017-08-07 15:43:42 +02:00
$pdf -> SetFont ( '' , 'B' , $default_font_size - $diffsizecontent );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $tmplength , 3 , $outputlangs -> transnoentities ( $val ), 0 , 'C' , false );
2016-03-19 23:00:33 +01:00
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
}
2024-03-30 12:46:22 +01:00
} elseif ( ! empty ( $account -> number )) {
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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , false );
2019-11-13 19:35:02 +01:00
$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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( " BankAccountNumber " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> number ), 0 , 'L' , false );
2019-11-13 19:35:02 +01:00
$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
2024-10-24 12:38:41 +02:00
if ( empty ( $onlynumber ) && ! empty ( $account -> address )) {
2011-09-20 14:56:06 +02:00
$pdf -> SetXY ( $curx , $cury );
2024-10-24 12:38:41 +02:00
$val = $outputlangs -> transnoentities ( " Residence " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> address );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $val , 0 , 'L' , false );
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
2024-04-20 22:53:40 +02:00
if ( ! empty ( $account -> owner_name )) {
2015-03-01 21:31:03 +01:00
$pdf -> SetXY ( $curx , $cury );
2024-04-20 22:53:40 +02:00
$val = $outputlangs -> transnoentities ( " BankAccountOwner " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> owner_name );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $val , 0 , 'L' , false );
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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $ibankey ) . ': ' . $ibanDisplay , 0 , 'L' , false );
2019-11-13 19:35:02 +01:00
$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 );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( $bickey ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bic ), 0 , 'L' , false );
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
*
2024-01-29 11:24:37 +01: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
2024-10-03 19:40:34 +02:00
* @ param ? Societe $fromcompany Object company
2024-11-07 17:31:40 +01:00
* @ param float $marge_basse Margin bottom we use for the autobreak
* @ param float $marge_gauche Margin left ( no more used )
2024-10-24 14:01:30 +02:00
* @ param float $page_hauteur Page height
2024-09-23 00:37:30 +02:00
* @ param CommonObject $object Object shown in PDF
* @ param int < 0 , 3 > $showdetails Show company address 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
2024-11-07 17:31:40 +01:00
* @ param float $page_largeur Page width
2024-01-13 15:32:07 +01:00
* @ param string $watermark Watermark text to print on page
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
*/
2022-05-22 00:05:03 +02:00
function pdf_pagefoot ( & $pdf , $outputlangs , $paramfreetext , $fromcompany , $marge_basse , $marge_gauche , $page_hauteur , $object , $showdetails = 0 , $hidefreetext = 0 , $page_largeur = 0 , $watermark = '' )
2009-01-28 16:09:37 +01:00
{
2024-01-10 21:51:32 +01:00
global $conf , $hookmanager ;
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 = '' ;
2021-11-07 13:53:30 +01:00
$reg = array ();
2024-03-20 19:59:51 +01:00
$marginwithfooter = 0 ; // Return value
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
2024-07-03 20:05:29 +02:00
if ( empty ( $hidefreetext ) && getDolGlobalString ( $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
2024-10-03 19:40:34 +02:00
if ( is_object ( $fromcompany )) {
$substitutionarray [ '__FROM_NAME__' ] = $fromcompany -> name ;
$substitutionarray [ '__FROM_EMAIL__' ] = $fromcompany -> email ;
}
2017-06-01 13:32:20 +02:00
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
2023-12-13 15:20:53 +01:00
$newfreetext = make_substitutions ( getDolGlobalString ( $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
2024-10-03 19:40:34 +02:00
if ( is_object ( $fromcompany ) && in_array ( $showdetails , array ( 1 , 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-10-22 15:27:36 +02:00
if ( $showdetails == 2 || $showdetails == 3 || ( ! empty ( $fromcompany -> country_code ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> forme_juridique_code ) && $fromcompany -> forme_juridique_code ) {
2024-09-05 16:05:37 +02:00
$line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> convToOutputCharset ( getFormeJuridiqueLabel (( string ) $fromcompany -> forme_juridique_code ));
2011-09-17 03:05:44 +02:00
}
// Capital
2022-02-10 10:23:42 +01:00
if ( ! empty ( $fromcompany -> capital )) {
2022-02-07 20:53:13 +01:00
$tmpamounttoshow = price2num ( $fromcompany -> capital ); // This field is a free string or a float
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 ));
2022-02-07 16:36:47 +01:00
} elseif ( ! empty ( $fromcompany -> capital )) {
2022-02-07 16:33:27 +01:00
$line3 .= ( $line3 ? " - " : " " ) . $outputlangs -> transnoentities ( " CapitalOf " , $fromcompany -> capital , $outputlangs );
2021-02-23 22:03:23 +01:00
}
2011-09-17 03:05:44 +02:00
}
// Prof Id 1
2021-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof1 ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof2 ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof3 ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof4 ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof5 ) && $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-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> idprof6 ) && $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
}
2023-10-12 17:44:08 +02:00
// Prof Id 7
if ( ! empty ( $fromcompany -> idprof7 ) && $fromcompany -> idprof7 ) {
$field = $outputlangs -> transcountrynoentities ( " ProfId7 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof7 );
}
// Prof Id 8
if ( ! empty ( $fromcompany -> idprof8 ) && $fromcompany -> idprof8 ) {
$field = $outputlangs -> transcountrynoentities ( " ProfId8 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof8 );
}
// Prof Id 9
if ( ! empty ( $fromcompany -> idprof9 ) && $fromcompany -> idprof9 ) {
$field = $outputlangs -> transcountrynoentities ( " ProfId9 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof9 );
}
// Prof Id 10
if ( ! empty ( $fromcompany -> idprof10 ) && $fromcompany -> idprof10 ) {
$field = $outputlangs -> transcountrynoentities ( " ProfId10 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) {
$field = $reg [ 1 ];
}
$line4 .= ( $line4 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof10 );
}
2011-09-17 03:05:44 +02:00
// IntraCommunautary VAT
2021-10-22 15:27:36 +02:00
if ( ! empty ( $fromcompany -> tva_intra ) && $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 );
2022-02-05 13:22:18 +01:00
// Option for footer text color
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PDF_FOOTER_TEXT_COLOR' )) {
2022-02-05 13:22:18 +01:00
list ( $r , $g , $b ) = sscanf ( $conf -> global -> PDF_FOOTER_TEXT_COLOR , '%d, %d, %d' );
$pdf -> SetTextColor ( $r , $g , $b );
}
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 ;
2024-09-23 00:37:30 +02:00
$align = null ;
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>";
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( '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.
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( '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
}
}
2024-09-23 00:37:30 +02:00
$posy = 0 ;
// For customized footer
2021-12-06 07:47:24 +01:00
if ( is_object ( $hookmanager )) {
2024-03-15 04:22:49 +01:00
$parameters = array ( 'line1' => $line1 , 'line2' => $line2 , 'line3' => $line3 , 'line4' => $line4 , 'outputlangs' => $outputlangs );
2021-12-06 07:47:24 +01:00
$action = '' ;
$hookmanager -> executeHooks ( 'pdf_pagefoot' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-12-08 16:43:11 +01:00
if ( ! empty ( $hookmanager -> resPrint ) && $hidefreetext == 0 ) {
2021-12-06 07:47:24 +01:00
$mycustomfooter = $hookmanager -> resPrint ;
$mycustomfooterheight = pdfGetHeightForHtmlContent ( $pdf , dol_htmlentitiesbr ( $mycustomfooter , 1 , 'UTF-8' , 0 ));
$marginwithfooter = $marge_basse + $freetextheight + $mycustomfooterheight ;
2022-12-28 16:40:03 +01:00
$posy = ( float ) $marginwithfooter ;
2021-12-06 07:47:24 +01:00
2022-02-05 13:22:18 +01:00
// Option for footer background color (without freetext zone)
2022-04-09 02:51:40 +02:00
if ( getDolGlobalString ( 'PDF_FOOTER_BACKGROUND_COLOR' )) {
2022-02-05 13:22:18 +01:00
list ( $r , $g , $b ) = sscanf ( $conf -> global -> PDF_FOOTER_BACKGROUND_COLOR , '%d, %d, %d' );
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 ); // Disable auto pagebreak
2024-09-23 00:37:30 +02:00
$pdf -> Rect ( 0 , $dims [ 'hk' ] - $posy + $freetextheight , $dims [ 'wk' ] + 1 , $marginwithfooter + 1 , 'F' , array (), $fill_color = array ( $r , $g , $b ));
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 ); // Restore pagebreak
2022-02-05 13:22:18 +01:00
}
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FREETEXT_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 );
2023-12-04 12:05:28 +01:00
} // Option for disable auto pagebreak
2021-12-06 07:47:24 +01:00
if ( $line ) { // Free text
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2022-04-09 02:51:40 +02:00
if ( ! getDolGlobalString ( 'PDF_ALLOW_HTML_FOR_FREE_TEXT' )) { // by default
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 0 , 3 , $line , 0 , $align , false );
2021-12-06 07:47:24 +01:00
} else {
2024-01-29 11:24:37 +01:00
$pdf -> writeHTMLCell ( $dims [ 'wk' ] - $dims [ 'lm' ] - $dims [ 'rm' ], $freetextheight , $dims [ 'lm' ], $dims [ 'hk' ] - $marginwithfooter , dol_htmlentitiesbr ( $line , 1 , 'UTF-8' , 0 ));
2021-12-06 07:47:24 +01:00
}
$posy -= $freetextheight ;
}
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FREETEXT_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 );
2023-12-04 12:05:28 +01:00
} // Restore pagebreak
2021-12-06 07:47:24 +01:00
$pdf -> SetY ( - $posy );
2022-02-05 13:22:18 +01:00
// Hide footer line if footer background color is set
2022-04-09 02:51:40 +02:00
if ( ! getDolGlobalString ( 'PDF_FOOTER_BACKGROUND_COLOR' )) {
2022-02-05 13:22:18 +01:00
$pdf -> line ( $dims [ 'lm' ], $dims [ 'hk' ] - $posy , $dims [ 'wk' ] - $dims [ 'rm' ], $dims [ 'hk' ] - $posy );
}
// Option for set top margin height of footer after freetext
2022-08-23 16:26:52 +02:00
if ( getDolGlobalString ( 'PDF_FOOTER_TOP_MARGIN' ) || getDolGlobalInt ( 'PDF_FOOTER_TOP_MARGIN' ) === 0 ) {
2023-12-27 12:12:20 +01:00
$posy -= ( float ) getDolGlobalString ( 'PDF_FOOTER_TOP_MARGIN' );
2022-04-09 02:51:40 +02:00
} else {
$posy -- ;
}
2022-02-05 13:22:18 +01:00
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FOOTER_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 );
2023-12-04 12:05:28 +01:00
} // Option for disable auto pagebreak
2024-01-29 11:24:37 +01:00
$pdf -> writeHTMLCell ( $dims [ 'wk' ] - $dims [ 'lm' ] - $dims [ 'rm' ], $mycustomfooterheight , $dims [ 'lm' ], $dims [ 'hk' ] - $posy , dol_htmlentitiesbr ( $mycustomfooter , 1 , 'UTF-8' , 0 ));
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FOOTER_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 );
2023-12-04 12:05:28 +01:00
} // Restore pagebreak
2021-12-06 07:47:24 +01:00
$posy -= $mycustomfooterheight - 3 ;
2021-12-06 12:06:50 +01:00
} else {
2021-12-06 12:06:32 +01:00
// Else default footer
2021-12-06 07:47:24 +01:00
$marginwithfooter = $marge_basse + $freetextheight + ( ! empty ( $line1 ) ? 3 : 0 ) + ( ! empty ( $line2 ) ? 3 : 0 ) + ( ! empty ( $line3 ) ? 3 : 0 ) + ( ! empty ( $line4 ) ? 3 : 0 );
2022-12-28 16:40:03 +01:00
$posy = ( float ) $marginwithfooter ;
2011-01-16 03:26:20 +01:00
2022-02-05 13:22:18 +01:00
// Option for footer background color (without freetext zone)
2022-04-09 02:51:40 +02:00
if ( getDolGlobalString ( 'PDF_FOOTER_BACKGROUND_COLOR' )) {
2022-02-05 13:22:18 +01:00
list ( $r , $g , $b ) = sscanf ( $conf -> global -> PDF_FOOTER_BACKGROUND_COLOR , '%d, %d, %d' );
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 ); // Disable auto pagebreak
2024-09-23 00:37:30 +02:00
$pdf -> Rect ( 0 , $dims [ 'hk' ] - $posy + $freetextheight , $dims [ 'wk' ] + 1 , $marginwithfooter + 1 , 'F' , array (), $fill_color = array ( $r , $g , $b ));
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 ); // Restore pagebreak
2022-02-05 13:22:18 +01:00
}
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FREETEXT_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( false , 0 );
2023-12-04 12:05:28 +01:00
} // Option for disable auto pagebreak
2021-12-06 07:47:24 +01:00
if ( $line ) { // Free text
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2022-04-09 02:51:40 +02:00
if ( ! getDolGlobalString ( 'PDF_ALLOW_HTML_FOR_FREE_TEXT' )) { // by default
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 0 , 3 , $line , 0 , $align , false );
2021-12-06 07:47:24 +01:00
} else {
2024-01-29 11:24:37 +01:00
$pdf -> writeHTMLCell ( $dims [ 'wk' ] - $dims [ 'lm' ] - $dims [ 'rm' ], $freetextheight , $dims [ 'lm' ], $dims [ 'hk' ] - $marginwithfooter , dol_htmlentitiesbr ( $line , 1 , 'UTF-8' , 0 ));
2021-12-06 07:47:24 +01:00
}
$posy -= $freetextheight ;
}
2023-12-04 12:05:28 +01:00
if ( getDolGlobalInt ( 'PDF_FREETEXT_DISABLE_PAGEBREAK' ) === 1 ) {
2025-02-05 00:52:48 +01:00
$pdf -> setAutoPageBreak ( true , 0 );
2023-12-04 12:05:28 +01:00
} // Restore pagebreak
2011-01-16 03:26:20 +01:00
2021-12-06 07:47:24 +01:00
$pdf -> SetY ( - $posy );
2022-02-05 13:22:18 +01:00
2023-02-02 17:28:47 +01:00
// Option for hide all footer (page number will no hidden)
2023-03-12 18:39:58 +01:00
if ( ! getDolGlobalInt ( 'PDF_FOOTER_HIDDEN' )) {
2023-02-02 17:28:47 +01:00
// Hide footer line if footer background color is set
if ( ! getDolGlobalString ( 'PDF_FOOTER_BACKGROUND_COLOR' )) {
$pdf -> line ( $dims [ 'lm' ], $dims [ 'hk' ] - $posy , $dims [ 'wk' ] - $dims [ 'rm' ], $dims [ 'hk' ] - $posy );
}
2011-09-17 03:05:44 +02:00
2023-02-02 17:28:47 +01:00
// Option for set top margin height of footer after freetext
if ( getDolGlobalString ( 'PDF_FOOTER_TOP_MARGIN' ) || getDolGlobalInt ( 'PDF_FOOTER_TOP_MARGIN' ) === 0 ) {
2023-12-27 12:12:20 +01:00
$posy -= ( float ) getDolGlobalString ( 'PDF_FOOTER_TOP_MARGIN' );
2023-02-02 17:28:47 +01:00
} else {
$posy -- ;
}
2011-09-17 03:05:44 +02:00
2023-02-02 17:28:47 +01:00
if ( ! empty ( $line1 )) {
$pdf -> SetFont ( '' , 'B' , 7 );
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line1 , 0 , 'C' , false );
2023-02-02 17:28:47 +01:00
$posy -= 3 ;
$pdf -> SetFont ( '' , '' , 7 );
}
2021-12-06 07:47:24 +01:00
2023-02-02 17:28:47 +01:00
if ( ! empty ( $line2 )) {
$pdf -> SetFont ( '' , 'B' , 7 );
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line2 , 0 , 'C' , false );
2023-02-02 17:28:47 +01:00
$posy -= 3 ;
$pdf -> SetFont ( '' , '' , 7 );
}
2011-09-17 03:05:44 +02:00
2023-02-02 17:28:47 +01:00
if ( ! empty ( $line3 )) {
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line3 , 0 , 'C' , false );
2023-02-02 17:28:47 +01:00
}
if ( ! empty ( $line4 )) {
$posy -= 3 ;
$pdf -> SetXY ( $dims [ 'lm' ], - $posy );
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( $dims [ 'wk' ] - $dims [ 'rm' ] - $dims [ 'lm' ], 2 , $line4 , 0 , 'C' , false );
2023-02-02 17:28:47 +01:00
}
2021-12-06 07:47:24 +01:00
}
}
}
2024-01-12 16:47:09 +01:00
2024-04-27 04:36:51 +02:00
// Show page nb and apply correction for some font.
2023-12-04 12:05:28 +01:00
$pdf -> SetXY ( $dims [ 'wk' ] - $dims [ 'rm' ] - 18 - getDolGlobalInt ( 'PDF_FOOTER_PAGE_NUMBER_X' , 0 ), - $posy - getDolGlobalInt ( 'PDF_FOOTER_PAGE_NUMBER_Y' , 0 ));
2024-01-12 16:47:09 +01:00
2024-04-27 04:36:51 +02:00
$pagination = $pdf -> PageNo () . ' / ' . $pdf -> getAliasNbPages ();
$fontRenderCorrection = 0 ;
if ( in_array ( pdf_getPDFFont ( $outputlangs ), array ( 'freemono' , 'DejaVuSans' ))) {
$fontRenderCorrection = 10 ;
2024-01-12 16:47:09 +01:00
}
2025-02-05 00:52:48 +01:00
$pdf -> MultiCell ( 18 + $fontRenderCorrection , 2 , $pagination , 0 , 'R' , false );
2012-08-08 04:12:20 +02:00
2022-05-22 00:05:03 +02:00
// Show Draft Watermark
if ( ! empty ( $watermark )) {
pdf_watermark ( $pdf , $outputlangs , $page_hauteur , $page_largeur , 'mm' , $watermark );
}
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
*
2024-07-09 19:28:59 +02:00
* @ param TCPDF $pdf Object PDF
2024-09-23 00:37:30 +02:00
* @ param CommonObject $object Object
2012-03-18 19:23:01 +01:00
* @ param Translate $outputlangs Object lang
2024-11-07 17:31:40 +01:00
* @ param float $posx X
* @ param float $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 .
2024-07-09 19:28:59 +02:00
* @ param string $align Align
2024-09-17 02:38:56 +02:00
* @ param float $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 );
2024-08-15 16:57:02 +02:00
$pdf -> SetFont ( '' , '' , ( float ) $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
2024-09-23 00:37:30 +02:00
* @ param CommonObject $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object lang for output
2025-01-27 20:44:10 +01:00
* @ param float $w Width
* @ param float $h Height
2024-10-24 14:01:30 +02:00
* @ param float $posx Pos x
* @ param float $posy Pos y
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 1 > $hideref Hide reference
* @ param int < 0 , 1 > $hidedesc Hide description
* @ param int < 0 , 1 > $issupplierline Is it a line for a supplier object ?
* @ param 'L' | 'C' | 'R' | 'J' $align text alignment ( 'L' , 'C' , 'R' , 'J' ( default ))
2015-10-22 17:51:05 +02:00
* @ return string
2009-01-28 16:09:37 +01:00
*/
2024-02-08 01:30:18 +01:00
function pdf_writelinedesc ( & $pdf , $object , $i , $outputlangs , $w , $h , $posx , $posy , $hideref = 0 , $hidedesc = 0 , $issupplierline = 0 , $align = 'J' )
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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2020-11-28 12:12:31 +01:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +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 );
2019-11-13 19:35:02 +01:00
$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 );
2024-03-12 14:08:29 +01:00
$labelproductservice = preg_replace ( '/(<img[^>]*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)/' , '\1file:/' . DOL_DATA_ROOT . '/medias/\2\3' , $labelproductservice , - 1 , $nbrep );
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.
2021-11-07 12:24:25 +01:00
$nbrep = 0 ;
2019-01-31 18:12:34 +01:00
$labelproductservice = preg_replace ( '/(<img[^>]*src=")([^"]*)(&)([^"]*")/' , '\1\2&\4' , $labelproductservice , - 1 , $nbrep );
2024-05-22 17:30:27 +02:00
if ( getDolGlobalString ( 'MARGIN_TOP_ZERO_UL' )) {
$pdf -> setListIndentWidth ( 5 );
2024-08-15 16:57:02 +02:00
$TMarginList = [ 'ul' => [[ 'h' => 0.1 , ],[ 'h' => 0.1 , ]], 'li' => [[ 'h' => 0.1 , ],],];
2024-05-22 17:30:27 +02:00
$pdf -> setHtmlVSpace ( $TMarginList );
}
2019-01-31 18:12:34 +01:00
2011-09-17 03:05:44 +02:00
// Description
2024-02-08 01:30:18 +01:00
$pdf -> writeHTMLCell ( $w , $h , $posx , $posy , $outputlangs -> convToOutputCharset ( $labelproductservice ), 0 , 1 , false , true , $align , 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
*
2024-09-23 00:37:30 +02:00
* @ param CommonObject $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 : '' ));
2023-10-30 03:13:12 +01:00
$product_barcode = ( ! empty ( $object -> lines [ $i ] -> product_barcode ) ? $object -> lines [ $i ] -> product_barcode : " " );
2019-11-13 19:35:02 +01:00
$desc = ( ! empty ( $object -> lines [ $i ] -> desc ) ? $object -> lines [ $i ] -> desc : ( ! empty ( $object -> lines [ $i ] -> description ) ? $object -> lines [ $i ] -> description : '' ));
$ref_supplier = ( ! empty ( $object -> lines [ $i ] -> ref_supplier ) ? $object -> lines [ $i ] -> ref_supplier : ( ! empty ( $object -> lines [ $i ] -> ref_fourn ) ? $object -> lines [ $i ] -> ref_fourn : '' )); // TODO Not yet saved for supplier invoices, only supplier orders
$note = ( ! empty ( $object -> lines [ $i ] -> note ) ? $object -> lines [ $i ] -> note : '' );
$dbatch = ( ! empty ( $object -> lines [ $i ] -> detail_batch ) ? $object -> lines [ $i ] -> detail_batch : false );
2011-09-17 03:05:44 +02:00
2023-12-18 13:44:19 +01:00
$multilangsactive = getDolGlobalInt ( 'MAIN_MULTILANGS' );
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
2024-09-25 23:18:16 +02:00
if ( getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES' ) || getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES' )) {
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
2023-12-18 13:44:19 +01:00
//id
2019-11-13 19:35:02 +01:00
$idprod = ( ! empty ( $object -> lines [ $i ] -> fk_product ) ? $object -> lines [ $i ] -> fk_product : false );
2021-02-23 22:03:23 +01:00
if ( $idprod ) {
2011-09-17 03:05:44 +02:00
$prodser -> fetch ( $idprod );
2025-01-16 00:36:56 +01:00
//load multilangs
if ( $multilangsactive ) {
$prodser -> getMultiLangs ();
$object -> lines [ $i ] -> multilangs = $prodser -> multilangs ;
}
}
2023-12-18 13:44:19 +01:00
//label
if ( ! empty ( $object -> lines [ $i ] -> label )) {
$label = $object -> lines [ $i ] -> label ;
} else {
2024-01-22 14:52:51 +01:00
if ( ! empty ( $object -> lines [ $i ] -> multilangs [ $outputlangs -> defaultlang ][ 'label' ]) && $multilangsactive ) {
$label = $object -> lines [ $i ] -> multilangs [ $outputlangs -> defaultlang ][ 'label' ];
2023-12-22 09:30:35 +01:00
} else {
if ( ! empty ( $object -> lines [ $i ] -> product_label )) {
$label = $object -> lines [ $i ] -> product_label ;
} else {
$label = '' ;
}
}
2023-12-18 13:44:19 +01:00
}
//description
if ( ! empty ( $object -> lines [ $i ] -> desc )) {
$desc = $object -> lines [ $i ] -> desc ;
} else {
2024-01-22 14:52:51 +01:00
if ( ! empty ( $object -> lines [ $i ] -> multilangs [ $outputlangs -> defaultlang ][ 'description' ]) && $multilangsactive ) {
$desc = $object -> lines [ $i ] -> multilangs [ $outputlangs -> defaultlang ][ 'description' ];
2023-12-22 09:30:35 +01:00
} else {
if ( ! empty ( $object -> lines [ $i ] -> description )) {
$desc = $object -> lines [ $i ] -> description ;
} else {
$desc = '' ;
}
2020-10-26 13:05:07 +01:00
}
2018-09-02 16:09:40 +02:00
}
2023-12-18 13:44:19 +01:00
//ref supplier
2019-11-13 19:35:02 +01:00
$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
2023-12-18 12:00:41 +01:00
//note
2023-12-18 13:44:19 +01:00
$note = ( ! empty ( $object -> lines [ $i ] -> note ) ? $object -> lines [ $i ] -> note : '' );
2023-12-18 12:00:41 +01:00
//dbatch
2023-12-18 13:44:19 +01:00
$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 ( $idprod ) {
2011-09-17 03:05:44 +02:00
// If a predefined product and multilang and on other lang, we renamed label with label translated
2023-12-18 12:00:41 +01:00
if ( $multilangsactive && ( $outputlangs -> defaultlang != $langs -> defaultlang )) {
2025-01-20 12:28:49 +01:00
$translatealsoifmodified = getDolGlobalString ( '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
}
2023-11-18 14:15:34 +01:00
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ])) {
if ( $textwasnotmodified ) {
$desc = str_replace ( $prodser -> description , $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ], $desc );
} elseif ( $translatealsoifmodified ) {
$desc = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ];
}
2021-02-23 22:03:23 +01:00
}
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
}
2022-02-22 17:42:11 +01:00
} elseif (( $object -> element == 'facture' || $object -> element == 'facturefourn' ) && preg_match ( '/^\(DEPOSIT\).+/' , $desc )) { // We must not replace '(DEPOSIT)' when it is alone, it will be translated and detailed later
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
2024-08-17 19:32:52 +02:00
$libelleproduitservice = '' ; // Default value
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'PDF_HIDE_PRODUCT_LABEL_IN_SUPPLIER_LINES' )) {
2021-08-12 13:56:41 +02:00
// Description short of product line
$libelleproduitservice = $label ;
2023-11-27 11:39:32 +01:00
if ( ! empty ( $libelleproduitservice ) && getDolGlobalString ( 'PDF_BOLD_PRODUCT_LABEL' )) {
2024-01-13 19:48:20 +01:00
// Adding <b> may convert the original string into a HTML string. So we have to first
2021-11-30 14:09:46 +01:00
// convert \n into <br> we text is not already HTML.
2021-11-30 12:17:48 +01:00
if ( ! dol_textishtml ( $libelleproduitservice )) {
2021-11-30 12:13:21 +01:00
$libelleproduitservice = str_replace ( " \n " , '<br>' , $libelleproduitservice );
2021-11-28 14:40:15 +01:00
}
2021-08-12 13:56:41 +02:00
$libelleproduitservice = '<b>' . $libelleproduitservice . '</b>' ;
}
2020-10-20 14:34:17 +02:00
}
2011-09-17 03:05:44 +02:00
2021-08-12 13:56:41 +02:00
2020-12-08 21:56:12 +01:00
// Add ref of subproducts
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'SHOW_SUBPRODUCT_REF_IN_PDF' )) {
2020-12-08 21:56:12 +01:00
$prodser -> get_sousproduits_arbo ();
if ( ! empty ( $prodser -> sousprods ) && is_array ( $prodser -> sousprods ) && count ( $prodser -> sousprods )) {
2023-11-03 16:27:02 +01:00
$outputlangs -> load ( 'mrp' );
2020-12-08 21:56:12 +01:00
$tmparrayofsubproducts = reset ( $prodser -> sousprods );
2023-11-03 16:27:02 +01:00
$qtyText = null ;
if ( isset ( $object -> lines [ $i ] -> qty ) && ! empty ( $object -> lines [ $i ] -> qty )) {
$qtyText = $object -> lines [ $i ] -> qty ;
} elseif ( isset ( $object -> lines [ $i ] -> qty_shipped ) && ! empty ( $object -> lines [ $i ] -> qty_shipped )) {
$qtyText = $object -> lines [ $i ] -> qty ;
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_GENERATE_DOCUMENTS_HIDE_REF' )) {
2022-02-04 19:05:22 +01:00
foreach ( $tmparrayofsubproducts as $subprodval ) {
2023-12-04 12:05:28 +01:00
$libelleproduitservice = dol_concatdesc (
dol_concatdesc ( $libelleproduitservice , " * " . $subprodval [ 3 ]),
2023-11-03 16:27:02 +01:00
( ! empty ( $qtyText ) ?
2024-03-15 04:22:49 +01:00
$outputlangs -> trans ( 'Qty' ) . ':' . $qtyText . ' x ' . $outputlangs -> trans ( 'AssociatedProducts' ) . ':' . $subprodval [ 1 ] . '= ' . $outputlangs -> trans ( 'QtyTot' ) . ':' . $subprodval [ 1 ] * $qtyText :
2023-12-04 12:05:28 +01:00
$outputlangs -> trans ( 'Qty' ) . ' ' . $outputlangs -> trans ( 'AssociatedProducts' ) . ':' . $subprodval [ 1 ])
);
2022-02-04 19:05:22 +01:00
}
} else {
foreach ( $tmparrayofsubproducts as $subprodval ) {
2023-12-04 12:05:28 +01:00
$libelleproduitservice = dol_concatdesc (
dol_concatdesc ( $libelleproduitservice , " * " . $subprodval [ 5 ] . (( $subprodval [ 5 ] && $subprodval [ 3 ]) ? ' - ' : '' ) . $subprodval [ 3 ]),
2023-11-03 16:27:02 +01:00
( ! empty ( $qtyText ) ?
2024-03-15 04:22:49 +01:00
$outputlangs -> trans ( 'Qty' ) . ':' . $qtyText . ' x ' . $outputlangs -> trans ( 'AssociatedProducts' ) . ':' . $subprodval [ 1 ] . '= ' . $outputlangs -> trans ( 'QtyTot' ) . ':' . $subprodval [ 1 ] * $qtyText :
2023-12-04 12:05:28 +01:00
$outputlangs -> trans ( 'Qty' ) . ' ' . $outputlangs -> trans ( 'AssociatedProducts' ) . ':' . $subprodval [ 1 ])
);
2022-02-04 19:05:22 +01:00
}
2020-12-08 21:56:12 +01:00
}
}
2020-10-20 14:34:17 +02:00
}
2011-09-17 03:05:44 +02:00
2023-10-30 03:13:12 +01:00
if ( isModEnabled ( 'barcode' ) && getDolGlobalString ( 'MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE' ) && ! empty ( $product_barcode )) {
$libelleproduitservice = dol_concatdesc ( $libelleproduitservice , $outputlangs -> trans ( " BarCode " ) . " " . $product_barcode );
}
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 ( $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 );
2022-06-14 20:57:58 +02:00
$sourceref = ! empty ( $discount -> discount_type ) ? $discount -> ref_invoice_supplier_source : $discount -> ref_facture_source ;
2019-11-13 19:35:02 +01:00
$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 );
2022-06-14 20:57:58 +02:00
$sourceref = ! empty ( $discount -> discount_type ) ? $discount -> ref_invoice_supplier_source : $discount -> ref_facture_source ;
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromDeposit " , $sourceref );
2013-04-04 13:58:33 +02:00
// Add date of deposit
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'INVOICE_ADD_DEPOSIT_DATE' )) {
2021-02-23 22:03:23 +01:00
$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 );
2024-07-03 20:05:29 +02:00
if ( getDolGlobalString ( $tmpkey )) {
2020-12-08 21:56:12 +01:00
$hidedesc = 1 ;
}
}
if ( empty ( $hidedesc )) {
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_DOCUMENTS_DESCRIPTION_FIRST' )) {
2021-11-30 14:09:46 +01:00
$libelleproduitservice = dol_concatdesc ( $desc , $libelleproduitservice );
2020-05-21 15:05:19 +02:00
} else {
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'HIDE_LABEL_VARIANT_PDF' ) && $prodser -> isVariant ()) {
2020-10-02 09:21:44 +02:00
$libelleproduitservice = $desc ;
} else {
2021-12-09 17:25:06 +01:00
$libelleproduitservice = dol_concatdesc ( $libelleproduitservice , $desc );
2020-10-02 09:21:44 +02:00
}
2018-06-07 17:24:45 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2021-12-09 17:25:06 +01:00
$libelleproduitservice = dol_concatdesc ( $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 = " " ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PRODUCT_ADD_TYPE_IN_DOCUMENTS' )) { // In standard mode, we do not show this
2020-11-26 10:12:24 +01:00
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 ) {
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( '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 ? ')' : '' );
}
2023-10-08 23:19:49 +02:00
} elseif ( getDolGlobalInt ( 'PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES' ) == 1 ) {
2020-11-26 10:12:24 +01:00
$ref_prodserv = $ref_supplier ;
2023-10-08 23:19:49 +02:00
} elseif ( getDolGlobalInt ( 'PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES' ) == 2 ) {
2020-11-26 10:12:24 +01:00
$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
2024-09-25 23:18:16 +02:00
if ( getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES' ) || getDolGlobalString ( 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES' )) {
2023-08-24 15:08:33 +02:00
$productCustomerPriceStatic = new ProductCustomerPrice ( $db );
2021-02-23 22:03:23 +01:00
$filter = array ( 'fk_product' => $idprod , 'fk_soc' => $object -> socid );
2020-10-26 13:05:07 +01:00
2022-09-10 14:03:47 +02:00
$nbCustomerPrices = $productCustomerPriceStatic -> fetchAll ( '' , '' , 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
2022-08-31 22:14:20 +02:00
if ( ! empty ( $productCustomerPrice -> ref_customer )) {
2021-02-23 22:03:23 +01:00
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
2023-11-27 11:39:32 +01:00
if ( ! empty ( $ref_prodserv ) && getDolGlobalString ( 'PDF_BOLD_PRODUCT_REF_AND_PERIOD' )) {
2021-11-30 12:17:48 +01:00
if ( ! dol_textishtml ( $libelleproduitservice )) {
2021-11-30 12:13:21 +01:00
$libelleproduitservice = str_replace ( " \n " , '<br>' , $libelleproduitservice );
2021-11-28 14:40:15 +01:00
}
2021-02-23 22:03:23 +01:00
$ref_prodserv = '<b>' . $ref_prodserv . '</b>' ;
2021-11-28 14:40:15 +01:00
// $prefix_prodserv and $ref_prodser are not HTML var
2021-11-28 14:42:25 +01:00
}
2019-11-13 19:35:02 +01:00
$libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice ;
2021-11-28 14:42:25 +01:00
2013-09-03 11:15:19 +02:00
// Add an additional description for the category products
2024-02-27 15:30:37 +01:00
if ( getDolGlobalString ( 'CATEGORY_ADD_DESC_INTO_DOC' ) && $idprod && isModEnabled ( 'category' )) {
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 ) {
2021-12-10 03:25:07 +01:00
$libelleproduitservice = dol_concatdesc ( $libelleproduitservice , $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;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PDF_BOLD_PRODUCT_REF_AND_PERIOD' )) {
2021-11-30 12:17:48 +01:00
if ( ! dol_textishtml ( $libelleproduitservice )) {
2021-11-30 12:13:21 +01:00
$libelleproduitservice = str_replace ( " \n " , '<br>' , $libelleproduitservice );
2021-11-28 14:40:15 +01:00
}
2021-11-30 12:13:21 +01:00
$libelleproduitservice .= '<br><b style="color:#333666;" ><em>' . $period . '</em></b>' ;
2019-10-27 11:53:20 +01:00
} else {
2021-12-10 03:25:07 +01:00
$libelleproduitservice = dol_concatdesc ( $libelleproduitservice , $period );
2018-12-08 17:56:03 +01:00
}
2011-09-17 03:05:44 +02:00
//print $libelleproduitservice;
}
2022-09-21 00:46:02 +02:00
// Show information for lot
2022-12-28 16:40:03 +01:00
if ( ! empty ( $dbatch )) {
2022-09-21 00:46:02 +02:00
// $object is a shipment.
2023-03-31 19:47:52 +02:00
//var_dump($object->lines[$i]->details_entrepot); // array from llx_expeditiondet (we can have several lines for one fk_origin_line)
2022-09-21 00:46:02 +02:00
//var_dump($object->lines[$i]->detail_batch); // array from llx_expeditiondet_batch (each line with a lot is linked to llx_expeditiondet)
include_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php' ;
$tmpwarehouse = new Entrepot ( $db );
$tmpproductbatch = new Productbatch ( $db );
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 );
2022-09-21 00:46:02 +02:00
// Add also info of planned warehouse for lot
if ( $object -> element == 'shipping' && $detail -> fk_origin_stock > 0 && getDolGlobalInt ( 'PRODUCTBATCH_SHOW_WAREHOUSE_ON_SHIPMENT' )) {
$resproductbatch = $tmpproductbatch -> fetch ( $detail -> fk_origin_stock );
if ( $resproductbatch > 0 ) {
$reswarehouse = $tmpwarehouse -> fetch ( $tmpproductbatch -> warehouseid );
if ( $reswarehouse > 0 ) {
$dte [] = $tmpwarehouse -> ref ;
}
}
}
2019-11-13 19:35:02 +01:00
$libelleproduitservice .= " __N__ " . implode ( " - " , $dte );
2014-03-07 11:35:16 +01:00
}
2022-09-21 00:46:02 +02:00
} else {
if ( getDolGlobalInt ( 'PRODUCTBATCH_SHOW_WAREHOUSE_ON_SHIPMENT' )) {
// TODO Show warehouse for shipment line without batch
}
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
*
2024-09-23 00:37:30 +02:00
* @ param CommonObject $object Object
2011-12-06 00:39:24 +01:00
* @ 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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param CommonObject $object Object
2011-12-06 00:39:24 +01:00
* @ 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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
}
2024-09-23 00:37:30 +02:00
2011-05-20 17:38:26 +02:00
/**
* Return line ref_supplier
2011-09-12 19:08:02 +02:00
*
2024-09-23 00:37:30 +02:00
* @ param Contrat | CommandeFournisseur | FactureFournisseur | Facture | Product | Reception | SupplierProposal $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param SupplierProposal | CommandeFournisseur | FactureFournisseur | Propal | Facture | Commande | ExpenseReport | StockTransfer $object Object
2024-09-23 01:59:14 +02:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int < 0 , 2 > $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 ;
2022-08-31 22:14:20 +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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
2025-01-05 18:44:12 +01:00
$tmpresult .= vatrate ( $object -> lines [ $i ] -> tva_tx , false , $object -> lines [ $i ] -> info_bits , - 1 );
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_PDF_MAIN_HIDE_SECOND_TAX' )) {
2021-02-23 22:03:23 +01:00
if ( $object -> lines [ $i ] -> total_localtax1 != 0 ) {
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) {
$tmpresult .= '/' ;
} else {
$tmpresult = '' ;
}
2025-01-05 18:44:12 +01:00
$tmpresult .= vatrate (( string ) abs ( $object -> lines [ $i ] -> localtax1_tx ), false );
2017-08-29 17:22:03 +02:00
}
}
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_PDF_MAIN_HIDE_THIRD_TAX' )) {
2021-02-23 22:03:23 +01:00
if ( $object -> lines [ $i ] -> total_localtax2 != 0 ) {
if ( preg_replace ( '/[\s0%]/' , '' , $tmpresult )) {
$tmpresult .= '/' ;
} else {
$tmpresult = '' ;
}
2025-01-05 18:44:12 +01:00
$tmpresult .= vatrate (( string ) abs ( $object -> lines [ $i ] -> localtax2_tx ), false );
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
*
2024-09-23 00:37:30 +02:00
* @ param SupplierProposal | CommandeFournisseur | Propal | Facture | FactureFournisseur | Commande | StockTransfer $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 ;
2023-11-27 11:39:32 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && getDolGlobalString ( 'INVOICE_POSITIVE_CREDIT_NOTE' )) {
2021-02-23 22:03:23 +01:00
$sign = - 1 ;
}
2011-11-11 00:36:01 +01:00
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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 ) {
2022-09-03 11:16:00 +02:00
$subprice = ( isModEnabled ( " multicurrency " ) && $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
*
2024-09-23 00:37:30 +02:00
* @ param SupplierProposal | CommandeFournisseur | Propal | Facture | Commande $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
2014-12-20 15:42:03 +01:00
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 ;
2023-11-27 11:39:32 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && getDolGlobalString ( 'INVOICE_POSITIVE_CREDIT_NOTE' )) {
2021-02-23 22:03:23 +01:00
$sign = - 1 ;
}
2013-01-26 10:35:30 +01:00
2019-11-13 19:35:02 +01:00
$result = '' ;
$reshook = 0 ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param Delivery | Asset | Commande | Facture | CommandeFournisseur | FactureFournisseur | SupplierProposal | Propal | StockTransfer | MyObject $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param Delivery $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param Delivery $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-11-04 12:32:13 +01:00
* @ param Delivery | Asset | Commande | Facture | CommandeFournisseur | FactureFournisseur | SupplierProposal | Propal | StockTransfer | MyObject $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2024-11-04 12:32:13 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) { // @phan-suppress-current-line PhanUndeclaredProperty
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param SupplierProposal | CommandeFournisseur | Propal | Facture | FactureFournisseur | Commande | StockTransfer $object Object
2015-02-26 14:15:33 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2016-05-19 17:36:25 +02:00
* @ return string Value for unit cell
2015-02-26 14:15:33 +01:00
*/
2024-01-13 15:32:07 +01:00
function pdf_getlineunit ( $object , $i , $outputlangs , $hidedetails = 0 )
2015-02-26 14:15:33 +01:00
{
2024-01-13 15:32:07 +01:00
global $hookmanager , $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2015-10-22 17:51:05 +02:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param SupplierProposal | CommandeFournisseur | Propal | Facture | FactureFournisseur | Commande | StockTransfer $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param Facture $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int < 0 , 2 > $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 = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$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 ) {
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'SITUATION_DISPLAY_DIFF_ON_PDF' )) {
2017-11-12 20:12:56 +01:00
$prev_progress = 0 ;
2021-12-19 00:17:37 +01:00
if ( method_exists ( $object -> lines [ $i ], 'get_prev_progress' )) {
2021-02-23 22:03:23 +01:00
$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
*
2024-09-23 00:37:30 +02:00
* @ param Commande | Facture | Propal | FactureFournisseur | CommandeFournisseur | SupplierProposal $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 ;
2023-11-27 11:39:32 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && getDolGlobalString ( 'INVOICE_POSITIVE_CREDIT_NOTE' )) {
2021-02-23 22:03:23 +01:00
$sign = - 1 ;
}
2011-11-11 00:36:01 +01:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$result = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code , 'sign' => $sign );
2019-11-13 19:35:02 +01:00
$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 )) {
2023-11-23 17:08:07 +01:00
if ( ! empty ( $object -> lines [ $i ]) && $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 ) {
2022-09-03 11:16:00 +02:00
$total_ht = ( isModEnabled ( " multicurrency " ) && $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
*
2024-09-23 00:37:30 +02:00
* @ param Commande | Facture | Propal | FactureFournisseur | CommandeFournisseur | SupplierProposal $object Object
2011-12-06 00:39:24 +01:00
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
2024-09-23 00:37:30 +02:00
* @ param int < 0 , 2 > $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 ;
2023-11-27 11:39:32 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && getDolGlobalString ( 'INVOICE_POSITIVE_CREDIT_NOTE' )) {
2021-02-23 22:03:23 +01:00
$sign = - 1 ;
}
2013-01-26 10:35:30 +01:00
2019-11-13 19:35:02 +01:00
$reshook = 0 ;
$result = '' ;
2022-08-31 22:14:20 +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) ) )
2024-09-23 00:37:30 +02: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
2023-10-11 02:54:19 +02:00
$special_code = empty ( $object -> lines [ $i ] -> special_code ) ? '' : $object -> lines [ $i ] -> special_code ;
2023-11-23 17:12:57 +01:00
if ( ! empty ( $object -> lines [ $i ] -> fk_parent_line ) && $object -> lines [ $i ] -> fk_parent_line > 0 ) {
2021-02-23 22:03:23 +01:00
$special_code = $object -> getSpecialCode ( $object -> lines [ $i ] -> fk_parent_line );
}
2024-03-15 04:22:49 +01:00
$parameters = array ( 'i' => $i , 'outputlangs' => $outputlangs , 'hidedetails' => $hidedetails , 'special_code' => $special_code );
2019-11-13 19:35:02 +01:00
$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 ) {
2022-09-03 11:16:00 +02:00
$total_ttc = ( isModEnabled ( " multicurrency " ) && $object -> multicurrency_tx != 1 ? $object -> lines [ $i ] -> multicurrency_total_ttc : $object -> lines [ $i ] -> total_ttc );
2024-06-15 15:06:58 +02:00
if ( isset ( $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' )) {
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
}
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
*
2023-11-23 17:07:32 +01:00
* @ param CommonObject $object Object
* @ param Translate $outputlangs Object lang for output
2024-09-23 00:37:30 +02:00
* @ return array < string , array < string , null | int | float | string >> Linked objects
2012-03-02 08:11:40 +01:00
*/
2021-06-10 14:24:01 +02: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' ) {
2024-01-13 19:48:20 +01:00
// For invoice, we don't want to have a reference line on document. Image we are using recurring invoice, we will have a line longer than document width.
2021-02-23 22:03:23 +01:00
} elseif ( $objecttype == 'propal' || $objecttype == 'supplier_proposal' ) {
2024-09-23 00:37:30 +02:00
'@phan-var-force array<Propal|SupplierProposal> $objects' ;
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' ) {
2024-09-23 00:37:30 +02:00
'@phan-var-force array<Commande|CommandeFournisseur> $objects' ;
2012-03-02 08:11:40 +01:00
$outputlangs -> load ( 'orders' );
2021-06-07 16:01:58 +02:00
2021-11-11 15:31:19 +01:00
if ( count ( $objects ) > 1 && count ( $objects ) <= ( getDolGlobalInt ( " MAXREFONDOC " ) ? getDolGlobalInt ( " MAXREFONDOC " ) : 10 )) {
2024-10-24 02:54:31 +02:00
if ( empty ( $object -> context [ 'DolPublicNoteAppendedGetLinkedObjects' ])) { // Check if already appended before add to avoid repeat data
$object -> note_public = dol_concatdesc ( $object -> note_public , $outputlangs -> transnoentities ( " RefOrder " ) . ' :' );
foreach ( $objects as $elementobject ) {
$object -> note_public = dol_concatdesc ( $object -> note_public , $outputlangs -> transnoentities ( $elementobject -> ref ) . ( empty ( $elementobject -> ref_client ) ? '' : ' (' . $elementobject -> ref_client . ')' ) . ( empty ( $elementobject -> ref_supplier ) ? '' : ' (' . $elementobject -> ref_supplier . ')' ) . ' ' );
$object -> note_public = dol_concatdesc ( $object -> note_public , $outputlangs -> transnoentities ( " OrderDate " ) . ' : ' . dol_print_date ( $elementobject -> date , 'day' , '' , $outputlangs ));
}
2021-06-10 14:28:26 +02:00
}
} elseif ( count ( $objects ) == 1 ) {
$elementobject = array_shift ( $objects );
2012-03-02 08:11:40 +01:00
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " );
2022-06-07 18:49:29 +02:00
$linkedobjects [ $objecttype ][ 'ref_value' ] = $outputlangs -> transnoentities ( $elementobject -> ref ) . ( ! empty ( $elementobject -> ref_client ) ? ' (' . $elementobject -> ref_client . ')' : '' ) . ( ! empty ( $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' ) {
2024-09-23 00:37:30 +02:00
'@phan-var-force Contrat[] $objects' ;
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' ) {
2024-09-23 00:37:30 +02:00
'@phan-var-force Fichinter[] $objects' ;
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' ) {
2024-09-23 00:37:30 +02:00
'@phan-var-force Expedition[] $objects' ;
2018-09-18 11:02:18 +02:00
$outputlangs -> loadLangs ( array ( " orders " , " sendings " ));
2021-06-10 14:28:26 +02:00
if ( count ( $objects ) > 1 ) {
$order = null ;
2024-10-19 00:57:57 +02:00
$refListsTxt = '' ;
2021-11-11 15:31:19 +01:00
if ( empty ( $object -> linkedObjects [ 'commande' ]) && $object -> element != 'commande' ) {
2024-10-24 14:01:30 +02:00
$refListsTxt .= $outputlangs -> transnoentities ( " RefOrder " ) . ' / ' . $outputlangs -> transnoentities ( " RefSending " ) . ' :' ;
2021-11-11 15:31:19 +01:00
} else {
2024-10-24 14:01:30 +02:00
$refListsTxt .= $outputlangs -> transnoentities ( " RefSending " ) . ' :' ;
2021-11-11 15:31:19 +01:00
}
2021-06-10 14:28:26 +02:00
// We concat this record info into fields xxx_value. title is overwrote.
foreach ( $objects as $elementobject ) {
if ( empty ( $object -> linkedObjects [ 'commande' ]) && $object -> element != 'commande' ) { // There is not already a link to order and object is not the order, so we show also info with order
$elementobject -> fetchObjectLinked ( null , '' , null , '' , 'OR' , 1 , 'sourcetype' , 0 );
2022-08-31 22:14:20 +02:00
if ( ! empty ( $elementobject -> linkedObjectsIds [ 'commande' ])) {
2021-06-10 14:28:26 +02:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
$order = new Commande ( $db );
$ret = $order -> fetch ( reset ( $elementobject -> linkedObjectsIds [ 'commande' ]));
if ( $ret < 1 ) {
$order = null ;
}
}
}
2024-10-24 14:01:30 +02:00
$refListsTxt .= ( ! empty ( $refListsTxt ) ? ' ' : '' );
2021-06-10 14:28:26 +02:00
if ( ! is_object ( $order )) {
2024-10-24 14:01:30 +02:00
$refListsTxt .= $outputlangs -> transnoentities ( $elementobject -> ref );
2021-06-10 14:28:26 +02:00
} else {
2024-10-24 14:01:30 +02:00
$refListsTxt .= $outputlangs -> convToOutputCharset ( $order -> ref ) . ( $order -> ref_client ? ' (' . $order -> ref_client . ')' : '' );
$refListsTxt .= ' / ' . $outputlangs -> transnoentities ( $elementobject -> ref );
2021-06-10 14:28:26 +02:00
}
}
2024-10-19 00:57:57 +02:00
2024-10-24 02:54:31 +02:00
if ( empty ( $object -> context [ 'DolPublicNoteAppendedGetLinkedObjects' ])) { // Check if already appended before add to avoid repeat data
$object -> note_public = dol_concatdesc ( $object -> note_public , $refListsTxt );
}
2021-06-10 14:28:26 +02:00
} elseif ( count ( $objects ) == 1 ) {
$elementobject = array_shift ( $objects );
2020-10-31 14:32:18 +01:00
$order = null ;
// We concat this record info into fields xxx_value. title is overwrote.
2021-06-10 14:28:26 +02: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 );
2022-08-31 22:14:20 +02:00
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-06-10 14:28:26 +02:00
if ( ! is_object ( $order )) {
2020-10-31 14:32:18 +01:00
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefSending " );
2023-10-10 21:48:07 +02:00
if ( empty ( $linkedobjects [ $objecttype ][ 'ref_value' ])) {
$linkedobjects [ $objecttype ][ 'ref_value' ] = '' ;
} else {
$linkedobjects [ $objecttype ][ 'ref_value' ] .= ' / ' ;
}
2020-10-31 14:32:18 +01:00
$linkedobjects [ $objecttype ][ 'ref_value' ] .= $outputlangs -> transnoentities ( $elementobject -> ref );
2023-02-21 18:32:36 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( empty ( $elementobject -> date_shipping ) ? $elementobject -> date_delivery : $elementobject -> date_shipping , 'day' , '' , $outputlangs );
2020-10-31 14:32:18 +01:00
} else {
$linkedobjects [ $objecttype ][ 'ref_title' ] = $outputlangs -> transnoentities ( " RefOrder " ) . ' / ' . $outputlangs -> transnoentities ( " RefSending " );
2023-10-10 21:48:07 +02: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 );
2023-02-21 18:32:36 +01:00
$linkedobjects [ $objecttype ][ 'date_value' ] = dol_print_date ( empty ( $elementobject -> date_shipping ) ? $elementobject -> date_delivery : $elementobject -> date_shipping , 'day' , '' , $outputlangs );
2020-10-31 14:32:18 +01:00
}
2014-09-14 12:06:38 +02:00
}
}
2012-03-02 08:11:40 +01:00
}
2012-03-18 19:23:01 +01:00
2024-10-24 02:54:31 +02:00
$object -> context [ 'DolPublicNoteAppendedGetLinkedObjects' ] = 1 ;
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 )) {
2024-03-15 04:22:49 +01:00
$parameters = array ( 'linkedobjects' => $linkedobjects , 'outputlangs' => $outputlangs );
2019-11-13 19:35:02 +01:00
$action = '' ;
2024-12-09 14:41:57 +01:00
$reshook = $hookmanager -> executeHooks ( 'pdf_getLinkedObjects' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2024-12-09 16:24:57 +01:00
if ( empty ( $reshook )) {
$linkedobjects = array_replace ( $linkedobjects , $hookmanager -> resArray ); // array_replace is used to preserve keys
2025-01-13 20:04:35 +01:00
} elseif ( $reshook > 0 ) {
2024-12-09 14:41:57 +01:00
// The array must be reinserted even if it is empty because clearing the array could be one of the actions performed by the hook.
2021-02-23 22:03:23 +01:00
$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
2024-09-23 00:37:30 +02:00
* maximum ( 20 x32 by default ) .
2013-07-13 21:14:05 +02:00
*
* @ param string $realpath Full path to photo file to use
2024-09-23 00:37:30 +02:00
* @ return array { width : int , height : int } 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
{
2024-04-20 23:36:54 +02:00
$maxwidth = getDolGlobalInt ( 'MAIN_DOCUMENTS_WITH_PICTURE_WIDTH' , 20 );
$maxheight = getDolGlobalInt ( 'MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT' , 32 );
2024-11-17 01:27:33 +01:00
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 );
2023-02-26 11:12:06 +01:00
$width = 0 ;
2023-02-26 11:17:38 +01:00
$height = 0 ;
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' ]);
2023-12-04 12:05:28 +01:00
} else { // No pb with maxheight
2019-11-13 19:35:02 +01:00
$height = $maxheight ;
2013-07-13 21:14:05 +02:00
}
}
2024-03-15 04:22:49 +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
*
2024-10-26 18:29:06 +02:00
* @ param Commande | Facture | Propal $object Object
* @ param int $i Current line number
* @ param Translate $outputlangs Object langs for output
* @ param int < 0 , 2 > $hidedetails Hide details ( 0 = no , 1 = yes , 2 = just special lines )
2024-11-17 01:27:33 +01:00
* @ return int | float | string Return total of line excl tax
2019-06-24 12:00:55 +02:00
*/
2019-06-24 14:36:06 +02:00
function pdfGetLineTotalDiscountAmount ( $object , $i , $outputlangs , $hidedetails = 0 )
2019-06-24 12:00:55 +02:00
{
2024-11-17 01:27:33 +01:00
global $hookmanager ;
2023-05-21 11:10:37 +02:00
2019-11-13 19:35:02 +01:00
$sign = 1 ;
2023-11-27 11:39:32 +01:00
if ( isset ( $object -> type ) && $object -> type == 2 && getDolGlobalString ( 'INVOICE_POSITIVE_CREDIT_NOTE' )) {
2021-02-23 22:03:23 +01:00
$sign = - 1 ;
}
if ( $object -> lines [ $i ] -> special_code == 3 ) {
2024-11-17 01:27:33 +01:00
// If option
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 (
2024-03-15 04:22:49 +01:00
'i' => $i ,
'outputlangs' => $outputlangs ,
'hidedetails' => $hidedetails ,
'special_code' => $special_code
2019-06-24 12:00:55 +02:00
);
2019-11-13 19:35:02 +01:00
$action = '' ;
2019-06-24 12:00:55 +02:00
2023-05-21 11:10:37 +02:00
if ( $hookmanager -> executeHooks ( 'getlinetotalremise' , $parameters , $object , $action ) > 0 ) { // Note that $action and $object may have been modified by some hooks
if ( isset ( $hookmanager -> resArray [ 'linetotalremise' ])) {
2024-11-17 01:27:33 +01:00
return ( float ) $hookmanager -> resArray [ 'linetotalremise' ];
2023-05-21 11:10:37 +02:00
} else {
return ( float ) $hookmanager -> resPrint ; // For backward compatibility
}
2019-06-24 12:00:55 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( empty ( $hidedetails ) || $hidedetails > 1 ) {
2024-11-17 01:27:33 +01:00
return ( float ) price2num ( $sign * (( $object -> lines [ $i ] -> subprice * ( float ) $object -> lines [ $i ] -> qty ) - $object -> lines [ $i ] -> total_ht ), 'MT' , 1 );
2021-02-23 22:03:23 +01:00
}
2019-06-24 12:00:55 +02:00
}
2023-05-21 11:10:37 +02:00
return 0 ;
2019-06-24 14:36:06 +02:00
}