238 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
241 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
243 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
245 if (!is_object($outputlangs)) {
246 $outputlangs = $langs;
249 if (!empty($conf->global->MAIN_USE_FPDF)) {
250 $outputlangs->charset_output =
'ISO-8859-1';
254 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
256 global $outputlangsbis;
257 $outputlangsbis =
null;
258 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
259 $outputlangsbis =
new Translate(
'', $conf);
260 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
261 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
265 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
266 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
269 $nblines = count($object->lines);
272 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
273 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
277 $realpatharray = array();
278 $this->atleastonephoto =
false;
279 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
280 $objphoto =
new Product($this->db);
282 for ($i = 0; $i < $nblines; $i++) {
283 if (empty($object->lines[$i]->fk_product)) {
287 $objphoto->fetch($object->lines[$i]->fk_product);
290 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
291 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
293 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
294 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
298 foreach ($pdir as $midir) {
300 if ($conf->entity != $objphoto->entity) {
301 $dir = $conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
303 $dir = $conf->product->dir_output.
'/'.$midir;
306 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
308 if ($obj[
'photo_vignette']) {
309 $filename = $obj[
'photo_vignette'];
311 $filename = $obj[
'photo'];
314 $filename = $obj[
'photo'];
317 $realpath = $dir.$filename;
319 $this->atleastonephoto =
true;
324 if ($realpath && $arephoto) {
325 $realpatharray[$i] = $realpath;
332 if ($conf->facture->multidir_output[$conf->entity]) {
333 $object->fetch_thirdparty();
335 $deja_regle = $object->getSommePaiement((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
336 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
337 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
340 if ($object->specimen) {
341 $dir = $conf->facture->multidir_output[$conf->entity];
342 $file = $dir.
"/SPECIMEN.pdf";
345 $dir = $conf->facture->multidir_output[$object->entity].
"/".$objectref;
346 $file = $dir.
"/".$objectref.
".pdf";
348 if (!file_exists($dir)) {
350 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
355 if (file_exists($dir)) {
357 if (!is_object($hookmanager)) {
358 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
361 $hookmanager->initHooks(array(
'pdfgeneration'));
362 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
364 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
367 $nblines = count($object->lines);
368 $nbpayments = count($object->getListOfPayments());
373 $pdf->SetAutoPageBreak(1, 0);
375 $this->heightforinfotot = 50 + (4 * $nbpayments);
376 $this->heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
377 $this->heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
379 $heightforqrinvoice = $heightforqrinvoice_firstpage = 0;
383 $this->heightforinfotot = 30 + (4 * $nbpayments);
387 if (class_exists(
'TCPDF')) {
388 $pdf->setPrintHeader(
false);
389 $pdf->setPrintFooter(
false);
394 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
395 $logodir = $conf->mycompany->dir_output;
396 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
397 $logodir = $conf->mycompany->multidir_output[$object->entity];
399 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
400 $tplidx = $pdf->importPage(1);
405 $pdf->SetDrawColor(128, 128, 128);
407 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
408 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
409 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
410 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
411 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
413 $pdf->SetCompression(
false);
417 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
418 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
421 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
424 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
429 'Name' => $this->emetteur->name,
430 'Location' =>
getCountry($this->emetteur->country_code, 0),
431 'Reason' =>
'INVOICE',
432 'ContactInfo' => $this->emetteur->email
434 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
437 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
441 $categoryOfOperation = 0;
444 for ($i = 0; $i < $nblines; $i++) {
445 if ($object->lines[$i]->remise_percent) {
446 $this->atleastonediscount++;
451 if (preg_match(
'/^\((.*)\)$/', $object->lines[$i]->desc, $reg)) {
452 if ($reg[1] ==
'DEPOSIT') {
463 if ($categoryOfOperation < 2) {
464 $lineProductType = $object->lines[$i]->product_type;
470 if ($nbProduct > 0 && $nbService > 0) {
472 $categoryOfOperation = 2;
477 if ($categoryOfOperation <= 0) {
479 if ($nbProduct == 0 && $nbService > 0) {
480 $categoryOfOperation = 1;
483 $this->categoryOfOperation = $categoryOfOperation;
486 if ($object->situation_cycle_ref) {
487 $this->situationinvoice =
true;
492 if (!empty($tplidx)) {
493 $pdf->useTemplate($tplidx);
498 $pagehead = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
499 $top_shift = $pagehead[
'top_shift'];
500 $shipp_shift = $pagehead[
'shipp_shift'];
501 $pdf->SetFont(
'',
'', $default_font_size - 1);
502 $pdf->MultiCell(0, 3,
'');
503 $pdf->SetTextColor(0, 0, 0);
508 $this->tab_top = 90 + $top_shift + $shipp_shift;
509 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
512 $extra_under_address_shift = 0;
514 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
515 $qrcodestring = $object->buildZATCAQRString();
517 $qrcodestring = $object->buildSwitzerlandQRString();
520 $qrcodecolor = array(
'25',
'25',
'25');
525 'fgcolor' => $qrcodecolor,
530 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
531 $extra_under_address_shift += 25;
539 'outputlangs' => $outputlangs,
540 'hidedetails' => $hidedetails
542 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
543 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
544 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
547 $this->tab_top += $extra_under_address_shift;
548 $this->tab_top_newpage += 0;
552 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1, $object, $langs);
554 $nexY = $this->tab_top - 1;
557 $height_incoterms = 0;
558 if (isModEnabled(
'incoterm')) {
559 $desc_incoterms = $object->getIncotermsForPDF();
560 if ($desc_incoterms) {
563 $pdf->SetFont(
'',
'', $default_font_size - 1);
564 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
565 $nexY = max($pdf->GetY(), $nexY);
566 $height_incoterms = $nexY - $this->tab_top;
569 $pdf->SetDrawColor(192, 192, 192);
570 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
572 $this->tab_top = $nexY + 6;
573 $height_incoterms += 4;
578 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
579 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
581 if (is_object($object->thirdparty)) {
582 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
583 $salerepobj =
new User($this->db);
584 $salerepobj->fetch($salereparray[0][
'id']);
585 if (!empty($salerepobj->signature)) {
586 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
592 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
593 if (!empty($extranote)) {
597 $pagenb = $pdf->getPage();
601 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
602 $pageposbeforenote = $pagenb;
609 $pdf->startTransaction();
611 $pdf->SetFont(
'',
'', $default_font_size - 1);
612 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
614 $pageposafternote = $pdf->getPage();
615 $posyafter = $pdf->GetY();
617 if ($pageposafternote > $pageposbeforenote) {
618 $pdf->rollbackTransaction(
true);
621 while ($pagenb < $pageposafternote) {
624 if (!empty($tplidx)) {
625 $pdf->useTemplate($tplidx);
628 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
630 $pdf->setTopMargin($this->tab_top_newpage);
632 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
636 $pdf->setPage($pageposbeforenote);
637 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
638 $pdf->SetFont(
'',
'', $default_font_size - 1);
639 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
640 $pageposafternote = $pdf->getPage();
642 $posyafter = $pdf->GetY();
644 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
645 $pdf->AddPage(
'',
'',
true);
648 $pdf->setPage($pageposafternote);
649 $pdf->setTopMargin($this->tab_top_newpage);
651 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
657 $i = $pageposbeforenote;
658 while ($i < $pageposafternote) {
662 $pdf->SetDrawColor(128, 128, 128);
664 if ($i > $pageposbeforenote) {
665 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
666 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
668 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
669 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
673 $pdf->setPageOrientation(
'', 1, 0);
680 $pdf->setPage($pageposafternote);
681 if (!empty($tplidx)) {
682 $pdf->useTemplate($tplidx);
685 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
687 $height_note = $posyafter - $this->tab_top_newpage;
688 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
691 $pdf->commitTransaction();
692 $posyafter = $pdf->GetY();
693 $height_note = $posyafter - $this->tab_top;
694 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
697 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
699 $pdf->AddPage(
'',
'',
true);
702 $pdf->setPage($pageposafternote);
703 if (!empty($tplidx)) {
704 $pdf->useTemplate($tplidx);
707 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
710 $posyafter = $this->tab_top_newpage;
714 $tab_height = $tab_height - $height_note;
715 $this->tab_top = $posyafter + 6;
724 $pdf->startTransaction();
725 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
726 $pdf->rollbackTransaction(
true);
728 $nexY = $this->tab_top + $this->tabTitleHeight;
731 $pageposbeforeprintlines = $pdf->getPage();
732 $pagenb = $pageposbeforeprintlines;
733 for ($i = 0; $i < $nblines; $i++) {
735 $pdf->SetFont(
'',
'', $default_font_size - 1);
736 $pdf->SetTextColor(0, 0, 0);
739 $imglinesize = array();
740 if (!empty($realpatharray[$i])) {
744 $pdf->setTopMargin($this->tab_top_newpage);
745 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(), $object, $langs);
746 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
747 $pageposbefore = $pdf->getPage();
749 $showpricebeforepagebreak = 1;
751 $posYAfterDescription = 0;
755 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
756 $pdf->AddPage(
'',
'',
true);
757 if (!empty($tplidx)) {
758 $pdf->useTemplate($tplidx);
760 $pdf->setPage($pageposbefore + 1);
762 $curY = $this->tab_top_newpage;
765 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
766 $showpricebeforepagebreak = 1;
768 $showpricebeforepagebreak = 0;
772 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
773 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
775 $posYAfterImage = $curY + $imglinesize[
'height'];
781 $pdf->startTransaction();
783 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
784 $pageposafter = $pdf->getPage();
786 if ($pageposafter > $pageposbefore) {
787 $pdf->rollbackTransaction(
true);
788 $pageposafter = $pageposbefore;
789 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
791 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
793 $pageposafter = $pdf->getPage();
794 $posyafter = $pdf->GetY();
796 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
797 if ($i == ($nblines - 1)) {
798 $pdf->AddPage(
'',
'',
true);
799 if (!empty($tplidx)) {
800 $pdf->useTemplate($tplidx);
802 $pdf->setPage($pageposafter + 1);
807 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
808 $showpricebeforepagebreak = 1;
810 $showpricebeforepagebreak = 0;
815 $pdf->commitTransaction();
817 $posYAfterDescription = $pdf->GetY();
820 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
822 $pageposafter = $pdf->getPage();
823 $pdf->setPage($pageposbefore);
824 $pdf->setTopMargin($this->marge_haute);
825 $pdf->setPageOrientation(
'', 1, 0);
828 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
829 $pdf->setPage($pageposafter);
830 $curY = $this->tab_top_newpage;
833 $pdf->SetFont(
'',
'', $default_font_size - 1);
839 $nexY = max($pdf->GetY(), $nexY);
846 $nexY = max($pdf->GetY(), $nexY);
854 $nexY = max($pdf->GetY(), $nexY);
861 $nexY = max($pdf->GetY(), $nexY);
866 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
868 $nexY = max($pdf->GetY(), $nexY);
872 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
875 $nexY = max($pdf->GetY(), $nexY);
882 $nexY = max($pdf->GetY(), $nexY);
889 $nexY = max($pdf->GetY(), $nexY);
893 if (!empty($object->lines[$i]->array_options)) {
894 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
896 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
898 $nexY = max($pdf->GetY(), $nexY);
910 'outputlangs' => $outputlangs,
911 'hidedetails' => $hidedetails
913 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
917 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
921 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
922 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
923 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
924 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
926 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
929 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
930 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
932 $tvaligne = $sign * $object->lines[$i]->total_tva;
936 $localtax1ligne = $object->lines[$i]->total_localtax1;
937 $localtax2ligne = $object->lines[$i]->total_localtax2;
938 $localtax1_rate = $object->lines[$i]->localtax1_tx;
939 $localtax2_rate = $object->lines[$i]->localtax2_tx;
940 $localtax1_type = $object->lines[$i]->localtax1_type;
941 $localtax2_type = $object->lines[$i]->localtax2_type;
954 $vatrate = (string) $object->lines[$i]->tva_tx;
957 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
958 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
960 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
961 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
965 if ($localtax1_type && $localtax1ligne != 0) {
966 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
967 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
969 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
972 if ($localtax2_type && $localtax2ligne != 0) {
973 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
974 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
976 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
980 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
985 if (!isset($this->tva[$vatrate])) {
986 $this->tva[$vatrate] = 0;
988 $this->tva[$vatrate] += $tvaligne;
989 $vatcode = $object->lines[$i]->vat_src_code;
990 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
991 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
993 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
995 $nexY = max($nexY, $posYAfterImage);
998 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
999 $pdf->setPage($pageposafter);
1000 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
1002 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1003 $pdf->SetLineStyle(array(
'dash'=>0));
1007 while ($pagenb < $pageposafter) {
1008 $pdf->setPage($pagenb);
1010 if ($pagenb == $pageposbeforeprintlines) {
1011 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1013 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1017 $pdf->setPage($pagenb);
1018 $pdf->setPageOrientation(
'', 1, 0);
1020 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1022 if (!empty($tplidx)) {
1023 $pdf->useTemplate($tplidx);
1027 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
1029 if ($pagenb == $pageposafter) {
1030 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1032 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1037 if (!empty($tplidx)) {
1038 $pdf->useTemplate($tplidx);
1042 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1049 if ($pagenb == $pageposbeforeprintlines) {
1050 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
1051 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1053 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
1054 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1058 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1061 $posy = $this->
drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1064 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1070 if (method_exists($pdf,
'AliasNbPages')) {
1071 $pdf->AliasNbPages();
1079 $pdf->Output($file,
'F');
1082 $hookmanager->initHooks(array(
'pdfgeneration'));
1083 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
1085 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1087 $this->error = $hookmanager->error;
1088 $this->errors = $hookmanager->errors;
1093 $this->result = array(
'fullpath'=>$file);
1097 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1101 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1260 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1262 global $conf, $mysoc;
1266 $pdf->SetFont(
'',
'', $default_font_size - 1);
1269 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1270 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1271 $pdf->SetXY($this->marge_gauche, $posy);
1272 if ($mysoc->forme_juridique_code == 92) {
1273 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1275 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1278 $posy = $pdf->GetY() + 4;
1283 if ($this->page_largeur < 210) {
1288 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1289 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1290 $pdf->SetXY($this->marge_gauche, $posy);
1291 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1292 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1294 $pdf->SetFont(
'',
'', $default_font_size - 2);
1295 $pdf->SetXY($posxval, $posy);
1296 $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);
1297 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1298 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1300 $posy = $pdf->GetY() + 3;
1304 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1305 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1306 $pdf->SetXY($this->marge_gauche, $posy);
1307 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1308 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1310 $pdf->SetFont(
'',
'', $default_font_size - 2);
1311 $pdf->SetXY($posxval, $posy);
1312 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1313 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1315 $posy = $pdf->GetY() + 3;
1318 if ($object->type != 2) {
1320 if (empty($object->mode_reglement_code)
1323 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1324 } elseif (($object->mode_reglement_code ==
'CHQ' && !
getDolGlobalInt(
'FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1325 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1327 $outputlangs->load(
"errors");
1329 $pdf->SetXY($this->marge_gauche, $posy);
1330 $pdf->SetTextColor(200, 0, 0);
1331 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1332 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1333 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1334 $pdf->SetTextColor(0, 0, 0);
1336 $posy = $pdf->GetY() + 1;
1340 if (!empty($object->mode_reglement_code)
1341 && $object->mode_reglement_code !=
'CHQ'
1342 && $object->mode_reglement_code !=
'VIR') {
1343 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1344 $pdf->SetXY($this->marge_gauche, $posy);
1345 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1346 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1348 $pdf->SetFont(
'',
'', $default_font_size - 2);
1349 $pdf->SetXY($posxval, $posy);
1350 $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);
1353 if ($object->mode_reglement_code ==
"PRE") {
1354 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1356 $bac->fetch(0, $object->thirdparty->id);
1357 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1358 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1361 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1363 $posy = $pdf->GetY();
1369 if ($this->emetteur->country_code ==
'FR') {
1370 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1371 $pdf->SetXY($this->marge_gauche, $posy);
1372 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1374 $posy = $pdf->GetY() + 1;
1379 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1380 $useonlinepayment = 0;
1381 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1382 if (isModEnabled(
'paypal')) {
1383 $useonlinepayment++;
1385 if (isModEnabled(
'stripe')) {
1386 $useonlinepayment++;
1388 if (isModEnabled(
'paybox')) {
1389 $useonlinepayment++;
1395 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1398 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1399 $servicename = $langs->transnoentities(
'Online');
1400 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1401 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1403 $pdf->SetXY($this->marge_gauche, $posy);
1404 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1406 $posy = $pdf->GetY() + 1;
1411 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1414 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1416 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1417 $account =
new Account($this->db);
1420 $pdf->SetXY($this->marge_gauche, $posy);
1421 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1422 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1423 $posy = $pdf->GetY() + 1;
1425 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1426 $pdf->SetXY($this->marge_gauche, $posy);
1427 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1428 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1429 $posy = $pdf->GetY() + 2;
1432 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1433 $pdf->SetXY($this->marge_gauche, $posy);
1434 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1435 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1436 $posy = $pdf->GetY() + 1;
1438 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1439 $pdf->SetXY($this->marge_gauche, $posy);
1440 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1441 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1442 $posy = $pdf->GetY() + 2;
1449 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1450 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1451 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1452 if ($object->fk_bank > 0) {
1453 $bankid = $object->fk_bank;
1455 $account =
new Account($this->db);
1456 $account->fetch($bankid);
1458 $curx = $this->marge_gauche;
1461 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1483 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1485 global $conf, $mysoc, $hookmanager;
1488 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1496 if (is_object($outputlangsbis)) {
1497 $pdf->SetFont(
'',
'', $default_font_size - 2);
1499 $pdf->SetFont(
'',
'', $default_font_size - 1);
1505 if ($this->page_largeur < 210) {
1509 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1515 $parameters = array(
1516 'object' => &$object,
1517 'outputlangs' => $outputlangs,
1519 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1524 foreach ($object->lines as $line) {
1525 if ($line->product_type != 9) {
1526 $percent += $line->situation_percent;
1532 $avancementGlobal = $percent / $i;
1534 $avancementGlobal = 0;
1537 $object->fetchPreviousNextSituationInvoice();
1538 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1541 $total_a_payer_ttc = 0;
1542 foreach ($TPreviousIncoice as &$fac) {
1543 $total_a_payer += $fac->total_ht;
1544 $total_a_payer_ttc += $fac->total_ttc;
1546 $total_a_payer += $object->total_ht;
1547 $total_a_payer_ttc += $object->total_ttc;
1549 if (!empty($avancementGlobal)) {
1550 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1551 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1554 $total_a_payer_ttc = 0;
1558 if (!empty($TPreviousIncoice)) {
1559 $pdf->setY($tab2_top);
1560 $posy = $pdf->GetY();
1562 foreach ($TPreviousIncoice as &$fac) {
1563 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1567 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1568 $pdf->setY($this->tab_top_newpage);
1570 $pdf->setY($this->marge_haute);
1572 $posy = $pdf->GetY();
1577 $pdf->SetFillColor(255, 255, 255);
1578 $pdf->SetXY($col1x, $posy);
1579 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1581 $pdf->SetXY($col2x, $posy);
1585 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1588 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1590 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1599 $pdf->SetFillColor(255, 255, 255);
1600 $pdf->SetXY($col1x, $posy);
1601 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1603 $pdf->SetXY($col2x, $posy);
1606 $facSign = $object->total_ht >= 0 ?
'+' :
'';
1614 $displayAmount =
' '.$facSign.
' '.
price($object->total_ht, 0, $outputlangs);
1615 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1620 $pdf->SetFont(
'',
'', $default_font_size - 1);
1621 $pdf->SetFillColor(255, 255, 255);
1622 $pdf->SetXY($col1x, $posy);
1623 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1625 $pdf->SetXY($col2x, $posy);
1626 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1627 $pdf->SetFont(
'',
'', $default_font_size - 2);
1631 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1634 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1635 $pdf->setY($this->tab_top_newpage);
1637 $pdf->setY($this->marge_haute);
1640 $posy = $pdf->GetY();
1651 $total_ht = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1654 $total_line_remise = 0;
1655 foreach ($object->lines as $i => $line) {
1657 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1659 if ($line->total_ht < 0) {
1660 $total_line_remise += -$line->total_ht;
1663 if ($total_line_remise > 0) {
1664 if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
1665 $pdf->SetFillColor(255, 255, 255);
1666 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1667 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1668 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1669 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1674 if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
1675 $pdf->SetFillColor(255, 255, 255);
1676 $pdf->SetXY($col1x, $tab2_top);
1677 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1678 $pdf->SetXY($col2x, $tab2_top);
1679 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1686 $pdf->SetFillColor(255, 255, 255);
1687 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1688 $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);
1690 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1691 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1692 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1695 $pdf->SetFillColor(248, 248, 248);
1697 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1699 $this->atleastoneratenotnull = 0;
1700 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1701 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1702 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1708 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1709 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1713 foreach ($localtax_rate as $tvakey => $tvaval) {
1718 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1721 if (preg_match(
'/\*/', $tvakey)) {
1722 $tvakey = str_replace(
'*',
'', $tvakey);
1723 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1726 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1728 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1729 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1731 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1733 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1734 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1742 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1743 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1747 foreach ($localtax_rate as $tvakey => $tvaval) {
1752 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1755 if (preg_match(
'/\*/', $tvakey)) {
1756 $tvakey = str_replace(
'*',
'', $tvakey);
1757 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1759 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1761 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1762 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1764 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1766 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1767 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1774 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1776 foreach ($this->tva as $tvakey => $tvaval) {
1777 $sum_pdf_tva += $tvaval;
1780 if ($sum_pdf_tva != $object->total_tva) {
1781 if (!empty($sum_pdf_tva)) {
1782 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1788 foreach ($this->tva as $tvakey => $tvaval) {
1789 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1791 foreach ($this->tva_array as $tvakey => $tvaval) {
1792 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1798 foreach ($this->tva_array as $tvakey => $tvaval) {
1800 $this->atleastoneratenotnull++;
1803 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1806 if (preg_match(
'/\*/', $tvakey)) {
1807 $tvakey = str_replace(
'*',
'', $tvakey);
1808 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1810 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1813 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1815 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1817 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1821 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1822 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1829 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1830 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1834 foreach ($localtax_rate as $tvakey => $tvaval) {
1839 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1842 if (preg_match(
'/\*/', $tvakey)) {
1843 $tvakey = str_replace(
'*',
'', $tvakey);
1844 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1846 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1848 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1850 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1852 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1854 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1855 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1863 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1864 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1868 foreach ($localtax_rate as $tvakey => $tvaval) {
1874 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1877 if (preg_match(
'/\*/', $tvakey)) {
1878 $tvakey = str_replace(
'*',
'', $tvakey);
1879 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1881 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1884 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1885 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1887 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1889 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1890 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1897 if (
price2num($object->revenuestamp) != 0) {
1899 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1900 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
1902 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1903 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1908 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1909 $pdf->SetTextColor(0, 0, 60);
1910 $pdf->SetFillColor(224, 224, 224);
1911 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1913 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1914 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1918 if ($object->displayRetainedWarranty()) {
1919 $pdf->SetTextColor(40, 40, 40);
1920 $pdf->SetFillColor(255, 255, 255);
1922 $retainedWarranty = $object->getRetainedWarrantyAmount();
1923 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1927 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1928 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1930 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1931 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1935 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1937 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.$object->retained_warranty.
'%)';
1938 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1940 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1941 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1942 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1947 $pdf->SetTextColor(0, 0, 0);
1949 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1950 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1952 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1953 if (!empty($object->paye)) {
1957 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1960 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1961 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
1962 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1963 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1966 if ($creditnoteamount) {
1967 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1968 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes")) :
'');
1970 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1971 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1972 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1973 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1992 $pdf->SetTextColor(0, 0, 60);
1993 $pdf->SetFillColor(224, 224, 224);
1994 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1995 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1996 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1997 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1999 $pdf->SetFont(
'',
'', $default_font_size - 1);
2000 $pdf->SetTextColor(0, 0, 0);
2004 return ($tab2_top + ($tab2_hl * $index));
2100 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
2102 global $conf, $langs;
2104 $ltrdirection =
'L';
2105 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
2108 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2114 $pdf->SetTextColor(0, 0, 60);
2115 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2119 $posy = $this->marge_haute;
2120 $posx = $this->page_largeur - $this->marge_droite - $w;
2122 $pdf->SetXY($this->marge_gauche, $posy);
2126 if ($this->emetteur->logo) {
2127 $logodir = $conf->mycompany->dir_output;
2128 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2129 $logodir = $conf->mycompany->multidir_output[$object->entity];
2132 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2134 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2136 if (is_readable($logo)) {
2138 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2140 $pdf->SetTextColor(200, 0, 0);
2141 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2142 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2143 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2146 $text = $this->emetteur->name;
2147 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2151 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2152 $pdf->SetXY($posx, $posy);
2153 $pdf->SetTextColor(0, 0, 60);
2154 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2155 if ($object->type == 1) {
2156 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2158 if ($object->type == 2) {
2159 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2161 if ($object->type == 3) {
2162 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2164 if ($object->type == 4) {
2165 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2167 if ($this->situationinvoice) {
2168 $outputlangs->loadLangs(array(
"other"));
2169 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") . $object->situation_counter .
" -";
2171 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2173 if ($object->type == 0) {
2174 if ($this->situationinvoice) {
2175 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2177 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2178 } elseif ($object->type == 1) {
2179 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2180 } elseif ($object->type == 2) {
2181 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2182 } elseif ($object->type == 3) {
2183 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2184 } elseif ($object->type == 4) {
2185 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2188 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
2189 if ($object->statut == $object::STATUS_DRAFT) {
2190 $pdf->SetTextColor(128, 0, 0);
2191 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2194 $pdf->MultiCell($w, 3, $title,
'',
'R');
2196 $pdf->SetFont(
'',
'B', $default_font_size);
2210 $pdf->SetFont(
'',
'', $default_font_size - 2);
2212 if ($object->ref_customer) {
2214 $pdf->SetXY($posx, $posy);
2215 $pdf->SetTextColor(0, 0, 60);
2216 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65),
'',
'R');
2219 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
2220 $object->fetch_projet();
2221 if (!empty($object->project->ref)) {
2223 $pdf->SetXY($posx, $posy);
2224 $pdf->SetTextColor(0, 0, 60);
2225 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
2229 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
2230 $object->fetch_projet();
2231 if (!empty($object->project->ref)) {
2232 $outputlangs->load(
"projects");
2234 $pdf->SetXY($posx, $posy);
2235 $pdf->SetTextColor(0, 0, 60);
2236 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
2240 $objectidnext = $object->getIdReplacingInvoice(
'validated');
2241 if ($object->type == 0 && $objectidnext) {
2242 $objectreplacing =
new Facture($this->db);
2243 $objectreplacing->fetch($objectidnext);
2246 $pdf->SetXY($posx, $posy);
2247 $pdf->SetTextColor(0, 0, 60);
2248 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2250 if ($object->type == 1) {
2251 $objectreplaced =
new Facture($this->db);
2252 $objectreplaced->fetch($object->fk_facture_source);
2255 $pdf->SetXY($posx, $posy);
2256 $pdf->SetTextColor(0, 0, 60);
2257 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2259 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2260 $objectreplaced =
new Facture($this->db);
2261 $objectreplaced->fetch($object->fk_facture_source);
2264 $pdf->SetXY($posx, $posy);
2265 $pdf->SetTextColor(0, 0, 60);
2266 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2270 $pdf->SetXY($posx, $posy);
2271 $pdf->SetTextColor(0, 0, 60);
2273 $title = $outputlangs->transnoentities(
"DateInvoice");
2274 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2275 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2277 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2279 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2281 $pdf->SetXY($posx, $posy);
2282 $pdf->SetTextColor(0, 0, 60);
2283 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2286 if ($object->type != 2) {
2288 $pdf->SetXY($posx, $posy);
2289 $pdf->SetTextColor(0, 0, 60);
2290 $title = $outputlangs->transnoentities(
"DateDue");
2291 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2292 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2294 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2297 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2299 $pdf->SetXY($posx, $posy);
2300 $pdf->SetTextColor(0, 0, 60);
2301 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2305 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2306 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2307 if (count($arrayidcontact) > 0) {
2308 $usertmp =
new User($this->db);
2309 $usertmp->fetch($arrayidcontact[0]);
2311 $pdf->SetXY($posx, $posy);
2312 $pdf->SetTextColor(0, 0, 60);
2313 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2322 $current_y = $pdf->getY();
2323 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2324 if ($current_y < $pdf->getY()) {
2325 $top_shift = $pdf->getY() - $current_y;
2330 $carac_emetteur =
'';
2332 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
2333 if (count($arrayidcontact) > 0) {
2334 $object->fetch_user($arrayidcontact[0]);
2335 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2336 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2337 $carac_emetteur .=
"\n";
2340 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2343 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2344 $posy += $top_shift;
2345 $posx = $this->marge_gauche;
2346 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2347 $posx = $this->page_largeur - $this->marge_droite - 80;
2350 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2351 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2354 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2355 $pdf->SetTextColor(0, 0, 0);
2356 $pdf->SetFont(
'',
'', $default_font_size - 2);
2357 $pdf->SetXY($posx, $posy - 5);
2358 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2359 $pdf->SetXY($posx, $posy);
2360 $pdf->SetFillColor(230, 230, 230);
2361 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2362 $pdf->SetTextColor(0, 0, 60);
2366 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2367 $pdf->SetXY($posx + 2, $posy + 3);
2368 $pdf->SetFont(
'',
'B', $default_font_size);
2369 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2370 $posy = $pdf->getY();
2374 $pdf->SetXY($posx + 2, $posy);
2375 $pdf->SetFont(
'',
'', $default_font_size - 1);
2376 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2379 $usecontact =
false;
2380 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2381 if (count($arrayidcontact) > 0) {
2383 $result = $object->fetch_contact($arrayidcontact[0]);
2387 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)))) {
2388 $thirdparty = $object->contact;
2390 $thirdparty = $object->thirdparty;
2396 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2399 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2400 if ($this->page_largeur < 210) {
2403 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2404 $posy += $top_shift;
2405 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2406 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2407 $posx = $this->marge_gauche;
2411 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2412 $pdf->SetTextColor(0, 0, 0);
2413 $pdf->SetFont(
'',
'', $default_font_size - 2);
2414 $pdf->SetXY($posx + 2, $posy - 5);
2415 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2416 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2420 $pdf->SetXY($posx + 2, $posy + 3);
2421 $pdf->SetFont(
'',
'B', $default_font_size);
2422 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2424 $posy = $pdf->getY();
2427 $pdf->SetFont(
'',
'', $default_font_size - 1);
2428 $pdf->SetXY($posx + 2, $posy);
2429 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2433 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2435 if (!empty($idaddressshipping)) {
2436 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2437 $companystatic =
new Societe($this->db);
2438 $companystatic->fetch($object->contact->fk_soc);
2440 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2443 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2445 if (!empty($carac_client_shipping)) {
2446 $posy += $hautcadre;
2449 $pdf->SetXY($posx + 2, $posy - 5);
2450 $pdf->SetFont(
'',
'', $default_font_size - 2);
2451 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2452 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2455 $pdf->SetXY($posx + 2, $posy + 3);
2456 $pdf->SetFont(
'',
'B', $default_font_size);
2457 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2459 $posy = $pdf->getY();
2462 $pdf->SetXY($posx+2, $posy);
2463 $pdf->SetFont(
'',
'', $default_font_size - 1);
2464 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2465 $shipp_shift += $hautcadre;
2470 $pdf->SetTextColor(0, 0, 0);
2472 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);