pdf_espadon.modules.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
  24. * \ingroup expedition
  25. * \brief Class file allowing Espadons shipping template generation
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  30. /**
  31. * Class to build sending documents with model espadon
  32. */
  33. class pdf_espadon extends ModelePdfExpedition
  34. {
  35. /**
  36. * @var DoliDb Database handler
  37. */
  38. public $db;
  39. /**
  40. * @var string model name
  41. */
  42. public $name;
  43. /**
  44. * @var string model description (short text)
  45. */
  46. public $description;
  47. /**
  48. * @var string document type
  49. */
  50. public $type;
  51. /**
  52. * @var array Minimum version of PHP required by module.
  53. * e.g.: PHP ≥ 5.5 = array(5, 5)
  54. */
  55. public $phpmin = array(5, 5);
  56. /**
  57. * Dolibarr version of the loaded document
  58. * @var string
  59. */
  60. public $version = 'dolibarr';
  61. /**
  62. * @var int page_largeur
  63. */
  64. public $page_largeur;
  65. /**
  66. * @var int page_hauteur
  67. */
  68. public $page_hauteur;
  69. /**
  70. * @var array format
  71. */
  72. public $format;
  73. /**
  74. * @var int marge_gauche
  75. */
  76. public $marge_gauche;
  77. /**
  78. * @var int marge_droite
  79. */
  80. public $marge_droite;
  81. /**
  82. * @var int marge_haute
  83. */
  84. public $marge_haute;
  85. /**
  86. * @var int marge_basse
  87. */
  88. public $marge_basse;
  89. /**
  90. * Issuer
  91. * @var Societe object that emits
  92. */
  93. public $emetteur;
  94. /**
  95. * Constructor
  96. *
  97. * @param DoliDB $db Database handler
  98. */
  99. public function __construct($db = 0)
  100. {
  101. global $conf, $langs, $mysoc;
  102. $this->db = $db;
  103. $this->name = "espadon";
  104. $this->description = $langs->trans("DocumentModelStandardPDF");
  105. $this->type = 'pdf';
  106. $formatarray = pdf_getFormat();
  107. $this->page_largeur = $formatarray['width'];
  108. $this->page_hauteur = $formatarray['height'];
  109. $this->format = array($this->page_largeur, $this->page_hauteur);
  110. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  111. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  112. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  113. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  114. $this->option_logo = 1;
  115. // Get source company
  116. $this->emetteur = $mysoc;
  117. if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  118. $this->tabTitleHeight = 5; // default height
  119. }
  120. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  121. /**
  122. * Function to build pdf onto disk
  123. *
  124. * @param Object $object Object expedition to generate (or id if old method)
  125. * @param Translate $outputlangs Lang output object
  126. * @param string $srctemplatepath Full path of source filename for generator using a template file
  127. * @param int $hidedetails Do not show line details
  128. * @param int $hidedesc Do not show desc
  129. * @param int $hideref Do not show ref
  130. * @return int 1=OK, 0=KO
  131. */
  132. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  133. {
  134. // phpcs:enable
  135. global $user, $conf, $langs, $hookmanager;
  136. $object->fetch_thirdparty();
  137. if (!is_object($outputlangs)) $outputlangs = $langs;
  138. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  139. if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
  140. // Load traductions files required by page
  141. $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
  142. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  143. global $outputlangsbis;
  144. $outputlangsbis = new Translate('', $conf);
  145. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  146. $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
  147. }
  148. $nblines = count($object->lines);
  149. // Loop on each lines to detect if there is at least one image to show
  150. $realpatharray = array();
  151. if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE))
  152. {
  153. $objphoto = new Product($this->db);
  154. for ($i = 0; $i < $nblines; $i++)
  155. {
  156. if (empty($object->lines[$i]->fk_product)) continue;
  157. $objphoto = new Product($this->db);
  158. $objphoto->fetch($object->lines[$i]->fk_product);
  159. $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
  160. $dir = $conf->product->dir_output.'/'.$pdir;
  161. $realpath = '';
  162. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
  163. {
  164. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  165. {
  166. if ($obj['photo_vignette'])
  167. {
  168. $filename = $obj['photo_vignette'];
  169. }
  170. else
  171. {
  172. $filename = $obj['photo'];
  173. }
  174. }
  175. else
  176. {
  177. $filename = $obj['photo'];
  178. }
  179. $realpath = $dir.$filename;
  180. break;
  181. }
  182. if ($realpath) $realpatharray[$i] = $realpath;
  183. }
  184. }
  185. if (count($realpatharray) == 0) $this->posxpicture = $this->posxweightvol;
  186. if ($conf->expedition->dir_output)
  187. {
  188. // Definition of $dir and $file
  189. if ($object->specimen)
  190. {
  191. $dir = $conf->expedition->dir_output."/sending";
  192. $file = $dir."/SPECIMEN.pdf";
  193. }
  194. else
  195. {
  196. $expref = dol_sanitizeFileName($object->ref);
  197. $dir = $conf->expedition->dir_output."/sending/".$expref;
  198. $file = $dir."/".$expref.".pdf";
  199. }
  200. if (!file_exists($dir))
  201. {
  202. if (dol_mkdir($dir) < 0)
  203. {
  204. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  205. return 0;
  206. }
  207. }
  208. if (file_exists($dir))
  209. {
  210. // Add pdfgeneration hook
  211. if (!is_object($hookmanager))
  212. {
  213. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  214. $hookmanager = new HookManager($this->db);
  215. }
  216. $hookmanager->initHooks(array('pdfgeneration'));
  217. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  218. global $action;
  219. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  220. // Set nblines with the new facture lines content after hook
  221. $nblines = count($object->lines);
  222. $pdf = pdf_getInstance($this->format);
  223. $default_font_size = pdf_getPDFFontSize($outputlangs);
  224. $heightforinfotot = 8; // Height reserved to output the info and total part
  225. $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
  226. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  227. if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
  228. $pdf->SetAutoPageBreak(1, 0);
  229. if (class_exists('TCPDF'))
  230. {
  231. $pdf->setPrintHeader(false);
  232. $pdf->setPrintFooter(false);
  233. }
  234. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  235. // Set path to the background PDF File
  236. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  237. {
  238. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  239. $tplidx = $pdf->importPage(1);
  240. }
  241. $pdf->Open();
  242. $pagenb = 0;
  243. $pdf->SetDrawColor(128, 128, 128);
  244. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  245. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  246. $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
  247. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  248. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  249. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
  250. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  251. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  252. // New page
  253. $pdf->AddPage();
  254. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  255. $pagenb++;
  256. $this->_pagehead($pdf, $object, 1, $outputlangs);
  257. $pdf->SetFont('', '', $default_font_size - 1);
  258. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  259. $pdf->SetTextColor(0, 0, 0);
  260. $tab_top = 90;
  261. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  262. $tab_height = 130;
  263. $tab_height_newpage = 150;
  264. // Incoterm
  265. $height_incoterms = 0;
  266. if ($conf->incoterm->enabled)
  267. {
  268. $desc_incoterms = $object->getIncotermsForPDF();
  269. if ($desc_incoterms)
  270. {
  271. $tab_top = 88;
  272. $pdf->SetFont('', '', $default_font_size - 1);
  273. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  274. $nexY = $pdf->GetY();
  275. $height_incoterms = $nexY - $tab_top;
  276. // Rect takes a length in 3rd parameter
  277. $pdf->SetDrawColor(192, 192, 192);
  278. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  279. $tab_top = $nexY + 6;
  280. $height_incoterms += 4;
  281. }
  282. }
  283. if (!empty($object->note_public) || !empty($object->tracking_number))
  284. {
  285. $tab_top = 88 + $height_incoterms;
  286. $tab_top_alt = $tab_top;
  287. $pdf->SetFont('', 'B', $default_font_size - 2);
  288. $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
  289. $tab_top_alt = $pdf->GetY();
  290. //$tab_top_alt += 1;
  291. // Tracking number
  292. if (!empty($object->tracking_number))
  293. {
  294. $object->getUrlTrackingStatus($object->tracking_number);
  295. if (!empty($object->tracking_url))
  296. {
  297. if ($object->shipping_method_id > 0)
  298. {
  299. // Get code using getLabelFromKey
  300. $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  301. $label = '';
  302. if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
  303. $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
  304. //var_dump($object->tracking_url != $object->tracking_number);exit;
  305. if ($object->tracking_url != $object->tracking_number)
  306. {
  307. $label .= " : ";
  308. $label .= $object->tracking_url;
  309. }
  310. $pdf->SetFont('', 'B', $default_font_size - 2);
  311. $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
  312. $tab_top_alt = $pdf->GetY();
  313. }
  314. }
  315. }
  316. // Notes
  317. if (!empty($object->note_public))
  318. {
  319. $pdf->SetFont('', '', $default_font_size - 1); // In loop to manage multi-page
  320. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
  321. }
  322. $nexY = $pdf->GetY();
  323. $height_note = $nexY - $tab_top;
  324. // Rect takes a length in 3rd parameter
  325. $pdf->SetDrawColor(192, 192, 192);
  326. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  327. $tab_height = $tab_height - $height_note;
  328. $tab_top = $nexY + 6;
  329. }
  330. else
  331. {
  332. $height_note = 0;
  333. }
  334. // Use new auto column system
  335. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  336. // Table simulation to know the height of the title line
  337. $pdf->startTransaction();
  338. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  339. $pdf->rollbackTransaction(true);
  340. $iniY = $tab_top + $this->tabTitleHeight + 2;
  341. $curY = $tab_top + $this->tabTitleHeight + 2;
  342. $nexY = $tab_top + $this->tabTitleHeight + 2;
  343. // Loop on each lines
  344. for ($i = 0; $i < $nblines; $i++)
  345. {
  346. $curY = $nexY;
  347. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  348. $pdf->SetTextColor(0, 0, 0);
  349. // Define size of image if we need it
  350. $imglinesize = array();
  351. if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  352. $pdf->setTopMargin($tab_top_newpage);
  353. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  354. $pageposbefore = $pdf->getPage();
  355. $showpricebeforepagebreak = 1;
  356. $posYAfterImage = 0;
  357. $posYAfterDescription = 0;
  358. if ($this->getColumnStatus('photo'))
  359. {
  360. // We start with Photo of product line
  361. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) // If photo too high, we moved completely on new page
  362. {
  363. $pdf->AddPage('', '', true);
  364. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  365. //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  366. $pdf->setPage($pageposbefore + 1);
  367. $curY = $tab_top_newpage;
  368. $showpricebeforepagebreak = 0;
  369. }
  370. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
  371. {
  372. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  373. // $pdf->Image does not increase value return by getY, so we save it manually
  374. $posYAfterImage = $curY + $imglinesize['height'];
  375. }
  376. }
  377. // Description of product line
  378. if ($this->getColumnStatus('desc'))
  379. {
  380. $pdf->startTransaction();
  381. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
  382. $pageposafter = $pdf->getPage();
  383. if ($pageposafter > $pageposbefore) // There is a pagebreak
  384. {
  385. $pdf->rollbackTransaction(true);
  386. $pageposafter = $pageposbefore;
  387. //print $pageposafter.'-'.$pageposbefore;exit;
  388. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  389. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
  390. $pageposafter = $pdf->getPage();
  391. $posyafter = $pdf->GetY();
  392. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  393. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) // There is no space left for total+free text
  394. {
  395. if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
  396. {
  397. $pdf->AddPage('', '', true);
  398. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  399. //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  400. $pdf->setPage($pageposafter + 1);
  401. }
  402. }
  403. else
  404. {
  405. // We found a page break
  406. $showpricebeforepagebreak = 0;
  407. }
  408. }
  409. else // No pagebreak
  410. {
  411. $pdf->commitTransaction();
  412. }
  413. $posYAfterDescription = $pdf->GetY();
  414. }
  415. $nexY = $pdf->GetY();
  416. $pageposafter = $pdf->getPage();
  417. $pdf->setPage($pageposbefore);
  418. $pdf->setTopMargin($this->marge_haute);
  419. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  420. // We suppose that a too long description or photo were moved completely on next page
  421. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  422. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  423. }
  424. // We suppose that a too long description is moved completely on next page
  425. if ($pageposafter > $pageposbefore) {
  426. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  427. }
  428. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  429. // weight
  430. $weighttxt = '';
  431. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
  432. {
  433. $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units);
  434. }
  435. $voltxt = '';
  436. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
  437. {
  438. $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0);
  439. }
  440. if ($this->getColumnStatus('weight'))
  441. {
  442. $this->printStdColumnContent($pdf, $curY, 'weight', $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, array('html'=>1));
  443. $nexY = max($pdf->GetY(), $nexY);
  444. }
  445. if ($this->getColumnStatus('qty_asked'))
  446. {
  447. $this->printStdColumnContent($pdf, $curY, 'qty_asked', $object->lines[$i]->qty_asked);
  448. $nexY = max($pdf->GetY(), $nexY);
  449. }
  450. if ($this->getColumnStatus('qty_shipped'))
  451. {
  452. $this->printStdColumnContent($pdf, $curY, 'qty_shipped', $object->lines[$i]->qty_shipped);
  453. $nexY = max($pdf->GetY(), $nexY);
  454. }
  455. if ($this->getColumnStatus('subprice'))
  456. {
  457. $this->printStdColumnContent($pdf, $curY, 'subprice', price($object->lines[$i]->subprice, 0, $outputlangs));
  458. $nexY = max($pdf->GetY(), $nexY);
  459. }
  460. $nexY += 3;
  461. if ($weighttxt && $voltxt) $nexY += 2;
  462. // Add line
  463. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
  464. {
  465. $pdf->setPage($pageposafter);
  466. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  467. //$pdf->SetDrawColor(190,190,200);
  468. $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
  469. $pdf->SetLineStyle(array('dash'=>0));
  470. }
  471. // Detect if some page were added automatically and output _tableau for past pages
  472. while ($pagenb < $pageposafter)
  473. {
  474. $pdf->setPage($pagenb);
  475. if ($pagenb == 1)
  476. {
  477. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  478. }
  479. else
  480. {
  481. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  482. }
  483. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  484. $pagenb++;
  485. $pdf->setPage($pagenb);
  486. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  487. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  488. }
  489. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
  490. {
  491. if ($pagenb == 1)
  492. {
  493. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  494. }
  495. else
  496. {
  497. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  498. }
  499. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  500. // New page
  501. $pdf->AddPage();
  502. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  503. $pagenb++;
  504. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  505. }
  506. }
  507. // Show square
  508. if ($pagenb == 1)
  509. {
  510. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  511. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  512. }
  513. else
  514. {
  515. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  516. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  517. }
  518. // Display total area
  519. $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
  520. // Pagefoot
  521. $this->_pagefoot($pdf, $object, $outputlangs);
  522. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  523. $pdf->Close();
  524. $pdf->Output($file, 'F');
  525. // Add pdfgeneration hook
  526. $hookmanager->initHooks(array('pdfgeneration'));
  527. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  528. global $action;
  529. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  530. if ($reshook < 0)
  531. {
  532. $this->error = $hookmanager->error;
  533. $this->errors = $hookmanager->errors;
  534. }
  535. if (!empty($conf->global->MAIN_UMASK))
  536. @chmod($file, octdec($conf->global->MAIN_UMASK));
  537. $this->result = array('fullpath'=>$file);
  538. return 1; // No error
  539. }
  540. else
  541. {
  542. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  543. return 0;
  544. }
  545. }
  546. else
  547. {
  548. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  549. return 0;
  550. }
  551. }
  552. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  553. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  554. /**
  555. * Show total to pay
  556. *
  557. * @param PDF $pdf Object PDF
  558. * @param Facture $object Object invoice
  559. * @param int $deja_regle Amount already paid
  560. * @param int $posy Start Position
  561. * @param Translate $outputlangs Objet langs
  562. * @return int Position for suite
  563. */
  564. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  565. {
  566. // phpcs:enable
  567. global $conf, $mysoc;
  568. $sign = 1;
  569. $default_font_size = pdf_getPDFFontSize($outputlangs);
  570. $tab2_top = $posy;
  571. $tab2_hl = 4;
  572. $pdf->SetFont('', 'B', $default_font_size - 1);
  573. // Total table
  574. $col1x = $this->posxweightvol - 50; $col2x = $this->posxweightvol;
  575. /*if ($this->page_largeur < 210) // To work with US executive format
  576. {
  577. $col2x-=20;
  578. }*/
  579. if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  580. else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  581. $useborder = 0;
  582. $index = 0;
  583. $totalWeighttoshow = '';
  584. $totalVolumetoshow = '';
  585. // Load dim data
  586. $tmparray = $object->getTotalWeightVolume();
  587. $totalWeight = $tmparray['weight'];
  588. $totalVolume = $tmparray['volume'];
  589. $totalOrdered = $tmparray['ordered'];
  590. $totalToShip = $tmparray['toship'];
  591. // Set trueVolume and volume_units not currently stored into database
  592. if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  593. {
  594. $object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
  595. $object->volume_units = $object->size_units * 3;
  596. }
  597. if ($totalWeight != '') $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  598. if ($totalVolume != '') $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  599. if ($object->trueWeight) $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  600. if ($object->trueVolume) $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  601. if ($this->getColumnStatus('desc'))
  602. {
  603. $this->printStdColumnContent($pdf, $tab2_top, 'desc', $outputlangs->transnoentities("Total"));
  604. }
  605. if ($this->getColumnStatus('weight'))
  606. {
  607. if ($totalWeighttoshow)
  608. {
  609. $this->printStdColumnContent($pdf, $tab2_top, 'weight', $totalWeighttoshow);
  610. $index++;
  611. }
  612. if ($totalVolumetoshow)
  613. {
  614. $y = $tab2_top + ($tab2_hl * $index);
  615. $this->printStdColumnContent($pdf, $y, 'weight', $totalVolumetoshow);
  616. }
  617. }
  618. if ($this->getColumnStatus('qty_asked') && $totalOrdered)
  619. {
  620. $this->printStdColumnContent($pdf, $tab2_top, 'qty_asked', $totalOrdered);
  621. }
  622. if ($this->getColumnStatus('qty_shipped') && $totalToShip)
  623. {
  624. $this->printStdColumnContent($pdf, $tab2_top, 'qty_shipped', $totalToShip);
  625. }
  626. if ($this->getColumnStatus('subprice'))
  627. {
  628. $this->printStdColumnContent($pdf, $tab2_top, 'subprice', price($object->total_ht, 0, $outputlangs));
  629. }
  630. $pdf->SetTextColor(0, 0, 0);
  631. return ($tab2_top + ($tab2_hl * $index));
  632. }
  633. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  634. /**
  635. * Show table for lines
  636. *
  637. * @param PDF $pdf Object PDF
  638. * @param string $tab_top Top position of table
  639. * @param string $tab_height Height of table (rectangle)
  640. * @param int $nexY Y
  641. * @param Translate $outputlangs Langs object
  642. * @param int $hidetop Hide top bar of array
  643. * @param int $hidebottom Hide bottom bar of array
  644. * @return void
  645. */
  646. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  647. {
  648. global $conf;
  649. // Force to disable hidetop and hidebottom
  650. $hidebottom = 0;
  651. if ($hidetop) $hidetop = -1;
  652. $currency = !empty($currency) ? $currency : $conf->currency;
  653. $default_font_size = pdf_getPDFFontSize($outputlangs);
  654. // Amount in (at tab_top - 1)
  655. $pdf->SetTextColor(0, 0, 0);
  656. $pdf->SetFont('', '', $default_font_size - 2);
  657. if (empty($hidetop))
  658. {
  659. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  660. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  661. $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));
  662. }
  663. }
  664. $pdf->SetDrawColor(128, 128, 128);
  665. $pdf->SetFont('', '', $default_font_size - 1);
  666. // Output Rect
  667. $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
  668. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  669. if (empty($hidetop)) {
  670. $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
  671. }
  672. }
  673. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  674. /**
  675. * Show top header of page.
  676. *
  677. * @param PDF $pdf Object PDF
  678. * @param Object $object Object to show
  679. * @param int $showaddress 0=no, 1=yes
  680. * @param Translate $outputlangs Object lang for output
  681. * @return void
  682. */
  683. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  684. {
  685. global $conf, $langs, $mysoc;
  686. $langs->load("orders");
  687. $default_font_size = pdf_getPDFFontSize($outputlangs);
  688. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  689. // Show Draft Watermark
  690. if ($object->statut == 0 && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK)))
  691. {
  692. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
  693. }
  694. //Prepare next
  695. $pdf->SetTextColor(0, 0, 60);
  696. $pdf->SetFont('', 'B', $default_font_size + 3);
  697. $w = 110;
  698. $posy = $this->marge_haute;
  699. $posx = $this->page_largeur - $this->marge_droite - $w;
  700. $pdf->SetXY($this->marge_gauche, $posy);
  701. // Logo
  702. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  703. if ($this->emetteur->logo)
  704. {
  705. if (is_readable($logo))
  706. {
  707. $height = pdf_getHeightForLogo($logo);
  708. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  709. }
  710. else
  711. {
  712. $pdf->SetTextColor(200, 0, 0);
  713. $pdf->SetFont('', 'B', $default_font_size - 2);
  714. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  715. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  716. }
  717. }
  718. else
  719. {
  720. $text = $this->emetteur->name;
  721. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  722. }
  723. // Show barcode
  724. if (!empty($conf->barcode->enabled))
  725. {
  726. $posx = 105;
  727. }
  728. else
  729. {
  730. $posx = $this->marge_gauche + 3;
  731. }
  732. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  733. if (!empty($conf->barcode->enabled))
  734. {
  735. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  736. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  737. //$pdf->Image($logo,10, 5, 0, 24);
  738. }
  739. $pdf->SetDrawColor(128, 128, 128);
  740. if (!empty($conf->barcode->enabled))
  741. {
  742. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  743. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  744. //$pdf->Image($logo,10, 5, 0, 24);
  745. }
  746. $posx = $this->page_largeur - $w - $this->marge_droite;
  747. $posy = $this->marge_haute;
  748. $pdf->SetFont('', 'B', $default_font_size + 2);
  749. $pdf->SetXY($posx, $posy);
  750. $pdf->SetTextColor(0, 0, 60);
  751. $title = $outputlangs->transnoentities("SendingSheet");
  752. $pdf->MultiCell($w, 4, $title, '', 'R');
  753. $pdf->SetFont('', '', $default_font_size + 1);
  754. $posy += 5;
  755. $pdf->SetXY($posx, $posy);
  756. $pdf->SetTextColor(0, 0, 60);
  757. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending")." : ".$object->ref, '', 'R');
  758. // Date planned delivery
  759. if (!empty($object->date_delivery))
  760. {
  761. $posy += 4;
  762. $pdf->SetXY($posx, $posy);
  763. $pdf->SetTextColor(0, 0, 60);
  764. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
  765. }
  766. if (!empty($object->thirdparty->code_client))
  767. {
  768. $posy += 4;
  769. $pdf->SetXY($posx, $posy);
  770. $pdf->SetTextColor(0, 0, 60);
  771. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  772. }
  773. $pdf->SetFont('', '', $default_font_size + 3);
  774. $Yoff = 25;
  775. // Add list of linked orders
  776. $origin = $object->origin;
  777. $origin_id = $object->origin_id;
  778. // TODO move to external function
  779. if (!empty($conf->$origin->enabled)) // commonly $origin='commande'
  780. {
  781. $outputlangs->load('orders');
  782. $classname = ucfirst($origin);
  783. $linkedobject = new $classname($this->db);
  784. $result = $linkedobject->fetch($origin_id);
  785. if ($result >= 0)
  786. {
  787. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  788. $pdf->SetFont('', '', $default_font_size - 2);
  789. $text = $linkedobject->ref;
  790. if ($linkedobject->ref_client) $text .= ' ('.$linkedobject->ref_client.')';
  791. $Yoff = $Yoff + 8;
  792. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  793. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
  794. $Yoff = $Yoff + 3;
  795. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  796. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  797. }
  798. }
  799. if ($showaddress)
  800. {
  801. // Sender properties
  802. $carac_emetteur = '';
  803. // Add internal contact of origin element if defined
  804. $arrayidcontact = array();
  805. if (!empty($origin) && is_object($object->$origin)) $arrayidcontact = $object->$origin->getIdContact('internal', 'SALESREPFOLL');
  806. if (is_array($arrayidcontact) && count($arrayidcontact) > 0)
  807. {
  808. $object->fetch_user(reset($arrayidcontact));
  809. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  810. }
  811. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  812. // Show sender
  813. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  814. $posx = $this->marge_gauche;
  815. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
  816. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  817. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  818. // Show sender frame
  819. $pdf->SetTextColor(0, 0, 0);
  820. $pdf->SetFont('', '', $default_font_size - 2);
  821. $pdf->SetXY($posx, $posy - 5);
  822. $pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
  823. $pdf->SetXY($posx, $posy);
  824. $pdf->SetFillColor(230, 230, 230);
  825. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  826. $pdf->SetTextColor(0, 0, 60);
  827. $pdf->SetFillColor(255, 255, 255);
  828. // Show sender name
  829. $pdf->SetXY($posx + 2, $posy + 3);
  830. $pdf->SetFont('', 'B', $default_font_size);
  831. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  832. $posy = $pdf->getY();
  833. // Show sender information
  834. $pdf->SetXY($posx + 2, $posy);
  835. $pdf->SetFont('', '', $default_font_size - 1);
  836. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
  837. // If SHIPPING contact defined, we use it
  838. $usecontact = false;
  839. $arrayidcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  840. if (count($arrayidcontact) > 0)
  841. {
  842. $usecontact = true;
  843. $result = $object->fetch_contact($arrayidcontact[0]);
  844. }
  845. //Recipient name
  846. // You can use the name of the contact company
  847. if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  848. $thirdparty = $object->contact;
  849. } else {
  850. $thirdparty = $object->thirdparty;
  851. }
  852. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  853. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  854. // Show recipient
  855. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  856. if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
  857. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  858. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  859. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
  860. // Show recipient frame
  861. $pdf->SetTextColor(0, 0, 0);
  862. $pdf->SetFont('', '', $default_font_size - 2);
  863. $pdf->SetXY($posx + 2, $posy - 5);
  864. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
  865. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  866. // Show recipient name
  867. $pdf->SetXY($posx + 2, $posy + 3);
  868. $pdf->SetFont('', 'B', $default_font_size);
  869. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
  870. $posy = $pdf->getY();
  871. // Show recipient information
  872. $pdf->SetFont('', '', $default_font_size - 1);
  873. $pdf->SetXY($posx + 2, $posy);
  874. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  875. }
  876. $pdf->SetTextColor(0, 0, 0);
  877. }
  878. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  879. /**
  880. * Show footer of page. Need this->emetteur object
  881. *
  882. * @param PDF $pdf PDF
  883. * @param Object $object Object to show
  884. * @param Translate $outputlangs Object lang for output
  885. * @param int $hidefreetext 1=Hide free text
  886. * @return int Return height of bottom margin including footer text
  887. */
  888. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  889. {
  890. global $conf;
  891. $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  892. return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  893. }
  894. /**
  895. * Define Array Column Field
  896. *
  897. * @param object $object common object
  898. * @param Translate $outputlangs langs
  899. * @param int $hidedetails Do not show line details
  900. * @param int $hidedesc Do not show desc
  901. * @param int $hideref Do not show ref
  902. * @return null
  903. */
  904. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  905. {
  906. global $conf, $hookmanager;
  907. // Default field style for content
  908. $this->defaultContentsFieldsStyle = array(
  909. 'align' => 'R', // R,C,L
  910. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  911. );
  912. // Default field style for content
  913. $this->defaultTitlesFieldsStyle = array(
  914. 'align' => 'C', // R,C,L
  915. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  916. );
  917. /*
  918. * For exemple
  919. $this->cols['theColKey'] = array(
  920. 'rank' => $rank, // int : use for ordering columns
  921. 'width' => 20, // the column width in mm
  922. 'title' => array(
  923. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  924. 'label' => ' ', // the final label : used fore final generated text
  925. 'align' => 'L', // text alignement : R,C,L
  926. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  927. ),
  928. 'content' => array(
  929. 'align' => 'L', // text alignement : R,C,L
  930. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  931. ),
  932. );
  933. */
  934. $rank = 0; // do not use negative rank
  935. $this->cols['desc'] = array(
  936. 'rank' => $rank,
  937. 'width' => false, // only for desc
  938. 'status' => true,
  939. 'title' => array(
  940. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  941. 'align' => 'L',
  942. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  943. // 'label' => ' ', // the final label
  944. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  945. ),
  946. 'content' => array(
  947. 'align' => 'L',
  948. ),
  949. );
  950. $rank = $rank + 10;
  951. $this->cols['photo'] = array(
  952. 'rank' => $rank,
  953. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  954. 'status' => false,
  955. 'title' => array(
  956. 'textkey' => 'Photo',
  957. 'label' => ' '
  958. ),
  959. 'content' => array(
  960. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  961. ),
  962. 'border-left' => false, // remove left line separator
  963. );
  964. if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
  965. {
  966. $this->cols['photo']['status'] = true;
  967. }
  968. $rank = $rank + 10;
  969. $this->cols['weight'] = array(
  970. 'rank' => $rank,
  971. 'width' => 30, // in mm
  972. 'status' => true,
  973. 'title' => array(
  974. 'textkey' => 'WeightVolShort'
  975. ),
  976. 'border-left' => true, // add left line separator
  977. );
  978. $rank = $rank + 10;
  979. $this->cols['subprice'] = array(
  980. 'rank' => $rank,
  981. 'width' => 19, // in mm
  982. 'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT) ? 1 : 0,
  983. 'title' => array(
  984. 'textkey' => 'PriceUHT'
  985. ),
  986. 'border-left' => true, // add left line separator
  987. );
  988. $rank = $rank + 10;
  989. $this->cols['totalexcltax'] = array(
  990. 'rank' => $rank,
  991. 'width' => 26, // in mm
  992. 'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT) ? 1 : 0,
  993. 'title' => array(
  994. 'textkey' => 'TotalHT'
  995. ),
  996. 'border-left' => true, // add left line separator
  997. );
  998. $rank = $rank + 10;
  999. $this->cols['qty_asked'] = array(
  1000. 'rank' => $rank,
  1001. 'width' => 30, // in mm
  1002. 'status' => empty($conf->global->SHIPPING_PDF_HIDE_ORDERED) ? 1 : 0,
  1003. 'title' => array(
  1004. 'textkey' => 'QtyOrdered'
  1005. ),
  1006. 'border-left' => true, // add left line separator
  1007. 'content' => array(
  1008. 'align' => 'C',
  1009. ),
  1010. );
  1011. $rank = $rank + 10;
  1012. $this->cols['qty_shipped'] = array(
  1013. 'rank' => $rank,
  1014. 'width' => 30, // in mm
  1015. 'status' => true,
  1016. 'title' => array(
  1017. 'textkey' => 'QtyToShip'
  1018. ),
  1019. 'border-left' => true, // add left line separator
  1020. 'content' => array(
  1021. 'align' => 'C',
  1022. ),
  1023. );
  1024. $parameters = array(
  1025. 'object' => $object,
  1026. 'outputlangs' => $outputlangs,
  1027. 'hidedetails' => $hidedetails,
  1028. 'hidedesc' => $hidedesc,
  1029. 'hideref' => $hideref
  1030. );
  1031. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1032. if ($reshook < 0)
  1033. {
  1034. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1035. }
  1036. elseif (empty($reshook))
  1037. {
  1038. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1039. }
  1040. else
  1041. {
  1042. $this->cols = $hookmanager->resArray;
  1043. }
  1044. }
  1045. }