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

Use tokens in offline contribution receipt (new installs) #22560

Merged
merged 1 commit into from Jan 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRM/Contribute/Form/AdditionalInfo.php
Expand Up @@ -435,14 +435,14 @@ public static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {

[$sendReceipt] = CRM_Core_BAO_MessageTemplate::sendTemplate(
[
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'contribution_offline_receipt',
'workflow' => 'contribution_offline_receipt',
'contactId' => $params['contact_id'],
'contributionId' => $params['contribution_id'],
'tokenContext' => ['contributionId' => (int) $params['contribution_id'], 'contactId' => $params['contact_id']],
'from' => $params['from_email_address'],
'toName' => $contributorDisplayName,
'toEmail' => $contributorEmail,
'isTest' => $form->_mode == 'test',
'isTest' => $form->_mode === 'test',
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
]
Expand Down
Expand Up @@ -9,13 +9,16 @@
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Receipt sent when confirming a back office contribution.
*
* @support template-only
*
* @see CRM_Contribute_Form_AdditionalInfo::emailReceipt
*/
class CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt extends \Civi\WorkflowMessage\GenericWorkflowMessage {
class CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt extends GenericWorkflowMessage {
use CRM_Contribute_WorkflowMessage_ContributionTrait;
public const WORKFLOW = 'contribution_offline_receipt';

Expand Down
20 changes: 20 additions & 0 deletions CRM/Contribute/WorkflowMessage/ContributionTrait.php
Expand Up @@ -21,6 +21,13 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
*/
public $contributionId;

/**
* Is the site configured such that tax should be displayed.
*
* @var bool
*/
public $isShowTax;

/**
* Set contribution object.
*
Expand All @@ -36,4 +43,17 @@ public function setContribution(array $contribution): self {
return $this;
}

/**
* Extra variables to be exported to smarty based on being calculated.
*
* We export isShowTax to denote whether invoicing is enabled but
* hopefully at some point we will separate the assumption that invoicing
* and tax are a package.
*
* @param array $export
*/
protected function exportExtraTplParams(array &$export): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not blocking but I'm wondering if there's some way to phpdoc these to avoid somebody going "I grepped and couldn't find anywhere it's used so let's remove it". You have to hunt to find that there's reflection being used to find functions starting with exportExtra.

$export['isShowTax'] = (bool) Civi::settings()->get('invoicing');
}

}
7,743 changes: 3,851 additions & 3,892 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Expand Up @@ -1216,6 +1216,7 @@ public function testReSubmitSaleTaxAlteredAmount(string $thousandSeparator): voi
'Date Received: April 21st, 2015',
'Paid By: Check',
'Check Number: 12345',
'Financial Type: Donation',
];

$mut->checkMailLog($strings);
Expand Down
Expand Up @@ -45,12 +45,12 @@
</td>
</tr>
<tr>
{if !empty($formValues.contributionType_name)}
{if '{contribution.financial_type_id}'}
<td {$labelStyle}>
{ts}Financial Type{/ts}
</td>
<td {$valueStyle}>
{$formValues.contributionType_name}
{contribution.financial_type_id:label}
</td>
{/if}
</tr>
Expand Down Expand Up @@ -131,13 +131,13 @@
{/foreach}
{/if}

{if isset($totalTaxAmount) && $totalTaxAmount !== 'null'}
{if $isShowTax}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little weird that it now always shows $0 if there's no tax, but I don't think it's a big deal.

Financial Type: Donation

Total Tax Amount : $0.00
Total Amount : $123.45
Date Received: January 21st, 2022  4:40 PM
Receipt Date: January 21st, 2022  4:41 PM
Paid By: Check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait it did before too if you have the tax setting turned on. But now it's adding a time component to the dates whereas it didn't before. I don't personally have a strong opinion on that.

<tr>
<td {$labelStyle}>
{ts}Total Tax Amount{/ts}
</td>
<td {$valueStyle}>
{$totalTaxAmount|crmMoney:$currency}
{contribution.tax_amount}
</td>
</tr>
{/if}
Expand All @@ -147,60 +147,60 @@
{ts}Total Amount{/ts}
</td>
<td {$valueStyle}>
{$formValues.total_amount|crmMoney:$currency}
{contribution.total_amount}
</td>
</tr>

{if !empty($receive_date)}
<tr>
{if '{contribution.receive_date}'}
<tr>
<td {$labelStyle}>
{ts}Date Received{/ts}
</td>
<td {$valueStyle}>
{$receive_date|truncate:10:''|crmDate}
{contribution.receive_date}
</td>
</tr>
{/if}

{if !empty($receipt_date)}
{if '{contribution.receipt_date}'}
<tr>
<td {$labelStyle}>
{ts}Receipt Date{/ts}
</td>
<td {$valueStyle}>
{$receipt_date|truncate:10:''|crmDate}
{contribution.receipt_date}
</td>
</tr>
{/if}

{if !empty($formValues.paidBy) and empty($formValues.hidden_CreditCard)}
{if '{contribution.payment_instrument_id}' and empty($formValues.hidden_CreditCard)}
<tr>
<td {$labelStyle}>
{ts}Paid By{/ts}
</td>
<td {$valueStyle}>
{$formValues.paidBy}
{contribution.payment_instrument_id:label}
</td>
</tr>
{if !empty($formValues.check_number)}
{if '{contribution.check_number}'}
<tr>
<td {$labelStyle}>
{ts}Check Number{/ts}
</td>
<td {$valueStyle}>
{$formValues.check_number}
{contribution.check_number}
</td>
</tr>
{/if}
{/if}

{if !empty($formValues.trxn_id)}
{if '{contribution.trxn_id}'}
<tr>
<td {$labelStyle}>
{ts}Transaction ID{/ts}
</td>
<td {$valueStyle}>
{$formValues.trxn_id}
{contribution.trxn_id}
</td>
</tr>
{/if}
Expand Down
Expand Up @@ -9,8 +9,8 @@

===========================================================
{ts}Contributor{/ts}: {contact.display_name}
{if !empty($formValues.contributionType_name)}
{ts}Financial Type{/ts}: {$formValues.contributionType_name}
{if '{contribution.financial_type_id}'}
{ts}Financial Type{/ts}: {contribution.financial_type_id:label}
{/if}
{if $lineItem}
{foreach from=$lineItem item=value key=priceset}
Expand Down Expand Up @@ -44,24 +44,24 @@
{/foreach}
{/if}

{if isset($totalTaxAmount) && $totalTaxAmount !== 'null'}
{ts}Total Tax Amount{/ts} : {$totalTaxAmount|crmMoney:$currency}
{if $isShowTax}
{ts}Total Tax Amount{/ts} : {contribution.tax_amount}
{/if}
{ts}Total Amount{/ts} : {$formValues.total_amount|crmMoney:$currency}
{if !empty($receive_date)}
{ts}Date Received{/ts}: {$receive_date|truncate:10:''|crmDate}
{ts}Total Amount{/ts} : {contribution.total_amount}
{if '{contribution.receive_date}'}
{ts}Date Received{/ts}: {contribution.receive_date}
{/if}
{if !empty($receipt_date)}
{ts}Receipt Date{/ts}: {$receipt_date|truncate:10:''|crmDate}
{if '{contribution.receipt_date}'}
{ts}Receipt Date{/ts}: {contribution.receipt_date}
{/if}
{if !empty($formValues.paidBy) and empty($formValues.hidden_CreditCard)}
{ts}Paid By{/ts}: {$formValues.paidBy}
{if !empty($formValues.check_number)}
{ts}Check Number{/ts}: {$formValues.check_number}
{if '{contribution.payment_instrument_id}' and empty($formValues.hidden_CreditCard)}
{ts}Paid By{/ts}: {contribution.payment_instrument_id:label}
{if '{contribution.check_number}'}
{ts}Check Number{/ts}: {contribution.check_number}
{/if}
{/if}
{if !empty($formValues.trxn_id)}
{ts}Transaction ID{/ts}: {$formValues.trxn_id}
{if '{contribution.trxn_id}'}
{ts}Transaction ID{/ts}: {contribution.trxn_id}
{/if}

{if !empty($ccContribution)}
Expand Down