pdf_squille.modules.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. <?php
  2. /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/reception/doc/pdf_squille.modules.php
  20. * \ingroup reception
  21. * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Squille
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  26. /**
  27. * Classe permettant de generer les borderaux envoi au modele Squille
  28. */
  29. class pdf_squille extends ModelePdfReception
  30. {
  31. public $emetteur; // Objet societe qui emet
  32. /**
  33. * Constructor
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. public function __construct($db = 0)
  38. {
  39. global $conf,$langs,$mysoc;
  40. $this->db = $db;
  41. $this->name = "squille";
  42. $this->description = $langs->trans("DocumentModelStandardPDF");
  43. $this->type = 'pdf';
  44. $formatarray=pdf_getFormat();
  45. $this->page_largeur = $formatarray['width'];
  46. $this->page_hauteur = $formatarray['height'];
  47. $this->format = array($this->page_largeur,$this->page_hauteur);
  48. $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  49. $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  50. $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  51. $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  52. $this->option_logo = 1;
  53. // Get source company
  54. $this->emetteur=$mysoc;
  55. if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang, -2); // By default if not defined
  56. // Define position of columns
  57. $this->posxdesc=$this->marge_gauche+1;
  58. $this->posxweightvol=$this->page_largeur - $this->marge_droite - 78;
  59. $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56;
  60. $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28;
  61. $this->posxpuht=$this->page_largeur - $this->marge_droite;
  62. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  63. $this->posxweightvol=$this->page_largeur - $this->marge_droite - 118;
  64. $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 96;
  65. $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 68;
  66. $this->posxpuht=$this->page_largeur - $this->marge_droite - 40;
  67. $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20;
  68. }
  69. $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
  70. if ($this->page_largeur < 210) // To work with US executive format
  71. {
  72. $this->posxweightvol-=20;
  73. $this->posxpicture-=20;
  74. $this->posxqtyordered-=20;
  75. $this->posxqtytoship-=20;
  76. }
  77. if (! empty($conf->global->RECEPTION_PDF_HIDE_ORDERED))
  78. {
  79. $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
  80. $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
  81. $this->posxqtyordered = $this->posxqtytoship;
  82. }
  83. }
  84. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  85. /**
  86. * Function to build pdf onto disk
  87. *
  88. * @param Object $object Object reception to generate (or id if old method)
  89. * @param Translate $outputlangs Lang output object
  90. * @param string $srctemplatepath Full path of source filename for generator using a template file
  91. * @param int $hidedetails Do not show line details
  92. * @param int $hidedesc Do not show desc
  93. * @param int $hideref Do not show ref
  94. * @return int 1=OK, 0=KO
  95. */
  96. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  97. {
  98. // phpcs:enable
  99. global $user,$conf,$langs,$hookmanager;
  100. $object->fetch_thirdparty();
  101. if (! is_object($outputlangs)) $outputlangs=$langs;
  102. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  103. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  104. $outputlangs->loadLangs(array("main","dict","companies","bills","products","propal","deliveries","receptions","productbatch","sendings"));
  105. $nblines = count($object->lines);
  106. // Loop on each lines to detect if there is at least one image to show
  107. $realpatharray=array();
  108. if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE))
  109. {
  110. $objphoto = new Product($this->db);
  111. for ($i = 0 ; $i < $nblines ; $i++)
  112. {
  113. if (empty($object->lines[$i]->fk_product)) continue;
  114. $objphoto = new Product($this->db);
  115. $objphoto->fetch($object->lines[$i]->fk_product);
  116. $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product ."/photos/";
  117. $dir = $conf->product->dir_output.'/'.$pdir;
  118. $realpath='';
  119. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  120. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
  121. // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  122. if ($obj['photo_vignette'])
  123. {
  124. $filename= $obj['photo_vignette'];
  125. }
  126. else
  127. {
  128. $filename=$obj['photo'];
  129. }
  130. }
  131. else
  132. {
  133. $filename=$obj['photo'];
  134. }
  135. $realpath = $dir.$filename;
  136. break;
  137. }
  138. if ($realpath) $realpatharray[$i]=$realpath;
  139. }
  140. }
  141. if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol;
  142. if ($conf->reception->dir_output)
  143. {
  144. // Definition de $dir et $file
  145. if ($object->specimen)
  146. {
  147. $dir = $conf->reception->dir_output;
  148. $file = $dir . "/SPECIMEN.pdf";
  149. }
  150. else
  151. {
  152. $rcpref = dol_sanitizeFileName($object->ref);
  153. $dir = $conf->reception->dir_output."/" . $rcpref;
  154. $file = $dir . "/" . $rcpref . ".pdf";
  155. }
  156. if (! file_exists($dir))
  157. {
  158. if (dol_mkdir($dir) < 0)
  159. {
  160. $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
  161. return 0;
  162. }
  163. }
  164. if (file_exists($dir))
  165. {
  166. // Add pdfgeneration hook
  167. if (! is_object($hookmanager))
  168. {
  169. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  170. $hookmanager=new HookManager($this->db);
  171. }
  172. $hookmanager->initHooks(array('pdfgeneration'));
  173. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  174. global $action;
  175. $reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  176. // Set nblines with the new facture lines content after hook
  177. $nblines = count($object->lines);
  178. $pdf=pdf_getInstance($this->format);
  179. $default_font_size = pdf_getPDFFontSize($outputlangs);
  180. $heightforinfotot = 8; // Height reserved to output the info and total part
  181. $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
  182. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  183. $pdf->SetAutoPageBreak(1, 0);
  184. if (class_exists('TCPDF'))
  185. {
  186. $pdf->setPrintHeader(false);
  187. $pdf->setPrintFooter(false);
  188. }
  189. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  190. // Set path to the background PDF File
  191. if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  192. {
  193. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  194. $tplidx = $pdf->importPage(1);
  195. }
  196. $pdf->Open();
  197. $pagenb=0;
  198. $pdf->SetDrawColor(128, 128, 128);
  199. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  200. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  201. $pdf->SetSubject($outputlangs->transnoentities("Reception"));
  202. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  203. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  204. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Reception"));
  205. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  206. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  207. // New page
  208. $pdf->AddPage();
  209. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  210. $pagenb++;
  211. $this->_pagehead($pdf, $object, 1, $outputlangs);
  212. $pdf->SetFont('', '', $default_font_size - 1);
  213. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  214. $pdf->SetTextColor(0, 0, 0);
  215. $tab_top = 90;
  216. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  217. $tab_height = 130;
  218. $tab_height_newpage = 150;
  219. // Incoterm
  220. $height_incoterms = 0;
  221. if ($conf->incoterm->enabled)
  222. {
  223. $desc_incoterms = $object->getIncotermsForPDF();
  224. if ($desc_incoterms)
  225. {
  226. $tab_top = 88;
  227. $pdf->SetFont('', '', $default_font_size - 1);
  228. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  229. $nexY = $pdf->GetY();
  230. $height_incoterms=$nexY-$tab_top;
  231. // Rect takes a length in 3rd parameter
  232. $pdf->SetDrawColor(192, 192, 192);
  233. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
  234. $tab_top = $nexY+6;
  235. $height_incoterms += 4;
  236. }
  237. }
  238. if (! empty($object->note_public) || ! empty($object->tracking_number))
  239. {
  240. $tab_top = 88 + $height_incoterms;
  241. $tab_top_alt = $tab_top;
  242. $pdf->SetFont('', 'B', $default_font_size - 2);
  243. $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L');
  244. $tab_top_alt = $pdf->GetY();
  245. //$tab_top_alt += 1;
  246. // Tracking number
  247. if (! empty($object->tracking_number))
  248. {
  249. $object->getUrlTrackingStatus($object->tracking_number);
  250. if (! empty($object->tracking_url))
  251. {
  252. if ($object->reception_method_id > 0)
  253. {
  254. // Get code using getLabelFromKey
  255. $code=$outputlangs->getLabelFromKey($this->db, $object->shipment_method_id, 'c_shipment_mode', 'rowid', 'code');
  256. $label='';
  257. if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
  258. $label.=$outputlangs->trans("ReceptionMethod").": ".$outputlangs->trans("ReceptionMethod".strtoupper($code));
  259. //var_dump($object->tracking_url != $object->tracking_number);exit;
  260. if ($object->tracking_url != $object->tracking_number)
  261. {
  262. $label.=" : ";
  263. $label.=$object->tracking_url;
  264. }
  265. $pdf->SetFont('', 'B', $default_font_size - 2);
  266. $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L');
  267. $tab_top_alt = $pdf->GetY();
  268. }
  269. }
  270. }
  271. // Notes
  272. if (! empty($object->note_public))
  273. {
  274. $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
  275. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
  276. }
  277. $nexY = $pdf->GetY();
  278. $height_note=$nexY-$tab_top;
  279. // Rect takes a length in 3rd parameter
  280. $pdf->SetDrawColor(192, 192, 192);
  281. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  282. $tab_height = $tab_height - $height_note;
  283. $tab_top = $nexY+6;
  284. }
  285. else
  286. {
  287. $height_note=0;
  288. }
  289. $iniY = $tab_top + 7;
  290. $curY = $tab_top + 7;
  291. $nexY = $tab_top + 7;
  292. $fk_commandefourndet=0;
  293. $totalOrdered=0;
  294. // Loop on each lines
  295. for ($i = 0; $i < $nblines; $i++)
  296. {
  297. $curY = $nexY;
  298. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  299. $pdf->SetTextColor(0, 0, 0);
  300. // Define size of image if we need it
  301. $imglinesize=array();
  302. if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
  303. $pdf->setTopMargin($tab_top_newpage);
  304. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  305. $pageposbefore=$pdf->getPage();
  306. $showpricebeforepagebreak=1;
  307. $posYAfterImage=0;
  308. $posYAfterDescription=0;
  309. // We start with Photo of product line
  310. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page
  311. {
  312. $pdf->AddPage('', '', true);
  313. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  314. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  315. $pdf->setPage($pageposbefore+1);
  316. $curY = $tab_top_newpage;
  317. $showpricebeforepagebreak=0;
  318. }
  319. if (isset($imglinesize['width']) && isset($imglinesize['height']))
  320. {
  321. $curX = $this->posxpicture-1;
  322. $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  323. // $pdf->Image does not increase value return by getY, so we save it manually
  324. $posYAfterImage=$curY+$imglinesize['height'];
  325. }
  326. // Description of product line
  327. $curX = $this->posxdesc-1;
  328. $pdf->startTransaction();
  329. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture-$curX, 3, $curX, $curY, $hideref, $hidedesc);
  330. $pageposafter=$pdf->getPage();
  331. if ($pageposafter > $pageposbefore) // There is a pagebreak
  332. {
  333. $pdf->rollbackTransaction(true);
  334. $pageposafter=$pageposbefore;
  335. //print $pageposafter.'-'.$pageposbefore;exit;
  336. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  337. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture-$curX, 3, $curX, $curY, $hideref, $hidedesc);
  338. $pageposafter=$pdf->getPage();
  339. $posyafter=$pdf->GetY();
  340. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  341. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  342. {
  343. if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
  344. {
  345. $pdf->AddPage('', '', true);
  346. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  347. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  348. $pdf->setPage($pageposafter+1);
  349. }
  350. }
  351. else
  352. {
  353. // We found a page break
  354. $showpricebeforepagebreak=0;
  355. }
  356. }
  357. else // No pagebreak
  358. {
  359. $pdf->commitTransaction();
  360. }
  361. $posYAfterDescription=$pdf->GetY();
  362. $nexY = $pdf->GetY();
  363. $pageposafter=$pdf->getPage();
  364. $pdf->setPage($pageposbefore);
  365. $pdf->setTopMargin($this->marge_haute);
  366. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  367. // We suppose that a too long description or photo were moved completely on next page
  368. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  369. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  370. }
  371. // We suppose that a too long description is moved completely on next page
  372. if ($pageposafter > $pageposbefore) {
  373. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  374. }
  375. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  376. $pdf->SetXY($this->posxweightvol, $curY);
  377. $weighttxt='';
  378. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->weight)
  379. {
  380. $weighttxt=round($object->lines[$i]->product->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->product->weight_units);
  381. }
  382. $voltxt='';
  383. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->volume)
  384. {
  385. $voltxt=round($object->lines[$i]->product->volume * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->product->volume_units?$object->lines[$i]->product->volume_units:0);
  386. }
  387. $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, 0, 0, false, true, 'C');
  388. //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
  389. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  390. $pdf->SetXY($this->posxqtyordered, $curY);
  391. if($object->lines[$i]->fk_commandefourndet!=$fk_commandefourndet){
  392. $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked, '', 'C');
  393. $totalOrdered+=$object->lines[$i]->qty_asked;
  394. }
  395. $fk_commandefourndet = $object->lines[$i]->fk_commandefourndet;
  396. }
  397. $pdf->SetXY($this->posxqtytoship, $curY);
  398. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty, '', 'C');
  399. if(!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT))
  400. {
  401. $pdf->SetXY($this->posxpuht, $curY);
  402. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
  403. $pdf->SetXY($this->posxtotalht, $curY);
  404. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
  405. }
  406. $nexY+=3;
  407. if ($weighttxt && $voltxt) $nexY+=2;
  408. // Add line
  409. if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
  410. {
  411. $pdf->setPage($pageposafter);
  412. $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
  413. //$pdf->SetDrawColor(190,190,200);
  414. $pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1);
  415. $pdf->SetLineStyle(array('dash'=>0));
  416. }
  417. // Detect if some page were added automatically and output _tableau for past pages
  418. while ($pagenb < $pageposafter)
  419. {
  420. $pdf->setPage($pagenb);
  421. if ($pagenb == 1)
  422. {
  423. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  424. }
  425. else
  426. {
  427. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  428. }
  429. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  430. $pagenb++;
  431. $pdf->setPage($pagenb);
  432. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  433. }
  434. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  435. {
  436. if ($pagenb == 1)
  437. {
  438. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  439. }
  440. else
  441. {
  442. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  443. }
  444. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  445. // New page
  446. $pdf->AddPage();
  447. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  448. $pagenb++;
  449. }
  450. }
  451. // Show square
  452. if ($pagenb == 1)
  453. {
  454. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  455. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  456. }
  457. else
  458. {
  459. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  460. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  461. }
  462. // Affiche zone totaux
  463. $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs, $totalOrdered);
  464. // Pied de page
  465. $this->_pagefoot($pdf, $object, $outputlangs);
  466. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  467. $pdf->Close();
  468. $pdf->Output($file, 'F');
  469. // Add pdfgeneration hook
  470. $hookmanager->initHooks(array('pdfgeneration'));
  471. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  472. global $action;
  473. $reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  474. if ($reshook < 0)
  475. {
  476. $this->error = $hookmanager->error;
  477. $this->errors = $hookmanager->errors;
  478. }
  479. if (! empty($conf->global->MAIN_UMASK))
  480. @chmod($file, octdec($conf->global->MAIN_UMASK));
  481. return 1; // No error
  482. }
  483. else
  484. {
  485. $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
  486. return 0;
  487. }
  488. }
  489. else
  490. {
  491. $this->error=$langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  492. return 0;
  493. }
  494. }
  495. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  496. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  497. /**
  498. * Show total to pay
  499. *
  500. * @param PDF $pdf Object PDF
  501. * @param Facture $object Object invoice
  502. * @param int $deja_regle Montant deja regle
  503. * @param int $posy Position depart
  504. * @param Translate $outputlangs Objet langs
  505. * @param int $totalOrdered Total ordered
  506. * @return int Position pour suite
  507. */
  508. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $totalOrdered)
  509. {
  510. // phpcs:enable
  511. global $conf,$mysoc;
  512. $sign=1;
  513. $default_font_size = pdf_getPDFFontSize($outputlangs);
  514. $tab2_top = $posy;
  515. $tab2_hl = 4;
  516. $pdf->SetFont('', 'B', $default_font_size - 1);
  517. // Tableau total
  518. $col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol;
  519. /*if ($this->page_largeur < 210) // To work with US executive format
  520. {
  521. $col2x-=20;
  522. }*/
  523. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  524. else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  525. $useborder=0;
  526. $index = 0;
  527. $totalWeighttoshow='';
  528. $totalVolumetoshow='';
  529. // Load dim data
  530. $tmparray=$object->getTotalWeightVolume();
  531. $totalWeight=$tmparray['weight'];
  532. $totalVolume=$tmparray['volume'];
  533. $totalToShip=$tmparray['toship'];
  534. // Set trueVolume and volume_units not currently stored into database
  535. if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  536. {
  537. $object->trueVolume= ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  538. $object->volume_units=$object->size_units * 3;
  539. }
  540. if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  541. if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  542. if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  543. if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  544. $pdf->SetFillColor(255, 255, 255);
  545. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  546. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
  547. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED))
  548. {
  549. $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
  550. $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
  551. }
  552. $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
  553. $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
  554. if(!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  555. $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
  556. $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
  557. $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
  558. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
  559. }
  560. // Total Weight
  561. if ($totalWeighttoshow)
  562. {
  563. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  564. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
  565. $index++;
  566. }
  567. if ($totalVolumetoshow)
  568. {
  569. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  570. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
  571. $index++;
  572. }
  573. if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++;
  574. $pdf->SetTextColor(0, 0, 0);
  575. return ($tab2_top + ($tab2_hl * $index));
  576. }
  577. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  578. /**
  579. * Show table for lines
  580. *
  581. * @param PDF $pdf Object PDF
  582. * @param string $tab_top Top position of table
  583. * @param string $tab_height Height of table (rectangle)
  584. * @param int $nexY Y
  585. * @param Translate $outputlangs Langs object
  586. * @param int $hidetop Hide top bar of array
  587. * @param int $hidebottom Hide bottom bar of array
  588. * @return void
  589. */
  590. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  591. {
  592. global $conf;
  593. // Force to disable hidetop and hidebottom
  594. $hidebottom=0;
  595. if ($hidetop) $hidetop=-1;
  596. $default_font_size = pdf_getPDFFontSize($outputlangs);
  597. // Amount in (at tab_top - 1)
  598. $pdf->SetTextColor(0, 0, 0);
  599. $pdf->SetFont('', '', $default_font_size - 2);
  600. // Output Rect
  601. $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
  602. $pdf->SetDrawColor(128, 128, 128);
  603. $pdf->SetFont('', '', $default_font_size - 1);
  604. if (empty($hidetop))
  605. {
  606. $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
  607. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  608. $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
  609. }
  610. $pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height);
  611. if (empty($hidetop))
  612. {
  613. $pdf->SetXY($this->posxweightvol-1, $tab_top+1);
  614. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
  615. }
  616. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED))
  617. {
  618. $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height);
  619. if (empty($hidetop))
  620. {
  621. $pdf->SetXY($this->posxqtyordered-1, $tab_top+1);
  622. $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
  623. }
  624. }
  625. $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height);
  626. if (empty($hidetop))
  627. {
  628. $pdf->SetXY($this->posxqtytoship, $tab_top+1);
  629. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToReceive"), '', 'C');
  630. }
  631. if(!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  632. $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height);
  633. if (empty($hidetop))
  634. {
  635. $pdf->SetXY($this->posxpuht-1, $tab_top+1);
  636. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  637. }
  638. $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height);
  639. if (empty($hidetop))
  640. {
  641. $pdf->SetXY($this->posxtotalht-1, $tab_top+1);
  642. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
  643. }
  644. }
  645. }
  646. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  647. /**
  648. * Show top header of page.
  649. *
  650. * @param PDF $pdf Object PDF
  651. * @param Object $object Object to show
  652. * @param int $showaddress 0=no, 1=yes
  653. * @param Translate $outputlangs Object lang for output
  654. * @return void
  655. */
  656. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  657. {
  658. global $conf,$langs,$mysoc;
  659. $langs->load("orders");
  660. $default_font_size = pdf_getPDFFontSize($outputlangs);
  661. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  662. // Show Draft Watermark
  663. if($object->statut==0 && (! empty($conf->global->RECEPTION_DRAFT_WATERMARK)) )
  664. {
  665. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->RECEPTION_DRAFT_WATERMARK);
  666. }
  667. //Prepare la suite
  668. $pdf->SetTextColor(0, 0, 60);
  669. $pdf->SetFont('', 'B', $default_font_size + 3);
  670. $w = 110;
  671. $posy=$this->marge_haute;
  672. $posx=$this->page_largeur-$this->marge_droite-$w;
  673. $pdf->SetXY($this->marge_gauche, $posy);
  674. // Logo
  675. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  676. if ($this->emetteur->logo)
  677. {
  678. if (is_readable($logo))
  679. {
  680. $height=pdf_getHeightForLogo($logo);
  681. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  682. }
  683. else
  684. {
  685. $pdf->SetTextColor(200, 0, 0);
  686. $pdf->SetFont('', 'B', $default_font_size - 2);
  687. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  688. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  689. }
  690. }
  691. else
  692. {
  693. $text=$this->emetteur->name;
  694. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  695. }
  696. // Show barcode
  697. if (! empty($conf->barcode->enabled))
  698. {
  699. $posx=105;
  700. }
  701. else
  702. {
  703. $posx=$this->marge_gauche+3;
  704. }
  705. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  706. if (! empty($conf->barcode->enabled))
  707. {
  708. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  709. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  710. //$pdf->Image($logo,10, 5, 0, 24);
  711. }
  712. $pdf->SetDrawColor(128, 128, 128);
  713. if (! empty($conf->barcode->enabled))
  714. {
  715. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  716. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  717. //$pdf->Image($logo,10, 5, 0, 24);
  718. }
  719. $posx=$this->page_largeur - $w - $this->marge_droite;
  720. $posy=$this->marge_haute;
  721. $pdf->SetFont('', 'B', $default_font_size + 2);
  722. $pdf->SetXY($posx, $posy);
  723. $pdf->SetTextColor(0, 0, 60);
  724. $title=$outputlangs->transnoentities("ReceptionSheet");
  725. $pdf->MultiCell($w, 4, $title, '', 'R');
  726. $pdf->SetFont('', '', $default_font_size + 1);
  727. $posy+=5;
  728. $pdf->SetXY($posx, $posy);
  729. $pdf->SetTextColor(0, 0, 60);
  730. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefReception") ." : ".$object->ref, '', 'R');
  731. // Date planned delivery
  732. if (! empty($object->date_delivery))
  733. {
  734. $posy+=4;
  735. $pdf->SetXY($posx, $posy);
  736. $pdf->SetTextColor(0, 0, 60);
  737. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
  738. }
  739. if (! empty($object->thirdparty->code_fournisseur))
  740. {
  741. $posy+=4;
  742. $pdf->SetXY($posx, $posy);
  743. $pdf->SetTextColor(0, 0, 60);
  744. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
  745. }
  746. $pdf->SetFont('', '', $default_font_size + 3);
  747. $Yoff=25;
  748. // Add list of linked orders
  749. $origin = $object->origin;
  750. $origin_id = $object->origin_id;
  751. // TODO move to external function
  752. if (! empty($conf->fournisseur->enabled)) // commonly $origin='commande'
  753. {
  754. $outputlangs->load('orders');
  755. $classname = 'CommandeFournisseur';
  756. $linkedobject = new $classname($this->db);
  757. $result=$linkedobject->fetch($origin_id);
  758. if ($result >= 0)
  759. {
  760. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  761. $pdf->SetFont('', '', $default_font_size - 2);
  762. $text=$linkedobject->ref;
  763. if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
  764. $Yoff = $Yoff+8;
  765. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  766. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
  767. $Yoff = $Yoff+3;
  768. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  769. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  770. }
  771. }
  772. if ($showaddress)
  773. {
  774. // Sender properties
  775. $carac_emetteur='';
  776. // Add internal contact of origin element if defined
  777. $arrayidcontact=array();
  778. if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal', 'SALESREPFOLL');
  779. if(empty($arrayidcontact)) $arrayidcontact=$object->$origin->getIdContact('internal', 'SHIPPING');
  780. if (count($arrayidcontact) > 0)
  781. {
  782. $object->fetch_user(reset($arrayidcontact));
  783. $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  784. }
  785. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  786. // Show sender
  787. $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  788. $posx=$this->marge_gauche;
  789. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  790. $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  791. $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  792. // Show sender frame
  793. $pdf->SetTextColor(0, 0, 0);
  794. $pdf->SetFont('', '', $default_font_size - 2);
  795. $pdf->SetXY($posx, $posy-5);
  796. $pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
  797. $pdf->SetXY($posx, $posy);
  798. $pdf->SetFillColor(230, 230, 230);
  799. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  800. $pdf->SetTextColor(0, 0, 60);
  801. $pdf->SetFillColor(255, 255, 255);
  802. // If RECEPTION contact defined, we use it
  803. $usecontact=false;
  804. $arrayidcontact=$object->$origin->getIdContact('external', 'SHIPPING');
  805. if (count($arrayidcontact) > 0)
  806. {
  807. $usecontact=true;
  808. $result=$object->fetch_contact($arrayidcontact[0]);
  809. }
  810. //Recipient name
  811. // On peut utiliser le nom de la societe du contact
  812. if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  813. $thirdparty = $object->contact;
  814. } else {
  815. $thirdparty = $object->thirdparty;
  816. }
  817. $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
  818. $carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact)?$object->contact:null), $usecontact, 'targetwithdetails', $object);
  819. // Show recipient name
  820. $pdf->SetXY($posx+2, $posy+3);
  821. $pdf->SetFont('', 'B', $default_font_size);
  822. $pdf->MultiCell($widthrecbox-2, 4, $carac_client_name, 0, 'L');
  823. $posy = $pdf->getY();
  824. // Show recipient information
  825. $pdf->SetFont('', '', $default_font_size - 1);
  826. $pdf->SetXY($posx+2, $posy);
  827. $pdf->MultiCell($widthrecbox-2, 4, $carac_client, 0, 'L');
  828. // Show recipient
  829. $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  830. if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
  831. $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  832. $posx=$this->page_largeur - $this->marge_droite - $widthrecbox;
  833. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  834. // Show recipient frame
  835. $pdf->SetTextColor(0, 0, 0);
  836. $pdf->SetFont('', '', $default_font_size - 2);
  837. $pdf->SetXY($posx+2, $posy-5);
  838. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
  839. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  840. // Show sender name
  841. $pdf->SetXY($posx+2, $posy+3);
  842. $pdf->SetFont('', 'B', $default_font_size);
  843. $pdf->MultiCell($widthrecbox, 2, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  844. $posy=$pdf->getY();
  845. // Show sender information
  846. $pdf->SetXY($posx+2, $posy);
  847. $pdf->SetFont('', '', $default_font_size - 1);
  848. $pdf->MultiCell($widthrecbox, 4, $carac_emetteur, 0, 'L');
  849. }
  850. $pdf->SetTextColor(0, 0, 0);
  851. }
  852. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  853. /**
  854. * Show footer of page. Need this->emetteur object
  855. *
  856. * @param PDF $pdf PDF
  857. * @param Object $object Object to show
  858. * @param Translate $outputlangs Object lang for output
  859. * @param int $hidefreetext 1=Hide free text
  860. * @return int Return height of bottom margin including footer text
  861. */
  862. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  863. {
  864. global $conf;
  865. $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  866. return pdf_pagefoot($pdf, $outputlangs, 'RECEPTION_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  867. }
  868. }