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_codeproduitservice = 1; // Display product-service code
  142. $this->option_multilang = 1; // Available in several languages
  143. $this->option_escompte = 1; // Displays if there has been a discount
  144. $this->option_credit_note = 1; // Support credit notes
  145. $this->option_freetext = 1; // Support add of a personalised text
  146. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  147. // Get source company
  148. $this->emetteur = $mysoc;
  149. if (empty($this->emetteur->country_code)) {
  150. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  151. }
  152. // Define position of columns
  153. $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
  154. $this->tabTitleHeight = 5; // default height
  155. // Use new system for position of columns, view $this->defineColumnField()
  156. $this->tva = array();
  157. $this->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. $nblines = count($object->lines);
  198. $hidetop = 0;
  199. if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
  200. $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
  201. }
  202. // Loop on each lines to detect if there is at least one image to show
  203. $realpatharray = array();
  204. $this->atleastonephoto = false;
  205. if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
  206. $objphoto = new Product($this->db);
  207. for ($i = 0; $i < $nblines; $i++) {
  208. if (empty($object->lines[$i]->fk_product)) {
  209. continue;
  210. }
  211. $objphoto->fetch($object->lines[$i]->fk_product);
  212. //var_dump($objphoto->ref);exit;
  213. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
  214. $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
  215. $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
  216. } else {
  217. $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
  218. $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
  219. }
  220. $arephoto = false;
  221. foreach ($pdir as $midir) {
  222. if (!$arephoto) {
  223. if ($conf->entity != $objphoto->entity) {
  224. $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
  225. } else {
  226. $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
  227. }
  228. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  229. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  230. if ($obj['photo_vignette']) {
  231. $filename = $obj['photo_vignette'];
  232. } else {
  233. $filename = $obj['photo'];
  234. }
  235. } else {
  236. $filename = $obj['photo'];
  237. }
  238. $realpath = $dir.$filename;
  239. $arephoto = true;
  240. $this->atleastonephoto = true;
  241. }
  242. }
  243. }
  244. if ($realpath && $arephoto) {
  245. $realpatharray[$i] = $realpath;
  246. }
  247. }
  248. }
  249. //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
  250. if ($conf->facture->multidir_output[$conf->entity]) {
  251. $object->fetch_thirdparty();
  252. $deja_regle = $object->getSommePaiement((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
  253. $amount_credit_notes_included = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
  254. $amount_deposits_included = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
  255. // Definition of $dir and $file
  256. if ($object->specimen) {
  257. $dir = $conf->facture->multidir_output[$conf->entity];
  258. $file = $dir."/SPECIMEN.pdf";
  259. } else {
  260. $objectref = dol_sanitizeFileName($object->ref);
  261. $dir = $conf->facture->multidir_output[$object->entity]."/".$objectref;
  262. $file = $dir."/".$objectref.".pdf";
  263. }
  264. if (!file_exists($dir)) {
  265. if (dol_mkdir($dir) < 0) {
  266. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  267. return 0;
  268. }
  269. }
  270. if (file_exists($dir)) {
  271. // Add pdfgeneration hook
  272. if (!is_object($hookmanager)) {
  273. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  274. $hookmanager = new HookManager($this->db);
  275. }
  276. $hookmanager->initHooks(array('pdfgeneration'));
  277. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  278. global $action;
  279. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  280. // Set nblines with the new facture lines content after hook
  281. $nblines = count($object->lines);
  282. $nbpayments = count($object->getListOfPayments());
  283. // Create pdf instance
  284. $pdf = pdf_getInstance($this->format);
  285. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  286. $pdf->SetAutoPageBreak(1, 0);
  287. $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
  288. $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
  289. $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)
  290. if (class_exists('TCPDF')) {
  291. $pdf->setPrintHeader(false);
  292. $pdf->setPrintFooter(false);
  293. }
  294. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  295. // Set path to the background PDF File
  296. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  297. $logodir = $conf->mycompany->dir_output;
  298. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  299. $logodir = $conf->mycompany->multidir_output[$object->entity];
  300. }
  301. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  302. $tplidx = $pdf->importPage(1);
  303. }
  304. $pdf->Open();
  305. $pagenb = 0;
  306. $pdf->SetDrawColor(128, 128, 128);
  307. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  308. $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
  309. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  310. $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
  311. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  312. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  313. $pdf->SetCompression(false);
  314. }
  315. // Set certificate
  316. $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
  317. $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
  318. // If user has no certificate, we try to take the company one
  319. if (!$cert) {
  320. $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
  321. }
  322. if (!$certprivate) {
  323. $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
  324. }
  325. // If a certificate is found
  326. if ($cert) {
  327. $info = array(
  328. 'Name' => $this->emetteur->name,
  329. 'Location' => getCountry($this->emetteur->country_code, 0),
  330. 'Reason' => 'INVOICE',
  331. 'ContactInfo' => $this->emetteur->email
  332. );
  333. $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
  334. }
  335. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  336. // Set $this->atleastonediscount if you have at least one discount
  337. for ($i = 0; $i < $nblines; $i++) {
  338. if ($object->lines[$i]->remise_percent) {
  339. $this->atleastonediscount++;
  340. }
  341. }
  342. // Situation invoice handling
  343. if ($object->situation_cycle_ref) {
  344. $this->situationinvoice = true;
  345. }
  346. // New page
  347. $pdf->AddPage();
  348. if (!empty($tplidx)) {
  349. $pdf->useTemplate($tplidx);
  350. }
  351. $pagenb++;
  352. // Output header (logo, ref and address blocks). This is first call for first page.
  353. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
  354. $pdf->SetFont('', '', $default_font_size - 1);
  355. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  356. $pdf->SetTextColor(0, 0, 0);
  357. // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
  358. // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
  359. $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
  360. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  361. // You can add more thing under header here, if you increase $extra_under_address_shift too.
  362. $extra_under_address_shift = 0;
  363. if (! empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
  364. $qrcodestring = $object->buildZATCAQRString();
  365. $qrcodecolor = array('25', '25', '25');
  366. // set style for QR-code
  367. $styleQr = array(
  368. 'border' => false,
  369. 'padding' => 0,
  370. 'fgcolor' => $qrcodecolor,
  371. 'bgcolor' => false, //array(255,255,255)
  372. 'module_width' => 1, // width of a single module in points
  373. 'module_height' => 1 // height of a single module in points
  374. );
  375. $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
  376. $extra_under_address_shift += 25;
  377. }
  378. // Call hook printUnderHeaderPDFline
  379. $parameters = array(
  380. 'object' => $object,
  381. 'i' => $i,
  382. 'pdf' =>& $pdf,
  383. 'outputlangs' => $outputlangs,
  384. 'hidedetails' => $hidedetails
  385. );
  386. $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
  387. if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
  388. $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
  389. }
  390. $tab_top += $extra_under_address_shift;
  391. $tab_top_newpage += 0;
  392. // Define heigth of table for lines (for first page)
  393. $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
  394. $nexY = $tab_top - 1;
  395. // Incoterm
  396. $height_incoterms = 0;
  397. if (!empty($conf->incoterm->enabled)) {
  398. $desc_incoterms = $object->getIncotermsForPDF();
  399. if ($desc_incoterms) {
  400. $tab_top -= 2;
  401. $pdf->SetFont('', '', $default_font_size - 1);
  402. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  403. $nexY = max($pdf->GetY(), $nexY);
  404. $height_incoterms = $nexY - $tab_top;
  405. // Rect takes a length in 3rd parameter
  406. $pdf->SetDrawColor(192, 192, 192);
  407. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  408. $tab_top = $nexY + 6;
  409. $height_incoterms += 4;
  410. }
  411. }
  412. // Displays notes. Here we are still on code eecuted only for the first page.
  413. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  414. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  415. // Get first sale rep
  416. if (is_object($object->thirdparty)) {
  417. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  418. $salerepobj = new User($this->db);
  419. $salerepobj->fetch($salereparray[0]['id']);
  420. if (!empty($salerepobj->signature)) {
  421. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  422. }
  423. }
  424. }
  425. // Extrafields in note
  426. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  427. if (!empty($extranote)) {
  428. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  429. }
  430. $pagenb = $pdf->getPage();
  431. if ($notetoshow) {
  432. $tab_top -= 2;
  433. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  434. $pageposbeforenote = $pagenb;
  435. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  436. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  437. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  438. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  439. $pdf->startTransaction();
  440. $pdf->SetFont('', '', $default_font_size - 1);
  441. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  442. // Description
  443. $pageposafternote = $pdf->getPage();
  444. $posyafter = $pdf->GetY();
  445. if ($pageposafternote > $pageposbeforenote) {
  446. $pdf->rollbackTransaction(true);
  447. // prepare pages to receive notes
  448. while ($pagenb < $pageposafternote) {
  449. $pdf->AddPage();
  450. $pagenb++;
  451. if (!empty($tplidx)) {
  452. $pdf->useTemplate($tplidx);
  453. }
  454. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  455. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  456. }
  457. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  458. $pdf->setTopMargin($tab_top_newpage);
  459. // The only function to edit the bottom margin of current page to set it.
  460. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  461. }
  462. // back to start
  463. $pdf->setPage($pageposbeforenote);
  464. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  465. $pdf->SetFont('', '', $default_font_size - 1);
  466. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  467. $pageposafternote = $pdf->getPage();
  468. $posyafter = $pdf->GetY();
  469. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  470. $pdf->AddPage('', '', true);
  471. $pagenb++;
  472. $pageposafternote++;
  473. $pdf->setPage($pageposafternote);
  474. $pdf->setTopMargin($tab_top_newpage);
  475. // The only function to edit the bottom margin of current page to set it.
  476. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  477. //$posyafter = $tab_top_newpage;
  478. }
  479. // apply note frame to previous pages
  480. $i = $pageposbeforenote;
  481. while ($i < $pageposafternote) {
  482. $pdf->setPage($i);
  483. $pdf->SetDrawColor(128, 128, 128);
  484. // Draw note frame
  485. if ($i > $pageposbeforenote) {
  486. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  487. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  488. } else {
  489. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  490. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  491. }
  492. // Add footer
  493. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  494. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  495. $i++;
  496. }
  497. // apply note frame to last page
  498. $pdf->setPage($pageposafternote);
  499. if (!empty($tplidx)) {
  500. $pdf->useTemplate($tplidx);
  501. }
  502. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  503. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  504. }
  505. $height_note = $posyafter - $tab_top_newpage;
  506. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  507. } else {
  508. // No pagebreak
  509. $pdf->commitTransaction();
  510. $posyafter = $pdf->GetY();
  511. $height_note = $posyafter - $tab_top;
  512. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  513. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  514. // not enough space, need to add page
  515. $pdf->AddPage('', '', true);
  516. $pagenb++;
  517. $pageposafternote++;
  518. $pdf->setPage($pageposafternote);
  519. if (!empty($tplidx)) {
  520. $pdf->useTemplate($tplidx);
  521. }
  522. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  523. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  524. }
  525. $posyafter = $tab_top_newpage;
  526. }
  527. }
  528. $tab_height = $tab_height - $height_note;
  529. $tab_top = $posyafter + 6;
  530. } else {
  531. $height_note = 0;
  532. }
  533. // Use new auto column system
  534. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  535. // Table simulation to know the height of the title line (this set this->tableTitleHeight)
  536. $pdf->startTransaction();
  537. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  538. $pdf->rollbackTransaction(true);
  539. $nexY = $tab_top + $this->tabTitleHeight;
  540. // Loop on each lines
  541. $pageposbeforeprintlines = $pdf->getPage();
  542. $pagenb = $pageposbeforeprintlines;
  543. for ($i = 0; $i < $nblines; $i++) {
  544. $curY = $nexY;
  545. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  546. $pdf->SetTextColor(0, 0, 0);
  547. // Define size of image if we need it
  548. $imglinesize = array();
  549. if (!empty($realpatharray[$i])) {
  550. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  551. }
  552. $pdf->setTopMargin($tab_top_newpage);
  553. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  554. $pageposbefore = $pdf->getPage();
  555. $showpricebeforepagebreak = 1;
  556. $posYAfterImage = 0;
  557. $posYAfterDescription = 0;
  558. if ($this->getColumnStatus('photo')) {
  559. // We start with Photo of product line
  560. 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
  561. $pdf->AddPage('', '', true);
  562. if (!empty($tplidx)) {
  563. $pdf->useTemplate($tplidx);
  564. }
  565. $pdf->setPage($pageposbefore + 1);
  566. $curY = $tab_top_newpage;
  567. // Allows data in the first page if description is long enough to break in multiples pages
  568. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  569. $showpricebeforepagebreak = 1;
  570. } else {
  571. $showpricebeforepagebreak = 0;
  572. }
  573. }
  574. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
  575. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  576. // $pdf->Image does not increase value return by getY, so we save it manually
  577. $posYAfterImage = $curY + $imglinesize['height'];
  578. }
  579. }
  580. // Description of product line
  581. if ($this->getColumnStatus('desc')) {
  582. $pdf->startTransaction();
  583. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  584. $pageposafter = $pdf->getPage();
  585. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  586. $pdf->rollbackTransaction(true);
  587. $pageposafter = $pageposbefore;
  588. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  589. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  590. $pageposafter = $pdf->getPage();
  591. $posyafter = $pdf->GetY();
  592. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  593. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  594. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  595. $pdf->AddPage('', '', true);
  596. if (!empty($tplidx)) {
  597. $pdf->useTemplate($tplidx);
  598. }
  599. $pdf->setPage($pageposafter + 1);
  600. }
  601. } else {
  602. // We found a page break
  603. // Allows data in the first page if description is long enough to break in multiples pages
  604. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  605. $showpricebeforepagebreak = 1;
  606. } else {
  607. $showpricebeforepagebreak = 0;
  608. }
  609. }
  610. } else // No pagebreak
  611. {
  612. $pdf->commitTransaction();
  613. }
  614. $posYAfterDescription = $pdf->GetY();
  615. }
  616. $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
  617. $pageposafter = $pdf->getPage();
  618. $pdf->setPage($pageposbefore);
  619. $pdf->setTopMargin($this->marge_haute);
  620. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  621. // We suppose that a too long description or photo were moved completely on next page
  622. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  623. $pdf->setPage($pageposafter);
  624. $curY = $tab_top_newpage;
  625. }
  626. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  627. // VAT Rate
  628. if ($this->getColumnStatus('vat')) {
  629. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  630. $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
  631. $nexY = max($pdf->GetY(), $nexY);
  632. }
  633. // Unit price before discount
  634. if ($this->getColumnStatus('subprice')) {
  635. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  636. $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
  637. $nexY = max($pdf->GetY(), $nexY);
  638. }
  639. // Quantity
  640. // Enough for 6 chars
  641. if ($this->getColumnStatus('qty')) {
  642. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  643. $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
  644. $nexY = max($pdf->GetY(), $nexY);
  645. }
  646. // Situation progress
  647. if ($this->getColumnStatus('progress')) {
  648. $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
  649. $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
  650. $nexY = max($pdf->GetY(), $nexY);
  651. }
  652. // Unit
  653. if ($this->getColumnStatus('unit')) {
  654. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  655. $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
  656. $nexY = max($pdf->GetY(), $nexY);
  657. }
  658. // Discount on line
  659. if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
  660. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  661. $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
  662. $nexY = max($pdf->GetY(), $nexY);
  663. }
  664. // Total excl tax line (HT)
  665. if ($this->getColumnStatus('totalexcltax')) {
  666. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  667. $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
  668. $nexY = max($pdf->GetY(), $nexY);
  669. }
  670. // Total with tax line (TTC)
  671. if ($this->getColumnStatus('totalincltax')) {
  672. $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
  673. $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
  674. $nexY = max($pdf->GetY(), $nexY);
  675. }
  676. // Extrafields
  677. if (!empty($object->lines[$i]->array_options)) {
  678. foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
  679. if ($this->getColumnStatus($extrafieldColKey)) {
  680. $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
  681. $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
  682. $nexY = max($pdf->GetY(), $nexY);
  683. }
  684. }
  685. }
  686. $parameters = array(
  687. 'object' => $object,
  688. 'i' => $i,
  689. 'pdf' =>& $pdf,
  690. 'curY' =>& $curY,
  691. 'nexY' =>& $nexY,
  692. 'outputlangs' => $outputlangs,
  693. 'hidedetails' => $hidedetails
  694. );
  695. $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
  696. $sign = 1;
  697. if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  698. $sign = -1;
  699. }
  700. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  701. $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
  702. if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
  703. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  704. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  705. } else {
  706. $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
  707. }
  708. } else {
  709. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  710. $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
  711. } else {
  712. $tvaligne = $sign * $object->lines[$i]->total_tva;
  713. }
  714. }
  715. $localtax1ligne = $object->lines[$i]->total_localtax1;
  716. $localtax2ligne = $object->lines[$i]->total_localtax2;
  717. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  718. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  719. $localtax1_type = $object->lines[$i]->localtax1_type;
  720. $localtax2_type = $object->lines[$i]->localtax2_type;
  721. if ($object->remise_percent) {
  722. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  723. }
  724. if ($object->remise_percent) {
  725. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  726. }
  727. if ($object->remise_percent) {
  728. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  729. }
  730. $vatrate = (string) $object->lines[$i]->tva_tx;
  731. // Retrieve type from database for backward compatibility with old records
  732. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  733. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  734. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  735. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  736. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  737. }
  738. // retrieve global local tax
  739. if ($localtax1_type && $localtax1ligne != 0) {
  740. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  741. }
  742. if ($localtax2_type && $localtax2ligne != 0) {
  743. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  744. }
  745. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  746. $vatrate .= '*';
  747. }
  748. // Fill $this->tva and $this->tva_array
  749. if (!isset($this->tva[$vatrate])) {
  750. $this->tva[$vatrate] = 0;
  751. }
  752. $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
  753. $vatcode = $object->lines[$i]->vat_src_code;
  754. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  755. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  756. }
  757. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  758. $nexY = max($nexY, $posYAfterImage);
  759. // Add line
  760. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  761. $pdf->setPage($pageposafter);
  762. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  763. //$pdf->SetDrawColor(190,190,200);
  764. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
  765. $pdf->SetLineStyle(array('dash'=>0));
  766. }
  767. // Detect if some page were added automatically and output _tableau for past pages
  768. while ($pagenb < $pageposafter) {
  769. $pdf->setPage($pagenb);
  770. if ($pagenb == $pageposbeforeprintlines) {
  771. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  772. } else {
  773. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  774. }
  775. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  776. $pagenb++;
  777. $pdf->setPage($pagenb);
  778. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  779. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  780. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  781. }
  782. }
  783. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  784. if ($pagenb == $pageposafter) {
  785. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  786. } else {
  787. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  788. }
  789. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  790. // New page
  791. $pdf->AddPage();
  792. if (!empty($tplidx)) {
  793. $pdf->useTemplate($tplidx);
  794. }
  795. $pagenb++;
  796. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  797. $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
  798. }
  799. }
  800. }
  801. // Show square
  802. if ($pagenb == $pageposbeforeprintlines) {
  803. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
  804. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  805. } else {
  806. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
  807. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  808. }
  809. // Display infos area
  810. $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
  811. // Display total zone
  812. $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
  813. // Display payment area
  814. if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  815. $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
  816. }
  817. // Pagefoot
  818. $this->_pagefoot($pdf, $object, $outputlangs);
  819. if (method_exists($pdf, 'AliasNbPages')) {
  820. $pdf->AliasNbPages();
  821. }
  822. $pdf->Close();
  823. $pdf->Output($file, 'F');
  824. // Add pdfgeneration hook
  825. $hookmanager->initHooks(array('pdfgeneration'));
  826. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  827. global $action;
  828. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  829. if ($reshook < 0) {
  830. $this->error = $hookmanager->error;
  831. $this->errors = $hookmanager->errors;
  832. }
  833. if (!empty($conf->global->MAIN_UMASK)) {
  834. @chmod($file, octdec($conf->global->MAIN_UMASK));
  835. }
  836. $this->result = array('fullpath'=>$file);
  837. return 1; // No error
  838. } else {
  839. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  840. return 0;
  841. }
  842. } else {
  843. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
  844. return 0;
  845. }
  846. }
  847. /**
  848. * Show payments table
  849. *
  850. * @param TCPDF $pdf Object PDF
  851. * @param Facture $object Object invoice
  852. * @param int $posy Position y in PDF
  853. * @param Translate $outputlangs Object langs for output
  854. * @return int <0 if KO, >0 if OK
  855. */
  856. public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
  857. {
  858. global $conf;
  859. $sign = 1;
  860. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  861. $sign = -1;
  862. }
  863. $tab3_posx = 120;
  864. $tab3_top = $posy + 8;
  865. $tab3_width = 80;
  866. $tab3_height = 4;
  867. if ($this->page_largeur < 210) { // To work with US executive format
  868. $tab3_posx -= 15;
  869. }
  870. $default_font_size = pdf_getPDFFontSize($outputlangs);
  871. $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
  872. if ($object->type == 2) {
  873. $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
  874. }
  875. $pdf->SetFont('', '', $default_font_size - 3);
  876. $pdf->SetXY($tab3_posx, $tab3_top - 4);
  877. $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
  878. $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
  879. $pdf->SetFont('', '', $default_font_size - 4);
  880. $pdf->SetXY($tab3_posx, $tab3_top);
  881. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  882. $pdf->SetXY($tab3_posx + 21, $tab3_top);
  883. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  884. $pdf->SetXY($tab3_posx + 40, $tab3_top);
  885. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  886. $pdf->SetXY($tab3_posx + 58, $tab3_top);
  887. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  888. $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
  889. $y = 0;
  890. $pdf->SetFont('', '', $default_font_size - 4);
  891. // Loop on each discount available (deposits and credit notes and excess of payment included)
  892. $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,";
  893. $sql .= " re.description, re.fk_facture_source,";
  894. $sql .= " f.type, f.datef";
  895. $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
  896. $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
  897. $resql = $this->db->query($sql);
  898. if ($resql) {
  899. $num = $this->db->num_rows($resql);
  900. $i = 0;
  901. $invoice = new Facture($this->db);
  902. while ($i < $num) {
  903. $y += 3;
  904. $obj = $this->db->fetch_object($resql);
  905. if ($obj->type == 2) {
  906. $text = $outputlangs->transnoentities("CreditNote");
  907. } elseif ($obj->type == 3) {
  908. $text = $outputlangs->transnoentities("Deposit");
  909. } elseif ($obj->type == 0) {
  910. $text = $outputlangs->transnoentities("ExcessReceived");
  911. } else {
  912. $text = $outputlangs->transnoentities("UnknownType");
  913. }
  914. $invoice->fetch($obj->fk_facture_source);
  915. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  916. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
  917. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  918. $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);
  919. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  920. $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
  921. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  922. $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
  923. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  924. $i++;
  925. }
  926. } else {
  927. $this->error = $this->db->lasterror();
  928. return -1;
  929. }
  930. // Loop on each payment
  931. // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
  932. $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
  933. $sql .= " cp.code";
  934. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  935. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  936. $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
  937. //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
  938. $sql .= " ORDER BY p.datep";
  939. $resql = $this->db->query($sql);
  940. if ($resql) {
  941. $num = $this->db->num_rows($resql);
  942. $i = 0;
  943. while ($i < $num) {
  944. $y += 3;
  945. $row = $this->db->fetch_object($resql);
  946. $pdf->SetXY($tab3_posx, $tab3_top + $y);
  947. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
  948. $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
  949. $pdf->MultiCell(20, 3, price($sign * ((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
  950. $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
  951. $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  952. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  953. $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
  954. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  955. $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
  956. $i++;
  957. }
  958. return $tab3_top + $y + 3;
  959. } else {
  960. $this->error = $this->db->lasterror();
  961. return -1;
  962. }
  963. }
  964. /**
  965. * Show miscellaneous information (payment mode, payment term, ...)
  966. *
  967. * @param TCPDF $pdf Object PDF
  968. * @param Facture $object Object to show
  969. * @param int $posy Y
  970. * @param Translate $outputlangs Langs object
  971. * @param Translate $outputlangsbis Object lang for output bis
  972. * @return int Pos y
  973. */
  974. protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
  975. {
  976. global $conf, $mysoc;
  977. $default_font_size = pdf_getPDFFontSize($outputlangs);
  978. $pdf->SetFont('', '', $default_font_size - 1);
  979. // If France, show VAT mention if not applicable
  980. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
  981. $pdf->SetFont('', 'B', $default_font_size - 2);
  982. $pdf->SetXY($this->marge_gauche, $posy);
  983. if ($mysoc->forme_juridique_code == 92) {
  984. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
  985. } else {
  986. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  987. }
  988. $posy = $pdf->GetY() + 4;
  989. }
  990. $posxval = 52; // Position of values of properties shown on left side
  991. $posxend = 110; // End of x for text on left side
  992. if ($this->page_largeur < 210) { // To work with US executive format
  993. $posxend -= 10;
  994. }
  995. // Show payments conditions
  996. if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
  997. $pdf->SetFont('', 'B', $default_font_size - 2);
  998. $pdf->SetXY($this->marge_gauche, $posy);
  999. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  1000. $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
  1001. $pdf->SetFont('', '', $default_font_size - 2);
  1002. $pdf->SetXY($posxval, $posy);
  1003. $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);
  1004. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  1005. $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
  1006. $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
  1007. }
  1008. if ($object->type != 2) {
  1009. // Check a payment mode is defined
  1010. if (empty($object->mode_reglement_code)
  1011. && empty($conf->global->FACTURE_CHQ_NUMBER)
  1012. && empty($conf->global->FACTURE_RIB_NUMBER)) {
  1013. $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
  1014. } elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
  1015. || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) {
  1016. // Avoid having any valid PDF with setup that is not complete
  1017. $outputlangs->load("errors");
  1018. $pdf->SetXY($this->marge_gauche, $posy);
  1019. $pdf->SetTextColor(200, 0, 0);
  1020. $pdf->SetFont('', 'B', $default_font_size - 2);
  1021. $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
  1022. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
  1023. $pdf->SetTextColor(0, 0, 0);
  1024. $posy = $pdf->GetY() + 1;
  1025. }
  1026. // Show payment mode
  1027. if (!empty($object->mode_reglement_code)
  1028. && $object->mode_reglement_code != 'CHQ'
  1029. && $object->mode_reglement_code != 'VIR') {
  1030. $pdf->SetFont('', 'B', $default_font_size - 2);
  1031. $pdf->SetXY($this->marge_gauche, $posy);
  1032. $titre = $outputlangs->transnoentities("PaymentMode").':';
  1033. $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
  1034. $pdf->SetFont('', '', $default_font_size - 2);
  1035. $pdf->SetXY($posxval, $posy);
  1036. $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);
  1037. $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
  1038. $posy = $pdf->GetY();
  1039. }
  1040. // Show online payment link
  1041. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
  1042. $useonlinepayment = 0;
  1043. if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
  1044. if (!empty($conf->paypal->enabled)) {
  1045. $useonlinepayment++;
  1046. }
  1047. if (!empty($conf->stripe->enabled)) {
  1048. $useonlinepayment++;
  1049. }
  1050. if (!empty($conf->paybox->enabled)) {
  1051. $useonlinepayment++;
  1052. }
  1053. }
  1054. if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
  1055. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  1056. global $langs;
  1057. $langs->loadLangs(array('payment', 'paybox'));
  1058. $servicename = $langs->transnoentities('Online');
  1059. $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
  1060. $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
  1061. $pdf->SetXY($this->marge_gauche, $posy);
  1062. $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
  1063. $posy = $pdf->GetY() + 1;
  1064. }
  1065. }
  1066. // Show payment mode CHQ
  1067. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  1068. // If payment mode unregulated or payment mode forced to CHQ
  1069. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  1070. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  1071. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  1072. $account = new Account($this->db);
  1073. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  1074. $pdf->SetXY($this->marge_gauche, $posy);
  1075. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1076. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  1077. $posy = $pdf->GetY() + 1;
  1078. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1079. $pdf->SetXY($this->marge_gauche, $posy);
  1080. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1081. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  1082. $posy = $pdf->GetY() + 2;
  1083. }
  1084. }
  1085. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  1086. $pdf->SetXY($this->marge_gauche, $posy);
  1087. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1088. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  1089. $posy = $pdf->GetY() + 1;
  1090. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1091. $pdf->SetXY($this->marge_gauche, $posy);
  1092. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1093. $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  1094. $posy = $pdf->GetY() + 2;
  1095. }
  1096. }
  1097. }
  1098. }
  1099. // If payment mode not forced or forced to VIR, show payment with BAN
  1100. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  1101. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  1102. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  1103. if ($object->fk_bank > 0) {
  1104. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  1105. }
  1106. $account = new Account($this->db);
  1107. $account->fetch($bankid);
  1108. $curx = $this->marge_gauche;
  1109. $cury = $posy;
  1110. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  1111. $posy += 2;
  1112. }
  1113. }
  1114. }
  1115. return $posy;
  1116. }
  1117. /**
  1118. * Show total to pay
  1119. *
  1120. * @param TCPDF $pdf Object PDF
  1121. * @param Facture $object Object invoice
  1122. * @param int $deja_regle Amount already paid (in the currency of invoice)
  1123. * @param int $posy Position depart
  1124. * @param Translate $outputlangs Objet langs
  1125. * @param Translate $outputlangsbis Object lang for output bis
  1126. * @return int Position pour suite
  1127. */
  1128. protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
  1129. {
  1130. global $conf, $mysoc, $hookmanager;
  1131. $sign = 1;
  1132. if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
  1133. $sign = -1;
  1134. }
  1135. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1136. $tab2_top = $posy;
  1137. $tab2_hl = 4;
  1138. if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
  1139. $pdf->SetFont('', '', $default_font_size - 2);
  1140. } else {
  1141. $pdf->SetFont('', '', $default_font_size - 1);
  1142. }
  1143. // Total table
  1144. $col1x = 120;
  1145. $col2x = 170;
  1146. if ($this->page_largeur < 210) { // To work with US executive format
  1147. $col1x -= 15;
  1148. $col2x -= 10;
  1149. }
  1150. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  1151. $useborder = 0;
  1152. $index = 0;
  1153. // Add trigger to allow to edit $object
  1154. $parameters = array(
  1155. 'object' => &$object,
  1156. 'outputlangs' => $outputlangs,
  1157. );
  1158. $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
  1159. // overall percentage of advancement
  1160. $percent = 0;
  1161. $i = 0;
  1162. foreach ($object->lines as $line) {
  1163. $percent += $line->situation_percent;
  1164. $i++;
  1165. }
  1166. if (!empty($i)) {
  1167. $avancementGlobal = $percent / $i;
  1168. } else {
  1169. $avancementGlobal = 0;
  1170. }
  1171. $object->fetchPreviousNextSituationInvoice();
  1172. $TPreviousIncoice = $object->tab_previous_situation_invoice;
  1173. $total_a_payer = 0;
  1174. $total_a_payer_ttc = 0;
  1175. foreach ($TPreviousIncoice as &$fac) {
  1176. $total_a_payer += $fac->total_ht;
  1177. $total_a_payer_ttc += $fac->total_ttc;
  1178. }
  1179. $total_a_payer += $object->total_ht;
  1180. $total_a_payer_ttc += $object->total_ttc;
  1181. if (!empty($avancementGlobal)) {
  1182. $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
  1183. $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
  1184. } else {
  1185. $total_a_payer = 0;
  1186. $total_a_payer_ttc = 0;
  1187. }
  1188. $i = 1;
  1189. if (!empty($TPreviousIncoice)) {
  1190. $pdf->setY($tab2_top);
  1191. $posy = $pdf->GetY();
  1192. foreach ($TPreviousIncoice as &$fac) {
  1193. if ($posy > $this->page_hauteur - 4) {
  1194. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  1195. $pdf->addPage();
  1196. $pdf->setY($this->marge_haute);
  1197. $posy = $pdf->GetY();
  1198. }
  1199. // Cumulate preceding VAT
  1200. $index++;
  1201. $pdf->SetFillColor(255, 255, 255);
  1202. $pdf->SetXY($col1x, $posy);
  1203. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  1204. $pdf->SetXY($col2x, $posy);
  1205. $facSign = '';
  1206. if ($i > 1) {
  1207. $facSign = $fac->total_ht >= 0 ? '+' : '';
  1208. }
  1209. $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
  1210. $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
  1211. $i++;
  1212. $posy += $tab2_hl;
  1213. $pdf->setY($posy);
  1214. }
  1215. // Display current total
  1216. $pdf->SetFillColor(255, 255, 255);
  1217. $pdf->SetXY($col1x, $posy);
  1218. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  1219. $pdf->SetXY($col2x, $posy);
  1220. $facSign = '';
  1221. if ($i > 1) {
  1222. $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
  1223. }
  1224. if ($fac->type === facture::TYPE_CREDIT_NOTE) {
  1225. $facSign = '-'; // les avoirs
  1226. }
  1227. $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
  1228. $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
  1229. $posy += $tab2_hl;
  1230. // Display all total
  1231. $pdf->SetFont('', '', $default_font_size - 1);
  1232. $pdf->SetFillColor(255, 255, 255);
  1233. $pdf->SetXY($col1x, $posy);
  1234. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
  1235. $pdf->SetXY($col2x, $posy);
  1236. $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
  1237. $pdf->SetFont('', '', $default_font_size - 2);
  1238. $posy += $tab2_hl;
  1239. if ($posy > $this->page_hauteur - 4) {
  1240. $pdf->addPage();
  1241. $pdf->setY($this->marge_haute);
  1242. $posy = $pdf->GetY();
  1243. }
  1244. $tab2_top = $posy;
  1245. $index = 0;
  1246. $tab2_top += 3;
  1247. }
  1248. // Get Total HT
  1249. $total_ht = (!empty($conf->multicurrency->enabled) && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
  1250. // Total remise
  1251. $total_line_remise = 0;
  1252. foreach ($object->lines as $i => $line) {
  1253. $total_line_remise += pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); // TODO: add this method to core/lib/pdf.lib
  1254. // Gestion remise sous forme de ligne négative
  1255. if ($line->total_ht < 0) {
  1256. $total_line_remise += -$line->total_ht;
  1257. }
  1258. }
  1259. if ($total_line_remise > 0) {
  1260. if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
  1261. $pdf->SetFillColor(255, 255, 255);
  1262. $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
  1263. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
  1264. $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
  1265. $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1);
  1266. $index++;
  1267. }
  1268. // Show total NET before discount
  1269. if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
  1270. $pdf->SetFillColor(255, 255, 255);
  1271. $pdf->SetXY($col1x, $tab2_top + 0);
  1272. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
  1273. $pdf->SetXY($col2x, $tab2_top + 0);
  1274. $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1);
  1275. $index++;
  1276. }
  1277. }
  1278. // Total HT
  1279. $pdf->SetFillColor(255, 255, 255);
  1280. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1281. $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);
  1282. $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  1283. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1284. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
  1285. // Show VAT by rates and total
  1286. $pdf->SetFillColor(248, 248, 248);
  1287. $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  1288. $this->atleastoneratenotnull = 0;
  1289. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  1290. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  1291. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  1292. // Nothing to do
  1293. } else {
  1294. // FIXME amount of vat not supported with multicurrency
  1295. //Local tax 1 before VAT
  1296. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1297. //{
  1298. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1299. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1300. continue;
  1301. }
  1302. foreach ($localtax_rate as $tvakey => $tvaval) {
  1303. if ($tvakey != 0) { // On affiche pas taux 0
  1304. //$this->atleastoneratenotnull++;
  1305. $index++;
  1306. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1307. $tvacompl = '';
  1308. if (preg_match('/\*/', $tvakey)) {
  1309. $tvakey = str_replace('*', '', $tvakey);
  1310. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1311. }
  1312. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1313. $totalvat .= ' ';
  1314. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1315. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1316. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1317. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1318. }
  1319. }
  1320. }
  1321. //}
  1322. //Local tax 2 before VAT
  1323. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1324. //{
  1325. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1326. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1327. continue;
  1328. }
  1329. foreach ($localtax_rate as $tvakey => $tvaval) {
  1330. if ($tvakey != 0) { // On affiche pas taux 0
  1331. //$this->atleastoneratenotnull++;
  1332. $index++;
  1333. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1334. $tvacompl = '';
  1335. if (preg_match('/\*/', $tvakey)) {
  1336. $tvakey = str_replace('*', '', $tvakey);
  1337. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1338. }
  1339. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1340. $totalvat .= ' ';
  1341. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1342. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1343. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1344. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1345. }
  1346. }
  1347. }
  1348. //}
  1349. // Situations totals migth be wrong on huge amounts with old mode 1
  1350. if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
  1351. $sum_pdf_tva = 0;
  1352. foreach ($this->tva as $tvakey => $tvaval) {
  1353. $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
  1354. }
  1355. if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
  1356. if (!empty($sum_pdf_tva)) {
  1357. $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
  1358. } else {
  1359. $coef_fix_tva = 1;
  1360. }
  1361. foreach ($this->tva as $tvakey => $tvaval) {
  1362. $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
  1363. }
  1364. foreach ($this->tva_array as $tvakey => $tvaval) {
  1365. $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
  1366. }
  1367. }
  1368. }
  1369. // VAT
  1370. foreach ($this->tva_array as $tvakey => $tvaval) {
  1371. if ($tvakey != 0) { // On affiche pas taux 0
  1372. $this->atleastoneratenotnull++;
  1373. $index++;
  1374. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1375. $tvacompl = '';
  1376. if (preg_match('/\*/', $tvakey)) {
  1377. $tvakey = str_replace('*', '', $tvakey);
  1378. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1379. }
  1380. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1381. $totalvat .= ' ';
  1382. if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
  1383. $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
  1384. } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
  1385. $totalvat .= ($tvaval['vatcode'] ? $tvaval['vatcode'] : vatrate($tvaval['vatrate'], 1)).$tvacompl;
  1386. } else {
  1387. $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
  1388. }
  1389. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1390. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1391. $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
  1392. }
  1393. }
  1394. //Local tax 1 after VAT
  1395. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1396. //{
  1397. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1398. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1399. continue;
  1400. }
  1401. foreach ($localtax_rate as $tvakey => $tvaval) {
  1402. if ($tvakey != 0) { // On affiche pas taux 0
  1403. //$this->atleastoneratenotnull++;
  1404. $index++;
  1405. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1406. $tvacompl = '';
  1407. if (preg_match('/\*/', $tvakey)) {
  1408. $tvakey = str_replace('*', '', $tvakey);
  1409. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1410. }
  1411. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1412. $totalvat .= ' ';
  1413. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1414. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1415. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1416. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1417. }
  1418. }
  1419. }
  1420. //}
  1421. //Local tax 2 after VAT
  1422. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1423. //{
  1424. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1425. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1426. continue;
  1427. }
  1428. foreach ($localtax_rate as $tvakey => $tvaval) {
  1429. // retrieve global local tax
  1430. if ($tvakey != 0) { // On affiche pas taux 0
  1431. //$this->atleastoneratenotnull++;
  1432. $index++;
  1433. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1434. $tvacompl = '';
  1435. if (preg_match('/\*/', $tvakey)) {
  1436. $tvakey = str_replace('*', '', $tvakey);
  1437. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1438. }
  1439. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1440. $totalvat .= ' ';
  1441. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1442. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1443. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1444. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1445. }
  1446. }
  1447. }
  1448. // Revenue stamp
  1449. if (price2num($object->revenuestamp) != 0) {
  1450. $index++;
  1451. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1452. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
  1453. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1454. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
  1455. }
  1456. // Total TTC
  1457. $index++;
  1458. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1459. $pdf->SetTextColor(0, 0, 60);
  1460. $pdf->SetFillColor(224, 224, 224);
  1461. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
  1462. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1463. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1464. // Retained warranty
  1465. if ($object->displayRetainedWarranty()) {
  1466. $pdf->SetTextColor(40, 40, 40);
  1467. $pdf->SetFillColor(255, 255, 255);
  1468. $retainedWarranty = $object->getRetainedWarrantyAmount();
  1469. $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
  1470. // Billed - retained warranty
  1471. $index++;
  1472. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1473. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
  1474. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1475. $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
  1476. // retained warranty
  1477. $index++;
  1478. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1479. $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
  1480. $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
  1481. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
  1482. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1483. $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
  1484. }
  1485. }
  1486. }
  1487. $pdf->SetTextColor(0, 0, 0);
  1488. $creditnoteamount = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
  1489. $depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
  1490. $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  1491. if (!empty($object->paye)) {
  1492. $resteapayer = 0;
  1493. }
  1494. if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
  1495. // Already paid + Deposits
  1496. $index++;
  1497. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1498. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
  1499. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1500. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
  1501. // Credit note
  1502. if ($creditnoteamount) {
  1503. $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
  1504. $labeltouse .= (is_object($outputlangsbis) ? (' / '.($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes")) : '');
  1505. $index++;
  1506. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1507. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
  1508. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1509. $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
  1510. }
  1511. /*
  1512. if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
  1513. {
  1514. $index++;
  1515. $pdf->SetFillColor(255, 255, 255);
  1516. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1517. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
  1518. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1519. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
  1520. $resteapayer = 0;
  1521. }
  1522. */
  1523. $index++;
  1524. $pdf->SetTextColor(0, 0, 60);
  1525. $pdf->SetFillColor(224, 224, 224);
  1526. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1527. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
  1528. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1529. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1530. $pdf->SetFont('', '', $default_font_size - 1);
  1531. $pdf->SetTextColor(0, 0, 0);
  1532. }
  1533. $index++;
  1534. return ($tab2_top + ($tab2_hl * $index));
  1535. }
  1536. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1537. /**
  1538. * Return list of active generation modules
  1539. *
  1540. * @param DoliDB $db Database handler
  1541. * @param integer $maxfilenamelength Max length of value to show
  1542. * @return array List of templates
  1543. */
  1544. public static function liste_modeles($db, $maxfilenamelength = 0)
  1545. {
  1546. // phpcs:enable
  1547. return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
  1548. }
  1549. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1550. /**
  1551. * Show table for lines
  1552. *
  1553. * @param TCPDF $pdf Object PDF
  1554. * @param string $tab_top Top position of table
  1555. * @param string $tab_height Height of table (rectangle)
  1556. * @param int $nexY Y (not used)
  1557. * @param Translate $outputlangs Langs object
  1558. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1559. * @param int $hidebottom Hide bottom bar of array
  1560. * @param string $currency Currency code
  1561. * @param Translate $outputlangsbis Langs object bis
  1562. * @return void
  1563. */
  1564. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1565. {
  1566. global $conf;
  1567. // Force to disable hidetop and hidebottom
  1568. $hidebottom = 0;
  1569. if ($hidetop) {
  1570. $hidetop = -1;
  1571. }
  1572. $currency = !empty($currency) ? $currency : $conf->currency;
  1573. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1574. // Amount in (at tab_top - 1)
  1575. $pdf->SetTextColor(0, 0, 0);
  1576. $pdf->SetFont('', '', $default_font_size - 2);
  1577. if (empty($hidetop)) {
  1578. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1579. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1580. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1581. }
  1582. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1583. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1584. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1585. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1586. $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));
  1587. }
  1588. }
  1589. $pdf->SetDrawColor(128, 128, 128);
  1590. $pdf->SetFont('', '', $default_font_size - 1);
  1591. // Output Rect
  1592. $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
  1593. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  1594. if (empty($hidetop)) {
  1595. $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
  1596. }
  1597. }
  1598. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1599. /**
  1600. * Show top header of page. This include the logo, ref and address blocs
  1601. *
  1602. * @param TCPDF $pdf Object PDF
  1603. * @param Facture $object Object to show
  1604. * @param int $showaddress 0=no, 1=yes (usually set to 1 for first page, and 0 for next pages)
  1605. * @param Translate $outputlangs Object lang for output
  1606. * @param Translate $outputlangsbis Object lang for output bis
  1607. * @return int top shift of linked object lines
  1608. */
  1609. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
  1610. {
  1611. global $conf, $langs;
  1612. $ltrdirection = 'L';
  1613. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1614. // Load traductions files required by page
  1615. $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
  1616. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1617. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1618. // Show Draft Watermark
  1619. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
  1620. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
  1621. }
  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);
  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. }