#!/usr/bin/php -q "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.= 'Commandes greffe non receptionné'; $emailTxt.= '
'; if(count($listeCmd)>0){ $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; foreach($listeCmd as $cmd){ $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; if( preg_match('/^([0-9]{4}_).*?$/', $cmd->refDocument, $matches) ){ $type = 'bilans'; }else{ $type = 'actes'; } $emailTxt.= ''; $emailTxt.= ''; $emailTxt.= ''; } $emailTxt.= ''; $emailTxt.= '
Ref.SirenRef. DocumentDate de commande
G'.$cmd->idCommande.''.$cmd->siren.''.$cmd->refDocument.''.$cmd->dateCommande.'
'; }else{ $emailTxt.= "Aucune commande
"; } $emailTxt.= '
'; //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();