pdf_eratosthene.modules.php 70 KB

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