181 lines
6.0 KiB
PHP
181 lines
6.0 KiB
PHP
<?php
|
|
require_once 'infogreffe/constantes.php';
|
|
require_once 'dbbootstrap.php';
|
|
setDbConn('sdv1');
|
|
|
|
define('PCLZIP_TEMPORARY_DIR', PATH_DATA.'/courrier/');
|
|
require_once 'lib/odtphp/library/odf.php';
|
|
$odf = new odf(realpath(dirname(__FILE__).'/modeleLettreGreffe.odt'));
|
|
|
|
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);
|
|
}
|
|
|
|
$info = new StdClass;
|
|
$info->ref = $id;
|
|
$typeCommande = substr($info->ref, 0, 1);
|
|
$id = substr($info->ref, 1);
|
|
|
|
if ($typeCommande == 'C') {
|
|
$commande = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->andWhere('idCommande = ?', $id)
|
|
->andWhere('typeCommande = ?', 'C')
|
|
->fetchOne();
|
|
|
|
if (preg_match('/^([0-9]{4}_).*?$/', $commande->refDocument, $matches)) {
|
|
$typeDocument = 'bilans';
|
|
} else {
|
|
$typeDocument = 'actes';
|
|
}
|
|
} else if ($typeCommande == 'K') {
|
|
$commande = Doctrine_Query::create()
|
|
->from('CommandesKbis')
|
|
->andWhere('id = ?', $id)
|
|
->andWhere('type = ?', 'C')
|
|
->fetchOne();
|
|
|
|
$typeDocument = 'kbis';
|
|
}
|
|
|
|
require_once 'scoresws/scoresws.php';
|
|
// Identite
|
|
$siren = $commande->siren;
|
|
$etab = scoresws_identite($siren, $siren, 0);
|
|
$commune = $etab->codeCommune;
|
|
$dept = $etab->Dept;
|
|
$siret = $etab->Siret;
|
|
$numRC = $etab->NumRC;
|
|
|
|
// Adresse du tribunal de commerce
|
|
$competence =
|
|
scorews_competences($siret, $siren, $idEntreprise, 'tri', $dept.$commune);
|
|
$tribunalCode = $competence['Code'];
|
|
$tribunalLib = $competence['Nom'];
|
|
if (preg_match('/(A|B|C|D)/i', $numRC)) {
|
|
$libTrib = ' RCS '.
|
|
preg_replace('/(^TC |^TI |^TGIcc |^TMX )/i', '', $tribunalLib);
|
|
} else if (preg_match('/(P)/i', $numRC)) {
|
|
$libTrib = ' RSAC '.
|
|
preg_replace('/(^TC |^TI |^TGIcc |^TMX )/i', '', $tribunalLib);
|
|
}
|
|
$info->siren =
|
|
substr($siren, 0, 3).' '.
|
|
substr($siren, 3, 3).' '.
|
|
substr($siren, 6, 3);
|
|
$info->nom = $etab->Nom;
|
|
$info->libTrib = $libTrib;
|
|
$info->adresse = $etab->Adresse.' ';
|
|
if (empty($etab->Adresse2) == false) {
|
|
$info->adresse .= $etab->Adresse2.' ';
|
|
}
|
|
$info->adresse .= "\n".$etab->CP.' '.$etab->Ville;
|
|
$info->tribunal = $competence;
|
|
|
|
// Prix
|
|
$tarifs = Doctrine_Query::create()
|
|
->from('CommandesTarifs')
|
|
->andWhere('codeTribunal = ?', $tribunalCode)
|
|
->andWhere('type = ?', $typeDocument)
|
|
->andWhere('annee = ?', date('Y'))
|
|
->execute();
|
|
|
|
if ($tarifs->count() == 0) {
|
|
echo 'Pas de tarifs défini pour le tribunal '.
|
|
$info->tribunal['Nom'].' ('.$tribunalCode.')';
|
|
exit;
|
|
}
|
|
$info->prix = number_format($tarifs[0]->prix, 2, ',', ' ');
|
|
$info->enveloppe = $tarifs[0]->enveloppe;
|
|
|
|
// Destinataire
|
|
/*
|
|
$destinataire =
|
|
strtr($info->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')
|
|
);
|
|
$destinataire .= "\n";
|
|
*/
|
|
$destinataire = "REGISTRE DU COMMERCE - GREFFE\n".
|
|
normaliseVoie(trim($info->tribunal['Adr']))."\n".
|
|
normaliseVoie($info->tribunal['AdrComp'])."\n".
|
|
$info->tribunal['CP'].' '.$info->tribunal['Ville']."\n";
|
|
|
|
// 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]
|
|
if ($typeDocument == 'bilans') {
|
|
preg_match('/^[0-9]{4}_.*?-([0-9]{8}).*?/',
|
|
$commande->refDocument, $matches);
|
|
$sujet = 'une copie du bilan au '.
|
|
substr($matches[1], 6, 2).'/'.
|
|
substr($matches[1], 4, 2).'/'.
|
|
substr($matches[1], 0, 4);
|
|
} else if ($typeDocument == 'actes') {
|
|
$sujet = 'une copie de l\'acte '.
|
|
$typeActes['a'.substr($commande->refDocument,0,2)];
|
|
if (empty($commande->libDocument) == false) {
|
|
$sujet .= ' ('.$commande->libDocument.')';
|
|
}
|
|
$sujet .= ' en date du '.
|
|
substr($commande->refDocument, 9, 2).'/'.
|
|
substr($commande->refDocument, 7, 2).'/'.
|
|
substr($commande->refDocument, 3, 4);
|
|
} else if ($typeDocument == 'kbis') {
|
|
$sujet = 'un extrait RCS';
|
|
}
|
|
|
|
// Societe
|
|
$societe = $info->nom."\n".'( '.$info->siren.$info->libTrib.' )'."\n";
|
|
$societe .= normaliseVoie(htmlspecialchars_decode($info->adresse, ENT_QUOTES));
|
|
|
|
// Piece jointe et montant
|
|
if ($info->enveloppe) {
|
|
$montant = 'Ci-joint une enveloppe timbrée ainsi qu\'un '.
|
|
'chèque d\'un montant de '.$info->prix.
|
|
' euros en règlement de cette commande.';
|
|
} else {
|
|
$montant = 'Ci-joint un chèque d\'un montant de '.$info->prix.
|
|
' euros en règlement de cette commande.';
|
|
}
|
|
|
|
$path = PATH_DATA.'/courrier/';
|
|
$file = $siren.'-'.$info->ref.'.odt';
|
|
|
|
$odf->setVars('destinataire', $destinataire, true, 'UTF-8');
|
|
$odf->setVars('date', date('d/m/Y'), true, 'UTF-8');
|
|
$odf->setVars('ref', $info->ref, true, 'UTF-8');
|
|
$odf->setVars('sujet', $sujet, true, 'UTF-8');
|
|
$odf->setVars('societe', $societe, true, 'UTF-8');
|
|
$odf->setVars('montant', $montant, true, 'UTF-8');
|
|
$odf->saveToDisk($path.$file);
|
|
|
|
if (file_exists($path.$file) == true) {
|
|
header('Content-Transfer-Encoding: none');
|
|
header('Content-type: application/vnd.oasis.opendocument.text');
|
|
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');
|
|
print file_get_contents($path.$file);
|
|
}
|