pdf_eratosthene.modules.php 72 KB

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