dolibarr/htdocs/includes/modules/fichinter/pdf_soleil.modules.php

341 lines
11 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
2003-06-11 15:35:25 +02:00
*
* 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/
*
* $Id$
* $Source$
*
*/
/**
\file htdocs/includes/modules/fichinter/pdf_soleil.modules.php
\ingroup ficheinter
\brief Fichier de la classe permettant de g<EFBFBD>n<EFBFBD>rer les fiches d'intervention au mod<EFBFBD>le Soleil
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT."/includes/modules/fichinter/modules_fichinter.php");
/**
\class pdf_soleil
\brief Classe permettant de g<EFBFBD>n<EFBFBD>rer les fiches d'intervention au mod<EFBFBD>le Soleil
*/
class pdf_soleil extends ModelePDFFicheinter
2003-06-28 21:54:29 +02:00
{
2003-06-11 15:35:25 +02:00
/**
\brief Constructeur
\param db Handler acc<EFBFBD>s base de donn<EFBFBD>e
*/
function pdf_soleil($db=0)
{
global $conf,$langs,$mysoc;
$this->db = $db;
$this->name = 'soleil';
2006-02-03 15:12:12 +01:00
$this->description = "Mod<EFBFBD>le de fiche d'intervention standard";
// 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
$this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
$this->option_modereg = 0; // Affiche mode r<>glement
$this->option_condreg = 0; // Affiche conditions r<>glement
$this->option_codeproduitservice = 0; // Affiche code produit-service
$this->option_multilang = 0; // Dispo en plusieurs langues
// Recupere code pays de l'emmetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->code_pays) $this->emetteur->code_pays=substr($langs->defaultlang,-2); // Par defaut, si n'<27>tait pas d<>fini
2003-06-11 15:35:25 +02:00
}
/**
\brief Fonction g<EFBFBD>n<EFBFBD>rant la fiche d'intervention sur le disque
2007-10-02 02:12:15 +02:00
\param fichinter Object fichinter
\return int 1=ok, 0=ko
*/
2007-09-03 14:23:54 +02:00
function write_pdf_file($fichinter,$outputlangs='')
2007-10-02 02:12:15 +02:00
{
global $user,$langs,$conf,$mysoc;
if (! is_object($outputlangs)) $outputlangs=$langs;
$outputlangs->load("main");
$outputlangs->load("companies");
$outputlangs->load("interventions");
$outputlangs->setPhpLang();
if ($conf->fichinter->dir_output)
{
// If $fichinter is id instead of object
if (! is_object($fichinter))
{
$id = $fichinter;
$fichinter = new Fichinter($this->db);
$result=$fichinter->fetch($id);
if ($result < 0)
{
dolibarr_print_error($db,$fichinter->error);
}
}
$fichref = sanitize_string($fichinter->ref);
$dir = $conf->fichinter->dir_output;
if (! eregi('specimen',$fichref)) $dir.= "/" . $fichref;
$file = $dir . "/" . $fichref . ".pdf";
if (! file_exists($dir))
{
if (create_exdir($dir) < 0)
{
$this->error=$langs->trans("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);
2007-10-02 02:12:15 +02:00
$pdfrights = array('print'); // Ne permet que l'impression du document
$pdfuserpass = ''; // Mot de passe pour l'utilisateur final
$pdfownerpass = NULL; // Mot de passe du propri<72>taire, cr<63><72> al<61>atoirement si pas d<>fini
$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
}
else
{
$pdf=new FPDI('P','mm',$this->format);
}
2007-10-02 02:12:15 +02:00
$pdf->Open();
$pdf->AddPage();
2007-10-02 02:12:15 +02:00
$posy=$this->marge_haute;
$pdf->SetXY($this->marge_gauche,$posy);
// Logo
2007-10-02 02:12:15 +02:00
$logo=$conf->societe->dir_logos.'/'.$mysoc->logo;
if ($mysoc->logo)
{
if (is_readable($logo))
{
2007-10-02 02:12:15 +02:00
$pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
}
else
{
2007-10-02 02:12:15 +02:00
$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');
}
}
// Nom emetteur
$posy=40;
$hautcadre=40;
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','',8);
$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);
$pdf->SetTextColor(0,0,60);
$pdf->SetFont('Arial','B',11);
if (defined("FAC_PDF_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) $pdf->MultiCell(80, 4, FAC_PDF_SOCIETE_NOM, 0, 'L');
else $pdf->MultiCell(80, 4, $mysoc->nom, 0, 'L');
// Caracteristiques emetteur
$carac_emetteur = '';
if (defined("FAC_PDF_ADRESSE") && FAC_PDF_ADRESSE) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).FAC_PDF_ADRESSE;
else {
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$mysoc->adresse;
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$mysoc->cp.' '.$mysoc->ville;
}
$carac_emetteur .= "\n";
// Tel
if (defined("FAC_PDF_TEL") && FAC_PDF_TEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".FAC_PDF_TEL;
elseif ($mysoc->tel) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$mysoc->tel;
// Fax
if (defined("FAC_PDF_FAX") && FAC_PDF_FAX) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".FAC_PDF_FAX;
elseif ($mysoc->fax) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$mysoc->fax;
// EMail
if (defined("FAC_PDF_MEL") && FAC_PDF_MEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".FAC_PDF_MEL;
elseif ($mysoc->email) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$mysoc->email;
// Web
if (defined("FAC_PDF_WWW") && FAC_PDF_WWW) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".FAC_PDF_WWW;
elseif ($mysoc->url) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$mysoc->url;
$pdf->SetFont('Arial','',9);
$pdf->SetXY($this->marge_gauche+2,$posy+8);
$pdf->MultiCell(80,4, $carac_emetteur);
/*
* Adresse Client
*/
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',12);
$fichinter->fetch_client();
$pdf->SetXY(102,42);
$pdf->MultiCell(66,5, $fichinter->client->nom);
$pdf->SetFont('Arial','B',11);
$pdf->SetXY(102,47);
$pdf->MultiCell(66,5, $fichinter->client->adresse . "\n" . $fichinter->client->cp . " " . $fichinter->client->ville);
$pdf->rect(100, 40, 100, 40);
$pdf->SetTextColor(200,0,0);
$pdf->SetFont('Arial','B',14);
$pdf->Text(11, 88, "Date : " . dolibarr_print_date($fichinter->date,'day'));
$pdf->Text(11, 94, $langs->trans("InterventionCard")." : ".$fichinter->ref);
$pdf->SetFillColor(220,220,220);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','',12);
$tab_top = 100;
$tab_height = 110;
$pdf->SetXY (10, $tab_top);
$pdf->MultiCell(190,8,$langs->transnoentities("Description"),0,'L',0);
$pdf->line(10, $tab_top + 8, 200, $tab_top + 8 );
$pdf->Rect(10, $tab_top, 190, $tab_height);
$pdf->SetFont('Arial','', 10);
$pdf->SetXY (10, $tab_top + 8 );
$pdf->MultiCell(190, 5, $fichinter->description, 0, 'J', 0);
$pdf->SetFont('Arial','', 9); // On repositionne la police par d?faut
$this->_pagefoot($pdf,$outputlangs);
$pdf->Close();
$pdf->Output($file);
return 1;
}
else
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0;
}
}
else
{
$this->error=$langs->trans("ErrorConstantNotDefined","FICHEINTER_OUTPUTDIR");
return 0;
}
$this->error=$langs->trans("ErrorUnknown");
return 0; // Erreur par defaut
}
/*
* \brief Affiche le pied de page
* \param pdf objet PDF
*/
function _pagefoot(&$pdf,$outputlangs)
{
global $conf;
$outputlangs->load("dict");
$html=new Form($this->db);
// Premiere ligne d'info r?glementaires
$ligne1="";
if ($this->emetteur->forme_juridique_code)
{
$ligne1.=($ligne1?" - ":"").$html->forme_juridique_name($this->emetteur->forme_juridique_code);
}
if ($this->emetteur->capital)
{
$ligne1.=($ligne1?" - ":"").$outputlangs->transnoentities("CapitalOf",$this->emetteur->capital)." ".$outputlangs->transnoentities("Currency".$conf->monnaie);
}
if ($this->emetteur->profid2)
{
$ligne1.=($ligne1?" - ":"").$outputlangs->transcountry("ProfId2",$this->emetteur->pays_code).": ".$this->emetteur->profid2;
}
if ($this->emetteur->profid1 && (! $this->emetteur->profid2 || $this->emetteur->pays_code != 'FR'))
{
$ligne1.=($ligne1?" - ":"").$outputlangs->transcountry("ProfId1",$this->emetteur->pays_code).": ".$this->emetteur->profid1;
}
// Deuxieme ligne d'info r?glementaires
$ligne2="";
if ($this->emetteur->profid3)
{
$ligne2.=($ligne2?" - ":"").$outputlangs->transcountry("ProfId3",$this->emetteur->pays_code).": ".$this->emetteur->profid3;
}
if ($this->emetteur->profid4)
{
$ligne2.=($ligne2?" - ":"").$outputlangs->transcountry("ProfId4",$this->emetteur->pays_code).": ".$this->emetteur->profid4;
}
2007-10-02 02:12:15 +02:00
if ($this->emetteur->tva_intra != '')
{
2007-10-02 02:12:15 +02:00
$ligne2.=($ligne2?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$this->emetteur->tva_intra;
}
2007-10-02 02:12:15 +02:00
$pdf->SetFont('Arial','',8);
$pdf->SetDrawColor(224,224,224);
// On positionne le debut du bas de page selon nbre de lignes de ce bas de page
$posy=$this->marge_basse + 1 + ($ligne1?3:0) + ($ligne2?3:0);
$pdf->SetY(-$posy);
$pdf->line($this->marge_gauche, $this->page_hauteur-$posy, 200, $this->page_hauteur-$posy);
$posy--;
if ($ligne1)
{
$pdf->SetXY($this->marge_gauche,-$posy);
$pdf->MultiCell(200, 2, $ligne1, 0, 'C', 0);
}
if ($ligne2)
{
$posy-=3;
$pdf->SetXY($this->marge_gauche,-$posy);
$pdf->MultiCell(200, 2, $ligne2, 0, 'C', 0);
}
//$pdf->SetXY(-20,-$posy);
//$pdf->MultiCell(10, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
2003-06-11 15:35:25 +02:00
}
2007-10-02 02:12:15 +02:00
2003-06-11 15:35:25 +02:00
}
?>