extranet/application/controllers/SurveillanceController.php

943 lines
30 KiB
PHP
Raw Normal View History

2011-02-21 08:45:13 +00:00
<?php
class SurveillanceController extends Zend_Controller_Action
{
2011-08-19 20:28:30 +00:00
/**
* Association source => texte
* @var array
*/
2011-05-04 13:17:01 +00:00
protected $sourceTxt = array(
'annonces' => 'Annonces',
'insee' => 'Insee',
'bilans' => 'Bilans',
'score' => 'IndiScore',
'actes' => 'Actes',
'dirigeants' => 'Dirigeants',
'privileges' => 'Privilèges',
);
2011-08-19 20:28:30 +00:00
/**
* Association source => droits
* @var array
*/
2011-05-04 13:17:01 +00:00
protected $sourceDroit = array(
'annonces' => 'survannonce',
'insee' => 'survinsee',
'bilans' => 'survbilan',
'score' => 'survscore',
'actes' => 'survactes',
'dirigeants' => 'survdirigeants',
'privileges' => 'survpriv',
);
2011-02-21 08:45:13 +00:00
2011-04-19 08:51:48 +00:00
public function init()
{
2011-04-20 07:26:17 +00:00
require_once 'Scores/Utilisateur.php';
2011-04-20 13:41:43 +00:00
require_once 'Scores/WsScores.php';
require_once 'common/dates.php';
2011-04-19 08:51:48 +00:00
}
public function indexAction()
{
2011-08-19 20:28:30 +00:00
//What we want to do here
2011-04-19 08:51:48 +00:00
}
2011-02-21 08:45:13 +00:00
2011-05-04 13:17:01 +00:00
/**
* Ajouter une surveillance
*/
public function ajouterAction()
{
//Affichage formulaire demande ref et email
$this->_helper->layout->disableLayout();
$request = $this->getRequest();
$siret = $request->getParam('siret', '');
$email = $request->getParam('email', '');
$ref = $request->getParam('ref', '');
$source = $request->getParam('source', 'annonces');
$encours = $request->getParam('encours', 0);
$user = new Utilisateur();
$email = $user->getEmail();
if( empty($source) ) {
$source = array();
foreach($this->sourceTxt as $Source => $Txt) {
if( $user->checkPerm($this->sourceDroit[$Source]) ) {
$checked = 'checked';
if ($Source=='privileges') {
$checked = '';
}
$source[] = array(
'id' => $Source,
'txt' => $Txt,
'checked' => $checked,
);
}
}
}
$this->view->assign('source', $source);
$this->view->assign('siret', $siret);
2011-05-04 13:17:01 +00:00
$this->view->assign('email', $email);
$this->view->assign('ref', $ref);
$this->view->assign('encours', $encours);
}
/**
* Supprimer une surveillances
*/
public function supprimerAction()
{
$request = $this->getRequest();
$siret = $request->getParam('siret', '');
$email = $request->getParam('email', '');
$ref = $request->getParam('ref', '');
$source = $request->getParam('source', 'annonces');
$ws = new WsScores();
$set = $ws->setSurveillance($siret, $email, $ref, $source, true);
2011-05-04 13:23:23 +00:00
$this->_redirect('surveillance/liste');
2011-05-04 13:17:01 +00:00
}
/**
* Ajoute, Supprime, Edite la surveillance (Ajax)
*/
public function setAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$request = $this->getRequest();
$siret = $request->getParam('siret', '');
$email = $request->getParam('email', '');
$ref = $request->getParam('ref', '');
$source = $request->getParam('source', 'annonces');
$delete = $request->getParam('delete', false);
$encours = $request->getParam('encours', 0);
//Vérification siret / email / ref
if (empty($siret) || empty($email) | empty($ref)){
echo 'Erreur email ou reférence non définie !';
exit;
}
//Vérification de l'encours (chiffres)
if (!preg_match('/([0-9]+)/', $encours)){
echo 'Encours incorrect';
exit;
}
if (!empty($delete)){
$delete = true;
}
$ws = new WsScores();
if (is_array($source)) {
foreach($source as $s) {
$set = $ws->setSurveillance($siret, $email, $ref, $s, $delete, $encours);
}
} else {
$set = $ws->setSurveillance($siret, $email, $ref, $source, $delete, $encours);
}
Zend_Registry::get('firebug')->info($result);
echo $set->result;
}
/**
* Ajoute un encours client
*/
public function encoursAction()
{
$this->_helper->layout->disableLayout();
$this->_forward('ajouter');
2011-05-04 13:17:01 +00:00
}
2011-05-24 06:25:58 +00:00
2011-04-20 13:41:43 +00:00
/**
* Affiche les infos d'une surveillance
*/
public function infosAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/surveillance.js', 'text/javascript');
2011-04-20 13:41:43 +00:00
$request = $this->getRequest();
$source = $request->getParam('source', '');
$siret = $request->getParam('siret', 0);
2011-04-20 13:41:43 +00:00
$user = new Utilisateur();
//if ($user->checkPerm())
$listSurv = array();
if (intval($siret)!=0)
{
$ws = new WsScores();
$infos = $ws->getSurveillances('siren', $source, $siret);
$surveillances = $infos->result->item;
if (count($surveillances)>0) {
$titre = 'Ajouter une surveillance';
$texte = "L'entité est sous surveillance";
foreach($surveillances as $surv){
$tooltipTexte = '';
$ref = $surv->ref;
$tooltipTexte.= "Ref : ".$ref;
$tooltipTexte.= "<br/>Date d'ajout :".WDate::dateT('Y-m-d', 'd/m/Y', $surv->dateAjout);
if ($surv->dateDerEnvoi!='0000-00-00 00:00:00') {
$tooltipTexte.= "<br/>Date de dernier envoi : ".
WDate::dateT('Y-m-d', 'd/m/Y', substr($surv->dateDerEnvoi,0,10));
}
$listSurv[] = array(
'tooltipTexte' => $tooltipTexte,
'sourceTexte' => $this->sourceTxt[$surv->source]
);
}
} else {
$titre = 'Ajouter une surveillance';
$texte = 'Mettre sous surveillance';
if (!empty($source)){
$texte.= ' '.$this->sourceTxt[$source];
2011-04-20 13:41:43 +00:00
}
}
2011-04-20 13:41:43 +00:00
}
2011-04-20 13:41:43 +00:00
if (!empty($ref)) {
$this->view->assign('ref', $ref);
} else {
$this->view->assign('ref', $ref);
}
$this->view->assign('surveillances', $listSurv);
$this->view->assign('dialogTitre', $titre);
$this->view->assign('dialogTexte', $texte);
$this->view->assign('dialogSource', $source);
2011-04-20 13:41:43 +00:00
}
/**
* Liste les surveillances
*/
2011-04-19 08:51:48 +00:00
public function listeAction()
{
2011-08-22 16:02:17 +00:00
$user = new Utilisateur();
if (!$user->checkPerm('survliste')){
$this->_forward('perm', 'error');
}
2011-05-04 13:17:01 +00:00
$this->view->headLink()
->appendStylesheet('/themes/default/styles/surveillance.css', 'all');
2011-04-20 07:26:17 +00:00
$this->view->headScript()
->appendFile('/themes/default/scripts/jquery.tablesorter.js', 'text/javascript')
->appendFile('/themes/default/scripts/surveillance.js', 'text/javascript');
$request = $this->getRequest();
2011-05-04 13:17:01 +00:00
2011-04-20 07:26:17 +00:00
$page = $request->getParam('page', 0);
$source = $request->getParam('source', '');
$tri = $request->getParam('tri', 'siren');
$detail = true;
$nbAffichage = 100;
$position = $page*$nbAffichage;
switch($tri){
default:
case 'siren': $triws = 'siren'; break;
case 'rs': $triws = 'rs'; break;
case 'reference': $triws = 'ref'; break;
case 'dateajout': $triws = 'dateAjout'; break;
case 'datederenvoi': $triws = 'dateDerEnvoi'; break;
}
// Source => Permission
$tabSource = array(
'annonces' => 'annonce',
'insee' => 'insee',
'bilans' => 'bilan',
'score' => 'score',
'actes' => 'actes',
'dirigeants' => 'dirigeants',
'privileges' => 'priv',
);
$user = new Utilisateur();
//Select Tri + Liste des sources autorisée
$selectTri = '';
$permSource = array();
foreach ($tabSource as $s => $perm) {
if ($user->checkPerm('surv'.$perm)) {
$permSource[] = $s;
$selectTri.= '<option value="'.$s.'"';
if ($source == $s) {
$selectTri.= 'selected';
}
$selectTri.= '>'.$s.'</option>';
}
}
2011-04-19 08:51:48 +00:00
$ws = new WsScores();
2011-04-20 07:26:17 +00:00
$infos = $ws->getSurveillances($tri, $source, '', $detail, $position);
$surveillances = $infos->result->item;
//Tri si nécessaire
if (empty($source)){
$i=0;
$tabIndex = array();
$listTrier = array();
if (count($surveillances)>0) {
foreach($surveillances as $item) {
if(!array_key_exists($item->siren, $tabIndex)) {
//Création du tableau trier
$listTrier[$i]['siren'] = $item->siren;
$listTrier[$i]['nic'] = $item->nic;
$listTrier[$i]['rs'] = $item->rs;
$listTrier[$i]['cp'] = $item->cp;
$listTrier[$i]['ville'] = $item->ville;
$listTrier[$i]['sources'][$item->source][0] = array(
'email' => $item->email,
'ref' => $item->ref,
'dateAjout' => $item->dateAjout,
'dateDerEnvoi' => $item->dateDerEnvoi,
);
//Tableau d'index
$tabIndex[$item->siren] = $i;
} else {
$key = $tabIndex[$item->siren];
$triSource = array(
2011-04-20 07:26:17 +00:00
'email' => $item->email,
'ref' => $item->ref,
'dateAjout' => $item->dateAjout,
'dateDerEnvoi'=> $item->dateDerEnvoi,
);
if ( array_key_exists( $item->source, $listTrier[$key]['sources'] ) ){
$nbSource = count($listTrier[$key]['sources'][$item->source]);
}else{
$nbSource = 0;
}
$listTrier[$key]['sources'][$item->source][$nbSource] = $triSource;
2011-04-20 07:26:17 +00:00
}
$i++;
}
}
} else {
2011-09-09 14:54:05 +00:00
$permSource = array();
$permSource[] = $source;
2011-04-20 07:26:17 +00:00
$listTrier = array();
if (count($surveillances)>0) {
foreach ($surveillances as $item) {
2011-09-09 14:54:05 +00:00
$data = array();
$data['sources'][$item->source][0] = array(
'email' => $item->email,
'ref' => $item->ref,
'dateAjout' => $item->dateAjout,
'dateDerEnvoi' => $item->dateDerEnvoi,
);
$data['email'] = $item->email;
$data['siren'] = $item->siren;
$data['nic'] = $item->nic;
$data['ref'] = $item->ref;
$data['dateAjout'] = $item->dateAjout;
$data['encoursClient'] = $item->encoursClient;
$data['rs'] = $item->rs;
$data['cp'] = $item->cp;
$data['ville'] = $item->ville;
$data['dateDerEnvoi'] = $item->dateDerEnvoi;
$listTrier[] = $data;
2011-04-20 07:26:17 +00:00
}
}
}
2011-09-09 14:54:05 +00:00
Zend_Registry::get('firebug')->info($listTrier);
2011-04-20 07:26:17 +00:00
//Calcul pagination
$nbReponses = $infos->nbReponses;
$nbSurveillances = $infos->nbReponsesTotal;
$totPage = ceil($nbSurveillances/$nbAffichage);
$curPage = ceil($position/$nbAffichage);
$this->view->assign('source', $source);
2011-04-20 07:26:17 +00:00
$this->view->assign('selectTri', $selectTri);
$this->view->assign('listSources', $permSource);
$this->view->assign('nbReponses', $nbReponses);
$this->view->assign('nbSurveillances', $nbSurveillances);
$this->view->assign('totPage', $totPage);
$this->view->assign('curPage', $curPage);
$this->view->assign('surveillances',$listTrier);
$this->view->assign('source', $source);
}
2011-04-20 13:41:43 +00:00
/**
* Liste les surveillances Scores
*/
2011-04-19 09:07:57 +00:00
public function portefeuilleAction()
{
2011-08-22 16:02:17 +00:00
$user = new Utilisateur();
if(!$user->checkPerm('portefeuille')){
$this->_forward('perm', 'error');
}
2011-04-20 07:26:17 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/surveillance.css', 'all');
$this->view->headScript()
->appendFile('/themes/default/scripts/jquery.qtip.js', 'text/javascript')
->appendFile('/themes/default/scripts/jquery.tablesorter.js', 'text/javascript')
->appendFile('/themes/default/scripts/surveillance.js', 'text/javascript')
2011-04-20 07:26:17 +00:00
->appendFile('/themes/default/scripts/portefeuille.js', 'text/javascript');
$request = $this->getRequest();
$page = $request->getParam('page', 0);
$tri = $request->getParam('tri', 'siren');
$nbAffichage = 100;
$position = $page*$nbAffichage;
switch ( $tri ){
default:
case 'siren': $triws = 'siren'; break;
case 'rs': $triws = 'rs'; break;
case 'reference': $triws = 'ref'; break;
case 'dateajout': $triws = 'dateAjout'; break;
case 'datederenvoi': $triws = 'dateDerEnvoi'; break;
case 'score' : $triws = 'indiScore'; break;
}
$user = new Utilisateur();
$maxIndiscore = $user->getTypeScore();
$typeScore = ($maxIndiscore == '100') ? '' : '20';
$dicoSource = array(
'ajout' => '',
'bilans1' => 'publication bilan',
'bilans2' => 'publication bilan',
'bodacc' => 'publication bodacc',
'collecte' => 'publication légale',
'dirigeants' => 'modification de l\'administration',
'insee' => 'modification identitaire',
'liens' => 'mise à jour de la structure du groupe',
'default' => 'modification identitaire',
);
$couleurRisque100 = array(
'rouge' => array('min'=>0, 'max'=>40),
'orange' => array('min'=>41, 'max'=>50),
'vert' => array('min'=>51, 'max'=>100),
);
$couleurRisque20 = array(
'rouge' => array('min'=>0, 'max'=>6),
'orange' => array('min'=>7, 'max'=>10),
'vert' => array('min'=>11, 'max'=>20),
);
2011-04-20 13:41:43 +00:00
2011-04-19 09:07:57 +00:00
$ws = new WsScores();
$filtre = new stdClass();
2011-04-20 07:26:17 +00:00
$filtre->tri = $triws;
2011-04-19 09:07:57 +00:00
$filtre->siret = '';
$filtre->ref = '';
$filtre->rs = '';
2011-04-20 07:26:17 +00:00
$infos = $ws->getPortefeuille($filtre, $position, $nbAffichage);
$portefeuille = $infos->result->item;
$tabResult = array();
if ( count($portefeuille)>0 ) {
foreach ( $portefeuille as $item ) {
$result = new stdClass();
$result = $item;
//Classe de risque
$couleurV = ${'couleurRisque'.$maxIndiscore};
foreach($couleurV as $couleur => $intervalle)
{
if($item->{'indiScore'.$typeScore}>=$intervalle['min'] &&
$item->{'indiScore'.$typeScore}<=$intervalle['max']){
break;
}
}
$indiScore = $item->{'indiScore'.$typeScore};
$indiScorePre = empty($item->{'indiScore'.$typeScore.'Pre'}) ?
0 : $item->{'indiScore'.$typeScore.'Pre'};
//Variation du risque
$variation = abs($item->indiScore-$item->indiScorePre);
if($variation>=5 && $variation<=9){
$deg = '45';
}else{
$deg = '';
}
//Tooltip
$tooltip = '';
if($item->procol=='P'){
$tooltip.= 'En procédure collective.<br/>';
}
if($item->actif==0){
$tooltip.= '&Eacute;tablissement inactif.<br/>';
}
$tooltip.= '- Dernier exercice pris en compte : ';
if ($item->dateBilan=='0000-00-00') {
$tooltip.= 'Néant';
} else {
2011-05-04 13:17:01 +00:00
$tooltip.= 'le '.WDate::dateT('Y-m-d', 'd/m/Y',$item->dateBilan);
2011-04-20 07:26:17 +00:00
}
$tooltip.= '<br/>';
if ($item->sourceModif!='ajout') {
if (!empty($item->sourceModif)) {
$tooltip.= '- Dernière modification ';
if( $item->indiScoreDate=='0000-00-00') {
$tooltip.= '';
} else {
//$tooltip.= 'le '.WDate::dateT('Y-m-d', 'd/m/Y',$item->indiScoreDate);
}
if (!empty($item->sourceModif)) {
if (in_array($item->sourceModif, $dicoSource)) {
$sourceModif = $item->sourceModif;
} else {
$sourceModif = 'default';
}
$tooltip.= ', suite à '.$dicoSource[$sourceModif];
}
$tooltip.= '<br/>';
}
if ($item->indiScoreDatePre!='0000-00-00') {
$tooltip.= '- Précédent score : '.$indiScorePre.'/'.$maxIndiscore;
}
}
$result->tooltip = $tooltip;
//Affichage score
$colScore = '';
if( $item->indiScoreDate!='0000-00-00' &&
$item->procol!='P' && $item->actif!=0)
{
$colScore.= '<span>'.$indiScore.'/'.$maxIndiscore.'</span>';
//Procols
if ($item->procol=='P') {
$colScore.= '<img src="/themes/default/images/portefeuille/score_alert.gif"/>';
//Constant
} elseif($indiScore==$indiScorePre || $item->sourceModif=='ajout') {
$colScore.= '<img src="/themes/default/images/portefeuille/score_'.$couleur.'constant.gif"/>';
//Hausse
} elseif($indiScore>$indiScorePre) {
$colScore.= '<img src="/themes/default/images/portefeuille/score_'.$couleur.'hausse'.$deg.'.gif"/>';
//Baisse
}elseif($indiScore<$indiScorePre){
$colScore.= '<img src="/themes/default/images/portefeuille/score_'.$couleur.'baisse'.$deg.'.gif"/>';
}
} else {
if ($item->procol=='P') {
$colScore.= '<img src="/themes/default/images/portefeuille/score_alert.gif"/>';
} else {
$colScore.= '-';
}
}
$result->colScore = $colScore;
$tabResult[] = $result;
}
}
//Calcul pagination
$nbReponses = $infos->nbReponses;
$nbSurveillances = $infos->nbReponsesTotal;
$totPage = ceil($nbSurveillances/$nbAffichage);
$curPage = ceil($position/$nbAffichage)+1;
2011-05-04 13:17:01 +00:00
2011-04-20 07:26:17 +00:00
$this->view->assign('nbReponses', $nbReponses);
$this->view->assign('nbSurveillances', $nbSurveillances);
$this->view->assign('totPage', $totPage);
$this->view->assign('curPage', $curPage);
$this->view->assign('portefeuille',$tabResult);
}
2011-08-19 20:28:30 +00:00
/**
* Affiche le lien pour exporter le portefeuille au format csv
*/
public function portefeuillecsvAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/portefeuillecsv.js', 'text/javascript');
}
2011-08-19 20:28:30 +00:00
/**
* Affiche le lien pour exporter les surveillances au format csv
*/
public function surveillancecsvAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/surveillancecsv.js', 'text/javascript');
$user = new Utilisateur();
$request = $this->getRequest();
$source = $request->getParam('source');
$tabSource = array();
foreach ($this->sourceDroit as $s => $perm) {
if ($user->checkPerm($perm)) {
$tabSource[] = array(
'value' => $s,
'name' => $this->sourceTxt[$s],
'select' => (!empty($source) && $source==$s) ? ' selected' : '',
);
}
}
$this->view->assign('tabSource', $tabSource);
}
2011-08-19 20:28:30 +00:00
/**
* Affichage des surveillances par fichier pour les clients
*/
2011-05-24 06:25:58 +00:00
public function fichierAction()
{
2011-08-09 15:40:02 +00:00
$request = $this->getRequest();
$user = new Utilisateur();
2011-05-24 06:25:58 +00:00
2011-08-09 15:40:02 +00:00
$client = new SoapClient(null, array(
'trace' => 1,
'soap_version' => SOAP_1_1,
'location' => 'http://78.31.45.206/ws2/',
'uri' => 'http://78.31.45.206/',
'login' => $user->getLogin(),
'password' => $user->getPassword()
));
$nomFic = $request->getParam('nomFic', '');
//Lister les fichiers
if (empty($nomFic)){
$ref = $user->getPrenom();
if ( strtolower($user->getLogin())=='cnasea95'
|| strtolower($user->getLogin())=='cnasea96'
|| strtolower($user->getLogin())=='omni04'
|| $user->getIdClient()==32
|| $user->getIdClient==82) {
$ref='*';
}
try {
$O = $client->getListeFichierSurv($user->getLogin(), $ref, $nomFic);
$tabFichier = $O['results'];
} catch (SoapFault $fault) {}
$listeFichier = array();
foreach($tabFichier as $fichier){
$tabTmp = explode('_', $nomFic);
$date = Wdate::dateT('Ymd','d/m/Y', substr($tabTmp[2],0,8));
$localfile = APPLICATION_PATH.'/../cache/survliste/'.$fichier;
$dejaLu = false;
if (!file_exists($localfile)) {
$dejaLu = true;
}
$result = array(
'fichier' => $fichier,
'date' => $date,
'dejaLu' => $dejaLu,
);
$listeFichier[] = $result;
}
$this->view->assign('listeFichier', $listeFichier);
}
//Lister les annonces
else {
$filtre = $request->getParam('filtre', '');
if (!empty($filtre)) {
switch (trim(strtolower($filtre))) {
case 'procol': $filtre = 'procol'; break;
case 'mmd': $filtre = 'mmd'; break;
case 'radiations': $filtre = 'radiations'; break;
case 'ventes': $filtre = 'ventes'; break;
case 'comptes': $filtre = 'comptes'; break;
case 'creations': $filtre = 'creations'; break;
case 'bodacc': $filtre = 'bodacc'; break;
default: $filtre = ''; break;
}
}
//Récupération du fichier
$file = APPLICATION_PATH.'/../cache/survliste/'.$nomFic;
$file2 = $file.'.bz2';
if (!file_exists($file) || filesize($file)==0 ) {
//Génération du fichier
try {
$O = $client->getListeFichierSurv($user->getLogin(), $user->getPrenom(), $nomFic);
} catch (SoapFault $fault) {}
require_once 'common/curl.php';
$page = getUrl('http://78.31.45.206/csv/'.$nomFic.'.bz2', '', '', '', false);
$body = $page['body'];
$fp=@fopen($file2, 'w');
@fwrite($fp, $body);
@fclose($fp);
$bz = bzopen($file2, "r") or die("Impossible d'ouvrir le fichier $file");
$fp=@fopen($file, 'w');
while (!feof($bz)) {
@fwrite($fp, bzread($bz, 4096));
}
bzclose($bz);
}
$tab = array();
$row = 0;
$count = 0;
$handle = fopen($file, "r");
while (($ann = fgetcsv($handle, 3000, ';')) !== FALSE)
{
$row++;
if ($row==1)
{
// Ligne d'entête, on repère les colonnes
$num = count($ann);
for ($i=0; $i<$num; $i++)
{
if (utf8_encode($ann[$i])=='SITE_CNASEA') $colSiteCnasea=$i;
elseif(utf8_encode($ann[$i])=='Siren') $colSiren=$i;
elseif(utf8_encode($ann[$i])=='Nic') $colNic=$i;
elseif(utf8_encode($ann[$i])=='Référence') $colRef=$i;
elseif(utf8_encode($ann[$i])=='Parution') $colParution=$i;
elseif(utf8_encode($ann[$i])=='Bodacc') $colBodacc=$i;
elseif(utf8_encode($ann[$i])=='Date parution') $colDatePar=$i;
elseif(utf8_encode($ann[$i])=='Numéro Annonce') $colNumAnn=$i;
elseif(utf8_encode($ann[$i])=='Type Annonce') $colTypeAnn=$i;
elseif(utf8_encode($ann[$i])=='Tribunal') $colTribunal=$i;
elseif(utf8_encode($ann[$i])=='Numéro RCS') $colNumRCS=$i;
elseif(utf8_encode($ann[$i])=='Raison sociale') $colRaisonSociale=$i;
elseif(utf8_encode($ann[$i])=='Chapitre') $colChapitre=$i;
elseif(utf8_encode($ann[$i])=='Evènement(s)') $colEven=$i;
elseif(utf8_encode($ann[$i])=='Texte Annonce') $colTexteAnn=$i;
elseif(utf8_encode($ann[$i])=='Date évènement') $colDateEven=$i;
}
}
elseif ($filtre!='' && $filtre!='bodacc' && $ann[$colChapitre]!=$filtre )
{
//On fait rien
}
else
{
//$filtre=='bodacc'
if( substr($user->getLogin(),0,6)=='cnasea' && $ann[$colBodacc]!='A' && $ann[$colBodacc]!='B' && $ann[$colBodacc]!='C' )
{
//on supprime toutes les annonces pas bodacc
}
else
{
$tab[$count]['RaisonSociale'] = utf8_encode($ann[$colRaisonSociale]);
$tab[$count]['Siren'] = utf8_encode($ann[$colSiren]);
$tab[$count]['SiteCnasea'] = utf8_encode($ann[$colSiteCnasea]);
$tab[$count]['Ref'] = utf8_encode($ann[$colRef]);
$tab[$count]['Parution'] = utf8_encode($ann[$colParution]);
$tab[$count]['Bodacc'] = utf8_encode($ann[$colBodacc]);
$tab[$count]['DatePar'] = WDate::dateT('Ymd','d/m/Y',$ann[$colDatePar]);
$tab[$count]['Tribunal'] = utf8_encode($ann[$colTribunal]);
$tab[$count]['Even'] = utf8_encode(str_replace(', ','<br/>',$ann[$colEven]));
$tab[$count]['TexteAnn'] = utf8_encode($ann[$colTexteAnn]);
$count++;
}
}
}
fclose($handle);
$this->view->assign('annonces', $tab);
$this->view->assign('filtre', $filtre);
$this->view->assign('nomFic', $nomFic);
$this->renderScript('surveillance/fichier-ann.phtml');
}
2011-05-24 06:25:58 +00:00
}
2011-08-09 15:40:02 +00:00
2011-08-19 20:28:30 +00:00
/**
* Export surveillance en fichier pdf
*/
2011-08-09 15:40:02 +00:00
public function fichierpdfAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$user = new Utilisateur();
$client = new SoapClient(null, array(
'trace' => 1,
'soap_version' => SOAP_1_1,
'location' => 'http://78.31.45.206/ws2/',
'uri' => 'http://78.31.45.206/',
'login' => $user->getLogin(),
'password' => $user->getPassword()
));
$nomFic = $request->getParam('q', '');
$filtre = $request->getParam('filtre', '');
if (!empty($filtre)){
switch (trim(strtolower($filtre))) {
case 'procol': $filtre = 'procol'; break;
case 'mmd': $filtre = 'mmd'; break;
case 'radiations': $filtre = 'radiations'; break;
case 'ventes': $filtre = 'ventes'; break;
case 'comptes': $filtre = 'comptes'; break;
case 'creations': $filtre = 'creations'; break;
case 'bodacc': $filtre = 'bodacc'; break;
default: $filtre = ''; break;
}
}
//Récupération du fichier
$file = APPLICATION_PATH.'/../cache/survliste/'.$nomFic;
$file2 = $file.'.bz2';
if (!file_exists($file) || filesize($file)==0 ) {
//Génération du fichier
try {
$O = $client->getListeFichierSurv($user->getLogin(), $user->getPrenom(), $nomFic);
} catch (SoapFault $fault) {
}
require_once 'common/curl.php';
$page = getUrl('http://78.31.45.206/csv/'.$nomFic.'.bz2', '', '', '', false);
$body = $page['body'];
$fp=@fopen($file2, 'w');
@fwrite($fp, $body);
@fclose($fp);
$bz = bzopen($file2, "r") or die("Impossible d'ouvrir le fichier $file");
$fp=@fopen($file, 'w');
while (!feof($bz)) {
@fwrite($fp, bzread($bz, 4096));
}
bzclose($bz);
}
$tab = array();
$row = 0;
$count = 0;
$handle = fopen($file, "r");
while (($ann = fgetcsv($handle, 3000, ';')) !== FALSE)
{
$row++;
if ($row==1)
{
// Ligne d'entête, on repère les colonnes
$num = count($ann);
for ($i=0; $i<$num; $i++)
{
if (utf8_encode($ann[$i])=='SITE_CNASEA') $colSiteCnasea=$i;
elseif(utf8_encode($ann[$i])=='Siren') $colSiren=$i;
elseif(utf8_encode($ann[$i])=='Nic') $colNic=$i;
elseif(utf8_encode($ann[$i])=='Référence') $colRef=$i;
elseif(utf8_encode($ann[$i])=='Parution') $colParution=$i;
elseif(utf8_encode($ann[$i])=='Bodacc') $colBodacc=$i;
elseif(utf8_encode($ann[$i])=='Date parution') $colDatePar=$i;
elseif(utf8_encode($ann[$i])=='Numéro Annonce') $colNumAnn=$i;
elseif(utf8_encode($ann[$i])=='Type Annonce') $colTypeAnn=$i;
elseif(utf8_encode($ann[$i])=='Tribunal') $colTribunal=$i;
elseif(utf8_encode($ann[$i])=='Numéro RCS') $colNumRCS=$i;
elseif(utf8_encode($ann[$i])=='Raison sociale') $colRaisonSociale=$i;
elseif(utf8_encode($ann[$i])=='Chapitre') $colChapitre=$i;
elseif(utf8_encode($ann[$i])=='Evènement(s)') $colEven=$i;
elseif(utf8_encode($ann[$i])=='Texte Annonce') $colTexteAnn=$i;
elseif(utf8_encode($ann[$i])=='Date évènement') $colDateEven=$i;
}
}
elseif ($filtre!='' && $filtre!='bodacc' && $ann[$colChapitre]!=$filtre )
{
//On fait rien
}
else
{
//$filtre=='bodacc'
if( substr($user->getLogin(),0,6)=='cnasea' && $ann[$colBodacc]!='A' && $ann[$colBodacc]!='B' && $ann[$colBodacc]!='C' )
{
//on supprime toutes les annonces pas bodacc
}
else
{
$tab[$count]['RaisonSociale'] = utf8_encode($ann[$colRaisonSociale]);
$tab[$count]['Siren'] = utf8_encode($ann[$colSiren]);
$tab[$count]['SiteCnasea'] = utf8_encode($ann[$colSiteCnasea]);
$tab[$count]['Ref'] = utf8_encode($ann[$colRef]);
$tab[$count]['Parution'] = utf8_encode($ann[$colParution]);
$tab[$count]['Bodacc'] = utf8_encode($ann[$colBodacc]);
$tab[$count]['DatePar'] = WDate::dateT('Ymd','d/m/Y',$ann[$colDatePar]);
$tab[$count]['Tribunal'] = utf8_encode($ann[$colTribunal]);
$tab[$count]['Even'] = utf8_encode(str_replace(', ','<br/>',$ann[$colEven]));
$tab[$count]['TexteAnn'] = utf8_encode($ann[$colTexteAnn]);
$count++;
}
}
}
fclose($handle);
$page = $request->getParam('page', '');
$nbAnnoncesMin = ($page-1)*100;
$nbAnnoncesMax = $nbAnnoncesMin+100;
$output = '';
$count = 0;
$annonces = $tab;
$nbAnnonces = count($annonces);
if($nbAnnonces>0){
foreach($annonces as $annonce){
if($count>$nbAnnoncesMax) break;
if($count>=$nbAnnoncesMin)
{
$output.= '<page backtop="10mm" backbottom="10mm">';
$output.= '<page_header>';
$output.= '<table style="width:100%; border:solid 1px black;">';
$output.= '<tr>';
$output.= '<td style="text-align:left; width:67%">Surveillance : '.$count.'/'.$nbAnnonces.'</td>';
$output.= '<td style="text-align:right; width:33%">'.date('d/m/Y').'</td>';
$output.= '</tr>';
$output.= '</table>';
$output.= '</page_header>';
$output.= '<table style="width:100%;">';
$output.= '<tr>';
$output.= '<td style="width:50%;">Entreprise : '.$annonce['RaisonSociale'].' ('.$annonce['Siren'].')</td>';
$output.= '<td style="width:50%;">&nbsp;</td>';
$output.= '</tr>';
$output.= '<tr>';
$output.= '<td style="width:50%;">Site : '.$annonce['SiteCnasea'].'</td>';
$output.= '<td style="width:50%;">Référence : '.$annonce['Ref'].'</td>';
$output.= '</tr>';
$output.= '<tr>';
if ($annonce['Bodacc']=='A' || $annonce['Bodacc']=='B' || $annonce['Bodacc']=='C')
{
$source = 'BODACC n&deg;'.$annonce['Parution'].'&nbsp;'.$annonce['Bodacc'].' du '.$annonce['DatePar'].' '.$annonce['Tribunal'].'.';
}
elseif ($annonce['Bodacc']=='G')
{
$source = 'GREFFE du '.$annonce['Tribunal'].' au '.$annonce['DatePar'].'.';
}
elseif ($annonce['Bodacc']=='P')
{
$source = 'RNCS du '.$annonce['Tribunal'].' au '.$annonce['DatePar'].'.';
}
else
{
$source = 'Collecte SD du '.$annonce['Tribunal'].' au '.$annonce['DatePar'].'.';
}
$output.= '<td style="width:100%;" colspan="2">'.$source.'</td>';
$output.= '</tr>';
$output.= '<tr><td style="width:100%;" colspan="2">&nbsp;</td></tr>';
$output.= '<tr>';
$output.= '<td style="width:100%;" colspan="2"><b>'.$annonce['Even'].'</b></td>';
$output.= '</tr>';
$output.= '<tr>';
$output.= '<td style="width:100%;" colspan="2">'.$annonce['TexteAnn'].'</td>';
$output.= '</tr>';
$output.= '</table>';
$output.= '</page>';
}
$count++;
}
}else{
/*
* Fermeture de la balise page lorsqu'il n'y a aucune annonce
* afin de générer un fichier pdf vide et non pas une erreur
*/
$output = '</page>';
}
// conversion HTML => PDF
require_once 'Vendors/html2pdf/html2pdf.class.php';
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML(utf8_decode($output));
$html2pdf->Output(str_replace('.csv', '.pdf', $nomFic), 'D');
}
2011-08-19 20:28:30 +00:00
}