From cc3f313d8ee4ac0f889ef92be487212022f4e66b Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 11 Jul 2017 11:17:35 +0100 Subject: [PATCH] Show tax term (eg. VAT) on UI when possible --- CRM/Price/BAO/LineItem.php | 3 ++- CRM/Price/Page/Option.php | 3 ++- templates/CRM/Contribute/Form/Contribution.tpl | 3 ++- templates/CRM/Contribute/Form/Contribution/Confirm.tpl | 2 +- templates/CRM/Contribute/Form/ContributionView.tpl | 2 +- templates/CRM/Event/Form/Registration/Confirm.tpl | 2 +- templates/CRM/Price/Page/LineItem.tpl | 4 ++-- templates/CRM/Price/Page/Option.tpl | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 066da4aa1a..cbe2c80d20 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -301,7 +301,8 @@ WHERE li.contribution_id = %1"; $taxRates = CRM_Core_PseudoConstant::getTaxRates(); if (isset($lineItems[$dao->id]['financial_type_id']) && array_key_exists($lineItems[$dao->id]['financial_type_id'], $taxRates)) { // We are close to output/display here - so apply some rounding at output/display level - to not show Tax Rate in all 8 decimals - $lineItems[$dao->id]['tax_rate'] = round($taxRates[$lineItems[$dao->id]['financial_type_id']], 3); + // Cast to float so trailing zero decimals are removed. + $lineItems[$dao->id]['tax_rate'] = (float) round($taxRates[$lineItems[$dao->id]['financial_type_id']], 3); } else { // There is no Tax Rate associated with this Financial Type diff --git a/CRM/Price/Page/Option.php b/CRM/Price/Page/Option.php index 6b48ca88dd..0724ebec9b 100644 --- a/CRM/Price/Page/Option.php +++ b/CRM/Price/Page/Option.php @@ -153,7 +153,8 @@ class CRM_Price_Page_Option extends CRM_Core_Page { $action = array_sum(array_keys(self::actionLinks())); // Adding the required fields in the array if (isset($taxRate[$values['financial_type_id']])) { - $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']]; + // Cast to float so trailing zero decimals are removed + $customOption[$id]['tax_rate'] = (float) $taxRate[$values['financial_type_id']]; if ($invoicing && isset($customOption[$id]['tax_rate'])) { $getTaxDetails = TRUE; } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index e9428e9734..3cb0381148 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -627,6 +627,7 @@ CRM.$(function($) { if (!freezeFinancialType) { var financialType = $('#financial_type_id').val(); var taxRates = '{/literal}{$taxRates}{literal}'; + var taxTerm = '{/literal}{$taxTerm}{literal}'; taxRates = JSON.parse(taxRates); var currencies = '{/literal}{$currencies}{literal}'; currencies = JSON.parse(currencies); @@ -653,7 +654,7 @@ CRM.$(function($) { var totalTaxAmount = taxAmount + Number(totalAmount); totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker ); - $("#totalTaxAmount" ).html('Amount with tax : ' + currencySymbol + ' '+ totalTaxAmount); + $("#totalTaxAmount" ).html('Amount with ' + taxTerm + ' : ' + currencySymbol + ' '+ totalTaxAmount); } event.handled = true; } diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 571e708849..26c64f314a 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -76,7 +76,7 @@ {/if} {else} {if $totalTaxAmount } - {ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney}
+ {ts}Total {$taxTerm} Amount{/ts}: {$totalTaxAmount|crmMoney}
{/if} {if $amount} {if $installments}{ts}Installment Amount{/ts}{else}{ts}Total Amount{/ts}{/if}: {$amount|crmMoney}{if $amount_level } – {$amount_level}{/if} diff --git a/templates/CRM/Contribute/Form/ContributionView.tpl b/templates/CRM/Contribute/Form/ContributionView.tpl index 33eee999e2..929b20ab6b 100644 --- a/templates/CRM/Contribute/Form/ContributionView.tpl +++ b/templates/CRM/Contribute/Form/ContributionView.tpl @@ -104,7 +104,7 @@ {/if} {if $invoicing && $tax_amount} - {ts}Total Tax Amount{/ts} + {ts}Total {$taxTerm} Amount{/ts} {$tax_amount|crmMoney:$currency} {/if} diff --git a/templates/CRM/Event/Form/Registration/Confirm.tpl b/templates/CRM/Event/Form/Registration/Confirm.tpl index e3a2d37287..bbb719f49d 100644 --- a/templates/CRM/Event/Form/Registration/Confirm.tpl +++ b/templates/CRM/Event/Form/Registration/Confirm.tpl @@ -119,7 +119,7 @@ {if $totalTaxAmount}
-
{ts}Total Tax Amount{/ts}:  {$totalTaxAmount|crmMoney}
+
{ts}Total {$taxTerm} Amount{/ts}:  {$totalTaxAmount|crmMoney}
{/if} diff --git a/templates/CRM/Price/Page/LineItem.tpl b/templates/CRM/Price/Page/LineItem.tpl index 21f093899a..7b7d542dce 100644 --- a/templates/CRM/Price/Page/LineItem.tpl +++ b/templates/CRM/Price/Page/LineItem.tpl @@ -78,7 +78,7 @@ {if $getTaxDetails} {$line.line_total|crmMoney} {if $line.tax_rate != "" || $line.tax_amount != ""} - {$taxTerm} ({$line.tax_rate|string_format:"%.3f"}%) + {$taxTerm} ({$line.tax_rate}%) {$line.tax_amount|crmMoney} {else} @@ -98,7 +98,7 @@
{if $getTaxDetails && $totalTaxAmount} - {ts}Total Tax Amount{/ts}: {$totalTaxAmount|crmMoney}
+ {ts}Total {$taxTerm} Amount{/ts}: {$totalTaxAmount|crmMoney}
{/if} {if $context EQ "Contribution"} {ts}Contribution Total{/ts}: diff --git a/templates/CRM/Price/Page/Option.tpl b/templates/CRM/Price/Page/Option.tpl index 76b625f470..1e337c2c6d 100644 --- a/templates/CRM/Price/Page/Option.tpl +++ b/templates/CRM/Price/Page/Option.tpl @@ -89,7 +89,7 @@ {$row.weight} {if $getTaxDetails} {if $row.tax_rate != '' } - {$taxTerm} ({$row.tax_rate|string_format:"%.2f"}%) + {$taxTerm} ({$row.tax_rate}%) {/if} {$row.tax_amount|crmMoney} -- 2.25.1