Ajout email

This commit is contained in:
Rodolphe Quiedeville 2005-02-28 11:54:28 +00:00
parent a56739c0e2
commit 5ceca89164

View File

@ -31,15 +31,25 @@ require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php";
define ('COMMANDETABLEUR_NOEMAIL', -3);
$opt = getopt("e:");
$email = $opt['e'];
if (strlen($email) == 0)
{
print "Usage :\n php recap-commande.php -e EMAIL\n";
}
$date = time();
$date_now = $date;
Generate($date, $db, $date_now);
Generate($date, $db, $date_now, $email);
if (strftime("%d", $date_now) < 7)
{
$date_prev = $date - (86400 * 9);
Generate($date_prev, $db, $date_now);
Generate($date_prev, $db, $date_now, $email);
}
/*
@ -47,12 +57,12 @@ if (strftime("%d", $date_now) < 7)
*
*/
function Generate($date_gen, $db, $date_now)
function Generate($date_gen, $db, $date_now, $email)
{
$datef = strftime("%Y-%m", $date_gen);
$fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/recap-".$datef.".xls";
$shortname = "recap-".$datef.".xls";
$fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/".$shortname;
$ligne = new LigneTel($db);
@ -62,8 +72,8 @@ function Generate($date_gen, $db, $date_now)
$worksheet->write(0, 0, "Récapitulation des commandes du mois de ".strftime("%B %Y",$date_gen)." (généré le ".strftime("%d %B %Y %HH%M", $date_now) . ")");
$worksheet->set_column('A:A', 24);
$worksheet->set_column('B:B', 40);
$worksheet->set_column('A:A', 12);
$worksheet->set_column('B:B', 42);
$worksheet->set_column('C:C', 15);
$worksheet->set_column('D:D', 14);
$worksheet->set_column('E:E', 28);
@ -72,6 +82,36 @@ function Generate($date_gen, $db, $date_now)
$formatcc->set_align('center');
$formatcc->set_align('vcenter');
$format[2] =& $workbook->addformat();
$format[2]->set_align('center');
$format[2]->set_align('vcenter');
$format[2]->set_color('blue');
$format[3] =& $workbook->addformat();
$format[3]->set_align('center');
$format[3]->set_align('vcenter');
$format[3]->set_color('green');
$format[4] =& $workbook->addformat();
$format[4]->set_align('center');
$format[4]->set_align('vcenter');
$format[4]->set_color('pink');
$format[5] =& $workbook->addformat();
$format[5]->set_align('center');
$format[5]->set_align('vcenter');
$format[5]->set_color('orange');
$format[6] =& $workbook->addformat();
$format[6]->set_align('center');
$format[6]->set_align('vcenter');
$format[6]->set_color('red');
$format[7] =& $workbook->addformat();
$format[7]->set_align('center');
$format[7]->set_align('vcenter');
$format[7]->set_color('red');
$formatccb =& $workbook->addformat();
$formatccb->set_align('center');
$formatccb->set_align('vcenter');
@ -94,7 +134,7 @@ function Generate($date_gen, $db, $date_now)
$ligneids = array();
$sqlall = "SELECT s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
$sqlall = "SELECT s.code_client, s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
$sqlall .= " , comm.name, comm.firstname, l.remise";
$sqlall .= " , ".$db->pdate("l.date_commande")." as date_commande";
$sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@ -120,8 +160,8 @@ function Generate($date_gen, $db, $date_now)
{
$num = $db->num_rows();
$worksheet->write(1, 0, "Clients", $formatc);
$worksheet->write(1, 1, "Adresses", $formatc);
$worksheet->write(1, 0, "Code", $formatc);
$worksheet->write(1, 1, "Client", $formatc);
$worksheet->write(1, 2, "Numéro", $formatcc);
$worksheet->write(1, 3, "Date commande", $formatcc);
$worksheet->write(1, 4, "Statut actuel", $formatcc);
@ -135,13 +175,14 @@ function Generate($date_gen, $db, $date_now)
$soc = new Societe($db);
$soc->fetch($obj->socid);
$worksheet->write($j, 0, $obj->nom, $formatc);
$worksheet->write($j, 1, $soc->adresse. " " . $soc->cp . " " . $soc->ville, $formatc);
$worksheet->write($j, 0, $obj->code_client, $formatc);
$worksheet->write($j, 1, $obj->nom, $formatc);
$worksheet->write_string($j, 2, "$obj->ligne", $formatcc);
$worksheet->write($j, 3, strftime("%d/%m/%y",$obj->date_commande), $formatcc);
$worksheet->write($j, 4, $ligne->statuts[$obj->statut], $formatcc);
$worksheet->write($j, 4, $ligne->statuts[$obj->statut], $format[3]);
$i++;
}
@ -159,4 +200,44 @@ function Generate($date_gen, $db, $date_now)
*/
$workbook->close();
/*
*
*/
if ($date_gen == $date_now)
{
MailFile($fname, $shortname, $email);
}
}
function MailFile($filename, $shortname, $to)
{
$subject = "Recapitulatif des commandes";
$sendto = $to;
$from = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC;
$message = "Bonjour,\n\nVeuillez trouver ci-joint le dernier récapitulatif des commandes.\n\n";
$message .= "\n\nCordialement,\n\n";
$message .= "-- \n";
$mailfile = new DolibarrMail($subject,
$sendto,
$from,
$message);
$mailfile->addr_bcc = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC;
$mailfile->PrepareFile(array($filename),
array("application/msexcel"),
array($shortname));
if ( $mailfile->sendfile() )
{
return 0;
}
}