Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIWEMB-422: Update CreditNote email functionality #62

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions CRM/Financeextras/Form/Contribute/CreditNoteEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,14 @@ public function submit(array $formValues): void {
$sents += ($sent ? 1 : 0);
}

CRM_Core_Session::setStatus(ts('One email has been sent successfully. ', [
'plural' => '%count emails were sent successfully. ',
'count' => $sents,
]), ts('Message Sent', ['plural' => 'Messages Sent', 'count' => $sents]), 'success');
CRM_Core_Session::setStatus(ts('Credit Note Sent by Email Successfully.'), ts('Message Sent'), 'success');

Civi::dispatcher()->dispatch(CreditNoteMailedEvent::NAME, new CreditNoteMailedEvent(
$this->creditNoteId,
$creditNoteInvoice,
$this->getSubject(),
array_column($this->getRowsForEmails(), 'contact_id')
$subject,
array_column($this->getRowsForEmails(), 'contact_id'),
$html . $additionalDetails
));
}

Expand Down
5 changes: 5 additions & 0 deletions Civi/Financeextras/Event/CreditNoteMailedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
protected array $creditNoteInvoice,
protected string $mailSubject,
protected array $contactIds,
protected string $details,
) {
}

Expand All @@ -36,4 +37,8 @@ public function getMailedContacts() {
return $this->contactIds;
}

public function getDetails() {
return $this->details;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function createDownloadActivity(CreditNoteDownloadedEvent $e) {
$subject = 'Downloaded Credit Note PDF';
$targetContactId = $this->getCreditNoteContactId($e->getCreditNoteId());
$attachment = $this->storeFile($e->getCreditNoteInvoice()['html'], $e->getCreditNoteInvoice()['format']);
$this->createActivity([$targetContactId], $activityType, $subject, $attachment);
$this->createActivity([$targetContactId], $activityType, $subject, $attachment, '');
}

/**
Expand All @@ -42,7 +42,7 @@ public function createDownloadActivity(CreditNoteDownloadedEvent $e) {
public function createMailActivity(CreditNoteMailedEvent $e) {
$activityType = 'Emailed Invoice';
$attachment = $this->storeFile($e->getCreditNoteInvoice()['html'], $e->getCreditNoteInvoice()['format']);
$this->createActivity($e->getMailedContacts(), $activityType, $e->getSubject(), $attachment);
$this->createActivity($e->getMailedContacts(), $activityType, $e->getSubject(), $attachment, $e->getDetails());
}

/**
Expand All @@ -52,8 +52,9 @@ public function createMailActivity(CreditNoteMailedEvent $e) {
* @param string $type
* @param string $subject
* @param array $attachment
* @param string $details
*/
private function createActivity($targetContactIds, $type, $subject, $attachment) {
private function createActivity($targetContactIds, $type, $subject, $attachment, $details) {
$now = (new DateTime())->format('YmdHis');
$currentUser = \CRM_Core_Session::singleton()->get('userID');
\Civi\Api4\Activity::create()
Expand All @@ -62,6 +63,7 @@ private function createActivity($targetContactIds, $type, $subject, $attachment)
->addValue('source_contact_id', $currentUser)
->addValue('activity_type_id:name', $type)
->addValue('activity_date_time', $now)
->addValue('details', $details)
->addValue('attachFile_1', [
'uri' => $attachment,
'type' => 'application/pdf',
Expand Down
21 changes: 12 additions & 9 deletions templates/CRM/Financeextras/Form/Contribute/CreditNoteEmail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
<td>{$form.template.html}</td>
</tr>
<tr class="crm-contactEmail-form-block-subject">
<td class="label">{$form.subject.label}</td>
<td>
{$form.subject.html|crmAddClass:huge}&nbsp;
</td>
</tr>
<tr class="crm-email-element">
<td class="label">{ts}Email body{/ts}</td>
<td><div class="html">{$form.html_message.html}</div></td>
</tr>
<td class="label">{$form.subject.label}</td>
<td>
{$form.subject.html|crmAddClass:huge}&nbsp;
<input class="crm-token-selector big" data-field="subject" />
{help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
</td>
</tr>
</table>

{include file="CRM/Contact/Form/Task/EmailCommon.tpl" noAttach=0}

<div class="spacer"></div>
<div class="crm-submit-buttons">
{$form.buttons.html}
Expand All @@ -46,6 +46,9 @@
<script>

CRM.$(function($) {
$('.crm-plaint_text_email-accordion').hide();
$('#attachments').parent().parent().hide()
$('#saveTemplate').parent().hide();
var sourceDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1' h=0 }{literal}";

var $form = $("form.{/literal}{$form.formClass}{literal}");
Expand Down
Loading