163 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
166 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
169 if (!is_object(
$object->thirdparty)) {
172 if (!is_object(
$object->thirdparty)) {
176 $this->emetteur =
$object->thirdparty;
177 if (!$this->emetteur->country_code) {
178 $this->emetteur->country_code = substr($langs->defaultlang, -2);
181 if (!is_object($outputlangs)) {
182 $outputlangs = $langs;
186 $outputlangs->charset_output =
'ISO-8859-1';
190 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
192 $nblines = count(
$object->lines);
194 if (
$conf->fournisseur->facture->dir_output) {
196 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
197 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
201 $dir =
$conf->fournisseur->facture->dir_output;
202 $file = $dir.
"/SPECIMEN.pdf";
207 $file = $dir.
"/".$objectref.
".pdf";
209 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
213 if (!file_exists($dir)) {
215 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
220 if (file_exists($dir)) {
222 if (!is_object($hookmanager)) {
223 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
226 $hookmanager->initHooks(array(
'pdfgeneration'));
227 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
229 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
232 $nblines = count(
$object->lines);
233 $nbpayments = count(
$object->getListOfPayments());
238 $pdf->setAutoPageBreak(
true, 0);
240 $heightforinfotot = 50 + (4 * $nbpayments);
241 if ($heightforinfotot > 220) {
242 $heightforinfotot = 220;
245 $heightforfooter = $this->marge_basse + 8;
247 $heightforfooter += 6;
250 if (class_exists(
'TCPDF')) {
251 $pdf->setPrintHeader(
false);
252 $pdf->setPrintFooter(
false);
257 $logodir =
$conf->mycompany->dir_output;
258 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
261 $pagecount = $pdf->setSourceFile($logodir .
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
262 $tplidx = $pdf->importPage(1);
267 $pdf->SetDrawColor(128, 128, 128);
269 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
270 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
271 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
272 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
273 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
275 $pdf->SetCompression(
false);
279 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
282 for ($i = 0; $i < $nblines; $i++) {
283 if (
$object->lines[$i]->remise_percent) {
284 $this->atleastonediscount++;
287 if (empty($this->atleastonediscount)) {
288 $delta = ($this->postotalht - $this->posxdiscount);
289 $this->posxpicture += $delta;
290 $this->posxtva += $delta;
291 $this->posxup += $delta;
292 $this->posxqty += $delta;
293 $this->posxunit += $delta;
294 $this->posxdiscount += $delta;
300 if (!empty($tplidx)) {
301 $pdf->useTemplate($tplidx);
305 $pdf->SetFont(
'',
'', $default_font_size - 1);
306 $pdf->MultiCell(0, 3,
'');
307 $pdf->SetTextColor(0, 0, 0);
309 $tab_top = 90 + $top_shift;
310 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
314 $desc_incoterms =
$object->getIncotermsForPDF();
315 if ($desc_incoterms) {
318 $pdf->SetFont(
'',
'', $default_font_size - 1);
319 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
320 $nexY = $pdf->GetY();
321 $height_incoterms = $nexY - $tab_top;
324 $pdf->SetDrawColor(192, 192, 192);
325 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
327 $tab_top = $nexY + 6;
332 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
336 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
337 if (!empty($extranote)) {
350 $pdf->SetFont(
'',
'', $default_font_size - 1);
351 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
352 $nexY = $pdf->GetY();
353 $height_note = $nexY - $tab_top;
356 $pdf->SetDrawColor(192, 192, 192);
357 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
359 $tab_top = $nexY + 6;
362 $iniY = $tab_top + 7;
363 $curY = $tab_top + 7;
364 $nexY = $tab_top + 7;
366 'titleshowuponpdf' => 1,
367 'titleshowtotalexludingvatonpdf' => 1,
371 for ($i = 0; $i < $nblines; $i++) {
372 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
374 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
375 $level =
$object->lines[$i]->qty;
377 if (isset($sub_options[
'titleshowuponpdf'])) {
378 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
379 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
380 unset($pdf_sub_options[
'titleshowuponpdf']);
382 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
383 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
384 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
385 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
388 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
389 unset($pdf_sub_options[
'titleshowuponpdf']);
391 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
392 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
397 $pdf->SetFont(
'',
'', $default_font_size - 1);
398 $pdf->SetTextColor(0, 0, 0);
406 $pdf->setTopMargin($tab_top_newpage);
407 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
408 $pageposbefore = $pdf->getPage();
410 $showpricebeforepagebreak = 1;
414 $curX = $this->posxdesc - 1;
416 $pdf->startTransaction();
417 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
418 $pageposafter = $pdf->getPage();
419 if ($pageposafter > $pageposbefore) {
420 $pdf->rollbackTransaction(
true);
421 $pageposafter = $pageposbefore;
423 $pdf->setPageOrientation(
'',
true, $heightforfooter);
424 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
425 $posyafter = $pdf->GetY();
426 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
427 if ($i == ($nblines - 1)) {
428 $pdf->AddPage(
'',
'',
true);
429 if (!empty($tplidx)) {
430 $pdf->useTemplate($tplidx);
435 $pdf->setPage($pageposafter + 1);
441 $showpricebeforepagebreak = 1;
443 $showpricebeforepagebreak = 0;
447 $pdf->commitTransaction();
449 $posYAfterDescription = $pdf->GetY();
451 $nexY = $pdf->GetY();
452 $pageposafter = $pdf->getPage();
453 $pdf->setPage($pageposbefore);
454 $pdf->setTopMargin($this->marge_haute);
455 $pdf->setPageOrientation(
'',
true, 0);
458 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
459 $pdf->setPage($pageposafter);
460 $curY = $tab_top_newpage;
463 $pdf->SetFont(
'',
'', $default_font_size - 1);
466 if (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
468 $pdf->SetXY($this->posxtva, $curY);
469 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
473 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
475 $pdf->SetXY($this->posxup, $curY);
476 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R',
false);
480 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
482 $pdf->SetXY($this->posxqty, $curY);
483 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
489 $pdf->SetXY($this->posxunit, $curY);
490 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
494 if (
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
495 $pdf->SetXY($this->posxdiscount - 2, $curY);
497 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
501 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
503 $pdf->SetXY($this->postotalht, $curY);
504 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R',
false);
505 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
507 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
509 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
511 $pdf->SetXY($this->postotalht, $curY);
512 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R',
false);
517 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
519 $tvaligne =
$object->lines[$i]->total_tva;
522 $localtax1ligne =
$object->lines[$i]->total_localtax1;
523 $localtax2ligne =
$object->lines[$i]->total_localtax2;
525 $vatrate = (string)
$object->lines[$i]->tva_tx;
526 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
527 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
529 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
532 if (empty($this->tva[$vatrate])) {
533 $this->tva[$vatrate] = 0;
535 if (empty($this->localtax1[$localtax1rate])) {
536 $this->localtax1[$localtax1rate] = 0;
538 if (empty($this->localtax2[$localtax2rate])) {
539 $this->localtax2[$localtax2rate] = 0;
541 $this->tva[$vatrate] += $tvaligne;
542 $this->localtax1[$localtax1rate] += $localtax1ligne;
543 $this->localtax2[$localtax2rate] += $localtax2ligne;
545 if ($posYAfterImage > $posYAfterDescription) {
546 $nexY = $posYAfterImage;
551 $pdf->setPage($pageposafter);
552 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
554 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
555 $pdf->SetLineStyle(array(
'dash' => 0));
561 while ($pagenb < $pageposafter) {
562 $pdf->setPage($pagenb);
564 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
566 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
570 $pdf->setPage($pagenb);
571 $pdf->setPageOrientation(
'',
true, 0);
576 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
578 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
580 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
585 if (!empty($tplidx)) {
586 $pdf->useTemplate($tplidx);
597 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
598 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
600 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
601 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
607 $amount_credit_notes_included = 0;
608 $amount_deposits_included = 0;
611 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
617 if (method_exists($pdf,
'AliasNbPages')) {
618 $pdf->AliasNbPages();
623 $pdf->Output($file,
'F');
626 $hookmanager->initHooks(array(
'pdfgeneration'));
627 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
629 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
630 $this->warnings = $hookmanager->warnings;
632 $this->error = $hookmanager->error;
633 $this->errors = $hookmanager->errors;
640 $this->result = array(
'fullpath' => $file);
644 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
648 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
679 $pdf->SetFont(
'',
'', $default_font_size - 1);
684 if ($this->page_largeur < 210) {
687 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
693 $pdf->SetFillColor(255, 255, 255);
694 $pdf->SetXY($col1x, $tab2_top);
695 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
698 $pdf->SetXY($col2x, $tab2_top);
699 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R',
true);
702 $pdf->SetFillColor(248, 248, 248);
706 $this->atleastoneratenotnull = 0;
707 foreach ($this->tva as $tvakey => $tvaval) {
709 $this->atleastoneratenotnull++;
712 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
716 if (preg_match(
'/\*/', $tvakey)) {
717 $tvakey = str_replace(
'*',
'', $tvakey);
718 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
721 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).
' ';
722 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
723 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
725 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
726 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
729 if (!$this->atleastoneratenotnull) {
731 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
732 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code), 0,
'L',
true);
733 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
734 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R',
true);
739 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
740 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code), 0,
'L',
true);
741 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
742 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R',
true);
748 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
749 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code), 0,
'L',
true);
750 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
751 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R',
true);
757 foreach ($this->localtax1 as $tvakey => $tvaval) {
762 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
765 if (preg_match(
'/\*/', (
string) $tvakey)) {
766 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
767 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
769 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).
' ';
770 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
771 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
773 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
774 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R',
true);
782 foreach ($this->localtax2 as $tvakey => $tvaval) {
787 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
790 if (preg_match(
'/\*/', (
string) $tvakey)) {
791 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
792 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
794 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).
' ';
795 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
796 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
798 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
799 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R',
true);
807 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
808 $pdf->SetTextColor(0, 0, 60);
809 $pdf->SetFillColor(224, 224, 224);
810 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L',
true);
812 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
813 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
815 $pdf->SetTextColor(0, 0, 0);
816 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
819 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
824 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
827 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
828 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L',
false);
829 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
830 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
833 if ($creditnoteamount) {
834 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
836 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
837 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
838 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
839 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
843 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
845 $pdf->SetFillColor(255, 255, 255);
847 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
848 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L',
true);
849 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
850 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R',
true);
856 $pdf->SetTextColor(0, 0, 60);
857 $pdf->SetFillColor(224, 224, 224);
858 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
859 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L',
true);
861 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
862 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
863 $pdf->SetFont(
'',
'', $default_font_size - 1);
864 $pdf->SetTextColor(0, 0, 0);
867 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
869 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
871 $this->error = $hookmanager->error;
872 $this->errors = $hookmanager->errors;
876 return ($tab2_top + ($tab2_hl * $index));
893 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
903 $currency = !empty($currency) ? $currency :
$conf->currency;
907 $pdf->SetTextColor(0, 0, 0);
908 $pdf->SetFont(
'',
'', $default_font_size - 2);
910 if (empty($hidetop)) {
911 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
912 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
913 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
917 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
921 $pdf->SetDrawColor(128, 128, 128);
922 $pdf->SetFont(
'',
'', $default_font_size - 1);
925 $this->
printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
927 if (empty($hidetop)) {
928 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
930 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
931 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
935 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
936 if (empty($hidetop)) {
937 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
938 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
942 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
943 if (empty($hidetop)) {
944 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
945 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
948 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
949 if (empty($hidetop)) {
950 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
951 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
955 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
956 if (empty($hidetop)) {
957 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
959 $this->posxdiscount - $this->posxunit - 1,
961 $outputlangs->transnoentities(
"Unit"),
968 if ($this->atleastonediscount) {
969 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
970 if (empty($hidetop)) {
971 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
972 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
976 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
977 if (empty($hidetop)) {
978 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
979 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1006 $tab3_top = $posy + 8;
1009 if ($this->page_largeur < 210) {
1015 $pdf->SetFont(
'',
'', $default_font_size - 3);
1016 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1017 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L',
false);
1019 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1021 $pdf->SetFont(
'',
'', $default_font_size - 4);
1022 $pdf->SetXY($tab3_posx, $tab3_top);
1023 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1024 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1025 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1026 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1027 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1028 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1029 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1031 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1035 $pdf->SetFont(
'',
'', $default_font_size - 4);
1041 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
1044 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1045 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
1046 $sql .=
" ORDER BY p.datep";
1047 $resql = $this->db->query($sql);
1049 $num = $this->db->num_rows($resql);
1053 $row = $this->db->fetch_object($resql);
1055 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1056 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1057 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1058 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L',
false);
1059 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1060 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1062 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1063 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1064 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L',
false);
1066 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1071 $this->error = $this->db->lasterror();
1092 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1099 $pdf->SetTextColor(0, 0, 60);
1100 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1104 $posy = $this->marge_haute;
1105 $posx = $this->page_largeur - $this->marge_droite - 100;
1107 $pdf->SetXY($this->marge_gauche, $posy);
1129 $text = $this->emetteur->name;
1130 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1133 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1134 $pdf->SetXY($posx, $posy);
1135 $pdf->SetTextColor(0, 0, 60);
1136 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1138 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1141 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1144 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1146 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1151 $pdf->SetFont(
'',
'B', $default_font_size);
1152 $pdf->SetXY($posx, $posy);
1153 $pdf->SetTextColor(0, 0, 60);
1154 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1158 $pdf->SetFont(
'',
'', $default_font_size - 1);
1162 if (!empty(
$object->project->ref)) {
1164 $pdf->SetXY($posx, $posy);
1165 $pdf->SetTextColor(0, 0, 60);
1166 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
pdf_truncate_text($pdf,
$object->project->title, 50)),
'',
'R');
1172 if (!empty(
$object->project->ref)) {
1173 $outputlangs->load(
"projects");
1175 $pdf->SetXY($posx, $posy);
1176 $langs->load(
"projects");
1177 $pdf->SetTextColor(0, 0, 60);
1178 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1184 $pdf->SetXY($posx, $posy);
1185 $pdf->SetTextColor(0, 0, 60);
1186 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1189 $pdf->SetXY($posx, $posy);
1190 $pdf->SetTextColor(255, 0, 0);
1191 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1194 if (
$object->thirdparty->code_fournisseur) {
1196 $pdf->SetXY($posx, $posy);
1197 $pdf->SetTextColor(0, 0, 60);
1198 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_fournisseur),
'',
'R');
1202 $pdf->SetTextColor(0, 0, 60);
1206 $current_y = $pdf->getY();
1208 if ($current_y < $pdf->getY()) {
1209 $top_shift = $pdf->getY() - $current_y;
1214 $carac_emetteur =
'';
1216 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1217 if (count($arrayidcontact) > 0) {
1218 $object->fetch_user($arrayidcontact[0]);
1219 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1220 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1222 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1226 $carac_emetteur .=
"\n";
1232 $posy = 42 + $top_shift;
1233 $posx = $this->marge_gauche;
1235 $posx = $this->page_largeur - $this->marge_droite - 80;
1240 $pdf->SetTextColor(0, 0, 0);
1241 $pdf->SetFont(
'',
'', $default_font_size - 2);
1242 $pdf->SetXY($posx, $posy - 5);
1243 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1244 $pdf->SetXY($posx, $posy);
1245 $pdf->SetFillColor(230, 230, 230);
1246 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
1247 $pdf->SetTextColor(0, 0, 60);
1250 $pdf->SetXY($posx + 2, $posy + 3);
1251 $pdf->SetFont(
'',
'B', $default_font_size);
1252 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1253 $posy = $pdf->getY();
1256 $pdf->SetXY($posx + 2, $posy);
1257 $pdf->SetFont(
'',
'', $default_font_size - 1);
1258 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1263 $usecontact =
false;
1264 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1265 if (count($arrayidcontact) > 0) {
1267 $result =
$object->fetch_contact($arrayidcontact[0]);
1271 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1272 $thirdparty =
$object->contact;
1283 if ($this->page_largeur < 210) {
1286 $posy = 42 + $top_shift;
1287 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1289 $posx = $this->marge_gauche;
1293 $pdf->SetTextColor(0, 0, 0);
1294 $pdf->SetFont(
'',
'', $default_font_size - 2);
1295 $pdf->SetXY($posx + 2, $posy - 5);
1296 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1297 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1300 $pdf->SetXY($posx + 2, $posy + 3);
1301 $pdf->SetFont(
'',
'B', $default_font_size);
1302 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1304 $posy = $pdf->getY();
1307 $pdf->SetFont(
'',
'', $default_font_size - 1);
1308 $pdf->SetXY($posx + 2, $posy);
1309 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');