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 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
254 $tplidx = $pdf->importPage(1);
259 $pdf->SetDrawColor(128, 128, 128);
261 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
262 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
263 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
264 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
265 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
267 $pdf->SetCompression(
false);
270 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
273 for ($i = 0; $i < $nblines; $i++) {
274 if ($object->lines[$i]->remise_percent) {
275 $this->atleastonediscount++;
278 if (empty($this->atleastonediscount)) {
279 $delta = ($this->postotalht - $this->posxdiscount);
280 $this->posxpicture += $delta;
281 $this->posxtva += $delta;
282 $this->posxup += $delta;
283 $this->posxqty += $delta;
284 $this->posxunit += $delta;
285 $this->posxdiscount += $delta;
291 if (!empty($tplidx)) {
292 $pdf->useTemplate($tplidx);
295 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
296 $pdf->SetFont(
'',
'', $default_font_size - 1);
297 $pdf->MultiCell(0, 3,
'');
298 $pdf->SetTextColor(0, 0, 0);
300 $tab_top = 90 + $top_shift;
301 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
304 if (isModEnabled(
'incoterm')) {
305 $desc_incoterms = $object->getIncotermsForPDF();
306 if ($desc_incoterms) {
309 $pdf->SetFont(
'',
'', $default_font_size - 1);
310 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
311 $nexY = $pdf->GetY();
312 $height_incoterms = $nexY - $tab_top;
315 $pdf->SetDrawColor(192, 192, 192);
316 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
318 $tab_top = $nexY + 6;
323 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
327 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
328 if (!empty($extranote)) {
341 $pdf->SetFont(
'',
'', $default_font_size - 1);
342 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
343 $nexY = $pdf->GetY();
344 $height_note = $nexY - $tab_top;
347 $pdf->SetDrawColor(192, 192, 192);
348 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
350 $tab_top = $nexY + 6;
353 $iniY = $tab_top + 7;
354 $curY = $tab_top + 7;
355 $nexY = $tab_top + 7;
358 for ($i = 0; $i < $nblines; $i++) {
360 $pdf->SetFont(
'',
'', $default_font_size - 1);
361 $pdf->SetTextColor(0, 0, 0);
369 $pdf->setTopMargin($tab_top_newpage);
370 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
371 $pageposbefore = $pdf->getPage();
373 $showpricebeforepagebreak = 1;
377 $curX = $this->posxdesc - 1;
379 $pdf->startTransaction();
380 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
381 $pageposafter = $pdf->getPage();
382 if ($pageposafter > $pageposbefore) {
383 $pdf->rollbackTransaction(
true);
384 $pageposafter = $pageposbefore;
386 $pdf->setPageOrientation(
'', 1, $heightforfooter);
387 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
388 $posyafter = $pdf->GetY();
389 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
390 if ($i == ($nblines - 1)) {
391 $pdf->AddPage(
'',
'',
true);
392 if (!empty($tplidx)) {
393 $pdf->useTemplate($tplidx);
396 $this->
_pagehead($pdf, $object, 0, $outputlangs);
398 $pdf->setPage($pageposafter + 1);
404 $showpricebeforepagebreak = 1;
406 $showpricebeforepagebreak = 0;
410 $pdf->commitTransaction();
412 $posYAfterDescription = $pdf->GetY();
414 $nexY = $pdf->GetY();
415 $pageposafter = $pdf->getPage();
416 $pdf->setPage($pageposbefore);
417 $pdf->setTopMargin($this->marge_haute);
418 $pdf->setPageOrientation(
'', 1, 0);
421 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
422 $pdf->setPage($pageposafter);
423 $curY = $tab_top_newpage;
426 $pdf->SetFont(
'',
'', $default_font_size - 1);
431 $pdf->SetXY($this->posxtva, $curY);
432 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
437 $pdf->SetXY($this->posxup, $curY);
438 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
442 $pdf->SetXY($this->posxqty, $curY);
443 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
447 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
448 $pdf->SetXY($this->posxunit, $curY);
449 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
453 if ($object->lines[$i]->remise_percent) {
454 $pdf->SetXY($this->posxdiscount - 2, $curY);
456 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
461 $pdf->SetXY($this->postotalht, $curY);
462 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
465 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
466 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
468 $tvaligne = $object->lines[$i]->total_tva;
471 $localtax1ligne = $object->lines[$i]->total_localtax1;
472 $localtax2ligne = $object->lines[$i]->total_localtax2;
479 $vatrate = (string) $object->lines[$i]->tva_tx;
480 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
481 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
483 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
486 if (empty($this->tva[$vatrate])) {
487 $this->tva[$vatrate] = 0;
489 if (empty($this->localtax1[$localtax1rate])) {
490 $this->localtax1[$localtax1rate] = 0;
492 if (empty($this->localtax2[$localtax2rate])) {
493 $this->localtax2[$localtax2rate] = 0;
495 $this->tva[$vatrate] += $tvaligne;
496 $this->localtax1[$localtax1rate] += $localtax1ligne;
497 $this->localtax2[$localtax2rate] += $localtax2ligne;
499 if ($posYAfterImage > $posYAfterDescription) {
500 $nexY = $posYAfterImage;
505 $pdf->setPage($pageposafter);
506 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
508 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
509 $pdf->SetLineStyle(array(
'dash'=>0));
515 while ($pagenb < $pageposafter) {
516 $pdf->setPage($pagenb);
518 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
520 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
522 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
524 $pdf->setPage($pagenb);
525 $pdf->setPageOrientation(
'', 1, 0);
527 $this->
_pagehead($pdf, $object, 0, $outputlangs);
530 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
532 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
534 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
536 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
539 if (!empty($tplidx)) {
540 $pdf->useTemplate($tplidx);
544 $this->
_pagehead($pdf, $object, 0, $outputlangs);
551 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
552 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
554 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
555 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
559 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
561 $amount_credit_notes_included = 0;
562 $amount_deposits_included = 0;
565 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
570 $this->
_pagefoot($pdf, $object, $outputlangs);
571 if (method_exists($pdf,
'AliasNbPages')) {
572 $pdf->AliasNbPages();
577 $pdf->Output($file,
'F');
580 $hookmanager->initHooks(array(
'pdfgeneration'));
581 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
583 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
585 $this->error = $hookmanager->error;
586 $this->errors = $hookmanager->errors;
591 $this->result = array(
'fullpath'=>$file);
595 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
599 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
616 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
619 global $conf, $mysoc;
630 $pdf->SetFont(
'',
'', $default_font_size - 1);
635 if ($this->page_largeur < 210) {
638 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
644 $pdf->SetFillColor(255, 255, 255);
645 $pdf->SetXY($col1x, $tab2_top);
646 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
648 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
649 $pdf->SetXY($col2x, $tab2_top);
650 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
653 $pdf->SetFillColor(248, 248, 248);
655 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
657 $this->atleastoneratenotnull = 0;
658 foreach ($this->tva as $tvakey => $tvaval) {
660 $this->atleastoneratenotnull++;
663 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
667 if (preg_match(
'/\*/', $tvakey)) {
668 $tvakey = str_replace(
'*',
'', $tvakey);
669 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
672 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
673 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
674 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
676 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
677 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
680 if (!$this->atleastoneratenotnull) {
682 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
683 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
684 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
685 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva, 0, $outputlangs), 0,
'R', 1);
688 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX1_OPTION') ==
'localtax1on' && $object->total_localtax1 > 0) {
690 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
691 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
692 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
693 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
697 if (
getDolGlobalString(
'FACTURE_LOCAL_TAX2_OPTION') ==
'localtax2on' && $object->total_localtax2 > 0) {
699 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
701 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
702 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
708 foreach ($this->localtax1 as $tvakey => $tvaval) {
713 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
716 if (preg_match(
'/\*/', $tvakey)) {
717 $tvakey = str_replace(
'*',
'', $tvakey);
718 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
720 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
721 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
722 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
724 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
725 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
733 foreach ($this->localtax2 as $tvakey => $tvaval) {
738 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
741 if (preg_match(
'/\*/', $tvakey)) {
742 $tvakey = str_replace(
'*',
'', $tvakey);
743 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
745 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
746 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
747 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
749 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
750 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
758 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
759 $pdf->SetTextColor(0, 0, 60);
760 $pdf->SetFillColor(224, 224, 224);
761 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
763 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
764 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
766 $pdf->SetTextColor(0, 0, 0);
767 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
768 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
770 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
771 if (!empty($object->paye)) {
775 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
778 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
779 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
780 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
781 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
784 if ($creditnoteamount) {
785 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
787 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
788 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
789 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
790 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
794 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
796 $pdf->SetFillColor(255, 255, 255);
798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
799 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
800 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
801 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
807 $pdf->SetTextColor(0, 0, 60);
808 $pdf->SetFillColor(224, 224, 224);
809 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
810 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
812 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
813 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
814 $pdf->SetFont(
'',
'', $default_font_size - 1);
815 $pdf->SetTextColor(0, 0, 0);
819 return ($tab2_top + ($tab2_hl * $index));
836 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
846 $currency = !empty($currency) ? $currency : $conf->currency;
850 $pdf->SetTextColor(0, 0, 0);
851 $pdf->SetFont(
'',
'', $default_font_size - 2);
853 if (empty($hidetop)) {
854 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
855 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
856 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
860 $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')));
864 $pdf->SetDrawColor(128, 128, 128);
865 $pdf->SetFont(
'',
'', $default_font_size - 1);
868 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
870 if (empty($hidetop)) {
871 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
873 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
874 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
878 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
879 if (empty($hidetop)) {
880 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
881 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
885 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
886 if (empty($hidetop)) {
887 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
888 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
891 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
892 if (empty($hidetop)) {
893 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
894 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
898 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
899 if (empty($hidetop)) {
900 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
902 $this->posxdiscount - $this->posxunit - 1,
904 $outputlangs->transnoentities(
"Unit"),
911 if ($this->atleastonediscount) {
912 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
913 if (empty($hidetop)) {
914 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
915 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
919 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
920 if (empty($hidetop)) {
921 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
922 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
949 $tab3_top = $posy + 8;
952 if ($this->page_largeur < 210) {
958 $pdf->SetFont(
'',
'', $default_font_size - 3);
959 $pdf->SetXY($tab3_posx, $tab3_top - 4);
960 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
962 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
964 $pdf->SetFont(
'',
'', $default_font_size - 4);
965 $pdf->SetXY($tab3_posx, $tab3_top);
966 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
967 $pdf->SetXY($tab3_posx + 21, $tab3_top);
968 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
969 $pdf->SetXY($tab3_posx + 40, $tab3_top);
970 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
971 $pdf->SetXY($tab3_posx + 58, $tab3_top);
972 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
974 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
978 $pdf->SetFont(
'',
'', $default_font_size - 4);
984 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
986 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
987 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
988 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
989 $sql .=
" ORDER BY p.datep";
990 $resql = $this->db->query($sql);
992 $num = $this->db->num_rows($resql);
996 $row = $this->db->fetch_object($resql);
998 $pdf->SetXY($tab3_posx, $tab3_top + $y);
999 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1000 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1001 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1002 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1003 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1005 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1006 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1007 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1009 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1014 $this->error = $this->db->lasterror();
1030 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1032 global $langs, $conf, $mysoc;
1035 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1042 $pdf->SetTextColor(0, 0, 60);
1043 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1047 $posy = $this->marge_haute;
1048 $posx = $this->page_largeur - $this->marge_droite - 100;
1050 $pdf->SetXY($this->marge_gauche, $posy);
1072 $text = $this->emetteur->name;
1073 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1076 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1077 $pdf->SetXY($posx, $posy);
1078 $pdf->SetTextColor(0, 0, 60);
1079 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1080 if ($object->type == 1) {
1081 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1083 if ($object->type == 2) {
1084 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1086 if ($object->type == 3) {
1087 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1089 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
1092 if ($object->ref_supplier) {
1094 $pdf->SetFont(
'',
'B', $default_font_size);
1095 $pdf->SetXY($posx, $posy);
1096 $pdf->SetTextColor(0, 0, 60);
1097 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".$object->ref_supplier,
'',
'R');
1101 $pdf->SetFont(
'',
'', $default_font_size - 1);
1104 $object->fetch_projet();
1105 if (!empty($object->project->ref)) {
1107 $pdf->SetXY($posx, $posy);
1108 $pdf->SetTextColor(0, 0, 60);
1109 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1114 $object->fetch_projet();
1115 if (!empty($object->project->ref)) {
1116 $outputlangs->load(
"projects");
1118 $pdf->SetXY($posx, $posy);
1119 $langs->load(
"projects");
1120 $pdf->SetTextColor(0, 0, 60);
1121 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1125 if ($object->date) {
1127 $pdf->SetXY($posx, $posy);
1128 $pdf->SetTextColor(0, 0, 60);
1129 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1132 $pdf->SetXY($posx, $posy);
1133 $pdf->SetTextColor(255, 0, 0);
1134 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1137 if ($object->thirdparty->code_fournisseur) {
1139 $pdf->SetXY($posx, $posy);
1140 $pdf->SetTextColor(0, 0, 60);
1141 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1145 $pdf->SetTextColor(0, 0, 60);
1149 $current_y = $pdf->getY();
1150 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1151 if ($current_y < $pdf->getY()) {
1152 $top_shift = $pdf->getY() - $current_y;
1157 $carac_emetteur =
'';
1159 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1160 if (count($arrayidcontact) > 0) {
1161 $object->fetch_user($arrayidcontact[0]);
1162 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1163 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1165 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1167 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1169 $carac_emetteur .=
"\n";
1172 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1175 $posy = 42 + $top_shift;
1176 $posx = $this->marge_gauche;
1178 $posx = $this->page_largeur - $this->marge_droite - 80;
1183 $pdf->SetTextColor(0, 0, 0);
1184 $pdf->SetFont(
'',
'', $default_font_size - 2);
1185 $pdf->SetXY($posx, $posy - 5);
1186 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1187 $pdf->SetXY($posx, $posy);
1188 $pdf->SetFillColor(230, 230, 230);
1189 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1190 $pdf->SetTextColor(0, 0, 60);
1193 $pdf->SetXY($posx + 2, $posy + 3);
1194 $pdf->SetFont(
'',
'B', $default_font_size);
1195 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1196 $posy = $pdf->getY();
1199 $pdf->SetXY($posx + 2, $posy);
1200 $pdf->SetFont(
'',
'', $default_font_size - 1);
1201 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1206 $usecontact =
false;
1207 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
1208 if (count($arrayidcontact) > 0) {
1210 $result = $object->fetch_contact($arrayidcontact[0]);
1214 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1215 $thirdparty = $object->contact;
1217 $thirdparty = $mysoc;
1222 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
1226 if ($this->page_largeur < 210) {
1229 $posy = 42 + $top_shift;
1230 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1232 $posx = $this->marge_gauche;
1236 $pdf->SetTextColor(0, 0, 0);
1237 $pdf->SetFont(
'',
'', $default_font_size - 2);
1238 $pdf->SetXY($posx + 2, $posy - 5);
1239 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1240 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1243 $pdf->SetXY($posx + 2, $posy + 3);
1244 $pdf->SetFont(
'',
'B', $default_font_size);
1245 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1247 $posy = $pdf->getY();
1250 $pdf->SetFont(
'',
'', $default_font_size - 1);
1251 $pdf->SetXY($posx + 2, $posy);
1252 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');