pdf_einstein.modules.php 60 KB

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