180 global $conf, $hookmanager, $langs, $user;
184 if (!is_object($outputlangs)) {
185 $outputlangs = $langs;
189 $outputlangs->charset_output =
'ISO-8859-1';
193 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
195 if ($conf->project->multidir_output[
$object->entity]) {
199 $dir = $conf->project->multidir_output[
$object->entity];
200 if (!preg_match(
'/specimen/i', $objectref)) {
201 $dir .=
"/".$objectref;
203 $file = $dir.
"/".$objectref.
".pdf";
205 if (!file_exists($dir)) {
207 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
212 if (file_exists($dir)) {
214 if (!is_object($hookmanager)) {
215 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
218 $hookmanager->initHooks(array(
'pdfgeneration'));
219 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
221 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
226 $pdf->SetAutoPageBreak(1, 0);
228 $heightforinfotot = 40;
230 $heightforfooter = $this->marge_basse + 8;
232 $heightforfooter += 6;
235 if (class_exists(
'TCPDF')) {
236 $pdf->setPrintHeader(
false);
237 $pdf->setPrintFooter(
false);
242 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
243 $tplidx = $pdf->importPage(1);
247 $task =
new Task($this->db);
248 $tasksarray = array();
249 $tasksarray = $task->getTasksArray(0, 0,
$object->id);
253 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
257 $nblines = count(
$object->lines);
261 $pdf->SetDrawColor(128, 128, 128);
263 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
264 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
265 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
266 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
267 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
269 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
276 $pdf->AddPage($this->orientation);
277 if (!empty($tplidx)) {
278 $pdf->useTemplate($tplidx);
282 $pdf->SetFont(
'',
'', $default_font_size - 1);
283 $pdf->MultiCell(0, 3,
'');
284 $pdf->SetTextColor(0, 0, 0);
287 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
289 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
301 $pdf->SetFont(
'',
'', $default_font_size - 1);
302 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
303 $nexY = $pdf->GetY();
304 $height_note = $nexY - $tab_top;
307 $pdf->SetDrawColor(192, 192, 192);
308 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
310 $tab_height = $tab_height - $height_note;
311 $tab_top = $nexY + 6;
316 $heightoftitleline = 10;
317 $iniY = $tab_top + $heightoftitleline + 1;
318 $curY = $tab_top + $heightoftitleline + 1;
319 $nexY = $tab_top + $heightoftitleline + 1;
321 $listofreferent = array(
323 'name' =>
"Proposals",
324 'title' =>
"ListProposalsAssociatedProject",
327 'datefieldname' =>
'datep',
328 'test' => isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
331 'name' =>
"CustomersOrders",
332 'title' =>
"ListOrdersAssociatedProject",
333 'class' =>
'Commande',
334 'table' =>
'commande',
335 'datefieldname' =>
'date_commande',
336 'test' => isModEnabled(
'order') && $user->hasRight(
'commande',
'lire'),
339 'name' =>
"CustomersInvoices",
340 'title' =>
"ListInvoicesAssociatedProject",
341 'class' =>
'Facture',
343 'table' =>
'facture',
344 'datefieldname' =>
'datef',
345 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
347 'invoice_predefined' => array(
348 'name' =>
"PredefinedInvoices",
349 'title' =>
"ListPredefinedInvoicesAssociatedProject",
350 'class' =>
'FactureRec',
351 'table' =>
'facture_rec',
352 'datefieldname' =>
'datec',
353 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
355 'order_supplier' => array(
356 'name' =>
"SuppliersOrders",
357 'title' =>
"ListSupplierOrdersAssociatedProject",
358 'class' =>
'CommandeFournisseur',
359 'table' =>
'commande_fournisseur',
360 'datefieldname' =>
'date_commande',
361 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'commande',
'lire')) || (isModEnabled(
"supplier_order") && $user->hasRight(
'supplier_order',
'lire')),
363 'invoice_supplier' => array(
364 'name' =>
"BillsSuppliers",
365 'title' =>
"ListSupplierInvoicesAssociatedProject",
366 'class' =>
'FactureFournisseur',
368 'table' =>
'facture_fourn',
369 'datefieldname' =>
'datef',
370 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'facture',
'lire')) || (isModEnabled(
"supplier_invoice") && $user->hasRight(
'supplier_invoice',
'lire')),
373 'name' =>
"Contracts",
374 'title' =>
"ListContractAssociatedProject",
375 'class' =>
'Contrat',
376 'table' =>
'contrat',
377 'datefieldname' =>
'date_contrat',
378 'test' => isModEnabled(
'contract') && $user->hasRight(
'contrat',
'lire'),
379 'lang' =>
'contract'),
380 'intervention' => array(
381 'name' =>
"Interventions",
382 'title' =>
"ListFichinterAssociatedProject",
383 'class' =>
'Fichinter',
384 'table' =>
'fichinter',
385 'datefieldname' =>
'date_valid',
386 'disableamount' => 1,
387 'test' => isModEnabled(
'intervention') && $user->hasRight(
'ficheinter',
'lire'),
388 'lang' =>
'interventions'),
390 'name' =>
"TripsAndExpenses",
391 'title' =>
"ListExpenseReportsAssociatedProject",
392 'class' =>
'Deplacement',
393 'table' =>
'deplacement',
394 'datefieldname' =>
'dated',
396 'disableamount' => 1,
397 'test' => isModEnabled(
'deplacement') && $user->hasRight(
'deplacement',
'lire'),
399 'expensereport' => array(
400 'name' =>
"ExpensesReports",
401 'title' =>
"ListExpenseReportsAssociatedProject",
402 'class' =>
'ExpenseReport',
403 'table' =>
'expensereport',
404 'datefieldname' =>
'dated',
406 'disableamount' => 1,
407 'test' => isModEnabled(
'expensereport') && $user->hasRight(
'expensereport',
'lire'),
411 'title' =>
"ListActionsAssociatedProject",
412 'class' =>
'ActionComm',
413 'table' =>
'actioncomm',
414 'datefieldname' =>
'datep',
415 'disableamount' => 1,
416 'test' => isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'allactions',
'read'),
420 $hookmanager->initHooks(array(
'completeListOfReferent'));
421 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent' => $listofreferent],
$object, $action);
422 if (!empty($hookmanager->resArray)) {
423 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
426 foreach ($listofreferent as $key => $value) {
427 $title = $value[
'title'];
428 $classname = $value[
'class'];
429 $tablename = $value[
'table'];
430 $datefieldname = $value[
'datefieldname'];
431 $qualified = $value[
'test'];
432 $langstoload = $value[
'lang'];
433 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
434 $langs->load($langstoload);
441 $elementarray =
$object->get_element_list($key, $tablename, $datefieldname,
null,
null, $projectField);
443 $num = count($elementarray);
445 $nexY = $pdf->GetY() + 5;
448 $pdf->SetFont(
'',
'', $default_font_size - 1);
449 $pdf->SetTextColor(0, 0, 0);
451 $pdf->SetXY($this->posxref, $curY);
452 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
454 $selectList = $formproject->select_element($tablename,
$object->thirdparty->id,
'', -2, $projectField);
455 $nexY = $pdf->GetY() + 1;
457 $pdf->SetXY($this->posxref, $curY);
458 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
459 $pdf->SetXY($this->posxdate, $curY);
460 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
461 $pdf->SetXY($this->posxsociety, $curY);
462 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
463 if ($classname ==
'ExpenseReport') {
464 $titlethirdparty = $langs->trans(
"User");
466 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
467 if (empty($value[
'disableamount'])) {
468 $pdf->SetXY($this->posxamountht, $curY);
469 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
470 $pdf->SetXY($this->posxamountttc, $curY);
471 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
473 $pdf->SetXY($this->posxamountht, $curY);
474 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
476 $pdf->SetXY($this->posxstatut, $curY);
477 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
479 if (is_array($elementarray) && count($elementarray) > 0) {
480 $nexY = $pdf->GetY();
484 $num = count($elementarray);
487 for ($i = 0; $i < $num; $i++) {
489 $pdf->SetFont(
'',
'', $default_font_size - 1);
490 $pdf->SetTextColor(0, 0, 0);
492 $pdf->setTopMargin($tab_top_newpage);
493 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
494 $pageposbefore = $pdf->getPage();
497 $idofelement = $elementarray[$i];
498 if ($classname ==
'ExpenseReport') {
501 $expensereportline->fetch($idofelement);
502 $idofelement = $expensereportline->fk_expensereport;
505 $element =
new $classname($this->db);
506 $element->fetch($idofelement);
507 $element->fetch_thirdparty();
510 $qualifiedfortotal =
true;
511 if ($key ==
'invoice') {
512 if ($element->close_code ==
'replaced') {
513 $qualifiedfortotal =
false;
517 $showpricebeforepagebreak = 1;
519 $pdf->startTransaction();
521 $pdf->SetXY($this->posxref, $curY);
522 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
523 $pageposafter = $pdf->getPage();
524 if ($pageposafter > $pageposbefore) {
525 $pdf->rollbackTransaction(
true);
526 $pageposafter = $pageposbefore;
528 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
530 $pdf->SetXY($this->posxref, $curY);
531 $posybefore = $pdf->GetY();
532 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
533 $pageposafter = $pdf->getPage();
534 $posyafter = $pdf->GetY();
535 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
536 if ($i == ($num - 1)) {
537 $pdf->AddPage($this->orientation,
'',
true);
538 if (!empty($tplidx)) {
539 $pdf->useTemplate($tplidx);
544 $pdf->setPage($pageposafter + 1);
551 $showpricebeforepagebreak = 1;
553 $showpricebeforepagebreak = 0;
556 $forcedesconsamepage = 1;
557 if ($forcedesconsamepage) {
558 $pdf->rollbackTransaction(
true);
559 $pageposafter = $pageposbefore;
560 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
562 $pdf->AddPage($this->orientation,
'',
true);
563 if (!empty($tplidx)) {
564 $pdf->useTemplate($tplidx);
569 $pdf->setPage($pageposafter + 1);
570 $pdf->SetFont(
'',
'', $default_font_size - 1);
571 $pdf->MultiCell(0, 3,
'');
572 $pdf->SetTextColor(0, 0, 0);
574 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
575 $curY = $tab_top_newpage + $heightoftitleline + 1;
578 $pdf->SetXY($this->posxref, $curY);
579 $posybefore = $pdf->GetY();
580 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
581 $pageposafter = $pdf->getPage();
582 $posyafter = $pdf->GetY();
587 $pdf->commitTransaction();
589 $posYAfterDescription = $pdf->GetY();
591 $nexY = $pdf->GetY();
592 $pageposafter = $pdf->getPage();
593 $pdf->setPage($pageposbefore);
594 $pdf->setTopMargin($this->marge_haute);
595 $pdf->setPageOrientation($this->orientation, 1, 0);
598 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
600 $pdf->setPage($pageposafter);
601 $curY = $tab_top_newpage + $heightoftitleline + 1;
604 $pdf->SetFont(
'',
'', $default_font_size - 1);
607 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
608 $date = $element->date_commande;
610 $date = $element->date;
612 $date = $element->datep;
615 $date = $element->date_contrat;
618 $date = $element->datev;
622 $pdf->SetXY($this->posxdate, $curY);
623 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
625 $pdf->SetXY($this->posxsociety, $curY);
626 if ($classname ==
'ExpenseReport') {
627 $fuser =
new User($this->db);
628 $fuser->fetch($element->fk_user_author);
629 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
631 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
635 if (empty($value[
'disableamount'])) {
636 $pdf->SetXY($this->posxamountht, $curY);
637 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
638 $pdf->SetXY($this->posxamountttc, $curY);
639 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
641 $pdf->SetXY($this->posxamountht, $curY);
642 if ($key ==
'agenda') {
643 $textforamount =
dol_trunc($element->label, 26);
644 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
646 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
653 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
655 $outputstatut = $element->getLibStatut(1);
657 $pdf->SetXY($this->posxstatut, $curY);
658 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
'',
'',
true, 0,
true);
660 if ($qualifiedfortotal) {
661 $total_ht = $total_ht + $element->total_ht;
662 $total_ttc = $total_ttc + $element->total_ttc;
664 $nexY = $pdf->GetY();
668 if (empty($value[
'disableamount'])) {
670 $pdf->SetXY($this->posxref, $curY);
671 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
672 $pdf->SetXY($this->posxamountht, $curY);
673 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
674 $pdf->SetXY($this->posxamountttc, $curY);
675 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
676 $pdf->SetXY($this->posxstatut, $curY);
677 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
679 $nexY = $pdf->GetY() + 5;
687 while ($pagenb < $pageposafter) {
688 $pdf->setPage($pagenb);
691 $pdf->setPage($pagenb);
692 $pdf->setPageOrientation($this->orientation, 1, 0);
696 if (!empty($tplidx)) {
697 $pdf->useTemplate($tplidx);
704 if (method_exists($pdf,
'AliasNbPages')) {
705 $pdf->AliasNbPages();
710 $pdf->Output($file,
'F');
713 $hookmanager->initHooks(array(
'pdfgeneration'));
714 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
716 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
718 $this->error = $hookmanager->error;
719 $this->errors = $hookmanager->errors;
724 $this->result = array(
'fullpath' => $file);
728 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
732 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
780 global $langs, $conf, $mysoc;
786 $pdf->SetTextColor(0, 0, 60);
787 $pdf->SetFont(
'',
'B', $default_font_size + 3);
789 $posx = $this->page_largeur - $this->marge_droite - 100;
790 $posy = $this->marge_haute;
792 $pdf->SetXY($this->marge_gauche, $posy);
795 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
797 if (is_readable($logo)) {
799 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
801 $pdf->SetTextColor(200, 0, 0);
802 $pdf->SetFont(
'',
'B', $default_font_size - 2);
803 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
804 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
807 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
810 $pdf->SetFont(
'',
'B', $default_font_size + 3);
811 $pdf->SetXY($posx, $posy);
812 $pdf->SetTextColor(0, 0, 60);
813 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
814 $pdf->SetFont(
'',
'', $default_font_size + 2);
817 $pdf->SetXY($posx, $posy);
818 $pdf->SetTextColor(0, 0, 60);
819 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
822 $pdf->SetXY($posx, $posy);
823 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
825 if (is_object(
$object->thirdparty)) {
827 $pdf->SetXY($posx, $posy);
828 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
831 $pdf->SetTextColor(0, 0, 60);