2011-09-06 15:09:47 +00:00
|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
// Define path to application directory
|
|
|
|
defined('APPLICATION_PATH')
|
2012-11-16 09:34:42 +00:00
|
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
2011-09-06 15:09:47 +00:00
|
|
|
|
|
|
|
// Define application environment
|
|
|
|
defined('APPLICATION_ENV')
|
2012-11-16 09:34:42 +00:00
|
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
2011-09-06 15:09:47 +00:00
|
|
|
|
|
|
|
// Ensure library/ is on include_path
|
|
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
2012-11-16 09:34:42 +00:00
|
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
|
|
get_include_path(),
|
2011-09-06 15:09:47 +00:00
|
|
|
)));
|
|
|
|
|
2014-03-14 10:42:09 +00:00
|
|
|
//Use classmap autoloader - useful with opcode and realpath cache
|
|
|
|
require_once 'Zend/Loader/AutoloaderFactory.php';
|
|
|
|
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
|
|
|
Zend_Loader_AutoloaderFactory::factory(array(
|
|
|
|
'Zend_Loader_ClassMapAutoloader' => array(
|
|
|
|
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
|
|
|
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
|
|
|
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
|
|
|
__DIR__ . '/../../application/autoload_classmap.php',
|
|
|
|
),
|
|
|
|
'Zend_Loader_StandardAutoloader' => array(
|
|
|
|
'prefixes' => array(
|
|
|
|
'Zend' => __DIR__ . '/../../library/Zend',
|
|
|
|
'Application' => __DIR__ . '/../../library/Application',
|
|
|
|
'Scores' => __DIR__ . '/../../library/Scores',
|
|
|
|
'Metier' => __DIR__ . '/../../library/Metier',
|
|
|
|
),
|
|
|
|
'fallback_autoloader' => true
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
// Zend_Application - Use it if you don't have autoloaders
|
|
|
|
//require_once 'Zend/Application.php';
|
|
|
|
|
|
|
|
// Create application, bootstrap, and run
|
|
|
|
$application = new Zend_Application(
|
|
|
|
APPLICATION_ENV,
|
|
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
|
|
);
|
|
|
|
|
2011-09-06 15:09:47 +00:00
|
|
|
/** Zend_Application */
|
|
|
|
require_once 'Zend/Application.php';
|
|
|
|
|
|
|
|
// Create application, bootstrap, and run
|
|
|
|
$application = new Zend_Application(
|
|
|
|
APPLICATION_ENV,
|
|
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$opts = new Zend_Console_Getopt(
|
|
|
|
//Options
|
|
|
|
array(
|
|
|
|
'help|?' => "Affiche l'aide.",
|
|
|
|
));
|
|
|
|
$opts->parse();
|
|
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
|
|
echo $e->getUsageMessage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Usage
|
|
|
|
if(isset($opts->help))
|
|
|
|
{
|
2011-12-07 16:53:23 +00:00
|
|
|
echo "Liste les commandes non envoyées du mois dernier";
|
2011-09-06 15:09:47 +00:00
|
|
|
echo "\n\n";
|
|
|
|
echo $opts->getUsageMessage();
|
|
|
|
echo "\n";
|
|
|
|
echo $argv[0] . ' [AAAAMM] >> /vers/fichier.log';
|
|
|
|
echo "\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$args = $opts->getRemainingArgs();
|
|
|
|
|
2012-11-16 09:34:42 +00:00
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
|
|
Zend_Registry::set('config', $c);
|
|
|
|
|
2012-01-29 11:28:40 +00:00
|
|
|
/**
|
|
|
|
* Connexion à la base de données
|
|
|
|
*/
|
2012-11-16 14:12:03 +00:00
|
|
|
$db = Zend_Db::factory($c->profil->db->sdv1);
|
2012-01-29 11:28:40 +00:00
|
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
|
2011-09-06 15:09:47 +00:00
|
|
|
function listCmdMois($statut, $date)
|
|
|
|
{
|
2011-09-27 15:33:24 +00:00
|
|
|
$commandes = new Application_Model_Commandes();
|
2011-09-06 15:09:47 +00:00
|
|
|
$sql = $commandes->select()
|
2012-11-16 09:34:42 +00:00
|
|
|
->where('typeCommande = ?', 'G')
|
2011-09-06 15:09:47 +00:00
|
|
|
->where('statutCommande = ?', $statut)
|
|
|
|
->where('dateCommande LIKE ?', $date.'%')
|
|
|
|
->where('dateReception = ?', '0000-00-00 00:00:00');
|
|
|
|
return $commandes->fetchAll($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=> Debut
|
|
|
|
if (count($args)>1){
|
|
|
|
echo "Erreur\n";
|
|
|
|
exit;
|
|
|
|
} elseif (count($args)==0){
|
|
|
|
$timeMoisPrecedent = mktime(0, 0, 0, date('m')-1, 1, date('Y'));
|
|
|
|
$moisPrecedent = date('Y-m', $timeMoisPrecedent);
|
|
|
|
} else {
|
|
|
|
$moisPrecedent = substr($args[0],0,4).'-'.substr($args[0],4,2);
|
|
|
|
}
|
|
|
|
|
|
|
|
$listeCmd = listCmdMois(0, $moisPrecedent);
|
|
|
|
|
|
|
|
$emailTxt = '';
|
|
|
|
//Liste commandes non-traites
|
|
|
|
$emailTxt.= '<b><u>Commandes greffe non receptionné</u></b>';
|
|
|
|
$emailTxt.= '<br/>';
|
|
|
|
if(count($listeCmd)>0){
|
|
|
|
$emailTxt.= '<table border="1" style="border:1px solid; margin:5px; border-collapse:collapse;">';
|
|
|
|
$emailTxt.= '<thead>';
|
|
|
|
$emailTxt.= '<tr>';
|
|
|
|
$emailTxt.= '<th>Ref.</th>';
|
|
|
|
$emailTxt.= '<th>Siren</th>';
|
|
|
|
$emailTxt.= '<th>Ref. Document</th>';
|
|
|
|
$emailTxt.= '<th>Date de commande</th>';
|
|
|
|
$emailTxt.= '</tr>';
|
|
|
|
$emailTxt.= '</thead>';
|
|
|
|
$emailTxt.= '<tbody>';
|
|
|
|
foreach($listeCmd as $cmd){
|
|
|
|
$emailTxt.= '<tr>';
|
|
|
|
$emailTxt.= '<td style="padding:5px">G'.$cmd->idCommande.'</td>';
|
|
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->siren.'</a></td>';
|
|
|
|
if( preg_match('/^([0-9]{4}_).*?$/', $cmd->refDocument, $matches) ){
|
|
|
|
$type = 'bilans';
|
|
|
|
}else{
|
|
|
|
$type = 'actes';
|
|
|
|
}
|
2012-01-29 11:28:40 +00:00
|
|
|
$emailTxt.= '<td style="padding:5px"><a href="/pieces/'.$type.'/siret/'.$cmd->siren.'">'.$cmd->refDocument.'</a></td>';
|
2011-09-06 15:09:47 +00:00
|
|
|
$emailTxt.= '<td style="padding:5px">'.$cmd->dateCommande.'</td>';
|
|
|
|
$emailTxt.= '</tr>';
|
|
|
|
}
|
|
|
|
$emailTxt.= '</tbody>';
|
|
|
|
$emailTxt.= '</table>';
|
|
|
|
}else{
|
|
|
|
$emailTxt.= "Aucune commande<br/>";
|
|
|
|
}
|
|
|
|
$emailTxt.= '<br/>';
|
|
|
|
|
|
|
|
//Envoi mail
|
2013-10-25 14:30:46 +00:00
|
|
|
$mail = new Scores_Mail();
|
2011-09-06 15:09:47 +00:00
|
|
|
$mail->setSubject("[Commandes greffe non receptionné] - ".date('d')."/".date('m')."/".date('Y'));
|
|
|
|
$mail->setFrom('production');
|
2012-11-16 09:34:42 +00:00
|
|
|
$mail->addTo('support@scores-decisions.com', 'Support');
|
2011-12-07 16:53:23 +00:00
|
|
|
$mail->addTo('supportdev@scores-decisions.com', 'SupportDev');
|
2012-01-29 11:28:40 +00:00
|
|
|
$mail->setBodyHtml($emailTxt);
|
2011-09-06 15:09:47 +00:00
|
|
|
$mail->send();
|