Skip to content

Commit e7dd094

Browse files
committed
refs #39156, use do_not_notify to restrict the email sending on receipt send task
1 parent 2e96d62 commit e7dd094

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

CRM/Contact/Form/Task/AnnualReceiptEmail/MailingOption.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function preProcess() {
4444
$queryParams = array();
4545
$returnProperties = array(
4646
'sort_name' => 1,
47-
'do_not_email' => 1,
47+
'do_not_notify' => 1,
4848
'is_deceased' => 1,
4949
'email' => 1,
5050
);
@@ -53,14 +53,13 @@ function preProcess() {
5353
CRM_Core_Form::CB_PREFIX . $contactId, '=', 1, 0, 0,
5454
);
5555
}
56-
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties);
5756
$numberofContacts = count($this->_contactIds);
5857
$suppressedDoNotEmail = array();
5958
$suppressedNoRecords = array();
60-
$details = $query->apiQuery($queryParams, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, TRUE);
59+
$details = CRM_Contact_BAO_Query::apiQuery($queryParams, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, TRUE);
6160
if (!empty($details[0])) {
6261
foreach ($details[0] as $contactDetail) {
63-
if (!empty($contactDetail['is_deceased']) || !empty($contactDetail['do_not_email']) || empty($contactDetail['email'])) {
62+
if (!empty($contactDetail['is_deceased']) || !empty($contactDetail['do_not_notify']) || empty($contactDetail['email'])) {
6463
$suppressedDoNotEmail[] = $contactDetail['contact_id'];
6564
}
6665
else {

CRM/Contribute/Form/Task/PDF.php

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ class CRM_Contribute_Form_Task_PDF extends CRM_Contribute_Form_Task {
5757
*/
5858
public $_lastSerialId = '';
5959

60-
6160
protected $_tmpreceipt;
6261

6362
protected $_rows;
6463

64+
private $_suppressedDoNotEmail = array();
65+
6566
/**
6667
* build all the data structures needed to build the form
6768
*
@@ -125,28 +126,40 @@ function preProcess() {
125126

126127
$activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Email Receipt', 'name');
127128
if (!empty($activityTypeId)) {
128-
129129
$this->_enableEmailReceipt = TRUE;
130130
CRM_Utils_System::setTitle(ts('Print or Email Contribution Receipts'));
131131
}
132-
// Check contact email
133-
$emailIsEmpty = FALSE;
134-
$contactId = intval($this->_contactIds);
135-
$emptyEmail = array();
132+
133+
$queryParams = array();
134+
$returnProperties = array(
135+
'sort_name' => 1,
136+
'do_not_notify' => 1,
137+
'is_deceased' => 1,
138+
'email' => 1,
139+
);
136140
foreach ($this->_contactIds as $contactId) {
137-
$contributorDisplayName = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId);
138-
$result = CRM_Core_BAO_Email::allEmails($contactId);
139-
$array = array_values($result);
140-
$email = $array[0]['email'];
141-
if (empty($email)) {
142-
$emailIsEmpty = TRUE;
143-
array_push($emptyEmail,$contributorDisplayName[0]);
141+
$queryParams[] = array(
142+
CRM_Core_Form::CB_PREFIX . $contactId, '=', 0, 0, 0,
143+
);
144+
}
145+
$numberofContacts = count($this->_contactIds);
146+
$emptyEmail = array();
147+
$details = CRM_Contact_BAO_Query::apiQuery($queryParams, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, TRUE);
148+
149+
if (!empty($details[0])) {
150+
foreach ($details[0] as $contactDetail) {
151+
if (!empty($contactDetail['is_deceased']) || !empty($contactDetail['do_not_notify']) || empty($contactDetail['email'])) {
152+
$this->_suppressedDoNotEmail[] = $contactDetail['contact_id'];
153+
$contributorDisplayName = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactDetail['contact_id']);
154+
$emptyEmail[] = $contributorDisplayName[0];
155+
}
144156
}
145157
}
146-
$emptyEmailList = CRM_Utils_Array::implode(",", $emptyEmail);
158+
147159
$actionName = $this->controller->getActionName($this->_name);
148-
if ($emailIsEmpty && $actionName[1] == 'display') {
149-
$this->assign('emptyEmailList', $emptyEmailList);
160+
if ($actionName[1] == 'display' && count($emptyEmail)) {
161+
$this->assign('empty_email_list', $emptyEmail);
162+
$this->assign('suppressed_no_email', count($this->_suppressedDoNotEmail));
150163
}
151164
}
152165

@@ -288,6 +301,12 @@ public function postProcess() {
288301
else if($action == 'upload') {
289302
// #28472, batch sending email pdf receipt
290303
$params = $this->controller->exportValues($this->_name);
304+
foreach($this->_contributionIds as $idx => $contributionId) {
305+
if (in_array($this->_contactIds[$idx], $this->_suppressedDoNotEmail)) {
306+
unset($this->_contributionIds[$idx]);
307+
unset($this->_componentIds[$idx]);
308+
}
309+
}
291310
foreach($this->_contributionIds as $contributionId) {
292311
CRM_Contribute_BAO_Contribution::sendPDFReceipt($contributionId, $params['from_email'], $params['window_envelope'], $params['receipt_text']);
293312
}

templates/CRM/Contact/Form/Task/AnnualReceiptEmail/MailingOption.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ul>
1515
</li>
1616
{if $suppressed_no_email}
17-
<li>{ts count=$suppressed_no_email plural='Email will NOT be sent to %count contacts - (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).'}Email will NOT be sent to %count contact - (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).{/ts}</li>
17+
<li>{ts count=$suppressed_no_email plural='Email will NOT be sent to %count contacts - (no email address on file, or communication preferences specify DO NOT NOTIFY, or contact is deceased).'}Email will NOT be sent to %count contact - (no email address on file, or communication preferences specify DO NOT NOTIFY, or contact is deceased).{/ts}</li>
1818
{/if}
1919
{if $suppressed_no_record}
2020
<li>{ts count=$suppressed_no_record plural='Email will NOT be sent to %count contacts.'}Email will NOT be sent to %count contact.{/ts}{ts}There were no contributions during the selected year.{/ts}</li>

templates/CRM/Contribute/Form/Task/PDF.tpl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
{if !empty($form.email_pdf_receipt.html)}
4848
<span class="description">{ts}Add receipt as attachment in email.{/ts}</span>
4949
{/if}
50-
{if $emptyEmailList}
51-
<span class="description">{$emptyEmailList}{ts}Doesn't have email. Would not generate receipt and send email.{/ts}</span>
52-
{/if}
5350
</div>
5451
<table class="form-layout-compressed pdf-receipt-table" style="display:none;">
5552
<tr class="form-item">
@@ -67,6 +64,20 @@
6764
<td class="label"><label>{$form.receipt_text.label}</label></td>
6865
<td>{$form.receipt_text.html}</td>
6966
</tr>
67+
{if $suppressed_no_email}
68+
<tr class="form-item">
69+
<td colspan="2">
70+
<span class="font-red">{ts count=$suppressed_no_email plural='Email will NOT be sent to %count contacts - (no email address on file, or communication preferences specify DO NOT NOTIFY, or contact is deceased).'}Email will NOT be sent to %count contact - (no email address on file, or communication preferences specify DO NOT NOTIFY, or contact is deceased).{/ts}</span>
71+
{if $empty_email_list}
72+
<ul>
73+
{foreach from=$empty_email_list item=sort_name}
74+
<li><span class="font-red">{$sort_name}</span></li>
75+
{/foreach}
76+
</ul>
77+
{/if}
78+
</td>
79+
</tr>
80+
{/if}
7081
</table>
7182

7283
<div id="dialog-confirm-download" title="{ts}Procceed Receipt Generation?{/ts}" style="display:none;">

0 commit comments

Comments
 (0)