160 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
163 global $user, $langs, $conf, $mysoc, $hookmanager;
165 if (!is_object($outputlangs)) {
166 $outputlangs = $langs;
170 $outputlangs->charset_output =
'ISO-8859-1';
174 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
178 if ($conf->fournisseur->payment->dir_output) {
183 $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';
184 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
185 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
186 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
187 $sql .=
' AND pf.fk_paiementfourn = '.((int)
$object->id);
188 $resql = $this->db->query($sql);
190 if ($this->db->num_rows($resql) > 0) {
191 while ($objp = $this->db->fetch_object($resql)) {
192 $objp->type = $outputlangs->trans(
'SupplierInvoice');
202 $dir = $conf->fournisseur->payment->dir_output;
203 $file = $dir.
"/SPECIMEN.pdf";
207 $dir = $conf->fournisseur->payment->dir_output.
'/'.$objectref;
208 $file = $dir.
"/".$objectref.
".pdf";
214 if (!file_exists($dir)) {
216 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
221 if (file_exists($dir)) {
223 if (!is_object($hookmanager)) {
224 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
227 $hookmanager->initHooks(array(
'pdfgeneration'));
228 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
230 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
236 $heightforinfotot = 50;
238 $heightforfooter = $this->marge_basse + 8;
240 $heightforfooter += 6;
242 $pdf->SetAutoPageBreak(1, 0);
244 if (class_exists(
'TCPDF')) {
245 $pdf->setPrintHeader(
false);
246 $pdf->setPrintFooter(
false);
251 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
252 $tplidx = $pdf->importPage(1);
257 $pdf->SetDrawColor(128, 128, 128);
259 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
260 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
261 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
262 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
263 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
265 $pdf->SetCompression(
false);
269 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
274 if (!empty($tplidx)) {
275 $pdf->useTemplate($tplidx);
279 $pdf->SetFont(
'',
'', $default_font_size - 1);
280 $pdf->MultiCell(0, 3,
'');
281 $pdf->SetTextColor(0, 0, 0);
284 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
286 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
289 $height_incoterms = 0;
293 $iniY = $tab_top + 7;
294 $curY = $tab_top + 7;
295 $nexY = $tab_top + 7;
298 for ($i = 0; $i < $nblines; $i++) {
300 $pdf->SetFont(
'',
'', $default_font_size - 1);
301 $pdf->SetTextColor(0, 0, 0);
303 $pdf->setTopMargin($tab_top_newpage);
304 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
305 $pageposbefore = $pdf->getPage();
308 $curX = $this->posxdate - 1;
309 $showpricebeforepagebreak = 1;
311 $pdf->startTransaction();
313 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
314 $pageposafter = $pdf->getPage();
315 if ($pageposafter > $pageposbefore) {
316 $pdf->rollbackTransaction(
true);
317 $pageposafter = $pageposbefore;
319 $pdf->setPageOrientation(
'', 1, $heightforfooter);
321 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
322 $posyafter = $pdf->GetY();
323 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
324 if ($i == ($nblines - 1)) {
325 $pdf->AddPage(
'',
'',
true);
326 if (!empty($tplidx)) {
327 $pdf->useTemplate($tplidx);
332 $pdf->setPage($pageposafter + 1);
338 $showpricebeforepagebreak = 1;
340 $showpricebeforepagebreak = 0;
344 $pdf->commitTransaction();
347 $nexY = $pdf->GetY();
348 $pageposafter = $pdf->getPage();
349 $pdf->setPage($pageposbefore);
350 $pdf->setTopMargin($this->marge_haute);
351 $pdf->setPageOrientation(
'', 1, 0);
354 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
355 $pdf->setPage($pageposafter);
356 $curY = $tab_top_newpage;
359 $pdf->SetFont(
'',
'', $default_font_size - 1);
362 $pdf->SetXY($this->posxreffacturefourn, $curY);
363 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L', 0);
366 $pdf->SetXY($this->posxreffacture, $curY);
367 $pdf->MultiCell($this->posxreffacture - 0.8, 3,
$object->lines[$i]->ref, 0,
'L', 0);
370 $pdf->SetXY($this->posxtype, $curY);
371 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L', 0);
374 $pdf->SetXY($this->posxtotalht, $curY);
375 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R', 0);
378 $pdf->SetXY($this->posxtva, $curY);
379 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R', 0);
382 $pdf->SetXY($this->posxtotalttc, $curY);
383 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R', 0);
388 $pdf->setPage($pageposafter);
389 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
391 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
392 $pdf->SetLineStyle(array(
'dash' => 0));
398 while ($pagenb < $pageposafter) {
399 $pdf->setPage($pagenb);
401 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
403 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
407 $pdf->setPage($pagenb);
408 $pdf->setPageOrientation(
'', 1, 0);
412 if (!empty($tplidx)) {
413 $pdf->useTemplate($tplidx);
416 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
418 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
420 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
425 if (!empty($tplidx)) {
426 $pdf->useTemplate($tplidx);
437 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
438 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
440 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
441 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
452 if (method_exists($pdf,
'AliasNbPages')) {
453 $pdf->AliasNbPages();
458 $pdf->Output($file,
'F');
461 $hookmanager->initHooks(array(
'pdfgeneration'));
462 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
464 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
466 $this->error = $hookmanager->error;
467 $this->errors = $hookmanager->errors;
472 $this->result = array(
'fullpath' => $file);
476 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
480 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
499 global $conf, $mysoc;
503 $pdf->SetFont(
'',
'', $default_font_size - 1);
504 $pdf->SetFillColor(255, 255, 255);
507 $pdf->SetXY($this->marge_gauche, $posy);
508 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
511 $pdf->SetXY($this->marge_gauche + 30, $posy);
512 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L', 1);
515 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
516 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R', 1);
520 $currency = $conf->currency;
522 $pdf->SetXY($this->marge_gauche + 50, $posy);
523 $pdf->SetFont(
'',
'', $default_font_size - 3);
524 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
525 $pdf->SetFont(
'',
'', $default_font_size - 1);
529 $pdf->SetXY($this->marge_gauche + 50, $posy);
530 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L', 1);
533 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
534 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
538 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
539 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
543 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
544 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
607 global $langs, $conf, $mysoc;
610 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
617 $pdf->SetTextColor(0, 0, 60);
618 $pdf->SetFont(
'',
'B', $default_font_size + 3);
620 $posy = $this->marge_haute;
621 $posx = $this->page_largeur - $this->marge_droite - 100;
623 $pdf->SetXY($this->marge_gauche, $posy);
626 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
628 if (is_readable($logo)) {
630 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
632 $pdf->SetTextColor(200, 0, 0);
633 $pdf->SetFont(
'',
'B', $default_font_size - 2);
634 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
635 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
638 $text = $this->emetteur->name;
639 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
719 $posx = $this->marge_gauche;
721 $posx = $this->page_largeur - $this->marge_droite - 80;
726 $pdf->SetTextColor(0, 0, 0);
727 $pdf->SetFont(
'',
'', $default_font_size - 2);
728 $pdf->SetXY($posx, $posy - 5);
729 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
730 $pdf->SetXY($posx, $posy);
731 $pdf->SetFillColor(230, 230, 230);
732 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
733 $pdf->SetTextColor(0, 0, 60);
736 $pdf->SetXY($posx + 2, $posy + 3);
737 $pdf->SetFont(
'',
'B', $default_font_size);
738 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
739 $posy = $pdf->getY();
742 $pdf->SetXY($posx + 2, $posy);
743 $pdf->SetFont(
'',
'', $default_font_size - 1);
744 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
747 $thirdparty =
$object->thirdparty;
757 if ($this->page_largeur < 210) {
761 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
763 $posx = $this->marge_gauche;
767 $pdf->SetTextColor(0, 0, 0);
768 $pdf->SetFont(
'',
'', $default_font_size - 2);
769 $pdf->SetXY($posx + 2, $posy - 5);
770 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
771 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
774 $pdf->SetXY($posx + 2, $posy + 3);
775 $pdf->SetFont(
'',
'B', $default_font_size);
776 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
778 $posy = $pdf->getY();
781 $pdf->SetFont(
'',
'', $default_font_size - 1);
782 $pdf->SetXY($posx + 2, $posy);
783 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
787 $sql =
"SELECT iban_prefix as iban";
788 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
789 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
790 $sql .=
" AND rib.default_rib = 1";
791 $sql .=
" AND rib.type = 'ban'";
793 $resql = $this->db->query($sql);
795 $obj = $this->db->fetch_object($resql);
802 $pdf->SetFont(
'',
'', $default_font_size - 1);
803 $pdf->SetXY($posx + 2, $posy + 15);
804 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');