extranet/application/controllers/EvaluationController.php

1034 lines
39 KiB
PHP

<?php
class EvaluationController extends Zend_Controller_Action
{
protected $siret = null;
protected $id = 0;
public function init()
{
$request = $this->getRequest();
$this->siret = $request->getParam('siret');
$this->id = $request->getParam('id', 0);
require_once 'Scores/WsScores.php';
require_once 'Scores/IdentiteEntreprise.php';
}
public function indexAction()
{
$this->forward('entreprise', 'recherche');
}
/**
* Affichage d'une reglette représentant le score
*/
public function printscoresAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$score = strtolower($request->getParam('score'));
if( $score == 'indiscore' ){
$user = new Scores_Utilisateur();
switch($user->getTypeScore()) {
case '20': $score.='20'; break;
case '100':
default: $score.='100'; break;
}
}
$note = $request->getParam('note');
$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 ),
);
$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']);
}
/**
* Historique des scores
*/
public function scoreshistoAction()
{
$this->view->headLink()
->appendStylesheet('/libs/tablesorter/themes/blue/style.css', 'all');
$this->view->headScript()
->appendFile('/libs/tablesorter/jquery.tablesorter.js', 'text/javascript');
$sessionEntreprise = new Scores_Session_Entreprise($this->siret, $this->id);
$siren = substr($this->siret,0,9);
$types = array (
'indiScore' => 'IndiScore',
'scoreDir' => 'Dirigeance',
'scoreConf' => 'Conformité',
'scoreZ' => 'Score Z',
'scoreCH' => 'Conan & Holder',
'scoreAfdcc1' => 'Afdcc1',
'scoreAfdcc2' => 'Afdcc2',
'scoreAltman' => 'Altman',
'scoreCCF' => 'CCF',
);
$bornes = array(
'indiScore' => array('min'=>0, 'max'=>20, 'rouge'=>8, 'orange'=>12),
'scoreDir' => array('min'=>0, 'max'=>100, 'rouge'=>45, 'orange'=>56),
'scoreConf' => array('min'=>0, 'max'=>100, 'rouge'=>45, 'orange'=>56),
'scoreZ' => array('min'=>-3, 'max'=>3, 'rouge'=>-0.25, 'orange'=>0.125),
'scoreCH' => array('min'=>-4.5,'max'=>16, 'rouge'=>3.75, 'orange'=>10),
'scoreAfdcc1' => array('min'=>-7, 'max'=>7, 'rouge'=>0, 'orange'=>1),
'scoreAfdcc2' => array('min'=>-3, 'max'=>2, 'rouge'=>-1, 'orange'=>0.5),
'scoreAltman' => array('min'=>-2, 'max'=>8, 'rouge'=>0, 'orange'=>2.7),
'scoreCCF' => array('min'=>500,'max'=>1500,'rouge'=>850, 'orange'=>1200), //corriger les bornes de CCF
);
$request = $this->getRequest();
$type = $request->getParam('type', 'indiScore');
$user = new Scores_Utilisateur();
$this->view->headTitle()->prepend('Historique indiScore');
$this->view->headTitle()->prepend('Siret '.$this->siret);
$ws = new WsScores();
$histoScores = $ws->getScoresHisto($this->siret, $type);
if ( $histoScores->nbReponses>1 ) {
$data = array();
foreach ($histoScores->result->item as $item) {
$d = array(
'date' => $item->date,
'value' => $item->value,
'encours' =>$item->encours,
);
$data['data'][] = $d;
}
//Make the graph - Ready to create a class for this char
require_once 'Vendors/ChartDirector/phpchartdir.php';
require_once 'Scores/Cache.php';
$c = Zend_Registry::get('config');
$path = $c->profil->path->pages . '/imgcache/';
$file = 'indiscorehisto-'.$this->siret.'-'.$this->id.'-'.$type.'.png';
$cache = new Cache();
$return = null;
if( $cache->exist($path.$file) ){
$return = $file;
} else {
if( count($data)<1 ){
$return = null;
} else {
$labelsX = array();
$dataX = array();
$encours = array();
foreach($data['data'] as $value){
$dataX[] = $value['value'];
$encours[] = $value['encours'];
$date = new Zend_Date($value['date'], 'yyyy-MM-dd');
$labelsX[] = chartTime($date->toString('yyyy'), $date->toString('MM'), $date->toString('dd'));
}
$c = new XYChart(600, 300);
$c->setPlotArea(50, 10, $c->getWidth() - 60, $c->getHeight() - 60, 0xFFFFFF, -1, 0xC0C0C0, $c->dashLineColor(0x808080, DotLine), -1);
$c->xAxis->setTitle($this->view->translate("Année"));
$c->xAxis->setColors(0x777777, 0x444444, 0x777777);
$c->xAxis->setWidth(2);
$c->yAxis->setTitle($this->view->translate("Score"));
$c->yAxis->setColors(0x777777, 0x444444, 0x777777);
$c->yAxis->setWidth(2);
$c->yAxis->addZone(abs($bornes[$type]['min'])*(-5), $bornes[$type]['rouge'], 0xFFE2E2);
$c->yAxis->addZone($bornes[$type]['rouge'], $bornes[$type]['orange'], 0xFFF2E2);
$c->yAxis->addZone($bornes[$type]['orange'], abs($bornes[$type]['max'])*5, 0xE2FFE2);
// If real value is not between min max scores, enlarge Y of graphic and mark limits
$maxY = (max($dataX) >= $bornes[$type]['max']) ? max($dataX)*1.1 : $bornes[$type]['max'];
$minY = (min($dataX) <= $bornes[$type]['min']) ? min($dataX)*1.1 : $bornes[$type]['min'];
$c->yAxis->setLinearScale($minY, $maxY);
$textBox = $c->addText(550, 15, $types[$type], "arialbi.ttf", 11, 0xAAAAAA);
$textBox->setAlignment(TopRight);
$layer = $c->addSplineLayer();
$layer->setXData($labelsX);
$layer->setLineWidth(1);
$layer->addExtraField($encours);
$dataSet = $layer->addDataSet($dataX, 0x0000FF);
$dataSet->setDataSymbol(CircleSymbol, 4, 0x5555FF);
if( $c->makeChart($path.$file ) === true){
$return = $file;
$graphMap = $c->getHTMLImageMap("", "", "title='{x|dd/mm/yyyy}\nScore: {value}\nEncours: {field0} K&euro;' style='cursor:pointer;'");
} else {
$return = false;
}
}
}
$this->view->assign('graphMap', $graphMap);
$this->view->assign('graph', $return);
//Assign vars
$this->view->assign('scores', $histoScores->result->item);
if ($histoScores->type == 'indiScore20') $histoScores->type = 'indiScore';
$this->view->assign('type', $histoScores->type);
$this->view->assign('bornes', $bornes);
}
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('raisonSociale', $sessionEntreprise->getRaisonSociale());
$this->view->assign('types', $types);
$this->view->assign('exportObjet', $histoScores);
}
/**
* IndiScore
*/
public function indiscoreAction()
{
$user = new Scores_Utilisateur();
if(!$user->checkPerm('INDISCORE') && !$user->checkPerm('INDISCOREP'))
$this->forward('perms', 'error');
$this->view->assign('edition', $user->checkModeEdition());
$request = $this->getRequest();
$autrePage = $request->getParam('apage');
//Récupération des informations
if (empty($autrePage)) {
$this->view->headTitle()->prepend('IndiScore');
$this->view->headTitle()->prepend('Siret '.$this->siret);
$plus = false;
if ($user->checkPerm('indiscorep')){
$plus = true;
}
$ref = $request->getParam('ref', '');
$encours = $request->getParam('encours', 0);
$email = $request->getParam('email', '');
$ws = new WsScores();
$infos = $ws->getIndiScore(substr($this->siret, 0,9), 0, 1, $plus, $ref, $encours, $email);
if ($infos === false) $this->forward('soap', 'error');
} else {
$infos = $this->getRequest()->getParam('infos');
}
$this->view->assign('siret', $this->siret);
$this->view->assign('typeScore', $user->getTypeScore());
$this->view->assign('indiscore', $infos);
$this->view->assign('AutrePage', $autrePage);
$this->view->assign('exportObjet', $infos);
$this->view->assign('aviscredit', $user->checkPerm('aviscredit'));
$this->view->assign('surveillance', $user->checkPerm('survscore'));
}
/**
* Rapport de synthese
*/
public function indiscore2Action()
{
$this->view->headScript()->appendFile('/themes/default/scripts/finance.js', 'text/javascript');
$this->view->headTitle()->prepend("Rapport de synthèse");
$this->view->headTitle()->prepend("Siret ".$this->siret);
$user = new Scores_Utilisateur();
if(!$user->checkPerm('INDISCORE2') && !$user->checkPerm('INDISCORE2P'))
$this->forward('perms', 'error');
$siren = substr($this->siret,0,9);
$ws = new WsScores();
$entreprise = new Scores_Session_Entreprise($this->siret, $this->id);
$identite = $ws->getIdentite($siren);
$indiscore = $ws->getIndiScore($siren);
$infos = $ws->getRatios($siren, 'indiscore2'); // @todo : vérifier la page
$score = array();
$tabRatio = array(
'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'),
);
//Formattage des données
$typeBilan = 'N';
$ratiosData = new Scores_Finance_Ratios_Data($infos);
$nbBilanN = $ratiosData->getNbBilan('N');
$nbBilanC = $ratiosData->getNbBilan('C');
if ($nbBilanN!=0)
{
foreach($tabRatio as $idRatio => $valRatio){
$tabRatio[$idRatio]['comment'] = $ratiosData->wrapComment($idRatio);
}
$this->view->assign('tabRatio', $tabRatio);
$infosAnnee = $ratiosData->getBilansInfo($typeBilan);
$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'];
}
$date = new Zend_Date($annee, 'yyyyMMdd');
$tabResult[] = array(
'dateCloture' => $date->toString('dd/MM/yyyy'),
'duree' => $infosAnnee[$annee]->duree.' Mois',
'ratio' => $data,
'total' => $dataTotal,
'info' => $dInfo,
);
}
$this->view->assign('tabResult', $tabResult);
}
$this->view->assign('tabRatio', $tabRatio);
/*
Correction pour indiscore seule
$indiscore->Siege;
$indiscore->SiretSiege;
$indiscore->NumRC;
*/
$indiscore->SiretSiege = $identite->SiretSiege;
$identite = new IdentiteEntreprise($identite);
//Définition des blocks
$blocks = array(
'Siret',
'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 = '';
if(isset($indiscore->DateRadiation) && $indiscore->DateRadiation!='' && $indiscore->DateRadiation!='0000-00-00') {
$date = new Zend_Date(str_replace('-','',$indiscore->DateRadiation), 'yyyyMMdd');
$this->view->assign('dateRadiation', $date->toString('dd/MM/yyyy'));
}
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');
}
$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;
}
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('encours', $indiscore->encours);
$this->view->assign('TendanceIndiscore', $indiscore->TendanceIndiscore);
$this->view->assign('SituationJuridique', $indiscore->SituationJuridique);
$this->view->assign('paiement', $indiscore->infoPaiement);
$this->view->assign('scores', $score);
$this->view->assign('bilanReference', $bilanReference);
}
/**
* Rapport complet
*/
public function indiscore3Action()
{
$this->view->headScript()->appendFile('/themes/default/scripts/evaluation.js', 'text/javascript');
$this->view->headTitle()->prepend("Rapport complet");
$this->view->headTitle()->prepend("Siret ".$this->siret);
$user = new Scores_Utilisateur();
if(!$user->checkPerm('INDISCORE3') && !$user->checkPerm('INDISCORE3P'))
$this->forward('perms', 'error');
// 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)
));
}
$sessionEntreprise = new Scores_Session_Entreprise($this->siret, $this->id);
$ws = new WsScores();
$siren = substr($this->siret,0,9);
$plus = false;
if ($user->checkPerm('indiscore3p')){
$plus = true;
}
$request = $this->getRequest();
$ref = $request->getParam('ref', '');
$encours = $request->getParam('encours', 0);
$email = $request->getParam('email', '');
$infos = $ws->getRapport($siren, 3, 0, $plus, $ref, $encours, $email);
Zend_Registry::get('firebug')->info($infos);
if ($infos === false) {
$this->forward('soap', 'error');
}
$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);
require_once 'Scores/RapportComment.php';
$rapportComment = new RapportComment($siren, $this->id,
$infos->Indiscore->tabCommentaires->item,
$infos->Ratios->RatiosInfos,
$infos->Ratios->BilansInfos,
$infos->Ratios->RatiosSecteur,
$infos->Indiscore->tabVariables
);
$this->view->assign('comment',$rapportComment->out());
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('raisonSociale', $sessionEntreprise->getRaisonSociale());
$this->view->assign('exportObjet', $infos);
}
/**
* Génération de rapport personnalisé
* @todo : à améliorer
*/
public function customindiscore3Action()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$upload = $request->getParam('upload', null);
$siren = substr($this->siret, 0, 9);
$user = new Scores_Utilisateur();
if (empty($upload)){
$adresse = array();
if ($user->checkModeEdition() || $user->getIdClient()==110) {
$adresse[] = 'Order to Cash';
$adresse[] = '6, rue Euryale Dehaynin ';
$adresse[] = '75019 PARIS';
$color1 = '#DFDB00';
$color2 = '#EFED9A';
$background = "background-image:url('/themes/default/images/customrapport/logo_ordertocash.jpg');background-repeat:no-repeat;background-position:center";
} 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);
$sessionEntreprise = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->assign('rs', $sessionEntreprise->getRaisonSociale());
} else {
$this->_helper->viewRenderer->setNoRender(true);
$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);
if ($this->id!=0){
$file = 'evaluation-indiscore3-'.$this->siret.'-'.$this->id.'.html';
} else {
$file = 'evaluation-indiscore3-'.$this->siret.'.html';
}
$c = Zend_Registry::get('config');
$path = $c->profil->path->pages;
if (file_exists($path.'/'.$file))
{
$doc = new DOMDocument();
$doc->preserveWhiteSpace = true;
@$doc->loadHTMLFile($path.'/'.$file);
//Générer style particulier pour le rapport
$style.= 'body {background-color:#ffffff;} ';
$style.= '#footer {display:none;} ';
$style.= '#customRapport {display:none;} ';
$style.= '.notvisible{display:none;} ';
$style.= '#center h1 {background-color:'.$couleurh1.';color:'.$texth1.';border:1px solid;} ';
if($logo_background) {
$style.= '#center {background-image:url(./themes/default/images/customrapport/logo_ordertocash_background.jpg);background-repeat:no-repeat;background-position:center;} ';
}
$style.= '#center h2 {background-color:'.$couleurh2.';color:'.$texth2.'} ';
$style.= 'p#rsynthese {font-size:14px;font-weight:bold;} ';
$styleDom = $doc->createElement('style', $style);
//Ajout information
$contentDom = $doc->createElement('div');
if(!$user->checkModeEdition()) {
$element = $doc->createElement('img');
$element->setAttribute('src', './themes/default/images/customrapport/logo_ordertocash.jpg');
$element->setAttribute('width', '12%');
} else {
$element = $doc->createElement('img');
$element->setAttribute('src', './themes/default/images/customrapport/logo_ordertocash.jpg');
$element->setAttribute('width', '12%');
}
$div = $doc->createElement('div');
$div->setAttribute('style', "clear:both;");
$div->appendChild($element);
$contentDom->appendChild($div);
$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() || $user->getIdClient()==110) {
$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 84 16 50 00 ou par mail à l'adresse suivante : contact@ordertocash.fr");
$element->setAttribute('style', 'text-align:left;');
$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();
$c = Zend_Registry::get('config');
$outfile = $c->profil->path->pages.'/p'.$user->getIdClient().'-'.$file;
file_put_contents($outfile, $xml);
//Génération du pdf
$wkhtmltopdf = new Scores_Wkhtml_Pdf();
$wkhtmltopdf->setOptions('footer-right', 'Page [page] sur [toPage]');
$wkhtmltopdf->setOptions('header-right', date('d/m/Y H:i:s'));
$wkhtmltopdf->setOptions('disable-external-links');
$wkhtmltopdf->setOptions('disable-internal-links');
$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 !";
}
}
}
/**
* Enquete commerciale
* @todo : Vérifier l'enregistrement
*/
public function enquetecAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/enquetec.js', 'text/javascript');
$this->view->headTitle()->prepend("Enquete commerciale");
$this->view->headTitle()->prepend("Siret ".$this->siret);
//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
if($InfoEnq['PrecisionsChoix'] = 1){
$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']);
}
$ws = new WsScore();
$result = $ws->commandeEnquete($siren, $InfoEnq, $InfoDemande);
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);
}
$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 Scores_Utilisateur();
$this->view->assign('user', $user);
}
$this->view->assign('commandeEnquete', $commandeEnquete);
}
/**
* Demande d'avis de credit
*/
public function aviscreditAction()
{
$this->view->headTitle()->prepend("Avis de crédit");
$this->view->headTitle()->prepend("Siret ".$this->siret);
$commande = false;
$request = $this->getRequest();
//Reception des données du formulaire
if ($request->isPost())
{
$InfoUser = $request->getParam('InfoUser');
$InfoEnq = $request->getParam('InfoEnq');
$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(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 retard 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;
}
}
//Envoi du mail formatté
if ( $formError==true )
{
$message = '<font color="red">';
$message.= 'Veuillez remplir les champs suivants : ';
$message.= join(', ', $fields);
$message.= '</font>';
$this->view->assign('message', $message);
}
else
{
$sujet = "Demande d'avis personnalisé";
$texte = "<pre>".print_r($InfoUser, 1)."</pre>".
"<pre>".print_r($InfoEnq, 1)."</pre>";
$mail = new Scores_Mail();
$mail->setFrom('production');
$mail->addToKey('support');
$mail->setSubject($sujet);
$mail->setBodyHtml($texte);
if ($mail->send()) {
$commande = true;
}
}
$this->view->assign('commande', $commande);
$this->view->assign('formError', $formError);
$this->view->assign('message', $message);
$this->view->assign('InfoUser', $InfoUser);
$this->view->assign('InfoEnq', $InfoEnq);
$this->view->assign('siren', substr($this->siret, 0,9));
}
//Affichage du formulaire
if ($commande == false) {
$ws = new WsScores();
$infosEntrep = $ws->getIdentite($this->siret, $this->id);
$this->view->assign('Etab', $infosEntrep);
$user = new Scores_Utilisateur();
$this->view->assign('user', $user);
}
}
/**
* Affichage des informations de scoring creditsafe
*/
public function scoringAction()
{
$this->view->headTitle()->prepend("Scoring Credit Safe");
$this->view->headTitle()->prepend("Siret ".$this->siret);
$user = new Scores_Utilisateur();
if(!$user->checkModeEdition() or !$user->checkPerm('SCORECSF'))
$this->render('error/perms', null, 'error');
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.
*
*/
$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>';
$date = date('Ymd');
$url = 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx/GetData?RequestXmlStr='.$req;
$file = APPLICATION_PATH.'/../../data/creditsafe/'.$this->siret.'.xml';
try {
$client = new Zend_Http_Client($url);
$client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful() ) {
$xml = html_entity_decode($response->getBody(), ENT_QUOTES, 'UTF-8');
$dom_object = new DOMDocument();
$ws = new WsScores();
if(!file_exists($file)) {
file_put_contents($file, $xml); // Ne pas oublier de metre les bons droits sur le dossier.
$ws->setLog('scorecsf', $this->siret);
} else {
$ws->setLog('scorecsf', $this->siret, 0, 'local');
}
$dom_object->load($file);
$companyname = $dom_object->getElementsByTagName('companyname')->item(0)->nodeValue;
$rating = $dom_object->getElementsByTagName('rating')->item(0)->nodeValue;
$ratingdesc1 = str_replace('?',"'",$dom_object->getElementsByTagName('ratingdesc1')->item(0)->nodeValue);
$ratingdesc2 = str_replace('?',"'",$dom_object->getElementsByTagName('ratingdesc2')->item(0)->nodeValue);
$creditlimit = $dom_object->getElementsByTagName('creditlimit')->item(0)->nodeValue;
$libelle = '';
if (strtoupper($creditlimit)<>strtolower($creditlimit) || $creditlimit=='')
$strCreditlimit = $creditlimit;
else
$strCreditlimit = number_format($creditlimit,null,null,' '). ' &euro;';
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='&nbsp;';
}
elseif ($rating == '') {
$fontColor = 'black';
$imgFeux = '&nbsp;';
}
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 **/
if (!empty($companyname)) {
$this->view->raisonSociale = $companyname;
} else {
$session = new Scores_Session_Entreprise($this->siret, $this->id);
$this->view->raisonSociale = $session->getRaisonSociale();
}
$this->view->emailCommande = $user->getEmail();
$this->view->id = $this->id;
$this->view->siren = substr($this->siret, 0,9);
$this->view->imgFeux = $imgFeux;
$this->view->fontColor = $fontColor;
$this->view->rating = $rating;
$this->view->libelle = $libelle;
$this->view->strCreditlimit = $strCreditlimit;
}
} catch (Zend_Http_Client_Exception $e) {}
}
/**
* Commande de scoring partenaire creditsafe
*/
public function scoringcommandeAction()
{
if ($this->getRequest()->isPost()){
$request = $this->getRequest();
$email = $request->getParam('email', '');
$siren = $request->getParam('siren', '');
if (preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#',$email)) {
$message = 'Entreprise mise sous surveillance scoring partenaire !';
$mail = new Scores_Mail();
$mail->setSubject("Demande de surveillance score CreditSafe pour $siren à ".$email);
$user = new Scores_Utilisateur();
$login = $user->getLogin();
$texte = 'REQUEST='.EOL.print_r($request->getParams(),true).EOL.
'Utilisateur='.$login;
$mail->setBodyTexte($texte);
$mail->setFrom('contact');
$mail->addToKey('contact');
$mail->send();
$c = Zend_Registry::get('config');
$path = $c->profil->path->data.'/log';
$fp=fopen($path.'/surveillance_scf.csv', 'a');
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);
}
}
public function valorisationAction()
{
$this->view->headTitle()->prepend("Valorisation");
$this->view->headTitle()->prepend("Siret ".$this->siret);
$user = new Scores_Utilisateur();
if(!$user->checkPerm('INDISCORE3') && !$user->checkPerm('INDISCORE3P'))
$this->_forward('perms', 'error');
$sessionEntreprise = new Scores_Session_Entreprise($this->siret, $this->id);
$ws = new WsScores();
$siren = substr($this->siret,0,9);
$request = $this->getRequest();
$ref = $request->getParam('ref', '');
$encours = $request->getParam('encours', 0);
$email = $request->getParam('email', '');
$infos = $ws->getEntrepriseValo($siren);
require_once 'Scores/RapportComment.php';
$rapportComment = new RapportComment($siren, $this->id,
$infos->Indiscore->tabCommentaires->item,
$infos->RatiosInfos,
$infos->RatiosBilansInfos,
$infos->RatiosSecteur,
$infos->Indiscore->tabVariables
);
$this->view->assign('comment',$rapportComment->out());
$this->view->assign('siret', $this->siret);
$this->view->assign('id', $this->id);
$this->view->assign('siren', $siren);
$this->view->assign('raisonSociale', $sessionEntreprise->getRaisonSociale());
$this->view->assign('exportObjet', $infos);
}
}