This commit is contained in:
Damien LASSERRE 2012-03-20 08:24:41 +00:00
parent 7135be80d3
commit 21ddf64775
16 changed files with 192 additions and 143 deletions

View File

@ -9,36 +9,10 @@ class DashboardController extends Libs_Controller
public function indexAction()
{
$object = new Object_Dashboard();
$this->view->comptages = $object->index();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Affichage des derniers enrichissements
$enrichissementsM = new Table_EnrichissementIdentifiants();
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
array('c' => 'comptages'), 'i.idComptage = c.id',
array('')
)
->join(
array('criteres' => 'criteres'), 'i.idCriteres = criteres.id',
array('')
)
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->order('dateAdded DESC');
$enrichissements = $enrichissementsM->fetchAll($sql);
$this->view->assign('enrichissements', $enrichissements);
$object = new Object_Dashboard();
$this->view->comptages = $object->index();
$this->view->enrichissements = $object->enrichissements();
}

View File

@ -76,6 +76,11 @@ class EnrichissementController extends Zend_Controller_Action
$idCriteres = $request->getParam('id', null);
$idProfil = $request->getParam('profil', null);
$comptage = new Table_Comptages();
$sql = $comptage->select()->where('idDefinition = ?', $idCriteres);
$result = $comptage->fetchRow($sql);
$idComptage = $result['idDefinition'];
//Vérifier les profils du client
if ( $idProfil===null ){
//Selection du profil du client
@ -94,8 +99,8 @@ class EnrichissementController extends Zend_Controller_Action
//Récupération des critères du ciblage
$criteresM = new Table_Criteres();
$criteresRow = $criteresM->find($idCriteres);
$criteres = $criteresRow->current();
$criteresRow = $criteresM->find($idCriteres);
$criteres = $criteresRow->current();
$structure = json_decode($criteres->criteres, true);
@ -105,21 +110,22 @@ class EnrichissementController extends Zend_Controller_Action
//Récupération des SIRET
require_once 'Scores/Ciblage.php';
$ciblage = new Ciblage($values);
$ciblage = new Ciblage($values, true);
$infosExtraction = $ciblage->execute(true);
//Attention calcul uniteInsee réelle
//car si donnée insee alors toutes les lignes doivent être comptés en unité insee
$data = array(
$data = array(
'idComptage' => $idComptage,
'reference' => $this->getRequest()->getParam('ref'),
'idCriteres' => $criteres->id,
'idProfil' => $idProfil,
'identifiants' => $infosExtraction['result'],
'identifiants' => json_encode($infosExtraction),
'idProfil' => $idProfil,
'fichier' => '',
'nbLigneTotales' => $infosExtraction['total'],
'nbLigneTraites' => '',
'uniteInsee' => $infosExtraction['insee'],
'nbLigneTotales' => count($infosExtraction),
'nbLigneTraites' => count($infosExtraction),
'uniteInsee' => $ciblage->calculRedevanceInsee(),
'error' => '',
'dateAdded' => date('YmdHis'),
);

View File

@ -90,7 +90,7 @@ class Object_Codepostaux extends Libs_Row
foreach($departements as $nom) {
$structure[] = array(
'data' => $nom['libdep'],
'data' => $nom['numdep'].' '.$nom['libdep'],
'attr' => array('id' => 'adr_dept:'.$nom['numdep'],
'niveau' => 1,
'class' => $this->_getClass('adr_dept:'.$nom['numdep'], 1)
@ -112,7 +112,7 @@ class Object_Codepostaux extends Libs_Row
foreach($codepostaux as $nom) {
$structure[] = array(
'data' => $nom['Commune'],
'data' => $nom['Codepos'].' '.$nom['Commune'],
'attr' => array('id'=> 'adr_com:'.$nom['INSEE'],
'niveau' => 2,
'class' => $this->_getClass('adr_com:'.$nom['INSEE'], 2)

View File

@ -73,23 +73,23 @@ class Object_Comptage extends Libs_Row
foreach($valeurs as $valeur) {
$vil .= 'adr_com:'.trim($valeur).',';
}
$vil = substr($vil, 0, strlen($vil)-1);
//$vil = substr($vil, 0, strlen($vil)-1);
}
if($session->getCritere('adr_reg')) {
$valeurs = explode(',', $session->getCritere('adr_reg'));
foreach($valeurs as $valeur) {
$reg .= 'adr_reg:'.trim($valeur).',';
}
$reg = substr($reg, 0, strlen($reg)-1);
//$reg = substr($reg, 0, strlen($reg)-1);
}
if($session->getCritere('adr_dept')) {
$valeurs = explode(',', $session->getCritere('adr_dept'));
foreach($valeurs as $valeur) {
$dept .= 'adr_dept:'.trim($valeur).',';
}
$dept = substr($dept, 0, strlen($dept)-1);
//$dept = substr($dept, 0, strlen($dept)-1);
}
$valeur = implode('', array($vil, $reg, $dept));
$valeur = $vil.$dept.$reg;
$session->setCritere($key, $valeur);
}
require_once 'Scores/Field.php';

View File

@ -43,6 +43,31 @@ Class Object_Dashboard
return ($results);
}
public function enrichissements()
{
$enrichissementsM = new Table_EnrichissementIdentifiants();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
array('c' => 'comptages'), 'i.idComptage = c.id',
array('')
)
->join(
array('criteres' => 'criteres'), 'i.idCriteres = criteres.id',
array('')
)
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->order('dateAdded DESC');
return ($enrichissementsM->fetchAll($sql));
}
public function menu()
{

View File

@ -0,0 +1,5 @@
<?php
class Table_EnrichissementCommandes extends Zend_Db_Table_Abstract
{
public $_name = 'enrichissement_commandes';
}

View File

@ -200,7 +200,7 @@ Class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
}
/* Modifier les données */
$return = '<textarea rows="5" style="border:1px inset silver;width:60%" class="criteres complited'.$type.'" id="textarea_'.$name.'" name="'.$name.'">'.$session->getCritere($name).'</textarea>';
$return .= '<a href="" class="autocomplet" textarea="'.$name.'">Valider</a>';
$return .= '<a href="" class="autocomplet" textarea="'.$name.'">Valider</a> <a href="">Aide</a>';
return ($return);
}

View File

@ -53,7 +53,7 @@
<div id="lastEnrichissement">
<h2>Vos derniers enrichissements</h2>
<?php if(count($this->enrichissement) > 0):?>
<?php if(count($this->enrichissements) > 0):?>
<table>
<thead>
<tr>
@ -64,7 +64,7 @@
</tr>
</thead>
<tbody>
<?php foreach($this->enrichissement as $item):?>
<?php foreach($this->enrichissements as $item):?>
<tr>
<td><?=$item['reference']?></td>
<td><?=number_format($item['nbLigneTotales'], 0, ',', ' ')?></td>

View File

@ -2,19 +2,12 @@
<ul id="fieldsblock">
<li><?php echo $this->Field('adr_com', $this->fields->get('adr_com'));?></li>
<li style="background-image:none;height:80px;">
<img style="float:right" src="/themes/default/images/help.png" />
<?php echo $this->Field('vil', $this->fields->get('adr_com'), 'text');?>
</li>
<li style="background-image:none;height:80px;">
<i>Indiquez les noms ou les codes des départements séparés par des virgules.
Si vous disposez d'une liste sous forme excel glissez le fichier dans l'encadré,
Pour la corse vous pouvez indiquer 20 ou 2A, 2B, pour les DOM-TOM vous pouvez indiquer deux ou trois chiffres,
exemple : 97 ou 971, 972...</i>
<?php echo $this->Field('adr_dept', $this->fields->get('adr_dept'), 'text');?>
</li>
<li style="background-image:none;height:80px;">
<i>Indiquez les noms ou les codes (insee) des régions séparés par des virgules.
Si vous disposez d'une liste sous forme excel glissez le fichier dans l'encadré</i>
<?php echo $this->Field('adr_reg', $this->fields->get('adr_reg'), 'text');?>
</li>
</ul>

View File

@ -1,29 +1,33 @@
<h1>Vos critères de selections</h1>
<style>
.color {
background-color:#DEDEDE;
}
a
{
text-decoration: none;
}
#criteres_ra
{
width:93%;
font-size: 11px;
}
#criteres_ra tr td {
border-left: 1px solid black;
border-right: 1px solid black;
padding-left:5px;
}
</style>
<table id="criteres_ra" style="margin-top:15px">
<table id="criteres_ra" style="margin:10px">
<tr>
<td><b>Champ séléction</b></td>
<td><b>Votre critère</b></td>
<td id="Valide" style="text-align: center" colspan="3"><a class="saveciblage" href="/comptage/savedialog">Valider mon comptage</a></td>
</tr>
<?php $color = 0;foreach($this->criteres as $critere => $valeur):?>
<?php $label = $this->field->get($critere); ?>
<?php if($valeur != 'tous' and $valeur != null and $valeur != 'null' and $valeur != ','):?>
<?php if($valeur != 'tous' and $valeur != null and $valeur != 'null' and $valeur != ',' and $critere != 'adr_com'):?>
<?php $valeur = explode(',', $valeur); ?>
<tr <?php echo ((($color%2) == 0)?'class="color"':''); $color++;?>>
<td valign="top" style="width:150px">
<td valign="top" style="padding:5px;width:150px">
<?php echo $label['label'];?>
</td>
<td>
@ -39,10 +43,11 @@
<?php echo $val;?>
<?php endif; ?>
</td>
<td>
<td style="text-align: center">
<a class="remove" href="index/remove/critere/<?php echo $critere;?>">
<img src="/themes/default/images/cross.png" />
<img width="14px;" src="/themes/default/images/cross.png" />
</a>
<img src="/themes/default/images/help.png" />
</td>
</tr>
<?php endif;?>

View File

@ -14,7 +14,6 @@ set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
@ -55,33 +54,37 @@ try {
}
//Définition bdd metier
try {
$dbMetier = Zend_Db::factory('Mysqli', $dbConfig->jo);
$dbMetier = Zend_Db::factory($dbConfig->jo);
} catch ( Exception $e ) {
exit ( $e->getMessage() );
}
$liste = array();
if ($opts->id) {
if ($opts->id)
{
$commandesM = new Table_EnrichissementCommandes($db);
$commande = $commandesM->find(intval($opts->id))->current();
$identifiants = json_decode($commande->identifiants, true);
//$commandesM = new Table_EnrichissementCommandes($db);
$sql = $db->select()
->from('enrichissement_identifiants')
->where('idComptage = ?', intval($opts->id));
$commande = $db->fetchRow($sql);
$identifiants = json_decode($commande['identifiants'], true);
//$profilM = new Table_EnrichissementProfils($db);
$sql = $db->select()
->from('enrichissement_profils')
->where('id = ?', $commande['idProfil']);
$profil = $db->fetchRow($sql);
$dataProfil = json_decode($profil['criteres'], true);
} else if ($opts->file)
{
$profilM = new Table_EnrichissementProfils($db);
$profil = $profilM->find($commande->idProfil);
$dataProfil = json_decode($profil->criteres, true);
} else if ($opts->file) {
}
if ( count($identifiants)>0 && count($dataProfil)>0 )
{
$outFile = uniqid($commande->reference.'-');
$outFile = uniqid($commande->reference.'-').'.csv';
require_once 'Scores/Enrichissement.php';
$dico = new Enrichissement();
@ -98,7 +101,7 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
//Construction de la requete SQL
if ( array_key_exists('sql', $fields[$item]) ) {
$sql.= ' '.$sql;
$sql.= '';
} else {
$sql.= ' '.$fields[$item]['column'].' AS '.$item.',';
}
@ -116,14 +119,12 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
if (count($tabEnteteLabel)>0){
fputcsv($fp, $tabEnteteLabel, ',', '"');
}
$model = $sql;
foreach ($identifiants as $siret )
{
$sql.= ' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
$result = $dbMetier->fetchAssoc($sql);
$sql = $model .' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
$result = $dbMetier->fetchAll($sql);
$tabData = $result[0];
//Trier pour la sortie
$tabSortie = array();
foreach($tabEntete as $key){
@ -133,7 +134,8 @@ if ( count($identifiants)>0 && count($dataProfil)>0 )
$row++;
}
fclose($fp);
echo $row .' Lignes !';
fclose($fp);
}

View File

@ -8,8 +8,8 @@ define('APPLICATION_ENV', 'production');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
@ -67,45 +67,60 @@ Class extract
return ($return);
}
protected function localisationArbo($name, $liste)
protected function localisationArbo($name, $valeur)
{
foreach($liste as $valeur)
{
if(strlen($valeur) == 2) {
switch($name) {
case 'adr_reg':
$return = array();
$sql = $this->db->select()
->from('departements')
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
->where('codeRegionInsee ='.$valeur);
$result = $this->db->fetchAll($sql);
foreach ($result as $res) {
$return[] = trim($res['INSEE']);
}
break;
case 'adr_dept':
$return = array();
$sql = $this->db->select()
->from('departements')
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
->where('numdep ='.$valeur);
$result = $this->db->fetchAll($sql);
foreach ($result as $res) {
$return[] = trim($res['INSEE']);
}
break;
}
if(strlen($valeur) == 2) {
switch($name) {
case 'adr_reg':
$return = array();
$sql = $this->db->select()
->from('departements')
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
->where('codeRegionInsee ='.$valeur);
$result = $this->db->fetchAll($sql);
foreach ($result as $res) {
$return[] = trim($res['INSEE']);
}
break;
case 'adr_dept':
$return = array();
$sql = $this->db->select()
->from('departements')
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
->where('numdep ='.$valeur);
$result = $this->db->fetchAll($sql);
foreach ($result as $res) {
$return[] = trim($res['INSEE']);
}
break;
}
}
return ($return);
}
public function getMinMax($name, $valeur)
{
$valeur = explode(',', $valeur);
if(count($valeur) > 1)
{
$sql = 'SELECT min, max FROM minmax WHERE cle ="'.$name.'"';
$result = $this->db->query($sql);
$result = $result->fetchAll();
if(empty($valeur[0])){
echo $name;
$valeur[0] = $result[0]['min'];
}
if(empty($valeur[1])){
$valeur[1] = $result[0]['max'];
}
}
return ($valeur);
}
public function getCli()
{
require_once('Scores/Ciblage.php');
require_once('Scores/Field.php');
//require_once('Scores/Field.php');
$sql = 'SELECT id, idDefinition, uniteInsee FROM comptages WHERE id = '.$this->reference;
$fetch = $this->db->query($sql);
@ -119,23 +134,34 @@ Class extract
$idCriteres = $result[0]['id'];
$structure = json_decode($result[0]['criteres']);
$element = array();
$element = array();
foreach ($structure as $name => $valeur){
$type = explode(':', $valeur);
if($type[0] == 'adr_dept') {
$array['adr_com'] = $this->localisationArbo($type[0], explode(',', $type[1]));
if($name == 'adr_com') {
$liste = explode(',', $valeur);
$codes = array();
foreach ($liste as $element) {
$val = explode(':', $element);
if(!empty($val[1]))
$codes = array_merge($this->localisationArbo($val[0], $val[1]), $codes);
}
$array['adr_com'] = $codes;
}
if($name == 'cj') {
else if($name == 'cj') {
$array['cj'] = $this->getCj(explode(',', $valeur));
}
else if($name == 'ape_etab')
$array['ape_etab'] = explode(',', $structure->ape_etab);
else {
$valeur = $this->getMinMax($name, $valeur);
$array[$name] = $valeur;
}
}
$array['ape_etab'] = explode(',', $structure->ape_etab);
$ciblage = new Ciblage($array);
$res = $ciblage->execute(true);
$ciblage = new Ciblage($array, true);
$res = $ciblage->execute(true);
$data = array(
'idComptage' => $idComptage,
'idCriteres' => $idCriteres,
'idProfil' => 0,
'idProfil' => 1,
'reference' => 'batch',
'identifiants' => json_encode($res),
'nbLigneTotales' => count($res),
@ -143,14 +169,13 @@ Class extract
'uniteInsee' => $uniteInsee,
'error' => 0
);
//$this->db->insert('enrichissement_identifiants',$data);
$this->db->insert('enrichissement_identifiants',$data);
$fd = fopen($idComptage.'_batch'.date('Y-m-d-hms').'.csv', 'x+');
try {
$array = array();
foreach($res as $field) {
fputcsv($fd, array($field), ';');
}
} catch(Exception $e) {
echo $e->getMessage();
}
@ -159,5 +184,5 @@ Class extract
}
}
$a = new extract('20');
$a = new extract('36');
$a->getCli();

View File

@ -6,6 +6,7 @@ Class Ciblage
private $sphinx;
private $alpha = '';
private $presentRcs = 0;
private $need;
public $index = 'ciblage';
@ -24,18 +25,21 @@ Class Ciblage
protected function setMinMax($name, $valeur)
{
if(!empty($name)) {
$default = Fields::getMinMax($name);
if(empty($valeur[0])){$valeur[0] = $default[0]['min'];}
if(empty($valeur[1])){$valeur[1] = $default[0]['max'];}
if(!$this->need) {
if(!empty($name)) {
$default = Fields::getMinMax($name);
if(empty($valeur[0])){$valeur[0] = $default[0]['min'];}
if(empty($valeur[1])){$valeur[1] = $default[0]['max'];}
}
return ($valeur);
}
return ($valeur);
}
public function __construct($structure, $need = false)
{
$this->need = true;
$this->sphinx = new SphinxClient();
$this->sphinx->SetServer($this->sphinx_host, $this->sphinx_port);
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
@ -75,7 +79,6 @@ Class Ciblage
return ($resSphinx['total_found']);
}
protected function getSiret($structure)
{
$siret = array();
@ -190,7 +193,7 @@ Class Ciblage
}
protected function capital($valeur) {
//$valeur = $this->setMinMax($name, $valeur);
$valeur = $this->setMinMax($name, $valeur);
$this->setFilterRange('capital', $valeur);
}
@ -221,7 +224,7 @@ Class Ciblage
}
protected function teff_etab($valeur) {
$valeur = $this->setMinMax($name, $valeur);
//$valeur = $this->setMinMax($name, $valeur);
$this->setFilterRange('teff_etab', $valeur);
}

View File

@ -784,7 +784,7 @@ Class Fields
$result = $table->fetchAll($sql)->toArray();
foreach ($result as $res) {
$return[] = $res['INSEE'];
$return[] = trim($res['INSEE']);
}
break;
case 'adr_dept':
@ -796,13 +796,12 @@ Class Fields
->setIntegrityCheck(false);
$result = $table->fetchAll($sql)->toArray();
foreach ($result as $res) {
$return[] = $res['INSEE'];
$return[] = trim($res['INSEE']);
}
break;
}
} else
return (array($valeur));
return ($return);
}

View File

@ -5,7 +5,7 @@ $(document).ready(function(){
function(){ $('#control').css('display', 'none'); }
);
$('#saveciblage').on('click', function(){
$('.saveciblage').on('click', function(){
var title = 'Sauvegarde du profil de ciblage';
var href = $(this).attr('href');
var dialogOpts = {

View File

@ -15,6 +15,18 @@ em { font-style: italic }
a img { border:none } /* Gets rid of IE's blue borders */
#Valide
{
padding:5px;
border:1px solid black;
background-color:#182838;
}
#Valide a
{
color:white;
text-decoration: none;
}
/* Main
----------------------------------*/
body {