pdf_squille.modules.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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($db = 0)
  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 = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  53. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  54. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  55. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->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. }
  457. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  458. if ($pagenb == 1) {
  459. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
  460. } else {
  461. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
  462. }
  463. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  464. // New page
  465. $pdf->AddPage();
  466. if (!empty($tplidx)) {
  467. $pdf->useTemplate($tplidx);
  468. }
  469. $pagenb++;
  470. }
  471. }
  472. // Show square
  473. if ($pagenb == 1) {
  474. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
  475. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  476. } else {
  477. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
  478. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  479. }
  480. // Affiche zone totaux
  481. $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs, $totalOrdered);
  482. // Pied de page
  483. $this->_pagefoot($pdf, $object, $outputlangs);
  484. if (method_exists($pdf, 'AliasNbPages')) {
  485. $pdf->AliasNbPages();
  486. }
  487. $pdf->Close();
  488. $pdf->Output($file, 'F');
  489. // Add pdfgeneration hook
  490. $hookmanager->initHooks(array('pdfgeneration'));
  491. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  492. global $action;
  493. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  494. if ($reshook < 0) {
  495. $this->error = $hookmanager->error;
  496. $this->errors = $hookmanager->errors;
  497. }
  498. if (!empty($conf->global->MAIN_UMASK)) {
  499. @chmod($file, octdec($conf->global->MAIN_UMASK));
  500. }
  501. return 1; // No error
  502. } else {
  503. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  504. return 0;
  505. }
  506. } else {
  507. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
  508. return 0;
  509. }
  510. }
  511. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  512. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  513. /**
  514. * Show total to pay
  515. *
  516. * @param TCPDF $pdf Object PDF
  517. * @param Facture $object Object invoice
  518. * @param int $deja_regle Montant deja regle
  519. * @param int $posy Position depart
  520. * @param Translate $outputlangs Objet langs
  521. * @param int $totalOrdered Total ordered
  522. * @return int Position pour suite
  523. */
  524. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $totalOrdered)
  525. {
  526. // phpcs:enable
  527. global $conf, $mysoc;
  528. $sign = 1;
  529. $default_font_size = pdf_getPDFFontSize($outputlangs);
  530. $tab2_top = $posy;
  531. $tab2_hl = 4;
  532. $pdf->SetFont('', 'B', $default_font_size - 1);
  533. // Tableau total
  534. $col1x = $this->posxweightvol - 50;
  535. $col2x = $this->posxweightvol;
  536. /*if ($this->page_largeur < 210) // To work with US executive format
  537. {
  538. $col2x-=20;
  539. }*/
  540. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  541. $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  542. } else {
  543. $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  544. }
  545. $useborder = 0;
  546. $index = 0;
  547. $totalWeighttoshow = '';
  548. $totalVolumetoshow = '';
  549. // Load dim data
  550. $tmparray = $object->getTotalWeightVolume();
  551. $totalWeight = $tmparray['weight'];
  552. $totalVolume = $tmparray['volume'];
  553. $totalToShip = $tmparray['toship'];
  554. // Set trueVolume and volume_units not currently stored into database
  555. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  556. $object->trueVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  557. $object->volume_units = $object->size_units * 3;
  558. }
  559. if ($totalWeight != '') {
  560. $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  561. }
  562. if ($totalVolume != '') {
  563. $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  564. }
  565. if ($object->trueWeight) {
  566. $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  567. }
  568. if ($object->trueVolume) {
  569. $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  570. }
  571. $pdf->SetFillColor(255, 255, 255);
  572. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  573. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
  574. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  575. $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
  576. $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
  577. }
  578. $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
  579. $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
  580. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  581. $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
  582. $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
  583. $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
  584. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
  585. }
  586. // Total Weight
  587. if ($totalWeighttoshow) {
  588. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  589. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
  590. $index++;
  591. }
  592. if ($totalVolumetoshow) {
  593. $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  594. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
  595. $index++;
  596. }
  597. if (!$totalWeighttoshow && !$totalVolumetoshow) {
  598. $index++;
  599. }
  600. $pdf->SetTextColor(0, 0, 0);
  601. return ($tab2_top + ($tab2_hl * $index));
  602. }
  603. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  604. /**
  605. * Show table for lines
  606. *
  607. * @param TCPDF $pdf Object PDF
  608. * @param string $tab_top Top position of table
  609. * @param string $tab_height Height of table (rectangle)
  610. * @param int $nexY Y
  611. * @param Translate $outputlangs Langs object
  612. * @param int $hidetop Hide top bar of array
  613. * @param int $hidebottom Hide bottom bar of array
  614. * @param Object|NULL $object Object reception to generate
  615. * @return void
  616. */
  617. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = null)
  618. {
  619. global $conf;
  620. // Force to disable hidetop and hidebottom
  621. $hidebottom = 0;
  622. if ($hidetop) {
  623. $hidetop = -1;
  624. }
  625. $default_font_size = pdf_getPDFFontSize($outputlangs);
  626. // Amount in (at tab_top - 1)
  627. $pdf->SetTextColor(0, 0, 0);
  628. $pdf->SetFont('', '', $default_font_size - 2);
  629. // Output Rect
  630. $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
  631. $pdf->SetDrawColor(128, 128, 128);
  632. $pdf->SetFont('', '', $default_font_size - 1);
  633. if (empty($hidetop)) {
  634. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
  635. $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
  636. $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
  637. }
  638. $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
  639. if (empty($hidetop)) {
  640. $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
  641. $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
  642. }
  643. if (empty($conf->global->RECEPTION_PDF_HIDE_ORDERED)) {
  644. $pdf->line($this->posxqtyordered - 1, $tab_top, $this->posxqtyordered - 1, $tab_top + $tab_height);
  645. if (empty($hidetop)) {
  646. $pdf->SetXY($this->posxqtyordered - 1, $tab_top + 1);
  647. $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
  648. }
  649. }
  650. $pdf->line($this->posxqtytoship - 1, $tab_top, $this->posxqtytoship - 1, $tab_top + $tab_height);
  651. if (empty($hidetop)) {
  652. $pdf->SetXY($this->posxqtytoship, $tab_top + 1);
  653. $statusreceived = Reception::STATUS_CLOSED;
  654. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
  655. $statusreceived = Reception::STATUS_VALIDATED;
  656. }
  657. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
  658. $statusreceived = Reception::STATUS_CLOSED;
  659. }
  660. if ($object && $object->statut < $statusreceived) {
  661. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities('QtyToReceive'), '', 'C');
  662. } else {
  663. $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities('QtyReceived'), '', 'C');
  664. }
  665. }
  666. if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
  667. $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
  668. if (empty($hidetop)) {
  669. $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
  670. $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  671. }
  672. $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
  673. if (empty($hidetop)) {
  674. $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
  675. $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
  676. }
  677. }
  678. }
  679. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  680. /**
  681. * Show top header of page.
  682. *
  683. * @param TCPDF $pdf Object PDF
  684. * @param Object $object Object to show
  685. * @param int $showaddress 0=no, 1=yes
  686. * @param Translate $outputlangs Object lang for output
  687. * @return void
  688. */
  689. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  690. {
  691. global $conf, $langs, $mysoc;
  692. $langs->load("orders");
  693. $default_font_size = pdf_getPDFFontSize($outputlangs);
  694. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  695. //Prepare la suite
  696. $pdf->SetTextColor(0, 0, 60);
  697. $pdf->SetFont('', 'B', $default_font_size + 3);
  698. $w = 110;
  699. $posy = $this->marge_haute;
  700. $posx = $this->page_largeur - $this->marge_droite - $w;
  701. $pdf->SetXY($this->marge_gauche, $posy);
  702. // Logo
  703. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  704. if ($this->emetteur->logo) {
  705. if (is_readable($logo)) {
  706. $height = pdf_getHeightForLogo($logo);
  707. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  708. } else {
  709. $pdf->SetTextColor(200, 0, 0);
  710. $pdf->SetFont('', 'B', $default_font_size - 2);
  711. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  712. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  713. }
  714. } else {
  715. $text = $this->emetteur->name;
  716. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  717. }
  718. // Show barcode
  719. if (!empty($conf->barcode->enabled)) {
  720. $posx = 105;
  721. } else {
  722. $posx = $this->marge_gauche + 3;
  723. }
  724. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  725. if (!empty($conf->barcode->enabled)) {
  726. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  727. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  728. //$pdf->Image($logo,10, 5, 0, 24);
  729. }
  730. $pdf->SetDrawColor(128, 128, 128);
  731. if (!empty($conf->barcode->enabled)) {
  732. // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref
  733. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  734. //$pdf->Image($logo,10, 5, 0, 24);
  735. }
  736. $posx = $this->page_largeur - $w - $this->marge_droite;
  737. $posy = $this->marge_haute;
  738. $pdf->SetFont('', 'B', $default_font_size + 2);
  739. $pdf->SetXY($posx, $posy);
  740. $pdf->SetTextColor(0, 0, 60);
  741. $title = $outputlangs->transnoentities("ReceptionSheet");
  742. $pdf->MultiCell($w, 4, $title, '', 'R');
  743. $pdf->SetFont('', '', $default_font_size + 1);
  744. $posy += 5;
  745. $pdf->SetXY($posx, $posy);
  746. $pdf->SetTextColor(0, 0, 60);
  747. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefReception")." : ".$object->ref, '', 'R');
  748. // Date planned delivery
  749. if (!empty($object->date_delivery)) {
  750. $posy += 4;
  751. $pdf->SetXY($posx, $posy);
  752. $pdf->SetTextColor(0, 0, 60);
  753. $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
  754. }
  755. if (!empty($object->thirdparty->code_fournisseur)) {
  756. $posy += 4;
  757. $pdf->SetXY($posx, $posy);
  758. $pdf->SetTextColor(0, 0, 60);
  759. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
  760. }
  761. $pdf->SetFont('', '', $default_font_size + 3);
  762. $Yoff = 25;
  763. // Add list of linked orders
  764. $origin = $object->origin;
  765. $origin_id = $object->origin_id;
  766. // TODO move to external function
  767. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) { // commonly $origin='commande'
  768. $outputlangs->load('orders');
  769. $classname = 'CommandeFournisseur';
  770. $linkedobject = new $classname($this->db);
  771. $result = $linkedobject->fetch($origin_id);
  772. if ($result >= 0) {
  773. //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  774. $pdf->SetFont('', '', $default_font_size - 2);
  775. $text = $linkedobject->ref;
  776. if ($linkedobject->ref_client) {
  777. $text .= ' ('.$linkedobject->ref_client.')';
  778. }
  779. $Yoff = $Yoff + 8;
  780. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  781. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
  782. $Yoff = $Yoff + 3;
  783. $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
  784. $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
  785. }
  786. }
  787. if ($showaddress) {
  788. // Sender properties
  789. $carac_emetteur = '';
  790. // Add internal contact of origin element if defined
  791. $arrayidcontact = array();
  792. if (!empty($origin) && is_object($object->$origin)) {
  793. $arrayidcontact = $object->$origin->getIdContact('internal', 'SALESREPFOLL');
  794. }
  795. if (empty($arrayidcontact)) {
  796. $arrayidcontact = $object->$origin->getIdContact('internal', 'SHIPPING');
  797. }
  798. if (count($arrayidcontact) > 0) {
  799. $object->fetch_user(reset($arrayidcontact));
  800. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  801. }
  802. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  803. // Show sender
  804. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  805. $posx = $this->marge_gauche;
  806. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  807. $posx = $this->page_largeur - $this->marge_droite - 80;
  808. }
  809. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  810. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  811. // Show sender frame
  812. $pdf->SetTextColor(0, 0, 0);
  813. $pdf->SetFont('', '', $default_font_size - 2);
  814. $pdf->SetXY($posx, $posy - 5);
  815. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
  816. $pdf->SetXY($posx, $posy);
  817. $pdf->SetFillColor(230, 230, 230);
  818. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  819. $pdf->SetTextColor(0, 0, 60);
  820. $pdf->SetFillColor(255, 255, 255);
  821. // If RECEPTION contact defined, we use it
  822. $usecontact = false;
  823. $arrayidcontact = $object->$origin->getIdContact('external', 'SHIPPING');
  824. if (count($arrayidcontact) > 0) {
  825. $usecontact = true;
  826. $result = $object->fetch_contact($arrayidcontact[0]);
  827. }
  828. // Recipient name
  829. 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)))) {
  830. $thirdparty = $object->contact;
  831. } else {
  832. $thirdparty = $object->thirdparty;
  833. }
  834. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  835. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
  836. // Show recipient name
  837. $pdf->SetXY($posx + 2, $posy + 3);
  838. $pdf->SetFont('', 'B', $default_font_size);
  839. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client_name, 0, 'L');
  840. $posy = $pdf->getY();
  841. // Show recipient information
  842. $pdf->SetFont('', '', $default_font_size - 1);
  843. $pdf->SetXY($posx + 2, $posy);
  844. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, 'L');
  845. // Show recipient
  846. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  847. if ($this->page_largeur < 210) {
  848. $widthrecbox = 84; // To work with US executive format
  849. }
  850. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  851. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  852. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  853. $posx = $this->marge_gauche;
  854. }
  855. // Show recipient frame
  856. $pdf->SetTextColor(0, 0, 0);
  857. $pdf->SetFont('', '', $default_font_size - 2);
  858. $pdf->SetXY($posx + 2, $posy - 5);
  859. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
  860. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  861. // Show sender name
  862. $pdf->SetXY($posx + 2, $posy + 3);
  863. $pdf->SetFont('', 'B', $default_font_size);
  864. $pdf->MultiCell($widthrecbox, 2, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  865. $posy = $pdf->getY();
  866. // Show sender information
  867. $pdf->SetXY($posx + 2, $posy);
  868. $pdf->SetFont('', '', $default_font_size - 1);
  869. $pdf->MultiCell($widthrecbox, 4, $carac_emetteur, 0, 'L');
  870. }
  871. $pdf->SetTextColor(0, 0, 0);
  872. }
  873. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  874. /**
  875. * Show footer of page. Need this->emetteur object
  876. *
  877. * @param TCPDF $pdf PDF
  878. * @param Object $object Object to show
  879. * @param Translate $outputlangs Object lang for output
  880. * @param int $hidefreetext 1=Hide free text
  881. * @return int Return height of bottom margin including footer text
  882. */
  883. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  884. {
  885. global $conf;
  886. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  887. 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);
  888. }
  889. }