pdf_vinci.modules.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. <?php
  2. /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  5. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. * or see https://www.gnu.org/
  23. */
  24. /**
  25. * \file htdocs/core/modules/mrp/doc/pdf_vinci.modules.php
  26. * \ingroup mrp
  27. * \brief File of class to generate MO document from vinci model
  28. */
  29. require_once DOL_DOCUMENT_ROOT.'/core/modules/mrp/modules_mo.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  36. /**
  37. * Class to generate the manufacturing orders with the vinci model
  38. */
  39. class pdf_vinci extends ModelePDFMo
  40. {
  41. /**
  42. * @var DoliDb Database handler
  43. */
  44. public $db;
  45. /**
  46. * @var string model name
  47. */
  48. public $name;
  49. /**
  50. * @var string model description (short text)
  51. */
  52. public $description;
  53. /**
  54. * @var int Save the name of generated file as the main doc when generating a doc with this template
  55. */
  56. public $update_main_doc_field;
  57. /**
  58. * @var string document type
  59. */
  60. public $type;
  61. /**
  62. * @var array Minimum version of PHP required by module.
  63. * e.g.: PHP ≥ 5.6 = array(5, 6)
  64. */
  65. public $phpmin = array(5, 6);
  66. /**
  67. * Dolibarr version of the loaded document
  68. * @var string
  69. */
  70. public $version = 'dolibarr';
  71. /**
  72. * @var int page_largeur
  73. */
  74. public $page_largeur;
  75. /**
  76. * @var int page_hauteur
  77. */
  78. public $page_hauteur;
  79. /**
  80. * @var array format
  81. */
  82. public $format;
  83. /**
  84. * @var int marge_gauche
  85. */
  86. public $marge_gauche;
  87. /**
  88. * @var int marge_droite
  89. */
  90. public $marge_droite;
  91. /**
  92. * @var int marge_haute
  93. */
  94. public $marge_haute;
  95. /**
  96. * @var int marge_basse
  97. */
  98. public $marge_basse;
  99. /**
  100. * Issuer
  101. * @var Societe object that emits
  102. */
  103. public $emetteur;
  104. /**
  105. * Constructor
  106. *
  107. * @param DoliDB $db Database handler
  108. */
  109. public function __construct($db)
  110. {
  111. global $conf, $langs, $mysoc;
  112. // Load translation files required by the page
  113. $langs->loadLangs(array("main", "bills"));
  114. $this->db = $db;
  115. $this->name = "vinci";
  116. $this->description = $langs->trans('DocumentModelStandardPDF');
  117. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  118. // Page size for A4 format
  119. $this->type = 'pdf';
  120. $formatarray = pdf_getFormat();
  121. $this->page_largeur = $formatarray['width'];
  122. $this->page_hauteur = $formatarray['height'];
  123. $this->format = array($this->page_largeur, $this->page_hauteur);
  124. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  125. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  126. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  127. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  128. $this->option_logo = 1; // Display logo
  129. $this->option_multilang = 1; //Available in several languages
  130. $this->option_escompte = 0; // Displays if there has been a discount
  131. $this->option_credit_note = 0; // Support credit notes
  132. $this->option_freetext = 1; // Support add of a personalised text
  133. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  134. // Get source company
  135. $this->emetteur = $mysoc;
  136. if (empty($this->emetteur->country_code)) {
  137. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  138. }
  139. // Define position of columns
  140. $this->posxdesc = $this->marge_gauche + 1; // For module retrocompatibility support durring PDF transition: TODO remove this at the end
  141. }
  142. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  143. /**
  144. * Function to build pdf onto disk
  145. *
  146. * @param CommandeFournisseur $object Id of object to generate
  147. * @param Translate $outputlangs Lang output object
  148. * @param string $srctemplatepath Full path of source filename for generator using a template file
  149. * @param int $hidedetails Do not show line details
  150. * @param int $hidedesc Do not show desc
  151. * @param int $hideref Do not show ref
  152. * @return int 1=OK, 0=KO
  153. */
  154. public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  155. {
  156. // phpcs:enable
  157. global $user, $langs, $conf, $hookmanager, $mysoc;
  158. if (!is_object($outputlangs)) {
  159. $outputlangs = $langs;
  160. }
  161. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  162. if (!empty($conf->global->MAIN_USE_FPDF)) {
  163. $outputlangs->charset_output = 'ISO-8859-1';
  164. }
  165. // Load translation files required by the page
  166. $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
  167. global $outputlangsbis;
  168. $outputlangsbis = null;
  169. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  170. $outputlangsbis = new Translate('', $conf);
  171. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  172. $outputlangsbis->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
  173. }
  174. if (!isset($object->lines) || !is_array($object->lines)) {
  175. $object->lines = array();
  176. }
  177. $nblines = count($object->lines);
  178. $hidetop = 0;
  179. if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
  180. $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
  181. }
  182. // Loop on each lines to detect if there is at least one image to show
  183. $realpatharray = array();
  184. if ($conf->mrp->dir_output) {
  185. $object->fetch_thirdparty();
  186. $deja_regle = 0;
  187. $amount_credit_notes_included = 0;
  188. $amount_deposits_included = 0;
  189. //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
  190. //$amount_deposits_included = $object->getSumDepositsUsed();
  191. // Definition of $dir and $file
  192. if ($object->specimen) {
  193. $dir = $conf->mrp->dir_output;
  194. $file = $dir."/SPECIMEN.pdf";
  195. } else {
  196. $objectref = dol_sanitizeFileName($object->ref);
  197. $dir = $conf->mrp->dir_output.'/'.$objectref;
  198. $file = $dir."/".$objectref.".pdf";
  199. }
  200. if (!file_exists($dir)) {
  201. if (dol_mkdir($dir) < 0) {
  202. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  203. return 0;
  204. }
  205. }
  206. if (file_exists($dir)) {
  207. // Add pdfgeneration hook
  208. if (!is_object($hookmanager)) {
  209. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  210. $hookmanager = new HookManager($this->db);
  211. }
  212. $hookmanager->initHooks(array('pdfgeneration'));
  213. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  214. global $action;
  215. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  216. $nblines = count($object->lines);
  217. $pdf = pdf_getInstance($this->format);
  218. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  219. $heightforinfotot = 50; // Height reserved to output the info and total part
  220. $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
  221. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  222. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  223. $heightforfooter += 6;
  224. }
  225. $pdf->SetAutoPageBreak(1, 0);
  226. if (class_exists('TCPDF')) {
  227. $pdf->setPrintHeader(false);
  228. $pdf->setPrintFooter(false);
  229. }
  230. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  231. // Set path to the background PDF File
  232. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  233. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  234. $tplidx = $pdf->importPage(1);
  235. }
  236. $pdf->Open();
  237. $pagenb = 0;
  238. $pdf->SetDrawColor(128, 128, 128);
  239. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  240. $pdf->SetSubject($outputlangs->transnoentities("Mo"));
  241. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  242. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  243. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Mo")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  244. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  245. $pdf->SetCompression(false);
  246. }
  247. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  248. // Does we have at least one line with discount $this->atleastonediscount
  249. // New page
  250. $pdf->AddPage();
  251. if (!empty($tplidx)) {
  252. $pdf->useTemplate($tplidx);
  253. }
  254. $pagenb++;
  255. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
  256. $pdf->SetFont('', '', $default_font_size - 1);
  257. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  258. $pdf->SetTextColor(0, 0, 0);
  259. $tab_top = 90 + $top_shift;
  260. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  261. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  262. // Affiche notes
  263. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  264. // Extrafields in note
  265. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  266. if (!empty($extranote)) {
  267. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  268. }
  269. $pagenb = $pdf->getPage();
  270. if ($notetoshow) {
  271. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  272. $pageposbeforenote = $pagenb;
  273. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  274. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  275. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  276. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  277. $tab_top -= 2;
  278. $pdf->startTransaction();
  279. $pdf->SetFont('', '', $default_font_size - 1);
  280. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  281. // Description
  282. $pageposafternote = $pdf->getPage();
  283. $posyafter = $pdf->GetY();
  284. if ($pageposafternote > $pageposbeforenote) {
  285. $pdf->rollbackTransaction(true);
  286. // prepar pages to receive notes
  287. while ($pagenb < $pageposafternote) {
  288. $pdf->AddPage();
  289. $pagenb++;
  290. if (!empty($tplidx)) {
  291. $pdf->useTemplate($tplidx);
  292. }
  293. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  294. $this->_pagehead($pdf, $object, 0, $outputlangs);
  295. }
  296. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  297. $pdf->setTopMargin($tab_top_newpage);
  298. // The only function to edit the bottom margin of current page to set it.
  299. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  300. }
  301. // back to start
  302. $pdf->setPage($pageposbeforenote);
  303. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  304. $pdf->SetFont('', '', $default_font_size - 1);
  305. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  306. $pageposafternote = $pdf->getPage();
  307. $posyafter = $pdf->GetY();
  308. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  309. $pdf->AddPage('', '', true);
  310. $pagenb++;
  311. $pageposafternote++;
  312. $pdf->setPage($pageposafternote);
  313. $pdf->setTopMargin($tab_top_newpage);
  314. // The only function to edit the bottom margin of current page to set it.
  315. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  316. //$posyafter = $tab_top_newpage;
  317. }
  318. // apply note frame to previus pages
  319. $i = $pageposbeforenote;
  320. while ($i < $pageposafternote) {
  321. $pdf->setPage($i);
  322. $pdf->SetDrawColor(128, 128, 128);
  323. // Draw note frame
  324. if ($i > $pageposbeforenote) {
  325. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  326. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  327. } else {
  328. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  329. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  330. }
  331. // Add footer
  332. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  333. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  334. $i++;
  335. }
  336. // apply note frame to last page
  337. $pdf->setPage($pageposafternote);
  338. if (!empty($tplidx)) {
  339. $pdf->useTemplate($tplidx);
  340. }
  341. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  342. $this->_pagehead($pdf, $object, 0, $outputlangs);
  343. }
  344. $height_note = $posyafter - $tab_top_newpage;
  345. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  346. } else {
  347. // No pagebreak
  348. $pdf->commitTransaction();
  349. $posyafter = $pdf->GetY();
  350. $height_note = $posyafter - $tab_top;
  351. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  352. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  353. // not enough space, need to add page
  354. $pdf->AddPage('', '', true);
  355. $pagenb++;
  356. $pageposafternote++;
  357. $pdf->setPage($pageposafternote);
  358. if (!empty($tplidx)) {
  359. $pdf->useTemplate($tplidx);
  360. }
  361. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  362. $this->_pagehead($pdf, $object, 0, $outputlangs);
  363. }
  364. $posyafter = $tab_top_newpage;
  365. }
  366. }
  367. $tab_height = $tab_height - $height_note;
  368. $tab_top = $posyafter + 6;
  369. } else {
  370. $height_note = 0;
  371. }
  372. $nexY = $tab_top + 5;
  373. // Use new auto collum system
  374. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  375. // Loop on each lines
  376. $pageposbeforeprintlines = $pdf->getPage();
  377. $pagenb = $pageposbeforeprintlines;
  378. $bom = new BOM($this->db);
  379. $bom -> fetch($object->fk_bom);
  380. $nblines = count($bom->lines);
  381. for ($i = 0; $i < $nblines; $i++) {
  382. $curY = $nexY;
  383. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  384. $pdf->SetTextColor(0, 0, 0);
  385. $prod = new Product($this->db);
  386. $prod->fetch($bom->lines[$i]->fk_product);
  387. // Define size of image if we need it
  388. $imglinesize = array();
  389. if (!empty($realpatharray[$i])) {
  390. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  391. }
  392. $pdf->setTopMargin($tab_top_newpage);
  393. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  394. $pageposbefore = $pdf->getPage();
  395. $showpricebeforepagebreak = 1;
  396. $posYAfterImage = 0;
  397. $posYAfterDescription = 0;
  398. // We start with Photo of product line
  399. if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
  400. $pdf->AddPage('', '', true);
  401. if (!empty($tplidx)) {
  402. $pdf->useTemplate($tplidx);
  403. }
  404. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  405. $this->_pagehead($pdf, $object, 0, $outputlangs);
  406. }
  407. $pdf->setPage($pageposbefore + 1);
  408. $curY = $tab_top_newpage;
  409. // Allows data in the first page if description is long enough to break in multiples pages
  410. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  411. $showpricebeforepagebreak = 1;
  412. } else {
  413. $showpricebeforepagebreak = 0;
  414. }
  415. }
  416. if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) {
  417. $curX = $this->posxpicture - 1;
  418. $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  419. // $pdf->Image does not increase value return by getY, so we save it manually
  420. $posYAfterImage = $curY + $imglinesize['height'];
  421. }
  422. // Description of product line
  423. $curX = $this->posxdesc - 1;
  424. $showpricebeforepagebreak = 1;
  425. if ($this->getColumnStatus('code')) {
  426. $pdf->startTransaction(); //description
  427. //$this->printColDescContent($pdf, $curY, 'code', $object, $i, $outputlangs, $hideref, $hidedesc, $showsupplierSKU);
  428. $this->printStdColumnContent($pdf, $curY, 'code', $prod->ref);
  429. $pageposafter = $pdf->getPage();
  430. $posyafter = $pdf->GetY();
  431. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  432. $pdf->rollbackTransaction(true);
  433. //$this->printColDescContent($pdf, $curY, 'code', $object, $i, $outputlangs, $hideref, $hidedesc, $showsupplierSKU);
  434. $this->printStdColumnContent($pdf, $curY, 'code', $prod->ref);
  435. $pageposafter = $pdf->getPage();
  436. $posyafter = $pdf->GetY();
  437. } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  438. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  439. $pdf->AddPage('', '', true);
  440. if (!empty($tplidx)) {
  441. $pdf->useTemplate($tplidx);
  442. }
  443. //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  444. $pdf->setPage($pageposafter + 1);
  445. } else {
  446. // We found a page break
  447. // Allows data in the first page if description is long enough to break in multiples pages
  448. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  449. $showpricebeforepagebreak = 1;
  450. } else {
  451. $showpricebeforepagebreak = 0;
  452. }
  453. }
  454. } else // No pagebreak
  455. {
  456. $pdf->commitTransaction();
  457. }
  458. $posYAfterDescription = $pdf->GetY();
  459. }
  460. $nexY = $pdf->GetY();
  461. $pageposafter = $pdf->getPage();
  462. $pdf->setPage($pageposbefore);
  463. $pdf->setTopMargin($this->marge_haute);
  464. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  465. // We suppose that a too long description is moved completely on next page
  466. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  467. $pdf->setPage($pageposafter);
  468. $curY = $tab_top_newpage;
  469. }
  470. if ($this->getColumnStatus('desc')) {
  471. $pdf->startTransaction(); //description
  472. $des = $prod -> description;
  473. $descr = $des;//implode("<br>", $des);
  474. $this->printStdColumnContent($pdf, $curY, 'desc', $descr);
  475. $pageposafter = $pdf->getPage();
  476. $posyafter = $pdf->GetY();
  477. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  478. $pdf->rollbackTransaction(true);
  479. $this->printStdColumnContent($pdf, $curY, 'desc', $descr);
  480. $pageposafter = $pdf->getPage();
  481. $posyafter = $pdf->GetY();
  482. } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  483. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  484. $pdf->AddPage('', '', true);
  485. if (!empty($tplidx)) {
  486. $pdf->useTemplate($tplidx);
  487. }
  488. //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  489. $pdf->setPage($pageposafter + 1);
  490. } else {
  491. // We found a page break
  492. // Allows data in the first page if description is long enough to break in multiples pages
  493. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  494. $showpricebeforepagebreak = 1;
  495. } else {
  496. $showpricebeforepagebreak = 0;
  497. }
  498. }
  499. } else // No pagebreak
  500. {
  501. $pdf->commitTransaction();
  502. }
  503. $posYAfterDescription = max($posYAfterDescription, $pdf->GetY());
  504. }
  505. $nexY = max($nexY, $pdf->GetY());
  506. $pageposafter = $pdf->getPage();
  507. $pdf->setPage($pageposbefore);
  508. $pdf->setTopMargin($this->marge_haute);
  509. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  510. // We suppose that a too long description is moved completely on next page
  511. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  512. $pdf->setPage($pageposafter);
  513. $curY = $tab_top_newpage;
  514. }
  515. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  516. // Quantity
  517. // Enough for 6 chars
  518. if ($this->getColumnStatus('qty')) {
  519. $qty = $bom->lines[$i]->qty;
  520. $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
  521. $nexY = max($pdf->GetY(), $nexY);
  522. }
  523. // Quantity
  524. // Enough for 6 chars
  525. if ($this->getColumnStatus('qtytot')) {
  526. $qtytot = $object->qty * $bom->lines[$i]->qty;
  527. $this->printStdColumnContent($pdf, $curY, 'qtytot', $qtytot);
  528. $nexY = max($pdf->GetY(), $nexY);
  529. }
  530. // Dimensions
  531. if ($this->getColumnStatus('dim')) {
  532. $array = array_filter(array($prod->length, $prod->width, $prod->height));
  533. $dim = implode("x", $array);
  534. $this->printStdColumnContent($pdf, $curY, 'dim', $dim);
  535. $nexY = max($pdf->GetY(), $nexY);
  536. }
  537. }
  538. // Show square
  539. if ($pagenb == $pageposbeforeprintlines) {
  540. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
  541. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  542. } else {
  543. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  544. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  545. }
  546. // Affiche zone infos
  547. $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  548. // Affiche zone totaux
  549. //$posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  550. // Affiche zone versements
  551. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
  552. $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  553. }
  554. // Pied de page
  555. $this->_pagefoot($pdf, $object, $outputlangs);
  556. if (method_exists($pdf, 'AliasNbPages')) {
  557. $pdf->AliasNbPages();
  558. }
  559. $pdf->Close();
  560. $pdf->Output($file, 'F');
  561. // Add pdfgeneration hook
  562. $hookmanager->initHooks(array('pdfgeneration'));
  563. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  564. global $action;
  565. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  566. if ($reshook < 0) {
  567. $this->error = $hookmanager->error;
  568. $this->errors = $hookmanager->errors;
  569. }
  570. if (!empty($conf->global->MAIN_UMASK)) {
  571. @chmod($file, octdec($conf->global->MAIN_UMASK));
  572. }
  573. $this->result = array('fullpath'=>$file);
  574. return 1; // No error
  575. } else {
  576. $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
  577. return 0;
  578. }
  579. } else {
  580. $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
  581. return 0;
  582. }
  583. }
  584. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  585. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  586. /**
  587. * Show payments table
  588. *
  589. * @param TCPDF $pdf Object PDF
  590. * @param CommandeFournisseur $object Object order
  591. * @param int $posy Position y in PDF
  592. * @param Translate $outputlangs Object langs for output
  593. * @return int <0 if KO, >0 if OK
  594. */
  595. protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  596. {
  597. // phpcs:enable
  598. }
  599. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  600. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  601. /**
  602. * Show miscellaneous information (payment mode, payment term, ...)
  603. *
  604. * @param TCPDF $pdf Object PDF
  605. * @param CommandeFournisseur $object Object to show
  606. * @param int $posy Y
  607. * @param Translate $outputlangs Langs object
  608. * @return integer
  609. */
  610. protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  611. {
  612. // phpcs:enable
  613. global $conf, $mysoc;
  614. $default_font_size = pdf_getPDFFontSize($outputlangs);
  615. // If France, show VAT mention if not applicable
  616. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  617. $pdf->SetFont('', 'B', $default_font_size - 2);
  618. $pdf->SetXY($this->marge_gauche, $posy);
  619. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  620. $posy = $pdf->GetY() + 4;
  621. }
  622. $posxval = 52;
  623. // Show payments conditions
  624. if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
  625. $pdf->SetFont('', 'B', $default_font_size - 2);
  626. $pdf->SetXY($this->marge_gauche, $posy);
  627. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  628. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  629. $pdf->SetFont('', '', $default_font_size - 2);
  630. $pdf->SetXY($posxval, $posy);
  631. $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);
  632. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  633. $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
  634. $posy = $pdf->GetY() + 3;
  635. }
  636. // Show payment mode
  637. if (!empty($object->mode_reglement_code)) {
  638. $pdf->SetFont('', 'B', $default_font_size - 2);
  639. $pdf->SetXY($this->marge_gauche, $posy);
  640. $titre = $outputlangs->transnoentities("PaymentMode").':';
  641. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  642. $pdf->SetFont('', '', $default_font_size - 2);
  643. $pdf->SetXY($posxval, $posy);
  644. $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);
  645. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  646. $posy = $pdf->GetY() + 2;
  647. }
  648. return $posy;
  649. }
  650. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  651. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  652. /**
  653. * Show total to pay
  654. *
  655. * @param TCPDF $pdf Object PDF
  656. * @param Facture $object Object invoice
  657. * @param int $deja_regle Montant deja regle
  658. * @param int $posy Position depart
  659. * @param Translate $outputlangs Objet langs
  660. * @return int Position pour suite
  661. */
  662. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  663. {
  664. // phpcs:enable
  665. global $conf, $mysoc;
  666. $default_font_size = pdf_getPDFFontSize($outputlangs);
  667. $tab2_top = $posy;
  668. $tab2_hl = 4;
  669. $pdf->SetFont('', '', $default_font_size - 1);
  670. // Tableau total
  671. $col1x = 120;
  672. $col2x = 170;
  673. if ($this->page_largeur < 210) { // To work with US executive format
  674. $col2x -= 20;
  675. }
  676. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  677. $useborder = 0;
  678. $index = 0;
  679. // Total HT
  680. $pdf->SetFillColor(255, 255, 255);
  681. $pdf->SetXY($col1x, $tab2_top + 0);
  682. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  683. $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  684. $pdf->SetXY($col2x, $tab2_top + 0);
  685. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
  686. // Show VAT by rates and total
  687. $pdf->SetFillColor(248, 248, 248);
  688. $this->atleastoneratenotnull = 0;
  689. foreach ($this->tva as $tvakey => $tvaval) {
  690. if ($tvakey > 0) { // On affiche pas taux 0
  691. $this->atleastoneratenotnull++;
  692. $index++;
  693. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  694. $tvacompl = '';
  695. if (preg_match('/\*/', $tvakey)) {
  696. $tvakey = str_replace('*', '', $tvakey);
  697. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  698. }
  699. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
  700. $totalvat .= vatrate($tvakey, 1).$tvacompl;
  701. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  702. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  703. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  704. }
  705. }
  706. if (!$this->atleastoneratenotnull) { // If no vat at all
  707. $index++;
  708. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  709. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
  710. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  711. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
  712. // Total LocalTax1
  713. if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
  714. $index++;
  715. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  716. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
  717. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  718. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
  719. }
  720. // Total LocalTax2
  721. if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
  722. $index++;
  723. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  724. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
  725. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  726. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
  727. }
  728. } else {
  729. //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  730. //{
  731. //Local tax 1
  732. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  733. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  734. continue;
  735. }
  736. foreach ($localtax_rate as $tvakey => $tvaval) {
  737. if ($tvakey != 0) { // On affiche pas taux 0
  738. //$this->atleastoneratenotnull++;
  739. $index++;
  740. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  741. $tvacompl = '';
  742. if (preg_match('/\*/', $tvakey)) {
  743. $tvakey = str_replace('*', '', $tvakey);
  744. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  745. }
  746. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
  747. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  748. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  749. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  750. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  751. }
  752. }
  753. }
  754. //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  755. //{
  756. //Local tax 2
  757. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  758. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  759. continue;
  760. }
  761. foreach ($localtax_rate as $tvakey => $tvaval) {
  762. if ($tvakey != 0) { // On affiche pas taux 0
  763. //$this->atleastoneratenotnull++;
  764. $index++;
  765. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  766. $tvacompl = '';
  767. if (preg_match('/\*/', $tvakey)) {
  768. $tvakey = str_replace('*', '', $tvakey);
  769. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  770. }
  771. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
  772. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  773. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  774. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  775. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  776. }
  777. }
  778. }
  779. }
  780. // Total TTC
  781. $index++;
  782. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  783. $pdf->SetTextColor(0, 0, 60);
  784. $pdf->SetFillColor(224, 224, 224);
  785. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
  786. $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  787. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  788. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
  789. $pdf->SetFont('', '', $default_font_size - 1);
  790. $pdf->SetTextColor(0, 0, 0);
  791. $creditnoteamount = 0;
  792. $depositsamount = 0;
  793. //$creditnoteamount=$object->getSumCreditNotesUsed();
  794. //$depositsamount=$object->getSumDepositsUsed();
  795. //print "x".$creditnoteamount."-".$depositsamount;exit;
  796. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  797. if (!empty($object->paye)) {
  798. $resteapayer = 0;
  799. }
  800. if ($deja_regle > 0) {
  801. // Already paid + Deposits
  802. $index++;
  803. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  804. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
  805. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  806. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
  807. $index++;
  808. $pdf->SetTextColor(0, 0, 60);
  809. $pdf->SetFillColor(224, 224, 224);
  810. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  811. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  812. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  813. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
  814. $pdf->SetFont('', '', $default_font_size - 1);
  815. $pdf->SetTextColor(0, 0, 0);
  816. }
  817. $index++;
  818. return ($tab2_top + ($tab2_hl * $index));
  819. }
  820. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  821. /**
  822. * Show table for lines
  823. *
  824. * @param TCPDF $pdf Object PDF
  825. * @param string $tab_top Top position of table
  826. * @param string $tab_height Height of table (rectangle)
  827. * @param int $nexY Y (not used)
  828. * @param Translate $outputlangs Langs object
  829. * @param int $hidetop Hide top bar of array
  830. * @param int $hidebottom Hide bottom bar of array
  831. * @param string $currency Currency code
  832. * @return void
  833. */
  834. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
  835. {
  836. global $conf;
  837. // Force to disable hidetop and hidebottom
  838. $hidebottom = 0;
  839. if ($hidetop) {
  840. $hidetop = -1;
  841. }
  842. $currency = !empty($currency) ? $currency : $conf->currency;
  843. $default_font_size = pdf_getPDFFontSize($outputlangs);
  844. // Amount in (at tab_top - 1)
  845. $pdf->SetTextColor(0, 0, 0);
  846. $pdf->SetFont('', '', $default_font_size - 2);
  847. if (empty($hidetop)) {
  848. //$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  849. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  850. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  851. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  852. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  853. $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));
  854. }
  855. }
  856. $pdf->SetDrawColor(128, 128, 128);
  857. $pdf->SetFont('', '', $default_font_size - 1);
  858. // Output Rect
  859. $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
  860. foreach ($this->cols as $colKey => $colDef) {
  861. if (!$this->getColumnStatus($colKey)) {
  862. continue;
  863. }
  864. // get title label
  865. $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
  866. // Add column separator
  867. if (!empty($colDef['border-left'])) {
  868. $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
  869. }
  870. if (empty($hidetop)) {
  871. $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
  872. $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
  873. $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
  874. }
  875. }
  876. if (empty($hidetop)) {
  877. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
  878. }
  879. }
  880. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  881. /**
  882. * Show top header of page.
  883. *
  884. * @param TCPDF $pdf Object PDF
  885. * @param CommandeFournisseur $object Object to show
  886. * @param int $showaddress 0=no, 1=yes
  887. * @param Translate $outputlangs Object lang for output
  888. * @return void
  889. */
  890. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  891. {
  892. global $langs, $conf, $mysoc;
  893. $ltrdirection = 'L';
  894. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  895. // Load translation files required by the page
  896. $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
  897. $default_font_size = pdf_getPDFFontSize($outputlangs);
  898. // Do not add the BACKGROUND as this is for suppliers
  899. //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  900. //Affiche le filigrane brouillon - Print Draft Watermark
  901. /*if($object->statut==0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
  902. {
  903. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
  904. }*/
  905. //Print content
  906. $pdf->SetTextColor(0, 0, 60);
  907. $pdf->SetFont('', 'B', $default_font_size + 3);
  908. $posx = $this->page_largeur - $this->marge_droite - 100;
  909. $posy = $this->marge_haute;
  910. $pdf->SetXY($this->marge_gauche, $posy);
  911. // Logo
  912. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  913. if ($this->emetteur->logo) {
  914. if (is_readable($logo)) {
  915. $height = pdf_getHeightForLogo($logo);
  916. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  917. } else {
  918. $pdf->SetTextColor(200, 0, 0);
  919. $pdf->SetFont('', 'B', $default_font_size - 2);
  920. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  921. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  922. }
  923. } else {
  924. $text = $this->emetteur->name;
  925. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
  926. }
  927. $pdf->SetFont('', 'B', $default_font_size + 3);
  928. $pdf->SetXY($posx, $posy);
  929. $pdf->SetTextColor(0, 0, 60);
  930. $title = $outputlangs->transnoentities("Mo")." ".$outputlangs->convToOutputCharset($object->ref);
  931. $pdf->MultiCell(100, 3, $title, '', 'R');
  932. $posy += 1;
  933. if ($object->ref_supplier) {
  934. $posy += 4;
  935. $pdf->SetFont('', 'B', $default_font_size);
  936. $pdf->SetXY($posx, $posy);
  937. $pdf->SetTextColor(0, 0, 60);
  938. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
  939. $posy += 1;
  940. }
  941. $pdf->SetFont('', '', $default_font_size - 1);
  942. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  943. $object->fetch_projet();
  944. if (!empty($object->project->ref)) {
  945. $posy += 3;
  946. $pdf->SetXY($posx, $posy);
  947. $pdf->SetTextColor(0, 0, 60);
  948. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  949. }
  950. }
  951. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  952. $object->fetch_projet();
  953. if (!empty($object->project->ref)) {
  954. $outputlangs->load("projects");
  955. $posy += 4;
  956. $pdf->SetXY($posx, $posy);
  957. $langs->load("projects");
  958. $pdf->SetTextColor(0, 0, 60);
  959. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  960. }
  961. }
  962. if (!empty($object->date_approve)) {
  963. $posy += 5;
  964. $pdf->SetXY($posx, $posy);
  965. $pdf->SetTextColor(0, 0, 60);
  966. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("MoDate")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs, true), '', 'R');
  967. } else {
  968. $posy += 5;
  969. $pdf->SetXY($posx, $posy);
  970. $pdf->SetTextColor(255, 0, 0);
  971. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToApprove"), '', 'R');
  972. }
  973. // product info
  974. $posy += 7;
  975. $prodToMake = new Product($this->db);
  976. $prodToMake->fetch($object->fk_product);
  977. $pdf->SetFont('', 'B', $default_font_size + 1);
  978. $pdf->SetXY($posx, $posy);
  979. $pdf->SetTextColor(0, 0, 60);
  980. $pdf->MultiCell($w, 3, $prodToMake->ref, '', 'R');
  981. $posy += 5;
  982. $prodToMake = new Product($this->db);
  983. $prodToMake->fetch($object->fk_product);
  984. $pdf->SetFont('', 'B', $default_font_size + 3);
  985. $pdf->SetXY($posx, $posy);
  986. $pdf->SetTextColor(0, 0, 60);
  987. $pdf->MultiCell($w, 3, $prodToMake->description, '', 'R');
  988. $array = array_filter(array($prodToMake->length, $prodToMake->width, $prodToMake->height));
  989. $dim = implode("x", $array);
  990. if (!empty($dim)) {
  991. $posy += 5;
  992. $pdf->SetFont('', 'B', $default_font_size + 3);
  993. $pdf->SetXY($posx, $posy);
  994. $pdf->SetTextColor(0, 0, 60);
  995. $pdf->MultiCell($w, 3, $dim, '', 'R');
  996. }
  997. $posy += 5;
  998. $prodToMake = new Product($this->db);
  999. $prodToMake->fetch($object->fk_product);
  1000. $pdf->SetFont('', 'B', $default_font_size + 3);
  1001. $pdf->SetXY($posx, $posy);
  1002. $pdf->SetTextColor(0, 0, 60);
  1003. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("QtyToProduce").": " .$object->qty, '', 'R');
  1004. $pdf->SetTextColor(0, 0, 60);
  1005. $usehourmin = 'day';
  1006. if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
  1007. $usehourmin = 'dayhour';
  1008. }
  1009. if (!empty($object->delivery_date)) {
  1010. $posy += 4;
  1011. $pdf->SetXY($posx - 90, $posy);
  1012. $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
  1013. }
  1014. if ($object->thirdparty->code_fournisseur) {
  1015. $posy += 4;
  1016. $pdf->SetXY($posx, $posy);
  1017. $pdf->SetTextColor(0, 0, 60);
  1018. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
  1019. }
  1020. // Get contact
  1021. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1022. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1023. if (count($arrayidcontact) > 0) {
  1024. $usertmp = new User($this->db);
  1025. $usertmp->fetch($arrayidcontact[0]);
  1026. $posy += 4;
  1027. $pdf->SetXY($posx, $posy);
  1028. $pdf->SetTextColor(0, 0, 60);
  1029. $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
  1030. }
  1031. }
  1032. $posy += 1;
  1033. $pdf->SetTextColor(0, 0, 60);
  1034. $top_shift = 0;
  1035. // Show list of linked objects
  1036. $current_y = $pdf->getY();
  1037. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
  1038. if ($current_y < $pdf->getY()) {
  1039. $top_shift = $pdf->getY() - $current_y;
  1040. }
  1041. if ($showaddress) {
  1042. // Sender properties
  1043. $carac_emetteur = '';
  1044. // Add internal contact of proposal if defined
  1045. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1046. if (count($arrayidcontact) > 0) {
  1047. $object->fetch_user($arrayidcontact[0]);
  1048. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  1049. }
  1050. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1051. // Show sender
  1052. $posy = 42 + $top_shift;
  1053. $posx = $this->marge_gauche;
  1054. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1055. $posx = $this->page_largeur - $this->marge_droite - 80;
  1056. }
  1057. $hautcadre = 40;
  1058. // Show sender frame
  1059. $pdf->SetTextColor(0, 0, 0);
  1060. $pdf->SetFont('', '', $default_font_size - 2);
  1061. $pdf->SetXY($posx, $posy - 5);
  1062. $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1063. $pdf->SetXY($posx, $posy);
  1064. $pdf->SetFillColor(230, 230, 230);
  1065. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  1066. $pdf->SetTextColor(0, 0, 60);
  1067. // Show sender name
  1068. $pdf->SetXY($posx + 2, $posy + 3);
  1069. $pdf->SetFont('', 'B', $default_font_size);
  1070. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1071. $posy = $pdf->getY();
  1072. // Show sender information
  1073. $pdf->SetXY($posx + 2, $posy);
  1074. $pdf->SetFont('', '', $default_font_size - 1);
  1075. $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
  1076. // If CUSTOMER contact defined on order, we use it. Note: Even if this is a supplier object, the code for external contat that follow order is 'CUSTOMER'
  1077. $usecontact = false;
  1078. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  1079. if (count($arrayidcontact) > 0) {
  1080. $usecontact = true;
  1081. $result = $object->fetch_contact($arrayidcontact[0]);
  1082. }
  1083. // Recipient name
  1084. if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  1085. $thirdparty = $object->contact;
  1086. } else {
  1087. $thirdparty = $object->thirdparty;
  1088. }
  1089. //$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1090. //$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
  1091. // Show recipient
  1092. //$widthrecbox = 100;
  1093. //if ($this->page_largeur < 210) {
  1094. // $widthrecbox = 84; // To work with US executive format
  1095. //}
  1096. //$posy = 42 + $top_shift;
  1097. //$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1098. //if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1099. // $posx = $this->marge_gauche;
  1100. //}
  1101. //
  1102. //// Show recipient frame
  1103. //$pdf->SetTextColor(0, 0, 0);
  1104. //$pdf->SetFont('', '', $default_font_size - 2);
  1105. //$pdf->SetXY($posx + 2, $posy - 5);
  1106. //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1107. //$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1108. //
  1109. //// Show recipient name
  1110. //$pdf->SetXY($posx + 2, $posy + 3);
  1111. //$pdf->SetFont('', 'B', $default_font_size);
  1112. //$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
  1113. //
  1114. //$posy = $pdf->getY();
  1115. //
  1116. //// Show recipient information
  1117. //$pdf->SetFont('', '', $default_font_size - 1);
  1118. //$pdf->SetXY($posx + 2, $posy);
  1119. //$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1120. }
  1121. return $top_shift;
  1122. }
  1123. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1124. /**
  1125. * Show footer of page. Need this->emetteur object
  1126. *
  1127. * @param TCPDF $pdf PDF
  1128. * @param CommandeFournisseur $object Object to show
  1129. * @param Translate $outputlangs Object lang for output
  1130. * @param int $hidefreetext 1=Hide free text
  1131. * @return int Return height of bottom margin including footer text
  1132. */
  1133. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1134. {
  1135. global $conf;
  1136. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1137. return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  1138. }
  1139. /**
  1140. * Define Array Column Field
  1141. *
  1142. * @param object $object common object
  1143. * @param Translate $outputlangs langs
  1144. * @param int $hidedetails Do not show line details
  1145. * @param int $hidedesc Do not show desc
  1146. * @param int $hideref Do not show ref
  1147. * @return null
  1148. */
  1149. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1150. {
  1151. global $conf, $hookmanager;
  1152. // Default field style for content
  1153. $this->defaultContentsFieldsStyle = array(
  1154. 'align' => 'R', // R,C,L
  1155. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1156. );
  1157. // Default field style for content
  1158. $this->defaultTitlesFieldsStyle = array(
  1159. 'align' => 'C', // R,C,L
  1160. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1161. );
  1162. /*
  1163. * For exemple
  1164. $this->cols['theColKey'] = array(
  1165. 'rank' => $rank, // int : use for ordering columns
  1166. 'width' => 20, // the column width in mm
  1167. 'title' => array(
  1168. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1169. 'label' => ' ', // the final label : used fore final generated text
  1170. 'align' => 'L', // text alignement : R,C,L
  1171. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1172. ),
  1173. 'content' => array(
  1174. 'align' => 'L', // text alignement : R,C,L
  1175. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1176. ),
  1177. );
  1178. */
  1179. $rank = 0;
  1180. $this->cols['code'] = array(
  1181. 'rank' => $rank,
  1182. 'status' => false,
  1183. 'width' => 35, // in mm
  1184. 'title' => array(
  1185. 'textkey' => 'Ref'
  1186. ),
  1187. 'border-left' => true, // add left line separator
  1188. );
  1189. $this->cols['code']['status'] = true;
  1190. $rank = 1; // do not use negative rank
  1191. $this->cols['desc'] = array(
  1192. 'rank' => $rank,
  1193. 'width' => false, // only for desc
  1194. 'status' => true,
  1195. 'title' => array(
  1196. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1197. 'align' => 'L',
  1198. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1199. // 'label' => ' ', // the final label
  1200. 'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1201. ),
  1202. 'border-left' => true,
  1203. 'content' => array(
  1204. 'align' => 'L',
  1205. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1206. ),
  1207. );
  1208. $rank = $rank + 10;
  1209. $this->cols['photo'] = array(
  1210. 'rank' => $rank,
  1211. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1212. 'status' => false,
  1213. 'title' => array(
  1214. 'textkey' => 'Photo',
  1215. 'label' => ' '
  1216. ),
  1217. 'content' => array(
  1218. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1219. ),
  1220. 'border-left' => false, // remove left line separator
  1221. );
  1222. if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) {
  1223. $this->cols['photo']['status'] = true;
  1224. }
  1225. $rank = $rank + 10;
  1226. $this->cols['dim'] = array(
  1227. 'rank' => $rank,
  1228. 'status' => false,
  1229. 'width' => 25, // in mm
  1230. 'title' => array(
  1231. 'textkey' => 'Size'
  1232. ),
  1233. 'border-left' => true, // add left line separator
  1234. );
  1235. $this->cols['dim']['status'] = true;
  1236. $rank = $rank + 10;
  1237. $this->cols['qty'] = array(
  1238. 'rank' => $rank,
  1239. 'width' => 16, // in mm
  1240. 'status' => true,
  1241. 'title' => array(
  1242. 'textkey' => 'Qty'
  1243. ),
  1244. 'border-left' => true, // add left line separator
  1245. );
  1246. $this->cols['qty']['status'] = true;
  1247. $rank = $rank + 10;
  1248. $this->cols['qtytot'] = array(
  1249. 'rank' => $rank,
  1250. 'width' => 25, // in mm
  1251. 'status' => true,
  1252. 'title' => array(
  1253. 'textkey' => 'QtyTot'
  1254. ),
  1255. 'border-left' => true, // add left line separator
  1256. );
  1257. $this->cols['qtytot']['status'] = true;
  1258. // Add extrafields cols
  1259. if (!empty($object->lines)) {
  1260. $line = reset($object->lines);
  1261. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  1262. }
  1263. $parameters = array(
  1264. 'object' => $object,
  1265. 'outputlangs' => $outputlangs,
  1266. 'hidedetails' => $hidedetails,
  1267. 'hidedesc' => $hidedesc,
  1268. 'hideref' => $hideref
  1269. );
  1270. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1271. if ($reshook < 0) {
  1272. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1273. } elseif (empty($reshook)) {
  1274. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1275. } else {
  1276. $this->cols = $hookmanager->resArray;
  1277. }
  1278. }
  1279. }