#!/usr/bin/php -q
"Affiche l'aide.",
'reprise' => "Reprise des actes en erreur de moins de 120 heures",
'rapport' => "Envoi d'un email listant les commandes en erreur à J-1",
'rapportcomplet' => "Envoi d'un email listant toutes les commandes en erreur",
));
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
/**
* Usage
*/
if(count($opts->getOptions())==0 || isset($opts->help))
{
echo "Reprise de commande InfoGreffe par le WebService.";
echo "\n\n";
echo $opts->getUsageMessage();
echo "\n";
exit;
}
$configuration = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini');
define ('PATH_DATA', $configuration->path->data);
/**
* Connexion à la base de données
*/
$db = Zend_Db::factory($configuration->databases->db->sdv1);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$db->setFetchMode(Zend_Db::FETCH_OBJ);
if ( isset($opts->reprise) )
{
$commandesM = new Application_Model_CommandesErreur();
$sql = $commandesM->select()->where("erreur!='' AND dateCommande > DATE_SUB(NOW(),INTERVAL 120 HOUR)");
$repErreur = $commandesM->fetchAll($sql);
if (count($repErreur)==0) exit;
foreach($repErreur as $cmd)
{
require_once 'Scores/Infogreffe.php';
$infogreffe = new Infogreffe();
switch($cmd->type){
case 'acte':
$fichier = $infogreffe->acteFilename($cmd->siren, $cmd->ref);
break;
case 'bilan':
$fichier = $infogreffe->bilanFilename($cmd->siren, $cmd->ref);
break;
}
$dl = $infogreffe->dl($fichier, $cmd->url, false);
if( $dl ) {
$data = array('erreur' => '', 'dateReception' => date('Y-m-d H:i:s'));
$where = "siren='".$cmd->siren."' AND type='".$cmd->type."' AND ref='".$cmd->ref."' AND dateCommande='".$cmd->dateCommande."'";
$commandesM->update($data, $where);
}
}
}
if ( isset($opts->rapport) || isset($opts->rapportcomplet) )
{
$commandesM = new Application_Model_CommandesErreur();
if (isset($opts->rapportcomplet)) {
$sql = $commandesM->select()->where("erreur!='' AND dateReception='0000-00-00 00:00:00' ORDER BY dateCommande ASC");
$sujet = "[Commandes Greffe - Erreur WebService] - Rapport Complet";
} else {
$timestamp = mktime(0, 0, 0, date("m"), date("d")-1, date("Y"));
$hier = date('Y-m-d', $timestamp);
$sujet = "[Commandes Greffe - Erreur WebService] - ".$hier;
$sql = $commandesM->select()->where("(dateCommande BETWEEN '".$hier." 00:00:00' AND '".$hier." 23:59:59') AND erreur!='' AND dateReception='0000-00-00 00:00:00' ORDER BY dateCommande ASC");
}
$repErreur = $commandesM->fetchAll($sql);
$emailTxt = 'Commandes Greffe - Erreur WebService';
$emailTxt.= '
';
if (count($repErreur)==0) {
$emailtTxt.= "Aucune commande en erreur !";
} else {
$emailTxt.= '
Siren | '; $emailTxt.= 'Type | '; $emailTxt.= 'Ref | '; $emailTxt.= 'Date de commande | '; $emailTxt.= 'URL | '; $emailTxt.= 'Erreur | '; $emailTxt.= '
---|---|---|---|---|---|
'.$cmd->siren.' | '; $emailTxt.= ''.$cmd->type.' | '; $emailTxt.= ''.$cmd->ref.' | '; $emailTxt.= ''.$cmd->dateCommande.' | '; $emailTxt.= ''.$cmd->url.' | '; $emailTxt.= ''.$cmd->erreur.' | '; $emailTxt.= '