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