pdf_crabe.modules.php 81 KB

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