pdf_rouget.modules.php 42 KB

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