pdf_crabe.modules.php 88 KB

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