147 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
150 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
152 if (!is_object($outputlangs)) {
153 $outputlangs = $langs;
157 $outputlangs->charset_output =
'ISO-8859-1';
161 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
163 global $outputlangsbis;
164 $outputlangsbis =
null;
165 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
166 $outputlangsbis =
new Translate(
'', $conf);
167 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
168 $outputlangsbis->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
171 $nblines = count($object->lines);
175 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
179 $realpatharray = array();
181 for ($i = 0; $i < $nblines; $i++) {
182 if (empty($object->lines[$i]->fk_product)) {
186 $objphoto =
new Product($this->db);
187 $objphoto->fetch($object->lines[$i]->fk_product);
190 $pdir =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
191 $dir = $conf->product->dir_output.
'/'.$pdir;
193 $pdir =
get_exdir($objphoto->id, 0, 0, 0, $objphoto,
'product');
194 $dir = $conf->product->dir_output.
'/'.$pdir;
198 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
200 if ($obj[
'photo_vignette']) {
201 $filename = $obj[
'photo_vignette'];
203 $filename = $obj[
'photo'];
206 $filename = $obj[
'photo'];
208 $realpath = $dir.$filename;
213 $realpatharray[$i] = $realpath;
217 if (count($realpatharray) == 0) {
218 $this->posxpicture = $this->posxtva;
221 if ($conf->fournisseur->commande->dir_output) {
222 $object->fetch_thirdparty();
225 $amount_credit_notes_included = 0;
226 $amount_deposits_included = 0;
231 if ($object->specimen) {
232 $dir = $conf->fournisseur->commande->dir_output;
233 $file = $dir.
"/SPECIMEN.pdf";
237 $dir = $conf->fournisseur->commande->dir_output.
'/'.$objectref;
238 $file = $dir.
"/".$objectref.
".pdf";
240 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
244 if (!file_exists($dir)) {
246 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
251 if (file_exists($dir)) {
253 if (!is_object($hookmanager)) {
254 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
257 $hookmanager->initHooks(array(
'pdfgeneration'));
258 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
260 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
262 $nblines = count($object->lines);
266 $heightforinfotot = 50;
267 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
268 $heightforfooter = $this->marge_basse + 8;
270 $heightforfooter += 6;
272 $pdf->SetAutoPageBreak(1, 0);
274 if (class_exists(
'TCPDF')) {
275 $pdf->setPrintHeader(
false);
276 $pdf->setPrintFooter(
false);
281 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
282 $tplidx = $pdf->importPage(1);
287 $pdf->SetDrawColor(128, 128, 128);
289 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
290 $pdf->SetSubject($outputlangs->transnoentities(
"Order"));
291 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
292 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
293 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
295 $pdf->SetCompression(
false);
298 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
301 foreach ($object->lines as $line) {
302 if ($line->remise_percent) {
303 $this->atleastonediscount =
true;
310 if (!empty($tplidx)) {
311 $pdf->useTemplate($tplidx);
314 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
315 $pdf->SetFont(
'',
'', $default_font_size - 1);
316 $pdf->MultiCell(0, 3,
'');
317 $pdf->SetTextColor(0, 0, 0);
319 $tab_top = 90 + $top_shift;
320 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
322 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
325 if (isModEnabled(
'incoterm')) {
326 $desc_incoterms = $object->getIncotermsForPDF();
327 if ($desc_incoterms) {
330 $pdf->SetFont(
'',
'', $default_font_size - 1);
331 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
332 $nexY = $pdf->GetY();
333 $height_incoterms = $nexY - $tab_top;
336 $pdf->SetDrawColor(192, 192, 192);
337 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
339 $tab_top = $nexY + 6;
344 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
347 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
348 if (!empty($extranote)) {
352 $pagenb = $pdf->getPage();
354 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
355 $pageposbeforenote = $pagenb;
364 $pdf->startTransaction();
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
369 $pageposafternote = $pdf->getPage();
370 $posyafter = $pdf->GetY();
372 if ($pageposafternote > $pageposbeforenote) {
373 $pdf->rollbackTransaction(
true);
376 while ($pagenb < $pageposafternote) {
379 if (!empty($tplidx)) {
380 $pdf->useTemplate($tplidx);
383 $this->
_pagehead($pdf, $object, 0, $outputlangs);
386 $pdf->setTopMargin($tab_top_newpage);
388 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
392 $pdf->setPage($pageposbeforenote);
393 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
394 $pdf->SetFont(
'',
'', $default_font_size - 1);
395 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
396 $pageposafternote = $pdf->getPage();
398 $posyafter = $pdf->GetY();
400 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
401 $pdf->AddPage(
'',
'',
true);
404 $pdf->setPage($pageposafternote);
405 $pdf->setTopMargin($tab_top_newpage);
407 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
413 $i = $pageposbeforenote;
414 while ($i < $pageposafternote) {
418 $pdf->SetDrawColor(128, 128, 128);
420 if ($i > $pageposbeforenote) {
421 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
422 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
424 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
425 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
429 $pdf->setPageOrientation(
'', 1, 0);
430 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
436 $pdf->setPage($pageposafternote);
437 if (!empty($tplidx)) {
438 $pdf->useTemplate($tplidx);
441 $this->
_pagehead($pdf, $object, 0, $outputlangs);
443 $height_note = $posyafter - $tab_top_newpage;
444 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
447 $pdf->commitTransaction();
448 $posyafter = $pdf->GetY();
449 $height_note = $posyafter - $tab_top;
450 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
453 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
455 $pdf->AddPage(
'',
'',
true);
458 $pdf->setPage($pageposafternote);
459 if (!empty($tplidx)) {
460 $pdf->useTemplate($tplidx);
463 $this->
_pagehead($pdf, $object, 0, $outputlangs);
466 $posyafter = $tab_top_newpage;
470 $tab_height = $tab_height - $height_note;
471 $tab_top = $posyafter + 6;
479 $nexY = $tab_top + $this->tabTitleHeight;
482 $pageposbeforeprintlines = $pdf->getPage();
483 $pagenb = $pageposbeforeprintlines;
484 for ($i = 0; $i < $nblines; $i++) {
486 $pdf->SetFont(
'',
'', $default_font_size - 1);
487 $pdf->SetTextColor(0, 0, 0);
490 $imglinesize = array();
491 if (!empty($realpatharray[$i])) {
495 $pdf->setTopMargin($tab_top_newpage);
496 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
497 $pageposbefore = $pdf->getPage();
499 $showpricebeforepagebreak = 1;
501 $posYAfterDescription = 0;
506 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
507 $pdf->AddPage(
'',
'',
true);
508 if (!empty($tplidx)) {
509 $pdf->useTemplate($tplidx);
511 $pdf->setPage($pageposbefore + 1);
513 $curY = $tab_top_newpage;
517 $showpricebeforepagebreak = 1;
519 $showpricebeforepagebreak = 0;
523 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
524 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
526 $posYAfterImage = $curY + $imglinesize[
'height'];
530 $curX = $this->posxdesc - 1;
531 $showpricebeforepagebreak = 1;
534 $pdf->startTransaction();
535 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
537 $pageposafter = $pdf->getPage();
538 if ($pageposafter > $pageposbefore) {
539 $pdf->rollbackTransaction(
true);
541 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
543 $pageposafter = $pdf->getPage();
544 $posyafter = $pdf->GetY();
545 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
546 if ($i == ($nblines - 1)) {
547 $pdf->AddPage(
'',
'',
true);
548 if (!empty($tplidx)) {
549 $pdf->useTemplate($tplidx);
552 $pdf->setPage($pageposafter + 1);
558 $showpricebeforepagebreak = 1;
560 $showpricebeforepagebreak = 0;
564 $pdf->commitTransaction();
566 $posYAfterDescription = $pdf->GetY();
569 $nexY = $pdf->GetY();
570 $pageposafter = $pdf->getPage();
571 $pdf->setPage($pageposbefore);
572 $pdf->setTopMargin($this->marge_haute);
573 $pdf->setPageOrientation(
'', 1, 0);
576 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
577 $pdf->setPage($pageposafter);
578 $curY = $tab_top_newpage;
581 $pdf->SetFont(
'',
'', $default_font_size - 1);
587 $nexY = max($pdf->GetY(), $nexY);
594 $nexY = max($pdf->GetY(), $nexY);
602 $nexY = max($pdf->GetY(), $nexY);
608 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
610 $nexY = max($pdf->GetY(), $nexY);
614 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
617 $nexY = max($pdf->GetY(), $nexY);
624 $nexY = max($pdf->GetY(), $nexY);
628 if (!empty($object->lines[$i]->array_options)) {
629 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
631 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
633 $nexY = max($pdf->GetY(), $nexY);
644 'outputlangs' => $outputlangs,
645 'hidedetails' => $hidedetails
647 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
651 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
652 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
654 $tvaligne = $object->lines[$i]->total_tva;
657 $localtax1ligne = $object->lines[$i]->total_localtax1;
658 $localtax2ligne = $object->lines[$i]->total_localtax2;
659 $localtax1_rate = $object->lines[$i]->localtax1_tx;
660 $localtax2_rate = $object->lines[$i]->localtax2_tx;
661 $localtax1_type = $object->lines[$i]->localtax1_type;
662 $localtax2_type = $object->lines[$i]->localtax2_type;
675 $vatrate = (string) $object->lines[$i]->tva_tx;
678 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
679 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
681 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
682 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
686 if ($localtax1_type && $localtax1ligne != 0) {
687 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
688 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
690 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
693 if ($localtax2_type && $localtax2ligne != 0) {
694 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
695 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
697 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
701 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
706 if (!isset($this->tva[$vatrate])) {
707 $this->tva[$vatrate] = 0;
709 $this->tva[$vatrate] += $tvaligne;
710 $vatcode = $object->lines[$i]->vat_src_code;
711 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
712 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
714 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
716 if ($posYAfterImage > $posYAfterDescription) {
717 $nexY = $posYAfterImage;
722 $pdf->setPage($pageposafter);
723 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
725 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
726 $pdf->SetLineStyle(array(
'dash'=>0));
730 while ($pagenb < $pageposafter) {
731 $pdf->setPage($pagenb);
732 if ($pagenb == $pageposbeforeprintlines) {
733 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
735 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
737 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
739 $pdf->setPage($pagenb);
740 $pdf->setPageOrientation(
'', 1, 0);
742 $this->
_pagehead($pdf, $object, 0, $outputlangs);
744 if (!empty($tplidx)) {
745 $pdf->useTemplate($tplidx);
748 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
749 if ($pagenb == $pageposafter) {
750 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
752 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
754 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
757 if (!empty($tplidx)) {
758 $pdf->useTemplate($tplidx);
762 $this->
_pagehead($pdf, $object, 0, $outputlangs);
768 if ($pagenb == $pageposbeforeprintlines) {
769 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
770 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
772 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
773 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
777 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
780 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
783 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
788 $this->
_pagefoot($pdf, $object, $outputlangs);
789 if (method_exists($pdf,
'AliasNbPages')) {
790 $pdf->AliasNbPages();
795 $pdf->Output($file,
'F');
798 $hookmanager->initHooks(array(
'pdfgeneration'));
799 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
801 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
803 $this->error = $hookmanager->error;
804 $this->errors = $hookmanager->errors;
809 $this->result = array(
'fullpath'=>$file);
813 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
817 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
916 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
919 global $conf, $mysoc;
925 $pdf->SetFont(
'',
'', $default_font_size - 1);
930 if ($this->page_largeur < 210) {
933 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
939 $pdf->SetFillColor(255, 255, 255);
940 $pdf->SetXY($col1x, $tab2_top);
941 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
943 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
944 $pdf->SetXY($col2x, $tab2_top);
945 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
948 $pdf->SetFillColor(248, 248, 248);
950 $this->atleastoneratenotnull = 0;
951 foreach ($this->tva as $tvakey => $tvaval) {
953 $this->atleastoneratenotnull++;
956 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
960 if (preg_match(
'/\*/', $tvakey)) {
961 $tvakey = str_replace(
'*',
'', $tvakey);
962 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
965 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
966 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
967 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
969 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
970 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
973 if (!$this->atleastoneratenotnull) {
975 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
976 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
978 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
979 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
982 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on' && $object->total_localtax1 > 0) {
984 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
985 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
986 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
987 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
991 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on' && $object->total_localtax2 > 0) {
993 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
994 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
995 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
996 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
1002 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1003 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1007 foreach ($localtax_rate as $tvakey => $tvaval) {
1012 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1015 if (preg_match(
'/\*/', $tvakey)) {
1016 $tvakey = str_replace(
'*',
'', $tvakey);
1017 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1019 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1020 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1021 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1023 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1024 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1032 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1033 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1037 foreach ($localtax_rate as $tvakey => $tvaval) {
1042 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1045 if (preg_match(
'/\*/', $tvakey)) {
1046 $tvakey = str_replace(
'*',
'', $tvakey);
1047 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1049 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1050 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1051 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1053 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1054 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
1062 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1063 $pdf->SetTextColor(0, 0, 60);
1064 $pdf->SetFillColor(224, 224, 224);
1065 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1067 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1068 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1069 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
1070 $pdf->SetFont(
'',
'', $default_font_size - 1);
1071 $pdf->SetTextColor(0, 0, 0);
1073 $creditnoteamount = 0;
1074 $depositsamount = 0;
1078 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1079 if (!empty($object->paye)) {
1083 if ($deja_regle > 0) {
1087 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1088 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
1089 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1090 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
1093 $pdf->SetTextColor(0, 0, 60);
1094 $pdf->SetFillColor(224, 224, 224);
1095 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1096 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1098 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1099 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
1101 $pdf->SetFont(
'',
'', $default_font_size - 1);
1102 $pdf->SetTextColor(0, 0, 0);
1106 return ($tab2_top + ($tab2_hl * $index));
1174 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1176 global $langs, $conf, $mysoc;
1178 $ltrdirection =
'L';
1179 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1180 $ltrdirection =
'R';
1184 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1198 $pdf->SetTextColor(0, 0, 60);
1199 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1203 $posx = $this->page_largeur - $this->marge_droite - $w;
1204 $posy = $this->marge_haute;
1206 $pdf->SetXY($this->marge_gauche, $posy);
1210 if ($this->emetteur->logo) {
1211 $logodir = $conf->mycompany->dir_output;
1212 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1213 $logodir = $conf->mycompany->multidir_output[$object->entity];
1216 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1218 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1220 if (is_readable($logo)) {
1222 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1224 $pdf->SetTextColor(200, 0, 0);
1225 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1226 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1227 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1230 $text = $this->emetteur->name;
1231 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1235 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1236 $pdf->SetXY($posx, $posy);
1237 $pdf->SetTextColor(0, 0, 60);
1238 $title = $outputlangs->transnoentities(
"SupplierOrder").
" ".$outputlangs->convToOutputCharset($object->ref);
1239 if ($object->status == $object::STATUS_DRAFT) {
1240 $pdf->SetTextColor(128, 0, 0);
1241 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1243 $pdf->MultiCell($w, 3, $title,
'',
'R');
1246 if ($object->ref_supplier) {
1248 $pdf->SetFont(
'',
'B', $default_font_size);
1249 $pdf->SetXY($posx, $posy);
1250 $pdf->SetTextColor(0, 0, 60);
1251 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1255 $pdf->SetFont(
'',
'', $default_font_size - 1);
1258 $object->fetch_projet();
1259 if (!empty($object->project->ref)) {
1261 $pdf->SetXY($posx, $posy);
1262 $pdf->SetTextColor(0, 0, 60);
1263 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1268 $object->fetch_projet();
1269 if (!empty($object->project->ref)) {
1270 $outputlangs->load(
"projects");
1272 $pdf->SetXY($posx, $posy);
1273 $langs->load(
"projects");
1274 $pdf->SetTextColor(0, 0, 60);
1275 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1279 if (!empty($object->date_commande)) {
1281 $pdf->SetXY($posx, $posy);
1282 $pdf->SetTextColor(0, 0, 60);
1283 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date($object->date_commande,
"day",
false, $outputlangs,
true),
'',
'R');
1294 $pdf->SetTextColor(0, 0, 60);
1295 $usehourmin =
'day';
1297 $usehourmin =
'dayhour';
1299 if (!empty($object->delivery_date)) {
1301 $pdf->SetXY($posx - 90, $posy);
1302 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1305 if ($object->thirdparty->code_fournisseur) {
1307 $pdf->SetXY($posx, $posy);
1308 $pdf->SetTextColor(0, 0, 60);
1309 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1314 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1315 if (count($arrayidcontact) > 0) {
1316 $usertmp =
new User($this->db);
1317 $usertmp->fetch($arrayidcontact[0]);
1319 $pdf->SetXY($posx, $posy);
1320 $pdf->SetTextColor(0, 0, 60);
1321 $pdf->MultiCell($w, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1326 $pdf->SetTextColor(0, 0, 60);
1330 $current_y = $pdf->getY();
1332 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1333 if ($current_y < $pdf->getY()) {
1334 $top_shift = $pdf->getY() - $current_y;
1339 $carac_emetteur =
'';
1341 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1342 if (count($arrayidcontact) > 0) {
1343 $object->fetch_user($arrayidcontact[0]);
1344 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1345 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1347 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1349 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1351 $carac_emetteur .=
"\n";
1354 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1357 $posy = 42 + $top_shift;
1358 $posx = $this->marge_gauche;
1360 $posx = $this->page_largeur - $this->marge_droite - 80;
1365 $pdf->SetTextColor(0, 0, 0);
1366 $pdf->SetFont(
'',
'', $default_font_size - 2);
1367 $pdf->SetXY($posx, $posy - 5);
1368 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1369 $pdf->SetXY($posx, $posy);
1370 $pdf->SetFillColor(230, 230, 230);
1371 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1372 $pdf->SetTextColor(0, 0, 60);
1375 $pdf->SetXY($posx + 2, $posy + 3);
1376 $pdf->SetFont(
'',
'B', $default_font_size);
1377 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1378 $posy = $pdf->getY();
1381 $pdf->SetXY($posx + 2, $posy);
1382 $pdf->SetFont(
'',
'', $default_font_size - 1);
1383 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1388 $usecontact =
false;
1389 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1390 if (count($arrayidcontact) > 0) {
1392 $result = $object->fetch_contact($arrayidcontact[0]);
1396 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1397 $thirdparty = $object->contact;
1399 $thirdparty = $object->thirdparty;
1404 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1408 if ($this->page_largeur < 210) {
1411 $posy = 42 + $top_shift;
1412 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1414 $posx = $this->marge_gauche;
1418 $pdf->SetTextColor(0, 0, 0);
1419 $pdf->SetFont(
'',
'', $default_font_size - 2);
1420 $pdf->SetXY($posx + 2, $posy - 5);
1421 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1422 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1425 $pdf->SetXY($posx + 2, $posy + 3);
1426 $pdf->SetFont(
'',
'B', $default_font_size);
1427 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1429 $posy = $pdf->getY();
1432 $pdf->SetFont(
'',
'', $default_font_size - 1);
1433 $pdf->SetXY($posx + 2, $posy);
1434 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);