Update membership offline receipt away from form dependence
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 27 Mar 2023 06:34:34 +0000 (19:34 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 27 Apr 2023 22:51:05 +0000 (10:51 +1200)
12 files changed:
CRM/Batch/Form/Entry.php
CRM/Contribute/WorkflowMessage/ContributionTrait.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php
CRM/Member/WorkflowMessage/Membership/Membership.php [new file with mode: 0644]
CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php
CRM/Member/WorkflowMessage/MembershipOnlineReceipt.php
CRM/Member/WorkflowMessage/MembershipTrait.php
Civi/Test/ExampleData/Contact/Barb.php
tests/phpunit/CRM/Member/Form/MembershipTest.php
xml/templates/message_templates/membership_offline_receipt_html.tpl
xml/templates/message_templates/membership_offline_receipt_text.tpl

index 7a4a7fe715494976c4201fca52ae3308e90fe262..a29e665abe393878010a5707e7499ddce516f3a1 100644 (file)
@@ -968,7 +968,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
         'modelProps' => [
           'contributionId' => $this->getCurrentRowContributionID(),
           'contactId' => $form->_receiptContactId,
-          'membershipId' => $this->getCurrentRowMembershipID(),
+          'membershipID' => $this->getCurrentRowMembershipID(),
         ],
       ]
     );
index 91db22e4c529bb9a7796af6e3440e7993c92c286..7cdaed94b98a5f760be2069e1bf96b3c8fbd9184 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Api4\Membership;
+
 /**
  * @method array getContribution()
  * @method ?int getContributionID()
@@ -17,7 +19,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
 
   /**
    * @var int
-   * @scope tokenContext as contributionId
+   * @scope tokenContext as contributionId, tplParams as contributionID
    */
   public $contributionId;
 
@@ -87,6 +89,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
    * Get bool for whether a line item breakdown be displayed.
    *
    * @return bool
