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);
493 $this->warnings = $hookmanager->warnings;
495 $this->error = $hookmanager->error;
496 $this->errors = $hookmanager->errors;
503 $this->result = array(
'fullpath' => $file);
507 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
511 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
534 $pdf->SetFont(
'',
'', $default_font_size - 1);
535 $pdf->SetFillColor(255, 255, 255);
538 $pdf->SetXY($this->marge_gauche, $posy);
539 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L',
true);
542 $pdf->SetXY($this->marge_gauche + 30, $posy);
543 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L',
true);
546 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
547 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R',
true);
551 $currency = $conf->currency;
553 $pdf->SetXY($this->marge_gauche + 50, $posy);
554 $pdf->SetFont(
'',
'', $default_font_size - 3);
555 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L',
true);
556 $pdf->SetFont(
'',
'', $default_font_size - 1);
560 $pdf->SetXY($this->marge_gauche + 50, $posy);
561 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L',
true);
564 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
565 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R',
true);
569 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
570 $pdf->MultiCell(150, 4,
$mysoc->town, 0,
'L',
true);
574 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
575 $pdf->MultiCell(150, 4,
date(
"d").
' '.$outputlangs->transnoentitiesnoconv(
date(
"F")).
' '.
date(
"Y"), 0,
'L',
true);
638 global $langs, $conf,
$mysoc;
641 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
648 $pdf->SetTextColor(0, 0, 60);
649 $pdf->SetFont(
'',
'B', $default_font_size + 3);
651 $posy = $this->marge_haute;
652 $posx = $this->page_largeur - $this->marge_droite - 100;
654 $pdf->SetXY($this->marge_gauche, $posy);
657 $logo = $conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
659 if (is_readable($logo)) {
661 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
663 $pdf->SetTextColor(200, 0, 0);
664 $pdf->SetFont(
'',
'B', $default_font_size - 2);
665 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
666 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
669 $text = $this->emetteur->name;
670 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
749 $posx = $this->marge_gauche;
751 $posx = $this->page_largeur - $this->marge_droite - 80;
756 $pdf->SetTextColor(0, 0, 0);
757 $pdf->SetFont(
'',
'', $default_font_size - 2);
758 $pdf->SetXY($posx, $posy - 5);
759 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
760 $pdf->SetXY($posx, $posy);
761 $pdf->SetFillColor(230, 230, 230);
762 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
763 $pdf->SetTextColor(0, 0, 60);
766 $pdf->SetXY($posx + 2, $posy + 3);
767 $pdf->SetFont(
'',
'B', $default_font_size);
768 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
769 $posy = $pdf->getY();
772 $pdf->SetXY($posx + 2, $posy);
773 $pdf->SetFont(
'',
'', $default_font_size - 1);
774 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
777 $thirdparty =
$object->thirdparty;
787 if ($this->page_largeur < 210) {
791 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
793 $posx = $this->marge_gauche;
797 $pdf->SetTextColor(0, 0, 0);
798 $pdf->SetFont(
'',
'', $default_font_size - 2);
799 $pdf->SetXY($posx + 2, $posy - 5);
800 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
801 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
804 $pdf->SetXY($posx + 2, $posy + 3);
805 $pdf->SetFont(
'',
'B', $default_font_size);
806 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
808 $posy = $pdf->getY();
811 $pdf->SetFont(
'',
'', $default_font_size - 1);
812 $pdf->SetXY($posx + 2, $posy);
813 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
817 $sql =
"SELECT iban_prefix as iban";
818 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
819 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
820 $sql .=
" AND rib.default_rib = 1";
821 $sql .=
" AND rib.type = 'ban'";
823 $resql = $this->db->query($sql);
825 $obj = $this->db->fetch_object($resql);
832 $pdf->SetFont(
'',
'', $default_font_size - 1);
833 $pdf->SetXY($posx + 2, $posy + 15);
834 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');