pdf.lib.php 86 KB

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