pdf_eratosthene.modules.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  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 Eratosthene
  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 = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  133. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  134. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  135. $this->marge_basse = getDolGlobalInt('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 (isModEnabled("multicurrency") && $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. if (!empty($tplidx)) {
  700. $pdf->useTemplate($tplidx);
  701. }
  702. }
  703. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  704. if ($pagenb == $pageposafter) {
  705. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
  706. } else {
  707. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  708. }
  709. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  710. // New page
  711. $pdf->AddPage();
  712. if (!empty($tplidx)) {
  713. $pdf->useTemplate($tplidx);
  714. }
  715. $pagenb++;
  716. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  717. $this->_pagehead($pdf, $object, 0, $outputlangs);
  718. }
  719. }
  720. }
  721. // Show square
  722. if ($pagenb == $pageposbeforeprintlines) {
  723. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
  724. } else {
  725. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  726. }
  727. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  728. // Display infos area
  729. $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
  730. // Display total zone
  731. $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  732. // Affiche zone versements
  733. /*
  734. if ($deja_regle)
  735. {
  736. $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
  737. }
  738. */
  739. // Pied de page
  740. $this->_pagefoot($pdf, $object, $outputlangs);
  741. if (method_exists($pdf, 'AliasNbPages')) {
  742. $pdf->AliasNbPages();
  743. }
  744. $pdf->Close();
  745. $pdf->Output($file, 'F');
  746. // Add pdfgeneration hook
  747. $hookmanager->initHooks(array('pdfgeneration'));
  748. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  749. global $action;
  750. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  751. if ($reshook < 0) {
  752. $this->error = $hookmanager->error;
  753. $this->errors = $hookmanager->errors;
  754. }
  755. if (!empty($conf->global->MAIN_UMASK)) {
  756. @chmod($file, octdec($conf->global->MAIN_UMASK));
  757. }
  758. $this->result = array('fullpath'=>$file);
  759. return 1; // No error
  760. } else {
  761. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  762. return 0;
  763. }
  764. } else {
  765. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
  766. return 0;
  767. }
  768. }
  769. /**
  770. * Show payments table
  771. *
  772. * @param TCPDF $pdf Object PDF
  773. * @param Commande $object Object order
  774. * @param int $posy Position y in PDF
  775. * @param Translate $outputlangs Object langs for output
  776. * @return int <0 if KO, >0 if OK
  777. */
  778. protected function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
  779. {
  780. }
  781. /**
  782. * Show miscellaneous information (payment mode, payment term, ...)
  783. *
  784. * @param TCPDF $pdf Object PDF
  785. * @param Commande $object Object to show
  786. * @param int $posy Y
  787. * @param Translate $outputlangs Langs object
  788. * @return int Pos y
  789. */
  790. protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
  791. {
  792. global $conf, $mysoc;
  793. $default_font_size = pdf_getPDFFontSize($outputlangs);
  794. $pdf->SetFont('', '', $default_font_size - 1);
  795. // If France, show VAT mention if not applicable
  796. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  797. $pdf->SetFont('', 'B', $default_font_size - 2);
  798. $pdf->SetXY($this->marge_gauche, $posy);
  799. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  800. $posy = $pdf->GetY() + 4;
  801. }
  802. $posxval = 52;
  803. // Show payments conditions
  804. if ($object->cond_reglement_code || $object->cond_reglement) {
  805. $pdf->SetFont('', 'B', $default_font_size - 2);
  806. $pdf->SetXY($this->marge_gauche, $posy);
  807. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  808. $pdf->MultiCell(43, 4, $titre, 0, 'L');
  809. $pdf->SetFont('', '', $default_font_size - 2);
  810. $pdf->SetXY($posxval, $posy);
  811. $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);
  812. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  813. if ($object->deposit_percent > 0) {
  814. $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
  815. }
  816. $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
  817. $posy = $pdf->GetY() + 3;
  818. }
  819. // Check a payment mode is defined
  820. /* Not used with orders
  821. if (empty($object->mode_reglement_code)
  822. && ! $conf->global->FACTURE_CHQ_NUMBER
  823. && ! $conf->global->FACTURE_RIB_NUMBER)
  824. {
  825. $pdf->SetXY($this->marge_gauche, $posy);
  826. $pdf->SetTextColor(200,0,0);
  827. $pdf->SetFont('','B', $default_font_size - 2);
  828. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  829. $pdf->SetTextColor(0,0,0);
  830. $posy=$pdf->GetY()+1;
  831. }
  832. */
  833. /* TODO
  834. else if (!empty($object->availability_code))
  835. {
  836. $pdf->SetXY($this->marge_gauche, $posy);
  837. $pdf->SetTextColor(200,0,0);
  838. $pdf->SetFont('','B', $default_font_size - 2);
  839. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
  840. $pdf->SetTextColor(0,0,0);
  841. $posy=$pdf->GetY()+1;
  842. }*/
  843. // Show planed date of delivery
  844. if (!empty($object->delivery_date)) {
  845. $outputlangs->load("sendings");
  846. $pdf->SetFont('', 'B', $default_font_size - 2);
  847. $pdf->SetXY($this->marge_gauche, $posy);
  848. $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
  849. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  850. $pdf->SetFont('', '', $default_font_size - 2);
  851. $pdf->SetXY($posxval, $posy);
  852. $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
  853. $pdf->MultiCell(80, 4, $dlp, 0, 'L');
  854. $posy = $pdf->GetY() + 1;
  855. } elseif ($object->availability_code || $object->availability) { // Show availability conditions
  856. $pdf->SetFont('', 'B', $default_font_size - 2);
  857. $pdf->SetXY($this->marge_gauche, $posy);
  858. $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
  859. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  860. $pdf->SetTextColor(0, 0, 0);
  861. $pdf->SetFont('', '', $default_font_size - 2);
  862. $pdf->SetXY($posxval, $posy);
  863. $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 : '');
  864. $lib_availability = str_replace('\n', "\n", $lib_availability);
  865. $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
  866. $posy = $pdf->GetY() + 1;
  867. }
  868. // Show payment mode
  869. if ($object->mode_reglement_code
  870. && $object->mode_reglement_code != 'CHQ'
  871. && $object->mode_reglement_code != 'VIR') {
  872. $pdf->SetFont('', 'B', $default_font_size - 2);
  873. $pdf->SetXY($this->marge_gauche, $posy);
  874. $titre = $outputlangs->transnoentities("PaymentMode").':';
  875. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  876. $pdf->SetFont('', '', $default_font_size - 2);
  877. $pdf->SetXY($posxval, $posy);
  878. $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);
  879. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  880. $posy = $pdf->GetY() + 2;
  881. }
  882. // Show payment mode CHQ
  883. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  884. // Si mode reglement non force ou si force a CHQ
  885. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  886. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  887. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  888. $account = new Account($this->db);
  889. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  890. $pdf->SetXY($this->marge_gauche, $posy);
  891. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  892. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  893. $posy = $pdf->GetY() + 1;
  894. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  895. $pdf->SetXY($this->marge_gauche, $posy);
  896. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  897. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  898. $posy = $pdf->GetY() + 2;
  899. }
  900. }
  901. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  902. $pdf->SetXY($this->marge_gauche, $posy);
  903. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  904. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  905. $posy = $pdf->GetY() + 1;
  906. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  907. $pdf->SetXY($this->marge_gauche, $posy);
  908. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  909. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  910. $posy = $pdf->GetY() + 2;
  911. }
  912. }
  913. }
  914. }
  915. // If payment mode not forced or forced to VIR, show payment with BAN
  916. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  917. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  918. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  919. if ($object->fk_bank > 0) {
  920. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  921. }
  922. $account = new Account($this->db);
  923. $account->fetch($bankid);
  924. $curx = $this->marge_gauche;
  925. $cury = $posy;
  926. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  927. $posy += 2;
  928. }
  929. }
  930. return $posy;
  931. }
  932. /**
  933. * Show total to pay
  934. *
  935. * @param TCPDF $pdf Object PDF
  936. * @param Commande $object Object to show
  937. * @param int $deja_regle Montant deja regle
  938. * @param int $posy Position depart
  939. * @param Translate $outputlangs Objet langs
  940. * @param Translate $outputlangsbis Object lang for output bis
  941. * @return int Position pour suite
  942. */
  943. protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
  944. {
  945. global $conf, $mysoc, $hookmanager;
  946. $default_font_size = pdf_getPDFFontSize($outputlangs);
  947. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  948. $outputlangsbis = new Translate('', $conf);
  949. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  950. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  951. $default_font_size--;
  952. }
  953. $tab2_top = $posy;
  954. $tab2_hl = 4;
  955. $pdf->SetFont('', '', $default_font_size - 1);
  956. // Total table
  957. $col1x = 120;
  958. $col2x = 170;
  959. if ($this->page_largeur < 210) { // To work with US executive format
  960. $col2x -= 20;
  961. }
  962. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  963. $useborder = 0;
  964. $index = 0;
  965. // Total HT
  966. $pdf->SetFillColor(255, 255, 255);
  967. $pdf->SetXY($col1x, $tab2_top + 0);
  968. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
  969. $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  970. $pdf->SetXY($col2x, $tab2_top + 0);
  971. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
  972. // Show VAT by rates and total
  973. $pdf->SetFillColor(248, 248, 248);
  974. $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  975. $this->atleastoneratenotnull = 0;
  976. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  977. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  978. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  979. // Nothing to do
  980. } else {
  981. //Local tax 1 before VAT
  982. //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  983. //{
  984. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  985. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  986. continue;
  987. }
  988. foreach ($localtax_rate as $tvakey => $tvaval) {
  989. if ($tvakey != 0) { // On affiche pas taux 0
  990. //$this->atleastoneratenotnull++;
  991. $index++;
  992. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  993. $tvacompl = '';
  994. if (preg_match('/\*/', $tvakey)) {
  995. $tvakey = str_replace('*', '', $tvakey);
  996. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  997. }
  998. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  999. $totalvat .= ' ';
  1000. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1001. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1002. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1003. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1004. }
  1005. }
  1006. }
  1007. //}
  1008. //Local tax 2 before VAT
  1009. //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1010. //{
  1011. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1012. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1013. continue;
  1014. }
  1015. foreach ($localtax_rate as $tvakey => $tvaval) {
  1016. if ($tvakey != 0) { // On affiche pas taux 0
  1017. //$this->atleastoneratenotnull++;
  1018. $index++;
  1019. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1020. $tvacompl = '';
  1021. if (preg_match('/\*/', $tvakey)) {
  1022. $tvakey = str_replace('*', '', $tvakey);
  1023. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1024. }
  1025. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1026. $totalvat .= ' ';
  1027. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1028. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1029. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1030. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1031. }
  1032. }
  1033. }
  1034. //}
  1035. // VAT
  1036. foreach ($this->tva_array as $tvakey => $tvaval) {
  1037. if ($tvakey != 0) { // On affiche pas taux 0
  1038. $this->atleastoneratenotnull++;
  1039. $index++;
  1040. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1041. $tvacompl = '';
  1042. if (preg_match('/\*/', $tvakey)) {
  1043. $tvakey = str_replace('*', '', $tvakey);
  1044. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1045. }
  1046. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1047. $totalvat .= ' ';
  1048. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  1049. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  1050. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  1051. $totalvat .= ($tvaval['vatcode'] ? $tvaval['vatcode'] : vatrate($tvaval['vatrate'], 1)).$tvacompl;
  1052. } else {
  1053. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  1054. }
  1055. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1056. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1057. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  1058. }
  1059. }
  1060. //Local tax 1 after VAT
  1061. //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1062. //{
  1063. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1064. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1065. continue;
  1066. }
  1067. foreach ($localtax_rate as $tvakey => $tvaval) {
  1068. if ($tvakey != 0) { // On affiche pas taux 0
  1069. //$this->atleastoneratenotnull++;
  1070. $index++;
  1071. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1072. $tvacompl = '';
  1073. if (preg_match('/\*/', $tvakey)) {
  1074. $tvakey = str_replace('*', '', $tvakey);
  1075. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1076. }
  1077. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1078. $totalvat .= ' ';
  1079. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1080. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1081. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1082. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1083. }
  1084. }
  1085. }
  1086. //}
  1087. //Local tax 2 after VAT
  1088. //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1089. //{
  1090. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1091. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1092. continue;
  1093. }
  1094. foreach ($localtax_rate as $tvakey => $tvaval) {
  1095. // retrieve global local tax
  1096. if ($tvakey != 0) { // On affiche pas taux 0
  1097. //$this->atleastoneratenotnull++;
  1098. $index++;
  1099. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1100. $tvacompl = '';
  1101. if (preg_match('/\*/', $tvakey)) {
  1102. $tvakey = str_replace('*', '', $tvakey);
  1103. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1104. }
  1105. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1106. $totalvat .= ' ';
  1107. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1108. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1109. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1110. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1111. }
  1112. }
  1113. }
  1114. //}
  1115. // Total TTC
  1116. $index++;
  1117. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1118. $pdf->SetTextColor(0, 0, 60);
  1119. $pdf->SetFillColor(224, 224, 224);
  1120. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
  1121. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1122. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1123. }
  1124. }
  1125. $pdf->SetTextColor(0, 0, 0);
  1126. $creditnoteamount = 0;
  1127. $depositsamount = 0;
  1128. //$creditnoteamount=$object->getSumCreditNotesUsed();
  1129. //$depositsamount=$object->getSumDepositsUsed();
  1130. //print "x".$creditnoteamount."-".$depositsamount;exit;
  1131. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  1132. if (!empty($object->paye)) {
  1133. $resteapayer = 0;
  1134. }
  1135. if ($deja_regle > 0) {
  1136. // Already paid + Deposits
  1137. $index++;
  1138. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1139. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
  1140. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1141. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
  1142. $index++;
  1143. $pdf->SetTextColor(0, 0, 60);
  1144. $pdf->SetFillColor(224, 224, 224);
  1145. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1146. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
  1147. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1148. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1149. $pdf->SetFont('', '', $default_font_size - 1);
  1150. $pdf->SetTextColor(0, 0, 0);
  1151. }
  1152. $index++;
  1153. return ($tab2_top + ($tab2_hl * $index));
  1154. }
  1155. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1156. /**
  1157. * Show table for lines
  1158. *
  1159. * @param TCPDF $pdf Object PDF
  1160. * @param string $tab_top Top position of table
  1161. * @param string $tab_height Height of table (rectangle)
  1162. * @param int $nexY Y (not used)
  1163. * @param Translate $outputlangs Langs object
  1164. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1165. * @param int $hidebottom Hide bottom bar of array
  1166. * @param string $currency Currency code
  1167. * @param Translate $outputlangsbis Langs object bis
  1168. * @return void
  1169. */
  1170. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1171. {
  1172. global $conf;
  1173. // Force to disable hidetop and hidebottom
  1174. $hidebottom = 0;
  1175. if ($hidetop) {
  1176. $hidetop = -1;
  1177. }
  1178. $currency = !empty($currency) ? $currency : $conf->currency;
  1179. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1180. // Amount in (at tab_top - 1)
  1181. $pdf->SetTextColor(0, 0, 0);
  1182. $pdf->SetFont('', '', $default_font_size - 2);
  1183. if (empty($hidetop)) {
  1184. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1185. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1186. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1187. }
  1188. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1189. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1190. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1191. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1192. $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));
  1193. }
  1194. }
  1195. $pdf->SetDrawColor(128, 128, 128);
  1196. $pdf->SetFont('', '', $default_font_size - 1);
  1197. // Output Rect
  1198. $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
  1199. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  1200. if (empty($hidetop)) {
  1201. $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
  1202. }
  1203. }
  1204. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1205. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1206. /**
  1207. * Show top header of page.
  1208. *
  1209. * @param TCPDF $pdf Object PDF
  1210. * @param Commande $object Object to show
  1211. * @param int $showaddress 0=no, 1=yes
  1212. * @param Translate $outputlangs Object lang for output
  1213. * @param Translate $outputlangsbis Object lang for output bis
  1214. * @param string $titlekey Translation key to show as title of document
  1215. * @return int Return topshift value
  1216. */
  1217. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
  1218. {
  1219. // phpcs:enable
  1220. global $conf, $langs, $hookmanager;
  1221. $ltrdirection = 'L';
  1222. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1223. // Load traductions files required by page
  1224. $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
  1225. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1226. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1227. $pdf->SetTextColor(0, 0, 60);
  1228. $pdf->SetFont('', 'B', $default_font_size + 3);
  1229. $w = 100;
  1230. $posy = $this->marge_haute;
  1231. $posx = $this->page_largeur - $this->marge_droite - $w;
  1232. $pdf->SetXY($this->marge_gauche, $posy);
  1233. // Logo
  1234. if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
  1235. if ($this->emetteur->logo) {
  1236. $logodir = $conf->mycompany->dir_output;
  1237. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1238. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1239. }
  1240. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  1241. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1242. } else {
  1243. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1244. }
  1245. if (is_readable($logo)) {
  1246. $height = pdf_getHeightForLogo($logo);
  1247. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1248. } else {
  1249. $pdf->SetTextColor(200, 0, 0);
  1250. $pdf->SetFont('', 'B', $default_font_size - 2);
  1251. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1252. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1253. }
  1254. } else {
  1255. $text = $this->emetteur->name;
  1256. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  1257. }
  1258. }
  1259. $pdf->SetFont('', 'B', $default_font_size + 3);
  1260. $pdf->SetXY($posx, $posy);
  1261. $pdf->SetTextColor(0, 0, 60);
  1262. $title = $outputlangs->transnoentities($titlekey);
  1263. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1264. $title .= ' - ';
  1265. $title .= $outputlangsbis->transnoentities($titlekey);
  1266. }
  1267. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1268. if ($object->statut == $object::STATUS_DRAFT) {
  1269. $pdf->SetTextColor(128, 0, 0);
  1270. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1271. }
  1272. $pdf->MultiCell($w, 3, $title, '', 'R');
  1273. $pdf->SetFont('', 'B', $default_font_size);
  1274. /*
  1275. $posy += 5;
  1276. $pdf->SetXY($posx, $posy);
  1277. $pdf->SetTextColor(0, 0, 60);
  1278. $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
  1279. if ($object->statut == $object::STATUS_DRAFT) {
  1280. $pdf->SetTextColor(128, 0, 0);
  1281. $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
  1282. }
  1283. $pdf->MultiCell($w, 4, $textref, '', 'R');
  1284. */
  1285. $posy += 3;
  1286. $pdf->SetFont('', '', $default_font_size - 2);
  1287. if ($object->ref_client) {
  1288. $posy += 4;
  1289. $pdf->SetXY($posx, $posy);
  1290. $pdf->SetTextColor(0, 0, 60);
  1291. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
  1292. }
  1293. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1294. $object->fetch_projet();
  1295. if (!empty($object->project->ref)) {
  1296. $posy += 3;
  1297. $pdf->SetXY($posx, $posy);
  1298. $pdf->SetTextColor(0, 0, 60);
  1299. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1300. }
  1301. }
  1302. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1303. $object->fetch_projet();
  1304. if (!empty($object->project->ref)) {
  1305. $outputlangs->load("projects");
  1306. $posy += 3;
  1307. $pdf->SetXY($posx, $posy);
  1308. $pdf->SetTextColor(0, 0, 60);
  1309. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1310. }
  1311. }
  1312. $posy += 4;
  1313. $pdf->SetXY($posx, $posy);
  1314. $pdf->SetTextColor(0, 0, 60);
  1315. $title = $outputlangs->transnoentities("OrderDate");
  1316. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1317. $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
  1318. }
  1319. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
  1320. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
  1321. $posy += 4;
  1322. $pdf->SetXY($posx, $posy);
  1323. $pdf->SetTextColor(0, 0, 60);
  1324. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1325. }
  1326. // Get contact
  1327. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1328. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1329. if (count($arrayidcontact) > 0) {
  1330. $usertmp = new User($this->db);
  1331. $usertmp->fetch($arrayidcontact[0]);
  1332. $posy += 4;
  1333. $pdf->SetXY($posx, $posy);
  1334. $pdf->SetTextColor(0, 0, 60);
  1335. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1336. }
  1337. }
  1338. $posy += 2;
  1339. $top_shift = 0;
  1340. // Show list of linked objects
  1341. $current_y = $pdf->getY();
  1342. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1343. if ($current_y < $pdf->getY()) {
  1344. $top_shift = $pdf->getY() - $current_y;
  1345. }
  1346. if ($showaddress) {
  1347. // Sender properties
  1348. $carac_emetteur = '';
  1349. // Add internal contact of proposal if defined
  1350. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1351. if (count($arrayidcontact) > 0) {
  1352. $object->fetch_user($arrayidcontact[0]);
  1353. $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
  1354. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  1355. }
  1356. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1357. // Show sender
  1358. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1359. $posy += $top_shift;
  1360. $posx = $this->marge_gauche;
  1361. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1362. $posx = $this->page_largeur - $this->marge_droite - 80;
  1363. }
  1364. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  1365. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1366. // Show sender frame
  1367. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1368. $pdf->SetTextColor(0, 0, 0);
  1369. $pdf->SetFont('', '', $default_font_size - 2);
  1370. $pdf->SetXY($posx, $posy - 5);
  1371. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1372. $pdf->SetXY($posx, $posy);
  1373. $pdf->SetFillColor(230, 230, 230);
  1374. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  1375. $pdf->SetTextColor(0, 0, 60);
  1376. }
  1377. // Show sender name
  1378. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1379. $pdf->SetXY($posx + 2, $posy + 3);
  1380. $pdf->SetFont('', 'B', $default_font_size);
  1381. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1382. $posy = $pdf->getY();
  1383. }
  1384. // Show sender information
  1385. $pdf->SetXY($posx + 2, $posy);
  1386. $pdf->SetFont('', '', $default_font_size - 1);
  1387. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
  1388. // If CUSTOMER contact defined, we use it
  1389. $usecontact = false;
  1390. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  1391. if (count($arrayidcontact) > 0) {
  1392. $usecontact = true;
  1393. $result = $object->fetch_contact($arrayidcontact[0]);
  1394. }
  1395. //Recipient name
  1396. 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)))) {
  1397. $thirdparty = $object->contact;
  1398. } else {
  1399. $thirdparty = $object->thirdparty;
  1400. }
  1401. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1402. $mode = 'target';
  1403. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1404. // Show recipient
  1405. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1406. if ($this->page_largeur < 210) {
  1407. $widthrecbox = 84; // To work with US executive format
  1408. }
  1409. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1410. $posy += $top_shift;
  1411. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1412. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1413. $posx = $this->marge_gauche;
  1414. }
  1415. // Show recipient frame
  1416. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1417. $pdf->SetTextColor(0, 0, 0);
  1418. $pdf->SetFont('', '', $default_font_size - 2);
  1419. $pdf->SetXY($posx + 2, $posy - 5);
  1420. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1421. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1422. }
  1423. // Show recipient name
  1424. $pdf->SetXY($posx + 2, $posy + 3);
  1425. $pdf->SetFont('', 'B', $default_font_size);
  1426. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1427. $posy = $pdf->getY();
  1428. // Show recipient information
  1429. $pdf->SetFont('', '', $default_font_size - 1);
  1430. $pdf->SetXY($posx + 2, $posy);
  1431. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1432. }
  1433. $pdf->SetTextColor(0, 0, 0);
  1434. return $top_shift;
  1435. }
  1436. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1437. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1438. /**
  1439. * Show footer of page. Need this->emetteur object
  1440. *
  1441. * @param TCPDF $pdf PDF
  1442. * @param Commande $object Object to show
  1443. * @param Translate $outputlangs Object lang for output
  1444. * @param int $hidefreetext 1=Hide free text
  1445. * @return int Return height of bottom margin including footer text
  1446. */
  1447. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1448. {
  1449. // phpcs:enable
  1450. global $conf;
  1451. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1452. 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);
  1453. }
  1454. /**
  1455. * Define Array Column Field
  1456. *
  1457. * @param Commande $object common object
  1458. * @param Translate $outputlangs langs
  1459. * @param int $hidedetails Do not show line details
  1460. * @param int $hidedesc Do not show desc
  1461. * @param int $hideref Do not show ref
  1462. * @return null
  1463. */
  1464. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1465. {
  1466. global $conf, $hookmanager;
  1467. // Default field style for content
  1468. $this->defaultContentsFieldsStyle = array(
  1469. 'align' => 'R', // R,C,L
  1470. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1471. );
  1472. // Default field style for content
  1473. $this->defaultTitlesFieldsStyle = array(
  1474. 'align' => 'C', // R,C,L
  1475. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1476. );
  1477. /*
  1478. * For exemple
  1479. $this->cols['theColKey'] = array(
  1480. 'rank' => $rank, // int : use for ordering columns
  1481. 'width' => 20, // the column width in mm
  1482. 'title' => array(
  1483. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1484. 'label' => ' ', // the final label : used fore final generated text
  1485. 'align' => 'L', // text alignement : R,C,L
  1486. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1487. ),
  1488. 'content' => array(
  1489. 'align' => 'L', // text alignement : R,C,L
  1490. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1491. ),
  1492. );
  1493. */
  1494. $rank = 0; // do not use negative rank
  1495. $this->cols['desc'] = array(
  1496. 'rank' => $rank,
  1497. 'width' => false, // only for desc
  1498. 'status' => true,
  1499. 'title' => array(
  1500. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1501. 'align' => 'L',
  1502. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1503. // 'label' => ' ', // the final label
  1504. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1505. ),
  1506. 'content' => array(
  1507. 'align' => 'L',
  1508. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1509. ),
  1510. );
  1511. // Image of product
  1512. $rank = $rank + 10;
  1513. $this->cols['photo'] = array(
  1514. 'rank' => $rank,
  1515. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1516. 'status' => false,
  1517. 'title' => array(
  1518. 'textkey' => 'Photo',
  1519. 'label' => ' '
  1520. ),
  1521. 'content' => array(
  1522. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1523. ),
  1524. 'border-left' => false, // remove left line separator
  1525. );
  1526. if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
  1527. $this->cols['photo']['status'] = true;
  1528. }
  1529. $rank = $rank + 10;
  1530. $this->cols['vat'] = array(
  1531. 'rank' => $rank,
  1532. 'status' => false,
  1533. 'width' => 16, // in mm
  1534. 'title' => array(
  1535. 'textkey' => 'VAT'
  1536. ),
  1537. 'border-left' => true, // add left line separator
  1538. );
  1539. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1540. $this->cols['vat']['status'] = true;
  1541. }
  1542. $rank = $rank + 10;
  1543. $this->cols['subprice'] = array(
  1544. 'rank' => $rank,
  1545. 'width' => 19, // in mm
  1546. 'status' => true,
  1547. 'title' => array(
  1548. 'textkey' => 'PriceUHT'
  1549. ),
  1550. 'border-left' => true, // add left line separator
  1551. );
  1552. // Adapt dynamically the width of subprice, if text is too long.
  1553. $tmpwidth = 0;
  1554. $nblines = count($object->lines);
  1555. for ($i = 0; $i < $nblines; $i++) {
  1556. $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
  1557. $tmpwidth = max($tmpwidth, $tmpwidth2);
  1558. }
  1559. if ($tmpwidth > 10) {
  1560. $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
  1561. }
  1562. $rank = $rank + 10;
  1563. $this->cols['qty'] = array(
  1564. 'rank' => $rank,
  1565. 'width' => 16, // in mm
  1566. 'status' => true,
  1567. 'title' => array(
  1568. 'textkey' => 'Qty'
  1569. ),
  1570. 'border-left' => true, // add left line separator
  1571. );
  1572. $rank = $rank + 10;
  1573. $this->cols['unit'] = array(
  1574. 'rank' => $rank,
  1575. 'width' => 11, // in mm
  1576. 'status' => false,
  1577. 'title' => array(
  1578. 'textkey' => 'Unit'
  1579. ),
  1580. 'border-left' => true, // add left line separator
  1581. );
  1582. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1583. $this->cols['unit']['status'] = true;
  1584. }
  1585. $rank = $rank + 10;
  1586. $this->cols['discount'] = array(
  1587. 'rank' => $rank,
  1588. 'width' => 13, // in mm
  1589. 'status' => false,
  1590. 'title' => array(
  1591. 'textkey' => 'ReductionShort'
  1592. ),
  1593. 'border-left' => true, // add left line separator
  1594. );
  1595. if ($this->atleastonediscount) {
  1596. $this->cols['discount']['status'] = true;
  1597. }
  1598. $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
  1599. $this->cols['totalexcltax'] = array(
  1600. 'rank' => $rank,
  1601. 'width' => 26, // in mm
  1602. 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
  1603. 'title' => array(
  1604. 'textkey' => 'TotalHT'
  1605. ),
  1606. 'border-left' => true, // add left line separator
  1607. );
  1608. $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
  1609. $this->cols['totalincltax'] = array(
  1610. 'rank' => $rank,
  1611. 'width' => 26, // in mm
  1612. 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
  1613. 'title' => array(
  1614. 'textkey' => 'TotalTTC'
  1615. ),
  1616. 'border-left' => true, // add left line separator
  1617. );
  1618. // Add extrafields cols
  1619. if (!empty($object->lines)) {
  1620. $line = reset($object->lines);
  1621. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  1622. }
  1623. $parameters = array(
  1624. 'object' => $object,
  1625. 'outputlangs' => $outputlangs,
  1626. 'hidedetails' => $hidedetails,
  1627. 'hidedesc' => $hidedesc,
  1628. 'hideref' => $hideref
  1629. );
  1630. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1631. if ($reshook < 0) {
  1632. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1633. } elseif (empty($reshook)) {
  1634. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1635. } else {
  1636. $this->cols = $hookmanager->resArray;
  1637. }
  1638. }
  1639. }