* 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ */ /** * \file htdocs/includes/modules/project/pdf/pdf_baleine.modules.php * \ingroup project * \brief Fichier de la classe permettant de generer les projets au modele Baleine * \author Regis Houssin * \version $Id$ */ require_once(DOL_DOCUMENT_ROOT."/includes/modules/project/modules_project.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); /** * \class pdf_baleine * \brief Classe permettant de generer les projets au modele Baleine */ class pdf_baleine extends ModelePDFProjects { var $emetteur; // Objet societe qui emet /** * \brief Constructor * \param db Database handler */ function pdf_baleine($db) { global $conf,$langs,$mysoc; $langs->load("main"); $langs->load("projects"); $langs->load("companies"); $this->db = $db; $this->name = "baleine"; $this->description = $langs->trans("DocumentModelBaleine"); // Dimension page pour format A4 $this->type = 'pdf'; $this->page_largeur = 210; $this->page_hauteur = 297; $this->format = array($this->page_largeur,$this->page_hauteur); $this->marge_gauche=10; $this->marge_droite=10; $this->marge_haute=10; $this->marge_basse=10; $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION $this->option_codeproduitservice = 1; // Affiche code produit-service // Recupere emmetteur $this->emetteur=$mysoc; if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini // Defini position des colonnes $this->posxdesc=$this->marge_gauche+1; $this->posxcomm=120; } /** * \brief Fonction generant le projet sur le disque * \param delivery Object project a generer * \param outputlangs Lang output object * \return int 1 if OK, <=0 if KO */ function write_file($object,$outputlangs) { global $user,$langs,$conf; if (! is_object($outputlangs)) $outputlangs=$langs; // Force output charset to ISO, because, FPDF expect text encoded in ISO $sav_charset_output=$outputlangs->charset_output; $outputlangs->charset_output='ISO-8859-1'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->projet->dir_output) { // If $object is id instead of object if (! is_object($object)) { $id = $object; $object = new Project($this->db); $object->fetch($id); if ($result < 0) { dol_print_error($db,$object->error); } } $nblignes = sizeof($object->lines); $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->projet->dir_output; if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; if (! file_exists($dir)) { if (create_exdir($dir) < 0) { $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } if (file_exists($dir)) { // Protection et encryption du pdf if ($conf->global->PDF_SECURITY_ENCRYPTION) { $pdf=new FPDI_Protection('P','mm',$this->format); $pdfrights = array('print'); // Ne permet que l'impression du document $pdfuserpass = ''; // Mot de passe pour l'utilisateur final $pdfownerpass = NULL; // Mot de passe du proprietaire, cree aleatoirement si pas defini $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); } else { $pdf=new FPDI('P','mm',$this->format); } // Complete object by loading several other informations $task = new Task($this->db); $tasksarray = $task->getTasksArray(0,0,$object->id); $object->lines=$tasksarray; $nblignes=sizeof($object->lines); $pdf->Open(); $pagenb=0; $pdf->SetDrawColor(128,128,128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Project")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname)); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project")); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1,0); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('Arial','', 9); $pdf->MultiCell(0, 3, '', 0, 'J'); // Set interline to 3 $pdf->SetTextColor(0,0,0); $tab_top = 50; $tab_height = 210; // Affiche notes if (! empty($object->note_public)) { $tab_top = 48; $pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page $pdf->SetXY ($this->posxdesc-1, $tab_top); $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'J'); $nexY = $pdf->GetY(); $height_note=$nexY-$tab_top; // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192,192,192); $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); $tab_height = $tab_height - $height_note; $tab_top = $nexY+6; } else { $height_note=0; } $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; // Boucle sur les lignes for ($i = 0 ; $i < $nblignes ; $i++) { $curY = $nexY; // Description of ligne $ref=$object->lines[$i]->ref; $libelleline=$object->lines[$i]->label; $pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page $pdf->writeHTMLCell(108, 3, $this->posxdesc-1, $curY, $outputlangs->convToOutputCharset($ref), 0, 1); $pdf->writeHTMLCell(108, 3, $this->posxdesc+10, $curY, $outputlangs->convToOutputCharset($libelleline), 0, 1); $pdf->SetFont('Arial','', 9); // On repositionne la police par defaut $nexY = $pdf->GetY(); $nexY+=2; // Passe espace entre les lignes // Cherche nombre de lignes a venir pour savoir si place suffisante if ($i < ($nblignes - 1)) // If it's not last line { //on recupere la description du produit suivant $follow_descproduitservice = $object->lines[$i+1]->label; //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4); } else // If it's last line { $nblineFollowDesc = 0; } if (($nexY+$nblineFollowDesc) > ($tab_top+$tab_height) && $i < ($nblignes - 1)) { $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs); $this->_pagefoot($pdf, $object, $outputlangs); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->SetFont('Arial','', 9); $pdf->MultiCell(0, 3, '', 0, 'J'); // Set interline to 3 $pdf->SetTextColor(0,0,0); $nexY = $tab_top_newpage + 7; } } // Show square $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); $bottomlasttab=$tab_top + $tab_height + 1; /* * Pied de page */ $this->_pagefoot($pdf,$object,$outputlangs); $pdf->AliasNbPages(); $pdf->Close(); $pdf->Output($file); if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); return 1; // Pas d'erreur } else { $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR"); return 0; } /* * \brief Affiche la grille des lignes * \param pdf objet PDF */ function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs) { global $conf,$mysoc; // Montants exprimes en (en tab_top - 1) $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); //$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie)); //$pdf->Text($this->page_largeur - $this->marge_droite - $pdf->GetStringWidth($titre), $tab_top-1, $titre); $pdf->SetDrawColor(128,128,128); // Rect prend une longueur en 3eme param $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height); // line prend une position y en 3eme param $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6); $pdf->SetFont('Arial','',10); $pdf->SetXY ($this->posxdesc-1, $tab_top+2); $pdf->MultiCell(80,2, $outputlangs->transnoentities("Tasks"),'','L'); } /** * \brief Affiche en-tete bon livraison * \param pdf objet PDF * \param delivery object delivery * \param showadress 0=non, 1=oui */ function _pagehead(&$pdf, $object, $showadress=1, $outputlangs) { global $langs,$conf,$mysoc; pdf_pagehead($pdf,$outputlangs,$pdf->page_hauteur); $pdf->SetTextColor(0,0,60); $pdf->SetFont('Arial','B',13); $posy=$this->marge_haute; $pdf->SetXY($this->marge_gauche,$posy); // Logo $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; if ($mysoc->logo) { if (is_readable($logo)) { $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24); } else { $pdf->SetTextColor(200,0,0); $pdf->SetFont('Arial','B',8); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } } else $pdf->MultiCell(100, 4, $this->emetteur->nom, 0, 'L'); $pdf->SetFont('Arial','B',13); $pdf->SetXY(100,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '' , 'R'); $pdf->SetFont('Arial','',12); $posy+=6; $pdf->SetXY(100,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : " . dol_print_date($object->date_start,'day',false,$outputlangs,true), '', 'R'); $posy+=6; $pdf->SetXY(100,$posy); $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R'); $pdf->SetTextColor(0,0,60); // Add list of linked orders // TODO mutualiser $object->load_object_linked(); if ($conf->commande->enabled) { $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { if ($key == 'commande') { for ($i = 0; $idb); $result=$newobject->fetch($val[$i]); if ($result >= 0) { $posy+=4; $pdf->SetXY(100,$posy); $pdf->SetFont('Arial','',9); $text=$newobject->ref; if ($newobject->ref_client) $text.=' ('.$newobject->ref_client.')'; $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); } } } } } if ($showadress) { // Emetteur /* $posy=42; $hautcadre=40; $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); $pdf->SetXY($this->marge_gauche,$posy-5); $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":"); $pdf->SetXY($this->marge_gauche,$posy); $pdf->SetFillColor(230,230,230); $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1); $pdf->SetXY($this->marge_gauche+2,$posy+3); // Nom emetteur $pdf->SetTextColor(0,0,60); $pdf->SetFont('Arial','B',11); $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L'); // Sender properties $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur); $pdf->SetFont('Arial','',9); $pdf->SetXY($this->marge_gauche+2,$posy+9); $pdf->MultiCell(80, 3, $carac_emetteur); // Client destinataire $posy=42; $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); $pdf->SetXY(102,$posy-5); $pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":"); // Cadre client destinataire $pdf->rect(100, $posy, 100, $hautcadre); $object->fetch_client(); // Recipient name if (! empty($usecontact)) { // On peut utiliser le nom de la societe du contact if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname; else $socname = $object->client->nom; $carac_client_name=$outputlangs->convToOutputCharset($socname); } else { $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom); } $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target'); // Show customer/recipient $pdf->SetXY(102,$posy+3); $pdf->SetFont('Arial','B',11); $pdf->MultiCell(106,4, $carac_client_name, 0, 'L'); $pdf->SetFont('Arial','',9); $pdf->SetXY(102,$posy+8); $pdf->MultiCell(86,4, $carac_client); */ } } /** * \brief Show footer of page * \param pdf PDF factory * \param object Object invoice * \param outputlangs Object lang for output * \remarks Need this->emetteur object */ function _pagefoot(&$pdf,$object,$outputlangs) { return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object); } } ?>