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++;
424 if (preg_match(
'/^\((.*)\)$/', $object->lines[$i]->desc, $reg)) {
425 if ($reg[1] ==
'DEPOSIT') {
436 if ($categoryOfOperation < 2) {
437 $lineProductType = $object->lines[$i]->product_type;
443 if ($nbProduct > 0 && $nbService > 0) {
445 $categoryOfOperation = 2;
450 if ($categoryOfOperation <= 0) {
452 if ($nbProduct == 0 && $nbService > 0) {
453 $categoryOfOperation = 1;
456 $this->categoryOfOperation = $categoryOfOperation;
457 if (empty($this->atleastonediscount)) {
458 $delta = ($this->posxprogress - $this->posxdiscount);
459 $this->posxpicture += $delta;
460 $this->posxtva += $delta;
461 $this->posxup += $delta;
462 $this->posxqty += $delta;
463 $this->posxunit += $delta;
464 $this->posxdiscount += $delta;
470 if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
471 $this->situationinvoice =
true;
472 $progress_width = 10;
473 $this->posxpicture -= $progress_width;
474 $this->posxtva -= $progress_width;
475 $this->posxup -= $progress_width;
476 $this->posxqty -= $progress_width;
477 $this->posxunit -= $progress_width;
478 $this->posxdiscount -= $progress_width;
479 $this->posxprogress -= $progress_width;
484 if (!empty($tplidx)) {
485 $pdf->useTemplate($tplidx);
490 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
491 $pdf->SetFont(
'',
'', $default_font_size - 1);
492 $pdf->MultiCell(0, 3,
'');
493 $pdf->SetTextColor(0, 0, 0);
498 $tab_top = 90 + $top_shift;
499 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
502 $extra_under_address_shift = 0;
504 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
505 $qrcodestring = $object->buildZATCAQRString();
507 $qrcodestring = $object->buildSwitzerlandQRString();
511 $qrcodecolor = array(
'25',
'25',
'25');
516 'fgcolor' => $qrcodecolor,
521 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
522 $extra_under_address_shift += 25;
530 'outputlangs' => $outputlangs,
531 'hidedetails' => $hidedetails
533 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
534 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
535 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
538 $tab_top += $extra_under_address_shift;
539 $tab_top_newpage += 0;
542 $height_incoterms = 0;
543 if (isModEnabled(
'incoterm')) {
544 $desc_incoterms = $object->getIncotermsForPDF();
545 if ($desc_incoterms) {
548 $pdf->SetFont(
'',
'', $default_font_size - 1);
549 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
550 $nexY = $pdf->GetY();
551 $height_incoterms = $nexY - $tab_top;
554 $pdf->SetDrawColor(192, 192, 192);
555 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
557 $tab_top = $nexY + 6;
562 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
563 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
565 if (is_object($object->thirdparty)) {
566 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
567 $salerepobj =
new User($this->db);
568 $salerepobj->fetch($salereparray[0][
'id']);
569 if (!empty($salerepobj->signature)) {
570 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
575 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
576 if (!empty($extranote)) {
588 $pdf->SetFont(
'',
'', $default_font_size - 1);
589 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
590 $nexY = $pdf->GetY();
591 $height_note = $nexY - $tab_top;
594 $pdf->SetDrawColor(192, 192, 192);
595 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
597 $tab_top = $nexY + 6;
600 $iniY = $tab_top + 7;
601 $curY = $tab_top + 7;
602 $nexY = $tab_top + 7;
605 for ($i = 0; $i < $nblines; $i++) {
607 $pdf->SetFont(
'',
'', $default_font_size - 1);
608 $pdf->SetTextColor(0, 0, 0);
611 $imglinesize = array();
612 if (!empty($realpatharray[$i])) {
616 $pdf->setTopMargin($tab_top_newpage);
617 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(), $object, $langs);
618 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
619 $pageposbefore = $pdf->getPage();
621 $showpricebeforepagebreak = 1;
623 $posYAfterDescription = 0;
626 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
627 $pdf->AddPage(
'',
'',
true);
628 if (!empty($tplidx)) {
629 $pdf->useTemplate($tplidx);
632 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
633 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
635 $pdf->setPage($pageposbefore + 1);
637 $curY = $tab_top_newpage;
640 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
641 $showpricebeforepagebreak = 1;
643 $showpricebeforepagebreak = 0;
647 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
648 $curX = $this->posxpicture - 1;
649 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
651 $posYAfterImage = $curY + $imglinesize[
'height'];
655 $curX = $this->posxdesc - 1;
657 $pdf->startTransaction();
658 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
659 $pageposafter = $pdf->getPage();
660 if ($pageposafter > $pageposbefore) {
661 $pdf->rollbackTransaction(
true);
662 $pageposafter = $pageposbefore;
664 $pdf->setPageOrientation(
'', 1, $heightforfooter);
665 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
666 $pageposafter = $pdf->getPage();
667 $posyafter = $pdf->GetY();
669 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
670 if ($i == ($nblines - 1)) {
671 $pdf->AddPage(
'',
'',
true);
672 if (!empty($tplidx)) {
673 $pdf->useTemplate($tplidx);
676 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
677 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
679 $pdf->setPage($pageposafter + 1);
685 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
686 $showpricebeforepagebreak = 1;
688 $showpricebeforepagebreak = 0;
693 $pdf->commitTransaction();
695 $posYAfterDescription = $pdf->GetY();
697 $nexY = $pdf->GetY();
698 $pageposafter = $pdf->getPage();
699 $pdf->setPage($pageposbefore);
700 $pdf->setTopMargin($this->marge_haute);
701 $pdf->setPageOrientation(
'', 1, 0);
704 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
705 $pdf->setPage($pageposafter);
706 $curY = $tab_top_newpage;
709 $pdf->SetFont(
'',
'', $default_font_size - 1);
712 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
714 $pdf->SetXY($this->posxtva - 5, $curY);
715 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
720 $pdf->SetXY($this->posxup, $curY);
721 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
725 $pdf->SetXY($this->posxqty, $curY);
726 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
730 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
731 $pdf->SetXY($this->posxunit, $curY);
732 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
736 if ($object->lines[$i]->remise_percent) {
737 $pdf->SetXY($this->posxdiscount - 2, $curY);
739 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
743 if ($this->situationinvoice) {
745 $pdf->SetXY($this->posxprogress, $curY);
746 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0,
'R');
751 $pdf->SetXY($this->postotalht, $curY);
752 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
756 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
760 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
761 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
762 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
763 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
765 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
768 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
769 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
771 $tvaligne = $sign * $object->lines[$i]->total_tva;
775 $localtax1ligne = $object->lines[$i]->total_localtax1;
776 $localtax2ligne = $object->lines[$i]->total_localtax2;
777 $localtax1_rate = $object->lines[$i]->localtax1_tx;
778 $localtax2_rate = $object->lines[$i]->localtax2_tx;
779 $localtax1_type = $object->lines[$i]->localtax1_type;
780 $localtax2_type = $object->lines[$i]->localtax2_type;
793 $vatrate = (string) $object->lines[$i]->tva_tx;
796 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
797 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
799 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
800 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
804 if ($localtax1_type && $localtax1ligne != 0) {
805 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
806 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
808 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
811 if ($localtax2_type && $localtax2ligne != 0) {
812 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
813 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
815 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
819 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
824 if (!isset($this->tva[$vatrate])) {
825 $this->tva[$vatrate] = 0;
827 $this->tva[$vatrate] += $tvaligne;
828 $vatcode = $object->lines[$i]->vat_src_code;
829 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
830 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
832 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
834 if ($posYAfterImage > $posYAfterDescription) {
835 $nexY = $posYAfterImage;
839 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
840 $pdf->setPage($pageposafter);
841 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
843 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
844 $pdf->SetLineStyle(array(
'dash'=>0));
850 while ($pagenb < $pageposafter) {
851 $pdf->setPage($pagenb);
853 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
855 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
859 $pdf->setPage($pagenb);
860 $pdf->setPageOrientation(
'', 1, 0);
862 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
863 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
865 if (!empty($tplidx)) {
866 $pdf->useTemplate($tplidx);
869 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
871 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code);
873 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
878 if (!empty($tplidx)) {
879 $pdf->useTemplate($tplidx);
883 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
884 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
891 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code);
892 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
894 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
895 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
897 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
900 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
903 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
906 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
912 if (method_exists($pdf,
'AliasNbPages')) {
913 $pdf->AliasNbPages();
925 $pdf->Output($file,
'F');
928 $hookmanager->initHooks(array(
'pdfgeneration'));
929 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
931 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
933 $this->error = $hookmanager->error;
934 $this->errors = $hookmanager->errors;
939 $this->result = array(
'fullpath'=>$file);
943 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
947 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
971 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
975 $current_page = $pdf->getPage();
977 $tab3_top = $posy + 8;
980 if ($this->page_largeur < 210) {
986 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
990 $pdf->SetFont(
'',
'', $default_font_size - 4);
994 $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,";
995 $sql .=
" re.description, re.fk_facture_source,";
996 $sql .=
" f.type, f.datef";
997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
998 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
999 $resql = $this->db->query($sql);
1001 $num = $this->db->num_rows($resql);
1003 $invoice =
new Facture($this->db);
1006 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1009 $pdf->AddPage(
'',
'',
true);
1010 if (!empty($tplidx)) {
1011 $pdf->useTemplate($tplidx);
1014 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1015 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1017 $pdf->setPage($current_page);
1018 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1021 $obj = $this->db->fetch_object($resql);
1023 if ($obj->type == 2) {
1024 $text = $outputlangs->transnoentities(
"CreditNote");
1025 } elseif ($obj->type == 3) {
1026 $text = $outputlangs->transnoentities(
"Deposit");
1027 } elseif ($obj->type == 0) {
1028 $text = $outputlangs->transnoentities(
"ExcessReceived");
1030 $text = $outputlangs->transnoentities(
"UnknownType");
1033 $invoice->fetch($obj->fk_facture_source);
1035 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1036 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1037 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1038 $pdf->MultiCell(20, 3,
price((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1039 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1040 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1041 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1042 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1044 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1049 $this->error = $this->db->lasterror();
1055 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1057 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1058 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1059 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1061 $sql .=
" ORDER BY p.datep";
1063 $resql = $this->db->query($sql);
1065 $num = $this->db->num_rows($resql);
1069 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1072 $pdf->AddPage(
'',
'',
true);
1073 if (!empty($tplidx)) {
1074 $pdf->useTemplate($tplidx);
1077 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1078 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1080 $pdf->setPage($current_page);
1081 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1084 $row = $this->db->fetch_object($resql);
1086 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1087 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1088 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1089 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1090 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1091 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1093 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1094 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1095 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1097 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1102 return $tab3_top + $y + 3;
1104 $this->error = $this->db->lasterror();
1163 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1166 global $conf, $mysoc;
1170 $pdf->SetFont(
'',
'', $default_font_size - 1);
1173 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1174 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1175 $pdf->SetXY($this->marge_gauche, $posy);
1176 if ($mysoc->forme_juridique_code == 92) {
1177 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1179 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1182 $posy = $pdf->GetY() + 4;
1187 if ($this->page_largeur < 210) {
1192 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1193 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1194 $pdf->SetXY($this->marge_gauche, $posy);
1195 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1196 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1198 $pdf->SetFont(
'',
'', $default_font_size - 2);
1199 $pdf->SetXY($posxval, $posy);
1200 $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);
1201 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1202 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1204 $posy = $pdf->GetY() + 3;
1208 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1209 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1210 $pdf->SetXY($this->marge_gauche, $posy);
1211 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1212 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1214 $pdf->SetFont(
'',
'', $default_font_size - 2);
1215 $pdf->SetXY($posxval, $posy);
1216 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1217 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1219 $posy = $pdf->GetY() + 3;
1222 if ($object->type != 2) {
1224 if (empty($object->mode_reglement_code)
1227 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1228 } elseif (($object->mode_reglement_code ==
'CHQ' && !
getDolGlobalInt(
'FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1229 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1231 $outputlangs->load(
"errors");
1233 $pdf->SetXY($this->marge_gauche, $posy);
1234 $pdf->SetTextColor(200, 0, 0);
1235 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1236 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1237 $pdf->MultiCell(80, 3, $this->error, 0,
'L', 0);
1238 $pdf->SetTextColor(0, 0, 0);
1240 $posy = $pdf->GetY() + 1;
1244 if (!empty($object->mode_reglement_code)
1245 && $object->mode_reglement_code !=
'CHQ'
1246 && $object->mode_reglement_code !=
'VIR') {
1247 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1248 $pdf->SetXY($this->marge_gauche, $posy);
1249 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1250 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1252 $pdf->SetFont(
'',
'', $default_font_size - 2);
1253 $pdf->SetXY($posxval, $posy);
1254 $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);
1256 if ($object->mode_reglement_code ==
"PRE") {
1257 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1259 $bac->fetch(0, $object->thirdparty->id);
1260 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1261 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1263 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1265 $posy = $pdf->GetY();
1271 if ($this->emetteur->country_code ==
'FR') {
1272 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1273 $pdf->SetXY($this->marge_gauche, $posy);
1274 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1276 $posy = $pdf->GetY() + 1;
1281 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1282 $useonlinepayment = 0;
1283 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1284 if (isModEnabled(
'paypal')) {
1285 $useonlinepayment++;
1287 if (isModEnabled(
'stripe')) {
1288 $useonlinepayment++;
1290 if (isModEnabled(
'paybox')) {
1291 $useonlinepayment++;
1296 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1299 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1300 $servicename = $langs->transnoentities(
'Online');
1301 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1302 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1304 $pdf->SetXY($this->marge_gauche, $posy);
1307 $posy = $pdf->GetY() + 1;
1312 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1315 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1317 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1318 $account =
new Account($this->db);
1321 $pdf->SetXY($this->marge_gauche, $posy);
1322 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1323 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 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($account->owner_address), 0,
'L', 0);
1330 $posy = $pdf->GetY() + 2;
1333 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1334 $pdf->SetXY($this->marge_gauche, $posy);
1335 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1336 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1337 $posy = $pdf->GetY() + 1;
1339 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1340 $pdf->SetXY($this->marge_gauche, $posy);
1341 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1342 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1343 $posy = $pdf->GetY() + 2;
1350 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1351 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1352 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1353 if ($object->fk_bank > 0) {
1354 $bankid = $object->fk_bank;
1356 $account =
new Account($this->db);
1357 $account->fetch($bankid);
1359 $curx = $this->marge_gauche;
1362 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1386 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1389 global $conf, $mysoc, $hookmanager;
1392 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1398 $outputlangsbis =
null;
1399 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1400 $outputlangsbis =
new Translate(
'', $conf);
1401 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1402 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1403 $default_font_size--;
1408 $pdf->SetFont(
'',
'', $default_font_size - 1);
1413 if ($this->page_largeur < 210) {
1417 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1423 $pdf->SetFillColor(255, 255, 255);
1424 $pdf->SetXY($col1x, $tab2_top);
1425 $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);
1427 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1428 $pdf->SetXY($col2x, $tab2_top);
1429 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1432 $pdf->SetFillColor(248, 248, 248);
1434 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1436 $this->atleastoneratenotnull = 0;
1437 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1438 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1439 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1445 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1446 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1450 foreach ($localtax_rate as $tvakey => $tvaval) {
1455 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1458 if (preg_match(
'/\*/', $tvakey)) {
1459 $tvakey = str_replace(
'*',
'', $tvakey);
1460 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1463 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1465 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1466 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1468 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1470 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1471 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1479 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1480 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1484 foreach ($localtax_rate as $tvakey => $tvaval) {
1489 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1492 if (preg_match(
'/\*/', $tvakey)) {
1493 $tvakey = str_replace(
'*',
'', $tvakey);
1494 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1496 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1498 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1499 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1501 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1503 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1504 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1512 foreach ($this->tva_array as $tvakey => $tvaval) {
1514 $this->atleastoneratenotnull++;
1517 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1520 if (preg_match(
'/\*/', $tvakey)) {
1521 $tvakey = str_replace(
'*',
'', $tvakey);
1522 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1524 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1527 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1529 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1531 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1533 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1535 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1536 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1543 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1544 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1548 foreach ($localtax_rate as $tvakey => $tvaval) {
1553 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1556 if (preg_match(
'/\*/', $tvakey)) {
1557 $tvakey = str_replace(
'*',
'', $tvakey);
1558 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1560 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1561 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1563 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1565 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1567 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1568 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1576 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1577 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1581 foreach ($localtax_rate as $tvakey => $tvaval) {
1585 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1588 if (preg_match(
'/\*/', $tvakey)) {
1589 $tvakey = str_replace(
'*',
'', $tvakey);
1590 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1592 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1594 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1595 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1597 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1599 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1600 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1606 if (
price2num($object->revenuestamp) != 0) {
1608 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1609 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L', 1);
1611 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1612 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1617 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1618 $pdf->SetTextColor(0, 0, 60);
1619 $pdf->SetFillColor(224, 224, 224);
1620 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1622 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1623 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1626 if ($object->displayRetainedWarranty()) {
1627 $pdf->SetTextColor(40, 40, 40);
1628 $pdf->SetFillColor(255, 255, 255);
1630 $retainedWarranty = $object->getRetainedWarrantyAmount();
1631 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1635 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1636 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1638 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1639 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1643 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1645 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
1646 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1648 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1649 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1650 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1655 $pdf->SetTextColor(0, 0, 0);
1656 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1657 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1659 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1660 if (!empty($object->paye)) {
1664 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1667 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1668 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
1669 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1670 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1673 if ($creditnoteamount) {
1674 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1676 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1677 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1678 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1679 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1683 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1685 $pdf->SetFillColor(255, 255, 255);
1687 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1688 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
1689 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1690 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
1696 $pdf->SetTextColor(0, 0, 60);
1697 $pdf->SetFillColor(224, 224, 224);
1698 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1699 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1700 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1701 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1703 $pdf->SetFont(
'',
'', $default_font_size - 1);
1704 $pdf->SetTextColor(0, 0, 0);
1708 return ($tab2_top + ($tab2_hl * $index));
1725 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1735 $currency = !empty($currency) ? $currency : $conf->currency;
1739 $pdf->SetTextColor(0, 0, 0);
1740 $pdf->SetFont(
'',
'', $default_font_size - 2);
1742 if (empty($hidetop)) {
1744 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1745 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1746 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1747 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1750 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1751 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1752 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1755 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1756 $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));
1760 $pdf->SetDrawColor(128, 128, 128);
1761 $pdf->SetFont(
'',
'', $default_font_size - 1);
1764 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1766 if (empty($hidetop)) {
1767 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1769 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1770 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1773 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1774 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1775 if (empty($hidetop)) {
1781 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1782 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1783 if (empty($hidetop)) {
1784 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1785 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1789 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1790 if (empty($hidetop)) {
1791 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1792 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1795 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1796 if (empty($hidetop)) {
1797 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1798 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1802 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1803 if (empty($hidetop)) {
1804 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1805 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1809 if ($this->atleastonediscount) {
1810 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1811 if (empty($hidetop)) {
1812 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1813 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1817 if ($this->situationinvoice) {
1818 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1819 if (empty($hidetop)) {
1820 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1821 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
1825 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1826 if (empty($hidetop)) {
1827 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1828 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1843 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1845 global $conf, $langs;
1847 $ltrdirection =
'L';
1848 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1851 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1857 $pdf->SetTextColor(0, 0, 60);
1858 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1862 $posy = $this->marge_haute;
1863 $posx = $this->page_largeur - $this->marge_droite - $w;
1865 $pdf->SetXY($this->marge_gauche, $posy);
1869 if ($this->emetteur->logo) {
1870 $logodir = $conf->mycompany->dir_output;
1871 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1872 $logodir = $conf->mycompany->multidir_output[$object->entity];
1875 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1877 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1879 if (is_readable($logo)) {
1881 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1883 $pdf->SetTextColor(200, 0, 0);
1884 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1885 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1886 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1889 $text = $this->emetteur->name;
1890 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1894 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1895 $pdf->SetXY($posx, $posy);
1896 $pdf->SetTextColor(0, 0, 60);
1897 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1898 if ($object->type == 1) {
1899 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1901 if ($object->type == 2) {
1902 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1904 if ($object->type == 3) {
1905 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1907 if ($object->type == 4) {
1908 $title = $outputlangs->transnoentities(
"InvoiceProForma");
1910 if ($this->situationinvoice) {
1911 $langs->loadLangs(array(
"other"));
1912 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") . $object->situation_counter .
" -";
1914 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1916 if ($object->type == 0) {
1917 if ($this->situationinvoice) {
1918 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
1920 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
1921 } elseif ($object->type == 1) {
1922 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
1923 } elseif ($object->type == 2) {
1924 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
1925 } elseif ($object->type == 3) {
1926 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
1927 } elseif ($object->type == 4) {
1928 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
1931 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1932 if ($object->statut == $object::STATUS_DRAFT) {
1933 $pdf->SetTextColor(128, 0, 0);
1934 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1937 $pdf->MultiCell($w, 3, $title,
'',
'R');
1939 $pdf->SetFont(
'',
'B', $default_font_size);
1953 $pdf->SetFont(
'',
'', $default_font_size - 2);
1955 if ($object->ref_customer) {
1957 $pdf->SetXY($posx, $posy);
1958 $pdf->SetTextColor(0, 0, 60);
1959 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_customer),
'',
'R');
1962 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1963 $object->fetch_projet();
1964 if (!empty($object->project->ref)) {
1966 $pdf->SetXY($posx, $posy);
1967 $pdf->SetTextColor(0, 0, 60);
1968 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1972 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1973 $object->fetch_projet();
1974 if (!empty($object->project->ref)) {
1975 $outputlangs->load(
"projects");
1977 $pdf->SetXY($posx, $posy);
1978 $pdf->SetTextColor(0, 0, 60);
1979 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1983 $objectidnext = $object->getIdReplacingInvoice(
'validated');
1984 if ($object->type == 0 && $objectidnext) {
1985 $objectreplacing =
new Facture($this->db);
1986 $objectreplacing->fetch($objectidnext);
1989 $pdf->SetXY($posx, $posy);
1990 $pdf->SetTextColor(0, 0, 60);
1991 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
1993 if ($object->type == 1) {
1994 $objectreplaced =
new Facture($this->db);
1995 $objectreplaced->fetch($object->fk_facture_source);
1998 $pdf->SetXY($posx, $posy);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2002 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2003 $objectreplaced =
new Facture($this->db);
2004 $objectreplaced->fetch($object->fk_facture_source);
2007 $pdf->SetXY($posx, $posy);
2008 $pdf->SetTextColor(0, 0, 60);
2009 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2013 $pdf->SetXY($posx, $posy);
2014 $pdf->SetTextColor(0, 0, 60);
2015 $title = $outputlangs->transnoentities(
"DateInvoice");
2016 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2017 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2019 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2021 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2023 $pdf->SetXY($posx, $posy);
2024 $pdf->SetTextColor(0, 0, 60);
2025 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2028 if ($object->type != 2) {
2030 $pdf->SetXY($posx, $posy);
2031 $pdf->SetTextColor(0, 0, 60);
2032 $title = $outputlangs->transnoentities(
"DateDue");
2033 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2034 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2036 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2039 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2041 $pdf->SetXY($posx, $posy);
2042 $pdf->SetTextColor(0, 0, 60);
2043 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2047 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2048 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2049 if (count($arrayidcontact) > 0) {
2050 $usertmp =
new User($this->db);
2051 $usertmp->fetch($arrayidcontact[0]);
2053 $pdf->SetXY($posx, $posy);
2054 $pdf->SetTextColor(0, 0, 60);
2055 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2063 $current_y = $pdf->getY();
2064 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2065 if ($current_y < $pdf->getY()) {
2066 $top_shift = $pdf->getY() - $current_y;
2071 $carac_emetteur =
'';
2073 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
2074 if (count($arrayidcontact) > 0) {
2075 $object->fetch_user($arrayidcontact[0]);
2076 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2077 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2078 $carac_emetteur .=
"\n";
2081 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2084 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2085 $posy += $top_shift;
2086 $posx = $this->marge_gauche;
2087 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2088 $posx = $this->page_largeur - $this->marge_droite - 80;
2091 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2092 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2096 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2097 $pdf->SetTextColor(0, 0, 0);
2098 $pdf->SetFont(
'',
'', $default_font_size - 2);
2099 $pdf->SetXY($posx, $posy - 5);
2100 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2101 $pdf->SetXY($posx, $posy);
2102 $pdf->SetFillColor(230, 230, 230);
2103 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2104 $pdf->SetTextColor(0, 0, 60);
2108 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2109 $pdf->SetXY($posx + 2, $posy + 3);
2110 $pdf->SetFont(
'',
'B', $default_font_size);
2111 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2112 $posy = $pdf->getY();
2116 $pdf->SetXY($posx + 2, $posy);
2117 $pdf->SetFont(
'',
'', $default_font_size - 1);
2118 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2122 $usecontact =
false;
2123 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2124 if (count($arrayidcontact) > 0) {
2126 $result = $object->fetch_contact($arrayidcontact[0]);
2130 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)))) {
2131 $thirdparty = $object->contact;
2133 $thirdparty = $object->thirdparty;
2139 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2142 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2143 if ($this->page_largeur < 210) {
2146 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2147 $posy += $top_shift;
2148 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2149 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2150 $posx = $this->marge_gauche;
2154 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2155 $pdf->SetTextColor(0, 0, 0);
2156 $pdf->SetFont(
'',
'', $default_font_size - 2);
2157 $pdf->SetXY($posx + 2, $posy - 5);
2158 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2159 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2163 $pdf->SetXY($posx + 2, $posy + 3);
2164 $pdf->SetFont(
'',
'B', $default_font_size);
2165 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2167 $posy = $pdf->getY();
2170 $pdf->SetFont(
'',
'', $default_font_size - 1);
2171 $pdf->SetXY($posx + 2, $posy);
2172 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2176 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2178 if (!empty($idaddressshipping)) {
2179 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2180 $companystatic =
new Societe($this->db);
2181 $companystatic->fetch($object->contact->fk_soc);
2183 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2186 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2188 if (!empty($carac_client_shipping)) {
2189 $posy += $hautcadre;
2192 $pdf->SetXY($posx + 2, $posy - 5);
2193 $pdf->SetFont(
'',
'', $default_font_size - 2);
2194 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2195 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2198 $pdf->SetXY($posx + 2, $posy + 3);
2199 $pdf->SetFont(
'',
'B', $default_font_size);
2200 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2202 $posy = $pdf->getY();
2205 $pdf->SetXY($posx+2, $posy);
2206 $pdf->SetFont(
'',
'', $default_font_size - 1);
2207 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2208 $top_shift += $hautcadre;
2213 $pdf->SetTextColor(0, 0, 0);