pdf_sponge.modules.php 107 KB

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