pdf_squille.modules.php 41 KB

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