186 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
189 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
191 if (!is_object($outputlangs)) {
192 $outputlangs = $langs;
195 if (!empty($conf->global->MAIN_USE_FPDF)) {
196 $outputlangs->charset_output =
'ISO-8859-1';
200 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
202 global $outputlangsbis;
203 $outputlangsbis =
null;
204 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
205 $outputlangsbis =
new Translate(
'', $conf);
206 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
207 $outputlangsbis->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
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();
219 if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
220 for ($i = 0; $i < $nblines; $i++) {
221 if (empty($object->lines[$i]->fk_product)) {
225 $objphoto =
new Product($this->db);
226 $objphoto->fetch($object->lines[$i]->fk_product);
229 $pdir =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
230 $dir = $conf->product->dir_output.
'/'.$pdir;
232 $pdir =
get_exdir($objphoto->id, 0, 0, 0, $objphoto,
'product');
233 $dir = $conf->product->dir_output.
'/'.$pdir;
237 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
239 if ($obj[
'photo_vignette']) {
240 $filename = $obj[
'photo_vignette'];
242 $filename = $obj[
'photo'];
245 $filename = $obj[
'photo'];
247 $realpath = $dir.$filename;
252 $realpatharray[$i] = $realpath;
256 if (count($realpatharray) == 0) {
257 $this->posxpicture = $this->posxtva;
260 if ($conf->fournisseur->commande->dir_output) {
261 $object->fetch_thirdparty();
264 $amount_credit_notes_included = 0;
265 $amount_deposits_included = 0;
270 if ($object->specimen) {
271 $dir = $conf->fournisseur->commande->dir_output;
272 $file = $dir.
"/SPECIMEN.pdf";
276 $dir = $conf->fournisseur->commande->dir_output.
'/'.$objectref;
277 $file = $dir.
"/".$objectref.
".pdf";
278 if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
279 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
283 if (!file_exists($dir)) {
285 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
290 if (file_exists($dir)) {
292 if (!is_object($hookmanager)) {
293 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
296 $hookmanager->initHooks(array(
'pdfgeneration'));
297 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
299 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
301 $nblines = count($object->lines);
305 $heightforinfotot = 50;
306 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
307 $heightforfooter = $this->marge_basse + 8;
308 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
309 $heightforfooter += 6;
311 $pdf->SetAutoPageBreak(1, 0);
313 if (class_exists(
'TCPDF')) {
314 $pdf->setPrintHeader(
false);
315 $pdf->setPrintFooter(
false);
319 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
320 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
321 $tplidx = $pdf->importPage(1);
326 $pdf->SetDrawColor(128, 128, 128);
328 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
329 $pdf->SetSubject($outputlangs->transnoentities(
"Order"));
330 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
331 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
332 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
334 $pdf->SetCompression(
false);
337 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
340 foreach ($object->lines as $line) {
341 if ($line->remise_percent) {
342 $this->atleastonediscount =
true;
349 if (!empty($tplidx)) {
350 $pdf->useTemplate($tplidx);
353 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
354 $pdf->SetFont(
'',
'', $default_font_size - 1);
355 $pdf->MultiCell(0, 3,
'');
356 $pdf->SetTextColor(0, 0, 0);
358 $tab_top = 90 + $top_shift;
359 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
361 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
364 if (isModEnabled(
'incoterm')) {
365 $desc_incoterms = $object->getIncotermsForPDF();
366 if ($desc_incoterms) {
369 $pdf->SetFont(
'',
'', $default_font_size - 1);
370 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
371 $nexY = $pdf->GetY();
372 $height_incoterms = $nexY - $tab_top;
375 $pdf->SetDrawColor(192, 192, 192);
376 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
378 $tab_top = $nexY + 6;
383 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
386 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
387 if (!empty($extranote)) {
391 $pagenb = $pdf->getPage();
393 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
394 $pageposbeforenote = $pagenb;
403 $pdf->startTransaction();
405 $pdf->SetFont(
'',
'', $default_font_size - 1);
406 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
408 $pageposafternote = $pdf->getPage();
409 $posyafter = $pdf->GetY();
411 if ($pageposafternote > $pageposbeforenote) {
412 $pdf->rollbackTransaction(
true);
415 while ($pagenb < $pageposafternote) {
418 if (!empty($tplidx)) {
419 $pdf->useTemplate($tplidx);
422 $this->
_pagehead($pdf, $object, 0, $outputlangs);
425 $pdf->setTopMargin($tab_top_newpage);
427 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
431 $pdf->setPage($pageposbeforenote);
432 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
433 $pdf->SetFont(
'',
'', $default_font_size - 1);
434 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
435 $pageposafternote = $pdf->getPage();
437 $posyafter = $pdf->GetY();
439 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
440 $pdf->AddPage(
'',
'',
true);
443 $pdf->setPage($pageposafternote);
444 $pdf->setTopMargin($tab_top_newpage);
446 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
452 $i = $pageposbeforenote;
453 while ($i < $pageposafternote) {
457 $pdf->SetDrawColor(128, 128, 128);
459 if ($i > $pageposbeforenote) {
460 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
461 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
463 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
464 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
468 $pdf->setPageOrientation(
'', 1, 0);
469 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
475 $pdf->setPage($pageposafternote);
476 if (!empty($tplidx)) {
477 $pdf->useTemplate($tplidx);
480 $this->
_pagehead($pdf, $object, 0, $outputlangs);
482 $height_note = $posyafter - $tab_top_newpage;
483 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
486 $pdf->commitTransaction();
487 $posyafter = $pdf->GetY();
488 $height_note = $posyafter - $tab_top;
489 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
492 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
494 $pdf->AddPage(
'',
'',
true);
497 $pdf->setPage($pageposafternote);
498 if (!empty($tplidx)) {
499 $pdf->useTemplate($tplidx);
502 $this->
_pagehead($pdf, $object, 0, $outputlangs);
505 $posyafter = $tab_top_newpage;
509 $tab_height = $tab_height - $height_note;
510 $tab_top = $posyafter + 6;
515 $nexY = $tab_top + 5;
521 $pageposbeforeprintlines = $pdf->getPage();
522 $pagenb = $pageposbeforeprintlines;
523 for ($i = 0; $i < $nblines; $i++) {
525 $pdf->SetFont(
'',
'', $default_font_size - 1);
526 $pdf->SetTextColor(0, 0, 0);
529 $imglinesize = array();
530 if (!empty($realpatharray[$i])) {
534 $pdf->setTopMargin($tab_top_newpage);
535 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
536 $pageposbefore = $pdf->getPage();
538 $showpricebeforepagebreak = 1;
540 $posYAfterDescription = 0;
545 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
546 $pdf->AddPage(
'',
'',
true);
547 if (!empty($tplidx)) {
548 $pdf->useTemplate($tplidx);
550 $pdf->setPage($pageposbefore + 1);
552 $curY = $tab_top_newpage;
555 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
556 $showpricebeforepagebreak = 1;
558 $showpricebeforepagebreak = 0;
562 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
563 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
565 $posYAfterImage = $curY + $imglinesize[
'height'];
569 $curX = $this->posxdesc - 1;
570 $showpricebeforepagebreak = 1;
573 $pdf->startTransaction();
574 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
576 $pageposafter = $pdf->getPage();
577 if ($pageposafter > $pageposbefore) {
578 $pdf->rollbackTransaction(
true);
580 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
582 $pageposafter = $pdf->getPage();
583 $posyafter = $pdf->GetY();
584 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
585 if ($i == ($nblines - 1)) {
586 $pdf->AddPage(
'',
'',
true);
587 if (!empty($tplidx)) {
588 $pdf->useTemplate($tplidx);
591 $pdf->setPage($pageposafter + 1);
596 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
597 $showpricebeforepagebreak = 1;
599 $showpricebeforepagebreak = 0;
604 $pdf->commitTransaction();
606 $posYAfterDescription = $pdf->GetY();
609 $nexY = $pdf->GetY();
610 $pageposafter = $pdf->getPage();
611 $pdf->setPage($pageposbefore);
612 $pdf->setTopMargin($this->marge_haute);
613 $pdf->setPageOrientation(
'', 1, 0);
616 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
617 $pdf->setPage($pageposafter);
618 $curY = $tab_top_newpage;
621 $pdf->SetFont(
'',
'', $default_font_size - 1);
627 $nexY = max($pdf->GetY(), $nexY);
634 $nexY = max($pdf->GetY(), $nexY);
642 $nexY = max($pdf->GetY(), $nexY);
648 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
650 $nexY = max($pdf->GetY(), $nexY);
654 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
657 $nexY = max($pdf->GetY(), $nexY);
664 $nexY = max($pdf->GetY(), $nexY);
668 if (!empty($object->lines[$i]->array_options)) {
669 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
671 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
673 $nexY = max($pdf->GetY(), $nexY);
684 'outputlangs' => $outputlangs,
685 'hidedetails' => $hidedetails
687 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
691 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
692 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
694 $tvaligne = $object->lines[$i]->total_tva;
697 $localtax1ligne = $object->lines[$i]->total_localtax1;
698 $localtax2ligne = $object->lines[$i]->total_localtax2;
699 $localtax1_rate = $object->lines[$i]->localtax1_tx;
700 $localtax2_rate = $object->lines[$i]->localtax2_tx;
701 $localtax1_type = $object->lines[$i]->localtax1_type;
702 $localtax2_type = $object->lines[$i]->localtax2_type;
715 $vatrate = (string) $object->lines[$i]->tva_tx;
718 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
719 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
721 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
722 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
726 if ($localtax1_type && $localtax1ligne != 0) {
727 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
728 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
730 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
733 if ($localtax2_type && $localtax2ligne != 0) {
734 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
735 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
737 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
741 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
746 if (!isset($this->tva[$vatrate])) {
747 $this->tva[$vatrate] = 0;
749 $this->tva[$vatrate] += $tvaligne;
750 $vatcode = $object->lines[$i]->vat_src_code;
751 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
752 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
754 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
756 if ($posYAfterImage > $posYAfterDescription) {
757 $nexY = $posYAfterImage;
761 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
762 $pdf->setPage($pageposafter);
763 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
765 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
766 $pdf->SetLineStyle(array(
'dash'=>0));
770 while ($pagenb < $pageposafter) {
771 $pdf->setPage($pagenb);
772 if ($pagenb == $pageposbeforeprintlines) {
773 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
775 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
777 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
779 $pdf->setPage($pagenb);
780 $pdf->setPageOrientation(
'', 1, 0);
782 $this->
_pagehead($pdf, $object, 0, $outputlangs);
784 if (!empty($tplidx)) {
785 $pdf->useTemplate($tplidx);
788 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
789 if ($pagenb == $pageposafter) {
790 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
792 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
794 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
797 if (!empty($tplidx)) {
798 $pdf->useTemplate($tplidx);
802 $this->
_pagehead($pdf, $object, 0, $outputlangs);
808 if ($pagenb == $pageposbeforeprintlines) {
809 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
810 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
812 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
813 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
817 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
820 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
823 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
828 $this->
_pagefoot($pdf, $object, $outputlangs);
829 if (method_exists($pdf,
'AliasNbPages')) {
830 $pdf->AliasNbPages();
835 $pdf->Output($file,
'F');
838 $hookmanager->initHooks(array(
'pdfgeneration'));
839 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
841 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
843 $this->error = $hookmanager->error;
844 $this->errors = $hookmanager->errors;
849 $this->result = array(
'fullpath'=>$file);
853 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
857 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
956 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
959 global $conf, $mysoc;
965 $pdf->SetFont(
'',
'', $default_font_size - 1);
970 if ($this->page_largeur < 210) {
973 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
979 $pdf->SetFillColor(255, 255, 255);
980 $pdf->SetXY($col1x, $tab2_top);
981 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
983 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
984 $pdf->SetXY($col2x, $tab2_top);
985 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
988 $pdf->SetFillColor(248, 248, 248);
990 $this->atleastoneratenotnull = 0;
991 foreach ($this->tva as $tvakey => $tvaval) {
993 $this->atleastoneratenotnull++;
996 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1000 if (preg_match(
'/\*/', $tvakey)) {
1001 $tvakey = str_replace(
'*',
'', $tvakey);
1002 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1005 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
1006 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
1007 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1009 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1010 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
1013 if (!$this->atleastoneratenotnull) {
1015 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1016 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
1018 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1019 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
1022 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
1024 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1025 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
1026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1027 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
1031 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
1033 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1034 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
1035 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1036 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
1042 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1043 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1047 foreach ($localtax_rate as $tvakey => $tvaval) {
1052 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1055 if (preg_match(
'/\*/', $tvakey)) {
1056 $tvakey = str_replace(
'*',
'', $tvakey);
1057 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1059 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1060 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1061 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1063 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1064 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1072 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1073 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1077 foreach ($localtax_rate as $tvakey => $tvaval) {
1082 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1085 if (preg_match(
'/\*/', $tvakey)) {
1086 $tvakey = str_replace(
'*',
'', $tvakey);
1087 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1089 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1090 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1091 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1093 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1094 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
1102 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103 $pdf->SetTextColor(0, 0, 60);
1104 $pdf->SetFillColor(224, 224, 224);
1105 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1107 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1108 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1109 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
1110 $pdf->SetFont(
'',
'', $default_font_size - 1);
1111 $pdf->SetTextColor(0, 0, 0);
1113 $creditnoteamount = 0;
1114 $depositsamount = 0;
1118 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1119 if (!empty($object->paye)) {
1123 if ($deja_regle > 0) {
1127 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1128 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
1129 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1130 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
1133 $pdf->SetTextColor(0, 0, 60);
1134 $pdf->SetFillColor(224, 224, 224);
1135 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1136 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1138 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1139 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
1141 $pdf->SetFont(
'',
'', $default_font_size - 1);
1142 $pdf->SetTextColor(0, 0, 0);
1146 return ($tab2_top + ($tab2_hl * $index));
1233 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1235 global $langs, $conf, $mysoc;
1237 $ltrdirection =
'L';
1238 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1241 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1255 $pdf->SetTextColor(0, 0, 60);
1256 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1260 $posx = $this->page_largeur - $this->marge_droite - $w;
1261 $posy = $this->marge_haute;
1263 $pdf->SetXY($this->marge_gauche, $posy);
1267 if ($this->emetteur->logo) {
1268 $logodir = $conf->mycompany->dir_output;
1269 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1270 $logodir = $conf->mycompany->multidir_output[$object->entity];
1273 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1275 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1277 if (is_readable($logo)) {
1279 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1281 $pdf->SetTextColor(200, 0, 0);
1282 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1283 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1284 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1287 $text = $this->emetteur->name;
1288 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1292 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1293 $pdf->SetXY($posx, $posy);
1294 $pdf->SetTextColor(0, 0, 60);
1295 $title = $outputlangs->transnoentities(
"SupplierOrder").
" ".$outputlangs->convToOutputCharset($object->ref);
1296 $pdf->MultiCell($w, 3, $title,
'',
'R');
1299 if ($object->ref_supplier) {
1301 $pdf->SetFont(
'',
'B', $default_font_size);
1302 $pdf->SetXY($posx, $posy);
1303 $pdf->SetTextColor(0, 0, 60);
1304 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1308 $pdf->SetFont(
'',
'', $default_font_size - 1);
1310 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1311 $object->fetch_projet();
1312 if (!empty($object->project->ref)) {
1314 $pdf->SetXY($posx, $posy);
1315 $pdf->SetTextColor(0, 0, 60);
1316 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1320 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1321 $object->fetch_projet();
1322 if (!empty($object->project->ref)) {
1323 $outputlangs->load(
"projects");
1325 $pdf->SetXY($posx, $posy);
1326 $langs->load(
"projects");
1327 $pdf->SetTextColor(0, 0, 60);
1328 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1332 if (!empty($object->date_commande)) {
1334 $pdf->SetXY($posx, $posy);
1335 $pdf->SetTextColor(0, 0, 60);
1336 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date($object->date_commande,
"day",
false, $outputlangs,
true),
'',
'R');
1339 $pdf->SetXY($posx, $posy);
1340 $pdf->SetTextColor(255, 0, 0);
1341 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"OrderToProcess"),
'',
'R');
1344 $pdf->SetTextColor(0, 0, 60);
1345 $usehourmin =
'day';
1346 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1347 $usehourmin =
'dayhour';
1349 if (!empty($object->delivery_date)) {
1351 $pdf->SetXY($posx - 90, $posy);
1352 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1355 if ($object->thirdparty->code_fournisseur) {
1357 $pdf->SetXY($posx, $posy);
1358 $pdf->SetTextColor(0, 0, 60);
1359 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1363 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1364 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1365 if (count($arrayidcontact) > 0) {
1366 $usertmp =
new User($this->db);
1367 $usertmp->fetch($arrayidcontact[0]);
1369 $pdf->SetXY($posx, $posy);
1370 $pdf->SetTextColor(0, 0, 60);
1371 $pdf->MultiCell($w, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1376 $pdf->SetTextColor(0, 0, 60);
1380 $current_y = $pdf->getY();
1381 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1382 if ($current_y < $pdf->getY()) {
1383 $top_shift = $pdf->getY() - $current_y;
1388 $carac_emetteur =
'';
1390 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1391 if (count($arrayidcontact) > 0) {
1392 $object->fetch_user($arrayidcontact[0]);
1393 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1394 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1396 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1398 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1400 $carac_emetteur .=
"\n";
1403 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1406 $posy = 42 + $top_shift;
1407 $posx = $this->marge_gauche;
1408 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1409 $posx = $this->page_largeur - $this->marge_droite - 80;
1414 $pdf->SetTextColor(0, 0, 0);
1415 $pdf->SetFont(
'',
'', $default_font_size - 2);
1416 $pdf->SetXY($posx, $posy - 5);
1417 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1418 $pdf->SetXY($posx, $posy);
1419 $pdf->SetFillColor(230, 230, 230);
1420 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1421 $pdf->SetTextColor(0, 0, 60);
1424 $pdf->SetXY($posx + 2, $posy + 3);
1425 $pdf->SetFont(
'',
'B', $default_font_size);
1426 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1427 $posy = $pdf->getY();
1430 $pdf->SetXY($posx + 2, $posy);
1431 $pdf->SetFont(
'',
'', $default_font_size - 1);
1432 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1437 $usecontact =
false;
1438 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1439 if (count($arrayidcontact) > 0) {
1441 $result = $object->fetch_contact($arrayidcontact[0]);
1445 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)))) {
1446 $thirdparty = $object->contact;
1448 $thirdparty = $object->thirdparty;
1453 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1457 if ($this->page_largeur < 210) {
1460 $posy = 42 + $top_shift;
1461 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1462 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1463 $posx = $this->marge_gauche;
1467 $pdf->SetTextColor(0, 0, 0);
1468 $pdf->SetFont(
'',
'', $default_font_size - 2);
1469 $pdf->SetXY($posx + 2, $posy - 5);
1470 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1471 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1474 $pdf->SetXY($posx + 2, $posy + 3);
1475 $pdf->SetFont(
'',
'B', $default_font_size);
1476 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1478 $posy = $pdf->getY();
1481 $pdf->SetFont(
'',
'', $default_font_size - 1);
1482 $pdf->SetXY($posx + 2, $posy);
1483 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);