2013-08-26 07:08:21 +00:00
|
|
|
<?php
|
2013-09-20 14:55:37 +00:00
|
|
|
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE ^ E_WARNING);
|
2013-09-10 16:16:55 +00:00
|
|
|
//error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);
|
2013-08-26 07:08:21 +00:00
|
|
|
// Define path to application directory
|
|
|
|
defined('APPLICATION_PATH')
|
2013-08-29 07:10:06 +00:00
|
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
2013-08-26 07:08:21 +00:00
|
|
|
|
|
|
|
// Define application environment
|
|
|
|
defined('APPLICATION_ENV')
|
2013-08-29 07:10:06 +00:00
|
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
2013-08-26 07:08:21 +00:00
|
|
|
|
|
|
|
// Ensure library/ is on include_path
|
|
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
2013-08-29 07:10:06 +00:00
|
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
|
|
get_include_path(),
|
2013-08-26 07:08:21 +00:00
|
|
|
)));
|
|
|
|
|
|
|
|
/** Zend_Application */
|
|
|
|
require_once 'Zend/Application.php';
|
|
|
|
|
|
|
|
// Create application, bootstrap, and run
|
|
|
|
$application = new Zend_Application(
|
|
|
|
APPLICATION_ENV,
|
|
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$opts = new Zend_Console_Getopt(
|
|
|
|
//Options
|
|
|
|
array(
|
2013-09-13 15:45:54 +00:00
|
|
|
'help|?' => "Displays usage information.",
|
|
|
|
'load=s' => "Preload file in database and check SIREN",
|
|
|
|
'evaluate-s' => "Lauch evaluation (specify the Seq Number to regen)",
|
2013-09-16 10:51:57 +00:00
|
|
|
'manual-s' => "Provide manualy the file path to get result and debug values",
|
2013-09-13 15:45:54 +00:00
|
|
|
'debug' => "Debug",
|
|
|
|
'cron' => "Mandatory option for launch the cli in cron",
|
2013-08-26 07:08:21 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$opts->parse();
|
|
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
|
|
echo $e->getUsageMessage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Usage
|
|
|
|
if( isset($opts->help) || count($opts->getOptions())==0 )
|
|
|
|
{
|
2013-09-13 15:45:54 +00:00
|
|
|
echo "Execute prestation SFR.\n";
|
2013-08-26 07:08:21 +00:00
|
|
|
echo $opts->getUsageMessage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once APPLICATION_PATH.'/configs/config.php';
|
|
|
|
|
|
|
|
require_once 'framework/fwk.php';
|
|
|
|
require_once 'framework/common/chiffres.php';
|
|
|
|
require_once 'framework/common/dates.php';
|
|
|
|
require_once 'framework/mail/sendMail.php';
|
|
|
|
require_once 'framework/common/mysql.php';
|
|
|
|
|
|
|
|
require_once 'Metier/insee/classMInsee.php';
|
|
|
|
require_once 'Metier/scores/classMSolvabilite.php';
|
|
|
|
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
|
2013-09-18 11:54:56 +00:00
|
|
|
$client = 'SFRBTR';
|
2013-09-16 10:51:57 +00:00
|
|
|
$typeDepot = 'SFTP';
|
|
|
|
$prestation = 'FICH_RCE';
|
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
//Input path
|
|
|
|
$pathIn = $c->profil->path->storage .
|
|
|
|
DIRECTORY_SEPARATOR . 'clients' .
|
|
|
|
DIRECTORY_SEPARATOR . strtolower($client) .
|
|
|
|
DIRECTORY_SEPARATOR . 'send';
|
|
|
|
|
|
|
|
//Output path
|
|
|
|
$pathOut = $c->profil->path->storage .
|
|
|
|
DIRECTORY_SEPARATOR . 'clients' .
|
|
|
|
DIRECTORY_SEPARATOR . strtolower($client) .
|
|
|
|
DIRECTORY_SEPARATOR . 'recv';
|
|
|
|
|
2013-09-20 14:55:37 +00:00
|
|
|
/*
|
|
|
|
* File Configuration
|
|
|
|
* Possible encoding :
|
|
|
|
* Windows-1252//TRANSLIT
|
|
|
|
* ISO-8859-15//TRANSLIT
|
|
|
|
*
|
|
|
|
*/
|
2013-08-26 07:08:21 +00:00
|
|
|
$fileOptionsIn = array(
|
2013-09-02 10:12:16 +00:00
|
|
|
'dir' => $pathIn,
|
2013-08-26 07:08:21 +00:00
|
|
|
'type' => 'csv',
|
|
|
|
'delimiter' => ';',
|
|
|
|
'enclosure' => '"',
|
|
|
|
'header' => array('idDemande', 'SSAEmetteur'),
|
|
|
|
'columns' => array('siren', 'nbLignes', 'dateContrat', 'nbContrats', 'ir'),
|
2013-09-20 14:55:37 +00:00
|
|
|
'encoding' => "Windows-1252//TRANSLIT",
|
2013-08-26 07:08:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$fileOkOptionsOut = array(
|
2013-09-02 10:12:16 +00:00
|
|
|
'dir' => $pathOut,
|
2013-08-26 07:08:21 +00:00
|
|
|
'type' => 'csv',
|
|
|
|
'delimiter' => ';',
|
|
|
|
'enclosure' => '"',
|
|
|
|
'header' => array('idDemande', 'SSAEmetteur'),
|
|
|
|
'columns' => array('siren', 'idVOR', 'PO', 'commentaire'),
|
|
|
|
'name' => 'FICH_RCE_RETOUR_',
|
2013-09-20 14:55:37 +00:00
|
|
|
'encoding' => "Windows-1252//TRANSLIT",
|
2013-08-26 07:08:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$fileErrorOptionsOut = array(
|
2013-09-02 10:12:16 +00:00
|
|
|
'dir' => $pathOut,
|
2013-08-26 07:08:21 +00:00
|
|
|
'type' => 'csv',
|
|
|
|
'delimiter' => ';',
|
|
|
|
'enclosure' => '"',
|
|
|
|
'header' => array('idDemande', 'SSAEmetteur'),
|
|
|
|
'columns' => array('siren', 'code'),
|
|
|
|
'name' => 'FICH_RCE_ERREUR_',
|
2013-09-20 14:55:37 +00:00
|
|
|
'encoding' => "Windows-1252//TRANSLIT",
|
2013-08-26 07:08:21 +00:00
|
|
|
);
|
|
|
|
|
2013-09-20 12:22:31 +00:00
|
|
|
$filePortefeuilleOptionsOut = 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_',
|
2013-09-20 14:55:37 +00:00
|
|
|
'encoding' => "Windows-1252//TRANSLIT",
|
2013-09-20 12:22:31 +00:00
|
|
|
);
|
|
|
|
|
2013-08-28 15:07:16 +00:00
|
|
|
// => Debug Mode - Create file with debug values
|
2013-08-26 07:08:21 +00:00
|
|
|
if ( $opts->manual ) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
if ( !empty($opts->manual) && $opts->manual!==true ) {
|
|
|
|
$filepath = $opts->manual;
|
|
|
|
$pathOut = dirname(realpath($filepath));
|
|
|
|
} else {
|
|
|
|
$pathOut = dirname(__FILE__);
|
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-03 14:54:52 +00:00
|
|
|
$fileOptionsIn['dir'] = $pathOut;
|
2013-09-02 10:12:16 +00:00
|
|
|
$fileErrorOptionsOut['dir'] = $pathOut;
|
|
|
|
$fileOkOptionsOut['dir'] = $pathOut;
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
$dateBegin = date('YmdHis');
|
|
|
|
$filesOutOptions = array(
|
|
|
|
'ok' => $fileOkOptionsOut,
|
|
|
|
'error' => $fileErrorOptionsOut
|
|
|
|
);
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// => Automatic mode
|
2013-09-13 15:45:54 +00:00
|
|
|
if ( $opts->cron ) {
|
2013-08-28 15:07:16 +00:00
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
/*
|
|
|
|
* @todo : Detecter si la date n'est pas trop ancienne
|
|
|
|
* Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi, Dimanche
|
|
|
|
* soir soir soir soir soir
|
|
|
|
*/
|
|
|
|
$dateNow = new Zend_Date();
|
|
|
|
$dateIn1 = $dateNow->toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
$diff = $dateNow->sub(12, Zend_Date::HOUR);
|
|
|
|
$dateIn2 = $diff->toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//client, name, typeDepot, dateDepot, fileDepot, nblignes, dateInsert, dateExecute
|
|
|
|
$fluxinM = new Application_Model_Sdv1FluxFileIn();
|
|
|
|
$sql = $fluxinM->select()
|
|
|
|
->where('client=?',$client)
|
|
|
|
->where('name=?', $prestation)
|
|
|
|
->where('typeDepot=?',$typeDepot)
|
|
|
|
->where('dateExecute=?','0000-00-00 00:00:00')
|
2013-09-16 10:51:57 +00:00
|
|
|
->where("dateInsert BETWEEN '".$dateIn2."' AND '".$dateIn1."' ")
|
2013-09-13 15:45:54 +00:00
|
|
|
->order('dateInsert DESC');
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
$pitems = $fluxinM->fetchAll($sql);
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
if ( $pitems->count()==0 ) {
|
2013-09-16 10:51:57 +00:00
|
|
|
//@todo : Aucun traitement à réaliser
|
2013-09-13 15:45:54 +00:00
|
|
|
exit;
|
2013-08-28 15:07:16 +00:00
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
foreach ($pitems as $p) {
|
|
|
|
$filepath = $pathIn . DIRECTORY_SEPARATOR . $p->fileDepot;
|
|
|
|
break;
|
2013-08-28 15:07:16 +00:00
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-08-28 15:07:16 +00:00
|
|
|
if ( !file_exists($filepath) ) {
|
|
|
|
echo "Fichier inexistant ! ".PHP_EOL;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
$opts->load = $filepath;
|
|
|
|
|
|
|
|
}
|
2013-09-02 10:12:16 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
if ($opts->load) {
|
2013-08-28 15:07:16 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Charger dans la table client AVEC vérification siren valide et existe
|
|
|
|
$seq = execDbIn($opts->load, $fileOptionsIn);
|
2013-08-28 15:07:16 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Ajouter les siren valide qui ne sont pas en surveillance
|
2013-09-16 10:51:57 +00:00
|
|
|
$sql = "INSERT IGNORE INTO jo.scores_surveillance (siren) (SELECT siren FROM jo.sfr_data WHERE error=0 AND NumSeq='".$seq."')";
|
2013-09-13 15:45:54 +00:00
|
|
|
$result = $db->query($sql);
|
|
|
|
|
|
|
|
echo "Nombre de surveillance ajoutées : ". count($result) . PHP_EOL;
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
if ( $opts->evaluate ) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
if ( !empty($opts->manual) && $opts->manual!==true ) {
|
2013-09-13 15:45:54 +00:00
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
echo "Traitement Manuel..." . PHP_EOL;
|
|
|
|
execFileIn($filepath, $fileOptionsIn, array('ok'=>$fileOkOptionsOut,'error'=>$fileErrorOptionsOut), $opts->debug);
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$nbLines = 0;
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Use Seq Number from command line
|
|
|
|
if ( $opts->evaluate !== true ) {
|
|
|
|
$seq = $opts->evaluate;
|
|
|
|
}
|
|
|
|
//Guess the last Seq Number
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
2013-09-16 10:51:57 +00:00
|
|
|
$result = $db->fetchRow('SELECT NumSeq, dateInsert FROM jo.sfr_data ORDER BY NumSeq DESC LIMIT 0,1');
|
2013-09-13 15:45:54 +00:00
|
|
|
} catch(Zend_Db_Adapter_Exception $e) {
|
|
|
|
echo $e->getMessage();
|
|
|
|
}
|
|
|
|
$seq = $result->NumSeq;
|
2013-09-16 10:51:57 +00:00
|
|
|
|
|
|
|
//Vérification date
|
|
|
|
$dateNow = new Zend_Date();
|
|
|
|
$dateInsert = new Zend_Date($result->dateInsert, 'yyyy-MM-dd HH:mm:ss');
|
|
|
|
$diff = $dateNow->sub($dateInsert);
|
|
|
|
$measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::HOUR);
|
|
|
|
if ( $measure->getValue()>12 ) {
|
|
|
|
echo "Aucun traitement à réaliser (Dernière date : ".$dateInsert->toString('yyyy-MM-dd HH:mm:ss').").".PHP_EOL;
|
|
|
|
exit;
|
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$dateBegin = date('YmdHis');
|
|
|
|
|
|
|
|
//Génération des fichiers
|
|
|
|
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
|
|
|
|
|
|
//Recherche des siren valides ainsi que leur scores
|
2013-09-16 10:51:57 +00:00
|
|
|
$sql = 'SELECT sfr.siren, sfr.DateContrat, sfr.IR,' .
|
|
|
|
' surv.actif, surv.procol, surv.naf, surv.CJ, surv.dateImmat, surv.dateCrea, surv.effectif, surv.indiScore20, surv.indiScoreDate, surv.dateUpdate' .
|
2013-09-13 15:45:54 +00:00
|
|
|
' FROM jo.sfr_data AS sfr' .
|
2013-09-16 10:51:57 +00:00
|
|
|
' LEFT JOIN jo.scores_surveillance AS surv ON sfr.siren=surv.siren' .
|
|
|
|
' WHERE sfr.error=0 AND sfr.NumSeq=\''.$seq.'\'';
|
|
|
|
|
|
|
|
echo "Recherche des SIREN valides avec leur score.".PHP_EOL;
|
2013-09-13 15:45:54 +00:00
|
|
|
$result = $db->fetchAll($sql);
|
|
|
|
|
|
|
|
if ( $result !== null ) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
echo "NbLignes=".count($result).PHP_EOL;
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
$sfrDataM = new Application_Model_JoSfrData();
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$file = $fileOkOptionsOut['dir'] . DIRECTORY_SEPARATOR . $fileOkOptionsOut['name'] . $dateBegin . '.' . $fileOkOptionsOut['type'];
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Ouverture fichier RETOUR
|
2013-09-16 10:51:57 +00:00
|
|
|
$fp = fopen($file, 'w');
|
|
|
|
|
|
|
|
require_once 'Metier/Sfr/Sfr.php';
|
|
|
|
$sfrM = new Metier_Sfr();
|
|
|
|
$sfrM->notCalculateInError = true;
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
//Header
|
2013-09-16 10:51:57 +00:00
|
|
|
if ( $opts->debug ) {
|
|
|
|
$keys = array_keys($sfrM->getValDebug());
|
|
|
|
$fileOkOptionsOut['columns'] = array_merge($fileOkOptionsOut['columns'], $keys);
|
|
|
|
$line = array();
|
|
|
|
foreach ( $fileOkOptionsOut['columns'] as $i => $column ) {
|
|
|
|
$line[] = array($seq, 'RCE');
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-18 11:54:56 +00:00
|
|
|
$line = array($seq, 'RCE');
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
2013-09-16 10:51:57 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
fputcsv($fp, $line, $fileOkOptionsOut['delimiter'], $fileOkOptionsOut['enclosure']);
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$row = 0;
|
2013-09-13 15:45:54 +00:00
|
|
|
//Content
|
|
|
|
foreach ($result as $item) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$row++;
|
|
|
|
echo "Ligne $row : ";
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Score non calculé
|
|
|
|
if ( $item->indiScore20 === null ) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$sfrDataM->update(array('error' => 2020), "siren='".$item->siren."' AND NumSeq='".$seq."'");
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
//Evaluation
|
|
|
|
else {
|
|
|
|
|
|
|
|
//Set Values
|
|
|
|
$sfrM->setVal('ContratDate', $item->DateContrat);
|
|
|
|
$sfrM->setVal('IR', $item->IR);
|
|
|
|
$sfrM->setVal('NAF', $item->naf);
|
|
|
|
$sfrM->setVal('FJ', $item->CJ);
|
|
|
|
$sfrM->setVal('InseeActif', $item->actif);
|
|
|
|
$sfrM->setVal('Effectif', $item->effectif);
|
|
|
|
$sfrM->setVal('Indiscore',$item->indiScore20);
|
|
|
|
|
|
|
|
$sfrM->setVal('DateCalculIndiscore',$item->indiScoreDate);
|
|
|
|
$sfrM->setVal('DateUpdate',$item->dateUpdate);
|
|
|
|
$sfrM->setVal('DateCrea',$item->dateCrea);
|
|
|
|
$sfrM->setVal('DateImmat',$item->dateImmat);
|
|
|
|
$sfrM->setVal('SituationJuridique',$item->procol);
|
|
|
|
|
|
|
|
//Evaluate
|
|
|
|
if ( $sfrM->evaluate($item->siren) ) {
|
2013-09-18 11:54:56 +00:00
|
|
|
$values = array();
|
|
|
|
$values['siren'] = $item->siren;
|
2013-09-13 15:45:54 +00:00
|
|
|
$values['idVOR'] = $sfrM->getIndicateur();
|
|
|
|
$values['commentaire'] = $sfrM->getComment();
|
|
|
|
$values['PO'] = $sfrM->getPo();
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
if ( $opts->debug ) {
|
2013-09-13 15:45:54 +00:00
|
|
|
$valuesDebug = $sfrM->getValDebug();
|
|
|
|
$values = array_merge($values, $valuesDebug);
|
|
|
|
}
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
echo " Siren=".$item->siren.", ID=".$values['idVOR'].", commentaire=".$values['commentaire'];
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Ecrire fichier RETOUR
|
|
|
|
$line = array();
|
|
|
|
foreach ( $fileOkOptionsOut['columns'] as $i => $column ) {
|
2013-09-20 14:55:37 +00:00
|
|
|
if ( !empty($encoding) ) {
|
|
|
|
$line[] = iconv("UTF-8", $fileOkOptionsOut['encoding'], $values[$column]);
|
|
|
|
} else {
|
|
|
|
$line[] = $values[$column];
|
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
fputcsv($fp, $line, $fileOkOptionsOut['delimiter'], $fileOkOptionsOut['enclosure']);
|
|
|
|
|
|
|
|
} else {
|
2013-09-16 10:51:57 +00:00
|
|
|
echo "- Pas de calcul";
|
|
|
|
$sfrDataM->update(array('error' => 2020), "siren='".$item->siren."' AND NumSeq='".$seq."'");
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-09-16 10:51:57 +00:00
|
|
|
echo PHP_EOL;
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$nbLines = $row;
|
|
|
|
|
|
|
|
if ( $opts->cron ) {
|
|
|
|
$fluxoutM = new Application_Model_Sdv1FluxFileOut();
|
|
|
|
$dateEnd = date('YmdHis');
|
|
|
|
$fluxoutM->insert(array(
|
|
|
|
'client' => $client,
|
|
|
|
'name' => $prestation,
|
|
|
|
'nbLines' => $nbLines,
|
|
|
|
'dateBegin' => $dateBegin,
|
|
|
|
'dateEnd' => $dateEnd,
|
|
|
|
'fileOut' => $file,
|
|
|
|
'depotType' => $typeDepot,
|
|
|
|
'depotDate' => '0000-00-00 00:00:00',
|
|
|
|
));
|
|
|
|
//Ecrire la date d'execution dans flux_filein
|
|
|
|
$fluxinM->update(array('dateExecute' => $dateEnd), 'id='.$p->id);
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Recherche des siren en erreur
|
|
|
|
$sql = 'SELECT sfr.siren, sfr.error' .
|
|
|
|
' FROM jo.sfr_data AS sfr' .
|
2013-09-18 11:54:56 +00:00
|
|
|
' WHERE sfr.error!=0 AND sfr.NumSeq=\''.$seq.'\'';
|
2013-09-16 10:51:57 +00:00
|
|
|
|
|
|
|
echo "Recherche des SIREN en erreur.".PHP_EOL;
|
2013-09-13 15:45:54 +00:00
|
|
|
$result = $db->fetchAll($sql);
|
|
|
|
|
|
|
|
if ( $result !== null ) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
echo "NbLignes=".count($result).PHP_EOL;
|
|
|
|
|
|
|
|
$file = $fileErrorOptionsOut['dir'] . DIRECTORY_SEPARATOR . $fileErrorOptionsOut['name'] . $dateBegin . '.' . $fileErrorOptionsOut['type'];
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Ouverture fichier ERREUR
|
2013-09-16 10:51:57 +00:00
|
|
|
$fp = fopen($file, 'w');
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
//Header
|
2013-09-18 11:54:56 +00:00
|
|
|
$line = array($seq, 'RCE');
|
2013-09-13 15:45:54 +00:00
|
|
|
fputcsv($fp, $line, $fileErrorOptionsOut['delimiter'], $fileErrorOptionsOut['enclosure']);
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$row = 0;
|
2013-09-13 15:45:54 +00:00
|
|
|
//Content
|
|
|
|
foreach ($result as $item) {
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$row++;
|
|
|
|
echo "Ligne $row : Siren=".$item->siren;
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
$values = array(
|
|
|
|
'siren' => $item->siren,
|
|
|
|
'code' => $item->error,
|
|
|
|
);
|
|
|
|
|
|
|
|
//Ecrire fichier ERREUR
|
|
|
|
$line = array();
|
|
|
|
foreach ( $fileErrorOptionsOut['columns'] as $i => $column ) {
|
2013-09-20 14:55:37 +00:00
|
|
|
if ( !empty($encoding) ) {
|
|
|
|
$line[] = iconv("UTF-8", $fileErrorOptionsOut['encoding'], $values[$column]);
|
|
|
|
} else {
|
|
|
|
$line[] = $values[$column];
|
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
fputcsv($fp, $line, $fileErrorOptionsOut['delimiter'], $fileErrorOptionsOut['enclosure']);
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
echo PHP_EOL;
|
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
fclose($fp);
|
2013-09-16 10:51:57 +00:00
|
|
|
|
|
|
|
$nbLines = $row;
|
|
|
|
echo "Nb Lignes Traitées : ".$nbLines.PHP_EOL;
|
|
|
|
|
|
|
|
if ( $opts->cron ) {
|
|
|
|
$fluxoutM = new Application_Model_Sdv1FluxFileOut();
|
|
|
|
$dateEnd = date('YmdHis');
|
|
|
|
$fluxoutM->insert(array(
|
|
|
|
'client' => $client,
|
|
|
|
'name' => $prestation,
|
|
|
|
'nbLines' => $nbLines,
|
|
|
|
'dateBegin' => $dateBegin,
|
|
|
|
'dateEnd' => $dateEnd,
|
|
|
|
'fileOut' => $file,
|
|
|
|
'depotType' => $typeDepot,
|
|
|
|
'depotDate' => '0000-00-00 00:00:00',
|
|
|
|
));
|
|
|
|
//Ecrire la date d'execution dans flux_filein
|
|
|
|
$fluxinM->update(array('dateExecute' => $dateEnd), 'id='.$p->id);
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Extraction du fichier PORTEFEUILLE - @todo
|
2013-09-18 11:54:56 +00:00
|
|
|
$sql = 'SELECT sfr.siren,' .
|
|
|
|
' surv.actif, surv.procol, surv.indiScore20, surv.encours, surv.indiScoreDate,' .
|
|
|
|
' surv.dateBilan, surv.indiScore20Pre, surv.encoursPre, surv.indiScoreDatePre, surv.sourceModif,' .
|
|
|
|
' surv.scoreSolv, surv.scoreSolvPre, surv.scoreDir, surv.scoreDirPre, surv.scoreConf, surv.scoreConfPre,' .
|
|
|
|
' surv.CJ, surv.naf, surv.effectif, surv.dateUpdate' .
|
2013-09-13 15:45:54 +00:00
|
|
|
' FROM jo.sfr_data AS sfr, jo.scores_surveillance AS surv' .
|
2013-09-18 11:54:56 +00:00
|
|
|
' WHERE sfr.siren=surv.siren AND sfr.error=0 AND sfr.NumSeq=\''.$seq.'\' AND indiScore20 IS NOT NULL';
|
2013-09-16 10:51:57 +00:00
|
|
|
|
|
|
|
echo "Extraction du portefeuille.".PHP_EOL;
|
2013-09-13 15:45:54 +00:00
|
|
|
$result = $db->fetchAll($sql);
|
|
|
|
|
|
|
|
if ( $result !== null ) {
|
|
|
|
|
2013-09-18 11:54:56 +00:00
|
|
|
echo "NbLignes=".count($result).PHP_EOL;
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
$file = $filePortefeuilleOptionsOut['dir'] . DIRECTORY_SEPARATOR . $filePortefeuilleOptionsOut['name'] . $dateBegin . '.' . $filePortefeuilleOptionsOut['type'];
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
//Ouverture fichier PORTEFEUILLE
|
2013-09-16 10:51:57 +00:00
|
|
|
$fp = fopen($file, 'w');
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
//Header
|
2013-09-18 11:54:56 +00:00
|
|
|
fputcsv($fp, $filePortefeuilleOptionsOut['columns'], $filePortefeuilleOptionsOut['delimiter'], $filePortefeuilleOptionsOut['enclosure']);
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
//Content
|
|
|
|
foreach ($result as $item) {
|
|
|
|
|
|
|
|
$values = array(
|
2013-09-17 07:26:46 +00:00
|
|
|
'loginUti' => 'AUTO',
|
|
|
|
'source' => 'score',
|
|
|
|
'email' => 'AUTO',
|
|
|
|
'siren' => $item->siren,
|
2013-09-18 11:54:56 +00:00
|
|
|
'nic' => '00000',
|
2013-09-17 07:26:46 +00:00
|
|
|
'ref' => 'AUTO',
|
2013-09-18 11:54:56 +00:00
|
|
|
'dateAjout' => '',
|
|
|
|
'rs' => '',
|
|
|
|
'cp' => '',
|
|
|
|
'ville' => '',
|
|
|
|
'dateDerEnvoi' => '',
|
|
|
|
'encoursClient' => '',
|
2013-09-17 07:26:46 +00:00
|
|
|
'actif' => $item->actif,
|
|
|
|
'procol' => $item->procol,
|
|
|
|
'indiScore20' => $item->indiScore20,
|
|
|
|
'encours' => $item->encours,
|
|
|
|
'indiScoreDate' => $item->indiScoreDate,
|
2013-09-20 12:22:31 +00:00
|
|
|
'dateBilan' => ($item->dateBilan == '0000-00-00 00:00:00') ? '' : $item->dateBilan,
|
2013-09-17 07:26:46 +00:00
|
|
|
'indiScore20Pre' => $item->indiScore20Pre,
|
|
|
|
'encoursPre' => $item->encoursPre,
|
2013-09-20 12:22:31 +00:00
|
|
|
'indiScoreDatePre' => ($item->indiScoreDatePre == '0000-00-00 00:00:00') ? '' : $item->indiScoreDatePre,
|
2013-09-17 07:26:46 +00:00
|
|
|
'sourceModif' => $item->sourceModif,
|
|
|
|
'scoreSolv' => $item->scoreSolv,
|
|
|
|
'scoreSolvPre' => $item->scoreSolvPre,
|
|
|
|
'scoreDir' => $item->scoreDir,
|
|
|
|
'scoreDirPre' => $item->scoreDirPre,
|
|
|
|
'scoreConf' => $item->scoreConf,
|
|
|
|
'scoreConfPre' => $item->scoreConfPre,
|
2013-09-18 11:54:56 +00:00
|
|
|
'cj' => $item->CJ,
|
|
|
|
'capital' => '',
|
|
|
|
'capitalDev' => '',
|
|
|
|
'ape_entrep' => $item->naf,
|
|
|
|
'tca' => '',
|
|
|
|
'teff_entrep' => $item->effectif,
|
2013-09-17 07:26:46 +00:00
|
|
|
'dateUpdate' => $item->dateUpdate,
|
2013-09-13 15:45:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//Ecrire fichier ERREUR
|
|
|
|
$line = array();
|
|
|
|
foreach ( $filePortefeuilleOptionsOut['columns'] as $i => $column ) {
|
2013-09-20 14:55:37 +00:00
|
|
|
if ( !empty($encoding) ) {
|
|
|
|
$line[] = iconv("UTF-8", $filePortefeuilleOptionsOut['encoding'], $values[$column]);
|
|
|
|
} else {
|
|
|
|
$line[] = $values[$column];
|
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
fputcsv($fp, $line, $filePortefeuilleOptionsOut['delimiter'], $filePortefeuilleOptionsOut['enclosure']);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
2013-09-16 10:51:57 +00:00
|
|
|
if ( $opts->cron ) {
|
|
|
|
$fluxoutM = new Application_Model_Sdv1FluxFileOut();
|
|
|
|
$dateEnd = date('YmdHis');
|
|
|
|
$fluxoutM->insert(array(
|
|
|
|
'client' => $client,
|
|
|
|
'name' => $prestation,
|
|
|
|
'nbLines' => $nbLines,
|
|
|
|
'dateBegin' => $dateBegin,
|
|
|
|
'dateEnd' => $dateEnd,
|
|
|
|
'fileOut' => $file,
|
|
|
|
'depotType' => $typeDepot,
|
|
|
|
'depotDate' => '0000-00-00 00:00:00',
|
|
|
|
));
|
|
|
|
//Ecrire la date d'execution dans flux_filein
|
|
|
|
$fluxinM->update(array('dateExecute' => $dateEnd), 'id='.$p->id);
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-08-27 08:50:25 +00:00
|
|
|
* @param array $values
|
2013-08-28 15:07:16 +00:00
|
|
|
* @param string $seq
|
2013-08-26 07:08:21 +00:00
|
|
|
* @param string $debug
|
2013-08-28 15:07:16 +00:00
|
|
|
* @return array
|
2013-08-26 07:08:21 +00:00
|
|
|
*/
|
2013-08-28 15:07:16 +00:00
|
|
|
function execInternal($values, $seq, $debug = false)
|
2013-08-26 07:08:21 +00:00
|
|
|
{
|
|
|
|
$error = 0;
|
|
|
|
|
|
|
|
$siren = $values['siren'];
|
|
|
|
|
|
|
|
echo "$siren";
|
|
|
|
|
|
|
|
$classInsee = new MInsee();
|
|
|
|
|
2013-08-28 15:07:16 +00:00
|
|
|
$values['code'] = '';
|
2013-08-26 07:08:21 +00:00
|
|
|
//Siren valide - 1010
|
|
|
|
if ( !$classInsee->valideSiren($siren) ) {
|
|
|
|
$error = 1;
|
2013-08-30 13:45:56 +00:00
|
|
|
$code = 'error';
|
2013-08-26 07:08:21 +00:00
|
|
|
$values['code'] = '1010';
|
2013-08-27 08:50:25 +00:00
|
|
|
echo " - Erreur 1010.";
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
//Siren existant - 1020
|
2013-08-27 08:50:25 +00:00
|
|
|
else if ( !$classInsee->sirenExiste($siren) ) {
|
2013-08-26 07:08:21 +00:00
|
|
|
$error = 1;
|
2013-08-30 13:45:56 +00:00
|
|
|
$code = 'error';
|
2013-08-26 07:08:21 +00:00
|
|
|
$values['code'] = '1020';
|
2013-08-27 08:50:25 +00:00
|
|
|
echo " - Erreur 1020.";
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 11:39:03 +00:00
|
|
|
//Date incorrecte - 2010
|
|
|
|
Zend_Date::setOptions(array('extend_month' => true));
|
|
|
|
if ( $values['dateContrat']!='' && Zend_Date::isDate($values['dateContrat'], array('date_format' => 'yyyyMMdd')) ) {
|
|
|
|
$error = 1;
|
|
|
|
$code = 'error';
|
|
|
|
$values['code'] = '2010';
|
|
|
|
echo " - Erreur 2010 ";
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:50:25 +00:00
|
|
|
if ( $error == 0 ) {
|
2013-08-26 07:08:21 +00:00
|
|
|
//Calculate data
|
|
|
|
require_once 'Metier/Sfr/Sfr.php';
|
|
|
|
$sfrM = new Metier_Sfr();
|
2013-09-13 15:45:54 +00:00
|
|
|
$sfrM->notCalculateInError = false;
|
2013-08-26 09:46:25 +00:00
|
|
|
|
|
|
|
//Set Values
|
2013-09-05 07:06:38 +00:00
|
|
|
$sfrM->setVal('ContratDate', $values['dateContrat']);
|
|
|
|
$sfrM->setVal('IR', $values['ir']);
|
2013-08-26 09:46:25 +00:00
|
|
|
|
|
|
|
//Evaluate
|
2013-09-13 15:45:54 +00:00
|
|
|
if ( $sfrM->evaluate($siren) ) {
|
|
|
|
$values['idVOR'] = $sfrM->getIndicateur();
|
|
|
|
$values['commentaire'] = $sfrM->getComment();
|
|
|
|
$values['PO'] = $sfrM->getPo();
|
|
|
|
|
|
|
|
$valuesDebug = $sfrM->getValDebug();
|
|
|
|
if ($debug) {
|
|
|
|
$values = array_merge($values, $valuesDebug);
|
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
$code = 'ok';
|
2013-08-30 13:45:56 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
echo " - VOR=".$values['idVOR']." , commentaire=".$values['commentaire']." , PO=".$values['PO'];
|
|
|
|
} else {
|
|
|
|
$error = 1;
|
|
|
|
$code = 'error';
|
|
|
|
$values['code'] = '2020';
|
|
|
|
echo " - Not calculated ";
|
|
|
|
}
|
2013-08-27 08:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
return array(
|
|
|
|
'values' => $values,
|
2013-08-30 13:45:56 +00:00
|
|
|
'code' => $code,
|
2013-08-26 07:08:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-09-02 10:12:16 +00:00
|
|
|
* @param string $file
|
2013-08-26 09:46:25 +00:00
|
|
|
* @param array $fileOptionsIn
|
|
|
|
* @param array $filesOptionsOut
|
|
|
|
* @param boolean $debug
|
2013-09-02 10:12:16 +00:00
|
|
|
* @param boolean $resume
|
|
|
|
* @return array
|
2013-08-26 07:08:21 +00:00
|
|
|
*/
|
2013-09-02 10:12:16 +00:00
|
|
|
function execFileIn($file, $fileOptionsIn, $filesOptionsOut = array(), $debug = false, $resume = false)
|
2013-08-26 07:08:21 +00:00
|
|
|
{
|
2013-09-16 10:51:57 +00:00
|
|
|
global $dateBegin;
|
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
//Set the input file path
|
2013-09-13 15:45:54 +00:00
|
|
|
$filepathIn = $file;
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
//Open output file path
|
2013-09-03 14:54:52 +00:00
|
|
|
foreach ($filesOptionsOut as $code => $file) {
|
2013-09-16 10:51:57 +00:00
|
|
|
${'fp'.$code} = fopen($file['dir'] . DIRECTORY_SEPARATOR . $file['name'] . $dateBegin . '.' . $file['type'], 'w');
|
2013-09-02 10:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Read file
|
|
|
|
if ( file_exists($filepathIn) ) {
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
if (($handle = fopen($filepathIn, 'r')) !== false) {
|
2013-08-26 07:08:21 +00:00
|
|
|
$row = 0;
|
|
|
|
while (($data = fgetcsv($handle, 0, $fileOptionsIn['delimiter'], $fileOptionsIn['enclosure'])) !== false)
|
|
|
|
{
|
|
|
|
$row++;
|
|
|
|
|
|
|
|
echo "Ligne $row : ";
|
|
|
|
|
|
|
|
//Header
|
|
|
|
if (count($fileOptionsIn['header']) > 0 && $row == 1) {
|
|
|
|
foreach ( $fileOptionsIn['header'] as $i => $column ) {
|
|
|
|
$header[$column] = $data[$i];
|
|
|
|
}
|
|
|
|
echo "Detection HEADER.".PHP_EOL;
|
|
|
|
|
|
|
|
if ($debug) {
|
2013-09-02 10:12:16 +00:00
|
|
|
$filesOptionsOut['error']['header'] = array();
|
|
|
|
$filesOptionsOut['ok']['header'] = array();
|
2013-08-26 07:08:21 +00:00
|
|
|
} else {
|
2013-09-02 10:12:16 +00:00
|
|
|
$filesOptionsOut['error']['header'] = $header;
|
|
|
|
$filesOptionsOut['ok']['header'] = $header;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $resume ) {
|
|
|
|
fputcsv(${'fp'.$codeRetour}, $filesOptionsOut['ok']['line'][0], $filesOptionsOut['ok']['delimiter'], $filesOptionsOut['ok']['enclosure']);
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Content
|
|
|
|
else {
|
|
|
|
|
2013-08-27 08:50:25 +00:00
|
|
|
//Set values from file
|
2013-08-26 07:08:21 +00:00
|
|
|
$values = array();
|
|
|
|
foreach ( $fileOptionsIn['columns'] as $i => $column ) {
|
|
|
|
$values[$column] = $data[$i];
|
|
|
|
}
|
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
$isResume = false;
|
2013-08-26 07:08:21 +00:00
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
if ( $resume ) {
|
|
|
|
foreach ( $filesOptionsOut['ok']['line'] as $line ) {
|
|
|
|
if ( $line[0] == $data[0] ) {
|
|
|
|
fputcsv(${'fp'.$codeRetour}, $line, $filesOptionsOut['ok']['delimiter'], $filesOptionsOut['ok']['enclosure']);
|
|
|
|
$isResume = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 10:12:16 +00:00
|
|
|
if ( !$isResume ) {
|
|
|
|
|
|
|
|
//Exec the process
|
|
|
|
$valuesClient = execInternal($values, $header['idDemande'], true);
|
|
|
|
|
|
|
|
//Format output
|
|
|
|
$codeRetour = $valuesClient['code'];
|
2013-09-10 16:16:55 +00:00
|
|
|
//$filesOptionsOut[$codeRetour]['line'][] = $valuesClient['values'];
|
2013-09-02 10:12:16 +00:00
|
|
|
if ($debug) {
|
|
|
|
$filesOptionsOut[$codeRetour]['columns'] = array_keys($valuesClient['values']);
|
|
|
|
}
|
|
|
|
|
2013-09-03 14:54:52 +00:00
|
|
|
if ($row == 2) {
|
|
|
|
foreach ($filesOptionsOut as $code => $file) {
|
2013-09-02 10:12:16 +00:00
|
|
|
$line = array();
|
|
|
|
//Dynamic Header
|
|
|
|
if ( count($file['header'])>0 ) {
|
|
|
|
foreach ( $file['header'] as $i => $column ) {
|
|
|
|
$line[] = $column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Static Header
|
|
|
|
else {
|
|
|
|
foreach ( $file['columns'] as $i => $column ) {
|
|
|
|
$line[] = $column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputcsv(${'fp'.$code}, $line, $filesOptionsOut[$code]['delimiter'], $filesOptionsOut[$code]['enclosure']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Write the line following the return code
|
|
|
|
$line = array();
|
|
|
|
foreach ( $filesOptionsOut[$codeRetour]['columns'] as $i => $column ) {
|
2013-09-03 14:54:52 +00:00
|
|
|
$line[] = $valuesClient['values'][$column];
|
2013-09-02 10:12:16 +00:00
|
|
|
}
|
|
|
|
fputcsv(${'fp'.$codeRetour}, $line, $filesOptionsOut[$codeRetour]['delimiter'], $filesOptionsOut[$codeRetour]['enclosure']);
|
|
|
|
}
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
fclose($handle);
|
|
|
|
|
2013-09-10 16:16:55 +00:00
|
|
|
foreach ($filesOptionsOut as $code => $file) {
|
2013-09-02 10:12:16 +00:00
|
|
|
fclose(${'fp'.$code});
|
|
|
|
}
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
/**
|
2013-09-13 15:45:54 +00:00
|
|
|
* Load in database
|
2013-08-27 08:50:25 +00:00
|
|
|
* @param string $file
|
2013-09-13 15:45:54 +00:00
|
|
|
* @param array $fileOptionsIn
|
|
|
|
* @param array $filesOptionsOut
|
|
|
|
* @param boolean $debug
|
|
|
|
* @param boolean $resume
|
|
|
|
* @return array
|
2013-08-26 07:08:21 +00:00
|
|
|
*/
|
2013-09-13 15:45:54 +00:00
|
|
|
function execDbIn($file, $fileOptionsIn, $debug = false)
|
2013-08-26 07:08:21 +00:00
|
|
|
{
|
2013-09-13 15:45:54 +00:00
|
|
|
//Set the input file path
|
|
|
|
//$filepathIn = $fileOptionsIn['dir'] . DIRECTORY_SEPARATOR . $file;
|
|
|
|
$filepathIn = $file;
|
|
|
|
|
|
|
|
//Read file
|
|
|
|
if ( file_exists($filepathIn) ) {
|
|
|
|
|
|
|
|
$sfrDataM = new Application_Model_JoSfrData();
|
|
|
|
|
|
|
|
if (($handle = fopen($filepathIn, 'r')) !== false) {
|
|
|
|
$row = 0;
|
|
|
|
while (($data = fgetcsv($handle, 0, $fileOptionsIn['delimiter'], $fileOptionsIn['enclosure'])) !== false)
|
|
|
|
{
|
|
|
|
$row++;
|
|
|
|
|
|
|
|
echo "Ligne $row : ";
|
|
|
|
|
|
|
|
//Header
|
|
|
|
if (count($fileOptionsIn['header']) > 0 && $row == 1) {
|
|
|
|
foreach ( $fileOptionsIn['header'] as $i => $column ) {
|
|
|
|
$header[$column] = $data[$i];
|
|
|
|
}
|
|
|
|
echo "Detection HEADER.".PHP_EOL;
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
$filesOptionsOut['error']['header'] = array();
|
|
|
|
$filesOptionsOut['ok']['header'] = array();
|
|
|
|
} else {
|
|
|
|
$filesOptionsOut['error']['header'] = $header;
|
|
|
|
$filesOptionsOut['ok']['header'] = $header;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Content
|
|
|
|
else {
|
|
|
|
|
|
|
|
//Set values from file
|
|
|
|
$values = array();
|
|
|
|
foreach ( $fileOptionsIn['columns'] as $i => $column ) {
|
|
|
|
$values[$column] = $data[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Exec the process
|
|
|
|
$values = execDbInternal($values);
|
|
|
|
$sfrDataM->insert(array(
|
|
|
|
'NumSeq' => $header['idDemande'],
|
|
|
|
'siren' => $values['siren'],
|
|
|
|
'NbLignes' => $values['nbLignes'],
|
|
|
|
'NbContrats' => $values['nbContrats'],
|
|
|
|
'DateContrat' => $values['dateContrat'],
|
|
|
|
'IR' => $values['ir'],
|
|
|
|
'IdVOR' => '',
|
|
|
|
'comment' => '',
|
|
|
|
'PO' => 0,
|
|
|
|
'debug' => '',
|
|
|
|
'error' => $values['code'],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
return $header['idDemande'];
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function execDbInternal($values, $debug = false)
|
|
|
|
{
|
|
|
|
$error = 0;
|
|
|
|
|
|
|
|
$siren = $values['siren'];
|
|
|
|
|
|
|
|
echo "$siren";
|
|
|
|
|
|
|
|
$classInsee = new MInsee();
|
|
|
|
|
|
|
|
$values['code'] = '';
|
|
|
|
|
|
|
|
//Siren valide - 1010
|
|
|
|
if ( !$classInsee->valideSiren($siren) ) {
|
|
|
|
$error = 1;
|
|
|
|
$code = 'error';
|
|
|
|
$values['code'] = '1010';
|
|
|
|
echo " - Erreur 1010.";
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Siren existant - 1020
|
|
|
|
else if ( !$classInsee->sirenExiste($siren) ) {
|
|
|
|
$error = 1;
|
|
|
|
$code = 'error';
|
|
|
|
$values['code'] = '1020';
|
|
|
|
echo " - Erreur 1020.";
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
2013-08-26 09:46:25 +00:00
|
|
|
|
2013-09-13 15:45:54 +00:00
|
|
|
//Date incorrecte - 2010
|
|
|
|
Zend_Date::setOptions(array('extend_month' => true));
|
|
|
|
if ( $values['dateContrat']!='' && Zend_Date::isDate($values['dateContrat'], array('date_format' => 'yyyyMMdd')) ) {
|
|
|
|
$error = 1;
|
|
|
|
$code = 'error';
|
|
|
|
$values['code'] = '2010';
|
|
|
|
echo " - Erreur 2010 ";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
|
|
|
return $values;
|
2013-08-26 07:08:21 +00:00
|
|
|
}
|
2013-09-13 15:45:54 +00:00
|
|
|
|