138 lines
4.6 KiB
PHP
138 lines
4.6 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
// Paramètres
|
|
if ( ( $argc != 2 )
|
|
|| in_array($argv[1], array('--help', '-help', '-h', '-?')) ) {
|
|
?>
|
|
Reprise de commande InfoGreffe par le WebService
|
|
|
|
Avec les options --help, -help, -h, et -?, vous obtiendrez cette aide.
|
|
|
|
Utilisation :
|
|
<?php echo $argv[0]; ?> reprise
|
|
Reprise des actes en erreur de moins de 120 heures
|
|
|
|
<?php echo $argv[0]; ?> rapport
|
|
Envoi d'un email listant les commandes en erreur à J-1
|
|
|
|
<?php echo $argv[0]; ?> rapportcomplet
|
|
Envoi d'un email listant toutes les commandes en erreur
|
|
|
|
<?php
|
|
exit;
|
|
}
|
|
|
|
if ($argv[1] == 'reprise')
|
|
{
|
|
require_once realpath(dirname(__FILE__)) . '/../config/prepend.php';
|
|
require_once 'common/curl.php';
|
|
require_once 'common/mysql.php';
|
|
require_once 'infogreffe/infogreffews.php';
|
|
|
|
$wdb = new WDB('sdv1');
|
|
$repErreur = $wdb->select('commandes_erreur', '*', "erreur!='' AND dateCommande > DATE_SUB(NOW(),INTERVAL 120 HOUR)");
|
|
|
|
if (count($repErreur)==0) exit;
|
|
foreach($repErreur as $cmd){
|
|
switch($cmd['type']){
|
|
case 'acte':
|
|
$fichier = infogreffe_acte_filename($cmd['siren'], $cmd['ref']);
|
|
break;
|
|
case 'bilan':
|
|
$fichier = infogreffe_bilan_filename($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']."'";
|
|
$wdb->update('commandes_erreur', $data, $where);
|
|
}
|
|
}
|
|
}
|
|
elseif (in_array($argv[1], array('rapport', 'rapportcomplet')))
|
|
{
|
|
require_once realpath(dirname(__FILE__)) . '/../config/prepend.php';
|
|
require_once 'common/curl.php';
|
|
require_once 'common/mysql.php';
|
|
require_once 'sendmail/mail.php';
|
|
require_once 'infogreffe/infogreffews.php';
|
|
|
|
$wdb = new WDB('sdv1');
|
|
|
|
if ($argv[1] == 'rapportcomplet') {
|
|
$repErreur = $wdb->select('commandes_erreur', '*', "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;
|
|
$repErreur = $wdb->select('commandes_erreur', '*', "(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");
|
|
}
|
|
$emailTxt = '<b><u>Commandes Greffe - Erreur WebService</u></b>';
|
|
$emailTxt.= '<br/>';
|
|
if (count($repErreur)==0) {
|
|
|
|
$emailtTxt.= "Aucune commande en erreur !";
|
|
|
|
} else {
|
|
$emailTxt.= '<table border="1" style="border:1px solid; margin:5px; border-collapse:collapse;">';
|
|
$emailTxt.= '<thead>';
|
|
$emailTxt.= '<tr>';
|
|
$emailTxt.= '<th>Siren</th>';
|
|
$emailTxt.= '<th>Type</th>';
|
|
$emailTxt.= '<th>Ref</th>';
|
|
$emailTxt.= '<th>Date de commande</th>';
|
|
$emailTxt.= '<th>URL</th>';
|
|
$emailTxt.= '<th>Erreur</th>';
|
|
$emailTxt.= '</tr>';
|
|
$emailTxt.= '</thead>';
|
|
$emailTxt.= '<tbody>';
|
|
foreach($repErreur as $cmd)
|
|
{
|
|
switch($cmd['type']){
|
|
case 'acte':
|
|
$fichier = infogreffe_acte_filename($cmd['siren'], $cmd['ref']);
|
|
break;
|
|
case 'bilan':
|
|
$fichier = infogreffe_bilan_filename($cmd['siren'], $cmd['ref']);
|
|
break;
|
|
}
|
|
//Le fichier existe, alors on a résolu le problème (mauellement ?)
|
|
if( file_exists(PATH_DATA . '/pdf/' . $fichier) ) {
|
|
$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']."'";
|
|
$wdb->update('commandes_erreur', $data, $where);
|
|
} else {
|
|
//Lister les fichier en erreur
|
|
$emailTxt.= '<tr>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['siren'].'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['type'].'</a></td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['ref'].'</a></td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['dateCommande'].'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['url'].'</td>';
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd['erreur'].'</td>';
|
|
$emailTxt.= '</tr>';
|
|
}
|
|
}
|
|
$emailTxt.= '</tbody>';
|
|
$emailTxt.= '</table>';
|
|
$emailTxt.= '<br/>';
|
|
$emailTxt = utf8_encode($emailTxt);
|
|
}
|
|
//Envoi mail
|
|
$from = array(
|
|
'email' => 'production@scores-decisions.com',
|
|
'name' => 'Production'
|
|
);
|
|
$to = array(
|
|
0 => array(
|
|
'email'=> 'production@scores-decisions.com',
|
|
'name' => 'Pieces'),
|
|
1 => array(
|
|
'email'=> 'supportdev@scores-decisions.com',
|
|
'name' => 'Support')
|
|
);
|
|
sendMail($sujet, $emailTxt, $from, $to);
|
|
}
|