pdf.lib.php 115 KB

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