2011-04-19 07:37:39 +00:00
< ? php
class EvaluationController extends Zend_Controller_Action
{
2011-05-20 09:06:34 +00:00
protected $siret = null ;
protected $id = 0 ;
2011-04-19 07:37:39 +00:00
public function init ()
{
2011-05-20 09:06:34 +00:00
$request = $this -> getRequest ();
$this -> siret = $request -> getParam ( 'siret' );
$this -> id = $request -> getParam ( 'id' , 0 );
2011-06-03 08:52:01 +00:00
require_once 'common/dates.php' ;
2011-05-20 09:06:34 +00:00
require_once 'Scores/WsScores.php' ;
require_once 'Scores/Utilisateur.php' ;
require_once 'Scores/SessionEntreprise.php' ;
2011-06-07 15:01:03 +00:00
require_once 'Scores/IdentiteEntreprise.php' ;
2011-07-06 06:49:05 +00:00
require_once 'Finance/RatiosData.php' ;
2011-05-24 16:03:25 +00:00
$this -> view -> headLink ()
-> appendStylesheet ( '/themes/default/styles/evaluation.css' , 'all' );
2011-04-19 07:37:39 +00:00
}
2011-05-19 15:24:35 +00:00
2011-08-24 15:27:22 +00:00
public function indexAction ()
{
$this -> _forward ( 'entreprise' , 'recherche' );
}
2011-09-05 13:34:33 +00:00
/**
* Affichage d ' une reglette représentant le score
*/
2011-05-26 15:56:16 +00:00
public function printscoresAction ()
{
$this -> _helper -> layout () -> disableLayout ();
$request = $this -> getRequest ();
$score = strtolower ( $request -> getParam ( 'score' ));
2011-06-07 15:01:03 +00:00
if ( $score == 'indiscore' ){
$user = new Utilisateur ();
switch ( $user -> getTypeScore ()) {
case '20' : $score .= '20' ; break ;
case '100' :
default : $score .= '100' ; break ;
}
}
2011-05-26 15:56:16 +00:00
$note = $request -> getParam ( 'note' );
2011-06-07 15:01:03 +00:00
$bornes = array (
'conanh' => array ( 'min' => - 4.5 , 'max' => 16 ),
'afdcc2' => array ( 'min' => 0 , 'max' => 5 ),
'afdcc1' => array ( 'min' => - 10 , 'max' => 10 ),
'z' => array ( 'min' => - 3 , 'max' => 3 ),
'indiscore100' => array ( 'min' => 0 , 'max' => 100 ),
'indiscore20' => array ( 'min' => 0 , 'max' => 20 ),
2011-05-26 15:56:16 +00:00
);
$note = round (( $note - $bornes [ $score ][ 'min' ]) * 100 / ( $bornes [ $score ][ 'max' ] - $bornes [ $score ][ 'min' ]));
if ( $note < 0 ) $note = 0 ;
if ( $note > 100 ) $note = 100 ;
$this -> view -> assign ( 'note' , $note );
$this -> view -> assign ( 'min' , $bornes [ $score ][ 'min' ]);
$this -> view -> assign ( 'max' , $bornes [ $score ][ 'max' ]);
}
2011-05-19 15:24:35 +00:00
/**
* IndiScore
*/
2011-05-24 16:03:25 +00:00
public function indiscoreAction ()
{
2011-06-15 13:16:39 +00:00
$user = new Utilisateur ();
2011-07-05 15:57:05 +00:00
2011-06-15 13:16:39 +00:00
if ( ! $user -> checkPerm ( 'INDISCORE' ))
$this -> _forward ( 'perms' , 'error' );
2011-07-05 15:57:05 +00:00
$request = $this -> getRequest ();
$autrePage = $request -> getParam ( 'apage' );
//Récupération des informations
if ( empty ( $autrePage )) {
2011-10-18 08:21:26 +00:00
$plus = false ;
if ( $user -> checkPerm ( 'indiscorep' )){
$plus = true ;
}
$ref = $request -> getParam ( 'ref' , '' );
$encours = $request -> getParam ( 'encours' , 0 );
$email = $request -> getParam ( 'email' , '' );
$ws = new WsScores ();
2012-01-23 13:17:39 +00:00
$infos = $ws -> getIndiScore ( substr ( $this -> siret , 0 , 9 ), 0 , 1 , $plus , $ref , $encours , $email );
2011-08-24 15:27:22 +00:00
if ( $infos === false ) $this -> _forward ( 'soap' , 'error' );
2011-07-05 15:57:05 +00:00
} else {
$infos = $this -> getRequest () -> getParam ( 'infos' );
}
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'siret' , $this -> siret );
2011-05-24 16:03:25 +00:00
$this -> view -> assign ( 'typeScore' , $user -> getTypeScore ());
2011-07-05 15:57:05 +00:00
$this -> view -> assign ( 'indiscore' , $infos );
$this -> view -> assign ( 'AutrePage' , $autrePage );
2011-09-05 13:34:33 +00:00
$this -> view -> assign ( 'exportObjet' , $infos );
2011-05-24 16:03:25 +00:00
}
2011-06-22 15:31:04 +00:00
2011-05-19 15:24:35 +00:00
/**
* Rapport de synthese
*/
2011-05-24 16:03:25 +00:00
public function indiscore2Action ()
{
2011-06-07 15:01:03 +00:00
$this -> view -> headScript () -> appendFile ( '/themes/default/scripts/finance.js' , 'text/javascript' );
2011-06-22 15:31:04 +00:00
2011-07-06 06:49:05 +00:00
$user = new Utilisateur ();
2011-06-15 13:16:39 +00:00
if ( ! $user -> checkPerm ( 'INDISCORE2' ))
$this -> _forward ( 'perms' , 'error' );
2011-06-22 15:31:04 +00:00
2011-07-06 06:49:05 +00:00
$siren = substr ( $this -> siret , 0 , 9 );
2011-06-22 15:31:04 +00:00
$ws = new WsScores ();
2011-10-26 10:34:32 +00:00
$entreprise = new SessionEntreprise ( $this -> siret , $this -> id );
2011-07-06 06:49:05 +00:00
$identite = $ws -> getIdentite ( $siren );
2011-06-22 15:31:04 +00:00
$indiscore = $ws -> getIndiScore ( $siren );
2011-07-06 06:49:05 +00:00
$infos = $ws -> getRatios ( $siren , 'indiscore2' ); // @todo : vérifier la page
$score = array ();
$tabRatio = array (
2011-06-07 15:01:03 +00:00
'r5' => array ( 'total' => 'r5' , 'total_info' => '% ca' , 'op' => 1000 , 'titre' => 'CHIFFRE D\'AFFAIRES' ),
'r16' => array ( 'total' => 'r5' , 'total_info' => '% ca' , 'op' => 1000 , 'titre' => 'RESULTAT D\'EXPLOITATION' ),
'r7' => array ( 'total' => 'r5' , 'total_info' => '% ca' , 'op' => 1000 , 'titre' => 'RESULTAT COURANT' ),
'r10' => array ( 'total' => 'r5' , 'total_info' => '% ca' , 'op' => 1000 , 'titre' => 'RESULTAT NET' ),
'r18' => array ( 'total' => 'r22' , 'total_info' => '% bilan' , 'op' => 1000 , 'titre' => 'FONDS PROPRES' ),
'r231' => array ( 'total' => 'r22' , 'total_info' => '% bilan' , 'op' => 1000 , 'titre' => 'FONDS DE ROULEMENT' ),
'r232' => array ( 'total' => 'r22' , 'total_info' => '% bilan' , 'op' => 1000 , 'titre' => 'BESOIN EN FONDS DE ROULEMENT' ),
'r249' => array ( 'total' => '' , 'total_info' => '' , 'op' => 1000 , 'titre' => 'TRESORERIE NETTE' ),
'r20' => array ( 'total' => 'r5' , 'total_info' => '% ca' , 'op' => 1000 , 'titre' => 'FRAIS FINANCIER' ),
2011-05-26 15:56:16 +00:00
);
2011-07-06 06:49:05 +00:00
//Formattage des données
$typeBilan = 'N' ;
$ratiosData = new RatiosData ( $infos );
$nbBilanN = $ratiosData -> getNbBilan ( 'N' );
if ( $nbBilanN != 0 )
{
foreach ( $tabRatio as $idRatio => $valRatio ){
$tabRatio [ $idRatio ][ 'comment' ] = $ratiosData -> wrapComment ( $idRatio );
}
$this -> view -> assign ( 'tabRatio' , $tabRatio );
2011-07-11 13:26:18 +00:00
$infosAnnee = $ratiosData -> getBilansInfo ( $typeBilan );
2011-07-06 06:49:05 +00:00
$annees = array_keys ( $infosAnnee );
//On prend les 3 derniers bilans pour l'affichage
$nbMaxBilan = 3 ;
rsort ( $annees );
$annees = array_slice ( $annees , 0 , $nbMaxBilan );
sort ( $annees );
$tabResult = array ();
foreach ( $annees as $annee ){
$data = array ();
$dataEvol = array ();
//Formatter les données
foreach ( $tabRatio as $idRatio => $valRatio ){
$data [ $idRatio ] = $ratiosData -> dRatio ( $typeBilan , $annee , $idRatio );
$dataTotal [ $idRatio ] = $ratiosData -> dTotal ( $typeBilan , $annee , $idRatio , $valRatio [ 'total' ]);
$dInfo [ $idRatio ] = $valRatio [ 'total_info' ];
}
$tabResult [] = array (
'dateCloture' => WDate :: dateT ( 'Ymd' , 'd/m/Y' , $annee ),
'duree' => $infosAnnee [ $annee ] -> duree . ' Mois' ,
'ratio' => $data ,
'total' => $dataTotal ,
'info' => $dInfo ,
);
}
$this -> view -> assign ( 'tabResult' , $tabResult );
}
2011-06-07 15:01:03 +00:00
2011-07-06 06:49:05 +00:00
$this -> view -> assign ( 'tabRatio' , $tabRatio );
2011-06-07 16:15:53 +00:00
/*
2011-07-06 06:49:05 +00:00
Correction pour indiscore seule
2011-06-07 16:15:53 +00:00
$indiscore -> Siege ;
$indiscore -> SiretSiege ;
$indiscore -> NumRC ;
*/
2011-07-08 09:25:38 +00:00
$identite = new IdentiteEntreprise ( $identite );
2011-06-07 15:01:03 +00:00
//Définition des blocks
$blocks = array (
'SiretSiege' ,
'NumRC' ,
'Actif' ,
'RaisonSociale' ,
'FormeJuridique' ,
'DateImmat' ,
'DateCreaEt' ,
'Adresse' ,
'ActiviteEn' ,
'Naf4' ,
'OrigineFond' ,
'TypeExploitation' ,
'Saisonnalite' ,
'Capital' ,
'ChiffreAffaire' ,
);
$dBlock = array ();
foreach ( $blocks as $item ) {
$display = array (
'label' => method_exists ( $identite , 'get' . $item . 'Label' ) ? $identite -> { 'get' . $item . 'Label' }() : '' ,
'texte' => method_exists ( $identite , 'get' . $item . 'Texte' ) ? $identite -> { 'get' . $item . 'Texte' }() : '' ,
'titre' => method_exists ( $identite , 'get' . $item . 'Titre' ) ? $identite -> { 'get' . $item . 'Titre' }() : '' ,
);
$dBlock [ $item ] = $display ;
}
$this -> view -> assign ( 'dBlock' , $dBlock );
$dateRadiation = '' ;
2011-05-26 15:56:16 +00:00
if ( isset ( $indiscore -> DateRadiation ) && $indiscore -> DateRadiation != '' && $indiscore -> DateRadiation != '0000-00-00' )
$this -> view -> assign ( 'dateRadiation' , WDate :: dateT ( 'Ymd' , 'd/m/Y' , str_replace ( '-' , '' , $indiscore -> DateRadiation )));
foreach ( $indiscore -> scores as $name => $sc ){
if ( $name == 'ConanH' )
$score [ $name ] = array ( $sc , 'Score Conan Holder' );
if ( $name == 'Afdcc2' )
$score [ $name ] = array ( $sc , 'Score Afdcc 2' );
if ( $name == 'Z' )
$score [ $name ] = array ( $sc , 'Score Z' );
}
2011-06-07 15:01:03 +00:00
$typeScore = $user -> getTypeScore ();
switch ( $typeScore ) {
case '20' :
$maxIndiscore = $typeScore ;
$score [ 'Indiscore' ] = array ( $indiscore -> Indiscore20 , 'IndiScore' );
break ;
case '100' :
default :
$maxIndiscore = empty ( $typeScore ) ? '100' : $typeScore ;
$score [ 'Indiscore' ] = array ( $indiscore -> Indiscore , 'IndiScore' );
break ;
}
2011-05-26 15:56:16 +00:00
$score [ 'Indiscore' ] = array ( $indiscore -> Indiscore20 , 'IndiScore' );
2011-06-03 08:52:01 +00:00
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'siret' , $this -> siret );
$this -> view -> assign ( 'id' , $this -> id );
2011-06-22 15:31:04 +00:00
$this -> view -> assign ( 'siren' , $siren );
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'encours' , $indiscore -> encours );
$this -> view -> assign ( 'TendanceIndiscore' , $indiscore -> TendanceIndiscore );
$this -> view -> assign ( 'SituationJuridique' , $indiscore -> SituationJuridique );
2011-05-26 15:56:16 +00:00
$this -> view -> assign ( 'paiement' , $indiscore -> infoPaiement );
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'scores' , $score );
2011-05-26 15:56:16 +00:00
$this -> view -> assign ( 'bilanReference' , $bilanReference );
2011-05-24 16:03:25 +00:00
}
2011-05-18 10:07:45 +00:00
2011-05-19 15:24:35 +00:00
/**
* Rapport complet
*/
2011-06-03 08:52:01 +00:00
public function indiscore3Action ()
{
2011-09-02 09:44:09 +00:00
$this -> view -> headLink () -> appendStylesheet ( '/themes/default/styles/comment.css' , 'all' );
$this -> view -> headScript () -> appendFile ( '/themes/default/scripts/evaluation.js' , 'text/javascript' );
2012-01-13 11:03:05 +00:00
$user = new Utilisateur ();
2011-06-15 13:16:39 +00:00
if ( ! $user -> checkPerm ( 'INDISCORE3' ))
$this -> _forward ( 'perms' , 'error' );
2011-06-22 15:31:04 +00:00
2012-01-13 11:03:05 +00:00
// Lien pour le rapport personnalisé
if ( $user -> getIdClient () == '110' || $user -> checkModeEdition ()) {
$this -> view -> assign ( 'customRapport' , $this -> view -> url ( array (
'controller' => 'evaluation' ,
'action' => 'customindiscore3' ,
'siret' => $this -> siret ,
'id' => $this -> id )
));
}
2011-06-22 15:31:04 +00:00
$sessionEntreprise = new SessionEntreprise ( $this -> siret , $this -> id );
$ws = new WsScores ();
$siren = substr ( $this -> siret , 0 , 9 );
2011-10-18 08:21:26 +00:00
$plus = false ;
if ( $user -> checkPerm ( 'indiscore3p' )){
$plus = true ;
}
2011-12-08 12:58:03 +00:00
$request = $this -> getRequest ();
2011-10-18 08:21:26 +00:00
$ref = $request -> getParam ( 'ref' , '' );
$encours = $request -> getParam ( 'encours' , 0 );
$email = $request -> getParam ( 'email' , '' );
2011-06-07 16:15:53 +00:00
2011-10-18 08:21:26 +00:00
$infos = $ws -> getRapport ( $siren , 3 , 0 , $plus , $ref , $encours , $email );
2011-06-07 16:15:53 +00:00
2011-06-22 15:31:04 +00:00
$this -> view -> assign ( 'Identite' , $infos -> Identite );
$this -> view -> assign ( 'Dirigeants' , $infos -> Dirigeants );
$this -> view -> assign ( 'Liens' , $infos -> Liens );
$this -> view -> assign ( 'Annonces' , $infos -> Annonces );
$this -> view -> assign ( 'Ratios' , $infos -> Ratios );
$this -> view -> assign ( 'Indiscore' , $infos -> Indiscore );
2011-06-07 16:15:53 +00:00
2011-06-22 15:31:04 +00:00
require_once 'Scores/RapportComment.php' ;
$rapportComment = new RapportComment ( $siren , $this -> id , $infos -> Indiscore -> tabCommentaires -> item , $infos -> Ratios );
$this -> view -> assign ( 'comment' , $rapportComment -> out ());
2011-06-03 08:52:01 +00:00
2011-06-22 15:31:04 +00:00
$this -> view -> assign ( 'siret' , $this -> siret );
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'id' , $this -> id );
2011-06-22 15:31:04 +00:00
$this -> view -> assign ( 'siren' , $siren );
2011-06-07 15:01:03 +00:00
$this -> view -> assign ( 'raisonSociale' , $sessionEntreprise -> getRaisonSociale ());
2011-09-05 13:34:33 +00:00
$this -> view -> assign ( 'exportObjet' , $infos );
2011-06-03 08:52:01 +00:00
}
2011-05-19 15:24:35 +00:00
2011-09-05 13:34:33 +00:00
/**
* Génération de rapport personnalisé
* @ todo : à améliorer
*/
2011-09-02 09:44:09 +00:00
public function customindiscore3Action ()
{
$this -> _helper -> layout () -> disableLayout ();
$request = $this -> getRequest ();
$upload = $request -> getParam ( 'upload' , null );
$user = new Utilisateur ();
if ( empty ( $upload )){
$adresse = array ();
if ( $user -> checkModeEdition ()){
$adresse [] = 'Order to Cash' ;
$adresse [] = '70 AVENUE DE LA MARNE ' ;
$adresse [] = '92600 ASNIERES SUR SEINE' ;
$color1 = '#DFDB00' ;
$color2 = '#EFED9A' ;
2012-01-30 11:24:12 +00:00
$background = " background-image:url('/themes/default/images/customrapport/logo_ordertocash.jpg');background-repeat:no-repeat;background-position:center " ;
2011-09-02 09:44:09 +00:00
} else {
$adresse [] = 'Financement Entreprise' ;
$adresse [] = '16 RUE SENAC DE MEILHAN' ;
$adresse [] = '17000 LA ROCHELLE' ;
$color1 = '#6699FF' ;
$color2 = '##66CCFF' ;
$background = null ;
}
$this -> view -> assign ( 'adresse' , $adresse );
$this -> view -> assign ( 'color1' , $color1 );
$this -> view -> assign ( 'color2' , $color2 );
$this -> view -> assign ( 'background' , $background );
$this -> view -> assign ( 'siret' , $this -> siret );
$this -> view -> assign ( 'id' , $this -> id );
} else {
2011-09-02 10:27:31 +00:00
$this -> _helper -> viewRenderer -> setNoRender ( true );
2011-09-02 09:44:09 +00:00
$couleurh1 = $request -> getParam ( 'couleurh1' , null );
$couleurh2 = $request -> getParam ( 'couleurh2' , null );
$texth1 = $request -> getParam ( 'texth1' , null );
$texth2 = $request -> getParam ( 'texth2' , null );
$societe_name = $request -> getParam ( 'societe_name' , null );
$adresse = $request -> getParam ( 'adresse' , null );
$logo_background = $request -> getParam ( 'logo_background' , null );
$siren = substr ( $this -> siret , 0 , 9 );
2011-09-02 10:27:31 +00:00
if ( $this -> id != 0 ){
$file = 'evaluation-indiscore3-' . $this -> siret . '-' . $this -> id . '.html' ;
2011-09-02 09:44:09 +00:00
} else {
2011-09-02 10:27:31 +00:00
$file = 'evaluation-indiscore3-' . $this -> siret . '.html' ;
2011-09-02 09:44:09 +00:00
}
2011-09-02 10:27:31 +00:00
if ( file_exists ( APPLICATION_PATH . '/../cache/pages/' . $file ))
{
$doc = new DOMDocument ();
$doc -> preserveWhiteSpace = true ;
@ $doc -> loadHTMLFile ( APPLICATION_PATH . '/../cache/pages/' . $file );
//Générer style particulier pour le rapport
2012-01-30 14:11:36 +00:00
$style .= 'body { background-color:#ffffff; }' ;
2012-01-30 14:12:56 +00:00
$style .= '#customRapport { display:none; }' ;
2011-09-02 10:27:31 +00:00
$style .= '#center h1 {background-color:' . $couleurh1 . ';color:' . $texth1 . '}' ;
if ( $logo_background ) {
2012-01-30 13:51:30 +00:00
$style .= '#center {background-image:url(./themes/default/images/customrapport/logo_ordertocash.jpg);background-repeat:repeat-y}' ;
2011-09-02 10:27:31 +00:00
}
$style .= '#center h2 {background-color:' . $couleurh2 . ';color:' . $texth2 . '}' ;
$styleDom = $doc -> createElement ( 'style' , $style );
//Ajout information
$contentDom = $doc -> createElement ( 'div' );
2012-01-30 14:33:04 +00:00
if ( ! $user -> checkModeEdition ()) {
$element = $doc -> createElement ( 'img' );
2012-01-30 13:51:30 +00:00
$element -> setAttribute ( 'src' , './themes/default/images/customrapport/logo_ordertocash.jpg' );
2011-09-02 10:27:31 +00:00
$element -> setAttribute ( 'width' , '12%' );
} else {
2012-01-30 14:29:40 +00:00
$element = $doc -> createElement ( 'img' );
2012-01-30 13:51:30 +00:00
$element -> setAttribute ( 'src' , './themes/default/images/customrapport/logo_ordertocash.jpg' );
2012-01-30 14:33:04 +00:00
$element -> setAttribute ( 'width' , '12%' );
2011-09-02 10:27:31 +00:00
}
2012-01-30 14:33:04 +00:00
$div = $doc -> createElement ( 'div' );
2012-01-30 14:35:05 +00:00
$div -> setAttribute ( 'style' , " clear:both; " );
2012-01-30 14:33:04 +00:00
$div -> appendChild ( $element );
$contentDom -> appendChild ( $div );
2012-01-30 14:24:29 +00:00
2011-09-02 10:27:31 +00:00
$i = 0 ;
foreach ( $adresse as $item ){
$element = $doc -> createElement ( 'span' , $item );
$contentDom -> appendChild ( $element );
$element = $doc -> createElement ( 'br' );
$contentDom -> appendChild ( $element );
$i ++ ;
}
$element = $doc -> createElement ( 'center' , $societe_name . ' Enquête Financière' );
$element -> setAttribute ( 'style' , 'font-size:17px' );
$contentDom -> appendChild ( $element );
if ( ! $user -> checkModeEdition ()){
$element = $doc -> createElement ( 'span' , " Les équipes d'Order To Cash se tiennent à votre disposition pour vous assister dans l'interprétation de ces données au 01 47 90 94 31 ou par mail à l'adresse suivante : contact@ordertocash.fr " );
$contentDom -> appendChild ( $element );
}
$ajout = $doc -> createElement ( 'div' );
$ajout -> appendChild ( $styleDom );
$ajout -> appendChild ( $contentDom );
//Après <div id="center"> on insére le contenu
$body = $doc -> getElementsByTagName ( 'body' ) -> item ( 0 );
$div = $body -> getElementsByTagName ( 'div' );
foreach ( $div as $item ){
if ( $item -> hasAttribute ( 'id' ) && $item -> getAttribute ( 'id' ) == 'center' ){
break ;
}
}
$item -> parentNode -> insertBefore ( $ajout , $item );
$xml = $doc -> saveXML ();
$outfile = APPLICATION_PATH . '/../cache/pages/p' . $user -> getIdClient () . '-' . $file ;
file_put_contents ( $outfile , $xml );
//Génération du pdf
require_once 'wkhtmltopdf/wkhtmltopdf.php' ;
$wkhtmltopdf = new wkhtmltopdf ();
$pdfFile = $wkhtmltopdf -> exec ( $outfile );
if ( file_exists ( $pdfFile )){
echo '<center>Votre fichier est prêt pour être téléchargé !<br />' .
'<a target="_blank" href="' . $this -> view -> url (
array ( 'controller' => 'fichier' ,
'action' => 'customrapport' ,
'fichier' => basename ( $pdfFile )), null , true ) . '">Télécharger</a></center>' ;
} else {
echo " Erreur lors de la génération du PDF. " ;
}
} else {
echo " Erreur fichier non présent ! " ;
}
2011-09-02 09:44:09 +00:00
}
}
2011-05-19 15:24:35 +00:00
/**
* Enquete commerciale
2011-09-05 13:34:33 +00:00
* @ todo : Vérifier l ' enregistrement
2011-05-19 15:24:35 +00:00
*/
public function enquetecAction ()
{
2011-05-20 09:06:34 +00:00
$this -> view -> headScript () -> appendFile ( '/themes/default/scripts/enquetec.js' , 'text/javascript' );
//isset($_REQUEST['pays']) ? $pays=$_REQUEST['pays'] : $pays='' ;
$commandeEnquete = false ;
$request = $this -> getRequest ();
if ( $request -> isPost ()){
$InfoUser = $request -> getParam ( 'InfoUser' );
$InfoEnq = $request -> getParam ( 'InfoEnq' );
//Affichage de la demande
//Vérification des informations
$formError = false ;
$fields = array ();
//Info utilisateur obligatoire :
if ( $InfoUser [ 'Identite' ] == '' ){ $fields [] = 'Votre Identite' ; $formError = true ;}
if ( $InfoUser [ 'Tel' ] == '' ){ $fields [] = 'Votre Téléphone' ; $formError = true ;}
if ( $InfoUser [ 'Email' ] == '' ){ $fields [] = 'Votre Email' ; $formError = true ;}
//Info entreprise obligatoire :
if ( isset ( $InfoEnq [ 'Type' ]) && $InfoEnq [ 'Type' ] == '' ){ $fields [] = 'Choix du type d\'enquête' ; $formError = true ;}
if ( $InfoEnq [ 'PrecisionsChoix' ] == '1' ){
if ( $InfoEnq [ 'Precisions' ][ 'Motif' ] == '' ){ $fields [] = 'Mofif de la demande' ; $formError = true ;}
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == '3' || $InfoEnq [ 'PrecisionsChoix' ] == '4' ){
if ( $InfoEnq [ 'Precisions' ][ 'MontantCA' ] == '' ){ $fields [] = 'Précisions de la demande' ; $formError = true ;}
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == '5' ){
if ( $InfoEnq [ 'Precisions' ][ 'Autre' ] == '' ){ $fields [] = 'Précisions de la demande' ; $formError = true ;}
}
if ( isset ( $InfoEnq [ 'ImpayeesChoix' ]) && $InfoEnq [ 'ImpayeesChoix' ] == 'oui' ){
if ( $InfoEnq [ 'Impayees' ][ 'Montant' ] == '' || $InfoEnq [ 'Impayees' ][ 'Nombre' ] == '' || $InfoEnq [ 'Impayees' ][ 'Date' ] == '' ){ $fields [] = 'Précisions sur les impayées' ; $formError = true ;}
}
if ( isset ( $InfoEnq [ 'RetardPaiementChoix' ]) && $InfoEnq [ 'RetardPaiementChoix' ] == 'oui' ){
if ( $InfoEnq [ 'RetardPaiement' ][ 'Montant' ] == '' || $InfoEnq [ 'Nombre' ] == '' || $InfoEnq [ 'RetardPaiement' ][ 'Date' ] == '' ){ $fields [] = 'Précisions sur le retarde de paiement' ; $formError = true ;}
}
if ( isset ( $_REQUEST [ 'InfoEnq' ][ 'LitigeChoix' ]) && $_REQUEST [ 'InfoEnq' ][ 'LitigeChoix' ] == 'oui' ){
if ( $_REQUEST [ 'InfoEnq' ][ 'Litige' ][ 'Precisions' ] == '' || $_REQUEST [ 'InfoEnq' ][ 'Litige' ][ 'Precisions' ] == '' ){ $fields [] = 'Précisions sur le litige' ; $formError = TRUE ;}
}
if ( $formError == true ){
$message = '<font color="red">' ;
$message .= 'Veuillez remplir les champs suivants : ' ;
$message .= join ( ', ' , $fields );
$message .= '</font>' ;
} else {
$InfoDemande = $InfoUser ;
$siren = $InfoEnq [ 'Siren' ];
unset ( $InfoEnq [ 'Siren' ]);
//Suppression et assigation des valeurs pour le webservice
2011-06-03 08:52:01 +00:00
if ( $InfoEnq [ 'PrecisionsChoix' ] = 1 ){
2011-05-20 09:06:34 +00:00
$InfoEnq [ 'Precisions' ][ 'Type' ] = " Enquête sur un client (contrôle crédit) " ;
unset ( $InfoEnq [ 'PrecisionsChoix' ]);
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == 2 ){
$InfoEnq [ 'Precisions' ][ 'Type' ] = " Enquête sur un prospect (ouverture de compte) " ;
unset ( $InfoEnq [ 'PrecisionsChoix' ]);
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == 3 ){
$InfoEnq [ 'Precisions' ][ 'Type' ] = " Enquête sur un fournisseur stratégique " ;
unset ( $InfoEnq [ 'PrecisionsChoix' ]);
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == 4 ){
$InfoEnq [ 'Precisions' ][ 'Type' ] = " Enquête sur un fournisseur non stratégique " ;
unset ( $InfoEnq [ 'PrecisionsChoix' ]);
} elseif ( $InfoEnq [ 'PrecisionsChoix' ] == 5 ){
$InfoEnq [ 'Precisions' ][ 'Type' ] = " Autre type d'enquête (Précisez...) " ;
unset ( $InfoEnq [ 'PrecisionsChoix' ]);
}
2011-09-06 12:08:21 +00:00
2011-05-20 09:06:34 +00:00
$ws = new WsScore ();
$result = $ws -> commandeEnquete ( $siren , $InfoEnq , $InfoDemande );
2011-09-06 12:08:21 +00:00
if ( $result === false ) {
$this -> _forward ( 'soap' , 'error' );
} else {
$this -> view -> assign ( 'annee' , substr ( $result -> dateCommande , 0 , 4 ));
$this -> view -> assign ( 'mois' , substr ( $result -> dateCommande , 4 , 2 ));
$this -> view -> assign ( 'jour' , substr ( $result -> dateCommande , 6 , 2 ));
$this -> view -> assign ( 'heure' , substr ( $result -> dateCommande , 8 , 2 ));
$this -> view -> assign ( 'minutes' , substr ( $result -> dateCommande , 10 , 2 ));
$this -> view -> assign ( 'ref' , substr ( $result -> refCmde , 1 ));
$this -> view -> assign ( 'siren' , $result -> siren );
$commandeEnquete = true ;
}
$this -> view -> assign ( 'commandeEnquete' , $commandeEnquete );
2011-05-20 09:06:34 +00:00
}
$this -> view -> assign ( 'formError' , $formError );
$this -> view -> assign ( 'message' , $message );
$this -> view -> assign ( 'InfoUser' , $InfoUser );
$this -> view -> assign ( 'InfoEnq' , $InfoEnq );
}
if ( $commandeEnquete == false ) {
$ws = new WsScores ();
$infosEntrep = $ws -> getIdentite ( $this -> siret , $this -> id );
$this -> view -> assign ( 'Etab' , $infosEntrep );
$user = new Utilisateur ();
$this -> view -> assign ( 'user' , $user );
}
$this -> view -> assign ( 'commandeEnquete' , $commandeEnquete );
2011-05-19 15:24:35 +00:00
}
2011-06-21 16:09:34 +00:00
2011-06-29 12:22:59 +00:00
/**
* Affichage des informations de scoring creditsafe
*/
2011-06-21 16:09:34 +00:00
public function scoringAction ()
{
2011-06-22 13:01:08 +00:00
$utilisateur = new Utilisateur ();
if ( ! $utilisateur -> checkModeEdition () or ! $utilisateur -> checkPerm ( 'SCORECSF' ))
$this -> render ( 'error/perms' , null , 'error' );
2011-06-29 10:10:18 +00:00
2011-06-21 16:09:34 +00:00
require_once 'Evaluation/DomDocument2.lib.php' ;
require_once 'common/curl.php' ;
define ( 'CREDITSAFE_WS_URL' , 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx' );
define ( 'CREDITSAFE_WS_URI' , 'https://www.creditsafe.fr/getdata/service/' );
define ( 'CREDITSAFE_WS_USER' , 'scores_decisions' );
define ( 'CREDITSAFE_WS_PASS' , 'yoann1306' );
define ( 'CREDITSAFE_WS_REF' , 'ref' );
/**
* L ' Url du WSDL est bonne simplament le formatage des données a changés , il faut respecter les données !
* comparer les exemples donnés .
2011-06-22 15:31:04 +00:00
*
2011-06-21 16:09:34 +00:00
*/
$req = '<xmlrequest>' .
'<header>' .
'<username>' . CREDITSAFE_WS_USER . '</username>' .
'<password>' . CREDITSAFE_WS_PASS . '</password>' .
//'<operation>getcompanyinformation</operation>'.
'<operation>getratinglimit</operation>' .
'<country>FR</country>' .
'<language>FR</language>' .
'<chargereference>' . CREDITSAFE_WS_REF . '</chargereference>' .
'</header>' .
'<body>' .
//'<package>standard</package>'.
'<package>ratinglimit</package>' .
" <companynumber> " . $this -> siret . " </companynumber> " .
'</body>' .
'</xmlrequest>' ;
$success = true ;
$date = date ( 'Ymd' );
$url = 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx/GetData?RequestXmlStr=' . $req ;
$referer = $cookie = '' ;
$page = getUrl ( $url , $cookie , '' , $referer , false , '' , '' );
$referer = $url ;
$file = APPLICATION_PATH . '/../../data/creditsafe/' . $this -> siret . '.xml' ;
$xml = html_entity_decode ( $page [ 'body' ], ENT_QUOTES , 'UTF-8' );
$dom_object = new DomDocument2 ();
2011-06-29 10:10:18 +00:00
$ws = new WsScores ();
if ( ! file_exists ( $file )) {
2011-06-21 16:09:34 +00:00
file_put_contents ( $file , $xml ); // Ne pas oublier de metre les bons droits sur le dossier.
2011-06-29 10:10:18 +00:00
$ws -> setLog ( 'scorecsf' , $this -> siret );
} else {
$ws -> setLog ( 'scorecsf' , $this -> siret , 0 , 'local' );
}
2011-06-21 16:09:34 +00:00
$dom_object -> load ( $file );
$companyname = $dom_object -> getValueFromTag ( 'companyname' );
$rating = $dom_object -> getValueFromTag ( 'rating' );
$ratingdesc1 = str_replace ( '?' , " ' " , $dom_object -> getValueFromTag ( 'ratingdesc1' ));
$ratingdesc2 = str_replace ( '?' , " ' " , $dom_object -> getValueFromTag ( 'ratingdesc2' ));
$creditlimit = $dom_object -> getValueFromTag ( 'creditlimit' );
$libelle = '' ;
if ( strtoupper ( $creditlimit ) <> strtolower ( $creditlimit ) || $creditlimit == '' )
$strCreditlimit = $creditlimit ;
else
$strCreditlimit = number_format ( $creditlimit , null , null , ' ' ) . ' €' ;
if ( $rating >= 40 ){
$fontColor = 'green' ;
$imgFeux = '<img src="/themes/default/images/scoring/feux_vert.png"/>' ;
if ( $rating >= 71 ) $libelle = 'Très bonne cote de crédit/solvabilité' ;
elseif ( $rating >= 51 ) $libelle = 'Bonne cote de crédit/solvabilité' ;
else $libelle = 'Solvable' ;
} elseif ( $rating >= 20 ) {
$fontColor = 'yellow' ; //#f2be2c';
$imgFeux = '<img src="/themes/default/images/scoring/feux_orange.png"/>' ;
$libelle = 'Précautions recommandées' ;
} elseif ( strtoupper ( $rating ) <> strtolower ( $rating )) {
$fontColor = 'black' ;
$imgFeux = ' ' ;
}
elseif ( $rating == '' ) {
$fontColor = 'black' ;
$imgFeux = ' ' ;
}
else {
$fontColor = 'red' ;
$imgFeux = '<img src="/themes/default/images/scoring/feux_rouge.png"/>' ;
if ( $rating == 0 ) $libelle = 'Entreprise en situation de défaillance et ayant un très fort risque de radiation' ;
else $libelle = 'Avertissement - Crédit à votre discrétion' ;
}
/** Assigne les valeur a la vue **/
2011-06-29 10:10:18 +00:00
if ( ! empty ( $companyname )) {
$this -> view -> raisonSociale = $companyname ;
} else {
2011-10-26 10:34:32 +00:00
$session = new SessionEntreprise ( $this -> siret , $this -> id );
2011-06-29 10:10:18 +00:00
$this -> view -> raisonSociale = $session -> getRaisonSociale ();
}
2011-06-29 10:20:18 +00:00
$this -> view -> emailCommande = $utilisateur -> getEmail ();
2011-06-29 12:22:59 +00:00
$this -> view -> id = $this -> id ;
2011-06-29 10:11:37 +00:00
$this -> view -> siren = substr ( $this -> siret , 0 , 9 );
2011-06-21 16:09:34 +00:00
$this -> view -> imgFeux = $imgFeux ;
$this -> view -> fontColor = $fontColor ;
$this -> view -> rating = $rating ;
$this -> view -> libelle = $libelle ;
$this -> view -> strCreditlimit = $strCreditlimit ;
}
2011-06-29 12:22:59 +00:00
/**
* Commande de scoring partenaire creditsafe
*/
2011-06-29 14:06:51 +00:00
public function scoringcommandeAction ()
2011-06-29 12:22:59 +00:00
{
if ( $this -> getRequest () -> isPost ()){
$request = $this -> getRequest ();
$email = $request -> getParam ( 'email' , '' );
$siren = $request -> getParam ( 'siren' , '' );
2011-06-30 15:30:43 +00:00
if ( preg_match ( '#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#' , $email )) {
2011-06-29 12:22:59 +00:00
$message = 'Entreprise mise sous surveillance scoring partenaire !' ;
require_once 'Scores/Mail.php' ;
$mail = new Mail ();
$mail -> setSubject ( " Demande de surveillance score CreditSafe pour $siren à " . $email );
$user = new Utilisateur ();
2011-06-30 15:30:43 +00:00
$login = $user -> getLogin ();
2011-06-29 12:22:59 +00:00
$texte = 'REQUEST=' . EOL . print_r ( $request -> getParams (), true ) . EOL .
'Utilisateur=' . $login ;
$mail -> setBodyTexte ( $texte );
$mail -> setFrom ( 'contact' );
$mail -> addToKey ( 'contact' );
$mail -> send ();
2011-09-29 15:15:14 +00:00
$configuration = Zend_Registry :: get ( 'configuration' );
$path = $configuration -> path -> data . '/' . $configuration -> path -> log ;
$fp = fopen ( $path . '/surveillance_scf.csv' , 'a' );
2011-06-29 12:22:59 +00:00
fwrite ( $fp , date ( 'Y/m/d H:i:s' ) . " ; $siren ; " . $email . ';' . $login . ';' . $user -> getEmail () . ';' . $user -> getIpAddress () . " \n " );
fclose ( $fp );
} else {
$message = " ERREUR : Veuillez saisir une adresse email valide pour la mise sous surveillance " ;
}
$this -> view -> assign ( 'message' , $message );
}
}
2011-04-19 07:37:39 +00:00
}