pdf_espadon.modules.php 46 KB

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