296 lines
8.0 KiB
PHP
296 lines
8.0 KiB
PHP
<?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;
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
function Footer() {}
|
|
}
|
|
|
|
function normaliseVoie($txt)
|
|
{
|
|
$replace_pairs = array(
|
|
'BD ' => 'BOULEVARD ',
|
|
'BVD ' => 'BOULEVARD ',
|
|
'AV ' => 'AVENUE ',
|
|
'AVE ' => 'AVENUE ',
|
|
'PL ' => 'PLACE ',
|
|
'PLA ' => 'PLACE ',
|
|
'PLAC ' => 'PLACE ',
|
|
'ESP ' => 'ESP ',
|
|
'RTE ' => 'ROUTE ',
|
|
'ST ' => 'SAINT ',
|
|
'STE ' => 'SAINTE ',
|
|
'QU ' => 'QUAI ',
|
|
);
|
|
return strtr($txt, $replace_pairs);
|
|
}
|
|
|
|
setDbConn('sdv1');
|
|
|
|
$pdfInfo = new StdClass();
|
|
|
|
// => Ref
|
|
$id = $_REQUEST['id'];
|
|
$typeCommande = substr($id, 0, 1);
|
|
$pdfInfo->ref = substr($id, 1);
|
|
|
|
if ( $typeCommande == 'C' ) {
|
|
|
|
// => Info Commande
|
|
$q = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->where('idCommande = ?', $pdfInfo->ref)
|
|
->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')
|
|
->where('id = ?', $pdfInfo->ref)
|
|
->andWhere('type = ?', 'C');
|
|
|
|
$commande = $q->fetchOne();
|
|
$typeDocument = 'kbis';
|
|
}
|
|
|
|
|
|
// => Identite
|
|
$siren = $commande->siren;
|
|
|
|
$client = new SoapClient(null, array(
|
|
'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'];
|
|
$codeCommune = $etab['codeCommune'];
|
|
$dept = $etab['Dept'];
|
|
$siret = $etab['Siret'];
|
|
$numRC = $etab['NumRC'];
|
|
|
|
//Adresse du tribunal de commerce
|
|
$O = $client->getListeCompetences($siret, 'tri', $dept.$codeCommune);
|
|
$competences = $O['result'];
|
|
$competence = $competences[0];
|
|
|
|
$tribunalCode = $competence['Code'];
|
|
$tribunalLib = $comptence['Nom'];
|
|
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'];
|
|
|
|
$pdfInfo->tribunal = $competence;
|
|
|
|
//Prix
|
|
$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)
|
|
{
|
|
echo 'Pas de tarifs défini pour le tribunal '.
|
|
$pdfInfo->tribunal['Nom'].' ('.$tribunalCode.')';
|
|
exit;
|
|
}
|
|
$firephp->log($tarifs[0]->prix,'prix');
|
|
$pdfInfo->prix = number_format($tarifs[0]->prix, 2, ',', ' ');
|
|
$pdfInfo->enveloppe = $tarifs[0]->enveloppe;
|
|
|
|
// initiate PDF
|
|
$pdf = new PDF();
|
|
/*
|
|
* Définition des marges
|
|
* Left, Top et Right
|
|
* Dimension du logo d'entete :
|
|
**/
|
|
$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',
|
|
'TC' => 'TRIBUNAL DE COMMERCE DE',
|
|
'TGIcc' => 'TRIBUNAL DE GRANDE INSTANCE A COMPETENCE COMMERCIALE DE'
|
|
)
|
|
);
|
|
$txt.= "\n";
|
|
*/
|
|
$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 du bilan au ';
|
|
preg_match('/^[0-9]{4}_.*?-([0-9]{8}).*?/', $commande->refDocument, $matches);
|
|
$txt.= substr($matches[1],6,2).'/'.substr($matches[1],4,2).'/'.substr($matches[1],0,4);
|
|
}
|
|
elseif( $typeDocument == 'actes' )
|
|
{
|
|
$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);
|
|
}
|
|
elseif ($typeDocument == 'kbis' )
|
|
{
|
|
$txt.= 'un extrait RCS';
|
|
}
|
|
|
|
$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){
|
|
if( !empty($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ée 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;
|
|
$pdf->MultiCell(0, 5,
|
|
"Veuillez nous renvoyer le(s) document(s) par retour à l'adresse suivante:",
|
|
$border, 'L', 0, 1, '', $positionY, true);
|
|
|
|
//Bloc adresse s&d
|
|
$positionY = '';
|
|
$pdf->MultiCell(0, 5,
|
|
"SCORES ET DECISIONS" . "\n" .
|
|
"19 rue Clairefontaine". "\n" .
|
|
"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);
|
|
}
|
|
|