234 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
237 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
239 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
241 if (!is_object($outputlangs)) {
242 $outputlangs = $langs;
245 if (!empty($conf->global->MAIN_USE_FPDF)) {
246 $outputlangs->charset_output =
'ISO-8859-1';
250 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
253 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
254 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
257 global $outputlangsbis;
258 $outputlangsbis =
null;
259 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
260 $outputlangsbis =
new Translate(
'', $conf);
261 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
262 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
265 $nblines = count($object->lines);
268 $realpatharray = array();
269 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
270 for ($i = 0; $i < $nblines; $i++) {
271 if (empty($object->lines[$i]->fk_product)) {
275 $objphoto =
new Product($this->db);
276 $objphoto->fetch($object->lines[$i]->fk_product);
278 $pdir =
get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
279 $dir = $conf->product->dir_output.
'/'.$pdir;
282 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
283 $filename = $obj[
'photo'];
285 $realpath = $dir.$filename;
290 $realpatharray[$i] = $realpath;
294 if (count($realpatharray) == 0) {
295 $this->posxpicture = $this->posxtva;
298 if ($conf->facture->dir_output) {
299 $object->fetch_thirdparty();
301 $deja_regle = $object->getSommePaiement((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
302 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
306 if ($object->specimen) {
307 $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity];
308 $file = $dir.
"/SPECIMEN.pdf";
311 $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity]).
"/".$objectref;
312 $file = $dir.
"/".$objectref.
".pdf";
314 if (!file_exists($dir)) {
316 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
321 if (file_exists($dir)) {
323 if (!is_object($hookmanager)) {
324 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
327 $hookmanager->initHooks(array(
'pdfgeneration'));
328 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
330 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
333 $nblines = count($object->lines);
334 $nbpayments = count($object->getListOfPayments());
339 $pdf->SetAutoPageBreak(1, 0);
341 $heightforinfotot = 50 + (4 * $nbpayments);
342 if ($heightforinfotot > 220) {
343 $heightforinfotot = 220;
345 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
346 $heightforfooter = $this->marge_basse + 8;
347 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
348 $heightforfooter += 6;
351 $heightforqrinvoice_firstpage = 0;
354 if ($heightforqrinvoice_firstpage > 0) {
356 $heightforinfotot = 30 + (4 * $nbpayments);
360 if (class_exists(
'TCPDF')) {
361 $pdf->setPrintHeader(
false);
362 $pdf->setPrintFooter(
false);
367 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
368 $logodir = $conf->mycompany->dir_output;
369 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
370 $logodir = $conf->mycompany->multidir_output[$object->entity];
372 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
373 $tplidx = $pdf->importPage(1);
378 $pdf->SetDrawColor(128, 128, 128);
380 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
381 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
382 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
383 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
384 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
386 $pdf->SetCompression(
false);
390 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
391 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
394 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
397 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
402 'Name' => $this->emetteur->name,
403 'Location' =>
getCountry($this->emetteur->country_code, 0),
404 'Reason' =>
'INVOICE',
405 'ContactInfo' => $this->emetteur->email
407 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
410 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
414 $categoryOfOperation = 0;
417 for ($i = 0; $i < $nblines; $i++) {
418 if ($object->lines[$i]->remise_percent) {
419 $this->atleastonediscount++;
423 if ($categoryOfOperation < 2) {
424 $lineProductType = $object->lines[$i]->product_type;
430 if ($nbProduct > 0 && $nbService > 0) {
432 $categoryOfOperation = 2;
437 if ($categoryOfOperation <= 0) {
439 if ($nbProduct == 0 && $nbService > 0) {
440 $categoryOfOperation = 1;
443 $this->categoryOfOperation = $categoryOfOperation;
444 if (empty($this->atleastonediscount)) {
445 $delta = ($this->posxprogress - $this->posxdiscount);
446 $this->posxpicture += $delta;
447 $this->posxtva += $delta;
448 $this->posxup += $delta;
449 $this->posxqty += $delta;
450 $this->posxunit += $delta;
451 $this->posxdiscount += $delta;
457 if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
458 $this->situationinvoice =
true;
459 $progress_width = 10;
460 $this->posxpicture -= $progress_width;
461 $this->posxtva -= $progress_width;
462 $this->posxup -= $progress_width;
463 $this->posxqty -= $progress_width;
464 $this->posxunit -= $progress_width;
465 $this->posxdiscount -= $progress_width;
466 $this->posxprogress -= $progress_width;
471 if (!empty($tplidx)) {
472 $pdf->useTemplate($tplidx);
477 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
478 $pdf->SetFont(
'',
'', $default_font_size - 1);
479 $pdf->MultiCell(0, 3,
'');
480 $pdf->SetTextColor(0, 0, 0);
485 $tab_top = 90 + $top_shift;
486 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
489 $extra_under_address_shift = 0;
491 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
492 $qrcodestring = $object->buildZATCAQRString();
494 $qrcodestring = $object->buildSwitzerlandQRString();
498 $qrcodecolor = array(
'25',
'25',
'25');
503 'fgcolor' => $qrcodecolor,
508 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
509 $extra_under_address_shift += 25;
517 'outputlangs' => $outputlangs,
518 'hidedetails' => $hidedetails
520 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
521 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
522 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
525 $tab_top += $extra_under_address_shift;
526 $tab_top_newpage += 0;
529 $height_incoterms = 0;
530 if (isModEnabled(
'incoterm')) {
531 $desc_incoterms = $object->getIncotermsForPDF();
532 if ($desc_incoterms) {
535 $pdf->SetFont(
'',
'', $default_font_size - 1);
536 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
537 $nexY = $pdf->GetY();
538 $height_incoterms = $nexY - $tab_top;
541 $pdf->SetDrawColor(192, 192, 192);
542 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
544 $tab_top = $nexY + 6;
549 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
550 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
552 if (is_object($object->thirdparty)) {
553 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
554 $salerepobj =
new User($this->db);
555 $salerepobj->fetch($salereparray[0][
'id']);
556 if (!empty($salerepobj->signature)) {
557 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
562 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
563 if (!empty($extranote)) {
575 $pdf->SetFont(
'',
'', $default_font_size - 1);
576 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
577 $nexY = $pdf->GetY();
578 $height_note = $nexY - $tab_top;
581 $pdf->SetDrawColor(192, 192, 192);
582 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
584 $tab_top = $nexY + 6;
587 $iniY = $tab_top + 7;
588 $curY = $tab_top + 7;
589 $nexY = $tab_top + 7;
592 for ($i = 0; $i < $nblines; $i++) {
594 $pdf->SetFont(
'',
'', $default_font_size - 1);
595 $pdf->SetTextColor(0, 0, 0);
598 $imglinesize = array();
599 if (!empty($realpatharray[$i])) {
603 $pdf->setTopMargin($tab_top_newpage);
604 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(), $object, $langs);
605 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
606 $pageposbefore = $pdf->getPage();
608 $showpricebeforepagebreak = 1;
610 $posYAfterDescription = 0;
613 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
614 $pdf->AddPage(
'',
'',
true);
615 if (!empty($tplidx)) {
616 $pdf->useTemplate($tplidx);
619 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
620 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
622 $pdf->setPage($pageposbefore + 1);
624 $curY = $tab_top_newpage;
627 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
628 $showpricebeforepagebreak = 1;
630 $showpricebeforepagebreak = 0;
634 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
635 $curX = $this->posxpicture - 1;
636 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
638 $posYAfterImage = $curY + $imglinesize[
'height'];
642 $curX = $this->posxdesc - 1;
644 $pdf->startTransaction();
645 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
646 $pageposafter = $pdf->getPage();
647 if ($pageposafter > $pageposbefore) {
648 $pdf->rollbackTransaction(
true);
649 $pageposafter = $pageposbefore;
651 $pdf->setPageOrientation(
'', 1, $heightforfooter);
652 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
653 $pageposafter = $pdf->getPage();
654 $posyafter = $pdf->GetY();
656 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
657 if ($i == ($nblines - 1)) {
658 $pdf->AddPage(
'',
'',
true);
659 if (!empty($tplidx)) {
660 $pdf->useTemplate($tplidx);
663 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
664 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
666 $pdf->setPage($pageposafter + 1);
672 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
673 $showpricebeforepagebreak = 1;
675 $showpricebeforepagebreak = 0;
680 $pdf->commitTransaction();
682 $posYAfterDescription = $pdf->GetY();
684 $nexY = $pdf->GetY();
685 $pageposafter = $pdf->getPage();
686 $pdf->setPage($pageposbefore);
687 $pdf->setTopMargin($this->marge_haute);
688 $pdf->setPageOrientation(
'', 1, 0);
691 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
692 $pdf->setPage($pageposafter);
693 $curY = $tab_top_newpage;
696 $pdf->SetFont(
'',
'', $default_font_size - 1);
699 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
701 $pdf->SetXY($this->posxtva - 5, $curY);
702 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
707 $pdf->SetXY($this->posxup, $curY);
708 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
712 $pdf->SetXY($this->posxqty, $curY);
713 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
717 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
718 $pdf->SetXY($this->posxunit, $curY);
719 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
723 if ($object->lines[$i]->remise_percent) {
724 $pdf->SetXY($this->posxdiscount - 2, $curY);
726 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
730 if ($this->situationinvoice) {
732 $pdf->SetXY($this->posxprogress, $curY);
733 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0,
'R');
738 $pdf->SetXY($this->postotalht, $curY);
739 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
743 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
747 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
748 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
749 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
750 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
752 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
755 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
756 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
758 $tvaligne = $sign * $object->lines[$i]->total_tva;
762 $localtax1ligne = $object->lines[$i]->total_localtax1;
763 $localtax2ligne = $object->lines[$i]->total_localtax2;
764 $localtax1_rate = $object->lines[$i]->localtax1_tx;
765 $localtax2_rate = $object->lines[$i]->localtax2_tx;
766 $localtax1_type = $object->lines[$i]->localtax1_type;
767 $localtax2_type = $object->lines[$i]->localtax2_type;
780 $vatrate = (string) $object->lines[$i]->tva_tx;
783 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
784 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
786 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
787 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
791 if ($localtax1_type && $localtax1ligne != 0) {
792 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
793 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
795 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
798 if ($localtax2_type && $localtax2ligne != 0) {
799 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
800 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
802 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
806 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
811 if (!isset($this->tva[$vatrate])) {
812 $this->tva[$vatrate] = 0;
814 $this->tva[$vatrate] += $tvaligne;
815 $vatcode = $object->lines[$i]->vat_src_code;
816 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
817 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
819 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
821 if ($posYAfterImage > $posYAfterDescription) {
822 $nexY = $posYAfterImage;
826 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
827 $pdf->setPage($pageposafter);
828 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
830 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
831 $pdf->SetLineStyle(array(
'dash'=>0));
837 while ($pagenb < $pageposafter) {
838 $pdf->setPage($pagenb);
840 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
842 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
846 $pdf->setPage($pagenb);
847 $pdf->setPageOrientation(
'', 1, 0);
849 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
850 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
852 if (!empty($tplidx)) {
853 $pdf->useTemplate($tplidx);
856 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
858 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
860 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
865 if (!empty($tplidx)) {
866 $pdf->useTemplate($tplidx);
870 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
871 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
878 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
879 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
881 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
882 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
884 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
887 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
890 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
893 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
899 if (method_exists($pdf,
'AliasNbPages')) {
900 $pdf->AliasNbPages();
912 $pdf->Output($file,
'F');
915 $hookmanager->initHooks(array(
'pdfgeneration'));
916 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
918 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
920 $this->error = $hookmanager->error;
921 $this->errors = $hookmanager->errors;
926 $this->result = array(
'fullpath'=>$file);
930 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
934 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
958 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
962 $current_page = $pdf->getPage();
964 $tab3_top = $posy + 8;
967 if ($this->page_largeur < 210) {
973 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
977 $pdf->SetFont(
'',
'', $default_font_size - 4);
981 $sql =
"SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
982 $sql .=
" re.description, re.fk_facture_source,";
983 $sql .=
" f.type, f.datef";
984 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
985 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
986 $resql = $this->db->query($sql);
988 $num = $this->db->num_rows($resql);
990 $invoice =
new Facture($this->db);
993 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
996 $pdf->AddPage(
'',
'',
true);
997 if (!empty($tplidx)) {
998 $pdf->useTemplate($tplidx);
1001 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1002 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1004 $pdf->setPage($current_page);
1005 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1008 $obj = $this->db->fetch_object($resql);
1010 if ($obj->type == 2) {
1011 $text = $outputlangs->transnoentities(
"CreditNote");
1012 } elseif ($obj->type == 3) {
1013 $text = $outputlangs->transnoentities(
"Deposit");
1014 } elseif ($obj->type == 0) {
1015 $text = $outputlangs->transnoentities(
"ExcessReceived");
1017 $text = $outputlangs->transnoentities(
"UnknownType");
1020 $invoice->fetch($obj->fk_facture_source);
1022 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1023 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1024 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1025 $pdf->MultiCell(20, 3,
price((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1026 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1027 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1028 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1029 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1031 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1036 $this->error = $this->db->lasterror();
1042 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1044 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1045 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1046 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1048 $sql .=
" ORDER BY p.datep";
1050 $resql = $this->db->query($sql);
1052 $num = $this->db->num_rows($resql);
1056 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1059 $pdf->AddPage(
'',
'',
true);
1060 if (!empty($tplidx)) {
1061 $pdf->useTemplate($tplidx);
1064 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1065 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1067 $pdf->setPage($current_page);
1068 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1071 $row = $this->db->fetch_object($resql);
1073 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1074 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1075 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1076 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1077 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1078 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1080 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1081 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1082 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1084 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1089 return $tab3_top + $y + 3;
1091 $this->error = $this->db->lasterror();
1150 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1153 global $conf, $mysoc;
1157 $pdf->SetFont(
'',
'', $default_font_size - 1);
1160 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1161 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1162 $pdf->SetXY($this->marge_gauche, $posy);
1163 if ($mysoc->forme_juridique_code == 92) {
1164 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1166 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1169 $posy = $pdf->GetY() + 4;
1174 if ($this->page_largeur < 210) {
1179 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1180 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1181 $pdf->SetXY($this->marge_gauche, $posy);
1182 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1183 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1185 $pdf->SetFont(
'',
'', $default_font_size - 2);
1186 $pdf->SetXY($posxval, $posy);
1187 $lib_condition_paiement = $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) != (
'PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
1188 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1189 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1191 $posy = $pdf->GetY() + 3;
1195 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1196 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1197 $pdf->SetXY($this->marge_gauche, $posy);
1198 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1199 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1201 $pdf->SetFont(
'',
'', $default_font_size - 2);
1202 $pdf->SetXY($posxval, $posy);
1203 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1204 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1206 $posy = $pdf->GetY() + 3;
1209 if ($object->type != 2) {
1211 if (empty($object->mode_reglement_code)
1214 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1215 } elseif (($object->mode_reglement_code ==
'CHQ' && !
getDolGlobalInt(
'FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1216 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1218 $outputlangs->load(
"errors");
1220 $pdf->SetXY($this->marge_gauche, $posy);
1221 $pdf->SetTextColor(200, 0, 0);
1222 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1223 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1224 $pdf->MultiCell(80, 3, $this->error, 0,
'L', 0);
1225 $pdf->SetTextColor(0, 0, 0);
1227 $posy = $pdf->GetY() + 1;
1231 if (!empty($object->mode_reglement_code)
1232 && $object->mode_reglement_code !=
'CHQ'
1233 && $object->mode_reglement_code !=
'VIR') {
1234 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1235 $pdf->SetXY($this->marge_gauche, $posy);
1236 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1237 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1239 $pdf->SetFont(
'',
'', $default_font_size - 2);
1240 $pdf->SetXY($posxval, $posy);
1241 $lib_mode_reg = $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) != (
'PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1243 if ($object->mode_reglement_code ==
"PRE") {
1244 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1246 $bac->fetch(0, $object->thirdparty->id);
1247 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1248 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1250 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1252 $posy = $pdf->GetY();
1258 if ($this->emetteur->country_code ==
'FR') {
1259 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1260 $pdf->SetXY($this->marge_gauche, $posy);
1261 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1263 $posy = $pdf->GetY() + 1;
1268 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1269 $useonlinepayment = 0;
1270 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1271 if (isModEnabled(
'paypal')) {
1272 $useonlinepayment++;
1274 if (isModEnabled(
'stripe')) {
1275 $useonlinepayment++;
1277 if (isModEnabled(
'paybox')) {
1278 $useonlinepayment++;
1283 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1286 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1287 $servicename = $langs->transnoentities(
'Online');
1288 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1289 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1291 $pdf->SetXY($this->marge_gauche, $posy);
1294 $posy = $pdf->GetY() + 1;
1299 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1302 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1304 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1305 $account =
new Account($this->db);
1308 $pdf->SetXY($this->marge_gauche, $posy);
1309 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1310 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1311 $posy = $pdf->GetY() + 1;
1313 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1314 $pdf->SetXY($this->marge_gauche, $posy);
1315 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1316 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1317 $posy = $pdf->GetY() + 2;
1320 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1321 $pdf->SetXY($this->marge_gauche, $posy);
1322 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1323 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1324 $posy = $pdf->GetY() + 1;
1326 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1327 $pdf->SetXY($this->marge_gauche, $posy);
1328 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1329 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1330 $posy = $pdf->GetY() + 2;
1337 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1338 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1339 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1340 if ($object->fk_bank > 0) {
1341 $bankid = $object->fk_bank;
1343 $account =
new Account($this->db);
1344 $account->fetch($bankid);
1346 $curx = $this->marge_gauche;
1349 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1373 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1376 global $conf, $mysoc, $hookmanager;
1379 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1385 $outputlangsbis =
null;
1386 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1387 $outputlangsbis =
new Translate(
'', $conf);
1388 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1389 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1390 $default_font_size--;
1395 $pdf->SetFont(
'',
'', $default_font_size - 1);
1400 if ($this->page_largeur < 210) {
1404 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1410 $pdf->SetFillColor(255, 255, 255);
1411 $pdf->SetXY($col1x, $tab2_top);
1412 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total") :
''), 0,
'L', 1);
1414 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1415 $pdf->SetXY($col2x, $tab2_top);
1416 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1419 $pdf->SetFillColor(248, 248, 248);
1421 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1423 $this->atleastoneratenotnull = 0;
1424 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1425 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1426 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1432 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1433 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1437 foreach ($localtax_rate as $tvakey => $tvaval) {
1442 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1445 if (preg_match(
'/\*/', $tvakey)) {
1446 $tvakey = str_replace(
'*',
'', $tvakey);
1447 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1450 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1452 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1453 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1455 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1457 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1458 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1466 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1467 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1471 foreach ($localtax_rate as $tvakey => $tvaval) {
1476 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1479 if (preg_match(
'/\*/', $tvakey)) {
1480 $tvakey = str_replace(
'*',
'', $tvakey);
1481 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1483 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1485 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1486 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1488 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1490 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1491 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1499 foreach ($this->tva_array as $tvakey => $tvaval) {
1501 $this->atleastoneratenotnull++;
1504 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1507 if (preg_match(
'/\*/', $tvakey)) {
1508 $tvakey = str_replace(
'*',
'', $tvakey);
1509 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1511 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1514 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1516 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1518 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1520 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1522 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1523 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1530 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1531 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1535 foreach ($localtax_rate as $tvakey => $tvaval) {
1540 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1543 if (preg_match(
'/\*/', $tvakey)) {
1544 $tvakey = str_replace(
'*',
'', $tvakey);
1545 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1547 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1548 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1550 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1552 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1554 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1555 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1563 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1564 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1568 foreach ($localtax_rate as $tvakey => $tvaval) {
1572 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1575 if (preg_match(
'/\*/', $tvakey)) {
1576 $tvakey = str_replace(
'*',
'', $tvakey);
1577 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1579 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1581 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1582 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1584 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1586 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1587 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1593 if (
price2num($object->revenuestamp) != 0) {
1595 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1596 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L', 1);
1598 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1599 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1604 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1605 $pdf->SetTextColor(0, 0, 60);
1606 $pdf->SetFillColor(224, 224, 224);
1607 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1609 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1610 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1613 if ($object->displayRetainedWarranty()) {
1614 $pdf->SetTextColor(40, 40, 40);
1615 $pdf->SetFillColor(255, 255, 255);
1617 $retainedWarranty = $object->getRetainedWarrantyAmount();
1618 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1622 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1623 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1625 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1626 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1630 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1632 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
1633 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1635 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1636 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1637 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1642 $pdf->SetTextColor(0, 0, 0);
1643 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1644 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1646 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1647 if (!empty($object->paye)) {
1651 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
1656 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1657 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1660 if ($creditnoteamount) {
1661 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1663 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1664 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1665 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1666 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1670 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1672 $pdf->SetFillColor(255, 255, 255);
1674 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1675 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
1676 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1677 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
1683 $pdf->SetTextColor(0, 0, 60);
1684 $pdf->SetFillColor(224, 224, 224);
1685 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1687 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1688 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1690 $pdf->SetFont(
'',
'', $default_font_size - 1);
1691 $pdf->SetTextColor(0, 0, 0);
1695 return ($tab2_top + ($tab2_hl * $index));
1712 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1722 $currency = !empty($currency) ? $currency : $conf->currency;
1726 $pdf->SetTextColor(0, 0, 0);
1727 $pdf->SetFont(
'',
'', $default_font_size - 2);
1729 if (empty($hidetop)) {
1731 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1732 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1733 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1734 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1737 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1738 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1739 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1742 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1743 $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));
1747 $pdf->SetDrawColor(128, 128, 128);
1748 $pdf->SetFont(
'',
'', $default_font_size - 1);
1751 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1753 if (empty($hidetop)) {
1754 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1756 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1757 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1760 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1761 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1762 if (empty($hidetop)) {
1768 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1769 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1770 if (empty($hidetop)) {
1771 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1772 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1776 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1777 if (empty($hidetop)) {
1778 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1779 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1782 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1783 if (empty($hidetop)) {
1784 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1785 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1789 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1790 if (empty($hidetop)) {
1791 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1792 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1796 if ($this->atleastonediscount) {
1797 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1798 if (empty($hidetop)) {
1799 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1800 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1804 if ($this->situationinvoice) {
1805 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1806 if (empty($hidetop)) {
1807 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1808 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
1812 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1813 if (empty($hidetop)) {
1814 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1815 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1830 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1832 global $conf, $langs;
1834 $ltrdirection =
'L';
1835 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1838 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1844 $pdf->SetTextColor(0, 0, 60);
1845 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1849 $posy = $this->marge_haute;
1850 $posx = $this->page_largeur - $this->marge_droite - $w;
1852 $pdf->SetXY($this->marge_gauche, $posy);
1856 if ($this->emetteur->logo) {
1857 $logodir = $conf->mycompany->dir_output;
1858 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1859 $logodir = $conf->mycompany->multidir_output[$object->entity];
1862 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1864 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1866 if (is_readable($logo)) {
1868 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1870 $pdf->SetTextColor(200, 0, 0);
1871 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1872 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1873 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1876 $text = $this->emetteur->name;
1877 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1881 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1882 $pdf->SetXY($posx, $posy);
1883 $pdf->SetTextColor(0, 0, 60);
1884 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1885 if ($object->type == 1) {
1886 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1888 if ($object->type == 2) {
1889 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1891 if ($object->type == 3) {
1892 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1894 if ($object->type == 4) {
1895 $title = $outputlangs->transnoentities(
"InvoiceProForma");
1897 if ($this->situationinvoice) {
1898 $langs->loadLangs(array(
"other"));
1899 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") . $object->situation_counter .
" -";
1901 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1903 if ($object->type == 0) {
1904 if ($this->situationinvoice) {
1905 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
1907 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
1908 } elseif ($object->type == 1) {
1909 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
1910 } elseif ($object->type == 2) {
1911 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
1912 } elseif ($object->type == 3) {
1913 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
1914 } elseif ($object->type == 4) {
1915 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
1918 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1919 if ($object->statut == $object::STATUS_DRAFT) {
1920 $pdf->SetTextColor(128, 0, 0);
1921 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1924 $pdf->MultiCell($w, 3, $title,
'',
'R');
1926 $pdf->SetFont(
'',
'B', $default_font_size);
1940 $pdf->SetFont(
'',
'', $default_font_size - 2);
1942 if ($object->ref_customer) {
1944 $pdf->SetXY($posx, $posy);
1945 $pdf->SetTextColor(0, 0, 60);
1946 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_customer),
'',
'R');
1949 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1950 $object->fetch_projet();
1951 if (!empty($object->project->ref)) {
1953 $pdf->SetXY($posx, $posy);
1954 $pdf->SetTextColor(0, 0, 60);
1955 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1959 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1960 $object->fetch_projet();
1961 if (!empty($object->project->ref)) {
1962 $outputlangs->load(
"projects");
1964 $pdf->SetXY($posx, $posy);
1965 $pdf->SetTextColor(0, 0, 60);
1966 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1970 $objectidnext = $object->getIdReplacingInvoice(
'validated');
1971 if ($object->type == 0 && $objectidnext) {
1972 $objectreplacing =
new Facture($this->db);
1973 $objectreplacing->fetch($objectidnext);
1976 $pdf->SetXY($posx, $posy);
1977 $pdf->SetTextColor(0, 0, 60);
1978 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
1980 if ($object->type == 1) {
1981 $objectreplaced =
new Facture($this->db);
1982 $objectreplaced->fetch($object->fk_facture_source);
1985 $pdf->SetXY($posx, $posy);
1986 $pdf->SetTextColor(0, 0, 60);
1987 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1989 if ($object->type == 2 && !empty($object->fk_facture_source)) {
1990 $objectreplaced =
new Facture($this->db);
1991 $objectreplaced->fetch($object->fk_facture_source);
1994 $pdf->SetXY($posx, $posy);
1995 $pdf->SetTextColor(0, 0, 60);
1996 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2000 $pdf->SetXY($posx, $posy);
2001 $pdf->SetTextColor(0, 0, 60);
2002 $title = $outputlangs->transnoentities(
"DateInvoice");
2003 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2004 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2006 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2008 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2010 $pdf->SetXY($posx, $posy);
2011 $pdf->SetTextColor(0, 0, 60);
2012 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2015 if ($object->type != 2) {
2017 $pdf->SetXY($posx, $posy);
2018 $pdf->SetTextColor(0, 0, 60);
2019 $title = $outputlangs->transnoentities(
"DateDue");
2020 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2021 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2023 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2026 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2028 $pdf->SetXY($posx, $posy);
2029 $pdf->SetTextColor(0, 0, 60);
2030 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2034 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2035 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2036 if (count($arrayidcontact) > 0) {
2037 $usertmp =
new User($this->db);
2038 $usertmp->fetch($arrayidcontact[0]);
2040 $pdf->SetXY($posx, $posy);
2041 $pdf->SetTextColor(0, 0, 60);
2042 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2050 $current_y = $pdf->getY();
2051 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2052 if ($current_y < $pdf->getY()) {
2053 $top_shift = $pdf->getY() - $current_y;
2058 $carac_emetteur =
'';
2060 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
2061 if (count($arrayidcontact) > 0) {
2062 $object->fetch_user($arrayidcontact[0]);
2063 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2064 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2065 $carac_emetteur .=
"\n";
2068 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2071 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2072 $posy += $top_shift;
2073 $posx = $this->marge_gauche;
2074 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2075 $posx = $this->page_largeur - $this->marge_droite - 80;
2078 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2079 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2083 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2084 $pdf->SetTextColor(0, 0, 0);
2085 $pdf->SetFont(
'',
'', $default_font_size - 2);
2086 $pdf->SetXY($posx, $posy - 5);
2087 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2088 $pdf->SetXY($posx, $posy);
2089 $pdf->SetFillColor(230, 230, 230);
2090 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2091 $pdf->SetTextColor(0, 0, 60);
2095 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2096 $pdf->SetXY($posx + 2, $posy + 3);
2097 $pdf->SetFont(
'',
'B', $default_font_size);
2098 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2099 $posy = $pdf->getY();
2103 $pdf->SetXY($posx + 2, $posy);
2104 $pdf->SetFont(
'',
'', $default_font_size - 1);
2105 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2109 $usecontact =
false;
2110 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2111 if (count($arrayidcontact) > 0) {
2113 $result = $object->fetch_contact($arrayidcontact[0]);
2117 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)))) {
2118 $thirdparty = $object->contact;
2120 $thirdparty = $object->thirdparty;
2126 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2129 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2130 if ($this->page_largeur < 210) {
2133 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2134 $posy += $top_shift;
2135 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2136 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2137 $posx = $this->marge_gauche;
2141 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2142 $pdf->SetTextColor(0, 0, 0);
2143 $pdf->SetFont(
'',
'', $default_font_size - 2);
2144 $pdf->SetXY($posx + 2, $posy - 5);
2145 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2146 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2150 $pdf->SetXY($posx + 2, $posy + 3);
2151 $pdf->SetFont(
'',
'B', $default_font_size);
2152 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2154 $posy = $pdf->getY();
2157 $pdf->SetFont(
'',
'', $default_font_size - 1);
2158 $pdf->SetXY($posx + 2, $posy);
2159 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2163 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2165 if (!empty($idaddressshipping)) {
2166 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2167 $companystatic =
new Societe($this->db);
2168 $companystatic->fetch($object->contact->fk_soc);
2170 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2173 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2175 if (!empty($carac_client_shipping)) {
2176 $posy += $hautcadre;
2179 $pdf->SetXY($posx + 2, $posy - 5);
2180 $pdf->SetFont(
'',
'', $default_font_size - 2);
2181 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2182 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2185 $pdf->SetXY($posx + 2, $posy + 3);
2186 $pdf->SetFont(
'',
'B', $default_font_size);
2187 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2189 $posy = $pdf->getY();
2192 $pdf->SetXY($posx+2, $posy);
2193 $pdf->SetFont(
'',
'', $default_font_size - 1);
2194 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2195 $top_shift += $hautcadre;
2200 $pdf->SetTextColor(0, 0, 0);