162 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
165 global $user, $langs,
$conf, $mysoc, $hookmanager, $nblines;
168 if (!is_object(
$object->thirdparty)) {
171 if (!is_object(
$object->thirdparty)) {
175 $this->emetteur =
$object->thirdparty;
176 if (!$this->emetteur->country_code) {
177 $this->emetteur->country_code = substr($langs->defaultlang, -2);
180 if (!is_object($outputlangs)) {
181 $outputlangs = $langs;
185 $outputlangs->charset_output =
'ISO-8859-1';
189 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
191 $nblines = count(
$object->lines);
193 if (
$conf->fournisseur->facture->dir_output) {
194 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
195 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
196 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
200 $dir =
$conf->fournisseur->facture->dir_output;
201 $file = $dir.
"/SPECIMEN.pdf";
206 $file = $dir.
"/".$objectref.
".pdf";
208 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
212 if (!file_exists($dir)) {
214 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
219 if (file_exists($dir)) {
221 if (!is_object($hookmanager)) {
222 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
225 $hookmanager->initHooks(array(
'pdfgeneration'));
226 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
228 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
231 $nblines = count(
$object->lines);
232 $nbpayments = count(
$object->getListOfPayments());
237 $pdf->SetAutoPageBreak(1, 0);
239 $heightforinfotot = 50 + (4 * $nbpayments);
240 if ($heightforinfotot > 220) {
241 $heightforinfotot = 220;
244 $heightforfooter = $this->marge_basse + 8;
246 $heightforfooter += 6;
249 if (class_exists(
'TCPDF')) {
250 $pdf->setPrintHeader(
false);
251 $pdf->setPrintFooter(
false);
256 $logodir =
$conf->mycompany->dir_output;
257 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
258 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
260 $pagecount = $pdf->setSourceFile($logodir .
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
261 $tplidx = $pdf->importPage(1);
266 $pdf->SetDrawColor(128, 128, 128);
268 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
269 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
270 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
271 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
272 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
274 $pdf->SetCompression(
false);
278 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
281 for ($i = 0; $i < $nblines; $i++) {
282 if (
$object->lines[$i]->remise_percent) {
283 $this->atleastonediscount++;
286 if (empty($this->atleastonediscount)) {
287 $delta = ($this->postotalht - $this->posxdiscount);
288 $this->posxpicture += $delta;
289 $this->posxtva += $delta;
290 $this->posxup += $delta;
291 $this->posxqty += $delta;
292 $this->posxunit += $delta;
293 $this->posxdiscount += $delta;
299 if (!empty($tplidx)) {
300 $pdf->useTemplate($tplidx);
304 $pdf->SetFont(
'',
'', $default_font_size - 1);
305 $pdf->MultiCell(0, 3,
'');
306 $pdf->SetTextColor(0, 0, 0);
308 $tab_top = 90 + $top_shift;
309 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
312 if (isModEnabled(
'incoterm')) {
313 $desc_incoterms =
$object->getIncotermsForPDF();
314 if ($desc_incoterms) {
317 $pdf->SetFont(
'',
'', $default_font_size - 1);
318 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
319 $nexY = $pdf->GetY();
320 $height_incoterms = $nexY - $tab_top;
323 $pdf->SetDrawColor(192, 192, 192);
324 $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');
326 $tab_top = $nexY + 6;
331 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
335 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
336 if (!empty($extranote)) {
349 $pdf->SetFont(
'',
'', $default_font_size - 1);
350 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
351 $nexY = $pdf->GetY();
352 $height_note = $nexY - $tab_top;
355 $pdf->SetDrawColor(192, 192, 192);
356 $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');
358 $tab_top = $nexY + 6;
361 $iniY = $tab_top + 7;
362 $curY = $tab_top + 7;
363 $nexY = $tab_top + 7;
366 for ($i = 0; $i < $nblines; $i++) {
368 $pdf->SetFont(
'',
'', $default_font_size - 1);
369 $pdf->SetTextColor(0, 0, 0);
377 $pdf->setTopMargin($tab_top_newpage);
378 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
379 $pageposbefore = $pdf->getPage();
381 $showpricebeforepagebreak = 1;
385 $curX = $this->posxdesc - 1;
387 $pdf->startTransaction();
388 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
389 $pageposafter = $pdf->getPage();
390 if ($pageposafter > $pageposbefore) {
391 $pdf->rollbackTransaction(
true);
392 $pageposafter = $pageposbefore;
394 $pdf->setPageOrientation(
'', 1, $heightforfooter);
395 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
396 $posyafter = $pdf->GetY();
397 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
398 if ($i == ($nblines - 1)) {
399 $pdf->AddPage(
'',
'',
true);
400 if (!empty($tplidx)) {
401 $pdf->useTemplate($tplidx);
406 $pdf->setPage($pageposafter + 1);
412 $showpricebeforepagebreak = 1;
414 $showpricebeforepagebreak = 0;
418 $pdf->commitTransaction();
420 $posYAfterDescription = $pdf->GetY();
422 $nexY = $pdf->GetY();
423 $pageposafter = $pdf->getPage();
424 $pdf->setPage($pageposbefore);
425 $pdf->setTopMargin($this->marge_haute);
426 $pdf->setPageOrientation(
'', 1, 0);
429 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
430 $pdf->setPage($pageposafter);
431 $curY = $tab_top_newpage;
434 $pdf->SetFont(
'',
'', $default_font_size - 1);
439 $pdf->SetXY($this->posxtva, $curY);
440 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
445 $pdf->SetXY($this->posxup, $curY);
446 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
450 $pdf->SetXY($this->posxqty, $curY);
451 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
456 $pdf->SetXY($this->posxunit, $curY);
457 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
461 if (
$object->lines[$i]->remise_percent) {
462 $pdf->SetXY($this->posxdiscount - 2, $curY);
464 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
469 $pdf->SetXY($this->postotalht, $curY);
470 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
473 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
474 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
476 $tvaligne =
$object->lines[$i]->total_tva;
479 $localtax1ligne =
$object->lines[$i]->total_localtax1;
480 $localtax2ligne =
$object->lines[$i]->total_localtax2;
487 $vatrate = (string)
$object->lines[$i]->tva_tx;
488 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
489 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
491 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
494 if (empty($this->tva[$vatrate])) {
495 $this->tva[$vatrate] = 0;
497 if (empty($this->localtax1[$localtax1rate])) {
498 $this->localtax1[$localtax1rate] = 0;
500 if (empty($this->localtax2[$localtax2rate])) {
501 $this->localtax2[$localtax2rate] = 0;
503 $this->tva[$vatrate] += $tvaligne;
504 $this->localtax1[$localtax1rate] += $localtax1ligne;
505 $this->localtax2[$localtax2rate] += $localtax2ligne;
507 if ($posYAfterImage > $posYAfterDescription) {
508 $nexY = $posYAfterImage;
513 $pdf->setPage($pageposafter);
514 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
516 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
517 $pdf->SetLineStyle(array(
'dash' => 0));
523 while ($pagenb < $pageposafter) {
524 $pdf->setPage($pagenb);
526 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
528 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
532 $pdf->setPage($pagenb);
533 $pdf->setPageOrientation(
'', 1, 0);
538 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
540 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
542 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
547 if (!empty($tplidx)) {
548 $pdf->useTemplate($tplidx);
559 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
560 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
562 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
563 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
569 $amount_credit_notes_included = 0;
570 $amount_deposits_included = 0;
573 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
579 if (method_exists($pdf,
'AliasNbPages')) {
580 $pdf->AliasNbPages();
585 $pdf->Output($file,
'F');
588 $hookmanager->initHooks(array(
'pdfgeneration'));
589 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
591 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
593 $this->error = $hookmanager->error;
594 $this->errors = $hookmanager->errors;
599 $this->result = array(
'fullpath' => $file);
603 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
607 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
627 global
$conf, $mysoc, $hookmanager;
638 $pdf->SetFont(
'',
'', $default_font_size - 1);
643 if ($this->page_largeur < 210) {
646 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
652 $pdf->SetFillColor(255, 255, 255);
653 $pdf->SetXY($col1x, $tab2_top);
654 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
656 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
657 $pdf->SetXY($col2x, $tab2_top);
658 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
661 $pdf->SetFillColor(248, 248, 248);
663 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
665 $this->atleastoneratenotnull = 0;
666 foreach ($this->tva as $tvakey => $tvaval) {
668 $this->atleastoneratenotnull++;
671 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
675 if (preg_match(
'/\*/', $tvakey)) {
676 $tvakey = str_replace(
'*',
'', $tvakey);
677 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
680 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
681 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
682 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
684 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
685 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
688 if (!$this->atleastoneratenotnull) {
690 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
691 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
692 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
693 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R', 1);
698 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
699 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
700 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
701 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
707 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
708 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
709 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
710 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
716 foreach ($this->localtax1 as $tvakey => $tvaval) {
721 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
724 if (preg_match(
'/\*/', (
string) $tvakey)) {
725 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
726 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
728 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
729 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
730 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
732 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
733 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R', 1);
741 foreach ($this->localtax2 as $tvakey => $tvaval) {
746 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
749 if (preg_match(
'/\*/', (
string) $tvakey)) {
750 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
751 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
753 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
754 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
755 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
757 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
758 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R', 1);
766 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
767 $pdf->SetTextColor(0, 0, 60);
768 $pdf->SetFillColor(224, 224, 224);
769 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
771 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
772 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
774 $pdf->SetTextColor(0, 0, 0);
775 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
776 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
778 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
783 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
786 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
787 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
788 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
789 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
792 if ($creditnoteamount) {
793 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
795 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
796 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
797 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
798 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
802 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
804 $pdf->SetFillColor(255, 255, 255);
806 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
807 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
808 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
809 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
815 $pdf->SetTextColor(0, 0, 60);
816 $pdf->SetFillColor(224, 224, 224);
817 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
818 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
820 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
821 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
822 $pdf->SetFont(
'',
'', $default_font_size - 1);
823 $pdf->SetTextColor(0, 0, 0);
826 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
828 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
830 $this->error = $hookmanager->error;
831 $this->errors = $hookmanager->errors;
835 return ($tab2_top + ($tab2_hl * $index));
852 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
862 $currency = !empty($currency) ? $currency :
$conf->currency;
866 $pdf->SetTextColor(0, 0, 0);
867 $pdf->SetFont(
'',
'', $default_font_size - 2);
869 if (empty($hidetop)) {
870 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
871 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
872 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
876 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
880 $pdf->SetDrawColor(128, 128, 128);
881 $pdf->SetFont(
'',
'', $default_font_size - 1);
884 $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');
886 if (empty($hidetop)) {
887 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
889 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
890 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
894 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
895 if (empty($hidetop)) {
896 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
897 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
901 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
902 if (empty($hidetop)) {
903 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
904 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
907 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
908 if (empty($hidetop)) {
909 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
910 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
914 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
915 if (empty($hidetop)) {
916 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
918 $this->posxdiscount - $this->posxunit - 1,
920 $outputlangs->transnoentities(
"Unit"),
927 if ($this->atleastonediscount) {
928 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
929 if (empty($hidetop)) {
930 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
931 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
935 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
936 if (empty($hidetop)) {
937 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
938 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
965 $tab3_top = $posy + 8;
968 if ($this->page_largeur < 210) {
974 $pdf->SetFont(
'',
'', $default_font_size - 3);
975 $pdf->SetXY($tab3_posx, $tab3_top - 4);
976 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
978 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
980 $pdf->SetFont(
'',
'', $default_font_size - 4);
981 $pdf->SetXY($tab3_posx, $tab3_top);
982 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
983 $pdf->SetXY($tab3_posx + 21, $tab3_top);
984 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
985 $pdf->SetXY($tab3_posx + 40, $tab3_top);
986 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
987 $pdf->SetXY($tab3_posx + 58, $tab3_top);
988 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
990 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
994 $pdf->SetFont(
'',
'', $default_font_size - 4);
1000 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1002 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
1003 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1004 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
1005 $sql .=
" ORDER BY p.datep";
1006 $resql = $this->db->query($sql);
1008 $num = $this->db->num_rows($resql);
1012 $row = $this->db->fetch_object($resql);
1014 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1015 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1016 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1017 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1018 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1019 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1021 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1022 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1023 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1025 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1030 $this->error = $this->db->lasterror();
1048 global $langs,
$conf, $mysoc;
1051 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1058 $pdf->SetTextColor(0, 0, 60);
1059 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1063 $posy = $this->marge_haute;
1064 $posx = $this->page_largeur - $this->marge_droite - 100;
1066 $pdf->SetXY($this->marge_gauche, $posy);
1088 $text = $this->emetteur->name;
1089 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1092 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1093 $pdf->SetXY($posx, $posy);
1094 $pdf->SetTextColor(0, 0, 60);
1095 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1097 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1100 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1103 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1105 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1110 $pdf->SetFont(
'',
'B', $default_font_size);
1111 $pdf->SetXY($posx, $posy);
1112 $pdf->SetTextColor(0, 0, 60);
1113 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1117 $pdf->SetFont(
'',
'', $default_font_size - 1);
1121 if (!empty(
$object->project->ref)) {
1123 $pdf->SetXY($posx, $posy);
1124 $pdf->SetTextColor(0, 0, 60);
1125 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1131 if (!empty(
$object->project->ref)) {
1132 $outputlangs->load(
"projects");
1134 $pdf->SetXY($posx, $posy);
1135 $langs->load(
"projects");
1136 $pdf->SetTextColor(0, 0, 60);
1137 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1143 $pdf->SetXY($posx, $posy);
1144 $pdf->SetTextColor(0, 0, 60);
1145 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1148 $pdf->SetXY($posx, $posy);
1149 $pdf->SetTextColor(255, 0, 0);
1150 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1153 if (
$object->thirdparty->code_fournisseur) {
1155 $pdf->SetXY($posx, $posy);
1156 $pdf->SetTextColor(0, 0, 60);
1157 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_fournisseur),
'',
'R');
1161 $pdf->SetTextColor(0, 0, 60);
1165 $current_y = $pdf->getY();
1167 if ($current_y < $pdf->getY()) {
1168 $top_shift = $pdf->getY() - $current_y;
1173 $carac_emetteur =
'';
1175 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1176 if (count($arrayidcontact) > 0) {
1177 $object->fetch_user($arrayidcontact[0]);
1178 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1179 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1181 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1185 $carac_emetteur .=
"\n";
1191 $posy = 42 + $top_shift;
1192 $posx = $this->marge_gauche;
1194 $posx = $this->page_largeur - $this->marge_droite - 80;
1199 $pdf->SetTextColor(0, 0, 0);
1200 $pdf->SetFont(
'',
'', $default_font_size - 2);
1201 $pdf->SetXY($posx, $posy - 5);
1202 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1203 $pdf->SetXY($posx, $posy);
1204 $pdf->SetFillColor(230, 230, 230);
1205 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
1206 $pdf->SetTextColor(0, 0, 60);
1209 $pdf->SetXY($posx + 2, $posy + 3);
1210 $pdf->SetFont(
'',
'B', $default_font_size);
1211 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1212 $posy = $pdf->getY();
1215 $pdf->SetXY($posx + 2, $posy);
1216 $pdf->SetFont(
'',
'', $default_font_size - 1);
1217 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1222 $usecontact =
false;
1223 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1224 if (count($arrayidcontact) > 0) {
1226 $result =
$object->fetch_contact($arrayidcontact[0]);
1230 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1231 $thirdparty =
$object->contact;
1233 $thirdparty = $mysoc;
1242 if ($this->page_largeur < 210) {
1245 $posy = 42 + $top_shift;
1246 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1248 $posx = $this->marge_gauche;
1252 $pdf->SetTextColor(0, 0, 0);
1253 $pdf->SetFont(
'',
'', $default_font_size - 2);
1254 $pdf->SetXY($posx + 2, $posy - 5);
1255 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1256 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1259 $pdf->SetXY($posx + 2, $posy + 3);
1260 $pdf->SetFont(
'',
'B', $default_font_size);
1261 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1263 $posy = $pdf->getY();
1266 $pdf->SetFont(
'',
'', $default_font_size - 1);
1267 $pdf->SetXY($posx + 2, $posy);
1268 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');