Correction de l'extraction des siret pour les nafs...

This commit is contained in:
Damien LASSERRE 2012-03-28 07:40:36 +00:00
parent 976e10b434
commit fe9747f9e4

View File

@ -55,7 +55,7 @@ Class extract
} else {
$sql = $this->db->select('formejuridique', array('fjCode'))
->from('formejuridique')
->where('fjCode = "'.$valeur.'"');exit;
->where('fjCode = "'.$valeur.'"');
}
$result = $this->db->fetchAll($sql);
foreach ($result as $code) {
@ -117,6 +117,36 @@ Class extract
return ($valeur);
}
protected function nafArbo($key, $valeur)
{
$value = array();
//$table = new Table_Nafs();
$valeur = trim($valeur);
if(strlen($valeur) == 1)
{
//$sql = $table->select()->where('parent = ?', $valeur);
$sql = 'SELECT * FROM naf WHERE parent ='.$valeur;
$result =$this->db->query($sql);
$result = $result->fetchAll();
foreach($result as $code) $where .= " code LIKE '".trim($code['code'])."%' and niveau = 5 or ";
$where = substr($where, 0, (strlen($where)) - 3);
$sql = 'SELECT * FROM naf '.$where;
$result = $this->db->query($sql);
$result = $result->fetchAll();
foreach($result as $code) $value[] = $code['code'];
} else if(strlen($valeur) < 5){
//$sql = $table->select()->where('code LIKE "'.trim($valeur).'%" and niveau = 5');
$sql = 'SELECT * FROM naf WHERE code LIKE "'.trim($valeur).'%" and niveau = 5';
$result = $this->db->query($sql);
$result = $result->fetchAll();
foreach($result as $code) $value[] = $code['code'];
} else if(strlen($valeur) == 5) {
$value[] = $valeur;
}
return ($value);
}
public function getCli()
{
require_once('Scores/Ciblage.php');
@ -149,15 +179,27 @@ Class extract
else if($name == 'cj') {
$array['cj'] = $this->getCj(explode(',', $valeur));
}
else if($name == 'ape_etab')
$array['ape_etab'] = explode(',', $structure->ape_etab);
else {
else if($name == 'ape_etab') {
$values = array();
$nafs = explode(',', $structure->ape_etab);
foreach($nafs as $naf) {
if($naf != ' ') {
$values = array_merge($values, $this->nafArbo('ape_etab', $naf));
}
}
$array['ape_etab'] = $values;
}else {
$valeur = $this->getMinMax($name, $valeur);
$array[$name] = $valeur;
}
}
unset($array['vil']);
unset($array['adr_com']);
unset($array['adr_dept']);
$array['bilTca'] = array(4, 5, 6);
$ciblage = new Ciblage($array, true);
$res = $ciblage->execute(true);
$data = array(
'idComptage' => $idComptage,
'idCriteres' => $idCriteres,
@ -184,5 +226,5 @@ Class extract
}
}
$a = new extract('36');
$a = new extract('38');
$a->getCli();