159 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
162 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
165 if (!is_object($object->thirdparty)) {
166 $object->fetch_thirdparty();
168 if (!is_object($object->thirdparty)) {
169 $object->thirdparty = $mysoc;
172 $this->emetteur = $object->thirdparty;
173 if (!$this->emetteur->country_code) {
174 $this->emetteur->country_code = substr($langs->defaultlang, -2);
177 if (!is_object($outputlangs)) {
178 $outputlangs = $langs;
182 $outputlangs->charset_output =
'ISO-8859-1';
186 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
188 $nblines = count($object->lines);
190 if ($conf->fournisseur->facture->dir_output) {
191 $deja_regle = $object->getSommePaiement((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
192 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
193 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
196 if ($object->specimen) {
197 $dir = $conf->fournisseur->facture->dir_output;
198 $file = $dir.
"/SPECIMEN.pdf";
202 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$objectref;
203 $file = $dir.
"/".$objectref.
".pdf";
205 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
209 if (!file_exists($dir)) {
211 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
216 if (file_exists($dir)) {
218 if (!is_object($hookmanager)) {
219 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
222 $hookmanager->initHooks(array(
'pdfgeneration'));
223 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
225 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
228 $nblines = count($object->lines);
229 $nbpayments = count($object->getListOfPayments());
234 $pdf->SetAutoPageBreak(1, 0);
236 $heightforinfotot = 50 + (4 * $nbpayments);
237 if ($heightforinfotot > 220) {
238 $heightforinfotot = 220;
240 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
241 $heightforfooter = $this->marge_basse + 8;
243 $heightforfooter += 6;
246 if (class_exists(
'TCPDF')) {
247 $pdf->setPrintHeader(
false);
248 $pdf->setPrintFooter(
false);
253 $logodir = $conf->mycompany->dir_output;
254 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
255 $logodir = $conf->mycompany->multidir_output[$object->entity];
257 $pagecount = $pdf->setSourceFile($logodir .
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
258 $tplidx = $pdf->importPage(1);
263 $pdf->SetDrawColor(128, 128, 128);
265 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
266 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
267 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
268 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
269 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
271 $pdf->SetCompression(
false);
274 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
277 for ($i = 0; $i < $nblines; $i++) {
278 if ($object->lines[$i]->remise_percent) {
279 $this->atleastonediscount++;
282 if (empty($this->atleastonediscount)) {
283 $delta = ($this->postotalht - $this->posxdiscount);
284 $this->posxpicture += $delta;
285 $this->posxtva += $delta;
286 $this->posxup += $delta;
287 $this->posxqty += $delta;
288 $this->posxunit += $delta;
289 $this->posxdiscount += $delta;
295 if (!empty($tplidx)) {
296 $pdf->useTemplate($tplidx);
299 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
300 $pdf->SetFont(
'',
'', $default_font_size - 1);
301 $pdf->MultiCell(0, 3,
'');
302 $pdf->SetTextColor(0, 0, 0);
304 $tab_top = 90 + $top_shift;
305 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
308 if (isModEnabled(
'incoterm')) {
309 $desc_incoterms = $object->getIncotermsForPDF();
310 if ($desc_incoterms) {
313 $pdf->SetFont(
'',
'', $default_font_size - 1);
314 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
315 $nexY = $pdf->GetY();
316 $height_incoterms = $nexY - $tab_top;
319 $pdf->SetDrawColor(192, 192, 192);
320 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
322 $tab_top = $nexY + 6;
327 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
331 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
332 if (!empty($extranote)) {
345 $pdf->SetFont(
'',
'', $default_font_size - 1);
346 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
347 $nexY = $pdf->GetY();
348 $height_note = $nexY - $tab_top;
351 $pdf->SetDrawColor(192, 192, 192);
352 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
354 $tab_top = $nexY + 6;
357 $iniY = $tab_top + 7;
358 $curY = $tab_top + 7;
359 $nexY = $tab_top + 7;
362 for ($i = 0; $i < $nblines; $i++) {
364 $pdf->SetFont(
'',
'', $default_font_size - 1);
365 $pdf->SetTextColor(0, 0, 0);
373 $pdf->setTopMargin($tab_top_newpage);
374 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
375 $pageposbefore = $pdf->getPage();
377 $showpricebeforepagebreak = 1;
381 $curX = $this->posxdesc - 1;
383 $pdf->startTransaction();
384 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
385 $pageposafter = $pdf->getPage();
386 if ($pageposafter > $pageposbefore) {
387 $pdf->rollbackTransaction(
true);
388 $pageposafter = $pageposbefore;
390 $pdf->setPageOrientation(
'', 1, $heightforfooter);
391 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
392 $posyafter = $pdf->GetY();
393 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
394 if ($i == ($nblines - 1)) {
395 $pdf->AddPage(
'',
'',
true);
396 if (!empty($tplidx)) {
397 $pdf->useTemplate($tplidx);
400 $this->
_pagehead($pdf, $object, 0, $outputlangs);
402 $pdf->setPage($pageposafter + 1);
408 $showpricebeforepagebreak = 1;
410 $showpricebeforepagebreak = 0;
414 $pdf->commitTransaction();
416 $posYAfterDescription = $pdf->GetY();
418 $nexY = $pdf->GetY();
419 $pageposafter = $pdf->getPage();
420 $pdf->setPage($pageposbefore);
421 $pdf->setTopMargin($this->marge_haute);
422 $pdf->setPageOrientation(
'', 1, 0);
425 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
426 $pdf->setPage($pageposafter);
427 $curY = $tab_top_newpage;
430 $pdf->SetFont(
'',
'', $default_font_size - 1);
435 $pdf->SetXY($this->posxtva, $curY);
436 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
441 $pdf->SetXY($this->posxup, $curY);
442 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
446 $pdf->SetXY($this->posxqty, $curY);
447 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
451 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
452 $pdf->SetXY($this->posxunit, $curY);
453 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
457 if ($object->lines[$i]->remise_percent) {
458 $pdf->SetXY($this->posxdiscount - 2, $curY);
460 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
465 $pdf->SetXY($this->postotalht, $curY);
466 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
469 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
470 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
472 $tvaligne = $object->lines[$i]->total_tva;
475 $localtax1ligne = $object->lines[$i]->total_localtax1;
476 $localtax2ligne = $object->lines[$i]->total_localtax2;
483 $vatrate = (string) $object->lines[$i]->tva_tx;
484 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
485 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
487 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
490 if (empty($this->tva[$vatrate])) {
491 $this->tva[$vatrate] = 0;
493 if (empty($this->localtax1[$localtax1rate])) {
494 $this->localtax1[$localtax1rate] = 0;
496 if (empty($this->localtax2[$localtax2rate])) {
497 $this->localtax2[$localtax2rate] = 0;
499 $this->tva[$vatrate] += $tvaligne;
500 $this->localtax1[$localtax1rate] += $localtax1ligne;
501 $this->localtax2[$localtax2rate] += $localtax2ligne;
503 if ($posYAfterImage > $posYAfterDescription) {
504 $nexY = $posYAfterImage;
509 $pdf->setPage($pageposafter);
510 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
512 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
513 $pdf->SetLineStyle(array(
'dash'=>0));
519 while ($pagenb < $pageposafter) {
520 $pdf->setPage($pagenb);
522 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
524 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
526 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
528 $pdf->setPage($pagenb);
529 $pdf->setPageOrientation(
'', 1, 0);
531 $this->
_pagehead($pdf, $object, 0, $outputlangs);
534 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
536 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
538 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
540 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
543 if (!empty($tplidx)) {
544 $pdf->useTemplate($tplidx);
548 $this->
_pagehead($pdf, $object, 0, $outputlangs);
555 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
556 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
558 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
559 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
563 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
565 $amount_credit_notes_included = 0;
566 $amount_deposits_included = 0;
569 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
574 $this->
_pagefoot($pdf, $object, $outputlangs);
575 if (method_exists($pdf,
'AliasNbPages')) {
576 $pdf->AliasNbPages();
581 $pdf->Output($file,
'F');
584 $hookmanager->initHooks(array(
'pdfgeneration'));
585 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
587 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
589 $this->error = $hookmanager->error;
590 $this->errors = $hookmanager->errors;
595 $this->result = array(
'fullpath'=>$file);
599 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
603 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
620 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
623 global $conf, $mysoc;
634 $pdf->SetFont(
'',
'', $default_font_size - 1);
639 if ($this->page_largeur < 210) {
642 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
648 $pdf->SetFillColor(255, 255, 255);
649 $pdf->SetXY($col1x, $tab2_top);
650 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
652 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
653 $pdf->SetXY($col2x, $tab2_top);
654 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
657 $pdf->SetFillColor(248, 248, 248);
659 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
661 $this->atleastoneratenotnull = 0;
662 foreach ($this->tva as $tvakey => $tvaval) {
664 $this->atleastoneratenotnull++;
667 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
671 if (preg_match(
'/\*/', $tvakey)) {
672 $tvakey = str_replace(
'*',
'', $tvakey);
673 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
676 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
677 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
678 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
680 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
681 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
684 if (!$this->atleastoneratenotnull) {
686 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
687 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
688 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
689 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva, 0, $outputlangs), 0,
'R', 1);
692 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on' && $object->total_localtax1 > 0) {
694 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
695 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
696 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
697 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
701 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on' && $object->total_localtax2 > 0) {
703 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
704 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
705 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
706 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
712 foreach ($this->localtax1 as $tvakey => $tvaval) {
717 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
720 if (preg_match(
'/\*/', $tvakey)) {
721 $tvakey = str_replace(
'*',
'', $tvakey);
722 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
724 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
725 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
726 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
728 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
729 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
737 foreach ($this->localtax2 as $tvakey => $tvaval) {
742 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
745 if (preg_match(
'/\*/', $tvakey)) {
746 $tvakey = str_replace(
'*',
'', $tvakey);
747 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
749 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
750 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
751 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
753 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
754 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
762 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
763 $pdf->SetTextColor(0, 0, 60);
764 $pdf->SetFillColor(224, 224, 224);
765 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
767 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
768 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
770 $pdf->SetTextColor(0, 0, 0);
771 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
772 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
774 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
775 if (!empty($object->paye)) {
779 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
782 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
783 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
784 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
785 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
788 if ($creditnoteamount) {
789 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
791 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
792 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
793 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
794 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
798 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
800 $pdf->SetFillColor(255, 255, 255);
802 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
803 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
804 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
805 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
811 $pdf->SetTextColor(0, 0, 60);
812 $pdf->SetFillColor(224, 224, 224);
813 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
814 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
816 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
817 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
818 $pdf->SetFont(
'',
'', $default_font_size - 1);
819 $pdf->SetTextColor(0, 0, 0);
823 return ($tab2_top + ($tab2_hl * $index));
840 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
850 $currency = !empty($currency) ? $currency : $conf->currency;
854 $pdf->SetTextColor(0, 0, 0);
855 $pdf->SetFont(
'',
'', $default_font_size - 2);
857 if (empty($hidetop)) {
858 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
859 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
860 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
864 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
868 $pdf->SetDrawColor(128, 128, 128);
869 $pdf->SetFont(
'',
'', $default_font_size - 1);
872 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
874 if (empty($hidetop)) {
875 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
877 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
878 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
882 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
883 if (empty($hidetop)) {
884 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
885 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
889 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
890 if (empty($hidetop)) {
891 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
892 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
895 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
896 if (empty($hidetop)) {
897 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
898 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
902 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
903 if (empty($hidetop)) {
904 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
906 $this->posxdiscount - $this->posxunit - 1,
908 $outputlangs->transnoentities(
"Unit"),
915 if ($this->atleastonediscount) {
916 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
917 if (empty($hidetop)) {
918 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
919 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
923 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
924 if (empty($hidetop)) {
925 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
926 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
953 $tab3_top = $posy + 8;
956 if ($this->page_largeur < 210) {
962 $pdf->SetFont(
'',
'', $default_font_size - 3);
963 $pdf->SetXY($tab3_posx, $tab3_top - 4);
964 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
966 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
968 $pdf->SetFont(
'',
'', $default_font_size - 4);
969 $pdf->SetXY($tab3_posx, $tab3_top);
970 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
971 $pdf->SetXY($tab3_posx + 21, $tab3_top);
972 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
973 $pdf->SetXY($tab3_posx + 40, $tab3_top);
974 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
975 $pdf->SetXY($tab3_posx + 58, $tab3_top);
976 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
978 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
982 $pdf->SetFont(
'',
'', $default_font_size - 4);
988 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
990 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
991 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
992 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
993 $sql .=
" ORDER BY p.datep";
994 $resql = $this->db->query($sql);
996 $num = $this->db->num_rows($resql);
1000 $row = $this->db->fetch_object($resql);
1002 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1003 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1004 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1005 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1006 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1007 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1009 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1010 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1011 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1013 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1018 $this->error = $this->db->lasterror();
1034 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1036 global $langs, $conf, $mysoc;
1039 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1046 $pdf->SetTextColor(0, 0, 60);
1047 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1051 $posy = $this->marge_haute;
1052 $posx = $this->page_largeur - $this->marge_droite - 100;
1054 $pdf->SetXY($this->marge_gauche, $posy);
1076 $text = $this->emetteur->name;
1077 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1080 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1081 $pdf->SetXY($posx, $posy);
1082 $pdf->SetTextColor(0, 0, 60);
1083 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1084 if ($object->type == 1) {
1085 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1087 if ($object->type == 2) {
1088 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1090 if ($object->type == 3) {
1091 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1093 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
1096 if ($object->ref_supplier) {
1098 $pdf->SetFont(
'',
'B', $default_font_size);
1099 $pdf->SetXY($posx, $posy);
1100 $pdf->SetTextColor(0, 0, 60);
1101 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".$object->ref_supplier,
'',
'R');
1105 $pdf->SetFont(
'',
'', $default_font_size - 1);
1108 $object->fetch_projet();
1109 if (!empty($object->project->ref)) {
1111 $pdf->SetXY($posx, $posy);
1112 $pdf->SetTextColor(0, 0, 60);
1113 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1118 $object->fetch_projet();
1119 if (!empty($object->project->ref)) {
1120 $outputlangs->load(
"projects");
1122 $pdf->SetXY($posx, $posy);
1123 $langs->load(
"projects");
1124 $pdf->SetTextColor(0, 0, 60);
1125 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1129 if ($object->date) {
1131 $pdf->SetXY($posx, $posy);
1132 $pdf->SetTextColor(0, 0, 60);
1133 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1136 $pdf->SetXY($posx, $posy);
1137 $pdf->SetTextColor(255, 0, 0);
1138 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1141 if ($object->thirdparty->code_fournisseur) {
1143 $pdf->SetXY($posx, $posy);
1144 $pdf->SetTextColor(0, 0, 60);
1145 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1149 $pdf->SetTextColor(0, 0, 60);
1153 $current_y = $pdf->getY();
1154 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1155 if ($current_y < $pdf->getY()) {
1156 $top_shift = $pdf->getY() - $current_y;
1161 $carac_emetteur =
'';
1163 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1164 if (count($arrayidcontact) > 0) {
1165 $object->fetch_user($arrayidcontact[0]);
1166 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1167 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1169 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1171 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1173 $carac_emetteur .=
"\n";
1176 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1179 $posy = 42 + $top_shift;
1180 $posx = $this->marge_gauche;
1182 $posx = $this->page_largeur - $this->marge_droite - 80;
1187 $pdf->SetTextColor(0, 0, 0);
1188 $pdf->SetFont(
'',
'', $default_font_size - 2);
1189 $pdf->SetXY($posx, $posy - 5);
1190 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1191 $pdf->SetXY($posx, $posy);
1192 $pdf->SetFillColor(230, 230, 230);
1193 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1194 $pdf->SetTextColor(0, 0, 60);
1197 $pdf->SetXY($posx + 2, $posy + 3);
1198 $pdf->SetFont(
'',
'B', $default_font_size);
1199 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1200 $posy = $pdf->getY();
1203 $pdf->SetXY($posx + 2, $posy);
1204 $pdf->SetFont(
'',
'', $default_font_size - 1);
1205 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1210 $usecontact =
false;
1211 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
1212 if (count($arrayidcontact) > 0) {
1214 $result = $object->fetch_contact($arrayidcontact[0]);
1218 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1219 $thirdparty = $object->contact;
1221 $thirdparty = $mysoc;
1226 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
1230 if ($this->page_largeur < 210) {
1233 $posy = 42 + $top_shift;
1234 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1236 $posx = $this->marge_gauche;
1240 $pdf->SetTextColor(0, 0, 0);
1241 $pdf->SetFont(
'',
'', $default_font_size - 2);
1242 $pdf->SetXY($posx + 2, $posy - 5);
1243 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1244 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1247 $pdf->SetXY($posx + 2, $posy + 3);
1248 $pdf->SetFont(
'',
'B', $default_font_size);
1249 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1251 $posy = $pdf->getY();
1254 $pdf->SetFont(
'',
'', $default_font_size - 1);
1255 $pdf->SetXY($posx + 2, $posy);
1256 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');