32 require_once DOL_DOCUMENT_ROOT.
'/core/modules/propale/modules_propale.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
62 public $update_main_doc_field;
73 public $version =
'dolibarr';
129 global $conf, $langs, $mysoc;
132 $langs->loadLangs(array(
"main",
"bills"));
135 $this->
name =
"cyan";
136 $this->
description = $langs->trans(
'DocModelCyanDescription');
137 $this->update_main_doc_field = 1;
142 $this->page_largeur = $formatarray[
'width'];
143 $this->page_hauteur = $formatarray[
'height'];
144 $this->format = array($this->page_largeur, $this->page_hauteur);
150 $this->option_logo = 1;
151 $this->option_tva = 1;
152 $this->option_modereg = 1;
153 $this->option_condreg = 1;
154 $this->option_multilang = 1;
155 $this->option_escompte = 0;
156 $this->option_credit_note = 0;
157 $this->option_freetext = 1;
158 $this->option_draft_watermark = 1;
159 $this->watermark =
'';
162 $this->emetteur = $mysoc;
163 if (empty($this->emetteur->country_code)) {
164 $this->emetteur->country_code = substr($langs->defaultlang, -2);
168 $this->posxdesc = $this->marge_gauche + 1;
171 $this->tabTitleHeight = 5;
175 $this->tva = array();
176 $this->tva_array = array();
177 $this->localtax1 = array();
178 $this->localtax2 = array();
179 $this->atleastoneratenotnull = 0;
180 $this->atleastonediscount = 0;
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;
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)) {
948 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
950 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
954 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
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 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1293 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1301 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1302 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1306 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 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1326 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1333 foreach ($this->tva as $tvakey => $tvaval) {
1335 $this->atleastoneratenotnull++;
1338 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1341 if (preg_match(
'/\*/', $tvakey)) {
1342 $tvakey = str_replace(
'*',
'', $tvakey);
1343 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1345 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1347 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
1348 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1350 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1351 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1358 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1359 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1363 foreach ($localtax_rate as $tvakey => $tvaval) {
1368 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1371 if (preg_match(
'/\*/', $tvakey)) {
1372 $tvakey = str_replace(
'*',
'', $tvakey);
1373 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1375 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1378 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1379 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1380 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1381 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1389 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1390 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1394 foreach ($localtax_rate as $tvakey => $tvaval) {
1400 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1403 if (preg_match(
'/\*/', $tvakey)) {
1404 $tvakey = str_replace(
'*',
'', $tvakey);
1405 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1407 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1410 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1411 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1413 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1414 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1422 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1423 $pdf->SetTextColor(0, 0, 60);
1424 $pdf->SetFillColor(224, 224, 224);
1425 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1427 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1428 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1432 $pdf->SetTextColor(0, 0, 0);
1440 if ($deja_regle > 0) {
1444 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1445 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1447 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1448 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1467 $pdf->SetTextColor(0, 0, 60);
1468 $pdf->SetFillColor(224, 224, 224);
1469 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1470 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1472 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1473 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1475 $pdf->SetFont(
'',
'', $default_font_size - 1);
1476 $pdf->SetTextColor(0, 0, 0);
1480 return ($tab2_top + ($tab2_hl * $index));
1498 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1508 $currency = !empty($currency) ? $currency : $conf->currency;
1512 $pdf->SetTextColor(0, 0, 0);
1513 $pdf->SetFont(
'',
'', $default_font_size - 2);
1515 if (empty($hidetop)) {
1516 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1517 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1518 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1521 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1522 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1525 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1526 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1530 $pdf->SetDrawColor(128, 128, 128);
1531 $pdf->SetFont(
'',
'', $default_font_size - 1);
1534 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1536 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1538 if (empty($hidetop)) {
1539 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
1554 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1556 global $conf, $langs;
1558 $ltrdirection =
'L';
1559 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1562 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1568 $pdf->SetTextColor(0, 0, 60);
1569 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1573 $posy = $this->marge_haute;
1574 $posx = $this->page_largeur - $this->marge_droite - $w;
1576 $pdf->SetXY($this->marge_gauche, $posy);
1580 if ($this->emetteur->logo) {
1581 $logodir = $conf->mycompany->dir_output;
1582 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1583 $logodir = $conf->mycompany->multidir_output[$object->entity];
1586 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1588 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1590 if (is_readable($logo)) {
1592 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1594 $pdf->SetTextColor(200, 0, 0);
1595 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1596 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1597 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1600 $text = $this->emetteur->name;
1601 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1605 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1606 $pdf->SetXY($posx, $posy);
1607 $pdf->SetTextColor(0, 0, 60);
1608 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1609 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1610 if ($object->statut == $object::STATUS_DRAFT) {
1611 $pdf->SetTextColor(128, 0, 0);
1612 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1615 $pdf->MultiCell($w, 4, $title,
'',
'R');
1617 $pdf->SetFont(
'',
'B', $default_font_size);
1632 $pdf->SetFont(
'',
'', $default_font_size - 2);
1634 if ($object->ref_client) {
1636 $pdf->SetXY($posx, $posy);
1637 $pdf->SetTextColor(0, 0, 60);
1638 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
1641 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1642 $object->fetch_projet();
1643 if (!empty($object->project->ref)) {
1645 $pdf->SetXY($posx, $posy);
1646 $pdf->SetTextColor(0, 0, 60);
1647 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1651 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1652 $object->fetch_projet();
1653 if (!empty($object->project->ref)) {
1654 $outputlangs->load(
"projects");
1656 $pdf->SetXY($posx, $posy);
1657 $pdf->SetTextColor(0, 0, 60);
1658 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1662 if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) {
1663 $displaydate =
"daytext";
1665 $displaydate =
"day";
1669 $posy = $pdf->getY();
1670 $pdf->SetXY($posx, $posy);
1671 $pdf->SetTextColor(0, 0, 60);
1672 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1675 $pdf->SetXY($posx, $posy);
1676 $pdf->SetTextColor(0, 0, 60);
1678 $title = $outputlangs->transnoentities(
"DateEndPropal");
1679 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1680 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1682 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1684 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
1686 $pdf->SetXY($posx, $posy);
1687 $pdf->SetTextColor(0, 0, 60);
1688 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1692 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1693 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1694 if (count($arrayidcontact) > 0) {
1695 $usertmp =
new User($this->db);
1696 $usertmp->fetch($arrayidcontact[0]);
1698 $pdf->SetXY($posx, $posy);
1699 $pdf->SetTextColor(0, 0, 60);
1700 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1708 $current_y = $pdf->getY();
1709 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1710 if ($current_y < $pdf->getY()) {
1711 $top_shift = $pdf->getY() - $current_y;
1716 $carac_emetteur =
'';
1718 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1719 if (count($arrayidcontact) > 0) {
1720 $object->fetch_user($arrayidcontact[0]);
1721 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1722 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1724 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1726 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1728 $carac_emetteur .=
"\n";
1731 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1734 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1735 $posy += $top_shift;
1736 $posx = $this->marge_gauche;
1737 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1738 $posx = $this->page_largeur - $this->marge_droite - 80;
1741 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1742 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1745 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1746 $pdf->SetTextColor(0, 0, 0);
1747 $pdf->SetFont(
'',
'', $default_font_size - 2);
1748 $pdf->SetXY($posx, $posy - 5);
1749 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1750 $pdf->SetXY($posx, $posy);
1751 $pdf->SetFillColor(230, 230, 230);
1752 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1753 $pdf->SetTextColor(0, 0, 60);
1757 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1758 $pdf->SetXY($posx + 2, $posy + 3);
1759 $pdf->SetFont(
'',
'B', $default_font_size);
1760 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1761 $posy = $pdf->getY();
1765 $pdf->SetXY($posx + 2, $posy);
1766 $pdf->SetFont(
'',
'', $default_font_size - 1);
1767 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1771 $usecontact =
false;
1772 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1773 if (count($arrayidcontact) > 0) {
1775 $result = $object->fetch_contact($arrayidcontact[0]);
1779 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)))) {
1780 $thirdparty = $object->contact;
1782 $thirdparty = $object->thirdparty;
1788 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
1791 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1792 if ($this->page_largeur < 210) {
1795 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1796 $posy += $top_shift;
1797 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1798 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1799 $posx = $this->marge_gauche;
1803 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1804 $pdf->SetTextColor(0, 0, 0);
1805 $pdf->SetFont(
'',
'', $default_font_size - 2);
1806 $pdf->SetXY($posx + 2, $posy - 5);
1807 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1808 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1812 $pdf->SetXY($posx + 2, $posy + 3);
1813 $pdf->SetFont(
'',
'B', $default_font_size);
1814 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1816 $posy = $pdf->getY();
1819 $pdf->SetFont(
'',
'', $default_font_size - 1);
1820 $pdf->SetXY($posx + 2, $posy);
1821 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1824 $pdf->SetTextColor(0, 0, 0);
1838 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1840 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1841 return pdf_pagefoot($pdf, $outputlangs,
'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1857 $tab_top = $posy + 4;
1861 $largcol = ($this->page_largeur - $this->marge_droite - $posx);
1865 $pdf->SetFillColor(255, 255, 255);
1866 $pdf->SetXY($posx, $tab_top);
1867 $pdf->SetFont(
'',
'', $default_font_size - 2);
1868 $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities(
"ProposalCustomerSignature"), 0,
'L', 1);
1870 $pdf->SetXY($posx, $tab_top + $tab_hl);
1871 $pdf->MultiCell($largcol, $tab_hl * 3,
'', 1,
'R');
1872 if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1873 $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
1876 return ($tab_hl * 7);
1890 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1892 global $conf, $hookmanager;
1895 $this->defaultContentsFieldsStyle = array(
1897 'padding' => array(1, 0.5, 1, 0.5),
1901 $this->defaultTitlesFieldsStyle = array(
1903 'padding' => array(0.5, 0, 0.5, 0),
1925 $this->cols[
'desc'] = array(
1930 'textkey' =>
'Designation',
1934 'padding' => array(0.5, 0.5, 0.5, 0.5),
1938 'padding' => array(1, 0.5, 1, 1.5),
1944 $this->cols[
'photo'] = array(
1946 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1949 'textkey' =>
'Photo',
1953 'padding' => array(0, 0, 0, 0),
1955 'border-left' =>
false,
1958 if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1959 $this->cols[
'photo'][
'status'] =
true;
1960 $this->cols[
'photo'][
'border-left'] =
true;
1965 $this->cols[
'vat'] = array(
1972 'border-left' =>
true,
1975 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1976 $this->cols[
'vat'][
'status'] =
true;
1980 $this->cols[
'subprice'] = array(
1985 'textkey' =>
'PriceUHT'
1987 'border-left' =>
true,
1992 $nblines = count($object->lines);
1993 for ($i = 0; $i < $nblines; $i++) {
1995 $tmpwidth = max($tmpwidth, $tmpwidth2);
1997 if ($tmpwidth > 10) {
1998 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
2002 $this->cols[
'qty'] = array(
2009 'border-left' =>
true,
2013 $this->cols[
'unit'] = array(
2020 'border-left' =>
true,
2023 $this->cols[
'unit'][
'status'] =
true;
2027 $this->cols[
'discount'] = array(
2032 'textkey' =>
'ReductionShort'
2034 'border-left' =>
true,
2036 if ($this->atleastonediscount) {
2037 $this->cols[
'discount'][
'status'] =
true;
2040 $rank = $rank + 1000;
2041 $this->cols[
'totalexcltax'] = array(
2044 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
2046 'textkey' =>
'TotalHTShort'
2048 'border-left' =>
true,
2051 $rank = $rank + 1010;
2052 $this->cols[
'totalincltax'] = array(
2055 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
2057 'textkey' =>
'TotalTTCShort'
2059 'border-left' =>
true,
2063 if (!empty($object->lines)) {
2064 $line = reset($object->lines);
2068 $parameters = array(
2069 'object' => $object,
2070 'outputlangs' => $outputlangs,
2071 'hidedetails' => $hidedetails,
2072 'hidedesc' => $hidedesc,
2073 'hideref' => $hideref
2076 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
2079 } elseif (empty($reshook)) {
2080 $this->cols = array_replace($this->cols, $hookmanager->resArray);
2082 $this->cols = $hookmanager->resArray;