pdf_sponge.modules.php 95 KB

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