pdf_eratosthene.modules.php 82 KB

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