pdf_merou.modules.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  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_merou.modules.php
  24. * \ingroup expedition
  25. * \brief Class file used to generate the dispatch slips for the Merou model
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  31. /**
  32. * Class to build sending documents with model Merou
  33. */
  34. class pdf_merou extends ModelePdfExpedition
  35. {
  36. /**
  37. * @var DoliDb Database handler
  38. */
  39. public $db;
  40. /**
  41. * @var string model name
  42. */
  43. public $name;
  44. /**
  45. * @var string model description (short text)
  46. */
  47. public $description;
  48. /**
  49. * @var string document type
  50. */
  51. public $type;
  52. /**
  53. * @var array Minimum version of PHP required by module.
  54. * e.g.: PHP ≥ 5.5 = array(5, 5)
  55. */
  56. public $phpmin = array(5, 5);
  57. /**
  58. * Dolibarr version of the loaded document
  59. * @var string
  60. */
  61. public $version = 'dolibarr';
  62. /**
  63. * @var int page_largeur
  64. */
  65. public $page_largeur;
  66. /**
  67. * @var int page_hauteur
  68. */
  69. public $page_hauteur;
  70. /**
  71. * @var array format
  72. */
  73. public $format;
  74. /**
  75. * @var int marge_gauche
  76. */
  77. public $marge_gauche;
  78. /**
  79. * @var int marge_droite
  80. */
  81. public $marge_droite;
  82. /**
  83. * @var int marge_haute
  84. */
  85. public $marge_haute;
  86. /**
  87. * @var int marge_basse
  88. */
  89. public $marge_basse;
  90. /**
  91. * Issuer
  92. * @var Societe
  93. */
  94. public $emetteur;
  95. /**
  96. * Constructor
  97. *
  98. * @param DoliDB $db Database handler
  99. */
  100. public function __construct($db = 0)
  101. {
  102. global $conf, $langs, $mysoc;
  103. $this->db = $db;
  104. $this->name = "merou";
  105. $this->description = $langs->trans("DocumentModelMerou");
  106. $this->type = 'pdf';
  107. $formatarray = pdf_getFormat();
  108. $this->page_largeur = $formatarray['width'];
  109. $this->page_hauteur = round($formatarray['height'] / 2);
  110. $this->format = array($this->page_largeur, $this->page_hauteur);
  111. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  112. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  113. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  114. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  115. $this->option_logo = 1; // Display logo
  116. // Get source company
  117. $this->emetteur = $mysoc;
  118. if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  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, $mysoc, $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 ($conf->expedition->dir_output)
  143. {
  144. $object->fetch_thirdparty();
  145. $origin = $object->origin;
  146. //Create sender
  147. $this->expediteur = $mysoc;
  148. //Create recipient
  149. $idcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  150. $this->destinataire = new Contact($this->db);
  151. if (!empty($idcontact[0])) $this->destinataire->fetch($idcontact[0]);
  152. //Create deliverer
  153. $idcontact = $object->$origin->getIdContact('internal', 'LIVREUR');
  154. $this->livreur = new User($this->db);
  155. if (!empty($idcontact[0])) $this->livreur->fetch($idcontact[0]);
  156. // Definition of $dir and $file
  157. if ($object->specimen)
  158. {
  159. $dir = $conf->expedition->dir_output."/sending";
  160. $file = $dir."/SPECIMEN.pdf";
  161. }
  162. else
  163. {
  164. $expref = dol_sanitizeFileName($object->ref);
  165. $dir = $conf->expedition->dir_output."/sending/".$expref;
  166. $file = $dir."/".$expref.".pdf";
  167. }
  168. if (!file_exists($dir))
  169. {
  170. if (dol_mkdir($dir) < 0)
  171. {
  172. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  173. return 0;
  174. }
  175. }
  176. if (file_exists($dir))
  177. {
  178. // Add pdfgeneration hook
  179. if (!is_object($hookmanager))
  180. {
  181. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  182. $hookmanager = new HookManager($this->db);
  183. }
  184. $hookmanager->initHooks(array('pdfgeneration'));
  185. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  186. global $action;
  187. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  188. $nblines = count($object->lines);
  189. $pdf = pdf_getInstance($this->format, 'mm', 'l');
  190. $default_font_size = pdf_getPDFFontSize($outputlangs);
  191. $heightforinfotot = 0; // Height reserved to output the info and total part
  192. $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
  193. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  194. if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
  195. $pdf->SetAutoPageBreak(1, 0);
  196. if (class_exists('TCPDF'))
  197. {
  198. $pdf->setPrintHeader(false);
  199. $pdf->setPrintFooter(false);
  200. }
  201. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  202. // Set path to the background PDF File
  203. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  204. {
  205. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  206. $tplidx = $pdf->importPage(1);
  207. }
  208. $pdf->Open();
  209. $pagenb = 0;
  210. $pdf->SetDrawColor(128, 128, 128);
  211. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  212. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  213. $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
  214. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  215. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  216. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
  217. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  218. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  219. // New page
  220. $pdf->AddPage();
  221. $pagenb++;
  222. $this->_pagehead($pdf, $object, 1, $outputlangs);
  223. $pdf->SetFont('', '', $default_font_size - 3);
  224. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  225. $pdf->SetTextColor(0, 0, 0);
  226. $tab_top = 52;
  227. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  228. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter;
  229. $tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter;
  230. // Display notes
  231. if (!empty($object->note_public))
  232. {
  233. $pdf->SetFont('', '', $default_font_size - 1);
  234. $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
  235. $nexY = $pdf->GetY();
  236. $height_note = $nexY - $tab_top;
  237. // Rect takes a length in 3rd parameter
  238. $pdf->SetDrawColor(192, 192, 192);
  239. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  240. $tab_height = $tab_height - $height_note;
  241. $tab_top = $nexY + 6;
  242. }
  243. else
  244. {
  245. $height_note = 0;
  246. }
  247. $pdf->SetFillColor(240, 240, 240);
  248. $pdf->SetTextColor(0, 0, 0);
  249. $pdf->SetXY(10, $tab_top + 5);
  250. $iniY = $tab_top + 7;
  251. $curY = $tab_top + 7;
  252. $nexY = $tab_top + 7;
  253. $num = count($object->lines);
  254. // Loop on each lines
  255. for ($i = 0; $i < $num; $i++)
  256. {
  257. $curY = $nexY;
  258. $pdf->SetFont('', '', $default_font_size - 3);
  259. $pdf->SetTextColor(0, 0, 0);
  260. $pdf->setTopMargin($tab_top_newpage);
  261. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  262. $pageposbefore = $pdf->getPage();
  263. // Description of product line
  264. $libelleproduitservice = pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
  265. $nexY = $pdf->GetY();
  266. $pageposafter = $pdf->getPage();
  267. $pdf->setPage($pageposbefore);
  268. $pdf->setTopMargin($this->marge_haute);
  269. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  270. // We suppose that a too long description is moved completely on next page
  271. if ($pageposafter > $pageposbefore) {
  272. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  273. }
  274. $pdf->SetFont('', '', $default_font_size - 3);
  275. // Check boxes
  276. $pdf->SetDrawColor(120, 120, 120);
  277. $pdf->Rect(10 + 3, $curY, 3, 3);
  278. $pdf->Rect(20 + 3, $curY, 3, 3);
  279. //Inserting the product reference
  280. $pdf->SetXY(30, $curY);
  281. $pdf->SetFont('', 'B', $default_font_size - 3);
  282. $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
  283. $pdf->SetXY(140, $curY);
  284. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
  285. $pdf->SetXY(170, $curY);
  286. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
  287. // Add line
  288. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
  289. {
  290. $pdf->setPage($pageposafter);
  291. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  292. //$pdf->SetDrawColor(190,190,200);
  293. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  294. $pdf->SetLineStyle(array('dash'=>0));
  295. }
  296. $nexY += 2; // Add space between lines
  297. // Detect if some page were added automatically and output _tableau for past pages
  298. while ($pagenb < $pageposafter)
  299. {
  300. $pdf->setPage($pagenb);
  301. if ($pagenb == 1)
  302. {
  303. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  304. }
  305. else
  306. {
  307. $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  308. }
  309. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  310. $pagenb++;
  311. $pdf->setPage($pagenb);
  312. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  313. }
  314. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
  315. {
  316. if ($pagenb == 1)
  317. {
  318. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  319. }
  320. else
  321. {
  322. $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  323. }
  324. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  325. // New page
  326. $pdf->AddPage();
  327. $pagenb++;
  328. }
  329. }
  330. // Show square
  331. if ($pagenb == 1)
  332. {
  333. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  334. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  335. }
  336. else
  337. {
  338. $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  339. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  340. }
  341. // Pagefoot
  342. $this->_pagefoot($pdf, $object, $outputlangs);
  343. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  344. $pdf->Close();
  345. $pdf->Output($file, 'F');
  346. // Add pdfgeneration hook
  347. if (!is_object($hookmanager))
  348. {
  349. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  350. $hookmanager = new HookManager($this->db);
  351. }
  352. $hookmanager->initHooks(array('pdfgeneration'));
  353. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  354. global $action;
  355. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  356. if ($reshook < 0)
  357. {
  358. $this->error = $hookmanager->error;
  359. $this->errors = $hookmanager->errors;
  360. }
  361. if (!empty($conf->global->MAIN_UMASK))
  362. @chmod($file, octdec($conf->global->MAIN_UMASK));
  363. $this->result = array('fullpath'=>$file);
  364. return 1;
  365. }
  366. else
  367. {
  368. $this->error = $outputlangs->transnoentities("ErrorCanNotCreateDir", $dir);
  369. return 0;
  370. }
  371. }
  372. else
  373. {
  374. $this->error = $outputlangs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  375. return 0;
  376. }
  377. }
  378. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  379. /**
  380. * Show table for lines
  381. *
  382. * @param PDF $pdf Object PDF
  383. * @param string $tab_top Top position of table
  384. * @param string $tab_height Height of table (rectangle)
  385. * @param int $nexY Y
  386. * @param Translate $outputlangs Langs object
  387. * @param int $hidetop Hide top bar of array
  388. * @param int $hidebottom Hide bottom bar of array
  389. * @return void
  390. */
  391. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  392. {
  393. global $langs;
  394. $default_font_size = pdf_getPDFFontSize($outputlangs);
  395. // Translations
  396. $langs->loadLangs(array("main", "bills"));
  397. if (empty($hidetop))
  398. {
  399. $pdf->SetFont('', 'B', $default_font_size - 2);
  400. $pdf->SetXY(10, $tab_top);
  401. $pdf->MultiCell(10, 5, "LS", 0, 'C', 1);
  402. $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
  403. $pdf->SetXY(20, $tab_top);
  404. $pdf->MultiCell(10, 5, "LR", 0, 'C', 1);
  405. $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
  406. $pdf->SetXY(30, $tab_top);
  407. $pdf->MultiCell(20, 5, $outputlangs->transnoentities("Ref"), 0, 'C', 1);
  408. $pdf->SetXY(50, $tab_top);
  409. $pdf->MultiCell(90, 5, $outputlangs->transnoentities("Description"), 0, 'L', 1);
  410. $pdf->SetXY(140, $tab_top);
  411. $pdf->MultiCell(30, 5, $outputlangs->transnoentities("QtyOrdered"), 0, 'C', 1);
  412. $pdf->SetXY(170, $tab_top);
  413. $pdf->MultiCell(30, 5, $outputlangs->transnoentities("QtyToShip"), 0, 'C', 1);
  414. }
  415. $pdf->Rect(10, $tab_top, 190, $tab_height);
  416. }
  417. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  418. /**
  419. * Show footer of page. Need this->emetteur object
  420. *
  421. * @param PDF $pdf PDF
  422. * @param Object $object Object to show
  423. * @param Translate $outputlangs Object lang for output
  424. * @param int $hidefreetext 1=Hide free text
  425. * @return void
  426. */
  427. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  428. {
  429. $default_font_size = pdf_getPDFFontSize($outputlangs);
  430. $pdf->SetFont('', '', $default_font_size - 2);
  431. $pdf->SetY(-23);
  432. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("GoodStatusDeclaration"), 0, 'L');
  433. $pdf->SetY(-13);
  434. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToAndDate"), 0, 'C');
  435. $pdf->SetXY(120, -23);
  436. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("NameAndSignature"), 0, 'C');
  437. // Show page nb only on iso languages (so default Helvetica font)
  438. //if (pdf_getPDFFont($outputlangs) == 'Helvetica')
  439. //{
  440. // $pdf->SetXY(-10,-10);
  441. // $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  442. //}
  443. }
  444. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  445. /**
  446. * Show top header of page.
  447. *
  448. * @param PDF $pdf Object PDF
  449. * @param Object $object Object to show
  450. * @param int $showaddress 0=no, 1=yes
  451. * @param Translate $outputlangs Object lang for output
  452. * @return void
  453. */
  454. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  455. {
  456. global $conf, $langs, $hookmanager;
  457. $default_font_size = pdf_getPDFFontSize($outputlangs);
  458. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  459. //Affiche le filigrane brouillon - Print Draft Watermark
  460. if ($object->statut == 0 && (!empty($conf->global->SENDING_DRAFT_WATERMARK)))
  461. {
  462. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SENDING_DRAFT_WATERMARK);
  463. }
  464. $posy = $this->marge_haute;
  465. $posx = $this->page_largeur - $this->marge_droite - 100;
  466. $Xoff = 90;
  467. $Yoff = 0;
  468. $tab4_top = 60;
  469. $tab4_hl = 6;
  470. $tab4_sl = 4;
  471. $line = 2;
  472. //*********************LOGO****************************
  473. $pdf->SetXY(11, 7);
  474. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  475. if ($this->emetteur->logo)
  476. {
  477. if (is_readable($logo))
  478. {
  479. $height = pdf_getHeightForLogo($logo);
  480. $pdf->Image($logo, 10, 5, 0, $height); // width=0 (auto)
  481. }
  482. else
  483. {
  484. $pdf->SetTextColor(200, 0, 0);
  485. $pdf->SetFont('', 'B', $default_font_size - 2);
  486. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  487. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  488. }
  489. }
  490. else
  491. {
  492. $text = $this->emetteur->name;
  493. $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0, 'L');
  494. }
  495. //*********************Entete****************************
  496. //Document name
  497. $pdf->SetXY($Xoff, 7);
  498. $pdf->SetFont('', 'B', $default_font_size + 2);
  499. $pdf->SetTextColor(0, 0, 0);
  500. $pdf->MultiCell(0, 3, $outputlangs->transnoentities("SendingSheet"), '', 'L'); // Sending sheet
  501. //Num Expedition
  502. $Yoff = $Yoff + 7;
  503. $Xoff = 142;
  504. //$pdf->Rect($Xoff, $Yoff, 85, 8);
  505. $pdf->SetXY($Xoff, $Yoff);
  506. $pdf->SetFont('', '', $default_font_size - 2);
  507. $pdf->SetTextColor(0, 0, 0);
  508. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($object->ref), '', 'R');
  509. //$this->Code39($Xoff+43, $Yoff+1, $object->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
  510. $origin = $object->origin;
  511. $origin_id = $object->origin_id;
  512. // Add list of linked elements
  513. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size - 1, $hookmanager);
  514. //$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
  515. //Definition Location of the Company block
  516. $Xoff = 110;
  517. $blSocX = 90;
  518. $blSocY = 24;
  519. $blSocW = 50;
  520. $blSocX2 = $blSocW + $blSocX;
  521. // Sender name
  522. $pdf->SetTextColor(0, 0, 0);
  523. $pdf->SetFont('', 'B', $default_font_size - 3);
  524. $pdf->SetXY($blSocX, $blSocY + 1);
  525. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  526. $pdf->SetTextColor(0, 0, 0);
  527. // Sender properties
  528. $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  529. $pdf->SetFont('', '', $default_font_size - 3);
  530. $pdf->SetXY($blSocX, $blSocY + 4);
  531. $pdf->MultiCell(80, 2, $carac_emetteur, 0, 'L');
  532. if ($object->thirdparty->code_client)
  533. {
  534. $Yoff += 3;
  535. $posy = $Yoff;
  536. $pdf->SetXY($Xoff, $posy);
  537. $pdf->SetTextColor(0, 0, 0);
  538. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $Xoff, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  539. }
  540. // Date delivery
  541. $Yoff = $Yoff + 7;
  542. $pdf->SetXY($blSocX - 80, $blSocY + 17);
  543. $pdf->SetFont('', 'B', $default_font_size - 3);
  544. $pdf->SetTextColor(0, 0, 0);
  545. $pdf->MultiCell(50, 8, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, 'day', false, $outputlangs, true), '', 'L');
  546. $pdf->SetXY($blSocX - 80, $blSocY + 20);
  547. $pdf->SetFont('', 'B', $default_font_size - 3);
  548. $pdf->SetTextColor(0, 0, 0);
  549. $pdf->MultiCell(50, 8, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, '', 'L');
  550. // Deliverer
  551. $pdf->SetXY($blSocX - 80, $blSocY + 23);
  552. $pdf->SetFont('', '', $default_font_size - 3);
  553. $pdf->SetTextColor(0, 0, 0);
  554. if (!empty($object->tracking_number))
  555. {
  556. $object->getUrlTrackingStatus($object->tracking_number);
  557. if (!empty($object->tracking_url))
  558. {
  559. if ($object->shipping_method_id > 0)
  560. {
  561. // Get code using getLabelFromKey
  562. $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  563. $label = '';
  564. $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
  565. //var_dump($object->tracking_url != $object->tracking_number);exit;
  566. if ($object->tracking_url != $object->tracking_number)
  567. {
  568. $label .= " : ";
  569. $label .= $object->tracking_url;
  570. }
  571. $pdf->SetFont('', 'B', $default_font_size - 3);
  572. $pdf->writeHTMLCell(50, 8, '', '', $label, '', 'L');
  573. }
  574. }
  575. }
  576. else
  577. {
  578. $pdf->MultiCell(50, 8, $outputlangs->transnoentities("Deliverer")." ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)), '', 'L');
  579. }
  580. // Shipping company (My Company)
  581. $Yoff = $blSocY;
  582. $blExpX = $Xoff - 20;
  583. $blW = 52;
  584. $Ydef = $Yoff;
  585. $pdf->Rect($blExpX, $Yoff, $blW, 26);
  586. $object->fetch_thirdparty();
  587. // If SHIPPING contact defined on order, we use it
  588. $usecontact = false;
  589. $arrayidcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  590. if (count($arrayidcontact) > 0)
  591. {
  592. $usecontact = true;
  593. $result = $object->fetch_contact($arrayidcontact[0]);
  594. }
  595. // Recipient name
  596. // You can use the name of the contact company
  597. if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  598. $thirdparty = $object->contact;
  599. } else {
  600. $thirdparty = $object->thirdparty;
  601. }
  602. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  603. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  604. $blDestX = $blExpX + 55;
  605. $blW = 54;
  606. $Yoff = $Ydef + 1;
  607. // Show Recipient frame
  608. $pdf->SetFont('', 'B', $default_font_size - 3);
  609. $pdf->SetXY($blDestX, $Yoff - 4);
  610. $pdf->MultiCell($blW, 3, $outputlangs->transnoentities("Recipient"), 0, 'L');
  611. $pdf->Rect($blDestX, $Yoff - 1, $blW, 26);
  612. // Show recipient name
  613. $pdf->SetFont('', 'B', $default_font_size - 3);
  614. $pdf->SetXY($blDestX, $Yoff);
  615. $pdf->MultiCell($blW, 3, $carac_client_name, 0, 'L');
  616. $posy = $pdf->getY();
  617. // Show recipient information
  618. $pdf->SetFont('', '', $default_font_size - 3);
  619. $pdf->SetXY($blDestX, $posy);
  620. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  621. }
  622. }