195 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
198 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
200 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
202 if (!is_object($outputlangs)) {
203 $outputlangs = $langs;
206 if (!empty($conf->global->MAIN_USE_FPDF)) {
207 $outputlangs->charset_output =
'ISO-8859-1';
211 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
214 if ($object->statut == $object::STATUS_DRAFT &&
getDolGlobalString(
'PROPALE_DRAFT_WATERMARK')) {
218 global $outputlangsbis;
219 $outputlangsbis =
null;
220 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
221 $outputlangsbis =
new Translate(
'', $conf);
222 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
223 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
226 $nblines = count($object->lines);
229 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
230 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
234 $realpatharray = array();
235 $this->atleastonephoto =
false;
236 if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE)) {
237 $objphoto =
new Product($this->db);
239 for ($i = 0; $i < $nblines; $i++) {
240 if (empty($object->lines[$i]->fk_product)) {
244 $objphoto->fetch($object->lines[$i]->fk_product);
247 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
248 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
250 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
251 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
255 foreach ($pdir as $midir) {
257 if ($conf->entity != $objphoto->entity) {
258 $dir = $conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
260 $dir = $conf->product->dir_output.
'/'.$midir;
263 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
265 if ($obj[
'photo_vignette']) {
266 $filename = $obj[
'photo_vignette'];
268 $filename = $obj[
'photo'];
271 $filename = $obj[
'photo'];
274 $realpath = $dir.$filename;
276 $this->atleastonephoto =
true;
281 if ($realpath && $arephoto) {
282 $realpatharray[$i] = $realpath;
287 if (count($realpatharray) == 0) {
288 $this->posxpicture = $this->posxtva;
291 if ($conf->propal->multidir_output[$conf->entity]) {
292 $object->fetch_thirdparty();
297 if ($object->specimen) {
298 $dir = $conf->propal->multidir_output[$conf->entity];
299 $file = $dir.
"/SPECIMEN.pdf";
302 $dir = $conf->propal->multidir_output[$object->entity].
"/".$objectref;
303 $file = $dir.
"/".$objectref.
".pdf";
306 if (!file_exists($dir)) {
308 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
313 if (file_exists($dir)) {
315 if (!is_object($hookmanager)) {
316 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
319 $hookmanager->initHooks(array(
'pdfgeneration'));
320 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
322 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
325 $nblines = count($object->lines);
331 $pdf->SetAutoPageBreak(1, 0);
333 if (class_exists(
'TCPDF')) {
334 $pdf->setPrintHeader(
false);
335 $pdf->setPrintFooter(
false);
339 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
340 $logodir = $conf->mycompany->dir_output;
341 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
342 $logodir = $conf->mycompany->multidir_output[$object->entity];
344 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
345 $tplidx = $pdf->importPage(1);
350 $pdf->SetDrawColor(128, 128, 128);
352 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
353 $pdf->SetSubject($outputlangs->transnoentities(
"PdfCommercialProposalTitle"));
354 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
355 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
356 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
358 $pdf->SetCompression(
false);
361 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
364 for ($i = 0; $i < $nblines; $i++) {
365 if ($object->lines[$i]->remise_percent) {
366 $this->atleastonediscount++;
373 if (!empty($tplidx)) {
374 $pdf->useTemplate($tplidx);
378 $heightforinfotot = 40;
379 $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE) ? (
pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities(
"ProposalCustomerSignature")) + 10) : 0;
380 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
381 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
384 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
385 $pdf->SetFont(
'',
'', $default_font_size - 1);
386 $pdf->MultiCell(0, 3,
'');
387 $pdf->SetTextColor(0, 0, 0);
390 $tab_top = 90 + $top_shift;
391 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
396 $height_incoterms = 0;
397 if (isModEnabled(
'incoterm')) {
398 $desc_incoterms = $object->getIncotermsForPDF();
399 if ($desc_incoterms) {
402 $pdf->SetFont(
'',
'', $default_font_size - 1);
403 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
404 $nexY = max($pdf->GetY(), $nexY);
405 $height_incoterms = $nexY - $tab_top;
408 $pdf->SetDrawColor(192, 192, 192);
409 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
411 $tab_top = $nexY + 6;
412 $height_incoterms += 4;
417 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
418 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
420 if (is_object($object->thirdparty)) {
421 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
422 $salerepobj =
new User($this->db);
423 $salerepobj->fetch($salereparray[0][
'id']);
424 if (!empty($salerepobj->signature)) {
425 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
431 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
432 if (!empty($extranote)) {
436 if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0) {
437 $tmpuser =
new User($this->db);
438 $tmpuser->fetch($object->user_author_id);
440 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
441 if ($tmpuser->email) $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
442 if ($tmpuser->office_phone) $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
447 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
449 $pagenb = $pdf->getPage();
453 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
454 $pageposbeforenote = $pagenb;
461 $pdf->startTransaction();
463 $pdf->SetFont(
'',
'', $default_font_size - 1);
464 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
466 $pageposafternote = $pdf->getPage();
467 $posyafter = $pdf->GetY();
469 if ($pageposafternote > $pageposbeforenote) {
470 $pdf->rollbackTransaction(
true);
473 while ($pagenb < $pageposafternote) {
476 if (!empty($tplidx)) {
477 $pdf->useTemplate($tplidx);
480 $this->
_pagehead($pdf, $object, 0, $outputlangs);
483 $pdf->setTopMargin($tab_top_newpage);
485 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
489 $pdf->setPage($pageposbeforenote);
490 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
491 $pdf->SetFont(
'',
'', $default_font_size - 1);
492 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
493 $pageposafternote = $pdf->getPage();
495 $posyafter = $pdf->GetY();
497 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
498 $pdf->AddPage(
'',
'',
true);
501 $pdf->setPage($pageposafternote);
502 $pdf->setTopMargin($tab_top_newpage);
504 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
510 $i = $pageposbeforenote;
511 while ($i < $pageposafternote) {
515 $pdf->SetDrawColor(128, 128, 128);
517 if ($i > $pageposbeforenote) {
518 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
519 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
521 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
522 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
526 $pdf->setPageOrientation(
'', 1, 0);
527 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
533 $pdf->setPage($pageposafternote);
534 if (!empty($tplidx)) {
535 $pdf->useTemplate($tplidx);
538 $this->
_pagehead($pdf, $object, 0, $outputlangs);
540 $height_note = $posyafter - $tab_top_newpage;
541 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
544 $pdf->commitTransaction();
545 $posyafter = $pdf->GetY();
546 $height_note = $posyafter - $tab_top;
547 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
550 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
552 $pdf->AddPage(
'',
'',
true);
555 $pdf->setPage($pageposafternote);
556 if (!empty($tplidx)) {
557 $pdf->useTemplate($tplidx);
560 $this->
_pagehead($pdf, $object, 0, $outputlangs);
563 $posyafter = $tab_top_newpage;
566 $tab_height = $tab_height - $height_note;
567 $tab_top = $posyafter + 6;
576 $pdf->startTransaction();
577 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
578 $pdf->rollbackTransaction(
true);
580 $nexY = $tab_top + $this->tabTitleHeight;
583 $pageposbeforeprintlines = $pdf->getPage();
584 $pagenb = $pageposbeforeprintlines;
585 for ($i = 0; $i < $nblines; $i++) {
587 $pdf->SetFont(
'',
'', $default_font_size - 1);
588 $pdf->SetTextColor(0, 0, 0);
591 $imglinesize = array();
592 if (!empty($realpatharray[$i])) {
596 $pdf->setTopMargin($tab_top_newpage);
597 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot);
598 $pageposbefore = $pdf->getPage();
600 $showpricebeforepagebreak = 1;
602 $posYAfterDescription = 0;
606 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
607 $pdf->AddPage(
'',
'',
true);
608 if (!empty($tplidx)) {
609 $pdf->useTemplate($tplidx);
611 $pdf->setPage($pageposbefore + 1);
613 $curY = $tab_top_newpage;
616 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
617 $showpricebeforepagebreak = 1;
619 $showpricebeforepagebreak = 0;
624 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
625 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
627 $posYAfterImage = $curY + $imglinesize[
'height'];
633 $pdf->startTransaction();
635 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
636 $pageposafter = $pdf->getPage();
638 if ($pageposafter > $pageposbefore) {
639 $pdf->rollbackTransaction(
true);
641 $pdf->setPageOrientation(
'', 1, $heightforfooter);
643 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
645 $pageposafter = $pdf->getPage();
646 $posyafter = $pdf->GetY();
648 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
649 if ($i == ($nblines - 1)) {
650 $pdf->AddPage(
'',
'',
true);
651 if (!empty($tplidx)) {
652 $pdf->useTemplate($tplidx);
654 $pdf->setPage($pageposafter + 1);
659 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
660 $showpricebeforepagebreak = 1;
662 $showpricebeforepagebreak = 0;
667 $pdf->commitTransaction();
669 $posYAfterDescription = $pdf->GetY();
672 $nexY = $pdf->GetY();
673 $pageposafter = $pdf->getPage();
675 $pdf->setPage($pageposbefore);
676 $pdf->setTopMargin($this->marge_haute);
677 $pdf->setPageOrientation(
'', 1, 0);
680 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
681 $pdf->setPage($pageposafter);
682 $curY = $tab_top_newpage;
685 $pdf->SetFont(
'',
'', $default_font_size - 1);
691 $nexY = max($pdf->GetY(), $nexY);
698 $nexY = max($pdf->GetY(), $nexY);
706 $nexY = max($pdf->GetY(), $nexY);
712 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
714 $nexY = max($pdf->GetY(), $nexY);
718 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
721 $nexY = max($pdf->GetY(), $nexY);
728 $nexY = max($pdf->GetY(), $nexY);
735 $nexY = max($pdf->GetY(), $nexY);
739 if (!empty($object->lines[$i]->array_options)) {
740 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
742 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
744 $nexY = max($pdf->GetY(), $nexY);
755 'outputlangs' => $outputlangs,
756 'hidedetails' => $hidedetails
758 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
762 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
763 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
765 $tvaligne = $object->lines[$i]->total_tva;
768 $localtax1ligne = $object->lines[$i]->total_localtax1;
769 $localtax2ligne = $object->lines[$i]->total_localtax2;
770 $localtax1_rate = $object->lines[$i]->localtax1_tx;
771 $localtax2_rate = $object->lines[$i]->localtax2_tx;
772 $localtax1_type = $object->lines[$i]->localtax1_type;
773 $localtax2_type = $object->lines[$i]->localtax2_type;
786 $vatrate = (string) $object->lines[$i]->tva_tx;
789 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
790 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
792 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
793 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
797 if ($localtax1_type && $localtax1ligne != 0) {
798 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
799 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
801 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
804 if ($localtax2_type && $localtax2ligne != 0) {
805 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
806 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
808 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
812 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
817 if (!isset($this->tva[$vatrate])) {
818 $this->tva[$vatrate] = 0;
820 $this->tva[$vatrate] += $tvaligne;
821 $vatcode = $object->lines[$i]->vat_src_code;
822 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
823 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
825 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
827 if ($posYAfterImage > $posYAfterDescription) {
828 $nexY = max($nexY, $posYAfterImage);
832 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
833 $pdf->setPage($pageposafter);
834 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
836 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
837 $pdf->SetLineStyle(array(
'dash'=>0));
843 while ($pagenb < $pageposafter) {
844 $pdf->setPage($pagenb);
845 if ($pagenb == $pageposbeforeprintlines) {
846 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
848 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
850 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
852 $pdf->setPage($pagenb);
853 $pdf->setPageOrientation(
'', 1, 0);
855 $this->
_pagehead($pdf, $object, 0, $outputlangs);
857 if (!empty($tplidx)) {
858 $pdf->useTemplate($tplidx);
862 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
863 if ($pagenb == $pageposafter) {
864 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
866 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
868 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
871 if (!empty($tplidx)) {
872 $pdf->useTemplate($tplidx);
876 $this->
_pagehead($pdf, $object, 0, $outputlangs);
882 if ($pagenb == $pageposbeforeprintlines) {
883 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
884 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
886 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
887 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
891 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
894 $posy = $this->
drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
905 if (empty($conf->global->PROPAL_DISABLE_SIGNATURE)) {
910 $this->
_pagefoot($pdf, $object, $outputlangs);
911 if (method_exists($pdf,
'AliasNbPages')) {
912 $pdf->AliasNbPages();
916 if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) {
917 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
919 $already_merged = array();
920 foreach ($object->lines as $line) {
921 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
926 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
928 $filetomerge->fetch_by_product($line->fk_product);
931 $already_merged[] = $line->fk_product;
933 $product =
new Product($this->db);
934 $product->fetch($line->fk_product);
936 if ($product->entity != $conf->entity) {
937 $entity_product_file = $product->entity;
939 $entity_product_file = $conf->entity;
943 if (count($filetomerge->lines) > 0) {
944 foreach ($filetomerge->lines as $linefile) {
945 if (!empty($linefile->id) && !empty($linefile->file_name)) {
947 if (isModEnabled(
"product")) {
948 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
949 } elseif (isModEnabled(
"service")) {
950 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
953 if (isModEnabled(
"product")) {
954 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
955 } elseif (isModEnabled(
"service")) {
956 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
960 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, LOG_DEBUG);
962 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
963 if (file_exists($infile) && is_readable($infile)) {
964 $pagecount = $pdf->setSourceFile($infile);
965 for ($i = 1; $i <= $pagecount; $i++) {
966 $tplIdx = $pdf->importPage($i);
967 if ($tplIdx !==
false) {
968 $s = $pdf->getTemplatesize($tplIdx);
969 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
970 $pdf->useTemplate($tplIdx);
972 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
985 $pdf->Output($file,
'F');
988 $hookmanager->initHooks(array(
'pdfgeneration'));
989 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
991 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
993 $this->error = $hookmanager->error;
994 $this->errors = $hookmanager->errors;
999 $this->result = array(
'fullpath'=>$file);
1003 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1007 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1036 global $conf, $mysoc;
1039 $pdf->SetFont(
'',
'', $default_font_size - 1);
1041 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1044 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1045 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1046 $pdf->SetXY($this->marge_gauche, $posy);
1047 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1049 $posy = $pdf->GetY() + 4;
1053 if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) {
1054 $displaydate =
"daytext";
1056 $displaydate =
"day";
1060 if (!empty($object->delivery_date)) {
1061 $outputlangs->load(
"sendings");
1062 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1063 $pdf->SetXY($this->marge_gauche, $posy);
1064 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1065 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1066 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1067 $pdf->SetXY($posxval, $posy);
1068 $dlp =
dol_print_date($object->delivery_date, $displaydate,
false, $outputlangs,
true);
1069 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1071 $posy = $pdf->GetY() + 1;
1072 } elseif ($object->availability_code || $object->availability) {
1073 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1074 $pdf->SetXY($this->marge_gauche, $posy);
1075 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1076 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1077 $pdf->SetTextColor(0, 0, 0);
1078 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1079 $pdf->SetXY($posxval, $posy);
1080 $lib_availability = $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) != (
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
1081 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1082 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1084 $posy = $pdf->GetY() + 1;
1088 if (empty($conf->global->PROPOSAL_PDF_HIDE_DELIVERYMODE) && $object->shipping_method_id > 0) {
1089 $outputlangs->load(
"sendings");
1091 $shipping_method_id = $object->shipping_method_id;
1092 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($this->emetteur->shipping_method_id)) {
1093 $shipping_method_id = $this->emetteur->shipping_method_id;
1095 $shipping_method_code =
dol_getIdFromCode($this->db, $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1096 $shipping_method_label =
dol_getIdFromCode($this->db, $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1098 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1099 $pdf->SetXY($this->marge_gauche, $posy);
1100 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1101 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1103 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1104 $pdf->SetXY($posxval, $posy);
1105 $lib_condition_paiement = ($outputlangs->transnoentities(
"SendingMethod".strtoupper($shipping_method_code)) !=
"SendingMethod".strtoupper($shipping_method_code)) ? $outputlangs->trans(
"SendingMethod".strtoupper($shipping_method_code)) : $shipping_method_label;
1106 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1107 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1109 $posy = $pdf->GetY() + 1;
1113 if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTTERM) && $object->cond_reglement_code) {
1114 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1115 $pdf->SetXY($this->marge_gauche, $posy);
1116 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1117 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1119 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1120 $pdf->SetXY($posxval, $posy);
1121 $lib_condition_paiement = $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) != (
'PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
1122 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1123 if ($object->deposit_percent > 0) {
1124 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
1126 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1128 $posy = $pdf->GetY() + 3;
1131 if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTMODE)) {
1133 if ($object->mode_reglement_code
1134 && $object->mode_reglement_code !=
'CHQ'
1135 && $object->mode_reglement_code !=
'VIR') {
1136 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1137 $pdf->SetXY($this->marge_gauche, $posy);
1138 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1139 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1140 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1141 $pdf->SetXY($posxval, $posy);
1142 $lib_mode_reg = $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) != (
'PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1143 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1145 $posy = $pdf->GetY() + 2;
1149 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1152 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1153 $account =
new Account($this->db);
1156 $pdf->SetXY($this->marge_gauche, $posy);
1157 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1158 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1159 $posy = $pdf->GetY() + 1;
1161 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1162 $pdf->SetXY($this->marge_gauche, $posy);
1163 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1164 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1165 $posy = $pdf->GetY() + 2;
1169 $pdf->SetXY($this->marge_gauche, $posy);
1170 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1171 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1172 $posy = $pdf->GetY() + 1;
1174 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1175 $pdf->SetXY($this->marge_gauche, $posy);
1176 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1177 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1178 $posy = $pdf->GetY() + 2;
1185 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1186 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1187 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1188 if ($object->fk_bank > 0) {
1189 $bankid = $object->fk_bank;
1191 $account =
new Account($this->db);
1192 $account->fetch($bankid);
1194 $curx = $this->marge_gauche;
1197 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1219 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis =
null)
1221 global $conf, $mysoc, $hookmanager;
1225 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1226 $outputlangsbis =
new Translate(
'', $conf);
1227 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1228 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1229 $default_font_size--;
1234 $pdf->SetFont(
'',
'', $default_font_size - 1);
1239 if ($this->page_largeur < 210) {
1242 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1248 $pdf->SetFillColor(255, 255, 255);
1249 $pdf->SetXY($col1x, $tab2_top);
1250 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L', 1);
1252 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1253 $pdf->SetXY($col2x, $tab2_top);
1254 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0,
'R', 1);
1257 $pdf->SetFillColor(248, 248, 248);
1259 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1261 $this->atleastoneratenotnull = 0;
1262 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1263 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1264 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1270 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1271 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1275 foreach ($localtax_rate as $tvakey => $tvaval) {
1280 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1283 if (preg_match(
'/\*/', $tvakey)) {
1284 $tvakey = str_replace(
'*',
'', $tvakey);
1285 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1287 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1289 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1290 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1292 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1294 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1295 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1303 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1304 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1308 foreach ($localtax_rate as $tvakey => $tvaval) {
1313 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1316 if (preg_match(
'/\*/', $tvakey)) {
1317 $tvakey = str_replace(
'*',
'', $tvakey);
1318 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1320 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1322 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1323 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1325 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1327 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1328 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1335 foreach ($this->tva as $tvakey => $tvaval) {
1337 $this->atleastoneratenotnull++;
1340 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1343 if (preg_match(
'/\*/', $tvakey)) {
1344 $tvakey = str_replace(
'*',
'', $tvakey);
1345 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1347 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1349 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
1350 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1352 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1353 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1360 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1361 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1365 foreach ($localtax_rate as $tvakey => $tvaval) {
1370 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1373 if (preg_match(
'/\*/', $tvakey)) {
1374 $tvakey = str_replace(
'*',
'', $tvakey);
1375 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1377 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1380 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1381 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1383 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1385 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1386 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1394 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1395 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1399 foreach ($localtax_rate as $tvakey => $tvaval) {
1405 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1408 if (preg_match(
'/\*/', $tvakey)) {
1409 $tvakey = str_replace(
'*',
'', $tvakey);
1410 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1412 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1415 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1416 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1418 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1420 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1421 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1429 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1430 $pdf->SetTextColor(0, 0, 60);
1431 $pdf->SetFillColor(224, 224, 224);
1432 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1434 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1435 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1439 $pdf->SetTextColor(0, 0, 0);
1447 if ($deja_regle > 0) {
1451 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1452 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1454 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1455 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1474 $pdf->SetTextColor(0, 0, 60);
1475 $pdf->SetFillColor(224, 224, 224);
1476 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1477 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1479 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1480 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1482 $pdf->SetFont(
'',
'', $default_font_size - 1);
1483 $pdf->SetTextColor(0, 0, 0);
1487 return ($tab2_top + ($tab2_hl * $index));
1561 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1563 global $conf, $langs;
1565 $ltrdirection =
'L';
1566 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1569 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1575 $pdf->SetTextColor(0, 0, 60);
1576 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1580 $posy = $this->marge_haute;
1581 $posx = $this->page_largeur - $this->marge_droite - $w;
1583 $pdf->SetXY($this->marge_gauche, $posy);
1587 if ($this->emetteur->logo) {
1588 $logodir = $conf->mycompany->dir_output;
1589 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1590 $logodir = $conf->mycompany->multidir_output[$object->entity];
1593 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1595 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1597 if (is_readable($logo)) {
1599 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1601 $pdf->SetTextColor(200, 0, 0);
1602 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1603 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1604 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1607 $text = $this->emetteur->name;
1608 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1612 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1613 $pdf->SetXY($posx, $posy);
1614 $pdf->SetTextColor(0, 0, 60);
1615 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1616 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1617 if ($object->statut == $object::STATUS_DRAFT) {
1618 $pdf->SetTextColor(128, 0, 0);
1619 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1622 $pdf->MultiCell($w, 4, $title,
'',
'R');
1624 $pdf->SetFont(
'',
'B', $default_font_size);
1639 $pdf->SetFont(
'',
'', $default_font_size - 2);
1641 if ($object->ref_client) {
1643 $pdf->SetXY($posx, $posy);
1644 $pdf->SetTextColor(0, 0, 60);
1645 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
1648 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1649 $object->fetch_projet();
1650 if (!empty($object->project->ref)) {
1652 $pdf->SetXY($posx, $posy);
1653 $pdf->SetTextColor(0, 0, 60);
1654 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1658 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1659 $object->fetch_projet();
1660 if (!empty($object->project->ref)) {
1661 $outputlangs->load(
"projects");
1663 $pdf->SetXY($posx, $posy);
1664 $pdf->SetTextColor(0, 0, 60);
1665 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1669 if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) {
1670 $displaydate =
"daytext";
1672 $displaydate =
"day";
1676 $posy = $pdf->getY();
1677 $pdf->SetXY($posx, $posy);
1678 $pdf->SetTextColor(0, 0, 60);
1679 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1682 $pdf->SetXY($posx, $posy);
1683 $pdf->SetTextColor(0, 0, 60);
1685 $title = $outputlangs->transnoentities(
"DateEndPropal");
1686 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1687 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1689 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1691 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
1693 $pdf->SetXY($posx, $posy);
1694 $pdf->SetTextColor(0, 0, 60);
1695 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1699 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1700 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1701 if (count($arrayidcontact) > 0) {
1702 $usertmp =
new User($this->db);
1703 $usertmp->fetch($arrayidcontact[0]);
1705 $pdf->SetXY($posx, $posy);
1706 $pdf->SetTextColor(0, 0, 60);
1707 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1715 $current_y = $pdf->getY();
1716 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1717 if ($current_y < $pdf->getY()) {
1718 $top_shift = $pdf->getY() - $current_y;
1723 $carac_emetteur =
'';
1725 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1726 if (count($arrayidcontact) > 0) {
1727 $object->fetch_user($arrayidcontact[0]);
1728 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1729 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1731 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1733 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1735 $carac_emetteur .=
"\n";
1738 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1741 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1742 $posy += $top_shift;
1743 $posx = $this->marge_gauche;
1744 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1745 $posx = $this->page_largeur - $this->marge_droite - 80;
1748 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1749 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1752 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1753 $pdf->SetTextColor(0, 0, 0);
1754 $pdf->SetFont(
'',
'', $default_font_size - 2);
1755 $pdf->SetXY($posx, $posy - 5);
1756 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1757 $pdf->SetXY($posx, $posy);
1758 $pdf->SetFillColor(230, 230, 230);
1759 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1760 $pdf->SetTextColor(0, 0, 60);
1764 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1765 $pdf->SetXY($posx + 2, $posy + 3);
1766 $pdf->SetFont(
'',
'B', $default_font_size);
1767 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1768 $posy = $pdf->getY();
1772 $pdf->SetXY($posx + 2, $posy);
1773 $pdf->SetFont(
'',
'', $default_font_size - 1);
1774 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1778 $usecontact =
false;
1779 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1780 if (count($arrayidcontact) > 0) {
1782 $result = $object->fetch_contact($arrayidcontact[0]);
1786 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1787 $thirdparty = $object->contact;
1789 $thirdparty = $object->thirdparty;
1795 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
1798 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1799 if ($this->page_largeur < 210) {
1802 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1803 $posy += $top_shift;
1804 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1805 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1806 $posx = $this->marge_gauche;
1810 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1811 $pdf->SetTextColor(0, 0, 0);
1812 $pdf->SetFont(
'',
'', $default_font_size - 2);
1813 $pdf->SetXY($posx + 2, $posy - 5);
1814 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1815 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1819 $pdf->SetXY($posx + 2, $posy + 3);
1820 $pdf->SetFont(
'',
'B', $default_font_size);
1821 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1823 $posy = $pdf->getY();
1826 $pdf->SetFont(
'',
'', $default_font_size - 1);
1827 $pdf->SetXY($posx + 2, $posy);
1828 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1831 $pdf->SetTextColor(0, 0, 0);