pdf_eagle.modules.php 46 KB

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