pdf_rouget.modules.php 43 KB

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