Skip to content

Commit

Permalink
Update online_event_template to use workflow message
Browse files Browse the repository at this point in the history
This updates the default online event template to use the variables assigned by
the workflow template

This works to standardise the variables previously in dataArray
, lineItem, totalAmount, taxAmount to reflect the
approach in other templates per
https://docs.civicrm.org/user/en/latest/email/message-templates/#variables-and-tokens-in-workflow-message-templates

However, for participants, per the helpful discussion at
civicrm#24576

the expectation is that the primaryParticipant gets the values for
all participants whereas the others only get line items,
tax breakdowns, totals that relate to them.

Hence I have assigned an array participants that holds detials for all participants
and the template iterates through them showing all or just the
one that relates to the assigned participant id depending on
whether it is primary.

This allows the template to display in the Message preview and should
also mean that those values that I have addressed will always reflect
the participantID being used. This also addresses some notices
and incompatibility with secure smarty.

However, there are still values I haven't made sense of, or otherwise left
out of the scope of this PR in the template.

Also note I updated the taxBreakdown in the contribution trait - I decided it
was cloberring the amount as it iterated through the line items - rather than
doing a running total.
  • Loading branch information
eileenmcnaughton committed Jun 19, 2023
1 parent 0ae0257 commit 947b7cf
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 90 deletions.
19 changes: 14 additions & 5 deletions CRM/Contribute/WorkflowMessage/ContributionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,20 @@ public function getTaxRateBreakdown(): array {
}
$this->taxRateBreakdown = [];
foreach ($this->getLineItems() as $lineItem) {
$this->taxRateBreakdown[$lineItem['tax_rate']] = [
'amount' => $lineItem['tax_amount'] ?? 0,
'rate' => $lineItem['tax_rate'],
'percentage' => sprintf('%.2f', $lineItem['tax_rate']),
];
if (!isset($this->taxRateBreakdown[$lineItem['tax_rate']])) {
$this->taxRateBreakdown[$lineItem['tax_rate']] = [
'amount' => 0,
'rate' => $lineItem['tax_rate'],
'percentage' => sprintf('%.2f', $lineItem['tax_rate']),
];
}
$this->taxRateBreakdown[$lineItem['tax_rate']]['amount'] += $lineItem['tax_amount'] ?? 0;
}
// Remove the rates with no value.
foreach ($this->taxRateBreakdown as $rate => $details) {
if ($details['amount'] === 0.0) {
unset($this->taxRateBreakdown[$rate]);
}
}
if (array_keys($this->taxRateBreakdown) === [0]) {
// If the only tax rate charged is 0% then no tax breakdown is returned.
Expand Down
159 changes: 74 additions & 85 deletions xml/templates/message_templates/event_online_receipt_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -180,108 +180,97 @@
</td>
</tr>
{/if}
{if !empty($event.is_monetary) and empty($isRequireApproval)}
{if {event.is_monetary|boolean} and empty($isRequireApproval)}

<tr>
<th {$headerStyle}>
{if !empty($event.fee_label)}{$event.fee_label}{/if}
{event.fee_label}
</th>
</tr>

{if !empty($lineItem)}
{foreach from=$lineItem item=value key=priceset}
{if $value neq 'skip'}
{if !empty($isPrimary)}
{if $lineItem|@count GT 1} {* Header for multi participant registration cases. *}
<tr>
<td colspan="2" {$labelStyle}>
{ts 1=$priceset+1}Participant %1{/ts} {if !empty($part.$priceset)}{$part.$priceset.info}{/if}
</td>
</tr>
{/if}
{/if}
<tr>
<td colspan="2" {$valueStyle}>
<table>
{if $isShowLineItems}
{foreach from=$participants key=index item=participant}
{if $isPrimary && $lineItems|@count GT 1} {* Header for multi participant registration cases. *}
<tr>
<th>{ts}Item{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Each{/ts}</th>
{if !empty($dataArray)}
<th>{ts}SubTotal{/ts}</th>
<th>{ts}Tax Rate{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Total{/ts}</th>
{if !empty($pricesetFieldsCount) }<th>{ts}Total Participants{/ts}</th>{/if}
</tr>
{foreach from=$value item=line}
<tr>
<td {$tdfirstStyle}>
{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description}<div>{$line.description|truncate:30:"..."}</div>{/if}
</td>
<td {$tdStyle} align="middle">
{$line.qty}
<td colspan="2" {$labelStyle}>
{ts 1=$participant.index}Participant %1{/ts} {$participant.contact.display_name}
</td>
<td {$tdStyle}>
{$line.unit_price|crmMoney:$currency}
</td>
{if !empty($dataArray)}
<td {$tdStyle}>
{$line.unit_price*$line.qty|crmMoney}
</td>
{if $line.tax_rate || $line.tax_amount != ""}
</tr>
{/if}

<tr>
<td colspan="2" {$valueStyle}>
<table>
<tr>
<th>{ts}Item{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Each{/ts}</th>
{if $isShowTax && {contribution.tax_amount|boolean}}
<th>{ts}Subtotal{/ts}</th>
<th>{ts}Tax Rate{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Total{/ts}</th>
{if !empty($pricesetFieldsCount)}<th>{ts}Total Participants{/ts}</th>{/if}
</tr>
{foreach from=$participant.line_items item=line}
<tr>
<td {$tdfirstStyle}>
{$line.title}
</td>
<td {$tdStyle} align="middle">
{$line.qty}
</td>
<td {$tdStyle}>
{$line.tax_rate|string_format:"%.2f"}%
{$line.unit_price|crmMoney:$currency}
</td>
{if $line.tax_rate || $line.tax_amount != ""}
<td>{$line.tax_rate|string_format:"%.2f"}%</td>
<td>{$line.tax_amount|crmMoney:$currency}</td>
{else}
<td></td>
<td></td>
{/if}
<td {$tdStyle}>
{$line.tax_amount|crmMoney}
{$line.line_total+$line.tax_amount|crmMoney:$currency}
</td>
{else}
<td></td>
<td></td>
{/if}
{/if}
<td {$tdStyle}>
{$line.line_total+$line.tax_amount|crmMoney:$currency}
</td>
{if !empty($pricesetFieldsCount) }<td {$tdStyle}>{$line.participant_count}</td> {/if}
</tr>
{if !empty($pricesetFieldsCount)}<td {$tdStyle}>{$line.participant_count}</td> {/if}
</tr>
{/foreach}
{if !empty($individual)}
{if $isShowTax}
<tr {$participantTotal}>
<td colspan=3>{ts}Participant Total{/ts}</td>
<td colspan=2>{$individual.$priceset.totalAmtWithTax-$individual.$priceset.totalTaxAmt|crmMoney}</td>
<td colspan=1>{$individual.$priceset.totalTaxAmt|crmMoney}</td>
<td colspan=2>{$individual.$priceset.totalAmtWithTax|crmMoney}</td>
<td colspan=2>{$participant.totals.total_amount_exclusive|crmMoney}</td>
<td colspan=1>{$participant.totals.tax_amount|crmMoney}</td>
<td colspan=2>{$participant.totals.total_amount_inclusive|crmMoney}</td>
</tr>
{/if}
</table>
</table>
</td>
</tr>
</tr>
{/foreach}
{/if}
{/foreach}
{if !empty($dataArray)}
{if isset($totalAmount) and isset($totalTaxAmount)}
<tr>
<td {$labelStyle}>
{ts} Amount Before Tax: {/ts}
</td>
<td {$valueStyle}>
{$totalAmount-$totalTaxAmount|crmMoney}
</td>
{if $isShowTax && {contribution.tax_amount|boolean}}
<tr>
<td {$labelStyle}>
{ts}Amount Before Tax:{/ts}
</td>
<td {$valueStyle}>
{if $isPrimary}{contribution.tax_exclusive_amount}{else}{$participant.totals.total_amount_exclusive|crmMoney}{/if}
</td>
</tr>

{if !$isPrimary}
{* Use the participant specific tax rate breakdown *}
{assign var=taxRateBreakdown value=$participant.tax_rate_breakdown}
{/if}
{foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
<tr>
<td {$labelStyle}>{if $taxRate == 0}{ts}No{/ts} {$taxTerm}{else}{$taxTerm} {$taxDetail.percentage}%{/if}</td>
<td {$valueStyle}>{$taxDetail.amount|crmMoney:'{contribution.currency}'}</td>
</tr>
{/foreach}
{/if}
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0}
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
{/foreach}
{/if}
{/if}

{if !empty($amounts) && empty($lineItem)}
{foreach from=$amounts item=amnt key=level}
Expand All @@ -293,13 +282,13 @@
{/foreach}
{/if}

{if isset($totalTaxAmount)}
{if $isShowTax && {contribution.tax_amount|boolean}}
<tr>
<td {$labelStyle}>
{ts}Total Tax Amount{/ts}
</td>
<td {$valueStyle}>
{$totalTaxAmount|crmMoney:$currency}
{if $isPrimary}{contribution.tax_amount}{else}{$participant.totals.tax_amount|crmMoney}{/if}
</td>
</tr>
{/if}
Expand All @@ -309,7 +298,7 @@
{ts}Total Amount{/ts}
</td>
<td {$valueStyle}>
{if !empty($totalAmount)}{$totalAmount|crmMoney:$currency}{/if} {if !empty($hookDiscount.message)}({$hookDiscount.message}){/if}
{contribution.total_amount} {if !empty($hookDiscount.message)}({$hookDiscount.message}){/if}
</td>
</tr>
{if !empty($pricesetFieldsCount) }
Expand Down Expand Up @@ -483,7 +472,7 @@
<tr>
<td colspan="2" {$valueStyle}>
{ts 1=$selfcancelxfer_time 2=$selfservice_preposition}You may transfer your registration to another participant or cancel your registration up to %1 hours %2 the event.{/ts} {if !empty($totalAmount)}{ts}Cancellations are not refundable.{/ts}{/if}<br />
{capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participantID`&{contact.checksum}" h=0 a=1 fe=1}{/capture}
{capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`{participant.id}`&{contact.checksum}" h=0 a=1 fe=1}{/capture}
<a href="{$selfService}">{ts}Click here to transfer or cancel your registration.{/ts}</a>
</td>
</tr>
Expand Down

0 comments on commit 947b7cf

Please sign in to comment.