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++;
450 if ($categoryOfOperation < 2) {
451 $lineProductType = $object->lines[$i]->product_type;
457 if ($nbProduct > 0 && $nbService > 0) {
459 $categoryOfOperation = 2;
464 if ($categoryOfOperation <= 0) {
466 if ($nbProduct == 0 && $nbService > 0) {
467 $categoryOfOperation = 1;
470 $this->categoryOfOperation = $categoryOfOperation;
473 if ($object->situation_cycle_ref) {
474 $this->situationinvoice =
true;
479 if (!empty($tplidx)) {
480 $pdf->useTemplate($tplidx);
485 $pagehead = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
486 $top_shift = $pagehead[
'top_shift'];
487 $shipp_shift = $pagehead[
'shipp_shift'];
488 $pdf->SetFont(
'',
'', $default_font_size - 1);
489 $pdf->MultiCell(0, 3,
'');
490 $pdf->SetTextColor(0, 0, 0);
495 $this->tab_top = 90 + $top_shift + $shipp_shift;
496 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
499 $extra_under_address_shift = 0;
501 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
502 $qrcodestring = $object->buildZATCAQRString();
504 $qrcodestring = $object->buildSwitzerlandQRString();
507 $qrcodecolor = array(
'25',
'25',
'25');
512 'fgcolor' => $qrcodecolor,
517 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
518 $extra_under_address_shift += 25;
526 'outputlangs' => $outputlangs,
527 'hidedetails' => $hidedetails
529 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
530 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
531 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
534 $this->tab_top += $extra_under_address_shift;
535 $this->tab_top_newpage += 0;
539 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1, $object, $langs);
541 $nexY = $this->tab_top - 1;
544 $height_incoterms = 0;
545 if (isModEnabled(
'incoterm')) {
546 $desc_incoterms = $object->getIncotermsForPDF();
547 if ($desc_incoterms) {
550 $pdf->SetFont(
'',
'', $default_font_size - 1);
551 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
552 $nexY = max($pdf->GetY(), $nexY);
553 $height_incoterms = $nexY - $this->tab_top;
556 $pdf->SetDrawColor(192, 192, 192);
557 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
559 $this->tab_top = $nexY + 6;
560 $height_incoterms += 4;
565 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
566 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
568 if (is_object($object->thirdparty)) {
569 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
570 $salerepobj =
new User($this->db);
571 $salerepobj->fetch($salereparray[0][
'id']);
572 if (!empty($salerepobj->signature)) {
573 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
579 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
580 if (!empty($extranote)) {
584 $pagenb = $pdf->getPage();
588 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
589 $pageposbeforenote = $pagenb;
596 $pdf->startTransaction();
598 $pdf->SetFont(
'',
'', $default_font_size - 1);
599 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
601 $pageposafternote = $pdf->getPage();
602 $posyafter = $pdf->GetY();
604 if ($pageposafternote > $pageposbeforenote) {
605 $pdf->rollbackTransaction(
true);
608 while ($pagenb < $pageposafternote) {
611 if (!empty($tplidx)) {
612 $pdf->useTemplate($tplidx);
615 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
617 $pdf->setTopMargin($this->tab_top_newpage);
619 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
623 $pdf->setPage($pageposbeforenote);
624 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
625 $pdf->SetFont(
'',
'', $default_font_size - 1);
626 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
627 $pageposafternote = $pdf->getPage();
629 $posyafter = $pdf->GetY();
631 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
632 $pdf->AddPage(
'',
'',
true);
635 $pdf->setPage($pageposafternote);
636 $pdf->setTopMargin($this->tab_top_newpage);
638 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
644 $i = $pageposbeforenote;
645 while ($i < $pageposafternote) {
649 $pdf->SetDrawColor(128, 128, 128);
651 if ($i > $pageposbeforenote) {
652 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
653 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
655 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
656 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
660 $pdf->setPageOrientation(
'', 1, 0);
667 $pdf->setPage($pageposafternote);
668 if (!empty($tplidx)) {
669 $pdf->useTemplate($tplidx);
672 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
674 $height_note = $posyafter - $this->tab_top_newpage;
675 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
678 $pdf->commitTransaction();
679 $posyafter = $pdf->GetY();
680 $height_note = $posyafter - $this->tab_top;
681 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
684 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
686 $pdf->AddPage(
'',
'',
true);
689 $pdf->setPage($pageposafternote);
690 if (!empty($tplidx)) {
691 $pdf->useTemplate($tplidx);
694 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
697 $posyafter = $this->tab_top_newpage;
701 $tab_height = $tab_height - $height_note;
702 $this->tab_top = $posyafter + 6;
711 $pdf->startTransaction();
712 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
713 $pdf->rollbackTransaction(
true);
715 $nexY = $this->tab_top + $this->tabTitleHeight;
718 $pageposbeforeprintlines = $pdf->getPage();
719 $pagenb = $pageposbeforeprintlines;
720 for ($i = 0; $i < $nblines; $i++) {
722 $pdf->SetFont(
'',
'', $default_font_size - 1);
723 $pdf->SetTextColor(0, 0, 0);
726 $imglinesize = array();
727 if (!empty($realpatharray[$i])) {
731 $pdf->setTopMargin($this->tab_top_newpage);
732 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(), $object, $langs);
733 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
734 $pageposbefore = $pdf->getPage();
736 $showpricebeforepagebreak = 1;
738 $posYAfterDescription = 0;
742 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
743 $pdf->AddPage(
'',
'',
true);
744 if (!empty($tplidx)) {
745 $pdf->useTemplate($tplidx);
747 $pdf->setPage($pageposbefore + 1);
749 $curY = $this->tab_top_newpage;
752 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
753 $showpricebeforepagebreak = 1;
755 $showpricebeforepagebreak = 0;
759 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
760 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
762 $posYAfterImage = $curY + $imglinesize[
'height'];
768 $pdf->startTransaction();
770 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
771 $pageposafter = $pdf->getPage();
773 if ($pageposafter > $pageposbefore) {
774 $pdf->rollbackTransaction(
true);
775 $pageposafter = $pageposbefore;
776 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
778 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
780 $pageposafter = $pdf->getPage();
781 $posyafter = $pdf->GetY();
783 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
784 if ($i == ($nblines - 1)) {
785 $pdf->AddPage(
'',
'',
true);
786 if (!empty($tplidx)) {
787 $pdf->useTemplate($tplidx);
789 $pdf->setPage($pageposafter + 1);
794 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
795 $showpricebeforepagebreak = 1;
797 $showpricebeforepagebreak = 0;
802 $pdf->commitTransaction();
804 $posYAfterDescription = $pdf->GetY();
807 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
809 $pageposafter = $pdf->getPage();
810 $pdf->setPage($pageposbefore);
811 $pdf->setTopMargin($this->marge_haute);
812 $pdf->setPageOrientation(
'', 1, 0);
815 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
816 $pdf->setPage($pageposafter);
817 $curY = $this->tab_top_newpage;
820 $pdf->SetFont(
'',
'', $default_font_size - 1);
826 $nexY = max($pdf->GetY(), $nexY);
833 $nexY = max($pdf->GetY(), $nexY);
841 $nexY = max($pdf->GetY(), $nexY);
848 $nexY = max($pdf->GetY(), $nexY);
853 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
855 $nexY = max($pdf->GetY(), $nexY);
859 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
862 $nexY = max($pdf->GetY(), $nexY);
869 $nexY = max($pdf->GetY(), $nexY);
876 $nexY = max($pdf->GetY(), $nexY);
880 if (!empty($object->lines[$i]->array_options)) {
881 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
883 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
885 $nexY = max($pdf->GetY(), $nexY);
897 'outputlangs' => $outputlangs,
898 'hidedetails' => $hidedetails
900 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
904 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
908 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
909 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
910 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
911 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
913 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
916 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
917 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
919 $tvaligne = $sign * $object->lines[$i]->total_tva;
923 $localtax1ligne = $object->lines[$i]->total_localtax1;
924 $localtax2ligne = $object->lines[$i]->total_localtax2;
925 $localtax1_rate = $object->lines[$i]->localtax1_tx;
926 $localtax2_rate = $object->lines[$i]->localtax2_tx;
927 $localtax1_type = $object->lines[$i]->localtax1_type;
928 $localtax2_type = $object->lines[$i]->localtax2_type;
941 $vatrate = (string) $object->lines[$i]->tva_tx;
944 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
945 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
947 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
948 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
952 if ($localtax1_type && $localtax1ligne != 0) {
953 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
954 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
956 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
959 if ($localtax2_type && $localtax2ligne != 0) {
960 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
961 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
963 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
967 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
972 if (!isset($this->tva[$vatrate])) {
973 $this->tva[$vatrate] = 0;
975 $this->tva[$vatrate] += $tvaligne;
976 $vatcode = $object->lines[$i]->vat_src_code;
977 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
978 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
980 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
982 $nexY = max($nexY, $posYAfterImage);
985 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
986 $pdf->setPage($pageposafter);
987 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
989 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
990 $pdf->SetLineStyle(array(
'dash'=>0));
994 while ($pagenb < $pageposafter) {
995 $pdf->setPage($pagenb);
997 if ($pagenb == $pageposbeforeprintlines) {
998 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1000 $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);
1004 $pdf->setPage($pagenb);
1005 $pdf->setPageOrientation(
'', 1, 0);
1007 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1009 if (!empty($tplidx)) {
1010 $pdf->useTemplate($tplidx);
1014 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
1016 if ($pagenb == $pageposafter) {
1017 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1019 $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);
1024 if (!empty($tplidx)) {
1025 $pdf->useTemplate($tplidx);
1029 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1036 if ($pagenb == $pageposbeforeprintlines) {
1037 $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);
1038 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1040 $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);
1041 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1045 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1048 $posy = $this->
drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1051 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1057 if (method_exists($pdf,
'AliasNbPages')) {
1058 $pdf->AliasNbPages();
1066 $pdf->Output($file,
'F');
1069 $hookmanager->initHooks(array(
'pdfgeneration'));
1070 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
1072 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1074 $this->error = $hookmanager->error;
1075 $this->errors = $hookmanager->errors;
1080 $this->result = array(
'fullpath'=>$file);
1084 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1088 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1247 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1249 global $conf, $mysoc;
1253 $pdf->SetFont(
'',
'', $default_font_size - 1);
1256 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1257 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1258 $pdf->SetXY($this->marge_gauche, $posy);
1259 if ($mysoc->forme_juridique_code == 92) {
1260 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1262 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1265 $posy = $pdf->GetY() + 4;
1270 if ($this->page_largeur < 210) {
1275 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1276 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1277 $pdf->SetXY($this->marge_gauche, $posy);
1278 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1279 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1281 $pdf->SetFont(
'',
'', $default_font_size - 2);
1282 $pdf->SetXY($posxval, $posy);
1283 $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);
1284 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1285 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1287 $posy = $pdf->GetY() + 3;
1291 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1292 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1293 $pdf->SetXY($this->marge_gauche, $posy);
1294 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1295 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1297 $pdf->SetFont(
'',
'', $default_font_size - 2);
1298 $pdf->SetXY($posxval, $posy);
1299 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1300 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1302 $posy = $pdf->GetY() + 3;
1305 if ($object->type != 2) {
1307 if (empty($object->mode_reglement_code)
1310 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1311 } elseif (($object->mode_reglement_code ==
'CHQ' && !
getDolGlobalInt(
'FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1312 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1314 $outputlangs->load(
"errors");
1316 $pdf->SetXY($this->marge_gauche, $posy);
1317 $pdf->SetTextColor(200, 0, 0);
1318 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1319 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1320 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1321 $pdf->SetTextColor(0, 0, 0);
1323 $posy = $pdf->GetY() + 1;
1327 if (!empty($object->mode_reglement_code)
1328 && $object->mode_reglement_code !=
'CHQ'
1329 && $object->mode_reglement_code !=
'VIR') {
1330 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1331 $pdf->SetXY($this->marge_gauche, $posy);
1332 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1333 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1335 $pdf->SetFont(
'',
'', $default_font_size - 2);
1336 $pdf->SetXY($posxval, $posy);
1337 $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);
1340 if ($object->mode_reglement_code ==
"PRE") {
1341 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1343 $bac->fetch(0, $object->thirdparty->id);
1344 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1345 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1348 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1350 $posy = $pdf->GetY();
1356 if ($this->emetteur->country_code ==
'FR') {
1357 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1358 $pdf->SetXY($this->marge_gauche, $posy);
1359 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1361 $posy = $pdf->GetY() + 1;
1366 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1367 $useonlinepayment = 0;
1368 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1369 if (isModEnabled(
'paypal')) {
1370 $useonlinepayment++;
1372 if (isModEnabled(
'stripe')) {
1373 $useonlinepayment++;
1375 if (isModEnabled(
'paybox')) {
1376 $useonlinepayment++;
1382 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1385 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1386 $servicename = $langs->transnoentities(
'Online');
1387 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1388 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1390 $pdf->SetXY($this->marge_gauche, $posy);
1391 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1393 $posy = $pdf->GetY() + 1;
1398 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1401 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1403 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1404 $account =
new Account($this->db);
1407 $pdf->SetXY($this->marge_gauche, $posy);
1408 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1409 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1410 $posy = $pdf->GetY() + 1;
1412 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1413 $pdf->SetXY($this->marge_gauche, $posy);
1414 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1415 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1416 $posy = $pdf->GetY() + 2;
1419 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
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', $this->emetteur->name), 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($this->emetteur->getFullAddress()), 0,
'L', 0);
1429 $posy = $pdf->GetY() + 2;
1436 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1437 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1438 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1439 if ($object->fk_bank > 0) {
1440 $bankid = $object->fk_bank;
1442 $account =
new Account($this->db);
1443 $account->fetch($bankid);
1445 $curx = $this->marge_gauche;
1448 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1470 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1472 global $conf, $mysoc, $hookmanager;
1475 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1483 if (is_object($outputlangsbis)) {
1484 $pdf->SetFont(
'',
'', $default_font_size - 2);
1486 $pdf->SetFont(
'',
'', $default_font_size - 1);
1492 if ($this->page_largeur < 210) {
1496 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1502 $parameters = array(
1503 'object' => &$object,
1504 'outputlangs' => $outputlangs,
1506 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1511 foreach ($object->lines as $line) {
1512 if ($line->product_type != 9) {
1513 $percent += $line->situation_percent;
1519 $avancementGlobal = $percent / $i;
1521 $avancementGlobal = 0;
1524 $object->fetchPreviousNextSituationInvoice();
1525 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1528 $total_a_payer_ttc = 0;
1529 foreach ($TPreviousIncoice as &$fac) {
1530 $total_a_payer += $fac->total_ht;
1531 $total_a_payer_ttc += $fac->total_ttc;
1533 $total_a_payer += $object->total_ht;
1534 $total_a_payer_ttc += $object->total_ttc;
1536 if (!empty($avancementGlobal)) {
1537 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1538 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1541 $total_a_payer_ttc = 0;
1545 if (!empty($TPreviousIncoice)) {
1546 $pdf->setY($tab2_top);
1547 $posy = $pdf->GetY();
1549 foreach ($TPreviousIncoice as &$fac) {
1550 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1554 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1555 $pdf->setY($this->tab_top_newpage);
1557 $pdf->setY($this->marge_haute);
1559 $posy = $pdf->GetY();
1564 $pdf->SetFillColor(255, 255, 255);
1565 $pdf->SetXY($col1x, $posy);
1566 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1568 $pdf->SetXY($col2x, $posy);
1572 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1575 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1577 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1586 $pdf->SetFillColor(255, 255, 255);
1587 $pdf->SetXY($col1x, $posy);
1588 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1590 $pdf->SetXY($col2x, $posy);
1593 $facSign = $object->total_ht >= 0 ?
'+' :
'';
1601 $displayAmount =
' '.$facSign.
' '.
price($object->total_ht, 0, $outputlangs);
1602 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1607 $pdf->SetFont(
'',
'', $default_font_size - 1);
1608 $pdf->SetFillColor(255, 255, 255);
1609 $pdf->SetXY($col1x, $posy);
1610 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1612 $pdf->SetXY($col2x, $posy);
1613 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1614 $pdf->SetFont(
'',
'', $default_font_size - 2);
1618 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1621 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1622 $pdf->setY($this->tab_top_newpage);
1624 $pdf->setY($this->marge_haute);
1627 $posy = $pdf->GetY();
1638 $total_ht = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1641 $total_line_remise = 0;
1642 foreach ($object->lines as $i => $line) {
1644 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1646 if ($line->total_ht < 0) {
1647 $total_line_remise += -$line->total_ht;
1650 if ($total_line_remise > 0) {
1651 if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
1652 $pdf->SetFillColor(255, 255, 255);
1653 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1654 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1655 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1656 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1661 if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
1662 $pdf->SetFillColor(255, 255, 255);
1663 $pdf->SetXY($col1x, $tab2_top);
1664 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1665 $pdf->SetXY($col2x, $tab2_top);
1666 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1673 $pdf->SetFillColor(255, 255, 255);
1674 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1675 $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);
1677 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1678 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1679 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1682 $pdf->SetFillColor(248, 248, 248);
1684 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1686 $this->atleastoneratenotnull = 0;
1687 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1688 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1689 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1695 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1696 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1700 foreach ($localtax_rate as $tvakey => $tvaval) {
1705 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1708 if (preg_match(
'/\*/', $tvakey)) {
1709 $tvakey = str_replace(
'*',
'', $tvakey);
1710 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1713 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1715 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1716 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1718 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1720 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1721 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1729 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1730 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1734 foreach ($localtax_rate as $tvakey => $tvaval) {
1739 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1742 if (preg_match(
'/\*/', $tvakey)) {
1743 $tvakey = str_replace(
'*',
'', $tvakey);
1744 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1746 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1748 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1749 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1751 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1753 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1754 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1761 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1763 foreach ($this->tva as $tvakey => $tvaval) {
1764 $sum_pdf_tva += $tvaval;
1767 if ($sum_pdf_tva != $object->total_tva) {
1768 if (!empty($sum_pdf_tva)) {
1769 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1775 foreach ($this->tva as $tvakey => $tvaval) {
1776 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1778 foreach ($this->tva_array as $tvakey => $tvaval) {
1779 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1785 foreach ($this->tva_array as $tvakey => $tvaval) {
1787 $this->atleastoneratenotnull++;
1790 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1793 if (preg_match(
'/\*/', $tvakey)) {
1794 $tvakey = str_replace(
'*',
'', $tvakey);
1795 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1797 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1800 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1802 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1804 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1806 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1808 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1809 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1816 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1817 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1821 foreach ($localtax_rate as $tvakey => $tvaval) {
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1829 if (preg_match(
'/\*/', $tvakey)) {
1830 $tvakey = str_replace(
'*',
'', $tvakey);
1831 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1833 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1835 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1837 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1839 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1841 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1842 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1850 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1851 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1855 foreach ($localtax_rate as $tvakey => $tvaval) {
1861 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1864 if (preg_match(
'/\*/', $tvakey)) {
1865 $tvakey = str_replace(
'*',
'', $tvakey);
1866 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1868 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1871 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1872 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1874 $total_localtax = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ?
price2num($tvaval * $object->multicurrency_tx,
'MT') : $tvaval);
1876 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1877 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1884 if (
price2num($object->revenuestamp) != 0) {
1886 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1887 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
1889 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1890 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1895 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1896 $pdf->SetTextColor(0, 0, 60);
1897 $pdf->SetFillColor(224, 224, 224);
1898 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1900 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1901 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1905 if ($object->displayRetainedWarranty()) {
1906 $pdf->SetTextColor(40, 40, 40);
1907 $pdf->SetFillColor(255, 255, 255);
1909 $retainedWarranty = $object->getRetainedWarrantyAmount();
1910 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1914 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1915 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1917 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1918 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1922 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1924 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.$object->retained_warranty.
'%)';
1925 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1927 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1928 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1929 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1934 $pdf->SetTextColor(0, 0, 0);
1936 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1937 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1939 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1940 if (!empty($object->paye)) {
1944 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1947 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
1949 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1950 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1953 if ($creditnoteamount) {
1954 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1955 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes")) :
'');
1957 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1958 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1959 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1960 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1979 $pdf->SetTextColor(0, 0, 60);
1980 $pdf->SetFillColor(224, 224, 224);
1981 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1982 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1983 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1984 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1986 $pdf->SetFont(
'',
'', $default_font_size - 1);
1987 $pdf->SetTextColor(0, 0, 0);
1991 return ($tab2_top + ($tab2_hl * $index));
2087 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
2089 global $conf, $langs;
2091 $ltrdirection =
'L';
2092 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
2095 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2101 $pdf->SetTextColor(0, 0, 60);
2102 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2106 $posy = $this->marge_haute;
2107 $posx = $this->page_largeur - $this->marge_droite - $w;
2109 $pdf->SetXY($this->marge_gauche, $posy);
2113 if ($this->emetteur->logo) {
2114 $logodir = $conf->mycompany->dir_output;
2115 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2116 $logodir = $conf->mycompany->multidir_output[$object->entity];
2119 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2121 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2123 if (is_readable($logo)) {
2125 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2127 $pdf->SetTextColor(200, 0, 0);
2128 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2129 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2130 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2133 $text = $this->emetteur->name;
2134 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2138 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2139 $pdf->SetXY($posx, $posy);
2140 $pdf->SetTextColor(0, 0, 60);
2141 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2142 if ($object->type == 1) {
2143 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2145 if ($object->type == 2) {
2146 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2148 if ($object->type == 3) {
2149 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2151 if ($object->type == 4) {
2152 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2154 if ($this->situationinvoice) {
2155 $langs->loadLangs(array(
"other"));
2156 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") . $object->situation_counter .
" -";
2158 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2160 if ($object->type == 0) {
2161 if ($this->situationinvoice) {
2162 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2164 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2165 } elseif ($object->type == 1) {
2166 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2167 } elseif ($object->type == 2) {
2168 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2169 } elseif ($object->type == 3) {
2170 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2171 } elseif ($object->type == 4) {
2172 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2175 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
2176 if ($object->statut == $object::STATUS_DRAFT) {
2177 $pdf->SetTextColor(128, 0, 0);
2178 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2181 $pdf->MultiCell($w, 3, $title,
'',
'R');
2183 $pdf->SetFont(
'',
'B', $default_font_size);
2197 $pdf->SetFont(
'',
'', $default_font_size - 2);
2199 if ($object->ref_customer) {
2201 $pdf->SetXY($posx, $posy);
2202 $pdf->SetTextColor(0, 0, 60);
2203 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65),
'',
'R');
2206 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
2207 $object->fetch_projet();
2208 if (!empty($object->project->ref)) {
2210 $pdf->SetXY($posx, $posy);
2211 $pdf->SetTextColor(0, 0, 60);
2212 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
2216 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
2217 $object->fetch_projet();
2218 if (!empty($object->project->ref)) {
2219 $outputlangs->load(
"projects");
2221 $pdf->SetXY($posx, $posy);
2222 $pdf->SetTextColor(0, 0, 60);
2223 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
2227 $objectidnext = $object->getIdReplacingInvoice(
'validated');
2228 if ($object->type == 0 && $objectidnext) {
2229 $objectreplacing =
new Facture($this->db);
2230 $objectreplacing->fetch($objectidnext);
2233 $pdf->SetXY($posx, $posy);
2234 $pdf->SetTextColor(0, 0, 60);
2235 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2237 if ($object->type == 1) {
2238 $objectreplaced =
new Facture($this->db);
2239 $objectreplaced->fetch($object->fk_facture_source);
2242 $pdf->SetXY($posx, $posy);
2243 $pdf->SetTextColor(0, 0, 60);
2244 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2246 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2247 $objectreplaced =
new Facture($this->db);
2248 $objectreplaced->fetch($object->fk_facture_source);
2251 $pdf->SetXY($posx, $posy);
2252 $pdf->SetTextColor(0, 0, 60);
2253 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2257 $pdf->SetXY($posx, $posy);
2258 $pdf->SetTextColor(0, 0, 60);
2260 $title = $outputlangs->transnoentities(
"DateInvoice");
2261 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2262 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2264 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2266 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2268 $pdf->SetXY($posx, $posy);
2269 $pdf->SetTextColor(0, 0, 60);
2270 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2273 if ($object->type != 2) {
2275 $pdf->SetXY($posx, $posy);
2276 $pdf->SetTextColor(0, 0, 60);
2277 $title = $outputlangs->transnoentities(
"DateDue");
2278 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2279 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2281 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2284 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2286 $pdf->SetXY($posx, $posy);
2287 $pdf->SetTextColor(0, 0, 60);
2288 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2292 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2293 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2294 if (count($arrayidcontact) > 0) {
2295 $usertmp =
new User($this->db);
2296 $usertmp->fetch($arrayidcontact[0]);
2298 $pdf->SetXY($posx, $posy);
2299 $pdf->SetTextColor(0, 0, 60);
2300 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2309 $current_y = $pdf->getY();
2310 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2311 if ($current_y < $pdf->getY()) {
2312 $top_shift = $pdf->getY() - $current_y;
2317 $carac_emetteur =
'';
2319 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
2320 if (count($arrayidcontact) > 0) {
2321 $object->fetch_user($arrayidcontact[0]);
2322 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2323 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2324 $carac_emetteur .=
"\n";
2327 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2330 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2331 $posy += $top_shift;
2332 $posx = $this->marge_gauche;
2333 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2334 $posx = $this->page_largeur - $this->marge_droite - 80;
2337 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2338 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2341 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2342 $pdf->SetTextColor(0, 0, 0);
2343 $pdf->SetFont(
'',
'', $default_font_size - 2);
2344 $pdf->SetXY($posx, $posy - 5);
2345 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2346 $pdf->SetXY($posx, $posy);
2347 $pdf->SetFillColor(230, 230, 230);
2348 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2349 $pdf->SetTextColor(0, 0, 60);
2353 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2354 $pdf->SetXY($posx + 2, $posy + 3);
2355 $pdf->SetFont(
'',
'B', $default_font_size);
2356 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2357 $posy = $pdf->getY();
2361 $pdf->SetXY($posx + 2, $posy);
2362 $pdf->SetFont(
'',
'', $default_font_size - 1);
2363 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2366 $usecontact =
false;
2367 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2368 if (count($arrayidcontact) > 0) {
2370 $result = $object->fetch_contact($arrayidcontact[0]);
2374 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)))) {
2375 $thirdparty = $object->contact;
2377 $thirdparty = $object->thirdparty;
2383 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2386 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2387 if ($this->page_largeur < 210) {
2390 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2391 $posy += $top_shift;
2392 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2393 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2394 $posx = $this->marge_gauche;
2398 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2399 $pdf->SetTextColor(0, 0, 0);
2400 $pdf->SetFont(
'',
'', $default_font_size - 2);
2401 $pdf->SetXY($posx + 2, $posy - 5);
2402 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2403 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2407 $pdf->SetXY($posx + 2, $posy + 3);
2408 $pdf->SetFont(
'',
'B', $default_font_size);
2409 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2411 $posy = $pdf->getY();
2414 $pdf->SetFont(
'',
'', $default_font_size - 1);
2415 $pdf->SetXY($posx + 2, $posy);
2416 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2420 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2422 if (!empty($idaddressshipping)) {
2423 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2424 $companystatic =
new Societe($this->db);
2425 $companystatic->fetch($object->contact->fk_soc);
2427 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2430 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2432 if (!empty($carac_client_shipping)) {
2433 $posy += $hautcadre;
2436 $pdf->SetXY($posx + 2, $posy - 5);
2437 $pdf->SetFont(
'',
'', $default_font_size - 2);
2438 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2439 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2442 $pdf->SetXY($posx + 2, $posy + 3);
2443 $pdf->SetFont(
'',
'B', $default_font_size);
2444 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2446 $posy = $pdf->getY();
2449 $pdf->SetXY($posx+2, $posy);
2450 $pdf->SetFont(
'',
'', $default_font_size - 1);
2451 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2452 $shipp_shift += $hautcadre;
2457 $pdf->SetTextColor(0, 0, 0);
2459 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);