pdf.lib.php 106 KB

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