pdf_sponge.modules.php 90 KB

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