pdf_einstein.modules.php 59 KB

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