pdf_espadon.modules.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
  24. * \ingroup expedition
  25. * \brief Class file allowing Espadons shipping template generation
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. /**
  32. * Class to build sending documents with model espadon
  33. */
  34. class pdf_espadon extends ModelePdfExpedition
  35. {
  36. /**
  37. * @var DoliDb Database handler
  38. */
  39. public $db;
  40. /**
  41. * @var string model name
  42. */
  43. public $name;
  44. /**
  45. * @var string model description (short text)
  46. */
  47. public $description;
  48. /**
  49. * @var int Save the name of generated file as the main doc when generating a doc with this template
  50. */
  51. public $update_main_doc_field;
  52. /**
  53. * @var string document type
  54. */
  55. public $type;
  56. /**
  57. * @var array Minimum version of PHP required by module.
  58. * e.g.: PHP ≥ 7.0 = array(7, 0)
  59. */
  60. public $phpmin = array(7, 0);
  61. /**
  62. * Dolibarr version of the loaded document
  63. * @var string
  64. */
  65. public $version = 'dolibarr';
  66. /**
  67. * @var int page_largeur
  68. */
  69. public $page_largeur;
  70. /**
  71. * @var int page_hauteur
  72. */
  73. public $page_hauteur;
  74. /**
  75. * @var array format
  76. */
  77. public $format;
  78. /**
  79. * @var int marge_gauche
  80. */
  81. public $marge_gauche;
  82. /**
  83. * @var int marge_droite
  84. */
  85. public $marge_droite;
  86. /**
  87. * @var int marge_haute
  88. */
  89. public $marge_haute;
  90. /**
  91. * @var int marge_basse
  92. */
  93. public $marge_basse;
  94. /**
  95. * Issuer
  96. * @var Societe object that emits
  97. */
  98. public $emetteur;
  99. /**
  100. * Constructor
  101. *
  102. * @param DoliDB $db Database handler
  103. */
  104. public function __construct(DoliDB $db)
  105. {
  106. global $conf, $langs, $mysoc;
  107. $this->db = $db;
  108. $this->name = "espadon";
  109. $this->description = $langs->trans("DocumentModelStandardPDF");
  110. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  111. $this->type = 'pdf';
  112. $formatarray = pdf_getFormat();
  113. $this->page_largeur = $formatarray['width'];
  114. $this->page_hauteur = $formatarray['height'];
  115. $this->format = array($this->page_largeur, $this->page_hauteur);
  116. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  117. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  118. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  119. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  120. $this->option_logo = 1; // Display logo
  121. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  122. $this->watermark = '';
  123. // Get source company
  124. $this->emetteur = $mysoc;
  125. if (!$this->emetteur->country_code) {
  126. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  127. }
  128. $this->tabTitleHeight = 5; // default height
  129. }
  130. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  131. /**
  132. * Function to build pdf onto disk
  133. *
  134. * @param Expedition $object Object expedition to generate (or id if old method)
  135. * @param Translate $outputlangs Lang output object
  136. * @param string $srctemplatepath Full path of source filename for generator using a template file
  137. * @param int $hidedetails Do not show line details
  138. * @param int $hidedesc Do not show desc
  139. * @param int $hideref Do not show ref
  140. * @return int 1=OK, 0=KO
  141. */
  142. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  143. {
  144. // phpcs:enable
  145. global $user, $conf, $langs, $hookmanager;
  146. $object->fetch_thirdparty();
  147. if (!is_object($outputlangs)) {
  148. $outputlangs = $langs;
  149. }
  150. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  151. if (!empty($conf->global->MAIN_USE_FPDF)) {
  152. $outputlangs->charset_output = 'ISO-8859-1';
  153. }
  154. // Load traductions files required by page
  155. $outputlangs->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
  156. // Show Draft Watermark
  157. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK))) {
  158. $this->watermark = $conf->global->SHIPPING_DRAFT_WATERMARK;
  159. }
  160. global $outputlangsbis;
  161. $outputlangsbis = null;
  162. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  163. $outputlangsbis = new Translate('', $conf);
  164. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  165. $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
  166. }
  167. $nblines = count($object->lines);
  168. // Loop on each lines to detect if there is at least one image to show
  169. $realpatharray = array();
  170. $this->atleastonephoto = false;
  171. if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) {
  172. $objphoto = new Product($this->db);
  173. for ($i = 0; $i < $nblines; $i++) {
  174. if (empty($object->lines[$i]->fk_product)) {
  175. continue;
  176. }
  177. $objphoto->fetch($object->lines[$i]->fk_product);
  178. if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
  179. $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
  180. $dir = $conf->product->dir_output.'/'.$pdir;
  181. } else {
  182. $pdir = get_exdir(0, 0, 0, 0, $objphoto, 'product');
  183. $dir = $conf->product->dir_output.'/'.$pdir;
  184. }
  185. $realpath = '';
  186. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  187. if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  188. if ($obj['photo_vignette']) {
  189. $filename = $obj['photo_vignette'];
  190. } else {
  191. $filename = $obj['photo'];
  192. }
  193. } else {
  194. $filename = $obj['photo'];
  195. }
  196. $realpath = $dir.$filename;
  197. $this->atleastonephoto = true;
  198. break;
  199. }
  200. if ($realpath) {
  201. $realpatharray[$i] = $realpath;
  202. }
  203. }
  204. }
  205. if (count($realpatharray) == 0) {
  206. $this->posxpicture = $this->posxweightvol;
  207. }
  208. if ($conf->expedition->dir_output) {
  209. // Definition of $dir and $file
  210. if ($object->specimen) {
  211. $dir = $conf->expedition->dir_output."/sending";
  212. $file = $dir."/SPECIMEN.pdf";
  213. } else {
  214. $expref = dol_sanitizeFileName($object->ref);
  215. $dir = $conf->expedition->dir_output."/sending/".$expref;
  216. $file = $dir."/".$expref.".pdf";
  217. }
  218. if (!file_exists($dir)) {
  219. if (dol_mkdir($dir) < 0) {
  220. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  221. return 0;
  222. }
  223. }
  224. if (file_exists($dir)) {
  225. // Add pdfgeneration hook
  226. if (!is_object($hookmanager)) {
  227. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  228. $hookmanager = new HookManager($this->db);
  229. }
  230. $hookmanager->initHooks(array('pdfgeneration'));
  231. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  232. global $action;
  233. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  234. // Set nblines with the new facture lines content after hook
  235. $nblines = count($object->lines);
  236. $pdf = pdf_getInstance($this->format);
  237. $default_font_size = pdf_getPDFFontSize($outputlangs);
  238. $heightforinfotot = 8; // Height reserved to output the info and total part
  239. $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
  240. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  241. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  242. $heightforfooter += 6;
  243. }
  244. $pdf->SetAutoPageBreak(1, 0);
  245. if (class_exists('TCPDF')) {
  246. $pdf->setPrintHeader(false);
  247. $pdf->setPrintFooter(false);
  248. }
  249. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  250. // Set path to the background PDF File
  251. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  252. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  253. $tplidx = $pdf->importPage(1);
  254. }
  255. $pdf->Open();
  256. $pagenb = 0;
  257. $pdf->SetDrawColor(128, 128, 128);
  258. if (method_exists($pdf, 'AliasNbPages')) {
  259. $pdf->AliasNbPages();
  260. }
  261. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  262. $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
  263. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  264. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  265. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
  266. if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
  267. $pdf->SetCompression(false);
  268. }
  269. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  270. // New page
  271. $pdf->AddPage();
  272. if (!empty($tplidx)) {
  273. $pdf->useTemplate($tplidx);
  274. }
  275. $pagenb++;
  276. $top_shift = $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 + $top_shift: 10);
  282. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  283. $this->posxdesc = $this->marge_gauche + 1;
  284. // Incoterm
  285. $height_incoterms = 0;
  286. if (isModEnabled('incoterm')) {
  287. $desc_incoterms = $object->getIncotermsForPDF();
  288. if ($desc_incoterms) {
  289. $tab_top -= 2;
  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. // display note
  302. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  303. // Extrafields in note
  304. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  305. if (!empty($extranote)) {
  306. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  307. }
  308. if (!empty($notetoshow) || !empty($object->tracking_number)) {
  309. $tab_top -= 2;
  310. $tab_topbeforetrackingnumber = $tab_top;
  311. // Tracking number
  312. if (!empty($object->tracking_number)) {
  313. $height_trackingnumber = 4;
  314. $pdf->SetFont('', 'B', $default_font_size - 2);
  315. $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber") . " : " . $object->tracking_number, 0, 1, false, true, 'L');
  316. $tab_top_alt = $pdf->GetY();
  317. $object->getUrlTrackingStatus($object->tracking_number);
  318. if (!empty($object->tracking_url)) {
  319. if ($object->shipping_method_id > 0) {
  320. // Get code using getLabelFromKey
  321. $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  322. $label = '';
  323. if ($object->tracking_url != $object->tracking_number) {
  324. $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
  325. }
  326. $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
  327. //var_dump($object->tracking_url != $object->tracking_number);exit;
  328. if ($object->tracking_url != $object->tracking_number) {
  329. $label .= " : ";
  330. $label .= $object->tracking_url;
  331. }
  332. $height_trackingnumber += 4;
  333. $pdf->SetFont('', 'B', $default_font_size - 2);
  334. $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
  335. }
  336. }
  337. $tab_top = $pdf->GetY();
  338. }
  339. // Notes
  340. $pagenb = $pdf->getPage();
  341. if (!empty($notetoshow) || !empty($object->tracking_number)) {
  342. $tab_top -= 1;
  343. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  344. $pageposbeforenote = $pagenb;
  345. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  346. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  347. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  348. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  349. $pdf->startTransaction();
  350. $pdf->SetFont('', '', $default_font_size - 1);
  351. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  352. // Description
  353. $pageposafternote = $pdf->getPage();
  354. $posyafter = $pdf->GetY();
  355. if ($pageposafternote > $pageposbeforenote) {
  356. $pdf->rollbackTransaction(true);
  357. // prepare pages to receive notes
  358. while ($pagenb < $pageposafternote) {
  359. $pdf->AddPage();
  360. $pagenb++;
  361. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  362. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
  363. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  364. $pdf->setTopMargin($tab_top_newpage);
  365. // The only function to edit the bottom margin of current page to set it.
  366. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  367. }
  368. // back to start
  369. $pdf->setPage($pageposbeforenote);
  370. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  371. $pdf->SetFont('', '', $default_font_size - 1);
  372. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  373. $pageposafternote = $pdf->getPage();
  374. $posyafter = $pdf->GetY();
  375. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  376. $pdf->AddPage('', '', true);
  377. $pagenb++;
  378. $pageposafternote++;
  379. $pdf->setPage($pageposafternote);
  380. $pdf->setTopMargin($tab_top_newpage);
  381. // The only function to edit the bottom margin of current page to set it.
  382. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  383. //$posyafter = $tab_top_newpage;
  384. }
  385. // apply note frame to previous pages
  386. $i = $pageposbeforenote;
  387. while ($i < $pageposafternote) {
  388. $pdf->setPage($i);
  389. $pdf->SetDrawColor(128, 128, 128);
  390. // Draw note frame
  391. if ($i > $pageposbeforenote) {
  392. if (empty($height_trackingnumber)) {
  393. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  394. } else {
  395. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter) + $height_trackingnumber + 1;
  396. $tab_top_newpage = $tab_topbeforetrackingnumber;
  397. }
  398. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2);
  399. } else {
  400. if (empty($height_trackingnumber)) {
  401. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  402. } else {
  403. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter)+ $height_trackingnumber + 1;
  404. $tab_top = $tab_topbeforetrackingnumber;
  405. }
  406. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2);
  407. }
  408. // Add footer
  409. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  410. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  411. $i++;
  412. }
  413. // apply note frame to last page
  414. $pdf->setPage($pageposafternote);
  415. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  416. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
  417. $height_note = $posyafter - $tab_top_newpage;
  418. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  419. } else // No pagebreak
  420. {
  421. $pdf->commitTransaction();
  422. $posyafter = $pdf->GetY();
  423. if (empty($height_trackingnumber)) {
  424. $height_note = $posyafter - $tab_top + 1;
  425. } else {
  426. $height_note = $posyafter - $tab_top + $height_trackingnumber + 1;
  427. $tab_top = $tab_topbeforetrackingnumber;
  428. }
  429. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2);
  430. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  431. // not enough space, need to add page
  432. $pdf->AddPage('', '', true);
  433. $pagenb++;
  434. $pageposafternote++;
  435. $pdf->setPage($pageposafternote);
  436. if (!empty($tplidx)) $pdf->useTemplate($tplidx);
  437. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
  438. $posyafter = $tab_top_newpage;
  439. }
  440. }
  441. $tab_height = $tab_height - $height_note;
  442. $tab_top = $posyafter + 6;
  443. } else {
  444. $height_note = 0;
  445. }
  446. }
  447. // Use new auto column system
  448. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  449. // Table simulation to know the height of the title line
  450. $pdf->startTransaction();
  451. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
  452. $pdf->rollbackTransaction(true);
  453. $nexY = $tab_top + $this->tabTitleHeight;
  454. // Loop on each lines
  455. $pageposbeforeprintlines = $pdf->getPage();
  456. $pagenb = $pageposbeforeprintlines;
  457. for ($i = 0; $i < $nblines; $i++) {
  458. $curY = $nexY;
  459. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  460. $pdf->SetTextColor(0, 0, 0);
  461. // Define size of image if we need it
  462. $imglinesize = array();
  463. if (!empty($realpatharray[$i])) {
  464. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  465. }
  466. $pdf->setTopMargin($tab_top_newpage);
  467. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  468. $pageposbefore = $pdf->getPage();
  469. $showpricebeforepagebreak = 1;
  470. $posYAfterImage = 0;
  471. $posYAfterDescription = 0;
  472. if ($this->getColumnStatus('photo')) {
  473. // We start with Photo of product line
  474. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // If photo too high, we moved completely on new page
  475. $pdf->AddPage('', '', true);
  476. if (!empty($tplidx)) {
  477. $pdf->useTemplate($tplidx);
  478. }
  479. //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
  480. $pdf->setPage($pageposbefore + 1);
  481. $curY = $tab_top_newpage;
  482. // Allows data in the first page if description is long enough to break in multiples pages
  483. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  484. $showpricebeforepagebreak = 1;
  485. } else {
  486. $showpricebeforepagebreak = 0;
  487. }
  488. }
  489. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
  490. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  491. // $pdf->Image does not increase value return by getY, so we save it manually
  492. $posYAfterImage = $curY + $imglinesize['height'];
  493. }
  494. }
  495. // Description of product line
  496. if ($this->getColumnStatus('desc')) {
  497. $pdf->startTransaction();
  498. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  499. $pageposafter = $pdf->getPage();
  500. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  501. $pdf->rollbackTransaction(true);
  502. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  503. $pageposafter = $pdf->getPage();
  504. $posyafter = $pdf->GetY();
  505. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  506. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
  507. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  508. $pdf->AddPage('', '', true);
  509. if (!empty($tplidx)) {
  510. $pdf->useTemplate($tplidx);
  511. }
  512. //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
  513. $pdf->setPage($pageposafter + 1);
  514. }
  515. } else {
  516. // We found a page break
  517. // Allows data in the first page if description is long enough to break in multiples pages
  518. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  519. $showpricebeforepagebreak = 1;
  520. } else {
  521. $showpricebeforepagebreak = 0;
  522. }
  523. }
  524. } else // No pagebreak
  525. {
  526. $pdf->commitTransaction();
  527. }
  528. $posYAfterDescription = $pdf->GetY();
  529. }
  530. $nexY = max($pdf->GetY(), $posYAfterImage);
  531. $pageposafter = $pdf->getPage();
  532. $pdf->setPage($pageposbefore);
  533. $pdf->setTopMargin($this->marge_haute);
  534. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  535. // We suppose that a too long description or photo were moved completely on next page
  536. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  537. $pdf->setPage($pageposafter);
  538. $curY = $tab_top_newpage;
  539. }
  540. // We suppose that a too long description is moved completely on next page
  541. if ($pageposafter > $pageposbefore) {
  542. $pdf->setPage($pageposafter);
  543. $curY = $tab_top_newpage;
  544. }
  545. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  546. // weight
  547. $weighttxt = '';
  548. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) {
  549. $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1);
  550. }
  551. $voltxt = '';
  552. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) {
  553. $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0, 1);
  554. }
  555. if ($this->getColumnStatus('weight')) {
  556. $this->printStdColumnContent($pdf, $curY, 'weight', $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt);
  557. $nexY = max($pdf->GetY(), $nexY);
  558. }
  559. if ($this->getColumnStatus('qty_asked')) {
  560. $this->printStdColumnContent($pdf, $curY, 'qty_asked', $object->lines[$i]->qty_asked);
  561. $nexY = max($pdf->GetY(), $nexY);
  562. }
  563. if ($this->getColumnStatus('unit_order')) {
  564. $this->printStdColumnContent($pdf, $curY, 'unit_order', measuringUnitString($object->lines[$i]->fk_unit));
  565. $nexY = max($pdf->GetY(), $nexY);
  566. }
  567. if ($this->getColumnStatus('qty_shipped')) {
  568. $this->printStdColumnContent($pdf, $curY, 'qty_shipped', $object->lines[$i]->qty_shipped);
  569. $nexY = max($pdf->GetY(), $nexY);
  570. }
  571. if ($this->getColumnStatus('subprice')) {
  572. $this->printStdColumnContent($pdf, $curY, 'subprice', price($object->lines[$i]->subprice, 0, $outputlangs));
  573. $nexY = max($pdf->GetY(), $nexY);
  574. }
  575. // Extrafields
  576. if (!empty($object->lines[$i]->array_options)) {
  577. foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
  578. if ($this->getColumnStatus($extrafieldColKey)) {
  579. $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
  580. $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
  581. $nexY = max($pdf->GetY(), $nexY);
  582. }
  583. }
  584. }
  585. // Add line
  586. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  587. $pdf->setPage($pageposafter);
  588. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  589. //$pdf->SetDrawColor(190,190,200);
  590. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
  591. $pdf->SetLineStyle(array('dash'=>0));
  592. }
  593. // Detect if some page were added automatically and output _tableau for past pages
  594. while ($pagenb < $pageposafter) {
  595. $pdf->setPage($pagenb);
  596. if ($pagenb == $pageposbeforeprintlines) {
  597. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  598. } else {
  599. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  600. }
  601. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  602. $pagenb++;
  603. $pdf->setPage($pagenb);
  604. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  605. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  606. $this->_pagehead($pdf, $object, 0, $outputlangs);
  607. }
  608. if (!empty($tplidx)) {
  609. $pdf->useTemplate($tplidx);
  610. }
  611. }
  612. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  613. if ($pagenb == 1) {
  614. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  615. } else {
  616. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  617. }
  618. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  619. // New page
  620. $pdf->AddPage();
  621. if (!empty($tplidx)) {
  622. $pdf->useTemplate($tplidx);
  623. }
  624. $pagenb++;
  625. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  626. $this->_pagehead($pdf, $object, 0, $outputlangs);
  627. }
  628. }
  629. }
  630. // Show square
  631. if ($pagenb == 1) {
  632. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  633. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  634. } else {
  635. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  636. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  637. }
  638. // Display total area
  639. $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
  640. // Pagefoot
  641. $this->_pagefoot($pdf, $object, $outputlangs);
  642. if (method_exists($pdf, 'AliasNbPages')) {
  643. $pdf->AliasNbPages();
  644. }
  645. $pdf->Close();
  646. $pdf->Output($file, 'F');
  647. // Add pdfgeneration hook
  648. $hookmanager->initHooks(array('pdfgeneration'));
  649. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  650. global $action;
  651. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  652. if ($reshook < 0) {
  653. $this->error = $hookmanager->error;
  654. $this->errors = $hookmanager->errors;
  655. }
  656. if (!empty($conf->global->MAIN_UMASK)) {
  657. @chmod($file, octdec($conf->global->MAIN_UMASK));
  658. }
  659. $this->result = array('fullpath'=>$file);
  660. return 1; // No error
  661. } else {
  662. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  663. return 0;
  664. }
  665. } else {
  666. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  667. return 0;
  668. }
  669. }
  670. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  671. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  672. /**
  673. * Show total to pay
  674. *
  675. * @param TCPDF $pdf Object PDF
  676. * @param Expedition $object Object expedition
  677. * @param int $deja_regle Amount already paid
  678. * @param int $posy Start Position
  679. * @param Translate $outputlangs Objet langs
  680. * @return int Position for suite
  681. */
  682. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  683. {
  684. // phpcs:enable
  685. global $conf, $mysoc;
  686. $sign = 1;
  687. $default_font_size = pdf_getPDFFontSize($outputlangs);
  688. $tab2_top = $posy;
  689. $tab2_hl = 4;
  690. $pdf->SetFont('', 'B', $default_font_size - 1);
  691. // Total table
  692. $col1x = $this->posxweightvol - 50;
  693. $col2x = $this->posxweightvol;
  694. /*if ($this->page_largeur < 210) // To work with US executive format
  695. {
  696. $col2x-=20;
  697. }*/
  698. if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) {
  699. $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  700. } else {
  701. $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  702. }
  703. $useborder = 0;
  704. $index = 0;
  705. $totalWeighttoshow = '';
  706. $totalVolumetoshow = '';
  707. // Load dim data
  708. $tmparray = $object->getTotalWeightVolume();
  709. $totalWeight = $tmparray['weight'];
  710. $totalVolume = $tmparray['volume'];
  711. $totalOrdered = $tmparray['ordered'];
  712. $totalToShip = $tmparray['toship'];
  713. // Set trueVolume and volume_units not currently stored into database
  714. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  715. $object->trueVolume = $object->trueWidth * $object->trueHeight * $object->trueDepth;
  716. $object->volume_units = $object->size_units * 3;
  717. }
  718. if ($totalWeight != '') {
  719. $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  720. }
  721. if ($totalVolume != '') {
  722. $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  723. }
  724. if ($object->trueWeight) {
  725. $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  726. }
  727. if ($object->trueVolume) {
  728. if ($object->volume_units < 50) {
  729. $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  730. } else {
  731. $totalVolumetoshow = price($object->trueVolume, 0, $outputlangs, 0, 0).' '.measuringUnitString(0, "volume", $object->volume_units);
  732. }
  733. }
  734. if ($this->getColumnStatus('desc')) {
  735. $this->printStdColumnContent($pdf, $tab2_top, 'desc', $outputlangs->transnoentities("Total"));
  736. }
  737. if ($this->getColumnStatus('weight')) {
  738. if ($totalWeighttoshow) {
  739. $this->printStdColumnContent($pdf, $tab2_top, 'weight', $totalWeighttoshow);
  740. $index++;
  741. }
  742. if ($totalVolumetoshow) {
  743. $y = $tab2_top + ($tab2_hl * $index);
  744. $this->printStdColumnContent($pdf, $y, 'weight', $totalVolumetoshow);
  745. }
  746. }
  747. if ($this->getColumnStatus('qty_asked') && $totalOrdered) {
  748. $this->printStdColumnContent($pdf, $tab2_top, 'qty_asked', $totalOrdered);
  749. }
  750. if ($this->getColumnStatus('qty_shipped') && $totalToShip) {
  751. $this->printStdColumnContent($pdf, $tab2_top, 'qty_shipped', $totalToShip);
  752. }
  753. if ($this->getColumnStatus('subprice')) {
  754. $this->printStdColumnContent($pdf, $tab2_top, 'subprice', price($object->total_ht, 0, $outputlangs));
  755. }
  756. $pdf->SetTextColor(0, 0, 0);
  757. return ($tab2_top + ($tab2_hl * $index));
  758. }
  759. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  760. /**
  761. * Show table for lines
  762. *
  763. * @param TCPDF $pdf Object PDF
  764. * @param string $tab_top Top position of table
  765. * @param string $tab_height Height of table (rectangle)
  766. * @param int $nexY Y
  767. * @param Translate $outputlangs Langs object
  768. * @param int $hidetop Hide top bar of array
  769. * @param int $hidebottom Hide bottom bar of array
  770. * @return void
  771. */
  772. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  773. {
  774. global $conf;
  775. // Force to disable hidetop and hidebottom
  776. $hidebottom = 0;
  777. if ($hidetop) {
  778. $hidetop = -1;
  779. }
  780. $currency = !empty($currency) ? $currency : $conf->currency;
  781. $default_font_size = pdf_getPDFFontSize($outputlangs);
  782. // Amount in (at tab_top - 1)
  783. $pdf->SetTextColor(0, 0, 0);
  784. $pdf->SetFont('', '', $default_font_size - 2);
  785. if (empty($hidetop)) {
  786. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  787. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  788. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  789. }
  790. }
  791. $pdf->SetDrawColor(128, 128, 128);
  792. $pdf->SetFont('', '', $default_font_size - 1);
  793. // Output Rect
  794. $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
  795. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  796. if (empty($hidetop)) {
  797. $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
  798. }
  799. }
  800. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  801. /**
  802. * Show top header of page.
  803. *
  804. * @param TCPDF $pdf Object PDF
  805. * @param Expedition $object Object to show
  806. * @param int $showaddress 0=no, 1=yes
  807. * @param Translate $outputlangs Object lang for output
  808. * @return int <0 if KO, > if OK
  809. */
  810. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  811. {
  812. global $conf, $langs, $mysoc;
  813. $langs->load("orders");
  814. $default_font_size = pdf_getPDFFontSize($outputlangs);
  815. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  816. //Prepare next
  817. $pdf->SetTextColor(0, 0, 60);
  818. $pdf->SetFont('', 'B', $default_font_size + 3);
  819. $w = 110;
  820. $posy = $this->marge_haute;
  821. $posx = $this->page_largeur - $this->marge_droite - $w;
  822. $pdf->SetXY($this->marge_gauche, $posy);
  823. // Logo
  824. if ($this->emetteur->logo) {
  825. $logodir = $conf->mycompany->dir_output;
  826. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  827. $logodir = $conf->mycompany->multidir_output[$object->entity];
  828. }
  829. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  830. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  831. } else {
  832. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  833. }
  834. if (is_readable($logo)) {
  835. $height = pdf_getHeightForLogo($logo);
  836. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  837. } else {
  838. $pdf->SetTextColor(200, 0, 0);
  839. $pdf->SetFont('', 'B', $default_font_size - 2);
  840. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  841. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  842. }
  843. } else {
  844. $text = $this->emetteur->name;
  845. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  846. }
  847. // Show barcode
  848. if (isModEnabled('barcode')) {
  849. $posx = 105;
  850. } else {
  851. $posx = $this->marge_gauche + 3;
  852. }
  853. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  854. if (isModEnabled('barcode')) {
  855. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  856. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  857. //$pdf->Image($logo,10, 5, 0, 24);
  858. }
  859. $pdf->SetDrawColor(128, 128, 128);
  860. if (isModEnabled('barcode')) {
  861. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  862. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  863. //$pdf->Image($logo,10, 5, 0, 24);
  864. }
  865. $posx = $this->page_largeur - $w - $this->marge_droite;
  866. $posy = $this->marge_haute;
  867. $pdf->SetFont('', 'B', $default_font_size + 2);
  868. $pdf->SetXY($posx, $posy);
  869. $pdf->SetTextColor(0, 0, 60);
  870. $title = $outputlangs->transnoentities("SendingSheet");
  871. $pdf->MultiCell($w, 4, $title, '', 'R');
  872. $pdf->SetFont('', '', $default_font_size + 1);
  873. $posy += 5;
  874. $pdf->SetXY($posx, $posy);
  875. $pdf->SetTextColor(0, 0, 60);
  876. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending")." : ".$object->ref, '', 'R');
  877. // Date planned delivery
  878. if (!empty($object->date_delivery)) {
  879. $posy += 4;
  880. $pdf->SetXY($posx, $posy);
  881. $pdf->SetTextColor(0, 0, 60);
  882. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
  883. }
  884. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
  885. $posy += 4;
  886. $pdf->SetXY($posx, $posy);
  887. $pdf->SetTextColor(0, 0, 60);
  888. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  889. }
  890. $pdf->SetFont('', '', $default_font_size + 3);
  891. $Yoff = 25;
  892. // Add list of linked orders
  893. $origin = $object->origin;
  894. $origin_id = $object->origin_id;
  895. // TODO move to external function
  896. if (!empty($conf->$origin->enabled)) { // commonly $origin='commande'
  897. $outputlangs->load('orders');
  898. $classname = ucfirst($origin);
  899. $linkedobject = new $classname($this->db);
  900. $result = $linkedobject->fetch($origin_id);
  901. if ($result >= 0) {
  902. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  903. $pdf->SetFont('', '', $default_font_size - 2);
  904. $text = $linkedobject->ref;
  905. if ($linkedobject->ref_client) {
  906. $text .= ' ('.$linkedobject->ref_client.')';
  907. }
  908. $Yoff = $Yoff + 8;
  909. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  910. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
  911. $Yoff = $Yoff + 3;
  912. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  913. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  914. }
  915. }
  916. $top_shift = 0;
  917. // Show list of linked objects
  918. /*$current_y = $pdf->getY();
  919. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  920. if ($current_y < $pdf->getY()) {
  921. $top_shift = $pdf->getY() - $current_y;
  922. }*/
  923. if ($showaddress) {
  924. // Sender properties
  925. $carac_emetteur = '';
  926. // Add internal contact of origin element if defined
  927. $arrayidcontact = array();
  928. if (!empty($origin) && is_object($object->$origin)) {
  929. $arrayidcontact = $object->$origin->getIdContact('internal', 'SALESREPFOLL');
  930. }
  931. if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
  932. $object->fetch_user(reset($arrayidcontact));
  933. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  934. }
  935. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  936. // Show sender
  937. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  938. $posx = $this->marge_gauche;
  939. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  940. $posx = $this->page_largeur - $this->marge_droite - 80;
  941. }
  942. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  943. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  944. // Show sender frame
  945. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  946. $pdf->SetTextColor(0, 0, 0);
  947. $pdf->SetFont('', '', $default_font_size - 2);
  948. $pdf->SetXY($posx, $posy - 5);
  949. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
  950. $pdf->SetXY($posx, $posy);
  951. $pdf->SetFillColor(230, 230, 230);
  952. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  953. $pdf->SetTextColor(0, 0, 60);
  954. $pdf->SetFillColor(255, 255, 255);
  955. }
  956. // Show sender name
  957. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  958. $pdf->SetXY($posx + 2, $posy + 3);
  959. $pdf->SetFont('', 'B', $default_font_size);
  960. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  961. $posy = $pdf->getY();
  962. }
  963. // Show sender information
  964. $pdf->SetXY($posx + 2, $posy);
  965. $pdf->SetFont('', '', $default_font_size - 1);
  966. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
  967. // If SHIPPING contact defined, we use it
  968. $usecontact = false;
  969. $arrayidcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  970. if (count($arrayidcontact) > 0) {
  971. $usecontact = true;
  972. $result = $object->fetch_contact($arrayidcontact[0]);
  973. }
  974. // Recipient name
  975. if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  976. $thirdparty = $object->contact;
  977. } else {
  978. $thirdparty = $object->thirdparty;
  979. }
  980. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  981. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  982. // Show recipient
  983. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  984. if ($this->page_largeur < 210) {
  985. $widthrecbox = 84; // To work with US executive format
  986. }
  987. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  988. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  989. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  990. $posx = $this->marge_gauche;
  991. }
  992. // Show recipient frame
  993. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  994. $pdf->SetTextColor(0, 0, 0);
  995. $pdf->SetFont('', '', $default_font_size - 2);
  996. $pdf->SetXY($posx + 2, $posy - 5);
  997. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
  998. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  999. }
  1000. // Show recipient name
  1001. $pdf->SetXY($posx + 2, $posy + 3);
  1002. $pdf->SetFont('', 'B', $default_font_size);
  1003. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
  1004. $posy = $pdf->getY();
  1005. // Show recipient information
  1006. $pdf->SetFont('', '', $default_font_size - 1);
  1007. $pdf->SetXY($posx + 2, $posy);
  1008. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  1009. }
  1010. $pdf->SetTextColor(0, 0, 0);
  1011. return $top_shift;
  1012. }
  1013. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1014. /**
  1015. * Show footer of page. Need this->emetteur object
  1016. *
  1017. * @param TCPDF $pdf PDF
  1018. * @param Expedition $object Object to show
  1019. * @param Translate $outputlangs Object lang for output
  1020. * @param int $hidefreetext 1=Hide free text
  1021. * @return int Return height of bottom margin including footer text
  1022. */
  1023. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1024. {
  1025. $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
  1026. return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
  1027. }
  1028. /**
  1029. * Define Array Column Field
  1030. *
  1031. * @param Expedition $object common object
  1032. * @param Translate $outputlangs langs
  1033. * @param int $hidedetails Do not show line details
  1034. * @param int $hidedesc Do not show desc
  1035. * @param int $hideref Do not show ref
  1036. * @return null
  1037. */
  1038. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1039. {
  1040. global $conf, $hookmanager;
  1041. // Default field style for content
  1042. $this->defaultContentsFieldsStyle = array(
  1043. 'align' => 'R', // R,C,L
  1044. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1045. );
  1046. // Default field style for content
  1047. $this->defaultTitlesFieldsStyle = array(
  1048. 'align' => 'C', // R,C,L
  1049. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1050. );
  1051. /*
  1052. * For exemple
  1053. $this->cols['theColKey'] = array(
  1054. 'rank' => $rank, // int : use for ordering columns
  1055. 'width' => 20, // the column width in mm
  1056. 'title' => array(
  1057. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1058. 'label' => ' ', // the final label : used fore final generated text
  1059. 'align' => 'L', // text alignement : R,C,L
  1060. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1061. ),
  1062. 'content' => array(
  1063. 'align' => 'L', // text alignement : R,C,L
  1064. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1065. ),
  1066. );
  1067. */
  1068. $rank = 0; // do not use negative rank
  1069. $this->cols['desc'] = array(
  1070. 'rank' => $rank,
  1071. 'width' => false, // only for desc
  1072. 'status' => true,
  1073. 'title' => array(
  1074. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1075. 'align' => 'L',
  1076. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1077. // 'label' => ' ', // the final label
  1078. 'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1079. ),
  1080. 'content' => array(
  1081. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1082. ),
  1083. );
  1084. $rank = $rank + 10;
  1085. $this->cols['photo'] = array(
  1086. 'rank' => $rank,
  1087. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1088. 'status' => false,
  1089. 'title' => array(
  1090. 'textkey' => 'Photo',
  1091. 'label' => ' '
  1092. ),
  1093. 'content' => array(
  1094. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1095. ),
  1096. 'border-left' => false, // remove left line separator
  1097. );
  1098. if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE) && !empty($this->atleastonephoto)) {
  1099. $this->cols['photo']['status'] = true;
  1100. }
  1101. $rank = $rank + 10;
  1102. $this->cols['weight'] = array(
  1103. 'rank' => $rank,
  1104. 'width' => 30, // in mm
  1105. 'status' => true,
  1106. 'title' => array(
  1107. 'textkey' => 'WeightVolShort'
  1108. ),
  1109. 'border-left' => true, // add left line separator
  1110. );
  1111. $rank = $rank + 10;
  1112. $this->cols['subprice'] = array(
  1113. 'rank' => $rank,
  1114. 'width' => 19, // in mm
  1115. 'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT) ? 1 : 0,
  1116. 'title' => array(
  1117. 'textkey' => 'PriceUHT'
  1118. ),
  1119. 'border-left' => true, // add left line separator
  1120. );
  1121. $rank = $rank + 10;
  1122. $this->cols['totalexcltax'] = array(
  1123. 'rank' => $rank,
  1124. 'width' => 26, // in mm
  1125. 'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT) ? 1 : 0,
  1126. 'title' => array(
  1127. 'textkey' => 'TotalHT'
  1128. ),
  1129. 'border-left' => true, // add left line separator
  1130. );
  1131. $rank = $rank + 10;
  1132. $this->cols['qty_asked'] = array(
  1133. 'rank' => $rank,
  1134. 'width' => 30, // in mm
  1135. 'status' => empty($conf->global->SHIPPING_PDF_HIDE_ORDERED) ? 1 : 0,
  1136. 'title' => array(
  1137. 'textkey' => 'QtyOrdered'
  1138. ),
  1139. 'border-left' => true, // add left line separator
  1140. 'content' => array(
  1141. 'align' => 'C',
  1142. ),
  1143. );
  1144. $rank = $rank + 10;
  1145. $this->cols['unit_order'] = array(
  1146. 'rank' => $rank,
  1147. 'width' => 15, // in mm
  1148. 'status' => empty($conf->global->PRODUCT_USE_UNITS) ? 0 : 1,
  1149. 'title' => array(
  1150. 'textkey' => 'Unit'
  1151. ),
  1152. 'border-left' => true, // add left line separator
  1153. 'content' => array(
  1154. 'align' => 'C',
  1155. ),
  1156. );
  1157. $rank = $rank + 10;
  1158. $this->cols['qty_shipped'] = array(
  1159. 'rank' => $rank,
  1160. 'width' => 30, // in mm
  1161. 'status' => true,
  1162. 'title' => array(
  1163. 'textkey' => 'QtyToShip'
  1164. ),
  1165. 'border-left' => true, // add left line separator
  1166. 'content' => array(
  1167. 'align' => 'C',
  1168. ),
  1169. );
  1170. // Add extrafields cols
  1171. if (!empty($object->lines)) {
  1172. $line = reset($object->lines);
  1173. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  1174. }
  1175. $parameters = array(
  1176. 'object' => $object,
  1177. 'outputlangs' => $outputlangs,
  1178. 'hidedetails' => $hidedetails,
  1179. 'hidedesc' => $hidedesc,
  1180. 'hideref' => $hideref
  1181. );
  1182. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1183. if ($reshook < 0) {
  1184. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1185. } elseif (empty($reshook)) {
  1186. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1187. } else {
  1188. $this->cols = $hookmanager->resArray;
  1189. }
  1190. }
  1191. }