pdf_merou.modules.php 25 KB

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