pdf_einstein.modules.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. <?php
  2. /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  7. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. * or see https://www.gnu.org/
  25. */
  26. /**
  27. * \file htdocs/core/modules/commande/doc/pdf_einstein.modules.php
  28. * \ingroup commande
  29. * \brief File of Class to generate PDF orders with template Einstein
  30. */
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  36. /**
  37. * Class to generate PDF orders with template Einstein
  38. */
  39. class pdf_einstein extends ModelePDFCommandes
  40. {
  41. /**
  42. * @var DoliDb Database handler
  43. */
  44. public $db;
  45. /**
  46. * @var int The environment ID when using a multicompany module
  47. */
  48. public $entity;
  49. /**
  50. * @var string model name
  51. */
  52. public $name;
  53. /**
  54. * @var string model description (short text)
  55. */
  56. public $description;
  57. /**
  58. * @var int Save the name of generated file as the main doc when generating a doc with this template
  59. */
  60. public $update_main_doc_field;
  61. /**
  62. * @var string document type
  63. */
  64. public $type;
  65. /**
  66. * @var array Minimum version of PHP required by module.
  67. * e.g.: PHP ≥ 5.6 = array(5, 6)
  68. */
  69. public $phpmin = array(5, 6);
  70. /**
  71. * Dolibarr version of the loaded document
  72. * @var string
  73. */
  74. public $version = 'dolibarr';
  75. /**
  76. * @var int page_largeur
  77. */
  78. public $page_largeur;
  79. /**
  80. * @var int page_hauteur
  81. */
  82. public $page_hauteur;
  83. /**
  84. * @var array format
  85. */
  86. public $format;
  87. /**
  88. * @var int marge_gauche
  89. */
  90. public $marge_gauche;
  91. /**
  92. * @var int marge_droite
  93. */
  94. public $marge_droite;
  95. /**
  96. * @var int marge_haute
  97. */
  98. public $marge_haute;
  99. /**
  100. * @var int marge_basse
  101. */
  102. public $marge_basse;
  103. /**
  104. * Issuer
  105. * @var Societe Object that emits
  106. */
  107. public $emetteur;
  108. /**
  109. * Constructor
  110. *
  111. * @param DoliDB $db Database handler
  112. */
  113. public function __construct($db)
  114. {
  115. global $conf, $langs, $mysoc;
  116. // Translations
  117. $langs->loadLangs(array("main", "bills", "products"));
  118. $this->db = $db;
  119. $this->name = "einstein";
  120. $this->description = $langs->trans('PDFEinsteinDescription');
  121. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  122. // Dimension page
  123. $this->type = 'pdf';
  124. $formatarray = pdf_getFormat();
  125. $this->page_largeur = $formatarray['width'];
  126. $this->page_hauteur = $formatarray['height'];
  127. $this->format = array($this->page_largeur, $this->page_hauteur);
  128. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  129. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  130. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  131. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  132. $this->option_logo = 1; // Display logo
  133. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  134. $this->option_modereg = 1; // Display payment mode
  135. $this->option_condreg = 1; // Display payment terms
  136. $this->option_codeproduitservice = 1; // Display product-service code
  137. $this->option_multilang = 1; // Available in several languages
  138. $this->option_escompte = 0; // Displays if there has been a discount
  139. $this->option_credit_note = 0; // Support credit notes
  140. $this->option_freetext = 1; // Support add of a personalised text
  141. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  142. $this->watermark = '';
  143. // Get source company
  144. $this->emetteur = $mysoc;
  145. if (empty($this->emetteur->country_code)) {
  146. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  147. }
  148. // Define position of columns
  149. $this->posxdesc = $this->marge_gauche + 1;
  150. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  151. $this->posxtva = 101;
  152. $this->posxup = 118;
  153. $this->posxqty = 135;
  154. $this->posxunit = 151;
  155. } else {
  156. $this->posxtva = 110;
  157. $this->posxup = 126;
  158. $this->posxqty = 145;
  159. $this->posxunit = 162;
  160. }
  161. $this->posxdiscount = 162;
  162. $this->postotalht = 174;
  163. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  164. $this->posxtva = $this->posxup;
  165. }
  166. $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
  167. if ($this->page_largeur < 210) { // To work with US executive format
  168. $this->posxpicture -= 20;
  169. $this->posxtva -= 20;
  170. $this->posxup -= 20;
  171. $this->posxqty -= 20;
  172. $this->posxunit -= 20;
  173. $this->posxdiscount -= 20;
  174. $this->postotalht -= 20;
  175. }
  176. $this->tva = array();
  177. $this->tva_array = array();
  178. $this->localtax1 = array();
  179. $this->localtax2 = array();
  180. $this->atleastoneratenotnull = 0;
  181. $this->atleastonediscount = 0;
  182. }
  183. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  184. /**
  185. * Function to build pdf onto disk
  186. *
  187. * @param Commande $object Object to generate
  188. * @param Translate $outputlangs Lang output object
  189. * @param string $srctemplatepath Full path of source filename for generator using a template file
  190. * @param int $hidedetails Do not show line details
  191. * @param int $hidedesc Do not show desc
  192. * @param int $hideref Do not show ref
  193. * @return int 1=OK, 0=KO
  194. */
  195. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  196. {
  197. // phpcs:enable
  198. global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
  199. if (!is_object($outputlangs)) {
  200. $outputlangs = $langs;
  201. }
  202. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  203. if (!empty($conf->global->MAIN_USE_FPDF)) {
  204. $outputlangs->charset_output = 'ISO-8859-1';
  205. }
  206. // Load translation files required by the page
  207. $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
  208. // Show Draft Watermark
  209. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK))) {
  210. $this->watermark = $conf->global->COMMANDE_DRAFT_WATERMARK;
  211. }
  212. global $outputlangsbis;
  213. $outputlangsbis = null;
  214. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  215. $outputlangsbis = new Translate('', $conf);
  216. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  217. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
  218. }
  219. $nblines = count($object->lines);
  220. if ($conf->commande->multidir_output[$conf->entity]) {
  221. $object->fetch_thirdparty();
  222. $deja_regle = 0;
  223. // Definition of $dir and $file
  224. if ($object->specimen) {
  225. $dir = $conf->commande->multidir_output[$conf->entity];
  226. $file = $dir."/SPECIMEN.pdf";
  227. } else {
  228. $objectref = dol_sanitizeFileName($object->ref);
  229. $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref;
  230. $file = $dir."/".$objectref.".pdf";
  231. }
  232. if (!file_exists($dir)) {
  233. if (dol_mkdir($dir) < 0) {
  234. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  235. return 0;
  236. }
  237. }
  238. if (file_exists($dir)) {
  239. // Add pdfgeneration hook
  240. if (!is_object($hookmanager)) {
  241. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  242. $hookmanager = new HookManager($this->db);
  243. }
  244. $hookmanager->initHooks(array('pdfgeneration'));
  245. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  246. global $action;
  247. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  248. // Set nblines with the new command lines content after hook
  249. $nblines = count($object->lines);
  250. // Create pdf instance
  251. $pdf = pdf_getInstance($this->format);
  252. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  253. $pdf->SetAutoPageBreak(1, 0);
  254. $heightforinfotot = 40; // Height reserved to output the info and total part
  255. $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
  256. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  257. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  258. $heightforfooter += 6;
  259. }
  260. if (class_exists('TCPDF')) {
  261. $pdf->setPrintHeader(false);
  262. $pdf->setPrintFooter(false);
  263. }
  264. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  265. // Set path to the background PDF File
  266. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  267. $logodir = $conf->mycompany->dir_output;
  268. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  269. $logodir = $conf->mycompany->multidir_output[$object->entity];
  270. }
  271. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  272. $tplidx = $pdf->importPage(1);
  273. }
  274. $pdf->Open();
  275. $pagenb = 0;
  276. $pdf->SetDrawColor(128, 128, 128);
  277. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  278. $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
  279. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  280. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  281. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  282. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  283. $pdf->SetCompression(false);
  284. }
  285. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  286. // Set $this->atleastonediscount if you have at least one discount
  287. for ($i = 0; $i < $nblines; $i++) {
  288. if ($object->lines[$i]->remise_percent) {
  289. $this->atleastonediscount++;
  290. }
  291. }
  292. if (empty($this->atleastonediscount)) {
  293. $delta = ($this->postotalht - $this->posxdiscount);
  294. $this->posxpicture += $delta;
  295. $this->posxtva += $delta;
  296. $this->posxup += $delta;
  297. $this->posxqty += $delta;
  298. $this->posxunit += $delta;
  299. $this->posxdiscount += $delta;
  300. // post of fields after are not modified, stay at same position
  301. }
  302. // New page
  303. $pdf->AddPage();
  304. if (!empty($tplidx)) {
  305. $pdf->useTemplate($tplidx);
  306. }
  307. $pagenb++;
  308. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
  309. $pdf->SetFont('', '', $default_font_size - 1);
  310. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  311. $pdf->SetTextColor(0, 0, 0);
  312. $tab_top = 90 + $top_shift;
  313. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  314. // Incoterm
  315. $height_incoterms = 0;
  316. if (!empty($conf->incoterm->enabled)) {
  317. $desc_incoterms = $object->getIncotermsForPDF();
  318. if ($desc_incoterms) {
  319. $tab_top -= 2;
  320. $pdf->SetFont('', '', $default_font_size - 1);
  321. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  322. $nexY = $pdf->GetY();
  323. $height_incoterms = $nexY - $tab_top;
  324. // Rect takes a length in 3rd parameter
  325. $pdf->SetDrawColor(192, 192, 192);
  326. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  327. $tab_top = $nexY + 6;
  328. }
  329. }
  330. // Displays notes
  331. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  332. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  333. // Get first sale rep
  334. if (is_object($object->thirdparty)) {
  335. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  336. $salerepobj = new User($this->db);
  337. $salerepobj->fetch($salereparray[0]['id']);
  338. if (!empty($salerepobj->signature)) {
  339. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  340. }
  341. }
  342. }
  343. // Extrafields in note
  344. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  345. if (!empty($extranote)) {
  346. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  347. }
  348. if ($notetoshow) {
  349. $tab_top -= 2;
  350. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  351. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  352. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  353. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  354. $pdf->SetFont('', '', $default_font_size - 1);
  355. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
  356. $nexY = $pdf->GetY();
  357. $height_note = $nexY - $tab_top;
  358. // Rect takes a length in 3rd parameter
  359. $pdf->SetDrawColor(192, 192, 192);
  360. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  361. $tab_top = $nexY + 6;
  362. }
  363. $iniY = $tab_top + 7;
  364. $curY = $tab_top + 7;
  365. $nexY = $tab_top + 7;
  366. // Loop on each lines
  367. for ($i = 0; $i < $nblines; $i++) {
  368. $curY = $nexY;
  369. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  370. $pdf->SetTextColor(0, 0, 0);
  371. $pdf->setTopMargin($tab_top_newpage);
  372. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  373. $pageposbefore = $pdf->getPage();
  374. // Description of product line
  375. $curX = $this->posxdesc - 1;
  376. $showpricebeforepagebreak = 1;
  377. $pdf->startTransaction();
  378. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
  379. $pageposafter = $pdf->getPage();
  380. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  381. $pdf->rollbackTransaction(true);
  382. $pageposafter = $pageposbefore;
  383. //print $pageposafter.'-'.$pageposbefore;exit;
  384. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  385. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc);
  386. $pageposafter = $pdf->getPage();
  387. $posyafter = $pdf->GetY();
  388. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  389. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  390. $pdf->AddPage('', '', true);
  391. if (!empty($tplidx)) {
  392. $pdf->useTemplate($tplidx);
  393. }
  394. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  395. $this->_pagehead($pdf, $object, 0, $outputlangs);
  396. }
  397. $pdf->setPage($pageposafter + 1);
  398. }
  399. } else {
  400. // We found a page break
  401. // Allows data in the first page if description is long enough to break in multiples pages
  402. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  403. $showpricebeforepagebreak = 1;
  404. } else {
  405. $showpricebeforepagebreak = 0;
  406. }
  407. }
  408. } else // No pagebreak
  409. {
  410. $pdf->commitTransaction();
  411. }
  412. $posYAfterDescription = $pdf->GetY();
  413. $nexY = $pdf->GetY();
  414. $pageposafter = $pdf->getPage();
  415. $pdf->setPage($pageposbefore);
  416. $pdf->setTopMargin($this->marge_haute);
  417. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  418. // We suppose that a too long description is moved completely on next page
  419. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  420. $pdf->setPage($pageposafter);
  421. $curY = $tab_top_newpage;
  422. }
  423. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  424. // VAT Rate
  425. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  426. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  427. $pdf->SetXY($this->posxtva - 5, $curY);
  428. $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
  429. }
  430. // Unit price before discount
  431. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  432. $pdf->SetXY($this->posxup, $curY);
  433. $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
  434. // Quantity
  435. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  436. $pdf->SetXY($this->posxqty, $curY);
  437. $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
  438. // Unit
  439. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  440. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  441. $pdf->SetXY($this->posxunit, $curY);
  442. $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
  443. }
  444. // Discount on line
  445. $pdf->SetXY($this->posxdiscount, $curY);
  446. if ($object->lines[$i]->remise_percent) {
  447. $pdf->SetXY($this->posxdiscount - 2, $curY);
  448. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  449. $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
  450. }
  451. // Total HT line
  452. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  453. $pdf->SetXY($this->postotalht, $curY);
  454. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
  455. // Collection of totals by value of vat in $this->vat["rate"] = total_tva
  456. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  457. $tvaligne = $object->lines[$i]->multicurrency_total_tva;
  458. } else {
  459. $tvaligne = $object->lines[$i]->total_tva;
  460. }
  461. $localtax1ligne = $object->lines[$i]->total_localtax1;
  462. $localtax2ligne = $object->lines[$i]->total_localtax2;
  463. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  464. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  465. $localtax1_type = $object->lines[$i]->localtax1_type;
  466. $localtax2_type = $object->lines[$i]->localtax2_type;
  467. if ($object->remise_percent) {
  468. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  469. }
  470. if ($object->remise_percent) {
  471. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  472. }
  473. if ($object->remise_percent) {
  474. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  475. }
  476. $vatrate = (string) $object->lines[$i]->tva_tx;
  477. // Retrieve type from database for backward compatibility with old records
  478. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  479. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  480. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  481. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  482. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  483. }
  484. // retrieve global local tax
  485. if ($localtax1_type && $localtax1ligne != 0) {
  486. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  487. }
  488. if ($localtax2_type && $localtax2ligne != 0) {
  489. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  490. }
  491. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  492. $vatrate .= '*';
  493. }
  494. // Fill $this->tva and $this->tva_array
  495. if (!isset($this->tva[$vatrate])) {
  496. $this->tva[$vatrate] = 0;
  497. }
  498. $this->tva[$vatrate] += $tvaligne;
  499. $vatcode = $object->lines[$i]->vat_src_code;
  500. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  501. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  502. }
  503. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  504. // Add line
  505. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  506. $pdf->setPage($pageposafter);
  507. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  508. //$pdf->SetDrawColor(190,190,200);
  509. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  510. $pdf->SetLineStyle(array('dash'=>0));
  511. }
  512. $nexY += 2; // Add space between lines
  513. // Detect if some page were added automatically and output _tableau for past pages
  514. while ($pagenb < $pageposafter) {
  515. $pdf->setPage($pagenb);
  516. if ($pagenb == 1) {
  517. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  518. } else {
  519. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  520. }
  521. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  522. $pagenb++;
  523. $pdf->setPage($pagenb);
  524. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  525. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  526. $this->_pagehead($pdf, $object, 0, $outputlangs);
  527. }
  528. }
  529. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  530. if ($pagenb == 1) {
  531. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  532. } else {
  533. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  534. }
  535. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  536. // New page
  537. $pdf->AddPage();
  538. if (!empty($tplidx)) {
  539. $pdf->useTemplate($tplidx);
  540. }
  541. $pagenb++;
  542. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  543. $this->_pagehead($pdf, $object, 0, $outputlangs);
  544. }
  545. }
  546. }
  547. // Show square
  548. if ($pagenb == 1) {
  549. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
  550. } else {
  551. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  552. }
  553. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  554. // Display infos area
  555. $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  556. // Display total zone
  557. $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  558. // Affiche zone versements
  559. /*
  560. if ($deja_regle)
  561. {
  562. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  563. }
  564. */
  565. // Pied de page
  566. $this->_pagefoot($pdf, $object, $outputlangs);
  567. if (method_exists($pdf, 'AliasNbPages')) {
  568. $pdf->AliasNbPages();
  569. }
  570. $pdf->Close();
  571. $pdf->Output($file, 'F');
  572. // Add pdfgeneration hook
  573. $hookmanager->initHooks(array('pdfgeneration'));
  574. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  575. global $action;
  576. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  577. if ($reshook < 0) {
  578. $this->error = $hookmanager->error;
  579. $this->errors = $hookmanager->errors;
  580. }
  581. if (!empty($conf->global->MAIN_UMASK)) {
  582. @chmod($file, octdec($conf->global->MAIN_UMASK));
  583. }
  584. $this->result = array('fullpath'=>$file);
  585. return 1; // No error
  586. } else {
  587. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  588. return 0;
  589. }
  590. } else {
  591. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
  592. return 0;
  593. }
  594. }
  595. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  596. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  597. /**
  598. * Show payments table
  599. *
  600. * @param TCPDF $pdf Object PDF
  601. * @param Commande $object Object order
  602. * @param int $posy Position y in PDF
  603. * @param Translate $outputlangs Object langs for output
  604. * @return int <0 if KO, >0 if OK
  605. */
  606. protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  607. {
  608. // phpcs:enable
  609. }
  610. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  611. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  612. /**
  613. * Show miscellaneous information (payment mode, payment term, ...)
  614. *
  615. * @param TCPDF $pdf Object PDF
  616. * @param Commande $object Object to show
  617. * @param int $posy Y
  618. * @param Translate $outputlangs Langs object
  619. * @return int
  620. */
  621. protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  622. {
  623. // phpcs:enable
  624. global $conf, $mysoc;
  625. $default_font_size = pdf_getPDFFontSize($outputlangs);
  626. $pdf->SetFont('', '', $default_font_size - 1);
  627. // If France, show VAT mention if not applicable
  628. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  629. $pdf->SetFont('', 'B', $default_font_size - 2);
  630. $pdf->SetXY($this->marge_gauche, $posy);
  631. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  632. $posy = $pdf->GetY() + 4;
  633. }
  634. $posxval = 52;
  635. // Show payments conditions
  636. if ($object->cond_reglement_code || $object->cond_reglement) {
  637. $pdf->SetFont('', 'B', $default_font_size - 2);
  638. $pdf->SetXY($this->marge_gauche, $posy);
  639. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  640. $pdf->MultiCell(43, 4, $titre, 0, 'L');
  641. $pdf->SetFont('', '', $default_font_size - 2);
  642. $pdf->SetXY($posxval, $posy);
  643. $lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
  644. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  645. $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
  646. $posy = $pdf->GetY() + 3;
  647. }
  648. // Check a payment mode is defined
  649. /* Not used with orders
  650. if (empty($object->mode_reglement_code)
  651. && ! $conf->global->FACTURE_CHQ_NUMBER
  652. && ! $conf->global->FACTURE_RIB_NUMBER)
  653. {
  654. $pdf->SetXY($this->marge_gauche, $posy);
  655. $pdf->SetTextColor(200,0,0);
  656. $pdf->SetFont('','B', $default_font_size - 2);
  657. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  658. $pdf->SetTextColor(0,0,0);
  659. $posy=$pdf->GetY()+1;
  660. }
  661. */
  662. /* TODO
  663. else if (! empty($object->availability_code))
  664. {
  665. $pdf->SetXY($this->marge_gauche, $posy);
  666. $pdf->SetTextColor(200,0,0);
  667. $pdf->SetFont('','B', $default_font_size - 2);
  668. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
  669. $pdf->SetTextColor(0,0,0);
  670. $posy=$pdf->GetY()+1;
  671. }*/
  672. // Show planed date of delivery
  673. if (!empty($object->delivery_date)) {
  674. $outputlangs->load("sendings");
  675. $pdf->SetFont('', 'B', $default_font_size - 2);
  676. $pdf->SetXY($this->marge_gauche, $posy);
  677. $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
  678. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  679. $pdf->SetFont('', '', $default_font_size - 2);
  680. $pdf->SetXY($posxval, $posy);
  681. $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
  682. $pdf->MultiCell(80, 4, $dlp, 0, 'L');
  683. $posy = $pdf->GetY() + 1;
  684. } elseif ($object->availability_code || $object->availability) {
  685. // Show availability conditions
  686. $pdf->SetFont('', 'B', $default_font_size - 2);
  687. $pdf->SetXY($this->marge_gauche, $posy);
  688. $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
  689. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  690. $pdf->SetTextColor(0, 0, 0);
  691. $pdf->SetFont('', '', $default_font_size - 2);
  692. $pdf->SetXY($posxval, $posy);
  693. $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
  694. $lib_availability = str_replace('\n', "\n", $lib_availability);
  695. $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
  696. $posy = $pdf->GetY() + 1;
  697. }
  698. // Show payment mode
  699. if ($object->mode_reglement_code
  700. && $object->mode_reglement_code != 'CHQ'
  701. && $object->mode_reglement_code != 'VIR') {
  702. $pdf->SetFont('', 'B', $default_font_size - 2);
  703. $pdf->SetXY($this->marge_gauche, $posy);
  704. $titre = $outputlangs->transnoentities("PaymentMode").':';
  705. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  706. $pdf->SetFont('', '', $default_font_size - 2);
  707. $pdf->SetXY($posxval, $posy);
  708. $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
  709. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  710. $posy = $pdf->GetY() + 2;
  711. }
  712. // Show payment mode CHQ
  713. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  714. // Si mode reglement non force ou si force a CHQ
  715. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  716. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  717. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  718. $account = new Account($this->db);
  719. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  720. $pdf->SetXY($this->marge_gauche, $posy);
  721. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  722. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  723. $posy = $pdf->GetY() + 1;
  724. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  725. $pdf->SetXY($this->marge_gauche, $posy);
  726. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  727. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  728. $posy = $pdf->GetY() + 2;
  729. }
  730. }
  731. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  732. $pdf->SetXY($this->marge_gauche, $posy);
  733. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  734. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  735. $posy = $pdf->GetY() + 1;
  736. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  737. $pdf->SetXY($this->marge_gauche, $posy);
  738. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  739. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  740. $posy = $pdf->GetY() + 2;
  741. }
  742. }
  743. }
  744. }
  745. // If payment mode not forced or forced to VIR, show payment with BAN
  746. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  747. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  748. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  749. if ($object->fk_bank > 0) {
  750. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  751. }
  752. $account = new Account($this->db);
  753. $account->fetch($bankid);
  754. $curx = $this->marge_gauche;
  755. $cury = $posy;
  756. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  757. $posy += 2;
  758. }
  759. }
  760. return $posy;
  761. }
  762. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  763. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  764. /**
  765. * Show total to pay
  766. *
  767. * @param TCPDF $pdf Object PDF
  768. * @param Commande $object Object invoice
  769. * @param int $deja_regle Montant deja regle
  770. * @param int $posy Position depart
  771. * @param Translate $outputlangs Objet langs
  772. * @param Translate $outputlangsbis Object lang for output bis
  773. * @return int Position pour suite
  774. */
  775. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
  776. {
  777. // phpcs:enable
  778. global $conf, $mysoc, $hookmanager;
  779. $default_font_size = pdf_getPDFFontSize($outputlangs);
  780. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  781. $outputlangsbis = new Translate('', $conf);
  782. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  783. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  784. $default_font_size--;
  785. }
  786. $tab2_top = $posy;
  787. $tab2_hl = 4;
  788. $pdf->SetFont('', '', $default_font_size - 1);
  789. // Total table
  790. $col1x = 120;
  791. $col2x = 170;
  792. if ($this->page_largeur < 210) { // To work with US executive format
  793. $col2x -= 20;
  794. }
  795. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  796. $useborder = 0;
  797. $index = 0;
  798. // Total HT
  799. $pdf->SetFillColor(255, 255, 255);
  800. $pdf->SetXY($col1x, $tab2_top + 0);
  801. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
  802. $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  803. $pdf->SetXY($col2x, $tab2_top + 0);
  804. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
  805. // Show VAT by rates and total
  806. $pdf->SetFillColor(248, 248, 248);
  807. $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  808. $this->atleastoneratenotnull = 0;
  809. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  810. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  811. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  812. // Nothing to do
  813. } else {
  814. //Local tax 1 before VAT
  815. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  816. //{
  817. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  818. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  819. continue;
  820. }
  821. foreach ($localtax_rate as $tvakey => $tvaval) {
  822. if ($tvakey != 0) { // On affiche pas taux 0
  823. //$this->atleastoneratenotnull++;
  824. $index++;
  825. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  826. $tvacompl = '';
  827. if (preg_match('/\*/', $tvakey)) {
  828. $tvakey = str_replace('*', '', $tvakey);
  829. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  830. }
  831. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  832. $totalvat .= ' ';
  833. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  834. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  835. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  836. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  837. }
  838. }
  839. }
  840. //}
  841. //Local tax 2 before VAT
  842. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  843. //{
  844. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  845. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  846. continue;
  847. }
  848. foreach ($localtax_rate as $tvakey => $tvaval) {
  849. if ($tvakey != 0) { // On affiche pas taux 0
  850. //$this->atleastoneratenotnull++;
  851. $index++;
  852. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  853. $tvacompl = '';
  854. if (preg_match('/\*/', $tvakey)) {
  855. $tvakey = str_replace('*', '', $tvakey);
  856. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  857. }
  858. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  859. $totalvat .= ' ';
  860. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  861. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  862. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  863. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  864. }
  865. }
  866. }
  867. //}
  868. // VAT
  869. foreach ($this->tva_array as $tvakey => $tvaval) {
  870. if ($tvakey != 0) { // On affiche pas taux 0
  871. $this->atleastoneratenotnull++;
  872. $index++;
  873. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  874. $tvacompl = '';
  875. if (preg_match('/\*/', $tvakey)) {
  876. $tvakey = str_replace('*', '', $tvakey);
  877. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  878. }
  879. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  880. $totalvat .= ' ';
  881. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  882. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  883. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  884. $totalvat .= $tvaval['vatcode'].$tvacompl;
  885. } else {
  886. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  887. }
  888. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  889. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  890. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  891. }
  892. }
  893. //Local tax 1 after VAT
  894. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  895. //{
  896. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  897. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  898. continue;
  899. }
  900. foreach ($localtax_rate as $tvakey => $tvaval) {
  901. if ($tvakey != 0) { // On affiche pas taux 0
  902. //$this->atleastoneratenotnull++;
  903. $index++;
  904. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  905. $tvacompl = '';
  906. if (preg_match('/\*/', $tvakey)) {
  907. $tvakey = str_replace('*', '', $tvakey);
  908. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  909. }
  910. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  911. $totalvat .= ' ';
  912. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  913. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  914. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  915. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  916. }
  917. }
  918. }
  919. //}
  920. //Local tax 2 after VAT
  921. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  922. //{
  923. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  924. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  925. continue;
  926. }
  927. foreach ($localtax_rate as $tvakey => $tvaval) {
  928. // retrieve global local tax
  929. if ($tvakey != 0) { // On affiche pas taux 0
  930. //$this->atleastoneratenotnull++;
  931. $index++;
  932. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  933. $tvacompl = '';
  934. if (preg_match('/\*/', $tvakey)) {
  935. $tvakey = str_replace('*', '', $tvakey);
  936. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  937. }
  938. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  939. $totalvat .= ' ';
  940. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  941. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  942. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  943. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  944. }
  945. }
  946. }
  947. //}
  948. // Total TTC
  949. $index++;
  950. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  951. $pdf->SetTextColor(0, 0, 60);
  952. $pdf->SetFillColor(224, 224, 224);
  953. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
  954. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  955. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  956. }
  957. }
  958. $pdf->SetTextColor(0, 0, 0);
  959. $creditnoteamount = 0;
  960. $depositsamount = 0;
  961. //$creditnoteamount=$object->getSumCreditNotesUsed();
  962. //$depositsamount=$object->getSumDepositsUsed();
  963. //print "x".$creditnoteamount."-".$depositsamount;exit;
  964. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  965. if (!empty($object->paye)) {
  966. $resteapayer = 0;
  967. }
  968. if ($deja_regle > 0) {
  969. // Already paid + Deposits
  970. $index++;
  971. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  972. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
  973. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  974. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
  975. $index++;
  976. $pdf->SetTextColor(0, 0, 60);
  977. $pdf->SetFillColor(224, 224, 224);
  978. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  979. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), $useborder, 'L', 1);
  980. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  981. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  982. $pdf->SetFont('', '', $default_font_size - 1);
  983. $pdf->SetTextColor(0, 0, 0);
  984. }
  985. $index++;
  986. return ($tab2_top + ($tab2_hl * $index));
  987. }
  988. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  989. /**
  990. * Show table for lines
  991. *
  992. * @param TCPDF $pdf Object PDF
  993. * @param string $tab_top Top position of table
  994. * @param string $tab_height Height of table (rectangle)
  995. * @param int $nexY Y (not used)
  996. * @param Translate $outputlangs Langs object
  997. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  998. * @param int $hidebottom Hide bottom bar of array
  999. * @param string $currency Currency code
  1000. * @param Translate $outputlangsbis Langs object bis
  1001. * @return void
  1002. */
  1003. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1004. {
  1005. global $conf;
  1006. // Force to disable hidetop and hidebottom
  1007. $hidebottom = 0;
  1008. if ($hidetop) {
  1009. $hidetop = -1;
  1010. }
  1011. $currency = !empty($currency) ? $currency : $conf->currency;
  1012. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1013. // Amount in (at tab_top - 1)
  1014. $pdf->SetTextColor(0, 0, 0);
  1015. $pdf->SetFont('', '', $default_font_size - 2);
  1016. if (empty($hidetop)) {
  1017. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1018. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1019. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1020. }
  1021. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1022. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1023. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1024. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1025. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  1026. }
  1027. }
  1028. $pdf->SetDrawColor(128, 128, 128);
  1029. $pdf->SetFont('', '', $default_font_size - 1);
  1030. // Output Rect
  1031. $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
  1032. if (empty($hidetop)) {
  1033. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
  1034. $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
  1035. $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
  1036. }
  1037. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1038. $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
  1039. if (empty($hidetop)) {
  1040. $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
  1041. $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
  1042. }
  1043. }
  1044. $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
  1045. if (empty($hidetop)) {
  1046. $pdf->SetXY($this->posxup - 1, $tab_top + 1);
  1047. $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  1048. }
  1049. $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
  1050. if (empty($hidetop)) {
  1051. $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
  1052. $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
  1053. }
  1054. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1055. $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
  1056. if (empty($hidetop)) {
  1057. $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
  1058. $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
  1059. }
  1060. }
  1061. $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
  1062. if (empty($hidetop)) {
  1063. if ($this->atleastonediscount) {
  1064. $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
  1065. $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
  1066. }
  1067. }
  1068. if ($this->atleastonediscount) {
  1069. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  1070. }
  1071. if (empty($hidetop)) {
  1072. $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
  1073. $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
  1074. }
  1075. }
  1076. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1077. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1078. /**
  1079. * Show top header of page.
  1080. *
  1081. * @param TCPDF $pdf Object PDF
  1082. * @param Commande $object Object to show
  1083. * @param int $showaddress 0=no, 1=yes
  1084. * @param Translate $outputlangs Object lang for output
  1085. * @param Translate $outputlangsbis Object lang for output bis
  1086. * @param string $titlekey Translation key to show as title of document
  1087. * @return int Return topshift value
  1088. */
  1089. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
  1090. {
  1091. // phpcs:enable
  1092. global $conf, $langs, $hookmanager;
  1093. $ltrdirection = 'L';
  1094. if ($outputlangs->trans("DIRECTION") == 'rtl') {
  1095. $ltrdirection = 'R';
  1096. }
  1097. // Load traductions files required by page
  1098. $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
  1099. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1100. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1101. $pdf->SetTextColor(0, 0, 60);
  1102. $pdf->SetFont('', 'B', $default_font_size + 3);
  1103. $w = 100;
  1104. $posy = $this->marge_haute;
  1105. $posx = $this->page_largeur - $this->marge_droite - $w;
  1106. $pdf->SetXY($this->marge_gauche, $posy);
  1107. // Logo
  1108. if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
  1109. if ($this->emetteur->logo) {
  1110. $logodir = $conf->mycompany->dir_output;
  1111. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1112. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1113. }
  1114. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  1115. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1116. } else {
  1117. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1118. }
  1119. if (is_readable($logo)) {
  1120. $height = pdf_getHeightForLogo($logo);
  1121. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1122. } else {
  1123. $pdf->SetTextColor(200, 0, 0);
  1124. $pdf->SetFont('', 'B', $default_font_size - 2);
  1125. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1126. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1127. }
  1128. } else {
  1129. $text = $this->emetteur->name;
  1130. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
  1131. }
  1132. }
  1133. $pdf->SetFont('', 'B', $default_font_size + 3);
  1134. $pdf->SetXY($posx, $posy);
  1135. $pdf->SetTextColor(0, 0, 60);
  1136. $title = $outputlangs->transnoentities($titlekey);
  1137. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1138. if ($object->statut == $object::STATUS_DRAFT) {
  1139. $pdf->SetTextColor(128, 0, 0);
  1140. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1141. }
  1142. $pdf->MultiCell($w, 3, $title, '', 'R');
  1143. $pdf->SetFont('', 'B', $default_font_size);
  1144. /*
  1145. $posy += 5;
  1146. $pdf->SetXY($posx, $posy);
  1147. $pdf->SetTextColor(0, 0, 60);
  1148. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  1149. */
  1150. $posy += 3;
  1151. $pdf->SetFont('', '', $default_font_size - 1);
  1152. if ($object->ref_client) {
  1153. $posy += 5;
  1154. $pdf->SetXY($posx, $posy);
  1155. $pdf->SetTextColor(0, 0, 60);
  1156. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
  1157. }
  1158. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1159. $object->fetch_projet();
  1160. if (!empty($object->project->ref)) {
  1161. $posy += 3;
  1162. $pdf->SetXY($posx, $posy);
  1163. $pdf->SetTextColor(0, 0, 60);
  1164. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1165. }
  1166. }
  1167. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1168. $object->fetch_projet();
  1169. if (!empty($object->project->ref)) {
  1170. $outputlangs->load("projects");
  1171. $posy += 3;
  1172. $pdf->SetXY($posx, $posy);
  1173. $pdf->SetTextColor(0, 0, 60);
  1174. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1175. }
  1176. }
  1177. $posy += 4;
  1178. $pdf->SetXY($posx, $posy);
  1179. $pdf->SetTextColor(0, 0, 60);
  1180. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
  1181. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
  1182. $posy += 4;
  1183. $pdf->SetXY($posx, $posy);
  1184. $pdf->SetTextColor(0, 0, 60);
  1185. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1186. }
  1187. // Get contact
  1188. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1189. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1190. if (count($arrayidcontact) > 0) {
  1191. $usertmp = new User($this->db);
  1192. $usertmp->fetch($arrayidcontact[0]);
  1193. $posy += 4;
  1194. $pdf->SetXY($posx, $posy);
  1195. $pdf->SetTextColor(0, 0, 60);
  1196. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1197. }
  1198. }
  1199. $posy += 2;
  1200. $top_shift = 0;
  1201. // Show list of linked objects
  1202. $current_y = $pdf->getY();
  1203. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1204. if ($current_y < $pdf->getY()) {
  1205. $top_shift = $pdf->getY() - $current_y;
  1206. }
  1207. if ($showaddress) {
  1208. // Sender properties
  1209. $carac_emetteur = '';
  1210. // Add internal contact of proposal if defined
  1211. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1212. if (count($arrayidcontact) > 0) {
  1213. $object->fetch_user($arrayidcontact[0]);
  1214. $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
  1215. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  1216. }
  1217. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1218. // Show sender
  1219. $posy = 42 + $top_shift;
  1220. $posx = $this->marge_gauche;
  1221. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1222. $posx = $this->page_largeur - $this->marge_droite - 80;
  1223. }
  1224. $hautcadre = 40;
  1225. // Show sender frame
  1226. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1227. $pdf->SetTextColor(0, 0, 0);
  1228. $pdf->SetFont('', '', $default_font_size - 2);
  1229. $pdf->SetXY($posx, $posy - 5);
  1230. $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1231. $pdf->SetXY($posx, $posy);
  1232. $pdf->SetFillColor(230, 230, 230);
  1233. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  1234. $pdf->SetTextColor(0, 0, 60);
  1235. }
  1236. // Show sender name
  1237. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1238. $pdf->SetXY($posx + 2, $posy + 3);
  1239. $pdf->SetFont('', 'B', $default_font_size);
  1240. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1241. $posy = $pdf->getY();
  1242. }
  1243. // Show sender information
  1244. $pdf->SetXY($posx + 2, $posy);
  1245. $pdf->SetFont('', '', $default_font_size - 1);
  1246. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  1247. // If CUSTOMER contact defined, we use it
  1248. $usecontact = false;
  1249. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  1250. if (count($arrayidcontact) > 0) {
  1251. $usecontact = true;
  1252. $result = $object->fetch_contact($arrayidcontact[0]);
  1253. }
  1254. // Recipient name
  1255. 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)))) {
  1256. $thirdparty = $object->contact;
  1257. } else {
  1258. $thirdparty = $object->thirdparty;
  1259. }
  1260. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1261. $mode = 'target';
  1262. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1263. // Show recipient
  1264. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1265. if ($this->page_largeur < 210) {
  1266. $widthrecbox = 84; // To work with US executive format
  1267. }
  1268. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1269. $posy += $top_shift;
  1270. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1271. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1272. $posx = $this->marge_gauche;
  1273. }
  1274. // Show recipient frame
  1275. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1276. $pdf->SetTextColor(0, 0, 0);
  1277. $pdf->SetFont('', '', $default_font_size - 2);
  1278. $pdf->SetXY($posx + 2, $posy - 5);
  1279. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1280. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1281. }
  1282. // Show recipient name
  1283. $pdf->SetXY($posx + 2, $posy + 3);
  1284. $pdf->SetFont('', 'B', $default_font_size);
  1285. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1286. $posy = $pdf->getY();
  1287. // Show recipient information
  1288. $pdf->SetFont('', '', $default_font_size - 1);
  1289. $pdf->SetXY($posx + 2, $posy);
  1290. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1291. }
  1292. $pdf->SetTextColor(0, 0, 0);
  1293. return $top_shift;
  1294. }
  1295. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1296. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1297. /**
  1298. * Show footer of page. Need this->emetteur object
  1299. *
  1300. * @param TCPDF $pdf PDF
  1301. * @param Commande $object Object to show
  1302. * @param Translate $outputlangs Object lang for output
  1303. * @param int $hidefreetext 1=Hide free text
  1304. * @return int Return height of bottom margin including footer text
  1305. */
  1306. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1307. {
  1308. // phpcs:enable
  1309. global $conf;
  1310. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1311. return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
  1312. }
  1313. }