* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2011 Fabrice CHERRIER * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2015 Marcos García * Copyright (C) 2018 Gaëtan MAISON * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see http://www.gnu.org/ */ /** * \file htdocs/core/modules/fichinter/doc/pdf_eti01.modules.php * \ingroup ficheinter * \brief Fichier de la classe permettant de generer les fiches d'intervention au modele eti01 * \brief Basé sur les fiches d'intervention au modele soleil */ require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; /** * Class to build interventions documents with model eti01 */ class pdf_eti01 extends ModelePDFFicheinter { var $db; var $name; var $description; var $type; var $phpmin = array(4,3,0); // Minimum version of PHP required by module var $version = 'dolibarr'; var $page_largeur; var $page_hauteur; var $format; var $marge_gauche; var $marge_droite; var $marge_haute; var $marge_basse; /** * Constructor * * @param DoliDB $db Database handler */ function __construct($db) { global $conf,$langs,$mysoc; $this->db = $db; $this->name = 'eti01'; $this->description = 'Étiquette Dymo 11354 57 × 32 mm'; // Dimension page pour format Dymo 11354 57 × 32 mm $this->type = 'pdf'; $formatarray=pdf_getFormat(); // Format souhaité $this->page_largeur = $formatarray['width']/"6.5"; $this->page_hauteur = $formatarray['height']/"5.25"; $this->format = array($this->page_largeur,$this->page_hauteur); $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:1; $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:1; $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:1; $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:1; $this->option_logo = 0; // Affiche logo $this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION $this->option_modereg = 0; // Affiche mode reglement $this->option_condreg = 0; // Affiche conditions reglement $this->option_codeproduitservice = 0; // Affiche code produit-service $this->option_multilang = 1; // Dispo en plusieurs langues $this->option_draft_watermark = 0; //Support add of a watermark on drafts // Get source company $this->emetteur=$mysoc; if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if not defined // Define position of columns $this->posxdesc=$this->marge_gauche+1; } /** * Function to build pdf onto disk * * @param Object $object Object to generate * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file * @param int $hidedetails Do not show line details * @param int $hidedesc Do not show desc * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { global $user,$langs,$conf,$mysoc,$db,$hookmanager; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("interventions"); if ($conf->ficheinter->dir_output) { $object->fetch_thirdparty(); // Definition of $dir and $file if ($object->specimen) { $dir = $conf->ficheinter->dir_output; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->ficheinter->dir_output . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } if (! file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } if (file_exists($dir)) { // Add pdfgeneration hook if (! is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager=new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $nblignes = count($object->lines); // Create pdf instance $pdf=pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // Height reserved to output the info and total part $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Set path to the background PDF File if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } $pdf->Open(); $pagenb=0; $pdf->SetDrawColor(128,128,128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("InterventionCard")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard")); if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // New page $pdf->AddPage('L'); if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->SetTextColor(0,0,0); $tab_top = 90; $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); $tab_height = 130; $tab_height_newpage = 150; $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; $pdf->SetFont('', '', $default_font_size - 1); $pdf->Close(); $pdf->Output($file,'F'); // Add pdfgeneration hook $hookmanager->initHooks(array('pdfgeneration')); $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); $this->result = array('fullpath'=>$file); return 1; } else { $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); return 0; } } else { $this->error=$langs->trans("ErrorConstantNotDefined","FICHEINTER_OUTPUTDIR"); return 0; } } /** * Show top header of page. * * @param PDF $pdf Object PDF * @param Object $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output * @return void */ function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { global $conf,$langs; $default_font_size = pdf_getPDFFontSize($outputlangs); $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("interventions"); pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); //Prepare la suite $pdf->SetTextColor(0,0,60); $pdf->SetFont('','B', $default_font_size + 3); $pdf->GetX(0); $pdf->GetY(0); $pdf->SetFont('','B',$default_font_size + 2); $posy+=0; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 4, $outputlangs->convToOutputCharset($object->ref), '', 'L'); $posy+=1; $pdf->SetFont('','', $default_font_size); $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 3, $outputlangs->transnoentities("Le")." : " . dol_print_date($object->datec,"day",false,$outputlangs,true) ." à " . dol_print_date($object->datec,"hour",false,$outputlangs,true), '', 'L'); if ($object->thirdparty->code_client) { $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 3, $outputlangs->transnoentities($object->thirdparty->code_client), '', 'L'); } $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 3, $outputlangs->transnoentities("Client")." : " . ($object->thirdparty->nom), '', 'L'); if ($object->thirdparty->phone) { $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 3, $outputlangs->transnoentities("Tel")." : " . ($object->thirdparty->phone), '', 'L'); } if ($object->thirdparty->fax) { $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(55, 3, $outputlangs->transnoentities("Fax")." : " . ($object->thirdparty->fax), '', 'L'); } /* Par Info Libre @ Dom : */ $posy+=4; $pdf->SetXY($posx+2,$posy); $pdf->SetFont('','', $default_font_size -5); $pdf->SetTextColor(160,171,169); $pdf->MultiCell(55, 3, $outputlangs->transnoentities("Model")." : " . ($object->modelpdf) . " Par Info Libre @ Dom http://www.doliilad.net", '', 'R'); } /** * Show footer of page. Need this->emetteur object * * @param PDF $pdf PDF * @param Object $object Object to show * @param Translate $outputlangs Object lang for output * @param int $hidefreetext 1=Hide free text * @return integer */ function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) { global $conf; $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; return pdf_pagefoot($pdf,$outputlangs,'FICHINTER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } }