pdf_squille.modules.php 41 KB

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