pdf_crabe.modules.php 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219
  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-2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  7. * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  9. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
  11. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. * or see https://www.gnu.org/
  27. */
  28. /**
  29. * \file htdocs/core/modules/facture/doc/pdf_crabe.modules.php
  30. * \ingroup facture
  31. * \brief File of class to generate customers invoices from crabe model
  32. */
  33. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  38. /**
  39. * Class to generate the customer invoice PDF with template Crabe
  40. */
  41. class pdf_crabe extends ModelePDFFactures
  42. {
  43. /**
  44. * @var DoliDb Database handler
  45. */
  46. public $db;
  47. /**
  48. * @var string model name
  49. */
  50. public $name;
  51. /**
  52. * @var string model description (short text)
  53. */
  54. public $description;
  55. /**
  56. * @var int Save the name of generated file as the main doc when generating a doc with this template
  57. */
  58. public $update_main_doc_field;
  59. /**
  60. * @var string document type
  61. */
  62. public $type;
  63. /**
  64. * @var array Minimum version of PHP required by module.
  65. * e.g.: PHP ≥ 7.0 = array(7, 0)
  66. */
  67. public $phpmin = array(7, 0);
  68. /**
  69. * Dolibarr version of the loaded document
  70. * @var string
  71. */
  72. public $version = 'dolibarr';
  73. /**
  74. * @var int page_largeur
  75. */
  76. public $page_largeur;
  77. /**
  78. * @var int page_hauteur
  79. */
  80. public $page_hauteur;
  81. /**
  82. * @var array format
  83. */
  84. public $format;
  85. /**
  86. * @var int marge_gauche
  87. */
  88. public $marge_gauche;
  89. /**
  90. * @var int marge_droite
  91. */
  92. public $marge_droite;
  93. /**
  94. * @var int marge_haute
  95. */
  96. public $marge_haute;
  97. /**
  98. * @var int marge_basse
  99. */
  100. public $marge_basse;
  101. /**
  102. * Issuer
  103. * @var Societe Object that emits
  104. */
  105. public $emetteur;
  106. /**
  107. * @var bool Situation invoice type
  108. */
  109. public $situationinvoice;
  110. /**
  111. * @var float X position for the situation progress column
  112. */
  113. public $posxprogress;
  114. /**
  115. * @var int Category of operation
  116. */
  117. public $categoryOfOperation = -1; // unknown by default
  118. /**
  119. * Constructor
  120. *
  121. * @param DoliDB $db Database handler
  122. */
  123. public function __construct($db)
  124. {
  125. global $conf, $langs, $mysoc;
  126. // Translations
  127. $langs->loadLangs(array("main", "bills"));
  128. $this->db = $db;
  129. $this->name = "crabe";
  130. $this->description = $langs->trans('PDFCrabeDescription');
  131. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  132. // Dimension page
  133. $this->type = 'pdf';
  134. $formatarray = pdf_getFormat();
  135. $this->page_largeur = $formatarray['width'];
  136. $this->page_hauteur = $formatarray['height'];
  137. $this->format = array($this->page_largeur, $this->page_hauteur);
  138. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  139. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  140. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  141. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  142. $this->option_logo = 1; // Display logo
  143. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  144. $this->option_modereg = 1; // Display payment mode
  145. $this->option_condreg = 1; // Display payment terms
  146. $this->option_multilang = 1; // Available in several languages
  147. $this->option_escompte = 1; // Displays if there has been a discount
  148. $this->option_credit_note = 1; // Support credit notes
  149. $this->option_freetext = 1; // Support add of a personalised text
  150. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  151. $this->watermark = '';
  152. // Get source company
  153. $this->emetteur = $mysoc;
  154. if (empty($this->emetteur->country_code)) {
  155. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  156. }
  157. // Define position of columns
  158. $this->posxdesc = $this->marge_gauche + 1;
  159. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  160. $this->posxtva = 101;
  161. $this->posxup = 118;
  162. $this->posxqty = 135;
  163. $this->posxunit = 151;
  164. } else {
  165. $this->posxtva = 106;
  166. $this->posxup = 122;
  167. $this->posxqty = 145;
  168. $this->posxunit = 162;
  169. }
  170. $this->posxprogress = 151; // Only displayed for situation invoices
  171. $this->posxdiscount = 162;
  172. $this->posxprogress = 174;
  173. $this->postotalht = 174;
  174. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  175. $this->posxtva = $this->posxup;
  176. }
  177. $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
  178. if ($this->page_largeur < 210) { // To work with US executive format
  179. $this->posxpicture -= 20;
  180. $this->posxtva -= 20;
  181. $this->posxup -= 20;
  182. $this->posxqty -= 20;
  183. $this->posxunit -= 20;
  184. $this->posxdiscount -= 20;
  185. $this->posxprogress -= 20;
  186. $this->postotalht -= 20;
  187. }
  188. $this->tva = array();
  189. $this->tva_array = array();
  190. $this->localtax1 = array();
  191. $this->localtax2 = array();
  192. $this->atleastoneratenotnull = 0;
  193. $this->atleastonediscount = 0;
  194. $this->situationinvoice = false;
  195. }
  196. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  197. /**
  198. * Function to build pdf onto disk
  199. *
  200. * @param Facture $object Object to generate
  201. * @param Translate $outputlangs Lang output object
  202. * @param string $srctemplatepath Full path of source filename for generator using a template file
  203. * @param int $hidedetails Do not show line details
  204. * @param int $hidedesc Do not show desc
  205. * @param int $hideref Do not show ref
  206. * @return int 1=OK, 0=KO
  207. */
  208. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  209. {
  210. // phpcs:enable
  211. global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
  212. dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
  213. if (!is_object($outputlangs)) {
  214. $outputlangs = $langs;
  215. }
  216. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  217. if (!empty($conf->global->MAIN_USE_FPDF)) {
  218. $outputlangs->charset_output = 'ISO-8859-1';
  219. }
  220. // Load translation files required by the page
  221. $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
  222. // Show Draft Watermark
  223. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
  224. $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
  225. }
  226. global $outputlangsbis;
  227. $outputlangsbis = null;
  228. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  229. $outputlangsbis = new Translate('', $conf);
  230. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  231. $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
  232. }
  233. $nblines = count($object->lines);
  234. // Loop on each lines to detect if there is at least one image to show
  235. $realpatharray = array();
  236. if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
  237. for ($i = 0; $i < $nblines; $i++) {
  238. if (empty($object->lines[$i]->fk_product)) {
  239. continue;
  240. }
  241. $objphoto = new Product($this->db);
  242. $objphoto->fetch($object->lines[$i]->fk_product);
  243. $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
  244. $dir = $conf->product->dir_output.'/'.$pdir;
  245. $realpath = '';
  246. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  247. $filename = $obj['photo'];
  248. //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
  249. $realpath = $dir.$filename;
  250. break;
  251. }
  252. if ($realpath) {
  253. $realpatharray[$i] = $realpath;
  254. }
  255. }
  256. }
  257. if (count($realpatharray) == 0) {
  258. $this->posxpicture = $this->posxtva;
  259. }
  260. if ($conf->facture->dir_output) {
  261. $object->fetch_thirdparty();
  262. $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
  263. $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
  264. $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
  265. // Definition of $dir and $file
  266. if ($object->specimen) {
  267. $dir = empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity];
  268. $file = $dir."/SPECIMEN.pdf";
  269. } else {
  270. $objectref = dol_sanitizeFileName($object->ref);
  271. $dir = (empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity])."/".$objectref;
  272. $file = $dir."/".$objectref.".pdf";
  273. }
  274. if (!file_exists($dir)) {
  275. if (dol_mkdir($dir) < 0) {
  276. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  277. return 0;
  278. }
  279. }
  280. if (file_exists($dir)) {
  281. // Add pdfgeneration hook
  282. if (!is_object($hookmanager)) {
  283. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  284. $hookmanager = new HookManager($this->db);
  285. }
  286. $hookmanager->initHooks(array('pdfgeneration'));
  287. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  288. global $action;
  289. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  290. // Set nblines with the new facture lines content after hook
  291. $nblines = count($object->lines);
  292. $nbpayments = count($object->getListOfPayments());
  293. // Create pdf instance
  294. $pdf = pdf_getInstance($this->format);
  295. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  296. $pdf->SetAutoPageBreak(1, 0);
  297. $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
  298. if ($heightforinfotot > 220) {
  299. $heightforinfotot = 220;
  300. }
  301. $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
  302. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  303. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  304. $heightforfooter += 6;
  305. }
  306. $heightforqrinvoice_firstpage = 0;
  307. if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
  308. $heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs);
  309. if ($heightforqrinvoice_firstpage > 0) {
  310. // Shrink infotot to a base 30
  311. $heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
  312. }
  313. }
  314. if (class_exists('TCPDF')) {
  315. $pdf->setPrintHeader(false);
  316. $pdf->setPrintFooter(false);
  317. }
  318. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  319. // Set path to the background PDF File
  320. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  321. $logodir = $conf->mycompany->dir_output;
  322. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  323. $logodir = $conf->mycompany->multidir_output[$object->entity];
  324. }
  325. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  326. $tplidx = $pdf->importPage(1);
  327. }
  328. $pdf->Open();
  329. $pagenb = 0;
  330. $pdf->SetDrawColor(128, 128, 128);
  331. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  332. $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
  333. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  334. $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
  335. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  336. if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
  337. $pdf->SetCompression(false);
  338. }
  339. // Set certificate
  340. $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
  341. $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
  342. // If user has no certificate, we try to take the company one
  343. if (!$cert) {
  344. $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
  345. }
  346. if (!$certprivate) {
  347. $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
  348. }
  349. // If a certificate is found
  350. if ($cert) {
  351. $info = array(
  352. 'Name' => $this->emetteur->name,
  353. 'Location' => getCountry($this->emetteur->country_code, 0),
  354. 'Reason' => 'INVOICE',
  355. 'ContactInfo' => $this->emetteur->email
  356. );
  357. $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
  358. }
  359. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  360. // Set $this->atleastonediscount if you have at least one discount
  361. // and determine category of operation
  362. $categoryOfOperation = 0;
  363. $nbProduct = 0;
  364. $nbService = 0;
  365. for ($i = 0; $i < $nblines; $i++) {
  366. if ($object->lines[$i]->remise_percent) {
  367. $this->atleastonediscount++;
  368. }
  369. // determine category of operation
  370. if ($categoryOfOperation < 2) {
  371. $lineProductType = $object->lines[$i]->product_type;
  372. if ($lineProductType == Product::TYPE_PRODUCT) {
  373. $nbProduct++;
  374. } elseif ($lineProductType == Product::TYPE_SERVICE) {
  375. $nbService++;
  376. }
  377. if ($nbProduct > 0 && $nbService > 0) {
  378. // mixed products and services
  379. $categoryOfOperation = 2;
  380. }
  381. }
  382. }
  383. // determine category of operation
  384. if ($categoryOfOperation <= 0) {
  385. // only services
  386. if ($nbProduct == 0 && $nbService > 0) {
  387. $categoryOfOperation = 1;
  388. }
  389. }
  390. $this->categoryOfOperation = $categoryOfOperation;
  391. if (empty($this->atleastonediscount)) { // retrieve space not used by discount
  392. $delta = ($this->posxprogress - $this->posxdiscount);
  393. $this->posxpicture += $delta;
  394. $this->posxtva += $delta;
  395. $this->posxup += $delta;
  396. $this->posxqty += $delta;
  397. $this->posxunit += $delta;
  398. $this->posxdiscount += $delta;
  399. // post of fields after are not modified, stay at same position
  400. }
  401. $progress_width = 0;
  402. // Situation invoice handling
  403. if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
  404. $this->situationinvoice = true;
  405. $progress_width = 10;
  406. $this->posxpicture -= $progress_width;
  407. $this->posxtva -= $progress_width;
  408. $this->posxup -= $progress_width;
  409. $this->posxqty -= $progress_width;
  410. $this->posxunit -= $progress_width;
  411. $this->posxdiscount -= $progress_width;
  412. $this->posxprogress -= $progress_width;
  413. }
  414. // New page
  415. $pdf->AddPage();
  416. if (!empty($tplidx)) {
  417. $pdf->useTemplate($tplidx);
  418. }
  419. $pagenb++;
  420. // Output header (logo, ref and address blocks). This is first call for first page.
  421. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
  422. $pdf->SetFont('', '', $default_font_size - 1);
  423. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  424. $pdf->SetTextColor(0, 0, 0);
  425. // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
  426. // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
  427. $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
  428. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  429. // You can add more thing under header here, if you increase $extra_under_address_shift too.
  430. $extra_under_address_shift = 0;
  431. $qrcodestring = '';
  432. if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
  433. $qrcodestring = $object->buildZATCAQRString();
  434. } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
  435. $qrcodestring = $object->buildSwitzerlandQRString();
  436. }
  437. if ($qrcodestring) {
  438. $qrcodecolor = array('25', '25', '25');
  439. // set style for QR-code
  440. $styleQr = array(
  441. 'border' => false,
  442. 'padding' => 0,
  443. 'fgcolor' => $qrcodecolor,
  444. 'bgcolor' => false, //array(255,255,255)
  445. 'module_width' => 1, // width of a single module in points
  446. 'module_height' => 1 // height of a single module in points
  447. );
  448. $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
  449. $extra_under_address_shift += 25;
  450. }
  451. // Call hook printUnderHeaderPDFline
  452. $parameters = array(
  453. 'object' => $object,
  454. 'i' => $i,
  455. 'pdf' =>& $pdf,
  456. 'outputlangs' => $outputlangs,
  457. 'hidedetails' => $hidedetails
  458. );
  459. $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
  460. if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
  461. $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
  462. }
  463. $tab_top += $extra_under_address_shift;
  464. $tab_top_newpage += 0;
  465. // Incoterm
  466. $height_incoterms = 0;
  467. if (isModEnabled('incoterm')) {
  468. $desc_incoterms = $object->getIncotermsForPDF();
  469. if ($desc_incoterms) {
  470. $tab_top -= 2;
  471. $pdf->SetFont('', '', $default_font_size - 1);
  472. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  473. $nexY = $pdf->GetY();
  474. $height_incoterms = $nexY - $tab_top;
  475. // Rect takes a length in 3rd parameter
  476. $pdf->SetDrawColor(192, 192, 192);
  477. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  478. $tab_top = $nexY + 6;
  479. }
  480. }
  481. // Display notes
  482. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  483. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  484. // Get first sale rep
  485. if (is_object($object->thirdparty)) {
  486. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  487. $salerepobj = new User($this->db);
  488. $salerepobj->fetch($salereparray[0]['id']);
  489. if (!empty($salerepobj->signature)) {
  490. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  491. }
  492. }
  493. }
  494. // Extrafields in note
  495. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  496. if (!empty($extranote)) {
  497. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  498. }
  499. if ($notetoshow) {
  500. $tab_top -= 2;
  501. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  502. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  503. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  504. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  505. $pdf->SetFont('', '', $default_font_size - 1);
  506. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
  507. $nexY = $pdf->GetY();
  508. $height_note = $nexY - $tab_top;
  509. // Rect takes a length in 3rd parameter
  510. $pdf->SetDrawColor(192, 192, 192);
  511. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  512. $tab_top = $nexY + 6;
  513. }
  514. $iniY = $tab_top + 7;
  515. $curY = $tab_top + 7;
  516. $nexY = $tab_top + 7;
  517. // Loop on each lines
  518. for ($i = 0; $i < $nblines; $i++) {
  519. $curY = $nexY;
  520. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  521. $pdf->SetTextColor(0, 0, 0);
  522. // Define size of image if we need it
  523. $imglinesize = array();
  524. if (!empty($realpatharray[$i])) {
  525. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  526. }
  527. $pdf->setTopMargin($tab_top_newpage);
  528. $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
  529. $pdf->setPageOrientation('', 1, $page_bottom_margin);
  530. $pageposbefore = $pdf->getPage();
  531. $showpricebeforepagebreak = 1;
  532. $posYAfterImage = 0;
  533. $posYAfterDescription = 0;
  534. // We start with Photo of product line
  535. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - $page_bottom_margin)) { // If photo too high, we moved completely on new page
  536. $pdf->AddPage('', '', true);
  537. if (!empty($tplidx)) {
  538. $pdf->useTemplate($tplidx);
  539. }
  540. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  541. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  542. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  543. }
  544. $pdf->setPage($pageposbefore + 1);
  545. $curY = $tab_top_newpage;
  546. // Allows data in the first page if description is long enough to break in multiples pages
  547. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  548. $showpricebeforepagebreak = 1;
  549. } else {
  550. $showpricebeforepagebreak = 0;
  551. }
  552. }
  553. if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
  554. $curX = $this->posxpicture - 1;
  555. $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  556. // $pdf->Image does not increase value return by getY, so we save it manually
  557. $posYAfterImage = $curY + $imglinesize['height'];
  558. }
  559. // Description of product line
  560. $curX = $this->posxdesc - 1;
  561. $pdf->startTransaction();
  562. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
  563. $pageposafter = $pdf->getPage();
  564. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  565. $pdf->rollbackTransaction(true);
  566. $pageposafter = $pageposbefore;
  567. //print $pageposafter.'-'.$pageposbefore;exit;
  568. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  569. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
  570. $pageposafter = $pdf->getPage();
  571. $posyafter = $pdf->GetY();
  572. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  573. if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
  574. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  575. $pdf->AddPage('', '', true);
  576. if (!empty($tplidx)) {
  577. $pdf->useTemplate($tplidx);
  578. }
  579. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  580. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  581. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  582. }
  583. $pdf->setPage($pageposafter + 1);
  584. }
  585. } else {
  586. // We found a page break
  587. // Allows data in the first page if description is long enough to break in multiples pages
  588. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  589. $showpricebeforepagebreak = 1;
  590. } else {
  591. $showpricebeforepagebreak = 0;
  592. }
  593. }
  594. } else // No pagebreak
  595. {
  596. $pdf->commitTransaction();
  597. }
  598. $posYAfterDescription = $pdf->GetY();
  599. $nexY = $pdf->GetY();
  600. $pageposafter = $pdf->getPage();
  601. $pdf->setPage($pageposbefore);
  602. $pdf->setTopMargin($this->marge_haute);
  603. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  604. // We suppose that a too long description or photo were moved completely on next page
  605. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  606. $pdf->setPage($pageposafter);
  607. $curY = $tab_top_newpage;
  608. }
  609. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  610. // VAT Rate
  611. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  612. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  613. $pdf->SetXY($this->posxtva - 5, $curY);
  614. $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
  615. }
  616. // Unit price before discount
  617. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  618. $pdf->SetXY($this->posxup, $curY);
  619. $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
  620. // Quantity
  621. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  622. $pdf->SetXY($this->posxqty, $curY);
  623. $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
  624. // Unit
  625. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  626. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  627. $pdf->SetXY($this->posxunit, $curY);
  628. $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
  629. }
  630. // Discount on line
  631. if ($object->lines[$i]->remise_percent) {
  632. $pdf->SetXY($this->posxdiscount - 2, $curY);
  633. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  634. $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
  635. }
  636. // Situation progress
  637. if ($this->situationinvoice) {
  638. $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
  639. $pdf->SetXY($this->posxprogress, $curY);
  640. $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
  641. }
  642. // Total HT line
  643. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  644. $pdf->SetXY($this->postotalht, $curY);
  645. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
  646. $sign = 1;
  647. if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  648. $sign = -1;
  649. }
  650. // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
  651. $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
  652. if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
  653. if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
  654. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  655. } else {
  656. $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  657. }
  658. } else {
  659. if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
  660. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
  661. } else {
  662. $tvaligne = $sign * $object->lines[$i]->total_tva;
  663. }
  664. }
  665. $localtax1ligne = $object->lines[$i]->total_localtax1;
  666. $localtax2ligne = $object->lines[$i]->total_localtax2;
  667. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  668. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  669. $localtax1_type = $object->lines[$i]->localtax1_type;
  670. $localtax2_type = $object->lines[$i]->localtax2_type;
  671. // TODO remise_percent is an obsolete field for object parent
  672. /*if ($object->remise_percent) {
  673. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  674. }
  675. if ($object->remise_percent) {
  676. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  677. }
  678. if ($object->remise_percent) {
  679. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  680. }*/
  681. $vatrate = (string) $object->lines[$i]->tva_tx;
  682. // Retrieve type from database for backward compatibility with old records
  683. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  684. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  685. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  686. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  687. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  688. }
  689. // retrieve global local tax
  690. if ($localtax1_type && $localtax1ligne != 0) {
  691. if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
  692. $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
  693. } else {
  694. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  695. }
  696. }
  697. if ($localtax2_type && $localtax2ligne != 0) {
  698. if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
  699. $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
  700. } else {
  701. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  702. }
  703. }
  704. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  705. $vatrate .= '*';
  706. }
  707. // Fill $this->tva and $this->tva_array
  708. if (!isset($this->tva[$vatrate])) {
  709. $this->tva[$vatrate] = 0;
  710. }
  711. $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
  712. $vatcode = $object->lines[$i]->vat_src_code;
  713. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  714. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  715. }
  716. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  717. if ($posYAfterImage > $posYAfterDescription) {
  718. $nexY = $posYAfterImage;
  719. }
  720. // Add line
  721. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  722. $pdf->setPage($pageposafter);
  723. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  724. //$pdf->SetDrawColor(190,190,200);
  725. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  726. $pdf->SetLineStyle(array('dash'=>0));
  727. }
  728. $nexY += 2; // Add space between lines
  729. // Detect if some page were added automatically and output _tableau for past pages
  730. while ($pagenb < $pageposafter) {
  731. $pdf->setPage($pagenb);
  732. if ($pagenb == 1) {
  733. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  734. } else {
  735. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  736. }
  737. $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
  738. $pagenb++;
  739. $pdf->setPage($pagenb);
  740. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  741. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  742. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  743. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  744. }
  745. if (!empty($tplidx)) {
  746. $pdf->useTemplate($tplidx);
  747. }
  748. }
  749. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  750. if ($pagenb == 1) {
  751. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  752. } else {
  753. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  754. }
  755. $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs));
  756. // New page
  757. $pdf->AddPage();
  758. if (!empty($tplidx)) {
  759. $pdf->useTemplate($tplidx);
  760. }
  761. $pagenb++;
  762. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  763. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  764. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  765. }
  766. }
  767. }
  768. // Show square
  769. if ($pagenb == 1) {
  770. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
  771. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
  772. } else {
  773. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  774. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  775. }
  776. dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
  777. // Display info area
  778. $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
  779. // Display total area
  780. $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
  781. // Display Payments area
  782. if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  783. $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
  784. }
  785. // Pagefoot
  786. $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pageposbefore, $object, $langs));
  787. if (method_exists($pdf, 'AliasNbPages')) {
  788. $pdf->AliasNbPages();
  789. }
  790. if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
  791. $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs);
  792. if (!$result) {
  793. $pdf->Close();
  794. return 0;
  795. }
  796. }
  797. $pdf->Close();
  798. $pdf->Output($file, 'F');
  799. // Add pdfgeneration hook
  800. $hookmanager->initHooks(array('pdfgeneration'));
  801. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  802. global $action;
  803. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  804. if ($reshook < 0) {
  805. $this->error = $hookmanager->error;
  806. $this->errors = $hookmanager->errors;
  807. }
  808. dolChmod($file);
  809. $this->result = array('fullpath'=>$file);
  810. return 1; // No error
  811. } else {
  812. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  813. return 0;
  814. }
  815. } else {
  816. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
  817. return 0;
  818. }
  819. }
  820. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  821. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  822. /**
  823. * Show payments table
  824. *
  825. * @param TCPDF $pdf Object PDF
  826. * @param Facture $object Object invoice
  827. * @param int $posy Position y in PDF
  828. * @param Translate $outputlangs Object langs for output
  829. * @param int $heightforfooter Height for footer
  830. * @return int <0 if KO, >0 if OK
  831. */
  832. protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
  833. {
  834. // phpcs:enable
  835. global $conf;
  836. $sign = 1;
  837. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  838. $sign = -1;
  839. }
  840. $current_page = $pdf->getPage();
  841. $tab3_posx = 120;
  842. $tab3_top = $posy + 8;
  843. $tab3_width = 80;
  844. $tab3_height = 4;
  845. if ($this->page_largeur < 210) { // To work with US executive format
  846. $tab3_posx -= 15;
  847. }
  848. $default_font_size = pdf_getPDFFontSize($outputlangs);
  849. $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
  850. $y = 0;
  851. $pdf->SetFont('', '', $default_font_size - 4);
  852. // Loop on each discount available (deposits and credit notes and excess of payment included)
  853. $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
  854. $sql .= " re.description, re.fk_facture_source,";
  855. $sql .= " f.type, f.datef";
  856. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
  857. $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
  858. $resql = $this->db->query($sql);
  859. if ($resql) {
  860. $num = $this->db->num_rows($resql);
  861. $i = 0;
  862. $invoice = new Facture($this->db);
  863. while ($i < $num) {
  864. $y += 3;
  865. if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
  866. $y = 0;
  867. $current_page++;
  868. $pdf->AddPage('', '', true);
  869. if (!empty($tplidx)) {
  870. $pdf->useTemplate($tplidx);
  871. }
  872. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  873. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  874. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  875. }
  876. $pdf->setPage($current_page);
  877. $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
  878. }
  879. $obj = $this->db->fetch_object($resql);
  880. if ($obj->type == 2) {
  881. $text = $outputlangs->transnoentities("CreditNote");
  882. } elseif ($obj->type == 3) {
  883. $text = $outputlangs->transnoentities("Deposit");
  884. } elseif ($obj->type == 0) {
  885. $text = $outputlangs->transnoentities("ExcessReceived");
  886. } else {
  887. $text = $outputlangs->transnoentities("UnknownType");
  888. }
  889. $invoice->fetch($obj->fk_facture_source);
  890. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  891. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
  892. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  893. $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
  894. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  895. $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
  896. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  897. $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
  898. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  899. $i++;
  900. }
  901. } else {
  902. $this->error = $this->db->lasterror();
  903. return -1;
  904. }
  905. // Loop on each payment
  906. // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
  907. $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
  908. $sql .= " cp.code";
  909. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  910. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  911. $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
  912. //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
  913. $sql .= " ORDER BY p.datep";
  914. $resql = $this->db->query($sql);
  915. if ($resql) {
  916. $num = $this->db->num_rows($resql);
  917. $i = 0;
  918. while ($i < $num) {
  919. $y += 3;
  920. if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
  921. $y = 0;
  922. $current_page++;
  923. $pdf->AddPage('', '', true);
  924. if (!empty($tplidx)) {
  925. $pdf->useTemplate($tplidx);
  926. }
  927. if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
  928. $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
  929. $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
  930. }
  931. $pdf->setPage($current_page);
  932. $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
  933. }
  934. $row = $this->db->fetch_object($resql);
  935. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  936. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
  937. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  938. $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
  939. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  940. $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  941. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  942. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  943. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  944. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  945. $i++;
  946. }
  947. return $tab3_top + $y + 3;
  948. } else {
  949. $this->error = $this->db->lasterror();
  950. return -1;
  951. }
  952. }
  953. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  954. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  955. /**
  956. * Function _tableau_versements_header
  957. *
  958. * @param TCPDF $pdf Object PDF
  959. * @param Facture $object Object invoice
  960. * @param Translate $outputlangs Object langs for output
  961. * @param int $default_font_size Font size
  962. * @param int $tab3_posx pos x
  963. * @param int $tab3_top pos y
  964. * @param int $tab3_width width
  965. * @param int $tab3_height height
  966. * @return void
  967. */
  968. protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
  969. {
  970. // phpcs:enable
  971. $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
  972. if ($object->type == 2) {
  973. $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
  974. }
  975. $pdf->SetFont('', '', $default_font_size - 3);
  976. $pdf->SetXY($tab3_posx, $tab3_top - 4);
  977. $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
  978. $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
  979. $pdf->SetFont('', '', $default_font_size - 4);
  980. $pdf->SetXY($tab3_posx, $tab3_top);
  981. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  982. $pdf->SetXY($tab3_posx + 21, $tab3_top);
  983. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  984. $pdf->SetXY($tab3_posx + 40, $tab3_top);
  985. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  986. $pdf->SetXY($tab3_posx + 58, $tab3_top);
  987. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  988. $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
  989. }
  990. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  991. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  992. /**
  993. * Show miscellaneous information (payment mode, payment term, ...)
  994. *
  995. * @param TCPDF $pdf Object PDF
  996. * @param Facture $object Object to show
  997. * @param int $posy Y
  998. * @param Translate $outputlangs Langs object
  999. * @param Translate $outputlangsbis Object lang for output bis
  1000. * @return int Pos y
  1001. */
  1002. protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
  1003. {
  1004. // phpcs:enable
  1005. global $conf, $mysoc;
  1006. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1007. $pdf->SetFont('', '', $default_font_size - 1);
  1008. // If France, show VAT mention if not applicable
  1009. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  1010. $pdf->SetFont('', 'B', $default_font_size - 2);
  1011. $pdf->SetXY($this->marge_gauche, $posy);
  1012. if ($mysoc->forme_juridique_code == 92) {
  1013. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
  1014. } else {
  1015. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  1016. }
  1017. $posy = $pdf->GetY() + 4;
  1018. }
  1019. $posxval = 52;
  1020. $posxend = 110; // End of x for text on left side
  1021. if ($this->page_largeur < 210) { // To work with US executive format
  1022. $posxend -= 10;
  1023. }
  1024. // Show payments conditions
  1025. if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
  1026. $pdf->SetFont('', 'B', $default_font_size - 2);
  1027. $pdf->SetXY($this->marge_gauche, $posy);
  1028. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  1029. $pdf->MultiCell(43, 4, $titre, 0, 'L');
  1030. $pdf->SetFont('', '', $default_font_size - 2);
  1031. $pdf->SetXY($posxval, $posy);
  1032. $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);
  1033. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  1034. $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
  1035. $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
  1036. }
  1037. // Show category of operations
  1038. if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
  1039. $pdf->SetFont('', 'B', $default_font_size - 2);
  1040. $pdf->SetXY($this->marge_gauche, $posy);
  1041. $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
  1042. $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
  1043. $pdf->SetFont('', '', $default_font_size - 2);
  1044. $pdf->SetXY($posxval, $posy);
  1045. $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
  1046. $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
  1047. $posy = $pdf->GetY() + 3; // for 2 lines
  1048. }
  1049. if ($object->type != 2) {
  1050. // Check a payment mode is defined
  1051. if (empty($object->mode_reglement_code)
  1052. && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
  1053. && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
  1054. $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
  1055. } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
  1056. || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
  1057. // Avoid having any valid PDF with setup that is not complete
  1058. $outputlangs->load("errors");
  1059. $pdf->SetXY($this->marge_gauche, $posy);
  1060. $pdf->SetTextColor(200, 0, 0);
  1061. $pdf->SetFont('', 'B', $default_font_size - 2);
  1062. $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
  1063. $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
  1064. $pdf->SetTextColor(0, 0, 0);
  1065. $posy = $pdf->GetY() + 1;
  1066. }
  1067. // Show payment mode
  1068. if (!empty($object->mode_reglement_code)
  1069. && $object->mode_reglement_code != 'CHQ'
  1070. && $object->mode_reglement_code != 'VIR') {
  1071. $pdf->SetFont('', 'B', $default_font_size - 2);
  1072. $pdf->SetXY($this->marge_gauche, $posy);
  1073. $titre = $outputlangs->transnoentities("PaymentMode").':';
  1074. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  1075. $pdf->SetFont('', '', $default_font_size - 2);
  1076. $pdf->SetXY($posxval, $posy);
  1077. $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);
  1078. //#21654: add account number used for the debit
  1079. if ($object->mode_reglement_code == "PRE") {
  1080. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  1081. $bac = new CompanyBankAccount($this->db);
  1082. $bac->fetch(0, $object->thirdparty->id);
  1083. $iban= $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
  1084. $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
  1085. }
  1086. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  1087. $posy = $pdf->GetY();
  1088. }
  1089. // Show if Option VAT debit option is on also if transmitter is french
  1090. // Decret n°2099-1299 2022-10-07
  1091. // French mention : "Option pour le paiement de la taxe d'après les débits"
  1092. if ($this->emetteur->country_code == 'FR') {
  1093. if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
  1094. $pdf->SetXY($this->marge_gauche, $posy);
  1095. $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
  1096. $posy = $pdf->GetY() + 1;
  1097. }
  1098. }
  1099. // Show online payment link
  1100. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
  1101. $useonlinepayment = 0;
  1102. if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
  1103. if (isModEnabled('paypal')) {
  1104. $useonlinepayment++;
  1105. }
  1106. if (isModEnabled('stripe')) {
  1107. $useonlinepayment++;
  1108. }
  1109. if (isModEnabled('paybox')) {
  1110. $useonlinepayment++;
  1111. }
  1112. }
  1113. if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
  1114. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  1115. global $langs;
  1116. $langs->loadLangs(array('payment', 'paybox', 'stripe'));
  1117. $servicename = $langs->transnoentities('Online');
  1118. $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
  1119. $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
  1120. $pdf->SetXY($this->marge_gauche, $posy);
  1121. $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
  1122. $posy = $pdf->GetY() + 1;
  1123. }
  1124. }
  1125. // Show payment mode CHQ
  1126. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  1127. // If payment mode unregulated or payment mode forced to CHQ
  1128. if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
  1129. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  1130. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  1131. $account = new Account($this->db);
  1132. $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
  1133. $pdf->SetXY($this->marge_gauche, $posy);
  1134. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1135. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  1136. $posy = $pdf->GetY() + 1;
  1137. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1138. $pdf->SetXY($this->marge_gauche, $posy);
  1139. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1140. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  1141. $posy = $pdf->GetY() + 2;
  1142. }
  1143. }
  1144. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  1145. $pdf->SetXY($this->marge_gauche, $posy);
  1146. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1147. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  1148. $posy = $pdf->GetY() + 1;
  1149. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1150. $pdf->SetXY($this->marge_gauche, $posy);
  1151. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1152. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  1153. $posy = $pdf->GetY() + 2;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. // If payment mode not forced or forced to VIR, show payment with BAN
  1159. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  1160. if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
  1161. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  1162. if ($object->fk_bank > 0) {
  1163. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  1164. }
  1165. $account = new Account($this->db);
  1166. $account->fetch($bankid);
  1167. $curx = $this->marge_gauche;
  1168. $cury = $posy;
  1169. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  1170. $posy += 2;
  1171. }
  1172. }
  1173. }
  1174. return $posy;
  1175. }
  1176. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1177. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1178. /**
  1179. * Show total to pay
  1180. *
  1181. * @param TCPDF $pdf Object PDF
  1182. * @param Facture $object Object invoice
  1183. * @param int $deja_regle Amount already paid (in the currency of invoice)
  1184. * @param int $posy Position depart
  1185. * @param Translate $outputlangs Objet langs
  1186. * @param Translate $outputlangsbis Object lang for output bis
  1187. * @return int Position pour suite
  1188. */
  1189. protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
  1190. {
  1191. // phpcs:enable
  1192. global $conf, $mysoc, $hookmanager;
  1193. $sign = 1;
  1194. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  1195. $sign = -1;
  1196. }
  1197. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1198. $outputlangsbis = null;
  1199. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  1200. $outputlangsbis = new Translate('', $conf);
  1201. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  1202. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  1203. $default_font_size--;
  1204. }
  1205. $tab2_top = $posy;
  1206. $tab2_hl = 4;
  1207. $pdf->SetFont('', '', $default_font_size - 1);
  1208. // Total table
  1209. $col1x = 120;
  1210. $col2x = 170;
  1211. if ($this->page_largeur < 210) { // To work with US executive format
  1212. $col1x -= 15;
  1213. $col2x -= 10;
  1214. }
  1215. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  1216. $useborder = 0;
  1217. $index = 0;
  1218. // Total HT
  1219. $pdf->SetFillColor(255, 255, 255);
  1220. $pdf->SetXY($col1x, $tab2_top);
  1221. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") : ''), 0, 'L', 1);
  1222. $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  1223. $pdf->SetXY($col2x, $tab2_top);
  1224. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
  1225. // Show VAT by rates and total
  1226. $pdf->SetFillColor(248, 248, 248);
  1227. $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  1228. $this->atleastoneratenotnull = 0;
  1229. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  1230. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  1231. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  1232. // Nothing to do
  1233. } else {
  1234. // FIXME amount of vat not supported with multicurrency
  1235. //Local tax 1 before VAT
  1236. //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1237. //{
  1238. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1239. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1240. continue;
  1241. }
  1242. foreach ($localtax_rate as $tvakey => $tvaval) {
  1243. if ($tvakey != 0) { // On affiche pas taux 0
  1244. //$this->atleastoneratenotnull++;
  1245. $index++;
  1246. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1247. $tvacompl = '';
  1248. if (preg_match('/\*/', $tvakey)) {
  1249. $tvakey = str_replace('*', '', $tvakey);
  1250. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1251. }
  1252. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1253. $totalvat .= ' ';
  1254. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1255. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1256. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1257. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1258. }
  1259. }
  1260. }
  1261. //}
  1262. //Local tax 2 before VAT
  1263. //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1264. //{
  1265. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1266. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1267. continue;
  1268. }
  1269. foreach ($localtax_rate as $tvakey => $tvaval) {
  1270. if ($tvakey != 0) { // On affiche pas taux 0
  1271. //$this->atleastoneratenotnull++;
  1272. $index++;
  1273. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1274. $tvacompl = '';
  1275. if (preg_match('/\*/', $tvakey)) {
  1276. $tvakey = str_replace('*', '', $tvakey);
  1277. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1278. }
  1279. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1280. $totalvat .= ' ';
  1281. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1282. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1283. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1284. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1285. }
  1286. }
  1287. }
  1288. //}
  1289. // VAT
  1290. foreach ($this->tva_array as $tvakey => $tvaval) {
  1291. if ($tvakey != 0) { // On affiche pas taux 0
  1292. $this->atleastoneratenotnull++;
  1293. $index++;
  1294. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1295. $tvacompl = '';
  1296. if (preg_match('/\*/', $tvakey)) {
  1297. $tvakey = str_replace('*', '', $tvakey);
  1298. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1299. }
  1300. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1301. $totalvat .= ' ';
  1302. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  1303. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  1304. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  1305. $totalvat .= $tvaval['vatcode'].$tvacompl;
  1306. } else {
  1307. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  1308. }
  1309. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1310. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1311. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  1312. }
  1313. }
  1314. //Local tax 1 after VAT
  1315. //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1316. //{
  1317. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1318. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1319. continue;
  1320. }
  1321. foreach ($localtax_rate as $tvakey => $tvaval) {
  1322. if ($tvakey != 0) { // On affiche pas taux 0
  1323. //$this->atleastoneratenotnull++;
  1324. $index++;
  1325. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1326. $tvacompl = '';
  1327. if (preg_match('/\*/', $tvakey)) {
  1328. $tvakey = str_replace('*', '', $tvakey);
  1329. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1330. }
  1331. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
  1332. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1333. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1334. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1335. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1336. }
  1337. }
  1338. }
  1339. //}
  1340. //Local tax 2 after VAT
  1341. //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1342. //{
  1343. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1344. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1345. continue;
  1346. }
  1347. foreach ($localtax_rate as $tvakey => $tvaval) {
  1348. //$this->atleastoneratenotnull++;
  1349. $index++;
  1350. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1351. $tvacompl = '';
  1352. if (preg_match('/\*/', $tvakey)) {
  1353. $tvakey = str_replace('*', '', $tvakey);
  1354. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1355. }
  1356. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
  1357. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1358. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1359. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1360. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1361. }
  1362. }
  1363. //}
  1364. // Revenue stamp
  1365. if (price2num($object->revenuestamp) != 0) {
  1366. $index++;
  1367. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1368. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
  1369. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1370. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
  1371. }
  1372. // Total TTC
  1373. $index++;
  1374. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1375. $pdf->SetTextColor(0, 0, 60);
  1376. $pdf->SetFillColor(224, 224, 224);
  1377. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
  1378. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1379. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1380. // Retained warranty
  1381. if ($object->displayRetainedWarranty()) {
  1382. $pdf->SetTextColor(40, 40, 40);
  1383. $pdf->SetFillColor(255, 255, 255);
  1384. $retainedWarranty = $object->getRetainedWarrantyAmount();
  1385. $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
  1386. // Billed - retained warranty
  1387. $index++;
  1388. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1389. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
  1390. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1391. $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
  1392. // retained warranty
  1393. $index++;
  1394. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1395. $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
  1396. $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
  1397. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
  1398. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1399. $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
  1400. }
  1401. }
  1402. }
  1403. $pdf->SetTextColor(0, 0, 0);
  1404. $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
  1405. $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
  1406. //print "x".$creditnoteamount."-".$depositsamount;exit;
  1407. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  1408. if (!empty($object->paye)) {
  1409. $resteapayer = 0;
  1410. }
  1411. if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  1412. // Already paid + Deposits
  1413. $index++;
  1414. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1415. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
  1416. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1417. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
  1418. // Credit note
  1419. if ($creditnoteamount) {
  1420. $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
  1421. $index++;
  1422. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1423. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
  1424. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1425. $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
  1426. }
  1427. // Escompte
  1428. if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
  1429. $index++;
  1430. $pdf->SetFillColor(255, 255, 255);
  1431. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1432. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
  1433. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1434. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
  1435. $resteapayer = 0;
  1436. }
  1437. $index++;
  1438. $pdf->SetTextColor(0, 0, 60);
  1439. $pdf->SetFillColor(224, 224, 224);
  1440. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1441. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  1442. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1443. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1444. $pdf->SetFont('', '', $default_font_size - 1);
  1445. $pdf->SetTextColor(0, 0, 0);
  1446. }
  1447. $index++;
  1448. return ($tab2_top + ($tab2_hl * $index));
  1449. }
  1450. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1451. /**
  1452. * Show table for lines
  1453. *
  1454. * @param TCPDF $pdf Object PDF
  1455. * @param string $tab_top Top position of table
  1456. * @param string $tab_height Height of table (rectangle)
  1457. * @param int $nexY Y (not used)
  1458. * @param Translate $outputlangs Langs object
  1459. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1460. * @param int $hidebottom Hide bottom bar of array
  1461. * @param string $currency Currency code
  1462. * @return void
  1463. */
  1464. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
  1465. {
  1466. global $conf;
  1467. // Force to disable hidetop and hidebottom
  1468. $hidebottom = 0;
  1469. if ($hidetop) {
  1470. $hidetop = -1;
  1471. }
  1472. $currency = !empty($currency) ? $currency : $conf->currency;
  1473. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1474. // Amount in (at tab_top - 1)
  1475. $pdf->SetTextColor(0, 0, 0);
  1476. $pdf->SetFont('', '', $default_font_size - 2);
  1477. if (empty($hidetop)) {
  1478. // Show category of operations
  1479. if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
  1480. $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
  1481. $pdf->SetXY($this->marge_gauche, $tab_top - 4);
  1482. $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
  1483. }
  1484. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1485. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1486. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1487. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1488. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1489. $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));
  1490. }
  1491. }
  1492. $pdf->SetDrawColor(128, 128, 128);
  1493. $pdf->SetFont('', '', $default_font_size - 1);
  1494. // Output Rect
  1495. $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
  1496. if (empty($hidetop)) {
  1497. $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
  1498. $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
  1499. $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
  1500. }
  1501. if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
  1502. $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
  1503. if (empty($hidetop)) {
  1504. //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
  1505. //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
  1506. }
  1507. }
  1508. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1509. $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
  1510. if (empty($hidetop)) {
  1511. $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
  1512. $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
  1513. }
  1514. }
  1515. $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
  1516. if (empty($hidetop)) {
  1517. $pdf->SetXY($this->posxup - 1, $tab_top + 1);
  1518. $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
  1519. }
  1520. $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
  1521. if (empty($hidetop)) {
  1522. $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
  1523. $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
  1524. }
  1525. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  1526. $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
  1527. if (empty($hidetop)) {
  1528. $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
  1529. $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
  1530. }
  1531. }
  1532. if ($this->atleastonediscount) {
  1533. $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
  1534. if (empty($hidetop)) {
  1535. $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
  1536. $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
  1537. }
  1538. }
  1539. if ($this->situationinvoice) {
  1540. $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
  1541. if (empty($hidetop)) {
  1542. $pdf->SetXY($this->posxprogress, $tab_top + 1);
  1543. $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
  1544. }
  1545. }
  1546. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  1547. if (empty($hidetop)) {
  1548. $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
  1549. $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
  1550. }
  1551. }
  1552. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1553. /**
  1554. * Show top header of page.
  1555. *
  1556. * @param TCPDF $pdf Object PDF
  1557. * @param Facture $object Object to show
  1558. * @param int $showaddress 0=no, 1=yes
  1559. * @param Translate $outputlangs Object lang for output
  1560. * @param Translate $outputlangsbis Object lang for output bis
  1561. * @return int top shift of linked object lines
  1562. */
  1563. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
  1564. {
  1565. global $conf, $langs;
  1566. $ltrdirection = 'L';
  1567. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1568. // Load traductions files required by page
  1569. $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
  1570. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1571. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1572. $pdf->SetTextColor(0, 0, 60);
  1573. $pdf->SetFont('', 'B', $default_font_size + 3);
  1574. $w = 110;
  1575. $posy = $this->marge_haute;
  1576. $posx = $this->page_largeur - $this->marge_droite - $w;
  1577. $pdf->SetXY($this->marge_gauche, $posy);
  1578. // Logo
  1579. if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
  1580. if ($this->emetteur->logo) {
  1581. $logodir = $conf->mycompany->dir_output;
  1582. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1583. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1584. }
  1585. if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
  1586. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1587. } else {
  1588. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1589. }
  1590. if (is_readable($logo)) {
  1591. $height = pdf_getHeightForLogo($logo);
  1592. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1593. } else {
  1594. $pdf->SetTextColor(200, 0, 0);
  1595. $pdf->SetFont('', 'B', $default_font_size - 2);
  1596. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1597. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1598. }
  1599. } else {
  1600. $text = $this->emetteur->name;
  1601. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
  1602. }
  1603. }
  1604. $pdf->SetFont('', 'B', $default_font_size + 3);
  1605. $pdf->SetXY($posx, $posy);
  1606. $pdf->SetTextColor(0, 0, 60);
  1607. $title = $outputlangs->transnoentities("PdfInvoiceTitle");
  1608. if ($object->type == 1) {
  1609. $title = $outputlangs->transnoentities("InvoiceReplacement");
  1610. }
  1611. if ($object->type == 2) {
  1612. $title = $outputlangs->transnoentities("InvoiceAvoir");
  1613. }
  1614. if ($object->type == 3) {
  1615. $title = $outputlangs->transnoentities("InvoiceDeposit");
  1616. }
  1617. if ($object->type == 4) {
  1618. $title = $outputlangs->transnoentities("InvoiceProForma");
  1619. }
  1620. if ($this->situationinvoice) {
  1621. $langs->loadLangs(array("other"));
  1622. $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
  1623. }
  1624. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1625. $title .= ' - ';
  1626. if ($object->type == 0) {
  1627. if ($this->situationinvoice) {
  1628. $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
  1629. }
  1630. $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
  1631. } elseif ($object->type == 1) {
  1632. $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
  1633. } elseif ($object->type == 2) {
  1634. $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
  1635. } elseif ($object->type == 3) {
  1636. $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
  1637. } elseif ($object->type == 4) {
  1638. $title .= $outputlangsbis->transnoentities("InvoiceProForma");
  1639. }
  1640. }
  1641. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1642. if ($object->statut == $object::STATUS_DRAFT) {
  1643. $pdf->SetTextColor(128, 0, 0);
  1644. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1645. }
  1646. $pdf->MultiCell($w, 3, $title, '', 'R');
  1647. $pdf->SetFont('', 'B', $default_font_size);
  1648. /*
  1649. $posy += 5;
  1650. $pdf->SetXY($posx, $posy);
  1651. $pdf->SetTextColor(0, 0, 60);
  1652. $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
  1653. if ($object->statut == $object::STATUS_DRAFT) {
  1654. $pdf->SetTextColor(128, 0, 0);
  1655. $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
  1656. }
  1657. $pdf->MultiCell($w, 4, $textref, '', 'R');*/
  1658. $posy += 3;
  1659. $pdf->SetFont('', '', $default_font_size - 2);
  1660. if ($object->ref_customer) {
  1661. $posy += 4;
  1662. $pdf->SetXY($posx, $posy);
  1663. $pdf->SetTextColor(0, 0, 60);
  1664. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_customer), '', 'R');
  1665. }
  1666. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1667. $object->fetch_projet();
  1668. if (!empty($object->project->ref)) {
  1669. $posy += 3;
  1670. $pdf->SetXY($posx, $posy);
  1671. $pdf->SetTextColor(0, 0, 60);
  1672. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1673. }
  1674. }
  1675. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1676. $object->fetch_projet();
  1677. if (!empty($object->project->ref)) {
  1678. $outputlangs->load("projects");
  1679. $posy += 3;
  1680. $pdf->SetXY($posx, $posy);
  1681. $pdf->SetTextColor(0, 0, 60);
  1682. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1683. }
  1684. }
  1685. $objectidnext = $object->getIdReplacingInvoice('validated');
  1686. if ($object->type == 0 && $objectidnext) {
  1687. $objectreplacing = new Facture($this->db);
  1688. $objectreplacing->fetch($objectidnext);
  1689. $posy += 3;
  1690. $pdf->SetXY($posx, $posy);
  1691. $pdf->SetTextColor(0, 0, 60);
  1692. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
  1693. }
  1694. if ($object->type == 1) {
  1695. $objectreplaced = new Facture($this->db);
  1696. $objectreplaced->fetch($object->fk_facture_source);
  1697. $posy += 4;
  1698. $pdf->SetXY($posx, $posy);
  1699. $pdf->SetTextColor(0, 0, 60);
  1700. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  1701. }
  1702. if ($object->type == 2 && !empty($object->fk_facture_source)) {
  1703. $objectreplaced = new Facture($this->db);
  1704. $objectreplaced->fetch($object->fk_facture_source);
  1705. $posy += 3;
  1706. $pdf->SetXY($posx, $posy);
  1707. $pdf->SetTextColor(0, 0, 60);
  1708. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  1709. }
  1710. $posy += 4;
  1711. $pdf->SetXY($posx, $posy);
  1712. $pdf->SetTextColor(0, 0, 60);
  1713. $title = $outputlangs->transnoentities("DateInvoice");
  1714. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1715. $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
  1716. }
  1717. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
  1718. if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
  1719. $posy += 4;
  1720. $pdf->SetXY($posx, $posy);
  1721. $pdf->SetTextColor(0, 0, 60);
  1722. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
  1723. }
  1724. if ($object->type != 2) {
  1725. $posy += 3;
  1726. $pdf->SetXY($posx, $posy);
  1727. $pdf->SetTextColor(0, 0, 60);
  1728. $title = $outputlangs->transnoentities("DateDue");
  1729. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1730. $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
  1731. }
  1732. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
  1733. }
  1734. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
  1735. $posy += 3;
  1736. $pdf->SetXY($posx, $posy);
  1737. $pdf->SetTextColor(0, 0, 60);
  1738. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1739. }
  1740. // Get contact
  1741. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1742. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1743. if (count($arrayidcontact) > 0) {
  1744. $usertmp = new User($this->db);
  1745. $usertmp->fetch($arrayidcontact[0]);
  1746. $posy += 4;
  1747. $pdf->SetXY($posx, $posy);
  1748. $pdf->SetTextColor(0, 0, 60);
  1749. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1750. }
  1751. }
  1752. $posy += 1;
  1753. $top_shift = 0;
  1754. // Show list of linked objects
  1755. $current_y = $pdf->getY();
  1756. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1757. if ($current_y < $pdf->getY()) {
  1758. $top_shift = $pdf->getY() - $current_y;
  1759. }
  1760. if ($showaddress) {
  1761. // Sender properties
  1762. $carac_emetteur = '';
  1763. // Add internal contact of object if defined
  1764. $arrayidcontact = $object->getIdContact('internal', 'BILLING');
  1765. if (count($arrayidcontact) > 0) {
  1766. $object->fetch_user($arrayidcontact[0]);
  1767. $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
  1768. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
  1769. $carac_emetteur .= "\n";
  1770. }
  1771. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1772. // Show sender
  1773. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1774. $posy += $top_shift;
  1775. $posx = $this->marge_gauche;
  1776. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1777. $posx = $this->page_largeur - $this->marge_droite - 80;
  1778. }
  1779. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  1780. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1781. // Show sender frame
  1782. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1783. $pdf->SetTextColor(0, 0, 0);
  1784. $pdf->SetFont('', '', $default_font_size - 2);
  1785. $pdf->SetXY($posx, $posy - 5);
  1786. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1787. $pdf->SetXY($posx, $posy);
  1788. $pdf->SetFillColor(230, 230, 230);
  1789. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  1790. $pdf->SetTextColor(0, 0, 60);
  1791. }
  1792. // Show sender name
  1793. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1794. $pdf->SetXY($posx + 2, $posy + 3);
  1795. $pdf->SetFont('', 'B', $default_font_size);
  1796. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1797. $posy = $pdf->getY();
  1798. }
  1799. // Show sender information
  1800. $pdf->SetXY($posx + 2, $posy);
  1801. $pdf->SetFont('', '', $default_font_size - 1);
  1802. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
  1803. // If BILLING contact defined on invoice, we use it
  1804. $usecontact = false;
  1805. $arrayidcontact = $object->getIdContact('external', 'BILLING');
  1806. if (count($arrayidcontact) > 0) {
  1807. $usecontact = true;
  1808. $result = $object->fetch_contact($arrayidcontact[0]);
  1809. }
  1810. // Recipient name
  1811. 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)))) {
  1812. $thirdparty = $object->contact;
  1813. } else {
  1814. $thirdparty = $object->thirdparty;
  1815. }
  1816. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1817. $mode = 'target';
  1818. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1819. // Show recipient
  1820. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1821. if ($this->page_largeur < 210) {
  1822. $widthrecbox = 84; // To work with US executive format
  1823. }
  1824. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1825. $posy += $top_shift;
  1826. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1827. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1828. $posx = $this->marge_gauche;
  1829. }
  1830. // Show recipient frame
  1831. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1832. $pdf->SetTextColor(0, 0, 0);
  1833. $pdf->SetFont('', '', $default_font_size - 2);
  1834. $pdf->SetXY($posx + 2, $posy - 5);
  1835. $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1836. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1837. }
  1838. // Show recipient name
  1839. $pdf->SetXY($posx + 2, $posy + 3);
  1840. $pdf->SetFont('', 'B', $default_font_size);
  1841. $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
  1842. $posy = $pdf->getY();
  1843. // Show recipient information
  1844. $pdf->SetFont('', '', $default_font_size - 1);
  1845. $pdf->SetXY($posx + 2, $posy);
  1846. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
  1847. // Show shipping address
  1848. if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
  1849. $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
  1850. if (!empty($idaddressshipping)) {
  1851. $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
  1852. $companystatic = new Societe($this->db);
  1853. $companystatic->fetch($object->contact->fk_soc);
  1854. $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs);
  1855. $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
  1856. } else {
  1857. $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
  1858. $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
  1859. }
  1860. if (!empty($carac_client_shipping)) {
  1861. $posy += $hautcadre;
  1862. // Show shipping frame
  1863. $pdf->SetXY($posx + 2, $posy - 5);
  1864. $pdf->SetFont('', '', $default_font_size - 2);
  1865. $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
  1866. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1867. // Show shipping name
  1868. $pdf->SetXY($posx + 2, $posy + 3);
  1869. $pdf->SetFont('', 'B', $default_font_size);
  1870. $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
  1871. $posy = $pdf->getY();
  1872. // Show shipping information
  1873. $pdf->SetXY($posx+2, $posy);
  1874. $pdf->SetFont('', '', $default_font_size - 1);
  1875. $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
  1876. $top_shift += $hautcadre;
  1877. }
  1878. }
  1879. }
  1880. $pdf->SetTextColor(0, 0, 0);
  1881. return $top_shift;
  1882. }
  1883. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1884. /**
  1885. * Show footer of page. Need this->emetteur object
  1886. *
  1887. * @param TCPDF $pdf PDF
  1888. * @param Facture $object Object to show
  1889. * @param Translate $outputlangs Object lang for output
  1890. * @param int $hidefreetext 1=Hide free text
  1891. * @param int $heightforqrinvoice Height for QR invoices
  1892. * @return int Return height of bottom margin including footer text
  1893. */
  1894. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
  1895. {
  1896. $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
  1897. return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
  1898. }
  1899. }