158 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
161 global $user, $langs, $conf, $mysoc, $hookmanager;
163 if (!is_object($outputlangs)) {
164 $outputlangs = $langs;
168 $outputlangs->charset_output =
'ISO-8859-1';
172 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
174 $object->factures = array();
176 if ($conf->fournisseur->payment->dir_output) {
177 $object->fetch_thirdparty();
181 $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';
182 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
183 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
184 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
185 $sql .=
' AND pf.fk_paiementfourn = '.((int) $object->id);
186 $resql = $this->db->query($sql);
188 if ($this->db->num_rows($resql) > 0) {
189 while ($objp = $this->db->fetch_object($resql)) {
190 $objp->type = $outputlangs->trans(
'SupplierInvoice');
191 $object->lines[] = $objp;
196 $total = $object->amount;
199 if ($object->specimen) {
200 $dir = $conf->fournisseur->payment->dir_output;
201 $file = $dir.
"/SPECIMEN.pdf";
205 $dir = $conf->fournisseur->payment->dir_output.
'/'.$objectref;
206 $file = $dir.
"/".$objectref.
".pdf";
212 if (!file_exists($dir)) {
214 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
219 if (file_exists($dir)) {
221 if (!is_object($hookmanager)) {
222 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
225 $hookmanager->initHooks(array(
'pdfgeneration'));
226 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
228 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
230 $nblines = (empty($object->lines) ? 0 : count($object->lines));
234 $heightforinfotot = 50;
235 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
236 $heightforfooter = $this->marge_basse + 8;
238 $heightforfooter += 6;
240 $pdf->SetAutoPageBreak(1, 0);
242 if (class_exists(
'TCPDF')) {
243 $pdf->setPrintHeader(
false);
244 $pdf->setPrintFooter(
false);
249 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
250 $tplidx = $pdf->importPage(1);
255 $pdf->SetDrawColor(128, 128, 128);
257 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
258 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
259 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
260 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
261 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
263 $pdf->SetCompression(
false);
266 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
271 if (!empty($tplidx)) {
272 $pdf->useTemplate($tplidx);
275 $this->
_pagehead($pdf, $object, 1, $outputlangs);
276 $pdf->SetFont(
'',
'', $default_font_size - 1);
277 $pdf->MultiCell(0, 3,
'');
278 $pdf->SetTextColor(0, 0, 0);
281 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
283 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
286 $height_incoterms = 0;
290 $iniY = $tab_top + 7;
291 $curY = $tab_top + 7;
292 $nexY = $tab_top + 7;
295 for ($i = 0; $i < $nblines; $i++) {
297 $pdf->SetFont(
'',
'', $default_font_size - 1);
298 $pdf->SetTextColor(0, 0, 0);
300 $pdf->setTopMargin($tab_top_newpage);
301 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
302 $pageposbefore = $pdf->getPage();
305 $curX = $this->posxdate - 1;
306 $showpricebeforepagebreak = 1;
308 $pdf->startTransaction();
310 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
311 $pageposafter = $pdf->getPage();
312 if ($pageposafter > $pageposbefore) {
313 $pdf->rollbackTransaction(
true);
314 $pageposafter = $pageposbefore;
316 $pdf->setPageOrientation(
'', 1, $heightforfooter);
318 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
319 $posyafter = $pdf->GetY();
320 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
321 if ($i == ($nblines - 1)) {
322 $pdf->AddPage(
'',
'',
true);
323 if (!empty($tplidx)) {
324 $pdf->useTemplate($tplidx);
327 $this->
_pagehead($pdf, $object, 0, $outputlangs);
329 $pdf->setPage($pageposafter + 1);
335 $showpricebeforepagebreak = 1;
337 $showpricebeforepagebreak = 0;
341 $pdf->commitTransaction();
344 $nexY = $pdf->GetY();
345 $pageposafter = $pdf->getPage();
346 $pdf->setPage($pageposbefore);
347 $pdf->setTopMargin($this->marge_haute);
348 $pdf->setPageOrientation(
'', 1, 0);
351 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
352 $pdf->setPage($pageposafter);
353 $curY = $tab_top_newpage;
356 $pdf->SetFont(
'',
'', $default_font_size - 1);
359 $pdf->SetXY($this->posxreffacturefourn, $curY);
360 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0,
'L', 0);
363 $pdf->SetXY($this->posxreffacture, $curY);
364 $pdf->MultiCell($this->posxreffacture - 0.8, 3, $object->lines[$i]->ref, 0,
'L', 0);
367 $pdf->SetXY($this->posxtype, $curY);
368 $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0,
'L', 0);
371 $pdf->SetXY($this->posxtotalht, $curY);
372 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price($object->lines[$i]->total_ht), 0,
'R', 0);
375 $pdf->SetXY($this->posxtva, $curY);
376 $pdf->MultiCell($this->posxtva - 0.8, 3,
price($object->lines[$i]->total_tva), 0,
'R', 0);
379 $pdf->SetXY($this->posxtotalttc, $curY);
380 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price($object->lines[$i]->total_ttc), 0,
'R', 0);
385 $pdf->setPage($pageposafter);
386 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
388 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
389 $pdf->SetLineStyle(array(
'dash'=>0));
395 while ($pagenb < $pageposafter) {
396 $pdf->setPage($pagenb);
398 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
400 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
402 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
404 $pdf->setPage($pagenb);
405 $pdf->setPageOrientation(
'', 1, 0);
407 $this->
_pagehead($pdf, $object, 0, $outputlangs);
409 if (!empty($tplidx)) {
410 $pdf->useTemplate($tplidx);
413 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
415 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
417 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
419 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
422 if (!empty($tplidx)) {
423 $pdf->useTemplate($tplidx);
427 $this->
_pagehead($pdf, $object, 0, $outputlangs);
434 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
435 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
437 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
438 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
442 $posy = $this->
_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
448 $this->
_pagefoot($pdf, $object, $outputlangs);
449 if (method_exists($pdf,
'AliasNbPages')) {
450 $pdf->AliasNbPages();
455 $pdf->Output($file,
'F');
458 $hookmanager->initHooks(array(
'pdfgeneration'));
459 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
461 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
463 $this->error = $hookmanager->error;
464 $this->errors = $hookmanager->errors;
469 $this->result = array(
'fullpath'=>$file);
473 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
477 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
496 global $conf, $mysoc;
500 $pdf->SetFont(
'',
'', $default_font_size - 1);
501 $pdf->SetFillColor(255, 255, 255);
504 $pdf->SetXY($this->marge_gauche, $posy);
505 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
508 $pdf->SetXY($this->marge_gauche + 30, $posy);
509 $pdf->MultiCell(50, 4, $object->ref, 0,
'L', 1);
512 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
513 $pdf->MultiCell(50, 4,
price($object->amount), 0,
'R', 1);
517 $currency = $conf->currency;
519 $pdf->SetXY($this->marge_gauche + 50, $posy);
520 $pdf->SetFont(
'',
'', $default_font_size - 3);
521 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
522 $pdf->SetFont(
'',
'', $default_font_size - 1);
526 $pdf->SetXY($this->marge_gauche + 50, $posy);
527 $pdf->MultiCell(150, 4, $object->thirdparty->name, 0,
'L', 1);
530 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
531 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price($object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
535 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
536 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
540 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
541 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
602 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
604 global $langs, $conf, $mysoc;
607 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
614 $pdf->SetTextColor(0, 0, 60);
615 $pdf->SetFont(
'',
'B', $default_font_size + 3);
617 $posy = $this->marge_haute;
618 $posx = $this->page_largeur - $this->marge_droite - 100;
620 $pdf->SetXY($this->marge_gauche, $posy);
623 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
625 if (is_readable($logo)) {
627 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
629 $pdf->SetTextColor(200, 0, 0);
630 $pdf->SetFont(
'',
'B', $default_font_size - 2);
631 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
632 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
635 $text = $this->emetteur->name;
636 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
712 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
716 $posx = $this->marge_gauche;
718 $posx = $this->page_largeur - $this->marge_droite - 80;
723 $pdf->SetTextColor(0, 0, 0);
724 $pdf->SetFont(
'',
'', $default_font_size - 2);
725 $pdf->SetXY($posx, $posy - 5);
726 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
727 $pdf->SetXY($posx, $posy);
728 $pdf->SetFillColor(230, 230, 230);
729 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
730 $pdf->SetTextColor(0, 0, 60);
733 $pdf->SetXY($posx + 2, $posy + 3);
734 $pdf->SetFont(
'',
'B', $default_font_size);
735 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
736 $posy = $pdf->getY();
739 $pdf->SetXY($posx + 2, $posy);
740 $pdf->SetFont(
'',
'', $default_font_size - 1);
741 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
744 $thirdparty = $object->thirdparty;
750 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
754 if ($this->page_largeur < 210) {
758 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
760 $posx = $this->marge_gauche;
764 $pdf->SetTextColor(0, 0, 0);
765 $pdf->SetFont(
'',
'', $default_font_size - 2);
766 $pdf->SetXY($posx + 2, $posy - 5);
767 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
768 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
771 $pdf->SetXY($posx + 2, $posy + 3);
772 $pdf->SetFont(
'',
'B', $default_font_size);
773 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
775 $posy = $pdf->getY();
778 $pdf->SetFont(
'',
'', $default_font_size - 1);
779 $pdf->SetXY($posx + 2, $posy);
780 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
784 $sql =
"SELECT iban_prefix as iban";
785 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
786 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
787 $sql .=
" AND rib.default_rib = 1";
788 $sql .=
" AND rib.type = 'ban'";
790 $resql = $this->db->query($sql);
792 $obj = $this->db->fetch_object($resql);
799 $pdf->SetFont(
'',
'', $default_font_size - 1);
800 $pdf->SetXY($posx + 2, $posy + 15);
801 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');