From 6daab7faabe9025cb3139c1fc6ba58a87fea1e4c Mon Sep 17 00:00:00 2001 From: pratikshad Date: Fri, 27 Jun 2014 19:34:24 +0530 Subject: [PATCH] Display amount including tax on Offline Contribution --- CRM/Contribute/Form/Contribution.php | 4 +++ CRM/Price/BAO/LineItem.php | 2 +- .../CRM/Contribute/Form/Contribution.tpl | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index f8afdec141..fca7b2c736 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -501,6 +501,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return; } $allPanes = array(); + //tax rate from financialType + $taxRates = CRM_Core_PseudoConstant::getTaxRates(); + $taxRates = json_encode($taxRates); + $this->assign('taxRates', $taxRates); // build price set form. $buildPriceSet = FALSE; diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 4f62aaedfc..22138f6aad 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -321,7 +321,7 @@ AND li.entity_id = {$entityId} $lineItems = CRM_Price_BAO_LineItem::create($line); if (!$update && $contributionDetails) { CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails); - if (isset($contributionDetails->tax_trxn_id) && !empty($contributionDetails->tax_trxn_id)) { + if (isset($contributionDetails->tax_trxn_id) && !empty($contributionDetails->tax_trxn_id) && isset($line['tax_amount'])) { CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE); } } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 7c5597dac5..71fd1ba840 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -119,6 +119,7 @@ {if $ppID}{ts}adjust payment amount{/ts}{help id="adjust-payment-amount"}{/if}
{ts}Total amount of this contribution.{/ts}{if $hasPriceSets} {ts}Alternatively, you can use a price set.{/ts}{/if} +
@@ -621,5 +622,35 @@ cj('#fee_amount').change( function() { cj('#net_amount').val(netAmount); } }); + +cj("#financial_type_id").on("change",function(){ + cj('#total_amount').trigger("change"); +}) + +cj('#total_amount').on("change",function(event) { +if(event.handled !== true) { + var financialType = cj('#financial_type_id').val(); + var taxRates = '{/literal}{$taxRates}{literal}'; + var taxRates = JSON.parse(taxRates); + var taxRate = taxRates[financialType]; + var totalAmount = cj('#total_amount').val(); + var taxAmount = calculateTaxAmount(totalAmount,taxRate); + var totalTaxAmount = Number(taxAmount)+Number(totalAmount); + cj( "#totalTaxAmount" ).html('Total Amount : '+totalTaxAmount); + event.handled = true; + } + return false; +}); + +function calculateTaxAmount(totalAmount,taxRate) { + var taxAmount = (taxRate/100)*totalAmount; + if(!taxAmount){ + cj('#totalTaxAmount').html('Total Amount : '+totalAmount); + return false; + } + else{ + return taxAmount; + } +} {/literal} -- 2.25.1