Format tax rate for display on confirm/thankyou pages
authorMatthew Wire <devel@mrwire.co.uk>
Sat, 21 Oct 2017 09:27:31 +0000 (10:27 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Sat, 21 Oct 2017 09:27:31 +0000 (10:27 +0100)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/ThankYou.php

index 04563c238d8e312b45beb1f364216973b9d79e21..abddc63b4772353c7f1ca2c745e1a6d0447b3db6 100644 (file)
@@ -520,14 +520,18 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
 
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+    // Make a copy of line items array to use for display only
+    $tplLineItems = $this->_lineItem;
     if ($invoicing) {
       $getTaxDetails = FALSE;
       $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
       foreach ($this->_lineItem as $key => $value) {
-        foreach ($value as $v) {
+        foreach ($value as $k => $v) {
           if (isset($v['tax_rate'])) {
             if ($v['tax_rate'] != '') {
               $getTaxDetails = TRUE;
+              // Cast to float to display without trailing zero decimals
+              $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
             }
           }
         }
@@ -591,7 +595,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
-      $this->assign('lineItem', $this->_lineItem);
+      $this->assign('lineItem', $tplLineItems);
     }
     else {
       $this->assign('is_quick_config', 1);
index 09b44253bbdbd8defa5a0dbe1e7eb66e6442686b..f00974809e67cdcf3435974f31dd8f87a8cee8e6 100644 (file)
@@ -99,30 +99,22 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
     if ($productID) {
       CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
-    if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
-      $this->assign('lineItem', $this->_lineItem);
-    }
-    else {
-      if (is_array($membershipTypeID)) {
-        $membershipTypeID = current($membershipTypeID);
-      }
-      $this->assign('is_quick_config', 1);
-      $this->_params['is_quick_config'] = 1;
-    }
-    $this->assign('priceSetID', $this->_priceSetId);
-    $this->assign('useForMember', $this->get('useForMember'));
 
     $params = $this->_params;
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+    // Make a copy of line items array to use for display only
+    $tplLineItems = $this->_lineItem;
     if ($invoicing) {
       $getTaxDetails = FALSE;
       $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
-      foreach ($this->_lineItem as $value) {
-        foreach ($value as $v) {
+      foreach ($this->_lineItem as $key => $value) {
+        foreach ($value as $k => $v) {
           if (isset($v['tax_rate'])) {
             if ($v['tax_rate'] != '') {
               $getTaxDetails = TRUE;
+              // Cast to float to display without trailing zero decimals
+              $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
             }
           }
         }
@@ -131,6 +123,20 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
       $this->assign('taxTerm', $taxTerm);
       $this->assign('totalTaxAmount', $params['tax_amount']);
     }
+
+    if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
+      $this->assign('lineItem', $tplLineItems);
+    }
+    else {
+      if (is_array($membershipTypeID)) {
+        $membershipTypeID = current($membershipTypeID);
+      }
+      $this->assign('is_quick_config', 1);
+      $this->_params['is_quick_config'] = 1;
+    }
+    $this->assign('priceSetID', $this->_priceSetId);
+    $this->assign('useForMember', $this->get('useForMember'));
+
     if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
       $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);