205 global
$conf, $hookmanager, $langs, $user;
209 if (!is_object($outputlangs)) {
210 $outputlangs = $langs;
214 $outputlangs->charset_output =
'ISO-8859-1';
218 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
224 $dir =
$conf->project->multidir_output[
$object->entity];
225 if (!preg_match(
'/specimen/i', $objectref)) {
226 $dir .=
"/".$objectref;
228 $file = $dir.
"/".$objectref.
".pdf";
230 if (!file_exists($dir)) {
232 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
237 if (file_exists($dir)) {
239 if (!is_object($hookmanager)) {
240 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
243 $hookmanager->initHooks(array(
'pdfgeneration'));
244 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
246 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
251 $pdf->SetAutoPageBreak(1, 0);
253 $heightforinfotot = 40;
255 $heightforfooter = $this->marge_basse + 8;
257 $heightforfooter += 6;
260 if (class_exists(
'TCPDF')) {
261 $pdf->setPrintHeader(
false);
262 $pdf->setPrintFooter(
false);
267 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
268 $tplidx = $pdf->importPage(1);
272 $task =
new Task($this->db);
273 $tasksarray = array();
274 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
278 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
282 $nblines = count(
$object->lines);
286 $pdf->SetDrawColor(128, 128, 128);
288 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
289 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
290 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
291 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
292 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
294 $pdf->SetCompression(
false);
298 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
301 $pdf->AddPage($this->orientation);
302 if (!empty($tplidx)) {
303 $pdf->useTemplate($tplidx);
307 $pdf->SetFont(
'',
'', $default_font_size - 1);
308 $pdf->MultiCell(0, 3,
'');
309 $pdf->SetTextColor(0, 0, 0);
312 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
314 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
317 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
326 $pdf->SetFont(
'',
'', $default_font_size - 1);
327 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
328 $nexY = $pdf->GetY();
329 $height_note = $nexY - $tab_top;
332 $pdf->SetDrawColor(192, 192, 192);
333 $pdf->RoundedRect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
335 $tab_height -= $height_note;
336 $tab_top = $nexY + 6;
341 $heightoftitleline = 10;
342 $iniY = $tab_top + $heightoftitleline + 1;
343 $curY = $tab_top + $heightoftitleline + 1;
344 $nexY = $tab_top + $heightoftitleline + 1;
346 $listofreferent = array(
348 'name' =>
"Proposals",
349 'title' =>
"ListProposalsAssociatedProject",
352 'datefieldname' =>
'datep',
353 'test' => isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
356 'name' =>
"CustomersOrders",
357 'title' =>
"ListOrdersAssociatedProject",
358 'class' =>
'Commande',
359 'table' =>
'commande',
360 'datefieldname' =>
'date_commande',
361 'test' => isModEnabled(
'order') && $user->hasRight(
'commande',
'lire'),
364 'name' =>
"CustomersInvoices",
365 'title' =>
"ListInvoicesAssociatedProject",
366 'class' =>
'Facture',
368 'table' =>
'facture',
369 'datefieldname' =>
'datef',
370 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
372 'invoice_predefined' => array(
373 'name' =>
"PredefinedInvoices",
374 'title' =>
"ListPredefinedInvoicesAssociatedProject",
375 'class' =>
'FactureRec',
376 'table' =>
'facture_rec',
377 'datefieldname' =>
'datec',
378 'test' => isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
380 'order_supplier' => array(
381 'name' =>
"SuppliersOrders",
382 'title' =>
"ListSupplierOrdersAssociatedProject",
383 'class' =>
'CommandeFournisseur',
384 'table' =>
'commande_fournisseur',
385 'datefieldname' =>
'date_commande',
386 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'commande',
'lire')) || (isModEnabled(
"supplier_order") && $user->hasRight(
'supplier_order',
'lire')),
388 'invoice_supplier' => array(
389 'name' =>
"BillsSuppliers",
390 'title' =>
"ListSupplierInvoicesAssociatedProject",
391 'class' =>
'FactureFournisseur',
393 'table' =>
'facture_fourn',
394 'datefieldname' =>
'datef',
395 'test' => (isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'facture',
'lire')) || (isModEnabled(
"supplier_invoice") && $user->hasRight(
'supplier_invoice',
'lire')),
398 'name' =>
"Contracts",
399 'title' =>
"ListContractAssociatedProject",
400 'class' =>
'Contrat',
401 'table' =>
'contrat',
402 'datefieldname' =>
'date_contrat',
403 'test' => isModEnabled(
'contract') && $user->hasRight(
'contrat',
'lire'),
404 'lang' =>
'contract'),
405 'intervention' => array(
406 'name' =>
"Interventions",
407 'title' =>
"ListFichinterAssociatedProject",
408 'class' =>
'Fichinter',
409 'table' =>
'fichinter',
410 'datefieldname' =>
'date_valid',
411 'disableamount' => 1,
412 'test' => isModEnabled(
'intervention') && $user->hasRight(
'ficheinter',
'lire'),
413 'lang' =>
'interventions'),
415 'name' =>
"TripsAndExpenses",
416 'title' =>
"ListExpenseReportsAssociatedProject",
417 'class' =>
'Deplacement',
418 'table' =>
'deplacement',
419 'datefieldname' =>
'dated',
421 'disableamount' => 1,
422 'test' => isModEnabled(
'deplacement') && $user->hasRight(
'deplacement',
'lire'),
424 'expensereport' => array(
425 'name' =>
"ExpensesReports",
426 'title' =>
"ListExpenseReportsAssociatedProject",
427 'class' =>
'ExpenseReport',
428 'table' =>
'expensereport',
429 'datefieldname' =>
'dated',
431 'disableamount' => 1,
432 'test' => isModEnabled(
'expensereport') && $user->hasRight(
'expensereport',
'lire'),
436 'title' =>
"ListActionsAssociatedProject",
437 'class' =>
'ActionComm',
438 'table' =>
'actioncomm',
439 'datefieldname' =>
'datep',
440 'disableamount' => 1,
441 'test' => isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'allactions',
'read'),
445 $hookmanager->initHooks(array(
'completeListOfReferent'));
446 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent' => $listofreferent],
$object, $action);
447 if (!empty($hookmanager->resArray)) {
448 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
453 foreach ($listofreferent as $key => $value) {
454 $title = $value[
'title'];
455 $classname = $value[
'class'];
456 $tablename = $value[
'table'];
457 $datefieldname = $value[
'datefieldname'];
458 $qualified = $value[
'test'];
459 $langstoload = $value[
'lang'];
460 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
461 $langs->load($langstoload);
468 $elementarray =
$object->get_element_list($key, $tablename, $datefieldname, 0, 0, $projectField);
470 $num = count($elementarray);
472 $nexY = $pdf->GetY() + 5;
475 $pdf->SetFont(
'',
'', $default_font_size - 1);
476 $pdf->SetTextColor(0, 0, 0);
478 $pdf->SetXY($this->posxref, $curY);
479 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
481 $selectList = $formproject->select_element($tablename,
$object->thirdparty->id,
'', -2, $projectField);
482 $nexY = $pdf->GetY() + 1;
484 $pdf->SetXY($this->posxref, $curY);
485 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
486 $pdf->SetXY($this->posxdate, $curY);
487 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
488 $pdf->SetXY($this->posxsociety, $curY);
489 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
490 if ($classname ==
'ExpenseReport') {
491 $titlethirdparty = $langs->trans(
"User");
493 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
494 if (empty($value[
'disableamount'])) {
495 $pdf->SetXY($this->posxamountht, $curY);
496 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
497 $pdf->SetXY($this->posxamountttc, $curY);
498 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
500 $pdf->SetXY($this->posxamountht, $curY);
501 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
503 $pdf->SetXY($this->posxstatut, $curY);
504 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
506 if (is_array($elementarray) && count($elementarray) > 0) {
507 $nexY = $pdf->GetY();
511 $num = count($elementarray);
514 for ($i = 0; $i < $num; $i++) {
516 $pdf->SetFont(
'',
'', $default_font_size - 1);
517 $pdf->SetTextColor(0, 0, 0);
519 $pdf->setTopMargin($tab_top_newpage);
520 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
521 $pageposbefore = $pdf->getPage();
524 $idofelement = $elementarray[$i];
525 if ($classname ==
'ExpenseReport') {
528 $expensereportline->fetch($idofelement);
529 $idofelement = $expensereportline->fk_expensereport;
532 $element =
new $classname($this->db);
533 $element->fetch($idofelement);
534 $element->fetch_thirdparty();
537 $qualifiedfortotal =
true;
538 if ($key ==
'invoice') {
539 if ($element->close_code ==
'replaced') {
540 $qualifiedfortotal =
false;
544 $showpricebeforepagebreak = 1;
546 $pdf->startTransaction();
548 $pdf->SetXY($this->posxref, $curY);
549 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
550 $pageposafter = $pdf->getPage();
551 if ($pageposafter > $pageposbefore) {
552 $pdf->rollbackTransaction(
true);
553 $pageposafter = $pageposbefore;
555 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
557 $pdf->SetXY($this->posxref, $curY);
558 $posybefore = $pdf->GetY();
559 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
560 $pageposafter = $pdf->getPage();
561 $posyafter = $pdf->GetY();
562 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
563 if ($i == ($num - 1)) {
564 $pdf->AddPage($this->orientation,
'',
true);
565 if (!empty($tplidx)) {
566 $pdf->useTemplate($tplidx);
571 $pdf->setPage($pageposafter + 1);
578 $showpricebeforepagebreak = 1;
580 $showpricebeforepagebreak = 0;
583 $forcedesconsamepage = 1;
584 if ($forcedesconsamepage) {
585 $pdf->rollbackTransaction(
true);
586 $pageposafter = $pageposbefore;
587 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
589 $pdf->AddPage($this->orientation,
'',
true);
590 if (!empty($tplidx)) {
591 $pdf->useTemplate($tplidx);
596 $pdf->setPage($pageposafter + 1);
597 $pdf->SetFont(
'',
'', $default_font_size - 1);
598 $pdf->MultiCell(0, 3,
'');
599 $pdf->SetTextColor(0, 0, 0);
601 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
602 $curY = $tab_top_newpage + $heightoftitleline + 1;
605 $pdf->SetXY($this->posxref, $curY);
606 $posybefore = $pdf->GetY();
607 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
608 $pageposafter = $pdf->getPage();
609 $posyafter = $pdf->GetY();
614 $pdf->commitTransaction();
616 $posYAfterDescription = $pdf->GetY();
618 $nexY = $pdf->GetY();
619 $pageposafter = $pdf->getPage();
620 $pdf->setPage($pageposbefore);
621 $pdf->setTopMargin($this->marge_haute);
622 $pdf->setPageOrientation($this->orientation, 1, 0);
625 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
627 $pdf->setPage($pageposafter);
628 $curY = $tab_top_newpage + $heightoftitleline + 1;
631 $pdf->SetFont(
'',
'', $default_font_size - 1);
634 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
635 $date = $element->date_commande;
637 $date = $element->date;
639 $date = $element->datep;
642 $date = $element->date_contrat;
645 $date = $element->datev;
649 $pdf->SetXY($this->posxdate, $curY);
650 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
652 $pdf->SetXY($this->posxsociety, $curY);
653 if ($classname ==
'ExpenseReport') {
654 $fuser =
new User($this->db);
655 $fuser->fetch($element->fk_user_author);
656 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
658 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
662 if (empty($value[
'disableamount'])) {
663 $pdf->SetXY($this->posxamountht, $curY);
664 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
665 $pdf->SetXY($this->posxamountttc, $curY);
666 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
668 $pdf->SetXY($this->posxamountht, $curY);
669 if ($key ==
'agenda') {
670 $textforamount =
dol_trunc($element->label, 26);
671 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
673 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
680 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
682 $outputstatut = $element->getLibStatut(1);
684 $pdf->SetXY($this->posxstatut, $curY);
685 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
'',
'',
true, 0,
true);
687 if ($qualifiedfortotal) {
688 $total_ht += $element->total_ht;
689 $total_ttc += $element->total_ttc;
691 $nexY = $pdf->GetY();
695 if (empty($value[
'disableamount'])) {
697 $pdf->SetXY($this->posxref, $curY);
698 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
699 $pdf->SetXY($this->posxamountht, $curY);
700 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
701 $pdf->SetXY($this->posxamountttc, $curY);
702 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
703 $pdf->SetXY($this->posxstatut, $curY);
704 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
706 $nexY = $pdf->GetY() + 5;
714 while ($pagenb < $pageposafter) {
715 $pdf->setPage($pagenb);
718 $pdf->setPage($pagenb);
719 $pdf->setPageOrientation($this->orientation, 1, 0);
723 if (!empty($tplidx)) {
724 $pdf->useTemplate($tplidx);
731 if (method_exists($pdf,
'AliasNbPages')) {
732 $pdf->AliasNbPages();
737 $pdf->Output($file,
'F');
740 $hookmanager->initHooks(array(
'pdfgeneration'));
741 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
743 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
745 $this->error = $hookmanager->error;
746 $this->errors = $hookmanager->errors;
751 $this->result = array(
'fullpath' => $file);
755 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
759 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
807 global $langs,
$conf, $mysoc;
813 $pdf->SetTextColor(0, 0, 60);
814 $pdf->SetFont(
'',
'B', $default_font_size + 3);
816 $posx = $this->page_largeur - $this->marge_droite - 100;
817 $posy = $this->marge_haute;
819 $pdf->SetXY($this->marge_gauche, $posy);
822 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
824 if (is_readable($logo)) {
826 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
828 $pdf->SetTextColor(200, 0, 0);
829 $pdf->SetFont(
'',
'B', $default_font_size - 2);
830 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
831 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
834 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
837 $pdf->SetFont(
'',
'B', $default_font_size + 3);
838 $pdf->SetXY($posx, $posy);
839 $pdf->SetTextColor(0, 0, 60);
840 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
841 $pdf->SetFont(
'',
'', $default_font_size + 2);
844 $pdf->SetXY($posx, $posy);
845 $pdf->SetTextColor(0, 0, 60);
846 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
849 $pdf->SetXY($posx, $posy);
850 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
852 if (is_object(
$object->thirdparty)) {
854 $pdf->SetXY($posx, $posy);
855 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
858 $pdf->SetTextColor(0, 0, 60);