213 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
216 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
218 if (!is_object($outputlangs)) {
219 $outputlangs = $langs;
222 if (!empty($conf->global->MAIN_USE_FPDF)) {
223 $outputlangs->charset_output =
'ISO-8859-1';
227 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
229 $nblines = count($object->lines);
232 $realpatharray = array();
233 if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
234 for ($i = 0; $i < $nblines; $i++) {
235 if (empty($object->lines[$i]->fk_product)) {
239 $objphoto =
new Product($this->db);
240 $objphoto->fetch($object->lines[$i]->fk_product);
243 $pdir =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
244 $dir = $conf->product->dir_output.
'/'.$pdir;
246 $pdir =
get_exdir($objphoto->id, 0, 0, 0, $objphoto,
'product');
247 $dir = $conf->product->dir_output.
'/'.$pdir;
250 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
252 if ($obj[
'photo_vignette']) {
253 $filename = $obj[
'photo_vignette'];
255 $filename = $obj[
'photo'];
258 $filename = $obj[
'photo'];
260 $realpath = $dir.$filename;
265 $realpatharray[$i] = $realpath;
269 if (count($realpatharray) == 0) {
270 $this->posxpicture = $this->posxtva;
273 if ($conf->fournisseur->commande->dir_output) {
274 $object->fetch_thirdparty();
277 $amount_credit_notes_included = 0;
278 $amount_deposits_included = 0;
283 if ($object->specimen) {
284 $dir = $conf->fournisseur->commande->dir_output;
285 $file = $dir.
"/SPECIMEN.pdf";
289 $dir = $conf->fournisseur->commande->dir_output.
'/'.$objectref;
290 $file = $dir.
"/".$objectref.
".pdf";
291 if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
292 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
296 if (!file_exists($dir)) {
298 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
303 if (file_exists($dir)) {
305 if (!is_object($hookmanager)) {
306 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
309 $hookmanager->initHooks(array(
'pdfgeneration'));
310 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
312 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
314 $nblines = count($object->lines);
318 $heightforinfotot = 50;
319 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
320 $heightforfooter = $this->marge_basse + 8;
321 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
322 $heightforfooter += 6;
324 $pdf->SetAutoPageBreak(1, 0);
326 if (class_exists(
'TCPDF')) {
327 $pdf->setPrintHeader(
false);
328 $pdf->setPrintFooter(
false);
332 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
333 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
334 $tplidx = $pdf->importPage(1);
339 $pdf->SetDrawColor(128, 128, 128);
341 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
342 $pdf->SetSubject($outputlangs->transnoentities(
"PurchaseOrder"));
343 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
344 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
346 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PurchaseOrder").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
348 $pdf->SetCompression(
false);
351 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
354 for ($i = 0; $i < $nblines; $i++) {
355 if ($object->lines[$i]->remise_percent) {
356 $this->atleastonediscount++;
359 if (empty($this->atleastonediscount)) {
360 $delta = ($this->postotalht - $this->posxdiscount);
361 $this->posxpicture += $delta;
362 $this->posxtva += $delta;
363 $this->posxup += $delta;
364 $this->posxqty += $delta;
365 $this->posxunit += $delta;
366 $this->posxdiscount += $delta;
372 if (!empty($tplidx)) {
373 $pdf->useTemplate($tplidx);
376 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
377 $pdf->SetFont(
'',
'', $default_font_size - 1);
378 $pdf->MultiCell(0, 3,
'');
379 $pdf->SetTextColor(0, 0, 0);
381 $tab_top = 90 + $top_shift;
382 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
385 if (isModEnabled(
'incoterm')) {
386 $desc_incoterms = $object->getIncotermsForPDF();
387 if ($desc_incoterms) {
390 $pdf->SetFont(
'',
'', $default_font_size - 1);
391 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
392 $nexY = $pdf->GetY();
393 $height_incoterms = $nexY - $tab_top;
396 $pdf->SetDrawColor(192, 192, 192);
397 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
399 $tab_top = $nexY + 6;
404 if (!empty($object->note_public)) {
407 $pdf->SetFont(
'',
'', $default_font_size - 1);
408 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($object->note_public), 0, 1);
409 $nexY = $pdf->GetY();
410 $height_note = $nexY - $tab_top;
413 $pdf->SetDrawColor(192, 192, 192);
414 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
416 $tab_top = $nexY + 6;
419 $iniY = $tab_top + 7;
420 $curY = $tab_top + 7;
421 $nexY = $tab_top + 7;
424 for ($i = 0; $i < $nblines; $i++) {
426 $pdf->SetFont(
'',
'', $default_font_size - 1);
427 $pdf->SetTextColor(0, 0, 0);
430 $imglinesize = array();
431 if (!empty($realpatharray[$i])) {
435 $pdf->setTopMargin($tab_top_newpage);
436 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
437 $pageposbefore = $pdf->getPage();
439 $showpricebeforepagebreak = 1;
441 $posYAfterDescription = 0;
444 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
445 $pdf->AddPage(
'',
'',
true);
446 if (!empty($tplidx)) {
447 $pdf->useTemplate($tplidx);
450 $this->
_pagehead($pdf, $object, 0, $outputlangs);
452 $pdf->setPage($pageposbefore + 1);
454 $curY = $tab_top_newpage;
457 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
458 $showpricebeforepagebreak = 1;
460 $showpricebeforepagebreak = 0;
464 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
465 $curX = $this->posxpicture - 1;
466 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
468 $posYAfterImage = $curY + $imglinesize[
'height'];
471 $curX = $this->posxdesc - 1;
472 $showpricebeforepagebreak = 1;
474 $pdf->startTransaction();
475 if ($posYAfterImage > 0) {
476 $descWidth = $this->posxpicture - $curX;
478 $descWidth = $this->posxtva - $curX;
480 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
482 $pageposafter = $pdf->getPage();
483 if ($pageposafter > $pageposbefore) {
484 $pdf->rollbackTransaction(
true);
485 $pageposafter = $pageposbefore;
487 $pdf->setPageOrientation(
'', 1, $heightforfooter);
488 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
489 $posyafter = $pdf->GetY();
490 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
491 if ($i == ($nblines - 1)) {
492 $pdf->AddPage(
'',
'',
true);
493 if (!empty($tplidx)) {
494 $pdf->useTemplate($tplidx);
497 $this->
_pagehead($pdf, $object, 0, $outputlangs);
499 $pdf->setPage($pageposafter + 1);
504 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
505 $showpricebeforepagebreak = 1;
507 $showpricebeforepagebreak = 0;
512 $pdf->commitTransaction();
515 $nexY = $pdf->GetY();
516 $pageposafter = $pdf->getPage();
517 $pdf->setPage($pageposbefore);
518 $pdf->setTopMargin($this->marge_haute);
519 $pdf->setPageOrientation(
'', 1, 0);
522 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
523 $pdf->setPage($pageposafter);
524 $curY = $tab_top_newpage;
527 $pdf->SetFont(
'',
'', $default_font_size - 1);
530 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
532 $pdf->SetXY($this->posxtva, $curY);
533 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
537 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE)) {
539 $pdf->SetXY($this->posxup, $curY);
540 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
545 $pdf->SetXY($this->posxqty, $curY);
546 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
550 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
551 $pdf->SetXY($this->posxunit, $curY);
552 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
556 $pdf->SetXY($this->posxdiscount, $curY);
557 if ($object->lines[$i]->remise_percent) {
559 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
563 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN)) {
565 $pdf->SetXY($this->postotalht, $curY);
566 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
570 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
571 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
573 $tvaligne = $object->lines[$i]->total_tva;
576 $localtax1ligne = $object->lines[$i]->total_localtax1;
577 $localtax2ligne = $object->lines[$i]->total_localtax2;
578 $localtax1_rate = $object->lines[$i]->localtax1_tx;
579 $localtax2_rate = $object->lines[$i]->localtax2_tx;
580 $localtax1_type = $object->lines[$i]->localtax1_type;
581 $localtax2_type = $object->lines[$i]->localtax2_type;
594 $vatrate = (string) $object->lines[$i]->tva_tx;
597 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
598 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
600 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
601 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
605 if ($localtax1_type && $localtax1ligne != 0) {
606 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
607 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
609 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
612 if ($localtax2_type && $localtax2ligne != 0) {
613 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
614 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
616 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
620 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
625 if (!isset($this->tva[$vatrate])) {
626 $this->tva[$vatrate] = 0;
628 $this->tva[$vatrate] += $tvaligne;
629 $vatcode = $object->lines[$i]->vat_src_code;
630 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
631 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
633 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
635 if ($posYAfterImage > $posYAfterDescription) {
636 $nexY = $posYAfterImage;
640 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
641 $pdf->setPage($pageposafter);
642 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
644 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
645 $pdf->SetLineStyle(array(
'dash'=>0));
651 while ($pagenb < $pageposafter) {
652 $pdf->setPage($pagenb);
654 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
656 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
658 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
660 $pdf->setPage($pagenb);
661 $pdf->setPageOrientation(
'', 1, 0);
663 $this->
_pagehead($pdf, $object, 0, $outputlangs);
665 if (!empty($tplidx)) {
666 $pdf->useTemplate($tplidx);
669 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
671 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
673 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
675 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
678 if (!empty($tplidx)) {
679 $pdf->useTemplate($tplidx);
683 $this->
_pagehead($pdf, $object, 0, $outputlangs);
690 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
691 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
693 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
694 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
698 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
701 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
704 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
709 $this->
_pagefoot($pdf, $object, $outputlangs);
710 if (method_exists($pdf,
'AliasNbPages')) {
711 $pdf->AliasNbPages();
716 $pdf->Output($file,
'F');
719 $hookmanager->initHooks(array(
'pdfgeneration'));
720 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
722 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
724 $this->error = $hookmanager->error;
725 $this->errors = $hookmanager->errors;
730 $this->result = array(
'fullpath'=>$file);
734 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
738 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
836 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
839 global $conf, $mysoc;
845 $pdf->SetFont(
'',
'', $default_font_size - 1);
850 if ($this->page_largeur < 210) {
853 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
859 $pdf->SetFillColor(255, 255, 255);
860 $pdf->SetXY($col1x, $tab2_top);
861 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
863 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
864 $pdf->SetXY($col2x, $tab2_top);
865 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
868 $pdf->SetFillColor(248, 248, 248);
870 $this->atleastoneratenotnull = 0;
871 foreach ($this->tva as $tvakey => $tvaval) {
873 $this->atleastoneratenotnull++;
876 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
880 if (preg_match(
'/\*/', $tvakey)) {
881 $tvakey = str_replace(
'*',
'', $tvakey);
882 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
885 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
886 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
887 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
889 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
890 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
893 if (!$this->atleastoneratenotnull) {
895 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
896 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
898 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
899 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
902 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
904 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
905 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
906 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
907 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
911 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
913 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
914 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
915 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
916 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
922 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
923 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
927 foreach ($localtax_rate as $tvakey => $tvaval) {
932 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
935 if (preg_match(
'/\*/', $tvakey)) {
936 $tvakey = str_replace(
'*',
'', $tvakey);
937 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
939 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
940 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
941 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
943 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
944 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
952 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
953 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
957 foreach ($localtax_rate as $tvakey => $tvaval) {
962 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
965 if (preg_match(
'/\*/', $tvakey)) {
966 $tvakey = str_replace(
'*',
'', $tvakey);
967 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
969 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
970 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
971 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
973 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
974 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
982 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
983 $pdf->SetTextColor(0, 0, 60);
984 $pdf->SetFillColor(224, 224, 224);
985 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
987 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
988 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
989 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
990 $pdf->SetFont(
'',
'', $default_font_size - 1);
991 $pdf->SetTextColor(0, 0, 0);
993 $creditnoteamount = 0;
998 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
999 if (!empty($object->paye)) {
1003 if ($deja_regle > 0) {
1007 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1008 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
1009 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1010 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
1013 $pdf->SetTextColor(0, 0, 60);
1014 $pdf->SetFillColor(224, 224, 224);
1015 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1016 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1018 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1019 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
1021 $pdf->SetFont(
'',
'', $default_font_size - 1);
1022 $pdf->SetTextColor(0, 0, 0);
1026 return ($tab2_top + ($tab2_hl * $index));
1043 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1053 $currency = !empty($currency) ? $currency : $conf->currency;
1057 $pdf->SetTextColor(0, 0, 0);
1058 $pdf->SetFont(
'',
'', $default_font_size - 2);
1060 if (empty($hidetop)) {
1061 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1062 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1063 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1066 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1067 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1071 $pdf->SetDrawColor(128, 128, 128);
1072 $pdf->SetFont(
'',
'', $default_font_size - 1);
1075 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1077 if (empty($hidetop)) {
1078 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1080 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1081 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1084 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1085 $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1086 if (empty($hidetop)) {
1087 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1088 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1092 $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1093 if (empty($hidetop)) {
1094 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1095 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1098 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1099 if (empty($hidetop)) {
1100 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1101 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1105 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1106 if (empty($hidetop)) {
1107 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1108 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1112 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1113 if (empty($hidetop)) {
1114 if ($this->atleastonediscount) {
1115 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1116 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1120 if ($this->atleastonediscount) {
1121 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1123 if (empty($hidetop)) {
1124 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1125 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1139 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1141 global $langs, $conf, $mysoc;
1143 $ltrdirection =
'L';
1144 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1145 $ltrdirection =
'R';
1149 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1163 $pdf->SetTextColor(0, 0, 60);
1164 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1166 $posx = $this->page_largeur - $this->marge_droite - 100;
1167 $posy = $this->marge_haute;
1169 $pdf->SetXY($this->marge_gauche, $posy);
1173 if ($this->emetteur->logo) {
1174 $logodir = $conf->mycompany->dir_output;
1175 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1176 $logodir = $conf->mycompany->multidir_output[$object->entity];
1179 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1181 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1183 if (is_readable($logo)) {
1185 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1187 $pdf->SetTextColor(200, 0, 0);
1188 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1189 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1190 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1193 $text = $this->emetteur->name;
1194 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1198 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1199 $pdf->SetXY($posx, $posy);
1200 $pdf->SetTextColor(0, 0, 60);
1201 $title = $outputlangs->transnoentities(
"SupplierOrder").
" ".$outputlangs->convToOutputCharset($object->ref);
1202 $pdf->MultiCell(100, 3, $title,
'',
'R');
1205 if ($object->ref_supplier) {
1207 $pdf->SetFont(
'',
'B', $default_font_size);
1208 $pdf->SetXY($posx, $posy);
1209 $pdf->SetTextColor(0, 0, 60);
1210 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1214 $pdf->SetFont(
'',
'', $default_font_size - 1);
1216 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1217 $object->fetch_projet();
1218 if (!empty($object->project->ref)) {
1220 $pdf->SetXY($posx, $posy);
1221 $pdf->SetTextColor(0, 0, 60);
1222 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1226 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1227 $object->fetch_projet();
1228 if (!empty($object->project->ref)) {
1229 $outputlangs->load(
"projects");
1231 $pdf->SetXY($posx, $posy);
1232 $langs->load(
"projects");
1233 $pdf->SetTextColor(0, 0, 60);
1234 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1238 if (!empty($object->date_commande)) {
1240 $pdf->SetXY($posx, $posy);
1241 $pdf->SetTextColor(0, 0, 60);
1242 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date($object->date_commande,
"day",
false, $outputlangs,
true),
'',
'R');
1245 $pdf->SetXY($posx, $posy);
1246 $pdf->SetTextColor(255, 0, 0);
1247 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"OrderToProcess"),
'',
'R');
1250 $pdf->SetTextColor(0, 0, 60);
1251 $usehourmin =
'day';
1252 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1253 $usehourmin =
'dayhour';
1255 if (!empty($object->delivery_date)) {
1257 $pdf->SetXY($posx - 90, $posy);
1258 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1261 if ($object->thirdparty->code_fournisseur) {
1263 $pdf->SetXY($posx, $posy);
1264 $pdf->SetTextColor(0, 0, 60);
1265 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1269 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1270 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1271 if (count($arrayidcontact) > 0) {
1272 $usertmp =
new User($this->db);
1273 $usertmp->fetch($arrayidcontact[0]);
1275 $pdf->SetXY($posx, $posy);
1276 $pdf->SetTextColor(0, 0, 60);
1277 $pdf->MultiCell(100, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1282 $pdf->SetTextColor(0, 0, 60);
1286 $current_y = $pdf->getY();
1287 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1288 if ($current_y < $pdf->getY()) {
1289 $top_shift = $pdf->getY() - $current_y;
1294 $carac_emetteur =
'';
1296 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1297 if (count($arrayidcontact) > 0) {
1298 $object->fetch_user($arrayidcontact[0]);
1299 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1300 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1302 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1304 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1306 $carac_emetteur .=
"\n";
1309 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1312 $posy = 42 + $top_shift;
1313 $posx = $this->marge_gauche;
1314 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1315 $posx = $this->page_largeur - $this->marge_droite - 80;
1320 $pdf->SetTextColor(0, 0, 0);
1321 $pdf->SetFont(
'',
'', $default_font_size - 2);
1322 $pdf->SetXY($posx, $posy - 5);
1323 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1324 $pdf->SetXY($posx, $posy);
1325 $pdf->SetFillColor(230, 230, 230);
1326 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1327 $pdf->SetTextColor(0, 0, 60);
1330 $pdf->SetXY($posx + 2, $posy + 3);
1331 $pdf->SetFont(
'',
'B', $default_font_size);
1332 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1333 $posy = $pdf->getY();
1336 $pdf->SetXY($posx + 2, $posy);
1337 $pdf->SetFont(
'',
'', $default_font_size - 1);
1338 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1342 $usecontact =
false;
1343 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1344 if (count($arrayidcontact) > 0) {
1346 $result = $object->fetch_contact($arrayidcontact[0]);
1350 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)))) {
1351 $thirdparty = $object->contact;
1353 $thirdparty = $object->thirdparty;
1358 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1362 if ($this->page_largeur < 210) {
1365 $posy = 42 + $top_shift;
1366 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1367 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1368 $posx = $this->marge_gauche;
1372 $pdf->SetTextColor(0, 0, 0);
1373 $pdf->SetFont(
'',
'', $default_font_size - 2);
1374 $pdf->SetXY($posx + 2, $posy - 5);
1375 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1376 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1379 $pdf->SetXY($posx + 2, $posy + 3);
1380 $pdf->SetFont(
'',
'B', $default_font_size);
1381 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1383 $posy = $pdf->getY();
1386 $pdf->SetFont(
'',
'', $default_font_size - 1);
1387 $pdf->SetXY($posx + 2, $posy);
1388 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);