pdf_crabe.modules.php 88 KB

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