diff --git a/CRM/Lineitemedit/Form/Edit.php b/CRM/Lineitemedit/Form/Edit.php index 1bff80a..55e58de 100644 --- a/CRM/Lineitemedit/Form/Edit.php +++ b/CRM/Lineitemedit/Form/Edit.php @@ -28,7 +28,18 @@ public function preProcess() { $this->assignFormVariables(); } + /** + * Check if there is tax value for selected financial type. + * @param $financialTypeId + * @return bool + */ + private function isTaxEnabledInFinancialType($financialTypeId) { + $taxRates = CRM_Core_PseudoConstant::getTaxRates(); + return (isset($taxRates[$financialTypeId])) ? TRUE : FALSE; + } + public function assignFormVariables($params = []) { + $this->_lineitemInfo = civicrm_api3('lineItem', 'getsingle', array('id' => $this->_id)); $this->_lineitemInfo['tax_amount'] = CRM_Utils_Array::value('tax_amount', $this->_lineitemInfo, 0.00); foreach (CRM_Lineitemedit_Util::getLineitemFieldNames() as $attribute) { @@ -105,6 +116,8 @@ public function buildQuickForm() { $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates())); + $this->assign('isTaxEnabled', $this->isTaxEnabledInFinancialType($this->_values['financial_type_id'])); + $this->addFormRule(array(__CLASS__, 'formRule'), $this); $this->addButtons(array( @@ -148,6 +161,10 @@ public function submit($values, $isTest = FALSE) { $this->_lineitemInfo['contribution_id'], 'contact_id' ); + + if (!$this->isTaxEnabledInFinancialType($values['financial_type_id'])) { + $values['tax_amount'] = ''; + } $params = array( 'id' => $this->_id, 'financial_type_id' => $values['financial_type_id'], @@ -157,6 +174,7 @@ public function submit($values, $isTest = FALSE) { 'line_total' => $values['line_total'], 'tax_amount' => CRM_Utils_Array::value('tax_amount', $values, 0.00), ); + $lineItem = CRM_Price_BAO_LineItem::create($params); $lineItem = $lineItem->toArray(); diff --git a/templates/CRM/Lineitemedit/Form/Edit.tpl b/templates/CRM/Lineitemedit/Form/Edit.tpl index 048e04b..438358f 100644 --- a/templates/CRM/Lineitemedit/Form/Edit.tpl +++ b/templates/CRM/Lineitemedit/Form/Edit.tpl @@ -1,7 +1,7 @@ {* HEADER *} {foreach from=$fieldNames item=fieldName} -