pdf_sponge.modules.php 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  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 Ferran Marcet <fmarcet@2byte.es>
  11. * Copyright (C) 2018 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_sponge.modules.php
  29. * \ingroup facture
  30. * \brief File of class to generate customers invoices from sponge 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 manage PDF invoice template sponge
  39. */
  40. class pdf_sponge 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 array of document table columns
  111. */
  112. public $cols;
  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 = "sponge";
  125. $this->description = $langs->trans('PDFSpongeDescription');
  126. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  127. // Dimension page
  128. $this->type = 'pdf';
  129. $formatarray = pdf_getFormat();
  130. $this->page_largeur = $formatarray['width'];
  131. $this->page_hauteur = $formatarray['height'];
  132. $this->format = array($this->page_largeur, $this->page_hauteur);
  133. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  134. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  135. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  136. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  137. $this->option_logo = 1; // Display logo
  138. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  139. $this->option_modereg = 1; // Display payment mode
  140. $this->option_condreg = 1; // Display payment terms
  141. $this->option_codeproduitservice = 1; // Display product-service code
  142. $this->option_multilang = 1; // Available in several languages
  143. $this->option_escompte = 1; // Displays if there has been a discount
  144. $this->option_credit_note = 1; // Support credit notes
  145. $this->option_freetext = 1; // Support add of a personalised text
  146. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  147. $this->watermark = '';
  148. // Get source company
  149. $this->emetteur = $mysoc;
  150. if (empty($this->emetteur->country_code)) {
  151. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  152. }
  153. // Define position of columns
  154. $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
  155. $this->tabTitleHeight = 5; // default height
  156. // Use new system for position of columns, view $this->defineColumnField()
  157. $this->tva = array();
  158. $this->tva_array = array();
  159. $this->localtax1 = array();
  160. $this->localtax2 = array();
  161. $this->atleastoneratenotnull = 0;
  162. $this->atleastonediscount = 0;
  163. $this->situationinvoice = false;
  164. }
  165. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  166. /**
  167. * Function to build pdf onto disk
  168. *
  169. * @param Facture $object Object to generate
  170. * @param Translate $outputlangs Lang output object
  171. * @param string $srctemplatepath Full path of source filename for generator using a template file
  172. * @param int $hidedetails Do not show line details
  173. * @param int $hidedesc Do not show desc
  174. * @param int $hideref Do not show ref
  175. * @return int 1=OK, 0=KO
  176. */
  177. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  178. {
  179. // phpcs:enable
  180. global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
  181. dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
  182. if (!is_object($outputlangs)) {
  183. $outputlangs = $langs;
  184. }
  185. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  186. if (!empty($conf->global->MAIN_USE_FPDF)) {
  187. $outputlangs->charset_output = 'ISO-8859-1';
  188. }
  189. // Load translation files required by the page
  190. $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
  191. global $outputlangsbis;
  192. $outputlangsbis = null;
  193. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  194. $outputlangsbis = new Translate('', $conf);
  195. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  196. $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
  197. }
  198. // Show Draft Watermark
  199. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
  200. $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
  201. }
  202. $nblines = count($object->lines);
  203. $hidetop = 0;
  204. if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
  205. $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
  206. }
  207. // Loop on each lines to detect if there is at least one image to show
  208. $realpatharray = array();
  209. $this->atleastonephoto = false;
  210. if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
  211. $objphoto = new Product($this->db);
  212. for ($i = 0; $i < $nblines; $i++) {
  213. if (empty($object->lines[$i]->fk_product)) {
  214. continue;
  215. }
  216. $objphoto->fetch($object->lines[$i]->fk_product);
  217. //var_dump($objphoto->ref);exit;
  218. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
  219. $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
  220. $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
  221. } else {
  222. $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
  223. $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
  224. }
  225. $arephoto = false;
  226. foreach ($pdir as $midir) {
  227. if (!$arephoto) {
  228. if ($conf->entity != $objphoto->entity) {
  229. $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
  230. } else {
  231. $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
  232. }
  233. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  234. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  235. if ($obj['photo_vignette']) {
  236. $filename = $obj['photo_vignette'];
  237. } else {
  238. $filename = $obj['photo'];
  239. }
  240. } else {
  241. $filename = $obj['photo'];
  242. }
  243. $realpath = $dir.$filename;
  244. $arephoto = true;
  245. $this->atleastonephoto = true;
  246. }
  247. }
  248. }
  249. if ($realpath && $arephoto) {
  250. $realpatharray[$i] = $realpath;
  251. }
  252. }
  253. }
  254. //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
  255. if ($conf->facture->multidir_output[$conf->entity]) {
  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 = $conf->facture->multidir_output[$conf->entity];
  263. $file = $dir."/SPECIMEN.pdf";
  264. } else {
  265. $objectref = dol_sanitizeFileName($object->ref);
  266. $dir = $conf->facture->multidir_output[$object->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. $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
  294. $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
  295. if (class_exists('TCPDF')) {
  296. $pdf->setPrintHeader(false);
  297. $pdf->setPrintFooter(false);
  298. }
  299. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  300. // Set path to the background PDF File
  301. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  302. $logodir = $conf->mycompany->dir_output;
  303. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  304. $logodir = $conf->mycompany->multidir_output[$object->entity];
  305. }
  306. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  307. $tplidx = $pdf->importPage(1);
  308. }
  309. $pdf->Open();
  310. $pagenb = 0;
  311. $pdf->SetDrawColor(128, 128, 128);
  312. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  313. $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
  314. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  315. $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
  316. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  317. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  318. $pdf->SetCompression(false);
  319. }
  320. // Set certificate
  321. $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
  322. $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
  323. // If user has no certificate, we try to take the company one
  324. if (!$cert) {
  325. $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
  326. }
  327. if (!$certprivate) {
  328. $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
  329. }
  330. // If a certificate is found
  331. if ($cert) {
  332. $info = array(
  333. 'Name' => $this->emetteur->name,
  334. 'Location' => getCountry($this->emetteur->country_code, 0),
  335. 'Reason' => 'INVOICE',
  336. 'ContactInfo' => $this->emetteur->email
  337. );
  338. $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
  339. }
  340. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  341. // Set $this->atleastonediscount if you have at least one discount
  342. for ($i = 0; $i < $nblines; $i++) {
  343. if ($object->lines[$i]->remise_percent) {
  344. $this->atleastonediscount++;
  345. }
  346. }
  347. // Situation invoice handling
  348. if ($object->situation_cycle_ref) {
  349. $this->situationinvoice = true;
  350. }
  351. // New page
  352. $pdf->AddPage();
  353. if (!empty($tplidx)) {
  354. $pdf->useTemplate($tplidx);
  355. }
  356. $pagenb++;
  357. // Output header (logo, ref and address blocks). This is first call for first page.
  358. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
  359. $pdf->SetFont('', '', $default_font_size - 1);
  360. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  361. $pdf->SetTextColor(0, 0, 0);
  362. // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
  363. // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
  364. $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
  365. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  366. // You can add more thing under header here, if you increase $extra_under_address_shift too.
  367. $extra_under_address_shift = 0;
  368. if (! empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
  369. $qrcodestring = $object->buildZATCAQRString();
  370. $qrcodecolor = array('25', '25', '25');
  371. // set style for QR-code
  372. $styleQr = array(
  373. 'border' => false,
  374. 'padding' => 0,
  375. 'fgcolor' => $qrcodecolor,
  376. 'bgcolor' => false, //array(255,255,255)
  377. 'module_width' => 1, // width of a single module in points
  378. 'module_height' => 1 // height of a single module in points
  379. );
  380. $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
  381. $extra_under_address_shift += 25;
  382. }
  383. // Call hook printUnderHeaderPDFline
  384. $parameters = array(
  385. 'object' => $object,
  386. 'i' => $i,
  387. 'pdf' =>& $pdf,
  388. 'outputlangs' => $outputlangs,
  389. 'hidedetails' => $hidedetails
  390. );
  391. $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
  392. if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
  393. $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
  394. }
  395. $tab_top += $extra_under_address_shift;
  396. $tab_top_newpage += 0;
  397. // Define heigth of table for lines (for first page)
  398. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  399. $nexY = $tab_top - 1;
  400. // Incoterm
  401. $height_incoterms = 0;
  402. if (!empty($conf->incoterm->enabled)) {
  403. $desc_incoterms = $object->getIncotermsForPDF();
  404. if ($desc_incoterms) {
  405. $tab_top -= 2;
  406. $pdf->SetFont('', '', $default_font_size - 1);
  407. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  408. $nexY = max($pdf->GetY(), $nexY);
  409. $height_incoterms = $nexY - $tab_top;
  410. // Rect takes a length in 3rd parameter
  411. $pdf->SetDrawColor(192, 192, 192);
  412. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  413. $tab_top = $nexY + 6;
  414. $height_incoterms += 4;
  415. }
  416. }
  417. // Displays notes. Here we are still on code eecuted only for the first page.
  418. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  419. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  420. // Get first sale rep
  421. if (is_object($object->thirdparty)) {
  422. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  423. $salerepobj = new User($this->db);
  424. $salerepobj->fetch($salereparray[0]['id']);
  425. if (!empty($salerepobj->signature)) {
  426. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  427. }
  428. }
  429. }
  430. // Extrafields in note
  431. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  432. if (!empty($extranote)) {
  433. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  434. }
  435. $pagenb = $pdf->getPage();
  436. if ($notetoshow) {
  437. $tab_top -= 2;
  438. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  439. $pageposbeforenote = $pagenb;
  440. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  441. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  442. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  443. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  444. $pdf->startTransaction();
  445. $pdf->SetFont('', '', $default_font_size - 1);
  446. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  447. // Description
  448. $pageposafternote = $pdf->getPage();
  449. $posyafter = $pdf->GetY();
  450. if ($pageposafternote > $pageposbeforenote) {
  451. $pdf->rollbackTransaction(true);
  452. // prepare pages to receive notes
  453. while ($pagenb < $pageposafternote) {
  454. $pdf->AddPage();
  455. $pagenb++;
  456. if (!empty($tplidx)) {
  457. $pdf->useTemplate($tplidx);
  458. }
  459. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  460. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  461. }
  462. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  463. $pdf->setTopMargin($tab_top_newpage);
  464. // The only function to edit the bottom margin of current page to set it.
  465. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  466. }
  467. // back to start
  468. $pdf->setPage($pageposbeforenote);
  469. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  470. $pdf->SetFont('', '', $default_font_size - 1);
  471. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  472. $pageposafternote = $pdf->getPage();
  473. $posyafter = $pdf->GetY();
  474. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  475. $pdf->AddPage('', '', true);
  476. $pagenb++;
  477. $pageposafternote++;
  478. $pdf->setPage($pageposafternote);
  479. $pdf->setTopMargin($tab_top_newpage);
  480. // The only function to edit the bottom margin of current page to set it.
  481. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  482. //$posyafter = $tab_top_newpage;
  483. }
  484. // apply note frame to previous pages
  485. $i = $pageposbeforenote;
  486. while ($i < $pageposafternote) {
  487. $pdf->setPage($i);
  488. $pdf->SetDrawColor(128, 128, 128);
  489. // Draw note frame
  490. if ($i > $pageposbeforenote) {
  491. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  492. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  493. } else {
  494. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  495. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  496. }
  497. // Add footer
  498. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  499. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  500. $i++;
  501. }
  502. // apply note frame to last page
  503. $pdf->setPage($pageposafternote);
  504. if (!empty($tplidx)) {
  505. $pdf->useTemplate($tplidx);
  506. }
  507. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  508. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  509. }
  510. $height_note = $posyafter - $tab_top_newpage;
  511. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  512. } else {
  513. // No pagebreak
  514. $pdf->commitTransaction();
  515. $posyafter = $pdf->GetY();
  516. $height_note = $posyafter - $tab_top;
  517. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  518. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  519. // not enough space, need to add page
  520. $pdf->AddPage('', '', true);
  521. $pagenb++;
  522. $pageposafternote++;
  523. $pdf->setPage($pageposafternote);
  524. if (!empty($tplidx)) {
  525. $pdf->useTemplate($tplidx);
  526. }
  527. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  528. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  529. }
  530. $posyafter = $tab_top_newpage;
  531. }
  532. }
  533. $tab_height = $tab_height - $height_note;
  534. $tab_top = $posyafter + 6;
  535. } else {
  536. $height_note = 0;
  537. }
  538. // Use new auto column system
  539. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  540. // Table simulation to know the height of the title line (this set this->tableTitleHeight)
  541. $pdf->startTransaction();
  542. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  543. $pdf->rollbackTransaction(true);
  544. $nexY = $tab_top + $this->tabTitleHeight;
  545. // Loop on each lines
  546. $pageposbeforeprintlines = $pdf->getPage();
  547. $pagenb = $pageposbeforeprintlines;
  548. for ($i = 0; $i < $nblines; $i++) {
  549. $curY = $nexY;
  550. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  551. $pdf->SetTextColor(0, 0, 0);
  552. // Define size of image if we need it
  553. $imglinesize = array();
  554. if (!empty($realpatharray[$i])) {
  555. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  556. }
  557. $pdf->setTopMargin($tab_top_newpage);
  558. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  559. $pageposbefore = $pdf->getPage();
  560. $showpricebeforepagebreak = 1;
  561. $posYAfterImage = 0;
  562. $posYAfterDescription = 0;
  563. if ($this->getColumnStatus('photo')) {
  564. // We start with Photo of product line
  565. 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
  566. $pdf->AddPage('', '', true);
  567. if (!empty($tplidx)) {
  568. $pdf->useTemplate($tplidx);
  569. }
  570. $pdf->setPage($pageposbefore + 1);
  571. $curY = $tab_top_newpage;
  572. // Allows data in the first page if description is long enough to break in multiples pages
  573. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  574. $showpricebeforepagebreak = 1;
  575. } else {
  576. $showpricebeforepagebreak = 0;
  577. }
  578. }
  579. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
  580. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  581. // $pdf->Image does not increase value return by getY, so we save it manually
  582. $posYAfterImage = $curY + $imglinesize['height'];
  583. }
  584. }
  585. // Description of product line
  586. if ($this->getColumnStatus('desc')) {
  587. $pdf->startTransaction();
  588. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  589. $pageposafter = $pdf->getPage();
  590. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  591. $pdf->rollbackTransaction(true);
  592. $pageposafter = $pageposbefore;
  593. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  594. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  595. $pageposafter = $pdf->getPage();
  596. $posyafter = $pdf->GetY();
  597. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  598. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  599. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  600. $pdf->AddPage('', '', true);
  601. if (!empty($tplidx)) {
  602. $pdf->useTemplate($tplidx);
  603. }
  604. $pdf->setPage($pageposafter + 1);
  605. }
  606. } else {
  607. // We found a page break
  608. // Allows data in the first page if description is long enough to break in multiples pages
  609. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  610. $showpricebeforepagebreak = 1;
  611. } else {
  612. $showpricebeforepagebreak = 0;
  613. }
  614. }
  615. } else // No pagebreak
  616. {
  617. $pdf->commitTransaction();
  618. }
  619. $posYAfterDescription = $pdf->GetY();
  620. }
  621. $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
  622. $pageposafter = $pdf->getPage();
  623. $pdf->setPage($pageposbefore);
  624. $pdf->setTopMargin($this->marge_haute);
  625. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  626. // We suppose that a too long description or photo were moved completely on next page
  627. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  628. $pdf->setPage($pageposafter);
  629. $curY = $tab_top_newpage;
  630. }
  631. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  632. // VAT Rate
  633. if ($this->getColumnStatus('vat')) {
  634. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  635. $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
  636. $nexY = max($pdf->GetY(), $nexY);
  637. }
  638. // Unit price before discount
  639. if ($this->getColumnStatus('subprice')) {
  640. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  641. $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
  642. $nexY = max($pdf->GetY(), $nexY);
  643. }
  644. // Quantity
  645. // Enough for 6 chars
  646. if ($this->getColumnStatus('qty')) {
  647. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  648. $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
  649. $nexY = max($pdf->GetY(), $nexY);
  650. }
  651. // Situation progress
  652. if ($this->getColumnStatus('progress')) {
  653. $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
  654. $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
  655. $nexY = max($pdf->GetY(), $nexY);
  656. }
  657. // Unit
  658. if ($this->getColumnStatus('unit')) {
  659. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  660. $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
  661. $nexY = max($pdf->GetY(), $nexY);
  662. }
  663. // Discount on line
  664. if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
  665. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  666. $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
  667. $nexY = max($pdf->GetY(), $nexY);
  668. }
  669. // Total excl tax line (HT)
  670. if ($this->getColumnStatus('totalexcltax')) {
  671. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  672. $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
  673. $nexY = max($pdf->GetY(), $nexY);
  674. }
  675. // Total with tax line (TTC)
  676. if ($this->getColumnStatus('totalincltax')) {
  677. $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
  678. $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
  679. $nexY = max($pdf->GetY(), $nexY);
  680. }
  681. // Extrafields
  682. if (!empty($object->lines[$i]->array_options)) {
  683. foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
  684. if ($this->getColumnStatus($extrafieldColKey)) {
  685. $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
  686. $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
  687. $nexY = max($pdf->GetY(), $nexY);
  688. }
  689. }
  690. }
  691. $parameters = array(
  692. 'object' => $object,
  693. 'i' => $i,
  694. 'pdf' =>& $pdf,
  695. 'curY' =>& $curY,
  696. 'nexY' =>& $nexY,
  697. 'outputlangs' => $outputlangs,
  698. 'hidedetails' => $hidedetails
  699. );
  700. $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
  701. $sign = 1;
  702. if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  703. $sign = -1;
  704. }
  705. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  706. $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
  707. if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
  708. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  709. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  710. } else {
  711. $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  712. }
  713. } else {
  714. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  715. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
  716. } else {
  717. $tvaligne = $sign * $object->lines[$i]->total_tva;
  718. }
  719. }
  720. $localtax1ligne = $object->lines[$i]->total_localtax1;
  721. $localtax2ligne = $object->lines[$i]->total_localtax2;
  722. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  723. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  724. $localtax1_type = $object->lines[$i]->localtax1_type;
  725. $localtax2_type = $object->lines[$i]->localtax2_type;
  726. if ($object->remise_percent) {
  727. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  728. }
  729. if ($object->remise_percent) {
  730. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  731. }
  732. if ($object->remise_percent) {
  733. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  734. }
  735. $vatrate = (string) $object->lines[$i]->tva_tx;
  736. // Retrieve type from database for backward compatibility with old records
  737. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  738. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  739. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  740. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  741. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  742. }
  743. // retrieve global local tax
  744. if ($localtax1_type && $localtax1ligne != 0) {
  745. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  746. }
  747. if ($localtax2_type && $localtax2ligne != 0) {
  748. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  749. }
  750. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  751. $vatrate .= '*';
  752. }
  753. // Fill $this->tva and $this->tva_array
  754. if (!isset($this->tva[$vatrate])) {
  755. $this->tva[$vatrate] = 0;
  756. }
  757. $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
  758. $vatcode = $object->lines[$i]->vat_src_code;
  759. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  760. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  761. }
  762. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  763. $nexY = max($nexY, $posYAfterImage);
  764. // Add line
  765. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  766. $pdf->setPage($pageposafter);
  767. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  768. //$pdf->SetDrawColor(190,190,200);
  769. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
  770. $pdf->SetLineStyle(array('dash'=>0));
  771. }
  772. // Detect if some page were added automatically and output _tableau for past pages
  773. while ($pagenb < $pageposafter) {
  774. $pdf->setPage($pagenb);
  775. if ($pagenb == $pageposbeforeprintlines) {
  776. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  777. } else {
  778. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  779. }
  780. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  781. $pagenb++;
  782. $pdf->setPage($pagenb);
  783. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  784. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  785. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  786. }
  787. }
  788. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  789. if ($pagenb == $pageposafter) {
  790. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  791. } else {
  792. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  793. }
  794. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  795. // New page
  796. $pdf->AddPage();
  797. if (!empty($tplidx)) {
  798. $pdf->useTemplate($tplidx);
  799. }
  800. $pagenb++;
  801. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  802. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  803. }
  804. }
  805. }
  806. // Show square
  807. if ($pagenb == $pageposbeforeprintlines) {
  808. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
  809. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  810. } else {
  811. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
  812. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  813. }
  814. // Display infos area
  815. $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
  816. // Display total zone
  817. $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
  818. // Display payment area
  819. if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  820. $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
  821. }
  822. // Pagefoot
  823. $this->_pagefoot($pdf, $object, $outputlangs);
  824. if (method_exists($pdf, 'AliasNbPages')) {
  825. $pdf->AliasNbPages();
  826. }
  827. $pdf->Close();
  828. $pdf->Output($file, 'F');
  829. // Add pdfgeneration hook
  830. $hookmanager->initHooks(array('pdfgeneration'));
  831. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  832. global $action;
  833. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  834. if ($reshook < 0) {
  835. $this->error = $hookmanager->error;
  836. $this->errors = $hookmanager->errors;
  837. }
  838. if (!empty($conf->global->MAIN_UMASK)) {
  839. @chmod($file, octdec($conf->global->MAIN_UMASK));
  840. }
  841. $this->result = array('fullpath'=>$file);
  842. return 1; // No error
  843. } else {
  844. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  845. return 0;
  846. }
  847. } else {
  848. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
  849. return 0;
  850. }
  851. }
  852. /**
  853. * Show payments table
  854. *
  855. * @param TCPDF $pdf Object PDF
  856. * @param Facture $object Object invoice
  857. * @param int $posy Position y in PDF
  858. * @param Translate $outputlangs Object langs for output
  859. * @return int <0 if KO, >0 if OK
  860. */
  861. public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
  862. {
  863. global $conf;
  864. $sign = 1;
  865. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  866. $sign = -1;
  867. }
  868. $tab3_posx = 120;
  869. $tab3_top = $posy + 8;
  870. $tab3_width = 80;
  871. $tab3_height = 4;
  872. if ($this->page_largeur < 210) { // To work with US executive format
  873. $tab3_posx -= 15;
  874. }
  875. $default_font_size = pdf_getPDFFontSize($outputlangs);
  876. $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
  877. if ($object->type == 2) {
  878. $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
  879. }
  880. $pdf->SetFont('', '', $default_font_size - 3);
  881. $pdf->SetXY($tab3_posx, $tab3_top - 4);
  882. $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
  883. $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
  884. $pdf->SetFont('', '', $default_font_size - 4);
  885. $pdf->SetXY($tab3_posx, $tab3_top);
  886. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  887. $pdf->SetXY($tab3_posx + 21, $tab3_top);
  888. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  889. $pdf->SetXY($tab3_posx + 40, $tab3_top);
  890. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  891. $pdf->SetXY($tab3_posx + 58, $tab3_top);
  892. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  893. $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
  894. $y = 0;
  895. $pdf->SetFont('', '', $default_font_size - 4);
  896. // Loop on each discount available (deposits and credit notes and excess of payment included)
  897. $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,";
  898. $sql .= " re.description, re.fk_facture_source,";
  899. $sql .= " f.type, f.datef";
  900. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
  901. $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
  902. $resql = $this->db->query($sql);
  903. if ($resql) {
  904. $num = $this->db->num_rows($resql);
  905. $i = 0;
  906. $invoice = new Facture($this->db);
  907. while ($i < $num) {
  908. $y += 3;
  909. $obj = $this->db->fetch_object($resql);
  910. if ($obj->type == 2) {
  911. $text = $outputlangs->transnoentities("CreditNote");
  912. } elseif ($obj->type == 3) {
  913. $text = $outputlangs->transnoentities("Deposit");
  914. } elseif ($obj->type == 0) {
  915. $text = $outputlangs->transnoentities("ExcessReceived");
  916. } else {
  917. $text = $outputlangs->transnoentities("UnknownType");
  918. }
  919. $invoice->fetch($obj->fk_facture_source);
  920. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  921. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
  922. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  923. $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);
  924. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  925. $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
  926. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  927. $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
  928. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  929. $i++;
  930. }
  931. } else {
  932. $this->error = $this->db->lasterror();
  933. return -1;
  934. }
  935. // Loop on each payment
  936. // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
  937. $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
  938. $sql .= " cp.code";
  939. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  940. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  941. $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
  942. //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
  943. $sql .= " ORDER BY p.datep";
  944. $resql = $this->db->query($sql);
  945. if ($resql) {
  946. $num = $this->db->num_rows($resql);
  947. $i = 0;
  948. while ($i < $num) {
  949. $y += 3;
  950. $row = $this->db->fetch_object($resql);
  951. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  952. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
  953. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  954. $pdf->MultiCell(20, 3, price($sign * ((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
  955. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  956. $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  957. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  958. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  959. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  960. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  961. $i++;
  962. }
  963. return $tab3_top + $y + 3;
  964. } else {
  965. $this->error = $this->db->lasterror();
  966. return -1;
  967. }
  968. }
  969. /**
  970. * Show miscellaneous information (payment mode, payment term, ...)
  971. *
  972. * @param TCPDF $pdf Object PDF
  973. * @param Facture $object Object to show
  974. * @param int $posy Y
  975. * @param Translate $outputlangs Langs object
  976. * @param Translate $outputlangsbis Object lang for output bis
  977. * @return int Pos y
  978. */
  979. protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
  980. {
  981. global $conf, $mysoc;
  982. $default_font_size = pdf_getPDFFontSize($outputlangs);
  983. $pdf->SetFont('', '', $default_font_size - 1);
  984. // If France, show VAT mention if not applicable
  985. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  986. $pdf->SetFont('', 'B', $default_font_size - 2);
  987. $pdf->SetXY($this->marge_gauche, $posy);
  988. if ($mysoc->forme_juridique_code == 92) {
  989. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
  990. } else {
  991. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  992. }
  993. $posy = $pdf->GetY() + 4;
  994. }
  995. $posxval = 52; // Position of values of properties shown on left side
  996. $posxend = 110; // End of x for text on left side
  997. if ($this->page_largeur < 210) { // To work with US executive format
  998. $posxend -= 10;
  999. }
  1000. // Show payments conditions
  1001. if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
  1002. $pdf->SetFont('', 'B', $default_font_size - 2);
  1003. $pdf->SetXY($this->marge_gauche, $posy);
  1004. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  1005. $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
  1006. $pdf->SetFont('', '', $default_font_size - 2);
  1007. $pdf->SetXY($posxval, $posy);
  1008. $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);
  1009. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  1010. $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
  1011. $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
  1012. }
  1013. if ($object->type != 2) {
  1014. // Check a payment mode is defined
  1015. if (empty($object->mode_reglement_code)
  1016. && empty($conf->global->FACTURE_CHQ_NUMBER)
  1017. && empty($conf->global->FACTURE_RIB_NUMBER)) {
  1018. $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
  1019. } elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
  1020. || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) {
  1021. // Avoid having any valid PDF with setup that is not complete
  1022. $outputlangs->load("errors");
  1023. $pdf->SetXY($this->marge_gauche, $posy);
  1024. $pdf->SetTextColor(200, 0, 0);
  1025. $pdf->SetFont('', 'B', $default_font_size - 2);
  1026. $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
  1027. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
  1028. $pdf->SetTextColor(0, 0, 0);
  1029. $posy = $pdf->GetY() + 1;
  1030. }
  1031. // Show payment mode
  1032. if (!empty($object->mode_reglement_code)
  1033. && $object->mode_reglement_code != 'CHQ'
  1034. && $object->mode_reglement_code != 'VIR') {
  1035. $pdf->SetFont('', 'B', $default_font_size - 2);
  1036. $pdf->SetXY($this->marge_gauche, $posy);
  1037. $titre = $outputlangs->transnoentities("PaymentMode").':';
  1038. $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
  1039. $pdf->SetFont('', '', $default_font_size - 2);
  1040. $pdf->SetXY($posxval, $posy);
  1041. $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);
  1042. $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
  1043. $posy = $pdf->GetY();
  1044. }
  1045. // Show online payment link
  1046. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
  1047. $useonlinepayment = 0;
  1048. if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
  1049. if (!empty($conf->paypal->enabled)) {
  1050. $useonlinepayment++;
  1051. }
  1052. if (!empty($conf->stripe->enabled)) {
  1053. $useonlinepayment++;
  1054. }
  1055. if (!empty($conf->paybox->enabled)) {
  1056. $useonlinepayment++;
  1057. }
  1058. }
  1059. if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
  1060. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  1061. global $langs;
  1062. $langs->loadLangs(array('payment', 'paybox'));
  1063. $servicename = $langs->transnoentities('Online');
  1064. $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
  1065. $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
  1066. $pdf->SetXY($this->marge_gauche, $posy);
  1067. $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
  1068. $posy = $pdf->GetY() + 1;
  1069. }
  1070. }
  1071. // Show payment mode CHQ
  1072. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  1073. // If payment mode unregulated or payment mode forced to CHQ
  1074. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  1075. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  1076. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  1077. $account = new Account($this->db);
  1078. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  1079. $pdf->SetXY($this->marge_gauche, $posy);
  1080. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1081. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  1082. $posy = $pdf->GetY() + 1;
  1083. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1084. $pdf->SetXY($this->marge_gauche, $posy);
  1085. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1086. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  1087. $posy = $pdf->GetY() + 2;
  1088. }
  1089. }
  1090. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  1091. $pdf->SetXY($this->marge_gauche, $posy);
  1092. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1093. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  1094. $posy = $pdf->GetY() + 1;
  1095. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1096. $pdf->SetXY($this->marge_gauche, $posy);
  1097. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1098. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  1099. $posy = $pdf->GetY() + 2;
  1100. }
  1101. }
  1102. }
  1103. }
  1104. // If payment mode not forced or forced to VIR, show payment with BAN
  1105. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  1106. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  1107. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  1108. if ($object->fk_bank > 0) {
  1109. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  1110. }
  1111. $account = new Account($this->db);
  1112. $account->fetch($bankid);
  1113. $curx = $this->marge_gauche;
  1114. $cury = $posy;
  1115. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  1116. $posy += 2;
  1117. }
  1118. }
  1119. }
  1120. return $posy;
  1121. }
  1122. /**
  1123. * Show total to pay
  1124. *
  1125. * @param TCPDF $pdf Object PDF
  1126. * @param Facture $object Object invoice
  1127. * @param int $deja_regle Amount already paid (in the currency of invoice)
  1128. * @param int $posy Position depart
  1129. * @param Translate $outputlangs Objet langs
  1130. * @param Translate $outputlangsbis Object lang for output bis
  1131. * @return int Position pour suite
  1132. */
  1133. protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
  1134. {
  1135. global $conf, $mysoc, $hookmanager;
  1136. $sign = 1;
  1137. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  1138. $sign = -1;
  1139. }
  1140. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1141. $tab2_top = $posy;
  1142. $tab2_hl = 4;
  1143. if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
  1144. $pdf->SetFont('', '', $default_font_size - 2);
  1145. } else {
  1146. $pdf->SetFont('', '', $default_font_size - 1);
  1147. }
  1148. // Total table
  1149. $col1x = 120;
  1150. $col2x = 170;
  1151. if ($this->page_largeur < 210) { // To work with US executive format
  1152. $col1x -= 15;
  1153. $col2x -= 10;
  1154. }
  1155. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  1156. $useborder = 0;
  1157. $index = 0;
  1158. // Add trigger to allow to edit $object
  1159. $parameters = array(
  1160. 'object' => &$object,
  1161. 'outputlangs' => $outputlangs,
  1162. );
  1163. $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
  1164. // overall percentage of advancement
  1165. $percent = 0;
  1166. $i = 0;
  1167. foreach ($object->lines as $line) {
  1168. $percent += $line->situation_percent;
  1169. $i++;
  1170. }
  1171. if (!empty($i)) {
  1172. $avancementGlobal = $percent / $i;
  1173. } else {
  1174. $avancementGlobal = 0;
  1175. }
  1176. $object->fetchPreviousNextSituationInvoice();
  1177. $TPreviousIncoice = $object->tab_previous_situation_invoice;
  1178. $total_a_payer = 0;
  1179. $total_a_payer_ttc = 0;
  1180. foreach ($TPreviousIncoice as &$fac) {
  1181. $total_a_payer += $fac->total_ht;
  1182. $total_a_payer_ttc += $fac->total_ttc;
  1183. }
  1184. $total_a_payer += $object->total_ht;
  1185. $total_a_payer_ttc += $object->total_ttc;
  1186. if (!empty($avancementGlobal)) {
  1187. $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
  1188. $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
  1189. } else {
  1190. $total_a_payer = 0;
  1191. $total_a_payer_ttc = 0;
  1192. }
  1193. $i = 1;
  1194. if (!empty($TPreviousIncoice)) {
  1195. $pdf->setY($tab2_top);
  1196. $posy = $pdf->GetY();
  1197. foreach ($TPreviousIncoice as &$fac) {
  1198. if ($posy > $this->page_hauteur - 4) {
  1199. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  1200. $pdf->addPage();
  1201. $pdf->setY($this->marge_haute);
  1202. $posy = $pdf->GetY();
  1203. }
  1204. // Cumulate preceding VAT
  1205. $index++;
  1206. $pdf->SetFillColor(255, 255, 255);
  1207. $pdf->SetXY($col1x, $posy);
  1208. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  1209. $pdf->SetXY($col2x, $posy);
  1210. $facSign = '';
  1211. if ($i > 1) {
  1212. $facSign = $fac->total_ht >= 0 ? '+' : '';
  1213. }
  1214. $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
  1215. $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
  1216. $i++;
  1217. $posy += $tab2_hl;
  1218. $pdf->setY($posy);
  1219. }
  1220. // Display current total
  1221. $pdf->SetFillColor(255, 255, 255);
  1222. $pdf->SetXY($col1x, $posy);
  1223. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  1224. $pdf->SetXY($col2x, $posy);
  1225. $facSign = '';
  1226. if ($i > 1) {
  1227. $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
  1228. }
  1229. if ($fac->type === facture::TYPE_CREDIT_NOTE) {
  1230. $facSign = '-'; // les avoirs
  1231. }
  1232. $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
  1233. $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
  1234. $posy += $tab2_hl;
  1235. // Display all total
  1236. $pdf->SetFont('', '', $default_font_size - 1);
  1237. $pdf->SetFillColor(255, 255, 255);
  1238. $pdf->SetXY($col1x, $posy);
  1239. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
  1240. $pdf->SetXY($col2x, $posy);
  1241. $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
  1242. $pdf->SetFont('', '', $default_font_size - 2);
  1243. $posy += $tab2_hl;
  1244. if ($posy > $this->page_hauteur - 4) {
  1245. $pdf->addPage();
  1246. $pdf->setY($this->marge_haute);
  1247. $posy = $pdf->GetY();
  1248. }
  1249. $tab2_top = $posy;
  1250. $index = 0;
  1251. $tab2_top += 3;
  1252. }
  1253. // Get Total HT
  1254. $total_ht = (!empty($conf->multicurrency->enabled) && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
  1255. // Total remise
  1256. $total_line_remise = 0;
  1257. foreach ($object->lines as $i => $line) {
  1258. $total_line_remise += pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); // TODO: add this method to core/lib/pdf.lib
  1259. // Gestion remise sous forme de ligne négative
  1260. if ($line->total_ht < 0) {
  1261. $total_line_remise += -$line->total_ht;
  1262. }
  1263. }
  1264. if ($total_line_remise > 0) {
  1265. if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
  1266. $pdf->SetFillColor(255, 255, 255);
  1267. $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
  1268. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
  1269. $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
  1270. $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1);
  1271. $index++;
  1272. }
  1273. // Show total NET before discount
  1274. if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
  1275. $pdf->SetFillColor(255, 255, 255);
  1276. $pdf->SetXY($col1x, $tab2_top + 0);
  1277. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
  1278. $pdf->SetXY($col2x, $tab2_top + 0);
  1279. $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1);
  1280. $index++;
  1281. }
  1282. }
  1283. // Total HT
  1284. $pdf->SetFillColor(255, 255, 255);
  1285. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1286. $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);
  1287. $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  1288. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1289. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
  1290. // Show VAT by rates and total
  1291. $pdf->SetFillColor(248, 248, 248);
  1292. $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  1293. $this->atleastoneratenotnull = 0;
  1294. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  1295. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  1296. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  1297. // Nothing to do
  1298. } else {
  1299. // FIXME amount of vat not supported with multicurrency
  1300. //Local tax 1 before VAT
  1301. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1302. //{
  1303. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1304. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1305. continue;
  1306. }
  1307. foreach ($localtax_rate as $tvakey => $tvaval) {
  1308. if ($tvakey != 0) { // On affiche pas taux 0
  1309. //$this->atleastoneratenotnull++;
  1310. $index++;
  1311. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1312. $tvacompl = '';
  1313. if (preg_match('/\*/', $tvakey)) {
  1314. $tvakey = str_replace('*', '', $tvakey);
  1315. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1316. }
  1317. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1318. $totalvat .= ' ';
  1319. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1320. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1321. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1322. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1323. }
  1324. }
  1325. }
  1326. //}
  1327. //Local tax 2 before VAT
  1328. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1329. //{
  1330. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1331. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1332. continue;
  1333. }
  1334. foreach ($localtax_rate as $tvakey => $tvaval) {
  1335. if ($tvakey != 0) { // On affiche pas taux 0
  1336. //$this->atleastoneratenotnull++;
  1337. $index++;
  1338. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1339. $tvacompl = '';
  1340. if (preg_match('/\*/', $tvakey)) {
  1341. $tvakey = str_replace('*', '', $tvakey);
  1342. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1343. }
  1344. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1345. $totalvat .= ' ';
  1346. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1347. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1348. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1349. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1350. }
  1351. }
  1352. }
  1353. //}
  1354. // Situations totals migth be wrong on huge amounts with old mode 1
  1355. if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
  1356. $sum_pdf_tva = 0;
  1357. foreach ($this->tva as $tvakey => $tvaval) {
  1358. $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
  1359. }
  1360. if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
  1361. if (!empty($sum_pdf_tva)) {
  1362. $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
  1363. } else {
  1364. $coef_fix_tva = 1;
  1365. }
  1366. foreach ($this->tva as $tvakey => $tvaval) {
  1367. $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
  1368. }
  1369. foreach ($this->tva_array as $tvakey => $tvaval) {
  1370. $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
  1371. }
  1372. }
  1373. }
  1374. // VAT
  1375. foreach ($this->tva_array as $tvakey => $tvaval) {
  1376. if ($tvakey != 0) { // On affiche pas taux 0
  1377. $this->atleastoneratenotnull++;
  1378. $index++;
  1379. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1380. $tvacompl = '';
  1381. if (preg_match('/\*/', $tvakey)) {
  1382. $tvakey = str_replace('*', '', $tvakey);
  1383. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1384. }
  1385. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1386. $totalvat .= ' ';
  1387. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  1388. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  1389. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  1390. $totalvat .= ($tvaval['vatcode'] ? $tvaval['vatcode'] : vatrate($tvaval['vatrate'], 1)).$tvacompl;
  1391. } else {
  1392. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  1393. }
  1394. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1395. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1396. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  1397. }
  1398. }
  1399. //Local tax 1 after VAT
  1400. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1401. //{
  1402. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1403. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1404. continue;
  1405. }
  1406. foreach ($localtax_rate as $tvakey => $tvaval) {
  1407. if ($tvakey != 0) { // On affiche pas taux 0
  1408. //$this->atleastoneratenotnull++;
  1409. $index++;
  1410. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1411. $tvacompl = '';
  1412. if (preg_match('/\*/', $tvakey)) {
  1413. $tvakey = str_replace('*', '', $tvakey);
  1414. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1415. }
  1416. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1417. $totalvat .= ' ';
  1418. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1419. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1420. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1421. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1422. }
  1423. }
  1424. }
  1425. //}
  1426. //Local tax 2 after VAT
  1427. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1428. //{
  1429. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1430. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1431. continue;
  1432. }
  1433. foreach ($localtax_rate as $tvakey => $tvaval) {
  1434. // retrieve global local tax
  1435. if ($tvakey != 0) { // On affiche pas taux 0
  1436. //$this->atleastoneratenotnull++;
  1437. $index++;
  1438. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1439. $tvacompl = '';
  1440. if (preg_match('/\*/', $tvakey)) {
  1441. $tvakey = str_replace('*', '', $tvakey);
  1442. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1443. }
  1444. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1445. $totalvat .= ' ';
  1446. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1447. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1448. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1449. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1450. }
  1451. }
  1452. }
  1453. // Revenue stamp
  1454. if (price2num($object->revenuestamp) != 0) {
  1455. $index++;
  1456. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1457. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
  1458. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1459. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
  1460. }
  1461. // Total TTC
  1462. $index++;
  1463. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1464. $pdf->SetTextColor(0, 0, 60);
  1465. $pdf->SetFillColor(224, 224, 224);
  1466. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
  1467. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1468. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1469. // Retained warranty
  1470. if ($object->displayRetainedWarranty()) {
  1471. $pdf->SetTextColor(40, 40, 40);
  1472. $pdf->SetFillColor(255, 255, 255);
  1473. $retainedWarranty = $object->getRetainedWarrantyAmount();
  1474. $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
  1475. // Billed - retained warranty
  1476. $index++;
  1477. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1478. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
  1479. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1480. $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
  1481. // retained warranty
  1482. $index++;
  1483. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1484. $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
  1485. $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
  1486. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
  1487. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1488. $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
  1489. }
  1490. }
  1491. }
  1492. $pdf->SetTextColor(0, 0, 0);
  1493. $creditnoteamount = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
  1494. $depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
  1495. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  1496. if (!empty($object->paye)) {
  1497. $resteapayer = 0;
  1498. }
  1499. if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  1500. // Already paid + Deposits
  1501. $index++;
  1502. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1503. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
  1504. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1505. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
  1506. // Credit note
  1507. if ($creditnoteamount) {
  1508. $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
  1509. $labeltouse .= (is_object($outputlangsbis) ? ' / '.($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes") : '');
  1510. $index++;
  1511. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1512. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
  1513. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1514. $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
  1515. }
  1516. /*
  1517. if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
  1518. {
  1519. $index++;
  1520. $pdf->SetFillColor(255, 255, 255);
  1521. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1522. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
  1523. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1524. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
  1525. $resteapayer = 0;
  1526. }
  1527. */
  1528. $index++;
  1529. $pdf->SetTextColor(0, 0, 60);
  1530. $pdf->SetFillColor(224, 224, 224);
  1531. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1532. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
  1533. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1534. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1535. $pdf->SetFont('', '', $default_font_size - 1);
  1536. $pdf->SetTextColor(0, 0, 0);
  1537. }
  1538. $index++;
  1539. return ($tab2_top + ($tab2_hl * $index));
  1540. }
  1541. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1542. /**
  1543. * Return list of active generation modules
  1544. *
  1545. * @param DoliDB $db Database handler
  1546. * @param integer $maxfilenamelength Max length of value to show
  1547. * @return array List of templates
  1548. */
  1549. public static function liste_modeles($db, $maxfilenamelength = 0)
  1550. {
  1551. // phpcs:enable
  1552. return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
  1553. }
  1554. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1555. /**
  1556. * Show table for lines
  1557. *
  1558. * @param TCPDF $pdf Object PDF
  1559. * @param string $tab_top Top position of table
  1560. * @param string $tab_height Height of table (rectangle)
  1561. * @param int $nexY Y (not used)
  1562. * @param Translate $outputlangs Langs object
  1563. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1564. * @param int $hidebottom Hide bottom bar of array
  1565. * @param string $currency Currency code
  1566. * @param Translate $outputlangsbis Langs object bis
  1567. * @return void
  1568. */
  1569. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1570. {
  1571. global $conf;
  1572. // Force to disable hidetop and hidebottom
  1573. $hidebottom = 0;
  1574. if ($hidetop) {
  1575. $hidetop = -1;
  1576. }
  1577. $currency = !empty($currency) ? $currency : $conf->currency;
  1578. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1579. // Amount in (at tab_top - 1)
  1580. $pdf->SetTextColor(0, 0, 0);
  1581. $pdf->SetFont('', '', $default_font_size - 2);
  1582. if (empty($hidetop)) {
  1583. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1584. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1585. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1586. }
  1587. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1588. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1589. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1590. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1591. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  1592. }
  1593. }
  1594. $pdf->SetDrawColor(128, 128, 128);
  1595. $pdf->SetFont('', '', $default_font_size - 1);
  1596. // Output Rect
  1597. $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
  1598. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  1599. if (empty($hidetop)) {
  1600. $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
  1601. }
  1602. }
  1603. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1604. /**
  1605. * Show top header of page. This include the logo, ref and address blocs
  1606. *
  1607. * @param TCPDF $pdf Object PDF
  1608. * @param Facture $object Object to show
  1609. * @param int $showaddress 0=no, 1=yes (usually set to 1 for first page, and 0 for next pages)
  1610. * @param Translate $outputlangs Object lang for output
  1611. * @param Translate $outputlangsbis Object lang for output bis
  1612. * @return int top shift of linked object lines
  1613. */
  1614. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
  1615. {
  1616. global $conf, $langs;
  1617. $ltrdirection = 'L';
  1618. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1619. // Load traductions files required by page
  1620. $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
  1621. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1622. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1623. $pdf->SetTextColor(0, 0, 60);
  1624. $pdf->SetFont('', 'B', $default_font_size + 3);
  1625. $w = 110;
  1626. $posy = $this->marge_haute;
  1627. $posx = $this->page_largeur - $this->marge_droite - $w;
  1628. $pdf->SetXY($this->marge_gauche, $posy);
  1629. // Logo
  1630. if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
  1631. if ($this->emetteur->logo) {
  1632. $logodir = $conf->mycompany->dir_output;
  1633. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1634. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1635. }
  1636. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  1637. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1638. } else {
  1639. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1640. }
  1641. if (is_readable($logo)) {
  1642. $height = pdf_getHeightForLogo($logo);
  1643. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1644. } else {
  1645. $pdf->SetTextColor(200, 0, 0);
  1646. $pdf->SetFont('', 'B', $default_font_size - 2);
  1647. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1648. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1649. }
  1650. } else {
  1651. $text = $this->emetteur->name;
  1652. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
  1653. }
  1654. }
  1655. $pdf->SetFont('', 'B', $default_font_size + 3);
  1656. $pdf->SetXY($posx, $posy);
  1657. $pdf->SetTextColor(0, 0, 60);
  1658. $title = $outputlangs->transnoentities("PdfInvoiceTitle");
  1659. if ($object->type == 1) {
  1660. $title = $outputlangs->transnoentities("InvoiceReplacement");
  1661. }
  1662. if ($object->type == 2) {
  1663. $title = $outputlangs->transnoentities("InvoiceAvoir");
  1664. }
  1665. if ($object->type == 3) {
  1666. $title = $outputlangs->transnoentities("InvoiceDeposit");
  1667. }
  1668. if ($object->type == 4) {
  1669. $title = $outputlangs->transnoentities("InvoiceProForma");
  1670. }
  1671. if ($this->situationinvoice) {
  1672. $title = $outputlangs->transnoentities("PDFInvoiceSituation");
  1673. }
  1674. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1675. $title .= ' - ';
  1676. if ($object->type == 0) {
  1677. if ($this->situationinvoice) {
  1678. $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
  1679. }
  1680. $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
  1681. } elseif ($object->type == 1) {
  1682. $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
  1683. } elseif ($object->type == 2) {
  1684. $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
  1685. } elseif ($object->type == 3) {
  1686. $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
  1687. } elseif ($object->type == 4) {
  1688. $title .= $outputlangsbis->transnoentities("InvoiceProForma");
  1689. }
  1690. }
  1691. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1692. if ($object->statut == $object::STATUS_DRAFT) {
  1693. $pdf->SetTextColor(128, 0, 0);
  1694. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1695. }
  1696. $pdf->MultiCell($w, 3, $title, '', 'R');
  1697. $pdf->SetFont('', 'B', $default_font_size);
  1698. /*
  1699. $posy += 5;
  1700. $pdf->SetXY($posx, $posy);
  1701. $pdf->SetTextColor(0, 0, 60);
  1702. $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
  1703. if ($object->statut == $object::STATUS_DRAFT) {
  1704. $pdf->SetTextColor(128, 0, 0);
  1705. $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
  1706. }
  1707. $pdf->MultiCell($w, 4, $textref, '', 'R');*/
  1708. $posy += 3;
  1709. $pdf->SetFont('', '', $default_font_size - 2);
  1710. if ($object->ref_client) {
  1711. $posy += 4;
  1712. $pdf->SetXY($posx, $posy);
  1713. $pdf->SetTextColor(0, 0, 60);
  1714. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
  1715. }
  1716. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1717. $object->fetch_projet();
  1718. if (!empty($object->project->ref)) {
  1719. $posy += 3;
  1720. $pdf->SetXY($posx, $posy);
  1721. $pdf->SetTextColor(0, 0, 60);
  1722. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1723. }
  1724. }
  1725. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1726. $object->fetch_projet();
  1727. if (!empty($object->project->ref)) {
  1728. $outputlangs->load("projects");
  1729. $posy += 3;
  1730. $pdf->SetXY($posx, $posy);
  1731. $pdf->SetTextColor(0, 0, 60);
  1732. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1733. }
  1734. }
  1735. $objectidnext = $object->getIdReplacingInvoice('validated');
  1736. if ($object->type == 0 && $objectidnext) {
  1737. $objectreplacing = new Facture($this->db);
  1738. $objectreplacing->fetch($objectidnext);
  1739. $posy += 3;
  1740. $pdf->SetXY($posx, $posy);
  1741. $pdf->SetTextColor(0, 0, 60);
  1742. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
  1743. }
  1744. if ($object->type == 1) {
  1745. $objectreplaced = new Facture($this->db);
  1746. $objectreplaced->fetch($object->fk_facture_source);
  1747. $posy += 4;
  1748. $pdf->SetXY($posx, $posy);
  1749. $pdf->SetTextColor(0, 0, 60);
  1750. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  1751. }
  1752. if ($object->type == 2 && !empty($object->fk_facture_source)) {
  1753. $objectreplaced = new Facture($this->db);
  1754. $objectreplaced->fetch($object->fk_facture_source);
  1755. $posy += 3;
  1756. $pdf->SetXY($posx, $posy);
  1757. $pdf->SetTextColor(0, 0, 60);
  1758. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  1759. }
  1760. $posy += 4;
  1761. $pdf->SetXY($posx, $posy);
  1762. $pdf->SetTextColor(0, 0, 60);
  1763. $title = $outputlangs->transnoentities("DateInvoice");
  1764. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1765. $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
  1766. }
  1767. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
  1768. if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
  1769. $posy += 4;
  1770. $pdf->SetXY($posx, $posy);
  1771. $pdf->SetTextColor(0, 0, 60);
  1772. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
  1773. }
  1774. if ($object->type != 2) {
  1775. $posy += 3;
  1776. $pdf->SetXY($posx, $posy);
  1777. $pdf->SetTextColor(0, 0, 60);
  1778. $title = $outputlangs->transnoentities("DateDue");
  1779. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1780. $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
  1781. }
  1782. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
  1783. }
  1784. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
  1785. $posy += 3;
  1786. $pdf->SetXY($posx, $posy);
  1787. $pdf->SetTextColor(0, 0, 60);
  1788. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1789. }
  1790. // Get contact
  1791. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1792. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1793. if (count($arrayidcontact) > 0) {
  1794. $usertmp = new User($this->db);
  1795. $usertmp->fetch($arrayidcontact[0]);
  1796. $posy += 4;
  1797. $pdf->SetXY($posx, $posy);
  1798. $pdf->SetTextColor(0, 0, 60);
  1799. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1800. }
  1801. }
  1802. $posy += 1;
  1803. $top_shift = 0;
  1804. // Show list of linked objects
  1805. $current_y = $pdf->getY();
  1806. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1807. if ($current_y < $pdf->getY()) {
  1808. $top_shift = $pdf->getY() - $current_y;
  1809. }
  1810. if ($showaddress) {
  1811. // Sender properties
  1812. $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1813. // Show sender
  1814. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1815. $posy += $top_shift;
  1816. $posx = $this->marge_gauche;
  1817. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1818. $posx = $this->page_largeur - $this->marge_droite - 80;
  1819. }
  1820. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  1821. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1822. // Show sender frame
  1823. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1824. $pdf->SetTextColor(0, 0, 0);
  1825. $pdf->SetFont('', '', $default_font_size - 2);
  1826. $pdf->SetXY($posx, $posy - 5);
  1827. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1828. $pdf->SetXY($posx, $posy);
  1829. $pdf->SetFillColor(230, 230, 230);
  1830. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  1831. $pdf->SetTextColor(0, 0, 60);
  1832. }
  1833. // Show sender name
  1834. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1835. $pdf->SetXY($posx + 2, $posy + 3);
  1836. $pdf->SetFont('', 'B', $default_font_size);
  1837. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1838. $posy = $pdf->getY();
  1839. }
  1840. // Show sender information
  1841. $pdf->SetXY($posx + 2, $posy);
  1842. $pdf->SetFont('', '', $default_font_size - 1);
  1843. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
  1844. // If BILLING contact defined on invoice, we use it
  1845. $usecontact = false;
  1846. $arrayidcontact = $object->getIdContact('external', 'BILLING');
  1847. if (count($arrayidcontact) > 0) {
  1848. $usecontact = true;
  1849. $result = $object->fetch_contact($arrayidcontact[0]);
  1850. }
  1851. // Recipient name
  1852. 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)))) {
  1853. $thirdparty = $object->contact;
  1854. } else {
  1855. $thirdparty = $object->thirdparty;
  1856. }
  1857. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1858. $mode = 'target';
  1859. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1860. // Show recipient
  1861. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1862. if ($this->page_largeur < 210) {
  1863. $widthrecbox = 84; // To work with US executive format
  1864. }
  1865. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1866. $posy += $top_shift;
  1867. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1868. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1869. $posx = $this->marge_gauche;
  1870. }
  1871. // Show recipient frame
  1872. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1873. $pdf->SetTextColor(0, 0, 0);
  1874. $pdf->SetFont('', '', $default_font_size - 2);
  1875. $pdf->SetXY($posx + 2, $posy - 5);
  1876. $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1877. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1878. }
  1879. // Show recipient name
  1880. $pdf->SetXY($posx + 2, $posy + 3);
  1881. $pdf->SetFont('', 'B', $default_font_size);
  1882. $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
  1883. $posy = $pdf->getY();
  1884. // Show recipient information
  1885. $pdf->SetFont('', '', $default_font_size - 1);
  1886. $pdf->SetXY($posx + 2, $posy);
  1887. $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
  1888. }
  1889. $pdf->SetTextColor(0, 0, 0);
  1890. return $top_shift;
  1891. }
  1892. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1893. /**
  1894. * Show footer of page. Need this->emetteur object
  1895. *
  1896. * @param TCPDF $pdf PDF
  1897. * @param Facture $object Object to show
  1898. * @param Translate $outputlangs Object lang for output
  1899. * @param int $hidefreetext 1=Hide free text
  1900. * @return int Return height of bottom margin including footer text
  1901. */
  1902. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1903. {
  1904. global $conf;
  1905. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1906. 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);
  1907. }
  1908. /**
  1909. * Define Array Column Field
  1910. *
  1911. * @param Facture $object common object
  1912. * @param Translate $outputlangs langs
  1913. * @param int $hidedetails Do not show line details
  1914. * @param int $hidedesc Do not show desc
  1915. * @param int $hideref Do not show ref
  1916. * @return null
  1917. */
  1918. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1919. {
  1920. global $conf, $hookmanager;
  1921. // Default field style for content
  1922. $this->defaultContentsFieldsStyle = array(
  1923. 'align' => 'R', // R,C,L
  1924. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1925. );
  1926. // Default field style for content
  1927. $this->defaultTitlesFieldsStyle = array(
  1928. 'align' => 'C', // R,C,L
  1929. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1930. );
  1931. /*
  1932. * For exemple
  1933. $this->cols['theColKey'] = array(
  1934. 'rank' => $rank, // int : use for ordering columns
  1935. 'width' => 20, // the column width in mm
  1936. 'title' => array(
  1937. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1938. 'label' => ' ', // the final label : used fore final generated text
  1939. 'align' => 'L', // text alignement : R,C,L
  1940. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1941. ),
  1942. 'content' => array(
  1943. 'align' => 'L', // text alignement : R,C,L
  1944. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1945. ),
  1946. );
  1947. */
  1948. $rank = 0; // do not use negative rank
  1949. $this->cols['desc'] = array(
  1950. 'rank' => $rank,
  1951. 'width' => false, // only for desc
  1952. 'status' => true,
  1953. 'title' => array(
  1954. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1955. 'align' => 'L',
  1956. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1957. // 'label' => ' ', // the final label
  1958. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1959. ),
  1960. 'content' => array(
  1961. 'align' => 'L',
  1962. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1963. ),
  1964. );
  1965. // Image of product
  1966. $rank = $rank + 10;
  1967. $this->cols['photo'] = array(
  1968. 'rank' => $rank,
  1969. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1970. 'status' => false,
  1971. 'title' => array(
  1972. 'textkey' => 'Photo',
  1973. 'label' => ' '
  1974. ),
  1975. 'content' => array(
  1976. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1977. ),
  1978. 'border-left' => false, // remove left line separator
  1979. );
  1980. if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
  1981. $this->cols['photo']['status'] = true;
  1982. }
  1983. $rank = $rank + 10;
  1984. $this->cols['vat'] = array(
  1985. 'rank' => $rank,
  1986. 'status' => false,
  1987. 'width' => 16, // in mm
  1988. 'title' => array(
  1989. 'textkey' => 'VAT'
  1990. ),
  1991. 'border-left' => true, // add left line separator
  1992. );
  1993. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1994. $this->cols['vat']['status'] = true;
  1995. }
  1996. $rank = $rank + 10;
  1997. $this->cols['subprice'] = array(
  1998. 'rank' => $rank,
  1999. 'width' => 19, // in mm
  2000. 'status' => true,
  2001. 'title' => array(
  2002. 'textkey' => 'PriceUHT'
  2003. ),
  2004. 'border-left' => true, // add left line separator
  2005. );
  2006. // Adapt dynamically the width of subprice, if text is too long.
  2007. $tmpwidth = 0;
  2008. $nblines = count($object->lines);
  2009. for ($i = 0; $i < $nblines; $i++) {
  2010. $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
  2011. $tmpwidth = max($tmpwidth, $tmpwidth2);
  2012. }
  2013. if ($tmpwidth > 10) {
  2014. $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
  2015. }
  2016. $rank = $rank + 10;
  2017. $this->cols['qty'] = array(
  2018. 'rank' => $rank,
  2019. 'width' => 16, // in mm
  2020. 'status' => true,
  2021. 'title' => array(
  2022. 'textkey' => 'Qty'
  2023. ),
  2024. 'border-left' => true, // add left line separator
  2025. );
  2026. $rank = $rank + 10;
  2027. $this->cols['progress'] = array(
  2028. 'rank' => $rank,
  2029. 'width' => 19, // in mm
  2030. 'status' => false,
  2031. 'title' => array(
  2032. 'textkey' => 'Progress'
  2033. ),
  2034. 'border-left' => true, // add left line separator
  2035. );
  2036. if ($this->situationinvoice) {
  2037. $this->cols['progress']['status'] = true;
  2038. }
  2039. $rank = $rank + 10;
  2040. $this->cols['unit'] = array(
  2041. 'rank' => $rank,
  2042. 'width' => 11, // in mm
  2043. 'status' => false,
  2044. 'title' => array(
  2045. 'textkey' => 'Unit'
  2046. ),
  2047. 'border-left' => true, // add left line separator
  2048. );
  2049. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  2050. $this->cols['unit']['status'] = true;
  2051. }
  2052. $rank = $rank + 10;
  2053. $this->cols['discount'] = array(
  2054. 'rank' => $rank,
  2055. 'width' => 13, // in mm
  2056. 'status' => false,
  2057. 'title' => array(
  2058. 'textkey' => 'ReductionShort'
  2059. ),
  2060. 'border-left' => true, // add left line separator
  2061. );
  2062. if ($this->atleastonediscount) {
  2063. $this->cols['discount']['status'] = true;
  2064. }
  2065. $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
  2066. $this->cols['totalexcltax'] = array(
  2067. 'rank' => $rank,
  2068. 'width' => 26, // in mm
  2069. 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
  2070. 'title' => array(
  2071. 'textkey' => 'TotalHT'
  2072. ),
  2073. 'border-left' => true, // add left line separator
  2074. );
  2075. $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
  2076. $this->cols['totalincltax'] = array(
  2077. 'rank' => $rank,
  2078. 'width' => 26, // in mm
  2079. 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
  2080. 'title' => array(
  2081. 'textkey' => 'TotalTTC'
  2082. ),
  2083. 'border-left' => true, // add left line separator
  2084. );
  2085. // Add extrafields cols
  2086. if (!empty($object->lines)) {
  2087. $line = reset($object->lines);
  2088. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  2089. }
  2090. $parameters = array(
  2091. 'object' => $object,
  2092. 'outputlangs' => $outputlangs,
  2093. 'hidedetails' => $hidedetails,
  2094. 'hidedesc' => $hidedesc,
  2095. 'hideref' => $hideref
  2096. );
  2097. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  2098. if ($reshook < 0) {
  2099. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  2100. } elseif (empty($reshook)) {
  2101. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  2102. } else {
  2103. $this->cols = $hookmanager->resArray;
  2104. }
  2105. }
  2106. }