158 public function write_file(
$object, $outputlangs =
null, $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"));
176 if ($conf->fournisseur->payment->dir_output) {
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');
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);
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);
267 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
272 if (!empty($tplidx)) {
273 $pdf->useTemplate($tplidx);
277 $pdf->SetFont(
'',
'', $default_font_size - 1);
278 $pdf->MultiCell(0, 3,
'');
279 $pdf->SetTextColor(0, 0, 0);
282 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
284 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
287 $height_incoterms = 0;
291 $iniY = $tab_top + 7;
292 $curY = $tab_top + 7;
293 $nexY = $tab_top + 7;
296 for ($i = 0; $i < $nblines; $i++) {
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->SetTextColor(0, 0, 0);
301 $pdf->setTopMargin($tab_top_newpage);
302 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
303 $pageposbefore = $pdf->getPage();
306 $curX = $this->posxdate - 1;
307 $showpricebeforepagebreak = 1;
309 $pdf->startTransaction();
311 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
312 $pageposafter = $pdf->getPage();
313 if ($pageposafter > $pageposbefore) {
314 $pdf->rollbackTransaction(
true);
315 $pageposafter = $pageposbefore;
317 $pdf->setPageOrientation(
'', 1, $heightforfooter);
319 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
320 $posyafter = $pdf->GetY();
321 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
322 if ($i == ($nblines - 1)) {
323 $pdf->AddPage(
'',
'',
true);
324 if (!empty($tplidx)) {
325 $pdf->useTemplate($tplidx);
330 $pdf->setPage($pageposafter + 1);
336 $showpricebeforepagebreak = 1;
338 $showpricebeforepagebreak = 0;
342 $pdf->commitTransaction();
345 $nexY = $pdf->GetY();
346 $pageposafter = $pdf->getPage();
347 $pdf->setPage($pageposbefore);
348 $pdf->setTopMargin($this->marge_haute);
349 $pdf->setPageOrientation(
'', 1, 0);
352 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
353 $pdf->setPage($pageposafter);
354 $curY = $tab_top_newpage;
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->SetXY($this->posxreffacturefourn, $curY);
361 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L', 0);
364 $pdf->SetXY($this->posxreffacture, $curY);
365 $pdf->MultiCell($this->posxreffacture - 0.8, 3,
$object->lines[$i]->ref, 0,
'L', 0);
368 $pdf->SetXY($this->posxtype, $curY);
369 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L', 0);
372 $pdf->SetXY($this->posxtotalht, $curY);
373 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R', 0);
376 $pdf->SetXY($this->posxtva, $curY);
377 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R', 0);
380 $pdf->SetXY($this->posxtotalttc, $curY);
381 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R', 0);
386 $pdf->setPage($pageposafter);
387 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
389 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
390 $pdf->SetLineStyle(array(
'dash' => 0));
396 while ($pagenb < $pageposafter) {
397 $pdf->setPage($pagenb);
399 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
401 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
405 $pdf->setPage($pagenb);
406 $pdf->setPageOrientation(
'', 1, 0);
410 if (!empty($tplidx)) {
411 $pdf->useTemplate($tplidx);
414 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
416 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
418 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
423 if (!empty($tplidx)) {
424 $pdf->useTemplate($tplidx);
435 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
436 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
438 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
439 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
450 if (method_exists($pdf,
'AliasNbPages')) {
451 $pdf->AliasNbPages();
456 $pdf->Output($file,
'F');
459 $hookmanager->initHooks(array(
'pdfgeneration'));
460 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
462 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
464 $this->error = $hookmanager->error;
465 $this->errors = $hookmanager->errors;
470 $this->result = array(
'fullpath' => $file);
474 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
478 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
497 global $conf, $mysoc;
501 $pdf->SetFont(
'',
'', $default_font_size - 1);
502 $pdf->SetFillColor(255, 255, 255);
505 $pdf->SetXY($this->marge_gauche, $posy);
506 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
509 $pdf->SetXY($this->marge_gauche + 30, $posy);
510 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L', 1);
513 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
514 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R', 1);
518 $currency = $conf->currency;
520 $pdf->SetXY($this->marge_gauche + 50, $posy);
521 $pdf->SetFont(
'',
'', $default_font_size - 3);
522 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
523 $pdf->SetFont(
'',
'', $default_font_size - 1);
527 $pdf->SetXY($this->marge_gauche + 50, $posy);
528 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L', 1);
531 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
532 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
536 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
537 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
541 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
542 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
605 global $langs, $conf, $mysoc;
608 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
615 $pdf->SetTextColor(0, 0, 60);
616 $pdf->SetFont(
'',
'B', $default_font_size + 3);
618 $posy = $this->marge_haute;
619 $posx = $this->page_largeur - $this->marge_droite - 100;
621 $pdf->SetXY($this->marge_gauche, $posy);
624 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
626 if (is_readable($logo)) {
628 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
630 $pdf->SetTextColor(200, 0, 0);
631 $pdf->SetFont(
'',
'B', $default_font_size - 2);
632 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
633 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
636 $text = $this->emetteur->name;
637 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
717 $posx = $this->marge_gauche;
719 $posx = $this->page_largeur - $this->marge_droite - 80;
724 $pdf->SetTextColor(0, 0, 0);
725 $pdf->SetFont(
'',
'', $default_font_size - 2);
726 $pdf->SetXY($posx, $posy - 5);
727 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
728 $pdf->SetXY($posx, $posy);
729 $pdf->SetFillColor(230, 230, 230);
730 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
731 $pdf->SetTextColor(0, 0, 60);
734 $pdf->SetXY($posx + 2, $posy + 3);
735 $pdf->SetFont(
'',
'B', $default_font_size);
736 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
737 $posy = $pdf->getY();
740 $pdf->SetXY($posx + 2, $posy);
741 $pdf->SetFont(
'',
'', $default_font_size - 1);
742 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
745 $thirdparty =
$object->thirdparty;
755 if ($this->page_largeur < 210) {
759 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
761 $posx = $this->marge_gauche;
765 $pdf->SetTextColor(0, 0, 0);
766 $pdf->SetFont(
'',
'', $default_font_size - 2);
767 $pdf->SetXY($posx + 2, $posy - 5);
768 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
769 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
772 $pdf->SetXY($posx + 2, $posy + 3);
773 $pdf->SetFont(
'',
'B', $default_font_size);
774 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
776 $posy = $pdf->getY();
779 $pdf->SetFont(
'',
'', $default_font_size - 1);
780 $pdf->SetXY($posx + 2, $posy);
781 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
785 $sql =
"SELECT iban_prefix as iban";
786 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
787 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
788 $sql .=
" AND rib.default_rib = 1";
789 $sql .=
" AND rib.type = 'ban'";
791 $resql = $this->db->query($sql);
793 $obj = $this->db->fetch_object($resql);
800 $pdf->SetFont(
'',
'', $default_font_size - 1);
801 $pdf->SetXY($posx + 2, $posy + 15);
802 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');