145 lines
3.6 KiB
PHP
145 lines
3.6 KiB
PHP
#!/usr/bin/php -q
|
|
<?php
|
|
$version = '0.1';
|
|
$argc = $_SERVER['argc'];
|
|
$argv = $_SERVER['argv'];
|
|
|
|
require_once '../config/prepend.php';
|
|
//Inclure la base de données
|
|
require_once 'dbbootstrap.php';
|
|
|
|
/*
|
|
* Execution du script a 10 heures ?
|
|
*
|
|
*
|
|
**/
|
|
|
|
function listeCmd($statut)
|
|
{
|
|
$q = Doctrine_Query::create()
|
|
->from('Commandes')
|
|
->Where('typeCommande = ?', 'C')
|
|
->andWhere('statutCommande = ?', $statut);
|
|
|
|
$listeCmd = $q->execute();
|
|
|
|
$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\">".$cmd->siren."</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> </td>";
|
|
$output.= "<td colspan=\"3\">".$txtInfo."</td>";
|
|
$output.= "</tr>";
|
|
}
|
|
$output.= "</tbody>";
|
|
$output.= "</table>";
|
|
return $output;
|
|
}
|
|
|
|
function codeTribunal($siren)
|
|
{
|
|
//Connection au webservice
|
|
$client = new SoapClient(null, array(
|
|
'trace' => 1,
|
|
'soap_version' => SOAP_1_1,
|
|
'location' => WEBSERVICE_URL,
|
|
'uri' => WEBSERVICE_URI,
|
|
'login' => 'mricois',
|
|
'password' => 'bj10sx',
|
|
));
|
|
$O = $client->getIdentite($siren, '', false);
|
|
$tribunalCode = $O['result']['TribunalCode'];
|
|
return $tribunalCode;
|
|
}
|
|
|
|
function infoPaiement($codeTribunal, $type)
|
|
{
|
|
$q = Doctrine_Query::create()
|
|
->from('CommandesTarifs')
|
|
->Where('annee = ?', date('Y'))
|
|
->andWhere('type = ?', $type)
|
|
->andWhere('codeTribunal = ?', $codeTribunal);
|
|
$rows = $q->execute();
|
|
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
|
|
require_once 'phpmailer/class.phpmailer.php';
|
|
$receptionCmd = array( 'email' =>'pieces@scores-decisions.com', 'nom'=>'Pieces');
|
|
$mail = new PHPMailer(true);
|
|
$mail->IsSendmail();
|
|
try
|
|
{
|
|
$body = $emailTxt;
|
|
$body = eregi_replace("[\]",'',$body);
|
|
$mail->AddReplyTo('production@scores-decisions.com','Production');
|
|
$mail->SetFrom('production@scores-decisions.com','Production');
|
|
$mail->AddAddress($receptionCmd['email'], $receptionCmd['nom']);
|
|
$mail->Subject = "[COMMANDES PIECES COURRIER] - ".date('d')."/".date('m')."/".date('Y');
|
|
$mail->MsgHTML($body);
|
|
$mail->Send();
|
|
}
|
|
catch (phpmailerException $e)
|
|
{
|
|
//echo $e->errorMessage();
|
|
} catch (Exception $e) {
|
|
//echo $e->getMessage();
|
|
}
|