pdf_beluga.modules.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2015-2018 Charlene Benke <charlie@patas-monkey.com>
  4. * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/project/doc/pdf_beluga.modules.php
  22. * \ingroup project
  23. * \brief File of class to generate project document beluga
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  34. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  35. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  36. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  37. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  38. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  39. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  40. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  41. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  42. if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  43. if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  44. if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  45. /**
  46. * Class to manage generation of project document Beluga
  47. */
  48. class pdf_beluga extends ModelePDFProjects
  49. {
  50. /**
  51. * Page orientation
  52. * @var string 'P' or 'Portait' (default), 'L' or 'Landscape'
  53. */
  54. private $orientation = '';
  55. /**
  56. * Issuer
  57. * @var Societe
  58. */
  59. public $emetteur;
  60. /**
  61. * Constructor
  62. *
  63. * @param DoliDB $db Database handler
  64. */
  65. public function __construct($db)
  66. {
  67. global $conf,$langs,$mysoc;
  68. // Translations
  69. $langs->loadLangs(array("main", "projects", "companies"));
  70. $this->db = $db;
  71. $this->name = "beluga";
  72. $this->description = $langs->trans("DocumentModelBeluga");
  73. // Page size for A4 format
  74. $this->type = 'pdf';
  75. $formatarray=pdf_getFormat();
  76. $this->orientation = 'L';
  77. if ($this->orientation == 'L' || $this->orientation == 'Landscape') {
  78. $this->page_largeur = $formatarray['height'];
  79. $this->page_hauteur = $formatarray['width'];
  80. } else {
  81. $this->page_largeur = $formatarray['width'];
  82. $this->page_hauteur = $formatarray['height'];
  83. }
  84. $this->format = array($this->page_largeur,$this->page_hauteur);
  85. $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  86. $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  87. $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  88. $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  89. $this->option_logo = 1; // Display logo FAC_PDF_LOGO
  90. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  91. $this->option_codeproduitservice = 1; // Display product-service code
  92. // Get source company
  93. $this->emetteur=$mysoc;
  94. if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang, -2); // By default if not defined
  95. // Define position of columns
  96. if ($this->orientation == 'L' || $this->orientation == 'Landscape') {
  97. $this->posxref=$this->marge_gauche+1;
  98. $this->posxdate=$this->marge_gauche+105;
  99. $this->posxsociety=$this->marge_gauche+125;
  100. $this->posxamountht=$this->marge_gauche+190;
  101. $this->posxamountttc=$this->marge_gauche+215;
  102. $this->posxstatut=$this->marge_gauche+245;
  103. } else {
  104. $this->posxref=$this->marge_gauche+1;
  105. $this->posxdate=$this->marge_gauche+25;
  106. $this->posxsociety=$this->marge_gauche+45;
  107. $this->posxamountht=$this->marge_gauche+110;
  108. $this->posxamountttc=$this->marge_gauche+135;
  109. $this->posxstatut=$this->marge_gauche+165;
  110. }
  111. if ($this->page_largeur < 210) // To work with US executive format
  112. {
  113. $this->posxref-=20;
  114. $this->posxdate-=20;
  115. $this->posxsociete-=20;
  116. $this->posxamountht-=20;
  117. $this->posxamountttc-=20;
  118. $this->posstatut-=20;
  119. }
  120. }
  121. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  122. /**
  123. * Fonction generant le projet sur le disque
  124. *
  125. * @param Project $object Object project a generer
  126. * @param Translate $outputlangs Lang output object
  127. * @return int 1 if OK, <=0 if KO
  128. */
  129. public function write_file($object, $outputlangs)
  130. {
  131. // phpcs:enable
  132. global $conf, $hookmanager, $langs, $user;
  133. $formproject=new FormProjets($this->db);
  134. if (! is_object($outputlangs)) $outputlangs=$langs;
  135. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  136. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  137. // Load traductions files required by page
  138. $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
  139. if ($conf->projet->dir_output)
  140. {
  141. //$nblines = count($object->lines); // This is set later with array of tasks
  142. $objectref = dol_sanitizeFileName($object->ref);
  143. $dir = $conf->projet->dir_output;
  144. if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref;
  145. $file = $dir . "/" . $objectref . ".pdf";
  146. if (! file_exists($dir))
  147. {
  148. if (dol_mkdir($dir) < 0)
  149. {
  150. $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
  151. return 0;
  152. }
  153. }
  154. if (file_exists($dir))
  155. {
  156. // Add pdfgeneration hook
  157. if (! is_object($hookmanager))
  158. {
  159. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  160. $hookmanager=new HookManager($this->db);
  161. }
  162. $hookmanager->initHooks(array('pdfgeneration'));
  163. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  164. global $action;
  165. $reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  166. // Create pdf instance
  167. $pdf=pdf_getInstance($this->format);
  168. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  169. $pdf->SetAutoPageBreak(1, 0);
  170. $heightforinfotot = 40; // Height reserved to output the info and total part
  171. $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
  172. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  173. if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
  174. if (class_exists('TCPDF'))
  175. {
  176. $pdf->setPrintHeader(false);
  177. $pdf->setPrintFooter(false);
  178. }
  179. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  180. // Set path to the background PDF File
  181. if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  182. {
  183. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  184. $tplidx = $pdf->importPage(1);
  185. }
  186. // Complete object by loading several other informations
  187. $task = new Task($this->db);
  188. $tasksarray = array();
  189. $tasksarray = $task->getTasksArray(0, 0, $object->id);
  190. // Special case when used with object = specimen, we may return all lines
  191. if (! $object->id > 0) {
  192. $tasksarray=array_slice($tasksarray, 0, min(5, count($tasksarray)));
  193. }
  194. $object->lines=$tasksarray;
  195. $nblines=count($object->lines);
  196. $pdf->Open();
  197. $pagenb=0;
  198. $pdf->SetDrawColor(128, 128, 128);
  199. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  200. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  201. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  202. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  203. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  204. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  205. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  206. // New page
  207. $pdf->AddPage($this->orientation);
  208. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  209. $pagenb++;
  210. $this->_pagehead($pdf, $object, 1, $outputlangs);
  211. $pdf->SetFont('', '', $default_font_size - 1);
  212. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  213. $pdf->SetTextColor(0, 0, 0);
  214. $tab_top = 50;
  215. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  216. $tab_height = 170;
  217. $tab_height_newpage = 190;
  218. // Show public note
  219. $notetoshow=empty($object->note_public)?'':$object->note_public;
  220. if ($notetoshow)
  221. {
  222. $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
  223. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  224. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  225. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  226. $tab_top -= 2;
  227. $pdf->SetFont('', '', $default_font_size - 1);
  228. $pdf->writeHTMLCell(190, 3, $this->posxref-1, $tab_top-2, dol_htmlentitiesbr($notetoshow), 0, 1);
  229. $nexY = $pdf->GetY();
  230. $height_note=$nexY-$tab_top;
  231. // Rect takes a length in 3rd parameter
  232. $pdf->SetDrawColor(192, 192, 192);
  233. $pdf->Rect($this->marge_gauche, $tab_top-2, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+2);
  234. $tab_height = $tab_height - $height_note;
  235. $tab_top = $nexY+6;
  236. }
  237. else
  238. {
  239. $height_note=0;
  240. }
  241. $heightoftitleline = 10;
  242. $iniY = $tab_top + $heightoftitleline + 1;
  243. $curY = $tab_top + $heightoftitleline + 1;
  244. $nexY = $tab_top + $heightoftitleline + 1;
  245. $listofreferent=array(
  246. 'propal'=>array(
  247. 'name'=>"Proposals",
  248. 'title'=>"ListProposalsAssociatedProject",
  249. 'class'=>'Propal',
  250. 'table'=>'propal',
  251. 'datefieldname'=>'datep',
  252. 'test'=>$conf->propal->enabled && $user->rights->propale->lire,
  253. 'lang'=>'propal'),
  254. 'order'=>array(
  255. 'name'=>"CustomersOrders",
  256. 'title'=>"ListOrdersAssociatedProject",
  257. 'class'=>'Commande',
  258. 'table'=>'commande',
  259. 'datefieldname'=>'date_commande',
  260. 'test'=>$conf->commande->enabled && $user->rights->commande->lire,
  261. 'lang'=>'orders'),
  262. 'invoice'=>array(
  263. 'name'=>"CustomersInvoices",
  264. 'title'=>"ListInvoicesAssociatedProject",
  265. 'class'=>'Facture',
  266. 'margin'=>'add',
  267. 'table'=>'facture',
  268. 'datefieldname'=>'datef',
  269. 'test'=>$conf->facture->enabled && $user->rights->facture->lire,
  270. 'lang'=>'bills'),
  271. 'invoice_predefined'=>array(
  272. 'name'=>"PredefinedInvoices",
  273. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  274. 'class'=>'FactureRec',
  275. 'table'=>'facture_rec',
  276. 'datefieldname'=>'datec',
  277. 'test'=>$conf->facture->enabled && $user->rights->facture->lire,
  278. 'lang'=>'bills'),
  279. 'order_supplier'=>array(
  280. 'name'=>"SuppliersOrders",
  281. 'title'=>"ListSupplierOrdersAssociatedProject",
  282. 'class'=>'CommandeFournisseur',
  283. 'table'=>'commande_fournisseur',
  284. 'datefieldname'=>'date_commande',
  285. 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire,
  286. 'lang'=>'orders'),
  287. 'invoice_supplier'=>array(
  288. 'name'=>"BillsSuppliers",
  289. 'title'=>"ListSupplierInvoicesAssociatedProject",
  290. 'class'=>'FactureFournisseur',
  291. 'margin'=>'minus',
  292. 'table'=>'facture_fourn',
  293. 'datefieldname'=>'datef',
  294. 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire,
  295. 'lang'=>'bills'),
  296. 'contract'=>array(
  297. 'name'=>"Contracts",
  298. 'title'=>"ListContractAssociatedProject",
  299. 'class'=>'Contrat',
  300. 'table'=>'contrat',
  301. 'datefieldname'=>'date_contrat',
  302. 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire,
  303. 'lang'=>'contract'),
  304. 'intervention'=>array(
  305. 'name'=>"Interventions",
  306. 'title'=>"ListFichinterAssociatedProject",
  307. 'class'=>'Fichinter',
  308. 'table'=>'fichinter',
  309. 'datefieldname'=>'date_valid',
  310. 'disableamount'=>1,
  311. 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire,
  312. 'lang'=>'interventions'),
  313. 'trip'=>array(
  314. 'name'=>"TripsAndExpenses",
  315. 'title'=>"ListExpenseReportsAssociatedProject",
  316. 'class'=>'Deplacement',
  317. 'table'=>'deplacement',
  318. 'datefieldname'=>'dated',
  319. 'margin'=>'minus',
  320. 'disableamount'=>1,
  321. 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire,
  322. 'lang'=>'trip'),
  323. 'expensereport'=>array(
  324. 'name'=>"ExpensesReports",
  325. 'title'=>"ListExpenseReportsAssociatedProject",
  326. 'class'=>'ExpenseReport',
  327. 'table'=>'expensereport',
  328. 'datefieldname'=>'dated',
  329. 'margin'=>'minus',
  330. 'disableamount'=>1,
  331. 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire,
  332. 'lang'=>'trip'),
  333. 'agenda'=>array(
  334. 'name'=>"Agenda",
  335. 'title'=>"ListActionsAssociatedProject",
  336. 'class'=>'ActionComm',
  337. 'table'=>'actioncomm',
  338. 'datefieldname'=>'datep',
  339. 'disableamount'=>1,
  340. 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->read,
  341. 'lang'=>'agenda')
  342. );
  343. $hookmanager->initHooks(array('completeListOfReferent'));
  344. $hookmanager->executeHooks('completeListOfReferent', ['listofreferent'=>$listofreferent], $object, $action);
  345. if(!empty($hookmanager->resArray)) {
  346. $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
  347. }
  348. foreach ($listofreferent as $key => $value)
  349. {
  350. $title=$value['title'];
  351. $classname=$value['class'];
  352. $tablename=$value['table'];
  353. $datefieldname=$value['datefieldname'];
  354. $qualified=$value['test'];
  355. $langstoload=$value['lang'];
  356. $projectField=isset($value['project_field']) ? $value['project_field'] : 'fk_projet';
  357. $langs->load($langstoload);
  358. if (! $qualified) continue;
  359. //var_dump("$key, $tablename, $datefieldname, $dates, $datee");
  360. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, $projectField);
  361. $num = count($elementarray);
  362. if ($num >= 0)
  363. {
  364. $nexY = $pdf->GetY() + 5;
  365. $curY = $nexY;
  366. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  367. $pdf->SetTextColor(0, 0, 0);
  368. $pdf->SetXY($this->posxref, $curY);
  369. $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L');
  370. $selectList = $formproject->select_element($tablename, $project->thirdparty->id, '', -2, $projectField);
  371. $nexY = $pdf->GetY() + 1;
  372. $curY = $nexY;
  373. $pdf->SetXY($this->posxref, $curY);
  374. $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L');
  375. $pdf->SetXY($this->posxdate, $curY);
  376. $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C');
  377. $pdf->SetXY($this->posxsociety, $curY);
  378. $titlethirdparty=$outputlangs->transnoentities("ThirdParty");
  379. if ($classname == 'ExpenseReport') $titlethirdparty=$langs->trans("User");
  380. $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1, 'L');
  381. if (empty($value['disableamount'])) {
  382. $pdf->SetXY($this->posxamountht, $curY);
  383. $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHTShort"), 1, 'R');
  384. $pdf->SetXY($this->posxamountttc, $curY);
  385. $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTCShort"), 1, 'R');
  386. } else {
  387. $pdf->SetXY($this->posxamountht, $curY);
  388. $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
  389. }
  390. $pdf->SetXY($this->posxstatut, $curY);
  391. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Status"), 1, 'R');
  392. if (is_array($elementarray) && count($elementarray) > 0)
  393. {
  394. $nexY = $pdf->GetY();
  395. $total_ht = 0;
  396. $total_ttc = 0;
  397. $num = count($elementarray);
  398. // Loop on each lines
  399. for ($i = 0; $i < $num; $i ++)
  400. {
  401. $curY = $nexY;
  402. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  403. $pdf->SetTextColor(0, 0, 0);
  404. $pdf->setTopMargin($tab_top_newpage);
  405. $pdf->setPageOrientation($this->orientation, 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  406. $pageposbefore=$pdf->getPage();
  407. // Description of line
  408. $idofelement=$elementarray[$i];
  409. if ($classname == 'ExpenseReport')
  410. {
  411. // We get id of expense report
  412. $expensereportline=new ExpenseReportLine($this->db);
  413. $expensereportline->fetch($idofelement);
  414. $idofelement = $expensereportline->fk_expensereport;
  415. }
  416. $element = new $classname($this->db);
  417. $element->fetch($idofelement);
  418. $element->fetch_thirdparty();
  419. // print $classname;
  420. $qualifiedfortotal = true;
  421. if ($key == 'invoice') {
  422. if ($element->close_code == 'replaced')
  423. $qualifiedfortotal = false; // Replacement invoice
  424. }
  425. $showpricebeforepagebreak=1;
  426. $pdf->startTransaction();
  427. // Label
  428. $pdf->SetXY($this->posxref, $curY);
  429. $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
  430. $pageposafter=$pdf->getPage();
  431. if ($pageposafter > $pageposbefore) // There is a pagebreak
  432. {
  433. $pdf->rollbackTransaction(true);
  434. $pageposafter=$pageposbefore;
  435. //print $pageposafter.'-'.$pageposbefore;exit;
  436. $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  437. // Label
  438. $pdf->SetXY($this->posxref, $curY);
  439. $posybefore=$pdf->GetY();
  440. $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
  441. $pageposafter=$pdf->getPage();
  442. $posyafter=$pdf->GetY();
  443. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  444. {
  445. if ($i == ($num-1)) // No more lines, and no space left to show total, so we create a new page
  446. {
  447. $pdf->AddPage($this->orientation, '', true);
  448. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  449. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  450. $pdf->setPage($pageposafter+1);
  451. }
  452. }
  453. else
  454. {
  455. // We found a page break
  456. $showpricebeforepagebreak=0;
  457. $forcedesconsamepage=1;
  458. if ($forcedesconsamepage)
  459. {
  460. $pdf->rollbackTransaction(true);
  461. $pageposafter=$pageposbefore;
  462. $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  463. $pdf->AddPage($this->orientation, '', true);
  464. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  465. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  466. $pdf->setPage($pageposafter+1);
  467. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  468. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  469. $pdf->SetTextColor(0, 0, 0);
  470. $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  471. $curY = $tab_top_newpage + $heightoftitleline + 1;
  472. // Label
  473. $pdf->SetXY($this->posxref, $curY);
  474. $posybefore=$pdf->GetY();
  475. $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
  476. $pageposafter=$pdf->getPage();
  477. $posyafter=$pdf->GetY();
  478. }
  479. }
  480. //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
  481. }
  482. else // No pagebreak
  483. {
  484. $pdf->commitTransaction();
  485. }
  486. $posYAfterDescription=$pdf->GetY();
  487. $nexY = $pdf->GetY();
  488. $pageposafter=$pdf->getPage();
  489. $pdf->setPage($pageposbefore);
  490. $pdf->setTopMargin($this->marge_haute);
  491. $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it.
  492. // We suppose that a too long description is moved completely on next page
  493. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  494. //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
  495. $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1;
  496. }
  497. $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
  498. // Date
  499. if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order')
  500. $date = $element->date_commande;
  501. else {
  502. $date = $element->date;
  503. if (empty($date))
  504. $date = $element->datep;
  505. if (empty($date))
  506. $date = $element->date_contrat;
  507. if (empty($date))
  508. $date = $element->datev; // Fiche inter
  509. }
  510. $pdf->SetXY($this->posxdate, $curY);
  511. $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C');
  512. $pdf->SetXY($this->posxsociety, $curY);
  513. if ($classname == 'ExpenseReport')
  514. {
  515. $fuser=new User($this->db);
  516. $fuser->fetch($element->fk_user_author);
  517. $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1, 'L');
  518. }
  519. else
  520. {
  521. $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty)?$element->thirdparty->name:''), 1, 'L');
  522. }
  523. // Amount without tax
  524. if (empty($value['disableamount'])) {
  525. $pdf->SetXY($this->posxamountht, $curY);
  526. $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($element->total_ht) : ''), 1, 'R');
  527. $pdf->SetXY($this->posxamountttc, $curY);
  528. $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($element->total_ttc) : ''), 1, 'R');
  529. } else {
  530. $pdf->SetXY($this->posxamountht, $curY);
  531. if ($key == 'agenda')
  532. {
  533. $textforamount = dol_trunc($element->label, 26);
  534. $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1, 'L');
  535. }
  536. else
  537. {
  538. $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
  539. }
  540. }
  541. // Status
  542. if ($element instanceof CommonInvoice) {
  543. // This applies for Facture and FactureFournisseur
  544. $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
  545. } else {
  546. $outputstatut = $element->getLibStatut(1);
  547. }
  548. $pdf->SetXY($this->posxstatut, $curY);
  549. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true);
  550. if ($qualifiedfortotal) {
  551. $total_ht = $total_ht + $element->total_ht;
  552. $total_ttc = $total_ttc + $element->total_ttc;
  553. }
  554. $nexY = $pdf->GetY();
  555. $curY = $nexY;
  556. }
  557. if (empty($value['disableamount'])) {
  558. $curY = $nexY;
  559. $pdf->SetXY($this->posxref, $curY);
  560. $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L');
  561. $pdf->SetXY($this->posxamountht, $curY);
  562. $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($total_ht) : ''), 1, 'R');
  563. $pdf->SetXY($this->posxamountttc, $curY);
  564. $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($total_ttc) : ''), 1, 'R');
  565. $pdf->SetXY($this->posxstatut, $curY);
  566. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb") . " " . $num, 1, 'L');
  567. }
  568. $nexY = $pdf->GetY() + 5;
  569. $curY = $nexY;
  570. }
  571. }
  572. $nexY+=2; // Add space between lines
  573. // Detect if some page were added automatically and output _tableau for past pages
  574. while ($pagenb < $pageposafter)
  575. {
  576. $pdf->setPage($pagenb);
  577. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  578. $pagenb++;
  579. $pdf->setPage($pagenb);
  580. $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it.
  581. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  582. }
  583. }
  584. // Pied de page
  585. $this->_pagefoot($pdf, $object, $outputlangs);
  586. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  587. $pdf->Close();
  588. $pdf->Output($file, 'F');
  589. // Add pdfgeneration hook
  590. $hookmanager->initHooks(array('pdfgeneration'));
  591. $parameters=array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  592. global $action;
  593. $reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  594. if ($reshook < 0)
  595. {
  596. $this->error = $hookmanager->error;
  597. $this->errors = $hookmanager->errors;
  598. }
  599. if (! empty($conf->global->MAIN_UMASK))
  600. @chmod($file, octdec($conf->global->MAIN_UMASK));
  601. $this->result = array('fullpath'=>$file);
  602. return 1; // No error
  603. }
  604. else
  605. {
  606. $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
  607. return 0;
  608. }
  609. }
  610. else
  611. {
  612. $this->error=$langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR");
  613. return 0;
  614. }
  615. }
  616. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  617. /**
  618. * Show table for lines
  619. *
  620. * @param PDF $pdf Object PDF
  621. * @param string $tab_top Top position of table
  622. * @param string $tab_height Height of table (rectangle)
  623. * @param int $nexY Y
  624. * @param Translate $outputlangs Langs object
  625. * @param int $hidetop Hide top bar of array
  626. * @param int $hidebottom Hide bottom bar of array
  627. * @return void
  628. */
  629. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  630. {
  631. global $conf,$mysoc;
  632. $heightoftitleline = 10;
  633. $default_font_size = pdf_getPDFFontSize($outputlangs);
  634. $pdf->SetDrawColor(128, 128, 128);
  635. // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter
  636. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  637. // line prend une position y en 3eme param
  638. $pdf->line($this->marge_gauche, $tab_top+$heightoftitleline, $this->page_largeur-$this->marge_droite, $tab_top+$heightoftitleline);
  639. $pdf->SetTextColor(0, 0, 0);
  640. $pdf->SetFont('', '', $default_font_size);
  641. $pdf->SetXY($this->posxref, $tab_top+1);
  642. $pdf->MultiCell($this->posxlabel-$this->posxref, 3, $outputlangs->transnoentities("Tasks"), '', 'L');
  643. $pdf->SetXY($this->posxlabel, $tab_top+1);
  644. $pdf->MultiCell($this->posxworkload-$this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
  645. $pdf->SetXY($this->posxworkload, $tab_top+1);
  646. $pdf->MultiCell($this->posxprogress-$this->posxworkload, 3, $outputlangs->transnoentities("PlannedWorkloadShort"), 0, 'R');
  647. $pdf->SetXY($this->posxprogress, $tab_top+1);
  648. $pdf->MultiCell($this->posxdatestart-$this->posxprogress, 3, '%', 0, 'R');
  649. $pdf->SetXY($this->posxdatestart, $tab_top+1);
  650. $pdf->MultiCell($this->posxdateend-$this->posxdatestart, 3, '', 0, 'C');
  651. $pdf->SetXY($this->posxdateend, $tab_top+1);
  652. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdatestart, 3, '', 0, 'C');
  653. }
  654. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  655. /**
  656. * Show top header of page.
  657. *
  658. * @param PDF $pdf Object PDF
  659. * @param Project $object Object to show
  660. * @param int $showaddress 0=no, 1=yes
  661. * @param Translate $outputlangs Object lang for output
  662. * @return void
  663. */
  664. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  665. {
  666. global $langs,$conf,$mysoc;
  667. $default_font_size = pdf_getPDFFontSize($outputlangs);
  668. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  669. $pdf->SetTextColor(0, 0, 60);
  670. $pdf->SetFont('', 'B', $default_font_size + 3);
  671. $posx=$this->page_largeur-$this->marge_droite-100;
  672. $posy=$this->marge_haute;
  673. $pdf->SetXY($this->marge_gauche, $posy);
  674. // Logo
  675. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  676. if ($mysoc->logo)
  677. {
  678. if (is_readable($logo))
  679. {
  680. $height=pdf_getHeightForLogo($logo);
  681. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  682. }
  683. else
  684. {
  685. $pdf->SetTextColor(200, 0, 0);
  686. $pdf->SetFont('', 'B', $default_font_size - 2);
  687. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  688. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  689. }
  690. }
  691. else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  692. $pdf->SetFont('', 'B', $default_font_size + 3);
  693. $pdf->SetXY($posx, $posy);
  694. $pdf->SetTextColor(0, 0, 60);
  695. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  696. $pdf->SetFont('', '', $default_font_size + 2);
  697. $posy+=6;
  698. $pdf->SetXY($posx, $posy);
  699. $pdf->SetTextColor(0, 0, 60);
  700. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : " . dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
  701. $posy+=6;
  702. $pdf->SetXY($posx, $posy);
  703. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
  704. if (is_object($object->thirdparty))
  705. {
  706. $posy+=6;
  707. $pdf->SetXY($posx, $posy);
  708. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : " . $object->thirdparty->getFullName($outputlangs), '', 'R');
  709. }
  710. $pdf->SetTextColor(0, 0, 60);
  711. }
  712. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  713. /**
  714. * Show footer of page. Need this->emetteur object
  715. *
  716. * @param PDF $pdf PDF
  717. * @param Project $object Object to show
  718. * @param Translate $outputlangs Object lang for output
  719. * @param int $hidefreetext 1=Hide free text
  720. * @return integer
  721. */
  722. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  723. {
  724. global $conf;
  725. $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  726. return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  727. }
  728. }