166 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
169 global $user, $langs,
$conf, $mysoc, $hookmanager;
171 if (!is_object($outputlangs)) {
172 $outputlangs = $langs;
176 $outputlangs->charset_output =
'ISO-8859-1';
180 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
184 if (
$conf->fournisseur->payment->dir_output) {
189 $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';
190 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
191 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
192 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
193 $sql .=
' AND pf.fk_paiementfourn = '.((int)
$object->id);
194 $resql = $this->db->query($sql);
196 if ($this->db->num_rows($resql) > 0) {
197 while ($objp = $this->db->fetch_object($resql)) {
198 $objp->type = $outputlangs->trans(
'SupplierInvoice');
208 $dir =
$conf->fournisseur->payment->dir_output;
209 $file = $dir.
"/SPECIMEN.pdf";
213 $dir =
$conf->fournisseur->payment->dir_output.
'/'.$objectref;
214 $file = $dir.
"/".$objectref.
".pdf";
220 if (!file_exists($dir)) {
222 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
227 if (file_exists($dir)) {
229 if (!is_object($hookmanager)) {
230 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
233 $hookmanager->initHooks(array(
'pdfgeneration'));
234 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
236 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
242 $heightforinfotot = 50;
244 $heightforfooter = $this->marge_basse + 8;
246 $heightforfooter += 6;
248 $pdf->SetAutoPageBreak(1, 0);
250 if (class_exists(
'TCPDF')) {
251 $pdf->setPrintHeader(
false);
252 $pdf->setPrintFooter(
false);
257 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
258 $tplidx = $pdf->importPage(1);
263 $pdf->SetDrawColor(128, 128, 128);
265 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
266 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
267 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
268 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
269 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
271 $pdf->SetCompression(
false);
275 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
280 if (!empty($tplidx)) {
281 $pdf->useTemplate($tplidx);
285 $pdf->SetFont(
'',
'', $default_font_size - 1);
286 $pdf->MultiCell(0, 3,
'');
287 $pdf->SetTextColor(0, 0, 0);
290 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
292 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
295 $height_incoterms = 0;
299 $iniY = $tab_top + 7;
300 $curY = $tab_top + 7;
301 $nexY = $tab_top + 7;
304 for ($i = 0; $i < $nblines; $i++) {
306 $pdf->SetFont(
'',
'', $default_font_size - 1);
307 $pdf->SetTextColor(0, 0, 0);
309 $pdf->setTopMargin($tab_top_newpage);
310 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
311 $pageposbefore = $pdf->getPage();
314 $curX = $this->posxdate - 1;
315 $showpricebeforepagebreak = 1;
317 $pdf->startTransaction();
319 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
320 $pageposafter = $pdf->getPage();
321 if ($pageposafter > $pageposbefore) {
322 $pdf->rollbackTransaction(
true);
323 $pageposafter = $pageposbefore;
325 $pdf->setPageOrientation(
'', 1, $heightforfooter);
327 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
328 $posyafter = $pdf->GetY();
329 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
330 if ($i == ($nblines - 1)) {
331 $pdf->AddPage(
'',
'',
true);
332 if (!empty($tplidx)) {
333 $pdf->useTemplate($tplidx);
338 $pdf->setPage($pageposafter + 1);
344 $showpricebeforepagebreak = 1;
346 $showpricebeforepagebreak = 0;
350 $pdf->commitTransaction();
353 $nexY = $pdf->GetY();
354 $pageposafter = $pdf->getPage();
355 $pdf->setPage($pageposbefore);
356 $pdf->setTopMargin($this->marge_haute);
357 $pdf->setPageOrientation(
'', 1, 0);
360 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
361 $pdf->setPage($pageposafter);
362 $curY = $tab_top_newpage;
365 $pdf->SetFont(
'',
'', $default_font_size - 1);
368 $pdf->SetXY($this->posxreffacturefourn, $curY);
369 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L', 0);
372 $pdf->SetXY($this->posxreffacture, $curY);
373 $pdf->MultiCell($this->posxreffacture - 0.8, 3,
$object->lines[$i]->ref, 0,
'L', 0);
376 $pdf->SetXY($this->posxtype, $curY);
377 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L', 0);
380 $pdf->SetXY($this->posxtotalht, $curY);
381 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R', 0);
384 $pdf->SetXY($this->posxtva, $curY);
385 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R', 0);
388 $pdf->SetXY($this->posxtotalttc, $curY);
389 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R', 0);
394 $pdf->setPage($pageposafter);
395 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
397 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
398 $pdf->SetLineStyle(array(
'dash' => 0));
404 while ($pagenb < $pageposafter) {
405 $pdf->setPage($pagenb);
407 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
409 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
413 $pdf->setPage($pagenb);
414 $pdf->setPageOrientation(
'', 1, 0);
418 if (!empty($tplidx)) {
419 $pdf->useTemplate($tplidx);
422 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
424 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
426 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
431 if (!empty($tplidx)) {
432 $pdf->useTemplate($tplidx);
443 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
444 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
446 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
447 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
458 if (method_exists($pdf,
'AliasNbPages')) {
459 $pdf->AliasNbPages();
464 $pdf->Output($file,
'F');
467 $hookmanager->initHooks(array(
'pdfgeneration'));
468 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
470 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
472 $this->error = $hookmanager->error;
473 $this->errors = $hookmanager->errors;
478 $this->result = array(
'fullpath' => $file);
482 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
486 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
505 global
$conf, $mysoc;
509 $pdf->SetFont(
'',
'', $default_font_size - 1);
510 $pdf->SetFillColor(255, 255, 255);
513 $pdf->SetXY($this->marge_gauche, $posy);
514 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
517 $pdf->SetXY($this->marge_gauche + 30, $posy);
518 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L', 1);
521 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
522 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R', 1);
526 $currency =
$conf->currency;
528 $pdf->SetXY($this->marge_gauche + 50, $posy);
529 $pdf->SetFont(
'',
'', $default_font_size - 3);
530 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
531 $pdf->SetFont(
'',
'', $default_font_size - 1);
535 $pdf->SetXY($this->marge_gauche + 50, $posy);
536 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L', 1);
539 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
540 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
544 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
545 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
549 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
550 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
613 global $langs,
$conf, $mysoc;
616 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
623 $pdf->SetTextColor(0, 0, 60);
624 $pdf->SetFont(
'',
'B', $default_font_size + 3);
626 $posy = $this->marge_haute;
627 $posx = $this->page_largeur - $this->marge_droite - 100;
629 $pdf->SetXY($this->marge_gauche, $posy);
632 $logo =
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
634 if (is_readable($logo)) {
636 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
638 $pdf->SetTextColor(200, 0, 0);
639 $pdf->SetFont(
'',
'B', $default_font_size - 2);
640 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
641 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
644 $text = $this->emetteur->name;
645 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
725 $posx = $this->marge_gauche;
727 $posx = $this->page_largeur - $this->marge_droite - 80;
732 $pdf->SetTextColor(0, 0, 0);
733 $pdf->SetFont(
'',
'', $default_font_size - 2);
734 $pdf->SetXY($posx, $posy - 5);
735 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
736 $pdf->SetXY($posx, $posy);
737 $pdf->SetFillColor(230, 230, 230);
738 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
739 $pdf->SetTextColor(0, 0, 60);
742 $pdf->SetXY($posx + 2, $posy + 3);
743 $pdf->SetFont(
'',
'B', $default_font_size);
744 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
745 $posy = $pdf->getY();
748 $pdf->SetXY($posx + 2, $posy);
749 $pdf->SetFont(
'',
'', $default_font_size - 1);
750 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
753 $thirdparty =
$object->thirdparty;
763 if ($this->page_largeur < 210) {
767 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
769 $posx = $this->marge_gauche;
773 $pdf->SetTextColor(0, 0, 0);
774 $pdf->SetFont(
'',
'', $default_font_size - 2);
775 $pdf->SetXY($posx + 2, $posy - 5);
776 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
777 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
780 $pdf->SetXY($posx + 2, $posy + 3);
781 $pdf->SetFont(
'',
'B', $default_font_size);
782 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
784 $posy = $pdf->getY();
787 $pdf->SetFont(
'',
'', $default_font_size - 1);
788 $pdf->SetXY($posx + 2, $posy);
789 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
793 $sql =
"SELECT iban_prefix as iban";
794 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
795 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
796 $sql .=
" AND rib.default_rib = 1";
797 $sql .=
" AND rib.type = 'ban'";
799 $resql = $this->db->query($sql);
801 $obj = $this->db->fetch_object($resql);
808 $pdf->SetFont(
'',
'', $default_font_size - 1);
809 $pdf->SetXY($posx + 2, $posy + 15);
810 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');