224 global $conf, $hookmanager, $langs, $user;
228 if (!is_object($outputlangs)) {
229 $outputlangs = $langs;
232 if (!empty($conf->global->MAIN_USE_FPDF)) {
233 $outputlangs->charset_output =
'ISO-8859-1';
237 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
239 if ($conf->project->multidir_output[$object->entity]) {
243 $dir = $conf->project->multidir_output[$object->entity];
244 if (!preg_match(
'/specimen/i', $objectref)) {
245 $dir .=
"/".$objectref;
247 $file = $dir.
"/".$objectref.
".pdf";
249 if (!file_exists($dir)) {
251 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
256 if (file_exists($dir)) {
258 if (!is_object($hookmanager)) {
259 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
262 $hookmanager->initHooks(array(
'pdfgeneration'));
263 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
265 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
270 $pdf->SetAutoPageBreak(1, 0);
272 $heightforinfotot = 40;
273 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
274 $heightforfooter = $this->marge_basse + 8;
275 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
276 $heightforfooter += 6;
279 if (class_exists(
'TCPDF')) {
280 $pdf->setPrintHeader(
false);
281 $pdf->setPrintFooter(
false);
285 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
286 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
287 $tplidx = $pdf->importPage(1);
291 $task =
new Task($this->db);
292 $tasksarray = array();
293 $tasksarray = $task->getTasksArray(0, 0, $object->id);
296 if (!$object->id > 0) {
297 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
300 $object->lines = $tasksarray;
301 $nblines = count($object->lines);
305 $pdf->SetDrawColor(128, 128, 128);
307 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
308 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
309 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
310 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
311 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
313 $pdf->SetCompression(
false);
316 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
319 $pdf->AddPage($this->orientation);
320 if (!empty($tplidx)) {
321 $pdf->useTemplate($tplidx);
324 $this->
_pagehead($pdf, $object, 1, $outputlangs);
325 $pdf->SetFont(
'',
'', $default_font_size - 1);
326 $pdf->MultiCell(0, 3,
'');
327 $pdf->SetTextColor(0, 0, 0);
330 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
332 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
335 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
344 $pdf->SetFont(
'',
'', $default_font_size - 1);
345 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
346 $nexY = $pdf->GetY();
347 $height_note = $nexY - $tab_top;
350 $pdf->SetDrawColor(192, 192, 192);
351 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
353 $tab_height = $tab_height - $height_note;
354 $tab_top = $nexY + 6;
359 $heightoftitleline = 10;
360 $iniY = $tab_top + $heightoftitleline + 1;
361 $curY = $tab_top + $heightoftitleline + 1;
362 $nexY = $tab_top + $heightoftitleline + 1;
364 $listofreferent = array(
367 'title'=>
"ListProposalsAssociatedProject",
370 'datefieldname'=>
'datep',
371 'test'=> isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
374 'name'=>
"CustomersOrders",
375 'title'=>
"ListOrdersAssociatedProject",
378 'datefieldname'=>
'date_commande',
379 'test'=> isModEnabled(
'commande') && $user->hasRight(
'commande',
'lire'),
382 'name'=>
"CustomersInvoices",
383 'title'=>
"ListInvoicesAssociatedProject",
387 'datefieldname'=>
'datef',
388 'test'=> isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire'),
390 'invoice_predefined'=>array(
391 'name'=>
"PredefinedInvoices",
392 'title'=>
"ListPredefinedInvoicesAssociatedProject",
393 'class'=>
'FactureRec',
394 'table'=>
'facture_rec',
395 'datefieldname'=>
'datec',
396 'test'=> isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire'),
398 'order_supplier'=>array(
399 'name'=>
"SuppliersOrders",
400 'title'=>
"ListSupplierOrdersAssociatedProject",
401 'class'=>
'CommandeFournisseur',
402 'table'=>
'commande_fournisseur',
403 'datefieldname'=>
'date_commande',
404 'test'=>(isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->commande->lire) || (isModEnabled(
"supplier_order") && $user->rights->supplier_order->lire),
406 'invoice_supplier'=>array(
407 'name'=>
"BillsSuppliers",
408 'title'=>
"ListSupplierInvoicesAssociatedProject",
409 'class'=>
'FactureFournisseur',
411 'table'=>
'facture_fourn',
412 'datefieldname'=>
'datef',
413 'test'=>(isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled(
"supplier_invoice") && $user->rights->supplier_invoice->lire),
417 'title'=>
"ListContractAssociatedProject",
420 'datefieldname'=>
'date_contrat',
421 'test'=> isModEnabled(
'contrat') && $user->hasRight(
'contrat',
'lire'),
423 'intervention'=>array(
424 'name'=>
"Interventions",
425 'title'=>
"ListFichinterAssociatedProject",
426 'class'=>
'Fichinter',
427 'table'=>
'fichinter',
428 'datefieldname'=>
'date_valid',
430 'test'=>isModEnabled(
'ficheinter') && $user->hasRight(
'ficheinter',
'lire'),
431 'lang'=>
'interventions'),
433 'name'=>
"TripsAndExpenses",
434 'title'=>
"ListExpenseReportsAssociatedProject",
435 'class'=>
'Deplacement',
436 'table'=>
'deplacement',
437 'datefieldname'=>
'dated',
440 'test'=>isModEnabled(
'deplacement') && $user->rights->deplacement->lire,
442 'expensereport'=>array(
443 'name'=>
"ExpensesReports",
444 'title'=>
"ListExpenseReportsAssociatedProject",
445 'class'=>
'ExpenseReport',
446 'table'=>
'expensereport',
447 'datefieldname'=>
'dated',
450 'test'=>isModEnabled(
'expensereport') && $user->rights->expensereport->lire,
454 'title'=>
"ListActionsAssociatedProject",
455 'class'=>
'ActionComm',
456 'table'=>
'actioncomm',
457 'datefieldname'=>
'datep',
459 'test'=> isModEnabled(
'agenda') && $user->rights->agenda->allactions->read,
463 $hookmanager->initHooks(array(
'completeListOfReferent'));
464 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent'=>$listofreferent], $object, $action);
465 if (!empty($hookmanager->resArray)) {
466 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
469 foreach ($listofreferent as $key => $value) {
470 $title = $value[
'title'];
471 $classname = $value[
'class'];
472 $tablename = $value[
'table'];
473 $datefieldname = $value[
'datefieldname'];
474 $qualified = $value[
'test'];
475 $langstoload = $value[
'lang'];
476 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
477 $langs->load($langstoload);
484 $elementarray = $object->get_element_list($key, $tablename, $datefieldname,
'',
'', $projectField);
486 $num = count($elementarray);
488 $nexY = $pdf->GetY() + 5;
491 $pdf->SetFont(
'',
'', $default_font_size - 1);
492 $pdf->SetTextColor(0, 0, 0);
494 $pdf->SetXY($this->posxref, $curY);
495 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
497 $selectList = $formproject->select_element($tablename, $object->thirdparty->id,
'', -2, $projectField);
498 $nexY = $pdf->GetY() + 1;
500 $pdf->SetXY($this->posxref, $curY);
501 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
502 $pdf->SetXY($this->posxdate, $curY);
503 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
504 $pdf->SetXY($this->posxsociety, $curY);
505 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
506 if ($classname ==
'ExpenseReport') {
507 $titlethirdparty = $langs->trans(
"User");
509 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
510 if (empty($value[
'disableamount'])) {
511 $pdf->SetXY($this->posxamountht, $curY);
512 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
513 $pdf->SetXY($this->posxamountttc, $curY);
514 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
516 $pdf->SetXY($this->posxamountht, $curY);
517 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
519 $pdf->SetXY($this->posxstatut, $curY);
520 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
522 if (is_array($elementarray) && count($elementarray) > 0) {
523 $nexY = $pdf->GetY();
527 $num = count($elementarray);
530 for ($i = 0; $i < $num; $i++) {
532 $pdf->SetFont(
'',
'', $default_font_size - 1);
533 $pdf->SetTextColor(0, 0, 0);
535 $pdf->setTopMargin($tab_top_newpage);
536 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
537 $pageposbefore = $pdf->getPage();
540 $idofelement = $elementarray[$i];
541 if ($classname ==
'ExpenseReport') {
544 $expensereportline->fetch($idofelement);
545 $idofelement = $expensereportline->fk_expensereport;
548 $element =
new $classname($this->db);
549 $element->fetch($idofelement);
550 $element->fetch_thirdparty();
553 $qualifiedfortotal =
true;
554 if ($key ==
'invoice') {
555 if ($element->close_code ==
'replaced') {
556 $qualifiedfortotal =
false;
560 $showpricebeforepagebreak = 1;
562 $pdf->startTransaction();
564 $pdf->SetXY($this->posxref, $curY);
565 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
566 $pageposafter = $pdf->getPage();
567 if ($pageposafter > $pageposbefore) {
568 $pdf->rollbackTransaction(
true);
569 $pageposafter = $pageposbefore;
571 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
573 $pdf->SetXY($this->posxref, $curY);
574 $posybefore = $pdf->GetY();
575 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
576 $pageposafter = $pdf->getPage();
577 $posyafter = $pdf->GetY();
578 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
579 if ($i == ($num - 1)) {
580 $pdf->AddPage($this->orientation,
'',
true);
581 if (!empty($tplidx)) {
582 $pdf->useTemplate($tplidx);
585 $this->
_pagehead($pdf, $object, 0, $outputlangs);
587 $pdf->setPage($pageposafter + 1);
593 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
594 $showpricebeforepagebreak = 1;
596 $showpricebeforepagebreak = 0;
599 $forcedesconsamepage = 1;
600 if ($forcedesconsamepage) {
601 $pdf->rollbackTransaction(
true);
602 $pageposafter = $pageposbefore;
603 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
605 $pdf->AddPage($this->orientation,
'',
true);
606 if (!empty($tplidx)) {
607 $pdf->useTemplate($tplidx);
610 $this->
_pagehead($pdf, $object, 0, $outputlangs);
612 $pdf->setPage($pageposafter + 1);
613 $pdf->SetFont(
'',
'', $default_font_size - 1);
614 $pdf->MultiCell(0, 3,
'');
615 $pdf->SetTextColor(0, 0, 0);
617 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
618 $curY = $tab_top_newpage + $heightoftitleline + 1;
621 $pdf->SetXY($this->posxref, $curY);
622 $posybefore = $pdf->GetY();
623 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
624 $pageposafter = $pdf->getPage();
625 $posyafter = $pdf->GetY();
631 $pdf->commitTransaction();
633 $posYAfterDescription = $pdf->GetY();
635 $nexY = $pdf->GetY();
636 $pageposafter = $pdf->getPage();
637 $pdf->setPage($pageposbefore);
638 $pdf->setTopMargin($this->marge_haute);
639 $pdf->setPageOrientation($this->orientation, 1, 0);
642 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
644 $pdf->setPage($pageposafter);
645 $curY = $tab_top_newpage + $heightoftitleline + 1;
648 $pdf->SetFont(
'',
'', $default_font_size - 1);
651 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
652 $date = $element->date_commande;
654 $date = $element->date;
656 $date = $element->datep;
659 $date = $element->date_contrat;
662 $date = $element->datev;
666 $pdf->SetXY($this->posxdate, $curY);
667 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
669 $pdf->SetXY($this->posxsociety, $curY);
670 if ($classname ==
'ExpenseReport') {
671 $fuser =
new User($this->db);
672 $fuser->fetch($element->fk_user_author);
673 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
675 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
679 if (empty($value[
'disableamount'])) {
680 $pdf->SetXY($this->posxamountht, $curY);
681 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
682 $pdf->SetXY($this->posxamountttc, $curY);
683 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
685 $pdf->SetXY($this->posxamountht, $curY);
686 if ($key ==
'agenda') {
687 $textforamount =
dol_trunc($element->label, 26);
688 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
690 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
697 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
699 $outputstatut = $element->getLibStatut(1);
701 $pdf->SetXY($this->posxstatut, $curY);
702 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
'',
'',
true, 0,
true);
704 if ($qualifiedfortotal) {
705 $total_ht = $total_ht + $element->total_ht;
706 $total_ttc = $total_ttc + $element->total_ttc;
708 $nexY = $pdf->GetY();
712 if (empty($value[
'disableamount'])) {
714 $pdf->SetXY($this->posxref, $curY);
715 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
716 $pdf->SetXY($this->posxamountht, $curY);
717 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
718 $pdf->SetXY($this->posxamountttc, $curY);
719 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
720 $pdf->SetXY($this->posxstatut, $curY);
721 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
723 $nexY = $pdf->GetY() + 5;
731 while ($pagenb < $pageposafter) {
732 $pdf->setPage($pagenb);
733 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
735 $pdf->setPage($pagenb);
736 $pdf->setPageOrientation($this->orientation, 1, 0);
738 $this->
_pagehead($pdf, $object, 0, $outputlangs);
740 if (!empty($tplidx)) {
741 $pdf->useTemplate($tplidx);
747 $this->
_pagefoot($pdf, $object, $outputlangs);
748 if (method_exists($pdf,
'AliasNbPages')) {
749 $pdf->AliasNbPages();
754 $pdf->Output($file,
'F');
757 $hookmanager->initHooks(array(
'pdfgeneration'));
758 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
760 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
762 $this->error = $hookmanager->error;
763 $this->errors = $hookmanager->errors;
768 $this->result = array(
'fullpath'=>$file);
772 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
776 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");