diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php
index 6a0a9be3cf2..eec9220afa4 100644
--- a/htdocs/compta/facture/impayees.php
+++ b/htdocs/compta/facture/impayees.php
@@ -34,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
-
+$langs->load("mails");
$langs->load("bills");
$id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int'));
@@ -57,10 +57,16 @@ $resultmasssend='';
*/
// Send remind email
-if ($action == 'presend' && GETPOST('cancel')) $action='';
+if ($action == 'presend' && GETPOST('cancel'))
+{
+ $action='';
+ if (GETPOST('models')=='facture_relance') $mode='sendmassremind'; // If we made a cancel from submit email form, this means we must be into mode=sendmassremind
+}
if ($action == 'presend' && GETPOST('sendmail'))
{
+ if (GETPOST('models')=='facture_relance') $mode='sendmassremind'; // If we made a cancel from submit email form, this means we must be into mode=sendmassremind
+
if (!isset($user->email))
{
$error++;
@@ -73,10 +79,10 @@ if ($action == 'presend' && GETPOST('sendmail'))
$error++;
setEventMessage("InvoiceNotChecked","warnings");
}
-
+
if (! $error)
{
- $compteEmailEnvoi = 0;
+ $nbsent = 0;
$nbignored = 0;
for ($i = 0; $i < $countToSend; $i++)
@@ -86,13 +92,19 @@ if ($action == 'presend' && GETPOST('sendmail'))
if ($result > 0) // Invoice was found
{
- if ($object->statut != 1) continue; // Payment done or started or canceled
+ if ($object->statut != 1)
+ {
+ continue; // Payment done or started or canceled
+ }
- // Read PDF
- $filename=dol_sanitizeFileName($object->ref);
+ // Read document
+ // TODO Use future field $object->fullpathdoc to know where is stored default file
+ // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
+ $filename=dol_sanitizeFileName($object->ref).'.pdf';
$filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
- $file = $filedir . '/' . $filename.'.pdf'; // TODO What if ODT ?
-
+ $file = $filedir . '/' . $filename;
+ $mime = 'application/pdf';
+
if (dol_is_file($file))
{
$object->fetch_thirdparty();
@@ -105,10 +117,21 @@ if ($action == 'presend' && GETPOST('sendmail'))
$langs->load("commercial");
$from = $user->getFullName($langs) . ' <' . $user->email .'>';
$replyto = $from;
- $message = $conf->global->RELANCES_MASSE_TEXTE_EMAIL;
- $subject = $conf->global->RELANCES_MASSE_OBJET_EMAIL;
-
- $substitutionarray=make_substitutions($message, $substitutionarray);
+ $subject = GETPOST('subject');
+ $message = GETPOST('message');
+ $sendtocc = GETPOST('sentocc');
+
+ $substitutionarray=array(
+ '__ID__' => $object->id,
+ '__EMAIL__' => $object->thirdparty->email,
+ '__CHECK_READ__' => '',
+ //'__LASTNAME__' => $obj2->lastname,
+ //'__FIRSTNAME__' => $obj2->firstname,
+ '__REF__' => $object->ref,
+ '__REFCLIENT__' => $object->thirdparty->name
+ );
+
+ $message=make_substitutions($message, $substitutionarray);
$actiontypecode='AC_FAC';
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
@@ -118,12 +141,9 @@ if ($action == 'presend' && GETPOST('sendmail'))
$actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
$actionmsg.=$message;
}
- // Create form object
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->clear_attached_files();
- $formmail->add_attached_files($file, $object->ref.'.pdf', 'application/pdf');
- $attachedfiles=$formmail->get_attached_files();
+
+ // Create form object
+ $attachedfiles=array('paths'=>array($file), 'names'=>array($filename), 'mimes'=>array($mime));
$filepath = $attachedfiles['paths'];
$filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes'];
@@ -137,7 +157,7 @@ if ($action == 'presend' && GETPOST('sendmail'))
}
else
{
- $result=$mailfile->sendfile();
+ //$result=$mailfile->sendfile();
if ($result)
{
$resultmasssend.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
@@ -159,42 +179,53 @@ if ($action == 'presend' && GETPOST('sendmail'))
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
- if ($error)
+ if (! $error)
+ {
+ $resultmasssend.=$langs->trans("MailSent").': '.$sendto."
\n";
+ }
+ else
{
dol_print_error($db);
}
- $compteEmailEnvoi ++;
+ $nbsent++;
}
else
{
$langs->load("other");
- $resultmasssend.='