pdf_espadon.modules.php 46 KB

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