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 () {}
}
2010-03-11 16:38:29 +00:00
2010-02-10 17:27:03 +00:00
function normaliseVoie ( $txt )
{
$replace_pairs = array (
2010-03-11 16:38:29 +00:00
'BD ' => 'BOULEVARD ' ,
'BVD ' => 'BOULEVARD ' ,
'AV ' => 'AVENUE ' ,
'AVE ' => 'AVENUE ' ,
'PL ' => 'PLACE ' ,
'PLA ' => 'PLACE ' ,
2010-04-15 06:59:21 +00:00
'PLAC ' => 'PLACE ' ,
2010-03-11 16:38:29 +00:00
'ESP ' => 'ESP ' ,
'RTE ' => 'ROUTE ' ,
'ST ' => 'SAINT ' ,
'STE ' => 'SAINTE ' ,
'QU ' => 'QUAI ' ,
2010-02-10 17:27:03 +00:00
);
return strtr ( $txt , $replace_pairs );
}
setDbConn ( 'sdv1' );
$pdfInfo = new StdClass ();
2010-06-18 14:52:53 +00:00
$pdfInfo -> ref = $id ;
2010-06-15 13:17:33 +00:00
$typeCommande = substr ( $pdfInfo -> ref , 0 , 1 );
$id = substr ( $pdfInfo -> ref , 1 );
2010-06-15 12:46:12 +00:00
2010-06-15 12:49:59 +00:00
if ( $typeCommande == 'C' ) {
2010-06-15 12:46:12 +00:00
// => Info Commande
$q = Doctrine_Query :: create ()
-> from ( 'Commandes' )
2010-06-15 13:11:24 +00:00
-> where ( 'idCommande = ?' , $id )
2010-06-15 12:46:12 +00:00
-> andWhere ( 'typeCommande = ?' , 'C' );
$commande = $q -> fetchOne ();
if ( preg_match ( '/^([0-9]{4}_).*?$/' , $commande -> refDocument , $matches ) )
{
$typeDocument = 'bilans' ;
}
else
{
$typeDocument = 'actes' ;
}
} elseif ( $typeCommande == 'K' ){
// => Info Commande
$q = Doctrine_Query :: create ()
-> from ( 'CommandesKbis' )
2010-06-15 13:11:24 +00:00
-> where ( 'id = ?' , $id )
2010-06-15 12:57:43 +00:00
-> andWhere ( 'type = ?' , 'C' );
2010-06-15 12:46:12 +00:00
$commande = $q -> fetchOne ();
$typeDocument = 'kbis' ;
2010-03-10 15:27:12 +00:00
}
2010-06-15 12:46:12 +00:00
2010-02-10 17:27:03 +00:00
// => Identite
$siren = $commande -> siren ;
$O = $client -> getIdentite ( $siren , '' , false );
$etab = $O [ 'result' ];
$codeCommune = $etab [ 'codeCommune' ];
$dept = $etab [ 'Dept' ];
$siret = $etab [ 'Siret' ];
$numRC = $etab [ 'NumRC' ];
2010-04-13 16:02:43 +00:00
//Adresse du tribunal de commerce
$O = $client -> getListeCompetences ( $siret , 'tri' , $dept . $codeCommune );
$competences = $O [ 'result' ];
$competence = $competences [ 0 ];
$tribunalCode = $competence [ 'Code' ];
$tribunalLib = $comptence [ 'Nom' ];
2010-02-10 17:27:03 +00:00
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' ];
2010-04-13 16:02:43 +00:00
$pdfInfo -> tribunal = $competence ;
2010-02-10 17:27:03 +00:00
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' );
2010-04-15 06:59:21 +00:00
$pdfInfo -> prix = number_format ( $tarifs [ 0 ] -> prix , 2 , ',' , ' ' );
2010-02-10 17:27:03 +00:00
$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 = '' ;
2010-03-11 16:38:29 +00:00
/*
2010-02-10 17:27:03 +00:00
$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-03-11 16:38:29 +00:00
*/
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' )
{
2010-03-11 16:38:29 +00:00
$txt .= 'une copie du bilan au ' ;
preg_match ( '/^[0-9]{4}_.*?-([0-9]{8}).*?/' , $commande -> refDocument , $matches );
2010-02-10 17:27:03 +00:00
$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 );
2010-06-15 12:46:12 +00:00
}
elseif ( $typeDocument == 'kbis' )
{
2010-06-15 12:57:43 +00:00
$txt .= 'un extrait RCS' ;
2010-02-10 17:27:03 +00:00
}
2010-03-11 16:38:29 +00:00
2010-02-10 17:27:03 +00:00
$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 ){
2010-03-11 16:38:29 +00:00
if ( ! empty ( $item ) ){
$txt .= normaliseVoie ( htmlspecialchars_decode ( $item , ENT_QUOTES )) . " \n " ;
}
2010-02-10 17:27:03 +00:00
}
$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 )
{
2010-03-11 16:38:29 +00:00
$txt = " Ci joint une enveloppe timbrée ainsi qu'un chèque d'un montant de " .
2010-02-10 17:27:03 +00:00
$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 );
}