SFR : Traitrement des fichiers ligne a ligne
This commit is contained in:
parent
05ad56ba29
commit
5ced50be88
@ -137,8 +137,9 @@ if ( $opts->resume ) {
|
||||
if ( $opts->manual ) {
|
||||
|
||||
$filepath = $opts->manual;
|
||||
$pathOut = dirname($filepath);
|
||||
$pathOut = dirname(realpath($filepath));
|
||||
|
||||
$fileOptionsIn['dir'] = $pathOut;
|
||||
$fileErrorOptionsOut['dir'] = $pathOut;
|
||||
$fileOkOptionsOut['dir'] = $pathOut;
|
||||
|
||||
@ -338,7 +339,7 @@ function execFileIn($file, $fileOptionsIn, $filesOptionsOut = array(), $debug =
|
||||
$filepathIn = $fileOptionsIn['dir'] . DIRECTORY_SEPARATOR . $file;
|
||||
|
||||
//Open output file path
|
||||
foreach ($filesOutOptions as $code => $file) {
|
||||
foreach ($filesOptionsOut as $code => $file) {
|
||||
${'fp'.$code} = fopen($file['dir'] . DIRECTORY_SEPARATOR . $file['name'], 'w');
|
||||
}
|
||||
|
||||
@ -406,9 +407,8 @@ function execFileIn($file, $fileOptionsIn, $filesOptionsOut = array(), $debug =
|
||||
$filesOptionsOut[$codeRetour]['columns'] = array_keys($valuesClient['values']);
|
||||
}
|
||||
|
||||
//Write the header
|
||||
if ($rows == 2) {
|
||||
foreach ($filesOutOptions as $code => $file) {
|
||||
if ($row == 2) {
|
||||
foreach ($filesOptionsOut as $code => $file) {
|
||||
$line = array();
|
||||
//Dynamic Header
|
||||
if ( count($file['header'])>0 ) {
|
||||
@ -429,10 +429,9 @@ function execFileIn($file, $fileOptionsIn, $filesOptionsOut = array(), $debug =
|
||||
//Write the line following the return code
|
||||
$line = array();
|
||||
foreach ( $filesOptionsOut[$codeRetour]['columns'] as $i => $column ) {
|
||||
$line[] = $c[$column];
|
||||
$line[] = $valuesClient['values'][$column];
|
||||
}
|
||||
fputcsv(${'fp'.$codeRetour}, $line, $filesOptionsOut[$codeRetour]['delimiter'], $filesOptionsOut[$codeRetour]['enclosure']);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ try {
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'cron' => "Mandatory option to execute the CLI",
|
||||
'cron' => "Mandatory option to execute the CLI",
|
||||
'debug' => "Send a mail for debug",
|
||||
)
|
||||
);
|
||||
@ -53,6 +53,8 @@ $c = new Zend_Config($application->getOptions());
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
||||
|
||||
$dateBegin = date('YmdHis');
|
||||
|
||||
|
||||
$sfrdataM = new Application_Model_JoSfrData();
|
||||
|
||||
@ -77,106 +79,201 @@ if ( $result->count()>0 ) {
|
||||
//Pour chaque entité
|
||||
foreach ($result as $item) {
|
||||
|
||||
//Valider le SIREN
|
||||
//Pour chaque source - set email for the different source
|
||||
|
||||
//Est ce que la surveillance existe ?
|
||||
$survM = new Application_Model_JoSurveillancesSite();
|
||||
$row = $survM->fetchRow("login='".$login."' AND siren='".$siren."' AND source='".$source."'");
|
||||
|
||||
//Identite
|
||||
$iInsee = new MInsee();
|
||||
$tabIdentite = $iInsee->getIdentiteLight($siren, $nic);
|
||||
|
||||
if ( $row === null ) {
|
||||
//Valider le SIREN
|
||||
if ( $iInsee->valideSiren($siren) && $iInsee->sirenExiste($siren) ) {
|
||||
|
||||
//Préapration insertion dans bdd
|
||||
$data = array(
|
||||
'source' => $source,
|
||||
//Identite
|
||||
$tabIdentite = $iInsee->getIdentiteLight($siren, $nic);
|
||||
|
||||
//Est ce que la surveillance existe ?
|
||||
$survM = new Application_Model_JoSurveillancesSite();
|
||||
$row = $survM->fetchRow("login='".$login."' AND siren='".$siren."' AND source='".$source."'");
|
||||
|
||||
// N'existe pas
|
||||
if ( $row === null ) {
|
||||
|
||||
//Préapration insertion dans bdd
|
||||
$data = array(
|
||||
'source' => $source,
|
||||
'login' => $login,
|
||||
'email' => $email,
|
||||
'siren' => $siren,
|
||||
'nic' => '00000',
|
||||
'ref' => 'AUTO',
|
||||
'encoursClient' => 0,
|
||||
'rs' => $tabIdentite['Nom'],
|
||||
'cp' => $tabIdentite['CP'],
|
||||
'ville' => $tabIdentite['Ville'],
|
||||
'dateAjout'=> date('Y-m-d'),
|
||||
'dateSuppr'=> 0,
|
||||
);
|
||||
//Insert database
|
||||
$survM->insert($data);
|
||||
|
||||
// Existe
|
||||
} else {
|
||||
|
||||
//Préapration insertion dans bdd
|
||||
$data = array('dateSuppr'=> 0);
|
||||
$where = array(
|
||||
'login' => $login,
|
||||
'email' => $email,
|
||||
'siren' => $siren,
|
||||
'nic' => '00000',
|
||||
'ref' => 'AUTO',
|
||||
'encoursClient' => 0,
|
||||
'rs' => $tabIdentite['Nom'],
|
||||
'cp' => $tabIdentite['CP'],
|
||||
'ville' => $tabIdentite['Ville'],
|
||||
'dateAjout'=> date('Y-m-d'),
|
||||
'dateSuppr'=> 0,
|
||||
);
|
||||
//Insert database
|
||||
$survM->insert($data);
|
||||
|
||||
//
|
||||
} else {
|
||||
|
||||
//Préapration insertion dans bdd
|
||||
$data = array('dateSuppr'=> 0);
|
||||
$where = array(
|
||||
'login' => $login,
|
||||
'siren' => $siren,
|
||||
'source' => $source,
|
||||
);
|
||||
//Update database
|
||||
$survM->update($data, $where);
|
||||
|
||||
}
|
||||
|
||||
if ($source == 'score') {
|
||||
|
||||
//Aller chercher la valeur du score déjà calculé
|
||||
$scoresurvM = new Application_Model_JoScoresSurveillance();
|
||||
$rowscore = $scoresurvM->fetchRow("siren='".$siren."' AND source='".$source."'");
|
||||
|
||||
//Préparation des valeurs pour le fichier
|
||||
$values = array(
|
||||
'loginUti' => $login,
|
||||
'source' => $source,
|
||||
'email' => $email,
|
||||
'siren' => $siren,
|
||||
'nic' => '00000',
|
||||
'ref' => 'AUTO',
|
||||
'dateAjout' => date('Y-m-d'),
|
||||
);
|
||||
//Update database
|
||||
$survM->update($data, $where);
|
||||
|
||||
'rs' => $tabIdentite['Nom'],
|
||||
'cp' => $tabIdentite['CP'],
|
||||
'ville' => $tabIdentite['Ville'],
|
||||
}
|
||||
|
||||
'dateDerEnvoi' => '0000-00-00 00:00:00',
|
||||
'encoursClient' => 0,
|
||||
'actif' => $rowscore->actif,
|
||||
'procol' => $rowscore->procol,
|
||||
'indiScore20' => $rowscore->indiScore20,
|
||||
'encours' => $rowscore->encours,
|
||||
'indiScoreDate' => $rowscore->indiScoreDate,
|
||||
'dateBilan' => $rowscore->dateBilan,
|
||||
'indiScore20Pre' => $rowscore->indiScore20Pre,
|
||||
'encoursPre' => $rowscore->encoursPre,
|
||||
'indiScoreDatePre' => $rowscore->indiScoreDatePre,
|
||||
'sourceModif' => $rowscore->sourceModif,
|
||||
'scoreSolv' => $rowscore->scoreSolv,
|
||||
'scoreSolvPre' => $rowscore->scoreSolvPre,
|
||||
'scoreDir' => $rowscore->scoreDir,
|
||||
'scoreDirPre' => $rowscore->scoreDirPre,
|
||||
'scoreConf' => $rowscore->scoreConf,
|
||||
'scoreConfPre' => $rowscore->scoreConfPre,
|
||||
if ($source == 'score') {
|
||||
|
||||
'cj' => $tabIdentite['FJ'],
|
||||
'capital' => $tabIdentite['Capital'],
|
||||
'capitalDev' => $tabIdentite['CapitalDev'],
|
||||
'ape_entrep' => $tabIdentite['NafEnt'],
|
||||
'tca' => $tabIdentite['TrancheCA'],
|
||||
'teff_entrep' => $tabIdentite['EffEnTr'],
|
||||
//Aller chercher la valeur du score déjà calculé
|
||||
$scoresurvM = new Application_Model_JoScoresSurveillance();
|
||||
$rowscore = $scoresurvM->fetchRow("siren='".$siren."' AND source='".$source."'");
|
||||
|
||||
'dateUpdate' => $rowscore->dateUpdate,
|
||||
);
|
||||
|
||||
$fileValues[] = $values;
|
||||
} // Fin source=score
|
||||
//Préparation des valeurs pour le fichier
|
||||
$values = array(
|
||||
'loginUti' => $login,
|
||||
'source' => $source,
|
||||
'email' => $email,
|
||||
'siren' => $siren,
|
||||
'nic' => '00000',
|
||||
'ref' => 'AUTO',
|
||||
'dateAjout' => date('Y-m-d'),
|
||||
'rs' => $tabIdentite['Nom'],
|
||||
'cp' => $tabIdentite['CP'],
|
||||
'ville' => $tabIdentite['Ville'],
|
||||
'dateDerEnvoi' => '0000-00-00 00:00:00',
|
||||
'encoursClient' => 0,
|
||||
'actif' => $rowscore->actif,
|
||||
'procol' => $rowscore->procol,
|
||||
'indiScore20' => $rowscore->indiScore20,
|
||||
'encours' => $rowscore->encours,
|
||||
'indiScoreDate' => $rowscore->indiScoreDate,
|
||||
'dateBilan' => $rowscore->dateBilan,
|
||||
'indiScore20Pre' => $rowscore->indiScore20Pre,
|
||||
'encoursPre' => $rowscore->encoursPre,
|
||||
'indiScoreDatePre' => $rowscore->indiScoreDatePre,
|
||||
'sourceModif' => $rowscore->sourceModif,
|
||||
'scoreSolv' => $rowscore->scoreSolv,
|
||||
'scoreSolvPre' => $rowscore->scoreSolvPre,
|
||||
'scoreDir' => $rowscore->scoreDir,
|
||||
'scoreDirPre' => $rowscore->scoreDirPre,
|
||||
'scoreConf' => $rowscore->scoreConf,
|
||||
'scoreConfPre' => $rowscore->scoreConfPre,
|
||||
'cj' => $tabIdentite['FJ'],
|
||||
'capital' => $tabIdentite['Capital'],
|
||||
'capitalDev' => $tabIdentite['CapitalDev'],
|
||||
'ape_entrep' => $tabIdentite['NafEnt'],
|
||||
'tca' => $tabIdentite['TrancheCA'],
|
||||
'teff_entrep' => $tabIdentite['EffEnTr'],
|
||||
'dateUpdate' => $rowscore->dateUpdate,
|
||||
);
|
||||
|
||||
$fileValues[] = $values;
|
||||
} // Fin source=score
|
||||
}
|
||||
} // Fin boucle sur entités à traiter
|
||||
}
|
||||
|
||||
//Générer le fichier
|
||||
$fileOptionsOut = array(
|
||||
'dir' => $pathOut,
|
||||
'type' => 'csv',
|
||||
'delimiter' => ';',
|
||||
'enclosure' => '"',
|
||||
'header' => array(),
|
||||
'columns' => array(
|
||||
'loginUti',
|
||||
'source',
|
||||
'email',
|
||||
'siren',
|
||||
'nic',
|
||||
'ref',
|
||||
'dateAjout',
|
||||
'rs',
|
||||
'cp',
|
||||
'ville',
|
||||
'dateDerEnvoi',
|
||||
'encoursClient',
|
||||
'actif',
|
||||
'procol',
|
||||
'indiScore20',
|
||||
'encours',
|
||||
'indiScoreDate',
|
||||
'dateBilan',
|
||||
'indiScore20Pre',
|
||||
'encoursPre',
|
||||
'indiScoreDatePre',
|
||||
'sourceModif',
|
||||
'scoreSolv',
|
||||
'scoreSolvPre',
|
||||
'scoreDir',
|
||||
'scoreDirPre',
|
||||
'scoreConf',
|
||||
'scoreConfPre',
|
||||
'cj',
|
||||
'capital',
|
||||
'capitalDev',
|
||||
'ape_entrep',
|
||||
'tca',
|
||||
'teff_entrep',
|
||||
'dateUpdate',
|
||||
),
|
||||
'name' => 'CLIENTSINDISCORE_',
|
||||
'line' => $fileValues,
|
||||
);
|
||||
|
||||
|
||||
$fileOut = $fileOptionsOut['name'] . $dateBegin;
|
||||
|
||||
execFileOut($pathOut . DIRECTORY_SEPARATOR . $fileOut, $fileOptionsOut);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
*/
|
||||
function execFileOut($file, $options)
|
||||
{
|
||||
$fp = fopen($file, 'w');
|
||||
|
||||
//=> Header
|
||||
$line = array();
|
||||
//Dynamic Header
|
||||
if ( count($options['header'])>0 ) {
|
||||
foreach ( $options['header'] as $i => $column ) {
|
||||
$line[] = $column;
|
||||
}
|
||||
}
|
||||
//Static Header
|
||||
else {
|
||||
foreach ( $options['columns'] as $i => $column ) {
|
||||
$line[] = $column;
|
||||
}
|
||||
}
|
||||
fputcsv($fp, $line, $options['delimiter'], $options['enclosure']);
|
||||
|
||||
//=> Content
|
||||
if ( count($options['line'])>0 ) {
|
||||
foreach ($options['line'] as $c ) {
|
||||
$line = array();
|
||||
foreach ( $options['columns'] as $i => $column ) {
|
||||
$line[] = $c[$column];
|
||||
}
|
||||
fputcsv($fp, $line, $options['delimiter'], $options['enclosure']);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
return count($options['line']);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
- Reprise du fichier ? ou lecture dans la bdd
|
||||
|
Loading…
Reference in New Issue
Block a user