batch/scripts/clients/SfrPortefeuille.php

191 lines
5.0 KiB
PHP
Raw Normal View History

2013-09-02 10:12:16 +00:00
<?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.",
'cron' => "Mandatory option to execute the CLI",
'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
//Tout supprimer
//Pour chaque entité
foreach ($result as $item) {
//Valider le SIREN
//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 ) {
//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);
//
} 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'),
'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
}
/*
- 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
*/