Skip to content

Commit

Permalink
Merge pull request civicrm#30 from dpradeep/VAT-569
Browse files Browse the repository at this point in the history
VAT-569 Changes for Offline Contribution with tax amount
  • Loading branch information
pradpnayak committed Aug 6, 2014
2 parents 8d27c10 + cce6ec9 commit e5a79a1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
13 changes: 12 additions & 1 deletion CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ function setDefaultValues() {

// fix the display of the monetary value, CRM-4038
if (isset($defaults['total_amount'])) {
$defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
if (!empty($defaults['tax_amount'])) {
$defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'] - $defaults['tax_amount'], NULL, '%a');
}
else {
$defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
}
}

if (isset($defaults['non_deductible_amount'])) {
Expand Down Expand Up @@ -503,6 +508,7 @@ public function buildQuickForm() {
$allPanes = array();
//tax rate from financialType
$this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
$this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled')));

// build price set form.
$buildPriceSet = FALSE;
Expand Down Expand Up @@ -1094,6 +1100,11 @@ public function postProcess() {

if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
$lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('total_amount', $submittedValues));
// Update line total and total amount with tax on edit
if ($lineItems[$itemId]['tax_amount']) {
$lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney($lineItems[$itemId]['line_total'] + $lineItems[$itemId]['tax_amount']);
$submittedValues['total_amount'] = $lineItems[$itemId]['line_total'];
}
}
// 10117 update th line items for participants
if (!empty($lineItems[$itemId]['price_field_id'])) {
Expand Down
10 changes: 10 additions & 0 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ static function processAmount(&$fields, &$params, &$lineItem, $component = '') {
$lineItem = self::setLineItem($field, $lineItem, key($field['options']));
$totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
}
if (CRM_Utils_Array::value('name', $field['options'][key($field['options'])]) == 'contribution_amount') {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
if (array_key_exists($params['financial_type_id'], $taxRates)) {
$field['options'][key($field['options'])]['tax_rate'] = $taxRates[$params['financial_type_id']];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($field['options'][key($field['options'])]['amount'], $field['options'][key($field['options'])]['tax_rate']);
$field['options'][key($field['options'])]['tax_amount'] = round($taxAmount['tax_amount'], 2);
$lineItem = self::setLineItem($field, $lineItem, key($field['options']));
$totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
}
}
$totalPrice += $lineItem[key($field['options'])]['line_total'];
break;

Expand Down
25 changes: 19 additions & 6 deletions templates/CRM/Contribute/Form/Contribution.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
loadPanes(cj(this).attr('id'));
});
cj('#total_amount').trigger("change");
});
// load panes function calls for snippet based on id of crm-accordion-header
function loadPanes( id ) {
Expand Down Expand Up @@ -627,21 +628,33 @@ cj("#financial_type_id").on("change",function(){
cj('#total_amount').trigger("change");
})
cj("#currency").on("change",function(){
cj('#total_amount').trigger("change");
})
cj('#total_amount').on("change",function(event) {
if(event.handled !== true) {
if (event.handled !== true) {
var financialType = cj('#financial_type_id').val();
var taxRates = '{/literal}{$taxRates}{literal}';
var taxRates = JSON.parse(taxRates);
var currencies = '{/literal}{$currencies}{literal}';
var currencies = JSON.parse(currencies);
var currencySelect = cj('#currency').val();
var currencySymbol = currencies[currencySelect];
var re= /\((.*?)\)/g;
for(m = re.exec(currencySymbol); m; m = re.exec(currencySymbol)){
var currencySymbol = m[1];
}
var taxRate = taxRates[financialType];
if (!taxRate) {
taxRate = 0;
taxRate = 0;
}
var totalAmount = cj('#total_amount').val();
var totalTaxAmount = Number((taxRate/100)*totalAmount)+Number(totalAmount);
cj( "#totalTaxAmount" ).html('Total Amount : '+totalTaxAmount);
var totalTaxAmount = parseFloat(Number((taxRate/100)*totalAmount)+Number(totalAmount)).toFixed(2);
cj( "#totalTaxAmount" ).html('Total Amount : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
event.handled = true;
}
return false;
}
return false;
});
</script>
{/literal}

0 comments on commit e5a79a1

Please sign in to comment.