extranet/batch/greffeCmdCourrier.php

159 lines
4.2 KiB
PHP
Raw Normal View History

2011-09-06 14:29:23 +00:00
#!/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(),
)));
/** 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 courrier traités";
echo "\n\n";
echo $opts->getUsageMessage();
echo "\n";
exit;
}
require_once 'Scores/WsScores.php';
require_once 'Scores/Mail.php';
define('LOGIN', 'mricois');
define('PASSWORD', '');
function listeCmd($statut)
{
$commandes = new Application_Model_Commandes();
2011-09-06 14:29:23 +00:00
$sql = $commandes->select()
->where('typeCommande = ?', 'C')
->where('statutCommande = ?', $statut);
$listeCmd = $commandes->fetchAll($sql);
if(count($listeCmd)>0){
$output = "<table border=\"1\" style=\"border:1px solid; margin:5px; border-collapse:collapse;\">";
$output.= "<thead>";
$output.= "<tr>";
$output.= "<th>Ref.</th>";
$output.= "<th>Siren</th>";
$output.= "<th>Ref. Document</th>";
$output.= "<th>Date de commande</th>";
$output.= "</tr>";
$output.= "</thead>";
$output.= "<tbody>";
foreach($listeCmd as $cmd){
$output.= "<tr>";
$output.= "<td style=\"padding:5px\">C".$cmd->idCommande."</td>";
$output.= "<td style=\"padding:5px\">".
"<a href=\"http://extranetrec.scores-decisions.com/".
"?page=competences&idEntreprise=0&siret=".
$cmd->siren."&type=tri\" >".
$cmd->siren.
"</a></td>";
$output.= "<td style=\"padding:5px\">".$cmd->refDocument."</td>";
$output.= "<td style=\"padding:5px\">".$cmd->dateCommande."</td>";
$output.= "</tr>";
if( preg_match('/^([0-9]{4}_).*?$/', $cmd->refDocument, $matches) ){
$type = 'bilans';
}else{
$type = 'actes';
}
$tribunalCode = codeTribunal($cmd->siren);
$infoPaiement = infoPaiement($tribunalCode, $type);
$txtInfo = "Pas d'information de paiement enregistré dans la base.";
if($infoPaiement!==false){
$txtInfo =
"Chéque de ".$infoPaiement['prix']." ".
"à l'ordre de ".$infoPaiement['ordre'];
if($infoPaiement['enveloppe'])
$txtInfo.= ", fournir une enveloppe timbré";
}
$output.= "<tr>";
$output.= "<td>&nbsp;</td>";
$output.= "<td colspan=\"3\">".$txtInfo."</td>";
$output.= "</tr>";
}
$output.= "</tbody>";
$output.= "</table>";
}else{
$output.= "Aucune commande<br/>";
}
return $output;
}
function codeTribunal($siren)
{
$ws = new WsScores(LOGIN, PASSWORD);
$identite = $ws->getIdentite($siren, 0);
return $identite->TribunalCode;
}
function infoPaiement($codeTribunal, $type)
{
$tarifs = new Application_Model_CommandesTarifs();
2011-09-06 14:29:23 +00:00
$sql = $tarifs->select()
->where('annee = ?', date('Y'))
->where('type = ?', $type)
->where('codeTribunal = ?', $codeTribunal);
$rows = $tarifs->fetchAll($sql);
if(count($rows)>0) {
return array(
'prix'=> $rows[0]->prix,
'enveloppe' => $rows[0]->enveloppe,
'ordre' => $rows[0]->ordre
);
} else {
return false;
}
}
$emailTxt = "";
//Liste commandes non-traites
$emailTxt.= "<b><u>Liste des commandes courrier non-traités</u></b>";
$emailTxt.= "<br/>";
$emailTxt.= listeCmd(0);
$emailTxt.= "<br/>";
//Liste des commandes en attente de cheques
$emailTxt.= "<b><u>Liste des commandes courrier en attente de chèque</u></b>";
$emailTxt.= "<br/>";
$emailTxt.= listeCmd(1);
//Envoi mail
$mail = new Mail();
$mail->setFrom('production');
$mail->addTo('production@scores-decisions.com', 'Pieces');
$mail->setSubject("[COMMANDES PIECES COURRIER] - ".date('d')."/".date('m')."/".date('Y'));
$mail->setBodyHtml($emailTxt);
$mail->send();