issue #0001784 : Amélioration enrichissement avec Libellé

This commit is contained in:
Michael RICOIS 2014-06-26 08:03:40 +00:00
parent 8fddb8367e
commit c8b263041f

View File

@ -103,9 +103,8 @@ $fields = $dico->getFields();
//Entete, Valeur de remplacement et Requete SQL
$tabEntete = array('siren', 'nic');
$tabEnteteLabel = array('SIREN', 'NIC');
$sqlSelect = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,';
$sqlFrom = 'jo.etablissements_act';
$sqlWhere = '';
$columns = array('LPAD(siren, 9, 000000000) AS siren', 'LPAD(nic,5,00000) AS nic');
$joins = array();
foreach ( $dataProfil as $item ) {
//Get item
@ -118,9 +117,9 @@ foreach ( $dataProfil as $item ) {
//Construction de la requete SQL
if ( array_key_exists('sql', $field) ) {
$sqlSelect.= ' '.$field['sql'].', ';
$columns[] = $field['sql'];
} else {
$sqlSelect.= ' '.$field['column'].' AS '.$item.',';
$columns[] = $field['column'].' AS '.$item;
}
//Pour les champs de type "code", ajouter le libellé
@ -131,14 +130,17 @@ foreach ( $dataProfil as $item ) {
//Sql
$tableAlias = $item.'L';
$sqlSelect.= $tableAlias.'.'.$field['join']['column'].' AS '.$joinColumn;
$sqlFrom.= ','.$field['join']['column'].' AS '.$tableAlias;
$sqlWhere = ' AND WHERE '.$field['join']['cond'];
}
$join['name'] = $field['join']['table'].' AS '.$tableAlias;
$join['col'] = $field['join']['column'].' AS '.$joinColumn;
$join['cond'] = $field['join']['cond'];
$joins[] = $join;
}
}
}
//Ajouter le champ presentRcs
$columns = 'presentRcs';
$tabEntete[] = 'presentRcs';
$tabEnteteLabel[] = 'RCS';
$sqlFrom .= ' presentRcs';
@ -164,8 +166,15 @@ $traite = 0;
$dateStart = date('YmdHms');
foreach ($identifiants as $siret )
{
$sql = $sqlSelect . ' FROM jo.etablissements_act ' . $sqlFrom .
' WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5) . $sqlWhere;
$sql = $db->select()->from('jo.etablissements_act', $columns);
$sql->where("siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."'");
if (count($joins)) {
foreach ( $joins as $join ) {
$sql->joinLeft($join['name'], $join['cond'], $join['col']);
}
}
try {
$result = $db->fetchRow($sql);
$traite++;