Skip to content

Commit

Permalink
Move tax handling from line item api to BAO to make it available from…
Browse files Browse the repository at this point in the history
… apiv4

This implementation has some limitations. I only address one in this PR - removing the rounding - as
the focus of the PR is the move.

The rounding from all save layers was previously removed but it was reverted when it was eroneously believed
to have caused a bug. The bug turned out to be civicrm#18297
  • Loading branch information
eileenmcnaughton committed Sep 4, 2020
1 parent a3ae022 commit 1c4d07a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
* @param array $params
* (reference) an assoc array of name/value pairs.
*
* @return \CRM_Price_DAO_LineItem
* @return CRM_Price_BAO_LineItem
*
* @throws \CiviCRM_API3_Exception
* @throws \Exception
Expand All @@ -53,6 +53,12 @@ public static function create(&$params) {
}
}

$taxRates = CRM_Core_PseudoConstant::getTaxRates();
if (isset($params['financial_type_id'], $params['line_total'], $taxRates[$params['financial_type_id']])) {
$taxRate = $taxRates[$params['financial_type_id']];
$params['tax_amount'] = ($taxRate / 100) * $params['line_total'];
}

$lineItemBAO = new CRM_Price_BAO_LineItem();
$lineItemBAO->copyValues($params);

Expand Down

0 comments on commit 1c4d07a

Please sign in to comment.