From 7cc50762b5b7443b70465406c2eb1d0902c8fb92 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 14 Feb 2004 21:50:09 +0000 Subject: [PATCH] =?UTF-8?q?On=20peut=20modifier=20le=20message=20d'accompa?= =?UTF-8?q?gnement=20propos=E9=20lors=20de=20l'envoi=20d'un=20rappel=20de?= =?UTF-8?q?=20facture=20par=20mail=20avec=20son=20propre=20message.=20Le?= =?UTF-8?q?=20code=20d'envoi=20de=20facture=20et=20de=20relance=20=E9tant?= =?UTF-8?q?=20similaire=20=E0=203=20lignes=20pr=E8s,=20il=20a=20=E9t=E9=20?= =?UTF-8?q?mutualis=E9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/facture.php | 166 ++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 79 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 4fdfc7980c6..0346a2785f9 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -251,87 +251,86 @@ if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] /* * */ -if ($action == 'send') +if ($HTTP_POST_VARS["action"] == 'send' || $HTTP_POST_VARS["action"] == 'relance') { $fac = new Facture($db,"",$facid); - if ( $fac->fetch($facid) ) { - $soc = new Societe($db, $fac->socidp); - - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; + $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; - if (is_readable($file)) - { - if ($HTTP_POST_VARS["sendto"]) { - // Le destinataire a été fourni via le champ libre - $sendto = $HTTP_POST_VARS["sendto"]; - $sendtoid = 0; - } - else { - // Le destinataire a été fourni via la liste déroulante - $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); - $sendtoid = $HTTP_POST_VARS["destinataire"]; - } - - if (strlen($sendto)) - { - $subject = "Facture $fac->ref"; - $message = $HTTP_POST_VARS["message"]; - $filename = $fac->ref.".pdf"; - - $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; - - $mailfile = new CMailFile($subject,$sendto,$replyto,$message,array ($file),array ("application/pdf"),array ($filename)); - - if ( $mailfile->sendfile() ) - { - $sendto = htmlentities($sendto); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '9' ,'$fac->socidp' ,'Envoyée à $sendto','$fac->id','$sendtoid','$user->id', 'Envoi Facture par mail',100);"; - - if (! $db->query($sql) ) - { - print $db->error(); - print "

$sql

"; - } - } - else + if (is_readable($file)) { - print "!! erreur d'envoi
$sendto
$replyto
$filename"; - } - } - else - { - dolibarr_syslog("Le mail du destinataire est vide"); - } - } - else - { - dolibarr_syslog("Impossible de lire :".$file); - } + + if ($HTTP_POST_VARS["sendto"]) { + // Le destinataire a été fourni via le champ libre + $sendto = $HTTP_POST_VARS["sendto"]; + $sendtoid = 0; + } + elseif ($HTTP_POST_VARS["destinataire"]) { + // Le destinataire a été fourni via la liste déroulante + $soc = new Societe($db, $fac->socidp); + $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); + $sendtoid = $HTTP_POST_VARS["destinataire"]; + } + + if (strlen($sendto)) + { + if ($HTTP_POST_VARS["action"] == 'send') { + $subject = "Facture $fac->ref"; + $actioncode=9; + $actionmsg="Envoyée à $sendto"; + $actionmsg2="Envoi Facture par mail"; + } + if ($HTTP_POST_VARS["action"] == 'relance') { + $subject = "Relance facture $fac->ref"; + $actioncode=10; + $actionmsg="Relance envoyée à $sendto"; + $actionmsg2="Relance Facture par mail"; + } + $message = $HTTP_POST_VARS["message"]; + $filename = $fac->ref.".pdf"; + + $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; + + // Envoi de la facture + $mailfile = new CMailFile($subject,$sendto,$replyto,$message,array ($file),array ("application/pdf"),array ($filename)); + + if ( $mailfile->sendfile() ) + { + $sendto = htmlentities($sendto); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '$actioncode' ,'$fac->socidp' ,'$actionmsg','$fac->id','$sendtoid','$user->id', '$actionmsg2',100);"; + + if (! $db->query($sql) ) + { + print $db->error(); + print "

$sql

"; + } + } + else + { + print "!! erreur d'envoi
$sendto
$replyto
$filename"; + } + } + else + { + dolibarr_syslog("Le mail du destinataire est vide"); + } + + } + else + { + dolibarr_syslog("Impossible de lire :".$file); + } } else { dolibarr_syslog("Impossible de lire les données de la facture. Le fichier facture n'a peut-être pas été généré."); } } -/* - * - */ -if ($HTTP_POST_VARS["action"] == 'relance') -{ - $fac = new Facture($db,"",$facid); - $fac->fetch($facid); - - $fac->send_relance($HTTP_POST_VARS["destinataire"], - $HTTP_POST_VARS["replytoname"], - $HTTP_POST_VARS["replytomail"], - $user); -} /* - * + * Générer ou regénérer le PDF */ if ($action == 'pdf') { @@ -1107,10 +1106,13 @@ else $from_mail = $replytomail; print "
id&action=send\">\n"; + print ''; + print ''; print ''; print ''; + print '
'; - print "

Envoyer la facture par mail"; + print_titre("Envoyer la facture par mail"); print ""; print ""; print ""; @@ -1118,11 +1120,10 @@ else $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); - print " ou email\">"; print '"; @@ -1139,24 +1140,31 @@ else $replytomail = $user->email; $from_mail = $replytomail; - print "id\">\n"; + print "id&action=send\">\n"; + print ''; print ''; print ''; print ''; + print '
'; - print_titre("Envoyer une relance"); - print "
Expéditeur$from_name$from_mail  
Répondre à$replytoname$replytomail  
Message'; - print "
"; - print "\n"; - print "\n"; - print '"; + + print "
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
Destinataire'; + print_titre("Envoyer une relance par mail"); + print ""; + print ""; + print ""; + print '"; - print "\n"; - print "
Expéditeur$from_name$from_mail  
Répondre à$replytoname$replytomail  
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); + print " ou email\">
email\">
"; + print '
Message'; + print "

\n"; - print "

"; + print "
\n"; } /*