235 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
240 if (!is_object($outputlangs)) {
241 $outputlangs = $langs;
245 $outputlangs->charset_output =
'ISO-8859-1';
249 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
253 if (
$conf->fournisseur->payment->dir_output) {
258 $sql =
'SELECT f.rowid, f.ref, f.datef, f.ref_supplier, f.total_ht, f.total_tva, f.total_ttc, pf.amount, f.rowid as facid, f.paye';
259 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
260 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
261 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
262 $sql .=
' AND pf.fk_paiementfourn = '.((int)
$object->id);
263 $resql = $this->db->query($sql);
265 if ($this->db->num_rows($resql) > 0) {
266 while ($objp = $this->db->fetch_object($resql)) {
267 $objp->type = $outputlangs->trans(
'SupplierInvoice');
277 $dir =
$conf->fournisseur->payment->dir_output;
278 $file = $dir.
"/SPECIMEN.pdf";
282 $dir =
$conf->fournisseur->payment->dir_output.
'/'.$objectref;
283 $file = $dir.
"/".$objectref.
".pdf";
289 if (!file_exists($dir)) {
291 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
296 if (file_exists($dir)) {
298 if (!is_object($hookmanager)) {
299 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
302 $hookmanager->initHooks(array(
'pdfgeneration'));
303 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
305 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
311 $heightforinfotot = 50;
313 $heightforfooter = $this->marge_basse + 8;
315 $heightforfooter += 6;
317 $pdf->setAutoPageBreak(
true, 0);
319 if (class_exists(
'TCPDF')) {
320 $pdf->setPrintHeader(
false);
321 $pdf->setPrintFooter(
false);
326 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
327 $tplidx = $pdf->importPage(1);
332 $pdf->SetDrawColor(128, 128, 128);
334 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
335 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
336 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
337 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
338 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
340 $pdf->SetCompression(
false);
344 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
349 if (!empty($tplidx)) {
350 $pdf->useTemplate($tplidx);
354 $pdf->SetFont(
'',
'', $default_font_size - 1);
355 $pdf->MultiCell(0, 3,
'');
356 $pdf->SetTextColor(0, 0, 0);
359 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
361 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
364 $height_incoterms = 0;
368 $iniY = $tab_top + 7;
369 $curY = $tab_top + 7;
370 $nexY = $tab_top + 7;
373 for ($i = 0; $i < $nblines; $i++) {
375 $pdf->SetFont(
'',
'', $default_font_size - 1);
376 $pdf->SetTextColor(0, 0, 0);
378 $pdf->setTopMargin($tab_top_newpage);
379 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
380 $pageposbefore = $pdf->getPage();
383 $curX = $this->posxdate - 1;
384 $showpricebeforepagebreak = 1;
386 $pdf->startTransaction();
388 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
389 $pageposafter = $pdf->getPage();
390 if ($pageposafter > $pageposbefore) {
391 $pdf->rollbackTransaction(
true);
392 $pageposafter = $pageposbefore;
394 $pdf->setPageOrientation(
'',
true, $heightforfooter);
396 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
397 $posyafter = $pdf->GetY();
398 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
399 if ($i == ($nblines - 1)) {
400 $pdf->AddPage(
'',
'',
true);
401 if (!empty($tplidx)) {
402 $pdf->useTemplate($tplidx);
407 $pdf->setPage($pageposafter + 1);
413 $showpricebeforepagebreak = 1;
415 $showpricebeforepagebreak = 0;
419 $pdf->commitTransaction();
422 $nexY = $pdf->GetY();
423 $pageposafter = $pdf->getPage();
424 $pdf->setPage($pageposbefore);
425 $pdf->setTopMargin($this->marge_haute);
426 $pdf->setPageOrientation(
'',
true, 0);
429 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
430 $pdf->setPage($pageposafter);
431 $curY = $tab_top_newpage;
434 $pdf->SetFont(
'',
'', $default_font_size - 1);
437 $pdf->SetXY($this->posxreffacturefourn, $curY);
438 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L',
false);
441 $pdf->SetXY($this->posxreffacture, $curY);
442 $pdf->MultiCell($this->posxreffacture - 0.8, 3, (
string)
$object->lines[$i]->ref, 0,
'L',
false);
445 $pdf->SetXY($this->posxtype, $curY);
446 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L',
false);
449 $pdf->SetXY($this->posxtotalht, $curY);
450 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R',
false);
453 $pdf->SetXY($this->posxtva, $curY);
454 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R',
false);
457 $pdf->SetXY($this->posxtotalttc, $curY);
458 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R',
false);
463 $pdf->setPage($pageposafter);
464 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
466 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
467 $pdf->SetLineStyle(array(
'dash' => 0));
473 while ($pagenb < $pageposafter) {
474 $pdf->setPage($pagenb);
476 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
478 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
482 $pdf->setPage($pagenb);
483 $pdf->setPageOrientation(
'',
true, 0);
487 if (!empty($tplidx)) {
488 $pdf->useTemplate($tplidx);
491 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
493 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
495 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
500 if (!empty($tplidx)) {
501 $pdf->useTemplate($tplidx);
512 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
513 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
515 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
516 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
527 if (method_exists($pdf,
'AliasNbPages')) {
528 $pdf->AliasNbPages();
533 $pdf->Output($file,
'F');
536 $hookmanager->initHooks(array(
'pdfgeneration'));
537 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
539 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
540 $this->warnings = $hookmanager->warnings;
542 $this->error = $hookmanager->error;
543 $this->errors = $hookmanager->errors;
550 $this->result = array(
'fullpath' => $file);
554 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
558 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
581 $pdf->SetFont(
'',
'', $default_font_size - 1);
582 $pdf->SetFillColor(255, 255, 255);
585 $pdf->SetXY($this->marge_gauche, $posy);
586 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L',
true);
589 $pdf->SetXY($this->marge_gauche + 30, $posy);
590 $pdf->MultiCell(50, 4, (
string)
$object->ref, 0,
'L',
true);
593 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
594 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R',
true);
598 $currency =
$conf->currency;
600 $pdf->SetXY($this->marge_gauche + 50, $posy);
601 $pdf->SetFont(
'',
'', $default_font_size - 3);
602 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L',
true);
603 $pdf->SetFont(
'',
'', $default_font_size - 1);
607 $pdf->SetXY($this->marge_gauche + 50, $posy);
608 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L',
true);
611 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
612 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R',
true);
616 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
617 $pdf->MultiCell(150, 4, (
string)
$mysoc->town, 0,
'L',
true);
621 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
622 $pdf->MultiCell(150, 4,
date(
"d").
' '.$outputlangs->transnoentitiesnoconv(
date(
"F")).
' '.
date(
"Y"), 0,
'L',
true);
684 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"banks",
"suppliers"));
691 $pdf->SetTextColor(0, 0, 60);
692 $pdf->SetFont(
'',
'B', $default_font_size + 3);
694 $posy = $this->marge_haute;
695 $posx = $this->page_largeur - $this->marge_droite - 100;
697 $pdf->SetXY($this->marge_gauche, $posy);
700 $logo =
$conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
702 if (is_readable($logo)) {
704 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
706 $pdf->SetTextColor(200, 0, 0);
707 $pdf->SetFont(
'',
'B', $default_font_size - 2);
708 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
709 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
712 $text = $this->emetteur->name;
713 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
717 $pdf->SetFont(
'',
'B', $default_font_size + 3);
718 $pdf->SetXY($posx, $posy);
719 $pdf->SetTextColor(0, 0, 60);
720 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"SupplierPayment").
" ".$outputlangs->convToOutputCharset(
$object->ref), 0,
'R');
722 $pdf->SetFont(
'',
'', $default_font_size - 1);
725 $pdf->SetXY($posx, $posy);
726 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true), 0,
'R');
731 if (!empty($supplierRefs)) {
732 $pdf->SetXY($posx, $posy);
733 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".implode(
', ', $supplierRefs), 0,
'R');
738 if (!empty($ibanDest)) {
739 $pdf->SetXY($posx, $posy);
740 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"IBAN").
" : ".$ibanDest, 0,
'R');
820 $posx = $this->marge_gauche;
822 $posx = $this->page_largeur - $this->marge_droite - 80;
827 $pdf->SetTextColor(0, 0, 0);
828 $pdf->SetFont(
'',
'', $default_font_size - 2);
829 $pdf->SetXY($posx, $posy - 5);
830 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
831 $pdf->SetXY($posx, $posy);
832 $pdf->SetFillColor(230, 230, 230);
833 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
834 $pdf->SetTextColor(0, 0, 60);
837 $pdf->SetXY($posx + 2, $posy + 3);
838 $pdf->SetFont(
'',
'B', $default_font_size);
839 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
840 $posy = $pdf->getY();
843 $pdf->SetXY($posx + 2, $posy);
844 $pdf->SetFont(
'',
'', $default_font_size - 1);
845 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
848 $thirdparty =
$object->thirdparty;
858 if ($this->page_largeur < 210) {
862 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
864 $posx = $this->marge_gauche;
868 $pdf->SetTextColor(0, 0, 0);
869 $pdf->SetFont(
'',
'', $default_font_size - 2);
870 $pdf->SetXY($posx + 2, $posy - 5);
871 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
872 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
875 $pdf->SetXY($posx + 2, $posy + 3);
876 $pdf->SetFont(
'',
'B', $default_font_size);
877 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
879 $posy = $pdf->getY();
882 $pdf->SetFont(
'',
'', $default_font_size - 1);
883 $pdf->SetXY($posx + 2, $posy);
884 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
889 $pdf->SetFont(
'',
'', $default_font_size - 1);
890 $pdf->SetXY($posx + 2, $posy + 15);
891 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');
895 if (!empty(
$object->fk_account) && (
int)
$object->fk_account > 0) {
896 $bankaccount =
new Account($this->db);
897 if ($bankaccount->fetch((
int)
$object->fk_account) > 0) {
898 $ibanOrigin =
dolDecrypt((
string) $bankaccount->iban);
899 if ($ibanOrigin ===
'' && !empty($bankaccount->iban)) {
900 $ibanOrigin = (
string) $bankaccount->iban;
902 $label = (
string) $bankaccount->label;
903 $line = $outputlangs->transnoentities(
"BankAccount").
': '.$label;
904 if ($ibanOrigin !==
'') {
905 $line .=
' - '.$langs->trans(
"IBAN").
': '.$ibanOrigin;
906 } elseif (!empty($bankaccount->number)) {
907 $line .=
' - '.$outputlangs->transnoentities(
"Account").
': '.$bankaccount->number;
910 $pdf->SetFont(
'',
'', $default_font_size - 2);
911 $pdf->SetTextColor(0, 0, 0);
912 $pdf->SetXY($this->marge_gauche, 82);
913 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 4, $line, 0,
'L');
914 $pdf->SetTextColor(0, 0, 60);