Fix online membership receipt to be form-independent
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 1 Dec 2023 06:11:49 +0000 (19:11 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 1 Dec 2023 23:16:04 +0000 (12:16 +1300)
CRM/Financial/BAO/Order.php
CRM/Member/WorkflowMessage/Membership/Membership.php
xml/templates/message_templates/membership_online_receipt_html.tpl

index bd934a62fb00e26417e8361f623042bc6bf03d16..fc2d59e61cd5f01522fbbd2306e0dbc6f40ad352 100644 (file)
@@ -1241,6 +1241,8 @@ class CRM_Financial_BAO_Order {
     }
     else {
       $lineItem['line_total'] = $this->getOverrideTotalAmount();
+      $lineItem['tax_amount'] = 0.0;
+      $lineItem['line_total_inclusive'] = $lineItem['line_total'];
     }
     if (!empty($lineItem['qty'])) {
       $lineItem['unit_price'] = $lineItem['line_total'] / $lineItem['qty'];
index f12c594bcf2c354f99b027a5694abbb1931306cc..1169ea498f5de9d3fc95ae7399e06553e306de74 100644 (file)
@@ -106,7 +106,6 @@ class CRM_Member_WorkflowMessage_Membership_Membership extends WorkflowMessageEx
       'contact_id' => 100,
       'financial_type_id' => $example['membership_type']['financial_type_id'],
       'receive_date' => '2021-07-23 15:39:20',
-      'total_amount' => $example['membership_type']['minimum_amount'],
       'fee_amount' => .99,
       'net_amount' => $example['membership_type']['minimum_amount'] - .99,
       'currency' => $example['currency'],
@@ -131,8 +130,14 @@ class CRM_Member_WorkflowMessage_Membership_Membership extends WorkflowMessageEx
     $mockOrder->setTemplateContributionID(50);
 
     if (empty($example['is_show_line_items'])) {
-      $mockOrder->setPriceSetToDefault('membership');
-      $mockOrder->setOverrideTotalAmount($example['membership_type']['minimum_fee']);
+      if (empty($example['contribution_page_id'])) {
+        $mockOrder->setOverrideTotalAmount($example['membership_type']['minimum_fee']);
+        $mockOrder->setPriceSetToDefault('membership');
+      }
+      else {
+        $priceSet = $this->getPriceSet()[$example['price_set_id']];
+        $mockOrder->setPriceSetID($priceSet['id']);
+      }
       $mockOrder->setDefaultFinancialTypeID($example['membership_type']['financial_type_id']);
     }
     else {
@@ -144,15 +149,14 @@ class CRM_Member_WorkflowMessage_Membership_Membership extends WorkflowMessageEx
     }
     foreach (PriceField::get()->addWhere('price_set_id', '=', $mockOrder->getPriceSetID())->execute() as $index => $priceField) {
       $priceFieldValue = PriceFieldValue::get()->addWhere('price_field_id', '=', $priceField['id'])->execute()->first();
-      if (empty($example['is_show_line_items'])) {
-        $priceFieldValue['amount'] = $contribution['total_amount'];
-        $priceFieldValue['financial_type_id'] = $contribution['financial_type_id'];
-      }
       $this->setLineItem($mockOrder, $priceField, $priceFieldValue, $index, $membership);
     }
 
     $contribution['total_amount'] = $mockOrder->getTotalAmount();
     $contribution['tax_amount'] = $mockOrder->getTotalTaxAmount() ? round($mockOrder->getTotalTaxAmount(), 2) : 0;
+    $contribution['amount_level'] = $mockOrder->getAmountLevel();
+    $contribution['address_id.name'] = 'Barbara Mary Jones';
+    $contribution['address_id.display'] = "123 Main Street\nMega City";
     $messageTemplate->setContribution($contribution);
     $messageTemplate->setOrder($mockOrder);
     $messageTemplate->setContribution($contribution);
@@ -204,6 +208,7 @@ class CRM_Member_WorkflowMessage_Membership_Membership extends WorkflowMessageEx
       'label' => $priceFieldValue['label'],
       'financial_type_id' => $priceFieldValue['financial_type_id'],
       'non_deductible_amount' => $priceFieldValue['non_deductible_amount'],
+      'membership_type_id' => $priceFieldValue['membership_type_id'],
     ];
     if (!empty($priceFieldValue['membership_type_id'])) {
       $lineItem['membership'] = ['start_date' => $membership['start_date'], 'end_date' => $membership['end_date']];
index 9375ed21efc5657333f3bee18618a03653b14f1e..3f6004244639bf39eb9220ee110ffca6b2e8c1a0 100644 (file)
@@ -43,7 +43,7 @@
         {ts}Membership Type{/ts}
        </td>
        <td {$valueStyle}>
-         {ts}{membership.membership_type_id:name}{/ts}
+         {ts}{membership.membership_type_id:label}{/ts}
        </td>
       </tr>
       {if {membership.start_date|boolean}}
        </tr>
       {/if}
     {/if}
-    {if $amount}
+    {if {contribution.total_amount|boolean}}
       <tr>
         <th {$headerStyle}>{ts}Membership Fee{/ts}</th>
       </tr>
 
       {if !$isShowLineItems && {contribution.total_amount|boolean}}
-        <tr>
-          <td {$labelStyle}>
-            {ts 1=$membership_name}%1 Membership{/ts}
-          </td>
-          <td {$valueStyle}>
-            {$membership_amount|crmMoney}
-          </td>
-        </tr>
-        {if $amount && !$is_separate_payment}
-          <tr>
-            <td {$labelStyle}>
-              {ts}Contribution Amount{/ts}
-            </td>
-            <td {$valueStyle}>
-              {$amount|crmMoney}
-            </td>
-          </tr>
+        {foreach from=$lineItems item=line}
           <tr>
             <td {$labelStyle}>
-              {ts}Total{/ts}
+              {if $line.membership_type_id}
+                {ts 1="{membership.membership_type_id:label}"}%1 Membership{/ts}
+              {else}
+                {ts}Contribution Amount{/ts}
+              {/if}
             </td>
             <td {$valueStyle}>
-              {contribution.total_amount}
+              {$line.line_total_inclusive|crmMoney:'{contribution.currency}'}
             </td>
           </tr>
-        {/if}
+        {/foreach}
       {elseif $isShowLineItems}
         <tr>
           <td colspan="2" {$valueStyle}>
             {ts}Amount{/ts}
         </td>
         <td {$valueStyle}>
-            {contribution.total_amount} {if isset($amount_level)} - {$amount_level}{/if}
+            {contribution.total_amount}
         </td>
       </tr>
     {/if}
       </tr>
     {/if}
 
-    {if !empty($trxn_id)}
+    {if {contribution.trxn_id|boolean}}
       <tr>
        <td {$labelStyle}>
         {ts}Transaction #{/ts}
        </td>
        <td {$valueStyle}>
-        {$trxn_id}
-       </td>
-      </tr>
-     {/if}
-
-    {if !empty($membership_trx_id)}
-      <tr>
-       <td {$labelStyle}>
-         {ts}Membership Transaction #{/ts}
-       </td>
-       <td {$valueStyle}>
-         {$membership_trx_id}
+         {contribution.trxn_id}
        </td>
       </tr>
     {/if}
-    {if !empty($is_recur)}
+
+    {if {contribution.contribution_recur_id|boolean}}
       <tr>
         <td colspan="2" {$labelStyle}>
           {ts}This membership will be renewed automatically.{/ts}
       {/foreach}
     {/if}
 
-    {if !empty($billingName)}
+    {if {contribution.address_id.display|boolean}}
       <tr>
         <th {$headerStyle}>
           {ts}Billing Name and Address{/ts}
       </tr>
       <tr>
         <td colspan="2" {$valueStyle}>
-          {$billingName}<br />
-          {$address|nl2br}<br />
-          {$email}
+          {contribution.address_id.name}<br/>
+          {contribution.address_id.display}
         </td>
       </tr>
-    {elseif !empty($email)}
+    {/if}
+    {if {contact.email_primary.email|boolean}}
       <tr>
         <th {$headerStyle}>
           {ts}Registered Email{/ts}
       </tr>
       <tr>
         <td colspan="2" {$valueStyle}>
-          {$email}
+          {contact.email_primary.email}
         </td>
       </tr>
     {/if}