Skip to content

Commit

Permalink
CRM-19585, fixed code for storing civicrm_contribution.tax_amount cor…
Browse files Browse the repository at this point in the history
…rectly

----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585
  • Loading branch information
pradpnayak committed Dec 28, 2016
1 parent ae8fa7c commit 2731885
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,20 +803,19 @@ public static function processAmount($fields, &$params, &$lineItem, $component =
$firstOption = reset($field['options']);
$params["price_{$id}"] = array($firstOption['id'] => $params["price_{$id}"]);
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
if (CRM_Utils_Array::value('tax_rate', $field['options'][key($field['options'])])) {
$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') {
$optionValueId = key($field['options']);

if (CRM_Utils_Array::value('name', $field['options'][$optionValueId]) == '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'];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($field['options'][$optionValueId]['amount'], $field['options'][$optionValueId]['tax_rate']);
$field['options'][$optionValueId]['tax_amount'] = round($taxAmount['tax_amount'], 2);
}
}
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionValueId, $totalTax);
}
$totalPrice += $lineItem[$firstOption['id']]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[key($field['options'])]);
break;

Expand All @@ -830,8 +829,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =

CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, $amount_override);
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionValueId);
$totalTax += $field['options'][$optionValueId]['tax_amount'];
$lineItem = self::setLineItem($field, $lineItem, $optionValueId, $totalTax);
if (CRM_Utils_Array::value('field_title', $lineItem[$optionValueId]) == 'Membership Amount') {
$lineItem[$optionValueId]['line_total'] = $lineItem[$optionValueId]['unit_price'] = CRM_Utils_Rule::cleanMoney($lineItem[$optionValueId]['line_total'] - $lineItem[$optionValueId]['tax_amount']);
}
Expand All @@ -854,8 +852,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =

CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionValueId);
$totalTax += $field['options'][$optionValueId]['tax_amount'];
$lineItem = self::setLineItem($field, $lineItem, $optionValueId, $totalTax);
}
$totalPrice += $lineItem[$optionValueId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionValueId]);
if (
Expand All @@ -872,8 +869,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component =
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
foreach ($params["price_{$id}"] as $optionId => $option) {
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionId])) {
$lineItem = self::setLineItem($field, $lineItem, $optionId);
$totalTax += $field['options'][$optionId]['tax_amount'];
$lineItem = self::setLineItem($field, $lineItem, $optionId, $totalTax);
}
$totalPrice += $lineItem[$optionId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionId]);
if (
Expand Down Expand Up @@ -1665,10 +1661,11 @@ public static function copyPriceSet($baoName, $id, $newId) {
* @param array $field
* @param array $lineItem
* @param int $optionValueId
* @param float $totalTax
*
* @return array
*/
public static function setLineItem($field, $lineItem, $optionValueId) {
public static function setLineItem($field, $lineItem, $optionValueId, &$totalTax) {
if ($field['html_type'] == 'Text') {
$taxAmount = $field['options'][$optionValueId]['tax_amount'] * $lineItem[$optionValueId]['qty'];
}
Expand All @@ -1678,7 +1675,7 @@ public static function setLineItem($field, $lineItem, $optionValueId) {
$taxRate = $field['options'][$optionValueId]['tax_rate'];
$lineItem[$optionValueId]['tax_amount'] = $taxAmount;
$lineItem[$optionValueId]['tax_rate'] = $taxRate;

$totalTax += $taxAmount;
return $lineItem;
}

Expand Down

0 comments on commit 2731885

Please sign in to comment.