From 147b56dcf3c54ad8e69557c4a3968c25ae0b3416 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 21 Oct 2017 10:27:31 +0100 Subject: [PATCH] Format tax rate for display on confirm/thankyou pages --- CRM/Contribute/Form/Contribution/Confirm.php | 8 +++-- CRM/Contribute/Form/Contribution/ThankYou.php | 34 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 04563c238d..abddc63b47 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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); diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 09b44253bb..f00974809e 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -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); -- 2.25.1