172 public function write_file($object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
175 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
177 if (!is_object($outputlangs)) {
178 $outputlangs = $langs;
182 $outputlangs->charset_output =
'ISO-8859-1';
186 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
188 $nblines = count($object->lines);
191 $realpatharray = array();
193 for ($i = 0; $i < $nblines; $i++) {
194 if (empty($object->lines[$i]->fk_product)) {
198 $objphoto =
new Product($this->db);
199 $objphoto->fetch($object->lines[$i]->fk_product);
202 $pdir =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
203 $dir = $conf->product->dir_output.
'/'.$pdir;
205 $pdir =
get_exdir($objphoto->id, 0, 0, 0, $objphoto,
'product');
206 $dir = $conf->product->dir_output.
'/'.$pdir;
209 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
211 if ($obj[
'photo_vignette']) {
212 $filename = $obj[
'photo_vignette'];
214 $filename = $obj[
'photo'];
217 $filename = $obj[
'photo'];
219 $realpath = $dir.$filename;
224 $realpatharray[$i] = $realpath;
228 if (count($realpatharray) == 0) {
229 $this->posxpicture = $this->posxtva;
232 if ($conf->fournisseur->commande->dir_output) {
233 $object->fetch_thirdparty();
236 $amount_credit_notes_included = 0;
237 $amount_deposits_included = 0;
242 if ($object->specimen) {
243 $dir = $conf->fournisseur->commande->dir_output;
244 $file = $dir.
"/SPECIMEN.pdf";
248 $dir = $conf->fournisseur->commande->dir_output.
'/'.$objectref;
249 $file = $dir.
"/".$objectref.
".pdf";
251 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
255 if (!file_exists($dir)) {
257 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
262 if (file_exists($dir)) {
264 if (!is_object($hookmanager)) {
265 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
268 $hookmanager->initHooks(array(
'pdfgeneration'));
269 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
271 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
273 $nblines = count($object->lines);
277 $heightforinfotot = 50;
278 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
279 $heightforfooter = $this->marge_basse + 8;
281 $heightforfooter += 6;
283 $pdf->SetAutoPageBreak(1, 0);
285 if (class_exists(
'TCPDF')) {
286 $pdf->setPrintHeader(
false);
287 $pdf->setPrintFooter(
false);
292 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
293 $tplidx = $pdf->importPage(1);
298 $pdf->SetDrawColor(128, 128, 128);
300 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
301 $pdf->SetSubject($outputlangs->transnoentities(
"PurchaseOrder"));
302 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
303 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
305 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PurchaseOrder").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
307 $pdf->SetCompression(
false);
310 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
313 for ($i = 0; $i < $nblines; $i++) {
314 if ($object->lines[$i]->remise_percent) {
315 $this->atleastonediscount++;
318 if (empty($this->atleastonediscount)) {
319 $delta = ($this->postotalht - $this->posxdiscount);
320 $this->posxpicture += $delta;
321 $this->posxtva += $delta;
322 $this->posxup += $delta;
323 $this->posxqty += $delta;
324 $this->posxunit += $delta;
325 $this->posxdiscount += $delta;
331 if (!empty($tplidx)) {
332 $pdf->useTemplate($tplidx);
335 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
336 $pdf->SetFont(
'',
'', $default_font_size - 1);
337 $pdf->MultiCell(0, 3,
'');
338 $pdf->SetTextColor(0, 0, 0);
340 $tab_top = 90 + $top_shift;
341 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
344 if (isModEnabled(
'incoterm')) {
345 $desc_incoterms = $object->getIncotermsForPDF();
346 if ($desc_incoterms) {
349 $pdf->SetFont(
'',
'', $default_font_size - 1);
350 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
351 $nexY = $pdf->GetY();
352 $height_incoterms = $nexY - $tab_top;
355 $pdf->SetDrawColor(192, 192, 192);
356 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
358 $tab_top = $nexY + 6;
363 if (!empty($object->note_public)) {
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($object->note_public), 0, 1);
368 $nexY = $pdf->GetY();
369 $height_note = $nexY - $tab_top;
372 $pdf->SetDrawColor(192, 192, 192);
373 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
375 $tab_top = $nexY + 6;
378 $iniY = $tab_top + 7;
379 $curY = $tab_top + 7;
380 $nexY = $tab_top + 7;
383 for ($i = 0; $i < $nblines; $i++) {
385 $pdf->SetFont(
'',
'', $default_font_size - 1);
386 $pdf->SetTextColor(0, 0, 0);
389 $imglinesize = array();
390 if (!empty($realpatharray[$i])) {
394 $pdf->setTopMargin($tab_top_newpage);
395 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
396 $pageposbefore = $pdf->getPage();
398 $showpricebeforepagebreak = 1;
400 $posYAfterDescription = 0;
403 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
404 $pdf->AddPage(
'',
'',
true);
405 if (!empty($tplidx)) {
406 $pdf->useTemplate($tplidx);
409 $this->
_pagehead($pdf, $object, 0, $outputlangs);
411 $pdf->setPage($pageposbefore + 1);
413 $curY = $tab_top_newpage;
417 $showpricebeforepagebreak = 1;
419 $showpricebeforepagebreak = 0;
423 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
424 $curX = $this->posxpicture - 1;
425 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
427 $posYAfterImage = $curY + $imglinesize[
'height'];
430 $curX = $this->posxdesc - 1;
431 $showpricebeforepagebreak = 1;
433 $pdf->startTransaction();
434 if ($posYAfterImage > 0) {
435 $descWidth = $this->posxpicture - $curX;
437 $descWidth = $this->posxtva - $curX;
439 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
441 $pageposafter = $pdf->getPage();
442 if ($pageposafter > $pageposbefore) {
443 $pdf->rollbackTransaction(
true);
444 $pageposafter = $pageposbefore;
446 $pdf->setPageOrientation(
'', 1, $heightforfooter);
447 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
448 $posyafter = $pdf->GetY();
449 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
450 if ($i == ($nblines - 1)) {
451 $pdf->AddPage(
'',
'',
true);
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
456 $this->
_pagehead($pdf, $object, 0, $outputlangs);
458 $pdf->setPage($pageposafter + 1);
464 $showpricebeforepagebreak = 1;
466 $showpricebeforepagebreak = 0;
470 $pdf->commitTransaction();
473 $nexY = $pdf->GetY();
474 $pageposafter = $pdf->getPage();
475 $pdf->setPage($pageposbefore);
476 $pdf->setTopMargin($this->marge_haute);
477 $pdf->setPageOrientation(
'', 1, 0);
480 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
481 $pdf->setPage($pageposafter);
482 $curY = $tab_top_newpage;
485 $pdf->SetFont(
'',
'', $default_font_size - 1);
490 $pdf->SetXY($this->posxtva, $curY);
491 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
495 if (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE')) {
497 $pdf->SetXY($this->posxup, $curY);
498 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
503 $pdf->SetXY($this->posxqty, $curY);
504 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
508 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
509 $pdf->SetXY($this->posxunit, $curY);
510 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
514 $pdf->SetXY($this->posxdiscount, $curY);
515 if ($object->lines[$i]->remise_percent) {
517 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
521 if (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN')) {
523 $pdf->SetXY($this->postotalht, $curY);
524 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
528 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
529 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
531 $tvaligne = $object->lines[$i]->total_tva;
534 $localtax1ligne = $object->lines[$i]->total_localtax1;
535 $localtax2ligne = $object->lines[$i]->total_localtax2;
536 $localtax1_rate = $object->lines[$i]->localtax1_tx;
537 $localtax2_rate = $object->lines[$i]->localtax2_tx;
538 $localtax1_type = $object->lines[$i]->localtax1_type;
539 $localtax2_type = $object->lines[$i]->localtax2_type;
552 $vatrate = (string) $object->lines[$i]->tva_tx;
555 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
556 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
558 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
559 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
563 if ($localtax1_type && $localtax1ligne != 0) {
564 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
565 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
567 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
570 if ($localtax2_type && $localtax2ligne != 0) {
571 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
572 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
574 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
578 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
583 if (!isset($this->tva[$vatrate])) {
584 $this->tva[$vatrate] = 0;
586 $this->tva[$vatrate] += $tvaligne;
587 $vatcode = $object->lines[$i]->vat_src_code;
588 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
589 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
591 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
593 if ($posYAfterImage > $posYAfterDescription) {
594 $nexY = $posYAfterImage;
599 $pdf->setPage($pageposafter);
600 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
602 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
603 $pdf->SetLineStyle(array(
'dash'=>0));
609 while ($pagenb < $pageposafter) {
610 $pdf->setPage($pagenb);
612 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
614 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
616 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
618 $pdf->setPage($pagenb);
619 $pdf->setPageOrientation(
'', 1, 0);
621 $this->
_pagehead($pdf, $object, 0, $outputlangs);
623 if (!empty($tplidx)) {
624 $pdf->useTemplate($tplidx);
627 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
629 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
631 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
633 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
636 if (!empty($tplidx)) {
637 $pdf->useTemplate($tplidx);
641 $this->
_pagehead($pdf, $object, 0, $outputlangs);
648 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
649 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
651 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
652 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
656 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
659 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
662 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
667 $this->
_pagefoot($pdf, $object, $outputlangs);
668 if (method_exists($pdf,
'AliasNbPages')) {
669 $pdf->AliasNbPages();
674 $pdf->Output($file,
'F');
677 $hookmanager->initHooks(array(
'pdfgeneration'));
678 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
680 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
682 $this->error = $hookmanager->error;
683 $this->errors = $hookmanager->errors;
688 $this->result = array(
'fullpath'=>$file);
692 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
696 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
794 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
797 global $conf, $mysoc;
803 $pdf->SetFont(
'',
'', $default_font_size - 1);
808 if ($this->page_largeur < 210) {
811 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
817 $pdf->SetFillColor(255, 255, 255);
818 $pdf->SetXY($col1x, $tab2_top);
819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
821 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
822 $pdf->SetXY($col2x, $tab2_top);
823 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
826 $pdf->SetFillColor(248, 248, 248);
828 $this->atleastoneratenotnull = 0;
829 foreach ($this->tva as $tvakey => $tvaval) {
831 $this->atleastoneratenotnull++;
834 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
838 if (preg_match(
'/\*/', $tvakey)) {
839 $tvakey = str_replace(
'*',
'', $tvakey);
840 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
843 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
844 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
845 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
847 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
848 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
851 if (!$this->atleastoneratenotnull) {
853 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
854 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
856 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
857 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
860 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on' && $object->total_localtax1 > 0) {
862 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
863 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
864 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
865 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
869 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on' && $object->total_localtax2 > 0) {
871 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
872 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
873 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
874 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
880 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
881 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
885 foreach ($localtax_rate as $tvakey => $tvaval) {
890 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
893 if (preg_match(
'/\*/', $tvakey)) {
894 $tvakey = str_replace(
'*',
'', $tvakey);
895 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
897 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
898 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
899 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
901 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
902 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
910 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
911 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
915 foreach ($localtax_rate as $tvakey => $tvaval) {
920 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
923 if (preg_match(
'/\*/', $tvakey)) {
924 $tvakey = str_replace(
'*',
'', $tvakey);
925 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
927 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
928 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
929 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
931 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
932 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
940 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
941 $pdf->SetTextColor(0, 0, 60);
942 $pdf->SetFillColor(224, 224, 224);
943 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
945 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
946 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
947 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
948 $pdf->SetFont(
'',
'', $default_font_size - 1);
949 $pdf->SetTextColor(0, 0, 0);
951 $creditnoteamount = 0;
956 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
957 if (!empty($object->paye)) {
961 if ($deja_regle > 0) {
965 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
966 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
967 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
968 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
971 $pdf->SetTextColor(0, 0, 60);
972 $pdf->SetFillColor(224, 224, 224);
973 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
974 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
976 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
977 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
979 $pdf->SetFont(
'',
'', $default_font_size - 1);
980 $pdf->SetTextColor(0, 0, 0);
984 return ($tab2_top + ($tab2_hl * $index));
1001 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1011 $currency = !empty($currency) ? $currency : $conf->currency;
1015 $pdf->SetTextColor(0, 0, 0);
1016 $pdf->SetFont(
'',
'', $default_font_size - 2);
1018 if (empty($hidetop)) {
1019 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1020 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1021 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1025 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1029 $pdf->SetDrawColor(128, 128, 128);
1030 $pdf->SetFont(
'',
'', $default_font_size - 1);
1033 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1035 if (empty($hidetop)) {
1036 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1038 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1039 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1043 $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1044 if (empty($hidetop)) {
1045 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1046 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1050 $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1051 if (empty($hidetop)) {
1052 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1053 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1056 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1057 if (empty($hidetop)) {
1058 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1059 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1063 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1064 if (empty($hidetop)) {
1065 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1066 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1070 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1071 if (empty($hidetop)) {
1072 if ($this->atleastonediscount) {
1073 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1074 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1078 if ($this->atleastonediscount) {
1079 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1081 if (empty($hidetop)) {
1082 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1083 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1097 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1099 global $langs, $conf, $mysoc;
1101 $ltrdirection =
'L';
1102 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1103 $ltrdirection =
'R';
1107 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1121 $pdf->SetTextColor(0, 0, 60);
1122 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1126 $posx = $this->page_largeur - $this->marge_droite - 100;
1127 $posy = $this->marge_haute;
1129 $pdf->SetXY($this->marge_gauche, $posy);
1133 if ($this->emetteur->logo) {
1134 $logodir = $conf->mycompany->dir_output;
1135 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1136 $logodir = $conf->mycompany->multidir_output[$object->entity];
1139 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1141 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1143 if (is_readable($logo)) {
1145 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1147 $pdf->SetTextColor(200, 0, 0);
1148 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1149 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1150 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1153 $text = $this->emetteur->name;
1154 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1158 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1159 $pdf->SetXY($posx, $posy);
1160 $pdf->SetTextColor(0, 0, 60);
1161 $title = $outputlangs->transnoentities(
"SupplierOrder").
" ".$outputlangs->convToOutputCharset($object->ref);
1162 if ($object->status == $object::STATUS_DRAFT) {
1163 $pdf->SetTextColor(128, 0, 0);
1164 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1166 $pdf->MultiCell($w, 3, $title,
'',
'R');
1169 if ($object->ref_supplier) {
1171 $pdf->SetFont(
'',
'B', $default_font_size);
1172 $pdf->SetXY($posx, $posy);
1173 $pdf->SetTextColor(0, 0, 60);
1174 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1178 $pdf->SetFont(
'',
'', $default_font_size - 1);
1181 $object->fetch_projet();
1182 if (!empty($object->project->ref)) {
1184 $pdf->SetXY($posx, $posy);
1185 $pdf->SetTextColor(0, 0, 60);
1186 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1191 $object->fetch_projet();
1192 if (!empty($object->project->ref)) {
1193 $outputlangs->load(
"projects");
1195 $pdf->SetXY($posx, $posy);
1196 $langs->load(
"projects");
1197 $pdf->SetTextColor(0, 0, 60);
1198 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1202 if (!empty($object->date_commande)) {
1204 $pdf->SetXY($posx, $posy);
1205 $pdf->SetTextColor(0, 0, 60);
1206 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date($object->date_commande,
"day",
false, $outputlangs,
true),
'',
'R');
1216 $pdf->SetTextColor(0, 0, 60);
1217 $usehourmin =
'day';
1219 $usehourmin =
'dayhour';
1221 if (!empty($object->delivery_date)) {
1223 $pdf->SetXY($posx - 90, $posy);
1224 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1227 if ($object->thirdparty->code_fournisseur) {
1229 $pdf->SetXY($posx, $posy);
1230 $pdf->SetTextColor(0, 0, 60);
1231 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1236 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1237 if (count($arrayidcontact) > 0) {
1238 $usertmp =
new User($this->db);
1239 $usertmp->fetch($arrayidcontact[0]);
1241 $pdf->SetXY($posx, $posy);
1242 $pdf->SetTextColor(0, 0, 60);
1243 $pdf->MultiCell($w, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1248 $pdf->SetTextColor(0, 0, 60);
1252 $current_y = $pdf->getY();
1253 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1254 if ($current_y < $pdf->getY()) {
1255 $top_shift = $pdf->getY() - $current_y;
1260 $carac_emetteur =
'';
1262 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1263 if (count($arrayidcontact) > 0) {
1264 $object->fetch_user($arrayidcontact[0]);
1265 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1266 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1268 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1270 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1272 $carac_emetteur .=
"\n";
1275 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1278 $posy = 42 + $top_shift;
1279 $posx = $this->marge_gauche;
1281 $posx = $this->page_largeur - $this->marge_droite - 80;
1286 $pdf->SetTextColor(0, 0, 0);
1287 $pdf->SetFont(
'',
'', $default_font_size - 2);
1288 $pdf->SetXY($posx, $posy - 5);
1289 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1290 $pdf->SetXY($posx, $posy);
1291 $pdf->SetFillColor(230, 230, 230);
1292 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1293 $pdf->SetTextColor(0, 0, 60);
1296 $pdf->SetXY($posx + 2, $posy + 3);
1297 $pdf->SetFont(
'',
'B', $default_font_size);
1298 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1299 $posy = $pdf->getY();
1302 $pdf->SetXY($posx + 2, $posy);
1303 $pdf->SetFont(
'',
'', $default_font_size - 1);
1304 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1308 $usecontact =
false;
1309 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1310 if (count($arrayidcontact) > 0) {
1312 $result = $object->fetch_contact($arrayidcontact[0]);
1316 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1317 $thirdparty = $object->contact;
1319 $thirdparty = $object->thirdparty;
1324 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1328 if ($this->page_largeur < 210) {
1331 $posy = 42 + $top_shift;
1332 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1334 $posx = $this->marge_gauche;
1338 $pdf->SetTextColor(0, 0, 0);
1339 $pdf->SetFont(
'',
'', $default_font_size - 2);
1340 $pdf->SetXY($posx + 2, $posy - 5);
1341 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1342 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1345 $pdf->SetXY($posx + 2, $posy + 3);
1346 $pdf->SetFont(
'',
'B', $default_font_size);
1347 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1349 $posy = $pdf->getY();
1352 $pdf->SetFont(
'',
'', $default_font_size - 1);
1353 $pdf->SetXY($posx + 2, $posy);
1354 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);