pdf_rouget.modules.php 42 KB

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