pdf_azur.modules.php 67 KB

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