pdf_eratosthene.modules.php 64 KB

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