Correction pour enrichissement

This commit is contained in:
Michael RICOIS 2014-06-19 07:48:54 +00:00
parent 82c098cc6a
commit 65c8980eb7
3 changed files with 243 additions and 350 deletions

View File

@ -1,157 +1,6 @@
<?php
class Enrichissement
{
/**
* Déclaration des colonnes de la table de données pour la transposition
* siren + nic + presentRcs
*/
protected $columns = array(
'id' => array(), //Non utilisé
'source' => array(),
'source_id' => array(),
'triCode' => array(),
'autre_id' => array(),
'siren' => array(), //Obligatoire
'nic' => array(), //Obligatoire
'actif' => array(
'values' => array(
'1' => "actif",
'0' => "inactif",
)
),
'siege' => array(
'values' => array(
'1' => "Etablissement Siege",
'0' => "Etablissement Secondaire",
)
),
'raisonSociale' => array(), //Raison Sociale
'enseigne' => array(), //Enseigne
'sigle' => array(), //Sigle
'identite_pre' => array(), //Identite Précédente
'marques' => array(),
'adr_num' => array(), //Adresse
'adr_btq' => array(), //Adresse
'adr_typeVoie' => array(), //Adresse
'adr_libVoie' => array(), //Adresse
'adr_comp' => array(), //Adresse - Complément
'adr_cp' => array(), //Adresse
'adr_ville' => array(), //Adresse
'adr_dep' => array(), //Département | Code Commune
'adr_com' => array(), //Code Commune
'tel' => array(), //Telephone
'fax' => array(), //Fax
'cj' => array(), //Forme Juridique
'capital' => array(),
'capitalDev' => array(),
'capitalSrc' => array(),
'ape_etab' => array(),
'ape_entrep' => array(),
'age_entrep' => array(),
'age_etab' => array(),
'tca' => array(),
'tcaexp' => array(),
'teff_entrep' => array(
'values' => array(
'NN' => "Unités non employeuses", //@todo : a vérifier NULL dans la base
'0' => "0 salarié",
'1' => "1 ou 2 salariés",
'2' => "3 à 5 salariés",
'3' => "6 à 9 salariés",
'11' => "10 à 19 salariés",
'12' => "20 à 49 salariés",
'21' => "50 à 99 salariés",
'22' => "100 à 199 salariés",
'31' => "200 à 249 salariés",
'32' => "250 à 499 salariés",
'41' => "500 à 999 salariés",
'42' => "1 000 à 1 999 salariés",
'51' => "2 000 à 4 999 salariés",
'52' => "5 000 à 9 999 salariés",
'53' => "10 000 salariés et plus",
),
),
'teff_etab' => array(
'values' => array(
'NN' => "Unités non employeuses", //@todo : a vérifier NULL dans la base
'0' => "0 salarié",
'1' => "1 ou 2 salariés",
'2' => "3 à 5 salariés",
'3' => "6 à 9 salariés",
'11' => "10 à 19 salariés",
'12' => "20 à 49 salariés",
'21' => "50 à 99 salariés",
'22' => "100 à 199 salariés",
'31' => "200 à 249 salariés",
'32' => "250 à 499 salariés",
'41' => "500 à 999 salariés",
'42' => "1 000 à 1 999 salariés",
'51' => "2 000 à 4 999 salariés",
'52' => "5 000 à 9 999 salariés",
'53' => "10 000 salariés et plus",
),
),
'rang' => array(),
'web' => array(),
'mail' => array(),
'adrDom' => array(),
'lieuAct' => array(),
'actifEco' => array(),
'presentRcs' => array(),
'procolHisto' => array(),
'tvaIntraCle' => array(),
'tvaIntraValide' => array(),
'ape4_etab' => array(),
'ape4_entrep' => array(),
'NaceEtab' => array(),
'NaceEntrep' => array(),
'dateCrea_etab' => array(),
'dateCrea_ent' => array(),
'dateImmat' => array(),
'eff_entrep' => array(),
'eff_etab' => array(),
'distSP' => array(),
'achPost' => array(),
'rivoli' => array(),
'dirCiv' => array(),
'dirNom' => array(),
'dirPrenom' => array(),
'dirDateNaiss' => array(),
'dirFct' => array(),
'nbEtab' => array(),
'nbMPubli' => array(),
'sirenGrp' => array(),
'nbActio' => array(),
'nbPart' => array(),
'bilType' => array(
'values' => array(
'1' => 'Inconnus', // I
'2' => 'Réels', // R
'3' => 'Estimés' //E
)
),
'bilAnnee' => array(),
'bilCloture' => array(),
'bilDuree' => array(),
'bilTca' => array(),
'bilEE' => array(),
'bilFL' => array(),
'bilFK' => array(),
'bilFR' => array(),
'bilGF' => array(),
'bilGP' => array(),
'bilGU' => array(),
'bilGW' => array(),
'bilHD' => array(),
'bilHH' => array(),
'bilHL' => array(),
'bilHM' => array(),
'bilHN' => array(),
'bilYP' => array(),
'avisCs' => array(),
);
/**
* Déclaration des champs exportable
* @var array
@ -160,6 +9,10 @@ class Enrichissement
'siege' => array(
'label' => "Type d'établissement",
'column' => 'siege',
'values' => array(
'1' => "Etablissement Siege",
'0' => "Etablissement Secondaire",
),
),
'raisonSociale' => array(
'label' => "Raison Sociale",
@ -220,10 +73,12 @@ class Enrichissement
'cj' => array(
'label' => "Code Forme juridique",
'column' => 'cj',
'join' => array('label'=>'Forme juridique',
'column'=>'libelle',
'table'=>'jo.tabFJur',
'stat'=>'jo.etablissements_act.cj=cj_libelle.code')
'join' => array(
'label' => 'Forme juridique',
'column' => 'libelle',
'table' => 'jo.tabFJur',
'cond' => 'jo.etablissements_act.cj = cj_libelle.code'
)
),
'dirigeant' => array(
'label' => "Dirigeant",
@ -233,17 +88,12 @@ class Enrichissement
'dirigeantFct' => array(
'label' => "Dirigeant - Code Fonction",
'column' => 'dirFct',
'join' => array('label'=>'Dirigeant - Libelle Fonction',
'column'=>'libelle',
'table'=>'jo.bodacc_fonctions',
'stat'=>'jo.etablissements_act.dirFct=dirFct_libelle.codeFct')
'join' => array(
'label' => 'Dirigeant - Libelle Fonction',
'column' => 'libelle',
'table' => 'jo.bodacc_fonctions',
'cond' => 'jo.etablissements_act.dirFct = dirFct_libelle.codeFct')
),
/*'dirigeantFct' => array(
'label' => array("Dirigeant - Code Fonction","Dirigeant - Libelle Fonction"),
'column' => 'libelle',
'sql' => array('dirFct',"jo_fonctions.libelle"),
),*/
'dirigeantnaiss' => array(
'label' => "Dirigeant - Date de naissance",
'column' => 'dirDateNaiss'
@ -251,29 +101,21 @@ class Enrichissement
'nafetablissement' => array(
'label' => "Code NAF Etablissement",
'column' => 'ape_etab',
'join' => array('Libelle NAF Etablissement',
'column'=>'libNaf5',
'table'=>'jo.tabNaf5',
'stat'=>'jo.etablissements_act.ape_etab=ape_etab_libNaf5.codNaf5')
'join' => array(
'label' => 'NAF Etablissement - Libelle',
'column' => 'libNaf5',
'table' => 'jo.tabNaf5',
'cond' => 'jo.etablissements_act.ape_etab = ape_etab_libNaf5.codNaf5')
),
/*'libNaf5_etab' => array(
'label' => "Libelle NAF Etablissement",
'column' => 'ape_etab',
'sql' => "jo_etab.libNaf5 AS etab_libNaf5",
),*/
'nafentreprise' => array(
'label' => "Code NAF Entreprise",
'column' => 'ape_entrep',
'join' => array('Libelle NAF Entreprise',
'column'=>'libNaf5',
'table'=>'jo.tabNaf5',
'stat'=>'jo.etablissements_act.ape_entrep=ape_entrep_libNaf5.codNaf5')
'join' => array(
'label' => 'NAF Entreprise - Libelle',
'column' => 'libNaf5',
'table' => 'jo.tabNaf5',
'cond' => 'jo.etablissements_act.ape_entrep = ape_entrep_libNaf5.codNaf5')
),
/*'libNaf5_entrep' => array(
'label' => "Libelle NAF Entreprise",
'column' => 'ape_entrep',
'sql' => "jo_entrep.libNaf5 AS entrep_libNaf5",
),*/
'effetablissement' => array(
'label' => "Effectif Etablissement",
'column' => 'eff_etab'
@ -284,11 +126,47 @@ class Enrichissement
),
'teffetablissement' => array(
'label' => "Code Tranche Effectif Etablissement",
'column' => 'teff_etab'
'column' => 'teff_etab',
'values' => array(
'NN' => "Unités non employeuses", //@todo : a vérifier NULL dans la base
'0' => "0 salarié",
'1' => "1 ou 2 salariés",
'2' => "3 à 5 salariés",
'3' => "6 à 9 salariés",
'11' => "10 à 19 salariés",
'12' => "20 à 49 salariés",
'21' => "50 à 99 salariés",
'22' => "100 à 199 salariés",
'31' => "200 à 249 salariés",
'32' => "250 à 499 salariés",
'41' => "500 à 999 salariés",
'42' => "1 000 à 1 999 salariés",
'51' => "2 000 à 4 999 salariés",
'52' => "5 000 à 9 999 salariés",
'53' => "10 000 salariés et plus",
),
),
'teffentreprise' => array(
'label' => "Code Tranche Effectif Entreprise",
'column' => 'teff_entrep'
'column' => 'teff_entrep',
'values' => array(
'NN' => "Unités non employeuses", //@todo : a vérifier NULL dans la base
'0' => "0 salarié",
'1' => "1 ou 2 salariés",
'2' => "3 à 5 salariés",
'3' => "6 à 9 salariés",
'11' => "10 à 19 salariés",
'12' => "20 à 49 salariés",
'21' => "50 à 99 salariés",
'22' => "100 à 199 salariés",
'31' => "200 à 249 salariés",
'32' => "250 à 499 salariés",
'41' => "500 à 999 salariés",
'42' => "1 000 à 1 999 salariés",
'51' => "2 000 à 4 999 salariés",
'52' => "5 000 à 9 999 salariés",
'53' => "10 000 salariés et plus",
),
),
'capital' => array(
'label' => "Capital",
@ -377,6 +255,11 @@ class Enrichissement
'biltype' => array(
'label' => 'Type du bilan',
'column' => 'bilType',
'values' => array(
'1' => 'Inconnus',
'2' => 'Réels',
'3' => 'Estimés'
)
),
//bilAnnee
//bilDuree
@ -393,20 +276,20 @@ class Enrichissement
public function getSql($key)
{
if ( array_key_exists($key, $this->columns) ) {
if ( array_key_exists('sql', $this->columns[$key]) ){
return $this->columns[$key]['sql'];
if ( array_key_exists($key, $this->fields) ) {
if ( array_key_exists('sql', $this->fields[$key]) ){
return $this->fields[$key]['sql'];
}
}
return false;
return false;
}
public function getColumnValue($key)
{
if ( array_key_exists($key, $this->columns) ) {
if ( array_key_exists('values', $this->columns[$key]) && count($this->columns[$key]['values'])>0 ){
return $this->columns[$key]['values'];
if ( array_key_exists($key, $this->fields) ) {
if ( array_key_exists('values', $this->fields[$key]) && count($this->fields[$key]['values'])>0 ){
return $this->fields[$key]['values'];
}
}
return false;

View File

@ -1,39 +1,69 @@
[local]
webservices.interne.wsdl = "http://webservice-2.4.sd.dev/interne/v0.3?wsdl-auto"
webservices.interne.wsdl = "http://webservice-2.7.sd.dev/interne/v0.6?wsdl-auto"
webservices.interne.options.soap_version = SOAP_1_2
webservices.entreprise.wsdl = "http://webservice-2.4.sd.dev/entreprise/v0.4?wsdl-auto"
webservices.entreprise.wsdl = "http://webservice-2.7.sd.dev/entreprise/v0.8?wsdl-auto"
webservices.entreprise.options.soap_version = SOAP_1_2
webservices.gestion.wsdl = "http://webservice-2.4.sd.dev/gestion/v0.1?wsdl-auto"
webservices.gestion.wsdl = "http://webservice-2.7.sd.dev/gestion/v0.3?wsdl-auto"
webservices.gestion.options.soap_version = SOAP_1_2
webservices.exporter.wsdl = "http://webservice-2.4.sd.dev/exporter/v0.1?wsdl-auto"
webservices.exporter.options.soap_version = SOAP_1_2
webservices.saisie.wsdl = "http://webservice-2.7.sd.dev/saisie/v0.2?wsdl-auto"
webservices.saisie.options.soap_version = SOAP_1_2
webservices.pieces.wsdl = "http://webservice-2.7.sd.dev/pieces/v0.1?wsdl-auto"
webservices.pieces.options.soap_version = SOAP_1_2
webservices.catalog.wsdl = "http://webservice-2.7.sd.dev/catalog/v0.1?wsdl-auto"
webservices.catalog.options.soap_version = SOAP_1_2
[sdsrvdev01]
webservices.interne.wsdl = "http://webservice-2.4.sd.lan/interne/v0.3?wsdl-auto"
webservices.interne.wsdl = "http://webservice-2.7.sd.lan/interne/v0.6?wsdl-auto"
webservices.interne.options.soap_version = SOAP_1_2
webservices.entreprise.wsdl = "http://webservice-2.4.sd.lan/entreprise/v0.4?wsdl-auto"
webservices.entreprise.wsdl = "http://webservice-2.7.sd.lan/entreprise/v0.8?wsdl-auto"
webservices.entreprise.options.soap_version = SOAP_1_2
webservices.gestion.wsdl = "http://webservice-2.4.sd.lan/gestion/v0.1?wsdl-auto"
webservices.gestion.wsdl = "http://webservice-2.6.sd.lan/gestion/v0.3?wsdl-auto"
webservices.gestion.options.soap_version = SOAP_1_2
webservices.exporter.wsdl = "http://webservice-2.4.sd.lan/exporter/v0.1?wsdl-auto"
webservices.exporter.options.soap_version = SOAP_1_2
webservices.saisie.wsdl = "http://webservice-2.7.sd.lan/saisie/v0.2?wsdl-auto"
webservices.saisie.options.soap_version = SOAP_1_2
webservices.pieces.wsdl = "http://webservice-2.7.sd.lan/pieces/v0.1?wsdl-auto"
webservices.pieces.options.soap_version = SOAP_1_2
webservices.catalog.wsdl = "http://webservice-2.7.sd.lan/catalog/v0.1?wsdl-auto"
webservices.catalog.options.soap_version = SOAP_1_2
[sd-25137]
webservices.interne.wsdl = "http://wse.scores-decisions.com:8081/interne/v0.3?wsdl"
webservices.interne.wsdl = "http://wse.scores-decisions.com:8081/interne/v0.6?wsdl"
webservices.interne.options.soap_version = SOAP_1_2
webservices.entreprise.wsdl = "http://wse.scores-decisions.com:8081/entreprise/v0.4?wsdl"
webservices.entreprise.wsdl = "http://wse.scores-decisions.com:8081/entreprise/v0.8?wsdl"
webservices.entreprise.options.soap_version = SOAP_1_2
webservices.gestion.wsdl = "http://wse.scores-decisions.com:8081/gestion/v0.1?wsdl"
webservices.gestion.wsdl = "http://wse.scores-decisions.com:8081/gestion/v0.3?wsdl"
webservices.gestion.options.soap_version = SOAP_1_2
webservices.exporter.wsdl = "http://wse.scores-decisions.com:8081/exporter/v0.1?wsdl"
webservices.exporter.options.soap_version = SOAP_1_2
webservices.saisie.wsdl = "http://wse.scores-decisions.com:8081/saisie/v0.2?wsdl"
webservices.saisie.options.soap_version = SOAP_1_2
webservices.pieces.wsdl = "http://wse.scores-decisions.com:8081/pieces/v0.1?wsdl"
webservices.pieces.options.soap_version = SOAP_1_2
webservices.catalog.wsdl = "http://wse.scores-decisions.com:8081/catalog/v0.1?wsdl-auto"
webservices.catalog.options.soap_version = SOAP_1_2
[celeste]
webservices.interne.wsdl = "http://wse.scores-decisions.com:8081/interne/v0.3?wsdl"
webservices.interne.wsdl = "http://wse.scores-decisions.com:8081/interne/v0.6?wsdl"
webservices.interne.options.soap_version = SOAP_1_2
webservices.entreprise.wsdl = "http://wse.scores-decisions.com:8081/entreprise/v0.4?wsdl"
webservices.entreprise.wsdl = "http://wse.scores-decisions.com:8081/entreprise/v0.8?wsdl"
webservices.entreprise.options.soap_version = SOAP_1_2
webservices.gestion.wsdl = "http://wse.scores-decisions.com:8081/gestion/v0.1?wsdl"
webservices.gestion.wsdl = "http://wse.scores-decisions.com:8081/gestion/v0.3?wsdl"
webservices.gestion.options.soap_version = SOAP_1_2
webservices.exporter.wsdl = "http://wse.scores-decisions.com:8081/exporter/v0.1?wsdl"
webservices.exporter.options.soap_version = SOAP_1_2
webservices.saisie.wsdl = "http://wse.scores-decisions.com:8081/saisie/v0.2?wsdl"
webservices.saisie.options.soap_version = SOAP_1_2
webservices.pieces.wsdl = "http://wse.scores-decisions.com:8081/pieces/v0.1?wsdl"
webservices.pieces.options.soap_version = SOAP_1_2
webservices.catalog.wsdl = "http://wse.scores-decisions.com:8081/catalog/v0.1?wsdl-auto"
webservices.catalog.options.soap_version = SOAP_1_2
[celeste-staging]
webservices.interne.wsdl = "http://wsrec.scores-decisions.com:8000/interne/v0.6?wsdl"
webservices.interne.options.soap_version = SOAP_1_2
webservices.entreprise.wsdl = "http://wsrec.scores-decisions.com:8000/entreprise/v0.8?wsdl"
webservices.entreprise.options.soap_version = SOAP_1_2
webservices.gestion.wsdl = "http://wsrec.scores-decisions.com:8000/gestion/v0.3?wsdl"
webservices.gestion.options.soap_version = SOAP_1_2
webservices.saisie.wsdl = "http://wsrec.scores-decisions.com:8000/saisie/v0.2?wsdl"
webservices.saisie.options.soap_version = SOAP_1_2
webservices.pieces.wsdl = "http://wsrec.scores-decisions.com:8000/pieces/v0.1?wsdl"
webservices.pieces.options.soap_version = SOAP_1_2
webservices.catalog.wsdl = "http://wsrec.scores-decisions.com:8000/catalog/v0.1?wsdl-auto"
webservices.catalog.options.soap_version = SOAP_1_2

View File

@ -101,52 +101,48 @@ $dico = new Enrichissement();
$fields = $dico->getFields();
//Entete, Valeur de remplacement et Requete SQL
$tabEntete = array('siret','siren', 'nic');
$tabEnteteLabel = array('SIRET','SIREN', 'NIC');
$sql = 'CONCAT(siren, nic) as siret, LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,';
$tabEntete = array('siren', 'nic');
$tabEnteteLabel = array('SIREN', 'NIC');
$sql = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,';
$from = 'jo.etablissements_act';
$addWhere = '';
foreach ( $dataProfil as $item ) {
//Définition de l'entete
$tabEnteteLabel[] = $fields[$item]['label'];
$tabEntete[] = $item;
//Construction de la requete SQL
if ( array_key_exists('sql', $fields[$item]) ) {
$sql.= ' '.$fields[$item]['sql'].', ';
} else {
$sql.= ' '.$fields[$item]['column'].' AS '.$item.',';
}
//Get item
if ( array_key_exists($item, $fields) ) {
$field = $fields[$item];
//Pour les champs de type "code", ajouter le libellé
if ( array_key_exists('join', $fields[$item]) ) {
//Définition de l'entete
$tabEnteteLabel[] = $field['label'];
$tabEntete[] = $item;
//Automatic column name .Lib
$joinColumn = $fields[$item]['join']['column'];
$colName = $fields[$item]['column'].$joinColumn;
$tabEntete[] = $colName;
//label
$tabEnteteLabel[] = $fields[$item]['join']['label'];
//Sql
$tableAlias = array($fields[$item]['column'].'_'.$joinColumn=>$fields[$item]['join']['table']);
$sql.= $fields[$item]['column'].'_'.$joinColumn.'.'.$joinColumn.' AS '.$colName.',';
$join[]= array($tableAlias,$fields[$item]['join']['stat']);
}
//Construction de la requete SQL
if ( array_key_exists('sql', $field) ) {
$sql.= ' '.$field['sql'].', ';
} else {
$sql.= ' '.$field['column'].' AS '.$item.',';
}
//Pour les champs de type "code", ajouter le libellé
if ( array_key_exists('join', $field) ) {
$tabEnteteLabel[] = $field['join']['label'];
$joinColumn = $item.'Lib';
$tabEntete[] = $joinColumn;
//Sql
$tableAlias = $item.'L';
$sql.= $tableAlias.'.'.$field['join']['column'].' AS '.$joinColumn;
$from.= ','.$field['join']['column'].' AS '.$tableAlias;
$addWhere = ' AND WHERE '.$field['join']['cond'];
}
}
}
//Ajouter le champ presentRcs
$tabEntete[] = 'presentRcs';
$tabEnteteLabel[] = 'RCS';
$sql .= ' presentRcs AS presentRcs';
$sql .= ' presentRcs';
//add Tranche Effectif
$teff_etab = $dico->getColumnValue('teff_etab');
$teff_entrep = $dico->getColumnValue('teff_entrep');
$tabEntete[] = 'teff_etabLib';
$tabEntete[] = 'teff_entrepLib';
$tabEnteteLabel[] = 'Libelle Tranche Effectif Etablissement ';
$tabEnteteLabel[] = 'Libelle Tranche Effectif Entreprise';
//Pour chaque identifiant traiter les données
$row = 0;
$fp = fopen($path.'/'.$outFile, 'w');
@ -163,51 +159,35 @@ if ($opts->id) {
"id = ".$commande->id);
}
$model = $sql;
//print_r($model);exit;
$traite = 0;
//Date de debut de traitement.
$dateStart = date('YmdHms');
$db = Zend_Db_Table::getDefaultAdapter();
$sql = $db->select()
->from($from,$model);
if($join){
foreach ($join as $params ){
$sql->joinLeft($params[0], $params[1], array());
}
}
$where = '';
foreach ($identifiants as $key=>$siret )
foreach ($identifiants as $siret )
{
if ($key>0) {
$where.=' OR ';
$sql = $model.' FROM jo.etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
try {
$result = $db->fetchRow($sql);
$traite++;
} catch(Exception $e) {
echo $sql;
}
$where.="(siren='".substr($siret,0,9)."' AND nic='".substr($siret,9,5)."')";
}
$sql->where($where);
try {
$result = $db->fetchAll($sql);
//print_r($result);exit;
} catch(Exception $e) {
echo $e;
}
foreach ($result as $tabData) {
if (array_key_exists('teffetablissement', $tabData)) {
$tabData['teff_etabLib']=$teff_etab[$tabData['teffetablissement']];
}
if(array_key_exists('teffentreprise', $tabData)){
$tabData['teff_entrepLib']=$teff_etab[$tabData['teffentreprise']];
}
if (array_key_exists('siege', $tabData)) {
($tabData[siege])?$tabData[siege]='Siège':$tabData[siege]='Secondaire';
}
$tabData = $result->toArray();
//Trier pour la sortie
$tabSortie = array();
foreach($tabEntete as $key){
foreach($tabEntete as $key) {
//Add static values
if ( array_key_exists($key, $fields) ) {
if ( array_key_exists('values', $fields[$key]) ) {
$values = $fields[$key]['values'];
//Remplace value if exist
if ( in_array($tabData[$key], $values) ) {
$tabData[$key] = $values[$tabData[$key]];
}
}
}
//Order data for CSV file
$tabSortie[] = isset($tabData[$key]) ? $tabData[$key] : '';
}
fputcsv($fp, $tabSortie, ',', '"');