178 global $conf, $hookmanager, $langs, $user;
182 if (!is_object($outputlangs)) {
183 $outputlangs = $langs;
187 $outputlangs->charset_output =
'ISO-8859-1';
191 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
193 if ($conf->project->multidir_output[$object->entity]) {
197 $dir = $conf->project->multidir_output[$object->entity];
198 if (!preg_match(
'/specimen/i', $objectref)) {
199 $dir .=
"/".$objectref;
201 $file = $dir.
"/".$objectref.
".pdf";
203 if (!file_exists($dir)) {
205 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
210 if (file_exists($dir)) {
212 if (!is_object($hookmanager)) {
213 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
216 $hookmanager->initHooks(array(
'pdfgeneration'));
217 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
219 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
224 $pdf->SetAutoPageBreak(1, 0);
226 $heightforinfotot = 40;
227 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
228 $heightforfooter = $this->marge_basse + 8;
230 $heightforfooter += 6;
233 if (class_exists(
'TCPDF')) {
234 $pdf->setPrintHeader(
false);
235 $pdf->setPrintFooter(
false);
240 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
241 $tplidx = $pdf->importPage(1);
245 $task =
new Task($this->db);
246 $tasksarray = array();
247 $tasksarray = $task->getTasksArray(0, 0, $object->id);
250 if (!$object->id > 0) {
251 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
254 $object->lines = $tasksarray;
255 $nblines = count($object->lines);
259 $pdf->SetDrawColor(128, 128, 128);
261 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
262 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
263 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
264 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
265 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Project"));
267 $pdf->SetCompression(
false);
270 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
273 $pdf->AddPage($this->orientation);
274 if (!empty($tplidx)) {
275 $pdf->useTemplate($tplidx);
278 $this->
_pagehead($pdf, $object, 1, $outputlangs);
279 $pdf->SetFont(
'',
'', $default_font_size - 1);
280 $pdf->MultiCell(0, 3,
'');
281 $pdf->SetTextColor(0, 0, 0);
284 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
286 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
289 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
300 $nexY = $pdf->GetY();
301 $height_note = $nexY - $tab_top;
304 $pdf->SetDrawColor(192, 192, 192);
305 $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2);
307 $tab_height = $tab_height - $height_note;
308 $tab_top = $nexY + 6;
313 $heightoftitleline = 10;
314 $iniY = $tab_top + $heightoftitleline + 1;
315 $curY = $tab_top + $heightoftitleline + 1;
316 $nexY = $tab_top + $heightoftitleline + 1;
318 $listofreferent = array(
321 'title'=>
"ListProposalsAssociatedProject",
324 'datefieldname'=>
'datep',
325 'test'=> isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
328 'name'=>
"CustomersOrders",
329 'title'=>
"ListOrdersAssociatedProject",
332 'datefieldname'=>
'date_commande',
333 'test'=> isModEnabled(
'commande') && $user->hasRight(
'commande',
'lire'),
336 'name'=>
"CustomersInvoices",
337 'title'=>
"ListInvoicesAssociatedProject",
341 'datefieldname'=>
'datef',
342 'test'=> isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire'),
344 'invoice_predefined'=>array(
345 'name'=>
"PredefinedInvoices",
346 'title'=>
"ListPredefinedInvoicesAssociatedProject",
347 'class'=>
'FactureRec',
348 'table'=>
'facture_rec',
349 'datefieldname'=>
'datec',
350 'test'=> isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire'),
352 'order_supplier'=>array(
353 'name'=>
"SuppliersOrders",
354 'title'=>
"ListSupplierOrdersAssociatedProject",
355 'class'=>
'CommandeFournisseur',
356 'table'=>
'commande_fournisseur',
357 'datefieldname'=>
'date_commande',
358 'test'=>(isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->rights->fournisseur->commande->lire) || (isModEnabled(
"supplier_order") && $user->rights->supplier_order->lire),
360 'invoice_supplier'=>array(
361 'name'=>
"BillsSuppliers",
362 'title'=>
"ListSupplierInvoicesAssociatedProject",
363 'class'=>
'FactureFournisseur',
365 'table'=>
'facture_fourn',
366 'datefieldname'=>
'datef',
367 'test'=>(isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->rights->fournisseur->facture->lire) || (isModEnabled(
"supplier_invoice") && $user->rights->supplier_invoice->lire),
371 'title'=>
"ListContractAssociatedProject",
374 'datefieldname'=>
'date_contrat',
375 'test'=> isModEnabled(
'contrat') && $user->hasRight(
'contrat',
'lire'),
377 'intervention'=>array(
378 'name'=>
"Interventions",
379 'title'=>
"ListFichinterAssociatedProject",
380 'class'=>
'Fichinter',
381 'table'=>
'fichinter',
382 'datefieldname'=>
'date_valid',
384 'test'=>isModEnabled(
'ficheinter') && $user->hasRight(
'ficheinter',
'lire'),
385 'lang'=>
'interventions'),
387 'name'=>
"TripsAndExpenses",
388 'title'=>
"ListExpenseReportsAssociatedProject",
389 'class'=>
'Deplacement',
390 'table'=>
'deplacement',
391 'datefieldname'=>
'dated',
394 'test'=>isModEnabled(
'deplacement') && $user->rights->deplacement->lire,
396 'expensereport'=>array(
397 'name'=>
"ExpensesReports",
398 'title'=>
"ListExpenseReportsAssociatedProject",
399 'class'=>
'ExpenseReport',
400 'table'=>
'expensereport',
401 'datefieldname'=>
'dated',
404 'test'=>isModEnabled(
'expensereport') && $user->rights->expensereport->lire,
408 'title'=>
"ListActionsAssociatedProject",
409 'class'=>
'ActionComm',
410 'table'=>
'actioncomm',
411 'datefieldname'=>
'datep',
413 'test'=> isModEnabled(
'agenda') && $user->rights->agenda->allactions->read,
417 $hookmanager->initHooks(array(
'completeListOfReferent'));
418 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent'=>$listofreferent], $object, $action);
419 if (!empty($hookmanager->resArray)) {
420 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
423 foreach ($listofreferent as $key => $value) {
424 $title = $value[
'title'];
425 $classname = $value[
'class'];
426 $tablename = $value[
'table'];
427 $datefieldname = $value[
'datefieldname'];
428 $qualified = $value[
'test'];
429 $langstoload = $value[
'lang'];
430 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
431 $langs->load($langstoload);
438 $elementarray = $object->get_element_list($key, $tablename, $datefieldname,
'',
'', $projectField);
440 $num = count($elementarray);
442 $nexY = $pdf->GetY() + 5;
445 $pdf->SetFont(
'',
'', $default_font_size - 1);
446 $pdf->SetTextColor(0, 0, 0);
448 $pdf->SetXY($this->posxref, $curY);
449 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
451 $selectList = $formproject->select_element($tablename, $object->thirdparty->id,
'', -2, $projectField);
452 $nexY = $pdf->GetY() + 1;
454 $pdf->SetXY($this->posxref, $curY);
455 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
456 $pdf->SetXY($this->posxdate, $curY);
457 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
458 $pdf->SetXY($this->posxsociety, $curY);
459 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
460 if ($classname ==
'ExpenseReport') {
461 $titlethirdparty = $langs->trans(
"User");
463 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
464 if (empty($value[
'disableamount'])) {
465 $pdf->SetXY($this->posxamountht, $curY);
466 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
467 $pdf->SetXY($this->posxamountttc, $curY);
468 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
470 $pdf->SetXY($this->posxamountht, $curY);
471 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
473 $pdf->SetXY($this->posxstatut, $curY);
474 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
476 if (is_array($elementarray) && count($elementarray) > 0) {
477 $nexY = $pdf->GetY();
481 $num = count($elementarray);
484 for ($i = 0; $i < $num; $i++) {
486 $pdf->SetFont(
'',
'', $default_font_size - 1);
487 $pdf->SetTextColor(0, 0, 0);
489 $pdf->setTopMargin($tab_top_newpage);
490 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
491 $pageposbefore = $pdf->getPage();
494 $idofelement = $elementarray[$i];
495 if ($classname ==
'ExpenseReport') {
498 $expensereportline->fetch($idofelement);
499 $idofelement = $expensereportline->fk_expensereport;
502 $element =
new $classname($this->db);
503 $element->fetch($idofelement);
504 $element->fetch_thirdparty();
507 $qualifiedfortotal =
true;
508 if ($key ==
'invoice') {
509 if ($element->close_code ==
'replaced') {
510 $qualifiedfortotal =
false;
514 $showpricebeforepagebreak = 1;
516 $pdf->startTransaction();
518 $pdf->SetXY($this->posxref, $curY);
519 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
520 $pageposafter = $pdf->getPage();
521 if ($pageposafter > $pageposbefore) {
522 $pdf->rollbackTransaction(
true);
523 $pageposafter = $pageposbefore;
525 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
527 $pdf->SetXY($this->posxref, $curY);
528 $posybefore = $pdf->GetY();
529 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
530 $pageposafter = $pdf->getPage();
531 $posyafter = $pdf->GetY();
532 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
533 if ($i == ($num - 1)) {
534 $pdf->AddPage($this->orientation,
'',
true);
535 if (!empty($tplidx)) {
536 $pdf->useTemplate($tplidx);
539 $this->
_pagehead($pdf, $object, 0, $outputlangs);
541 $pdf->setPage($pageposafter + 1);
548 $showpricebeforepagebreak = 1;
550 $showpricebeforepagebreak = 0;
553 $forcedesconsamepage = 1;
554 if ($forcedesconsamepage) {
555 $pdf->rollbackTransaction(
true);
556 $pageposafter = $pageposbefore;
557 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
559 $pdf->AddPage($this->orientation,
'',
true);
560 if (!empty($tplidx)) {
561 $pdf->useTemplate($tplidx);
564 $this->
_pagehead($pdf, $object, 0, $outputlangs);
566 $pdf->setPage($pageposafter + 1);
567 $pdf->SetFont(
'',
'', $default_font_size - 1);
568 $pdf->MultiCell(0, 3,
'');
569 $pdf->SetTextColor(0, 0, 0);
571 $pdf->setPageOrientation($this->orientation, 1, $heightforfooter);
572 $curY = $tab_top_newpage + $heightoftitleline + 1;
575 $pdf->SetXY($this->posxref, $curY);
576 $posybefore = $pdf->GetY();
577 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1,
'L');
578 $pageposafter = $pdf->getPage();
579 $posyafter = $pdf->GetY();
584 $pdf->commitTransaction();
586 $posYAfterDescription = $pdf->GetY();
588 $nexY = $pdf->GetY();
589 $pageposafter = $pdf->getPage();
590 $pdf->setPage($pageposbefore);
591 $pdf->setTopMargin($this->marge_haute);
592 $pdf->setPageOrientation($this->orientation, 1, 0);
595 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
597 $pdf->setPage($pageposafter);
598 $curY = $tab_top_newpage + $heightoftitleline + 1;
601 $pdf->SetFont(
'',
'', $default_font_size - 1);
604 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
605 $date = $element->date_commande;
607 $date = $element->date;
609 $date = $element->datep;
612 $date = $element->date_contrat;
615 $date = $element->datev;
619 $pdf->SetXY($this->posxdate, $curY);
620 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
622 $pdf->SetXY($this->posxsociety, $curY);
623 if ($classname ==
'ExpenseReport') {
624 $fuser =
new User($this->db);
625 $fuser->fetch($element->fk_user_author);
626 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
628 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
632 if (empty($value[
'disableamount'])) {
633 $pdf->SetXY($this->posxamountht, $curY);
634 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
635 $pdf->SetXY($this->posxamountttc, $curY);
636 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
638 $pdf->SetXY($this->posxamountht, $curY);
639 if ($key ==
'agenda') {
640 $textforamount =
dol_trunc($element->label, 26);
641 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
643 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
650 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
652 $outputstatut = $element->getLibStatut(1);
654 $pdf->SetXY($this->posxstatut, $curY);
655 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
'',
'',
true, 0,
true);
657 if ($qualifiedfortotal) {
658 $total_ht = $total_ht + $element->total_ht;
659 $total_ttc = $total_ttc + $element->total_ttc;
661 $nexY = $pdf->GetY();
665 if (empty($value[
'disableamount'])) {
667 $pdf->SetXY($this->posxref, $curY);
668 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
669 $pdf->SetXY($this->posxamountht, $curY);
670 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
671 $pdf->SetXY($this->posxamountttc, $curY);
672 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
673 $pdf->SetXY($this->posxstatut, $curY);
674 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
676 $nexY = $pdf->GetY() + 5;
684 while ($pagenb < $pageposafter) {
685 $pdf->setPage($pagenb);
686 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
688 $pdf->setPage($pagenb);
689 $pdf->setPageOrientation($this->orientation, 1, 0);
691 $this->
_pagehead($pdf, $object, 0, $outputlangs);
693 if (!empty($tplidx)) {
694 $pdf->useTemplate($tplidx);
700 $this->
_pagefoot($pdf, $object, $outputlangs);
701 if (method_exists($pdf,
'AliasNbPages')) {
702 $pdf->AliasNbPages();
707 $pdf->Output($file,
'F');
710 $hookmanager->initHooks(array(
'pdfgeneration'));
711 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
713 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
715 $this->error = $hookmanager->error;
716 $this->errors = $hookmanager->errors;
721 $this->result = array(
'fullpath'=>$file);
725 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
729 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
775 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
777 global $langs, $conf, $mysoc;
783 $pdf->SetTextColor(0, 0, 60);
784 $pdf->SetFont(
'',
'B', $default_font_size + 3);
786 $posx = $this->page_largeur - $this->marge_droite - 100;
787 $posy = $this->marge_haute;
789 $pdf->SetXY($this->marge_gauche, $posy);
792 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
794 if (is_readable($logo)) {
796 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
798 $pdf->SetTextColor(200, 0, 0);
799 $pdf->SetFont(
'',
'B', $default_font_size - 2);
800 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
801 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
804 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
807 $pdf->SetFont(
'',
'B', $default_font_size + 3);
808 $pdf->SetXY($posx, $posy);
809 $pdf->SetTextColor(0, 0, 60);
810 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
811 $pdf->SetFont(
'',
'', $default_font_size + 2);
814 $pdf->SetXY($posx, $posy);
815 $pdf->SetTextColor(0, 0, 60);
816 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date($object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
819 $pdf->SetXY($posx, $posy);
820 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date($object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
822 if (is_object($object->thirdparty)) {
824 $pdf->SetXY($posx, $posy);
825 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".$object->thirdparty->getFullName($outputlangs),
'',
'R');
828 $pdf->SetTextColor(0, 0, 60);