pdf_cyan.modules.php 78 KB

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