pdf_eratosthene.modules.php 72 KB

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