extranet/scripts/jobs/greffeCmdMois.php
2014-03-14 10:42:09 +00:00

156 lines
4.6 KiB
PHP

#!/usr/bin/php -q
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
//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'
);
/** 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))
{
echo "Liste les commandes non envoyées du mois dernier";
echo "\n\n";
echo $opts->getUsageMessage();
echo "\n";
echo $argv[0] . ' [AAAAMM] >> /vers/fichier.log';
echo "\n";
exit;
}
$args = $opts->getRemainingArgs();
$c = new Zend_Config($application->getOptions());
Zend_Registry::set('config', $c);
/**
* Connexion à la base de données
*/
$db = Zend_Db::factory($c->profil->db->sdv1);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
function listCmdMois($statut, $date)
{
$commandes = new Application_Model_Commandes();
$sql = $commandes->select()
->where('typeCommande = ?', 'G')
->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';
}
$emailTxt.= '<td style="padding:5px"><a href="/pieces/'.$type.'/siret/'.$cmd->siren.'">'.$cmd->refDocument.'</a></td>';
$emailTxt.= '<td style="padding:5px">'.$cmd->dateCommande.'</td>';
$emailTxt.= '</tr>';
}
$emailTxt.= '</tbody>';
$emailTxt.= '</table>';
}else{
$emailTxt.= "Aucune commande<br/>";
}
$emailTxt.= '<br/>';
//Envoi mail
$mail = new Scores_Mail();
$mail->setSubject("[Commandes greffe non receptionné] - ".date('d')."/".date('m')."/".date('Y'));
$mail->setFrom('production');
$mail->addTo('support@scores-decisions.com', 'Support');
$mail->addTo('supportdev@scores-decisions.com', 'SupportDev');
$mail->setBodyHtml($emailTxt);
$mail->send();