Can force recipient of unpaid invoice email reminder

This commit is contained in:
Laurent Destailleur 2022-11-07 14:22:43 +01:00
parent 055627e248
commit 7fae4d1b1c

View File

@ -5424,9 +5424,10 @@ class Facture extends CommonInvoice
* @param int $nbdays Delay after due date (or before if delay is negative) * @param int $nbdays Delay after due date (or before if delay is negative)
* @param string $paymentmode '' or 'all' by default (no filter), or 'LIQ', 'CHQ', CB', ... * @param string $paymentmode '' or 'all' by default (no filter), or 'LIQ', 'CHQ', CB', ...
* @param int|string $template Name (or id) of email template (Must be a template of type 'facture_send') * @param int|string $template Name (or id) of email template (Must be a template of type 'facture_send')
* @param string $forcerecipient Force email of recipient (for example to send the email to an accountant supervisor instead of the customer)
* @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK) * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
*/ */
public function sendEmailsRemindersOnInvoiceDueDate($nbdays = 0, $paymentmode = 'all', $template = '') public function sendEmailsRemindersOnInvoiceDueDate($nbdays = 0, $paymentmode = 'all', $template = '', $forcerecipient = '')
{ {
global $conf, $langs, $user; global $conf, $langs, $user;
@ -5527,6 +5528,9 @@ class Facture extends CommonInvoice
// Recipient // Recipient
$to = array(); $to = array();
if ($forcerecipient) { // If a recipient was forced
$to = array($forcerecipient);
} else {
$res = $tmpinvoice->fetch_thirdparty(); $res = $tmpinvoice->fetch_thirdparty();
$recipient = $tmpinvoice->thirdparty; $recipient = $tmpinvoice->thirdparty;
if ($res > 0) { if ($res > 0) {
@ -5548,6 +5552,7 @@ class Facture extends CommonInvoice
$errormesg = "Failed to load recipient with thirdparty id=".$tmpinvoice->socid; $errormesg = "Failed to load recipient with thirdparty id=".$tmpinvoice->socid;
$error++; $error++;
} }
}
// Sender // Sender
$from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); $from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');