176 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
179 global $user, $langs, $conf, $hookmanager, $mysoc;
181 if (!is_object($outputlangs)) {
182 $outputlangs = $langs;
185 if (!empty($conf->global->MAIN_USE_FPDF)) {
186 $outputlangs->charset_output =
'ISO-8859-1';
190 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
192 global $outputlangsbis;
193 $outputlangsbis =
null;
194 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
195 $outputlangsbis =
new Translate(
'', $conf);
196 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
197 $outputlangsbis->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
200 if (!isset($object->lines) || !is_array($object->lines)) {
201 $object->lines = array();
204 $nblines = count($object->lines);
207 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
208 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
212 $realpatharray = array();
214 if ($conf->mrp->dir_output) {
215 $object->fetch_thirdparty();
218 $amount_credit_notes_included = 0;
219 $amount_deposits_included = 0;
224 if ($object->specimen) {
225 $dir = $conf->mrp->dir_output;
226 $file = $dir.
"/SPECIMEN.pdf";
229 $dir = $conf->mrp->dir_output.
'/'.$objectref;
230 $file = $dir.
"/".$objectref.
".pdf";
233 if (!file_exists($dir)) {
235 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
240 if (file_exists($dir)) {
242 if (!is_object($hookmanager)) {
243 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
246 $hookmanager->initHooks(array(
'pdfgeneration'));
247 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
249 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
251 $nblines = count($object->lines);
255 $heightforinfotot = 50;
256 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
257 $heightforfooter = $this->marge_basse + 8;
258 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
259 $heightforfooter += 6;
261 $pdf->SetAutoPageBreak(1, 0);
263 if (class_exists(
'TCPDF')) {
264 $pdf->setPrintHeader(
false);
265 $pdf->setPrintFooter(
false);
269 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
270 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
271 $tplidx = $pdf->importPage(1);
276 $pdf->SetDrawColor(128, 128, 128);
278 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
279 $pdf->SetSubject($outputlangs->transnoentities(
"Mo"));
280 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
281 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
282 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Mo").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
284 $pdf->SetCompression(
false);
287 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
293 if (!empty($tplidx)) {
294 $pdf->useTemplate($tplidx);
297 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->MultiCell(0, 3,
'');
300 $pdf->SetTextColor(0, 0, 0);
302 $tab_top = 90 + $top_shift;
303 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
305 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
309 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
312 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
313 if (!empty($extranote)) {
317 $pagenb = $pdf->getPage();
319 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
320 $pageposbeforenote = $pagenb;
329 $pdf->startTransaction();
331 $pdf->SetFont(
'',
'', $default_font_size - 1);
332 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
334 $pageposafternote = $pdf->getPage();
335 $posyafter = $pdf->GetY();
337 if ($pageposafternote > $pageposbeforenote) {
338 $pdf->rollbackTransaction(
true);
341 while ($pagenb < $pageposafternote) {
344 if (!empty($tplidx)) {
345 $pdf->useTemplate($tplidx);
348 $this->
_pagehead($pdf, $object, 0, $outputlangs);
351 $pdf->setTopMargin($tab_top_newpage);
353 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
357 $pdf->setPage($pageposbeforenote);
358 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
359 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
361 $pageposafternote = $pdf->getPage();
363 $posyafter = $pdf->GetY();
365 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
366 $pdf->AddPage(
'',
'',
true);
369 $pdf->setPage($pageposafternote);
370 $pdf->setTopMargin($tab_top_newpage);
372 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
378 $i = $pageposbeforenote;
379 while ($i < $pageposafternote) {
383 $pdf->SetDrawColor(128, 128, 128);
385 if ($i > $pageposbeforenote) {
386 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
387 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
389 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
390 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
394 $pdf->setPageOrientation(
'', 1, 0);
395 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
401 $pdf->setPage($pageposafternote);
402 if (!empty($tplidx)) {
403 $pdf->useTemplate($tplidx);
406 $this->
_pagehead($pdf, $object, 0, $outputlangs);
408 $height_note = $posyafter - $tab_top_newpage;
409 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
412 $pdf->commitTransaction();
413 $posyafter = $pdf->GetY();
414 $height_note = $posyafter - $tab_top;
415 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
418 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
420 $pdf->AddPage(
'',
'',
true);
423 $pdf->setPage($pageposafternote);
424 if (!empty($tplidx)) {
425 $pdf->useTemplate($tplidx);
428 $this->
_pagehead($pdf, $object, 0, $outputlangs);
431 $posyafter = $tab_top_newpage;
435 $tab_height = $tab_height - $height_note;
436 $tab_top = $posyafter + 6;
441 $nexY = $tab_top + 5;
447 $pageposbeforeprintlines = $pdf->getPage();
448 $pagenb = $pageposbeforeprintlines;
450 $bom =
new BOM($this->db);
451 $bom -> fetch($object->fk_bom);
453 $nblines = count($bom->lines);
455 for ($i = 0; $i < $nblines; $i++) {
457 $pdf->SetFont(
'',
'', $default_font_size - 1);
458 $pdf->SetTextColor(0, 0, 0);
460 $prod =
new Product($this->db);
461 $prod->fetch($bom->lines[$i]->fk_product);
464 $imglinesize = array();
465 if (!empty($realpatharray[$i])) {
469 $pdf->setTopMargin($tab_top_newpage);
470 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
471 $pageposbefore = $pdf->getPage();
473 $showpricebeforepagebreak = 1;
475 $posYAfterDescription = 0;
478 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
479 $pdf->AddPage(
'',
'',
true);
480 if (!empty($tplidx)) {
481 $pdf->useTemplate($tplidx);
484 $this->
_pagehead($pdf, $object, 0, $outputlangs);
486 $pdf->setPage($pageposbefore + 1);
488 $curY = $tab_top_newpage;
491 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
492 $showpricebeforepagebreak = 1;
494 $showpricebeforepagebreak = 0;
498 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
499 $curX = $this->posxpicture - 1;
500 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
502 $posYAfterImage = $curY + $imglinesize[
'height'];
505 $curX = $this->posxdesc - 1;
506 $showpricebeforepagebreak = 1;
509 $pdf->startTransaction();
513 $pageposafter = $pdf->getPage();
514 $posyafter = $pdf->GetY();
515 if ($pageposafter > $pageposbefore) {
516 $pdf->rollbackTransaction(
true);
521 $pageposafter = $pdf->getPage();
522 $posyafter = $pdf->GetY();
523 } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
524 if ($i == ($nblines - 1)) {
525 $pdf->AddPage(
'',
'',
true);
526 if (!empty($tplidx)) {
527 $pdf->useTemplate($tplidx);
530 $pdf->setPage($pageposafter + 1);
534 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
535 $showpricebeforepagebreak = 1;
537 $showpricebeforepagebreak = 0;
542 $pdf->commitTransaction();
544 $posYAfterDescription = $pdf->GetY();
547 $nexY = $pdf->GetY();
548 $pageposafter = $pdf->getPage();
549 $pdf->setPage($pageposbefore);
550 $pdf->setTopMargin($this->marge_haute);
551 $pdf->setPageOrientation(
'', 1, 0);
554 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
555 $pdf->setPage($pageposafter);
556 $curY = $tab_top_newpage;
560 $pdf->startTransaction();
566 $pageposafter = $pdf->getPage();
567 $posyafter = $pdf->GetY();
568 if ($pageposafter > $pageposbefore) {
569 $pdf->rollbackTransaction(
true);
573 $pageposafter = $pdf->getPage();
574 $posyafter = $pdf->GetY();
575 } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
576 if ($i == ($nblines - 1)) {
577 $pdf->AddPage(
'',
'',
true);
578 if (!empty($tplidx)) {
579 $pdf->useTemplate($tplidx);
582 $pdf->setPage($pageposafter + 1);
586 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
587 $showpricebeforepagebreak = 1;
589 $showpricebeforepagebreak = 0;
594 $pdf->commitTransaction();
596 $posYAfterDescription = max($posYAfterDescription, $pdf->GetY());
599 $nexY = max($nexY, $pdf->GetY());
600 $pageposafter = $pdf->getPage();
601 $pdf->setPage($pageposbefore);
602 $pdf->setTopMargin($this->marge_haute);
603 $pdf->setPageOrientation(
'', 1, 0);
606 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
607 $pdf->setPage($pageposafter);
608 $curY = $tab_top_newpage;
611 $pdf->SetFont(
'',
'', $default_font_size - 1);
616 $qty = $bom->lines[$i]->qty;
618 $nexY = max($pdf->GetY(), $nexY);
624 $qtytot = $object->qty * $bom->lines[$i]->qty;
626 $nexY = max($pdf->GetY(), $nexY);
631 $array = array_filter(array($prod->length, $prod->width, $prod->height));
632 $dim = implode(
"x", $array);
634 $nexY = max($pdf->GetY(), $nexY);
642 if ($pagenb == $pageposbeforeprintlines) {
643 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
644 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
646 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
647 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
651 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
657 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
662 $this->
_pagefoot($pdf, $object, $outputlangs);
663 if (method_exists($pdf,
'AliasNbPages')) {
664 $pdf->AliasNbPages();
669 $pdf->Output($file,
'F');
672 $hookmanager->initHooks(array(
'pdfgeneration'));
673 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
675 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
677 $this->error = $hookmanager->error;
678 $this->errors = $hookmanager->errors;
683 $this->result = array(
'fullpath'=>$file);
687 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
691 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
727 global $conf, $mysoc;
731 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
732 $pdf->SetFont(
'',
'B', $default_font_size - 2);
733 $pdf->SetXY($this->marge_gauche, $posy);
734 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
736 $posy = $pdf->GetY() + 4;
742 if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
743 $pdf->SetFont(
'',
'B', $default_font_size - 2);
744 $pdf->SetXY($this->marge_gauche, $posy);
745 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
746 $pdf->MultiCell(80, 4, $titre, 0,
'L');
748 $pdf->SetFont(
'',
'', $default_font_size - 2);
749 $pdf->SetXY($posxval, $posy);
750 $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);
751 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
752 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0,
'L');
754 $posy = $pdf->GetY() + 3;
758 if (!empty($object->mode_reglement_code)) {
759 $pdf->SetFont(
'',
'B', $default_font_size - 2);
760 $pdf->SetXY($this->marge_gauche, $posy);
761 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
762 $pdf->MultiCell(80, 5, $titre, 0,
'L');
764 $pdf->SetFont(
'',
'', $default_font_size - 2);
765 $pdf->SetXY($posxval, $posy);
766 $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);
767 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
769 $posy = $pdf->GetY() + 2;
788 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
791 global $conf, $mysoc;
797 $pdf->SetFont(
'',
'', $default_font_size - 1);
802 if ($this->page_largeur < 210) {
805 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
811 $pdf->SetFillColor(255, 255, 255);
812 $pdf->SetXY($col1x, $tab2_top);
813 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
815 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
816 $pdf->SetXY($col2x, $tab2_top);
817 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
820 $pdf->SetFillColor(248, 248, 248);
822 $this->atleastoneratenotnull = 0;
823 foreach ($this->tva as $tvakey => $tvaval) {
825 $this->atleastoneratenotnull++;
828 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
832 if (preg_match(
'/\*/', $tvakey)) {
833 $tvakey = str_replace(
'*',
'', $tvakey);
834 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
837 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
838 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
839 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
841 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
842 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
845 if (!$this->atleastoneratenotnull) {
847 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
848 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
850 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
851 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
854 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
856 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
857 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
858 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
859 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
863 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
865 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
866 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
867 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
868 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
874 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
875 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
879 foreach ($localtax_rate as $tvakey => $tvaval) {
884 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
887 if (preg_match(
'/\*/', $tvakey)) {
888 $tvakey = str_replace(
'*',
'', $tvakey);
889 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
891 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
892 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
893 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
895 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
896 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
904 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
905 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
909 foreach ($localtax_rate as $tvakey => $tvaval) {
914 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
917 if (preg_match(
'/\*/', $tvakey)) {
918 $tvakey = str_replace(
'*',
'', $tvakey);
919 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
921 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
922 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
923 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
925 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
926 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
934 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
935 $pdf->SetTextColor(0, 0, 60);
936 $pdf->SetFillColor(224, 224, 224);
937 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
939 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
940 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
941 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
942 $pdf->SetFont(
'',
'', $default_font_size - 1);
943 $pdf->SetTextColor(0, 0, 0);
945 $creditnoteamount = 0;
950 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
951 if (!empty($object->paye)) {
955 if ($deja_regle > 0) {
959 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
960 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
961 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
962 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
965 $pdf->SetTextColor(0, 0, 60);
966 $pdf->SetFillColor(224, 224, 224);
967 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
968 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
970 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
971 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
973 $pdf->SetFont(
'',
'', $default_font_size - 1);
974 $pdf->SetTextColor(0, 0, 0);
978 return ($tab2_top + ($tab2_hl * $index));
1065 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1067 global $langs, $conf, $mysoc;
1069 $ltrdirection =
'L';
1070 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1073 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1087 $pdf->SetTextColor(0, 0, 60);
1088 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1090 $posx = $this->page_largeur - $this->marge_droite - 100;
1091 $posy = $this->marge_haute;
1094 $pdf->SetXY($this->marge_gauche, $posy);
1097 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
1098 if ($this->emetteur->logo) {
1099 if (is_readable($logo)) {
1101 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1103 $pdf->SetTextColor(200, 0, 0);
1104 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1105 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1106 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
1109 $text = $this->emetteur->name;
1110 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1113 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1114 $pdf->SetXY($posx, $posy);
1115 $pdf->SetTextColor(0, 0, 60);
1116 $title = $outputlangs->transnoentities(
"Mo").
" ".$outputlangs->convToOutputCharset($object->ref);
1117 $pdf->MultiCell(100, 3, $title,
'',
'R');
1120 if ($object->ref_supplier) {
1122 $pdf->SetFont(
'',
'B', $default_font_size);
1123 $pdf->SetXY($posx, $posy);
1124 $pdf->SetTextColor(0, 0, 60);
1125 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1129 $pdf->SetFont(
'',
'', $default_font_size - 1);
1130 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1131 $object->fetch_projet();
1132 if (!empty($object->project->ref)) {
1134 $pdf->SetXY($posx, $posy);
1135 $pdf->SetTextColor(0, 0, 60);
1136 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1140 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1141 $object->fetch_projet();
1142 if (!empty($object->project->ref)) {
1143 $outputlangs->load(
"projects");
1145 $pdf->SetXY($posx, $posy);
1146 $langs->load(
"projects");
1147 $pdf->SetTextColor(0, 0, 60);
1148 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1152 if (!empty($object->date_approve)) {
1154 $pdf->SetXY($posx, $posy);
1155 $pdf->SetTextColor(0, 0, 60);
1156 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"MoDate").
" : ".
dol_print_date($object->date_approve,
"day",
false, $outputlangs,
true),
'',
'R');
1159 $pdf->SetXY($posx, $posy);
1160 $pdf->SetTextColor(255, 0, 0);
1161 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ToApprove"),
'',
'R');
1165 $prodToMake =
new Product($this->db);
1166 $resProdToMake = $prodToMake->fetch($object->fk_product);
1168 if ($resProdToMake > 0) {
1171 $pdf->SetFont(
'',
'B', $default_font_size + 1);
1172 $pdf->SetXY($posx, $posy);
1173 $pdf->SetTextColor(0, 0, 60);
1174 $pdf->MultiCell($w, 3, $prodToMake->ref,
'',
'R');
1178 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1179 $pdf->SetXY($posx, $posy);
1180 $pdf->SetTextColor(0, 0, 60);
1181 $pdf->MultiCell($w, 3, html_entity_decode($prodToMake->description),
'',
'R',
false, 1,
'',
'',
true, 0,
false,
true, 51,
'T',
true);
1182 $posy = $pdf->GetY() - 5;
1185 $array = array_filter(array($prodToMake->length, $prodToMake->width, $prodToMake->height));
1186 $dim = implode(
"x", $array);
1189 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1190 $pdf->SetXY($posx, $posy);
1191 $pdf->SetTextColor(0, 0, 60);
1192 $pdf->MultiCell($w, 3, $dim,
'',
'R');
1197 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1198 $pdf->SetXY($posx, $posy);
1199 $pdf->SetTextColor(0, 0, 60);
1200 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"QtyToProduce").
": " .$object->qty,
'',
'R');
1203 $pdf->SetTextColor(0, 0, 60);
1204 $usehourmin =
'day';
1205 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1206 $usehourmin =
'dayhour';
1208 if (!empty($object->delivery_date)) {
1210 $pdf->SetXY($posx - 90, $posy);
1211 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1214 if ($object->thirdparty->code_fournisseur) {
1216 $pdf->SetXY($posx, $posy);
1217 $pdf->SetTextColor(0, 0, 60);
1218 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1222 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1223 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1224 if (count($arrayidcontact) > 0) {
1225 $usertmp =
new User($this->db);
1226 $usertmp->fetch($arrayidcontact[0]);
1228 $pdf->SetXY($posx, $posy);
1229 $pdf->SetTextColor(0, 0, 60);
1230 $pdf->MultiCell(100, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1235 $pdf->SetTextColor(0, 0, 60);
1239 $current_y = $pdf->getY();
1240 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1241 if ($current_y < $pdf->getY()) {
1242 $top_shift = $pdf->getY() - $current_y;
1247 $carac_emetteur =
'';
1249 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1250 if (count($arrayidcontact) > 0) {
1251 $object->fetch_user($arrayidcontact[0]);
1252 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1253 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1255 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1257 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1259 $carac_emetteur .=
"\n";
1262 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1265 $posy = 42 + $top_shift;
1266 $posx = $this->marge_gauche;
1267 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1268 $posx = $this->page_largeur - $this->marge_droite - 80;
1273 $pdf->SetTextColor(0, 0, 0);
1274 $pdf->SetFont(
'',
'', $default_font_size - 2);
1275 $pdf->SetXY($posx, $posy - 5);
1276 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1277 $pdf->SetXY($posx, $posy);
1278 $pdf->SetFillColor(230, 230, 230);
1279 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1280 $pdf->SetTextColor(0, 0, 60);
1283 $pdf->SetXY($posx + 2, $posy + 3);
1284 $pdf->SetFont(
'',
'B', $default_font_size);
1285 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1286 $posy = $pdf->getY();
1289 $pdf->SetXY($posx + 2, $posy);
1290 $pdf->SetFont(
'',
'', $default_font_size - 1);
1291 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1296 $usecontact =
false;
1297 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1298 if (count($arrayidcontact) > 0) {
1300 $result = $object->fetch_contact($arrayidcontact[0]);
1304 if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1305 $thirdparty = $object->contact;
1307 $thirdparty = $object->thirdparty;