pdf_crabe.modules.php 81 KB

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