From 055627e248a713de787e57c278473200b238c4eb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Nov 2022 14:16:04 +0100 Subject: [PATCH] NEW scheduled job to send unpaid invoice reminder can use the cc and bcc of template. --- htdocs/compta/facture/class/facture.class.php | 20 +++++++++++++++++-- htdocs/core/class/html.formmail.class.php | 9 +++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 183ee457c32..1e770ccd08b 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5550,7 +5550,10 @@ class Facture extends CommonInvoice } // Sender - $from = $conf->global->MAIN_MAIL_EMAIL_FROM; + $from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); + if (!empty($arraymessage->email_from)) { // If a sender is defined into template, we use it in priority + $from = $arraymessage->email_from; + } if (empty($from)) { $errormesg = "Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM"; $error++; @@ -5560,6 +5563,9 @@ class Facture extends CommonInvoice $this->db->begin(); $to = implode(',', $to); + if (!empty($arraymessage->email_to)) { // If a recipient is defined into template, we add it + $to = $to.','.$arraymessage->email_to; + } // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; @@ -5567,8 +5573,18 @@ class Facture extends CommonInvoice $trackid = 'inv'.$tmpinvoice->id; $sendcontext = 'standard'; + $email_tocc = ''; + if (!empty($arraymessage->email_tocc)) { // If a CC is defined into template, we use it + $email_tocc = $arraymessage->email_tocc; + } + + $email_tobcc = ''; + if (!empty($arraymessage->email_tobcc)) { // If a BCC is defined into template, we use it + $email_tobcc = $arraymessage->email_tobcc; + } + // Mail Creation - $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', $trackid, '', $sendcontext, ''); + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), $email_tocc, $email_tobcc, 0, 1, $errors_to, '', $trackid, '', $sendcontext, ''); // Sending Mail if ($cMailFile->sendfile()) { diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 41cf2482f9a..aa2ee4b3e6a 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1305,9 +1305,9 @@ class FormMail extends Form $languagetosearchmain = ''; } - $sql = "SELECT rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang"; + $sql = "SELECT rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc"; $sql .= " FROM ".$dbs->prefix().'c_email_templates'; - $sql .= " WHERE (type_template='".$dbs->escape($type_template)."' OR type_template='all')"; + $sql .= " WHERE (type_template = '".$dbs->escape($type_template)."' OR type_template = 'all')"; $sql .= " AND entity IN (".getEntity('c_email_templates').")"; $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned if ($active >= 0) { @@ -1728,6 +1728,11 @@ class ModelMail public $lang; public $joinfiles; + public $email_from; + public $email_to; + public $email_tocc; + public $email_tobcc; + /** * @var string Module the template is dedicated for */