pdf_azur.modules.php 68 KB

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