pdf_squille.modules.php 42 KB

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