Skip to content

Commit

Permalink
BTHAB-257: Ensure quotation is attached to mail by default
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Oct 17, 2023
1 parent d9a7756 commit abb3f06
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function run(CRM_Core_Form &$form, $formName) {
}

$form->add('checkbox', 'attach_quote', ts('Attach Quotation'));
$form->setDefaults(array_merge($form->_defaultValues, ['attach_quote' => TRUE]));

CRM_Core_Region::instance('page-body')->add([
'template' => "CRM/Civicase/Form/Contribute/AttachQuotation.tpl",
Expand Down
7 changes: 4 additions & 3 deletions CRM/Civicase/Hook/alterMailParams/AttachQuotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public function run(array &$params, $context) {
return;
}

$rendered = $this->getContributionQuotationInvoice($params['tokenContext']['contributionId']);
$contributionId = $params['tokenContext']['contributionId'] ?? $params['tplParams']['id'];
$rendered = $this->getContributionQuotationInvoice($contributionId);

$attachment = CRM_Utils_Mail::appendPDF('quotation_invoice.pdf', $rendered['html'], $rendered['format']);

if ($attachment) {
$params['attachments'][] = $attachment;
$params['attachments']['quotaition_invoice'] = $attachment;
}
}

Expand Down Expand Up @@ -73,7 +74,7 @@ private function getContributionQuotationInvoice($contributionId) {
*/
private function shouldRun(array $params, $context, $shouldAttachQuote) {
$component = $params['tplParams']['component'] ?? '';
if ($component !== 'contribute' || $context !== 'messageTemplate' || empty($shouldAttachQuote)) {
if ($component !== 'contribute' || empty($shouldAttachQuote)) {
return FALSE;
}

Expand Down
1 change: 1 addition & 0 deletions templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{literal}
<script type="text/javascript">
CRM.$(function ($) {
$('#attach_quote').prop('checked', 1)
if ($('#html_message').length) {
$('#html_message').parent().parent().after($('tr.attach-quote'))
Expand Down

0 comments on commit abb3f06

Please sign in to comment.