204 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
207 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
209 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
211 if (!is_object($outputlangs)) {
212 $outputlangs = $langs;
216 $outputlangs->charset_output =
'ISO-8859-1';
220 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
222 global $outputlangsbis;
223 $outputlangsbis =
null;
227 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
235 $nblines = count(
$object->lines);
243 $realpatharray = array();
244 $this->atleastonephoto =
false;
246 $objphoto =
new Product($this->db);
248 for ($i = 0; $i < $nblines; $i++) {
249 if (empty(
$object->lines[$i]->fk_product)) {
253 $objphoto->fetch(
$object->lines[$i]->fk_product);
257 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
258 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
260 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
261 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
265 foreach ($pdir as $midir) {
267 if (
$conf->entity != $objphoto->entity) {
268 $dir =
$conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
270 $dir =
$conf->product->dir_output.
'/'.$midir;
273 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
275 if ($obj[
'photo_vignette']) {
276 $filename = $obj[
'photo_vignette'];
278 $filename = $obj[
'photo'];
281 $filename = $obj[
'photo'];
284 $realpath = $dir.$filename;
286 $this->atleastonephoto =
true;
291 if ($realpath && $arephoto) {
292 $realpatharray[$i] = $realpath;
299 if (
$conf->facture->multidir_output[
$conf->entity]) {
302 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
304 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
308 $dir =
$conf->facture->multidir_output[
$conf->entity];
309 $file = $dir.
"/SPECIMEN.pdf";
312 $dir =
$conf->facture->multidir_output[
$object->entity].
"/".$objectref;
313 $file = $dir.
"/".$objectref.
".pdf";
315 if (!file_exists($dir)) {
317 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
322 if (file_exists($dir)) {
324 if (!is_object($hookmanager)) {
325 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
328 $hookmanager->initHooks(array(
'pdfgeneration'));
329 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
331 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
334 $nblines = count(
$object->lines);
335 $nbpayments = count(
$object->getListOfPayments());
340 $pdf->SetAutoPageBreak(1, 0);
342 $this->heightforinfotot = 50 + (4 * $nbpayments);
343 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
344 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
346 $heightforqrinvoice = $heightforqrinvoice_firstpage = 0;
350 $this->heightforinfotot = 30 + (4 * $nbpayments);
354 if (class_exists(
'TCPDF')) {
355 $pdf->setPrintHeader(
false);
356 $pdf->setPrintFooter(
false);
362 $logodir =
$conf->mycompany->dir_output;
363 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
364 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
366 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
367 $tplidx = $pdf->importPage(1);
372 $pdf->SetDrawColor(128, 128, 128);
374 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
375 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
376 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
377 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
378 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
380 $pdf->SetCompression(
false);
384 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
385 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
396 'Name' => $this->emetteur->name,
397 'Location' =>
getCountry($this->emetteur->country_code,
''),
398 'Reason' =>
'INVOICE',
399 'ContactInfo' => $this->emetteur->email
401 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
405 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
409 $categoryOfOperation = 0;
412 for ($i = 0; $i < $nblines; $i++) {
413 if (
$object->lines[$i]->remise_percent) {
414 $this->atleastonediscount++;
418 if ($categoryOfOperation < 2) {
419 $lineProductType =
$object->lines[$i]->product_type;
425 if ($nbProduct > 0 && $nbService > 0) {
427 $categoryOfOperation = 2;
432 if ($categoryOfOperation <= 0) {
434 if ($nbProduct == 0 && $nbService > 0) {
435 $categoryOfOperation = 1;
438 $this->categoryOfOperation = $categoryOfOperation;
441 if (
$object->situation_cycle_ref) {
442 $this->situationinvoice =
true;
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
453 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
454 $top_shift = $pagehead[
'top_shift'];
455 $shipp_shift = $pagehead[
'shipp_shift'];
456 $pdf->SetFont(
'',
'', $default_font_size - 1);
457 $pdf->MultiCell(0, 3,
'');
458 $pdf->SetTextColor(0, 0, 0);
463 $this->tab_top = 90 + $top_shift + $shipp_shift;
464 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
467 $extra_under_address_shift = 0;
470 $qrcodestring =
$object->buildZATCAQRString();
473 $qrcodestring =
$object->buildSwitzerlandQRString();
477 $qrcodestring =
$object->buildEPCQrCodeString();
482 $qrcodecolor = array(
'25',
'25',
'25');
487 'fgcolor' => $qrcodecolor,
492 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
496 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
497 $pdf->SetFont(
'',
'', $default_font_size - 4);
498 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
502 $extra_under_address_shift += 25;
510 'outputlangs' => $outputlangs,
511 'hidedetails' => $hidedetails
513 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
514 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
515 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
518 $this->tab_top += $extra_under_address_shift;
519 $this->tab_top_newpage += 0;
523 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
525 $nexY = $this->tab_top - 1;
528 $height_incoterms = 0;
529 if (isModEnabled(
'incoterm')) {
530 $desc_incoterms =
$object->getIncotermsForPDF();
531 if ($desc_incoterms) {
534 $pdf->SetFont(
'',
'', $default_font_size - 1);
535 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
536 $nexY = max($pdf->GetY(), $nexY);
537 $height_incoterms = $nexY - $this->tab_top;
540 $pdf->SetDrawColor(192, 192, 192);
541 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
543 $this->tab_top = $nexY + 6;
544 $height_incoterms += 4;
549 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
552 if (is_object(
$object->thirdparty)) {
553 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
554 $salerepobj =
new User($this->db);
555 $salerepobj->fetch($salereparray[0][
'id']);
556 if (!empty($salerepobj->signature)) {
557 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
563 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
564 if (!empty($extranote)) {
568 $pagenb = $pdf->getPage();
572 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
573 $pageposbeforenote = $pagenb;
580 $pdf->startTransaction();
582 $pdf->SetFont(
'',
'', $default_font_size - 1);
583 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
585 $pageposafternote = $pdf->getPage();
586 $posyafter = $pdf->GetY();
588 if ($pageposafternote > $pageposbeforenote) {
589 $pdf->rollbackTransaction(
true);
592 while ($pagenb < $pageposafternote) {
595 if (!empty($tplidx)) {
596 $pdf->useTemplate($tplidx);
601 $pdf->setTopMargin($this->tab_top_newpage);
603 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
607 $pdf->setPage($pageposbeforenote);
608 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
609 $pdf->SetFont(
'',
'', $default_font_size - 1);
610 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
611 $pageposafternote = $pdf->getPage();
613 $posyafter = $pdf->GetY();
615 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
616 $pdf->AddPage(
'',
'',
true);
619 $pdf->setPage($pageposafternote);
620 $pdf->setTopMargin($this->tab_top_newpage);
622 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
628 $i = $pageposbeforenote;
629 while ($i < $pageposafternote) {
633 $pdf->SetDrawColor(128, 128, 128);
635 if ($i > $pageposbeforenote) {
636 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
637 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
639 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
640 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
644 $pdf->setPageOrientation(
'', 1, 0);
651 $pdf->setPage($pageposafternote);
652 if (!empty($tplidx)) {
653 $pdf->useTemplate($tplidx);
658 $height_note = $posyafter - $this->tab_top_newpage;
659 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
662 $pdf->commitTransaction();
663 $posyafter = $pdf->GetY();
664 $height_note = $posyafter - $this->tab_top;
665 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
668 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
670 $pdf->AddPage(
'',
'',
true);
673 $pdf->setPage($pageposafternote);
674 if (!empty($tplidx)) {
675 $pdf->useTemplate($tplidx);
681 $posyafter = $this->tab_top_newpage;
685 $tab_height -= $height_note;
686 $this->tab_top = $posyafter + 6;
695 $pdf->startTransaction();
696 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
697 $pdf->rollbackTransaction(
true);
699 $nexY = $this->tab_top + $this->tabTitleHeight;
702 $pageposbeforeprintlines = $pdf->getPage();
703 $pagenb = $pageposbeforeprintlines;
704 for ($i = 0; $i < $nblines; $i++) {
706 $pdf->SetFont(
'',
'', $default_font_size - 1);
707 $pdf->SetTextColor(0, 0, 0);
710 $imglinesize = array();
711 if (!empty($realpatharray[$i])) {
715 $pdf->setTopMargin($this->tab_top_newpage);
716 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
717 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
718 $pageposbefore = $pdf->getPage();
720 $showpricebeforepagebreak = 1;
722 $posYAfterDescription = 0;
726 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
727 $pdf->AddPage(
'',
'',
true);
728 if (!empty($tplidx)) {
729 $pdf->useTemplate($tplidx);
731 $pdf->setPage($pageposbefore + 1);
733 $curY = $this->tab_top_newpage;
737 $showpricebeforepagebreak = 1;
739 $showpricebeforepagebreak = 0;
743 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
744 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
746 $posYAfterImage = $curY + $imglinesize[
'height'];
752 $pdf->startTransaction();
755 $pageposafter = $pdf->getPage();
757 if ($pageposafter > $pageposbefore) {
758 $pdf->rollbackTransaction(
true);
759 $pageposafter = $pageposbefore;
760 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
764 $pageposafter = $pdf->getPage();
765 $posyafter = $pdf->GetY();
767 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
768 if ($i == ($nblines - 1)) {
769 $pdf->AddPage(
'',
'',
true);
770 if (!empty($tplidx)) {
771 $pdf->useTemplate($tplidx);
773 $pdf->setPage($pageposafter + 1);
779 $showpricebeforepagebreak = 1;
781 $showpricebeforepagebreak = 0;
785 $pdf->commitTransaction();
787 $posYAfterDescription = $pdf->GetY();
790 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
792 $pageposafter = $pdf->getPage();
793 $pdf->setPage($pageposbefore);
794 $pdf->setTopMargin($this->marge_haute);
795 $pdf->setPageOrientation(
'', 1, 0);
798 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
799 $pdf->setPage($pageposafter);
800 $curY = $this->tab_top_newpage;
803 $pdf->SetFont(
'',
'', $default_font_size - 1);
814 $nexY = max($pdf->GetY(), $nexY);
821 $nexY = max($pdf->GetY(), $nexY);
829 $nexY = max($pdf->GetY(), $nexY);
836 $nexY = max($pdf->GetY(), $nexY);
843 $nexY = max($pdf->GetY(), $nexY);
850 $nexY = max($pdf->GetY(), $nexY);
857 $nexY = max($pdf->GetY(), $nexY);
864 $nexY = max($pdf->GetY(), $nexY);
868 if (!empty(
$object->lines[$i]->array_options)) {
869 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
873 $nexY = max($pdf->GetY(), $nexY);
885 'outputlangs' => $outputlangs,
886 'hidedetails' => $hidedetails
888 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
896 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
897 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
898 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
899 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
901 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
904 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
905 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
907 $tvaligne = $sign *
$object->lines[$i]->total_tva;
911 $localtax1ligne =
$object->lines[$i]->total_localtax1;
912 $localtax2ligne =
$object->lines[$i]->total_localtax2;
913 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
914 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
915 $localtax1_type =
$object->lines[$i]->localtax1_type;
916 $localtax2_type =
$object->lines[$i]->localtax2_type;
929 $vatrate = (string)
$object->lines[$i]->tva_tx;
932 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
933 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
935 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
936 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
940 if ($localtax1_type && $localtax1ligne != 0) {
941 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
942 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
944 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
947 if ($localtax2_type && $localtax2ligne != 0) {
948 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
949 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
951 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
955 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
960 if (!isset($this->tva[$vatrate])) {
961 $this->tva[$vatrate] = 0;
963 $this->tva[$vatrate] += $tvaligne;
964 $vatcode =
$object->lines[$i]->vat_src_code;
966 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
967 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
969 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne,
'tot_ht'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'] +
$object->lines[$i]->total_ht);
971 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
972 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
974 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
977 $nexY = max($nexY, $posYAfterImage);
981 $pdf->setPage($pageposafter);
982 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
984 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
985 $pdf->SetLineStyle(array(
'dash' => 0));
989 while ($pagenb < $pageposafter) {
990 $pdf->setPage($pagenb);
992 if ($pagenb == $pageposbeforeprintlines) {
993 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
995 $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);
999 $pdf->setPage($pagenb);
1000 $pdf->setPageOrientation(
'', 1, 0);
1004 if (!empty($tplidx)) {
1005 $pdf->useTemplate($tplidx);
1009 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1011 if ($pagenb == $pageposafter) {
1012 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1014 $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);
1019 if (!empty($tplidx)) {
1020 $pdf->useTemplate($tplidx);
1031 if ($pagenb == $pageposbeforeprintlines) {
1032 $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);
1033 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1035 $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);
1036 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1043 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1046 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1047 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1053 if (method_exists($pdf,
'AliasNbPages')) {
1054 $pdf->AliasNbPages();
1057 if (!empty($mysoc->termsofsale) &&
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
1058 $termsofsale =
$conf->mycompany->dir_output.
'/'.$mysoc->termsofsale;
1059 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
1060 $termsofsale =
$conf->mycompany->multidir_output[
$object->entity].
'/'.$mysoc->termsofsale;
1062 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1063 $pagecount = $pdf->setSourceFile($termsofsale);
1064 for ($i = 1; $i <= $pagecount; $i++) {
1065 $tplIdx = $pdf->importPage($i);
1066 if ($tplIdx!==
false) {
1067 $s = $pdf->getTemplatesize($tplIdx);
1068 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1069 $pdf->useTemplate($tplIdx);
1071 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1083 $pdf->Output($file,
'F');
1086 $hookmanager->initHooks(array(
'pdfgeneration'));
1087 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1089 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1091 $this->error = $hookmanager->error;
1092 $this->errors = $hookmanager->errors;
1097 $this->result = array(
'fullpath' => $file);
1101 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1105 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1265 global
$conf, $mysoc, $hookmanager;
1269 $pdf->SetFont(
'',
'', $default_font_size - 1);
1271 krsort($this->tva_array);
1275 $pdf->SetFillColor(224, 224, 224);
1277 $pdf->SetFont(
'',
'', $default_font_size - 2);
1278 $pdf->SetXY($this->marge_gauche, $posy);
1279 $titre = $outputlangs->transnoentities(
"VAT");
1280 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1282 $pdf->SetFont(
'',
'', $default_font_size - 2);
1283 $pdf->SetXY($this->marge_gauche + 25, $posy);
1284 $titre = $outputlangs->transnoentities(
"NetTotal");
1285 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1287 $pdf->SetFont(
'',
'', $default_font_size - 2);
1288 $pdf->SetXY($this->marge_gauche + 50, $posy);
1289 $titre = $outputlangs->transnoentities(
"VATAmount");
1290 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1292 $pdf->SetFont(
'',
'', $default_font_size - 2);
1293 $pdf->SetXY($this->marge_gauche + 75, $posy);
1294 $titre = $outputlangs->transnoentities(
"AmountTotal");
1295 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1297 $posy = $pdf->GetY();
1302 foreach ($this->tva_array as $tvakey => $tvaval) {
1303 $pdf->SetFont(
'',
'', $default_font_size - 2);
1304 $pdf->SetXY($this->marge_gauche, $posy);
1305 $titre = round((
float) $tvakey, 2) .
"%";
1306 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1308 $pdf->SetFont(
'',
'', $default_font_size - 2);
1309 $pdf->SetXY($this->marge_gauche + 25, $posy);
1310 $titre =
price($tvaval[
'tot_ht']);
1311 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1312 $tot_ht += $tvaval[
'tot_ht'];
1314 $pdf->SetFont(
'',
'', $default_font_size - 2);
1315 $pdf->SetXY($this->marge_gauche + 50, $posy);
1316 $titre =
price($tvaval[
'amount']);
1317 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1318 $tot_tva += $tvaval[
'amount'];
1320 $pdf->SetFont(
'',
'', $default_font_size - 2);
1321 $pdf->SetXY($this->marge_gauche + 75, $posy);
1322 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1323 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1324 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1326 $posy = $pdf->GetY();
1331 if ($this->emetteur->country_code ==
'FR' && empty(
$object->total_tva) && (empty($mysoc->tva_assuj) || ($this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()))) {
1332 $pdf->SetFont(
'',
'', $default_font_size - 2);
1333 $pdf->SetXY($this->marge_gauche, $posy);
1334 if ($mysoc->forme_juridique_code == 92) {
1335 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1337 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1340 $posy = $pdf->GetY() + 4;
1345 if ($this->page_largeur < 210) {
1351 $pdf->SetFont(
'',
'', $default_font_size - 2);
1352 $pdf->SetXY($this->marge_gauche, $posy);
1353 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1354 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1356 $pdf->SetFont(
'',
'', $default_font_size - 2);
1357 $pdf->SetXY($posxval, $posy);
1358 $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);
1359 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1360 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1362 $posy = $pdf->GetY() + 3;
1366 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1367 $pdf->SetFont(
'',
'', $default_font_size - 2);
1368 $pdf->SetXY($this->marge_gauche, $posy);
1369 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1370 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1372 $pdf->SetFont(
'',
'', $default_font_size - 2);
1373 $pdf->SetXY($posxval, $posy);
1374 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1375 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1377 $posy = $pdf->GetY() + 3;
1382 if (empty(
$object->mode_reglement_code)
1385 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1389 $outputlangs->load(
"errors");
1391 $pdf->SetXY($this->marge_gauche, $posy);
1392 $pdf->SetTextColor(200, 0, 0);
1393 $pdf->SetFont(
'',
'', $default_font_size - 2);
1394 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1395 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1396 $pdf->SetTextColor(0, 0, 0);
1398 $posy = $pdf->GetY() + 1;
1402 if (!empty(
$object->mode_reglement_code)
1403 &&
$object->mode_reglement_code !=
'CHQ'
1404 &&
$object->mode_reglement_code !=
'VIR') {
1405 $pdf->SetFont(
'',
'', $default_font_size - 2);
1406 $pdf->SetXY($this->marge_gauche, $posy);
1407 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1408 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1410 $pdf->SetFont(
'',
'', $default_font_size - 2);
1411 $pdf->SetXY($posxval, $posy);
1412 $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);
1415 if (
$object->mode_reglement_code ==
"PRE") {
1416 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1419 $bac->fetch(0,
'',
$object->thirdparty->id);
1420 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1421 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1424 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1426 $posy = $pdf->GetY();
1432 if ($this->emetteur->country_code ==
'FR') {
1434 $pdf->SetXY($this->marge_gauche, $posy);
1435 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1437 $posy = $pdf->GetY() + 1;
1442 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1443 $useonlinepayment = 0;
1447 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1448 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1449 $useonlinepayment = count($validpaymentmethod);
1454 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1457 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1458 $servicename = $langs->transnoentities(
'Online');
1459 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1460 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1462 $pdf->SetXY($this->marge_gauche, $posy);
1463 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1465 $posy = $pdf->GetY() + 1;
1470 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1476 $account =
new Account($this->db);
1479 $pdf->SetXY($this->marge_gauche, $posy);
1480 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1481 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L', 0);
1482 $posy = $pdf->GetY() + 1;
1485 $pdf->SetXY($this->marge_gauche, $posy);
1486 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1487 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1488 $posy = $pdf->GetY() + 2;
1491 if (
$conf->global->FACTURE_CHQ_NUMBER == -1) {
1492 $pdf->SetXY($this->marge_gauche, $posy);
1493 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1494 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1495 $posy = $pdf->GetY() + 1;
1498 $pdf->SetXY($this->marge_gauche, $posy);
1499 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1500 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1501 $posy = $pdf->GetY() + 2;
1508 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1514 $account =
new Account($this->db);
1515 $account->fetch($bankid);
1517 $curx = $this->marge_gauche;
1520 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1528 $qrCodeColor = array(
'25',
'25',
'25');
1532 'fgcolor' => $qrCodeColor,
1534 'module_width' => 1,
1535 'module_height' => 1
1538 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1539 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr,
'N');
1541 $pdf->SetXY($qrPosX + 30, $posy + 5);
1542 $pdf->SetFont(
'',
'', $default_font_size - 5);
1543 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
1544 $posy = $pdf->GetY() + 2;
1549 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1552 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L', 0);
1575 global
$conf, $mysoc, $hookmanager;
1586 if (is_object($outputlangsbis)) {
1587 $pdf->SetFont(
'',
'', $default_font_size - 2);
1589 $pdf->SetFont(
'',
'', $default_font_size - 1);
1595 if ($this->page_largeur < 210) {
1599 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1605 $parameters = array(
1607 'outputlangs' => $outputlangs,
1609 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1614 foreach (
$object->lines as $line) {
1615 if ($line->product_type != 9) {
1616 $percent += $line->situation_percent;
1622 $avancementGlobal = $percent / $i;
1624 $avancementGlobal = 0;
1627 $object->fetchPreviousNextSituationInvoice();
1628 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1631 $total_a_payer_ttc = 0;
1632 foreach ($TPreviousIncoice as &$fac) {
1633 $total_a_payer += $fac->total_ht;
1634 $total_a_payer_ttc += $fac->total_ttc;
1636 $total_a_payer +=
$object->total_ht;
1637 $total_a_payer_ttc +=
$object->total_ttc;
1639 if (!empty($avancementGlobal)) {
1640 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1641 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1644 $total_a_payer_ttc = 0;
1648 if (!empty($TPreviousIncoice)) {
1649 $pdf->setY($tab2_top);
1650 $posy = $pdf->GetY();
1652 foreach ($TPreviousIncoice as &$fac) {
1653 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1658 $pdf->setY($this->tab_top_newpage);
1660 $pdf->setY($this->marge_haute);
1662 $posy = $pdf->GetY();
1667 $pdf->SetFillColor(255, 255, 255);
1668 $pdf->SetXY($col1x, $posy);
1669 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1671 $pdf->SetXY($col2x, $posy);
1675 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1678 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1680 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1689 $pdf->SetFillColor(255, 255, 255);
1690 $pdf->SetXY($col1x, $posy);
1691 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle",
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1693 $pdf->SetXY($col2x, $posy);
1696 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1704 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1705 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1710 $pdf->SetFont(
'',
'', $default_font_size - 1);
1711 $pdf->SetFillColor(255, 255, 255);
1712 $pdf->SetXY($col1x, $posy);
1713 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1715 $pdf->SetXY($col2x, $posy);
1716 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1717 $pdf->SetFont(
'',
'', $default_font_size - 2);
1721 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1725 $pdf->setY($this->tab_top_newpage);
1727 $pdf->setY($this->marge_haute);
1730 $posy = $pdf->GetY();
1741 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1744 $total_line_remise = 0;
1745 foreach (
$object->lines as $i => $line) {
1747 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1749 if ($line->total_ht < 0) {
1750 $total_line_remise += -$line->total_ht;
1753 if ($total_line_remise > 0) {
1754 $pdf->SetFillColor(255, 255, 255);
1755 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1756 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1757 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1758 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1763 $pdf->SetFillColor(255, 255, 255);
1764 $pdf->SetXY($col1x, $tab2_top);
1765 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1766 $pdf->SetXY($col2x, $tab2_top);
1767 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1773 $pdf->SetFillColor(255, 255, 255);
1774 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1775 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total") :
''), 0,
'L', 1);
1777 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1778 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1779 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1783 $pdf->SetFillColor(255, 255, 255);
1784 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1785 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L', 1);
1787 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1788 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R', 1);
1792 $pdf->SetFillColor(248, 248, 248);
1794 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1796 $this->atleastoneratenotnull = 0;
1798 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1799 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1803 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1804 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1808 foreach ($localtax_rate as $tvakey => $tvaval) {
1813 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1816 if (preg_match(
'/\*/', (
string) $tvakey)) {
1817 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1818 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1821 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1825 $totalvat .= $tvacompl;
1827 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1830 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1832 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1834 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1835 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1841 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1842 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1846 foreach ($localtax_rate as $tvakey => $tvaval) {
1851 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1854 if (preg_match(
'/\*/', (
string) $tvakey)) {
1855 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1856 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1858 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1862 $totalvat .= $tvacompl;
1864 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1867 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1869 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1871 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1872 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1880 foreach ($this->tva as $tvakey => $tvaval) {
1881 $sum_pdf_tva += $tvaval;
1884 if ($sum_pdf_tva !=
$object->total_tva) {
1885 if (!empty($sum_pdf_tva)) {
1886 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
1892 foreach ($this->tva as $tvakey => $tvaval) {
1893 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1895 foreach ($this->tva_array as $tvakey => $tvaval) {
1896 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1903 foreach ($this->tva_array as $tvakey => $tvaval) {
1905 $this->atleastoneratenotnull++;
1908 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1911 if (preg_match(
'/\*/', $tvakey)) {
1912 $tvakey = str_replace(
'*',
'', $tvakey);
1913 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1915 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1918 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1920 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1922 $totalvat .= $tvacompl;
1924 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1926 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1928 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1929 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1935 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1936 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1940 foreach ($localtax_rate as $tvakey => $tvaval) {
1945 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948 if (preg_match(
'/\*/', (
string) $tvakey)) {
1949 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1950 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1952 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1956 $totalvat .= $tvacompl;
1958 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1961 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1963 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1965 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1966 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1972 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1973 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1977 foreach ($localtax_rate as $tvakey => $tvaval) {
1983 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1986 if (preg_match(
'/\*/', (
string) $tvakey)) {
1987 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1988 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1990 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1994 $totalvat .= $tvacompl;
1996 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1999 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
2001 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
2003 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2004 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
2012 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2013 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
2015 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2016 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R', 1);
2021 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2022 $pdf->SetTextColor(0, 0, 60);
2023 $pdf->SetFillColor(224, 224, 224);
2024 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
2026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2027 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
2031 if (
$object->displayRetainedWarranty()) {
2032 $pdf->SetTextColor(40, 40, 40);
2033 $pdf->SetFillColor(255, 255, 255);
2035 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2036 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2040 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2041 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L', 1);
2043 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2044 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
2048 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2050 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2051 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2053 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
2054 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2055 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
2060 $pdf->SetTextColor(0, 0, 0);
2062 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2063 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2065 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2070 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2073 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2074 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
2075 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2076 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
2079 if ($creditnoteamount) {
2080 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2081 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2083 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2084 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
2085 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2086 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
2089 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2091 $pdf->SetFillColor(255, 255, 255);
2093 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2094 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L', 1);
2095 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2096 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R', 1);
2102 $pdf->SetTextColor(0, 0, 60);
2103 $pdf->SetFillColor(224, 224, 224);
2104 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2105 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
2106 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2107 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
2109 $pdf->SetFont(
'',
'', $default_font_size - 1);
2110 $pdf->SetTextColor(0, 0, 0);
2113 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2115 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2117 $this->error = $hookmanager->error;
2118 $this->errors = $hookmanager->errors;
2122 return ($tab2_top + ($tab2_hl * $index));
2218 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2221 global
$conf, $langs;
2223 $ltrdirection =
'L';
2224 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2225 $ltrdirection =
'R';
2229 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2235 $pdf->SetTextColor(0, 0, 60);
2236 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2240 $posy = $this->marge_haute;
2241 $posx = $this->page_largeur - $this->marge_droite - $w;
2243 $pdf->SetXY($this->marge_gauche, $posy);
2247 if ($this->emetteur->logo) {
2248 $logodir =
$conf->mycompany->dir_output;
2249 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
2250 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
2253 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2255 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2257 if (is_readable($logo)) {
2259 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2261 $pdf->SetTextColor(200, 0, 0);
2262 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2263 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2264 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2267 $text = $this->emetteur->name;
2268 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2272 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2273 $pdf->SetXY($posx, $posy);
2274 $pdf->SetTextColor(0, 0, 60);
2275 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2277 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2280 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2283 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2286 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2288 if ($this->situationinvoice) {
2289 $langs->loadLangs(array(
"other"));
2290 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2292 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2295 if ($this->situationinvoice) {
2296 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2298 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2299 } elseif (
$object->type == 1) {
2300 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2301 } elseif (
$object->type == 2) {
2302 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2303 } elseif (
$object->type == 3) {
2304 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2305 } elseif (
$object->type == 4) {
2306 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2309 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2310 if (
$object->status == $object::STATUS_DRAFT) {
2311 $pdf->SetTextColor(128, 0, 0);
2312 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2315 $pdf->MultiCell($w, 3, $title,
'',
'R');
2317 $pdf->SetFont(
'',
'B', $default_font_size);
2331 $pdf->SetFont(
'',
'', $default_font_size - 2);
2335 $pdf->SetXY($posx, $posy);
2336 $pdf->SetTextColor(0, 0, 60);
2337 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2342 if (!empty(
$object->project->ref)) {
2344 $pdf->SetXY($posx, $posy);
2345 $pdf->SetTextColor(0, 0, 60);
2346 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2352 if (!empty(
$object->project->ref)) {
2353 $outputlangs->load(
"projects");
2355 $pdf->SetXY($posx, $posy);
2356 $pdf->SetTextColor(0, 0, 60);
2357 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2361 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2362 if (
$object->type == 0 && $objectidnext) {
2363 $objectreplacing =
new Facture($this->db);
2364 $objectreplacing->fetch($objectidnext);
2367 $pdf->SetXY($posx, $posy);
2368 $pdf->SetTextColor(0, 0, 60);
2369 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2372 $objectreplaced =
new Facture($this->db);
2373 $objectreplaced->fetch(
$object->fk_facture_source);
2376 $pdf->SetXY($posx, $posy);
2377 $pdf->SetTextColor(0, 0, 60);
2378 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2381 $objectreplaced =
new Facture($this->db);
2382 $objectreplaced->fetch(
$object->fk_facture_source);
2385 $pdf->SetXY($posx, $posy);
2386 $pdf->SetTextColor(0, 0, 60);
2387 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2391 $pdf->SetXY($posx, $posy);
2392 $pdf->SetTextColor(0, 0, 60);
2394 $title = $outputlangs->transnoentities(
"DateInvoice");
2395 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2396 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2398 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2402 $pdf->SetXY($posx, $posy);
2403 $pdf->SetTextColor(0, 0, 60);
2404 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2409 $pdf->SetXY($posx, $posy);
2410 $pdf->SetTextColor(0, 0, 60);
2411 $title = $outputlangs->transnoentities(
"DateDue");
2412 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2413 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2415 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2420 $pdf->SetXY($posx, $posy);
2421 $pdf->SetTextColor(0, 0, 60);
2422 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2427 $pdf->SetXY($posx, $posy);
2428 $pdf->SetTextColor(0, 0, 60);
2429 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2434 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2435 if (count($arrayidcontact) > 0) {
2436 $usertmp =
new User($this->db);
2437 $usertmp->fetch($arrayidcontact[0]);
2439 $pdf->SetXY($posx, $posy);
2440 $pdf->SetTextColor(0, 0, 60);
2441 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2450 $current_y = $pdf->getY();
2452 if ($current_y < $pdf->getY()) {
2453 $top_shift = $pdf->getY() - $current_y;
2458 $carac_emetteur =
'';
2460 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2461 if (count($arrayidcontact) > 0) {
2462 $object->fetch_user($arrayidcontact[0]);
2463 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2464 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2465 $carac_emetteur .=
"\n";
2472 $posy += $top_shift;
2473 $posx = $this->marge_gauche;
2475 $posx = $this->page_largeur - $this->marge_droite - 80;
2483 $pdf->SetTextColor(0, 0, 0);
2484 $pdf->SetFont(
'',
'', $default_font_size - 2);
2485 $pdf->SetXY($posx, $posy - 5);
2486 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2487 $pdf->SetXY($posx, $posy);
2488 $pdf->SetFillColor(230, 230, 230);
2489 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2490 $pdf->SetTextColor(0, 0, 60);
2495 $pdf->SetXY($posx + 2, $posy + 3);
2496 $pdf->SetFont(
'',
'B', $default_font_size);
2497 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2498 $posy = $pdf->getY();
2502 $pdf->SetXY($posx + 2, $posy);
2503 $pdf->SetFont(
'',
'', $default_font_size - 1);
2504 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2507 $usecontact =
false;
2508 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2509 if (count($arrayidcontact) > 0) {
2511 $result =
$object->fetch_contact($arrayidcontact[0]);
2515 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2516 $thirdparty =
$object->contact;
2518 $thirdparty =
$object->thirdparty;
2528 if ($this->page_largeur < 210) {
2532 $posy += $top_shift;
2533 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2535 $posx = $this->marge_gauche;
2540 $pdf->SetTextColor(0, 0, 0);
2541 $pdf->SetFont(
'',
'', $default_font_size - 2);
2542 $pdf->SetXY($posx + 2, $posy - 5);
2543 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2544 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2548 $pdf->SetXY($posx + 2, $posy + 3);
2549 $pdf->SetFont(
'',
'B', $default_font_size);
2551 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2553 $posy = $pdf->getY();
2556 $pdf->SetFont(
'',
'', $default_font_size - 1);
2557 $pdf->SetXY($posx + 2, $posy);
2559 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2563 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2565 if (!empty($idaddressshipping)) {
2566 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2567 $companystatic =
new Societe($this->db);
2568 $companystatic->fetch(
$object->contact->fk_soc);
2570 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic,
$object->contact, ($usecontact ? 1 : 0),
'target',
$object);
2575 if (!empty($carac_client_shipping)) {
2576 $posy += $hautcadre;
2581 $pdf->SetXY($posx + 2, $posy - 5);
2582 $pdf->SetFont(
'',
'', $default_font_size - 2);
2583 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2584 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2587 $pdf->SetXY($posx + 2, $posy + 3);
2588 $pdf->SetFont(
'',
'B', $default_font_size);
2589 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2591 $posy = $pdf->getY();
2594 $pdf->SetXY($posx + 2, $posy);
2595 $pdf->SetFont(
'',
'', $default_font_size - 1);
2596 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2598 $shipp_shift += $hautcadre + 10;
2603 $pdf->SetTextColor(0, 0, 0);
2605 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);