2009-01-28 16:09:37 +01:00
< ? php
2010-06-23 21:17:38 +02:00
/* Copyright ( C ) 2006 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-01-28 16:09:37 +01:00
* Copyright ( C ) 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
*
* 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 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
* or see http :// www . gnu . org /
*/
/**
2009-06-15 20:57:34 +02:00
* \file htdocs / lib / pdf . lib . php
* \brief Set of functions used for PDF generation
* \ingroup core
2009-01-28 16:09:37 +01:00
* \version $Id $
*/
2009-06-15 20:57:34 +02:00
2010-03-30 20:03:01 +02:00
/**
* \brief Mutualize code to build address for PDF generation
* \param outputlangs Output langs object
* \param sourcecompany Source company object
2010-04-06 20:40:08 +02:00
* \param targetcompany Target company object
* \param targetcontact Target contact object
* \param usecontact Use contact instead of company
2010-03-30 20:03:01 +02:00
* \return string Source of file
*/
2010-04-06 20:40:08 +02:00
function pdf_build_address ( $outputlangs , $sourcecompany , $targetcompany = '' , $targetcontact = '' , $usecontact = 0 , $mode = 'source' )
2010-03-30 20:03:01 +02:00
{
2010-04-06 20:40:08 +02:00
global $conf ;
2010-03-30 20:21:58 +02:00
$stringaddress = '' ;
2010-03-30 21:08:07 +02:00
2010-04-06 20:40:08 +02:00
if ( $mode == 'source' && ! is_object ( $sourcecompany )) return - 1 ;
if ( $mode == 'target' && ! is_object ( $targetcompany )) return - 1 ;
if ( $mode == 'source' )
2010-03-30 20:21:58 +02:00
{
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $sourcecompany -> address );
$stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> convToOutputCharset ( $sourcecompany -> cp ) . ' ' . $outputlangs -> convToOutputCharset ( $sourcecompany -> ville );
2010-06-19 00:54:16 +02:00
if (( $sourcecompany -> departement_id || $sourcecompany -> departement ) && in_array ( $sourcecompany -> pays_code , array ( 'US' , 'IN' )))
{
if ( $sourcecompany -> departement_id && empty ( $sourcecompany -> departement )) $sourcecompany -> departement = getState ( $sourcecompany -> departement_id );
$stringaddress .= " - " . $outputlangs -> convToOutputCharset ( $sourcecompany -> departement );
}
2010-03-30 20:21:58 +02:00
$stringaddress .= " \n " ;
// Tel
if ( $sourcecompany -> tel ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Phone " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> tel );
// Fax
if ( $sourcecompany -> fax ) $stringaddress .= ( $stringaddress ? ( $sourcecompany -> tel ? " - " : " \n " ) : '' ) . $outputlangs -> transnoentities ( " Fax " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> fax );
// EMail
if ( $sourcecompany -> email ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Email " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> email );
// Web
if ( $sourcecompany -> url ) $stringaddress .= ( $stringaddress ? " \n " : '' ) . $outputlangs -> transnoentities ( " Web " ) . " : " . $outputlangs -> convToOutputCharset ( $sourcecompany -> url );
}
2010-04-06 20:40:08 +02:00
if ( $mode == 'target' )
{
if ( $usecontact )
{
2010-06-23 21:17:38 +02:00
$stringaddress .= " \n " . $outputlangs -> convToOutputCharset ( $targetcontact -> getFullName ( $outputlangs , 1 ));
2010-04-06 20:40:08 +02:00
// Recipient properties
$stringaddress .= " \n " . $outputlangs -> convToOutputCharset ( $targetcontact -> address );
2010-06-06 17:11:46 +02:00
$stringaddress .= " \n " . $outputlangs -> convToOutputCharset ( $targetcontact -> cp ) . " " . $outputlangs -> convToOutputCharset ( $targetcontact -> ville );
2010-06-19 00:54:16 +02:00
if (( $targetcompany -> departement_id || $targetcompany -> departement ) && in_array ( $targetcompany -> pays_code , array ( 'US' , 'IN' )))
2010-06-06 17:11:46 +02:00
{
2010-06-19 00:54:16 +02:00
if ( $targetcompany -> departement_id && empty ( $targetcompany -> departement )) $targetcompany -> departement = getState ( $targetcompany -> departement_id );
2010-06-06 17:11:46 +02:00
$stringaddress .= " - " . $outputlangs -> convToOutputCharset ( $targetcompany -> departement );
}
$stringaddress .= " \n " ;
2010-04-06 20:40:08 +02:00
if ( $targetcontact -> pays_code && $targetcontact -> pays_code != $sourcecompany -> pays_code ) $stringaddress .= $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcontact -> pays_code )) . " \n " ;
}
else
{
// Recipient properties
$stringaddress .= " \n " . $outputlangs -> convToOutputCharset ( $targetcompany -> address );
2010-06-06 17:11:46 +02:00
$stringaddress .= " \n " . $outputlangs -> convToOutputCharset ( $targetcompany -> cp ) . " " . $outputlangs -> convToOutputCharset ( $targetcompany -> ville );
2010-06-19 00:54:16 +02:00
if (( $targetcompany -> departement_id || $targetcompany -> departement ) && in_array ( $targetcompany -> pays_code , array ( 'US' , 'IN' )))
2010-06-06 17:11:46 +02:00
{
2010-06-19 00:54:16 +02:00
if ( $targetcompany -> departement_id && empty ( $targetcompany -> departement )) $targetcompany -> departement = getState ( $targetcompany -> departement_id );
2010-06-06 17:11:46 +02:00
$stringaddress .= " - " . $outputlangs -> convToOutputCharset ( $targetcompany -> departement );
}
$stringaddress .= " \n " ;
2010-04-06 20:40:08 +02:00
if ( $targetcompany -> pays_code && $targetcompany -> pays_code != $sourcecompany -> pays_code ) $stringaddress .= $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $targetcompany -> pays_code )) . " \n " ;
}
2010-04-07 23:14:55 +02:00
// Intra VAT
if ( $targetcompany -> tva_intra ) $stringaddress .= " \n " . $outputlangs -> transnoentities ( " VATIntraShort " ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> tva_intra );
if ( $conf -> global -> MAIN_PROFID1_IN_ADDRESS ) $stringaddress .= " \n " . $outputlangs -> transcountrynoentities ( " ProfId1 " , $targetcompany -> pays_code ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof1 );
if ( $conf -> global -> MAIN_PROFID2_IN_ADDRESS ) $stringaddress .= " \n " . $outputlangs -> transcountrynoentities ( " ProfId2 " , $targetcompany -> pays_code ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof2 );
if ( $conf -> global -> MAIN_PROFID3_IN_ADDRESS ) $stringaddress .= " \n " . $outputlangs -> transcountrynoentities ( " ProfId3 " , $targetcompany -> pays_code ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof3 );
if ( $conf -> global -> MAIN_PROFID4_IN_ADDRESS ) $stringaddress .= " \n " . $outputlangs -> transcountrynoentities ( " ProfId4 " , $targetcompany -> pays_code ) . ': ' . $outputlangs -> convToOutputCharset ( $targetcompany -> idprof4 );
2010-04-06 20:40:08 +02:00
}
2010-03-30 20:03:01 +02:00
2010-03-30 20:21:58 +02:00
return $stringaddress ;
2010-03-30 20:03:01 +02:00
}
2009-06-15 20:57:34 +02:00
/**
* \brief Show header of page for PDF generation
* \param pdf Object PDF
* \param outputlang Object lang for output
* \param page_height
*/
function pdf_pagehead ( & $pdf , $outputlangs , $page_height )
{
global $conf ;
// Add a background image on document
if ( ! empty ( $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF ))
{
2009-07-02 02:16:50 +02:00
$pdf -> Image ( $conf -> mycompany -> dir_output . '/logos/' . $conf -> global -> MAIN_USE_BACKGROUND_ON_PDF , 0 , 0 , 0 , $page_height );
2009-06-15 20:57:34 +02:00
}
}
2009-01-28 16:09:37 +01:00
/**
* \brief Show bank informations for PDF generation
*/
function pdf_bank ( & $pdf , $outputlangs , $curx , $cury , $account )
{
2010-06-17 23:43:46 +02:00
global $mysoc ;
2009-01-28 16:09:37 +01:00
$pdf -> SetXY ( $curx , $cury );
$pdf -> SetFont ( 'Arial' , 'B' , 8 );
$pdf -> MultiCell ( 100 , 3 , $outputlangs -> transnoentities ( 'PaymentByTransferOnThisBankAccount' ) . ':' , 0 , 'L' , 0 );
$cury += 4 ;
2010-06-17 23:19:00 +02:00
$outputlangs -> load ( " banks " );
2010-06-17 23:43:46 +02:00
// Get format of bank id according to country of $account
2009-01-28 16:09:37 +01:00
$usedetailedbban = $account -> useDetailedBBAN ();
if ( $usedetailedbban )
{
2010-06-17 23:19:00 +02:00
$pdf -> SetFont ( 'Arial' , '' , 6 );
2009-01-28 16:09:37 +01:00
$pdf -> SetXY ( $curx , $cury );
2010-06-17 23:19:00 +02:00
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
$cury += 3 ;
$pdf -> SetFont ( 'Arial' , 'B' , 6 );
$pdf -> line ( $curx + 1 , $cury + 1 , $curx + 1 , $cury + 10 );
$pdf -> SetXY ( $curx , $cury + 1 );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 18 , 3 , $outputlangs -> transnoentities ( " BankCode " ), 0 , 'C' , 0 );
2010-06-17 23:19:00 +02:00
$pdf -> line ( $curx + 18 , $cury + 1 , $curx + 18 , $cury + 10 );
$pdf -> SetXY ( $curx + 18 , $cury + 1 );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 18 , 3 , $outputlangs -> transnoentities ( " DeskCode " ), 0 , 'C' , 0 );
2010-06-17 23:19:00 +02:00
$pdf -> line ( $curx + 36 , $cury + 1 , $curx + 36 , $cury + 10 );
$pdf -> SetXY ( $curx + 36 , $cury + 1 );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 24 , 3 , $outputlangs -> transnoentities ( " BankAccountNumber " ), 0 , 'C' , 0 );
2010-06-17 23:19:00 +02:00
$pdf -> line ( $curx + 60 , $cury + 1 , $curx + 60 , $cury + 10 );
$pdf -> SetXY ( $curx + 60 , $cury + 1 );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 13 , 3 , $outputlangs -> transnoentities ( " BankAccountNumberKey " ), 0 , 'C' , 0 );
2010-06-17 23:19:00 +02:00
$pdf -> line ( $curx + 73 , $cury + 1 , $curx + 73 , $cury + 10 );
2009-01-28 16:09:37 +01:00
$pdf -> SetFont ( 'Arial' , '' , 8 );
$pdf -> SetXY ( $curx , $cury + 6 );
$pdf -> MultiCell ( 18 , 3 , $outputlangs -> convToOutputCharset ( $account -> code_banque ), 0 , 'C' , 0 );
$pdf -> SetXY ( $curx + 18 , $cury + 6 );
$pdf -> MultiCell ( 18 , 3 , $outputlangs -> convToOutputCharset ( $account -> code_guichet ), 0 , 'C' , 0 );
$pdf -> SetXY ( $curx + 36 , $cury + 6 );
$pdf -> MultiCell ( 24 , 3 , $outputlangs -> convToOutputCharset ( $account -> number ), 0 , 'C' , 0 );
$pdf -> SetXY ( $curx + 60 , $cury + 6 );
$pdf -> MultiCell ( 13 , 3 , $outputlangs -> convToOutputCharset ( $account -> cle_rib ), 0 , 'C' , 0 );
}
else
{
2010-06-17 23:19:00 +02:00
$pdf -> SetFont ( 'Arial' , 'B' , 6 );
$pdf -> SetXY ( $curx , $cury );
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( " Bank " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bank ), 0 , 'L' , 0 );
$cury += 3 ;
2009-01-28 16:09:37 +01:00
$pdf -> SetFont ( 'Arial' , 'B' , 6 );
$pdf -> SetXY ( $curx , $cury );
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( " BankAccountNumber " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> number ), 0 , 'L' , 0 );
$cury -= 9 ;
}
2010-06-17 23:43:46 +02:00
// Use correct name of bank id according to country
$ibankey = " IBANNumber " ;
$bickey = " BICNumber " ;
if ( $account -> getCountryCode () == 'IN' ) $ibankey = " IFSC " ;
if ( $account -> getCountryCode () == 'IN' ) $bickey = " SWIFT " ;
2010-06-17 23:19:00 +02:00
$pdf -> SetFont ( 'Arial' , '' , 6 );
2009-01-28 16:09:37 +01:00
$pdf -> SetXY ( $curx , $cury + 12 );
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( " Residence " ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> domiciliation ), 0 , 'L' , 0 );
$pdf -> SetXY ( $curx , $cury + 22 );
2010-06-17 23:43:46 +02:00
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( $ibankey ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> iban ), 0 , 'L' , 0 );
2009-01-28 16:09:37 +01:00
$pdf -> SetXY ( $curx , $cury + 25 );
2010-06-17 23:43:46 +02:00
$pdf -> MultiCell ( 90 , 3 , $outputlangs -> transnoentities ( $bickey ) . ': ' . $outputlangs -> convToOutputCharset ( $account -> bic ), 0 , 'L' , 0 );
2009-01-28 16:09:37 +01:00
return $pdf -> getY ();
}
/**
* \brief Show footer of page for PDF generation
2009-08-25 15:37:29 +02:00
* \param pdf The PDF factory
2009-01-28 16:09:37 +01:00
* \param outputlang Object lang for output
* \param paramfreetext Constant name of free text
* \param fromcompany Object company
2009-08-25 15:37:29 +02:00
* \param marge_basse Margin bottom
* \param marge_gauche Margin left
* \param page_hauteur Page height
* \param object Object shown in PDF
2009-01-28 16:09:37 +01:00
*/
2009-08-25 15:37:29 +02:00
function pdf_pagefoot ( & $pdf , $outputlangs , $paramfreetext , $fromcompany , $marge_basse , $marge_gauche , $page_hauteur , $object )
2009-01-28 16:09:37 +01:00
{
2009-08-25 22:57:54 +02:00
global $conf , $user ;
2009-01-28 16:09:37 +01:00
$outputlangs -> load ( " dict " );
2009-08-25 15:37:29 +02:00
$ligne = '' ;
2009-01-28 16:09:37 +01:00
// Line of free text
2009-08-25 15:37:29 +02:00
if ( ! empty ( $conf -> global -> $paramfreetext ))
{
// Make substitution
$substitutionarray = array (
'__FROM_NAME__' => $fromcompany -> nom ,
'__FROM_EMAIL__' => $fromcompany -> email ,
'__TOTAL_TTC__' => $object -> total_ttc ,
'__TOTAL_HT__' => $object -> total_ht ,
2010-04-28 13:14:53 +02:00
'__TOTAL_VAT__' => $object -> total_vat
2009-08-25 15:37:29 +02:00
);
2009-08-25 22:57:54 +02:00
$newfreetext = make_substitutions ( $conf -> global -> $paramfreetext , $substitutionarray , $outputlangs , $object );
2009-08-25 15:37:29 +02:00
$ligne .= $outputlangs -> convToOutputCharset ( $newfreetext );
}
2009-01-28 16:09:37 +01:00
// First line of company infos
// Juridical status
$ligne1 = " " ;
if ( $fromcompany -> forme_juridique_code )
{
$ligne1 .= ( $ligne1 ? " - " : " " ) . $outputlangs -> convToOutputCharset ( getFormeJuridiqueLabel ( $fromcompany -> forme_juridique_code ));
}
// Capital
if ( $fromcompany -> capital )
{
$ligne1 .= ( $ligne1 ? " - " : " " ) . $outputlangs -> transnoentities ( " CapitalOf " , $fromcompany -> capital ) . " " . $outputlangs -> transnoentities ( " Currency " . $conf -> monnaie );
}
// Prof Id 1
2010-05-09 16:47:02 +02:00
if ( $fromcompany -> idprof1 && ( $fromcompany -> pays_code != 'FR' || ! $fromcompany -> idprof2 ))
2009-01-28 16:09:37 +01:00
{
$field = $outputlangs -> transcountrynoentities ( " ProfId1 " , $fromcompany -> pays_code );
2009-10-23 21:03:01 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
2010-05-09 16:47:02 +02:00
$ligne1 .= ( $ligne1 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof1 );
2009-01-28 16:09:37 +01:00
}
// Prof Id 2
2010-05-09 16:47:02 +02:00
if ( $fromcompany -> idprof2 )
2009-01-28 16:09:37 +01:00
{
$field = $outputlangs -> transcountrynoentities ( " ProfId2 " , $fromcompany -> pays_code );
2009-10-23 21:03:01 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
2010-05-09 16:47:02 +02:00
$ligne1 .= ( $ligne1 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof2 );
2009-01-28 16:09:37 +01:00
}
// Second line of company infos
$ligne2 = " " ;
// Prof Id 3
2010-05-09 16:47:02 +02:00
if ( $fromcompany -> idprof3 )
2009-01-28 16:09:37 +01:00
{
$field = $outputlangs -> transcountrynoentities ( " ProfId3 " , $fromcompany -> pays_code );
2009-10-23 21:03:01 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
2010-05-09 16:47:02 +02:00
$ligne2 .= ( $ligne2 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof3 );
2009-01-28 16:09:37 +01:00
}
// Prof Id 4
2010-05-09 16:47:02 +02:00
if ( $fromcompany -> idprof4 )
2009-01-28 16:09:37 +01:00
{
$field = $outputlangs -> transcountrynoentities ( " ProfId4 " , $fromcompany -> pays_code );
2009-10-23 21:03:01 +02:00
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
2010-05-09 16:47:02 +02:00
$ligne2 .= ( $ligne2 ? " - " : " " ) . $field . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> idprof4 );
2009-01-28 16:09:37 +01:00
}
// IntraCommunautary VAT
if ( $fromcompany -> tva_intra != '' )
{
$ligne2 .= ( $ligne2 ? " - " : " " ) . $outputlangs -> transnoentities ( " VATIntraShort " ) . " : " . $outputlangs -> convToOutputCharset ( $fromcompany -> tva_intra );
}
$pdf -> SetFont ( 'Arial' , '' , 7 );
$pdf -> SetDrawColor ( 224 , 224 , 224 );
// On positionne le debut du bas de page selon nbre de lignes de ce bas de page
2009-08-25 15:37:29 +02:00
$nbofligne = dol_nboflines_bis ( $ligne , 0 , $outputlangs -> charset_output );
2009-08-02 19:40:13 +02:00
//print 'nbofligne='.$nbofligne; exit;
2009-01-28 16:09:37 +01:00
//print 'e'.$ligne.'t'.dol_nboflines($ligne);exit;
2009-08-02 19:40:13 +02:00
$posy = $marge_basse + ( $nbofligne * 3 ) + ( $ligne1 ? 3 : 0 ) + ( $ligne2 ? 3 : 0 );
2009-01-28 16:09:37 +01:00
2009-02-07 01:38:29 +01:00
if ( $ligne ) // Free text
2009-01-28 16:09:37 +01:00
{
2009-08-02 19:40:13 +02:00
$pdf -> SetXY ( $marge_gauche , - $posy );
$width = 20000 ; $align = 'L' ; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
if ( $conf -> global -> MAIN_USE_AUTOWRAP_ON_FREETEXT ) { $width = 200 ; $align = 'C' ; }
2009-08-25 15:37:29 +02:00
$pdf -> MultiCell ( $width , 3 , $ligne , 0 , $align , 0 );
2009-08-02 19:40:13 +02:00
$posy -= ( $nbofligne * 3 ); // 6 of ligne + 3 of MultiCell
2009-01-28 16:09:37 +01:00
}
$pdf -> SetY ( - $posy );
$pdf -> line ( $marge_gauche , $page_hauteur - $posy , 200 , $page_hauteur - $posy );
$posy -- ;
if ( $ligne1 )
{
2009-08-02 19:40:13 +02:00
$pdf -> SetXY ( $marge_gauche , - $posy );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 200 , 2 , $ligne1 , 0 , 'C' , 0 );
}
if ( $ligne2 )
{
$posy -= 3 ;
2009-08-02 19:40:13 +02:00
$pdf -> SetXY ( $marge_gauche , - $posy );
2009-01-28 16:09:37 +01:00
$pdf -> MultiCell ( 200 , 2 , $ligne2 , 0 , 'C' , 0 );
}
$pdf -> SetXY ( - 20 , - $posy );
$pdf -> MultiCell ( 11 , 2 , $pdf -> PageNo () . '/{nb}' , 0 , 'R' , 0 );
}
/**
2009-07-04 13:55:45 +02:00
* \brief Return line description translated in outputlangs and encoded in UTF8
* \param line Line to format
* \param outputlang Object lang for output
2009-07-23 09:51:23 +02:00
* \param hideref Hide reference
2009-07-23 09:51:23 +02:00
* \param hidedesc Hide description
2009-07-04 13:55:45 +02:00
* \param issupplierline Is it a line for a supplier object ?
2009-01-28 16:09:37 +01:00
*/
2009-07-23 09:51:23 +02:00
function pdf_getlinedesc ( $line , $outputlangs , $hideref = 0 , $hidedesc = 0 , $issupplierline = 0 )
2009-01-28 16:09:37 +01:00
{
2009-01-28 16:37:10 +01:00
global $db , $conf , $langs ;
2009-01-28 16:09:37 +01:00
2010-03-11 11:40:58 +01:00
$idprod = $line -> fk_product ;
2009-07-04 13:55:45 +02:00
$label = $line -> label ; if ( empty ( $label )) $label = $line -> libelle ;
$desc = $line -> desc ; if ( empty ( $desc )) $desc = $line -> description ;
$ref_supplier = $line -> ref_supplier ; if ( empty ( $ref_supplier )) $ref_supplier = $line -> ref_fourn ; // TODO Not yeld saved for supplier invoices, only supplier orders
2009-01-28 16:37:10 +01:00
$note = $line -> note ;
2009-01-28 16:09:37 +01:00
2009-07-04 13:55:45 +02:00
if ( $issupplierline ) $prodser = new ProductFournisseur ( $db );
else $prodser = new Product ( $db );
2009-01-28 16:37:10 +01:00
if ( $idprod )
{
$prodser -> fetch ( $idprod );
// If a predefined product and multilang and on other lang, we renamed label with label translated
if ( $conf -> global -> MAIN_MULTILANGS && ( $outputlangs -> defaultlang != $langs -> defaultlang ))
{
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ])) $label = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ];
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ])) $desc = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " description " ];
if ( ! empty ( $prodser -> multilangs [ $outputlangs -> defaultlang ][ " note " ])) $note = $prodser -> multilangs [ $outputlangs -> defaultlang ][ " note " ];
}
}
// Description short of product line
$libelleproduitservice = $label ;
// Description long of product line
2009-01-29 02:57:56 +01:00
if ( $desc && ( $desc != $label ))
2009-01-28 16:09:37 +01:00
{
2009-07-23 09:51:23 +02:00
if ( $libelleproduitservice && ! $hidedesc ) $libelleproduitservice .= " \n " ;
2009-01-28 16:09:37 +01:00
2009-01-28 16:37:10 +01:00
if ( $desc == '(CREDIT_NOTE)' && $line -> fk_remise_except )
2009-01-28 16:09:37 +01:00
{
2009-05-06 22:41:48 +02:00
$discount = new DiscountAbsolute ( $db );
2009-01-28 16:09:37 +01:00
$discount -> fetch ( $line -> fk_remise_except );
$libelleproduitservice = $outputlangs -> transnoentitiesnoconv ( " DiscountFromCreditNote " , $discount -> ref_facture_source );
}
else
{
2009-01-28 16:37:10 +01:00
if ( $idprod )
2009-01-28 16:09:37 +01:00
{
2009-07-23 09:51:23 +02:00
if ( ! $hidedesc ) $libelleproduitservice .= $desc ;
2009-01-28 16:09:37 +01:00
}
else
{
2009-01-28 16:37:10 +01:00
$libelleproduitservice .= $desc ;
2009-01-28 16:09:37 +01:00
}
}
}
2009-07-04 13:55:45 +02:00
// If line linked to a product
2009-01-28 16:37:10 +01:00
if ( $idprod )
2009-01-28 16:09:37 +01:00
{
// On ajoute la ref
if ( $prodser -> ref )
{
$prefix_prodserv = " " ;
2009-05-13 12:21:26 +02:00
$ref_prodserv = " " ;
2009-02-07 01:38:29 +01:00
if ( $conf -> global -> PRODUCT_ADD_TYPE_IN_DOCUMENTS ) // In standard mode, we do not show this
2009-01-28 16:09:37 +01:00
{
2009-02-07 01:38:29 +01:00
if ( $prodser -> isservice ())
{
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Service " ) . " " ;
}
else
{
$prefix_prodserv = $outputlangs -> transnoentitiesnoconv ( " Product " ) . " " ;
}
2009-01-28 16:09:37 +01:00
}
2009-06-15 20:57:34 +02:00
2009-07-23 09:51:23 +02:00
if ( ! $hideref )
2009-07-04 13:55:45 +02:00
{
if ( $issupplierline ) $ref_prodserv = $prodser -> ref . ' (' . $outputlangs -> trans ( " SupplierRef " ) . ' ' . $ref_supplier . ')' ; // Show local ref and supplier ref
else $ref_prodserv = $prodser -> ref ; // Show local ref only
$ref_prodserv .= " - " ;
}
2009-06-15 20:57:34 +02:00
2009-05-13 12:21:26 +02:00
$libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice ;
2009-01-28 16:09:37 +01:00
}
}
2009-01-29 02:57:56 +01:00
$libelleproduitservice = dol_htmlentitiesbr ( $libelleproduitservice , 1 );
2009-01-28 16:09:37 +01:00
if ( $line -> date_start || $line -> date_end )
{
2009-02-07 01:38:29 +01:00
// Show duration if exists
if ( $line -> date_start && $line -> date_end )
{
2009-02-20 23:53:15 +01:00
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateFromTo' , dol_print_date ( $line -> date_start , $format , false , $outputlangs ), dol_print_date ( $line -> date_end , $format , false , $outputlangs )) . ')' ;
2009-02-07 01:38:29 +01:00
}
if ( $line -> date_start && ! $line -> date_end )
{
2009-02-20 23:53:15 +01:00
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateFrom' , dol_print_date ( $line -> date_start , $format , false , $outputlangs )) . ')' ;
2009-02-07 01:38:29 +01:00
}
if ( ! $line -> date_start && $line -> date_end )
{
2009-02-20 23:53:15 +01:00
$period = '(' . $outputlangs -> transnoentitiesnoconv ( 'DateUntil' , dol_print_date ( $line -> date_end , $format , false , $outputlangs )) . ')' ;
2009-02-07 01:38:29 +01:00
}
//print '>'.$outputlangs->charset_output.','.$period;
2009-01-28 16:09:37 +01:00
$libelleproduitservice .= " <br> " . dol_htmlentitiesbr ( $period , 1 );
2009-02-07 01:38:29 +01:00
//print $libelleproduitservice;
2009-01-28 16:09:37 +01:00
}
return $libelleproduitservice ;
}
?>