2010-02-10 17:27:03 +00:00
< ? php
// just require TCPDF instead of FPDF
require_once 'tcpdf/tcpdf.php' ;
require_once 'fpdi/fpdi.php' ;
require_once 'dbbootstrap.php' ;
require_once 'infogreffe/constantes.php' ;
class PDF extends FPDI {
/**
* " Remembers " the template id of the imported page
*/
var $_tplIdx ;
2010-03-10 15:27:12 +00:00
2010-02-10 17:27:03 +00:00
/**
* include a background template for every page
*/
function Header () {
if ( is_null ( $this -> _tplIdx )) {
$this -> setSourceFile ( PATH_SITE . '/includes/courrier/modele.pdf' );
$this -> _tplIdx = $this -> importPage ( 1 );
}
$this -> useTemplate ( $this -> _tplIdx );
}
2010-03-10 15:27:12 +00:00
2010-02-10 17:27:03 +00:00
function Footer () {}
}
function normaliseVoie ( $txt )
{
$replace_pairs = array (
'BD' => 'BOULEVARD' ,
'BVD' => 'BOULEVARD' ,
'AV' => 'AVENUE' ,
'AVE' => 'AVENUE' ,
'PL' => 'PLACE' ,
'PLA' => 'PLACE' ,
'ESP' => 'ESP' ,
'RTE' => 'ROUTE' ,
'ST' => 'SAINT' ,
'STE' => 'SAINTE' ,
);
return strtr ( $txt , $replace_pairs );
}
setDbConn ( 'sdv1' );
$pdfInfo = new StdClass ();
// => Ref
$id = $_REQUEST [ 'id' ];
$pdfInfo -> ref = 'C' . $id ;
// => Info Commande
$q = Doctrine_Query :: create ()
-> from ( 'Commandes' )
-> where ( 'idCommande = ?' , $id )
-> andWhere ( 'typeCommande = ?' , 'C' );
$commande = $q -> fetchOne ();
if ( preg_match ( '/^([0-9]{4}_).*?$/' , $commande -> refDocument , $matches ) )
{
$typeDocument = 'bilans' ;
}
else
{
$typeDocument = 'actes' ;
2010-03-10 15:27:12 +00:00
}
2010-02-10 17:27:03 +00:00
// => Identite
$siren = $commande -> siren ;
2010-03-10 15:27:12 +00:00
$client = new SoapClient ( null , array (
2010-02-10 17:27:03 +00:00
'trace' => 1 ,
'soap_version' => SOAP_1_1 ,
'location' => WEBSERVICE_URL ,
'uri' => WEBSERVICE_URI ,
'login' => $_SESSION [ 'tabInfo' ][ 'login' ],
'password' => $_SESSION [ 'tabInfo' ][ 'password' ],
));
$O = $client -> getIdentite ( $siren , '' , false );
$etab = $O [ 'result' ];
$tribunalCode = $etab [ 'TribunalCode' ];
$codeCommune = $etab [ 'codeCommune' ];
$dept = $etab [ 'Dept' ];
$siret = $etab [ 'Siret' ];
$numRC = $etab [ 'NumRC' ];
$tribunalLib = $etab [ 'TribunalLib' ];
if ( preg_match ( '/(A|B|C|D)/i' , $numRC ))
{
$libTrib = ' RCS ' . preg_replace ( '/(^TC |^TI |^TGIcc |^TMX )/i' , '' , $tribunalLib );
}
elseif ( preg_match ( '/(P)/i' , $numRC ))
{
$libTrib = ' RSAC ' . preg_replace ( '/(^TC |^TI |^TGIcc |^TMX )/i' , '' , $tribunalLib );
}
$pdfInfo -> siren = substr ( $siren , 0 , 3 ) . ' ' .
substr ( $siren , 3 , 3 ) . ' ' .
substr ( $siren , 6 , 3 );
$pdfInfo -> nom = $etab [ 'Nom' ];
$pdfInfo -> libTrib = $libTrib ;
$pdfInfo -> adresse [] = $etab [ 'Adresse' ];
$pdfInfo -> adresse [] = $etab [ 'Adresse2' ];
$pdfInfo -> adresse [] = $etab [ 'CP' ] . ' ' . $etab [ 'Ville' ];
//Adresse du tribunal de commerce
$O = $client -> getListeCompetences ( $siret , 'tri' , $dept . $codeCommune );
$competences = $O [ 'result' ];
foreach ( $competences as $competence )
{
if ( $competence [ 'Code' ] == $tribunalCode )
{
$pdfInfo -> tribunal = $competence ;
break ;
}
}
2010-03-10 15:27:12 +00:00
//Prix
2010-02-10 17:27:03 +00:00
$q = Doctrine_Query :: create ()
-> from ( 'CommandesTarifs' )
-> where ( 'codeTribunal = ?' , $tribunalCode )
-> andWhere ( 'type = ?' , $typeDocument )
-> andWhere ( 'annee = ?' , date ( 'Y' ));
$tarifs = $q -> execute ();
$firephp -> log ( $tarifs -> toArray (), 'tarifs' );
if ( $tarifs -> count () == 0 )
{
2010-03-10 15:27:12 +00:00
echo 'Pas de tarifs défini pour le tribunal ' .
2010-02-10 17:27:03 +00:00
$pdfInfo -> tribunal [ 'Nom' ] . ' (' . $tribunalCode . ')' ;
exit ;
}
$firephp -> log ( $tarifs [ 0 ] -> prix , 'prix' );
$pdfInfo -> prix = $tarifs [ 0 ] -> prix ;
$pdfInfo -> enveloppe = $tarifs [ 0 ] -> enveloppe ;
// initiate PDF
$pdf = new PDF ();
/*
2010-03-10 15:27:12 +00:00
* Définition des marges
2010-02-10 17:27:03 +00:00
* Left , Top et Right
2010-03-10 15:27:12 +00:00
* Dimension du logo d ' entete :
2010-02-10 17:27:03 +00:00
**/
$pdf -> SetMargins ( 25 , 50 , 25 );
$border = 0 ;
// add a page
$pdf -> AddPage ();
$pdf -> SetFont ( " times " , " " , 10 );
//Position de départ
$pdf -> SetY ( 50 );
//Bloc Addresse destinataire
$txt = '' ;
$txt .= strtr (
$pdfInfo -> tribunal [ 'Nom' ],
array (
'TGI' => 'TRIBUNAL DE GRANDE INSTANCE DE' ,
'TI' => 'TRIBUNAL D\'INSTANCE DE' ,
2010-03-10 15:27:12 +00:00
'TC' => 'TRIBUNAL DE COMMERCE DE' ,
2010-02-10 17:27:03 +00:00
'TGIcc' => 'TRIBUNAL DE GRANDE INSTANCE A COMPETENCE COMMERCIALE DE'
)
);
2010-03-10 15:27:12 +00:00
$txt .= " \n " ;
2010-02-10 17:27:03 +00:00
$txt .= " REGISTRE DU COMMERCE - GREFFE " . " \n " ;
$txt .= normaliseVoie ( $pdfInfo -> tribunal [ 'Adr' ]) . " \n " ;
$txt .= normaliseVoie ( $pdfInfo -> tribunal [ 'AdrComp' ]) . " \n " ;
$txt .= $pdfInfo -> tribunal [ 'CP' ] . ' ' . $pdfInfo -> tribunal [ 'Ville' ] . " \n " ;
$largeur = 80 ;
$positionX = 105 ;
$pdf -> MultiCell ( $largeur , 5 , $txt , $border , 'L' , 0 , 1 , $positionX );
//Bloc Lieu, date
$date = date ( 'd/m/Y' );
$txt = " Rambouillet, le $date " ;
$positionY = $pdf -> GetY () + 8 ;
$pdf -> MultiCell ( $largeur , 5 , $txt , $border , 'L' , 0 , 1 , $positionX , $positionY );
//Bloc objet
$positionY = $pdf -> GetY () + 5 ;
$pdf -> MultiCell ( 20 , 5 , " Objet: " , $border , 'L' , 0 , 0 , '' , $positionY , true );
$pdf -> MultiCell ( 0 , 5 , " Commande de document " , $border , 'L' , 0 , 1 , '' , '' , true );
//Bloc ref
$pdf -> MultiCell ( 20 , 5 , " Réf. " , $border , 'L' , 0 , 0 , '' , '' , true );
$pdf -> MultiCell ( 0 , 5 , $pdfInfo -> ref , $border , 'L' , 0 , 1 , '' , '' , true );;
//Bloc titre
$positionY = $pdf -> GetY () + 5 ;
$pdf -> MultiCell ( 0 , 5 , " Madame, Monsieur, " , $border , 'L' , 0 , 1 , '' , $positionY , true );
//Type de document demandé (actes ou bilans pour l'instant)
//[un Kbis / l'état d'endettement / la copie de jugement de XXX en date du XXX ]
$txt = '' ;
if ( $typeDocument == 'bilans' )
{
$txt .= 'une copie des comptes au' ;
preg_match ( '/^[0-9]{3}_.*?-([0-9]{8}).*?/' , $commande -> refDocument , $matches );
$txt .= substr ( $matches [ 1 ], 6 , 2 ) . '/' . substr ( $matches [ 1 ], 4 , 2 ) . '/' . substr ( $matches [ 1 ], 0 , 4 );
}
2010-03-10 15:27:12 +00:00
elseif ( $typeDocument == 'actes' )
2010-02-10 17:27:03 +00:00
{
$txt .= 'une copie de l\'acte ' ;
$txt .= $typeActes [ 'a' . substr ( $commande -> refDocument , 0 , 2 )];
if ( ! empty ( $commande -> libDocument ) ) $txt .= ' (' . $commande -> libDocument . ')' ;
$txt .= ' en date du ' .
substr ( $commande -> refDocument , 9 , 2 ) . '/' .
substr ( $commande -> refDocument , 7 , 2 ) . '/' .
substr ( $commande -> refDocument , 3 , 4 );
}
$positionY = $pdf -> GetY () + 2 ;
$pdf -> MultiCell ( 0 , 5 , " Je vous prie de nous faire parvenir $txt concernant la société: " , $border , 'L' , 0 , 1 , '' , $positionY , true );
//Bloc société
$txt = '' ;
$txt .= $pdfInfo -> nom ;
$txt .= ' ( ' . $pdfInfo -> siren . $pdfInfo -> libTrib . ' )' . " \n " ;
foreach ( $pdfInfo -> adresse as $item ){
$txt .= normaliseVoie ( htmlspecialchars_decode ( $item , ENT_QUOTES )) . " \n " ;
}
$positionY = $pdf -> GetY () + 2 ;
$pdf -> MultiCell ( 0 , 5 , $txt , $border , 'L' , 0 , 1 , '' , $positionY , true );
//Bloc pièce jointe
$positionY = $pdf -> GetY () + 5 ;
if ( $pdfInfo -> enveloppe )
{
$txt = " Ci joint une enveloppe timbré ainsi qu'un chèque d'un montant de " .
$pdfInfo -> prix . " euros en règlement de cette commande. " ;
} else {
$txt = " Ci joint un chèque d'un montant de " .
$pdfInfo -> prix . " euros en règlement de cette commande. " ;
}
$pdf -> MultiCell ( 0 , 5 , $txt , $border , 'L' , 0 , 1 , '' , $positionY , true );
//Bloc intitulé adresse reception
$positionY = $pdf -> GetY () + 2 ;
2010-03-10 15:27:12 +00:00
$pdf -> MultiCell ( 0 , 5 ,
2010-02-10 17:27:03 +00:00
" Veuillez nous renvoyer le(s) document(s) par retour à l'adresse suivante: " ,
$border , 'L' , 0 , 1 , '' , $positionY , true );
2010-03-10 15:27:12 +00:00
2010-02-10 17:27:03 +00:00
//Bloc adresse s&d
$positionY = '' ;
2010-03-10 15:27:12 +00:00
$pdf -> MultiCell ( 0 , 5 ,
2010-02-10 17:27:03 +00:00
" SCORES ET DECISIONS " . " \n " .
2010-03-10 15:27:12 +00:00
" 19 rue Clairefontaine " . " \n " .
2010-02-10 17:27:03 +00:00
" 78120 RAMBOUILLET " . " \n "
, $border , 'L' , 0 , 1 , '' , $positionY , true );
//Bloc formule politesse
$positionY = $pdf -> GetY () + 2 ;
$pdf -> MultiCell ( 0 , 5 , " Dans l'attente de notre prochain échange, je vous prie de recevoir, Madame, Monsieur, l'expression de nos plus sincères salutations. " , $border , 'L' , 0 , 1 , '' , $positionY , true );
$nomFichier = $siren . '-' . $pdfInfo -> ref ;
$file = $nomFichier . '.pdf' ;
$path = PATH_DATA . '/courrier/' ;
$pdf -> Output ( $path . $file , 'F' );
if ( file_exists ( $path . $file ))
{
$content_type = 'application/pdf' ;
header ( 'Content-Transfer-Encoding: none' );
header ( 'Content-type: ' . $content_type . '' );
header ( 'Content-Length: ' . filesize ( $path . $file ));
header ( 'Content-MD5: ' . base64_encode ( md5_file ( $path . $file )));
header ( 'Content-Disposition: attachment, filename="' . $file . '"' );
header ( 'Cache-Control: private, max-age=0, must-revalidate' );
header ( 'Pragma: public' );
ini_set ( 'zlib.output_compression' , '0' );
echo file_get_contents ( $path . $file );
}