Align online membership receipt with other templates for line items, tax
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 17 Nov 2023 03:42:48 +0000 (16:42 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 17 Nov 2023 05:16:04 +0000 (18:16 +1300)
This uses the same code as the offline for the online which

1) removes the last usage on the mystical 'dataArray', allowing us to deprecate it
and remove a lot of code
2) fixes one of the 3 known smarty3 issues in core

tests/phpunit/api/v3/ContributionPageTest.php
xml/templates/message_templates/membership_online_receipt_html.tpl

index 1d6c1c7667f7f844940965cec9babf164064642b..26da68452a6c4954e13413cb248c1f147389e0fe 100644 (file)
@@ -425,7 +425,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->assertCount(2, $contributions);
     $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => ['IN' => array_keys($contributions)]]);
     $mut->checkMailLog([
-      'Membership Amount',
+      'Membership Fee',
       '$2.00',
     ]);
     $mut->stop();
index 900a96362fb9834ca7511b288440512d3974ef0a..e469152b026713a3cd9517cb432e0236f5479d59 100644 (file)
             </td>
           </tr>
         {/if}
-      {elseif empty($useForMember) && !empty($lineItem) and $priceSetID and empty($is_quick_config)}
-        {foreach from=$lineItem item=value key=priceset}
-          <tr>
-            <td colspan="2" {$valueStyle}>
-              <table>
-                <tr>
-                  <th>{ts}Item{/ts}</th>
-                  <th>{ts}Qty{/ts}</th>
-                  <th>{ts}Each{/ts}</th>
+      {elseif $isShowLineItems}
+        <tr>
+          <td colspan="2" {$valueStyle}>
+            <table>
+              <tr>
+                <th>{ts}Item{/ts}</th>
+                <th>{ts}Fee{/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>
                   <th>{ts}Total{/ts}</th>
-                </tr>
-                {foreach from=$value item=line}
-                  <tr>
-                    <td>
-                      {$line.description|truncate:30:"..."}
-                    </td>
-                    <td>
-                      {$line.qty}
-                    </td>
+                {/if}
+                <th>{ts}Membership Start Date{/ts}</th>
+                <th>{ts}Membership Expiration Date{/ts}</th>
+              </tr>
+              {foreach from=$lineItems item=line}
+                <tr>
+                  <td>{$line.title}</td>
+                  <td>
+                    {$line.line_total|crmMoney}
+                  </td>
+                  {if $isShowTax && {contribution.tax_amount|boolean}}
                     <td>
-                      {$line.unit_price|crmMoney}
+                      {$line.line_total|crmMoney:'{contribution.currency}'}
                     </td>
+                    {if $line.tax_rate || $line.tax_amount != ""}
+                      <td>
+                        {$line.tax_rate|string_format:"%.2f"}%
+                      </td>
+                      <td>
+                        {$line.tax_amount|crmMoney:'{contribution.currency}'}
+                      </td>
+                    {else}
+                      <td></td>
+                      <td></td>
+                    {/if}
                     <td>
-                      {$line.line_total|crmMoney}
+                      {$line.line_total_inclusive|crmMoney:'{contribution.currency}'}
                     </td>
-                  </tr>
-                {/foreach}
-              </table>
-            </td>
-          </tr>
-        {/foreach}
-        <tr>
-          <td {$labelStyle}>
-            {ts}Total Amount{/ts}
-          </td>
-          <td {$valueStyle}>
-            {$amount|crmMoney}
+                  {/if}
+                  <td>
+                    {$line.membership.start_date|crmDate:"Full"}
+                  </td>
+                  <td>
+                    {$line.membership.end_date|crmDate:"Full"}
+                  </td>
+                </tr>
+              {/foreach}
+            </table>
           </td>
         </tr>
 
-      {else}
-        {if $useForMember && $lineItem and empty($is_quick_config)}
-           {foreach from=$lineItem item=value key=priceset}
-             <tr>
-               <td colspan="2" {$valueStyle}>
-                <table>
-                  <tr>
-                    <th>{ts}Item{/ts}</th>
-                    <th>{ts}Fee{/ts}</th>
-                    {if !empty($dataArray)}
-                      <th>{ts}SubTotal{/ts}</th>
-                      <th>{ts}Tax Rate{/ts}</th>
-                      <th>{ts}Tax Amount{/ts}</th>
-                      <th>{ts}Total{/ts}</th>
-                    {/if}
-                    <th>{ts}Membership Start Date{/ts}</th>
-                    <th>{ts}Membership Expiration Date{/ts}</th>
-                  </tr>
-                  {foreach from=$value item=line}
-                    <tr>
-                      <td>
-                        {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>
-                        {$line.line_total|crmMoney}
-                      </td>
-                      {if !empty($dataArray)}
-                        <td>
-                          {$line.unit_price*$line.qty|crmMoney}
-                        </td>
-                        {if ($line.tax_rate || $line.tax_amount != "")}
-                          <td>
-                            {$line.tax_rate|string_format:"%.2f"}%
-                          </td>
-                          <td>
-                           {$line.tax_amount|crmMoney}
-                          </td>
-                        {else}
-                          <td></td>
-                          <td></td>
-                        {/if}
-                        <td>
-                          {$line.line_total+$line.tax_amount|crmMoney}
-                        </td>
-                      {/if}
-                      <td>
-                        {$line.start_date}
-                      </td>
-                      <td>
-                        {$line.end_date}
-                      </td>
-                    </tr>
-                  {/foreach}
-                </table>
-               </td>
-             </tr>
-           {/foreach}
-           {if !empty($dataArray)}
+        {if $isShowTax && {contribution.tax_amount|boolean}}
+          <tr>
+            <td {$labelStyle}>
+                {ts}Amount Before Tax:{/ts}
+            </td>
+            <td {$valueStyle}>
+                {contribution.tax_exclusive_amount}
+            </td>
+          </tr>
+          {foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
             <tr>
-             <td {$labelStyle}>
-              {ts}Amount Before Tax:{/ts}
-             </td>
-             <td {$valueStyle}>
-               {contribution.tax_exclusive_amount}
-             </td>
+              <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 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>
-             {else}
-               <td>&nbsp;{ts}NO{/ts} {$taxTerm}</td>
-               <td>&nbsp;{$value|crmMoney:$currency}</td>
-             {/if}
-             </tr>
-            {/foreach}
-           {/if}
-         {/if}
-        {if $totalTaxAmount}
-           <tr>
-             <td {$labelStyle}>
-               {ts}Total Tax Amount{/ts}
-             </td>
-             <td {$valueStyle}>
-               {$totalTaxAmount|crmMoney:$currency}
-             </td>
-           </tr>
-         {/if}
-        <tr>
-           <td {$labelStyle}>
-             {ts}Amount{/ts}
-           </td>
-           <td {$valueStyle}>
-             {$amount|crmMoney} {if isset($amount_level)} - {$amount_level}{/if}
-           </td>
-         </tr>
+          {/foreach}
+        {/if}
       {/if}
-
+      <tr>
+        <td {$labelStyle}>
+            {ts}Amount{/ts}
+        </td>
+        <td {$valueStyle}>
+            {contribution.total_amount} {if isset($amount_level)} - {$amount_level}{/if}
+        </td>
+      </tr>
     {elseif isset($membership_amount)}
       <tr>
         <th {$headerStyle}>