201 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
204 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
207 if (!is_object($object->thirdparty)) {
208 $object->fetch_thirdparty();
210 if (!is_object($object->thirdparty)) {
211 $object->thirdparty = $mysoc;
214 $this->emetteur = $object->thirdparty;
215 if (!$this->emetteur->country_code) {
216 $this->emetteur->country_code = substr($langs->defaultlang, -2);
219 if (!is_object($outputlangs)) {
220 $outputlangs = $langs;
223 if (!empty($conf->global->MAIN_USE_FPDF)) {
224 $outputlangs->charset_output =
'ISO-8859-1';
228 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
230 $nblines = count($object->lines);
232 if ($conf->fournisseur->facture->dir_output) {
233 $deja_regle = $object->getSommePaiement((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
234 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
235 $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
238 if ($object->specimen) {
239 $dir = $conf->fournisseur->facture->dir_output;
240 $file = $dir.
"/SPECIMEN.pdf";
244 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$objectref;
245 $file = $dir.
"/".$objectref.
".pdf";
246 if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
247 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
251 if (!file_exists($dir)) {
253 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
258 if (file_exists($dir)) {
260 if (!is_object($hookmanager)) {
261 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
264 $hookmanager->initHooks(array(
'pdfgeneration'));
265 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
267 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
270 $nblines = count($object->lines);
271 $nbpayments = count($object->getListOfPayments());
276 $pdf->SetAutoPageBreak(1, 0);
278 $heightforinfotot = 50 + (4 * $nbpayments);
279 if ($heightforinfotot > 220) {
280 $heightforinfotot = 220;
282 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
283 $heightforfooter = $this->marge_basse + 8;
284 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
285 $heightforfooter += 6;
288 if (class_exists(
'TCPDF')) {
289 $pdf->setPrintHeader(
false);
290 $pdf->setPrintFooter(
false);
294 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
295 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
296 $tplidx = $pdf->importPage(1);
301 $pdf->SetDrawColor(128, 128, 128);
303 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
304 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
305 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
306 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
307 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
309 $pdf->SetCompression(
false);
312 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
315 for ($i = 0; $i < $nblines; $i++) {
316 if ($object->lines[$i]->remise_percent) {
317 $this->atleastonediscount++;
320 if (empty($this->atleastonediscount)) {
321 $delta = ($this->postotalht - $this->posxdiscount);
322 $this->posxpicture += $delta;
323 $this->posxtva += $delta;
324 $this->posxup += $delta;
325 $this->posxqty += $delta;
326 $this->posxunit += $delta;
327 $this->posxdiscount += $delta;
333 if (!empty($tplidx)) {
334 $pdf->useTemplate($tplidx);
337 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
338 $pdf->SetFont(
'',
'', $default_font_size - 1);
339 $pdf->MultiCell(0, 3,
'');
340 $pdf->SetTextColor(0, 0, 0);
342 $tab_top = 90 + $top_shift;
343 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
346 if (isModEnabled(
'incoterm')) {
347 $desc_incoterms = $object->getIncotermsForPDF();
348 if ($desc_incoterms) {
351 $pdf->SetFont(
'',
'', $default_font_size - 1);
352 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
353 $nexY = $pdf->GetY();
354 $height_incoterms = $nexY - $tab_top;
357 $pdf->SetDrawColor(192, 192, 192);
358 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
360 $tab_top = $nexY + 6;
365 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
368 if (!empty($conf->global->INVOICE_ADD_EXTRAFIELD_IN_NOTE)) {
369 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
370 if (!empty($extranote)) {
383 $pdf->SetFont(
'',
'', $default_font_size - 1);
384 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
385 $nexY = $pdf->GetY();
386 $height_note = $nexY - $tab_top;
389 $pdf->SetDrawColor(192, 192, 192);
390 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
392 $tab_top = $nexY + 6;
395 $iniY = $tab_top + 7;
396 $curY = $tab_top + 7;
397 $nexY = $tab_top + 7;
400 for ($i = 0; $i < $nblines; $i++) {
402 $pdf->SetFont(
'',
'', $default_font_size - 1);
403 $pdf->SetTextColor(0, 0, 0);
406 $imglinesize = array();
407 if (!empty($realpatharray[$i])) {
411 $pdf->setTopMargin($tab_top_newpage);
412 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
413 $pageposbefore = $pdf->getPage();
415 $showpricebeforepagebreak = 1;
419 $curX = $this->posxdesc - 1;
421 $pdf->startTransaction();
422 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
423 $pageposafter = $pdf->getPage();
424 if ($pageposafter > $pageposbefore) {
425 $pdf->rollbackTransaction(
true);
426 $pageposafter = $pageposbefore;
428 $pdf->setPageOrientation(
'', 1, $heightforfooter);
429 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
430 $posyafter = $pdf->GetY();
431 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
432 if ($i == ($nblines - 1)) {
433 $pdf->AddPage(
'',
'',
true);
434 if (!empty($tplidx)) {
435 $pdf->useTemplate($tplidx);
438 $this->
_pagehead($pdf, $object, 0, $outputlangs);
440 $pdf->setPage($pageposafter + 1);
445 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
446 $showpricebeforepagebreak = 1;
448 $showpricebeforepagebreak = 0;
453 $pdf->commitTransaction();
455 $posYAfterDescription = $pdf->GetY();
457 $nexY = $pdf->GetY();
458 $pageposafter = $pdf->getPage();
459 $pdf->setPage($pageposbefore);
460 $pdf->setTopMargin($this->marge_haute);
461 $pdf->setPageOrientation(
'', 1, 0);
464 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
465 $pdf->setPage($pageposafter);
466 $curY = $tab_top_newpage;
469 $pdf->SetFont(
'',
'', $default_font_size - 1);
472 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
474 $pdf->SetXY($this->posxtva, $curY);
475 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
480 $pdf->SetXY($this->posxup, $curY);
481 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
485 $pdf->SetXY($this->posxqty, $curY);
486 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
490 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
491 $pdf->SetXY($this->posxunit, $curY);
492 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
496 if ($object->lines[$i]->remise_percent) {
497 $pdf->SetXY($this->posxdiscount - 2, $curY);
499 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
504 $pdf->SetXY($this->postotalht, $curY);
505 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
508 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
509 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
511 $tvaligne = $object->lines[$i]->total_tva;
514 $localtax1ligne = $object->lines[$i]->total_localtax1;
515 $localtax2ligne = $object->lines[$i]->total_localtax2;
522 $vatrate = (string) $object->lines[$i]->tva_tx;
523 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
524 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
526 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
529 if (empty($this->tva[$vatrate])) {
530 $this->tva[$vatrate] = 0;
532 if (empty($this->localtax1[$localtax1rate])) {
533 $this->localtax1[$localtax1rate] = 0;
535 if (empty($this->localtax2[$localtax2rate])) {
536 $this->localtax2[$localtax2rate] = 0;
538 $this->tva[$vatrate] += $tvaligne;
539 $this->localtax1[$localtax1rate] += $localtax1ligne;
540 $this->localtax2[$localtax2rate] += $localtax2ligne;
542 if ($posYAfterImage > $posYAfterDescription) {
543 $nexY = $posYAfterImage;
547 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
548 $pdf->setPage($pageposafter);
549 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
551 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
552 $pdf->SetLineStyle(array(
'dash'=>0));
558 while ($pagenb < $pageposafter) {
559 $pdf->setPage($pagenb);
561 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
563 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
565 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
567 $pdf->setPage($pagenb);
568 $pdf->setPageOrientation(
'', 1, 0);
570 $this->
_pagehead($pdf, $object, 0, $outputlangs);
573 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
575 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
577 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
579 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
582 if (!empty($tplidx)) {
583 $pdf->useTemplate($tplidx);
587 $this->
_pagehead($pdf, $object, 0, $outputlangs);
594 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
595 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
597 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
598 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
602 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
604 $amount_credit_notes_included = 0;
605 $amount_deposits_included = 0;
608 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->SUPPLIER_INVOICE_NO_PAYMENT_DETAILS)) {
613 $this->
_pagefoot($pdf, $object, $outputlangs);
614 if (method_exists($pdf,
'AliasNbPages')) {
615 $pdf->AliasNbPages();
620 $pdf->Output($file,
'F');
623 $hookmanager->initHooks(array(
'pdfgeneration'));
624 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
626 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
628 $this->error = $hookmanager->error;
629 $this->errors = $hookmanager->errors;
634 $this->result = array(
'fullpath'=>$file);
638 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
642 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
659 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
662 global $conf, $mysoc;
665 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
673 $pdf->SetFont(
'',
'', $default_font_size - 1);
678 if ($this->page_largeur < 210) {
681 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
687 $pdf->SetFillColor(255, 255, 255);
688 $pdf->SetXY($col1x, $tab2_top);
689 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
691 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
692 $pdf->SetXY($col2x, $tab2_top);
693 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
696 $pdf->SetFillColor(248, 248, 248);
698 $total_ttc = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
700 $this->atleastoneratenotnull = 0;
701 foreach ($this->tva as $tvakey => $tvaval) {
703 $this->atleastoneratenotnull++;
706 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
710 if (preg_match(
'/\*/', $tvakey)) {
711 $tvakey = str_replace(
'*',
'', $tvakey);
712 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
715 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
716 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
717 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
719 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
720 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
723 if (!$this->atleastoneratenotnull) {
725 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
726 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
727 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
728 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva, 0, $outputlangs), 0,
'R', 1);
731 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
733 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
734 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
735 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
736 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
740 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
742 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
743 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
744 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
745 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
751 foreach ($this->localtax1 as $tvakey => $tvaval) {
756 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
759 if (preg_match(
'/\*/', $tvakey)) {
760 $tvakey = str_replace(
'*',
'', $tvakey);
761 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
763 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
764 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
765 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
767 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
768 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
776 foreach ($this->localtax2 as $tvakey => $tvaval) {
781 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
784 if (preg_match(
'/\*/', $tvakey)) {
785 $tvakey = str_replace(
'*',
'', $tvakey);
786 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
788 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
789 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
790 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
792 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
793 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
801 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
802 $pdf->SetTextColor(0, 0, 60);
803 $pdf->SetFillColor(224, 224, 224);
804 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
806 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
807 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
809 $pdf->SetTextColor(0, 0, 0);
810 $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
811 $depositsamount = $object->getSumDepositsUsed((isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
813 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
814 if (!empty($object->paye)) {
818 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
821 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
822 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
823 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
824 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
827 if ($creditnoteamount) {
828 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
830 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
831 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
832 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
833 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
837 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
839 $pdf->SetFillColor(255, 255, 255);
841 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
842 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
843 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
844 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
850 $pdf->SetTextColor(0, 0, 60);
851 $pdf->SetFillColor(224, 224, 224);
852 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
853 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
855 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
856 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
857 $pdf->SetFont(
'',
'', $default_font_size - 1);
858 $pdf->SetTextColor(0, 0, 0);
862 return ($tab2_top + ($tab2_hl * $index));
879 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
889 $currency = !empty($currency) ? $currency : $conf->currency;
893 $pdf->SetTextColor(0, 0, 0);
894 $pdf->SetFont(
'',
'', $default_font_size - 2);
896 if (empty($hidetop)) {
897 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
898 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
899 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
902 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
903 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
907 $pdf->SetDrawColor(128, 128, 128);
908 $pdf->SetFont(
'',
'', $default_font_size - 1);
911 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
913 if (empty($hidetop)) {
914 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
916 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
917 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
920 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
921 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
922 if (empty($hidetop)) {
923 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
924 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
928 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
929 if (empty($hidetop)) {
930 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
931 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
934 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
935 if (empty($hidetop)) {
936 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
937 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
941 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
942 if (empty($hidetop)) {
943 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
945 $this->posxdiscount - $this->posxunit - 1,
947 $outputlangs->transnoentities(
"Unit"),
954 if ($this->atleastonediscount) {
955 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
956 if (empty($hidetop)) {
957 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
958 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
962 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
963 if (empty($hidetop)) {
964 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
965 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1073 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1075 global $langs, $conf, $mysoc;
1078 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1085 $pdf->SetTextColor(0, 0, 60);
1086 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1088 $posy = $this->marge_haute;
1089 $posx = $this->page_largeur - $this->marge_droite - 100;
1091 $pdf->SetXY($this->marge_gauche, $posy);
1113 $text = $this->emetteur->name;
1114 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1117 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1118 $pdf->SetXY($posx, $posy);
1119 $pdf->SetTextColor(0, 0, 60);
1120 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1121 if ($object->type == 1) {
1122 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1124 if ($object->type == 2) {
1125 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1127 if ($object->type == 3) {
1128 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1130 $pdf->MultiCell(100, 3, $title.
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
1133 if ($object->ref_supplier) {
1135 $pdf->SetFont(
'',
'B', $default_font_size);
1136 $pdf->SetXY($posx, $posy);
1137 $pdf->SetTextColor(0, 0, 60);
1138 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".$object->ref_supplier,
'',
'R');
1142 $pdf->SetFont(
'',
'', $default_font_size - 1);
1144 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1145 $object->fetch_projet();
1146 if (!empty($object->project->ref)) {
1148 $pdf->SetXY($posx, $posy);
1149 $pdf->SetTextColor(0, 0, 60);
1150 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1154 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1155 $object->fetch_projet();
1156 if (!empty($object->project->ref)) {
1157 $outputlangs->load(
"projects");
1159 $pdf->SetXY($posx, $posy);
1160 $langs->load(
"projects");
1161 $pdf->SetTextColor(0, 0, 60);
1162 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1166 if ($object->date) {
1168 $pdf->SetXY($posx, $posy);
1169 $pdf->SetTextColor(0, 0, 60);
1170 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1173 $pdf->SetXY($posx, $posy);
1174 $pdf->SetTextColor(255, 0, 0);
1175 $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1178 if ($object->thirdparty->code_fournisseur) {
1180 $pdf->SetXY($posx, $posy);
1181 $pdf->SetTextColor(0, 0, 60);
1182 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1186 $pdf->SetTextColor(0, 0, 60);
1190 $current_y = $pdf->getY();
1191 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1192 if ($current_y < $pdf->getY()) {
1193 $top_shift = $pdf->getY() - $current_y;
1198 $carac_emetteur =
'';
1200 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1201 if (count($arrayidcontact) > 0) {
1202 $object->fetch_user($arrayidcontact[0]);
1203 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1204 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1206 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1208 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1210 $carac_emetteur .=
"\n";
1213 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1216 $posy = 42 + $top_shift;
1217 $posx = $this->marge_gauche;
1218 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1219 $posx = $this->page_largeur - $this->marge_droite - 80;
1224 $pdf->SetTextColor(0, 0, 0);
1225 $pdf->SetFont(
'',
'', $default_font_size - 2);
1226 $pdf->SetXY($posx, $posy - 5);
1227 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1228 $pdf->SetXY($posx, $posy);
1229 $pdf->SetFillColor(230, 230, 230);
1230 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1231 $pdf->SetTextColor(0, 0, 60);
1234 $pdf->SetXY($posx + 2, $posy + 3);
1235 $pdf->SetFont(
'',
'B', $default_font_size);
1236 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1237 $posy = $pdf->getY();
1240 $pdf->SetXY($posx + 2, $posy);
1241 $pdf->SetFont(
'',
'', $default_font_size - 1);
1242 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1247 $usecontact =
false;
1248 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
1249 if (count($arrayidcontact) > 0) {
1251 $result = $object->fetch_contact($arrayidcontact[0]);
1255 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1256 $thirdparty = $object->contact;
1258 $thirdparty = $mysoc;
1263 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
1267 if ($this->page_largeur < 210) {
1270 $posy = 42 + $top_shift;
1271 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1272 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1273 $posx = $this->marge_gauche;
1277 $pdf->SetTextColor(0, 0, 0);
1278 $pdf->SetFont(
'',
'', $default_font_size - 2);
1279 $pdf->SetXY($posx + 2, $posy - 5);
1280 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1281 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1284 $pdf->SetXY($posx + 2, $posy + 3);
1285 $pdf->SetFont(
'',
'B', $default_font_size);
1286 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1288 $posy = $pdf->getY();
1291 $pdf->SetFont(
'',
'', $default_font_size - 1);
1292 $pdf->SetXY($posx + 2, $posy);
1293 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');