pdf.lib.php 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192
  1. <?php
  2. /* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  5. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  8. * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2012-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  10. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  11. * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
  12. * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. * or see http://www.gnu.org/
  27. */
  28. /**
  29. * \file htdocs/core/lib/pdf.lib.php
  30. * \brief Set of functions used for PDF generation
  31. * \ingroup core
  32. */
  33. /**
  34. * Return array with format properties of default PDF format
  35. *
  36. * @param Translate $outputlangs Output lang to use to autodetect output format if setup not done
  37. * @return array Array('width'=>w,'height'=>h,'unit'=>u);
  38. */
  39. function pdf_getFormat(Translate $outputlangs = null)
  40. {
  41. global $conf,$db;
  42. // Default value if setup was not done and/or entry into c_paper_format not defined
  43. $width=210; $height=297; $unit='mm';
  44. if (empty($conf->global->MAIN_PDF_FORMAT))
  45. {
  46. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  47. $pdfformat=dol_getDefaultFormat($outputlangs);
  48. }
  49. else $pdfformat=$conf->global->MAIN_PDF_FORMAT;
  50. $sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
  51. $sql.=" WHERE code = '".$pdfformat."'";
  52. $resql=$db->query($sql);
  53. if ($resql)
  54. {
  55. $obj=$db->fetch_object($resql);
  56. if ($obj)
  57. {
  58. $width=(int) $obj->width;
  59. $height=(int) $obj->height;
  60. $unit=$obj->unit;
  61. }
  62. }
  63. //print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
  64. return array('width'=>$width,'height'=>$height,'unit'=>$unit);
  65. }
  66. /**
  67. * Return a PDF instance object. We create a FPDI instance that instantiate TCPDF.
  68. *
  69. * @param string $format Array(width,height). Keep empty to use default setup.
  70. * @param string $metric Unit of format ('mm')
  71. * @param string $pagetype 'P' or 'l'
  72. * @return TCPDF PDF object
  73. */
  74. function pdf_getInstance($format='',$metric='mm',$pagetype='P')
  75. {
  76. global $conf;
  77. // Define constant for TCPDF
  78. if (! defined('K_TCPDF_EXTERNAL_CONFIG'))
  79. {
  80. define('K_TCPDF_EXTERNAL_CONFIG',1); // this avoid using tcpdf_config file
  81. define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
  82. define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
  83. dol_mkdir(K_PATH_CACHE);
  84. define('K_BLANK_IMAGE', '_blank.png');
  85. define('PDF_PAGE_FORMAT', 'A4');
  86. define('PDF_PAGE_ORIENTATION', 'P');
  87. define('PDF_CREATOR', 'TCPDF');
  88. define('PDF_AUTHOR', 'TCPDF');
  89. define('PDF_HEADER_TITLE', 'TCPDF Example');
  90. define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
  91. define('PDF_UNIT', 'mm');
  92. define('PDF_MARGIN_HEADER', 5);
  93. define('PDF_MARGIN_FOOTER', 10);
  94. define('PDF_MARGIN_TOP', 27);
  95. define('PDF_MARGIN_BOTTOM', 25);
  96. define('PDF_MARGIN_LEFT', 15);
  97. define('PDF_MARGIN_RIGHT', 15);
  98. define('PDF_FONT_NAME_MAIN', 'helvetica');
  99. define('PDF_FONT_SIZE_MAIN', 10);
  100. define('PDF_FONT_NAME_DATA', 'helvetica');
  101. define('PDF_FONT_SIZE_DATA', 8);
  102. define('PDF_FONT_MONOSPACED', 'courier');
  103. define('PDF_IMAGE_SCALE_RATIO', 1.25);
  104. define('HEAD_MAGNIFICATION', 1.1);
  105. define('K_CELL_HEIGHT_RATIO', 1.25);
  106. define('K_TITLE_MAGNIFICATION', 1.3);
  107. define('K_SMALL_RATIO', 2/3);
  108. define('K_THAI_TOPCHARS', true);
  109. define('K_TCPDF_CALLS_IN_HTML', true);
  110. define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
  111. }
  112. // Load TCPDF
  113. require_once TCPDF_PATH.'tcpdf.php';
  114. // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
  115. if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php';
  116. //$arrayformat=pdf_getFormat();
  117. //$format=array($arrayformat['width'],$arrayformat['height']);
  118. //$metric=$arrayformat['unit'];
  119. $pdfa=false; // PDF-1.3
  120. if (! empty($conf->global->PDF_USE_1A)) $pdfa=true; // PDF1/A
  121. if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
  122. else $pdf = new TCPDF($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
  123. // Protection and encryption of pdf
  124. if (! empty($conf->global->PDF_SECURITY_ENCRYPTION))
  125. {
  126. /* Permission supported by TCPDF
  127. - print : Print the document;
  128. - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
  129. - copy : Copy or otherwise extract text and graphics from the document;
  130. - 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);
  131. - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
  132. - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
  133. - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
  134. - 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.
  135. - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
  136. */
  137. // For TCPDF, we specify permission we want to block
  138. $pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true):array('modify','copy')); // Json format in llx_const
  139. // Password for the end user
  140. $pdfuserpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_USERPASS:'');
  141. // Password of the owner, created randomly if not defined
  142. $pdfownerpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS:null);
  143. // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
  144. $encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0);
  145. // Array of recipients containing public-key certificates ('c') and permissions ('p').
  146. // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
  147. $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const
  148. $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass,$encstrength,$pubkeys);
  149. }
  150. return $pdf;
  151. }
  152. /**
  153. * Return if pdf file is protected/encrypted
  154. *
  155. * @param TCPDF $pdf PDF initialized object
  156. * @param string $pathoffile Path of file
  157. * @return boolean True or false
  158. */
  159. function pdf_getEncryption(&$pdf, $pathoffile)
  160. {
  161. $isencrypted = false;
  162. $pdfparser = $pdf->_getPdfParser($pathoffile);
  163. $data = $pdfparser->getParsedData();
  164. if (isset($data[0]['trailer'][1]['/Encrypt'])) {
  165. $isencrypted = true;
  166. }
  167. return $isencrypted;
  168. }
  169. /**
  170. * Return font name to use for PDF generation
  171. *
  172. * @param Translate $outputlangs Output langs object
  173. * @return string Name of font to use
  174. */
  175. function pdf_getPDFFont($outputlangs)
  176. {
  177. global $conf;
  178. if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
  179. $font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF
  180. if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
  181. {
  182. if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
  183. {
  184. $font=$outputlangs->trans('FONTFORPDF');
  185. }
  186. }
  187. return $font;
  188. }
  189. /**
  190. * Return font size to use for PDF generation
  191. *
  192. * @param Translate $outputlangs Output langs object
  193. * @return int Size of font to use
  194. */
  195. function pdf_getPDFFontSize($outputlangs)
  196. {
  197. $size=10; // By default, for FPDI or ISO language on TCPDF
  198. if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
  199. {
  200. if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
  201. {
  202. $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
  203. }
  204. }
  205. return $size;
  206. }
  207. /**
  208. * Return height to use for Logo onto PDF
  209. *
  210. * @param string $logo Full path to logo file to use
  211. * @param bool $url Image with url (true or false)
  212. * @return number
  213. */
  214. function pdf_getHeightForLogo($logo, $url = false)
  215. {
  216. global $conf;
  217. $height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
  218. $maxwidth=130;
  219. include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  220. $tmp=dol_getImageSize($logo, $url);
  221. if ($tmp['height'])
  222. {
  223. $width=round($height*$tmp['width']/$tmp['height']);
  224. if ($width > $maxwidth) $height=$height*$maxwidth/$width;
  225. }
  226. //print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
  227. return $height;
  228. }
  229. /**
  230. * Function to try to calculate height of a HTML Content
  231. *
  232. * @param TCPDF $pdf PDF initialized object
  233. * @param string $htmlcontent HTML Contect
  234. * @return int Height
  235. * @see getStringHeight
  236. */
  237. function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
  238. {
  239. // store current object
  240. $pdf->startTransaction();
  241. // store starting values
  242. $start_y = $pdf->GetY();
  243. //var_dump($start_y);
  244. $start_page = $pdf->getPage();
  245. // call printing functions with content
  246. $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J',true);
  247. // get the new Y
  248. $end_y = $pdf->GetY();
  249. $end_page = $pdf->getPage();
  250. // calculate height
  251. $height = 0;
  252. if ($end_page == $start_page) {
  253. $height = $end_y - $start_y;
  254. }
  255. else
  256. {
  257. for ($page=$start_page; $page <= $end_page; ++$page) {
  258. $pdf->setPage($page);
  259. $tmpm=$pdf->getMargins();
  260. $tMargin = $tmpm['top'];
  261. if ($page == $start_page) {
  262. // first page
  263. $height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
  264. } elseif ($page == $end_page) {
  265. // last page
  266. $height = $end_y - $tMargin;
  267. } else {
  268. $height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
  269. }
  270. }
  271. }
  272. // restore previous object
  273. $pdf = $pdf->rollbackTransaction();
  274. return $height;
  275. }
  276. /**
  277. * Returns the name of the thirdparty
  278. *
  279. * @param Societe|Contact $thirdparty Contact or thirdparty
  280. * @param Translate $outputlangs Output language
  281. * @param int $includealias 1=Include alias name after name
  282. * @return string String with name of thirdparty (+ alias if requested)
  283. */
  284. function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
  285. {
  286. global $conf;
  287. // Recipient name
  288. $socname = '';
  289. if ($thirdparty instanceof Societe) {
  290. $socname .= $thirdparty->name;
  291. if (($includealias || ! empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
  292. $socname .= "\n".$thirdparty->name_alias;
  293. }
  294. } elseif ($thirdparty instanceof Contact) {
  295. $socname = $thirdparty->socname;
  296. } else {
  297. throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
  298. }
  299. return $outputlangs->convToOutputCharset($socname);
  300. }
  301. /**
  302. * Return a string with full address formated for output on documents
  303. *
  304. * @param Translate $outputlangs Output langs object
  305. * @param Societe $sourcecompany Source company object
  306. * @param Societe $targetcompany Target company object
  307. * @param Contact $targetcontact Target contact object
  308. * @param int $usecontact Use contact instead of company
  309. * @param int $mode Address type ('source', 'target', 'targetwithdetails', 'targetwithdetails_xxx': target but include also phone/fax/email/url)
  310. * @param Object $object Object we want to build document for
  311. * @return string String with full address
  312. */
  313. function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null)
  314. {
  315. global $conf, $hookmanager;
  316. if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
  317. if ($mode == 'target' && ! is_object($targetcompany)) return -1;
  318. if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
  319. if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
  320. if (! empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id)) $sourcecompany->departement_id=getState($sourcecompany->state_id,'2');
  321. if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
  322. if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
  323. if (! empty($targetcompany->state_id) && !isset($targetcompany->departement_id)) $targetcompany->departement_id=getState($targetcompany->state_id,'2');
  324. $reshook=0;
  325. $stringaddress = '';
  326. if (is_object($hookmanager))
  327. {
  328. $parameters = array('sourcecompany'=>&$sourcecompany,'targetcompany'=>&$targetcompany,'targetcontact'=>$targetcontact,'outputlangs'=>$outputlangs,'mode'=>$mode,'usecontact'=>$usecontact);
  329. $action='';
  330. $reshook = $hookmanager->executeHooks('pdf_build_address',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  331. $stringaddress.=$hookmanager->resPrint;
  332. }
  333. if (empty($reshook))
  334. {
  335. if ($mode == 'source')
  336. {
  337. $withCountry = 0;
  338. if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;
  339. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
  340. if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
  341. {
  342. // Phone
  343. if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
  344. // Fax
  345. if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
  346. // EMail
  347. if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
  348. // Web
  349. if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
  350. }
  351. // Intra VAT
  352. if (! empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
  353. {
  354. if ($sourcecompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
  355. }
  356. // Professionnal Ids
  357. if (! empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof1))
  358. {
  359. $tmp=$outputlangs->transcountrynoentities("ProfId1",$sourcecompany->country_code);
  360. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  361. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
  362. }
  363. if (! empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof2))
  364. {
  365. $tmp=$outputlangs->transcountrynoentities("ProfId2",$sourcecompany->country_code);
  366. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  367. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
  368. }
  369. if (! empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof3))
  370. {
  371. $tmp=$outputlangs->transcountrynoentities("ProfId3",$sourcecompany->country_code);
  372. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  373. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
  374. }
  375. if (! empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof4))
  376. {
  377. $tmp=$outputlangs->transcountrynoentities("ProfId4",$sourcecompany->country_code);
  378. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  379. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
  380. }
  381. if (! empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof5))
  382. {
  383. $tmp=$outputlangs->transcountrynoentities("ProfId5",$sourcecompany->country_code);
  384. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  385. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
  386. }
  387. if (! empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof6))
  388. {
  389. $tmp=$outputlangs->transcountrynoentities("ProfId6",$sourcecompany->country_code);
  390. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  391. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
  392. }
  393. }
  394. if ($mode == 'target' || preg_match('/targetwithdetails/',$mode))
  395. {
  396. if ($usecontact)
  397. {
  398. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
  399. if (!empty($targetcontact->address)) {
  400. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
  401. } else {
  402. $companytouseforaddress = $targetcompany;
  403. // Contact on a thirdparty that is a different thirdparty than the thirdparty of object
  404. if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id)
  405. {
  406. $targetcontact->fetch_thirdparty();
  407. $companytouseforaddress = $targetcontact->thirdparty;
  408. }
  409. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
  410. }
  411. // Country
  412. if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
  413. $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
  414. }
  415. else if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
  416. $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
  417. }
  418. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
  419. {
  420. // Phone
  421. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
  422. {
  423. if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
  424. if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
  425. if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
  426. if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
  427. }
  428. // Fax
  429. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
  430. {
  431. if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
  432. }
  433. // EMail
  434. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
  435. {
  436. if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
  437. }
  438. // Web
  439. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
  440. {
  441. if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
  442. }
  443. }
  444. }
  445. else
  446. {
  447. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
  448. // Country
  449. if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
  450. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
  451. {
  452. // Phone
  453. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
  454. {
  455. if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
  456. if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
  457. if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
  458. if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
  459. }
  460. // Fax
  461. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
  462. {
  463. if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
  464. }
  465. // EMail
  466. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
  467. {
  468. if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
  469. }
  470. // Web
  471. if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
  472. {
  473. if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
  474. }
  475. }
  476. }
  477. // Intra VAT
  478. if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS))
  479. {
  480. if ($targetcompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
  481. }
  482. // Professionnal Ids
  483. if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1))
  484. {
  485. $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code);
  486. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  487. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
  488. }
  489. if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2))
  490. {
  491. $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code);
  492. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  493. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
  494. }
  495. if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3))
  496. {
  497. $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code);
  498. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  499. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
  500. }
  501. if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4))
  502. {
  503. $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code);
  504. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  505. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
  506. }
  507. if (! empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && ! empty($targetcompany->idprof5))
  508. {
  509. $tmp=$outputlangs->transcountrynoentities("ProfId5",$targetcompany->country_code);
  510. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  511. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
  512. }
  513. if (! empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && ! empty($targetcompany->idprof6))
  514. {
  515. $tmp=$outputlangs->transcountrynoentities("ProfId6",$targetcompany->country_code);
  516. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  517. $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
  518. }
  519. // Public note
  520. if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
  521. {
  522. if ($mode == 'source' && ! empty($sourcecompany->note_public))
  523. {
  524. $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($sourcecompany->note_public);
  525. }
  526. if (($mode == 'target' || preg_match('/targetwithdetails/',$mode)) && ! empty($targetcompany->note_public))
  527. {
  528. $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($targetcompany->note_public);
  529. }
  530. }
  531. }
  532. }
  533. return $stringaddress;
  534. }
  535. /**
  536. * Show header of page for PDF generation
  537. *
  538. * @param TCPDF $pdf Object PDF
  539. * @param Translate $outputlangs Object lang for output
  540. * @param int $page_height Height of page
  541. * @return void
  542. */
  543. function pdf_pagehead(&$pdf,$outputlangs,$page_height)
  544. {
  545. global $conf;
  546. // Add a background image on document
  547. if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF)) // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
  548. {
  549. $pdf->SetAutoPageBreak(0,0); // Disable auto pagebreak before adding image
  550. $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);
  551. $pdf->SetAutoPageBreak(1,0); // Restore pagebreak
  552. }
  553. }
  554. /**
  555. * Return array of possible substitutions for PDF content (without external module substitutions).
  556. *
  557. * @param Translate $outputlangs Output language
  558. * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...)
  559. * @param Object $object Object
  560. * @param int $onlykey 1=Do not calculate some heavy values of keys (performance enhancement when we need only the keys), 2=Values are truncated and html sanitized (to use for help tooltip)
  561. * @return array Array of substitutions
  562. */
  563. function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
  564. {
  565. $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
  566. $substitutionarray['__FROM_NAME__']='__FROM_NAME__';
  567. $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
  568. return $substitutionarray;
  569. }
  570. /**
  571. * Add a draft watermark on PDF files
  572. *
  573. * @param TCPDF $pdf Object PDF
  574. * @param Translate $outputlangs Object lang
  575. * @param int $h Height of PDF
  576. * @param int $w Width of PDF
  577. * @param string $unit Unit of height (mm, pt, ...)
  578. * @param string $text Text to show
  579. * @return void
  580. */
  581. function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
  582. {
  583. global $langs, $mysoc, $user;
  584. // Print Draft Watermark
  585. if ($unit=='pt') $k=1;
  586. elseif ($unit=='mm') $k=72/25.4;
  587. elseif ($unit=='cm') $k=72/2.54;
  588. elseif ($unit=='in') $k=72;
  589. // Make substitution
  590. $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
  591. complete_substitutions_array($substitutionarray, $outputlangs, null);
  592. $text=make_substitutions($text, $substitutionarray, $outputlangs);
  593. $text=$outputlangs->convToOutputCharset($text);
  594. $savx=$pdf->getX(); $savy=$pdf->getY();
  595. $watermark_angle=atan($h/$w)/2;
  596. $watermark_x_pos=0;
  597. $watermark_y_pos=$h/3;
  598. $watermark_x=$w/2;
  599. $watermark_y=$h/3;
  600. $pdf->SetFont('','B',40);
  601. $pdf->SetTextColor(255,192,203);
  602. //rotate
  603. $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));
  604. //print watermark
  605. $pdf->SetXY($watermark_x_pos,$watermark_y_pos);
  606. $pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0);
  607. //antirotate
  608. $pdf->_out('Q');
  609. $pdf->SetXY($savx,$savy);
  610. }
  611. /**
  612. * Show bank informations for PDF generation
  613. *
  614. * @param TCPDF $pdf Object PDF
  615. * @param Translate $outputlangs Object lang
  616. * @param int $curx X
  617. * @param int $cury Y
  618. * @param Account $account Bank account object
  619. * @param int $onlynumber Output only number (bank+desk+key+number according to country, but without name of bank and domiciliation)
  620. * @param int $default_font_size Default font size
  621. * @return float The Y PDF position
  622. */
  623. function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default_font_size=10)
  624. {
  625. global $mysoc, $conf;
  626. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
  627. $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
  628. $diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT);
  629. $pdf->SetXY($curx, $cury);
  630. if (empty($onlynumber))
  631. {
  632. $pdf->SetFont('','B',$default_font_size - $diffsizetitle);
  633. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
  634. $cury+=4;
  635. }
  636. $outputlangs->load("banks");
  637. // Use correct name of bank id according to country
  638. $bickey="BICNumber";
  639. if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
  640. // Get format of bank account according to its country
  641. $usedetailedbban=$account->useDetailedBBAN();
  642. //$onlynumber=0; $usedetailedbban=1; // For tests
  643. if ($usedetailedbban)
  644. {
  645. $savcurx=$curx;
  646. if (empty($onlynumber))
  647. {
  648. $pdf->SetFont('','',$default_font_size - $diffsizecontent);
  649. $pdf->SetXY($curx, $cury);
  650. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  651. $cury+=3;
  652. }
  653. if (empty($conf->global->PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN)) // Note that some countries still need bank number, BIC/IBAN not enougth for them
  654. {
  655. // Note:
  656. // bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
  657. // desk = code guichet (FR), used only when $usedetailedbban = 1
  658. // number = account number
  659. // key = check control key used only when $usedetailedbban = 1
  660. if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6);
  661. foreach ($account->getFieldsToShow() as $val)
  662. {
  663. $pdf->SetXY($curx, $cury+4);
  664. $pdf->SetFont('','',$default_font_size - 3);
  665. if ($val == 'BankCode') {
  666. // Bank code
  667. $tmplength = 18;
  668. $content = $account->code_banque;
  669. } elseif ($val == 'DeskCode') {
  670. // Desk
  671. $tmplength = 18;
  672. $content = $account->code_guichet;
  673. } elseif ($val == 'BankAccountNumber') {
  674. // Number
  675. $tmplength = 24;
  676. $content = $account->number;
  677. } elseif ($val == 'BankAccountNumberKey') {
  678. // Key
  679. $tmplength = 15;
  680. $content = $account->cle_rib;
  681. }elseif ($val == 'IBAN' || $val == 'BIC') {
  682. // Key
  683. $tmplength = 0;
  684. $content = '';
  685. } else {
  686. dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
  687. break;
  688. }
  689. $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0);
  690. $pdf->SetXY($curx, $cury + 1);
  691. $curx += $tmplength;
  692. $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
  693. $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0);
  694. if (empty($onlynumber)) {
  695. $pdf->line($curx, $cury + 1, $curx, $cury + 7);
  696. }
  697. }
  698. $curx=$savcurx;
  699. $cury+=8;
  700. }
  701. }
  702. else
  703. {
  704. $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
  705. $pdf->SetXY($curx, $cury);
  706. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  707. $cury+=3;
  708. $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
  709. $pdf->SetXY($curx, $cury);
  710. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
  711. $cury+=3;
  712. if ($diffsizecontent <= 2) $cury+=1;
  713. }
  714. $pdf->SetFont('','',$default_font_size - $diffsizecontent);
  715. if (empty($onlynumber) && ! empty($account->domiciliation))
  716. {
  717. $pdf->SetXY($curx, $cury);
  718. $val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
  719. $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
  720. //$nboflines=dol_nboflines_bis($val,120);
  721. //$cury+=($nboflines*3)+2;
  722. $tmpy=$pdf->getStringHeight(100, $val);
  723. $cury+=$tmpy;
  724. }
  725. if (! empty($account->proprio))
  726. {
  727. $pdf->SetXY($curx, $cury);
  728. $val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio);
  729. $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
  730. $tmpy=$pdf->getStringHeight(100, $val);
  731. $cury+=$tmpy;
  732. $cur+=1;
  733. }
  734. else if (! $usedetailedbban) $cury+=1;
  735. // Use correct name of bank id according to country
  736. $ibankey = FormBank::getIBANLabel($account);
  737. if (! empty($account->iban))
  738. {
  739. //Remove whitespaces to ensure we are dealing with the format we expect
  740. $ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
  741. $ibanDisplay = "";
  742. $nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
  743. for ($i = 0; $i < $nbIbanDisplay_temp; $i++)
  744. {
  745. $ibanDisplay .= $ibanDisplay_temp[$i];
  746. if($i%4 == 3 && $i > 0) $ibanDisplay .= " ";
  747. }
  748. $pdf->SetFont('','B',$default_font_size - 3);
  749. $pdf->SetXY($curx, $cury);
  750. $pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0);
  751. $cury+=3;
  752. }
  753. if (! empty($account->bic))
  754. {
  755. $pdf->SetFont('','B',$default_font_size - 3);
  756. $pdf->SetXY($curx, $cury);
  757. $pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
  758. }
  759. return $pdf->getY();
  760. }
  761. /**
  762. * Show footer of page for PDF generation
  763. *
  764. * @param TCPDF $pdf The PDF factory
  765. * @param Translate $outputlangs Object lang for output
  766. * @param string $paramfreetext Constant name of free text
  767. * @param Societe $fromcompany Object company
  768. * @param int $marge_basse Margin bottom we use for the autobreak
  769. * @param int $marge_gauche Margin left (no more used)
  770. * @param int $page_hauteur Page height (no more used)
  771. * @param Object $object Object shown in PDF
  772. * @param int $showdetails Show company adress details into footer (0=Nothing, 1=Show address, 2=Show managers, 3=Both)
  773. * @param int $hidefreetext 1=Hide free text, 0=Show free text
  774. * @return int Return height of bottom margin including footer text
  775. */
  776. function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0,$hidefreetext=0)
  777. {
  778. global $conf,$user,$mysoc;
  779. $outputlangs->load("dict");
  780. $line='';
  781. $dims=$pdf->getPageDimensions();
  782. // Line of free text
  783. if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
  784. {
  785. $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
  786. // More substitution keys
  787. $substitutionarray['__FROM_NAME__']=$fromcompany->name;
  788. $substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
  789. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  790. $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
  791. // Make a change into HTML code to allow to include images from medias directory.
  792. // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
  793. // become
  794. // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
  795. $newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
  796. $line.=$outputlangs->convToOutputCharset($newfreetext);
  797. }
  798. // First line of company infos
  799. $line1=""; $line2=""; $line3=""; $line4="";
  800. if ($showdetails == 1 || $showdetails == 3)
  801. {
  802. // Company name
  803. if ($fromcompany->name)
  804. {
  805. $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
  806. }
  807. // Address
  808. if ($fromcompany->address)
  809. {
  810. $line1.=($line1?" - ":"").str_replace("\n", ", ", $fromcompany->address);
  811. }
  812. // Zip code
  813. if ($fromcompany->zip)
  814. {
  815. $line1.=($line1?" - ":"").$fromcompany->zip;
  816. }
  817. // Town
  818. if ($fromcompany->town)
  819. {
  820. $line1.=($line1?" ":"").$fromcompany->town;
  821. }
  822. // Phone
  823. if ($fromcompany->phone)
  824. {
  825. $line2.=($line2?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
  826. }
  827. // Fax
  828. if ($fromcompany->fax)
  829. {
  830. $line2.=($line2?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
  831. }
  832. // URL
  833. if ($fromcompany->url)
  834. {
  835. $line2.=($line2?" - ":"").$fromcompany->url;
  836. }
  837. // Email
  838. if ($fromcompany->email)
  839. {
  840. $line2.=($line2?" - ":"").$fromcompany->email;
  841. }
  842. }
  843. if ($showdetails == 2 || $showdetails == 3 || ($fromcompany->country_code == 'DE'))
  844. {
  845. // Managers
  846. if ($fromcompany->managers)
  847. {
  848. $line2.=($line2?" - ":"").$fromcompany->managers;
  849. }
  850. }
  851. // Line 3 of company infos
  852. // Juridical status
  853. if ($fromcompany->forme_juridique_code)
  854. {
  855. $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
  856. }
  857. // Capital
  858. if ($fromcompany->capital)
  859. {
  860. $tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string
  861. if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
  862. else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$tmpamounttoshow,$outputlangs);
  863. }
  864. // Prof Id 1
  865. if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
  866. {
  867. $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
  868. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  869. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
  870. }
  871. // Prof Id 2
  872. if ($fromcompany->idprof2)
  873. {
  874. $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
  875. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  876. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
  877. }
  878. // Line 4 of company infos
  879. // Prof Id 3
  880. if ($fromcompany->idprof3)
  881. {
  882. $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
  883. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  884. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
  885. }
  886. // Prof Id 4
  887. if ($fromcompany->idprof4)
  888. {
  889. $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
  890. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  891. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
  892. }
  893. // Prof Id 5
  894. if ($fromcompany->idprof5)
  895. {
  896. $field=$outputlangs->transcountrynoentities("ProfId5",$fromcompany->country_code);
  897. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  898. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
  899. }
  900. // Prof Id 6
  901. if ($fromcompany->idprof6)
  902. {
  903. $field=$outputlangs->transcountrynoentities("ProfId6",$fromcompany->country_code);
  904. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  905. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
  906. }
  907. // IntraCommunautary VAT
  908. if ($fromcompany->tva_intra != '')
  909. {
  910. $line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
  911. }
  912. $pdf->SetFont('','',7);
  913. $pdf->SetDrawColor(224,224,224);
  914. // The start of the bottom of this page footer is positioned according to # of lines
  915. $freetextheight=0;
  916. if ($line) // Free text
  917. {
  918. //$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
  919. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  920. {
  921. $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.
  922. if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
  923. $width=200; $align='C';
  924. }
  925. $freetextheight=$pdf->getStringHeight($width,$line);
  926. }
  927. else
  928. {
  929. $freetextheight=pdfGetHeightForHtmlContent($pdf,dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
  930. //print '<br>'.$freetextheight;exit;
  931. }
  932. }
  933. $marginwithfooter=$marge_basse + $freetextheight + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0);
  934. $posy=$marginwithfooter+0;
  935. if ($line) // Free text
  936. {
  937. $pdf->SetXY($dims['lm'],-$posy);
  938. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) // by default
  939. {
  940. $pdf->MultiCell(0, 3, $line, 0, $align, 0);
  941. }
  942. else
  943. {
  944. $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk']-$marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
  945. }
  946. $posy-=$freetextheight;
  947. }
  948. $pdf->SetY(-$posy);
  949. $pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy);
  950. $posy--;
  951. if (! empty($line1))
  952. {
  953. $pdf->SetFont('','B',7);
  954. $pdf->SetXY($dims['lm'],-$posy);
  955. $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line1, 0, 'C', 0);
  956. $posy-=3;
  957. $pdf->SetFont('','',7);
  958. }
  959. if (! empty($line2))
  960. {
  961. $pdf->SetFont('','B',7);
  962. $pdf->SetXY($dims['lm'],-$posy);
  963. $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line2, 0, 'C', 0);
  964. $posy-=3;
  965. $pdf->SetFont('','',7);
  966. }
  967. if (! empty($line3))
  968. {
  969. $pdf->SetXY($dims['lm'],-$posy);
  970. $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line3, 0, 'C', 0);
  971. }
  972. if (! empty($line4))
  973. {
  974. $posy-=3;
  975. $pdf->SetXY($dims['lm'],-$posy);
  976. $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line4, 0, 'C', 0);
  977. }
  978. // Show page nb only on iso languages (so default Helvetica font)
  979. if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica')
  980. {
  981. $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy);
  982. //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
  983. $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  984. }
  985. return $marginwithfooter;
  986. }
  987. /**
  988. * Show linked objects for PDF generation
  989. *
  990. * @param TCPDF $pdf Object PDF
  991. * @param object $object Object
  992. * @param Translate $outputlangs Object lang
  993. * @param int $posx X
  994. * @param int $posy Y
  995. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  996. * @param float $h Cell minimum height. The cell extends automatically if needed.
  997. * @param int $align Align
  998. * @param string $default_font_size Font size
  999. * @return float The Y PDF position
  1000. */
  1001. function pdf_writeLinkedObjects(&$pdf,$object,$outputlangs,$posx,$posy,$w,$h,$align,$default_font_size)
  1002. {
  1003. $linkedobjects = pdf_getLinkedObjects($object,$outputlangs);
  1004. if (! empty($linkedobjects))
  1005. {
  1006. foreach($linkedobjects as $linkedobject)
  1007. {
  1008. $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
  1009. if (! empty($linkedobject["date_value"]))
  1010. {
  1011. $reftoshow .= ' / '.$linkedobject["date_value"];
  1012. }
  1013. $posy+=3;
  1014. $pdf->SetXY($posx,$posy);
  1015. $pdf->SetFont('','', $default_font_size - 2);
  1016. $pdf->MultiCell($w, $h, $reftoshow, '', $align);
  1017. }
  1018. }
  1019. return $pdf->getY();
  1020. }
  1021. /**
  1022. * Output line description into PDF
  1023. *
  1024. * @param TCPDF $pdf PDF object
  1025. * @param Object $object Object
  1026. * @param int $i Current line number
  1027. * @param Translate $outputlangs Object lang for output
  1028. * @param int $w Width
  1029. * @param int $h Height
  1030. * @param int $posx Pos x
  1031. * @param int $posy Pos y
  1032. * @param int $hideref Hide reference
  1033. * @param int $hidedesc Hide description
  1034. * @param int $issupplierline Is it a line for a supplier object ?
  1035. * @return string
  1036. */
  1037. function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0)
  1038. {
  1039. global $db, $conf, $langs, $hookmanager;
  1040. $reshook=0;
  1041. $result='';
  1042. //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) ) )
  1043. 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
  1044. {
  1045. $special_code = $object->lines[$i]->special_code;
  1046. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1047. $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);
  1048. $action='';
  1049. $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1050. if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1051. }
  1052. if (empty($reshook))
  1053. {
  1054. $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
  1055. //var_dump($labelproductservice);exit;
  1056. // Fix bug of some HTML editors that replace links <img src="http://localhostgit/viewimage.php?modulepart=medias&file=image/efd.png" into <img src="http://localhostgit/viewimage.php?modulepart=medias&amp;file=image/efd.png"
  1057. // We make the reverse, so PDF generation has the real URL.
  1058. $labelproductservice = preg_replace('/(<img[^>]*src=")([^"]*)(&amp;)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep);
  1059. //var_dump($labelproductservice);exit;
  1060. // Description
  1061. $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true);
  1062. $result.=$labelproductservice;
  1063. }
  1064. return $result;
  1065. }
  1066. /**
  1067. * Return line description translated in outputlangs and encoded into htmlentities and with <br>
  1068. *
  1069. * @param Object $object Object
  1070. * @param int $i Current line number (0 = first line, 1 = second line, ...)
  1071. * @param Translate $outputlangs Object langs for output
  1072. * @param int $hideref Hide reference
  1073. * @param int $hidedesc Hide description
  1074. * @param int $issupplierline Is it a line for a supplier object ?
  1075. * @return string String with line
  1076. */
  1077. function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
  1078. {
  1079. global $db, $conf, $langs;
  1080. $idprod=(! empty($object->lines[$i]->fk_product)?$object->lines[$i]->fk_product:false);
  1081. $label=(! empty($object->lines[$i]->label)?$object->lines[$i]->label:(! empty($object->lines[$i]->product_label)?$object->lines[$i]->product_label:''));
  1082. $desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:''));
  1083. $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
  1084. $note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:'');
  1085. $dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false);
  1086. if ($issupplierline)
  1087. {
  1088. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  1089. $prodser = new ProductFournisseur($db);
  1090. }
  1091. else
  1092. {
  1093. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  1094. $prodser = new Product($db);
  1095. }
  1096. if ($idprod)
  1097. {
  1098. $prodser->fetch($idprod);
  1099. // If a predefined product and multilang and on other lang, we renamed label with label translated
  1100. if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
  1101. {
  1102. $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)
  1103. // 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
  1104. // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
  1105. // Set label
  1106. // 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.
  1107. //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
  1108. $textwasmodified=($label == $prodser->label);
  1109. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
  1110. // Set desc
  1111. // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
  1112. $textwasmodified=false;
  1113. if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
  1114. $textwasmodified=(strpos(dol_html_entity_decode($desc,ENT_QUOTES | ENT_HTML401),dol_html_entity_decode($prodser->description,ENT_QUOTES | ENT_HTML401))!==false);
  1115. } else {
  1116. $textwasmodified=($desc == $prodser->description);
  1117. }
  1118. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
  1119. // Set note
  1120. $textwasmodified=($note == $prodser->note);
  1121. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
  1122. }
  1123. }
  1124. // Description short of product line
  1125. $libelleproduitservice=$label;
  1126. // Description long of product line
  1127. if (! empty($desc) && ($desc != $label))
  1128. {
  1129. if ($libelleproduitservice && empty($hidedesc))
  1130. {
  1131. $libelleproduitservice.='__N__';
  1132. }
  1133. if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
  1134. {
  1135. $discount=new DiscountAbsolute($db);
  1136. $discount->fetch($object->lines[$i]->fk_remise_except);
  1137. $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
  1138. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
  1139. }
  1140. elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
  1141. {
  1142. $discount=new DiscountAbsolute($db);
  1143. $discount->fetch($object->lines[$i]->fk_remise_except);
  1144. $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
  1145. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
  1146. // Add date of deposit
  1147. if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
  1148. }
  1149. if ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except)
  1150. {
  1151. $discount=new DiscountAbsolute($db);
  1152. $discount->fetch($object->lines[$i]->fk_remise_except);
  1153. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
  1154. }
  1155. elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except)
  1156. {
  1157. $discount=new DiscountAbsolute($db);
  1158. $discount->fetch($object->lines[$i]->fk_remise_except);
  1159. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
  1160. }
  1161. else
  1162. {
  1163. if ($idprod)
  1164. {
  1165. if (empty($hidedesc))
  1166. {
  1167. if (!empty($conf->global->MAIN_DOCUMENTS_DESCRIPTION_FIRST))
  1168. {
  1169. $libelleproduitservice=$desc."\n".$libelleproduitservice;
  1170. }
  1171. else
  1172. {
  1173. $libelleproduitservice.=$desc;
  1174. }
  1175. }
  1176. }
  1177. else
  1178. {
  1179. $libelleproduitservice.=$desc;
  1180. }
  1181. }
  1182. }
  1183. // We add ref of product (and supplier ref if defined)
  1184. $prefix_prodserv = "";
  1185. $ref_prodserv = "";
  1186. if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
  1187. {
  1188. if ($prodser->isService())
  1189. {
  1190. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  1191. }
  1192. else
  1193. {
  1194. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  1195. }
  1196. }
  1197. if (empty($hideref))
  1198. {
  1199. if ($issupplierline)
  1200. {
  1201. if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1)
  1202. $ref_prodserv = $ref_supplier;
  1203. elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2)
  1204. $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
  1205. else // Common case
  1206. {
  1207. $ref_prodserv = $prodser->ref; // Show local ref
  1208. if ($ref_supplier) $ref_prodserv.= ($prodser->ref?' (':'').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref?')':'');
  1209. }
  1210. }
  1211. else
  1212. {
  1213. $ref_prodserv = $prodser->ref; // Show local ref only
  1214. }
  1215. if (! empty($libelleproduitservice) && ! empty($ref_prodserv)) $ref_prodserv .= " - ";
  1216. }
  1217. $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
  1218. // Add an additional description for the category products
  1219. if (! empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && ! empty($conf->categorie->enabled))
  1220. {
  1221. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1222. $categstatic=new Categorie($db);
  1223. // recovering the list of all the categories linked to product
  1224. $tblcateg=$categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
  1225. foreach ($tblcateg as $cate)
  1226. {
  1227. // Adding the descriptions if they are filled
  1228. $desccateg=$cate->add_description;
  1229. if ($desccateg)
  1230. $libelleproduitservice.='__N__'.$desccateg;
  1231. }
  1232. }
  1233. if (! empty($object->lines[$i]->date_start) || ! empty($object->lines[$i]->date_end))
  1234. {
  1235. $format='day';
  1236. // Show duration if exists
  1237. if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
  1238. {
  1239. $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)).')';
  1240. }
  1241. if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
  1242. {
  1243. $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
  1244. }
  1245. if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
  1246. {
  1247. $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
  1248. }
  1249. //print '>'.$outputlangs->charset_output.','.$period;
  1250. $libelleproduitservice.="__N__".$period;
  1251. //print $libelleproduitservice;
  1252. }
  1253. if ($dbatch)
  1254. {
  1255. $format='day';
  1256. foreach ($dbatch as $detail)
  1257. {
  1258. $dte=array();
  1259. if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
  1260. if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
  1261. if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
  1262. $dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->qty);
  1263. $libelleproduitservice.= "__N__ ".implode(" - ", $dte);
  1264. }
  1265. }
  1266. // Now we convert \n into br
  1267. if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice);
  1268. else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice);
  1269. $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
  1270. return $libelleproduitservice;
  1271. }
  1272. /**
  1273. * Return line num
  1274. *
  1275. * @param Object $object Object
  1276. * @param int $i Current line number
  1277. * @param Translate $outputlangs Object langs for output
  1278. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1279. * @return string
  1280. */
  1281. function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0)
  1282. {
  1283. global $hookmanager;
  1284. $reshook=0;
  1285. $result='';
  1286. //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) ) )
  1287. 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
  1288. {
  1289. $special_code = $object->lines[$i]->special_code;
  1290. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1291. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1292. $action='';
  1293. $reshook = $hookmanager->executeHooks('pdf_getlinenum',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1294. $result.=$hookmanager->resPrint;
  1295. }
  1296. if (empty($reshook))
  1297. {
  1298. $result.=dol_htmlentitiesbr($object->lines[$i]->num);
  1299. }
  1300. return $result;
  1301. }
  1302. /**
  1303. * Return line product ref
  1304. *
  1305. * @param Object $object Object
  1306. * @param int $i Current line number
  1307. * @param Translate $outputlangs Object langs for output
  1308. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1309. * @return string
  1310. */
  1311. function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0)
  1312. {
  1313. global $hookmanager;
  1314. $reshook=0;
  1315. $result='';
  1316. //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) ) )
  1317. 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
  1318. {
  1319. $special_code = $object->lines[$i]->special_code;
  1320. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1321. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1322. $action='';
  1323. $reshook = $hookmanager->executeHooks('pdf_getlineref',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1324. $result.=$hookmanager->resPrint;
  1325. }
  1326. if (empty($reshook))
  1327. {
  1328. $result.=dol_htmlentitiesbr($object->lines[$i]->product_ref);
  1329. }
  1330. return $result;
  1331. }
  1332. /**
  1333. * Return line ref_supplier
  1334. *
  1335. * @param Object $object Object
  1336. * @param int $i Current line number
  1337. * @param Translate $outputlangs Object langs for output
  1338. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1339. * @return string
  1340. */
  1341. function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0)
  1342. {
  1343. global $hookmanager;
  1344. $reshook=0;
  1345. $result='';
  1346. //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) ) )
  1347. 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
  1348. {
  1349. $special_code = $object->lines[$i]->special_code;
  1350. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1351. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1352. $action='';
  1353. $reshook = $hookmanager->executeHooks('pdf_getlineref_supplier',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1354. $result.=$hookmanager->resPrint;
  1355. }
  1356. if (empty($reshook))
  1357. {
  1358. $result.=dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
  1359. }
  1360. return $result;
  1361. }
  1362. /**
  1363. * Return line vat rate
  1364. *
  1365. * @param Object $object Object
  1366. * @param int $i Current line number
  1367. * @param Translate $outputlangs Object langs for output
  1368. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1369. * @return string
  1370. */
  1371. function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
  1372. {
  1373. global $conf, $hookmanager, $mysoc;
  1374. $result='';
  1375. $reshook=0;
  1376. //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) ) )
  1377. 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
  1378. {
  1379. $special_code = $object->lines[$i]->special_code;
  1380. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1381. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1382. $action='';
  1383. $reshook = $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1384. if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1385. }
  1386. if (empty($reshook))
  1387. {
  1388. if (empty($hidedetails) || $hidedetails > 1)
  1389. {
  1390. $tmpresult='';
  1391. $tmpresult.=vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
  1392. if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX))
  1393. {
  1394. if ($object->lines[$i]->total_localtax1 != 0)
  1395. {
  1396. if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
  1397. else $tmpresult='';
  1398. $tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx), 0);
  1399. }
  1400. }
  1401. if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX))
  1402. {
  1403. if ($object->lines[$i]->total_localtax2 != 0)
  1404. {
  1405. if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
  1406. else $tmpresult='';
  1407. $tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx), 0);
  1408. }
  1409. }
  1410. $tmpresult.= '%';
  1411. $result.=$tmpresult;
  1412. }
  1413. }
  1414. return $result;
  1415. }
  1416. /**
  1417. * Return line unit price excluding tax
  1418. *
  1419. * @param Object $object Object
  1420. * @param int $i Current line number
  1421. * @param Translate $outputlangs Object langs for output
  1422. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1423. * @return string
  1424. */
  1425. function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0)
  1426. {
  1427. global $conf, $hookmanager;
  1428. $sign=1;
  1429. if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  1430. $result='';
  1431. $reshook=0;
  1432. //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) ) )
  1433. 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
  1434. {
  1435. $special_code = $object->lines[$i]->special_code;
  1436. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1437. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1438. $action='';
  1439. $reshook = $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1440. if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1441. }
  1442. if (empty($reshook))
  1443. {
  1444. if (empty($hidedetails) || $hidedetails > 1)
  1445. {
  1446. $subprice = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
  1447. $result.=price($sign * $subprice, 0, $outputlangs);
  1448. }
  1449. }
  1450. return $result;
  1451. }
  1452. /**
  1453. * Return line unit price including tax
  1454. *
  1455. * @param Object $object Object
  1456. * @param int $i Current line number
  1457. * @param Translate $outputlangs Object langs for output
  1458. * @param int $hidedetails Hide value (0 = no, 1 = yes, 2 = just special lines)
  1459. * @return string
  1460. */
  1461. function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0)
  1462. {
  1463. global $hookmanager,$conf;
  1464. $sign=1;
  1465. if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  1466. $result='';
  1467. $reshook=0;
  1468. //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) ) )
  1469. 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
  1470. {
  1471. $special_code = $object->lines[$i]->special_code;
  1472. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1473. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1474. $action='';
  1475. $reshook = $hookmanager->executeHooks('pdf_getlineupwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1476. if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1477. }
  1478. if (empty($reshook))
  1479. {
  1480. if (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs);
  1481. }
  1482. return $result;
  1483. }
  1484. /**
  1485. * Return line quantity
  1486. *
  1487. * @param Object $object Object
  1488. * @param int $i Current line number
  1489. * @param Translate $outputlangs Object langs for output
  1490. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1491. * @return string
  1492. */
  1493. function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0)
  1494. {
  1495. global $hookmanager;
  1496. $result='';
  1497. $reshook=0;
  1498. //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) ) )
  1499. 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
  1500. {
  1501. $special_code = $object->lines[$i]->special_code;
  1502. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1503. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1504. $action='';
  1505. $reshook = $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1506. if(!empty($hookmanager->resPrint)) $result=$hookmanager->resPrint;
  1507. }
  1508. if (empty($reshook))
  1509. {
  1510. if ($object->lines[$i]->special_code == 3) return '';
  1511. if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty;
  1512. }
  1513. return $result;
  1514. }
  1515. /**
  1516. * Return line quantity asked
  1517. *
  1518. * @param Object $object Object
  1519. * @param int $i Current line number
  1520. * @param Translate $outputlangs Object langs for output
  1521. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1522. * @return string
  1523. */
  1524. function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0)
  1525. {
  1526. global $hookmanager;
  1527. $reshook=0;
  1528. $result='';
  1529. //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) ) )
  1530. 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
  1531. {
  1532. $special_code = $object->lines[$i]->special_code;
  1533. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1534. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1535. $action='';
  1536. $reshook = $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1537. if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1538. }
  1539. if (empty($reshook))
  1540. {
  1541. if ($object->lines[$i]->special_code == 3) return '';
  1542. if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_asked;
  1543. }
  1544. return $result;
  1545. }
  1546. /**
  1547. * Return line quantity shipped
  1548. *
  1549. * @param Object $object Object
  1550. * @param int $i Current line number
  1551. * @param Translate $outputlangs Object langs for output
  1552. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1553. * @return string
  1554. */
  1555. function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0)
  1556. {
  1557. global $hookmanager;
  1558. $reshook=0;
  1559. $result='';
  1560. //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) ) )
  1561. 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
  1562. {
  1563. $special_code = $object->lines[$i]->special_code;
  1564. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1565. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1566. $action='';
  1567. $reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1568. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1569. }
  1570. if (empty($reshook))
  1571. {
  1572. if ($object->lines[$i]->special_code == 3) return '';
  1573. if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_shipped;
  1574. }
  1575. return $result;
  1576. }
  1577. /**
  1578. * Return line keep to ship quantity
  1579. *
  1580. * @param Object $object Object
  1581. * @param int $i Current line number
  1582. * @param Translate $outputlangs Object langs for output
  1583. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1584. * @return string
  1585. */
  1586. function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
  1587. {
  1588. global $hookmanager;
  1589. $reshook=0;
  1590. $result='';
  1591. //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) ) )
  1592. 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
  1593. {
  1594. $special_code = $object->lines[$i]->special_code;
  1595. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1596. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1597. $action='';
  1598. $reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1599. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1600. }
  1601. if (empty($reshook))
  1602. {
  1603. if ($object->lines[$i]->special_code == 3) return '';
  1604. if (empty($hidedetails) || $hidedetails > 1) $result.=($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
  1605. }
  1606. return $result;
  1607. }
  1608. /**
  1609. * Return line unit
  1610. *
  1611. * @param Object $object Object
  1612. * @param int $i Current line number
  1613. * @param Translate $outputlangs Object langs for output
  1614. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1615. * @param HookManager $hookmanager Hook manager instance
  1616. * @return string Value for unit cell
  1617. */
  1618. function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false)
  1619. {
  1620. global $langs;
  1621. $reshook=0;
  1622. $result='';
  1623. //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) ) )
  1624. 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
  1625. {
  1626. $special_code = $object->lines[$i]->special_code;
  1627. if (!empty($object->lines[$i]->fk_parent_line)) {
  1628. $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1629. }
  1630. $parameters = array(
  1631. 'i' => $i,
  1632. 'outputlangs' => $outputlangs,
  1633. 'hidedetails' => $hidedetails,
  1634. 'special_code' => $special_code
  1635. );
  1636. $action = '';
  1637. $reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  1638. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1639. }
  1640. if (empty($reshook))
  1641. {
  1642. if ($object->lines[$i]->special_code == 3) return '';
  1643. if (empty($hidedetails) || $hidedetails > 1) $result.=$langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
  1644. }
  1645. return $result;
  1646. }
  1647. /**
  1648. * Return line remise percent
  1649. *
  1650. * @param Object $object Object
  1651. * @param int $i Current line number
  1652. * @param Translate $outputlangs Object langs for output
  1653. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1654. * @return string
  1655. */
  1656. function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
  1657. {
  1658. global $hookmanager;
  1659. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1660. $reshook=0;
  1661. $result='';
  1662. //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) ) )
  1663. 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
  1664. {
  1665. $special_code = $object->lines[$i]->special_code;
  1666. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1667. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1668. $action='';
  1669. $reshook = $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1670. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1671. }
  1672. if (empty($reshook))
  1673. {
  1674. if ($object->lines[$i]->special_code == 3) return '';
  1675. if (empty($hidedetails) || $hidedetails > 1) $result.=dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
  1676. }
  1677. return $result;
  1678. }
  1679. /**
  1680. * Return line percent
  1681. *
  1682. * @param Object $object Object
  1683. * @param int $i Current line number
  1684. * @param Translate $outputlangs Object langs for output
  1685. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1686. * @param HookManager $hookmanager Hook manager instance
  1687. * @return string
  1688. */
  1689. function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null)
  1690. {
  1691. if (empty($hookmanager)) global $hookmanager;
  1692. global $conf;
  1693. $reshook=0;
  1694. $result='';
  1695. //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) ) )
  1696. 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
  1697. {
  1698. $special_code = $object->lines[$i]->special_code;
  1699. if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1700. $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
  1701. $action = '';
  1702. $reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  1703. if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint;
  1704. }
  1705. if (empty($reshook))
  1706. {
  1707. if ($object->lines[$i]->special_code == 3) return '';
  1708. if (empty($hidedetails) || $hidedetails > 1)
  1709. {
  1710. if ($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF)
  1711. {
  1712. $prev_progress = 0;
  1713. if (method_exists($object, 'get_prev_progress'))
  1714. {
  1715. $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
  1716. }
  1717. $result = ($object->lines[$i]->situation_percent - $prev_progress) . '%';
  1718. }
  1719. else
  1720. $result = $object->lines[$i]->situation_percent . '%';
  1721. }
  1722. }
  1723. return $result;
  1724. }
  1725. /**
  1726. * Return line total excluding tax
  1727. *
  1728. * @param Object $object Object
  1729. * @param int $i Current line number
  1730. * @param Translate $outputlangs Object langs for output
  1731. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1732. * @return string Return total of line excl tax
  1733. */
  1734. function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0)
  1735. {
  1736. global $conf, $hookmanager;
  1737. $sign=1;
  1738. if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  1739. $reshook=0;
  1740. $result='';
  1741. //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) ) )
  1742. 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
  1743. {
  1744. $special_code = $object->lines[$i]->special_code;
  1745. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1746. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code, 'sign'=>$sign);
  1747. $action='';
  1748. $reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1749. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1750. }
  1751. if (empty($reshook))
  1752. {
  1753. if ($object->lines[$i]->special_code == 3)
  1754. {
  1755. return $outputlangs->transnoentities("Option");
  1756. }
  1757. if (empty($hidedetails) || $hidedetails > 1)
  1758. {
  1759. $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht);
  1760. if ($object->lines[$i]->situation_percent > 0)
  1761. {
  1762. $prev_progress = 0;
  1763. $progress = 1;
  1764. if (method_exists($object->lines[$i], 'get_prev_progress'))
  1765. {
  1766. $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
  1767. $progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
  1768. }
  1769. $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs);
  1770. }
  1771. else
  1772. $result.=price($sign * $total_ht, 0, $outputlangs);
  1773. }
  1774. }
  1775. return $result;
  1776. }
  1777. /**
  1778. * Return line total including tax
  1779. *
  1780. * @param Object $object Object
  1781. * @param int $i Current line number
  1782. * @param Translate $outputlangs Object langs for output
  1783. * @param int $hidedetails Hide value (0 = no, 1 = yes, 2 = just special lines)
  1784. * @return string Return total of line incl tax
  1785. */
  1786. function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
  1787. {
  1788. global $hookmanager,$conf;
  1789. $sign=1;
  1790. if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  1791. $reshook=0;
  1792. $result='';
  1793. //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) ) )
  1794. 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
  1795. {
  1796. $special_code = $object->lines[$i]->special_code;
  1797. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1798. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1799. $action='';
  1800. $reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1801. if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
  1802. }
  1803. if (empty($reshook))
  1804. {
  1805. if ($object->lines[$i]->special_code == 3)
  1806. {
  1807. $result.=$outputlangs->transnoentities("Option");
  1808. }
  1809. 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);
  1810. }
  1811. return $result;
  1812. }
  1813. /**
  1814. * Return total quantity of products and/or services
  1815. *
  1816. * @param Object $object Object
  1817. * @param string $type Type
  1818. * @param Translate $outputlangs Object langs for output
  1819. * @return integer
  1820. * @deprecated Not used by Dolibarr core, so will be removed.
  1821. */
  1822. function pdf_getTotalQty($object,$type,$outputlangs)
  1823. {
  1824. global $hookmanager;
  1825. $total=0;
  1826. $nblignes=count($object->lines);
  1827. // Loop on each lines
  1828. for ($i = 0 ; $i < $nblignes ; $i++)
  1829. {
  1830. if ($object->lines[$i]->special_code != 3)
  1831. {
  1832. if ($type=='all')
  1833. {
  1834. $total += $object->lines[$i]->qty;
  1835. }
  1836. 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)))
  1837. {
  1838. $special_code = $object->lines[$i]->special_code;
  1839. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1840. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1841. $action='';
  1842. $reshook = $hookmanager->executeHooks('pdf_getTotalQty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1843. return $hookmanager->resPrint;
  1844. }
  1845. else if ($type==0 && $object->lines[$i]->product_type == 0)
  1846. {
  1847. $total += $object->lines[$i]->qty;
  1848. }
  1849. else if ($type==1 && $object->lines[$i]->product_type == 1)
  1850. {
  1851. $total += $object->lines[$i]->qty;
  1852. }
  1853. }
  1854. }
  1855. return $total;
  1856. }
  1857. /**
  1858. * Return linked objects to use for document generation.
  1859. * 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
  1860. *
  1861. * @param object $object Object
  1862. * @param Translate $outputlangs Object lang for output
  1863. * @return array Linked objects
  1864. */
  1865. function pdf_getLinkedObjects($object,$outputlangs)
  1866. {
  1867. global $hookmanager;
  1868. $linkedobjects=array();
  1869. $object->fetchObjectLinked();
  1870. foreach($object->linkedObjects as $objecttype => $objects)
  1871. {
  1872. if ($objecttype == 'facture')
  1873. {
  1874. // 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.
  1875. }
  1876. elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal')
  1877. {
  1878. $outputlangs->load('propal');
  1879. foreach($objects as $elementobject)
  1880. {
  1881. $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
  1882. $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
  1883. $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
  1884. $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
  1885. }
  1886. }
  1887. else if ($objecttype == 'commande' || $objecttype == 'supplier_order')
  1888. {
  1889. $outputlangs->load('orders');
  1890. foreach($objects as $elementobject)
  1891. {
  1892. $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
  1893. $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '') . ($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
  1894. $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
  1895. $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
  1896. }
  1897. }
  1898. else if ($objecttype == 'contrat')
  1899. {
  1900. $outputlangs->load('contracts');
  1901. foreach($objects as $elementobject)
  1902. {
  1903. $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
  1904. $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
  1905. $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
  1906. $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat,'day','',$outputlangs);
  1907. }
  1908. }
  1909. else if ($objecttype == 'shipping')
  1910. {
  1911. $outputlangs->loadLangs(array("orders", "sendings"));
  1912. foreach($objects as $x => $elementobject)
  1913. {
  1914. $order=null;
  1915. // We concat this record info into fields xxx_value. title is overwrote.
  1916. 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
  1917. {
  1918. $elementobject->fetchObjectLinked();
  1919. if (! empty($elementobject->linkedObjects['commande'])) $order = reset($elementobject->linkedObjects['commande']);
  1920. }
  1921. if (! is_object($order))
  1922. {
  1923. $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
  1924. if (! empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'].=' / ';
  1925. $linkedobjects[$objecttype]['ref_value'].= $outputlangs->transnoentities($elementobject->ref);
  1926. //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
  1927. //if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
  1928. //$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
  1929. }
  1930. else
  1931. {
  1932. $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
  1933. if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' ('.$order->ref_client.')' : '');
  1934. $linkedobjects[$objecttype]['ref_value'].= ' / ' . $outputlangs->transnoentities($elementobject->ref);
  1935. //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
  1936. //if (empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs);
  1937. //$linkedobjects[$objecttype]['date_value'].= ($elementobject->date_delivery ? ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs) : '');
  1938. }
  1939. }
  1940. }
  1941. }
  1942. // For add external linked objects
  1943. if (is_object($hookmanager))
  1944. {
  1945. $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs);
  1946. $action='';
  1947. $hookmanager->executeHooks('pdf_getLinkedObjects',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1948. if (! empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray;
  1949. }
  1950. return $linkedobjects;
  1951. }
  1952. /**
  1953. * Return dimensions to use for images onto PDF checking that width and height are not higher than
  1954. * maximum (16x32 by default).
  1955. *
  1956. * @param string $realpath Full path to photo file to use
  1957. * @return array Height and width to use to output image (in pdf user unit, so mm)
  1958. */
  1959. function pdf_getSizeForImage($realpath)
  1960. {
  1961. global $conf;
  1962. $maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
  1963. $maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
  1964. include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  1965. $tmp=dol_getImageSize($realpath);
  1966. if ($tmp['height'])
  1967. {
  1968. $width=(int) round($maxheight*$tmp['width']/$tmp['height']); // I try to use maxheight
  1969. if ($width > $maxwidth) // Pb with maxheight, so i use maxwidth
  1970. {
  1971. $width=$maxwidth;
  1972. $height=(int) round($maxwidth*$tmp['height']/$tmp['width']);
  1973. }
  1974. else // No pb with maxheight
  1975. {
  1976. $height=$maxheight;
  1977. }
  1978. }
  1979. return array('width'=>$width,'height'=>$height);
  1980. }