2011-10-13 10:35:48 +00:00
#!/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
2011-10-14 11:48:38 +00:00
Reprise des actes en erreur de moins de 120 heures
2011-10-13 10:35:48 +00:00
< ? php echo $argv [ 0 ]; ?> rapport
2011-10-18 15:22:40 +00:00
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
2011-10-13 10:35:48 +00:00
< ? php
exit ;
}
if ( $argv [ 1 ] == 'reprise' )
{
2011-10-18 09:36:00 +00:00
require_once realpath ( dirname ( __FILE__ )) . '/../config/prepend.php' ;
2011-10-13 12:51:02 +00:00
require_once 'common/curl.php' ;
require_once 'common/mysql.php' ;
require_once 'infogreffe/infogreffews.php' ;
2011-10-13 10:35:48 +00:00
$wdb = new WDB ( 'sdv1' );
2011-10-19 07:11:37 +00:00
$repErreur = $wdb -> select ( 'commandes_erreur' , '*' , " erreur!='' AND dateCommande > DATE_SUB(NOW(),INTERVAL 120 HOUR) " );
2011-10-13 10:35:48 +00:00
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 ) {
2011-10-19 08:09:10 +00:00
$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 );
2011-10-13 10:35:48 +00:00
}
}
}
2011-10-18 15:22:40 +00:00
elseif ( in_array ( $argv [ 1 ], array ( 'rapport' , 'rapportcomplet' )))
2011-10-13 10:35:48 +00:00
{
2011-10-19 07:11:37 +00:00
require_once realpath ( dirname ( __FILE__ )) . '/../config/prepend.php' ;
2011-10-13 12:51:02 +00:00
require_once 'common/curl.php' ;
require_once 'common/mysql.php' ;
2011-10-13 10:35:48 +00:00
require_once 'sendmail/mail.php' ;
2011-10-13 12:51:02 +00:00
require_once 'infogreffe/infogreffews.php' ;
2011-10-13 10:35:48 +00:00
$wdb = new WDB ( 'sdv1' );
2011-10-18 15:22:40 +00:00
if ( $argv [ 1 ] == 'rapportcomplet' ) {
2011-10-19 08:09:10 +00:00
$repErreur = $wdb -> select ( 'commandes_erreur' , '*' , " erreur!='' AND dateReception='0000-00-00 00:00:00' ORDER BY dateCommande ASC " );
2011-10-18 15:22:40 +00:00
$sujet = " [Commandes Greffe - Erreur WebService] - Rapport Complet " ;
} else {
2011-10-19 08:09:10 +00:00
$timestamp = mktime ( 0 , 0 , 0 , date ( " m " ), date ( " d " ) - 1 , date ( " Y " ));
2011-10-18 15:22:40 +00:00
$hier = date ( 'Y-m-d' , $timestamp );
$sujet = " [Commandes Greffe - Erreur WebService] - " . $hier ;
2011-10-19 08:09:10 +00:00
$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 " );
2011-10-18 15:22:40 +00:00
}
2011-10-13 10:35:48 +00:00
$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>' ;
2011-10-19 08:09:10 +00:00
foreach ( $repErreur as $cmd )
{
2011-10-13 10:35:48 +00:00
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 ) ) {
2011-10-19 08:09:10 +00:00
$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 );
2011-10-13 10:35:48 +00:00
} else {
//Lister les fichier en erreur
$emailTxt .= '<tr>' ;
$emailTxt .= '<td style="padding:5px">' . $cmd [ 'siren' ] . '</td>' ;
2011-10-13 13:22:54 +00:00
$emailTxt .= '<td style="padding:5px">' . $cmd [ 'type' ] . '</a></td>' ;
2011-10-13 10:35:48 +00:00
$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>' ;
2011-10-19 08:09:10 +00:00
$emailTxt .= '</tr>' ;
2011-10-13 10:35:48 +00:00
}
}
$emailTxt .= '</tbody>' ;
$emailTxt .= '</table>' ;
$emailTxt .= '<br/>' ;
2011-10-19 08:09:10 +00:00
$emailTxt = utf8_encode ( $emailTxt );
2011-10-13 10:35:48 +00:00
}
//Envoi mail
$from = array (
'email' => 'production@scores-decisions.com' ,
'name' => 'Production'
);
$to = array (
0 => array (
'email' => 'production@scores-decisions.com' ,
'name' => 'Pieces' ),
2011-10-13 13:22:54 +00:00
1 => array (
2011-10-13 10:35:48 +00:00
'email' => 'supportdev@scores-decisions.com' ,
'name' => 'Support' )
);
sendMail ( $sujet , $emailTxt , $from , $to );
2011-10-19 08:09:10 +00:00
}