dolibarr  13.0.2
pdf_beluga.modules.php
Go to the documentation of this file.
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 
27 require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36 
37 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
48 
49 
50 
56 {
61  private $orientation = '';
62 
67  public $emetteur;
68 
74  public function __construct($db)
75  {
76  global $conf, $langs, $mysoc;
77 
78  // Translations
79  $langs->loadLangs(array("main", "projects", "companies"));
80 
81  $this->db = $db;
82  $this->name = "beluga";
83  $this->description = $langs->trans("DocumentModelBeluga");
84 
85  // Page size for A4 format
86  $this->type = 'pdf';
87  $formatarray = pdf_getFormat();
88  $this->orientation = 'L';
89  if ($this->orientation == 'L' || $this->orientation == 'Landscape') {
90  $this->page_largeur = $formatarray['height'];
91  $this->page_hauteur = $formatarray['width'];
92  } else {
93  $this->page_largeur = $formatarray['width'];
94  $this->page_hauteur = $formatarray['height'];
95  }
96  $this->format = array($this->page_largeur, $this->page_hauteur);
97  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
98  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
99  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
100  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
101 
102  $this->option_logo = 1; // Display logo FAC_PDF_LOGO
103  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
104  $this->option_codeproduitservice = 1; // Display product-service code
105 
106  // Get source company
107  $this->emetteur = $mysoc;
108  if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
109 
110  // Define position of columns
111  if ($this->orientation == 'L' || $this->orientation == 'Landscape') {
112  $this->posxref = $this->marge_gauche + 1;
113  $this->posxdate = $this->marge_gauche + 105;
114  $this->posxsociety = $this->marge_gauche + 126;
115  $this->posxamountht = $this->marge_gauche + 190;
116  $this->posxamountttc = $this->marge_gauche + 215;
117  $this->posxstatut = $this->marge_gauche + 245;
118  } else {
119  $this->posxref = $this->marge_gauche + 1;
120  $this->posxdate = $this->marge_gauche + 25;
121  $this->posxsociety = $this->marge_gauche + 46;
122  $this->posxamountht = $this->marge_gauche + 110;
123  $this->posxamountttc = $this->marge_gauche + 135;
124  $this->posxstatut = $this->marge_gauche + 165;
125  }
126  if ($this->page_largeur < 210) // To work with US executive format
127  {
128  $this->posxref -= 20;
129  $this->posxdate -= 20;
130  $this->posxsociete -= 20;
131  $this->posxamountht -= 20;
132  $this->posxamountttc -= 20;
133  $this->posstatut -= 20;
134  }
135  }
136 
137 
138  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
146  public function write_file($object, $outputlangs)
147  {
148  // phpcs:enable
149  global $conf, $hookmanager, $langs, $user;
150 
151  $formproject = new FormProjets($this->db);
152 
153  if (!is_object($outputlangs)) $outputlangs = $langs;
154  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
155  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
156 
157  // Load traductions files required by page
158  $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
159 
160  if ($conf->projet->dir_output)
161  {
162  //$nblines = count($object->lines); // This is set later with array of tasks
163 
164  $objectref = dol_sanitizeFileName($object->ref);
165  $dir = $conf->projet->dir_output;
166  if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
167  $file = $dir."/".$objectref.".pdf";
168 
169  if (!file_exists($dir))
170  {
171  if (dol_mkdir($dir) < 0)
172  {
173  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
174  return 0;
175  }
176  }
177 
178  if (file_exists($dir))
179  {
180  // Add pdfgeneration hook
181  if (!is_object($hookmanager))
182  {
183  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
184  $hookmanager = new HookManager($this->db);
185  }
186  $hookmanager->initHooks(array('pdfgeneration'));
187  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
188  global $action;
189  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
190 
191  // Create pdf instance
192  $pdf = pdf_getInstance($this->format);
193  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
194  $pdf->SetAutoPageBreak(1, 0);
195 
196  $heightforinfotot = 40; // Height reserved to output the info and total part
197  $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
198  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
199  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
200 
201  if (class_exists('TCPDF'))
202  {
203  $pdf->setPrintHeader(false);
204  $pdf->setPrintFooter(false);
205  }
206  $pdf->SetFont(pdf_getPDFFont($outputlangs));
207  // Set path to the background PDF File
208  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
209  {
210  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
211  $tplidx = $pdf->importPage(1);
212  }
213 
214  // Complete object by loading several other informations
215  $task = new Task($this->db);
216  $tasksarray = array();
217  $tasksarray = $task->getTasksArray(0, 0, $object->id);
218 
219  // Special case when used with object = specimen, we may return all lines
220  if (!$object->id > 0) {
221  $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
222  }
223 
224  $object->lines = $tasksarray;
225  $nblines = count($object->lines);
226 
227  $pdf->Open();
228  $pagenb = 0;
229  $pdf->SetDrawColor(128, 128, 128);
230 
231  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
232  $pdf->SetSubject($outputlangs->transnoentities("Project"));
233  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
234  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
235  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
236  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
237 
238  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
239 
240  // New page
241  $pdf->AddPage($this->orientation);
242  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
243  $pagenb++;
244  $this->_pagehead($pdf, $object, 1, $outputlangs);
245  $pdf->SetFont('', '', $default_font_size - 1);
246  $pdf->MultiCell(0, 3, ''); // Set interline to 3
247  $pdf->SetTextColor(0, 0, 0);
248 
249  $tab_top = 50;
250  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
251  $tab_height = 170;
252  $tab_height_newpage = 190;
253 
254  // Show public note
255  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
256  if ($notetoshow)
257  {
258  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
259  complete_substitutions_array($substitutionarray, $outputlangs, $object);
260  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
261  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
262 
263  $tab_top -= 2;
264 
265  $pdf->SetFont('', '', $default_font_size - 1);
266  $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1);
267  $nexY = $pdf->GetY();
268  $height_note = $nexY - $tab_top;
269 
270  // Rect takes a length in 3rd parameter
271  $pdf->SetDrawColor(192, 192, 192);
272  $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
273 
274  $tab_height = $tab_height - $height_note;
275  $tab_top = $nexY + 6;
276  } else {
277  $height_note = 0;
278  }
279 
280  $heightoftitleline = 10;
281  $iniY = $tab_top + $heightoftitleline + 1;
282  $curY = $tab_top + $heightoftitleline + 1;
283  $nexY = $tab_top + $heightoftitleline + 1;
284 
285  $listofreferent = array(
286  'propal'=>array(
287  'name'=>"Proposals",
288  'title'=>"ListProposalsAssociatedProject",
289  'class'=>'Propal',
290  'table'=>'propal',
291  'datefieldname'=>'datep',
292  'test'=>$conf->propal->enabled && $user->rights->propale->lire,
293  'lang'=>'propal'),
294  'order'=>array(
295  'name'=>"CustomersOrders",
296  'title'=>"ListOrdersAssociatedProject",
297  'class'=>'Commande',
298  'table'=>'commande',
299  'datefieldname'=>'date_commande',
300  'test'=>$conf->commande->enabled && $user->rights->commande->lire,
301  'lang'=>'orders'),
302  'invoice'=>array(
303  'name'=>"CustomersInvoices",
304  'title'=>"ListInvoicesAssociatedProject",
305  'class'=>'Facture',
306  'margin'=>'add',
307  'table'=>'facture',
308  'datefieldname'=>'datef',
309  'test'=>$conf->facture->enabled && $user->rights->facture->lire,
310  'lang'=>'bills'),
311  'invoice_predefined'=>array(
312  'name'=>"PredefinedInvoices",
313  'title'=>"ListPredefinedInvoicesAssociatedProject",
314  'class'=>'FactureRec',
315  'table'=>'facture_rec',
316  'datefieldname'=>'datec',
317  'test'=>$conf->facture->enabled && $user->rights->facture->lire,
318  'lang'=>'bills'),
319  'order_supplier'=>array(
320  'name'=>"SuppliersOrders",
321  'title'=>"ListSupplierOrdersAssociatedProject",
322  'class'=>'CommandeFournisseur',
323  'table'=>'commande_fournisseur',
324  'datefieldname'=>'date_commande',
325  'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire,
326  'lang'=>'orders'),
327  'invoice_supplier'=>array(
328  'name'=>"BillsSuppliers",
329  'title'=>"ListSupplierInvoicesAssociatedProject",
330  'class'=>'FactureFournisseur',
331  'margin'=>'minus',
332  'table'=>'facture_fourn',
333  'datefieldname'=>'datef',
334  'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire,
335  'lang'=>'bills'),
336  'contract'=>array(
337  'name'=>"Contracts",
338  'title'=>"ListContractAssociatedProject",
339  'class'=>'Contrat',
340  'table'=>'contrat',
341  'datefieldname'=>'date_contrat',
342  'test'=>$conf->contrat->enabled && $user->rights->contrat->lire,
343  'lang'=>'contract'),
344  'intervention'=>array(
345  'name'=>"Interventions",
346  'title'=>"ListFichinterAssociatedProject",
347  'class'=>'Fichinter',
348  'table'=>'fichinter',
349  'datefieldname'=>'date_valid',
350  'disableamount'=>1,
351  'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire,
352  'lang'=>'interventions'),
353  'trip'=>array(
354  'name'=>"TripsAndExpenses",
355  'title'=>"ListExpenseReportsAssociatedProject",
356  'class'=>'Deplacement',
357  'table'=>'deplacement',
358  'datefieldname'=>'dated',
359  'margin'=>'minus',
360  'disableamount'=>1,
361  'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire,
362  'lang'=>'trip'),
363  'expensereport'=>array(
364  'name'=>"ExpensesReports",
365  'title'=>"ListExpenseReportsAssociatedProject",
366  'class'=>'ExpenseReport',
367  'table'=>'expensereport',
368  'datefieldname'=>'dated',
369  'margin'=>'minus',
370  'disableamount'=>1,
371  'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire,
372  'lang'=>'trip'),
373  'agenda'=>array(
374  'name'=>"Agenda",
375  'title'=>"ListActionsAssociatedProject",
376  'class'=>'ActionComm',
377  'table'=>'actioncomm',
378  'datefieldname'=>'datep',
379  'disableamount'=>1,
380  'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->read,
381  'lang'=>'agenda')
382  );
383 
384  $hookmanager->initHooks(array('completeListOfReferent'));
385  $hookmanager->executeHooks('completeListOfReferent', ['listofreferent'=>$listofreferent], $object, $action);
386  if (!empty($hookmanager->resArray)) {
387  $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
388  }
389 
390  foreach ($listofreferent as $key => $value)
391  {
392  $title = $value['title'];
393  $classname = $value['class'];
394  $tablename = $value['table'];
395  $datefieldname = $value['datefieldname'];
396  $qualified = $value['test'];
397  $langstoload = $value['lang'];
398  $projectField = isset($value['project_field']) ? $value['project_field'] : 'fk_projet';
399  $langs->load($langstoload);
400 
401  if (!$qualified) continue;
402 
403  //var_dump("$key, $tablename, $datefieldname, $dates, $datee");
404  $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, $projectField);
405 
406  $num = count($elementarray);
407  if ($num >= 0)
408  {
409  $nexY = $pdf->GetY() + 5;
410 
411  $curY = $nexY;
412  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
413  $pdf->SetTextColor(0, 0, 0);
414 
415  $pdf->SetXY($this->posxref, $curY);
416  $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L');
417 
418  $selectList = $formproject->select_element($tablename, $project->thirdparty->id, '', -2, $projectField);
419  $nexY = $pdf->GetY() + 1;
420  $curY = $nexY;
421  $pdf->SetXY($this->posxref, $curY);
422  $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L');
423  $pdf->SetXY($this->posxdate, $curY);
424  $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C');
425  $pdf->SetXY($this->posxsociety, $curY);
426  $titlethirdparty = $outputlangs->transnoentities("ThirdParty");
427  if ($classname == 'ExpenseReport') $titlethirdparty = $langs->trans("User");
428  $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1, 'L');
429  if (empty($value['disableamount'])) {
430  $pdf->SetXY($this->posxamountht, $curY);
431  $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHTShort"), 1, 'R');
432  $pdf->SetXY($this->posxamountttc, $curY);
433  $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTCShort"), 1, 'R');
434  } else {
435  $pdf->SetXY($this->posxamountht, $curY);
436  $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
437  }
438  $pdf->SetXY($this->posxstatut, $curY);
439  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Status"), 1, 'R');
440 
441  if (is_array($elementarray) && count($elementarray) > 0)
442  {
443  $nexY = $pdf->GetY();
444 
445  $total_ht = 0;
446  $total_ttc = 0;
447  $num = count($elementarray);
448 
449  // Loop on each lines
450  for ($i = 0; $i < $num; $i++)
451  {
452  $curY = $nexY;
453  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
454  $pdf->SetTextColor(0, 0, 0);
455 
456  $pdf->setTopMargin($tab_top_newpage);
457  $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
458  $pageposbefore = $pdf->getPage();
459 
460  // Description of line
461  $idofelement = $elementarray[$i];
462  if ($classname == 'ExpenseReport')
463  {
464  // We get id of expense report
465  $expensereportline = new ExpenseReportLine($this->db);
466  $expensereportline->fetch($idofelement);
467  $idofelement = $expensereportline->fk_expensereport;
468  }
469 
470  $element = new $classname($this->db);
471  $element->fetch($idofelement);
472  $element->fetch_thirdparty();
473  // print $classname;
474 
475  $qualifiedfortotal = true;
476  if ($key == 'invoice') {
477  if ($element->close_code == 'replaced')
478  $qualifiedfortotal = false; // Replacement invoice
479  }
480 
481  $showpricebeforepagebreak = 1;
482 
483  $pdf->startTransaction();
484  // Label
485  $pdf->SetXY($this->posxref, $curY);
486  $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
487  $pageposafter = $pdf->getPage();
488  if ($pageposafter > $pageposbefore) // There is a pagebreak
489  {
490  $pdf->rollbackTransaction(true);
491  $pageposafter = $pageposbefore;
492  //print $pageposafter.'-'.$pageposbefore;exit;
493  $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
494  // Label
495  $pdf->SetXY($this->posxref, $curY);
496  $posybefore = $pdf->GetY();
497  $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
498  $pageposafter = $pdf->getPage();
499  $posyafter = $pdf->GetY();
500  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text
501  {
502  if ($i == ($num - 1)) // No more lines, and no space left to show total, so we create a new page
503  {
504  $pdf->AddPage($this->orientation, '', true);
505  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
506  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
507  $pdf->setPage($pageposafter + 1);
508  }
509  } else {
510  // We found a page break
511 
512  // Allows data in the first page if description is long enough to break in multiples pages
513  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
514  $showpricebeforepagebreak = 1;
515  else $showpricebeforepagebreak = 0;
516 
517  $forcedesconsamepage = 1;
518  if ($forcedesconsamepage)
519  {
520  $pdf->rollbackTransaction(true);
521  $pageposafter = $pageposbefore;
522  $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
523 
524  $pdf->AddPage($this->orientation, '', true);
525  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
526  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
527  $pdf->setPage($pageposafter + 1);
528  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
529  $pdf->MultiCell(0, 3, ''); // Set interline to 3
530  $pdf->SetTextColor(0, 0, 0);
531 
532  $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
533  $curY = $tab_top_newpage + $heightoftitleline + 1;
534 
535  // Label
536  $pdf->SetXY($this->posxref, $curY);
537  $posybefore = $pdf->GetY();
538  $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
539  $pageposafter = $pdf->getPage();
540  $posyafter = $pdf->GetY();
541  }
542  }
543  //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak);
544  } else // No pagebreak
545  {
546  $pdf->commitTransaction();
547  }
548  $posYAfterDescription = $pdf->GetY();
549 
550  $nexY = $pdf->GetY();
551  $pageposafter = $pdf->getPage();
552  $pdf->setPage($pageposbefore);
553  $pdf->setTopMargin($this->marge_haute);
554  $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it.
555 
556  // We suppose that a too long description is moved completely on next page
557  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
558  //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak);
559  $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1;
560  }
561 
562  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
563 
564  // Date
565  if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order')
566  $date = $element->date_commande;
567  else {
568  $date = $element->date;
569  if (empty($date))
570  $date = $element->datep;
571  if (empty($date))
572  $date = $element->date_contrat;
573  if (empty($date))
574  $date = $element->datev; // Fiche inter
575  }
576 
577  $pdf->SetXY($this->posxdate, $curY);
578  $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C');
579 
580  $pdf->SetXY($this->posxsociety, $curY);
581  if ($classname == 'ExpenseReport')
582  {
583  $fuser = new User($this->db);
584  $fuser->fetch($element->fk_user_author);
585  $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1, 'L');
586  } else {
587  $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name : ''), 1, 'L');
588  }
589 
590  // Amount without tax
591  if (empty($value['disableamount'])) {
592  $pdf->SetXY($this->posxamountht, $curY);
593  $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($element->total_ht) : ''), 1, 'R');
594  $pdf->SetXY($this->posxamountttc, $curY);
595  $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($element->total_ttc) : ''), 1, 'R');
596  } else {
597  $pdf->SetXY($this->posxamountht, $curY);
598  if ($key == 'agenda')
599  {
600  $textforamount = dol_trunc($element->label, 26);
601  $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1, 'L');
602  } else {
603  $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
604  }
605  }
606 
607  // Status
608  if ($element instanceof CommonInvoice) {
609  // This applies for Facture and FactureFournisseur
610  $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
611  } else {
612  $outputstatut = $element->getLibStatut(1);
613  }
614  $pdf->SetXY($this->posxstatut, $curY);
615  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true);
616 
617  if ($qualifiedfortotal) {
618  $total_ht = $total_ht + $element->total_ht;
619  $total_ttc = $total_ttc + $element->total_ttc;
620  }
621  $nexY = $pdf->GetY();
622  $curY = $nexY;
623  }
624 
625  if (empty($value['disableamount'])) {
626  $curY = $nexY;
627  $pdf->SetXY($this->posxref, $curY);
628  $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L');
629  $pdf->SetXY($this->posxamountht, $curY);
630  $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($total_ht) : ''), 1, 'R');
631  $pdf->SetXY($this->posxamountttc, $curY);
632  $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($total_ttc) : ''), 1, 'R');
633  $pdf->SetXY($this->posxstatut, $curY);
634  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb")." ".$num, 1, 'L');
635  }
636  $nexY = $pdf->GetY() + 5;
637  $curY = $nexY;
638  }
639  }
640 
641  $nexY += 2; // Add space between lines
642 
643  // Detect if some page were added automatically and output _tableau for past pages
644  while ($pagenb < $pageposafter)
645  {
646  $pdf->setPage($pagenb);
647  $this->_pagefoot($pdf, $object, $outputlangs, 1);
648  $pagenb++;
649  $pdf->setPage($pagenb);
650  $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it.
651  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
652  }
653  }
654 
655  // Pied de page
656  $this->_pagefoot($pdf, $object, $outputlangs);
657  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
658 
659  $pdf->Close();
660 
661  $pdf->Output($file, 'F');
662 
663  // Add pdfgeneration hook
664  $hookmanager->initHooks(array('pdfgeneration'));
665  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
666  global $action;
667  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
668  if ($reshook < 0)
669  {
670  $this->error = $hookmanager->error;
671  $this->errors = $hookmanager->errors;
672  }
673 
674  if (!empty($conf->global->MAIN_UMASK))
675  @chmod($file, octdec($conf->global->MAIN_UMASK));
676 
677  $this->result = array('fullpath'=>$file);
678 
679  return 1; // No error
680  } else {
681  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
682  return 0;
683  }
684  } else {
685  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR");
686  return 0;
687  }
688  }
689 
690  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
703  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
704  {
705  global $conf, $mysoc;
706 
707  $heightoftitleline = 10;
708 
709  $default_font_size = pdf_getPDFFontSize($outputlangs);
710 
711  $pdf->SetDrawColor(128, 128, 128);
712 
713  // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter
714  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
715 
716  // line prend une position y en 3eme param
717  $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline);
718 
719  $pdf->SetTextColor(0, 0, 0);
720  $pdf->SetFont('', '', $default_font_size);
721 
722  $pdf->SetXY($this->posxref, $tab_top + 1);
723  $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->transnoentities("Tasks"), '', 'L');
724 
725  $pdf->SetXY($this->posxlabel, $tab_top + 1);
726  $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L');
727 
728  $pdf->SetXY($this->posxworkload, $tab_top + 1);
729  $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $outputlangs->transnoentities("PlannedWorkloadShort"), 0, 'R');
730 
731  $pdf->SetXY($this->posxprogress, $tab_top + 1);
732  $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, '%', 0, 'R');
733 
734  $pdf->SetXY($this->posxdatestart, $tab_top + 1);
735  $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, '', 0, 'C');
736 
737  $pdf->SetXY($this->posxdateend, $tab_top + 1);
738  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdatestart, 3, '', 0, 'C');
739  }
740 
741  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
751  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
752  {
753  global $langs, $conf, $mysoc;
754 
755  $default_font_size = pdf_getPDFFontSize($outputlangs);
756 
757  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
758 
759  $pdf->SetTextColor(0, 0, 60);
760  $pdf->SetFont('', 'B', $default_font_size + 3);
761 
762  $posx = $this->page_largeur - $this->marge_droite - 100;
763  $posy = $this->marge_haute;
764 
765  $pdf->SetXY($this->marge_gauche, $posy);
766 
767  // Logo
768  $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
769  if ($mysoc->logo)
770  {
771  if (is_readable($logo))
772  {
773  $height = pdf_getHeightForLogo($logo);
774  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
775  } else {
776  $pdf->SetTextColor(200, 0, 0);
777  $pdf->SetFont('', 'B', $default_font_size - 2);
778  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
779  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
780  }
781  } else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
782 
783  $pdf->SetFont('', 'B', $default_font_size + 3);
784  $pdf->SetXY($posx, $posy);
785  $pdf->SetTextColor(0, 0, 60);
786  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
787  $pdf->SetFont('', '', $default_font_size + 2);
788 
789  $posy += 6;
790  $pdf->SetXY($posx, $posy);
791  $pdf->SetTextColor(0, 0, 60);
792  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : ".dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R');
793 
794  $posy += 6;
795  $pdf->SetXY($posx, $posy);
796  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : ".dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R');
797 
798  if (is_object($object->thirdparty))
799  {
800  $posy += 6;
801  $pdf->SetXY($posx, $posy);
802  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty")." : ".$object->thirdparty->getFullName($outputlangs), '', 'R');
803  }
804 
805  $pdf->SetTextColor(0, 0, 60);
806  }
807 
808  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
818  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
819  {
820  global $conf;
821  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
822  return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
823  }
824 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:620
Class of expense report details lines.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
Class to manage generation of project document Beluga.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:222
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage hooks.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Parent class for projects models.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:887
Class to manage building of HTML components.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:270
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
Superclass for invoices classes.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:643
__construct($db)
Constructor.
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
Definition: pdf.lib.php:88
Class to manage tasks.
Definition: task.class.php:35
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
write_file($object, $outputlangs)
Fonction generant le projet sur le disque.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the &quot;subst...