From baf1d7a8028e1cfefb3eedcf3c0a1c13675b81eb Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 30 Dec 2021 11:00:08 +1300 Subject: [PATCH] Add workflow template classes for contributions --- CRM/Contribute/Form/Task/Invoice.php | 3 +- .../ContributionInvoiceReceipt.php | 37 ++++++++++++++++++ .../ContributionOfflineReceipt.php | 22 +++++++++++ .../ContributionOnlineReceipt.php | 29 ++++++++++++++ .../WorkflowMessage/ContributionTrait.php | 39 +++++++++++++++++++ .../CRM/Contribute/Form/Task/InvoiceTest.php | 6 ++- .../contribution_invoice_receipt_html.tpl | 2 + 7 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 CRM/Contribute/WorkflowMessage/ContributionInvoiceReceipt.php create mode 100644 CRM/Contribute/WorkflowMessage/ContributionOfflineReceipt.php create mode 100644 CRM/Contribute/WorkflowMessage/ContributionOnlineReceipt.php create mode 100644 CRM/Contribute/WorkflowMessage/ContributionTrait.php diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index cf238c902edc..9cc366f0507a 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -366,7 +366,6 @@ public static function printPDF($contribIDs, &$params, $contactIds) { 'resourceBase' => $config->userFrameworkResourceURL, 'defaultCurrency' => $config->defaultCurrency, 'amount' => $contribution->total_amount, - 'currency' => $contribution->currency, 'amountDue' => $amountDue, 'amountPaid' => $amountPaid, 'invoice_date' => $invoiceDate, @@ -414,9 +413,9 @@ public static function printPDF($contribIDs, &$params, $contactIds) { $sendTemplateParams = [ 'groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_invoice_receipt', - 'contactId' => $contribution->contact_id, 'tplParams' => $tplParams, 'PDFFilename' => $pdfFileName, + 'tokenContext' => ['contributionId' => $contribution->id, 'contactId' => $contribution->contact_id], ]; // from email address diff --git a/CRM/Contribute/WorkflowMessage/ContributionInvoiceReceipt.php b/CRM/Contribute/WorkflowMessage/ContributionInvoiceReceipt.php new file mode 100644 index 000000000000..977c8b5742c8 --- /dev/null +++ b/CRM/Contribute/WorkflowMessage/ContributionInvoiceReceipt.php @@ -0,0 +1,37 @@ +contribution = $contribution; + if (!empty($contribution['id'])) { + $this->contributionId = $contribution['id']; + } + return $this; + } + +} diff --git a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php index 50bd78df9a9e..90f57e2ba1f2 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php @@ -34,7 +34,7 @@ public function tearDown(): void { * CRM-17815 - Test due date and payment advice block in generated * invoice pdf for pending and completed contributions */ - public function testInvoiceForDueDate() { + public function testInvoiceForDueDate(): void { $contactIds = []; $params = [ 'output' => 'pdf_invoice', @@ -86,7 +86,7 @@ public function testInvoiceForDueDate() { * * @throws \CRM_Core_Exception */ - public function testInvoiceForLineItems() { + public function testInvoiceForLineItems(): void { $this->enableTaxAndInvoicing(); @@ -217,6 +217,8 @@ public function testInvoiceContactFields(): void { $expected = [ 'externalIdentifier (token):::2345', 'displayName (token):::Mr. Anthony Anderson II', + 'currency (token):::GBP', + 'currency (smarty):::GBP', ]; foreach ($expected as $string) { $this->assertStringContainsString($string, $invoiceHTML); diff --git a/tests/templates/message_templates/contribution_invoice_receipt_html.tpl b/tests/templates/message_templates/contribution_invoice_receipt_html.tpl index 7ab5b21f50ac..91a064e320d7 100644 --- a/tests/templates/message_templates/contribution_invoice_receipt_html.tpl +++ b/tests/templates/message_templates/contribution_invoice_receipt_html.tpl @@ -1,3 +1,5 @@ displayName (token):::{contact.display_name} organizationName (token):::{contact.organization_name} externalIdentifier (token):::{contact.external_identifier} +currency (token):::{contribution.currency} +currency (smarty):::{$currency}