179 global $conf, $hookmanager, $langs, $user;
183 if (!is_object($outputlangs)) {
184 $outputlangs = $langs;
188 $outputlangs->charset_output =
'ISO-8859-1';
192 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
194 if ($conf->project->multidir_output[
$object->entity]) {
198 $dir = $conf->project->multidir_output[
$object->entity];
199 if (!preg_match(
'/specimen/i', $objectref)) {
200 $dir .=
"/".$objectref;
202 $file = $dir.
"/".$objectref.
".pdf";
204 if (!file_exists($dir)) {
206 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
211 if (file_exists($dir)) {
213 if (!is_object($hookmanager)) {
214 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
217 $hookmanager->initHooks(array(
'pdfgeneration'));
218 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
220 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
225 $pdf->SetAutoPageBreak(1, 0);
227 $heightforinfotot = 40;
228 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
229 $heightforfooter = $this->marge_basse + 8;
231 $heightforfooter += 6;
234 if (class_exists(
'TCPDF')) {
235 $pdf->setPrintHeader(
false);
236 $pdf->setPrintFooter(
false);
241 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
242 $tplidx = $pdf->importPage(1);
246 $task =
new Task($this->db);
247 $tasksarray = array();
248 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
252 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
256 $nblines = count(
$object->lines);
260 $pdf->SetDrawColor(128, 128, 128);
262 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
263 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
264 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
265 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
266 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
268 $pdf->SetCompression(
false);
272 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
275 $pdf->AddPage($this->orientation);
276 if (!empty($tplidx)) {
277 $pdf->useTemplate($tplidx);
281 $pdf->SetFont(
'',
'', $default_font_size - 1);
282 $pdf->MultiCell(0, 3,
'');
283 $pdf->SetTextColor(0, 0, 0);
286 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
288 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
291 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
300 $pdf->SetFont(
'',
'', $default_font_size - 1);
301 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
302 $nexY = $pdf->GetY();
303 $height_note = $nexY - $tab_top;
306 $pdf->SetDrawColor(192, 192, 192);
307 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
309 $tab_height = $tab_height - $height_note;
310 $tab_top = $nexY + 6;
315 $heightoftitleline = 10;
316 $iniY = $tab_top + $heightoftitleline + 1;
317 $curY = $tab_top + $heightoftitleline + 1;
318 $nexY = $tab_top + $heightoftitleline + 1;
320 $listofreferent = array(
322 'name' =>
"Proposals",
323 'title' =>
"ListProposalsAssociatedProject",
326 'datefieldname' =>
'datep',
327 'test' => isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
330 'name' =>
"CustomersOrders",
331 'title' =>
"ListOrdersAssociatedProject",
332 'class' =>
'Commande',
333 'table' =>
'commande',
334 'datefieldname' =>
'date_commande',
335 'test' => isModEnabled(
'order') && $user->hasRight(
'commande',
'lire'),
338 'name' =>
"CustomersInvoices",
339 'title' =>
"ListInvoicesAssociatedProject",
340 'class' =>
'Facture',
342 'table' =>
'facture',
343 'datefieldname' =>
'datef',
344 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
346 'invoice_predefined' => array(
347 'name' =>
"PredefinedInvoices",
348 'title' =>
"ListPredefinedInvoicesAssociatedProject",
349 'class' =>
'FactureRec',
350 'table' =>
'facture_rec',
351 'datefieldname' =>
'datec',
352 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
354 'order_supplier' => array(
355 'name' =>
"SuppliersOrders",
356 'title' =>
"ListSupplierOrdersAssociatedProject",
357 'class' =>
'CommandeFournisseur',
358 'table' =>
'commande_fournisseur',
359 'datefieldname' =>
'date_commande',
360 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'commande',
'lire')) || (isModEnabled(
"supplier_order") && $user->hasRight(
'supplier_order',
'lire')),
362 'invoice_supplier' => array(
363 'name' =>
"BillsSuppliers",
364 'title' =>
"ListSupplierInvoicesAssociatedProject",
365 'class' =>
'FactureFournisseur',
367 'table' =>
'facture_fourn',
368 'datefieldname' =>
'datef',
369 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'facture',
'lire')) || (isModEnabled(
"supplier_invoice") && $user->hasRight(
'supplier_invoice',
'lire')),
372 'name' =>
"Contracts",
373 'title' =>
"ListContractAssociatedProject",
374 'class' =>
'Contrat',
375 'table' =>
'contrat',
376 'datefieldname' =>
'date_contrat',
377 'test' => isModEnabled(
'contract') && $user->hasRight(
'contrat',
'lire'),
378 'lang' =>
'contract'),
379 'intervention' => array(
380 'name' =>
"Interventions",
381 'title' =>
"ListFichinterAssociatedProject",
382 'class' =>
'Fichinter',
383 'table' =>
'fichinter',
384 'datefieldname' =>
'date_valid',
385 'disableamount' => 1,
386 'test' => isModEnabled(
'intervention') && $user->hasRight(
'ficheinter',
'lire'),
387 'lang' =>
'interventions'),
389 'name' =>
"TripsAndExpenses",
390 'title' =>
"ListExpenseReportsAssociatedProject",
391 'class' =>
'Deplacement',
392 'table' =>
'deplacement',
393 'datefieldname' =>
'dated',
395 'disableamount' => 1,
396 'test' => isModEnabled(
'deplacement') && $user->hasRight(
'deplacement',
'lire'),
398 'expensereport' => array(
399 'name' =>
"ExpensesReports",
400 'title' =>
"ListExpenseReportsAssociatedProject",
401 'class' =>
'ExpenseReport',
402 'table' =>
'expensereport',
403 'datefieldname' =>
'dated',
405 'disableamount' => 1,
406 'test' => isModEnabled(
'expensereport') && $user->hasRight(
'expensereport',
'lire'),
410 'title' =>
"ListActionsAssociatedProject",
411 'class' =>
'ActionComm',
412 'table' =>
'actioncomm',
413 'datefieldname' =>
'datep',
414 'disableamount' => 1,
415 'test' => isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'allactions',
'read'),
419 $hookmanager->initHooks(array(
'completeListOfReferent'));
420 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent' => $listofreferent],
$object, $action);
421 if (!empty($hookmanager->resArray)) {
422 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
425 foreach ($listofreferent as $key => $value) {
426 $title = $value[
'title'];
427 $classname = $value[
'class'];
428 $tablename = $value[
'table'];
429 $datefieldname = $value[
'datefieldname'];
430 $qualified = $value[
'test'];
431 $langstoload = $value[
'lang'];
432 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
433 $langs->load($langstoload);
440 $elementarray =
$object->get_element_list($key, $tablename, $datefieldname,
null,
null, $projectField);
442 $num = count($elementarray);
444 $nexY = $pdf->GetY() + 5;
447 $pdf->SetFont(
'',
'', $default_font_size - 1);
448 $pdf->SetTextColor(0, 0, 0);
450 $pdf->SetXY($this->posxref, $curY);
451 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
453 $selectList = $formproject->select_element($tablename,
$object->thirdparty->id,
'', -2, $projectField);
454 $nexY = $pdf->GetY() + 1;
456 $pdf->SetXY($this->posxref, $curY);
457 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
458 $pdf->SetXY($this->posxdate, $curY);
459 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
460 $pdf->SetXY($this->posxsociety, $curY);
461 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
462 if ($classname ==
'ExpenseReport') {
463 $titlethirdparty = $langs->trans(
"User");
465 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
466 if (empty($value[
'disableamount'])) {
467 $pdf->SetXY($this->posxamountht, $curY);
468 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
469 $pdf->SetXY($this->posxamountttc, $curY);
470 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
472 $pdf->SetXY($this->posxamountht, $curY);
473 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
475 $pdf->SetXY($this->posxstatut, $curY);
476 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
478 if (is_array($elementarray) && count($elementarray) > 0) {
479 $nexY = $pdf->GetY();
483 $num = count($elementarray);
486 for ($i = 0; $i < $num; $i++) {
488 $pdf->SetFont(
'',
'', $default_font_size - 1);
489 $pdf->SetTextColor(0, 0, 0);
491 $pdf->setTopMargin($tab_top_newpage);
492 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
493 $pageposbefore = $pdf->getPage();
496 $idofelement = $elementarray[$i];
497 if ($classname ==
'ExpenseReport') {
500 $expensereportline->fetch($idofelement);
501 $idofelement = $expensereportline->fk_expensereport;
504 $element =
new $classname($this->db);
505 $element->fetch($idofelement);
506 $element->fetch_thirdparty();
509 $qualifiedfortotal =
true;
510 if ($key ==
'invoice') {
511 if ($element->close_code ==
'replaced') {
512 $qualifiedfortotal =
false;
516 $showpricebeforepagebreak = 1;
518 $pdf->startTransaction();
520 $pdf->SetXY($this->posxref, $curY);
521 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
522 $pageposafter = $pdf->getPage();
523 if ($pageposafter > $pageposbefore) {
524 $pdf->rollbackTransaction(
true);
525 $pageposafter = $pageposbefore;
527 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
529 $pdf->SetXY($this->posxref, $curY);
530 $posybefore = $pdf->GetY();
531 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
532 $pageposafter = $pdf->getPage();
533 $posyafter = $pdf->GetY();
534 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
535 if ($i == ($num - 1)) {
536 $pdf->AddPage($this->orientation,
'',
true);
537 if (!empty($tplidx)) {
538 $pdf->useTemplate($tplidx);
543 $pdf->setPage($pageposafter + 1);
550 $showpricebeforepagebreak = 1;
552 $showpricebeforepagebreak = 0;
555 $forcedesconsamepage = 1;
556 if ($forcedesconsamepage) {
557 $pdf->rollbackTransaction(
true);
558 $pageposafter = $pageposbefore;
559 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
561 $pdf->AddPage($this->orientation,
'',
true);
562 if (!empty($tplidx)) {
563 $pdf->useTemplate($tplidx);
568 $pdf->setPage($pageposafter + 1);
569 $pdf->SetFont(
'',
'', $default_font_size - 1);
570 $pdf->MultiCell(0, 3,
'');
571 $pdf->SetTextColor(0, 0, 0);
573 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
574 $curY = $tab_top_newpage + $heightoftitleline + 1;
577 $pdf->SetXY($this->posxref, $curY);
578 $posybefore = $pdf->GetY();
579 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
580 $pageposafter = $pdf->getPage();
581 $posyafter = $pdf->GetY();
586 $pdf->commitTransaction();
588 $posYAfterDescription = $pdf->GetY();
590 $nexY = $pdf->GetY();
591 $pageposafter = $pdf->getPage();
592 $pdf->setPage($pageposbefore);
593 $pdf->setTopMargin($this->marge_haute);
594 $pdf->setPageOrientation($this->orientation, 1, 0);
597 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
599 $pdf->setPage($pageposafter);
600 $curY = $tab_top_newpage + $heightoftitleline + 1;
603 $pdf->SetFont(
'',
'', $default_font_size - 1);
606 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
607 $date = $element->date_commande;
609 $date = $element->date;
611 $date = $element->datep;
614 $date = $element->date_contrat;
617 $date = $element->datev;
621 $pdf->SetXY($this->posxdate, $curY);
622 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
624 $pdf->SetXY($this->posxsociety, $curY);
625 if ($classname ==
'ExpenseReport') {
626 $fuser =
new User($this->db);
627 $fuser->fetch($element->fk_user_author);
628 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
630 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
634 if (empty($value[
'disableamount'])) {
635 $pdf->SetXY($this->posxamountht, $curY);
636 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
637 $pdf->SetXY($this->posxamountttc, $curY);
638 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
640 $pdf->SetXY($this->posxamountht, $curY);
641 if ($key ==
'agenda') {
642 $textforamount =
dol_trunc($element->label, 26);
643 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
645 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
652 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
654 $outputstatut = $element->getLibStatut(1);
656 $pdf->SetXY($this->posxstatut, $curY);
657 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
'',
'',
true, 0,
true);
659 if ($qualifiedfortotal) {
660 $total_ht = $total_ht + $element->total_ht;
661 $total_ttc = $total_ttc + $element->total_ttc;
663 $nexY = $pdf->GetY();
667 if (empty($value[
'disableamount'])) {
669 $pdf->SetXY($this->posxref, $curY);
670 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
671 $pdf->SetXY($this->posxamountht, $curY);
672 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
673 $pdf->SetXY($this->posxamountttc, $curY);
674 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
675 $pdf->SetXY($this->posxstatut, $curY);
676 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
678 $nexY = $pdf->GetY() + 5;
686 while ($pagenb < $pageposafter) {
687 $pdf->setPage($pagenb);
690 $pdf->setPage($pagenb);
691 $pdf->setPageOrientation($this->orientation, 1, 0);
695 if (!empty($tplidx)) {
696 $pdf->useTemplate($tplidx);
703 if (method_exists($pdf,
'AliasNbPages')) {
704 $pdf->AliasNbPages();
709 $pdf->Output($file,
'F');
712 $hookmanager->initHooks(array(
'pdfgeneration'));
713 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
715 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
717 $this->error = $hookmanager->error;
718 $this->errors = $hookmanager->errors;
723 $this->result = array(
'fullpath' => $file);
727 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
731 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
779 global $langs, $conf, $mysoc;
785 $pdf->SetTextColor(0, 0, 60);
786 $pdf->SetFont(
'',
'B', $default_font_size + 3);
788 $posx = $this->page_largeur - $this->marge_droite - 100;
789 $posy = $this->marge_haute;
791 $pdf->SetXY($this->marge_gauche, $posy);
794 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
796 if (is_readable($logo)) {
798 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
800 $pdf->SetTextColor(200, 0, 0);
801 $pdf->SetFont(
'',
'B', $default_font_size - 2);
802 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
803 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
806 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
809 $pdf->SetFont(
'',
'B', $default_font_size + 3);
810 $pdf->SetXY($posx, $posy);
811 $pdf->SetTextColor(0, 0, 60);
812 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
813 $pdf->SetFont(
'',
'', $default_font_size + 2);
816 $pdf->SetXY($posx, $posy);
817 $pdf->SetTextColor(0, 0, 60);
818 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
821 $pdf->SetXY($posx, $posy);
822 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
824 if (is_object(
$object->thirdparty)) {
826 $pdf->SetXY($posx, $posy);
827 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
830 $pdf->SetTextColor(0, 0, 60);