Sfr : Traitement Altisys

This commit is contained in:
Michael RICOIS 2013-08-28 15:07:16 +00:00
parent 610f6896c7
commit 300dc72725
12 changed files with 507 additions and 96 deletions

View File

@ -1,6 +0,0 @@
<?php
class Application_Model_JoFluxFileIn extends Zend_Db_Table_Abstract
{
protected $_name = 'flux_filein';
protected $_schema = 'jo';
}

View File

@ -1,6 +0,0 @@
<?php
class Application_Model_JoFluxFileOut extends Zend_Db_Table_Abstract
{
protected $_name = 'flux_fileout';
protected $_schema = 'jo';
}

View File

@ -0,0 +1,6 @@
<?php
class Application_Model_JoScoresSurveillance extends Zend_Db_Table_Abstract
{
protected $_name = 'scores_surveillance';
protected $_schema = 'jo';
}

View File

@ -0,0 +1,6 @@
<?php
class Application_Model_JoSfrData extends Zend_Db_Table_Abstract
{
protected $_name = 'sfr_data';
protected $_schema = 'jo';
}

View File

@ -0,0 +1,6 @@
<?php
class Application_Model_JoSurveillancesSite extends Zend_Db_Table_Abstract
{
protected $_name = 'surveillances_site';
protected $_schema = 'jo';
}

View File

@ -0,0 +1,6 @@
<?php
class Application_Model_Sdv1FluxFileIn extends Zend_Db_Table_Abstract
{
protected $_name = 'flux_filein';
protected $_schema = 'sdv1';
}

View File

@ -0,0 +1,6 @@
<?php
class Application_Model_Sdv1FluxFileOut extends Zend_Db_Table_Abstract
{
protected $_name = 'flux_fileout';
protected $_schema = 'sdv1';
}

0
docs/README Normal file
View File

View File

@ -0,0 +1,74 @@
[production]
phpSettings.date.timezone = "Europe/Paris"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layout = "main"
resources.layout.layoutPath = APPLICATION_PATH "/views"
resources.view.basePath = APPLICATION_PATH "/views"
autoloaderNamespaces[] = "Application_"
autoloaderNamespaces[] = "Scores_"
autoloaderNamespaces[] = "Metier_"
; Scores configuration
profil.server.name = development
profil.mail.method = smtp
profil.mail.smtp_host = smtp.free.fr
profil.mail.email.support = supportdev@scores-decisions.com
profil.mail.email.supportdev = supportdev@scores-decisions.com
profil.mail.email.contact = supportdev@scores-decisions.com
profil.mail.email.production = supportdev@scores-decisions.com
profil.path.batch = APPLICATION_PATH "/../scripts/jobs"
profil.path.cache = APPLICATION_PATH "/../data/cache"
profil.path.files = APPLICATION_PATH "/../data/files"
profil.path.log = APPLICATION_PATH "/../data/log"
profil.path.data = "c:\Users\mricois\www\data\ws"
profil.path.secure = "c:\Users\mricois\www\data\ws"
; Metier - Infogreffe
profil.infogreffe.wsdl = "infogreffe.wsdl"
profil.infogreffe.url = "https://webservices.infogreffe.fr/WSContextInfogreffe/INFOGREFFE"
profil.infogreffe.uri = "https://webservices.infogreffe.fr/"
profil.infogreffe.user = 85000109
profil.infogreffe.password = 166
profil.infogreffe.cache.path = APPLICATION_PATH "/../data/cache"
profil.infogreffe.cache.time = 8
profil.infogreffe.storage.path = "c:\Users\mricois\www\dataws\greffes"
; Sphinx configuration
profil.sphinx.ent.host = "192.168.78.242"
profil.sphinx.ent.port = 3312
profil.sphinx.ent.version = 2
profil.sphinx.dir.host = "192.168.78.242"
profil.sphinx.dir.port = 3312
profil.sphinx.dir.version = 2
profil.sphinx.act.host = "192.168.78.242"
profil.sphinx.act.port = 3312
profil.sphinx.act.version = 2
profil.sphinx.histo.host = "192.168.78.242"
profil.sphinx.histo.port = 3312
profil.sphinx.histo.version = 2
; Database configuration - For old configuration - see Configure.php
profil.db.metier.adapter=mysqli
profil.db.metier.params.host=192.168.3.30
profil.db.metier.params.username=batchuser
profil.db.metier.params.password=2XQTpKatBVRezXE9
profil.db.metier.params.dbname=sdv1
profil.db.metier.params.driver_options.MYSQLI_INIT_COMMAND = "SET NAMES utf8"
[staging : production]
resources.frontController.params.displayExceptions = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 0
resources.frontController.params.displayExceptions = 1
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

