"Displays usage information.", 'fileIn=s' => "Give the full file path to integrate", '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; } //Configuration $fileOptionsIn = array( 'type' => 'csv', 'delimiter' => ';', 'enclosure' => '"', 'header' => array('idDemande', 'SSAEmetteur'), 'columns' => array('siren', 'nbLignes', 'dateContrat', 'nbContrats', 'ir'), ); $fileOkOptionsOut = array( 'type' => 'csv', 'separator' => ';', 'enclosure' => '"', 'header' => array('idDemande', 'SSAEmetteur'), 'columns' => array('siren', 'idVOR', 'PO', 'commentaire'), 'name' => 'FICH_RCE_RETOUR_', ); $fileErrorOptionsOut = array( 'type' => 'csv', 'delimiter' => ';', 'header' => array('idDemande', 'SSAEmetteur'), 'columns' => array('siren', 'code'), 'name' => 'FICH_RCE_ERREUR_', ); $client = 'SFR'; $typeDepot = 'SFTP'; //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); //client, typeDepot, dateDepot, fileDepot, nblignes, dateInsert, dateExecute $fluxinM = new Application_Model_JoFluxFileIn(); $sql = $fluxinM->select() ->where('client=?',$client) ->where('typeDepot=?',$typeDepot) ->where('dateExecute=','0000-00-00 00:00:00'); $result = $fluxinM->fetchAll($sql); if ( $result->count()==0 ) { //Send a mail } else { $dateBegin = date('YmdHis'); //Historiser la table //INSERT INTO histo VALUES() SELECT () FROM table //Vider la table $lineError = array(); $lineOk = array(); foreach ( $result as $item ) { $filepath = $c->profil->path->storage . DIRECTORY_SEPARATOR . $client . DIRECTORY_SEPARATOR . 'send' . DIRECTORY_SEPARATOR . $item->fileDepot; //Read file if ( file_exist($filepath) ) { if (($handle = fopen($filepath, 'r')) !== false) { $row = 1; while (($data = fgetcsv($handle, 0, $fileOptionsIn['delimiter'], $fileOptionsIn['enclosure'])) !== false) { //Header if (count($fileOptionsIn['header']) > 0 && $row == 1) { $header = array(); foreach ( $fileOptionsIn['header'] as $i => $column ) { $header[$column] = $data[$i]; } $row++; continue; } //Content $row++; $classInsee = new MInsee(); //Siren valide - 1010 if ( !$classInsee->valideSiren($siren) ) { $lineError[] = array( 'siren' => $siren, 'code' => '1010', ); continue; } //Siren existant - 1020 if ( !$classInsee->sirenExiste($siren) ) { $lineError[] = array( 'siren' => $siren, 'code' => '1020', ); continue; } //Calculate data //Set values $values = array(); foreach ( $fileOptionsIn['columns'] as $i => $column ) { $values[$column] = $data[$i]; } //Supplemental values //IdVOR, PO, commentaire //Save in database //Create array for return file $output = array(); foreach ( $fileOkOptionsOut['columns'] as $i => $column ) { $output[] = $values[$column]; } $lineOk[] = $output; } fclose($handle); } } } $dateEnd = date('YmdHis'); //Create output file from result $pathOut = $c->profil->path->storage . DIRECTORY_SEPARATOR . 'clients' . DIRECTORY_SEPARATOR . 'recv'; //Error $fp = fopen('file.csv', 'w'); //=> Header $line = array(); foreach ( $fileOptionsIn['header'] as $i => $column ) { $line[] = $header[$column]; } fputcsv($fp, $line, $fileErrorOptionsOut['delimiter'], $fileErrorOptionsOut['enclosure']); //=> Content foreach ( $lineError as $line ) { fputcsv($fp, $line, $fileErrorOptionsOut['delimiter'], $fileErrorOptionsOut['enclosure']); } fclose($fp); //Ok $fp = fopen('file.csv', 'w'); //=> Header $line = array(); foreach ( $fileOptionsIn['header'] as $i => $column ) { $line[] = $header[$column]; } fputcsv($fp, $line, $fileErrorOptionsOut['delimiter'], $fileErrorOptionsOut['enclosure']); //=> Content foreach ( $lineOk as $line ) { fputcsv($fp, $line, $fileOkOptionsOut['delimiter'], $fileOkOptionsOut['enclosure']); } fclose($fp); $fluxoutM = new Application_Model_JoFluxFileOut(); $fluxoutM->insert(array( 'client' => $client, 'name' => $name, 'nbLines' => $rows, 'dateBegin' => $dateBegin, 'dateEnd' => $dateEnd, 'fileOut' => $file, 'typeDepot' => $typeDepot, 'dateDepot' => '0000-00-00 00:00:00', )); $fluxoutM->insert(array( 'client' => $client, 'name' => $name, 'nbLines' => $rows, 'dateBegin' => $dateBegin, 'dateEnd' => $dateEnd, 'fileOut' => $file, 'typeDepot' => $typeDepot, 'dateDepot' => '0000-00-00 00:00:00', )); //Ecrire la date d'execution dans flux_filein $fluxinM->update(array( 'dateExecute' => $dateEnd, ), 'id='.$item->id); } //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) //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 ...