164 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
167 global $user, $langs, $conf, $mysoc, $hookmanager;
169 if (!is_object($outputlangs)) {
170 $outputlangs = $langs;
173 if (!empty($conf->global->MAIN_USE_FPDF)) {
174 $outputlangs->charset_output =
'ISO-8859-1';
178 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
180 $object->factures = array();
182 if ($conf->fournisseur->payment->dir_output) {
183 $object->fetch_thirdparty();
187 $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';
188 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
189 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
190 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
191 $sql .=
' AND pf.fk_paiementfourn = '.((int) $object->id);
192 $resql = $this->db->query($sql);
194 if ($this->db->num_rows($resql) > 0) {
195 while ($objp = $this->db->fetch_object($resql)) {
196 $objp->type = $outputlangs->trans(
'SupplierInvoice');
197 $object->lines[] = $objp;
202 $total = $object->amount;
205 if ($object->specimen) {
206 $dir = $conf->fournisseur->payment->dir_output;
207 $file = $dir.
"/SPECIMEN.pdf";
211 $dir = $conf->fournisseur->payment->dir_output.
'/'.$objectref;
212 $file = $dir.
"/".$objectref.
".pdf";
218 if (!file_exists($dir)) {
220 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
225 if (file_exists($dir)) {
227 if (!is_object($hookmanager)) {
228 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
231 $hookmanager->initHooks(array(
'pdfgeneration'));
232 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
234 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
236 $nblines = (empty($object->lines) ? 0 : count($object->lines));
240 $heightforinfotot = 50;
241 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
242 $heightforfooter = $this->marge_basse + 8;
243 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
244 $heightforfooter += 6;
246 $pdf->SetAutoPageBreak(1, 0);
248 if (class_exists(
'TCPDF')) {
249 $pdf->setPrintHeader(
false);
250 $pdf->setPrintFooter(
false);
254 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
255 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
256 $tplidx = $pdf->importPage(1);
261 $pdf->SetDrawColor(128, 128, 128);
263 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
264 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
265 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
266 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
267 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
269 $pdf->SetCompression(
false);
272 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
277 if (!empty($tplidx)) {
278 $pdf->useTemplate($tplidx);
281 $this->
_pagehead($pdf, $object, 1, $outputlangs);
282 $pdf->SetFont(
'',
'', $default_font_size - 1);
283 $pdf->MultiCell(0, 3,
'');
284 $pdf->SetTextColor(0, 0, 0);
287 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
289 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 $height_incoterms = 0;
296 $iniY = $tab_top + 7;
297 $curY = $tab_top + 7;
298 $nexY = $tab_top + 7;
301 for ($i = 0; $i < $nblines; $i++) {
303 $pdf->SetFont(
'',
'', $default_font_size - 1);
304 $pdf->SetTextColor(0, 0, 0);
306 $pdf->setTopMargin($tab_top_newpage);
307 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
308 $pageposbefore = $pdf->getPage();
311 $curX = $this->posxdate - 1;
312 $showpricebeforepagebreak = 1;
314 $pdf->startTransaction();
316 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
317 $pageposafter = $pdf->getPage();
318 if ($pageposafter > $pageposbefore) {
319 $pdf->rollbackTransaction(
true);
320 $pageposafter = $pageposbefore;
322 $pdf->setPageOrientation(
'', 1, $heightforfooter);
324 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
325 $posyafter = $pdf->GetY();
326 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
327 if ($i == ($nblines - 1)) {
328 $pdf->AddPage(
'',
'',
true);
329 if (!empty($tplidx)) {
330 $pdf->useTemplate($tplidx);
333 $this->
_pagehead($pdf, $object, 0, $outputlangs);
335 $pdf->setPage($pageposafter + 1);
340 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
341 $showpricebeforepagebreak = 1;
343 $showpricebeforepagebreak = 0;
348 $pdf->commitTransaction();
351 $nexY = $pdf->GetY();
352 $pageposafter = $pdf->getPage();
353 $pdf->setPage($pageposbefore);
354 $pdf->setTopMargin($this->marge_haute);
355 $pdf->setPageOrientation(
'', 1, 0);
358 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
359 $pdf->setPage($pageposafter);
360 $curY = $tab_top_newpage;
363 $pdf->SetFont(
'',
'', $default_font_size - 1);
366 $pdf->SetXY($this->posxreffacturefourn, $curY);
367 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0,
'L', 0);
370 $pdf->SetXY($this->posxreffacture, $curY);
371 $pdf->MultiCell($this->posxreffacture - 0.8, 3, $object->lines[$i]->ref, 0,
'L', 0);
374 $pdf->SetXY($this->posxtype, $curY);
375 $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0,
'L', 0);
378 $pdf->SetXY($this->posxtotalht, $curY);
379 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price($object->lines[$i]->total_ht), 0,
'R', 0);
382 $pdf->SetXY($this->posxtva, $curY);
383 $pdf->MultiCell($this->posxtva - 0.8, 3,
price($object->lines[$i]->total_tva), 0,
'R', 0);
386 $pdf->SetXY($this->posxtotalttc, $curY);
387 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price($object->lines[$i]->total_ttc), 0,
'R', 0);
391 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
392 $pdf->setPage($pageposafter);
393 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
395 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
396 $pdf->SetLineStyle(array(
'dash'=>0));
402 while ($pagenb < $pageposafter) {
403 $pdf->setPage($pagenb);
405 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
407 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
409 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
411 $pdf->setPage($pagenb);
412 $pdf->setPageOrientation(
'', 1, 0);
414 $this->
_pagehead($pdf, $object, 0, $outputlangs);
416 if (!empty($tplidx)) {
417 $pdf->useTemplate($tplidx);
420 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
422 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
424 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
426 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
429 if (!empty($tplidx)) {
430 $pdf->useTemplate($tplidx);
434 $this->
_pagehead($pdf, $object, 0, $outputlangs);
441 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
442 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
444 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
445 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
449 $posy = $this->
_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
455 $this->
_pagefoot($pdf, $object, $outputlangs);
456 if (method_exists($pdf,
'AliasNbPages')) {
457 $pdf->AliasNbPages();
462 $pdf->Output($file,
'F');
465 $hookmanager->initHooks(array(
'pdfgeneration'));
466 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
468 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
470 $this->error = $hookmanager->error;
471 $this->errors = $hookmanager->errors;
476 $this->result = array(
'fullpath'=>$file);
480 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
484 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
503 global $conf, $mysoc;
507 $pdf->SetFont(
'',
'', $default_font_size - 1);
508 $pdf->SetFillColor(255, 255, 255);
511 $pdf->SetXY($this->marge_gauche, $posy);
512 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
515 $pdf->SetXY($this->marge_gauche + 30, $posy);
516 $pdf->MultiCell(50, 4, $object->ref, 0,
'L', 1);
519 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
520 $pdf->MultiCell(50, 4,
price($object->amount), 0,
'R', 1);
524 $currency = $conf->currency;
526 $pdf->SetXY($this->marge_gauche + 50, $posy);
527 $pdf->SetFont(
'',
'', $default_font_size - 3);
528 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
529 $pdf->SetFont(
'',
'', $default_font_size - 1);
533 $pdf->SetXY($this->marge_gauche + 50, $posy);
534 $pdf->MultiCell(150, 4, $object->thirdparty->nom, 0,
'L', 1);
537 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
538 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price($object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
542 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
543 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
547 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
548 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
609 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
611 global $langs, $conf, $mysoc;
614 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
621 $pdf->SetTextColor(0, 0, 60);
622 $pdf->SetFont(
'',
'B', $default_font_size + 3);
624 $posy = $this->marge_haute;
625 $posx = $this->page_largeur - $this->marge_droite - 100;
627 $pdf->SetXY($this->marge_gauche, $posy);
630 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
632 if (is_readable($logo)) {
634 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
636 $pdf->SetTextColor(200, 0, 0);
637 $pdf->SetFont(
'',
'B', $default_font_size - 2);
638 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
639 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
642 $text = $this->emetteur->name;
643 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
719 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
723 $posx = $this->marge_gauche;
724 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
725 $posx = $this->page_largeur - $this->marge_droite - 80;
730 $pdf->SetTextColor(0, 0, 0);
731 $pdf->SetFont(
'',
'', $default_font_size - 2);
732 $pdf->SetXY($posx, $posy - 5);
733 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
734 $pdf->SetXY($posx, $posy);
735 $pdf->SetFillColor(230, 230, 230);
736 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
737 $pdf->SetTextColor(0, 0, 60);
740 $pdf->SetXY($posx + 2, $posy + 3);
741 $pdf->SetFont(
'',
'B', $default_font_size);
742 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
743 $posy = $pdf->getY();
746 $pdf->SetXY($posx + 2, $posy);
747 $pdf->SetFont(
'',
'', $default_font_size - 1);
748 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
751 $thirdparty = $object->thirdparty;
757 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
761 if ($this->page_largeur < 210) {
765 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
766 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
767 $posx = $this->marge_gauche;
771 $pdf->SetTextColor(0, 0, 0);
772 $pdf->SetFont(
'',
'', $default_font_size - 2);
773 $pdf->SetXY($posx + 2, $posy - 5);
774 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
775 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
778 $pdf->SetXY($posx + 2, $posy + 3);
779 $pdf->SetFont(
'',
'B', $default_font_size);
780 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
782 $posy = $pdf->getY();
785 $pdf->SetFont(
'',
'', $default_font_size - 1);
786 $pdf->SetXY($posx + 2, $posy);
787 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
791 $sql =
"SELECT iban_prefix as iban";
792 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
793 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
794 $sql .=
" AND rib.default_rib = 1";
795 $sql .=
" AND rib.type = 'ban'";
797 $resql = $this->db->query($sql);
799 $obj = $this->db->fetch_object($resql);
806 $pdf->SetFont(
'',
'', $default_font_size - 1);
807 $pdf->SetXY($posx + 2, $posy + 15);
808 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');