View File

@ -0,0 +1,95 @@
<?php
/** BATCH **/
define('FILLER',' ');
define('VERSION_FICHIER_BODACC','0106');
define('LONGUEUR_LIGNE_SORTIE', 2000);
/** Paramétres du FTP des JO **/
define('BODACC_FTP_URL', 'ftp.journal-officiel.gouv.fr');
define('BODACC_FTP_USER', 'SCORE');
define('BODACC_FTP_PASS', 'SD075');
define('BODACC_LOCAL_DIR', '/home/data/sources/bodacc/');
define('JAL_LOCAL_DIR', '/home/data/sources/jal/');
/** Paramétres du FTP de Hugin : Communiqués de presse **/
define('HUGIN_FTP_URL', 'ftp.companynews.fr');
define('HUGIN_FTP_USER', 'scores');
define('HUGIN_FTP_PASS', 'scores_632');
define('HUGIN_LOCAL_DIR', '/home/data/sources/infosreg/hugin/');
/** Paramétres du FTP de ActusNews : Communiqués de presse **/
define('ACTUSNEWS_FTP_URL', 'ftp.actusnews.com');
define('ACTUSNEWS_FTP_USER', 'scores_act');
define('ACTUSNEWS_FTP_PASS', '6_etIwL');
define('ACTUSNEWS_LOCAL_DIR', '/home/data/sources/infosreg/actusnews/');
/** Paramétres du FTP de Di Release : Communiqués de presse **/
define('DIRELEASE_FTP_URL', 'ftp.actusnews.com');
define('DIRELEASE_FTP_USER', 'scores_dir');
define('DIRELEASE_FTP_PASS', '-gT52sQ');
define('DIRELEASE_LOCAL_DIR', '/home/data/sources/infosreg/direlease/');
/** Paramétres du FTP des Echos: Communiqués de presse **/
define('LESECHOS_FTP_URL', 'ftp.webdisclosure.com');
define('LESECHOS_FTP_USER', 'Scores');
define('LESECHOS_FTP_PASS', 'scores2001');
define('LESECHOS_LOCAL_DIR', '/home/data/sources/infosreg/lesechos/');
/** Paramétres du FTP de BusinessWire : Communiqués de presse **/
define('BUSINESSWIRE_LOCAL_DIR_INCOMING', '/home/data/ftp/businesswire/');
define('BUSINESSWIRE_LOCAL_DIR', '/home/data/infosreg/businesswire/');
/** Base de données de S&D **/
define ('MYSQL_HOST', '192.168.3.30');
define ('MYSQL_USER', 'batchuser');
define ('MYSQL_PASS', '2XQTpKatBVRezXE9');
define ('MYSQL_DEFAULT_DB', 'jo');
define ('MYSQL_SQL_LOG', 'NONE');
define ('SPHINX_HOST', '192.168.3.32');
define ('SPHINX_PORT', 9312);
define ('SPHINX_ENT_HOST', '192.168.3.32');
define ('SPHINX_ENT_PORT', 9312);
define ('SPHINX_DIR_HOST', '192.168.3.32');
define ('SPHINX_DIR_PORT', 9312);
define ('SPHINX_ACT_HOST', '192.168.3.25');
define ('SPHINX_ACT_PORT', 3312);
define ('SPHINX_HISTO_HOST', '192.168.3.25');
define ('SPHINX_HISTO_PORT', 3312);
/** SERVEUR DE MESSAGERIE **/
define ('SMTP_HOST', 'smtp.celeste.fr');
define ('SMTP_PORT', 25);
define ('SMTP_USER', '');
define ('SMTP_PASS', '');
/** INFOGREFFE **/
define('INFOGREFFE_DISPO', true);
define('INFOGREFFE_DISPO_WS', true);
define('INFOGREFFE_DISPO_WEB', true);
define('INFOGREFFE_WS_URL', 'https://webservices.infogreffe.fr/WSContextInfogreffe/INFOGREFFE');
define('INFOGREFFE_WS_URI', 'https://webservices.infogreffe.fr/');
define('INFOGREFFE_WS_USER', '85000109');
define('INFOGREFFE_WS_PASS', '166');
/** AMABIS **/
define('AMABIS_WS_URL', 'http://sw4.amabis.com:5101');
define('AMABIS_WS_URI', 'http://sw4.amabis.com:5101');
/** Dossiers locaux pour les documents a telecharger (PDF kbis, marques, etc...) **/
define ('DOC_WEB_LOCAL', '/home/data/datafile/');
define ('DOC_WEB_URL', '/data/');
/** LOGGING **/
define('LOG_PATH', '/home/data/sources/log');
define ('DATETIME', date('YmdHis'));
define ('DATE', substr(DATETIME,0,8));
define ('TIME', substr(DATETIME,8,6));
define ('DATE_LISIBLE', substr(DATETIME,6,2).'/'.substr(DATETIME,4,2).'/'.substr(DATETIME,0,4));
define ('TIME_LISIBLE', substr(DATETIME,8,2).':'.substr(DATETIME,10,2).':'.substr(DATETIME,12,2));

