pdf_eratosthene.modules.php 80 KB

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