188 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
191 global $user, $langs,
$conf, $mysoc, $hookmanager;
193 if (!is_object($outputlangs)) {
194 $outputlangs = $langs;
198 $outputlangs->charset_output =
'ISO-8859-1';
202 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
206 if (
$conf->fournisseur->payment->dir_output) {
211 $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';
212 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
213 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
214 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
215 $sql .=
' AND pf.fk_paiementfourn = '.((int)
$object->id);
216 $resql = $this->db->query($sql);
218 if ($this->db->num_rows($resql) > 0) {
219 while ($objp = $this->db->fetch_object($resql)) {
220 $objp->type = $outputlangs->trans(
'SupplierInvoice');
230 $dir =
$conf->fournisseur->payment->dir_output;
231 $file = $dir.
"/SPECIMEN.pdf";
235 $dir =
$conf->fournisseur->payment->dir_output.
'/'.$objectref;
236 $file = $dir.
"/".$objectref.
".pdf";
242 if (!file_exists($dir)) {
244 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
249 if (file_exists($dir)) {
251 if (!is_object($hookmanager)) {
252 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
255 $hookmanager->initHooks(array(
'pdfgeneration'));
256 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
258 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
264 $heightforinfotot = 50;
266 $heightforfooter = $this->marge_basse + 8;
268 $heightforfooter += 6;
270 $pdf->setAutoPageBreak(
true, 0);
272 if (class_exists(
'TCPDF')) {
273 $pdf->setPrintHeader(
false);
274 $pdf->setPrintFooter(
false);
279 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
280 $tplidx = $pdf->importPage(1);
285 $pdf->SetDrawColor(128, 128, 128);
287 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
288 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
289 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
290 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
291 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
293 $pdf->SetCompression(
false);
297 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
302 if (!empty($tplidx)) {
303 $pdf->useTemplate($tplidx);
307 $pdf->SetFont(
'',
'', $default_font_size - 1);
308 $pdf->MultiCell(0, 3,
'');
309 $pdf->SetTextColor(0, 0, 0);
312 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
314 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
317 $height_incoterms = 0;
321 $iniY = $tab_top + 7;
322 $curY = $tab_top + 7;
323 $nexY = $tab_top + 7;
326 for ($i = 0; $i < $nblines; $i++) {
328 $pdf->SetFont(
'',
'', $default_font_size - 1);
329 $pdf->SetTextColor(0, 0, 0);
331 $pdf->setTopMargin($tab_top_newpage);
332 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext + $heightforinfotot);
333 $pageposbefore = $pdf->getPage();
336 $curX = $this->posxdate - 1;
337 $showpricebeforepagebreak = 1;
339 $pdf->startTransaction();
341 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
342 $pageposafter = $pdf->getPage();
343 if ($pageposafter > $pageposbefore) {
344 $pdf->rollbackTransaction(
true);
345 $pageposafter = $pageposbefore;
347 $pdf->setPageOrientation(
'',
true, $heightforfooter);
349 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
350 $posyafter = $pdf->GetY();
351 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
352 if ($i == ($nblines - 1)) {
353 $pdf->AddPage(
'',
'',
true);
354 if (!empty($tplidx)) {
355 $pdf->useTemplate($tplidx);
360 $pdf->setPage($pageposafter + 1);
366 $showpricebeforepagebreak = 1;
368 $showpricebeforepagebreak = 0;
372 $pdf->commitTransaction();
375 $nexY = $pdf->GetY();
376 $pageposafter = $pdf->getPage();
377 $pdf->setPage($pageposbefore);
378 $pdf->setTopMargin($this->marge_haute);
379 $pdf->setPageOrientation(
'',
true, 0);
382 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
383 $pdf->setPage($pageposafter);
384 $curY = $tab_top_newpage;
387 $pdf->SetFont(
'',
'', $default_font_size - 1);
390 $pdf->SetXY($this->posxreffacturefourn, $curY);
391 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L',
false);
394 $pdf->SetXY($this->posxreffacture, $curY);
395 $pdf->MultiCell($this->posxreffacture - 0.8, 3,
$object->lines[$i]->ref, 0,
'L',
false);
398 $pdf->SetXY($this->posxtype, $curY);
399 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L',
false);
402 $pdf->SetXY($this->posxtotalht, $curY);
403 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R',
false);
406 $pdf->SetXY($this->posxtva, $curY);
407 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R',
false);
410 $pdf->SetXY($this->posxtotalttc, $curY);
411 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R',
false);
416 $pdf->setPage($pageposafter);
417 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
419 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
420 $pdf->SetLineStyle(array(
'dash' => 0));
426 while ($pagenb < $pageposafter) {
427 $pdf->setPage($pagenb);
429 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
431 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
435 $pdf->setPage($pagenb);
436 $pdf->setPageOrientation(
'',
true, 0);
440 if (!empty($tplidx)) {
441 $pdf->useTemplate($tplidx);
444 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
446 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
448 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
453 if (!empty($tplidx)) {
454 $pdf->useTemplate($tplidx);
465 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
466 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
468 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
469 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
480 if (method_exists($pdf,
'AliasNbPages')) {
481 $pdf->AliasNbPages();
486 $pdf->Output($file,
'F');
489 $hookmanager->initHooks(array(
'pdfgeneration'));
490 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
492 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
494 $this->error = $hookmanager->error;
495 $this->errors = $hookmanager->errors;
500 $this->result = array(
'fullpath' => $file);
504 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
508 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
527 global
$conf, $mysoc;
531 $pdf->SetFont(
'',
'', $default_font_size - 1);
532 $pdf->SetFillColor(255, 255, 255);
535 $pdf->SetXY($this->marge_gauche, $posy);
536 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L',
true);
539 $pdf->SetXY($this->marge_gauche + 30, $posy);
540 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L',
true);
543 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
544 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R',
true);
548 $currency =
$conf->currency;
550 $pdf->SetXY($this->marge_gauche + 50, $posy);
551 $pdf->SetFont(
'',
'', $default_font_size - 3);
552 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L',
true);
553 $pdf->SetFont(
'',
'', $default_font_size - 1);
557 $pdf->SetXY($this->marge_gauche + 50, $posy);
558 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L',
true);
561 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
562 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R',
true);
566 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
567 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L',
true);
571 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
572 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L',
true);
635 global $langs,
$conf, $mysoc;
638 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
645 $pdf->SetTextColor(0, 0, 60);
646 $pdf->SetFont(
'',
'B', $default_font_size + 3);
648 $posy = $this->marge_haute;
649 $posx = $this->page_largeur - $this->marge_droite - 100;
651 $pdf->SetXY($this->marge_gauche, $posy);
654 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
656 if (is_readable($logo)) {
658 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
660 $pdf->SetTextColor(200, 0, 0);
661 $pdf->SetFont(
'',
'B', $default_font_size - 2);
662 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
663 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
666 $text = $this->emetteur->name;
667 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
746 $posx = $this->marge_gauche;
748 $posx = $this->page_largeur - $this->marge_droite - 80;
753 $pdf->SetTextColor(0, 0, 0);
754 $pdf->SetFont(
'',
'', $default_font_size - 2);
755 $pdf->SetXY($posx, $posy - 5);
756 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
757 $pdf->SetXY($posx, $posy);
758 $pdf->SetFillColor(230, 230, 230);
759 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
760 $pdf->SetTextColor(0, 0, 60);
763 $pdf->SetXY($posx + 2, $posy + 3);
764 $pdf->SetFont(
'',
'B', $default_font_size);
765 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
766 $posy = $pdf->getY();
769 $pdf->SetXY($posx + 2, $posy);
770 $pdf->SetFont(
'',
'', $default_font_size - 1);
771 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
774 $thirdparty =
$object->thirdparty;
784 if ($this->page_largeur < 210) {
788 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
790 $posx = $this->marge_gauche;
794 $pdf->SetTextColor(0, 0, 0);
795 $pdf->SetFont(
'',
'', $default_font_size - 2);
796 $pdf->SetXY($posx + 2, $posy - 5);
797 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
798 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
801 $pdf->SetXY($posx + 2, $posy + 3);
802 $pdf->SetFont(
'',
'B', $default_font_size);
803 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
805 $posy = $pdf->getY();
808 $pdf->SetFont(
'',
'', $default_font_size - 1);
809 $pdf->SetXY($posx + 2, $posy);
810 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
814 $sql =
"SELECT iban_prefix as iban";
815 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
816 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
817 $sql .=
" AND rib.default_rib = 1";
818 $sql .=
" AND rib.type = 'ban'";
820 $resql = $this->db->query($sql);
822 $obj = $this->db->fetch_object($resql);
829 $pdf->SetFont(
'',
'', $default_font_size - 1);
830 $pdf->SetXY($posx + 2, $posy + 15);
831 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');