pdf_cyan.modules.php 77 KB

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