"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); $dateBegin = date('YmdHis'); $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) { //Pour chaque source - set email for the different source $iInsee = new MInsee(); //Valider le SIREN if ( $iInsee->valideSiren($siren) && $iInsee->sirenExiste($siren) ) { //Identite $tabIdentite = $iInsee->getIdentiteLight($siren, $nic); //Est ce que la surveillance existe ? $survM = new Application_Model_JoSurveillancesSite(); $row = $survM->fetchRow("login='".$login."' AND siren='".$siren."' AND source='".$source."'"); // N'existe pas if ( $row === null ) { //Préapration insertion dans bdd $data = array( 'source' => $source, 'login' => $login, 'email' => $email, 'siren' => $siren, 'nic' => '00000', 'ref' => 'AUTO', 'encoursClient' => 0, 'rs' => $tabIdentite['Nom'], 'cp' => $tabIdentite['CP'], 'ville' => $tabIdentite['Ville'], 'dateAjout'=> date('Y-m-d'), 'dateSuppr'=> 0, ); //Insert database $survM->insert($data); // Existe } else { //Préapration insertion dans bdd $data = array('dateSuppr'=> 0); $where = array( 'login' => $login, '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 } //Générer le fichier $fileOptionsOut = array( 'dir' => $pathOut, 'type' => 'csv', 'delimiter' => ';', 'enclosure' => '"', 'header' => array(), 'columns' => array( 'loginUti', 'source', 'email', 'siren', 'nic', 'ref', 'dateAjout', 'rs', 'cp', 'ville', 'dateDerEnvoi', 'encoursClient', 'actif', 'procol', 'indiScore20', 'encours', 'indiScoreDate', 'dateBilan', 'indiScore20Pre', 'encoursPre', 'indiScoreDatePre', 'sourceModif', 'scoreSolv', 'scoreSolvPre', 'scoreDir', 'scoreDirPre', 'scoreConf', 'scoreConfPre', 'cj', 'capital', 'capitalDev', 'ape_entrep', 'tca', 'teff_entrep', 'dateUpdate', ), 'name' => 'CLIENTSINDISCORE_', 'line' => $fileValues, ); $fileOut = $fileOptionsOut['name'] . $dateBegin; execFileOut($pathOut . DIRECTORY_SEPARATOR . $fileOut, $fileOptionsOut); /** * * @param string $file * @param array $options */ function execFileOut($file, $options) { $fp = fopen($file, 'w'); //=> Header $line = array(); //Dynamic Header if ( count($options['header'])>0 ) { foreach ( $options['header'] as $i => $column ) { $line[] = $column; } } //Static Header else { foreach ( $options['columns'] as $i => $column ) { $line[] = $column; } } fputcsv($fp, $line, $options['delimiter'], $options['enclosure']); //=> Content if ( count($options['line'])>0 ) { foreach ($options['line'] as $c ) { $line = array(); foreach ( $options['columns'] as $i => $column ) { $line[] = $c[$column]; } fputcsv($fp, $line, $options['delimiter'], $options['enclosure']); } } fclose($fp); return count($options['line']); } /* - Reprise du fichier ? ou lecture dans la bdd - 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 */