pdf.lib.php 106 KB

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