pdf_sponge.modules.php 108 KB

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