View File

@ -0,0 +1,237 @@
<?php
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE ^ E_WARNING);
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** 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(
'help|?' => "Displays usage information.",
'manual=s' => "Provide manualy the file without save in database",
'debug' => "Send a mail for debug",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if( isset($opts->help) || count($opts->getOptions())==0 )
{
echo "Place files in right directory for sending to the customer.\n";
echo $opts->getUsageMessage();
exit;
}
require_once APPLICATION_PATH.'/configs/config.php';
$c = new Zend_Config($application->getOptions());
$db = Zend_Db::factory($c->profil->db->metier);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$sfrdataM = new Application_Model_JoSfrData();
//Select NumSeq
$sql = $sfrdataM->select()
->order('dateInsert DESC')
->limit(1);
$result = $sfrdataM->fetchRow($sql);
$numSeq = $result->NumSeq;
//Select all NumSeq
$sql = $sfrdataM->select()->where('NumSeq=?',$numSeq);
$result = $sfrdataM->fetchAll($sql);
$fileValues = array();
if ( $result->count()>0 ) {
//Marqueur suppression dans les portefeuilles
//Pour chaque entité
foreach ($result as $item) {
$values = array();
//Est ce que la surveillance existe ?
$survM = new Application_Model_JoSurveillancesSite();
$row = $survM->fetchRow("login='".$login."' AND siren='".$siren."' AND source='".$source."'");
// |- non => on insert
// |-- Est ce une surveillance score ?
// |--- oui => on initialise avec le scores dans scores_surveillance
// |--- Si surveillance scores, on garde les éléments pour le fichier
if ( $row === null ) {
if ($source == 'score') {
$scoresurvM = new Application_Model_JoScoresSurveillance();
$rowscore = $scoresurvM->fetchRow("siren='".$siren."' AND source='".$source."'");
if ($rowscore !== null) {
//Assignation des variables au fichier
}
$iInsee = new MInsee();
$tabIdentite = $iInsee->getIdentiteLight($siren, $nic);
$data = array(
'source' => $source,
'login' => $login,
'email' => $email,
'siren' => $siren,
'nic' => $nic,
'ref' => $ref,
'encoursClient' => $encoursClient,
'rs' => $tabIdentite['Nom'],
'cp' => $tabIdentite['CP'],
'ville' => $tabIdentite['Ville'],
'dateAjout'=>date('Y-m-d'),
'dateSuppr'=>0,
);
$values = array(
'loginUti' => $login,
'source' => $source,
'email' => $email,
'siren' => $siren,
'nic' => '00000',
'ref' => 'AUTO',
'dateAjout' => date('Y-m-d'),
'rs' => IDENTITE,
'cp' => IDENTITE,
'ville' => IDENTITE,
'dateDerEnvoi' => '0000-00-00 00:00:00',
'encoursClient' => 0,
'actif' => scores_surveillance,
'procol' => scores_surveillance,
'indiScore20' => scores_surveillance,
'encours' => scores_surveillance,
'indiScoreDate' => scores_surveillance,
'dateBilan' => scores_surveillance,
'indiScore20Pre' => scores_surveillance,
'encoursPre' => scores_surveillance,
'indiScoreDatePre' => scores_surveillance,
'sourceModif' => scores_surveillance,
'scoreSolv' => scores_surveillance,
'scoreSolvPre' => scores_surveillance,
'scoreDir' => scores_sureillance,
'scoreDirPre' => scores_surveillance,
'scoreConf' => scores_surveillance,
'scoreConfPre' => scores_surveillance,
'cj' => IDENTITE,
'capital' => IDENTITE,
'capitalDev' => IDENTITE,
'ape_entrep' => IDENTITE,
'tca' => IDENTITE,
'teff_entrep' => IDENTITE,
'dateUpdate' => scores_surveillance,
);
}
//Insertion de la surveillance
} else {
// |- oui => on réactive
// |-- Si surveillance scores, on garde les éléments pour le fichier
if ($source == 'score') {
//Assignation des variables au fichier
}
}
$fileValues[] = $values;
}
}
/*
loginUti => AUTO
source => score
email => ''
siren => scores_surveillance
nic => 00000
ref => AUTO
dateAjout => sfr_data
rs => IDENTITE
cp => IDENTITE
ville => IDENTITE
dateDerEnvoi => 0000-00-00 00:00:00
encoursClient => 0
actif => scores_surveillance
procol => scores_surveillance
indiScore20 => scores_surveillance
encours => scores_surveillance
indiScoreDate => scores_surveillance
dateBilan => scores_surveillance
indiScore20Pre => scores_surveillance
encoursPre => scores_surveillance
indiScoreDatePre => Lecture historique
sourceModif => scores_surveillance
scoreSolv => scores_surveillance
scoreSolvPre => scores_surveillance
scoreDir => scores_sureillance
scoreDirPre => scores_surveillance
scoreConf => scores_surveillance
scoreConfPre => scores_surveillance
cj => IDENTITE
capital => IDENTITE
capitalDev => IDENTITE
ape_entrep => IDENTITE
tca => IDENTITE
teff_entrep => IDENTITE
dateUpdate => scores_surveillance
*/
/*
- Reprise du fichier ? ou lecture dans la bdd
- Pour chaque entités
1 -> Mettre le marqueur de suppression sur toutes les entités du portefeuille (login)
2 -> Pour element du fichier ajouter ou réactiver surveillance
(login, email) + initialisation suivant les éléments de scores_surveillance
3 -> A la lecture des scores du portefeuille ou de scores_surveillance alors on place dans le fichier
*/

View File

@ -29,7 +29,9 @@ try {
//Options
array(
'help|?' => "Displays usage information.",
'manual=s' => "Provide manualy the file without save in database",
'cron' => "Mandatory option for launch the cli in cron",
'manual=s' => "Provide manualy the file path to get result and debug values",
'file' => "Specify the file name to execute or regenerate output file",
'debug' => "Send a mail for debug",
)
);
@ -94,7 +96,7 @@ $client = 'SFR';
$typeDepot = 'SFTP';
$prestation = 'FICH_RCE';
// => Manual Mode
// => Debug Mode - Create file with debug values
if ( $opts->manual ) {
$filepath = $opts->manual;
@ -112,51 +114,67 @@ if ( $opts->manual ) {
}
// => Automatic mode
else {
if ($opts->cron || $opts->file ) {
//Lire les fichiers à traiter dans la table
$c = new Zend_Config($application->getOptions());
$db = Zend_Db::factory($c->profil->metier);
Zend_Db_Table::setDefaultAdapter($db);
//Output path
$pathOut = $c->profil->path->storage .
DIRECTORY_SEPARATOR . 'clients' .
DIRECTORY_SEPARATOR . strtolower($client) .
DIRECTORY_SEPARATOR . 'recv';
//client, name, typeDepot, dateDepot, fileDepot, nblignes, dateInsert, dateExecute
$fluxinM = new Application_Model_JoFluxFileIn();
$sql = $fluxinM->select()
->where('client=?',$client)
->where('name=?', $prestation)
->where('typeDepot=?',$typeDepot)
->where('dateExecute=?','0000-00-00 00:00:00')
->order('dateInsert DESC');
if ( $opts->cron ) {
$pitems = $fluxinM->fetchAll($sql);
//Lire les fichiers à traiter dans la table
$c = new Zend_Config($application->getOptions());
$db = Zend_Db::factory($c->profil->metier);
Zend_Db_Table::setDefaultAdapter($db);
if ( $pitems->count()==0 ) {
//Send a mail
} else {
//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')
->order('dateInsert DESC');
//Create output file from result
$pathOut = $c->profil->path->storage .
DIRECTORY_SEPARATOR . 'clients' .
DIRECTORY_SEPARATOR . 'recv';
$pitems = $fluxinM->fetchAll($sql);
if ( $pitems->count()==0 ) {
//@todo : Send a mail
exit;
}
foreach ($pitems as $p) {
$filepath = $pathOut . DIRECTORY_SEPARATOR . $p->fileDepot;
break;
}
//Read file
$result = execFileIn($filepath, $fileOptionsIn, array('ok'=>$fileOkOptionsOut, 'error'=>$fileErrorOptionsOut));
}
$fluxoutM = new Application_Model_JoFluxFileOut();
$rows = 0;
foreach($result as $code => $file) {
$dateBegin = date('YmdHis');
if ($opts->file) {
$filepath = $pathOut . DIRECTORY_SEPARATOR . $opts->file;
}
$filename = $file['name'] . $dateBegin . '.csv';
$rows = execFileOut($pathOut . DIRECTORY_SEPARATOR . $filename, $file);
if ( !file_exists($filepath) ) {
echo "Fichier inexistant ! ".PHP_EOL;
exit;
}
$dateEnd = date('YmdHis');
//Read file
$result = execFileIn($filepath, $fileOptionsIn, array('ok'=>$fileOkOptionsOut, 'error'=>$fileErrorOptionsOut));
$fluxoutM = new Application_Model_Sdv1FluxFileOut();
$rows = 0;
foreach($result as $code => $file) {
$dateBegin = date('YmdHis');
$filename = $file['name'] . $dateBegin . '.csv';
$rows = execFileOut($pathOut . DIRECTORY_SEPARATOR . $filename, $file);
$dateEnd = date('YmdHis');
if ( $opts->cron ) {
$fluxoutM->insert(array(
'client' => $client,
'name' => $prestation,
@ -164,27 +182,28 @@ else {
'dateBegin' => $dateBegin,
'dateEnd' => $dateEnd,
'fileOut' => $filename,
'typeDepot' => $typeDepot,
'dateDepot' => '0000-00-00 00:00:00',
'depotType' => $typeDepot,
'depotDate' => '0000-00-00 00:00:00',
));
}
}
if ( $opts->cron ) {
//Ecrire la date d'execution dans flux_filein
$fluxinM->update(array(
'dateExecute' => $dateEnd,
), 'id='.$p->id);
}
}
/**
*
* @param array $values
* @param array $row
* @param string $seq
* @param string $debug
* @return multitype:number multitype: Ambigous <string, multitype:, number, mixed, NULL>
* @return array
*/
function execInternal($values, $row, $debug = false)
function execInternal($values, $seq, $debug = false)
{
$error = 0;
@ -194,6 +213,7 @@ function execInternal($values, $row, $debug = false)
$classInsee = new MInsee();
$values['code'] = '';
//Siren valide - 1010
if ( !$classInsee->valideSiren($siren) ) {
$error = 1;
@ -235,17 +255,17 @@ function execInternal($values, $row, $debug = false)
if ( !$debug ) {
$sfrDataM = new Application_Model_JoSfrData();
$sfrDataM->insert(array(
'NumSeq',
'siren',
'NbLignes',
'NbContrats',
'DateContrat',
'IR',
'IdVOR',
'comment',
'PO',
'debug',
'error',
'NumSeq' => $seq,
'siren' => $siren,
'NbLignes' => $values['nbLignes'],
'NbContrats' => $values[''],
'DateContrat' => $values['dateContrat'],
'IR' => $values['ir'],
'IdVOR' => $values['idVOR'],
'comment' => $values['comment'],
'PO' => $values['PO'],
'debug' => json_encode($valuesDebug),
'error' => $values['code'],
));
}
@ -304,7 +324,7 @@ function execFileIn($filepath, $fileOptionsIn, $filesOptionsOut = array(), $debu
}
//Exec the process
$valuesClient = execInternal($values, $row, true);
$valuesClient = execInternal($values, $header['idDemande'], true);
//Format output
if ( $valuesClient['error'] == 1 ) {
@ -368,36 +388,3 @@ function execFileOut($file, $options)
return count($options['line']);
}
//Lire ligne à ligne pour intégration
//Eviter les lignes vide
//=> Siren Ok alors calcul puis dans bdd et dans fichier ok
//=> Siren Non Ok dans fichier erreur avec son code
//Siren invalide, siren inexistant, calcul impossible
//Ligne d'entête (colonne 1 RCE<NumSeq>)
//SIREN => VARCHAR(9)
//Nombre de lignes actives => INT
//Date d'entrée en relation => VARCHAR()
//Nombre de contrats actifs => INT
//Indicateur de recouvrement => FLOAT
//Elements de sortie
//SIREN
//Indicateur VOR
//PO
//Commentaire
//Paramètres supplémentaires
//NumSeq
//Elements de calcul
//date
//Historisation
// INSERT [LOW_PRIORITY] [IGNORE] [INTO] nom_de_la_table [(liste des colonnes)] SELECT ...