204 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
207 global
$conf, $hookmanager, $langs, $user;
211 if (!is_object($outputlangs)) {
212 $outputlangs = $langs;
216 $outputlangs->charset_output =
'ISO-8859-1';
220 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"projects"));
227 if (!preg_match(
'/specimen/i', $objectref)) {
228 $dir .=
"/".$objectref;
230 $file = $dir.
"/".$objectref.
".pdf";
232 if (!file_exists($dir)) {
234 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
239 if (file_exists($dir)) {
241 if (!is_object($hookmanager)) {
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
245 $hookmanager->initHooks(array(
'pdfgeneration'));
246 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
248 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
253 $pdf->setAutoPageBreak(
true, 0);
255 $heightforinfotot = 40;
257 $heightforfooter = $this->marge_basse + 8;
259 $heightforfooter += 6;
262 if (class_exists(
'TCPDF')) {
263 $pdf->setPrintHeader(
false);
264 $pdf->setPrintFooter(
false);
269 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
270 $tplidx = $pdf->importPage(1);
274 $task =
new Task($this->db);
275 $tasksarray = array();
276 $tasksarray = $task->getTasksArray(
null,
null,
$object->id);
280 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
284 $nblines = count(
$object->lines);
288 $pdf->SetDrawColor(128, 128, 128);
290 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
291 $pdf->SetSubject($outputlangs->transnoentities(
"Project"));
292 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
293 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
294 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Project"));
296 $pdf->SetCompression(
false);
300 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
303 $pdf->AddPage($this->orientation);
304 if (!empty($tplidx)) {
305 $pdf->useTemplate($tplidx);
309 $pdf->SetFont(
'',
'', $default_font_size - 1);
310 $pdf->MultiCell(0, 3,
'');
311 $pdf->SetTextColor(0, 0, 0);
314 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
316 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
319 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
328 $pdf->SetFont(
'',
'', $default_font_size - 1);
329 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2,
dol_htmlentitiesbr($notetoshow), 0, 1);
330 $nexY = $pdf->GetY();
331 $height_note = $nexY - $tab_top;
334 $pdf->SetDrawColor(192, 192, 192);
335 $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');
337 $tab_height -= $height_note;
338 $tab_top = $nexY + 6;
343 $heightoftitleline = 10;
344 $iniY = $tab_top + $heightoftitleline + 1;
345 $curY = $tab_top + $heightoftitleline + 1;
346 $nexY = $tab_top + $heightoftitleline + 1;
348 $listofreferent = array(
350 'name' =>
"Proposals",
351 'title' =>
"ListProposalsAssociatedProject",
354 'datefieldname' =>
'datep',
355 'test' =>
isModEnabled(
'propal') && $user->hasRight(
'propal',
'lire'),
358 'name' =>
"CustomersOrders",
359 'title' =>
"ListOrdersAssociatedProject",
360 'class' =>
'Commande',
361 'table' =>
'commande',
362 'datefieldname' =>
'date_commande',
363 'test' =>
isModEnabled(
'order') && $user->hasRight(
'commande',
'lire'),
366 'name' =>
"CustomersInvoices",
367 'title' =>
"ListInvoicesAssociatedProject",
368 'class' =>
'Facture',
370 'table' =>
'facture',
371 'datefieldname' =>
'datef',
372 'test' =>
isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
374 'invoice_predefined' => array(
375 'name' =>
"PredefinedInvoices",
376 'title' =>
"ListPredefinedInvoicesAssociatedProject",
377 'class' =>
'FactureRec',
378 'table' =>
'facture_rec',
379 'datefieldname' =>
'datec',
380 'test' =>
isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire'),
382 'order_supplier' => array(
383 'name' =>
"SuppliersOrders",
384 'title' =>
"ListSupplierOrdersAssociatedProject",
385 'class' =>
'CommandeFournisseur',
386 'table' =>
'commande_fournisseur',
387 'datefieldname' =>
'date_commande',
388 'test' => (
isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'commande',
'lire')) || (
isModEnabled(
"supplier_order") && $user->hasRight(
'supplier_order',
'lire')),
390 'invoice_supplier' => array(
391 'name' =>
"BillsSuppliers",
392 'title' =>
"ListSupplierInvoicesAssociatedProject",
393 'class' =>
'FactureFournisseur',
395 'table' =>
'facture_fourn',
396 'datefieldname' =>
'datef',
397 'test' => (
isModEnabled(
"fournisseur") && !
getDolGlobalString(
'MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight(
'fournisseur',
'facture',
'lire')) || (
isModEnabled(
"supplier_invoice") && $user->hasRight(
'supplier_invoice',
'lire')),
400 'name' =>
"Contracts",
401 'title' =>
"ListContractAssociatedProject",
402 'class' =>
'Contrat',
403 'table' =>
'contrat',
404 'datefieldname' =>
'date_contrat',
405 'test' =>
isModEnabled(
'contract') && $user->hasRight(
'contrat',
'lire'),
406 'lang' =>
'contract'),
407 'intervention' => array(
408 'name' =>
"Interventions",
409 'title' =>
"ListFichinterAssociatedProject",
410 'class' =>
'Fichinter',
411 'table' =>
'fichinter',
412 'datefieldname' =>
'date_valid',
413 'disableamount' => 1,
414 'test' =>
isModEnabled(
'intervention') && $user->hasRight(
'ficheinter',
'lire'),
415 'lang' =>
'interventions'),
416 'expensereport' => array(
417 'name' =>
"ExpensesReports",
418 'title' =>
"ListExpenseReportsAssociatedProject",
419 'class' =>
'ExpenseReport',
420 'table' =>
'expensereport',
421 'datefieldname' =>
'date_debut',
423 'disableamount' => 0,
424 'test' =>
isModEnabled(
'expensereport') && $user->hasRight(
'expensereport',
'lire'),
428 'title' =>
"ListActionsAssociatedProject",
429 'class' =>
'ActionComm',
430 'table' =>
'actioncomm',
431 'datefieldname' =>
'datep',
432 'disableamount' => 1,
433 'test' =>
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'allactions',
'read'),
437 $hookmanager->initHooks(array(
'completeListOfReferent'));
438 $hookmanager->executeHooks(
'completeListOfReferent', [
'listofreferent' => $listofreferent],
$object, $action);
439 if (!empty($hookmanager->resArray)) {
440 $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
445 foreach ($listofreferent as $key => $value) {
446 $title = $value[
'title'];
447 $classname = $value[
'class'];
448 $tablename = $value[
'table'];
449 $datefieldname = $value[
'datefieldname'];
450 $qualified = $value[
'test'];
451 $langstoload = $value[
'lang'];
452 $projectField = isset($value[
'project_field']) ? $value[
'project_field'] :
'fk_projet';
453 $langs->load($langstoload);
460 $elementarray =
$object->get_element_list($key, $tablename, $datefieldname, 0, 0, $projectField);
462 $num = is_array($elementarray) ? count($elementarray) : $elementarray;
464 $nexY = $pdf->GetY() + 5;
467 $pdf->SetFont(
'',
'', $default_font_size - 1);
468 $pdf->SetTextColor(0, 0, 0);
470 $pdf->SetXY($this->posxref, $curY);
471 $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0,
'L');
473 $selectList = $formproject->select_element($tablename,
$object->thirdparty->id,
'', -2, $projectField);
474 $nexY = $pdf->GetY() + 1;
476 $pdf->SetXY($this->posxref, $curY);
477 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities(
"Ref"), 1,
'L');
478 $pdf->SetXY($this->posxdate, $curY);
479 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities(
"Date"), 1,
'C');
480 $pdf->SetXY($this->posxsociety, $curY);
481 $titlethirdparty = $outputlangs->transnoentities(
"ThirdParty");
482 if ($classname ==
'ExpenseReport') {
483 $titlethirdparty = $langs->trans(
"User");
485 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1,
'L');
486 if (empty($value[
'disableamount'])) {
487 $pdf->SetXY($this->posxamountht, $curY);
488 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities(
"AmountHTShort"), 1,
'R');
489 $pdf->SetXY($this->posxamountttc, $curY);
490 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities(
"AmountTTCShort"), 1,
'R');
492 $pdf->SetXY($this->posxamountht, $curY);
493 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
495 $pdf->SetXY($this->posxstatut, $curY);
496 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Status"), 1,
'R');
498 if (is_array($elementarray) && count($elementarray) > 0) {
499 $nexY = $pdf->GetY();
503 $num = count($elementarray);
506 for ($i = 0; $i < $num; $i++) {
508 $pdf->SetFont(
'',
'', $default_font_size - 1);
509 $pdf->SetTextColor(0, 0, 0);
511 $pdf->setTopMargin($tab_top_newpage);
512 $pdf->setPageOrientation($this->orientation,
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
513 $pageposbefore = $pdf->getPage();
516 $idofelement = (int) $elementarray[$i];
517 if ($classname ==
'ExpenseReport') {
520 $expensereportline->fetch($idofelement);
521 $idofelement = $expensereportline->fk_expensereport;
524 $element =
new $classname($this->db);
525 $element->fetch($idofelement);
526 $element->fetch_thirdparty();
529 $qualifiedfortotal =
true;
530 if ($key ==
'invoice') {
531 if ($element->close_code ==
'replaced') {
532 $qualifiedfortotal =
false;
536 $showpricebeforepagebreak = 1;
538 $pdf->startTransaction();
540 $pdf->SetXY($this->posxref, $curY);
541 $pdf->MultiCell($this->posxdate - $this->posxref, 3, (
string) $element->ref, 1,
'L');
542 $pageposafter = $pdf->getPage();
543 if ($pageposafter > $pageposbefore) {
544 $pdf->rollbackTransaction(
true);
545 $pageposafter = $pageposbefore;
547 $pdf->setPageOrientation($this->orientation,
true, $heightforfooter);
549 $pdf->SetXY($this->posxref, $curY);
550 $posybefore = $pdf->GetY();
551 $pdf->MultiCell($this->posxdate - $this->posxref, 3, (
string) $element->ref, 1,
'L');
552 $pageposafter = $pdf->getPage();
553 $posyafter = $pdf->GetY();
554 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
555 if ($i == ($num - 1)) {
556 $pdf->AddPage($this->orientation,
'',
true);
557 if (!empty($tplidx)) {
558 $pdf->useTemplate($tplidx);
563 $pdf->setPage($pageposafter + 1);
570 $showpricebeforepagebreak = 1;
572 $showpricebeforepagebreak = 0;
575 $forcedesconsamepage = 1;
576 if ($forcedesconsamepage) {
577 $pdf->rollbackTransaction(
true);
578 $pageposafter = $pageposbefore;
579 $pdf->setPageOrientation($this->orientation,
true, $heightforfooter);
581 $pdf->AddPage($this->orientation,
'',
true);
582 if (!empty($tplidx)) {
583 $pdf->useTemplate($tplidx);
588 $pdf->setPage($pageposafter + 1);
589 $pdf->SetFont(
'',
'', $default_font_size - 1);
590 $pdf->MultiCell(0, 3,
'');
591 $pdf->SetTextColor(0, 0, 0);
593 $pdf->setPageOrientation($this->orientation,
true, $heightforfooter);
594 $curY = $tab_top_newpage + $heightoftitleline + 1;
597 $pdf->SetXY($this->posxref, $curY);
598 $posybefore = $pdf->GetY();
599 $pdf->MultiCell($this->posxdate - $this->posxref, 3, (
string) $element->ref, 1,
'L');
600 $pageposafter = $pdf->getPage();
601 $posyafter = $pdf->GetY();
606 $pdf->commitTransaction();
608 $posYAfterDescription = $pdf->GetY();
610 $nexY = $pdf->GetY();
611 $pageposafter = $pdf->getPage();
612 $pdf->setPage($pageposbefore);
613 $pdf->setTopMargin($this->marge_haute);
614 $pdf->setPageOrientation($this->orientation,
true, 0);
617 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
619 $pdf->setPage($pageposafter);
620 $curY = $tab_top_newpage + $heightoftitleline + 1;
623 $pdf->SetFont(
'',
'', $default_font_size - 1);
626 if ($tablename ==
'commande_fournisseur' || $tablename ==
'supplier_order') {
627 $date = $element->date_commande;
629 $date = $element->date;
631 $date = $element->datep;
634 $date = $element->date_contrat;
637 $date = $element->datev;
640 $date = $element->date_debut;
644 $pdf->SetXY($this->posxdate, $curY);
645 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3,
dol_print_date($date,
'day'), 1,
'C');
647 $pdf->SetXY($this->posxsociety, $curY);
648 if ($classname ==
'ExpenseReport') {
649 $fuser =
new User($this->db);
650 $fuser->fetch($element->fk_user_author);
651 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1,
'L');
653 $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name :
''), 1,
'L');
657 if (empty($value[
'disableamount'])) {
658 $pdf->SetXY($this->posxamountht, $curY);
659 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($element->total_ht) :
''), 1,
'R');
660 $pdf->SetXY($this->posxamountttc, $curY);
661 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($element->total_ttc) :
''), 1,
'R');
663 $pdf->SetXY($this->posxamountht, $curY);
664 if ($key ==
'agenda') {
665 $textforamount =
dol_trunc($element->label, 26);
666 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1,
'L');
668 $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3,
"", 1,
'R');
675 $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
677 $outputstatut = $element->getLibStatut(1);
679 $pdf->SetXY($this->posxstatut, $curY);
680 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1,
'R',
false, 1,
null,
null,
true, 0,
true);
682 if ($qualifiedfortotal) {
683 $total_ht += $element->total_ht;
684 $total_ttc += $element->total_ttc;
686 $nexY = $pdf->GetY();
690 if (empty($value[
'disableamount'])) {
692 $pdf->SetXY($this->posxref, $curY);
693 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3,
"TOTAL", 1,
'L');
694 $pdf->SetXY($this->posxamountht, $curY);
695 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ?
price($total_ht) :
''), 1,
'R');
696 $pdf->SetXY($this->posxamountttc, $curY);
697 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ?
price($total_ttc) :
''), 1,
'R');
698 $pdf->SetXY($this->posxstatut, $curY);
699 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities(
"Nb").
" ".$num, 1,
'L');
701 $nexY = $pdf->GetY() + 5;
709 while ($pagenb < $pageposafter) {
710 $pdf->setPage($pagenb);
713 $pdf->setPage($pagenb);
714 $pdf->setPageOrientation($this->orientation,
true, 0);
718 if (!empty($tplidx)) {
719 $pdf->useTemplate($tplidx);
726 if (method_exists($pdf,
'AliasNbPages')) {
727 $pdf->AliasNbPages();
732 $pdf->Output($file,
'F');
735 $hookmanager->initHooks(array(
'pdfgeneration'));
736 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
738 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
739 $this->warnings = $hookmanager->warnings;
741 $this->error = $hookmanager->error;
742 $this->errors = $hookmanager->errors;
749 $this->result = array(
'fullpath' => $file);
753 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
757 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"PROJECT_OUTPUTDIR");
811 $pdf->SetTextColor(0, 0, 60);
812 $pdf->SetFont(
'',
'B', $default_font_size + 3);
814 $posx = $this->page_largeur - $this->marge_droite - 100;
815 $posy = $this->marge_haute;
817 $pdf->SetXY($this->marge_gauche, $posy);
820 $logo =
$conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
822 if (is_readable($logo)) {
824 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
826 $pdf->SetTextColor(200, 0, 0);
827 $pdf->SetFont(
'',
'B', $default_font_size - 2);
828 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
829 $pdf->MultiCell(100, 3, $langs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
832 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0,
'L');
835 $pdf->SetFont(
'',
'B', $default_font_size + 3);
836 $pdf->SetXY($posx, $posy);
837 $pdf->SetTextColor(0, 0, 60);
838 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Project").
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
839 $pdf->SetFont(
'',
'', $default_font_size + 2);
842 $pdf->SetXY($posx, $posy);
843 $pdf->SetTextColor(0, 0, 60);
844 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateStart").
" : ".
dol_print_date(
$object->date_start,
'day',
false, $outputlangs,
true),
'',
'R');
847 $pdf->SetXY($posx, $posy);
848 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"DateEnd").
" : ".
dol_print_date(
$object->date_end,
'day',
false, $outputlangs,
true),
'',
'R');
850 if (is_object(
$object->thirdparty)) {
852 $pdf->SetXY($posx, $posy);
853 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"ThirdParty").
" : ".
$object->thirdparty->getFullName($outputlangs),
'',
'R');
856 $pdf->SetTextColor(0, 0, 60);