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