Skip to content

Commit

Permalink
Remove trailing zeros in tax rate for online Confirm/Thankyou forms. …
Browse files Browse the repository at this point in the history
…The actual change is a cast to float, but a small amount of rearranging the function was required so it was actually set. Added note that buildQuickform() in Confirm.php and Thankyou.php share quite a bit of code and would benefit from refactoring
  • Loading branch information
mattwire committed Aug 7, 2017
1 parent 2597efb commit 4b58e3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
21 changes: 12 additions & 9 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,11 @@ public function buildQuickForm() {
$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;
$this->_lineItem[$key][$k]['tax_rate'] = (float) $v['tax_rate']; // Cast to float to display without trailing zero decimals
}
}
}
Expand All @@ -535,6 +536,16 @@ public function buildQuickForm() {
$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', $this->_lineItem);
}
else {
$this->assign('is_quick_config', 1);
$this->_params['is_quick_config'] = 1;
}
$this->assign('priceSetID', $this->_priceSetId);

if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
$option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
$productID = $params['selectProduct'];
Expand Down Expand Up @@ -589,14 +600,6 @@ public function buildQuickForm() {

$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);
}
else {
$this->assign('is_quick_config', 1);
$this->_params['is_quick_config'] = 1;
}
$this->assign('priceSetID', $this->_priceSetId);

// The concept of contributeMode is deprecated.
// the is_monetary concept probably should be too as it can be calculated from
Expand Down
34 changes: 19 additions & 15 deletions CRM/Contribute/Form/Contribution/ThankYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function getAction() {
*/
public function buildQuickForm() {
$this->assignToTemplate();
$params = $this->_params;

$this->_ccid = $this->get('ccid');
$productID = $this->get('productID');
$option = $this->get('option');
Expand All @@ -98,30 +100,18 @@ public function buildQuickForm() {
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);
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;
$this->_lineItem[$key][$k]['tax_rate'] = (float) $v['tax_rate']; // Cast to float to display without trailing zero decimals
}
}
}
Expand All @@ -130,6 +120,20 @@ public function buildQuickForm() {
$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', $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'));

if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);

Expand Down

0 comments on commit 4b58e3b

Please sign in to comment.