31 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mrp/modules_mo.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.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/files.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
63 public $update_main_doc_field;
74 public $phpmin = array(7, 0);
80 public $version =
'dolibarr';
100 public $marge_gauche;
105 public $marge_droite;
131 global $conf, $langs, $mysoc;
134 $langs->loadLangs(array(
"main",
"bills"));
137 $this->
name =
"vinci";
138 $this->
description = $langs->trans(
'DocumentModelStandardPDF');
139 $this->update_main_doc_field = 1;
144 $this->page_largeur = $formatarray[
'width'];
145 $this->page_hauteur = $formatarray[
'height'];
146 $this->format = array($this->page_largeur, $this->page_hauteur);
152 $this->option_logo = 1;
153 $this->option_multilang = 1;
154 $this->option_escompte = 0;
155 $this->option_credit_note = 0;
156 $this->option_freetext = 1;
157 $this->option_draft_watermark = 1;
160 $this->emetteur = $mysoc;
161 if (empty($this->emetteur->country_code)) {
162 $this->emetteur->country_code = substr($langs->defaultlang, -2);
166 $this->posxdesc = $this->marge_gauche + 1;
182 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
185 global $user, $langs, $conf, $hookmanager, $mysoc;
187 if (!is_object($outputlangs)) {
188 $outputlangs = $langs;
191 if (!empty($conf->global->MAIN_USE_FPDF)) {
192 $outputlangs->charset_output =
'ISO-8859-1';
196 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
198 global $outputlangsbis;
199 $outputlangsbis =
null;
200 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
201 $outputlangsbis =
new Translate(
'', $conf);
202 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
203 $outputlangsbis->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
206 if (!isset($object->lines) || !is_array($object->lines)) {
207 $object->lines = array();
210 $nblines = count($object->lines);
213 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
214 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
218 $realpatharray = array();
220 if ($conf->mrp->dir_output) {
221 $object->fetch_thirdparty();
224 $amount_credit_notes_included = 0;
225 $amount_deposits_included = 0;
230 if ($object->specimen) {
231 $dir = $conf->mrp->dir_output;
232 $file = $dir.
"/SPECIMEN.pdf";
235 $dir = $conf->mrp->dir_output.
'/'.$objectref;
236 $file = $dir.
"/".$objectref.
".pdf";
239 if (!file_exists($dir)) {
241 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
246 if (file_exists($dir)) {
248 if (!is_object($hookmanager)) {
249 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
252 $hookmanager->initHooks(array(
'pdfgeneration'));
253 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
255 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
257 $nblines = count($object->lines);
261 $heightforinfotot = 50;
262 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
263 $heightforfooter = $this->marge_basse + 8;
264 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
265 $heightforfooter += 6;
267 $pdf->SetAutoPageBreak(1, 0);
269 if (class_exists(
'TCPDF')) {
270 $pdf->setPrintHeader(
false);
271 $pdf->setPrintFooter(
false);
275 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
276 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
277 $tplidx = $pdf->importPage(1);
282 $pdf->SetDrawColor(128, 128, 128);
284 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
285 $pdf->SetSubject($outputlangs->transnoentities(
"Mo"));
286 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
287 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
288 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Mo").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
290 $pdf->SetCompression(
false);
293 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
299 if (!empty($tplidx)) {
300 $pdf->useTemplate($tplidx);
303 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
304 $pdf->SetFont(
'',
'', $default_font_size - 1);
305 $pdf->MultiCell(0, 3,
'');
306 $pdf->SetTextColor(0, 0, 0);
308 $tab_top = 90 + $top_shift;
309 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
311 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
315 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
318 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
319 if (!empty($extranote)) {
323 $pagenb = $pdf->getPage();
325 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
326 $pageposbeforenote = $pagenb;
335 $pdf->startTransaction();
337 $pdf->SetFont(
'',
'', $default_font_size - 1);
338 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
340 $pageposafternote = $pdf->getPage();
341 $posyafter = $pdf->GetY();
343 if ($pageposafternote > $pageposbeforenote) {
344 $pdf->rollbackTransaction(
true);
347 while ($pagenb < $pageposafternote) {
350 if (!empty($tplidx)) {
351 $pdf->useTemplate($tplidx);
354 $this->
_pagehead($pdf, $object, 0, $outputlangs);
357 $pdf->setTopMargin($tab_top_newpage);
359 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
363 $pdf->setPage($pageposbeforenote);
364 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
365 $pdf->SetFont(
'',
'', $default_font_size - 1);
366 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
367 $pageposafternote = $pdf->getPage();
369 $posyafter = $pdf->GetY();
371 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
372 $pdf->AddPage(
'',
'',
true);
375 $pdf->setPage($pageposafternote);
376 $pdf->setTopMargin($tab_top_newpage);
378 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
384 $i = $pageposbeforenote;
385 while ($i < $pageposafternote) {
389 $pdf->SetDrawColor(128, 128, 128);
391 if ($i > $pageposbeforenote) {
392 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
393 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
395 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
396 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
400 $pdf->setPageOrientation(
'', 1, 0);
401 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
407 $pdf->setPage($pageposafternote);
408 if (!empty($tplidx)) {
409 $pdf->useTemplate($tplidx);
412 $this->
_pagehead($pdf, $object, 0, $outputlangs);
414 $height_note = $posyafter - $tab_top_newpage;
415 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
418 $pdf->commitTransaction();
419 $posyafter = $pdf->GetY();
420 $height_note = $posyafter - $tab_top;
421 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
424 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
426 $pdf->AddPage(
'',
'',
true);
429 $pdf->setPage($pageposafternote);
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
434 $this->
_pagehead($pdf, $object, 0, $outputlangs);
437 $posyafter = $tab_top_newpage;
441 $tab_height = $tab_height - $height_note;
442 $tab_top = $posyafter + 6;
447 $nexY = $tab_top + 5;
453 $pageposbeforeprintlines = $pdf->getPage();
454 $pagenb = $pageposbeforeprintlines;
456 $bom =
new BOM($this->
db);
457 $bom -> fetch($object->fk_bom);
459 $nblines = count($bom->lines);
461 for ($i = 0; $i < $nblines; $i++) {
463 $pdf->SetFont(
'',
'', $default_font_size - 1);
464 $pdf->SetTextColor(0, 0, 0);
467 $prod->fetch($bom->lines[$i]->fk_product);
470 $imglinesize = array();
471 if (!empty($realpatharray[$i])) {
475 $pdf->setTopMargin($tab_top_newpage);
476 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
477 $pageposbefore = $pdf->getPage();
479 $showpricebeforepagebreak = 1;
481 $posYAfterDescription = 0;
484 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
485 $pdf->AddPage(
'',
'',
true);
486 if (!empty($tplidx)) {
487 $pdf->useTemplate($tplidx);
490 $this->
_pagehead($pdf, $object, 0, $outputlangs);
492 $pdf->setPage($pageposbefore + 1);
494 $curY = $tab_top_newpage;
497 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
498 $showpricebeforepagebreak = 1;
500 $showpricebeforepagebreak = 0;
504 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
505 $curX = $this->posxpicture - 1;
506 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
508 $posYAfterImage = $curY + $imglinesize[
'height'];
511 $curX = $this->posxdesc - 1;
512 $showpricebeforepagebreak = 1;
515 $pdf->startTransaction();
519 $pageposafter = $pdf->getPage();
520 $posyafter = $pdf->GetY();
521 if ($pageposafter > $pageposbefore) {
522 $pdf->rollbackTransaction(
true);
527 $pageposafter = $pdf->getPage();
528 $posyafter = $pdf->GetY();
529 } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
530 if ($i == ($nblines - 1)) {
531 $pdf->AddPage(
'',
'',
true);
532 if (!empty($tplidx)) {
533 $pdf->useTemplate($tplidx);
536 $pdf->setPage($pageposafter + 1);
540 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
541 $showpricebeforepagebreak = 1;
543 $showpricebeforepagebreak = 0;
548 $pdf->commitTransaction();
550 $posYAfterDescription = $pdf->GetY();
553 $nexY = $pdf->GetY();
554 $pageposafter = $pdf->getPage();
555 $pdf->setPage($pageposbefore);
556 $pdf->setTopMargin($this->marge_haute);
557 $pdf->setPageOrientation(
'', 1, 0);
560 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
561 $pdf->setPage($pageposafter);
562 $curY = $tab_top_newpage;
566 $pdf->startTransaction();
572 $pageposafter = $pdf->getPage();
573 $posyafter = $pdf->GetY();
574 if ($pageposafter > $pageposbefore) {
575 $pdf->rollbackTransaction(
true);
579 $pageposafter = $pdf->getPage();
580 $posyafter = $pdf->GetY();
581 } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
582 if ($i == ($nblines - 1)) {
583 $pdf->AddPage(
'',
'',
true);
584 if (!empty($tplidx)) {
585 $pdf->useTemplate($tplidx);
588 $pdf->setPage($pageposafter + 1);
592 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
593 $showpricebeforepagebreak = 1;
595 $showpricebeforepagebreak = 0;
600 $pdf->commitTransaction();
602 $posYAfterDescription = max($posYAfterDescription, $pdf->GetY());
605 $nexY = max($nexY, $pdf->GetY());
606 $pageposafter = $pdf->getPage();
607 $pdf->setPage($pageposbefore);
608 $pdf->setTopMargin($this->marge_haute);
609 $pdf->setPageOrientation(
'', 1, 0);
612 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
613 $pdf->setPage($pageposafter);
614 $curY = $tab_top_newpage;
617 $pdf->SetFont(
'',
'', $default_font_size - 1);
622 $qty = $bom->lines[$i]->qty;
624 $nexY = max($pdf->GetY(), $nexY);
630 $qtytot = $object->qty * $bom->lines[$i]->qty;
632 $nexY = max($pdf->GetY(), $nexY);
637 $array = array_filter(array($prod->length, $prod->width, $prod->height));
638 $dim = implode(
"x", $array);
640 $nexY = max($pdf->GetY(), $nexY);
648 if ($pagenb == $pageposbeforeprintlines) {
649 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
650 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
652 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
653 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
657 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
663 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
668 $this->
_pagefoot($pdf, $object, $outputlangs);
669 if (method_exists($pdf,
'AliasNbPages')) {
670 $pdf->AliasNbPages();
675 $pdf->Output($file,
'F');
678 $hookmanager->initHooks(array(
'pdfgeneration'));
679 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
681 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
683 $this->error = $hookmanager->error;
684 $this->errors = $hookmanager->errors;
687 if (!empty($conf->global->MAIN_UMASK)) {
688 @chmod($file, octdec($conf->global->MAIN_UMASK));
691 $this->result = array(
'fullpath'=>$file);
695 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
699 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
734 global $conf, $mysoc;
738 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
739 $pdf->SetFont(
'',
'B', $default_font_size - 2);
740 $pdf->SetXY($this->marge_gauche, $posy);
741 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
743 $posy = $pdf->GetY() + 4;
749 if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
750 $pdf->SetFont(
'',
'B', $default_font_size - 2);
751 $pdf->SetXY($this->marge_gauche, $posy);
752 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
753 $pdf->MultiCell(80, 4, $titre, 0,
'L');
755 $pdf->SetFont(
'',
'', $default_font_size - 2);
756 $pdf->SetXY($posxval, $posy);
757 $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);
758 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
759 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0,
'L');
761 $posy = $pdf->GetY() + 3;
765 if (!empty($object->mode_reglement_code)) {
766 $pdf->SetFont(
'',
'B', $default_font_size - 2);
767 $pdf->SetXY($this->marge_gauche, $posy);
768 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
769 $pdf->MultiCell(80, 5, $titre, 0,
'L');
771 $pdf->SetFont(
'',
'', $default_font_size - 2);
772 $pdf->SetXY($posxval, $posy);
773 $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);
774 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
776 $posy = $pdf->GetY() + 2;
795 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
798 global $conf, $mysoc;
804 $pdf->SetFont(
'',
'', $default_font_size - 1);
809 if ($this->page_largeur < 210) {
812 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
818 $pdf->SetFillColor(255, 255, 255);
819 $pdf->SetXY($col1x, $tab2_top);
820 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
822 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
823 $pdf->SetXY($col2x, $tab2_top);
824 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
827 $pdf->SetFillColor(248, 248, 248);
829 $this->atleastoneratenotnull = 0;
830 foreach ($this->tva as $tvakey => $tvaval) {
832 $this->atleastoneratenotnull++;
835 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
839 if (preg_match(
'/\*/', $tvakey)) {
840 $tvakey = str_replace(
'*',
'', $tvakey);
841 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
844 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
845 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
846 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
848 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
849 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
852 if (!$this->atleastoneratenotnull) {
854 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
855 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
857 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
858 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
861 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
863 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
864 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
865 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
866 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
870 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
872 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
873 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
874 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
875 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
881 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
882 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
886 foreach ($localtax_rate as $tvakey => $tvaval) {
891 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
894 if (preg_match(
'/\*/', $tvakey)) {
895 $tvakey = str_replace(
'*',
'', $tvakey);
896 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
898 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
899 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
900 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
902 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
903 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
911 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
912 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
916 foreach ($localtax_rate as $tvakey => $tvaval) {
921 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
924 if (preg_match(
'/\*/', $tvakey)) {
925 $tvakey = str_replace(
'*',
'', $tvakey);
926 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
928 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
929 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
930 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
932 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
933 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
941 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
942 $pdf->SetTextColor(0, 0, 60);
943 $pdf->SetFillColor(224, 224, 224);
944 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
946 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
947 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
948 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
949 $pdf->SetFont(
'',
'', $default_font_size - 1);
950 $pdf->SetTextColor(0, 0, 0);
952 $creditnoteamount = 0;
957 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
958 if (!empty($object->paye)) {
962 if ($deja_regle > 0) {
966 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
967 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
968 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
969 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
972 $pdf->SetTextColor(0, 0, 60);
973 $pdf->SetFillColor(224, 224, 224);
974 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
975 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
977 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
978 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
980 $pdf->SetFont(
'',
'', $default_font_size - 1);
981 $pdf->SetTextColor(0, 0, 0);
985 return ($tab2_top + ($tab2_hl * $index));
1002 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1012 $currency = !empty($currency) ? $currency : $conf->currency;
1016 $pdf->SetTextColor(0, 0, 0);
1017 $pdf->SetFont(
'',
'', $default_font_size - 2);
1019 if (empty($hidetop)) {
1021 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1022 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1025 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1026 $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));
1030 $pdf->SetDrawColor(128, 128, 128);
1031 $pdf->SetFont(
'',
'', $default_font_size - 1);
1034 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1036 foreach ($this->cols as $colKey => $colDef) {
1042 $colDef[
'title'][
'label'] = !empty($colDef[
'title'][
'label']) ? $colDef[
'title'][
'label'] : $outputlangs->transnoentities($colDef[
'title'][
'textkey']);
1045 if (!empty($colDef[
'border-left'])) {
1046 $pdf->line($colDef[
'xStartPos'], $tab_top, $colDef[
'xStartPos'], $tab_top + $tab_height);
1049 if (empty($hidetop)) {
1050 $pdf->SetXY($colDef[
'xStartPos'] + $colDef[
'title'][
'padding'][3], $tab_top + $colDef[
'title'][
'padding'][0]);
1052 $textWidth = $colDef[
'width'] - $colDef[
'title'][
'padding'][3] - $colDef[
'title'][
'padding'][1];
1053 $pdf->MultiCell($textWidth, 2, $colDef[
'title'][
'label'],
'', $colDef[
'title'][
'align']);
1057 if (empty($hidetop)) {
1058 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1072 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1074 global $langs, $conf, $mysoc;
1076 $ltrdirection =
'L';
1077 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1080 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1094 $pdf->SetTextColor(0, 0, 60);
1095 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1097 $posx = $this->page_largeur - $this->marge_droite - 100;
1098 $posy = $this->marge_haute;
1100 $pdf->SetXY($this->marge_gauche, $posy);
1103 $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
1104 if ($this->emetteur->logo) {
1105 if (is_readable($logo)) {
1107 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1109 $pdf->SetTextColor(200, 0, 0);
1110 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1111 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1112 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
1115 $text = $this->emetteur->name;
1116 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1119 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1120 $pdf->SetXY($posx, $posy);
1121 $pdf->SetTextColor(0, 0, 60);
1122 $title = $outputlangs->transnoentities(
"Mo").
" ".$outputlangs->convToOutputCharset($object->ref);
1123 $pdf->MultiCell(100, 3, $title,
'',
'R');
1126 if ($object->ref_supplier) {
1128 $pdf->SetFont(
'',
'B', $default_font_size);
1129 $pdf->SetXY($posx, $posy);
1130 $pdf->SetTextColor(0, 0, 60);
1131 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1135 $pdf->SetFont(
'',
'', $default_font_size - 1);
1136 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1137 $object->fetch_projet();
1138 if (!empty($object->project->ref)) {
1140 $pdf->SetXY($posx, $posy);
1141 $pdf->SetTextColor(0, 0, 60);
1142 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1146 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1147 $object->fetch_projet();
1148 if (!empty($object->project->ref)) {
1149 $outputlangs->load(
"projects");
1151 $pdf->SetXY($posx, $posy);
1152 $langs->load(
"projects");
1153 $pdf->SetTextColor(0, 0, 60);
1154 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1158 if (!empty($object->date_approve)) {
1160 $pdf->SetXY($posx, $posy);
1161 $pdf->SetTextColor(0, 0, 60);
1162 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"MoDate").
" : ".
dol_print_date($object->date_approve,
"day",
false, $outputlangs,
true),
'',
'R');
1165 $pdf->SetXY($posx, $posy);
1166 $pdf->SetTextColor(255, 0, 0);
1167 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ToApprove"),
'',
'R');
1173 $prodToMake->fetch($object->fk_product);
1174 $pdf->SetFont(
'',
'B', $default_font_size + 1);
1175 $pdf->SetXY($posx, $posy);
1176 $pdf->SetTextColor(0, 0, 60);
1177 $pdf->MultiCell($w, 3, $prodToMake->ref,
'',
'R');
1181 $prodToMake->fetch($object->fk_product);
1182 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1183 $pdf->SetXY($posx, $posy);
1184 $pdf->SetTextColor(0, 0, 60);
1185 $pdf->MultiCell($w, 3, $prodToMake->description,
'',
'R');
1187 $array = array_filter(array($prodToMake->length, $prodToMake->width, $prodToMake->height));
1188 $dim = implode(
"x", $array);
1191 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1192 $pdf->SetXY($posx, $posy);
1193 $pdf->SetTextColor(0, 0, 60);
1194 $pdf->MultiCell($w, 3, $dim,
'',
'R');
1199 $prodToMake->fetch($object->fk_product);
1200 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1201 $pdf->SetXY($posx, $posy);
1202 $pdf->SetTextColor(0, 0, 60);
1203 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"QtyToProduce").
": " .$object->qty,
'',
'R');
1206 $pdf->SetTextColor(0, 0, 60);
1207 $usehourmin =
'day';
1208 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1209 $usehourmin =
'dayhour';
1211 if (!empty($object->delivery_date)) {
1213 $pdf->SetXY($posx - 90, $posy);
1214 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1217 if ($object->thirdparty->code_fournisseur) {
1219 $pdf->SetXY($posx, $posy);
1220 $pdf->SetTextColor(0, 0, 60);
1221 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1225 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1226 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1227 if (count($arrayidcontact) > 0) {
1228 $usertmp =
new User($this->
db);
1229 $usertmp->fetch($arrayidcontact[0]);
1231 $pdf->SetXY($posx, $posy);
1232 $pdf->SetTextColor(0, 0, 60);
1233 $pdf->MultiCell(100, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1238 $pdf->SetTextColor(0, 0, 60);
1242 $current_y = $pdf->getY();
1243 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1244 if ($current_y < $pdf->getY()) {
1245 $top_shift = $pdf->getY() - $current_y;
1250 $carac_emetteur =
'';
1252 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1253 if (count($arrayidcontact) > 0) {
1254 $object->fetch_user($arrayidcontact[0]);
1255 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1258 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1261 $posy = 42 + $top_shift;
1262 $posx = $this->marge_gauche;
1263 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1264 $posx = $this->page_largeur - $this->marge_droite - 80;
1269 $pdf->SetTextColor(0, 0, 0);
1270 $pdf->SetFont(
'',
'', $default_font_size - 2);
1271 $pdf->SetXY($posx, $posy - 5);
1272 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1273 $pdf->SetXY($posx, $posy);
1274 $pdf->SetFillColor(230, 230, 230);
1275 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1276 $pdf->SetTextColor(0, 0, 60);
1279 $pdf->SetXY($posx + 2, $posy + 3);
1280 $pdf->SetFont(
'',
'B', $default_font_size);
1281 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1282 $posy = $pdf->getY();
1285 $pdf->SetXY($posx + 2, $posy);
1286 $pdf->SetFont(
'',
'', $default_font_size - 1);
1287 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1292 $usecontact =
false;
1293 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1294 if (count($arrayidcontact) > 0) {
1296 $result = $object->fetch_contact($arrayidcontact[0]);
1300 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)))) {
1301 $thirdparty = $object->contact;
1303 $thirdparty = $object->thirdparty;
1354 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1356 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1357 return pdf_pagefoot($pdf, $outputlangs,
'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1372 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1374 global $conf, $hookmanager;
1377 $this->defaultContentsFieldsStyle = array(
1379 'padding' => array(1, 0.5, 1, 0.5),
1383 $this->defaultTitlesFieldsStyle = array(
1385 'padding' => array(0.5, 0, 0.5, 0),
1406 $this->cols[
'code'] = array(
1413 'border-left' =>
true,
1417 $this->cols[
'desc'] = array(
1422 'textkey' =>
'Designation',
1426 'padding' => array(0.5, 1, 0.5, 1.5),
1428 'border-left' =>
true,
1431 'padding' => array(1, 0.5, 1, 1.5),
1436 $this->cols[
'photo'] = array(
1438 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1441 'textkey' =>
'Photo',
1445 'padding' => array(0, 0, 0, 0),
1447 'border-left' =>
false,
1450 if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) {
1451 $this->cols[
'photo'][
'status'] =
true;
1455 $this->cols[
'dim'] = array(
1462 'border-left' =>
true,
1466 $this->cols[
'qty'] = array(
1473 'border-left' =>
true,
1477 $this->cols[
'qtytot'] = array(
1482 'textkey' =>
'QtyTot'
1484 'border-left' =>
true,
1488 if (!empty($object->lines)) {
1489 $line = reset($object->lines);
1493 $parameters = array(
1494 'object' => $object,
1495 'outputlangs' => $outputlangs,
1496 'hidedetails' => $hidedetails,
1497 'hidedesc' => $hidedesc,
1498 'hideref' => $hideref
1501 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1504 } elseif (empty($reshook)) {
1505 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1507 $this->cols = $hookmanager->resArray;
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Parent class for mos models.
Class to manage products or services.
Class to manage translations.
Class to manage Dolibarr users.
Class to generate the manufacturing orders with the vinci model.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.