odea/application/modules/frontend/controllers/EnrichissementController.php

219 lines
6.8 KiB
PHP
Raw Normal View History

2012-02-15 12:46:40 +00:00
<?php
class EnrichissementController extends Zend_Controller_Action
{
public function init()
{
$this->view->headScript()->appendFile('/themes/default/scripts/enrichissement.js', 'text/javascript');
$this->view->headLink()->appendStylesheet('/themes/default/styles/enrichissement.css');
}
/**
* Enter description here ...
*/
public function indexAction(){}
public function fileformAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/jquery.form.js', 'text/javascript');
$this->view->headScript()->appendFile('/themes/default/scripts/jqueryprogressbar.js', 'text/javascript');
$this->view->assign('filesize', ini_get('upload_max_filesize'));
}
public function fileuploadAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
2012-02-15 12:56:55 +00:00
$config = Zend_Registrey::get('configuration');
$path = realpath($config->path->data).'/clients';
2012-02-15 12:46:40 +00:00
if(!file_exists($path)) mkdir($path);
if ( isset($_FILES) && count($_FILES)==1 ){
$n = $_FILES['fichier']['name'];
$s = $_FILES['fichier']['size'];
$tmp_name = $_FILES['fichier']['tmp_name'];
$name = $_REQUEST['ref'];
$extValide = array('csv');
$extension = strrchr($n,'.');
$extension = substr($extension,1);
//@todo : vérifier l'extension du fichier
if (move_uploaded_file($tmp_name, $path.'/'.$name.'.'.$extension)){
echo "Uploadé !";
} else {
echo "Erreur : ".$_FILES['fichier']['error'];
}
}
}
/**
* Etat de progression de l'upload du fichier
*/
public function fileprogressAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$key = $request->getParam('key', '');
if ( !empty($key) ) {
2012-02-15 12:46:40 +00:00
//$rep sera égal à false si la clef n'existe pas dans le cache apc
$rep = apc_fetch('upload_'.$key);
echo json_encode($rep);
}
}
2012-02-21 09:38:04 +00:00
/**
* Enregistrement de la commande pour l'ennrichissement
*/
public function commandeAction()
{
$this->_helper->layout()->disableLayout();
2012-02-22 09:30:25 +00:00
$request = $this->getRequest();
$idCriteres = $request->getParam('id', null);
$idProfil = $request->getParam('profil', null);
//Vérifier les profils du client
if ( $idProfil===null ){
//Selection du profil du client
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$profilsM = new Table_EnrichissementProfils();
$sql = $profilsM->select()
->from($profilsM, array('id'))
->where('idClient=?', $user->idClient)
->where('login=?', $user->username)
->where('actif=?', 1);
$profil = $profilsM->fetchRow($sql);
$idProfil = $profil->id;
}
2012-02-22 09:30:25 +00:00
2012-04-05 08:20:14 +00:00
$comptage = new Table_Comptages();
$sql = $comptage->select()->where('idDefinition = ?', $idCriteres);
$result = $comptage->fetchRow($sql);
2012-04-05 08:20:14 +00:00
$idComptage = $result['idDefinition'];
2012-02-22 09:30:25 +00:00
//Récupération des critères du ciblage
$criteresM = new Table_Criteres();
2012-03-20 08:24:41 +00:00
$criteresRow = $criteresM->find($idCriteres);
$criteres = $criteresRow->current();
2012-02-22 09:30:25 +00:00
$structure = json_decode($criteres->criteres, true);
require_once 'Scores/Field.php';
$field = new Fields();
2012-02-22 16:30:54 +00:00
$values = $field->getValues($structure);
//Récupération des SIRET
2012-02-22 09:30:25 +00:00
require_once 'Scores/Ciblage.php';
2012-03-20 08:24:41 +00:00
$ciblage = new Ciblage($values, true);
2012-03-15 15:44:10 +00:00
$infosExtraction = $ciblage->execute(true);
2012-03-20 08:24:41 +00:00
//Attention calcul uniteInsee réelle
2012-02-22 09:30:25 +00:00
//car si donnée insee alors toutes les lignes doivent être comptés en unité insee
2012-03-20 08:24:41 +00:00
$data = array(
'idComptage' => $idComptage,
2012-03-20 08:24:41 +00:00
'reference' => $this->getRequest()->getParam('ref'),
'idCriteres' => $criteres->id,
'idProfil' => $idProfil,
2012-03-20 08:24:41 +00:00
'identifiants' => json_encode($infosExtraction),
2012-02-22 09:30:25 +00:00
'idProfil' => $idProfil,
'fichier' => '',
2012-03-20 08:24:41 +00:00
'nbLigneTotales' => count($infosExtraction),
'nbLigneTraites' => 0,
2012-03-20 08:24:41 +00:00
'uniteInsee' => $ciblage->calculRedevanceInsee(),
2012-02-22 09:30:25 +00:00
'error' => '',
2012-04-05 08:20:14 +00:00
'dateAdded' => date('YmdHms'),
2012-02-22 09:30:25 +00:00
);
$identifiantsM = new Table_EnrichissementIdentifiants();
$idIdentifiant = $identifiantsM->insert($data);
2012-02-21 09:38:04 +00:00
}
2012-02-22 11:38:57 +00:00
/**
* Demande de référence pour l'enrichissement
*/
public function referenceAction()
{
2012-02-22 12:56:54 +00:00
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
2012-02-24 10:42:06 +00:00
//Récupération du profil de l'utilisateur
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$profilsM = new Table_EnrichissementProfils();
$sql = $profilsM->select()
->from($profilsM, array('id', 'reference', 'tarifLigne', 'dataInsee'))
->where('idClient=?', $user->idClient)
->where('login=?', $user->username)
->where('actif=?', 1);
2012-03-07 10:41:49 +00:00
$profil = $profilsM->fetchRow($sql);
2012-02-24 10:42:06 +00:00
2012-03-07 10:41:49 +00:00
if ($profil!==null)
2012-02-24 10:42:06 +00:00
{
2012-03-07 10:41:49 +00:00
$this->view->assign('profil', true);
2012-04-04 13:15:56 +00:00
$idCritere = $request->getParam('id', null);
2012-02-24 10:42:06 +00:00
$comptagesM = new Table_Comptages();
$sql = $comptagesM->select()
->where('idDefinition = ?', $idCritere)
->order('dateAjout DESC')
->limit(1);
$comptages = $comptagesM->fetchAll($sql);
$old = $comptages;
$oldResultat = $old[0]->resultat;
$oldResultatInsee = $old[0]->uniteInsee;
2012-02-24 10:42:06 +00:00
if ( $comptages->count()>0 ) {
$item = $comptages[0];
$date = explode(' ', $item->dateAjout);
$date = $date[0];
if($date != '0000-00-00') {
if($date != date('Y-m-d')) {
$criteres = new Table_Criteres();
$sql = $criteres->select()->where('id = ?', $idCritere);
$result = $criteres->fetchRow($sql)->toArray();
$criteres = json_decode($result['criteres'], true);
require_once('Scores/Field.php');
require_once('Scores/Ciblage.php');
$field = new Fields();
$count = new Ciblage($field->getValues($criteres));
$item['resultat'] = $count->execute();
$item['uniteInsee'] = $count->calculRedevanceInsee();
}
}
2012-02-24 10:42:06 +00:00
$this->view->assign('resultat', $item['resultat']);
$this->view->assign('uniteInsee', $item['uniteInsee']);
//Calcul du prix
$redevanceInsee = 3.295/100; //Seuil de facturation 52 734 euros
2012-02-24 10:42:06 +00:00
$prixInsee = $item['uniteInsee']*$redevanceInsee;
$infoInsee = '';
if ($profil->dataInsee){
$prixInsee = $item['resultat']*$redevanceInsee;
$infoInsee = "Votre profil inclus au moins une donnée Insee, la redevance sera applicable sur chaque ligne.";
}
$prix = $item['resultat'] * $profil->tarifLigne + $prixInsee;
$this->view->prix = round($prix, 2);
$this->view->prixInsee = round($prixInsee, 2);
$this->view->infoInsee = $infoInsee;
$this->view->id = $item['id'];
$this->view->oldDate = $date;
$this->view->oldResult = $oldResultat;
$this->view->oldResultInsee = $oldResultatInsee;
$this->view->oldPrice = round($oldResultat* $profil->tarifLigne + $oldResultatInsee, 2);
$this->view->oldPriceInsee = round($oldResultatInsee*$redevanceInsee, 2);
$this->view->criteres = $criteres;
2012-02-24 10:42:06 +00:00
}
}
2012-02-24 10:42:06 +00:00
2012-02-22 11:38:57 +00:00
}
2012-02-15 12:46:40 +00:00
}