pdf_eagle.modules.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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. if (!empty($conf->global->MAIN_UMASK))
  554. @chmod($file, octdec($conf->global->MAIN_UMASK));
  555. $this->result = array('fullpath'=>$file);
  556. return 1; // No error
  557. } else {
  558. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  559. return 0;
  560. }
  561. } else {
  562. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  563. return 0;
  564. }
  565. }
  566. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  567. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  568. /**
  569. * Show total to pay
  570. *
  571. * @param PDF $pdf Object PDF
  572. * @param Facture $object Object invoice
  573. * @param int $deja_regle Montant deja regle
  574. * @param int $posy Position depart
  575. * @param Translate $outputlangs Objet langs
  576. * @return int Position pour suite
  577. */
  578. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  579. {
  580. // phpcs:enable
  581. global $conf, $mysoc;
  582. $sign = 1;
  583. $default_font_size = pdf_getPDFFontSize($outputlangs);
  584. $tab2_top = $posy;
  585. $tab2_hl = 4;
  586. $pdf->SetFont('', 'B', $default_font_size - 1);
  587. // Tableau total
  588. $col1x = $this->posxqty - 50; $col2x = $this->posxqty;
  589. /*if ($this->page_largeur < 210) // To work with US executive format
  590. {
  591. $col2x-=20;
  592. }*/
  593. if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxwarehousesource - $this->posxqty);
  594. else $largcol2 = ($this->posxwarehousedestination - $this->posxqty);
  595. $useborder = 0;
  596. $index = 0;
  597. $totalWeighttoshow = '';
  598. $totalVolumetoshow = '';
  599. // Load dim data
  600. $tmparray = $object->getTotalWeightVolume();
  601. $totalWeight = $tmparray['weight'];
  602. $totalVolume = $tmparray['volume'];
  603. $totalQty = 0;
  604. if (!empty($object->lines))
  605. foreach ($object->lines as $line) {
  606. $totalQty+=$line->qty;
  607. }
  608. // Set trueVolume and volume_units not currently stored into database
  609. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  610. $object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
  611. $object->volume_units = $object->size_units * 3;
  612. }
  613. if ($totalWeight != '') $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  614. if ($totalVolume != '') $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  615. if ($object->trueWeight) $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  616. if ($object->trueVolume) $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  617. $pdf->SetFillColor(255, 255, 255);
  618. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  619. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
  620. if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) {
  621. $pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index);
  622. $pdf->MultiCell($this->posxwarehousesource - $this->posxqty, $tab2_hl, $totalQty, 0, 'C', 1);
  623. }
  624. if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
  625. $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
  626. $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
  627. $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
  628. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
  629. }
  630. if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
  631. // Total Weight
  632. if ($totalWeighttoshow) {
  633. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  634. $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
  635. $index++;
  636. }
  637. if ($totalVolumetoshow) {
  638. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  639. $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
  640. $index++;
  641. }
  642. if (!$totalWeighttoshow && !$totalVolumetoshow) $index++;
  643. }
  644. $pdf->SetTextColor(0, 0, 0);
  645. return ($tab2_top + ($tab2_hl * $index));
  646. }
  647. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  648. /**
  649. * Show table for lines
  650. *
  651. * @param PDF $pdf Object PDF
  652. * @param string $tab_top Top position of table
  653. * @param string $tab_height Height of table (rectangle)
  654. * @param int $nexY Y
  655. * @param Translate $outputlangs Langs object
  656. * @param int $hidetop Hide top bar of array
  657. * @param int $hidebottom Hide bottom bar of array
  658. * @return void
  659. */
  660. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  661. {
  662. // phpcs:enable
  663. global $conf;
  664. // Force to disable hidetop and hidebottom
  665. $hidebottom = 0;
  666. if ($hidetop) $hidetop = -1;
  667. $default_font_size = pdf_getPDFFontSize($outputlangs);
  668. // Amount in (at tab_top - 1)
  669. $pdf->SetTextColor(0, 0, 0);
  670. $pdf->SetFont('', '', $default_font_size - 2);
  671. // Output Rect
  672. $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
  673. $pdf->SetDrawColor(128, 128, 128);
  674. $pdf->SetFont('', '', $default_font_size - 1);
  675. if (empty($hidetop)) {
  676. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
  677. $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
  678. $pdf->MultiCell($this->posxlot - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
  679. }
  680. if (isModEnabled('productbatch') && $this->atLeastOneBatch) {
  681. $pdf->line($this->posxlot - 1, $tab_top, $this->posxlot - 1, $tab_top + $tab_height);
  682. if (empty($hidetop)) {
  683. $pdf->SetXY($this->posxlot, $tab_top + 1);
  684. $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 2, $outputlangs->transnoentities("Batch"), '', 'C');
  685. }
  686. }
  687. if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
  688. $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
  689. if (empty($hidetop)) {
  690. $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
  691. $pdf->MultiCell(($this->posxqty - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
  692. }
  693. }
  694. $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
  695. if (empty($hidetop)) {
  696. $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
  697. $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 2, $outputlangs->transnoentities("Qty"), '', 'C');
  698. }
  699. $pdf->line($this->posxwarehousesource - 1, $tab_top, $this->posxwarehousesource - 1, $tab_top + $tab_height);
  700. if (empty($hidetop)) {
  701. $pdf->SetXY($this->posxwarehousesource - 1, $tab_top + 1);
  702. $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 2, $outputlangs->transnoentities("WarehouseSource"), '', 'C');
  703. }
  704. $pdf->line($this->posxwarehousedestination - 1, $tab_top, $this->posxwarehousedestination - 1, $tab_top + $tab_height);
  705. if (empty($hidetop)) {
  706. $pdf->SetXY($this->posxwarehousedestination-2.5, $tab_top + 1);
  707. $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination+4), 2, $outputlangs->transnoentities("WarehouseTarget"), '', 'C');
  708. }
  709. /*if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
  710. $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
  711. if (empty($hidetop))
  712. {
  713. $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
  714. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  715. }
  716. $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
  717. if (empty($hidetop))
  718. {
  719. $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
  720. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
  721. }
  722. }*/
  723. }
  724. /**
  725.  * Used to know if at least one line of Stock Transfer object has a batch set
  726.  *
  727. * @param Object $object Stock Transfer object
  728. * @return boolean true if at least one line has batch set, false if not
  729.  */
  730. public function atLeastOneBatch($object)
  731. {
  732. global $conf;
  733. $atLeastOneBatch = false;
  734. if (empty($conf->productbatch->enabled)) return false;
  735. foreach ($object->lines as $line) {
  736. if (!empty($line->batch)) {
  737. return true;
  738. }
  739. }
  740. return false;
  741. }
  742. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  743. /**
  744. * Show top header of page.
  745. *
  746. * @param TCPDF $pdf Object PDF
  747. * @param Object $object Object to show
  748. * @param int $showaddress 0=no, 1=yes
  749. * @param Translate $outputlangs Object lang for output
  750. * @return void
  751. */
  752. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  753. {
  754. // phpcs:enable
  755. global $conf, $langs, $mysoc;
  756. $langs->load("orders");
  757. $default_font_size = pdf_getPDFFontSize($outputlangs);
  758. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  759. // Show Draft Watermark
  760. if ($object->statut == 0 && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK))) {
  761. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
  762. }
  763. //Prepare la suite
  764. $pdf->SetTextColor(0, 0, 60);
  765. $pdf->SetFont('', 'B', $default_font_size + 3);
  766. $w = 110;
  767. $posy = $this->marge_haute;
  768. $posx = $this->page_largeur - $this->marge_droite - $w;
  769. $pdf->SetXY($this->marge_gauche, $posy);
  770. // Logo
  771. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  772. if ($this->emetteur->logo) {
  773. if (is_readable($logo)) {
  774. $height = pdf_getHeightForLogo($logo);
  775. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  776. } else {
  777. $pdf->SetTextColor(200, 0, 0);
  778. $pdf->SetFont('', 'B', $default_font_size - 2);
  779. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  780. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  781. }
  782. } else {
  783. $text = $this->emetteur->name;
  784. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  785. }
  786. // Show barcode
  787. if (isModEnabled('barcode')) {
  788. $posx = 105;
  789. } else {
  790. $posx = $this->marge_gauche + 3;
  791. }
  792. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  793. if (isModEnabled('barcode')) {
  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. $pdf->SetDrawColor(128, 128, 128);
  799. if (isModEnabled('barcode')) {
  800. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  801. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  802. //$pdf->Image($logo,10, 5, 0, 24);
  803. }
  804. $posx = $this->page_largeur - $w - $this->marge_droite;
  805. $posy = $this->marge_haute;
  806. $pdf->SetFont('', 'B', $default_font_size + 2);
  807. $pdf->SetXY($posx, $posy);
  808. $pdf->SetTextColor(0, 0, 60);
  809. $title = $outputlangs->transnoentities("StockTransferSheet");
  810. $pdf->MultiCell($w, 4, $title, '', 'R');
  811. $pdf->SetFont('', '', $default_font_size + 1);
  812. $posy += 5;
  813. $pdf->SetXY($posx, $posy);
  814. $pdf->SetTextColor(0, 0, 60);
  815. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
  816. // Date prévue depart
  817. if (!empty($object->date_prevue_depart)) {
  818. $posy += 4;
  819. $pdf->SetXY($posx, $posy);
  820. $pdf->SetTextColor(0, 0, 60);
  821. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueDepart")." : ".dol_print_date($object->date_prevue_depart, "day", false, $outputlangs, true), '', 'R');
  822. }
  823. // Date prévue arrivée
  824. if (!empty($object->date_prevue_arrivee)) {
  825. $posy += 4;
  826. $pdf->SetXY($posx, $posy);
  827. $pdf->SetTextColor(0, 0, 60);
  828. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueArrivee")." : ".dol_print_date($object->date_prevue_arrivee, "day", false, $outputlangs, true), '', 'R');
  829. }
  830. // Date reelle depart
  831. if (!empty($object->date_reelle_depart)) {
  832. $posy += 4;
  833. $pdf->SetXY($posx, $posy);
  834. $pdf->SetTextColor(0, 0, 60);
  835. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleDepart")." : ".dol_print_date($object->date_reelle_depart, "day", false, $outputlangs, true), '', 'R');
  836. }
  837. // Date reelle arrivée
  838. if (!empty($object->date_reelle_arrivee)) {
  839. $posy += 4;
  840. $pdf->SetXY($posx, $posy);
  841. $pdf->SetTextColor(0, 0, 60);
  842. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
  843. }
  844. if (!empty($object->thirdparty->code_client)) {
  845. $posy += 4;
  846. $pdf->SetXY($posx, $posy);
  847. $pdf->SetTextColor(0, 0, 60);
  848. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  849. }
  850. $pdf->SetFont('', '', $default_font_size + 3);
  851. $Yoff = 25;
  852. // Add list of linked orders
  853. $origin = $object->origin;
  854. $origin_id = $object->origin_id;
  855. // TODO move to external function
  856. if (!empty($conf->$origin->enabled)) { // commonly $origin='commande'
  857. $outputlangs->load('orders');
  858. $classname = ucfirst($origin);
  859. $linkedobject = new $classname($this->db);
  860. $result = $linkedobject->fetch($origin_id);
  861. if ($result >= 0) {
  862. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  863. $pdf->SetFont('', '', $default_font_size - 2);
  864. $text = $linkedobject->ref;
  865. if ($linkedobject->ref_client) $text .= ' ('.$linkedobject->ref_client.')';
  866. $Yoff = $Yoff + 8;
  867. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  868. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
  869. $Yoff = $Yoff + 3;
  870. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  871. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  872. }
  873. }
  874. if ($showaddress) {
  875. // Sender properties
  876. $carac_emetteur = '';
  877. // Add internal contact of origin element if defined
  878. $arrayidcontact = array();
  879. $arrayidcontact = $object->getIdContact('external', 'STFROM');
  880. $usecontact = false;
  881. if (count($arrayidcontact) > 0) {
  882. /*$object->fetch_user(reset($arrayidcontact));
  883. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
  884. $usecontact = true;
  885. $result = $object->fetch_contact($arrayidcontact[0]);
  886. }
  887. if ($usecontact) $thirdparty = $object->contact;
  888. else $thirdparty = $this->emetteur;
  889. if (!empty($thirdparty)) $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  890. if ($usecontact) $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
  891. else $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  892. // Show sender
  893. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  894. $posx = $this->marge_gauche;
  895. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
  896. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  897. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  898. // Show sender frame
  899. $pdf->SetTextColor(0, 0, 0);
  900. $pdf->SetFont('', '', $default_font_size - 2);
  901. $pdf->SetXY($posx, $posy - 5);
  902. $pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
  903. $pdf->SetXY($posx, $posy);
  904. $pdf->SetFillColor(230, 230, 230);
  905. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  906. $pdf->SetTextColor(0, 0, 60);
  907. $pdf->SetFillColor(255, 255, 255);
  908. // Show sender name
  909. $pdf->SetXY($posx + 2, $posy + 3);
  910. $pdf->SetFont('', 'B', $default_font_size);
  911. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_emetteur_name), 0, 'L');
  912. $posy = $pdf->getY();
  913. // Show sender information
  914. $pdf->SetXY($posx + 2, $posy);
  915. $pdf->SetFont('', '', $default_font_size - 1);
  916. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
  917. // If SHIPPING contact defined, we use it
  918. $usecontact = false;
  919. $arrayidcontact = $object->getIdContact('external', 'STDEST');
  920. if (count($arrayidcontact) > 0) {
  921. $usecontact = true;
  922. $result = $object->fetch_contact($arrayidcontact[0]);
  923. }
  924. //Recipient name
  925. // On peut utiliser le nom de la societe du contact
  926. if ($usecontact/* && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)*/) {
  927. $thirdparty = $object->contact;
  928. } else {
  929. $thirdparty = $object->thirdparty;
  930. }
  931. if (!empty($thirdparty)) $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  932. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  933. // Show recipient
  934. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  935. if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
  936. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  937. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  938. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
  939. // Show recipient frame
  940. $pdf->SetTextColor(0, 0, 0);
  941. $pdf->SetFont('', '', $default_font_size - 2);
  942. $pdf->SetXY($posx + 2, $posy - 5);
  943. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
  944. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  945. // Show recipient name
  946. $pdf->SetXY($posx + 2, $posy + 3);
  947. $pdf->SetFont('', 'B', $default_font_size);
  948. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
  949. $posy = $pdf->getY();
  950. // Show recipient information
  951. $pdf->SetFont('', '', $default_font_size - 1);
  952. $pdf->SetXY($posx + 2, $posy);
  953. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  954. }
  955. $pdf->SetTextColor(0, 0, 0);
  956. }
  957. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  958. /**
  959. * Show footer of page. Need this->emetteur object
  960. *
  961. * @param PDF $pdf PDF
  962. * @param Object $object Object to show
  963. * @param Translate $outputlangs Object lang for output
  964. * @param int $hidefreetext 1=Hide free text
  965. * @return int Return height of bottom margin including footer text
  966. */
  967. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  968. {
  969. // phpcs:enable
  970. $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
  971. return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  972. }
  973. }