From 664ba283bc3b7a6fafc8114aa073bbb00e0de104 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 6 Oct 2022 09:49:17 +0200 Subject: [PATCH 1/3] fix/feat: on CronJob sendEmailsRemindersOnInvoiceDueDate use billing contact email if exists --- htdocs/compta/facture/class/facture.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 67d5568e438..b781cc15961 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5530,7 +5530,16 @@ class Facture extends CommonInvoice $res = $tmpinvoice->fetch_thirdparty(); $recipient = $tmpinvoice->thirdparty; if ($res > 0) { - if (!empty($recipient->email)) { + $tmparraycontact = $tmpinvoice->liste_contact(-1, 'external', 0, 'BILLING'); + if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { + foreach ($tmparraycontact as $data_email) { + if (!empty($data_email['email'])) { + $to = $data_email['email']; + break; + } + } + } + if (empty($to) && !empty($recipient->email)) { $to = $recipient->email; } else { $errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user."; From fea1b2ef14a333704bae12c415fc9d51ff0457b7 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 10 Oct 2022 15:00:51 +0200 Subject: [PATCH 2/3] review --- htdocs/compta/facture/class/facture.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 32798f3724d..42be01bcc13 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5526,7 +5526,7 @@ class Facture extends CommonInvoice $sendContent = make_substitutions($content, $substitutionarray, $outputlangs, 1); // Recipient - $to = ''; + $to = array(); $res = $tmpinvoice->fetch_thirdparty(); $recipient = $tmpinvoice->thirdparty; if ($res > 0) { @@ -5534,13 +5534,12 @@ class Facture extends CommonInvoice if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { foreach ($tmparraycontact as $data_email) { if (!empty($data_email['email'])) { - $to = $data_email['email']; - break; + $to[] = $data_email['firstname'] . ' '. $data_email['lastname']. '<'.$data_email['email'].'>'; } } } if (empty($to) && !empty($recipient->email)) { - $to = $recipient->email; + $to[] = $recipient->email; } else { $errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user."; $error++; @@ -5557,9 +5556,11 @@ class Facture extends CommonInvoice $error++; } - if (!$error && $to) { + if (!$error && !empty($to)) { $this->db->begin(); + $to = implode(',', $to); + // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; From 26a1825411f0c0a81b1bb7b13f211587679d66c5 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 10 Oct 2022 15:54:03 +0200 Subject: [PATCH 3/3] review --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 42be01bcc13..69bfb73e867 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5534,7 +5534,7 @@ class Facture extends CommonInvoice if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { foreach ($tmparraycontact as $data_email) { if (!empty($data_email['email'])) { - $to[] = $data_email['firstname'] . ' '. $data_email['lastname']. '<'.$data_email['email'].'>'; + $to[] = $tmpinvoice->thirdparty->contact_get_property($data_email['id'], 'email'); } } }