pdf_squille.modules.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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 (!empty($conf->global->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 (empty($conf->global->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 (!empty($conf->global->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 = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  231. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  232. // Incoterm
  233. $height_incoterms = 0;
  234. if (!empty($conf->incoterm->enabled)) {
  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. // Loop on each lines
  300. for ($i = 0; $i < $nblines; $i++) {
  301. $curY = $nexY;
  302. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  303. $pdf->SetTextColor(0, 0, 0);
  304. // Define size of image if we need it
  305. $imglinesize = array();
  306. if (!empty($realpatharray[$i])) {
  307. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  308. }
  309. $pdf->setTopMargin($tab_top_newpage);
  310. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  311. $pageposbefore = $pdf->getPage();
  312. $showpricebeforepagebreak = 1;
  313. $posYAfterImage = 0;
  314. $posYAfterDescription = 0;
  315. // We start with Photo of product line
  316. 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
  317. $pdf->AddPage('', '', true);
  318. if (!empty($tplidx)) {
  319. $pdf->useTemplate($tplidx);
  320. }
  321. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  322. $this->_pagehead($pdf, $object, 0, $outputlangs);
  323. }
  324. $pdf->setPage($pageposbefore + 1);
  325. $curY = $tab_top_newpage;
  326. // Allows data in the first page if description is long enough to break in multiples pages
  327. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  328. $showpricebeforepagebreak = 1;
  329. } else {
  330. $showpricebeforepagebreak = 0;
  331. }
  332. }
  333. if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
  334. $curX = $this->posxpicture - 1;
  335. $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  336. // $pdf->Image does not increase value return by getY, so we save it manually
  337. $posYAfterImage = $curY + $imglinesize['height'];
  338. }
  339. // Description of product line
  340. $curX = $this->posxdesc - 1;
  341. // The desc of line is not store into reception, so we force it to the value of product.
  342. /*
  343. if (empty($object->lines[0]->desc)) {
  344. // TODO We must get value from fk_commendefourndet
  345. $sqldesc = 'SELECT description FROM '.MAIN_DB_PREFIX.' WHERE rowid = '.((int) $object->lines[0]->fk_commandefourndet);
  346. $resqldesc = $this->db->query($sqldesc);
  347. if ($resqldesc) {
  348. $objdesc = $this->db->fetch_object($resqldesc);
  349. $object->lines[0]->desc = $objdesc->description;
  350. }
  351. }*/
  352. $pdf->startTransaction();
  353. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
  354. $pageposafter = $pdf->getPage();
  355. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  356. $pdf->rollbackTransaction(true);
  357. $pageposafter = $pageposbefore;
  358. //print $pageposafter.'-'.$pageposbefore;exit;
  359. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  360. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
  361. $pageposafter = $pdf->getPage();
  362. $posyafter = $pdf->GetY();
  363. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  364. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  365. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  366. $pdf->AddPage('', '', true);
  367. if (!empty($tplidx)) {
  368. $pdf->useTemplate($tplidx);
  369. }
  370. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  371. $this->_pagehead($pdf, $object, 0, $outputlangs);
  372. }
  373. $pdf->setPage($pageposafter + 1);
  374. }
  375. } else {
  376. // We found a page break
  377. // Allows data in the first page if description is long enough to break in multiples pages
  378. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  379. $showpricebeforepagebreak = 1;
  380. } else {
  381. $showpricebeforepagebreak = 0;
  382. }
  383. }
  384. } else // No pagebreak
  385. {
  386. $pdf->commitTransaction();
  387. }
  388. $posYAfterDescription = $pdf->GetY();
  389. $nexY = max($pdf->GetY(), $posYAfterImage);
  390. $pageposafter = $pdf->getPage();
  391. $pdf->setPage($pageposbefore);
  392. $pdf->setTopMargin($this->marge_haute);
  393. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  394. // We suppose that a too long description or photo were moved completely on next page
  395. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  396. $pdf->setPage($pageposafter);
  397. $curY = $tab_top_newpage;
  398. }
  399. // We suppose that a too long description is moved completely on next page
  400. if ($pageposafter > $pageposbefore) {
  401. $pdf->setPage($pageposafter);
  402. $curY = $tab_top_newpage;
  403. }
  404. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  405. $pdf->SetXY($this->posxweightvol, $curY);
  406. $weighttxt = '';
  407. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->weight) {
  408. $weighttxt = round($object->lines[$i]->product->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->product->weight_units);
  409. }
  410. $voltxt = '';
  411. if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->volume) {
  412. $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);
  413. }
  414. $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, 0, 0, false, true, 'C');
  415. //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
  416. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  417. $pdf->SetXY($this->posxqtyordered, $curY);
  418. if ($object->lines[$i]->fk_commandefourndet != $fk_commandefourndet) {
  419. $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked, '', 'C');
  420. $totalOrdered += $object->lines[$i]->qty_asked;
  421. }
  422. $fk_commandefourndet = $object->lines[$i]->fk_commandefourndet;
  423. }
  424. $pdf->SetXY($this->posxqtytoship, $curY);
  425. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty, '', 'C');
  426. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  427. $pdf->SetXY($this->posxpuht, $curY);
  428. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
  429. $pdf->SetXY($this->posxtotalht, $curY);
  430. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
  431. }
  432. $nexY += 3;
  433. if ($weighttxt && $voltxt) {
  434. $nexY += 2;
  435. }
  436. // Add line
  437. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  438. $pdf->setPage($pageposafter);
  439. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  440. //$pdf->SetDrawColor(190,190,200);
  441. $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
  442. $pdf->SetLineStyle(array('dash'=>0));
  443. }
  444. // Detect if some page were added automatically and output _tableau for past pages
  445. while ($pagenb < $pageposafter) {
  446. $pdf->setPage($pagenb);
  447. if ($pagenb == 1) {
  448. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
  449. } else {
  450. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
  451. }
  452. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  453. $pagenb++;
  454. $pdf->setPage($pagenb);
  455. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  456. if (!empty($tplidx)) {
  457. $pdf->useTemplate($tplidx);
  458. }
  459. }
  460. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  461. if ($pagenb == 1) {
  462. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
  463. } else {
  464. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
  465. }
  466. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  467. // New page
  468. $pdf->AddPage();
  469. if (!empty($tplidx)) {
  470. $pdf->useTemplate($tplidx);
  471. }
  472. $pagenb++;
  473. }
  474. }
  475. // Show square
  476. if ($pagenb == 1) {
  477. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
  478. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  479. } else {
  480. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
  481. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  482. }
  483. // Affiche zone totaux
  484. $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs, $totalOrdered);
  485. // Pied de page
  486. $this->_pagefoot($pdf, $object, $outputlangs);
  487. if (method_exists($pdf, 'AliasNbPages')) {
  488. $pdf->AliasNbPages();
  489. }
  490. $pdf->Close();
  491. $pdf->Output($file, 'F');
  492. // Add pdfgeneration hook
  493. $hookmanager->initHooks(array('pdfgeneration'));
  494. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  495. global $action;
  496. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  497. if ($reshook < 0) {
  498. $this->error = $hookmanager->error;
  499. $this->errors = $hookmanager->errors;
  500. }
  501. if (!empty($conf->global->MAIN_UMASK)) {
  502. @chmod($file, octdec($conf->global->MAIN_UMASK));
  503. }
  504. return 1; // No error
  505. } else {
  506. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  507. return 0;
  508. }
  509. } else {
  510. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  511. return 0;
  512. }
  513. }
  514. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  515. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  516. /**
  517. * Show total to pay
  518. *
  519. * @param TCPDF $pdf Object PDF
  520. * @param Facture $object Object invoice
  521. * @param int $deja_regle Montant deja regle
  522. * @param int $posy Position depart
  523. * @param Translate $outputlangs Objet langs
  524. * @param int $totalOrdered Total ordered
  525. * @return int Position pour suite
  526. */
  527. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $totalOrdered)
  528. {
  529. // phpcs:enable
  530. global $conf, $mysoc;
  531. $sign = 1;
  532. $default_font_size = pdf_getPDFFontSize($outputlangs);
  533. $tab2_top = $posy;
  534. $tab2_hl = 4;
  535. $pdf->SetFont('', 'B', $default_font_size - 1);
  536. // Tableau total
  537. $col1x = $this->posxweightvol - 50;
  538. $col2x = $this->posxweightvol;
  539. /*if ($this->page_largeur < 210) // To work with US executive format
  540. {
  541. $col2x-=20;
  542. }*/
  543. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  544. $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  545. } else {
  546. $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  547. }
  548. $useborder = 0;
  549. $index = 0;
  550. $totalWeighttoshow = '';
  551. $totalVolumetoshow = '';
  552. // Load dim data
  553. $tmparray = $object->getTotalWeightVolume();
  554. $totalWeight = $tmparray['weight'];
  555. $totalVolume = $tmparray['volume'];
  556. $totalToShip = $tmparray['toship'];
  557. // Set trueVolume and volume_units not currently stored into database
  558. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  559. $object->trueVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  560. $object->volume_units = $object->size_units * 3;
  561. }
  562. if ($totalWeight != '') {
  563. $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  564. }
  565. if ($totalVolume != '') {
  566. $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  567. }
  568. if ($object->trueWeight) {
  569. $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  570. }
  571. if ($object->trueVolume) {
  572. $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  573. }
  574. $pdf->SetFillColor(255, 255, 255);
  575. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  576. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
  577. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  578. $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
  579. $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
  580. }
  581. $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
  582. $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
  583. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  584. $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
  585. $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
  586. $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
  587. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
  588. }
  589. // Total Weight
  590. if ($totalWeighttoshow) {
  591. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  592. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
  593. $index++;
  594. }
  595. if ($totalVolumetoshow) {
  596. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  597. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
  598. $index++;
  599. }
  600. if (!$totalWeighttoshow && !$totalVolumetoshow) {
  601. $index++;
  602. }
  603. $pdf->SetTextColor(0, 0, 0);
  604. return ($tab2_top + ($tab2_hl * $index));
  605. }
  606. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  607. /**
  608. * Show table for lines
  609. *
  610. * @param TCPDF $pdf Object PDF
  611. * @param string $tab_top Top position of table
  612. * @param string $tab_height Height of table (rectangle)
  613. * @param int $nexY Y
  614. * @param Translate $outputlangs Langs object
  615. * @param int $hidetop Hide top bar of array
  616. * @param int $hidebottom Hide bottom bar of array
  617. * @param Object|NULL $object Object reception to generate
  618. * @return void
  619. */
  620. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = null)
  621. {
  622. global $conf;
  623. // Force to disable hidetop and hidebottom
  624. $hidebottom = 0;
  625. if ($hidetop) {
  626. $hidetop = -1;
  627. }
  628. $default_font_size = pdf_getPDFFontSize($outputlangs);
  629. // Amount in (at tab_top - 1)
  630. $pdf->SetTextColor(0, 0, 0);
  631. $pdf->SetFont('', '', $default_font_size - 2);
  632. // Output Rect
  633. $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
  634. $pdf->SetDrawColor(128, 128, 128);
  635. $pdf->SetFont('', '', $default_font_size - 1);
  636. if (empty($hidetop)) {
  637. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
  638. $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
  639. $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
  640. }
  641. $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
  642. if (empty($hidetop)) {
  643. $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
  644. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
  645. }
  646. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  647. $pdf->line($this->posxqtyordered - 1, $tab_top, $this->posxqtyordered - 1, $tab_top + $tab_height);
  648. if (empty($hidetop)) {
  649. $pdf->SetXY($this->posxqtyordered - 1, $tab_top + 1);
  650. $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
  651. }
  652. }
  653. $pdf->line($this->posxqtytoship - 1, $tab_top, $this->posxqtytoship - 1, $tab_top + $tab_height);
  654. if (empty($hidetop)) {
  655. $pdf->SetXY($this->posxqtytoship, $tab_top + 1);
  656. $statusreceived = Reception::STATUS_CLOSED;
  657. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
  658. $statusreceived = Reception::STATUS_VALIDATED;
  659. }
  660. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
  661. $statusreceived = Reception::STATUS_CLOSED;
  662. }
  663. if ($object && $object->statut < $statusreceived) {
  664. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities('QtyToReceive'), '', 'C');
  665. } else {
  666. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities('QtyReceived'), '', 'C');
  667. }
  668. }
  669. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  670. $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
  671. if (empty($hidetop)) {
  672. $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
  673. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  674. }
  675. $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
  676. if (empty($hidetop)) {
  677. $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
  678. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
  679. }
  680. }
  681. }
  682. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  683. /**
  684. * Show top header of page.
  685. *
  686. * @param TCPDF $pdf Object PDF
  687. * @param Object $object Object to show
  688. * @param int $showaddress 0=no, 1=yes
  689. * @param Translate $outputlangs Object lang for output
  690. * @return void
  691. */
  692. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  693. {
  694. global $conf, $langs, $mysoc;
  695. $langs->load("orders");
  696. $default_font_size = pdf_getPDFFontSize($outputlangs);
  697. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  698. //Prepare la suite
  699. $pdf->SetTextColor(0, 0, 60);
  700. $pdf->SetFont('', 'B', $default_font_size + 3);
  701. $w = 110;
  702. $posy = $this->marge_haute;
  703. $posx = $this->page_largeur - $this->marge_droite - $w;
  704. $pdf->SetXY($this->marge_gauche, $posy);
  705. // Logo
  706. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  707. if ($this->emetteur->logo) {
  708. if (is_readable($logo)) {
  709. $height = pdf_getHeightForLogo($logo);
  710. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  711. } else {
  712. $pdf->SetTextColor(200, 0, 0);
  713. $pdf->SetFont('', 'B', $default_font_size - 2);
  714. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  715. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  716. }
  717. } else {
  718. $text = $this->emetteur->name;
  719. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  720. }
  721. // Show barcode
  722. if (isModEnabled('barcode')) {
  723. $posx = 105;
  724. } else {
  725. $posx = $this->marge_gauche + 3;
  726. }
  727. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  728. if (isModEnabled('barcode')) {
  729. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  730. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  731. //$pdf->Image($logo,10, 5, 0, 24);
  732. }
  733. $pdf->SetDrawColor(128, 128, 128);
  734. if (isModEnabled('barcode')) {
  735. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  736. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  737. //$pdf->Image($logo,10, 5, 0, 24);
  738. }
  739. $posx = $this->page_largeur - $w - $this->marge_droite;
  740. $posy = $this->marge_haute;
  741. $pdf->SetFont('', 'B', $default_font_size + 2);
  742. $pdf->SetXY($posx, $posy);
  743. $pdf->SetTextColor(0, 0, 60);
  744. $title = $outputlangs->transnoentities("ReceptionSheet");
  745. $pdf->MultiCell($w, 4, $title, '', 'R');
  746. $pdf->SetFont('', '', $default_font_size + 1);
  747. $posy += 5;
  748. $pdf->SetXY($posx, $posy);
  749. $pdf->SetTextColor(0, 0, 60);
  750. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefReception")." : ".$object->ref, '', 'R');
  751. // Date planned delivery
  752. if (!empty($object->date_delivery)) {
  753. $posy += 4;
  754. $pdf->SetXY($posx, $posy);
  755. $pdf->SetTextColor(0, 0, 60);
  756. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
  757. }
  758. if (!empty($object->thirdparty->code_fournisseur)) {
  759. $posy += 4;
  760. $pdf->SetXY($posx, $posy);
  761. $pdf->SetTextColor(0, 0, 60);
  762. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
  763. }
  764. $pdf->SetFont('', '', $default_font_size + 3);
  765. $Yoff = 25;
  766. // Add list of linked orders
  767. $origin = $object->origin;
  768. $origin_id = $object->origin_id;
  769. // TODO move to external function
  770. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order")) { // commonly $origin='commande'
  771. $outputlangs->load('orders');
  772. $classname = 'CommandeFournisseur';
  773. $linkedobject = new $classname($this->db);
  774. $result = $linkedobject->fetch($origin_id);
  775. if ($result >= 0) {
  776. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  777. $pdf->SetFont('', '', $default_font_size - 2);
  778. $text = $linkedobject->ref;
  779. if ($linkedobject->ref_client) {
  780. $text .= ' ('.$linkedobject->ref_client.')';
  781. }
  782. $Yoff = $Yoff + 8;
  783. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  784. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
  785. $Yoff = $Yoff + 3;
  786. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  787. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  788. }
  789. }
  790. if ($showaddress) {
  791. // Sender properties
  792. $carac_emetteur = '';
  793. // Add internal contact of origin element if defined
  794. $arrayidcontact = array();
  795. if (!empty($origin) && is_object($object->$origin)) {
  796. $arrayidcontact = $object->$origin->getIdContact('internal', 'SALESREPFOLL');
  797. }
  798. if (empty($arrayidcontact)) {
  799. $arrayidcontact = $object->$origin->getIdContact('internal', 'SHIPPING');
  800. }
  801. if (count($arrayidcontact) > 0) {
  802. $object->fetch_user(reset($arrayidcontact));
  803. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  804. }
  805. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  806. // Show sender
  807. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  808. $posx = $this->marge_gauche;
  809. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  810. $posx = $this->page_largeur - $this->marge_droite - 80;
  811. }
  812. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  813. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  814. // Show sender frame
  815. $pdf->SetTextColor(0, 0, 0);
  816. $pdf->SetFont('', '', $default_font_size - 2);
  817. $pdf->SetXY($posx, $posy - 5);
  818. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
  819. $pdf->SetXY($posx, $posy);
  820. $pdf->SetFillColor(230, 230, 230);
  821. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  822. $pdf->SetTextColor(0, 0, 60);
  823. $pdf->SetFillColor(255, 255, 255);
  824. // If RECEPTION contact defined, we use it
  825. $usecontact = false;
  826. $arrayidcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  827. if (count($arrayidcontact) > 0) {
  828. $usecontact = true;
  829. $result = $object->fetch_contact($arrayidcontact[0]);
  830. }
  831. // Recipient name
  832. 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)))) {
  833. $thirdparty = $object->contact;
  834. } else {
  835. $thirdparty = $object->thirdparty;
  836. }
  837. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  838. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  839. // Show recipient name
  840. $pdf->SetXY($posx + 2, $posy + 3);
  841. $pdf->SetFont('', 'B', $default_font_size);
  842. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client_name, 0, 'L');
  843. $posy = $pdf->getY();
  844. // Show recipient information
  845. $pdf->SetFont('', '', $default_font_size - 1);
  846. $pdf->SetXY($posx + 2, $posy);
  847. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, 'L');
  848. // Show recipient
  849. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  850. if ($this->page_largeur < 210) {
  851. $widthrecbox = 84; // To work with US executive format
  852. }
  853. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  854. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  855. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  856. $posx = $this->marge_gauche;
  857. }
  858. // Show recipient frame
  859. $pdf->SetTextColor(0, 0, 0);
  860. $pdf->SetFont('', '', $default_font_size - 2);
  861. $pdf->SetXY($posx + 2, $posy - 5);
  862. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
  863. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  864. // Show sender name
  865. $pdf->SetXY($posx + 2, $posy + 3);
  866. $pdf->SetFont('', 'B', $default_font_size);
  867. $pdf->MultiCell($widthrecbox, 2, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  868. $posy = $pdf->getY();
  869. // Show sender information
  870. $pdf->SetXY($posx + 2, $posy);
  871. $pdf->SetFont('', '', $default_font_size - 1);
  872. $pdf->MultiCell($widthrecbox, 4, $carac_emetteur, 0, 'L');
  873. }
  874. $pdf->SetTextColor(0, 0, 0);
  875. }
  876. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  877. /**
  878. * Show footer of page. Need this->emetteur object
  879. *
  880. * @param TCPDF $pdf PDF
  881. * @param Object $object Object to show
  882. * @param Translate $outputlangs Object lang for output
  883. * @param int $hidefreetext 1=Hide free text
  884. * @return int Return height of bottom margin including footer text
  885. */
  886. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  887. {
  888. global $conf;
  889. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  890. 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);
  891. }
  892. }