pdf_crabe.modules.php 82 KB

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