correction code naf arbo

This commit is contained in:
Damien LASSERRE 2012-01-25 13:58:07 +00:00
parent 46c7f5a8ee
commit 569150e763

View File

@ -654,7 +654,7 @@ Class Fields
if(strlen($valeur) < 5){
if($valeur[0] == 'D') {
$table = new Application_Model_Codepostaux();
$sql = $table->select()->where('Codepos LIKE "'.$valeur.'%"');
$sql = $table->select()->where('Codepos LIKE "'.substr($valeur, 1).'%"');
$codes = $table->fetchAll($sql)->toArray();
foreach($codes as $code) {
$values[] = $code['Codepos'];
@ -679,19 +679,24 @@ Class Fields
protected function nafArbo($key, $valeur)
{
$value = array();
$table = new Application_Model_Naf();
$value = array();
$table = new Application_Model_Naf();
$sql = $table->select()->from('naf')->where('parent = ?', $valeur);
$result = $sql->query();
$codes = $result->fetchAll();
foreach ($codes as $code) {
$sql = $table->select()->from('naf')->where("code LIKE '".$code['code']."%' and niveau = 5");
$result = $sql->query();
$elements = $result->fetchAll();
foreach($elements as $element) {
$value[] = $element['code'];
}
if(strlen($valeur) == 1)
{
$sql = $table->select()->where('parent = ?', $valeur);
$result =$table->fetchAll($sql)->toArray();
foreach($result as $code) $where .= " code LIKE '".$code['code']."%' and niveau = 5 or ";
$where = substr($where, 0, (strlen($where)) - 3);
$sql = $table->select()->where($where);
$result = $table->fetchAll($sql)->toArray();
foreach($result as $code) $value[] = $code['code'];
} else if(strlen($valeur) < 5){
$sql = $table->select()->where("code LIKE '".$valeur."%' and niveau = 5");
$result = $table->fetchAll($sql)->toArray();
foreach($result as $code) $value[] = $code['code'];
} else if(strlen($valeur) == 5) {
$value[] = $valeur;
}
return ($value);
}