extranet/application/controllers/SurveillanceController.php

523 lines
15 KiB
PHP
Raw Normal View History

2011-02-21 08:45:13 +00:00
<?php
class SurveillanceController extends Zend_Controller_Action
{
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',
);
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-05-04 13:17:01 +00:00
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('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();
$request = $this->getRequest();
$params = $request->getParams();
}
/**
* Récupére le fichier d'extraction des surveillances
*/
public function listecsvAction(){}
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');
$user = new Utilisateur();
//if ($user->checkPref())
//if ($user->checkPerm())
$listSurv = array();
$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,
2011-05-04 13:17:01 +00:00
'sourceTexte' => $this->sourceTxt[$surv->source]
2011-04-20 13:41:43 +00:00
);
}
} else {
$titre = 'Ajouter une surveillance';
$texte = 'Mettre sous surveillance';
}
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-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.qtip.js', 'text/javascript')
->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 {
$listTrier = array();
if (count($surveillances)>0) {
foreach ($surveillances as $item) {
$listTrier[]['source'] = $item->source;
$listTrier[]['email'] = $item->email;
$listTrier[]['siren'] = $item->siren;
$listTrier[]['nic'] = $item->nic;
$listTrier[]['ref'] = $item->ref;
$listTrier[]['dateAjout'] = $item->dateAjout;
$listTrier[]['encoursClient'] = $item->encoursClient;
$listTrier[]['rs'] = $item->rs;
$listTrier[]['cp'] = $item->cp;
$listTrier[]['ville'] = $item->ville;
$listTrier[]['dateDerEnvoi'] = $item->dateDerEnvoi;
}
}
}
//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-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/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-02-21 08:45:13 +00:00
}