+   * @noinspection PhpUnused
    */
   public function getIsShowLineItems(): bool {
     if (isset($this->isShowLineItems)) {
@@ -107,6 +110,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
    * Get the line items.
    *
    * @return array
+   * @throws \CRM_Core_Exception
    */
   public function getLineItems(): array {
     if (isset($this->lineItems)) {
@@ -119,13 +123,23 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
       // always have the contribution ID available as well as migrated ones.
       return [];
     }
-    return $order->getLineItems();
+    $lineItems = $order->getLineItems();
+    foreach ($lineItems as $index => $lineItem) {
+      if ($lineItem['entity_table'] === 'civicrm_membership' && !empty($lineItem['entity_id'])) {
+        // Add in some per line membership details. This could also go in the Order class?
+        $lineItems[$index]['membership'] = Membership::get(FALSE)->addWhere('id', '=', $lineItem['entity_id'])->addSelect('start_date', 'end_date')->execute()->first();
+      }
+    }
+    return $lineItems;
   }
 
   /**
    * Get the line items.
    *
    * @return array
+   * @throws \CRM_Core_Exception
+   *
+   * @noinspection PhpUnused
    */
   public function getTaxRateBreakdown(): array {
     if (isset($this->taxRateBreakdown)) {
@@ -184,6 +198,8 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
    * and tax are a package.
    *
    * @param array $export
+   *
+   * @noinspection PhpUnused
    */
   protected function exportExtraTplParams(array &$export): void {
     $export['isShowTax'] = (bool) Civi::settings()->get('invoicing');
index e0e362a8508f78991558a31148ff8a639b157177..2fbd84e928a695302babd6ee5564f242cd2f8041 100644 (file)
@@ -983,7 +983,7 @@ DESC limit 1");
           'receiptText' => $this->getSubmittedValue('receipt_text'),
           'contributionId' => $formValues['contribution_id'],
           'contactId' => $this->_receiptContactId,
-          'membershipId' => $this->getMembershipID(),
+          'membershipID' => $this->getMembershipID(),
         ],
       ]
     );
index 82dd22d5b690e951573292e3f5af3c7900764af0..26725094528be455d4c3cf14979bd126f2ebcb4c 100644 (file)
@@ -705,7 +705,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
         'modelProps' => [
           'receiptText' => $this->getSubmittedValue('receipt_text'),
           'contactId' => $this->_receiptContactId,
-          'contributionID' => $this->getContributionID(),
+          'contributionId' => $this->getContributionID(),
           'membershipID' => $this->_membershipId,
         ],
       ]
diff --git a/CRM/Member/WorkflowMessage/Membership/Membership.php b/CRM/Member/WorkflowMessage/Membership/Membership.php
new file mode 100644 (file)
index 0000000..25c46a6
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+
+use Civi\Api4\MembershipType;
+use Civi\Api4\PriceField;
+use Civi\Api4\PriceFieldValue;
+use Civi\Api4\PriceSet;
+use Civi\Api4\WorkflowMessage;
+use Civi\Test;
+use Civi\WorkflowMessage\GenericWorkflowMessage;
+use Civi\WorkflowMessage\WorkflowMessageExample;
+
+/**
+ * Examples for membership templates.
+ *
+ * @noinspection PhpUnused
+ */
+class CRM_Member_WorkflowMessage_Membership_Membership extends WorkflowMessageExample {
+
+  /**
+   * Get the examples this class is able to deliver.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function getExamples(): iterable {
+    if (!CRM_Core_Component::isEnabled('CiviMember')) {
+      return;
+    }
+    $membershipType = MembershipType::get(FALSE)->execute()->first();
+    if (empty($membershipType)) {
+      return;
+    }
+    $workflows = ['membership_online_receipt', 'membership_offline_receipt'];
+    $defaultCurrency = \Civi::settings()->get('defaultCurrency');
+    $priceSets = $this->getPriceSet();
+
+    foreach ($workflows as $workflow) {
+      foreach ($priceSets as $priceSet) {
+        yield [
+          'name' => 'workflow/' . $workflow . '/' . strtolower($membershipType['name']) . '_' . strtolower($priceSet['name']) . '_' . strtolower($defaultCurrency),
+          'title' => $priceSet['title'] . ' - ' . $membershipType['name'] . ' : ' . $defaultCurrency,
+          'tags' => ['preview'],
+          'workflow' => $workflow,
+          'membership_type' => $membershipType,
+          'currency' => $defaultCurrency,
+          'price_set_id' => $priceSet['id'],
+          'is_show_line_items' => !$priceSets['is_quick_config'],
+        ];
+      }
+    }
+  }
+
+  /**
+   * Build an example to use when rendering the workflow.
+   *
+   * @param array $example
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function build(array &$example): void {
+    $workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first();
+    $this->setWorkflowName($workFlow['name']);
+    $messageTemplate = new $workFlow['class']();
+    $this->addExampleData($messageTemplate, $example);
+    $example['data'] = $this->toArray($messageTemplate);
+  }
+
+  /**
+   * Add relevant example data.
+   *
+   * @param \CRM_Member_WorkflowMessage_MembershipOfflineReceipt|\CRM_Member_WorkflowMessage_MembershipOnlineReceipt $messageTemplate
+   * @param array $example
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
+   */
+  private function addExampleData(GenericWorkflowMessage $messageTemplate, array $example): void {
+    $messageTemplate->setContact(Test::example('entity/Contact/Barb'));
+
+    $membership = [
+      'membership_type_id' => $example['membership_type']['id'],
+      'membership_type_id:name' => $example['membership_type']['name'],
+      'membership_type_id:label' => $example['membership_type']['name'],
+      'status_id:name' => 'Current',
+      'start_date' => date('Y-m-05', strtotime('-1 month')),
+      // Ideally we would leave blank for lifetime & maybe calculate more meaningfully.
+      'end_date' => date('Y-m-05', strtotime('+ 11 months')),
+    ];
+    $messageTemplate->setMembership($membership);
+
+    $contribution = [
+      'id' => 50,
+      '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'],
+      'trxn_id' => 123,
+      'invoice_id' => 'I-123',
+      'contribution_status_id:name' => 'Completed',
+      'contribution_status_id' => \CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
+    ];
+    $contribution['contribution_status_id:label'] = \CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id']);
+
+    if (isset($example['contribution_params'])) {
+      $contribution = array_merge($contribution, $example['contribution_params']);
+    }
+
+    $mockOrder = new CRM_Financial_BAO_Order();
+    $mockOrder->setTemplateContributionID(50);
+
+    if (empty($example['is_show_line_items'])) {
+      $mockOrder->setPriceSetToDefault('membership');
+      $mockOrder->setOverrideTotalAmount($example['membership_type']['minimum_fee']);
+      $mockOrder->setDefaultFinancialTypeID($example['membership_type']['financial_type_id']);
+    }
+    else {
+      $priceSet = $this->getPriceSet()[$example['price_set_id']];
+      $mockOrder->setPriceSetID($priceSet['id']);
+      if ($priceSet['financial_type_id']) {
+        $mockOrder->setDefaultFinancialTypeID($priceSet['financial_type_id']);
+      }
+    }
+    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;
+    $messageTemplate->setContribution($contribution);
+    $messageTemplate->setOrder($mockOrder);
+    $messageTemplate->setContribution($contribution);
+  }
+
+  /**
+   * Get a non-quick-config price set.
+   *
+   * @return array|null
+   * @throws \CRM_Core_Exception
+   */
+  private function getPriceSet(): ?array {
+    // Permission check defaults to true - likely implicitly OK but may need to be false.
+    return (array) PriceSet::get()
+      ->addWhere('extends', '=', CRM_Core_Component::getComponentID('CiviMember'))
+      ->addOrderBy('is_quick_config', 'DESC')
+      ->execute()->indexBy('id');
+  }
+
+  /**
+   * @param \CRM_Financial_BAO_Order $mockOrder
+   * @param $priceField
+   * @param array|null $priceFieldValue
+   * @param $index
+   * @param $membership
+   *
+   * @throws \CRM_Core_Exception
+   */
+  private function setLineItem(CRM_Financial_BAO_Order $mockOrder, $priceField, ?array $priceFieldValue, $index, $membership): void {
+    $lineItem = [
+      'price_field_id' => $priceField['id'],
+      'price_field_id.label' => $priceField['label'],
+      'price_field_value_id' => $priceFieldValue['id'],
+      'qty' => $priceField['is_enter_qty'] ? 2 : 1,
+      'unit_price' => $priceFieldValue['amount'],
+      'line_total' => $priceField['is_enter_qty'] ? ($priceFieldValue['amount'] * 2) : $priceFieldValue['amount'],
+      'label' => $priceFieldValue['label'],
+      'financial_type_id' => $priceFieldValue['financial_type_id'],
+      'non_deductible_amount' => $priceFieldValue['non_deductible_amount'],
+    ];
+    if (!empty($priceFieldValue['membership_type_id'])) {
+      $lineItem['membership'] = ['start_date' => $membership['start_date'], 'end_date' => $membership['end_date']];
+    }
+    $mockOrder->setLineItem($lineItem, $index);
+  }
+
+}
index 171fe673c2e5c1f0c19bcac5ad1d63f8a8a0b6d1..9522240d5c4683222df128c8b37f09c88671d457 100644 (file)
@@ -22,6 +22,7 @@ use Civi\WorkflowMessage\GenericWorkflowMessage;
  */
 class CRM_Member_WorkflowMessage_MembershipOfflineReceipt extends GenericWorkflowMessage {
   use CRM_Member_WorkflowMessage_MembershipTrait;
+  use CRM_Contribute_WorkflowMessage_ContributionTrait;
   public const WORKFLOW = 'membership_offline_receipt';
 
   /**
index 6ba72b07775c397bd86e7ae8a6c673909d9f454c..13f43f9258df87c32f0410dd88a7027e81b9f6c4 100644 (file)
@@ -22,6 +22,7 @@ use Civi\WorkflowMessage\GenericWorkflowMessage;
  */
 class CRM_Member_WorkflowMessage_MembershipOnlineReceipt extends GenericWorkflowMessage {
   use CRM_Member_WorkflowMessage_MembershipTrait;
+  use CRM_Contribute_WorkflowMessage_ContributionTrait;
   public const WORKFLOW = 'membership_online_receipt';
 
 }
index 62a7fef27dfe4debeb1e5d6e80c670b88a693239..665fd4cb7ea87988d515fedd83100a598f090f3b 100644 (file)
@@ -4,8 +4,6 @@
  * @method array getMembership()
  * @method ?int getMembershipID()
  * @method $this setMembershipID(?int $membershipID)
- * @method ?int getContributionID()
- * @method $this setContributionID(?int $membershipID)
  */
 trait CRM_Member_WorkflowMessage_MembershipTrait {
   /**
@@ -23,15 +21,6 @@ trait CRM_Member_WorkflowMessage_MembershipTrait {
    */
   protected $membershipID;
 
-  /**
-   * Contribution ID.
-   *
-   * @var int
-   *
-   * @scope tokenContext as contributionId, tplParams as contributionID
-   */
-  protected $contributionID;
-
   /**
    * Set membership object.
    *
index 3bbcdf99f82b484ab1a0e2de87d8e7aa1a295d85..3044a098c44d5c3780e78b147e84e8e546cbda3c 100644 (file)
@@ -66,25 +66,9 @@ class Barb extends EntityExample {
       'phone' => '393-7924',
       'email_id' => '7',
       'email' => 'barb@testing.net',
-      'on_hold' => '0',
-      'im_id' => NULL,
-      'provider_id' => NULL,
-      'im' => NULL,
       'worldregion_id' => NULL,
       'world_region' => NULL,
-      'languages' => NULL,
-      'individual_prefix' => NULL,
-      'individual_suffix' => NULL,
-      'communication_style' => NULL,
-      'gender' => 'Female',
-      'state_province_name' => NULL,
-      'state_province' => NULL,
-      'country' => NULL,
-      'email_greeting_id' => 1,
-      'email_greeting_custom' => NULL,
       'email_greeting_display' => 'Dear Barb',
-      'postal_greeting_id' => 1,
-      'postal_greeting_custom' => NULL,
       'postal_greeting_display' => 'Dear Barb',
     ];
   }
index 5fd4eaf96324c73ef6df8dad0d74bbd1685d767c..23f9eb59132eb9d3cf9cf3c91b7e286c3d3afd09 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 use Civi\Api4\FinancialType;
+use Civi\Api4\Membership;
 use Civi\Api4\MembershipType;
 use Civi\Api4\PriceFieldValue;
 
@@ -1518,16 +1519,19 @@ Expires: ',
    * @return string[]
    */
   private function getExpectedEmailStrings(): array {
+    $membership = Membership::get()->execute()->first();
     return [
+      '<td> ' . CRM_Utils_Date::formatDateOnlyLong($membership['start_date']) . ' </td> <td> ' . CRM_Utils_Date::formatDateOnlyLong($membership['end_date']) . ' </td>',
       '<table id="crm-membership_receipt"',
+      'AnnualFixed',
       'Membership Fee',
       'Financial Type',
       'Member Dues </td>',
-      '<tr> <td colspan="2" style="padding: 4px; border-bottom: 1px solid #999;"> <table> <tr> <th>Item</th> <th>Fee</th> <th>SubTotal</th> <th>Tax Rate</th> <th>Tax Amount</th> <th>Total</th> <th>Membership Start Date</th> <th>Membership Expiration Date</th> </tr> <tr> <td> Membership Amount - AnnualFixed </td>',
+      '<tr> <td colspan="2" style="padding: 4px; border-bottom: 1px solid #999;"> <table> <tr> <th>Item</th> <th>Fee</th> <th>SubTotal</th> <th>Tax Rate</th> <th>Tax Amount</th> <th>Total</th> <th>Membership Start Date</th> <th>Membership Expiration Date</th> </tr> <tr> <td>Membership Amount - AnnualFixed</td>',
       '<td> $50.00 </td> <td> $50.00 </td> <td> 10.00% </td> <td> $5.00 </td> <td> $55.00 </td> <td>',
       'Amount Before Tax: </td>',
       '<td style="padding: 4px; border-bottom: 1px solid #999;"> $50.00 </td>',
-      '<td>&nbsp;Sales Tax 10.00%</td> <td>&nbsp;$5.00</td>',
+      '<td style="padding: 4px; border-bottom: 1px solid #999; background-color: #f7f7f7;"> Sales Tax 10.00%</td> <td style="padding: 4px; border-bottom: 1px solid #999;">$5.00</td>',
       'Total Tax Amount </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> $5.00 </td>',
       'Amount </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> $55.00 </td>',
       'Paid By </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> Check </td>',
index 0d00a94e1177e7ef48023dd8fd5c79922025769f..17b704ebf092ecf617f5abd88fe030a8efce73aa 100644 (file)
@@ -32,7 +32,7 @@
     <tr>
       <td>
         <table style="border: 1px solid #999; margin: 1em 0em 1em; border-collapse: collapse; width:100%;">
-          {if empty($lineItem)}
+          {if !$isShowLineItems}
             <tr>
               <th {$headerStyle}>
                 {ts}Membership Information{/ts}
                 {ts}Membership Type{/ts}
               </td>
               <td {$valueStyle}>
-                {$membership_name}
+                {membership.membership_type_id:name}
               </td>
             </tr>
           {/if}
-          {if empty($cancelled)}
-            {if empty($lineItem)}
+          {if '{membership.status_id:name}' !== 'Cancelled'}
+            {if !$isShowLineItems}
               <tr>
                 <td {$labelStyle}>
                   {ts}Membership Start Date{/ts}
                 </td>
                 <td {$valueStyle}>
-                  {$mem_start_date}
+                  {membership.start_date|crmDate:"Full"}
                 </td>
               </tr>
               <tr>
                   {ts}Membership Expiration Date{/ts}
                 </td>
                 <td {$valueStyle}>
-                  {$mem_end_date}
+                    {membership.end_date|crmDate:"Full"}
                 </td>
               </tr>
             {/if}
-            {if $formValues.total_amount OR $formValues.total_amount eq 0 }
+            {if '{contribution.total_amount|raw}' !== '0.00'}
               <tr>
                 <th {$headerStyle}>
                   {ts}Membership Fee{/ts}
                 </th>
               </tr>
-              {if !empty($formValues.contributionType_name)}
+              {if {contribution.financial_type_id|boolean}}
                 <tr>
                   <td {$labelStyle}>
                     {ts}Financial Type{/ts}
                   </td>
                   <td {$valueStyle}>
-                    {$formValues.contributionType_name}
+                    {contribution.financial_type_id:label}
                   </td>
                 </tr>
               {/if}
 
-              {if !empty($lineItem)}
-                {foreach from=$lineItem item=value key=priceset}
+              {if $isShowLineItems}
                   <tr>
                     <td colspan="2" {$valueStyle}>
                       <table>
                         <tr>
                           <th>{ts}Item{/ts}</th>
                           <th>{ts}Fee{/ts}</th>
-                          {if !empty($dataArray)}
+                          {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
                             <th>{ts}SubTotal{/ts}</th>
                             <th>{ts}Tax Rate{/ts}</th>
                             <th>{ts}Tax Amount{/ts}</th>
                           <th>{ts}Membership Start Date{/ts}</th>
                           <th>{ts}Membership Expiration Date{/ts}</th>
                         </tr>
-                        {foreach from=$value item=line}
+                        {foreach from=$lineItems 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.title}</td>
                             <td>
                               {$line.line_total|crmMoney}
                             </td>
-                            {if !empty($dataArray)}
+                            {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
                               <td>
-                                {$line.unit_price*$line.qty|crmMoney}
+                                {$line.unit_price*$line.qty|crmMoney:'{contribution.currency}'}
                               </td>
                               {if $line.tax_rate || $line.tax_amount != ""}
                                 <td>
                                   {$line.tax_rate|string_format:"%.2f"}%
                                 </td>
                                 <td>
-                                  {$line.tax_amount|crmMoney}
+                                  {$line.tax_amount|crmMoney:'{contribution.currency}'}
                                 </td>
                               {else}
                                 <td></td>
                                 <td></td>
                               {/if}
                               <td>
-                                {$line.line_total+$line.tax_amount|crmMoney}
+                                {$line.line_total+$line.tax_amount|crmMoney:'{contribution.currency}'}
                               </td>
                             {/if}
                             <td>
-                              {$line.start_date}
+                              {$line.membership.start_date|crmDate:"Full"}
                             </td>
                             <td>
-                              {$line.end_date}
+                              {$line.membership.end_date|crmDate:"Full"}
                             </td>
                           </tr>
                         {/foreach}
                       </table>
                     </td>
                   </tr>
-                {/foreach}
-                {if !empty($dataArray)}
-                  {if $formValues.total_amount and $totalTaxAmount}
+
+                {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
                   <tr>
                     <td {$labelStyle}>
-                      {ts}Amount Before Tax:{/ts}
+                        {ts}Amount Before Tax{/ts}:
                     </td>
                     <td {$valueStyle}>
-                      {$formValues.total_amount-$totalTaxAmount|crmMoney}
+                        {contribution.tax_exclusive_amount}
                     </td>
                   </tr>
-                  {/if}
-                  {foreach from=$dataArray item=value key=priceset}
+                  {foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
                     <tr>
-                      {if $priceset}
-                        <td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
-                        <td>&nbsp;{$value|crmMoney:$currency}</td>
-                      {elseif  $priceset == 0}
-                        <td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
-                        <td>&nbsp;{$value|crmMoney:$currency}</td>
-                      {/if}
+                      <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}
               {/if}
-              {if $totalTaxAmount}
+              {if '{contribution.tax_amount|raw}' !== '0.00'}
                 <tr>
                   <td {$labelStyle}>
                     {ts}Total Tax Amount{/ts}
                   </td>
                   <td {$valueStyle}>
-                    {$totalTaxAmount|crmMoney:$currency}
+                    {contribution.tax_amount}
                   </td>
                 </tr>
               {/if}
                   {ts}Amount{/ts}
                 </td>
                 <td {$valueStyle}>
-                  {$formValues.total_amount|crmMoney}
+                  {contribution.total_amount}
                 </td>
               </tr>
-              {if !empty($receive_date)}
+              {if {contribution.receive_date|boolean}}
                 <tr>
                   <td {$labelStyle}>
                     {ts}Date Received{/ts}
                   </td>
                   <td {$valueStyle}>
-                    {$receive_date|truncate:10:''|crmDate}
+                    {contribution.receive_date}
                   </td>
                 </tr>
               {/if}
-              {if !empty($formValues.paidBy)}
+              {if {contribution.payment_instrument_id|boolean}}
                 <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|boolean}}
                   <tr>
                     <td {$labelStyle}>
                       {ts}Check Number{/ts}
                     </td>
                     <td {$valueStyle}>
-                      {$formValues.check_number}
+                      {contribution.check_number}
                     </td>
                   </tr>
                 {/if}
index 16207453d0a4fb05e2a2238d84f5ae7e0bb3d3c2..5e2bd3461a1b64a27ab0b44d723ac677e5b71c2f 100644 (file)
@@ -4,32 +4,31 @@
 {$receipt_text}
 {else}{ts}Thank you for this contribution.{/ts}{/if}
 
-{if empty($lineItem)}
+{if !$isShowLineItems}
 ===========================================================
 {ts}Membership Information{/ts}
 
 ===========================================================
-{ts}Membership Type{/ts}: {$membership_name}
+{ts}Membership Type{/ts}: {membership.membership_type_id:name}
 {/if}
-{if empty($cancelled)}
-{if empty($lineItem)}
-{ts}Membership Start Date{/ts}: {$mem_start_date}
-{ts}Membership Expiration Date{/ts}: {$mem_end_date}
+{if '{membership.status_id:name}' !== 'Cancelled'}
+{if !$isShowLineItems}
+{ts}Membership Start Date{/ts}: {membership.start_date|crmDate:"Full"}
+{ts}Membership Expiration Date{/ts}: {membership.end_date|crmDate:"Full"}
 {/if}
 
-{if $formValues.total_amount OR $formValues.total_amount eq 0 }
+{if '{contribution.total_amount|raw}' !== '0.00'}
 ===========================================================
 {ts}Membership Fee{/ts}
 
 ===========================================================
-{if !empty($formValues.contributionType_name)}
-{ts}Financial Type{/ts}: {$formValues.contributionType_name}
+{if {contribution.financial_type_id|boolean}}
+{ts}Financial Type{/ts}: {contribution.financial_type_id:label}
 {/if}
-{if !empty($lineItem)}
-{foreach from=$lineItem item=value key=priceset}
+{if $isShowLineItems}
 {capture assign=ts_item}{ts}Item{/ts}{/capture}
 {capture assign=ts_total}{ts}Fee{/ts}{/capture}
-{if !empty($dataArray)}
+{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
 {capture assign=ts_subtotal}{ts}Subtotal{/ts}{/capture}
 {capture assign=ts_taxRate}{ts}Tax Rate{/ts}{/capture}
 {capture assign=ts_taxAmount}{ts}Tax Amount{/ts}{/capture}
 {/if}
 {capture assign=ts_start_date}{ts}Membership Start Date{/ts}{/capture}
 {capture assign=ts_end_date}{ts}Membership Expiration Date{/ts}{/capture}
-{$ts_item|string_format:"%-30s"} {$ts_total|string_format:"%10s"} {if !empty($dataArray)} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate|string_format:"%10s"} {$ts_taxAmount|string_format:"%10s"} {$ts_total|string_format:"%10s"} {/if} {$ts_start_date|string_format:"%20s"} {$ts_end_date|string_format:"%20s"}
+{$ts_item|string_format:"%-30s"} {$ts_total|string_format:"%10s"} {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate|string_format:"%10s"} {$ts_taxAmount|string_format:"%10s"} {$ts_total|string_format:"%10s"} {/if} {$ts_start_date|string_format:"%20s"} {$ts_end_date|string_format:"%20s"}
 --------------------------------------------------------------------------------------------------
 
-{foreach from=$value item=line}
-{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.line_total|crmMoney|string_format:"%10s"}  {if !empty($dataArray)} {$line.unit_price*$line.qty|crmMoney:$currency|string_format:"%10s"} {if $line.tax_rate || $line.tax_amount != ""}  {$line.tax_rate|string_format:"%.2f"} %  {$line.tax_amount|crmMoney:$currency|string_format:"%10s"}  {else}                  {/if}   {$line.line_total+$line.tax_amount|crmMoney|string_format:"%10s"} {/if} {$line.start_date|string_format:"%20s"} {$line.end_date|string_format:"%20s"}
-{/foreach}
+{foreach from=$lineItems item=line}
+{line.title} {$line.line_total|crmMoney|string_format:"%10s"}  {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'} {$line.unit_price*$line.qty|crmMoney:'{contribution.currency}'|string_format:"%10s"} {if $line.tax_rate || $line.tax_amount != ""}  {$line.tax_rate|string_format:"%.2f"} %  {$line.tax_amount|crmMoney:'{contribution.currency}'|string_format:"%10s"}  {else}                  {/if}   {$line.line_total+$line.tax_amount|crmMoney|string_format:"%10s"} {/if} {$line.membership.start_date|string_format:"%20s"} {$line.membership.end_date|string_format:"%20s"}
 {/foreach}
 
-{if !empty($dataArray)}
-{ts}Amount before Tax{/ts}: {$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}
+{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
+{ts}Amount before Tax{/ts}: {contribution.tax_exclusive_amount}
 
-{foreach from=$dataArray item=value key=priceset}
-{if $priceset}
-{$taxTerm} {$priceset|string_format:"%.2f"} %: {$value|crmMoney:$currency}
-{elseif  $priceset == 0}
-{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency}
-{/if}
+{foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
+{if $taxRate == 0}{ts}No{/ts} {$taxTerm}{else} {$taxTerm} {$taxDetail.percentage}%{/if}: {$taxDetail.amount|crmMoney:'{contribution.currency}'}
 {/foreach}
 {/if}
 --------------------------------------------------------------------------------------------------
 {/if}
 
-{if $totalTaxAmount}
-{ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney:$currency}
+{if '{contribution.tax_amount|raw}' !== '0.00'}
+{ts}Total Tax Amount{/ts}: {contribution.tax_amount}
 {/if}
 
-{ts}Amount{/ts}: {$formValues.total_amount|crmMoney}
-{if !empty($receive_date)}
-{ts}Date Received{/ts}: {$receive_date|truncate:10:''|crmDate}
+{ts}Amount{/ts}: {contribution.total_amount}
+{if {contribution.receive_date|boolean}}
+{ts}Date Received{/ts}: {contribution.receive_date}
 {/if}
-{if !empty($formValues.paidBy)}
-{ts}Paid By{/ts}: {$formValues.paidBy}
-{if !empty($formValues.check_number)}
-{ts}Check Number{/ts}: {$formValues.check_number}
+{if {contribution.payment_instrument_id|boolean}}
+{ts}Paid By{/ts}: {contribution.payment_instrument_id:label}
+{if {contribution.check_number|boolean}}
+{ts}Check Number{/ts}: {contribution.check_number|boolean}
 {/if}
 {/if}
 {/if}