pdf_eratosthene.modules.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. <?php
  2. /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  7. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. * or see https://www.gnu.org/
  25. */
  26. /**
  27. * \file htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php
  28. * \ingroup commande
  29. * \brief File of Class to generate PDF orders with template Eratosthène
  30. */
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  36. /**
  37. * Class to generate PDF orders with template Eratosthene
  38. */
  39. class pdf_eratosthene extends ModelePDFCommandes
  40. {
  41. /**
  42. * @var DoliDb Database handler
  43. */
  44. public $db;
  45. /**
  46. * @var int The environment ID when using a multicompany module
  47. */
  48. public $entity;
  49. /**
  50. * @var string model name
  51. */
  52. public $name;
  53. /**
  54. * @var string model description (short text)
  55. */
  56. public $description;
  57. /**
  58. * @var int Save the name of generated file as the main doc when generating a doc with this template
  59. */
  60. public $update_main_doc_field;
  61. /**
  62. * @var string document type
  63. */
  64. public $type;
  65. /**
  66. * @var array Minimum version of PHP required by module.
  67. * e.g.: PHP ≥ 5.6 = array(5, 6)
  68. */
  69. public $phpmin = array(5, 6);
  70. /**
  71. * Dolibarr version of the loaded document
  72. * @var string
  73. */
  74. public $version = 'dolibarr';
  75. /**
  76. * @var int page_largeur
  77. */
  78. public $page_largeur;
  79. /**
  80. * @var int page_hauteur
  81. */
  82. public $page_hauteur;
  83. /**
  84. * @var array format
  85. */
  86. public $format;
  87. /**
  88. * @var int marge_gauche
  89. */
  90. public $marge_gauche;
  91. /**
  92. * @var int marge_droite
  93. */
  94. public $marge_droite;
  95. /**
  96. * @var int marge_haute
  97. */
  98. public $marge_haute;
  99. /**
  100. * @var int marge_basse
  101. */
  102. public $marge_basse;
  103. /**
  104. * Issuer
  105. * @var Societe Object that emits
  106. */
  107. public $emetteur;
  108. /**
  109. * @var array of document table columns
  110. */
  111. public $cols;
  112. /**
  113. * Constructor
  114. *
  115. * @param DoliDB $db Database handler
  116. */
  117. public function __construct($db)
  118. {
  119. global $conf, $langs, $mysoc;
  120. // Translations
  121. $langs->loadLangs(array("main", "bills", "products"));
  122. $this->db = $db;
  123. $this->name = "eratosthene";
  124. $this->description = $langs->trans('PDFEratostheneDescription');
  125. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  126. // Dimension page
  127. $this->type = 'pdf';
  128. $formatarray = pdf_getFormat();
  129. $this->page_largeur = $formatarray['width'];
  130. $this->page_hauteur = $formatarray['height'];
  131. $this->format = array($this->page_largeur, $this->page_hauteur);
  132. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  133. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  134. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  135. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  136. $this->option_logo = 1; // Display logo
  137. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  138. $this->option_modereg = 1; // Display payment mode
  139. $this->option_condreg = 1; // Display payment terms
  140. $this->option_multilang = 1; // Available in several languages
  141. $this->option_escompte = 0; // Displays if there has been a discount
  142. $this->option_credit_note = 0; // Support credit notes
  143. $this->option_freetext = 1; // Support add of a personalised text
  144. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  145. $this->watermark = '';
  146. // Get source company
  147. $this->emetteur = $mysoc;
  148. if (empty($this->emetteur->country_code)) {
  149. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  150. }
  151. // Define position of columns
  152. $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
  153. $this->tabTitleHeight = 5; // default height
  154. // Use new system for position of columns, view $this->defineColumnField()
  155. $this->tva = array();
  156. $this->tva_array = array();
  157. $this->localtax1 = array();
  158. $this->localtax2 = array();
  159. $this->atleastoneratenotnull = 0;
  160. $this->atleastonediscount = 0;
  161. }
  162. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  163. /**
  164. * Function to build pdf onto disk
  165. *
  166. * @param Commande $object Object to generate
  167. * @param Translate $outputlangs Lang output object
  168. * @param string $srctemplatepath Full path of source filename for generator using a template file
  169. * @param int $hidedetails Do not show line details
  170. * @param int $hidedesc Do not show desc
  171. * @param int $hideref Do not show ref
  172. * @return int 1=OK, 0=KO
  173. */
  174. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  175. {
  176. // phpcs:enable
  177. global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
  178. if (!is_object($outputlangs)) {
  179. $outputlangs = $langs;
  180. }
  181. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  182. if (!empty($conf->global->MAIN_USE_FPDF)) {
  183. $outputlangs->charset_output = 'ISO-8859-1';
  184. }
  185. // Load translation files required by the page
  186. $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
  187. // Show Draft Watermark
  188. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK))) {
  189. $this->watermark = $conf->global->COMMANDE_DRAFT_WATERMARK;
  190. }
  191. global $outputlangsbis;
  192. $outputlangsbis = null;
  193. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  194. $outputlangsbis = new Translate('', $conf);
  195. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  196. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
  197. }
  198. $nblines = count($object->lines);
  199. $hidetop = 0;
  200. if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
  201. $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
  202. }
  203. // Loop on each lines to detect if there is at least one image to show
  204. $realpatharray = array();
  205. $this->atleastonephoto = false;
  206. if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) {
  207. $objphoto = new Product($this->db);
  208. for ($i = 0; $i < $nblines; $i++) {
  209. if (empty($object->lines[$i]->fk_product)) {
  210. continue;
  211. }
  212. $objphoto->fetch($object->lines[$i]->fk_product);
  213. //var_dump($objphoto->ref);exit;
  214. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
  215. $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
  216. $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
  217. } else {
  218. $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
  219. $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
  220. }
  221. $arephoto = false;
  222. foreach ($pdir as $midir) {
  223. if (!$arephoto) {
  224. if ($conf->entity != $objphoto->entity) {
  225. $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
  226. } else {
  227. $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
  228. }
  229. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  230. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  231. if ($obj['photo_vignette']) {
  232. $filename = $obj['photo_vignette'];
  233. } else {
  234. $filename = $obj['photo'];
  235. }
  236. } else {
  237. $filename = $obj['photo'];
  238. }
  239. $realpath = $dir.$filename;
  240. $arephoto = true;
  241. $this->atleastonephoto = true;
  242. }
  243. }
  244. }
  245. if ($realpath && $arephoto) {
  246. $realpatharray[$i] = $realpath;
  247. }
  248. }
  249. }
  250. if ($conf->commande->multidir_output[$conf->entity]) {
  251. $object->fetch_thirdparty();
  252. $deja_regle = 0;
  253. // Definition of $dir and $file
  254. if ($object->specimen) {
  255. $dir = $conf->commande->multidir_output[$conf->entity];
  256. $file = $dir."/SPECIMEN.pdf";
  257. } else {
  258. $objectref = dol_sanitizeFileName($object->ref);
  259. $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref;
  260. $file = $dir."/".$objectref.".pdf";
  261. }
  262. if (!file_exists($dir)) {
  263. if (dol_mkdir($dir) < 0) {
  264. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  265. return 0;
  266. }
  267. }
  268. if (file_exists($dir)) {
  269. // Add pdfgeneration hook
  270. if (!is_object($hookmanager)) {
  271. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  272. $hookmanager = new HookManager($this->db);
  273. }
  274. $hookmanager->initHooks(array('pdfgeneration'));
  275. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  276. global $action;
  277. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  278. // Set nblines with the new command lines content after hook
  279. $nblines = count($object->lines);
  280. // Create pdf instance
  281. $pdf = pdf_getInstance($this->format);
  282. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  283. $pdf->SetAutoPageBreak(1, 0);
  284. $heightforinfotot = 40; // Height reserved to output the info and total part
  285. $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
  286. $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
  287. if (class_exists('TCPDF')) {
  288. $pdf->setPrintHeader(false);
  289. $pdf->setPrintFooter(false);
  290. }
  291. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  292. // Set path to the background PDF File
  293. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  294. $logodir = $conf->mycompany->dir_output;
  295. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  296. $logodir = $conf->mycompany->multidir_output[$object->entity];
  297. }
  298. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  299. $tplidx = $pdf->importPage(1);
  300. }
  301. $pdf->Open();
  302. $pagenb = 0;
  303. $pdf->SetDrawColor(128, 128, 128);
  304. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  305. $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
  306. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  307. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  308. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  309. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  310. $pdf->SetCompression(false);
  311. }
  312. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  313. // Set $this->atleastonediscount if you have at least one discount
  314. for ($i = 0; $i < $nblines; $i++) {
  315. if ($object->lines[$i]->remise_percent) {
  316. $this->atleastonediscount++;
  317. }
  318. }
  319. // New page
  320. $pdf->AddPage();
  321. if (!empty($tplidx)) {
  322. $pdf->useTemplate($tplidx);
  323. }
  324. $pagenb++;
  325. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
  326. $pdf->SetFont('', '', $default_font_size - 1);
  327. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  328. $pdf->SetTextColor(0, 0, 0);
  329. $tab_top = 90 + $top_shift;
  330. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  331. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  332. // Incoterm
  333. $height_incoterms = 0;
  334. if (!empty($conf->incoterm->enabled)) {
  335. $desc_incoterms = $object->getIncotermsForPDF();
  336. if ($desc_incoterms) {
  337. $tab_top -= 2;
  338. $pdf->SetFont('', '', $default_font_size - 1);
  339. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  340. $nexY = max($pdf->GetY(), $nexY);
  341. $height_incoterms = $nexY - $tab_top;
  342. // Rect takes a length in 3rd parameter
  343. $pdf->SetDrawColor(192, 192, 192);
  344. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  345. $tab_top = $nexY + 6;
  346. }
  347. }
  348. // Displays notes
  349. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  350. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  351. // Get first sale rep
  352. if (is_object($object->thirdparty)) {
  353. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  354. $salerepobj = new User($this->db);
  355. $salerepobj->fetch($salereparray[0]['id']);
  356. if (!empty($salerepobj->signature)) {
  357. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  358. }
  359. }
  360. }
  361. // Extrafields in note
  362. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  363. if (!empty($extranote)) {
  364. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  365. }
  366. $pagenb = $pdf->getPage();
  367. if ($notetoshow) {
  368. $tab_top -= 2;
  369. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  370. $pageposbeforenote = $pagenb;
  371. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  372. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  373. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  374. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  375. $pdf->startTransaction();
  376. $pdf->SetFont('', '', $default_font_size - 1);
  377. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  378. // Description
  379. $pageposafternote = $pdf->getPage();
  380. $posyafter = $pdf->GetY();
  381. if ($pageposafternote > $pageposbeforenote) {
  382. $pdf->rollbackTransaction(true);
  383. // prepare pages to receive notes
  384. while ($pagenb < $pageposafternote) {
  385. $pdf->AddPage();
  386. $pagenb++;
  387. if (!empty($tplidx)) {
  388. $pdf->useTemplate($tplidx);
  389. }
  390. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  391. $this->_pagehead($pdf, $object, 0, $outputlangs);
  392. }
  393. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  394. $pdf->setTopMargin($tab_top_newpage);
  395. // The only function to edit the bottom margin of current page to set it.
  396. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  397. }
  398. // back to start
  399. $pdf->setPage($pageposbeforenote);
  400. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  401. $pdf->SetFont('', '', $default_font_size - 1);
  402. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  403. $pageposafternote = $pdf->getPage();
  404. $posyafter = $pdf->GetY();
  405. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  406. $pdf->AddPage('', '', true);
  407. $pagenb++;
  408. $pageposafternote++;
  409. $pdf->setPage($pageposafternote);
  410. $pdf->setTopMargin($tab_top_newpage);
  411. // The only function to edit the bottom margin of current page to set it.
  412. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  413. //$posyafter = $tab_top_newpage;
  414. }
  415. // apply note frame to previous pages
  416. $i = $pageposbeforenote;
  417. while ($i < $pageposafternote) {
  418. $pdf->setPage($i);
  419. $pdf->SetDrawColor(128, 128, 128);
  420. // Draw note frame
  421. if ($i > $pageposbeforenote) {
  422. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  423. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  424. } else {
  425. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  426. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  427. }
  428. // Add footer
  429. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  430. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  431. $i++;
  432. }
  433. // apply note frame to last page
  434. $pdf->setPage($pageposafternote);
  435. if (!empty($tplidx)) {
  436. $pdf->useTemplate($tplidx);
  437. }
  438. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  439. $this->_pagehead($pdf, $object, 0, $outputlangs);
  440. }
  441. $height_note = $posyafter - $tab_top_newpage;
  442. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  443. } else {
  444. // No pagebreak
  445. $pdf->commitTransaction();
  446. $posyafter = $pdf->GetY();
  447. $height_note = $posyafter - $tab_top;
  448. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  449. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  450. // not enough space, need to add page
  451. $pdf->AddPage('', '', true);
  452. $pagenb++;
  453. $pageposafternote++;
  454. $pdf->setPage($pageposafternote);
  455. if (!empty($tplidx)) {
  456. $pdf->useTemplate($tplidx);
  457. }
  458. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  459. $this->_pagehead($pdf, $object, 0, $outputlangs);
  460. }
  461. $posyafter = $tab_top_newpage;
  462. }
  463. }
  464. $tab_height = $tab_height - $height_note;
  465. $tab_top = $posyafter + 6;
  466. } else {
  467. $height_note = 0;
  468. }
  469. // Use new auto column system
  470. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  471. // Table simulation to know the height of the title line
  472. $pdf->startTransaction();
  473. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  474. $pdf->rollbackTransaction(true);
  475. $nexY = $tab_top + $this->tabTitleHeight;
  476. // Loop on each lines
  477. $pageposbeforeprintlines = $pdf->getPage();
  478. $pagenb = $pageposbeforeprintlines;
  479. for ($i = 0; $i < $nblines; $i++) {
  480. $curY = $nexY;
  481. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  482. $pdf->SetTextColor(0, 0, 0);
  483. // Define size of image if we need it
  484. $imglinesize = array();
  485. if (!empty($realpatharray[$i])) {
  486. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  487. }
  488. $pdf->setTopMargin($tab_top_newpage);
  489. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  490. $pageposbefore = $pdf->getPage();
  491. $showpricebeforepagebreak = 1;
  492. $posYAfterImage = 0;
  493. $posYAfterDescription = 0;
  494. if ($this->getColumnStatus('photo')) {
  495. // We start with Photo of product line
  496. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
  497. $pdf->AddPage('', '', true);
  498. if (!empty($tplidx)) {
  499. $pdf->useTemplate($tplidx);
  500. }
  501. $pdf->setPage($pageposbefore + 1);
  502. $curY = $tab_top_newpage;
  503. // Allows data in the first page if description is long enough to break in multiples pages
  504. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  505. $showpricebeforepagebreak = 1;
  506. } else {
  507. $showpricebeforepagebreak = 0;
  508. }
  509. }
  510. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
  511. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  512. // $pdf->Image does not increase value return by getY, so we save it manually
  513. $posYAfterImage = $curY + $imglinesize['height'];
  514. }
  515. }
  516. // Description of product line
  517. if ($this->getColumnStatus('desc')) {
  518. $pdf->startTransaction();
  519. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  520. $pageposafter = $pdf->getPage();
  521. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  522. $pdf->rollbackTransaction(true);
  523. $pageposafter = $pageposbefore;
  524. //print $pageposafter.'-'.$pageposbefore;exit;
  525. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  526. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  527. $pageposafter = $pdf->getPage();
  528. $posyafter = $pdf->GetY();
  529. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  530. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  531. $pdf->AddPage('', '', true);
  532. if (!empty($tplidx)) {
  533. $pdf->useTemplate($tplidx);
  534. }
  535. //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  536. $pdf->setPage($pageposafter + 1);
  537. }
  538. } else {
  539. // We found a page break
  540. // Allows data in the first page if description is long enough to break in multiples pages
  541. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  542. $showpricebeforepagebreak = 1;
  543. } else {
  544. $showpricebeforepagebreak = 0;
  545. }
  546. }
  547. } else // No pagebreak
  548. {
  549. $pdf->commitTransaction();
  550. }
  551. $posYAfterDescription = $pdf->GetY();
  552. }
  553. $nexY = max($pdf->GetY(), $posYAfterImage);
  554. $pageposafter = $pdf->getPage();
  555. $pdf->setPage($pageposbefore);
  556. $pdf->setTopMargin($this->marge_haute);
  557. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  558. // We suppose that a too long description or photo were moved completely on next page
  559. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  560. $pdf->setPage($pageposafter);
  561. $curY = $tab_top_newpage;
  562. }
  563. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  564. // VAT Rate
  565. if ($this->getColumnStatus('vat')) {
  566. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  567. $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
  568. $nexY = max($pdf->GetY(), $nexY);
  569. }
  570. // Unit price before discount
  571. if ($this->getColumnStatus('subprice')) {
  572. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  573. $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
  574. $nexY = max($pdf->GetY(), $nexY);
  575. }
  576. // Quantity
  577. // Enough for 6 chars
  578. if ($this->getColumnStatus('qty')) {
  579. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  580. $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
  581. $nexY = max($pdf->GetY(), $nexY);
  582. }
  583. // Unit
  584. if ($this->getColumnStatus('unit')) {
  585. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  586. $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
  587. $nexY = max($pdf->GetY(), $nexY);
  588. }
  589. // Discount on line
  590. if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
  591. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  592. $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
  593. $nexY = max($pdf->GetY(), $nexY);
  594. }
  595. // Total excl tax line (HT)
  596. if ($this->getColumnStatus('totalexcltax')) {
  597. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  598. $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
  599. $nexY = max($pdf->GetY(), $nexY);
  600. }
  601. // Total with tax line (TTC)
  602. if ($this->getColumnStatus('totalincltax')) {
  603. $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
  604. $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
  605. $nexY = max($pdf->GetY(), $nexY);
  606. }
  607. // Extrafields
  608. if (!empty($object->lines[$i]->array_options)) {
  609. foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
  610. if ($this->getColumnStatus($extrafieldColKey)) {
  611. $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
  612. $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
  613. $nexY = max($pdf->GetY(), $nexY);
  614. }
  615. }
  616. }
  617. $parameters = array(
  618. 'object' => $object,
  619. 'i' => $i,
  620. 'pdf' =>& $pdf,
  621. 'curY' =>& $curY,
  622. 'nexY' =>& $nexY,
  623. 'outputlangs' => $outputlangs,
  624. 'hidedetails' => $hidedetails
  625. );
  626. $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
  627. // Collection of totals by value of vat in $this->tva["rate"] = total_tva
  628. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  629. $tvaligne = $object->lines[$i]->multicurrency_total_tva;
  630. } else {
  631. $tvaligne = $object->lines[$i]->total_tva;
  632. }
  633. $localtax1ligne = $object->lines[$i]->total_localtax1;
  634. $localtax2ligne = $object->lines[$i]->total_localtax2;
  635. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  636. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  637. $localtax1_type = $object->lines[$i]->localtax1_type;
  638. $localtax2_type = $object->lines[$i]->localtax2_type;
  639. if ($object->remise_percent) {
  640. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  641. }
  642. if ($object->remise_percent) {
  643. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  644. }
  645. if ($object->remise_percent) {
  646. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  647. }
  648. $vatrate = (string) $object->lines[$i]->tva_tx;
  649. // Retrieve type from database for backward compatibility with old records
  650. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  651. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  652. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  653. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  654. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  655. }
  656. // retrieve global local tax
  657. if ($localtax1_type && $localtax1ligne != 0) {
  658. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  659. }
  660. if ($localtax2_type && $localtax2ligne != 0) {
  661. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  662. }
  663. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  664. $vatrate .= '*';
  665. }
  666. // Fill $this->tva and $this->tva_array
  667. if (!isset($this->tva[$vatrate])) {
  668. $this->tva[$vatrate] = 0;
  669. }
  670. $this->tva[$vatrate] += $tvaligne;
  671. $vatcode = $object->lines[$i]->vat_src_code;
  672. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  673. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  674. }
  675. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  676. // Add line
  677. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  678. $pdf->setPage($pageposafter);
  679. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  680. //$pdf->SetDrawColor(190,190,200);
  681. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
  682. $pdf->SetLineStyle(array('dash'=>0));
  683. }
  684. // Detect if some page were added automatically and output _tableau for past pages
  685. while ($pagenb < $pageposafter) {
  686. $pdf->setPage($pagenb);
  687. if ($pagenb == $pageposbeforeprintlines) {
  688. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
  689. } else {
  690. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  691. }
  692. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  693. $pagenb++;
  694. $pdf->setPage($pagenb);
  695. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  696. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  697. $this->_pagehead($pdf, $object, 0, $outputlangs);
  698. }
  699. }
  700. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  701. if ($pagenb == $pageposafter) {
  702. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
  703. } else {
  704. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  705. }
  706. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  707. // New page
  708. $pdf->AddPage();
  709. if (!empty($tplidx)) {
  710. $pdf->useTemplate($tplidx);
  711. }
  712. $pagenb++;
  713. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  714. $this->_pagehead($pdf, $object, 0, $outputlangs);
  715. }
  716. }
  717. }
  718. // Show square
  719. if ($pagenb == $pageposbeforeprintlines) {
  720. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
  721. } else {
  722. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  723. }
  724. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  725. // Display infos area
  726. $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
  727. // Display total zone
  728. $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  729. // Affiche zone versements
  730. /*
  731. if ($deja_regle)
  732. {
  733. $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
  734. }
  735. */
  736. // Pied de page
  737. $this->_pagefoot($pdf, $object, $outputlangs);
  738. if (method_exists($pdf, 'AliasNbPages')) {
  739. $pdf->AliasNbPages();
  740. }
  741. $pdf->Close();
  742. $pdf->Output($file, 'F');
  743. // Add pdfgeneration hook
  744. $hookmanager->initHooks(array('pdfgeneration'));
  745. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  746. global $action;
  747. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  748. if ($reshook < 0) {
  749. $this->error = $hookmanager->error;
  750. $this->errors = $hookmanager->errors;
  751. }
  752. if (!empty($conf->global->MAIN_UMASK)) {
  753. @chmod($file, octdec($conf->global->MAIN_UMASK));
  754. }
  755. $this->result = array('fullpath'=>$file);
  756. return 1; // No error
  757. } else {
  758. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  759. return 0;
  760. }
  761. } else {
  762. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
  763. return 0;
  764. }
  765. }
  766. /**
  767. * Show payments table
  768. *
  769. * @param TCPDF $pdf Object PDF
  770. * @param Commande $object Object order
  771. * @param int $posy Position y in PDF
  772. * @param Translate $outputlangs Object langs for output
  773. * @return int <0 if KO, >0 if OK
  774. */
  775. protected function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
  776. {
  777. }
  778. /**
  779. * Show miscellaneous information (payment mode, payment term, ...)
  780. *
  781. * @param TCPDF $pdf Object PDF
  782. * @param Commande $object Object to show
  783. * @param int $posy Y
  784. * @param Translate $outputlangs Langs object
  785. * @return int Pos y
  786. */
  787. protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
  788. {
  789. global $conf, $mysoc;
  790. $default_font_size = pdf_getPDFFontSize($outputlangs);
  791. $pdf->SetFont('', '', $default_font_size - 1);
  792. // If France, show VAT mention if not applicable
  793. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  794. $pdf->SetFont('', 'B', $default_font_size - 2);
  795. $pdf->SetXY($this->marge_gauche, $posy);
  796. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  797. $posy = $pdf->GetY() + 4;
  798. }
  799. $posxval = 52;
  800. // Show payments conditions
  801. if ($object->cond_reglement_code || $object->cond_reglement) {
  802. $pdf->SetFont('', 'B', $default_font_size - 2);
  803. $pdf->SetXY($this->marge_gauche, $posy);
  804. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  805. $pdf->MultiCell(43, 4, $titre, 0, 'L');
  806. $pdf->SetFont('', '', $default_font_size - 2);
  807. $pdf->SetXY($posxval, $posy);
  808. $lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
  809. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  810. if ($object->deposit_percent > 0) {
  811. $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
  812. }
  813. $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
  814. $posy = $pdf->GetY() + 3;
  815. }
  816. // Check a payment mode is defined
  817. /* Not used with orders
  818. if (empty($object->mode_reglement_code)
  819. && ! $conf->global->FACTURE_CHQ_NUMBER
  820. && ! $conf->global->FACTURE_RIB_NUMBER)
  821. {
  822. $pdf->SetXY($this->marge_gauche, $posy);
  823. $pdf->SetTextColor(200,0,0);
  824. $pdf->SetFont('','B', $default_font_size - 2);
  825. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  826. $pdf->SetTextColor(0,0,0);
  827. $posy=$pdf->GetY()+1;
  828. }
  829. */
  830. /* TODO
  831. else if (! empty($object->availability_code))
  832. {
  833. $pdf->SetXY($this->marge_gauche, $posy);
  834. $pdf->SetTextColor(200,0,0);
  835. $pdf->SetFont('','B', $default_font_size - 2);
  836. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
  837. $pdf->SetTextColor(0,0,0);
  838. $posy=$pdf->GetY()+1;
  839. }*/
  840. // Show planed date of delivery
  841. if (!empty($object->delivery_date)) {
  842. $outputlangs->load("sendings");
  843. $pdf->SetFont('', 'B', $default_font_size - 2);
  844. $pdf->SetXY($this->marge_gauche, $posy);
  845. $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
  846. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  847. $pdf->SetFont('', '', $default_font_size - 2);
  848. $pdf->SetXY($posxval, $posy);
  849. $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
  850. $pdf->MultiCell(80, 4, $dlp, 0, 'L');
  851. $posy = $pdf->GetY() + 1;
  852. } elseif ($object->availability_code || $object->availability) { // Show availability conditions
  853. $pdf->SetFont('', 'B', $default_font_size - 2);
  854. $pdf->SetXY($this->marge_gauche, $posy);
  855. $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
  856. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  857. $pdf->SetTextColor(0, 0, 0);
  858. $pdf->SetFont('', '', $default_font_size - 2);
  859. $pdf->SetXY($posxval, $posy);
  860. $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
  861. $lib_availability = str_replace('\n', "\n", $lib_availability);
  862. $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
  863. $posy = $pdf->GetY() + 1;
  864. }
  865. // Show payment mode
  866. if ($object->mode_reglement_code
  867. && $object->mode_reglement_code != 'CHQ'
  868. && $object->mode_reglement_code != 'VIR') {
  869. $pdf->SetFont('', 'B', $default_font_size - 2);
  870. $pdf->SetXY($this->marge_gauche, $posy);
  871. $titre = $outputlangs->transnoentities("PaymentMode").':';
  872. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  873. $pdf->SetFont('', '', $default_font_size - 2);
  874. $pdf->SetXY($posxval, $posy);
  875. $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
  876. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  877. $posy = $pdf->GetY() + 2;
  878. }
  879. // Show payment mode CHQ
  880. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  881. // Si mode reglement non force ou si force a CHQ
  882. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  883. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  884. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  885. $account = new Account($this->db);
  886. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  887. $pdf->SetXY($this->marge_gauche, $posy);
  888. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  889. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  890. $posy = $pdf->GetY() + 1;
  891. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  892. $pdf->SetXY($this->marge_gauche, $posy);
  893. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  894. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  895. $posy = $pdf->GetY() + 2;
  896. }
  897. }
  898. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  899. $pdf->SetXY($this->marge_gauche, $posy);
  900. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  901. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  902. $posy = $pdf->GetY() + 1;
  903. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  904. $pdf->SetXY($this->marge_gauche, $posy);
  905. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  906. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  907. $posy = $pdf->GetY() + 2;
  908. }
  909. }
  910. }
  911. }
  912. // If payment mode not forced or forced to VIR, show payment with BAN
  913. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  914. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  915. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  916. if ($object->fk_bank > 0) {
  917. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  918. }
  919. $account = new Account($this->db);
  920. $account->fetch($bankid);
  921. $curx = $this->marge_gauche;
  922. $cury = $posy;
  923. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  924. $posy += 2;
  925. }
  926. }
  927. return $posy;
  928. }
  929. /**
  930. * Show total to pay
  931. *
  932. * @param TCPDF $pdf Object PDF
  933. * @param Commande $object Object to show
  934. * @param int $deja_regle Montant deja regle
  935. * @param int $posy Position depart
  936. * @param Translate $outputlangs Objet langs
  937. * @param Translate $outputlangsbis Object lang for output bis
  938. * @return int Position pour suite
  939. */
  940. protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
  941. {
  942. global $conf, $mysoc, $hookmanager;
  943. $default_font_size = pdf_getPDFFontSize($outputlangs);
  944. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  945. $outputlangsbis = new Translate('', $conf);
  946. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  947. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  948. $default_font_size--;
  949. }
  950. $tab2_top = $posy;
  951. $tab2_hl = 4;
  952. $pdf->SetFont('', '', $default_font_size - 1);
  953. // Total table
  954. $col1x = 120;
  955. $col2x = 170;
  956. if ($this->page_largeur < 210) { // To work with US executive format
  957. $col2x -= 20;
  958. }
  959. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  960. $useborder = 0;
  961. $index = 0;
  962. // Total HT
  963. $pdf->SetFillColor(255, 255, 255);
  964. $pdf->SetXY($col1x, $tab2_top + 0);
  965. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
  966. $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  967. $pdf->SetXY($col2x, $tab2_top + 0);
  968. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
  969. // Show VAT by rates and total
  970. $pdf->SetFillColor(248, 248, 248);
  971. $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  972. $this->atleastoneratenotnull = 0;
  973. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  974. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  975. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  976. // Nothing to do
  977. } else {
  978. //Local tax 1 before VAT
  979. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  980. //{
  981. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  982. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  983. continue;
  984. }
  985. foreach ($localtax_rate as $tvakey => $tvaval) {
  986. if ($tvakey != 0) { // On affiche pas taux 0
  987. //$this->atleastoneratenotnull++;
  988. $index++;
  989. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  990. $tvacompl = '';
  991. if (preg_match('/\*/', $tvakey)) {
  992. $tvakey = str_replace('*', '', $tvakey);
  993. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  994. }
  995. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  996. $totalvat .= ' ';
  997. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  998. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  999. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1000. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1001. }
  1002. }
  1003. }
  1004. //}
  1005. //Local tax 2 before VAT
  1006. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1007. //{
  1008. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1009. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1010. continue;
  1011. }
  1012. foreach ($localtax_rate as $tvakey => $tvaval) {
  1013. if ($tvakey != 0) { // On affiche pas taux 0
  1014. //$this->atleastoneratenotnull++;
  1015. $index++;
  1016. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1017. $tvacompl = '';
  1018. if (preg_match('/\*/', $tvakey)) {
  1019. $tvakey = str_replace('*', '', $tvakey);
  1020. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1021. }
  1022. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1023. $totalvat .= ' ';
  1024. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1025. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1026. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1027. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1028. }
  1029. }
  1030. }
  1031. //}
  1032. // VAT
  1033. foreach ($this->tva_array as $tvakey => $tvaval) {
  1034. if ($tvakey != 0) { // On affiche pas taux 0
  1035. $this->atleastoneratenotnull++;
  1036. $index++;
  1037. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1038. $tvacompl = '';
  1039. if (preg_match('/\*/', $tvakey)) {
  1040. $tvakey = str_replace('*', '', $tvakey);
  1041. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1042. }
  1043. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1044. $totalvat .= ' ';
  1045. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  1046. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  1047. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  1048. $totalvat .= ($tvaval['vatcode'] ? $tvaval['vatcode'] : vatrate($tvaval['vatrate'], 1)).$tvacompl;
  1049. } else {
  1050. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  1051. }
  1052. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1053. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1054. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  1055. }
  1056. }
  1057. //Local tax 1 after VAT
  1058. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1059. //{
  1060. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1061. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1062. continue;
  1063. }
  1064. foreach ($localtax_rate as $tvakey => $tvaval) {
  1065. if ($tvakey != 0) { // On affiche pas taux 0
  1066. //$this->atleastoneratenotnull++;
  1067. $index++;
  1068. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1069. $tvacompl = '';
  1070. if (preg_match('/\*/', $tvakey)) {
  1071. $tvakey = str_replace('*', '', $tvakey);
  1072. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1073. }
  1074. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1075. $totalvat .= ' ';
  1076. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1077. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1078. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1079. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1080. }
  1081. }
  1082. }
  1083. //}
  1084. //Local tax 2 after VAT
  1085. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1086. //{
  1087. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1088. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1089. continue;
  1090. }
  1091. foreach ($localtax_rate as $tvakey => $tvaval) {
  1092. // retrieve global local tax
  1093. if ($tvakey != 0) { // On affiche pas taux 0
  1094. //$this->atleastoneratenotnull++;
  1095. $index++;
  1096. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1097. $tvacompl = '';
  1098. if (preg_match('/\*/', $tvakey)) {
  1099. $tvakey = str_replace('*', '', $tvakey);
  1100. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1101. }
  1102. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1103. $totalvat .= ' ';
  1104. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1105. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1106. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1107. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1108. }
  1109. }
  1110. }
  1111. //}
  1112. // Total TTC
  1113. $index++;
  1114. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1115. $pdf->SetTextColor(0, 0, 60);
  1116. $pdf->SetFillColor(224, 224, 224);
  1117. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
  1118. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1119. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1120. }
  1121. }
  1122. $pdf->SetTextColor(0, 0, 0);
  1123. $creditnoteamount = 0;
  1124. $depositsamount = 0;
  1125. //$creditnoteamount=$object->getSumCreditNotesUsed();
  1126. //$depositsamount=$object->getSumDepositsUsed();
  1127. //print "x".$creditnoteamount."-".$depositsamount;exit;
  1128. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  1129. if (!empty($object->paye)) {
  1130. $resteapayer = 0;
  1131. }
  1132. if ($deja_regle > 0) {
  1133. // Already paid + Deposits
  1134. $index++;
  1135. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1136. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
  1137. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1138. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
  1139. $index++;
  1140. $pdf->SetTextColor(0, 0, 60);
  1141. $pdf->SetFillColor(224, 224, 224);
  1142. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1143. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
  1144. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1145. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1146. $pdf->SetFont('', '', $default_font_size - 1);
  1147. $pdf->SetTextColor(0, 0, 0);
  1148. }
  1149. $index++;
  1150. return ($tab2_top + ($tab2_hl * $index));
  1151. }
  1152. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1153. /**
  1154. * Show table for lines
  1155. *
  1156. * @param TCPDF $pdf Object PDF
  1157. * @param string $tab_top Top position of table
  1158. * @param string $tab_height Height of table (rectangle)
  1159. * @param int $nexY Y (not used)
  1160. * @param Translate $outputlangs Langs object
  1161. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1162. * @param int $hidebottom Hide bottom bar of array
  1163. * @param string $currency Currency code
  1164. * @param Translate $outputlangsbis Langs object bis
  1165. * @return void
  1166. */
  1167. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1168. {
  1169. global $conf;
  1170. // Force to disable hidetop and hidebottom
  1171. $hidebottom = 0;
  1172. if ($hidetop) {
  1173. $hidetop = -1;
  1174. }
  1175. $currency = !empty($currency) ? $currency : $conf->currency;
  1176. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1177. // Amount in (at tab_top - 1)
  1178. $pdf->SetTextColor(0, 0, 0);
  1179. $pdf->SetFont('', '', $default_font_size - 2);
  1180. if (empty($hidetop)) {
  1181. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1182. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1183. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1184. }
  1185. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1186. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1187. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1188. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1189. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  1190. }
  1191. }
  1192. $pdf->SetDrawColor(128, 128, 128);
  1193. $pdf->SetFont('', '', $default_font_size - 1);
  1194. // Output Rect
  1195. $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
  1196. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  1197. if (empty($hidetop)) {
  1198. $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
  1199. }
  1200. }
  1201. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1202. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1203. /**
  1204. * Show top header of page.
  1205. *
  1206. * @param TCPDF $pdf Object PDF
  1207. * @param Commande $object Object to show
  1208. * @param int $showaddress 0=no, 1=yes
  1209. * @param Translate $outputlangs Object lang for output
  1210. * @param Translate $outputlangsbis Object lang for output bis
  1211. * @param string $titlekey Translation key to show as title of document
  1212. * @return int Return topshift value
  1213. */
  1214. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
  1215. {
  1216. // phpcs:enable
  1217. global $conf, $langs, $hookmanager;
  1218. $ltrdirection = 'L';
  1219. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1220. // Load traductions files required by page
  1221. $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
  1222. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1223. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1224. $pdf->SetTextColor(0, 0, 60);
  1225. $pdf->SetFont('', 'B', $default_font_size + 3);
  1226. $w = 100;
  1227. $posy = $this->marge_haute;
  1228. $posx = $this->page_largeur - $this->marge_droite - $w;
  1229. $pdf->SetXY($this->marge_gauche, $posy);
  1230. // Logo
  1231. if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
  1232. if ($this->emetteur->logo) {
  1233. $logodir = $conf->mycompany->dir_output;
  1234. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1235. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1236. }
  1237. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  1238. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1239. } else {
  1240. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1241. }
  1242. if (is_readable($logo)) {
  1243. $height = pdf_getHeightForLogo($logo);
  1244. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1245. } else {
  1246. $pdf->SetTextColor(200, 0, 0);
  1247. $pdf->SetFont('', 'B', $default_font_size - 2);
  1248. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1249. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1250. }
  1251. } else {
  1252. $text = $this->emetteur->name;
  1253. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  1254. }
  1255. }
  1256. $pdf->SetFont('', 'B', $default_font_size + 3);
  1257. $pdf->SetXY($posx, $posy);
  1258. $pdf->SetTextColor(0, 0, 60);
  1259. $title = $outputlangs->transnoentities($titlekey);
  1260. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1261. $title .= ' - ';
  1262. $title .= $outputlangsbis->transnoentities($titlekey);
  1263. }
  1264. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1265. if ($object->statut == $object::STATUS_DRAFT) {
  1266. $pdf->SetTextColor(128, 0, 0);
  1267. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1268. }
  1269. $pdf->MultiCell($w, 3, $title, '', 'R');
  1270. $pdf->SetFont('', 'B', $default_font_size);
  1271. /*
  1272. $posy += 5;
  1273. $pdf->SetXY($posx, $posy);
  1274. $pdf->SetTextColor(0, 0, 60);
  1275. $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
  1276. if ($object->statut == $object::STATUS_DRAFT) {
  1277. $pdf->SetTextColor(128, 0, 0);
  1278. $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
  1279. }
  1280. $pdf->MultiCell($w, 4, $textref, '', 'R');
  1281. */
  1282. $posy += 3;
  1283. $pdf->SetFont('', '', $default_font_size - 2);
  1284. if ($object->ref_client) {
  1285. $posy += 4;
  1286. $pdf->SetXY($posx, $posy);
  1287. $pdf->SetTextColor(0, 0, 60);
  1288. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
  1289. }
  1290. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1291. $object->fetch_projet();
  1292. if (!empty($object->project->ref)) {
  1293. $posy += 3;
  1294. $pdf->SetXY($posx, $posy);
  1295. $pdf->SetTextColor(0, 0, 60);
  1296. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1297. }
  1298. }
  1299. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1300. $object->fetch_projet();
  1301. if (!empty($object->project->ref)) {
  1302. $outputlangs->load("projects");
  1303. $posy += 3;
  1304. $pdf->SetXY($posx, $posy);
  1305. $pdf->SetTextColor(0, 0, 60);
  1306. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1307. }
  1308. }
  1309. $posy += 4;
  1310. $pdf->SetXY($posx, $posy);
  1311. $pdf->SetTextColor(0, 0, 60);
  1312. $title = $outputlangs->transnoentities("OrderDate");
  1313. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1314. $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
  1315. }
  1316. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
  1317. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
  1318. $posy += 4;
  1319. $pdf->SetXY($posx, $posy);
  1320. $pdf->SetTextColor(0, 0, 60);
  1321. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1322. }
  1323. // Get contact
  1324. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1325. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1326. if (count($arrayidcontact) > 0) {
  1327. $usertmp = new User($this->db);
  1328. $usertmp->fetch($arrayidcontact[0]);
  1329. $posy += 4;
  1330. $pdf->SetXY($posx, $posy);
  1331. $pdf->SetTextColor(0, 0, 60);
  1332. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1333. }
  1334. }
  1335. $posy += 2;
  1336. $top_shift = 0;
  1337. // Show list of linked objects
  1338. $current_y = $pdf->getY();
  1339. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1340. if ($current_y < $pdf->getY()) {
  1341. $top_shift = $pdf->getY() - $current_y;
  1342. }
  1343. if ($showaddress) {
  1344. // Sender properties
  1345. $carac_emetteur = '';
  1346. // Add internal contact of proposal if defined
  1347. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1348. if (count($arrayidcontact) > 0) {
  1349. $object->fetch_user($arrayidcontact[0]);
  1350. $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
  1351. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  1352. }
  1353. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1354. // Show sender
  1355. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1356. $posy += $top_shift;
  1357. $posx = $this->marge_gauche;
  1358. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1359. $posx = $this->page_largeur - $this->marge_droite - 80;
  1360. }
  1361. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  1362. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1363. // Show sender frame
  1364. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1365. $pdf->SetTextColor(0, 0, 0);
  1366. $pdf->SetFont('', '', $default_font_size - 2);
  1367. $pdf->SetXY($posx, $posy - 5);
  1368. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1369. $pdf->SetXY($posx, $posy);
  1370. $pdf->SetFillColor(230, 230, 230);
  1371. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  1372. $pdf->SetTextColor(0, 0, 60);
  1373. }
  1374. // Show sender name
  1375. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1376. $pdf->SetXY($posx + 2, $posy + 3);
  1377. $pdf->SetFont('', 'B', $default_font_size);
  1378. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1379. $posy = $pdf->getY();
  1380. }
  1381. // Show sender information
  1382. $pdf->SetXY($posx + 2, $posy);
  1383. $pdf->SetFont('', '', $default_font_size - 1);
  1384. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
  1385. // If CUSTOMER contact defined, we use it
  1386. $usecontact = false;
  1387. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  1388. if (count($arrayidcontact) > 0) {
  1389. $usecontact = true;
  1390. $result = $object->fetch_contact($arrayidcontact[0]);
  1391. }
  1392. //Recipient name
  1393. if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  1394. $thirdparty = $object->contact;
  1395. } else {
  1396. $thirdparty = $object->thirdparty;
  1397. }
  1398. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1399. $mode = 'target';
  1400. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1401. // Show recipient
  1402. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1403. if ($this->page_largeur < 210) {
  1404. $widthrecbox = 84; // To work with US executive format
  1405. }
  1406. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1407. $posy += $top_shift;
  1408. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1409. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1410. $posx = $this->marge_gauche;
  1411. }
  1412. // Show recipient frame
  1413. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1414. $pdf->SetTextColor(0, 0, 0);
  1415. $pdf->SetFont('', '', $default_font_size - 2);
  1416. $pdf->SetXY($posx + 2, $posy - 5);
  1417. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1418. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1419. }
  1420. // Show recipient name
  1421. $pdf->SetXY($posx + 2, $posy + 3);
  1422. $pdf->SetFont('', 'B', $default_font_size);
  1423. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1424. $posy = $pdf->getY();
  1425. // Show recipient information
  1426. $pdf->SetFont('', '', $default_font_size - 1);
  1427. $pdf->SetXY($posx + 2, $posy);
  1428. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1429. }
  1430. $pdf->SetTextColor(0, 0, 0);
  1431. return $top_shift;
  1432. }
  1433. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1434. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1435. /**
  1436. * Show footer of page. Need this->emetteur object
  1437. *
  1438. * @param TCPDF $pdf PDF
  1439. * @param Commande $object Object to show
  1440. * @param Translate $outputlangs Object lang for output
  1441. * @param int $hidefreetext 1=Hide free text
  1442. * @return int Return height of bottom margin including footer text
  1443. */
  1444. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1445. {
  1446. // phpcs:enable
  1447. global $conf;
  1448. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1449. return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
  1450. }
  1451. /**
  1452. * Define Array Column Field
  1453. *
  1454. * @param Commande $object common object
  1455. * @param Translate $outputlangs langs
  1456. * @param int $hidedetails Do not show line details
  1457. * @param int $hidedesc Do not show desc
  1458. * @param int $hideref Do not show ref
  1459. * @return null
  1460. */
  1461. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1462. {
  1463. global $conf, $hookmanager;
  1464. // Default field style for content
  1465. $this->defaultContentsFieldsStyle = array(
  1466. 'align' => 'R', // R,C,L
  1467. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1468. );
  1469. // Default field style for content
  1470. $this->defaultTitlesFieldsStyle = array(
  1471. 'align' => 'C', // R,C,L
  1472. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1473. );
  1474. /*
  1475. * For exemple
  1476. $this->cols['theColKey'] = array(
  1477. 'rank' => $rank, // int : use for ordering columns
  1478. 'width' => 20, // the column width in mm
  1479. 'title' => array(
  1480. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1481. 'label' => ' ', // the final label : used fore final generated text
  1482. 'align' => 'L', // text alignement : R,C,L
  1483. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1484. ),
  1485. 'content' => array(
  1486. 'align' => 'L', // text alignement : R,C,L
  1487. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1488. ),
  1489. );
  1490. */
  1491. $rank = 0; // do not use negative rank
  1492. $this->cols['desc'] = array(
  1493. 'rank' => $rank,
  1494. 'width' => false, // only for desc
  1495. 'status' => true,
  1496. 'title' => array(
  1497. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1498. 'align' => 'L',
  1499. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1500. // 'label' => ' ', // the final label
  1501. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1502. ),
  1503. 'content' => array(
  1504. 'align' => 'L',
  1505. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1506. ),
  1507. );
  1508. // Image of product
  1509. $rank = $rank + 10;
  1510. $this->cols['photo'] = array(
  1511. 'rank' => $rank,
  1512. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1513. 'status' => false,
  1514. 'title' => array(
  1515. 'textkey' => 'Photo',
  1516. 'label' => ' '
  1517. ),
  1518. 'content' => array(
  1519. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1520. ),
  1521. 'border-left' => false, // remove left line separator
  1522. );
  1523. if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
  1524. $this->cols['photo']['status'] = true;
  1525. }
  1526. $rank = $rank + 10;
  1527. $this->cols['vat'] = array(
  1528. 'rank' => $rank,
  1529. 'status' => false,
  1530. 'width' => 16, // in mm
  1531. 'title' => array(
  1532. 'textkey' => 'VAT'
  1533. ),
  1534. 'border-left' => true, // add left line separator
  1535. );
  1536. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1537. $this->cols['vat']['status'] = true;
  1538. }
  1539. $rank = $rank + 10;
  1540. $this->cols['subprice'] = array(
  1541. 'rank' => $rank,
  1542. 'width' => 19, // in mm
  1543. 'status' => true,
  1544. 'title' => array(
  1545. 'textkey' => 'PriceUHT'
  1546. ),
  1547. 'border-left' => true, // add left line separator
  1548. );
  1549. // Adapt dynamically the width of subprice, if text is too long.
  1550. $tmpwidth = 0;
  1551. $nblines = count($object->lines);
  1552. for ($i = 0; $i < $nblines; $i++) {
  1553. $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
  1554. $tmpwidth = max($tmpwidth, $tmpwidth2);
  1555. }
  1556. if ($tmpwidth > 10) {
  1557. $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
  1558. }
  1559. $rank = $rank + 10;
  1560. $this->cols['qty'] = array(
  1561. 'rank' => $rank,
  1562. 'width' => 16, // in mm
  1563. 'status' => true,
  1564. 'title' => array(
  1565. 'textkey' => 'Qty'
  1566. ),
  1567. 'border-left' => true, // add left line separator
  1568. );
  1569. $rank = $rank + 10;
  1570. $this->cols['unit'] = array(
  1571. 'rank' => $rank,
  1572. 'width' => 11, // in mm
  1573. 'status' => false,
  1574. 'title' => array(
  1575. 'textkey' => 'Unit'
  1576. ),
  1577. 'border-left' => true, // add left line separator
  1578. );
  1579. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1580. $this->cols['unit']['status'] = true;
  1581. }
  1582. $rank = $rank + 10;
  1583. $this->cols['discount'] = array(
  1584. 'rank' => $rank,
  1585. 'width' => 13, // in mm
  1586. 'status' => false,
  1587. 'title' => array(
  1588. 'textkey' => 'ReductionShort'
  1589. ),
  1590. 'border-left' => true, // add left line separator
  1591. );
  1592. if ($this->atleastonediscount) {
  1593. $this->cols['discount']['status'] = true;
  1594. }
  1595. $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
  1596. $this->cols['totalexcltax'] = array(
  1597. 'rank' => $rank,
  1598. 'width' => 26, // in mm
  1599. 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
  1600. 'title' => array(
  1601. 'textkey' => 'TotalHT'
  1602. ),
  1603. 'border-left' => true, // add left line separator
  1604. );
  1605. $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
  1606. $this->cols['totalincltax'] = array(
  1607. 'rank' => $rank,
  1608. 'width' => 26, // in mm
  1609. 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
  1610. 'title' => array(
  1611. 'textkey' => 'TotalTTC'
  1612. ),
  1613. 'border-left' => true, // add left line separator
  1614. );
  1615. // Add extrafields cols
  1616. if (!empty($object->lines)) {
  1617. $line = reset($object->lines);
  1618. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  1619. }
  1620. $parameters = array(
  1621. 'object' => $object,
  1622. 'outputlangs' => $outputlangs,
  1623. 'hidedetails' => $hidedetails,
  1624. 'hidedesc' => $hidedesc,
  1625. 'hideref' => $hideref
  1626. );
  1627. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1628. if ($reshook < 0) {
  1629. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1630. } elseif (empty($reshook)) {
  1631. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1632. } else {
  1633. $this->cols = $hookmanager->resArray;
  1634. }
  1635. }
  1636. }