diff --git a/application/bin.bootstrap.php b/application/bin.bootstrap.php new file mode 100644 index 00000000..1c2b51be --- /dev/null +++ b/application/bin.bootstrap.php @@ -0,0 +1,40 @@ +getOptions()); +Zend_Registry::set('config', $c); + +// Database - Zend Style +$db = Zend_Db::factory($c->profil->db->metier); +Zend_Db_Table_Abstract::setDefaultAdapter($db); + +// Database - Doctrine Style +$config = new \Doctrine\DBAL\Configuration(); +$connectionParams = array( + 'dbname' => $c->profil->db->metier->params->dbname, + 'user' => $c->profil->db->metier->params->username, + 'password' => $c->profil->db->metier->params->password, + 'host' => $c->profil->db->metier->params->host, + 'charset' => 'utf8', + 'driver' => 'pdo_mysql', +); + +try { + $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); + Zend_Registry::set('doctrine', $conn); +} catch (\Doctrine\DBAL\DBALException $e) { + echo "Connection Database impossible.\n"; + exit; +} \ No newline at end of file diff --git a/scripts/build/genCache.php b/bin/buildCache.php similarity index 89% rename from scripts/build/genCache.php rename to bin/buildCache.php index 2a018f04..69919335 100644 --- a/scripts/build/genCache.php +++ b/bin/buildCache.php @@ -1,17 +1,5 @@ "Generate the specify cache.", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -62,25 +51,6 @@ if ( $opts->list ) { exit; } -// Database -$c = new Zend_Config($application->getOptions()); -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - /** * Cache des Tribunaux Bodacc */ diff --git a/scripts/build/genCodeRatios.php b/bin/buildCodeRatios.php similarity index 96% rename from scripts/build/genCodeRatios.php rename to bin/buildCodeRatios.php index c42dfea8..38121107 100644 --- a/scripts/build/genCodeRatios.php +++ b/bin/buildCodeRatios.php @@ -1,17 +1,5 @@ "Tab in cache", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -44,27 +33,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -// Database -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - // Fichier MRatios if (isset($opts->ratios)) { diff --git a/bin/buildCodeSfr.php b/bin/buildCodeSfr.php new file mode 100644 index 00000000..cd16d087 --- /dev/null +++ b/bin/buildCodeSfr.php @@ -0,0 +1,47 @@ + "Aide.", + 'compile-s' => "Génére le cache des règles, sans paramètres (tout), avec paramètres (VORD, VORP, PO)", + 'version=s' => "Version des régles", + )); + $opts->parse(); + $optionsNb = count($opts->getOptions()); +} catch (Zend_Console_Getopt_Exception $e) { + $displayUsage = true; +} + +// --- Aide / Options +if ($optionsNb == 0 || isset($opts->help)) { + $displayUsage = true; +} + +// --- Usage +if ($displayUsage) { + echo "\nRegles SFR\n\n"; + echo $opts->getUsageMessage(); + exit; +} + +$types = array('VORD', 'VORP', 'PO'); + +if ( $opts->compile!='' && in_array($opts->compile, $types) ) { + $types = array($opts->compile); +} + +if ( count($types) > 0 ) { + + foreach ( $types as $type ) { + $ruleSfrM = new Metier_Sfr_Compile($conn); + $ruleSfrM->setVersion($opts->version); + $ruleSfrM->construct($type); + } + +} + + + diff --git a/scripts/build/genLog.php b/bin/buildLog.php similarity index 53% rename from scripts/build/genLog.php rename to bin/buildLog.php index 9fa1a730..32bba05b 100644 --- a/scripts/build/genLog.php +++ b/bin/buildLog.php @@ -1,17 +1,5 @@ "", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -38,25 +27,6 @@ if ($displayUsage) { } if ($opts->log) { - // Database - $c = new Zend_Config($application->getOptions()); - $config = new \Doctrine\DBAL\Configuration(); - $connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', - ); - - try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); - } catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; - } - $sql = "SELECT * FROM sdv1.logs_item"; $stmt = $conn->prepare($sql); $stmt->execute(); diff --git a/scripts/build/genTypes.php b/bin/buildTypes.php similarity index 63% rename from scripts/build/genTypes.php rename to bin/buildTypes.php index f535126f..0d6b443f 100644 --- a/scripts/build/genTypes.php +++ b/bin/buildTypes.php @@ -1,17 +1,5 @@ "{Service Name}/{version}", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } diff --git a/scripts/jobs/removeTempFile.php b/bin/cleanTemp.php similarity index 57% rename from scripts/jobs/removeTempFile.php rename to bin/cleanTemp.php index 6723b269..8a88b598 100644 --- a/scripts/jobs/removeTempFile.php +++ b/bin/cleanTemp.php @@ -1,26 +1,8 @@ getOptions()); -Zend_Registry::set('config', $c); - -require_once 'WsScore/Configure.php'; -$oldconfig = new Configure(); - $typesFichier = array('csv', 'fichiers', 'clients', 'kbis'); // --- Options @@ -32,12 +14,13 @@ try { 'type=w' => 'Supprime uniquement les fichiers indiqués.', )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } diff --git a/scripts/jobs/getGreffe.php b/bin/greffe.php similarity index 93% rename from scripts/jobs/getGreffe.php rename to bin/greffe.php index 1cebe695..e9dffd37 100644 --- a/scripts/jobs/getGreffe.php +++ b/bin/greffe.php @@ -1,17 +1,5 @@ "Control", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -43,32 +32,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - if (APPLICATION_ENV == 'development') { - echo '
'; print_r($e); echo ''; - } else { - echo "Le service rencontre actuellement un problème technique."; - } - exit; -} -Zend_Registry::set('doctrine', $conn); - $testMail = false; $test = false; diff --git a/scripts/jobs/getKbis.php b/bin/kbis.php similarity index 96% rename from scripts/jobs/getKbis.php rename to bin/kbis.php index 9f639fb4..d46552ca 100644 --- a/scripts/jobs/getKbis.php +++ b/bin/kbis.php @@ -1,18 +1,6 @@ #!/usr/bin/php parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { +if ($optionsNb == 0 || isset($opts->help)) { $displayUsage = true; } @@ -46,9 +35,6 @@ if ($displayUsage) { exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - if ( isset($opts->debug) ) { define('DEBUG', true); } else { diff --git a/scripts/jobs/getKbis2.php b/bin/kbis2.php similarity index 97% rename from scripts/jobs/getKbis2.php rename to bin/kbis2.php index 07a1b639..3feb0aec 100644 --- a/scripts/jobs/getKbis2.php +++ b/bin/kbis2.php @@ -1,4 +1,6 @@ parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); exit; } -$c = new Zend_Config($application->getOptions()); -Zend_Registry::set('config', $c); - -if ( isset($opts->debug) ) { - define('DEBUG', true); -} else { - define('DEBUG', false); +// --- Aide / Options +if ($optionsNb == 0 || isset($opts->help)) { + $displayUsage = true; } -//Usage -if(count($opts->getOptions())==0 || isset($opts->help)) -{ +// --- Usage +if ($displayUsage) { echo "Telecharge le kbis chez infogreffe."; echo "\n\n"; echo $opts->getUsageMessage(); @@ -57,6 +41,12 @@ if(count($opts->getOptions())==0 || isset($opts->help)) exit; } +if ( isset($opts->debug) ) { + define('DEBUG', true); +} else { + define('DEBUG', false); +} + /* 338 437 189 diff --git a/scripts/build/loadCodeRatios.php b/bin/loadCodeRatios.php similarity index 93% rename from scripts/build/loadCodeRatios.php rename to bin/loadCodeRatios.php index 08843120..0c09032c 100644 --- a/scripts/build/loadCodeRatios.php +++ b/bin/loadCodeRatios.php @@ -1,17 +1,5 @@ "Affiche resultat traitement " )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { + $displayUsage = true; +} + +// --- Aide / Options +if ($optionsNb == 0 || isset($opts->help)) { + $displayUsage = true; +} + +// --- Usage +if ($displayUsage) { + echo "Charge les commentaires ratios à partir de CSV."; + echo "\n\n"; echo $opts->getUsageMessage(); + echo "\n"; exit; } - //Usage - if( count($opts->getOptions())==0 || isset($opts->help)) - { - echo $opts->getUsageMessage(); - exit; - } - ######################################################### + ######################################################### ##### Presence te taille du fichier ##### ######################################################### diff --git a/scripts/jobs/sql2csv.php b/bin/sql2csv.php similarity index 51% rename from scripts/jobs/sql2csv.php rename to bin/sql2csv.php index 924f009b..6254848d 100644 --- a/scripts/jobs/sql2csv.php +++ b/bin/sql2csv.php @@ -1,17 +1,5 @@ "", )); $opts->parse(); + $optionsNb = count($opts->getOptions()); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } @@ -40,25 +29,6 @@ if ($displayUsage) { use League\Csv\Writer; -// Database -$c = new Zend_Config($application->getOptions()); -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => 'sdv1', - 'user' => 'wsuser', - 'password' => 'wspass2012', - 'host' => '195.154.170.169', - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - echo "Connection Database impossible.\n"; - exit; -} - $sql = file_get_contents($opts->sqlfile); //we fetch the info from a DB using a PDO object diff --git a/library/Metier/Insee/MInsee.php b/library/Metier/Insee/MInsee.php index cf3c7002..b23758e0 100644 --- a/library/Metier/Insee/MInsee.php +++ b/library/Metier/Insee/MInsee.php @@ -4966,13 +4966,9 @@ class Metier_Insee_MInsee extends Metier_Insee_Table // --- Liste des jugements principaux - Tri chronologique par date de jugement foreach ($tabRet as $i => $ann) { $item = new stdClass(); - $dateEff = str_replace('-', '', $ann['dateEffet'])*1; $dateJug = str_replace('-', '', $ann['dateJugement'])*1; $datePar = str_replace('-', '', $ann['DateParution'])*1; - if ($dateEff > 0) { - $item->date = $dateEff; - $item->dateISO8601 = $ann['dateEffet']; - } elseif ($dateJug > 0) { + if ($dateJug > 0) { $item->date = $dateJug; $item->dateISO8601 = $ann['dateJugement']; } elseif ($datePar > 0) { diff --git a/library/Metier/Sfr/Scoring.php b/library/Metier/Sfr/Scoring.php index 2fc858c0..49ea1f3a 100644 --- a/library/Metier/Sfr/Scoring.php +++ b/library/Metier/Sfr/Scoring.php @@ -417,7 +417,7 @@ class Metier_Sfr_Scoring $this->conn = $conn; } - //Charger les Rules (dans l'ordre) + // Charger les Rules (dans l'ordre) $this->RulesVORP = include realpath(dirname(__FILE__)) . '/RulesVorp-'.$this->version.'.php'; $this->RulesVORD = include realpath(dirname(__FILE__)) . '/RulesVord-'.$this->version.'.php'; $this->RulesPO = include realpath(dirname(__FILE__)) . '/RulesPo-'.$this->version.'.php'; @@ -433,7 +433,7 @@ class Metier_Sfr_Scoring file_put_contents('sfr.log', "SIREN = $siren\n", FILE_APPEND); } - //Set ValContratAge + // Set ValContratAge if (!empty($this->ValContratDate)) { $dateContrat = DateTime::createFromFormat('Ymd', $this->ValContratDate); $dateNow = new DateTime(); diff --git a/library/Scores/Ws/Server.php b/library/Scores/Ws/Server.php index d86543cc..89736fcf 100644 --- a/library/Scores/Ws/Server.php +++ b/library/Scores/Ws/Server.php @@ -90,14 +90,14 @@ class Scores_Ws_Server * @var array */ protected $listePrefs = array( - 'NAF4' => "Afficher les anciens NAF", - 'NACE' => "Afficher les codes NACES", - 'NEWS' => "Afficher les news Google©", - 'MAPPY' => "Afficher les façades d'immeubles", + 'NAF4' => "Afficher les anciens NAF", + 'NACE' => "Afficher les codes NACES", + 'NEWS' => "Afficher les news Google©", + 'MAPPY' => "Afficher les façades d'immeubles", 'CARTES' => "Afficher les cartes et les plans", - 'VOIRSURV' => "Afficher les entités sous surveillances", + 'VOIRSURV' => "Afficher les entités sous surveillances", 'DEMANDEREF' => "Demande de référence par defaut", - 'RECHREF' => "Afficher le formulaire de recherche par référence", + 'RECHREF' => "Afficher le formulaire de recherche par référence", ); /** diff --git a/library/WsScore/Clients/Sfr/v0.1/Service.php b/library/WsScore/Clients/Sfr/v0.1/Service.php index f2a36bf0..e50a9e91 100644 --- a/library/WsScore/Clients/Sfr/v0.1/Service.php +++ b/library/WsScore/Clients/Sfr/v0.1/Service.php @@ -40,6 +40,22 @@ class Entreprise extends Scores_Ws_Server $sfrM = new Metier_Sfr_Scoring(); $sfrM->setVersion('1.4'); $sfrM->forceIdentite = true; + + // Data SFR + try { + $sql = "SELECT sfr.DateContrat, sfr.IR FROM jo.sfr_data AS sfr + WHERE sfr.error=0 AND sfr.siren=:siren ORDER BY sfr.dateInsert DESC LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $contrat = $stmt->fetch(\PDO::FETCH_OBJ); + //Set Values + $sfrM->setVal('ContratDate', $contrat->DateContrat); + $sfrM->setVal('IR', $contrat->IR); + } + } catch(\Doctrine\DBAL\DBALException $e) {} + $sfrM->evaluate($siren); //Calculate diff --git a/library/WsScore/Clients/Sfr/v0.2/Service.php b/library/WsScore/Clients/Sfr/v0.2/Service.php index f2a36bf0..8bebb194 100644 --- a/library/WsScore/Clients/Sfr/v0.2/Service.php +++ b/library/WsScore/Clients/Sfr/v0.2/Service.php @@ -40,6 +40,22 @@ class Entreprise extends Scores_Ws_Server $sfrM = new Metier_Sfr_Scoring(); $sfrM->setVersion('1.4'); $sfrM->forceIdentite = true; + + // Data SFR + try { + $sql = "SELECT sfr.DateContrat, sfr.IR FROM jo.sfr_data AS sfr + WHERE sfr.error=0 AND sfr.siren=:siren ORDER BY sfr.dateInsert DESC LIMIT 0,1"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $siren); + $stmt->execute(); + if ($stmt->rowCount() > 0) { + $contrat = $stmt->fetch(\PDO::FETCH_OBJ); + //Set Values + $sfrM->setVal('ContratDate', $contrat->DateContrat); + $sfrM->setVal('IR', $contrat->IR); + } + } catch(\Doctrine\DBAL\DBALException $e) {} + $sfrM->evaluate($siren); //Calculate diff --git a/library/WsScore/Entreprise/v0.8/Service.php b/library/WsScore/Entreprise/v0.8/Service.php index 3a191b93..b2f12591 100644 --- a/library/WsScore/Entreprise/v0.8/Service.php +++ b/library/WsScore/Entreprise/v0.8/Service.php @@ -2254,11 +2254,17 @@ class Entreprise extends Scores_Ws_Server $tabRet = array(); $this->logger->info("IndiScore demandée pour $siren en niveau $niveau"); - if (strlen($siren)>9 || (substr($siren,0,9)*1)<100 ){ + if (strlen($siren) > 9 || (substr($siren,0,9)*1) < 100 ){ $this->logger->warning( "Siren $siren incorrect"); $this->sendError('1010'); } + $iInsee = new Metier_Insee_MInsee(); + $result = $iInsee->getIdentiteLight($siren); + if (count($result) == 0) { + throw new SoapFault('ERR', "SIREN invalid"); + } + $tDeb = microtime(true); require_once 'Metier/Scores/MScores.php'; $tabRet = calculIndiScore($siren, $nic, $accesDist, $niveau, false, 'scores'); diff --git a/library/WsScore/Gestion/v0.3/Service.php b/library/WsScore/Gestion/v0.3/Service.php index 03d329af..084c3f15 100644 --- a/library/WsScore/Gestion/v0.3/Service.php +++ b/library/WsScore/Gestion/v0.3/Service.php @@ -940,7 +940,7 @@ class Gestion extends Scores_Ws_Server AND l.login=u.login AND u.idClient=c.id ORDER BY l.login ASC, l.dateHeure ASC"; file_put_contents($c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql", $sql); - exec("php ".APPLICATION_PATH."/../scripts/jobs/sql2csv.php --sqlfile ".$c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql --csvfile $fichierCsv > /dev/null &"); + exec("php ".APPLICATION_PATH."/../bin/sql2csv.php --sqlfile ".$c->profil->path->shared."/files/logs-$annee-$mois-$detail-$idClient-$login-$all.sql --csvfile $fichierCsv > /dev/null &"); $size = $cache = 0; } diff --git a/library/WsScore/Interne/v0.6/Service.php b/library/WsScore/Interne/v0.6/Service.php index 4e3a4c0b..d97da90a 100644 --- a/library/WsScore/Interne/v0.6/Service.php +++ b/library/WsScore/Interne/v0.6/Service.php @@ -1338,7 +1338,7 @@ class Interne extends Scores_Ws_Server $c = Zend_Registry::get('config'); $path = $c->profil->path->shared.'/files'; file_put_contents($path."/listesurv-$source-$login-$idClient.sql", $sql); - exec("php ".APPLICATION_PATH."/../scripts/jobs/sql2csv.php --sqlfile ".$path."/listesurv-$source-$login-$idClient.sql --csvfile $fichierCsv > /dev/null &"); + exec("php ".APPLICATION_PATH."/../bin/sql2csv.php --sqlfile ".$path."/listesurv-$source-$login-$idClient.sql --csvfile $fichierCsv > /dev/null &"); $size=$cache=0; } diff --git a/library/WsScore/Pieces/v0.1/Service.php b/library/WsScore/Pieces/v0.1/Service.php index 7e478b24..055faf1d 100644 --- a/library/WsScore/Pieces/v0.1/Service.php +++ b/library/WsScore/Pieces/v0.1/Service.php @@ -115,7 +115,7 @@ class Pieces extends Scores_Ws_Server //Téléchargement du KBIS $result = array(); - exec('php '.APPLICATION_PATH.'/../scripts/jobs/getKbis.php --siren '.$siren, $result); + exec('php '.APPLICATION_PATH.'/../bin/kbis.php --siren '.$siren, $result); $result = end($result); if (substr($result,-5) == '.html') { $file = $dir.'/'.$result; diff --git a/scripts/build/genCodeSfr.php b/scripts/build/genCodeSfr.php deleted file mode 100644 index f831e046..00000000 --- a/scripts/build/genCodeSfr.php +++ /dev/null @@ -1,75 +0,0 @@ - "Aide.", - 'compile-s' => "Génére le cache des règles, sans paramètres (tout), avec paramètres (VORD, VORP, PO)", - 'version=s' => "Version des régles", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "\nRegles SFR\n\n"; - echo $opts->getUsageMessage(); - exit; -} - -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $application->profil->db->metier->params->dbname, - 'user' => $application->profil->db->metier->params->username, - 'password' => $application->profil->db->metier->params->password, - 'host' => $application->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - exit; -} - -$types = array('VORD', 'VORP', 'PO'); - -if ( $opts->compile!='' && in_array($opts->compile, $types) ) { - $types = array($opts->compile); -} - -if ( count($types) > 0 ) { - - foreach ( $types as $type ) { - $ruleSfrM = new Metier_Sfr_Compile($conn); - $ruleSfrM->setVersion($opts->version); - $ruleSfrM->construct($type); - } - -} - - - diff --git a/scripts/jobs/filesGreffes.php b/scripts/jobs/filesGreffes.php deleted file mode 100644 index 55abd04e..00000000 --- a/scripts/jobs/filesGreffes.php +++ /dev/null @@ -1,581 +0,0 @@ - "Affiche l'aide.", - 'acte' => "Traitement des actes ", - 'bilan-s' => "Traitement des bilans (année millesime à traiter)", - 'siren=s' => "Ecrase les données du fichier pour les éléments du siren", - 'max=s' => "Nombre d'unités maximum à traités", - 'part=s' => "Offset", - 'total' => "Get total", - 'files' => "Lister les fichiers puis intégration", - 'numdepot=s' => "Specifier repetoire pour integrer fichier nommé (SIREN_MILLESIME_NUMDEPOT_BilanComplet.pdf) ", - 'debug' => "Debug", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "Set informations in database for greffe files."; - echo "\n\n"; - echo $opts->getUsageMessage(); - echo "\n"; - exit; -} - -$c = new Zend_Config($application->getOptions()); - -//@todo : Remove the use of registry -Zend_Registry::set('config', $c); - -// Doctrine conn -$config = new \Doctrine\DBAL\Configuration(); -$connectionParams = array( - 'dbname' => $c->profil->db->metier->params->dbname, - 'user' => $c->profil->db->metier->params->username, - 'password' => $c->profil->db->metier->params->password, - 'host' => $c->profil->db->metier->params->host, - 'charset' => 'utf8', - 'driver' => 'pdo_mysql', -); - -try { - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); -} catch (\Doctrine\DBAL\DBALException $e) { - if (APPLICATION_ENV == 'development') { - echo '
'; print_r($e); echo ''; - } else { - echo "Le service rencontre actuellement un problème technique."; - } - exit; -} -Zend_Registry::set('doctrine', $conn); - -/** - * Connexion à la base de données - */ -$db = Zend_Db::factory($c->profil->db->metier); -Zend_Db_Table_Abstract::setDefaultAdapter($db); - -// Bilans -if ($opts->bilan) { - - if ($opts->files) { - - $nbBilans = 0; - - //Type de bilan - $types = array('consolides', 'sociaux'); - foreach ( $types as $type ) { - - $path = $c->profil->infogreffe->storage->path . '/' . 'bilans'; - - echo "Bilans ".$type.PHP_EOL; - - //AAAA - echo "Liste des années...".PHP_EOL; - $dirYears = array(); - $path = $path . '/' . $type; - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' && is_dir($path . '/' . $file)) { - $dirYears[] = $file; - } - } - sort($dirYears); - } - - //Fichier - foreach ($dirYears as $year) { - echo "Traitement des fichiers $type $year".PHP_EOL; - $pathFile = $path . '/' . $year; - if ($handle = opendir($pathFile)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - //'bilan-' . $this->siren . '-' . $type . '-' . $dateCloture . '.pdf'; - if (preg_match('/^bilan-([0-9]{9})-(sociaux|consolides)-([0-9]{8})\.pdf/', $file, $matches)) { - - echo "Fichier ".$file; - - $siren = $matches[1]; - $typeComptes = $matches[2]; - $dateCloture = substr($matches[3],0,4).'-'.substr($matches[3],4,2).'-'.substr($matches[3],6,2); - - //Recherche dans la bdd - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->where('siren=?',$siren) - ->where('date_cloture=?', $dateCloture); - if ($typeComptes=='sociaux') { - $sql->where('type_comptes="" OR type_comptes="sociaux"'); - } else { - $sql->where('type_comptes="consolides"'); - } - $sql->where('actif=1'); - $sql->order('dateInsert DESC')->order('num_depot DESC')->limit(1); - $item = $bilanM->fetchRow($sql); - - if ($item === null) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $item = $bilanM->fetchRow($sql); - } - - if ($item === null) { - echo " = non trouvé."; - } else { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infos = $infogreffe->pdfInfos($pathFile . '/' . $file); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $bilanM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - - } else { - echo " = présent."; - } - - } - echo PHP_EOL; - } - $nbBilans++; - } - } - } - } - } - echo "Nombre de fichier : ".$nbBilans.PHP_EOL; - } - - /** - * Lecture des fichiers depuis un répertoire - * siren_YYYY_NUMDEPOT_BilanComplet.pdf - */ - elseif ($opts->numdepot) { - - echo $opts->numdepot."\n"; - - if( !is_dir($opts->numdepot) ) { - echo "Répertoire inexistant !\n"; exit; - } - - if ($handle = opendir($opts->numdepot)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - if (preg_match('/^([0-9]{9})_([0-9]{4})_([0-9]{1,})_(.*)\.pdf/', $file, $matches)) { - - echo $file; - - $siren = $matches[1]; - $millesime = $matches[2]; - $depot = $matches[3]; - - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->from($bilanM, array('id','siren','millesime', 'date_cloture','type_comptes', 'pdfDate')) - ->where('siren=?', $siren) - ->where('millesime=?', $millesime) - ->where('num_depot=?', $depot); - $item = $bilanM->fetchRow($sql); - - if ($item === null) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $item = $bilanM->fetchRow($sql); - } - - if ($item === null) { - echo " = non trouvé."; - } else { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - - $type = "sociaux"; - if ( !empty($item->type_comptes) ) { - $type = $item->type_comptes; - } - - //File path - 2012_sociaux-20121231-7501-55-B-14450-0035567 - $newfile = $infogreffe->getFileName($type, $item->date_cloture); - $filepath = $c->profil->infogreffe->storage->path . '/' . - $infogreffe->getFilePath($type, $item->date_cloture) . '/' . $newfile; - - if (copy($opts->numdepot . '/' .$file, $filepath)) { - $infos = $infogreffe->pdfInfos($filepath); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $bilanM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - } else { - echo " = copie du fichier impossible."; - } - - } else { - echo " = présent."; - } - } - echo PHP_EOL; - } - } - } - } - - } - - //Lecture de toute la base de données - else { - - //Lire la base de données - $bilanM = new Application_Model_JoGreffesBilans(); - $sql = $bilanM->select() - ->from($bilanM, array('siren','millesime', 'date_cloture','type_comptes')) - ->order('millesime DESC'); - - if ( is_numeric($opts->bilan) ){ - $sql->where('millesime=?', $opts->bilan); - } - - if ( $opts->total ) { - $nbTotal = $bilanM->fetchAll($sql)->count(); - echo "Total : ".$nbTotal.PHP_EOL; - exit; - } - - if ( $opts->max && $opts->part ) { - $sql->limit($opts->max, $opts->part); - } elseif ($opts->max) { - $sql->limit($opts->max); - } - - //$nbTotal = $bilanM->fetchAll($sql)->count(); - - if ( $opts->siren ) { - $sql->where('siren=?',$opts->siren); - } else { - $sql->where('pdfDate=?','0000-00-00'); - } - - $sql->where('actif=1'); - - $result = $bilanM->fetchAll($sql); - - $NbLignes = $result->count(); - - echo "Nb Lignes à traiter : ".$NbLignes.PHP_EOL; - - if ( $NbLignes > 0 ) { - $cpt = 1; - foreach ( $result as $item ) { - $siren = str_pad($item->siren, 9, '0', STR_PAD_LEFT); - - echo "Ligne ".$cpt."/".$NbLignes." - siren = ".$siren." , millesime = ".$item->millesime; - - // Lire les informations du fichier - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $type = 'sociaux'; - if ( !empty($item->type_comptes) ) { - $type = $item->type_comptes; - } - - //File path - 2012_sociaux-20121231-7501-55-B-14450-0035567 - $file = $infogreffe->getFileName($type, $item->date_cloture); - $filepath = $c->profil->infogreffe->storage->path . '/' . - $infogreffe->getFilePath($type, $item->date_cloture) . '/' . $file; - - echo " Fichier : ".$filepath; - - if ( file_exists($filepath) ) { - echo " lecture."; - //Analyser le fichier - Nombre de page et taille - $infos = $infogreffe->pdfInfos($filepath); - - //Enregistrer les infos du fichier dans la base de données - if (false !== $infos) { - $infogreffe->type_comptes = $item->type_comptes; - $infogreffe->date_cloture = $item->date_cloture; - $infogreffe->dbSetFile($file, $infos['size'], $infos['pages'], $infos['version']); - } - } else { - echo " non trouvé."; - } - - echo PHP_EOL; - $cpt++; - } - } else { - echo "Aucun enregistrement !".PHP_EOL; - } - - } - - exit; -} - -// Actes -if ($opts->acte) { - - if ($opts->files) { - - $path = $c->profil->infogreffe->storage->path . '/' . 'actes'; - $months = array('01','02','03','04','05','06','07','08','09','10','11','12'); - - $nbActes = 0; - - //AAAA - echo "Liste des années...".PHP_EOL; - $dirYears = array(); - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' && is_dir($path . '/' . $file)) { - $dirYears[] = $file; - } - } - sort($dirYears); - } - - //Fichier - foreach ($dirYears as $year) { - foreach ($months as $month) { - $pathFile = $path . '/' . $year . '/' . $month; - echo "Traitement des fichiers $year/$month".PHP_EOL; - if ( is_dir($pathFile) ) { - if ($handle = opendir($pathFile)) { - while (false !== ($file = readdir($handle))) { - if ( $file != '..' && $file != '.' ) { - - //acte-347614984-TB-2012-03-15-1402-00-D-50625-4-1.pdf - if (preg_match('/^acte-([0-9]{9})-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.pdf/', $file, $matches)) { - $outfile = 'acte-'.$matches[1].'-'.$matches[2].'-'. - $matches[3].$matches[4].$matches[5].'-'. - $matches[6].'-'.$matches[7].'-'.$matches[8].'-'.$matches[9].'-'.$matches[10].'-'.$matches[11].'.pdf'; - echo "Fichier ".$file; - if ( rename($pathFile.'/'.$file, $pathFile.'/'.$outfile) ) { - $data = array( - 'pdfLink' => $outfile, - ); - try { - $acteM = new Application_Model_JoGreffesActes(); - $result = $acteM->update($data, array( - 'pdfLink="'.$file.'"', - 'siren='.$matches[1], - )); - echo " = " . $outfile . " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - echo "\n"; - continue; - } - - //'acte-' . $this->siren . '-' . $type . '-' . $date . '-' . $options . '-' . $num . '.pdf'; - //with options = NumGreffe - NumRC - NumRC - NumRC - NumDepot - //acte-876580325-XB-20120427-5602-65-B-00032-18-01.pdf - if (preg_match('/^acte-([0-9]{9})-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.pdf/', $file, $matches)) { - - echo "Fichier ".$file; - - $siren = $matches[1]; - $type = $matches[2]; - $date = substr($matches[3],0,4).'-'.substr($matches[3],4,2).'-'.substr($matches[3],6,2); - $depot = $matches[8]; - $num = $matches[9]; - - $acteM = new Application_Model_JoGreffesActes(); - $sql = $acteM->select() - ->where('siren=?', $siren) - ->where('num_depot=?', $depot) - ->where('date_acte=?', $date) - ->where('num_acte=?', intval($num)); - //->where('type_acte=?', $type); - //GROUP BY type_acte_libelle - - $sql->where('actif=1'); - - $items = $acteM->fetchAll($sql); - - if (count($items)==0) { - //If not find write the database - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infogreffe->getList(); - //And get again the item in database - $items = $acteM->fetchAll($sql); - } - - if (count($items)==0) { - echo " = non trouvé."; - } else { - foreach($items as $item) { - if ($item->pdfDate == '0000-00-00') { - - $infogreffe = new Metier_Infogreffe_DocBI(); - $infogreffe->setSiren($siren); - $infos = $infogreffe->pdfInfos($pathFile . '/' . $file); - - if (false !== $infos) { - $data = array( - 'pdfLink' => $file, - 'pdfSize' => $infos['size'], - 'pdfPage' => $infos['pages'], - 'pdfVer' => $infos['version'], - 'pdfDate' => date('Ymd'), - ); - try { - $result = $acteM->update($data, 'id='.$item->id); - echo " = enregistrement."; - } catch(Zend_Db_Adapter_Exception $e) { - echo $e->getMessage(); - } catch(Zend_Db_Exception $e) { - echo $e->getMessage(); - } - } - - } else { - echo " = présent."; - } - } - - } - echo PHP_EOL; - } - $nbActes++; - } - } - } - } - } - - - } - echo "Nombre de fichier : ".$nbActes.PHP_EOL; - - } else { - - //Lire la base de données - $acteM = new Application_Model_JoGreffesActes(); - $sql = $acteM->select() - ->from($actesM, array( - 'siren', - 'numRC', - 'LPAD(numGreffe,4,0) AS numGreffe', - 'pdfLink', - 'pdfSize', - 'pdfPage', - 'num_depot', - 'date_depot', - 'date_acte', - 'LPAD(num_acte,2,0) AS num_acte', - 'type_acte', - 'type_acte_libelle', - 'nbpages_acte', - 'decision_nature', - 'decision_libelle', - 'mode_diffusion' - )) - ->order('date_depot ASC'); - if ( $opts->siren ) { - $sql->where('siren=?',$opts->siren); - } else { - $sql->where('pdfLink=?',''); - } - - $result = $acteM->fetchAll($sql); - - if ( $result->count() > 0 ) { - $cpt = 1; - foreach ( $result as $item ) { - - $date = $item->date_acte; - $num = $item->num_acte; - $type = $item->type_acte; - - $infogreffe = new Metier_Infogreffe_DocAC(); - $infogreffe->setSiren($siren); - - $options = $item->numGreffe . '-' . substr($item->numRC,0,2) . '-' . substr($item->numRC,2,1) . '-' . substr($item->numRC,3) . '-' . $item->num_depot; - $file = $infogreffe->getFileName($date, $num, $type, $options); - $path = $c->profil->path->shared . '/datafile/' . $infogreffe->getFilePath($date) . '/' . $file; - - if ( file_exists($filepath) ) { - //Analyser le fichier - Nombre de page et taille - $infos = $infogreffe->pdfInfos($filepath); - - //Enregistrer les infos du fichier dans la base de données - if (false !== $infos) { - $infogreffe->dbSetFile($file, $infos['size'], $infos['pages'], $infos['version']); - } - } - - } - } else { - echo "Aucun enregistrement !\n"; - } - } -} \ No newline at end of file