pdf_cyan.modules.php 77 KB

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