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) {
195 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
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])) {
259 $logodir =
$conf->mycompany->multidir_output[
$object->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->getFullName($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);
313 if (isModEnabled(
'incoterm')) {
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;
367 for ($i = 0; $i < $nblines; $i++) {
369 $pdf->SetFont(
'',
'', $default_font_size - 1);
370 $pdf->SetTextColor(0, 0, 0);
378 $pdf->setTopMargin($tab_top_newpage);
379 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
380 $pageposbefore = $pdf->getPage();
382 $showpricebeforepagebreak = 1;
386 $curX = $this->posxdesc - 1;
388 $pdf->startTransaction();
389 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
390 $pageposafter = $pdf->getPage();
391 if ($pageposafter > $pageposbefore) {
392 $pdf->rollbackTransaction(
true);
393 $pageposafter = $pageposbefore;
395 $pdf->setPageOrientation(
'',
true, $heightforfooter);
396 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
397 $posyafter = $pdf->GetY();
398 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
399 if ($i == ($nblines - 1)) {
400 $pdf->AddPage(
'',
'',
true);
401 if (!empty($tplidx)) {
402 $pdf->useTemplate($tplidx);
407 $pdf->setPage($pageposafter + 1);
413 $showpricebeforepagebreak = 1;
415 $showpricebeforepagebreak = 0;
419 $pdf->commitTransaction();
421 $posYAfterDescription = $pdf->GetY();
423 $nexY = $pdf->GetY();
424 $pageposafter = $pdf->getPage();
425 $pdf->setPage($pageposbefore);
426 $pdf->setTopMargin($this->marge_haute);
427 $pdf->setPageOrientation(
'',
true, 0);
430 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
431 $pdf->setPage($pageposafter);
432 $curY = $tab_top_newpage;
435 $pdf->SetFont(
'',
'', $default_font_size - 1);
440 $pdf->SetXY($this->posxtva, $curY);
441 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
446 $pdf->SetXY($this->posxup, $curY);
447 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R',
false);
451 $pdf->SetXY($this->posxqty, $curY);
452 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
457 $pdf->SetXY($this->posxunit, $curY);
458 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
462 if (
$object->lines[$i]->remise_percent) {
463 $pdf->SetXY($this->posxdiscount - 2, $curY);
465 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
470 $pdf->SetXY($this->postotalht, $curY);
471 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R',
false);
474 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
475 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
477 $tvaligne =
$object->lines[$i]->total_tva;
480 $localtax1ligne =
$object->lines[$i]->total_localtax1;
481 $localtax2ligne =
$object->lines[$i]->total_localtax2;
488 $vatrate = (string)
$object->lines[$i]->tva_tx;
489 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
490 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
492 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
495 if (empty($this->tva[$vatrate])) {
496 $this->tva[$vatrate] = 0;
498 if (empty($this->localtax1[$localtax1rate])) {
499 $this->localtax1[$localtax1rate] = 0;
501 if (empty($this->localtax2[$localtax2rate])) {
502 $this->localtax2[$localtax2rate] = 0;
504 $this->tva[$vatrate] += $tvaligne;
505 $this->localtax1[$localtax1rate] += $localtax1ligne;
506 $this->localtax2[$localtax2rate] += $localtax2ligne;
508 if ($posYAfterImage > $posYAfterDescription) {
509 $nexY = $posYAfterImage;
514 $pdf->setPage($pageposafter);
515 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
517 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
518 $pdf->SetLineStyle(array(
'dash' => 0));
524 while ($pagenb < $pageposafter) {
525 $pdf->setPage($pagenb);
527 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
529 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
533 $pdf->setPage($pagenb);
534 $pdf->setPageOrientation(
'',
true, 0);
539 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
541 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
543 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
548 if (!empty($tplidx)) {
549 $pdf->useTemplate($tplidx);
560 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
561 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
563 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
564 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
570 $amount_credit_notes_included = 0;
571 $amount_deposits_included = 0;
574 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
580 if (method_exists($pdf,
'AliasNbPages')) {
581 $pdf->AliasNbPages();
586 $pdf->Output($file,
'F');
589 $hookmanager->initHooks(array(
'pdfgeneration'));
590 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
592 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
594 $this->error = $hookmanager->error;
595 $this->errors = $hookmanager->errors;
600 $this->result = array(
'fullpath' => $file);
604 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
608 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
628 global
$conf, $mysoc, $hookmanager;
639 $pdf->SetFont(
'',
'', $default_font_size - 1);
644 if ($this->page_largeur < 210) {
647 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
653 $pdf->SetFillColor(255, 255, 255);
654 $pdf->SetXY($col1x, $tab2_top);
655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
657 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
658 $pdf->SetXY($col2x, $tab2_top);
659 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R',
true);
662 $pdf->SetFillColor(248, 248, 248);
664 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
666 $this->atleastoneratenotnull = 0;
667 foreach ($this->tva as $tvakey => $tvaval) {
669 $this->atleastoneratenotnull++;
672 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
676 if (preg_match(
'/\*/', $tvakey)) {
677 $tvakey = str_replace(
'*',
'', $tvakey);
678 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
681 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
682 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
683 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
685 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
686 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
689 if (!$this->atleastoneratenotnull) {
691 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
692 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L',
true);
693 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
694 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R',
true);
699 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L',
true);
701 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
702 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R',
true);
708 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
709 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L',
true);
710 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
711 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R',
true);
717 foreach ($this->localtax1 as $tvakey => $tvaval) {
722 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
725 if (preg_match(
'/\*/', (
string) $tvakey)) {
726 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
727 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
729 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
730 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
731 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
733 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
734 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R',
true);
742 foreach ($this->localtax2 as $tvakey => $tvaval) {
747 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
750 if (preg_match(
'/\*/', (
string) $tvakey)) {
751 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
752 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
754 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
755 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
756 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
758 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
759 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R',
true);
767 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
768 $pdf->SetTextColor(0, 0, 60);
769 $pdf->SetFillColor(224, 224, 224);
770 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L',
true);
772 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
773 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
775 $pdf->SetTextColor(0, 0, 0);
776 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
777 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
779 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
784 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
787 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
788 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L',
false);
789 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
790 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
793 if ($creditnoteamount) {
794 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
796 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
797 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
798 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
799 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
803 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
805 $pdf->SetFillColor(255, 255, 255);
807 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
808 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L',
true);
809 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
810 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R',
true);
816 $pdf->SetTextColor(0, 0, 60);
817 $pdf->SetFillColor(224, 224, 224);
818 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L',
true);
821 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
822 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
823 $pdf->SetFont(
'',
'', $default_font_size - 1);
824 $pdf->SetTextColor(0, 0, 0);
827 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
829 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
831 $this->error = $hookmanager->error;
832 $this->errors = $hookmanager->errors;
836 return ($tab2_top + ($tab2_hl * $index));
853 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
863 $currency = !empty($currency) ? $currency :
$conf->currency;
867 $pdf->SetTextColor(0, 0, 0);
868 $pdf->SetFont(
'',
'', $default_font_size - 2);
870 if (empty($hidetop)) {
871 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
872 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
873 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
877 $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')));
881 $pdf->SetDrawColor(128, 128, 128);
882 $pdf->SetFont(
'',
'', $default_font_size - 1);
885 $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');
887 if (empty($hidetop)) {
888 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
890 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
891 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
895 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
896 if (empty($hidetop)) {
897 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
898 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
902 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
903 if (empty($hidetop)) {
904 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
905 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
908 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
909 if (empty($hidetop)) {
910 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
911 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
915 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
916 if (empty($hidetop)) {
917 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
919 $this->posxdiscount - $this->posxunit - 1,
921 $outputlangs->transnoentities(
"Unit"),
928 if ($this->atleastonediscount) {
929 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
930 if (empty($hidetop)) {
931 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
932 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
936 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
937 if (empty($hidetop)) {
938 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
939 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
966 $tab3_top = $posy + 8;
969 if ($this->page_largeur < 210) {
975 $pdf->SetFont(
'',
'', $default_font_size - 3);
976 $pdf->SetXY($tab3_posx, $tab3_top - 4);
977 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L',
false);
979 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
981 $pdf->SetFont(
'',
'', $default_font_size - 4);
982 $pdf->SetXY($tab3_posx, $tab3_top);
983 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
984 $pdf->SetXY($tab3_posx + 21, $tab3_top);
985 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
986 $pdf->SetXY($tab3_posx + 40, $tab3_top);
987 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
988 $pdf->SetXY($tab3_posx + 58, $tab3_top);
989 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
991 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
995 $pdf->SetFont(
'',
'', $default_font_size - 4);
1001 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1003 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
1004 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1005 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
1006 $sql .=
" ORDER BY p.datep";
1007 $resql = $this->db->query($sql);
1009 $num = $this->db->num_rows($resql);
1013 $row = $this->db->fetch_object($resql);
1015 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1016 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1017 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1018 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L',
false);
1019 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1020 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1022 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1023 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1024 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L',
false);
1026 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1031 $this->error = $this->db->lasterror();
1049 global $langs,
$conf, $mysoc;
1052 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1059 $pdf->SetTextColor(0, 0, 60);
1060 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1064 $posy = $this->marge_haute;
1065 $posx = $this->page_largeur - $this->marge_droite - 100;
1067 $pdf->SetXY($this->marge_gauche, $posy);
1089 $text = $this->emetteur->name;
1090 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1093 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1094 $pdf->SetXY($posx, $posy);
1095 $pdf->SetTextColor(0, 0, 60);
1096 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1098 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1101 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1104 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1106 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1111 $pdf->SetFont(
'',
'B', $default_font_size);
1112 $pdf->SetXY($posx, $posy);
1113 $pdf->SetTextColor(0, 0, 60);
1114 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1118 $pdf->SetFont(
'',
'', $default_font_size - 1);
1122 if (!empty(
$object->project->ref)) {
1124 $pdf->SetXY($posx, $posy);
1125 $pdf->SetTextColor(0, 0, 60);
1126 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1132 if (!empty(
$object->project->ref)) {
1133 $outputlangs->load(
"projects");
1135 $pdf->SetXY($posx, $posy);
1136 $langs->load(
"projects");
1137 $pdf->SetTextColor(0, 0, 60);
1138 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1144 $pdf->SetXY($posx, $posy);
1145 $pdf->SetTextColor(0, 0, 60);
1146 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1149 $pdf->SetXY($posx, $posy);
1150 $pdf->SetTextColor(255, 0, 0);
1151 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1154 if (
$object->thirdparty->code_fournisseur) {
1156 $pdf->SetXY($posx, $posy);
1157 $pdf->SetTextColor(0, 0, 60);
1158 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_fournisseur),
'',
'R');
1162 $pdf->SetTextColor(0, 0, 60);
1166 $current_y = $pdf->getY();
1168 if ($current_y < $pdf->getY()) {
1169 $top_shift = $pdf->getY() - $current_y;
1174 $carac_emetteur =
'';
1176 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1177 if (count($arrayidcontact) > 0) {
1178 $object->fetch_user($arrayidcontact[0]);
1179 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1180 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1182 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1186 $carac_emetteur .=
"\n";
1192 $posy = 42 + $top_shift;
1193 $posx = $this->marge_gauche;
1195 $posx = $this->page_largeur - $this->marge_droite - 80;
1200 $pdf->SetTextColor(0, 0, 0);
1201 $pdf->SetFont(
'',
'', $default_font_size - 2);
1202 $pdf->SetXY($posx, $posy - 5);
1203 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1204 $pdf->SetXY($posx, $posy);
1205 $pdf->SetFillColor(230, 230, 230);
1206 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
1207 $pdf->SetTextColor(0, 0, 60);
1210 $pdf->SetXY($posx + 2, $posy + 3);
1211 $pdf->SetFont(
'',
'B', $default_font_size);
1212 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1213 $posy = $pdf->getY();
1216 $pdf->SetXY($posx + 2, $posy);
1217 $pdf->SetFont(
'',
'', $default_font_size - 1);
1218 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1223 $usecontact =
false;
1224 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1225 if (count($arrayidcontact) > 0) {
1227 $result =
$object->fetch_contact($arrayidcontact[0]);
1231 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1232 $thirdparty =
$object->contact;
1234 $thirdparty = $mysoc;
1243 if ($this->page_largeur < 210) {
1246 $posy = 42 + $top_shift;
1247 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1249 $posx = $this->marge_gauche;
1253 $pdf->SetTextColor(0, 0, 0);
1254 $pdf->SetFont(
'',
'', $default_font_size - 2);
1255 $pdf->SetXY($posx + 2, $posy - 5);
1256 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1257 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1260 $pdf->SetXY($posx + 2, $posy + 3);
1261 $pdf->SetFont(
'',
'B', $default_font_size);
1262 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1264 $posy = $pdf->getY();
1267 $pdf->SetFont(
'',
'', $default_font_size - 1);
1268 $pdf->SetXY($posx + 2, $posy);
1269 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');